Import-via-modules.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <base href="../../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. <h1>[name]</h1><br />
  12. <p>
  13. 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:
  14. <ul>
  15. <li>You have to manually fetch and include a copy of the library as part of your project's source code</li>
  16. <li>Updating the library's version is a manual process</li>
  17. <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>
  18. </ul>
  19. </p>
  20. <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>
  21. <h2>Installation via npm</h2>
  22. <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>
  23. <h2>Importing the module</h2>
  24. <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>
  25. <p>
  26. You should now be able to import the module into your source files and continue to use it as per normal.
  27. </p>
  28. <code>
  29. var THREE = require('three');
  30. var scene = new THREE.Scene();
  31. ...
  32. </code>
  33. <p>
  34. You're also able to leverage [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import ES6 import syntax]:
  35. </p>
  36. <code>
  37. import * as THREE from 'three';
  38. const scene = new THREE.Scene();
  39. ...
  40. </code>
  41. <p>
  42. or if you wish to import only select parts of three.js library, for example Scene:
  43. </p>
  44. <code>
  45. import { Scene } from 'three';
  46. const scene = new Scene();
  47. ...
  48. </code>
  49. <h2>Importable Examples</h2>
  50. <p>
  51. 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
  52. 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
  53. 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,
  54. 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.
  55. If you install three.js via npm, you can import them like so:
  56. </p>
  57. <code>
  58. import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
  59. </code>
  60. <p>
  61. The following examples files are already available as modules:
  62. <ul>
  63. <li>cameras
  64. <ul>
  65. <li>CinematicCamera</li>
  66. </ul>
  67. </li>
  68. <li>controls
  69. <ul>
  70. <li>DeviceOrientationControls</li>
  71. <li>DragControls</li>
  72. <li>EditorControls</li>
  73. <li>FirstPersonControls</li>
  74. <li>FlyControls</li>
  75. <li>MapControls</li>
  76. <li>OrbitControls</li>
  77. <li>OrthographicTrackballControls</li>
  78. <li>PointerLockControls</li>
  79. <li>TrackballControls</li>
  80. <li>TransformControls</li>
  81. </ul>
  82. </li>
  83. <li>curves
  84. <ul>
  85. <li>CurveExtras</li>
  86. <li>NURBSCurve</li>
  87. <li>NURBSSurface</li>
  88. <li>NURBSUtils</li>
  89. </ul>
  90. </li>
  91. <li>effects
  92. <ul>
  93. <li>AnaglyphEffect</li>
  94. <li>AsciiEffect</li>
  95. <li>OutlineEffect</li>
  96. <li>ParallaxBarrierEffect</li>
  97. <li>PeppersGhostEffect</li>
  98. <li>StereoEffect</li>
  99. </ul>
  100. </li>
  101. <li>exporters
  102. <ul>
  103. <li>ColladaExporter</li>
  104. <li>GLTFExporter</li>
  105. <li>MMDExporter</li>
  106. <li>OBJExporter</li>
  107. <li>PLYExporter</li>
  108. <li>STLExporter</li>
  109. <li>TypedGeometryExporter</li>
  110. </ul>
  111. </li>
  112. <li>geometries
  113. <ul>
  114. <li>BoxLineGeometry</li>
  115. <li>ConvexGeometry</li>
  116. <li>DecalGeometry</li>
  117. <li>ParametricGeometries</li>
  118. <li>TeapotBufferGeometry</li>
  119. </ul>
  120. </li>
  121. <li>interactive
  122. <ul>
  123. <li>SelectionBox</li>
  124. <li>SelectionHelper</li>
  125. </ul>
  126. </li>
  127. <li>lines
  128. <ul>
  129. <li>Line2</li>
  130. <li>LineGeometry</li>
  131. <li>LineMaterial</li>
  132. <li>LineSegments2</li>
  133. <li>LineSegmentsGeometry</li>
  134. <li>Wireframe</li>
  135. <li>WireframeGeometry2</li>
  136. </ul>
  137. </li>
  138. <li>loaders
  139. <ul>
  140. <li>3MFLoader</li>
  141. <li>AMFLoader</li>
  142. <li>AssimpJSONLoader</li>
  143. <li>AssimpLoader</li>
  144. <li>BabylonLoader</li>
  145. <li>BVHLoader</li>
  146. <li>ColladaLoader</li>
  147. <li>DDSLoader</li>
  148. <li>EXRLoader</li>
  149. <li>FBXLoader</li>
  150. <li>GCodeLoader</li>
  151. <li>GLTFLoader</li>
  152. <li>HDRCubeTextureLoader</li>
  153. <li>KMZLoader</li>
  154. <li>KTXLoader</li>
  155. <li>LWOLoader</li>
  156. <li>MTLLoader</li>
  157. <li>OBJLoader</li>
  158. <li>PCDLoader</li>
  159. <li>PDBLoader</li>
  160. <li>PlayCanvasLoader</li>
  161. <li>PLYLoader</li>
  162. <li>PRWMLoader</li>
  163. <li>PVRLoader</li>
  164. <li>RGBELoader</li>
  165. <li>STLLoader</li>
  166. <li>SVGLoader</li>
  167. <li>TDSLoader</li>
  168. <li>TGALoader</li>
  169. <li>VRMLLoader</li>
  170. <li>VTKLoader</li>
  171. </ul>
  172. </li>
  173. <li>math
  174. <ul>
  175. <li>ColorConverter</li>
  176. <li>ConvexHull</li>
  177. <li>ImprovedNoise</li>
  178. <li>Lut</li>
  179. <li>SimplexNoise</li>
  180. </ul>
  181. </li>
  182. <li>modifiers
  183. <ul>
  184. <li>ExplodeModifier</li>
  185. <li>SimplifyModifier</li>
  186. <li>SubdivisionModifier</li>
  187. <li>TessellateModifier</li>
  188. </ul>
  189. </li>
  190. <li>objects
  191. <ul>
  192. <li>Fire</li>
  193. <li>Lensflare</li>
  194. <li>Reflector</li>
  195. <li>Refractor</li>
  196. <li>ReflectorRTT</li>
  197. <li>ShadowMesh</li>
  198. <li>Sky</li>
  199. <li>Water</li>
  200. <li>Water2</li>
  201. </ul>
  202. </li>
  203. <li>pmrem
  204. <ul>
  205. <li>PMREMCubeUVPacker</li>
  206. <li>PMREMGenerator</li>
  207. </ul>
  208. </li>
  209. <li>postprocessing
  210. <ul>
  211. <li>AdaptiveToneMappingPass</li>
  212. <li>AfterimagePass</li>
  213. <li>BloomPass</li>
  214. <li>BokehPass</li>
  215. <li>ClearPass</li>
  216. <li>CubeTexturePass</li>
  217. <li>DotScreenPass</li>
  218. <li>EffectComposer</li>
  219. <li>FilmPass</li>
  220. <li>GlitchPass</li>
  221. <li>HalftonePass</li>
  222. <li>MaskPass</li>
  223. <li>OutlinePass</li>
  224. <li>RenderPass</li>
  225. <li>SAOPass</li>
  226. <li>SavePass</li>
  227. <li>ShaderPass</li>
  228. <li>SMAAPass</li>
  229. <li>SSAARenderPass</li>
  230. <li>SSAOPass</li>
  231. <li>TAARenderPass</li>
  232. <li>TexturePass</li>
  233. <li>UnrealBloomPass</li>
  234. </ul>
  235. </li>
  236. <li>renderers
  237. <ul>
  238. <li>CSS2DRenderer</li>
  239. <li>CSS3DRenderer</li>
  240. <li>Projector</li>
  241. <li>SoftwareRenderer</li>
  242. <li>SVGRenderer</li>
  243. <li>RaytracingRenderer</li>
  244. <li>WebGLDeferredRenderer</li>
  245. </ul>
  246. </li>
  247. <li>shaders
  248. <ul>
  249. <li>AfterimageShader</li>
  250. <li>BasicShader</li>
  251. <li>BleachBypassShader</li>
  252. <li>BlendShader</li>
  253. <li>BokehShader</li>
  254. <li>BokehShader2</li>
  255. <li>BrightnessContrastShader</li>
  256. <li>ColorCorrectionShader</li>
  257. <li>ColorifyShader</li>
  258. <li>ConvolutionShader</li>
  259. <li>CopyShader</li>
  260. <li>DepthLimitedBlurShader</li>
  261. <li>DigitalGlitch</li>
  262. <li>DOFMipMapShader</li>
  263. <li>DotScreenShader</li>
  264. <li>FilmShader</li>
  265. <li>FocusShader</li>
  266. <li>FreiChenShader</li>
  267. <li>FresnelShader</li>
  268. <li>FXAAShader</li>
  269. <li>GammaCorrectionShader</li>
  270. <li>GodRaysShader</li>
  271. <li>HalftoneShader</li>
  272. <li>HorizontalBlurShader</li>
  273. <li>HorizontalTiltShiftShader</li>
  274. <li>HueSaturationShader</li>
  275. <li>KaleidoShader</li>
  276. <li>LuminosityHighPassShader</li>
  277. <li>LuminosityShader</li>
  278. <li>MirrorShader</li>
  279. <li>NormalMapShader</li>
  280. <li>ParallaxShader</li>
  281. <li>PixelShader</li>
  282. <li>RGBShiftShader</li>
  283. <li>SAOShader</li>
  284. <li>SepiaShader</li>
  285. <li>SkinShader</li>
  286. <li>SMAAShader</li>
  287. <li>SobelOperatorShader</li>
  288. <li>SSAOShader</li>
  289. <li>TechnicolorShader</li>
  290. <li>TerrainShader</li>
  291. <li>ToneMapShader</li>
  292. <li>ToonShader</li>
  293. <li>TranslucentShader</li>
  294. <li>TriangleBlurShader</li>
  295. <li>UnpackDepthRGBAShader</li>
  296. <li>VerticalBlurShader</li>
  297. <li>VerticalTiltShiftShader</li>
  298. <li>VignetteShader</li>
  299. <li>VolumeShader</li>
  300. <li>WaterRefractionShader</li>
  301. </ul>
  302. </li>
  303. <li>utils
  304. <ul>
  305. <li>BufferGeometryUtils</li>
  306. <li>GeometryUtils</li>
  307. <li>MathUtils</li>
  308. <li>SceneUtils</li>
  309. <li>ShadowMapViewer</li>
  310. <li>SkeletonUtils</li>
  311. <li>TypedArrayUtils</li>
  312. <li>UVsDebug</li>
  313. </ul>
  314. </li>
  315. </ul>
  316. </p>
  317. <p>
  318. Note: When using code from the examples directory, it's important that all files match the version of
  319. your three.js main file. For example, it's not acceptable to use *GLTFLoader* and *OrbitControls* from R96 together
  320. with three.js R103. You can easily keep your files in sync by using the modules from the JSM directory. If the file
  321. is not available as a module, you can still use third-party npm packages or convert the file to a module by yourself.
  322. In both cases, ensure the code is compatible with your three.js main file.
  323. </p>
  324. </body>
  325. </html>