I built my first Three JS project. Here’s what I learned.

Today, I’ll teach you how to create an introductory scene with Three.js which is probably the most useful library for you to work with, as it already has many useful functions pre-written, which would otherwise require a lot of effort.

HRブログ
Ageless Dynasty
4 min readJul 11, 2022

--

ThreeJS Setup

Fundamentals

Three.js is a 3D library that tries to make it as easy as possible to get 3D content on a webpage. Three.js is often confused with WebGL since more often than not, but not always, three.js uses WebGL to draw 3D.

WebGL is a very low-level system that only draws points, lines, and triangles. To do anything useful with WebGL generally requires quite a bit of code and that is where three.js comes in. It handles stuff like scenes, lights, shadows, materials, textures, 3d math, all things that you’d have to write yourself if you were to use WebGL directly.

Getting started

Go ahead and initialise our new project using the CodePen playground or setup your own project on Visual Studio Code with the following file structure under your src folder.

Part 1: HTML

The HTML is really basic. Edit your `index.html` and replace it with the following code.

Part 2: CSS

Next step is to add the following styles and complete our `style.css` file. Just make sure the div that will wrap the canvas fits the document, and apply any size you want to your plane div element.

Part 3: JavaScript

Now we can implement our JavaScript logic to our ThreeJS setup like so.

Cool! Now, if you save it, you should see this in the browser:

ThreeJS Setup

Recap

If you followed along then you should have completed the project and finished off your basic scene setup with ThreeJS.

Now if you made it this far, then I am linking the code to my Sandbox for you to fork or clone and then the job’s done.

Useful resources

https://threejs.org/

--

--

HRブログ
Ageless Dynasty

Talks about #realworld, #finance , #economics, #crypto and #technology.