Thank you to edwinwebb for the starter, which I used to create myself a template to run shadertoy code. The template I used can be found here: https://github.com/edwinwebb/three-seed
Three.js starter project boilerplate bundled with Webpack.
This project is designed to help you get started on your next three.js project. It sets up a simple scene, camera and renderer to view two imported GLTF assets.
Before you begin, make sure you are comfortable with terminal commands and have Node and NPM installed. Then either install via a download or with Git.
First download the zip of the project and extract it. Then in terminal at that folder type npm install
to set things up. To get going run: npm start
.
In terminal clone the project into a directory of your choice then delete the git folder to start fresh.
git clone --depth=1 https://github.com/edwinwebb/three-seed.git my-project
cd my-project
rm -rf .git
npm install
To see the changes you make to the starter project go to the project folder in terminal and type...
npm start
This command will bundle the project code and start a development server at http://localhost:8080/. Visit this in your web browser; you should see a rotating island and flower.
The first file you should open is ./objects/Scene.js
. In it you will find the three objects comprising the ThreeJS scene represented in your browser. The flower, the island, and the lights illuminating them are each represented as a javascript file in the ./object/
folder. Open these, edit them and see your changes in the browser. If something goes wrong a message will displayed in the debug console of the browser.
Local files, such as images and 3D models, are imported into the application as URLs then loaded asynchronously with three.js. Most common files that three.js uses are supported. For more information about this system see the webpack site.
If you want to add additional functionality to your project, you can search and install them from the NPM repository. Some modules you might want to consider are...
Additions like these are best managed in the projects entry file: ./src/entry.js
. In it are the Scene, Camera, Renderer, the window event listeners and the animation loop.
Once you are happy with your project you'll be sure to want to show it off. Running npm run build
in terminal will bundle your project into the folder ./build/
. You can upload this directory to a web server. For more complex results read this guide.