<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jorge Gómez 👨‍💻🚀 </title>
    <description>The latest articles on Forem by Jorge Gómez 👨‍💻🚀  (@jgcarrillo).</description>
    <link>https://forem.com/jgcarrillo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F410853%2F636e11f3-419e-41be-95d5-dd872c5296fc.jpg</url>
      <title>Forem: Jorge Gómez 👨‍💻🚀 </title>
      <link>https://forem.com/jgcarrillo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jgcarrillo"/>
    <language>en</language>
    <item>
      <title>Create a First Person Movement in React Three Fiber - Part 2</title>
      <dc:creator>Jorge Gómez 👨‍💻🚀 </dc:creator>
      <pubDate>Mon, 26 Sep 2022 05:42:18 +0000</pubDate>
      <link>https://forem.com/jgcarrillo/create-a-first-person-movement-in-react-three-fiber-part-2-1jic</link>
      <guid>https://forem.com/jgcarrillo/create-a-first-person-movement-in-react-three-fiber-part-2-1jic</guid>
      <description>&lt;p&gt;Continuing with the series, in this post we are going to see &lt;strong&gt;the real code&lt;/strong&gt; for this project. As always, the entire project is available in my personal repo below:&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/jgcarrillo" rel="noopener noreferrer"&gt;
        jgcarrillo
      &lt;/a&gt; / &lt;a href="https://github.com/jgcarrillo/react-fp-movement" rel="noopener noreferrer"&gt;
        react-fp-movement
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Basic scene with geometries and gLTF models to control a character in first person camera
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/1dc0e4b9031b59393a3d9b82a1df79ecaf0a8df5b83ef7633b0eabfadb178801/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6a6763617272696c6c6f2f72656163742d66702d6d6f76656d656e74"&gt;&lt;img src="https://camo.githubusercontent.com/1dc0e4b9031b59393a3d9b82a1df79ecaf0a8df5b83ef7633b0eabfadb178801/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6a6763617272696c6c6f2f72656163742d66702d6d6f76656d656e74" alt="GitHub stars"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/a3a39207103d1b994b452812865391e78dd559100ba7ec06e5a32dd8356f452d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6a6763617272696c6c6f2f72656163742d66702d6d6f76656d656e74"&gt;&lt;img src="https://camo.githubusercontent.com/a3a39207103d1b994b452812865391e78dd559100ba7ec06e5a32dd8356f452d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6a6763617272696c6c6f2f72656163742d66702d6d6f76656d656e74" alt="GitHub issues"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/cafb4753b8ebef3f4978694c66ed4a2bdef69a3771d466641a9c474d091d16f2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6a6763617272696c6c6f2f72656163742d66702d6d6f76656d656e74"&gt;&lt;img src="https://camo.githubusercontent.com/cafb4753b8ebef3f4978694c66ed4a2bdef69a3771d466641a9c474d091d16f2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6a6763617272696c6c6f2f72656163742d66702d6d6f76656d656e74" alt="GitHub forks"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/64fd1376407134c90f2506b17606b8b80de65d15aa097c9e9cf921ce2fdbff3d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f6a6763617272696c6c6f2f72656163742d66702d6d6f76656d656e74"&gt;&lt;img src="https://camo.githubusercontent.com/64fd1376407134c90f2506b17606b8b80de65d15aa097c9e9cf921ce2fdbff3d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f6a6763617272696c6c6f2f72656163742d66702d6d6f76656d656e74" alt="GitHub PRs"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Table of contents 👇&lt;/h2&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/jgcarrillo/react-fp-movement#-motivation" rel="noopener noreferrer"&gt;✨ Motivation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jgcarrillo/react-fp-movement#-technologies" rel="noopener noreferrer"&gt;🚩 Technologies&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jgcarrillo/react-fp-movement#-project-structure" rel="noopener noreferrer"&gt;🕸️ Project Structure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jgcarrillo/react-fp-movement#-basic-explanation" rel="noopener noreferrer"&gt;🚀 Basic Explanation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jgcarrillo/react-fp-movement#-contact" rel="noopener noreferrer"&gt;🌎 Contact&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;✨ Motivation&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;A few months ago I started to working with &lt;strong&gt;React Three Fiber&lt;/strong&gt;. I was impressed with the possibilities the library gives to you to create 3D environments. I saw a wide variety of examples in &lt;a href="https://docs.pmnd.rs/react-three-fiber/getting-started/examples" rel="nofollow noopener noreferrer"&gt;R3F website&lt;/a&gt; so I started to explore more about the project.&lt;/p&gt;
&lt;p&gt;There are so many good examples out there, but I get motivated with some of them, for example, a &lt;a href="https://codesandbox.io/s/ping-pong-0mgum" rel="nofollow noopener noreferrer"&gt;Ping Pong game&lt;/a&gt; or even a &lt;a href="https://codesandbox.io/s/arkanoid-under-60-loc-66cd7" rel="nofollow noopener noreferrer"&gt;simple Arkanoid clone&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Since that, I have working in so many pet projects to understand the &lt;em&gt;key concepts&lt;/em&gt; of React Three Fiber and also &lt;strong&gt;Three.js&lt;/strong&gt;. I don't consider myself a R3F pro, nor even a beginner, but now I feel confident about the fact that I can create such 3D scenarios.&lt;/p&gt;
&lt;p&gt;I started creating basic &lt;strong&gt;isometric scenes&lt;/strong&gt;…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/jgcarrillo/react-fp-movement" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Physics 🧲
&lt;/h2&gt;

