123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <base href="../../../" />
- <script src="list.js"></script>
- <script src="page.js"></script>
- <link type="text/css" rel="stylesheet" href="page.css" />
- </head>
- <body>
- <h1>[name]</h1><br />
- <p>
- While importing three.js via script tags is a great way to get up and running fast, it has a few drawbacks for longer lived projects, for example:
- <ul>
- <li>You have to manually fetch and include a copy of the library as part of your project's source code</li>
- <li>Updating the library's version is a manual process</li>
- <li>When checking in a new version of the library your version control diffs are cluttered by the many lines of the build file</li>
- </ul>
- </p>
- <p>Using a dependency manager like npm avoids these caveats by allowing you to simply download and import your desired version of the library onto your machine.</p>
- <h2>Installation via npm</h2>
- <p>Three.js is published as an npm module, see: [link:https://www.npmjs.com/package/three npm]. This means all you need to do to include three.js into your project is run "npm install three"</p>
- <h2>Importing the module</h2>
- <p>Assuming that you're bundling your files with a tool such as [link:https://webpack.github.io/ Webpack] or [link:https://github.com/substack/node-browserify Browserify], which allow you to "require('modules')" in the browser by bundling up all of your dependencies.</p>
- <p>
- You should now be able to import the module into your source files and continue to use it as per normal.
- </p>
- <code>
- var THREE = require('three');
- var scene = new THREE.Scene();
- ...
- </code>
- <p>
- You're also able to leverage [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import ES6 import syntax]:
- </p>
- <code>
- import * as THREE from 'three';
- const scene = new THREE.Scene();
- ...
- </code>
- <p>
- or if you wish to import only select parts of three.js library, for example Scene:
- </p>
- <code>
- import { Scene } from 'three';
- const scene = new Scene();
- ...
- </code>
- <h2>Importable Examples</h2>
- <p>
- The core of three.js is focused on the most important components of a 3D engine. Many other components like loaders or controls are part of the
- examples directory. three.js ensures that these files are kept in sync with the core but users have to import them separately if they are required
- for their project. However, most of these files are not modules which makes their usage in certain cases inconvenient. In order to address this issue,
- we are working to provide all the examples as modules in the [link:https://github.com/mrdoob/three.js/tree/master/examples/jsm examples/jsm] directory.
- If you install three.js via npm, you can import them like so:
- </p>
- <code>
- import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
- </code>
- <p>
- The following examples files are already available as modules:
- <ul>
- <li>controls
- <ul>
- <li>DeviceOrientationControls</li>
- <li>DragControls</li>
- <li>EditorControls</li>
- <li>FirstPersonControls</li>
- <li>FlyControls</li>
- <li>MapControls</li>
- <li>OrbitControls</li>
- <li>OrthographicTrackballControls</li>
- <li>PointerLockControls</li>
- <li>TrackballControls</li>
- <li>TransformControls</li>
- </ul>
- </li>
- <li>curves
- <ul>
- <li>NURBSCurve</li>
- <li>NURBSSurface</li>
- <li>NURBSUtils</li>
- </ul>
- </li>
- <li>exporters
- <ul>
- <li>ColladaExporter</li>
- <li>GLTFExporter</li>
- <li>MMDExporter</li>
- <li>OBJExporter</li>
- <li>PLYExporter</li>
- <li>STLExporter</li>
- <li>TypedGeometryExporter</li>
- </ul>
- </li>
- <li>loaders
- <ul>
- <li>BVHLoader</li>
- <li>ColladaLoader</li>
- <li>DDSLoader</li>
- <li>FBXLoader</li>
- <li>GLTFLoader</li>
- <li>MTLLoader</li>
- <li>OBJLoader</li>
- <li>PCDLoader</li>
- <li>PDBLoader</li>
- <li>PLYLoader</li>
- <li>STLLoader</li>
- <li>SVGLoader</li>
- <li>TGALoader</li>
- <li>VRMLLoader</li>
- </ul>
- </li>
- <li>pmrem
- <ul>
- <li>PMREMCubeUVPacker</li>
- <li>PMREMGenerator</li>
- </ul>
- </li>
- <li>renderers
- <ul>
- <li>CSS2DRenderer</li>
- <li>CSS3DRenderer</li>
- <li>Projector</li>
- <li>SoftwareRenderer</li>
- <li>SVGRenderer</li>
- </ul>
- </li>
- <li>utils
- <ul>
- <li>BufferGeometryUtils</li>
- <li>GeometryUtils</li>
- <li>MathUtils</li>
- <li>SceneUtils</li>
- <li>ShadowMapViewer</li>
- <li>SkeletonUtils</li>
- <li>TypedArrayUtils</li>
- <li>UVsDebug</li>
- </ul>
- </li>
- </ul>
- </p>
- <p>
- Note: When using code from the examples directory, it's important that all files match the version of
- your three.js main file. For example, it's not acceptable to use *GLTFLoader* and *OrbitControls* from R96 together
- with three.js R103. You can easily keep your files in sync by using the modules from the JSM directory. If the file
- is not available as a module, you can still use third-party npm packages or convert the file to a module by yourself.
- In both cases, ensure the code is compatible with your three.js main file.
- </p>
- </body>
- </html>
|