<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Napoleon Services on Medium]]></title>
        <description><![CDATA[Stories by Napoleon Services on Medium]]></description>
        <link>https://medium.com/@eriksachse?source=rss-358774e3a648------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZTquYDZi7Mf1RR2LHZ4E3w.png</url>
            <title>Stories by Napoleon Services on Medium</title>
            <link>https://medium.com/@eriksachse?source=rss-358774e3a648------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 15:58:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@eriksachse/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to automatically fill out a field with a random value in pocketbase]]></title>
            <link>https://eriksachse.medium.com/how-to-automatically-fill-out-a-field-with-a-random-value-in-pocketbase-94c221c2e37b?source=rss-358774e3a648------2</link>
            <guid isPermaLink="false">https://medium.com/p/94c221c2e37b</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[pocketbase]]></category>
            <dc:creator><![CDATA[Napoleon Services]]></dc:creator>
            <pubDate>Wed, 25 Oct 2023 14:58:59 GMT</pubDate>
            <atom:updated>2023-10-25T14:58:59.027Z</atom:updated>
            <content:encoded><![CDATA[<p>In your backend, besides the pocketbase exe, create a new folder called <em>pb_hooks</em>. Inside this folder create a new file called <em>main.pb.js</em>.</p><pre>onModelBeforeCreate((e) =&gt; {<br>  const randomNamesArray = [ &quot;Aelthorin&quot;, &quot;Zephyria&quot;, &quot;Seraphandor&quot;, &quot;Thalorys&quot;, &quot;Echlyssaria&quot; } ];<br>  e.model.set(&quot;name&quot;, randomNamesArray[Math.floor(Math.random() * randomNamesArray.length)]);<br>  console.log(&quot;name created...&quot;, e.model.get(&quot;name&quot;));<br>}, &quot;name&quot;);</pre><p>Now every time a new record gets created, it automatically adds a random name to the name prop.</p><p>Happy coding 🏖️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94c221c2e37b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Infinite grid gallery with threlte]]></title>
            <link>https://eriksachse.medium.com/infinite-grid-gallery-with-threlte-250c20019bd3?source=rss-358774e3a648------2</link>
            <guid isPermaLink="false">https://medium.com/p/250c20019bd3</guid>
            <category><![CDATA[svelte]]></category>
            <category><![CDATA[threlte]]></category>
            <dc:creator><![CDATA[Napoleon Services]]></dc:creator>
            <pubDate>Wed, 09 Nov 2022 14:46:25 GMT</pubDate>
            <atom:updated>2022-11-09T14:46:25.694Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NeS4RMJnFk-BjW_u1NuV5g.jpeg" /></figure><h3>What we are building:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*pR4DToKw5mBCvHyskVC_Dw.gif" /></figure><h3>Let’s start</h3><h4>1: Place all items</h4><p><a href="https://svelte.dev/repl/d4d83383b2904629ad689257994aaae4?version=3.52.0">Infinite grid gallery threlte * REPL * Svelte</a></p><p>I use an array for this. Make sure each object has their own x and y.</p><p>You can randomize the position a little as you wish, because we’ll check for the distance from each object to the camera.</p><h4>2: Implement drag and move the camera</h4><p>We do this by &lt;svelte:window /&gt; and attach all eventListeners to it. If you don’t have a fullscreen app, use the related container. We also add a dragged value for the x y values. A pointer to check if we are on mousedown. A mousestart for the start position of the mousedown. With this we have the values stored and ready to use.</p><p><em>Task: Try to implement a wheel event as well. Can you do it so it adds the event value to the dragged.y value? Add the touch listeners for mobile as well!</em></p><p>Finally, put the dragged value forward to the camera. We won’t change the position of the elements on drag, because there will be a little smoothing on drag. Also we can add a “tripod” on the camera for future advancements. It makes things a little easier in my head.</p><p><a href="https://svelte.dev/repl/88697350c4004e0692411fa0ee39ea08?version=3.52.0">Infinite grid gallery threlte * REPL * Svelte</a></p><h4>3: Update the position of the objects</h4><p>This is the tricky part. Forward the dragged variable to the Element. Inside Element, use useFrame from threlte to check for the distance to the camera. If the distance is bigger then the array length, update the new position according to the array length.</p><p><a href="https://svelte.dev/repl/c99ffa6332af441ea77da217068668eb?version=3.52.0">Infinite grid gallery threlte * REPL * Svelte</a></p><p>Next steps: Zoom in the camera to make the infinite seemless.</p><p>I hope this helps some people with their projects ✌️</p><p>This is the most important line:</p><pre>distance.x = Math.round((-_.x + dragged.x / 100) / arrayLength);</pre><pre>distance.y = Math.round((_.y + dragged.y / 100) / arrayLength);</pre><pre>if (distance.x !== loop.x) {</pre><pre>  loop.x = distance.x;</pre><pre>  position.x = loop.x * arrayLength + _.x;</pre><pre>}</pre><pre>if (distance.y !== loop.y) {</pre><pre>  loop.y = distance.y;</pre><pre>  position.y = -loop.y * arrayLength + _.y;</pre><pre>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=250c20019bd3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use R3F Next.js || Add page transitions with Framer Motion in the Canvas and DOM]]></title>
            <link>https://eriksachse.medium.com/how-to-use-r3f-next-js-add-page-transitions-with-framer-motion-in-the-canvas-and-dom-95c33c34ce70?source=rss-358774e3a648------2</link>
            <guid isPermaLink="false">https://medium.com/p/95c33c34ce70</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[threejs]]></category>
            <dc:creator><![CDATA[Napoleon Services]]></dc:creator>
            <pubDate>Sun, 03 Apr 2022 05:53:50 GMT</pubDate>
            <atom:updated>2022-04-03T05:53:50.978Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G1exYfV3YzwlZb-MgdnhAA.jpeg" /></figure><blockquote>Disclaimer: This is more a cheatsheet for me, but feel free to use it to understand it. All descriptions of files and functions are my understanding , if that makes sense. Take it with a grain of Salt. You also need some basic framer-motion knowledge. It’s also like a notebook with things noted that work and don’t work, as well as why. Big shout out to the 1 and only <a href="https://twitter.com/onirenaud">Oni</a> creating this wonderful package in the first place👌</blockquote><p>Let’s start with the File structure.</p><pre>[src]<br>--^-- [components]<br>-------------^-- [canvas]<br>--------------------^-- [Shader]<br>---------------------------^-- [glsl]<br>---------------------------------^-- shader.frag<br>---------------------------------^-- shader.vert<br>---------------------------^-- Shader.jsx<br>------------------------ Box.jsx<br>-------------^-- [dom]<br>------------------^-- instruction.jsx</pre><pre>-------------^-- [layout]<br>---------------------^-- canvas.jsx<br>---------------------^-- dom.jsx</pre><pre>--^-- [helpers]<br>-----------^-- partition.js<br>-----------^-- store.js</pre><pre>--^-- [pages]<br>---------^-- _app.jsx<br>---------^-- 404.jsx<br>---------^-- 500.jsx<br>---------^-- box.jsx<br>---------^-- index.jsx</pre><pre>--^-- [styles]<br>---------^-- index.css</pre><pre>--^-- config.jsx</pre><p>Let’s check out some files sorted by their importance.</p><h4>_app.jsx</h4><p>_app.jsx is the fundament of our App. No matter which page, all informations that are set are available gloablly. E.g. if you have a navigation component with urls, it’ll be accesible on all subpages without them re-rendering.</p><h4>index.jsx</h4><p>index.jsx is the file we acces as our base url. Everything that is set there is only our startpage.</p><h4>box.jsx</h4><p>box.jsx will is a subpage that is accessible via _app.jsx (if you have a menu there) or on clicking the box inside index.jsx.</p><h4>layout/canvas.jsx</h4><p>Since this is nested in the _app.jsx file, it won’t change on a page transition. All children are <em>dynamically </em>added.</p><h4>layout/dom.jsx</h4><p>Same as Canvas.</p><h4>config.jsx</h4><p>All meta informations.</p><p>store.js</p><p>Stores values globally. Storing the router object there makes a lot of sense actually, we don’t have to call the router function in components.</p><p>I don’t know what dom does actually.</p><h3>Start</h3><p>Note how on a page switch the Shader cube disappers and the other one appears. It only changes the elements inside the layout component, so in order to have a page transition, we have to put all elements inside the layout component outside of index.jsx and box.jsx…</p><p>Either that, or as in our case we will take advantage of Framer Motion, which has a <a href="https://www.framer.com/docs/animate-presence/">AnimatePresence</a> property. That way we can change the page without have an abrupt change.</p><p>Ok yeah, let’s add &lt;AnimatePresence initial={false}&gt; to our _app.jsx.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*76BIeG96fpaaBxtMxuvnlw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*B75wN8CYyvV8dtT4me4VlQ.png" /></figure><p>And a motion prop to the Shader mesh. Note that there is a framer-motion and framer-motion-3d package. 3D for the meshes. On top of that, add variants.</p><pre>const variants = {<br>    hidden: { opacity: 0, x: -2, y: 0 },<br>    enter: { opacity: 1, x: 0, y: 0 },<br>    exit: { opacity: 0, x: 0, y: -1 },<br>}</pre><p>Should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*FNfKvnd26r6KthqYR2gzVA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v0Z0sBe06f0aGi8DQ-XPjA.png" /></figure><p>Note when switching pages, when the shader cube comes, it has a small animation. You can go ahead and clap on your shoulders now 🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BIFF0XpP8DMRGrzd6gprxg.gif" /></figure><p>The problem is that AnimatePresence is not working with framer-motion-3d. We’ll have to use the <a href="https://nextjs.org/docs/api-reference/next/router#routerevents">router</a> prop shipped with next.js. We also have to check the <a href="https://discoverthreejs.com/tips-and-tricks/#disposing-of-things">disposing of objects</a> guide in order to only load the model of the page.</p><p>Instead of working with pages, where the model is in, we just create pages. And when a page transitions, we check the path to get the correct model. This isn’t suitable for dynamic created pages for now. Maybe?</p><p>Let’s just replace the children props inside the canvas component and put the shader cube in there and check what happens. A router is already in place, so let’s use it to get the path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j1tefWSiPJ7BDTbhe91eUQ.gif" /></figure><p>I just did a useState and check how the router is doing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KDQNyUsEEM50bDbfbvqMig.png" /></figure><p>Now Let’s see if we can check if the animation is finished. If yes, remove the mesh from the scene. I don’t know if that is a good performance option, but the most simple one of course.</p><p>Set an onAnimationComplete={onComplete} prop to the mesh. That way we see if the animation is finished.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RdXitmXg69dBtnOerL6GBQ.gif" /></figure><p>In this tutorial we won’t get rid of the object. We can just make it invisible for performance reasons.</p><blockquote>Removing something from your scene?</blockquote><blockquote>First of all, <strong>consider not doing that</strong>, especially if you will add it back again later. You can hide objects temporarily using object.visible = false (works for lights too), or material.opacity = 0. You can set light.intensity = 0 to disable a light without causing shaders to recompile.</blockquote><p><a href="https://discoverthreejs.com/tips-and-tricks/#disposing-of-things">https://discoverthreejs.com/tips-and-tricks/#disposing-of-things</a></p><blockquote>What happens when I call dispose() and then use the respective object at a later point?</blockquote><blockquote>The deleted internal resources will be created again by the engine. So no runtime error will occur but you might notice a negative performance impact for the current frame, especially when shader programs have to be compiled.</blockquote><p><a href="https://threejs.org/docs/#manual/en/introduction/How-to-dispose-of-objects">three.js</a></p><p>So, if animation is finished, just make the ref invisble. Easy!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*zRE5SkHe6ywwml7nMWUu5A.png" /></figure><p>Push the disabled prop a little outside the screen and we have a nice page transition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cHN8R8sW34ABFkOT5f9zow.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95c33c34ce70" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React-Three-Fiber custom PostProcessing render target solution (Without using the EffectComposer)]]></title>
            <link>https://eriksachse.medium.com/react-three-fiber-custom-postprocessing-render-target-solution-without-using-the-effectcomposer-d3a94e6ae3c3?source=rss-358774e3a648------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3a94e6ae3c3</guid>
            <dc:creator><![CDATA[Napoleon Services]]></dc:creator>
            <pubDate>Tue, 07 Sep 2021 15:23:31 GMT</pubDate>
            <atom:updated>2021-09-10T16:49:34.744Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GZAg4l2wg-q9QGI46yXuDA.png" /></figure><p>Do you want to use a simple fragment shader to spice up your scene without loosing a lot of performance? Or simply want to avoid big imports that you just don’t understand on what they actually do?</p><p>Well I got news.</p><p>First, save this PostFX file in the src/ folder:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce5c23d5fbd480d3b9920f0785678ef9/href">https://medium.com/media/ce5c23d5fbd480d3b9920f0785678ef9/href</a></iframe><p>(Shoutout to <a href="https://gist.github.com/luruke">Luigi</a> for that code)</p><p>Keep in mind that this works well, but it isn’t react hooks yet. If someone wants to convert it to react hooks, I’m happy to help :)</p><p>Then we have to decouple the renderer from React and pipe the scene and camera through PostFX. We are doing this with a component:</p><pre>function Effect() {</pre><pre>  const { gl, scene, camera, size } = useThree()</pre><pre>  const renderer = new PostFX(gl)</pre><pre>  return useFrame((state) =&gt; {</pre><pre>    renderer.render(scene, camera)</pre><pre>  }, 1)</pre><pre>}</pre><p>After that, simply put the Component inside your Canvas.</p><pre>&lt;Canvas&gt;</pre><pre>  &lt;Effect /&gt;</pre><p>Final result:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fxu0e4&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fxu0e4&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fxu0e4%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/291c42bfc5ce79226991c8b30edb01b6/href">https://medium.com/media/291c42bfc5ce79226991c8b30edb01b6/href</a></iframe><p>Now you can simply push some mousemovement values or time values to the PostFX component.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3a94e6ae3c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Kirby as Headless CMS (Outdated)]]></title>
            <link>https://eriksachse.medium.com/using-kirby-as-headless-cms-3ace18a30345?source=rss-358774e3a648------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ace18a30345</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[kirby-cms]]></category>
            <dc:creator><![CDATA[Napoleon Services]]></dc:creator>
            <pubDate>Mon, 05 Jul 2021 15:37:00 GMT</pubDate>
            <atom:updated>2023-02-20T10:39:20.544Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oAhZI3xUAMefH-aoQpyO4w.png" /></figure><blockquote>Part 2 (2022) currently in the making! Lots of changes. Check out the most recent tutorial here: <a href="https://getkirby.com/plugins/getkirby/kql">https://getkirby.com/plugins/getkirby/kql</a></blockquote><p>Modern frontend frameworks usually don’t come with a CMS. But most of my clients want to edit the content on their website. I’ve been learning about JavaScript Frameworks in the past months and it feels fresh 😎</p><p>We will use Kirby CMS, Kirby QL, Next.js and Axios. I guess this is in my opinion the perfect stack for portfolios, blogs or just online presentations. We have a modern framework, hosted on a CDN, and a fundamentally stable and cheap backend.</p><p>But how do I connect the frontend with the backend? What backend can I use? There are plenty of tutorials on how to use a headless CMS, but most of the time it gets really frustrating. I want to have it easy and customisable as I’m used to.</p><p>We want to host the frontend— Next.js in this case — on a CDN platform. And the backend — Kirby CMS in this case — on Uberspace. It can be any shared hoster. We don’t want to spend 50$ a month just to change some images every 6 months. Uberspace is enough and starts at just 5€! <em>(Or even 1€ </em>🤯<em>) </em>Next.js then pulls the content from Uberspace and places it into the website. The only spicy pricy is Kirby CMS with a one time fee of 99€.</p><h4>Backend (Online Installation)</h4><p>First we create a new Uberspace account. I can’t recommend Uberspace enough… They let you use the system for free for a month, then you just pay as much as you want. In the past years I never had one incident. Everything just works. Head over to <a href="https://uberspace.de/en/">https://uberspace.de/en/</a> and create an account. In the main menu page, head over to logins and provide a strong SSH password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rFJDq1bSSYrZO_bSy3Cjdw.png" /></figure><p>After that, go to datasheet and copy the url for the webspace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_fc8oGTaQJ1AY4x7AiKVtA.png" /></figure><p>Now we are ready to hit up terminal and log into the server. Always exciting! In your terminal, write</p><pre>ssh <em>username</em>@<em>hostname</em>.uberspace.de</pre><p>click enter and provide your SSH password when prompted.</p><p>Now we have to find the html folder. go to</p><pre>cd /var/www/virtual/$USER/</pre><p>and check with</p><pre>ls</pre><p>if you are in your home folder. If you see an <em>html</em> folder popping up, make sure to delete its contents with</p><pre>rm -r html/*</pre><p>and install Kirby with</p><pre>composer create-project getkirby/starterkit html</pre><p>and cd into the html folder.</p><pre>cd html</pre><p>Install Kirby QL</p><pre>composer require getkirby/kql</pre><p>This will create our interface so we can say “Hey let me get that specific content of that specific page asap 😤” and the plugin will be like “Here you go 😊”.</p><p>Last thing we need done is to create a user. nano into the Kirby configuration with</p><pre>mkdir site/config</pre><pre>nano site/config/config.php</pre><p>And paste this code:</p><pre><strong>&lt;?php<br></strong>return [<br>   &#39;debug&#39; =&gt; false,<br>   &#39;api&#39; =&gt; [<br>       &#39;basicAuth&#39; =&gt; true<br>   ],<br>   &#39;panel&#39; =&gt;[<br>       &#39;install&#39; =&gt; true<br>   ]<br>];</pre><p>Save the file and close nano (Mac: control + o, enter, control + x)</p><p>Now go to <a href="https://username.uber.space/">https://<em>username</em>.uber.space/</a> and if you see images, the installation was successful. Hit up <a href="https://username.uber.space/panel">https://<em>username</em>.uber.space/panel</a> and create a user. Save the password, or just use the same as the SSH to not get confused.</p><p>After that we have the Starterkit installed and created a user. We surely have to edit Kirby in the future, but that is another tutorial itself. Since it’s a filesystem we could just make a git and push and pull back and forth. But there is also a SSH plugin for visual studio code which works surprisingly well. (<a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh">https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh</a>) Alternative for Atom: <a href="https://atom.io/packages/ftp-remote-edit">https://atom.io/packages/ftp-remote-edit</a></p><h4>Additional Info</h4><p>If you want to fetch certain data like PDF’s, you’ll need a special header for this. I struggled with that one for quite some time, but I’ll share it with you here.</p><p>When logged into the server with your terminal, paste</p><pre>uberspace web header set / Access-Control-Allow-Origin “*”</pre><p>into (Replace the “ with the corrent quotation marks. Medium changes these here 😒)the terminal and it’ll allow another domain to access all kinds of files. Don’t ask me, I’m still confused on why images work, but PDF’s.</p><h3>~~</h3><p>Nowadays and personally I use <a href="https://laravel.com/docs/8.x/valet">laravel valet</a> as a local server to have a better access to the code. The above Uberspace guide is cool, but if you want to have a more sustainable environment try to set laravel up.</p><h4>Frontend</h4><p>After the installation of Next.js, go to index.js inside the page folder.</p><p>Copy this code on the bottom of the file. getStaticProps can handle async requests which is a cool website feature. It makes sure that the page looks like something before the content - consisting of heavy images - gets loaded. Read more here: <a href="https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation">https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/690b67ccf17c3cdd1aa9501bd4153e1f/href">https://medium.com/media/690b67ccf17c3cdd1aa9501bd4153e1f/href</a></iframe><p>To put the data into the website, we use the props given in the return statement.</p><pre>export default function Home({ data }) { …</pre><p>and inside the return we can try something smooth like</p><pre>{data.result.map((dat, i) =&gt; (</pre><pre>    &lt;div key={i} className={styles.card}&gt;</pre><pre>        &lt;h3&gt;{dat}&lt;/h3&gt;</pre><pre>    &lt;/div&gt;</pre><pre>))}</pre><p>And voila, we’ve got ourselves a nice webpage:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q8KtMXksF2k_hO-3UocYQg.png" /></figure><p>Next update on this tutorial is gonna be dynamical created pages (static and on build time) So make sure to follow this :)</p><h3>🦕</h3><p>todo (maybe someone wants to help me out)</p><ul><li>Hide Kirby password in frontend files</li><li>Global state</li><li>Is prefetch still a thing?</li><li>Routing (getStaticPaths)</li><li>Image scrset with KQL</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ace18a30345" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React-Three-Fiber use-gesture to move the camera]]></title>
            <link>https://eriksachse.medium.com/react-three-fiber-use-gesture-to-move-the-camera-f50288cec862?source=rss-358774e3a648------2</link>
            <guid isPermaLink="false">https://medium.com/p/f50288cec862</guid>
            <category><![CDATA[threejs]]></category>
            <category><![CDATA[r3f]]></category>
            <category><![CDATA[react-three-fiber]]></category>
            <dc:creator><![CDATA[Napoleon Services]]></dc:creator>
            <pubDate>Sat, 03 Oct 2020 08:33:24 GMT</pubDate>
            <atom:updated>2023-10-14T12:24:00.190Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Disclaimer: This article is from 2020. Please refer to newer articles about R3F since a lot of things changed.</em></p><p>In this tutorial you gonna learn how to bind gesture inputs from use-gesture to react-three-fiber. It wasn’t clear for me at first, so I thought I’ld make a simple tutorial about it. It’s originally from an <a href="https://codesandbox.io/s/r3f-train-l900i">example</a> by Paul.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o8nLtkhGWM03b4mgEJNAUw.jpeg" /></figure><p>We are gonna using a custom camera. The reason behind this is to animate the camera. If you want to move objects with gestures, you don’t need to separate the camera from the canvas.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc1c577e15ab7374f1b84394cb7af547/href">https://medium.com/media/bc1c577e15ab7374f1b84394cb7af547/href</a></iframe><p>Instead of</p><pre>&lt;Canvas camera ...&gt;</pre><p>we can use</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce03f5f9c58303536845a6e66f2e2554/href">https://medium.com/media/ce03f5f9c58303536845a6e66f2e2554/href</a></iframe><p>After stripping down the code a lil bit, it should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e511b550b3184d51f523740527d737f9/href">https://medium.com/media/e511b550b3184d51f523740527d737f9/href</a></iframe><p>Next we are going to bind user gestures to our scene with <a href="https://github.com/pmndrs/react-use-gesture">react-use-gesture</a>. Install</p><pre>npm install react-use-gesture</pre><p>and</p><pre>npm install @react-spring/three</pre><p>use-gesture for the input and react-spring for the animating of object. In this case it’s the camera. To keep things simple, create a new file named scroll.js and import both librarys like this.</p><pre>import { useSpring, config } from “@react-spring/core”;</pre><pre>import { useGesture } from “react-use-gesture”;</pre><p>We also need</p><pre>import { useCallback, useEffect } from “react”;</pre><p>useCallBack and useEffect are simply hooks. Further reading: <a href="https://reactjs.org/docs/hooks-reference.html">https://reactjs.org/docs/hooks-reference.html</a></p><p>We are not only gonna bind the wheel event, but also the drag event to make it mobile friendly. After that we bind it to the domTarget, which is the canvas. Usually gestures are bound to an object (e.g. for click events), but we don’t want that here. The final code for the Scroll.js looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1950c8f83c6827880e4c0951fdf5eac8/href">https://medium.com/media/1950c8f83c6827880e4c0951fdf5eac8/href</a></iframe><p>Oh yeah, I forgot to mention that clamp is a super important and cool feature. We don’t need it in the infinite scene example, but it clamps two numbers and returns it. It’s like two if statements.</p><p>Next, import</p><pre>import { a } from “@react-spring/three”;</pre><pre>import Scroll from “./Scroll”;</pre><p>to the App.js. We are binding <em>a</em> for the camera.</p><p>Inside our Camera function, create a constant,</p><pre>const [y] = Scroll([-100, 100], { domTarget: window });</pre><p>assign it to the position of the camera (Still in the camera function)</p><pre>&lt;perspectiveCamera ref={ref} {...props} position-y={y.to((y) =&gt; (y / 500) * 25)} /&gt;</pre><p>and assign the animation <em>a</em></p><pre>return &lt;a.perspectiveCamera ref={ref} {...props} position-y={y.to((y) =&gt; (y / 500) * 25)} /&gt;</pre><p>And voilá, scroll activated.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f50288cec862" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React-Three-Fiber — let’s create a dice]]></title>
            <link>https://eriksachse.medium.com/react-three-fiber-lets-create-a-dice-b83f322d28ea?source=rss-358774e3a648------2</link>
            <guid isPermaLink="false">https://medium.com/p/b83f322d28ea</guid>
            <category><![CDATA[react-three-fiber]]></category>
            <category><![CDATA[threejs]]></category>
            <category><![CDATA[r3f]]></category>
            <dc:creator><![CDATA[Napoleon Services]]></dc:creator>
            <pubDate>Thu, 24 Sep 2020 10:22:45 GMT</pubDate>
            <atom:updated>2023-09-08T15:27:42.795Z</atom:updated>
            <content:encoded><![CDATA[<h3>React-Three-Fiber — let’s create a dice</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D2oAcdbLnNBEMzDW7NNfww.png" /><figcaption>A nice dice</figcaption></figure><p>This article is outdated. To apply multiple textures on one object, refer to <a href="https://github.com/pmndrs/react-three-fiber/discussions/744#discussioncomment-3041660">https://github.com/pmndrs/react-three-fiber/discussions/744#discussioncomment-3041660</a></p><p>In this article I want to show you how simple it is to create a mesh with different textures on each surface. It can even be multiple materials. You’ll learn how to load textures and display them on a cube.</p><p>Start with a basic react-three-fiber setup. Just fork the demo below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fun3di&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fun3di&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fun3di%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/cccff761b5be589f6895cdbd29f89dd9/href">https://medium.com/media/cccff761b5be589f6895cdbd29f89dd9/href</a></iframe><p>Next, in the Box function we copy the material 6 times. One material for each side.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f7d1dca8686f7b20fc4b612805d5b82/href">https://medium.com/media/5f7d1dca8686f7b20fc4b612805d5b82/href</a></iframe><p>Inside our public folder, create a folder called <em>textures</em>.</p><p>Upload these images into textures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*7qQEl145W_OxflGNUNm0Xg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*NDSbSXPqhYC4T7x27g-HDg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*hMTCwMk2Gi6recy-oV-cwA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*FPiVjfdW9HnXSbkt-8DF8A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*4pM1-Vgnh_cAVW5pK9P-YQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*PkcAXeWVF-ZQWoUmMhss3Q.jpeg" /></figure><p>Next, we need a Texture Loader. It comes with three.js, so we have to import that. On top of our document:</p><pre>import { TextureLoader } from ‘three/src/loaders/TextureLoader.js’;</pre><p>and now, inside our Box() function, we can use that loader.</p><pre>const texture_1 = useLoader(TextureLoader, &#39;textures/dice_1.jpg&#39;);</pre><p>To use the loader, we also have to import a useLoader function from react-three.</p><pre>import { Canvas, useFrame, <em>useLoader</em> } from &#39;react-three-fiber&#39;</pre><p>If we look at the output of this function, we can see it’s all gut. Wait, no, it’s not all gut:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o_5V7EE22_1XRpJqXV1UZQ.png" /></figure><p>React wants us to display something else while the texture is loading. Ok, why not.</p><p>Import Suspense from react.</p><pre>import React, { useRef, Suspense } from ‘react’</pre><p>And in our Canvas output, put the box inside a Suspense component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f52a5b9a8fbcd5b3330ff305e8c2a25/href">https://medium.com/media/3f52a5b9a8fbcd5b3330ff305e8c2a25/href</a></iframe><p>With Suspense you are able to show a loading indicator. Here is more information: <a href="https://reactjs.org/docs/concurrent-mode-suspense.html">https://reactjs.org/docs/concurrent-mode-suspense.html</a></p><p>Now it’s working, and our console shows the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yKSIoMQcU69rp4j2aEwclQ.png" /><figcaption>console imported texture</figcaption></figure><p>Add a const for every texture and use it for each dice side.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94f205367083cb6772745d9907bc9418/href">https://medium.com/media/94f205367083cb6772745d9907bc9418/href</a></iframe><p>But wait… now we only see one texture applied.</p><p>To fix that we have to replace</p><pre>attach=”material” </pre><p>with</p><pre>attachArray=”material” </pre><p>And voila, it creates a texture for each surface.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2F2kzbr&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F2kzbr&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F2kzbr%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/dadafba9851a802639690b94e08d376d/href">https://medium.com/media/dadafba9851a802639690b94e08d376d/href</a></iframe><p>A nice dice.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b83f322d28ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Three.js pixelated lo-fi energy look]]></title>
            <link>https://eriksachse.medium.com/three-js-pixelated-lo-fi-energy-look-298b8dc3eaad?source=rss-358774e3a648------2</link>
            <guid isPermaLink="false">https://medium.com/p/298b8dc3eaad</guid>
            <category><![CDATA[webgl]]></category>
            <category><![CDATA[pixel]]></category>
            <category><![CDATA[threejs]]></category>
            <category><![CDATA[3d]]></category>
            <dc:creator><![CDATA[Napoleon Services]]></dc:creator>
            <pubDate>Fri, 05 Jun 2020 09:54:42 GMT</pubDate>
            <atom:updated>2020-06-10T08:24:09.667Z</atom:updated>
            <content:encoded><![CDATA[<p>Three.js comes with a pre build in WebGLRenderer. The other day I wanted to create a scene in a pixelated low quality look. By just turning down the Pixel-Ratio it still will *<em>antialias</em>* some parts of the scene. This has more to do with the internal GPU, rather than three.js.</p><blockquote>renderer.setPixelRatio( 0.2 );</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*-mujcwDcg9GKzHcYS2Z9ew.gif" /><figcaption>Not my kind of lo-fi energy</figcaption></figure><p>Now what we can do is to create a new scene. This scene consists of a new camera and texture. The camera is an orthographic camera, which means it does not have a perspective. Everything Orthographic-Scene related will be called <em>dummy</em>.</p><pre>renderer.setPixelRatio( window.devicePixelRatio )</pre><pre>dummyTexture = new THREE.WebGLRenderTarget(</pre><pre>  container.clientWidth/4, //resolution x</pre><pre>  container.clientHeight/4, //resolution y</pre><pre>  {</pre><pre>    minFilter: THREE.LinearFilter,</pre><pre>    magFilter: THREE.NearestFilter,</pre><pre>    format: THREE.RGBFormat</pre><pre>  }<br>);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*AiH6djg9kwxn40m67SLm5Q.gif" /><figcaption>That’s the spirit</figcaption></figure><p>Basically we’ll just use the <a href="https://threejs.org/examples/webgl_rtt.html">RenderToTexture</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8RjRmM-uXhEgAEYTe1x1lQ.jpeg" /></figure><p>Because the Scene gets rendered as a texture via vertexShader, we can ignore the MSAA as well.</p><p>Quick fiddle: <a href="https://jsfiddle.net/joooo0/2y3qc7sw/">https://jsfiddle.net/joooo0/2y3qc7sw/</a></p><h3>Including a FragmentShader</h3><p>Now that we have our render to texture in place, we can add some fine shader on top of it. These won’t affect the big pixels, but the smaller device pixels. Let’s just add a little <em>wobbly</em> wave.</p><p>The FragmentShader looks like this: (I copied this from <a href="https://www.shadertoy.com/view/MsK3WW">ToyShader</a>, don’t tell anyone)</p><pre>#include &lt;common&gt;<br> <br>uniform vec3 iResolution;<br>uniform float <em>iTime</em>;<br>varying vec2 vUv;<br>uniform sampler2D tDiffuse;</pre><pre>void mainImage( out vec4 fragColor, in vec2 fragCoord ) {<br>  vec2 uv = vUv / 1.0;<br>  fragColor = texture2D(tDiffuse, uv + vec2(sin(<em>iTime</em>*3.0 + uv.x * 10.0) * 0.003, 0.0));</pre><pre>}</pre><pre>void main() { <br>  mainImage(gl_FragColor, gl_FragCoord.xy);<br>}</pre><p>Next, edit our code and split the uniforms, so it’s cleaner; and we add a iTime value. This will make the wobble go <em>wobble 💃</em></p><pre>var uniforms = {<br> tDiffuse: { value: rtTexture.texture }, <br> <em>iTime</em>: { value: 0 }, <br> iResolution: { value: new THREE.Vector3() },<br>};</pre><p>After that, we edit our animation so it’ll update the iTime value.</p><pre>function animate(time) {<br> time *= 0.001;<br> uniforms.iResolution.value.set(window.innerWidth, window.innerHeight, 1);<br> uniforms.iTime.value = time;<br> requestAnimationFrame( animate );<br> render();<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*h-vH6yfpmiAGdERRTmfeeQ.gif" /><figcaption><em>Wobble</em></figcaption></figure><p>The final fiddle: <a href="https://jsfiddle.net/joooo0/akmcexfv/">https://jsfiddle.net/joooo0/akmcexfv/</a></p><p>Now it’s time to just experiment with different shaders. Maybe add a cool <a href="https://medium.com/@joshmarinacci/cartoon-outline-effect-6c4e95545537">outline</a>?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=298b8dc3eaad" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>