&lt;p&gt;For this example we are going to use &lt;a href="https://github.com/pmndrs/use-cannon" rel="noopener noreferrer"&gt;Reac Three Cannon&lt;/a&gt; a specific library to create &lt;strong&gt;physics&lt;/strong&gt;. You can use &lt;a href="https://github.com/pmndrs/react-three-rapier" rel="noopener noreferrer"&gt;Rapier&lt;/a&gt;, another cool library, but is under development right now.&lt;/p&gt;

&lt;p&gt;To set up physics you need to import the appropriate geometry such as &lt;strong&gt;plane geometry, sphere geometry&lt;/strong&gt;, etc. Then you need to &lt;strong&gt;establish  the physics options&lt;/strong&gt; like mass, position, etc.&lt;/p&gt;

&lt;p&gt;In the code below you can see the &lt;strong&gt;floor component&lt;/strong&gt; a 2D plane. We need that the plane has physics but no mass since in that case it would go into a downward loop.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// Floor.js&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;usePlane&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@react-three/cannon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Floor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;usePlane&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Static&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;mass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="p"&gt;}));&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;mesh&lt;/span&gt; &lt;span class="nx"&gt;receiveShadow&lt;/span&gt; &lt;span class="nx"&gt;rotation&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rotation&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;planeGeometry&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{[&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;meshStandardMaterial&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/mesh&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;From now, every of our components will have physics as they would otherwise go into an &lt;strong&gt;infinite drop&lt;/strong&gt; and behave strangely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Important components 📚
&lt;/h2&gt;

&lt;p&gt;We are not going to see all the code of the components but it's important to know &lt;strong&gt;some key concepts&lt;/strong&gt;. The next component is &lt;code&gt;ThreeModel.js&lt;/code&gt; which is the model of the three. To do this I have used a model from internet and &lt;a href="https://gltf.pmnd.rs/" rel="noopener noreferrer"&gt;this utility&lt;/a&gt; to create a &lt;strong&gt;React component from a gLTF&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;glTF (derivative short form of Graphics Language Transmission Format or GL Transmission Format) is a standard file format for three-dimensional scenes and models. &lt;a href="https://en.wikipedia.org/wiki/GlTF" rel="noopener noreferrer"&gt;Wikipedia&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The point is that you need to set up the physics as following. The important thing to know is that you need to set the &lt;strong&gt;size of the hit box&lt;/strong&gt; that corresponds to the model.&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://www.gamedeveloper.com/design/hitboxes-and-hurtboxes-in-unity" rel="noopener noreferrer"&gt;following image from here&lt;/a&gt; you can see the concept.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5v86mnfrptnpekzd978d.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5v86mnfrptnpekzd978d.jpg" alt="Hit box of a character"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, with this code I have created a hit box with &lt;strong&gt;the same size as the three&lt;/strong&gt;. I know it's difficult at first. We are receiving all these options &lt;strong&gt;through props&lt;/strong&gt; to make the component more &lt;em&gt;reusable&lt;/em&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// Physics for ThreeModel.js&lt;/span&gt;
&lt;span class="c1"&gt;// Don't forget to put your models inside the public folder&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useBox&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Static&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;mass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;position&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

  &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}));&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Probably the &lt;strong&gt;most tricky&lt;/strong&gt; component is the character because we need to define physics, movement and also the position of the camera. It has a lot of code but we are going to see the most interesting.&lt;/p&gt;

