

Import Individual Components from the Core Then we can use any element of the core by referencing them under the THREE namespace: main.js: accessing classes from the core under the THREE namespace Import \* as THREE from './vendor/three/build/' The simplest approach is to import everything from the three.js core into main.js under the THREE namespace: main.js: import the entire three.js core So, for this chapter, let’s assume we want to import just three classes from : the We’ll never need to use all of them at once, and in fact, it’s almost certain you’ll never need to use all of them across an entire application, no matter how big it is. The three.js core contains hundreds of classes such as cameras, materials, geometries, textures, lights, shadows, the animation system, various loaders, audio, the renderer, 2D shapes, helpers, fog, and so on. Over the rest of this chapter, we’ll demonstrate various ways to import and OrbitControls.js here. To use them, first, we need to import them into main.js, so open up that file now. The core and OrbitControls plugins are JavaScript modules. If using JavaScript modules is new to you, or you need a refresher, check out A.4: JavaScript Modules. If anything in index.html is unfamiliar to you, check out A.1: HTML and CSS Used in This Book. Take special notice of type="module", which we’re using to tell the browser the linked file is a JavaScript module. We have also set up a very simple web page consisting of these three files:Ĭheck out index.html now, and you’ll see that we have referenced main.js in the section: index.html: referencing the main JavaScript file

In addition to the core file, we’ll often add plugins such as camera controls or post-processing. There are several ways to include three.js in your JavaScript application, some simple, some a little more complex, but they all boil down to this: you need to include the three.js core in your project, which you can find in this file on the three.js repo:
#Nextjs unpkg how to
Word Count:1444, reading time: ~7minutes How to Include three.js in Your Projects
