Skip to content

Commit

Permalink
Update manual (examples -> addons) (#24888)
Browse files Browse the repository at this point in the history
* Change imports

* Fix links

* More fixes

* Fix merge conflicts

* Fix merge conflicts

* More fixes

* Rename Examples -> Addons in docs also

* Update English versions of fundamentals.html and prerequisites.html
  • Loading branch information
LeviPesin authored Nov 2, 2022
1 parent 1674b5b commit d66496c
Show file tree
Hide file tree
Showing 80 changed files with 343 additions and 318 deletions.
6 changes: 3 additions & 3 deletions docs/list.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@

},

"Examples": {
"Addons": {

"Animations": {
"CCDIKSolver": "examples/en/animations/CCDIKSolver",
Expand Down Expand Up @@ -829,7 +829,7 @@

},

"示例": {
"Addons": {

"动画": {
"CCDIKSolver": "examples/zh/animations/CCDIKSolver",
Expand Down Expand Up @@ -1065,7 +1065,7 @@

},

"예제": {
"Addons": {

"컨트롤": {
"DragControls": "examples/ko/controls/DragControls",
Expand Down
10 changes: 5 additions & 5 deletions manual/en/align-html-elements-to-3d.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ <h1>Aligning HTML Elements to 3D</h1>
<p>Let's start simple. We'll make a 3D scene with a few primitives and then add a label to each primitive. We'll start
with an example from <a href="responsive.html">the article on responsive pages</a> </p>
<p>We'll add some <a href="/docs/#examples/controls/OrbitControls"><code class="notranslate" translate="no">OrbitControls</code></a> like we did in <a href="lights.html">the article on lighting</a>.</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import * as THREE from '/build/three.module.js';
+import {OrbitControls} from '/examples/jsm/controls/OrbitControls.js';
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import * as THREE from 'three';
+import {OrbitControls} from 'three/addons/controls/OrbitControls.js';
</pre>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">const controls = new OrbitControls(camera, canvas);
controls.target.set(0, 0, 0);
Expand Down Expand Up @@ -659,9 +659,9 @@ <h1>Aligning HTML Elements to 3D</h1>
</pre>
<p>Finally, since I'm not sure what good values are for these settings lets
add a GUI so we can play with them</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import * as THREE from '/build/three.module.js';
import {OrbitControls} from '/examples/jsm/controls/OrbitControls.js';
+import {GUI} from '/examples/jsm/libs/lil-gui.module.min.js';
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import * as THREE from 'three';
import {OrbitControls} from 'three/addons/controls/OrbitControls.js';
+import {GUI} from 'three/addons/libs/lil-gui.module.min.js';
</pre>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">+const settings = {
+ minArea: 20,
Expand Down
2 changes: 1 addition & 1 deletion manual/en/backgrounds.html
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ <h1>Backgrounds and Skyboxes</h1>
}
</pre>
<p>Let's add some controls in so we can rotate the camera.</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import {OrbitControls} from '/examples/jsm/controls/OrbitControls.js';
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import {OrbitControls} from 'three/addons/controls/OrbitControls.js';
</pre>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">const fov = 75;
const aspect = 2; // the canvas default
Expand Down
4 changes: 2 additions & 2 deletions manual/en/canvas-textures.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ <h1>Canvas Textures</h1>
</pre>
<p>What's left is to add some <a href="/docs/#examples/controls/OrbitControls"><code class="notranslate" translate="no">OrbitControls</code></a> so we can move
the camera.</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import * as THREE from '/build/three.module.js';
+import {OrbitControls} from '/examples/jsm/controls/OrbitControls.js';
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import * as THREE from 'three';
+import {OrbitControls} from 'three/addons/controls/OrbitControls.js';
</pre>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">const fov = 75;
const aspect = 2; // the canvas default
Expand Down
114 changes: 65 additions & 49 deletions manual/en/fundamentals.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,12 @@ <h1>Fundamentals</h1>

<p>First let's load three.js</p>
<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;script type="module"&gt;
import * as THREE from '../../build/three.module.js';
import * as THREE from 'three';
&lt;/script&gt;
</pre>
<p>It's important you put <code class="notranslate" translate="no">type="module"</code> in the script tag. This enables
us to use the <code class="notranslate" translate="no">import</code> keyword to load three.js. There are other ways
to load three.js but as of r106 using modules is the recommended way.
Modules have the advantage that they can easily import other modules
us to use the <code class="notranslate" translate="no">import</code> keyword to load three.js. As of r147, this is the
only way to load three.js properly. Modules have the advantage that they can easily import other modules
they need. That saves us from having to manually load extra scripts
they are dependent on.</p>
<p>Next we need is a <code class="notranslate" translate="no">&lt;canvas&gt;</code> tag so...</p>
Expand All @@ -132,7 +131,7 @@ <h1>Fundamentals</h1>
</pre>
<p>We will ask three.js to draw into that canvas so we need to look it up.</p>
<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;script type="module"&gt;
import * as THREE from '../../build/three.module.js';
import * as THREE from 'three';

+function main() {
+ const canvas = document.querySelector('#c');
Expand Down Expand Up @@ -365,69 +364,86 @@ <h1>Fundamentals</h1>
making our code responsive so it is adaptable to multiple situations</a>.</p>
<div id="es6" class="threejs_bottombar">
<h3>es6 modules, three.js, and folder structure</h3>
<p>As of version r106 the preferred way to use three.js is via <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import">es6 modules</a>.</p>
<p>As of version r147 the preferred way to use three.js is via <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import">es6 modules</a> and import maps.</p>
<p>
es6 modules can be loaded via the <code class="notranslate" translate="no">import</code> keyword in a script
or inline via a <code class="notranslate" translate="no">&lt;script type="module"&gt;</code> tag. Here's an example of
both
or inline via a <code class="notranslate" translate="no">&lt;script type="module"&gt;</code> tag. Here's an example
</p>
<pre class="prettyprint">&lt;script type="module"&gt;
import * as THREE from '../../build/three.module.js';
<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;script type="module"&gt;
import * as THREE from 'three';

...

&lt;/script&gt;
</pre>
<p>
Paths must be absolute or relative. Relative paths always start with <code class="notranslate" translate="no">./</code> or <code class="notranslate" translate="no">../</code>
which is different than other tags like <code class="notranslate" translate="no">&lt;img&gt;</code> and <code class="notranslate" translate="no">&lt;a&gt;</code>.
Notice <code class="notranslate" translate="no">'three'</code> specifier there. If you leave it as it is, it will likely produce an error. An <i>import map</i> should be used to tell the browser where to find three.js
</p>
<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;script type="importmap"&gt;
{
"imports": {
"three": "./path/to/three.module.js"
}
}
&lt;/script&gt;
</pre>
<p>
Note that path specifier can start only with <code class="notranslate" translate="no">./</code> or <code class="notranslate" translate="no">../</code>.
</p>
<p>
References to the same script will only be loaded once as long as their absolute paths
are exactly the same. For three.js this means it's required that you put all the examples
libraries in the correct folder structure
Import maps are still unsupported in Firefox and Safari, so it is recommended to use <a href="https://github.com/guybedford/es-module-shims">an import maps polyfill</a> like so
</p>
<pre class="dos">someFolder
|
├-build
| |
| +-three.module.js
|
+-examples
|
+-jsm
|
+-controls
| |
| +-OrbitControls.js
| +-TrackballControls.js
| +-...
|
+-loaders
| |
| +-GLTFLoader.js
| +-...
|
...
<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"&gt;&lt;/script&gt;</pre>
<p>
To import addons like <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/OrbitControls.js"><code class="notranslate" translate="no">OrbitControls.js</code></a> use the following
</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import {OrbitControls} from 'three/addons/controls/OrbitControls.js';
</pre>
<p>
The reason this folder structure is required is because the scripts in the
examples like <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/OrbitControls.js"><code class="notranslate" translate="no">OrbitControls.js</code></a>
have hard coded relative paths like
Don't forget to add addons to the import map like so
</p>
<pre class="prettyprint">import * as THREE from '../../../build/three.module.js';
<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;script type="importmap"&gt;
{
"imports": {
"three": "./path/to/three.module.js",
"three/addons/": "./different/path/to/examples/jsm/"
}
}
&lt;/script&gt;
</pre>
<p>
Using the same structure assures then when you import both three and one of the example
libraries they'll both reference the same <code class="notranslate" translate="no">three.module.js</code> file.
You can also use a CDN
</p>
<pre class="prettyprint">import * as THREE from './someFolder/build/three.module.js';
import {OrbitControls} from './someFolder/examples/jsm/controls/OrbitControls.js';
<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;script type="importmap"&gt;
{
"imports": {
"three": "https://unpkg.com/[email protected]/build/three.module.js",
"three/addons/": "https://unpkg.com/[email protected]/examples/jsm/"
}
}
&lt;/script&gt;
</pre>
<p>This includes when using a CDN. Be sure your path to <code class="notranslate" translate="no">three.module.js</code> ends with
<code class="notranslate" translate="no">/build/three.modules.js</code>. For example</p>
<pre class="prettyprint">import * as THREE from 'https://unpkg.com/[email protected]<b>/build/three.module.js</b>';
import {OrbitControls} from 'https://unpkg.com/[email protected]/examples/jsm/controls/OrbitControls.js';
<p>
To conclude, the recommended way of using three.js is
</p>
<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"&gt;&lt;/script&gt;

&lt;script type="importmap"&gt;
{
"imports": {
"three": "./path/to/three.module.js",
"three/addons/": "./different/path/to/examples/jsm/"
}
}
&lt;/script&gt;

&lt;script type="module"&gt;
import * as THREE from 'three';
import {OrbitControls} from 'three/addons/controls/OrbitControls.js';

...

&lt;/script&gt;
</pre>
</div>

Expand Down
18 changes: 9 additions & 9 deletions manual/en/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ <h1>Making a Game</h1>
it for skinned animated characters. Fortunately there's a utility function,
<code class="notranslate" translate="no">SkeletonUtils.clone</code> we can use to do this. So, first we need to include
the utils.</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import * as THREE from '/build/three.module.js';
import {OrbitControls} from '/examples/jsm/controls/OrbitControls.js';
import {GLTFLoader} from '/examples/jsm/loaders/GLTFLoader.js';
+import * as SkeletonUtils from '/examples/jsm/utils/SkeletonUtils.js';
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import * as THREE from 'three';
import {OrbitControls} from 'three/addons/controls/OrbitControls.js';
import {GLTFLoader} from 'three/addons/loaders/GLTFLoader.js';
+import * as SkeletonUtils from 'three/addons/utils/SkeletonUtils.js';
</pre>
<p>Then we can clone the models we just loaded</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">function init() {
Expand Down Expand Up @@ -1513,11 +1513,11 @@ <h1>Making a Game</h1>
</pre>
<p>While we're at it lets make it so we can turn them on/off using lil-gui like
we've used else where</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import * as THREE from '/build/three.module.js';
import {OrbitControls} from '/examples/jsm/controls/OrbitControls.js';
import {GLTFLoader} from '/examples/jsm/loaders/GLTFLoader.js';
import * as SkeletonUtils from '/examples/jsm/utils/SkeletonUtils.js';
+import {GUI} from '/examples/jsm/libs/lil-gui.module.min.js';
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import * as THREE from 'three';
import {OrbitControls} from 'three/addons/controls/OrbitControls.js';
import {GLTFLoader} from 'three/addons/loaders/GLTFLoader.js';
import * as SkeletonUtils from 'three/addons/utils/SkeletonUtils.js';
+import {GUI} from 'three/addons/libs/lil-gui.module.min.js';
</pre>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">+const gui = new GUI();
+gui.add(globals, 'debug').onChange(showHideDebugInfo);
Expand Down
10 changes: 5 additions & 5 deletions manual/en/lights.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ <h1>Lights</h1>
or <em>orbit</em> the camera around some point. The <a href="/docs/#examples/controls/OrbitControls"><code class="notranslate" translate="no">OrbitControls</code></a> are
an optional feature of three.js so first we need to include them
in our page</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import * as THREE from '/build/three.module.js';
+import {OrbitControls} from '/examples/jsm/controls/OrbitControls.js';
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import * as THREE from 'three';
+import {OrbitControls} from 'three/addons/controls/OrbitControls.js';
</pre>
<p>Then we can use them. We pass the <a href="/docs/#examples/controls/OrbitControls"><code class="notranslate" translate="no">OrbitControls</code></a> a camera to
control and the DOM element to use to get input events</p>
Expand Down Expand Up @@ -422,9 +422,9 @@ <h2 id="-rectarealight-"><a href="/docs/#api/en/lights/RectAreaLight"><code clas
</pre>
<p>To use the <a href="/docs/#api/en/lights/RectAreaLight"><code class="notranslate" translate="no">RectAreaLight</code></a> we need to include some extra three.js optional data and we'll
include the <a href="/docs/#api/en/helpers/RectAreaLightHelper"><code class="notranslate" translate="no">RectAreaLightHelper</code></a> to help us visualize the light</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import * as THREE from '/build/three.module.js';
+import {RectAreaLightUniformsLib} from '/examples/jsm/lights/RectAreaLightUniformsLib.js';
+import {RectAreaLightHelper} from '/examples/jsm/helpers/RectAreaLightHelper.js';
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import * as THREE from 'three';
+import {RectAreaLightUniformsLib} from 'three/addons/lights/RectAreaLightUniformsLib.js';
+import {RectAreaLightHelper} from 'three/addons/helpers/RectAreaLightHelper.js';
</pre>
<p>and we need to call <code class="notranslate" translate="no">RectAreaLightUniformsLib.init</code></p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">function main() {
Expand Down
8 changes: 4 additions & 4 deletions manual/en/load-gltf.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ <h1>Loading a .GLTF File</h1>
</pre>
<p>I kept the auto framing code as before</p>
<p>We also need to include the <a href="/docs/#examples/loaders/GLTFLoader"><code class="notranslate" translate="no">GLTFLoader</code></a> and we can get rid of the <a href="/docs/#examples/loaders/OBJLoader"><code class="notranslate" translate="no">OBJLoader</code></a>.</p>
<pre class="prettyprint showlinemods notranslate lang-html" translate="no">-import {LoaderSupport} from '/examples/jsm/loaders/LoaderSupport.js';
-import {OBJLoader} from '/examples/jsm/loaders/OBJLoader.js';
-import {MTLLoader} from '/examples/jsm/loaders/MTLLoader.js';
+import {GLTFLoader} from '/examples/jsm/loaders/GLTFLoader.js';
<pre class="prettyprint showlinemods notranslate lang-html" translate="no">-import {LoaderSupport} from 'three/addons/loaders/LoaderSupport.js';
-import {OBJLoader} from 'three/addons/loaders/OBJLoader.js';
-import {MTLLoader} from 'three/addons/loaders/MTLLoader.js';
+import {GLTFLoader} from 'three/addons/loaders/GLTFLoader.js';
</pre>
<p>And running that we get</p>
<p></p><div translate="no" class="threejs_example_container notranslate">
Expand Down
10 changes: 5 additions & 5 deletions manual/en/load-obj.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h1>Loading a .OBJ File</h1>
related to adjusting the lights. I also removed the cube and sphere
that were being added to the scene.</p>
<p>From that the first thing we need to do is include the <a href="/docs/#examples/loaders/OBJLoader"><code class="notranslate" translate="no">OBJLoader</code></a> loader in our script.</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import {OBJLoader} from '/examples/jsm/loaders/OBJLoader.js';
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import {OBJLoader} from 'three/addons/loaders/OBJLoader.js';
</pre>
<p>Then to load the .OBJ file we create an instance of <a href="/docs/#examples/loaders/OBJLoader"><code class="notranslate" translate="no">OBJLoader</code></a>,
pass it the URL of our .OBJ file, and pass in a callback that adds
Expand Down Expand Up @@ -148,10 +148,10 @@ <h1>Loading a .OBJ File</h1>

<p>Now that we have the textures available we can load the .MTL file.</p>
<p>First we need to include the <a href="/docs/#examples/loaders/MTLLoader"><code class="notranslate" translate="no">MTLLoader</code></a>;</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import * as THREE from '/build/three.module.js';
import {OrbitControls} from '/examples/jsm/controls/OrbitControls.js';
import {OBJLoader} from '/examples/jsm/loaders/OBJLoader.js';
+import {MTLLoader} from '/examples/jsm/loaders/MTLLoader.js';
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import * as THREE from 'three';
import {OrbitControls} from 'three/addons/controls/OrbitControls.js';
import {OBJLoader} from 'three/addons/loaders/OBJLoader.js';
+import {MTLLoader} from 'three/addons/loaders/MTLLoader.js';
</pre>
<p>Then we first load the .MTL file. When it's finished loading we add
the just loaded materials on to the <a href="/docs/#examples/loaders/OBJLoader"><code class="notranslate" translate="no">OBJLoader</code></a> itself via the <code class="notranslate" translate="no">setMaterials</code>
Expand Down
2 changes: 1 addition & 1 deletion manual/en/multiple-scenes.html
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ <h2 id="using-html-dataset">Using HTML Dataset</h2>
<p></p>
<h2 id="adding-controls-to-each-element">Adding Controls to each element</h2>
<p>Adding interactively, for example a <code class="notranslate" translate="no">TrackballControls</code> is just as easy. First we add the script for the control.</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import {TrackballControls} from '/examples/jsm/controls/TrackballControls.js';
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">import {TrackballControls} from 'three/addons/controls/TrackballControls.js';
</pre>
<p>And then we can add a <code class="notranslate" translate="no">TrackballControls</code> to each scene passing in the element associated with that scene.</p>
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">-function makeScene() {
Expand Down
Loading

0 comments on commit d66496c

Please sign in to comment.