&lt;p&gt;We use the &lt;strong&gt;hook&lt;/strong&gt; &lt;code&gt;useThree&lt;/code&gt; to access to the &lt;strong&gt;state model&lt;/strong&gt; such as camera, renderer, scene, etc. Then, we need to define the &lt;strong&gt;position of the world&lt;/strong&gt;. Finally, we set up the character movement.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// BaseCharacter.js&lt;/span&gt;

&lt;span class="c1"&gt;// Access to the state model&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;camera&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useThree&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Set the current World position&lt;/span&gt;
&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getWorldPosition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;camera&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;position&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Set the direction of the character&lt;/span&gt;
&lt;span class="nx"&gt;direction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subVectors&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;frontVector&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sideVector&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;multiplyScalar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;SPEED&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;applyEuler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;camera&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rotation&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Another important component is the &lt;strong&gt;Scene&lt;/strong&gt;. In this case I have create a &lt;em&gt;basic scene&lt;/em&gt;* one. The important thing to know is the use of &lt;strong&gt;React children&lt;/strong&gt; &lt;a href="https://reactjs.org/docs/legacy-context.html#parent-child-coupling" rel="noopener noreferrer"&gt;prop&lt;/a&gt; to reuse the scene.&lt;/p&gt;

&lt;p&gt;Here, you need to notice that I'm using &lt;code&gt;&amp;lt;PointerLockControls /&amp;gt;&lt;/code&gt; a component of &lt;strong&gt;Drei library&lt;/strong&gt; to use the mouse as the same way you would use in a FPS.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Canvas&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@react-three/fiber&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Loader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;PointerLockControls&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@react-three/drei&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Physics&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@react-three/cannon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Lights&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../components/Lights.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Floor&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../components/Floor.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;BasicScene&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Canvas&lt;/span&gt; &lt;span class="nx"&gt;shadows&lt;/span&gt; &lt;span class="nx"&gt;camera&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;fov&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Lights&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;

        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Physics&lt;/span&gt; &lt;span class="nx"&gt;gravity&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;9.8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Floor&lt;/span&gt; &lt;span class="nx"&gt;rotation&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{[&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PI&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;white&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Physics&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;PointerLockControls&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Canvas&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Loader&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;BasicScene&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Another importat thing is that the physics &lt;strong&gt;only works&lt;/strong&gt; within &lt;code&gt;Physics&lt;/code&gt; component.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;helper.js&lt;/code&gt; file contains the movement for different geometries. I'm not going to explain this because &lt;strong&gt;I found it on internet in one of the R3F examples&lt;/strong&gt; and it's not difficult to set up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the scene 🎭
&lt;/h2&gt;

&lt;p&gt;So, that's it! The next step is to create the scene within the &lt;code&gt;App.js&lt;/code&gt; component. It's also important to set up the &lt;strong&gt;CSS styles&lt;/strong&gt; for the canvas.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nt"&gt;canvas&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;max-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;&lt;span class="n"&gt;wh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I hope you find it useful as I did. You can see the final project &lt;a href="https://react-fp-movement.netlify.app/" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Feel free to reach me out and start creating your own projects. 💪💪 &lt;/p&gt;

</description>
      <category>react</category>
      <category>tutorial</category>
      <category>reactthreefiber</category>
      <category>threejs</category>
    </item>
    <item>
      <title>Create a First Person Movement in React Three Fiber - Part 1</title>
      <dc:creator>Jorge Gómez 👨‍💻🚀 </dc:creator>
      <pubDate>Fri, 23 Sep 2022 09:30:38 +0000</pubDate>
      <link>https://forem.com/jgcarrillo/create-a-first-person-movement-in-react-three-fiber-part-1-f0c</link>
      <guid>https://forem.com/jgcarrillo/create-a-first-person-movement-in-react-three-fiber-part-1-f0c</guid>
      <description>&lt;p&gt;In this post I want to show you how I have created a 3D environment in &lt;strong&gt;React&lt;/strong&gt; with &lt;strong&gt;React Three Fiber&lt;/strong&gt;, a library that implements &lt;em&gt;Three.js&lt;/em&gt; in its core.&lt;/p&gt;

&lt;p&gt;I will try to explain myself as much clear as I can because there are a lot of concepts that go beyond programming.&lt;/p&gt;

&lt;p&gt;I have been using &lt;em&gt;Three.js&lt;/em&gt; and &lt;em&gt;React Three Fiber&lt;/em&gt; for almost three months and I'm not consider myself a pro (nor even a begginer) but during this time I have been able to learn &lt;strong&gt;some basic concepts&lt;/strong&gt; to create stunning scenes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ok but, what is Three.js? 🎄
&lt;/h2&gt;

&lt;p&gt;To be clear, &lt;a href="https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-scene" rel="noopener noreferrer"&gt;Three.js&lt;/a&gt; is a JavaScript library to render graphics in a browser that uses WebGL.&lt;/p&gt;

&lt;p&gt;It has a lot of possibilities but with &lt;em&gt;Three.js&lt;/em&gt; you need to &lt;strong&gt;imperative set all the steps&lt;/strong&gt; to your application such as creacte a camera, create a scene, then put this camera into this scene... you got the concept.&lt;/p&gt;

&lt;p&gt;Because of this, many libraries emerged with the aim of using &lt;em&gt;Three.js&lt;/em&gt; inside a framework. I have tried &lt;a href="https://github.com/nartc/angular-three" rel="noopener noreferrer"&gt;Angular Three&lt;/a&gt; and &lt;a href="https://github.com/troisjs/trois" rel="noopener noreferrer"&gt;Trois.js&lt;/a&gt; for Vue but I prefer &lt;strong&gt;React Three Fiber&lt;/strong&gt; because of its large community, examples and documentation but feel free to give a try to the other ones.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, you said React Three Fiber... ⚗
&lt;/h2&gt;

&lt;p&gt;Exactly, as I said before, R3F gives you a &lt;a href="https://docs.pmnd.rs/react-three-fiber/getting-started/introduction" rel="noopener noreferrer"&gt;good documentation&lt;/a&gt;, a wide &lt;a href="https://docs.pmnd.rs/react-three-fiber/getting-started/examples" rel="noopener noreferrer"&gt;variety of examples&lt;/a&gt; and a very active community.&lt;/p&gt;

&lt;p&gt;There are also many &lt;strong&gt;YouTube tutorials&lt;/strong&gt; to give your knowledge to the next level and the creator of the library, &lt;a href="https://twitter.com/0xca0a" rel="noopener noreferrer"&gt;Paul Henschel&lt;/a&gt; is very active on Twitter.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;advantage&lt;/strong&gt; of this library as well as the others for Angular or Vue is that you only need to declare a component and the magic happen behind the scenes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Concepts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The Mesh 🎨
&lt;/h3&gt;

&lt;p&gt;Probably the most important concept you need to know is &lt;strong&gt;the mesh&lt;/strong&gt; which is a combination of a &lt;strong&gt;geometry and a material&lt;/strong&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;mesh&lt;/span&gt; &lt;span class="nx"&gt;position&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;boxGeometry&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;meshStandardMaterial&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;yellow&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/mesh&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Other important things 🎇
&lt;/h3&gt;

&lt;p&gt;Meshes are only the beginning, but to create a scene you need several components. Here are some of the (important ones), but you can check &lt;a href="https://docs.pmnd.rs/react-three-fiber/getting-started/your-first-scene" rel="noopener noreferrer"&gt;the official R3F documentation&lt;/a&gt; to know more about them.&lt;/p&gt;

&lt;p&gt;There are &lt;a href="https://threejs.org/docs/index.html#api/en/materials/MeshBasicMaterial" rel="noopener noreferrer"&gt;many materials&lt;/a&gt; each of them with its own parameters. Along with the meshes, there are also some &lt;strong&gt;geometries&lt;/strong&gt; that you can use in your scenes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Canvas&lt;/code&gt;. This component will setup the &lt;strong&gt;Scene&lt;/strong&gt; and the &lt;strong&gt;Camera&lt;/strong&gt; and also render the scene every frame.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Lights&lt;/code&gt;. Obviously to be able to see the scene and &lt;strong&gt;cast shadows&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  It's time to coding 💻
&lt;/h2&gt;

&lt;p&gt;The entire code of the project is in my GitHub account, just below.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/jgcarrillo" rel="noopener noreferrer"&gt;
        jgcarrillo
      &lt;/a&gt; / &lt;a href="https://github.com/jgcarrillo/react-fp-movement" rel="noopener noreferrer"&gt;
        react-fp-movement
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Basic scene with geometries and gLTF models to control a character in first person camera
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/1dc0e4b9031b59393a3d9b82a1df79ecaf0a8df5b83ef7633b0eabfadb178801/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6a6763617272696c6c6f2f72656163742d66702d6d6f76656d656e74"&gt;&lt;img src="https://camo.githubusercontent.com/1dc0e4b9031b59393a3d9b82a1df79ecaf0a8df5b83ef7633b0eabfadb178801/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6a6763617272696c6c6f2f72656163742d66702d6d6f76656d656e74" alt="GitHub stars"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/a3a39207103d1b994b452812865391e78dd559100ba7ec06e5a32dd8356f452d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6a6763617272696c6c6f2f72656163742d66702d6d6f76656d656e74"&gt;&lt;img src="https://camo.githubusercontent.com/a3a39207103d1b994b452812865391e78dd559100ba7ec06e5a32dd8356f452d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6a6763617272696c6c6f2f72656163742d66702d6d6f76656d656e74" alt="GitHub issues"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/cafb4753b8ebef3f4978694c66ed4a2bdef69a3771d466641a9c474d091d16f2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6a6763617272696c6c6f2f72656163742d66702d6d6f76656d656e74"&gt;&lt;img src="https://camo.githubusercontent.com/cafb4753b8ebef3f4978694c66ed4a2bdef69a3771d466641a9c474d091d16f2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6a6763617272696c6c6f2f72656163742d66702d6d6f76656d656e74" alt="GitHub forks"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/64fd1376407134c90f2506b17606b8b80de65d15aa097c9e9cf921ce2fdbff3d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f6a6763617272696c6c6f2f72656163742d66702d6d6f76656d656e74"&gt;&lt;img src="https://camo.githubusercontent.com/64fd1376407134c90f2506b17606b8b80de65d15aa097c9e9cf921ce2fdbff3d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f6a6763617272696c6c6f2f72656163742d66702d6d6f76656d656e74" alt="GitHub PRs"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Table of contents 👇&lt;/h2&gt;
&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/jgcarrillo/react-fp-movement#-motivation" rel="noopener noreferrer"&gt;✨ Motivation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jgcarrillo/react-fp-movement#-technologies" rel="noopener noreferrer"&gt;🚩 Technologies&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jgcarrillo/react-fp-movement#-project-structure" rel="noopener noreferrer"&gt;🕸️ Project Structure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jgcarrillo/react-fp-movement#-basic-explanation" rel="noopener noreferrer"&gt;🚀 Basic Explanation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jgcarrillo/react-fp-movement#-contact" rel="noopener noreferrer"&gt;🌎 Contact&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;✨ Motivation&lt;/h2&gt;
&lt;/div&gt;

&lt;p&gt;A few months ago I started to working with &lt;strong&gt;React Three Fiber&lt;/strong&gt;. I was impressed with the possibilities the library gives to you to create 3D environments. I saw a wide variety of examples in &lt;a href="https://docs.pmnd.rs/react-three-fiber/getting-started/examples" rel="nofollow noopener noreferrer"&gt;R3F website&lt;/a&gt; so I started to explore more about the project.&lt;/p&gt;

&lt;p&gt;There are so many good examples out there, but I get motivated with some of them, for example, a &lt;a href="https://codesandbox.io/s/ping-pong-0mgum" rel="nofollow noopener noreferrer"&gt;Ping Pong game&lt;/a&gt; or even a &lt;a href="https://codesandbox.io/s/arkanoid-under-60-loc-66cd7" rel="nofollow noopener noreferrer"&gt;simple Arkanoid clone&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Since that, I have working in so many pet projects to understand the &lt;em&gt;key concepts&lt;/em&gt; of React Three Fiber and also &lt;strong&gt;Three.js&lt;/strong&gt;. I don't consider myself a R3F pro, nor even a beginner, but now I feel confident about the fact that I can create such 3D scenarios.&lt;/p&gt;

&lt;p&gt;I started creating basic &lt;strong&gt;isometric scenes&lt;/strong&gt;…&lt;/p&gt;
&lt;/div&gt;


&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/jgcarrillo/react-fp-movement" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


&lt;p&gt;First of all we need to create a &lt;strong&gt;React project&lt;/strong&gt; from scratch with the classic &lt;code&gt;npx create-react-app&lt;/code&gt; you can use &lt;em&gt;Vite&lt;/em&gt; if you prefer.&lt;/p&gt;

&lt;p&gt;I'am using the &lt;strong&gt;following folder structure&lt;/strong&gt; to organize my projects but you can use another.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2p9pxeob7bfb0tu4boy5.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2p9pxeob7bfb0tu4boy5.JPG" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To be clear, I'm going to explain everyone of them. Probably you can create your own code in the same file but we want to take advantage of the React library to &lt;strong&gt;reuse components&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Floor.js&lt;/code&gt;. It's a basic geometry of a &lt;em&gt;Plane&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Lights.js&lt;/code&gt;. This component generate some lights for our meshes to be displayed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ThreeModel.js&lt;/code&gt;. With this component we can generate a React compoment from a 3D model created with Blender or similar.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;BaseBox.js&lt;/code&gt;. Used to generate a basic box geometry.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;BaseCharacter.js&lt;/code&gt;. This component generates a sphere geometry with movement.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;BaseScene.js&lt;/code&gt;. Using this component we can create a basic Three.js scene. Through props we can insert our custom scene with the same parameters.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;helpers.js&lt;/code&gt;. Some important functions, for example, the character movement.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the next part we will continue with the example by &lt;strong&gt;making the real scene&lt;/strong&gt; and explaining some concepts like physics. 🚀&lt;/p&gt;

</description>
      <category>react</category>
      <category>tutorial</category>
      <category>reactthreefiber</category>
      <category>threejs</category>
    </item>
    <item>
      <title>Improving your Productivity with VIM (+ VS Code Shortcuts)</title>
      <dc:creator>Jorge Gómez 👨‍💻🚀 </dc:creator>
      <pubDate>Thu, 24 Sep 2020 05:58:16 +0000</pubDate>
      <link>https://forem.com/jgcarrillo/improving-your-productivity-with-vim-vs-code-shortcuts-12a4</link>
      <guid>https://forem.com/jgcarrillo/improving-your-productivity-with-vim-vs-code-shortcuts-12a4</guid>
      <description>&lt;p&gt;When my peers see me writing code they think I'm possessed by some kind of dark forze which drives me to use a series of &lt;em&gt;strange shortcuts&lt;/em&gt; for them. The reality is that, with practice, I have gained a great ability to put the mouse aside.&lt;/p&gt;

&lt;p&gt;But, to be honest, &lt;strong&gt;the path was hard&lt;/strong&gt;. The vas majority Vim's gurus uses such a great amount of shortcuts, macros, and patterns that shocked me out.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Basics
&lt;/h2&gt;

&lt;p&gt;That's the entry point of this post, bring you a series of &lt;strong&gt;most common&lt;/strong&gt; shortcurts that I use in my day to day as a web dev. Furthermore, there are also great shortcuts for VS Code that will take you to the next level.&lt;/p&gt;

&lt;h3&gt;
  
  
  Modes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;i&lt;/code&gt; -&amp;gt; For normal mode. In this mode you can &lt;em&gt;insert text before the cursor&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;esc&lt;/code&gt; -&amp;gt; Exit &lt;strong&gt;insert mode&lt;/strong&gt;. A fat cursor appears and you will able to move throught the document.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Ctrl+v&lt;/code&gt; -&amp;gt; Start visual mode (lines).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Ctrl+V&lt;/code&gt; -&amp;gt; Start visual mode (blocks).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Movement
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;h&lt;/code&gt; -&amp;gt; Left&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;j&lt;/code&gt; -&amp;gt; Down&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;k&lt;/code&gt; -&amp;gt; Up&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;l&lt;/code&gt; -&amp;gt; Right&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;0&lt;/code&gt; -&amp;gt; Jump to the start of the line&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;$&lt;/code&gt; -&amp;gt; Jump to the end of the line&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;G&lt;/code&gt; -&amp;gt; Go to the last line of the document&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;zz&lt;/code&gt; -&amp;gt; Go to the first line of the document&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Exiting
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;:q!&lt;/code&gt; -&amp;gt; Quit and throw away unsaved changes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:wq&lt;/code&gt; -&amp;gt; Write (save) and quit.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Most used shortcuts (for me)
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Insert text
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;I&lt;/code&gt; -&amp;gt; Insert at the beginning of the line.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;A&lt;/code&gt; -&amp;gt; Insert (append) at the end of the line.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;o&lt;/code&gt; -&amp;gt; Append (open) a new line below the current line.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;O&lt;/code&gt; -&amp;gt; Append (open) a new line above the current line.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;gd&lt;/code&gt; -&amp;gt; Go to a definition (variable, function...).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;gf&lt;/code&gt; -&amp;gt; Go to a specifil file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Editing
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;r&lt;/code&gt; -&amp;gt; Replace a single character.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;x&lt;/code&gt; -&amp;gt; Delete characters.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;u&lt;/code&gt; -&amp;gt; Undo&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Ctrl+r&lt;/code&gt; -&amp;gt; Redo&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ciw&lt;/code&gt; -&amp;gt; Replace the entire word.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cc&lt;/code&gt; -&amp;gt; Replace the entire line&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Cut and paste
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;yy&lt;/code&gt; -&amp;gt; Copy a line.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;2yy&lt;/code&gt; -&amp;gt; Copy two lines.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;p&lt;/code&gt; -&amp;gt; Paste after cursor.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;P&lt;/code&gt; -&amp;gt; Paste before cursor.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dd&lt;/code&gt; -&amp;gt; Delete a line&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;d$&lt;/code&gt; -&amp;gt; Delete to the end of the line.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dw&lt;/code&gt; -&amp;gt; Delete the characters of the word from the cursor position to the start of the next word.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Pro commands
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;line-number + G&lt;/code&gt; -&amp;gt; Go to this line.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/search-term&lt;/code&gt; -&amp;gt; Search inside the code. Move witch &lt;code&gt;n&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;%&lt;/code&gt; -&amp;gt; Move to matching character ({}, []).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:/s/text-to-change/new-text/gc&lt;/code&gt; -&amp;gt; Replaces the indicated text with the new one throughout the document.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  VS Code
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Ctrl+n&lt;/code&gt; -&amp;gt; Move forward through options in a drop-down panel.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Ctrl+p&lt;/code&gt; -&amp;gt; Move backwards through options in a drop-down panel.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Alt+arrow keys&lt;/code&gt; -&amp;gt; Move the current line up or down.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Alt+Shift+arrow keys&lt;/code&gt; -&amp;gt; Copy the current line up or down.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope you will find it useful for your projects. Honestly in my case I have notably improved the way I write code 😉&lt;/p&gt;

&lt;p&gt;&lt;small&gt;&lt;em&gt;Cover photo by &lt;a href="https://unsplash.com/@nihongraphy?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;NihoNorway graphy&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/keyboard?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/small&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>learning</category>
      <category>vim</category>
    </item>
    <item>
      <title>12 Useful Resources for Junior Web Developers</title>
      <dc:creator>Jorge Gómez 👨‍💻🚀 </dc:creator>
      <pubDate>Wed, 16 Sep 2020 10:23:22 +0000</pubDate>
      <link>https://forem.com/jgcarrillo/8-useful-resources-for-junior-web-developers-12mp</link>
      <guid>https://forem.com/jgcarrillo/8-useful-resources-for-junior-web-developers-12mp</guid>
      <description>&lt;p&gt;Hi! My name is Jorge, I'm a junior web developer based in Spain. My &lt;em&gt;path&lt;/em&gt; started one year ago, when I decided to jump into my real dream as a web dev. I had previously programmed but I decided to take it seriously.&lt;/p&gt;

&lt;p&gt;A few months later, my skills was improved so far. 99.9% of &lt;em&gt;my improvement&lt;/em&gt; was thanks to a lot of resources I found on internet.&lt;/p&gt;

&lt;h2&gt;
  
  
  List of Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://app.diagrams.net"&gt;Diagrams&lt;/a&gt; | This is such a great web for draw a lot of &lt;strong&gt;diagrams&lt;/strong&gt; you need. I use it for my databases as long as I need to share with my peers.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://awwapp.com/#"&gt;Aww App&lt;/a&gt; | A useful &lt;strong&gt;whiteboard&lt;/strong&gt; for share your ideas. Perfect for collaborative drawing.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docusaurus.io/"&gt;Docusaurus&lt;/a&gt; | A good tool for maintain Open Source &lt;strong&gt;documentation websites&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://wweb.dev/resources/css-separator-generator"&gt;CSS Section Generator&lt;/a&gt; | If you want to take your website design to another level, this separator generator allows you to create different &lt;strong&gt;sections&lt;/strong&gt; for your web.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n6AihDr6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/khxno1051qfowekixjnh.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n6AihDr6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/khxno1051qfowekixjnh.PNG" alt="CSS Section Generator" width="880" height="158"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://gridbyexample.com/"&gt;Grid by example&lt;/a&gt; | The perfect place if you need to understand how &lt;strong&gt;grid layout&lt;/strong&gt; works.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://sweetalert.js.org/"&gt;Sweet Alerts&lt;/a&gt; | A beautiful tool for replacement &lt;strong&gt;alerts&lt;/strong&gt;. It's a

&lt;code&gt;npm pakage&lt;/code&gt;

so you need to install it as a dependencie.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LqfsiRPS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gxbd0n4x1hlawlekf8dk.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LqfsiRPS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gxbd0n4x1hlawlekf8dk.PNG" alt="Sweet Alerts" width="880" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://regexr.com/"&gt;Regular Expressions&lt;/a&gt; | For those who want yo &lt;strong&gt;learn&lt;/strong&gt;, build and test &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions"&gt;regular expressions&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://jsfiddle.net/"&gt;JSFiddle&lt;/a&gt; | If you need to test your code and you don't want to open VS Code, JSFiddle brings you the possibility to use an &lt;strong&gt;online&lt;/strong&gt; editor.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.toptal.com/developers/gitignore"&gt;Gitignore&lt;/a&gt; | Node modules? logs? Try this tool to autogenerate a &lt;em&gt;.gitignore&lt;/em&gt; file that includes all the directories and files you don't want to push into GitHub.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://carbon.now.sh/"&gt;Carbon&lt;/a&gt; | Since SnapCode (and Polacode) stopped working on VS Code, Carbon was my first choice for create and share &lt;strong&gt;images of my code&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fSqJ3spK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fzm65xudxr5ho2p4bqg8.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fSqJ3spK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fzm65xudxr5ho2p4bqg8.PNG" alt="Carbon" width="880" height="651"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://typora.io/"&gt;Typora&lt;/a&gt; | A minimal &lt;strong&gt;markdown&lt;/strong&gt; editor (free during beta version). &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.barbarianmeetscoding.com/blog/2019/02/08/boost-your-coding-fu-with-vscode-and-vim"&gt;Improving your Vim skills&lt;/a&gt; | That's an incredible-long post about &lt;strong&gt;Vim&lt;/strong&gt;. If you want learn vim as a pro, you need to check it out.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's was my first post here! so sorry if I made grammar mistakes. I hope you will find it interesting. Feel free to correct any mistakes I have made. 🙂&lt;/p&gt;

&lt;p&gt;&lt;small&gt;&lt;em&gt;Cover photo by &lt;a href="https://unsplash.com/@wocintechchat"&gt;Christina&lt;/a&gt; on &lt;a href="https://unsplash.com/@wocintechchat?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/small&gt;&lt;/p&gt;

</description>
      <category>useful</category>
      <category>resources</category>
      <category>list</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
