<?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 Máximo Fernández on Medium]]></title>
        <description><![CDATA[Stories by Máximo Fernández on Medium]]></description>
        <link>https://medium.com/@maxfarenas?source=rss-6003252c7068------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*892BFcVy310lFEhM4O0jQg.jpeg</url>
            <title>Stories by Máximo Fernández on Medium</title>
            <link>https://medium.com/@maxfarenas?source=rss-6003252c7068------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 15:17:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@maxfarenas/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[Building an interactive web portfolio with Vue + Three.js — Part Three: Implementing Three.js]]></title>
            <link>https://medium.com/nicasource/building-an-interactive-web-portfolio-with-vue-three-js-part-three-implementing-three-js-452cb375ef80?source=rss-6003252c7068------2</link>
            <guid isPermaLink="false">https://medium.com/p/452cb375ef80</guid>
            <category><![CDATA[portfolio]]></category>
            <category><![CDATA[3d]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[threejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Máximo Fernández]]></dc:creator>
            <pubDate>Thu, 21 Jul 2022 15:33:56 GMT</pubDate>
            <atom:updated>2022-07-21T15:45:35.363Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building an interactive web portfolio with Vue + Three.js — Part Three: Implementing Three.js</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SjBASeN6kVDl2ICGIyFafA.png" /></figure><p>This is the home stretch! We learned how to set up a Vue + SCSS project in the last two episodes.</p><ul><li><a href="https://medium.com/nicasource/building-an-interactive-web-portfolio-with-vue-three-js-part-one-introduction-and-setup-405426cec84">Building an interactive web portfolio with Vue + Three.js — Part One: Introduction and Setup</a></li><li><a href="https://medium.com/nicasource/building-an-interactive-web-portfolio-with-vue-three-js-part-two-vue-basics-12fcfc85e033">Building an interactive web portfolio with Vue + Three.js — Part Two: Vue Basics</a></li></ul><p>, and create a basic portfolio template. Now, it’s time to integrate Three.js into our project!</p><h3>But… What is Three.js?</h3><p>Three.js is a graphics API created with Web GL. It has <strong>countless features</strong>, but the most popular are the ones regarding 3D rendering. As I said earlier, Three.js is a High-level API for the WebGL engine, so luckily, you don’t need to be a math wizard to render a 10x10 cube.</p><p>In this article, we will create an interactive background for our site. But remember: this is just an example. Feel free to do your own thing while building it. Don’t exclusively stick to what I’m showcasing! It is <strong>your </strong>personal portfolio, after all.</p><h4>Installing Three.js</h4><p>The first thing to do is to download the required dependencies into our project.</p><pre>npm install three</pre><h4>Temporarily disabling Vue</h4><p>It’s best to start by disabling our Vue container, just for now. This way, we will be sure it won’t affect our Three.js code. Just go to your index.html file and comment on your #app div.</p><pre>index.html<br>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;&quot;&gt;<br> &lt;head&gt;<br>   &lt;meta charset=&quot;utf-8&quot; /&gt;<br>   &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot; /&gt;<br>   &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width,initial-scale=1.0&quot; /&gt;<br>   &lt;link rel=&quot;icon&quot; href=&quot;&lt;%= BASE_URL %&gt;favicon.ico&quot; /&gt;<br>   &lt;link rel=&quot;stylesheet&quot; href=&quot;./styles.css&quot;&gt;<br>   &lt;title&gt;&lt;%= htmlWebpackPlugin.options.title %&gt;&lt;/title&gt;<br> &lt;/head&gt;<br> &lt;body&gt;<br>   &lt;!-- &lt;div id=&quot;app&quot;&gt;&lt;/div&gt; --&gt;<br> &lt;/body&gt;<br>&lt;/html&gt;</pre><h3>Structuring our project</h3><p>This guide is based on <a href="https://discoverthreejs.com/">this</a> fantastic manual. “Discover Three.js” is a perfect resource for anyone who wants to get started with this library. But it’s best suited for vanilla JS projects, so I’ll modify it here and there to explain how to set it up with Vue.</p><p>Inside our source folder, we will create a “World” folder. This is where <em>all</em> our Three.js-related code will be placed. Inside it, we will create two folders and one file:</p><p><strong>Components: </strong>Like with Vue, we will store all reusable elements here. Objects, cameras, scenes… We’ll go through them one by one later on.</p><p><strong>Systems:</strong> Here, we save the different systems in our 3D render. In our case, those things are the animation loop, the resizer, the renderer, and the controls.</p><p><strong>World.js: </strong>Here’s where the magic happens. The World.js file is where all the different systems and components are connected and introduced into the HTML.</p><p>In the end, you should have a folder structure similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/0*3yODXBFkWL_-uCah" /></figure><p>Now it’s time to get down to business! Sadly, making a 3D scene requires a lot of boilerplate. So we’ll have to write several lines of code before seeing anything. But don’t worry! Remember: patience is a <em>virtue!</em> 😎</p><h3>Making our Systems</h3><h4>Creating the Renderer</h4><p>Not much to say here. The renderer is, as you may have guessed, what <em>renders </em>everything. We’ll be using WebGL.</p><pre>renderer.js<br>import { WebGLRenderer } from &quot;three&quot;;<br> <br>function createRenderer() {<br> const renderer = new WebGLRenderer({ antialias: true });<br> <br> // Turn on the physically correct lighting model.<br> renderer.physicallyCorrectLights = true;<br> <br> return renderer;<br>}<br> <br>export { createRenderer };</pre><h4>Creating the Resizer</h4><p>The resizer is a crucial element in our project. It handles the resizing window events, which allows us to make our scenes responsive!</p><pre>Resizer.js<br>const setSize = (container, camera, renderer) =&gt; {<br>   camera.aspect = window.innerWidth / window.innerHeight;<br>   camera.updateProjectionMatrix();<br>    renderer.setSize(window.innerWidth, window.innerHeight);<br>   renderer.setPixelRatio(window.devicePixelRatio);<br> };<br>  class Resizer {<br>   constructor(container, camera, renderer) {<br>     // Set initial size on load.<br>     setSize(container, camera, renderer);<br>      window.addEventListener(&#39;resize&#39;, () =&gt; {<br>       // Set the size again if a resize occurs.<br>       setSize(container, camera, renderer);<br>       // Perform any custom actions.<br>       this.onResize();<br>     });<br>   }<br>    onResize() {}<br> }<br>  export { Resizer };</pre><h4>Creating the Animation Loop</h4><p>We’ll be making our loop as a class. The animation loop is what gives “life” to our scene. It allows us to animate different elements at once. It has four properties: a camera, a scene, a renderer, and an updatable array where we must push the elements we want to animate. We also have three methods: the start and stop, which, surprisingly, start and stop our loop, and the <em>tick</em> methods. And this one is pretty important: the tick method will run once for every frame of our animation, which <strong>updates</strong> the positioning of our objects, making it possible to animate!</p><p>All this is possible thanks to the <em>Clock</em> object from Three, which allows us to get the current <em>delta</em>: the time difference between the current frame and the last one.</p><pre>Loop.js<br>import { Clock } from &#39;three&#39;;<br> <br>const clock = new Clock();<br> <br> <br>class Loop {<br> constructor(camera, scene, renderer) {<br>   this.camera = camera;<br>   this.scene = scene;<br>   this.renderer = renderer;<br>   this.updatables = [];<br> }<br> <br> start() {<br>   this.renderer.setAnimationLoop(() =&gt; {<br>       this.tick();<br>       // render a frame<br>       this.renderer.render(this.scene, this.camera);<br>   });<br> }<br> <br> stop() {<br>   this.renderer.setAnimationLoop(null);<br> }<br> <br> tick() {<br>   const delta = clock.getDelta();<br>   for (const object of this.updatables) {<br>       object.tick(delta);<br>   }<br> }<br>}<br> <br>export { Loop }</pre><h3>Making our scene</h3><p>We’ll create our scene step by step, file by file, to make our project as modular as possible. Working with Three.js can get messy fast if you are not careful. So it’s best to keep our code clean and organized. Each of these modules will be able to export a function that generates a new instance of something. This will allow us to give them arguments and have several cases, such as lights or objects.</p><h4>Creating the Camera</h4><p>With the camera, we can see and manipulate the point of view of our scene that we want our users to have. We’ll use a Perspective camera, the closest thing to a real-life camera Three.js has, with no distortions.</p><pre>camera.js<br>import { PerspectiveCamera } from &#39;three&#39;;<br> <br>function createCamera() {<br> const camera = new PerspectiveCamera(<br>   35, // FOV = Field Of View<br>   1, // Aspect ratio (dummy value)<br>   0.1, // Near clipping plane<br>   100, // Far clipping plane<br> );<br> <br> // Move the camera back so we can view the scene<br> //      x y  z<br> camera.position.set(0, 0, 10);<br> camera.tick = (delta) =&gt; {<br>  <br> };<br> <br> return camera;<br>}<br> <br>export { createCamera };</pre><p>We can configure the field of the camera’s view, the initial position, and several different parameters with simple numerical variables. Easy, right?</p><p>As you will see, all of these components have a tick function, which allows them to communicate with the animation loop if necessary!</p><h4>Creating the Lights</h4><p>Controlling the light is not that different, but here we have more options to choose: from the directional, hemisphere, and point light. Let’s keep it simple for now and import a directional light. You can think of this light as the sun’s light: it shines everything from a unique point in space.</p><pre>lights.js<br>import {<br>   DirectionalLight,<br>   DirectionalLightHelper,<br> } from &quot;three&quot;;<br>  function createLights(color) {<br>   const light = new DirectionalLight(color, 4);<br>   const lightHelper = new DirectionalLightHelper(light, 0);<br>   light.position.set(0, 0, 5);<br>    light.tick = (delta) =&gt; {<br>   <br>   };<br>    return { light, lightHelper };<br> }<br>  export { createLights };</pre><p>Just like with the camera, we can set a position for the light, but this time we can also get a light color as an argument!</p><p>In this case, we return two objects: the proper light and an optional light helper that allows us to see where the light is and where it is pointing.</p><h4>Creating the Scene</h4><p>A scene is a place where everything will be rendered. Here is where you can see everything and what the camera will show the user.</p><pre>scene.js<br>import { Color, Scene } from &#39;three&#39;;<br> <br>function createScene(color) {<br> const scene = new Scene();<br> <br> scene.background = new Color(color);<br> <br> return scene;<br>}<br> <br>export { createScene };</pre><p>Like the lights, we have a color argument, but this time it refers to the scene’s background color.</p><h3>Making sure everything’s working correctly</h3><p>Okay, we have written a whole lot of code. I think we should check if everything is working correctly by actually rendering something.</p><h4>Updating World.js</h4><p>Now it’s time to import everything we created and add it to our World.js file!</p><pre>World.js<br>import { createCamera } from &quot;./components/camera.js&quot;;<br>import { createLights } from &quot;./components/lights.js&quot;;<br>import { createScene } from &quot;./components/scene.js&quot;;<br>import { createRenderer } from &quot;./systems/renderer.js&quot;;<br>import { Loop } from &quot;./systems/Loop.js&quot;;<br>import { Resizer } from &quot;./systems/Resizer.js&quot;;<br> <br>// These variables are module-scoped: we cannot access them<br>// from outside the module.<br>let camera;<br>let renderer;<br>let scene;<br>let loop;<br> <br>class World {<br>   constructor(container) {<br>     // Instances of camera, scene, and renderer<br>     camera = createCamera();<br>     scene = createScene(&quot;blue&quot;);<br>     renderer = createRenderer();<br>      // Initialize Loop<br>     loop = new Loop(camera, scene, renderer);<br>      container.append(renderer.domElement);<br>      // Light Instance, with optional light helper<br>     const { light, lightHelper } = createLights(&quot;white&quot;);<br>      loop.updatables.push(light);<br>      scene.add(light);<br> <br>     const resizer = new Resizer(container, camera, renderer);<br>      resizer.onResize = () =&gt; {<br>      this.render();<br>     };<br> <br>    }<br>    render() {<br>     // Draw a single frame<br>     renderer.render(scene, camera);<br>   }<br>    // Animation handlers<br>   start() {<br>     loop.start();<br>   }<br>    stop() {<br>     loop.stop();<br>   }<br> }<br>  export { World };</pre><p>Our World-class accepts a “container” parameter. This is the HTML element where our Three.js will be rendered.</p><h4>Updating our HTML and main.js</h4><p>Now, in our index.html, we have to add our container where the canvas will be inserted.</p><pre>index.html<br>&lt;div id=&quot;scene-container&quot;&gt;<br>     &lt;!-- Three.js canvas will be inserted here --&gt;<br>&lt;/div&gt;</pre><p>And lastly, we need to call our World-class in our main.js file while also initializing our animation loop with the ‘start’ method.</p><pre>main.js<br>import { createApp } from &quot;vue&quot;;<br>import App from &quot;./App.vue&quot;;<br>import router from &quot;./router&quot;;<br>import { World } from &quot;./World/World.js&quot;;<br> <br>function main() {<br> // Get a reference to the container element<br> const container = document.querySelector(&quot;#scene-container&quot;);<br> <br> // Create an instance of the World app<br> const world = new World(container);<br> <br> // Start the loop (produce a stream of frames)<br> world.start();<br>}<br> <br>main();<br> <br>createApp(App).use(router).mount(&quot;#app&quot;);</pre><p>And if everything goes well, you should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eNNW9UfiyKGjvhu7" /></figure><p>Okay, I’m not going to lie: that <em>does</em> look pretty anticlimactic. But it works! As you may have noticed, I declared the scene with a blue background in our World.js. And this big blue blob is the actual 3d scene being rendered, with the animation loop running <em>frame by frame</em>! That’s quite the feat.</p><p>What I’d recommend doing now is to update the styles of the container to be fullscreen and to avoid overflow. Note that you’ll have to do a dedicated CSS file in the public folder for this. Something like this should do the trick:</p><pre>#scene-container {<br>   position: fixed;<br>   width: 100%;<br>   height: 100%;<br>   left: 0;<br>   top: 0;<br>}</pre><h3>Our first Render!</h3><p>Alright! Now that we have all that boilerplate code working, it’s time to <strong>render an object</strong>. We will make a moving terrain-like plane where the user can rotate the camera.</p><h4>Rendering the plane</h4><p>You might remember I created an empty “objects “folder inside our components folder. Here’s where all your 3D figures will be stored. In this post, I’ll show you how to make a plane, but if you ever want to dive deeper and render different figures, you should make them here.</p><pre>terrain.js<br>import {<br> PlaneBufferGeometry,<br> MeshStandardMaterial,<br> Mesh,<br> TextureLoader,<br>} from &quot;three&quot;;<br> <br>export default function createTerrain(props) {<br> const loader = new TextureLoader();<br> const height = loader.load(&quot;textures/height.png&quot;);<br> //                                        w    h <br> const geometry = new PlaneBufferGeometry(150, 150, 64, 64);<br> <br> const material = new MeshStandardMaterial({<br>   color: props.color,<br> });<br> <br> <br> <br> const plane = new Mesh(geometry, material);<br> plane.position.set(0, 0, 0);<br> plane.rotation.x -= Math.PI * 0.35;<br> <br> let frame = 0;<br> plane.tick = (delta) =&gt; {<br> <br> };<br> <br> return plane;<br>}</pre><p>To render a 3D object, we need quite a lot of things. But these are the three most important:</p><p><strong>Geometry</strong>: These are all the vertices that make our object. It will define its shape. Three.js has different types of geometries for cubes, spheres, and more. We’ll be using the “plane” geometry for our project. We can change the size of our geometry by changing the numbers passed to the element.</p><p><strong>Material</strong>: This is what gives our object a surface. Again, we have several different material styles, but let’s keep it simple and use the ‘Standard Material.’ This is a pretty good option because it can react to light. It accepts an object as a parameter, with several customization options. We will pass a color variable here, just like for the scene’s background.</p><p><strong>Mesh:</strong> is the most used way of visualizing three-dimensional objects on a computer. A mesh is composed of geometry and material, and this is our actual 3D object.</p><p>We’ll rotate our mesh; this way, it will be easier to notice it in the scene.</p><p>We have to add the terrain to the World.js file, just like we did with all the other elements. Remember to add it to the loop updateable and the scene!</p><pre>World.js<br>   ...<br>   let terrain = createTerrain({<br>     color: color,<br>   });<br> <br>   loop.updatables.push(light);<br>   loop.updatables.push(terrain);<br> <br>   scene.add(light, terrain);<br>   ...</pre><p>You can also create some global color variables to make the palette easier to switch. I chose some green shades to keep that Vue style.</p><p>When updated, you should see your plane being rendered! It might not look three-dimensional at first glance, but try changing the rotation of the plane, and you’ll see that it is a 3D object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kesExho9a7swXDHx" /></figure><h3>Spicing up our plane geometry</h3><p>So, you just rendered your first 3D object. Well done! But it’s a bit bland. You can’t even notice the 3D awesomeness. We’ll give it a displacement map and animation to make it look like a voxel alien world.</p><h4>Updating World.js</h4><p>We’ll create an array of random values that will dictate how each vertex in our plane will move.</p><pre>World.js<br>   // Random values for terrain vertices<br>   const randomVals = [];<br> <br>   for (let i = 0; i &lt; 12675; i++) {<br>     randomVals.push(Math.random() - 0.5);<br>   }<br> <br>   // Terrain Instance<br>   let terrain = createTerrain({<br>     color: color,<br>     randVertexArr: randomVals,<br>   });</pre><p>As you saw on the declaration of our plane, our function accepts a ‘props’ argument, which is an object. That means we can pass as many opinions as we want! We’ll pass the values array, so we can use it to manipulate our geometry.</p><h4>Adding texture to our plane</h4><p>Now let’s make our plane, well, <em>less plane</em>. First, we have to update our “Mesh Material.” We’ll add a displacement scale and a map. The displacement map is a grayscale texture that Three.js uses as a guide and elevates each vertex depending on how bright that pixel is on the image. The scale is simply a multiplier; the bigger it is, the more pronounced the displacement will be. Optionally, we can also enable flat shading, giving our terrain a retro lighting style.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*SVpDQKNUN-QnS5bF" /><figcaption><em>Example of a displacement map.</em></figcaption></figure><pre>terrain.js <br> const loader = new TextureLoader();<br> const height = loader.load(&quot;textures/height.png&quot;);<br> ...<br> const material = new MeshStandardMaterial({<br>   color: props.color,<br>   flatShading: true,<br>   displacementMap: height,<br>   displacementScale: 5,<br> });</pre><p><em>Pro-tip: Save your texture images inside your public folder! Three.js won’t recognize them in the source folder.</em></p><p>You should already be able to see your terrain!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8mXgpl0KIilF_OYo" /></figure><h4>Animating the terrain</h4><p>Okay, this part is a little tricky. We will use random numbers and initial vertex position arrays to move all our vertices on the y axis. Then we will animate it using cosine waves to make a controlled motion. I’ll explain the code with some comments:</p><pre>World.js<br>   // Random values for terrain vertices<br>   // We could do this on the terrain.js file,<br>   // but if we want to have a single random<br>   // number array for more than one terrain<br>   // instance, then we would be in trouble.<br>   const randomVals = [];<br>   for (let i = 0; i &lt; 12675; i++) {<br>     randomVals.push(Math.random() - 0.5);<br>   }<br> <br>   // Terrain Instance<br>   let terrain = createTerrain({<br>     color: color,<br>     randVertexArr: randomVals,<br>   });<br>terrain.js<br>const plane = new Mesh(geometry, material);<br> plane.position.set(0, 0, 0);<br> plane.rotation.x -= Math.PI * 0.35;<br>  // Storing our original vertices position on a new attribute<br> plane.geometry.attributes.position.originalPosition =<br>   plane.geometry.attributes.position.array;<br> // Utilizing our random number array<br> const { array } = plane.geometry.attributes.position;<br> for (let i = 0; i &lt; array.length; i++) {<br>   props.randVertexArr.push(Math.random());<br> }<br> <br> plane.geometry.attributes.position.randomValues = props.randVertexArr;<br> <br> let frame = 0;<br> plane.tick = (delta) =&gt; {<br>   frame += 0.01;<br>   // Destructuring of the random values, the original position and the current vertex position<br>   const { array, originalPosition, randomValues } =  plane.geometry.attributes.position;<br> <br>   // Animation for loop<br>   // In our vertex array, we have 3 coordinates: x, y and z. We are<br>   // going to animate on ONE coordinate only: the z coordinate.<br>   // This means we have to omit the x and y coords, hence the i+=3 in our loop.<br>   // Also, to access that y coordinate on each vertex, we have to add 2 to our<br>   // current i each time.<br>   for (let i = 0; i &lt; array.length; i += 3) {<br>     // Accessing the z coord<br>     array[i + 2] =<br>       // Try switching these numbers up, or using sine instead of cosine, see how the animation changes.<br>       originalPosition[i + 2] + Math.cos(frame + randomValues[i + 2]) * 0.002;<br>   }<br>   plane.geometry.attributes.position.needsUpdate = true;<br> };</pre><p>And voila! Your terrain is moving!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*Rkj-nwR99aNLi4E1" /></figure><p>As you can see, it’s a pretty subtle effect. It’s more noticeable in bigger sizes. In any case, you can change the terrain animation loop variables to have a more substantial impact.</p><h3>Optional features</h3><p>Okay! We did <em>a lot</em> in this post. But we can still touch it up a little bit and make our scene even better! I have two more features for you to try:</p><h4>Background fog</h4><p>Trying to hide the end of our plane is not a bad idea. We could stretch it and make it bigger, but that’s not the best solution. First, because it will also stretch our height map, which will make the displacement effect softer and harder to notice (maybe you like that look, though!), and secondly, it will be harder to render on lower-end machines.</p><p>Luckily, Three.js is back to the rescue. We can add <em>fog</em> to the scene with just some new lines of code. You can also select the fog’s color and intensity.</p><pre>scene.js<br>import { Color, Scene, Fog } from &quot;three&quot;;<br> <br>function createScene(color) {<br> const scene = new Scene();<br> <br> scene.background = new Color(color);<br> <br>   scene.fog = new Fog(color, 50, 90);<br> <br> return scene;<br>}<br> <br>export { createScene };</pre><h4>Rotation and orbit controls</h4><p>Another great pre-built tool is the “Orbit Controls”! This lets us rotate and pan our camera with ease. It also comes with an auto-rotate feature, which we will be implementing. We’ll first make a new controls.js file in our systems folder.</p><pre>controls.js<br>import { OrbitControls } from &quot;three/examples/jsm/controls/OrbitControls.js&quot;;<br>import { MathUtils } from &quot;three&quot;;<br> <br>function createControls(camera, canvas) {<br> const controls = new OrbitControls(camera, canvas);<br> <br> // Enable controls?<br> controls.enabled = true;<br> controls.autoRotate = true;<br> controls.autoRotateSpeed = 0.2;<br> <br> // Control limits<br> // It&#39;s recommended to set some control boundaries<br> // to prevent the user from clipping with the objects.<br> <br> // Y axis<br> controls.minPolarAngle = MathUtils.degToRad(40); // default<br> controls.maxPolarAngle = MathUtils.degToRad(75);<br> <br> // X axis<br> //   controls.minAzimuthAngle = ...<br> //   controls.maxAzimuthAngle = ...<br> <br> // Smooth camera:<br> // Remember to add to loop updatables to work.<br> controls.enableDamping = true;<br> controls.enableZoom = false;<br> controls.enablePan = false;<br> <br> controls.tick = () =&gt; controls.update();<br> <br> return controls;<br>}<br> <br>export { createControls };</pre><p>Then, it’s time to add it to our World.js, just like any other element in our project. Remember to add it to the loop updatables if you want to enable damping.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*nGufgC9dy_b89SDS" /></figure><p>You’ll also want to tweak your camera and light position and your initial terrain rotation if you’re going to have a better view angle.</p><p>I switched mine to these values for this screenshot:</p><pre><strong>Lights</strong>: light.position.set(0, 30, 30);<br><strong>Camera</strong>: camera.position.set(0, 10, 30);<br><strong>Terrain</strong>: plane.rotation.x -= Math.PI * 0.5;</pre><h3>Enabling Vue and keeping the mouse rotation</h3><p>The last part of the project! Now we have to re-enable Vue. Just uncomment the #app div on your HTML, and that’s it… Right? Well, yes and <em>no</em>. Because even though our 3D background still works perfectly, the Vue elements on top of our background will “steal” all the mouse click events, and therefore the orbit controls won’t be allowed to work.</p><p>The solution I’ve come up with is to disable the click events where needed. And that sounds like a chore, but it’s not! With a simple SCSS mixin, we’ll be good to go:</p><pre>mixins.scss<br>@mixin child-events-on($debug: false) {<br>   &amp; &gt; * {<br>       @if $debug {<br>           background: red;<br>       }<br>       pointer-events: all;<br>   }<br> <br>   @content;<br>}</pre><p>This mixin will enable all pointer-events <strong>only</strong> on the container’s children. You can enable the debugging mode. It will give a red background to all the elements with pointer-events enabled.</p><p>Now, we globally disable pointer-events on the #app, and we can enable them on the containers we want by including the mixin: for example, our nav. In the end, your App.vue should look like this:</p><pre>App.vue<br>&lt;style lang=&quot;scss&quot;&gt;<br>#app {<br> position: relative;<br> padding: 0px auto;<br> padding: 0px 2vw;<br> z-index: 2;<br> pointer-events: none;<br> @include desktop {<br>   padding: 0px 10vw;<br> }<br>}<br> <br>#nav {<br> padding: 30px;<br> text-align: center;<br> @include child-events-on();<br> a {<br>   font-weight: bold;<br>   color: $text-color;<br> <br>   &amp;.router-link-exact-active {<br>     color: $active-link;<br>   }<br> }<br>}<br>&lt;/style&gt;</pre><p><em>Pro-tip: Remember to update the #app z-index and the position to be on top of the background.</em></p><p>And, at last, our 3D Portfolio is finally ready!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*mjSIT96tAF9zip-P" /></figure><h3>Conclusion and next steps</h3><p>What a ride! We’ve created a web portfolio and made it unique by having a randomly-generated animation for our 3D background. We’ve also improved our developer experience by implementing Vue, which helps us make our code modular and clean, and SCSS, which will save us tons of time while writing our CSS.</p><p>Now it’s time to add some personality! I made this example quite bland on purpose. If you want your Portfolio to stand out, you have to think of something more unique. Maybe change the font and the color palette. Or you could change the heightmap texture and the animation strength to convey a different effect. Or just scratch the whole terrain altogether and try something completely new. You can check <a href="https://max-fer.vercel.app/">my own Portfolio</a> to see a very different approach to practically the same idea. In any case, the best place to start is the <a href="https://threejs.org/docs/">Three.js’ docs</a>, and the <a href="https://threejs.org/">homepage</a> for some inspiration.</p><p>If you want to tinker with this example project, <a href="https://github.com/maxfer03/vue-three-ns">here’s the repo</a>. Or check out my <a href="https://github.com/maxfer03/vue-three-starter">Vue + Three.js starter</a> to make something different.</p><p>Don’t forget to deploy your Portfolio, too! So others can see your amazing 3D scenes 😎</p><h3>Resources used in this series and recommended reads</h3><ul><li><a href="https://vuejs.org/">Vue</a></li><li><a href="https://sass-lang.com/">SCSS</a></li><li><a href="https://threejs.org/">Three.js</a></li><li><a href="https://discoverthreejs.com/">Discover Three.js</a></li><li><a href="https://www.youtube.com/watch?v=YK1Sw_hnm58">Three.js Crash Course</a></li><li><a href="https://www.youtube.com/watch?v=2AQLMZwQpDo">Three.js Displacement map example</a></li><li><a href="https://github.com/maxfer03/vue-three-starter">Vue + Three.js starter</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=452cb375ef80" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nicasource/building-an-interactive-web-portfolio-with-vue-three-js-part-three-implementing-three-js-452cb375ef80">Building an interactive web portfolio with Vue + Three.js — Part Three: Implementing Three.js</a> was originally published in <a href="https://medium.com/nicasource">NicaSource</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an interactive web portfolio with Vue + Three.js — Part Two: Vue Basics]]></title>
            <link>https://medium.com/nicasource/building-an-interactive-web-portfolio-with-vue-three-js-part-two-vue-basics-12fcfc85e033?source=rss-6003252c7068------2</link>
            <guid isPermaLink="false">https://medium.com/p/12fcfc85e033</guid>
            <category><![CDATA[portfolio]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[vue]]></category>
            <dc:creator><![CDATA[Máximo Fernández]]></dc:creator>
            <pubDate>Thu, 07 Jul 2022 19:51:52 GMT</pubDate>
            <atom:updated>2023-06-12T12:32:08.994Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building an interactive web portfolio with Vue + Three.js — Part Two: Vue Basics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gdd_stw1U8PiSlzk-UspBQ.png" /></figure><p>In the previous section, we initialized our Vue Project. If you haven’t got the chance to read it, go check it out, it has the initial setup required. 👇</p><p><a href="https://medium.com/nicasource/building-an-interactive-web-portfolio-with-vue-three-js-part-one-introduction-and-setup-405426cec84">Building an interactive web portfolio with Vue + Three.js — Part One: Introduction and Setup</a></p><p>Now It’s time to use Vue and learn how we can structure our webpage with reusable components and keep our code tidy and clean.</p><h3>Why Vue instead of React or Angular?</h3><p>Cutting things short: because it’s simpler.</p><p>Vue is a fantastic JavasScript framework that works great for small and big projects. Whereas frameworks like React or Angular are more suitable for bigger enterprise applications.</p><p>Remember: we’re just making a personal portfolio, no need for overkill setups! If you have used React or Angular before, you’ll feel right at home using Vue. 😉</p><h3>What is a component?</h3><p>A component is a file that contains code that can be reused with ease. One of the most significant advantages of using web frameworks is that they let us encapsulate our code in smaller, easier-to-read, easier-to-debug components with no hassle.</p><p>A Vue component consists of <strong>three</strong> sections:</p><p><strong>Template</strong>: Here is where you write your HTML. In Vue, you can also embed code into the HTML by wrapping it in double curly braces:</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    {{1 + myVar}}<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><p><strong>Script: </strong>This is where you write your component logic. Most of the time, you’ll see a function, known as “data” that returns an object. This is where we can declare the initial reactive state for the component instance. You can send properties (called “props”) to this component. This data is sent as an HTML attribute when calling the component. There are also a whole lot of other things to do in this section but don’t worry; we’ll check them later.</p><pre>&lt;script&gt;<br>export default {<br> data(){<br>   return {<br>       myVar: 2<br>   }<br> }<br>}<br>&lt;/script&gt;</pre><p><strong>Style</strong>: The style section is where you define the CSS for your component. You can use CSS classes, inline styles, or even CSS preprocessors like Sass or Less. Vue provides a convenient way to scope your styles to the component using the “scoped” attribute. This means that the styles you define here will only apply to the elements within this component’s template. Also, you can add a &quot;lang&quot; attribute if you use sass or less.</p><pre>&lt;style scoped lang=&quot;scss&quot;&gt;<br>  .my-component {<br>    background-color: #f5f5f5;<br>    padding: 20px;<br>    border-radius: 4px;<br>  }<br><br>  h1 {<br>    color: #333333;<br>    font-size: 24px;<br>  }<br>&lt;/style&gt;</pre><h3>Structure of a Vue Project</h3><p>In the Source folder of our project, you’ll find something similar to this file tree:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/167/0*gwKXowzZlQvWEVKB" /></figure><p><strong>App.vue: </strong>This is the entry point of the project. Here, we will add the elements we want to be always rendered (like the navigation bar or the footer) and the routing.</p><p><strong>Views folder: </strong>Here, we will store the “view” files. You can think of them as Vue components that symbolize different pages on our site, which we will call other components.</p><p><strong>Router folder: </strong>This is the folder where the routing configs are stored. If you don’t know what routing is, it’s pretty simple: with the Vue CLI, we have already installed Vue Router, an extension that lets us add navigation to our site without needing the browser to reload when switching the URL.</p><p><strong>Components folder: </strong>This is where all our reusable components will be stored! Things like buttons, containers, you name it. The components you intend to use on different views should be stored in this folder.</p><p><strong>Assets folder: </strong>As we saw in the last chapter, here is where all our SCSS and static files are stored.</p><h3>Routing</h3><p>With Vue’s routing plugin, we’ll be able to add navigation to our website and access different routes without reloading our browser. We’ll see how we can configure it to make a new page where we can show off our personal projects!</p><h4>Making the Vue File</h4><p>First, we have to make our view Vue file, where we’ll render our page-specific information.</p><p>This is pretty straightforward! Make a file called “Projects.vue” inside the views folder, and use the default Vue boilerplate. (Remember to add some text to see if it renders something and specify the style’s language and scope!)</p><p>It should look like this:</p><pre>//Projects.vue<br>&lt;template&gt;<br>   &lt;div class=&quot;projects-section&quot;&gt;<br>       This is the Projects view<br>   &lt;/div&gt;<br>&lt;/template&gt;<br> <br>&lt;script&gt;<br>export default {};<br>&lt;/script&gt;<br> <br>&lt;style lang=&quot;scss&quot; scoped&gt;<br>.projects-section {<br>}<br>&lt;/style&gt;</pre><p><em>Pro-tip: It’s recommended to install the Vetur plugin to add proper code coloring and code snippets for Vue in VS code and the Vue Devtools browser extension.</em></p><h4>Configuring the Router</h4><p>After creating the file, you need to specify the URL path in index.js inside the router folder.</p><p>You’ll need to import the Projects file and add this object right after the “Home” route object:</p><pre>//router/index.js <br>import Projects from &#39;../views/Projects.vue&#39;<br>...<br>{<br>   path: &#39;/projects&#39;,<br>   name: &#39;Projects&#39;,<br>   component: Projects<br> },</pre><p>This is how we declare the path to the new route (in this case, being “yourweburl.com/projects”) and the component to be rendered there (the “Projects” component).</p><h4>Adding the Router Link</h4><p>Now it’s time to access this new route! Vue Router comes with built-in navigation components called router-links: these are native components that accept a “to” prop. It is used to specify where that element should send to us when we click it. We will add it in our prebuilt “Nav” inside our App.vue file. This way, it will always render, and therefore we’ll always be able to switch pages!</p><pre>App.vue<br>&lt;div id=&quot;nav&quot;&gt;<br>   &lt;router-link to=&quot;/&quot;&gt;Home&lt;/router-link&gt; |<br>   &lt;router-link to=&quot;/projects&quot;&gt;Projects&lt;/router-link&gt;<br> &lt;/div&gt;</pre><p><em>You can also customize how the active link should look with the “router-link-exact-active” class.</em></p><p>If everything is working correctly, you should be able to go to the new “projects” route when clicking on the top link!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*809R4_vt-nbqWrUv" /></figure><h3>Our first Component</h3><p>We’ll make a straightforward text container to understand some of the capabilities of a component. As always, we need to start by creating a TextContainer.vue file inside our components folder, in which we’ll add the typical Vue boilerplate code.</p><p>Inside the template section, we’ll use the following code: a div with a “text-container” class, and inside it, we’ll also add a “slot” component. This will allow us to accept template content from component calls! We’ll see more about that in a minute.</p><pre>//TextContainer.vue<br>&lt;template&gt;<br> &lt;div class=&quot;text-container&quot;&gt;<br>   &lt;slot/&gt;<br> &lt;/div&gt;<br>&lt;/template&gt;</pre><p>Now, we need to call our component on our Home view. To do this, we need to import it, and thanks to the slot component, we can write in it as if it were a simple HTML element.</p><pre>//Home.vue<br>&lt;template&gt;<br> &lt;div class=&quot;home&quot;&gt;<br>   &lt;TextContainer&gt; Lorem Ipsum &lt;/TextContainer&gt;<br> &lt;/div&gt;<br>&lt;/template&gt;<br> <br>&lt;script&gt;<br>import TextContainer from &#39;@/components/TextContainer.vue&#39;;<br> <br>export default {<br> name: &quot;Home&quot;,<br> components: {<br>   TextContainer,<br> },<br>};<br>&lt;/script&gt;</pre><p><em>Pro-tip: @ is an alias to /src . You can always use it inside Vue files.</em></p><p>And the best thing: as I said earlier, components are reusable. You can call this text container as many times as you want!</p><p>So with a little HTML and CSS magic, we can get something like this with less than half as much code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c9ajFTPp4L3Q3nCT" /></figure><pre>&lt;template&gt;<br> &lt;div class=&quot;home&quot;&gt;<br>   &lt;TextContainer&gt;<br>     &lt;h2&gt;About me&lt;/h2&gt;<br>     &lt;p&gt;<br>       Lorem ipsum dolor sit, amet consectetur adipisicing elit. Autem minus<br>       at, nobis ut beatae incidunt quos a rerum et odit esse ullam sit aliquam<br>       vel! Doloribus provident magnam accusamus architecto velit a dolores<br>       explicabo rerum aperiam unde quas sunt magni corrupti, quis vitae vero.<br>       Explicabo adipisci perferendis pariatur dolores illum!<br>     &lt;/p&gt;<br>     &lt;p&gt;<br>       Lorem ipsum dolor sit, amet consectetur adipisicing elit. Autem minus<br>       at, nobis ut beatae incidunt quos a rerum et odit esse ullam sit aliquam<br>       vel! Doloribus provident magnam accusamus architecto velit a dolores<br>       explicabo rerum aperiam unde quas sunt magni corrupti, quis vitae vero.<br>       Explicabo adipisci perferendis pariatur dolores illum!<br>     &lt;/p&gt;<br>   &lt;/TextContainer&gt;<br>   &lt;TextContainer&gt;<br>     &lt;h2&gt;My Skills&lt;/h2&gt;<br>     &lt;ul&gt;<br>       &lt;li&gt;Lorem ipsum dolor sit amet.&lt;/li&gt;<br>       &lt;li&gt;Lorem ipsum dolor sit amet.&lt;/li&gt;<br>       &lt;li&gt;Lorem ipsum dolor sit amet.&lt;/li&gt;<br>       &lt;li&gt;Lorem ipsum dolor sit amet.&lt;/li&gt;<br>     &lt;/ul&gt;<br>   &lt;/TextContainer&gt;<br>   &lt;TextContainer&gt;<br>     &lt;h2&gt;Contact me!&lt;/h2&gt;<br>     &lt;p&gt;johndoe@gmail.com&lt;/p&gt;<br>   &lt;/TextContainer&gt;<br> &lt;/div&gt;<br>&lt;/template&gt;<br> <br>&lt;script&gt;<br>// @ is an alias to /src<br>import TextContainer from &quot;@/components/TextContainer.vue&quot;;<br> <br>export default {<br> name: &quot;Home&quot;,<br> components: {<br>   TextContainer,<br> },<br>};<br>&lt;/script&gt;<br> <br>&lt;style lang=&quot;scss&quot; scoped&gt;<br>.home {<br> display: flex;<br> gap: 20px;<br> flex-flow: row wrap;<br>   .text-container {<br>     flex: 1 1 0px;<br>     min-width: 45%;<br>   }<br> }<br>&lt;/style&gt;</pre><h3>Getting a Little Bit Deeper: a Projects Showcase Component</h3><p>Alright, now that we know the basic functionalities of a component, it’s time to learn some of the core concepts. And what better way to do it than by implementing a project showcase carousel?</p><p>First and foremost, we have to create the Showcase.vue component and render it on the Projects view. I won’t be going into details. I’m sure you are pretty comfortable with doing that now. I’ll go straight to the point and show you the script section:</p><pre>Showcase.vue<br>&lt;script&gt;<br>export default {<br> data() {<br>   return {<br>     projects: [<br>       {<br>         title: &quot;My first Project&quot;,<br>         desc: `Lorem ipsum  ...`,<br>         techs: [&quot;PostgreSQL&quot;, &quot;React&quot;, &quot;Redux&quot;, &quot;Node&quot;],<br>         urlText: &quot;Github&quot;,<br>         url: &quot;https://github.com/maxfer03/solana-digital-nomads&quot;,<br>         img: &quot;https://efectocolibri.com/wp-content/uploads/2021/01/placeholder.png&quot;,<br>       },<br>       ...<br>     ],<br>     index: 0,<br>   };<br> },<br> methods: {<br>   async next() {<br>     if (this.projects.length - 1 === this.index) {<br>       this.index = 0;<br>     } else {<br>       this.index++;<br>     }<br>   },<br>   async prev() {<br>     if (this.index === 0) {<br>       this.index = this.projects.length - 1;<br>     } else {<br>       this.index--;<br>     }<br>   },<br> },<br>};<br>&lt;/script&gt;</pre><h4>Data</h4><p>As I mentioned, the data function returns all the reactive variables we will use in the component. If you come from a React background, you can think of it as a React state. In this case, we have two variables inside our data: a “projects” array, where we will store all our projects as objects, and the “index,” which is a number. This will be useful to know the current rendered project. We will manipulate this variable to see the next or the previous projects.</p><h4>Methods</h4><p>The methods object is where you store all your functions. These methods can (and probably will) interact with the data variables to make our component truly reactive and updatable. As you can see, we have two ways: the prev and following functions. They update the index element depending on its value, so we can continuously cycle through our projects without getting out of boundaries.</p><p>Note: We must call our variables using the “this” keyword to access them. It won’t work otherwise.</p><p>This is just the tip of the iceberg regarding what tools we have inside our script section, but it will do just fine for our small portfolio. If you want to dig deeper, you can check the Vue lifecycle, computed properties, and the list goes on!</p><h4>The HTML</h4><pre>&lt;template&gt;<br> &lt;div class=&quot;proj-showcase&quot;&gt;<br>   &lt;div class=&quot;carousell&quot;&gt;<br>     &lt;button class=&quot;carousell-btns btn-back&quot; @click=&quot;prev&quot;&gt;{{ &quot;&lt;&quot; }}&lt;/button&gt;<br>     &lt;div class=&quot;carousell-content&quot;&gt;<br>       &lt;img<br>         v-if=&quot;projects[index].img&quot;<br>         :alt=&quot;projects[index].title + &#39; image&#39;&quot;<br>         class=&quot;carousell-img&quot;<br>         :src=&quot;projects[index].img&quot;<br>       /&gt;<br> <br>       &lt;div class=&quot;carousell-content-text&quot;&gt;<br>         &lt;h3&gt;{{ projects[index].title }}&lt;/h3&gt;<br>         &lt;h4&gt;<br>           &lt;span v-for=&quot;(tech, i) in projects[index].techs&quot; :key=&quot;i&quot;&gt;<br>             {{ tech }}{{ i === projects[index].techs.length - 1 ? &quot;&quot; : &quot;, &quot; }}<br>           &lt;/span&gt;<br>         &lt;/h4&gt;<br>         &lt;p&gt;<br>           {{ projects[index].desc }}<br>         &lt;/p&gt;<br>         &lt;a v-if=&quot;projects[index].url&quot; :href=&quot;projects[index].url&quot;&gt;{{<br>           projects[index].urlText<br>         }}&lt;/a&gt;<br>         &lt;span v-else&gt;{{ projects[index].urlText }}&lt;/span&gt;<br>       &lt;/div&gt;<br>     &lt;/div&gt;<br>     &lt;button class=&quot;carousell-btns btn-next&quot; @click=&quot;next&quot;&gt;{{ &quot;&gt;&quot; }}&lt;/button&gt;<br>   &lt;/div&gt;<br> &lt;/div&gt;<br>&lt;/template&gt;</pre><p>There are a few new things to note on the HTML here:</p><p><strong>Double braces</strong>: We can embed logic into our template HTML by wrapping the code inside double braces. This way, we can render our variables with ease.</p><p>Note: unlike the Script section, here, we can call our variables without the “this” keyword.</p><p><strong>@click</strong> : This is an event. Just as you can have the onClick event in React or Javascript, we apply the @ syntax when using events on Vue: @click, @mouseenter, @mouseleave, etc. As you can see, it’s also possible to call functions when the circumstances are fired.</p><p><strong>:src, :href, :alt</strong> : Using a colon before any given prop is Vue’s strategy to embed Javascript into HTML props and attributes.</p><p><strong>v-if, v-else</strong> :This is a beneficial Vue attribute that allows us to render HTML conditionally! If the v-if condition returns false, then the v-else code will render.</p><p><strong>v-for</strong>: This is probably my favorite Vue feature. It’s a simple for loop that allows us to cycle through some Javascript code or our reactive variables. No hassle, no array mapping, just a simple for loop with a pythonic syntax.</p><p>With this knowledge and some CSS, we can get a scalable project and a nice-looking carousel in no time!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8CM_R9HRGY6XiVon" /></figure><h3>Conclusion and next Steps</h3><p>You can now create a reactive, modular, and clean Vue-powered website with what you’ve learned in this post. Now it’s time to be a little more creative! Aggregate a footer component, or edit the navbar styles, whatever you want! Remember to harness the power of SCSS variables and global classes or even try to introduce some mixins! The sky’s the limit.</p><p>Also, take your time to write some nice things about yourself. A portfolio’s priority is to help you sell yourself, so show off! Reveal your most significant strengths, and let your personality shine through your words and stylings. Don’t forget to check out Github for some inspiration! Here and here are some places to start.</p><p>You can visit <a href="https://github.com/maxfer03/vue-three-ns">the repo</a> if you want to use this same code as a base. Beware that if you visit it after the series finishes, you’ll be spoiling it for yourself by anticipating the Three.js implementation!</p><p>In the next and last section, we’ll finally implement Three.js into our project and develop a 3D interactive background. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12fcfc85e033" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nicasource/building-an-interactive-web-portfolio-with-vue-three-js-part-two-vue-basics-12fcfc85e033">Building an interactive web portfolio with Vue + Three.js — Part Two: Vue Basics</a> was originally published in <a href="https://medium.com/nicasource">NicaSource</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an interactive web portfolio with Vue + Three.js — Part One: Introduction and Setup]]></title>
            <link>https://medium.com/nicasource/building-an-interactive-web-portfolio-with-vue-three-js-part-one-introduction-and-setup-405426cec84?source=rss-6003252c7068------2</link>
            <guid isPermaLink="false">https://medium.com/p/405426cec84</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[threejs]]></category>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[portfolio]]></category>
            <dc:creator><![CDATA[Máximo Fernández]]></dc:creator>
            <pubDate>Thu, 30 Jun 2022 22:14:48 GMT</pubDate>
            <atom:updated>2022-07-21T15:46:31.579Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Building an interactive web portfolio with Vue + Three.js — Part One: </strong>Introduction and Setup</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S6vyb2U9Jn5aZujZ2CxQuQ.png" /></figure><p>It is safe to say that a web portfolio is one of the best ways to show off your projects and share your brand. But this is even <em>more</em> important in the case of web developers, to whom a personal website is the best way to show what one can do.</p><h3>Designing as a non-designer</h3><p>Here’s the thing: it’s pretty hard to make a nice-looking portfolio when you are just starting. And it’s even more complicated when you are not a designer — which is my case.</p><p>A good portfolio must communicate your brand and stand out at first sight, but how can we get there when our strengths lie in programming, not design?</p><p>I have an idea for you: implementing <strong>3D geometry</strong>! Computer graphics never get out of fashion, and we can create amazing interactive elements while showing off our core strength: <strong>programming</strong> 😎!</p><h3>But graphics programming is HARD, isn’t it?</h3><p>Of course, it is!</p><p>But don’t worry; we will not render the next <em>Minecraft</em> from scratch. As always, the web development scene is packed with <strong>incredible</strong> tools and libraries, and we’ll be using:</p><ul><li><a href="https://threejs.org/"><strong>Three.js</strong></a>, a JavaScript library that simplifies the rendering process for us. You can think of it as an abstraction of WebGL, the open-source web graphics engine.</li><li><a href="https://vuejs.org/"><strong>Vue.js</strong></a>, a popular JavaScript framework that handles routing and encapsulates our logic into reusable components.</li><li><a href="https://sass-lang.com/"><strong>SASS</strong></a> for a better development experience while making the styles.</li></ul><p>At the end of this short series, you’ll be able to build something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LsK8YrESulMAHF3I" /><figcaption>The project may look a little bit different when we finish the series.</figcaption></figure><h3>Requirements</h3><p>The requirements for this project are pretty basic! If you know:</p><p>✅ Javascript<br>✅ HTML<br>✅ CSS</p><p>Then you are good to go 👍</p><h3>Let’s get started!</h3><p>With all that said, let’s kick off our project by setting up our Vue app!</p><p><strong>Initializing our Vue project<br></strong>The easiest way to initialize a Vue app is by using the <a href="https://cli.vuejs.org/">Vue CLI</a>. It’s really straightforward and saves you a lot of time. It will feel similar if you have ever worked with Create React App. If you haven’t, don’t worry, we’ll go step by step.</p><ol><li>Installing the Vue CLI</li></ol><p>You’ll need to download the package from NPM. This command will install the CLI globally.</p><pre>npm install -g @vue/cli</pre><p>2. Initializing the project</p><p>Here is where the CLI really shines. You can configure your project by selecting between multiple presets and options. You can do this with the &quot;vue&quot; command that you have installed earlier with npm:</p><pre>vue create your-project-name</pre><p>For our project, we’ll be using the following configuration:</p><ul><li>Preset: Manually select features</li><li>Features ( You can still install the rest, but these are a must):<br>◉ Choose Vue version<br>◉ Babel<br>◉ Router<br>◉ CSS Pre-processors</li><li>Vue version: 3.x</li><li>CSS preprocessor: Sass/SCSS (with dart-sass)</li><li>Placing config: whatever fancies you</li><li>Now we wait…</li></ul><p>And done! If everything went well, you should be able to open the folder, run &quot;npm run serve&quot;, and see this on your local 8080 port:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XCFsp8mK9vVEeP4I" /><figcaption>How about that? 👀</figcaption></figure><p><strong>Configuring Global SCSS stylesheets</strong></p><p>Now that our project is initialized, we need to make some changes so we can use global .scss files where we can store our variables, mixins, whatever! We’ll get a little deeper into SCSS in the next chapter.</p><ol><li>Creating our files<br>You’ll see a folder called “assets” inside the source folder. Here, we’ll have different folders for static files, like images, svgs, and in our case: the stylesheets.<br>Inside our assets folder, we create the “scss” folder. In there, we’ll create our variables file, called “variables.scss” (Pretty original, right?) <br>In the end, the folder should look like this:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*UyMqiLnX20QqAuB0L3yZNg.png" /></figure><p>2. In this file, we&#39;ll create a test color variable: &quot;$test-variable: #A0D995&quot;.<br>As you may have guessed by now, SCSS allows us to store colors, sizes, and more as variables we can call whenever we want. But beware because it would fail if we tried to use that variable in a Vue component. We’ll fix that with the next and last step.</p><p>3. Configuring Vue<br>You’ll find a file called ‘vue.config.js’ at the root of our project. If you don’t, create it.<br>Inside it, write:</p><pre>module.exports = {<br>  css: {<br>    loaderOptions: {<br>      scss: {<br>//if not working, try with &quot;additionalData&quot; instead of &quot;prependData&quot;<br>        prependData: `<br>            <a href="http://twitter.com/import">@import</a> &quot;@/assets/scss/variables.scss&quot;;<br>          `,<br>      },<br>    },<br>  },<br>};</pre><p>In the future, if you want to add more .scss files, simply add them here, one import after the other.</p><p>4. Calling the variable<br>Try calling the variable inside a Vue component’s &lt;style&gt; tag. For example, as a background color for the App.vue file.</p><p>Now restart the project, and… <em>Voila! </em>Your project should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EuIWYuPzKKJ1-PNO" /><figcaption>Do you see how the background changed? This means the variable was successfully called, and we are ready to go!</figcaption></figure><h3>Next Steps</h3><p>All right! We finished our initial configuration. We initialized our Vue project and configured it to accept global stylesheets. In the next chapter, we’ll dive deeper into Vue and SCSS, and build some components for our portfolio!</p><p>For now, if you want to start learning on your own, check out <a href="https://vuejs.org/guide/introduction.html">Vue’s official documentation</a>. Or if you already know Vue and want to start playing with Three.js, check out my <a href="https://github.com/maxfer03/vue-three-starter">vue-three starter on GitHub</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=405426cec84" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nicasource/building-an-interactive-web-portfolio-with-vue-three-js-part-one-introduction-and-setup-405426cec84">Building an interactive web portfolio with Vue + Three.js — Part One: Introduction and Setup</a> was originally published in <a href="https://medium.com/nicasource">NicaSource</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>