super-three 0.136.1 → 0.144.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (842) hide show
  1. package/README.md +31 -33
  2. package/build/three.cjs +36413 -0
  3. package/build/three.js +5108 -5809
  4. package/build/three.min.js +2 -2
  5. package/build/three.module.js +7877 -8586
  6. package/examples/js/animation/CCDIKSolver.js +3 -2
  7. package/examples/js/animation/MMDAnimationHelper.js +3 -1
  8. package/examples/js/animation/MMDPhysics.js +3 -18
  9. package/examples/js/controls/ArcballControls.js +19 -4
  10. package/examples/js/controls/FirstPersonControls.js +0 -7
  11. package/examples/js/controls/FlyControls.js +0 -8
  12. package/examples/js/controls/OrbitControls.js +0 -4
  13. package/examples/js/controls/PointerLockControls.js +3 -10
  14. package/examples/js/controls/TrackballControls.js +1 -6
  15. package/examples/js/controls/TransformControls.js +25 -22
  16. package/examples/js/csm/CSMFrustum.js +1 -1
  17. package/examples/js/csm/CSMShader.js +51 -35
  18. package/examples/js/curves/CurveExtras.js +14 -18
  19. package/examples/js/effects/AnaglyphEffect.js +9 -6
  20. package/examples/js/effects/AsciiEffect.js +10 -29
  21. package/examples/js/effects/OutlineEffect.js +4 -24
  22. package/examples/js/effects/ParallaxBarrierEffect.js +2 -2
  23. package/examples/js/effects/PeppersGhostEffect.js +2 -2
  24. package/examples/js/effects/StereoEffect.js +2 -2
  25. package/examples/js/environments/RoomEnvironment.js +22 -0
  26. package/examples/js/exporters/ColladaExporter.js +33 -20
  27. package/examples/js/exporters/DRACOExporter.js +0 -12
  28. package/examples/js/exporters/EXRExporter.js +458 -0
  29. package/examples/js/exporters/GLTFExporter.js +246 -119
  30. package/examples/js/exporters/OBJExporter.js +14 -41
  31. package/examples/js/exporters/PLYExporter.js +27 -44
  32. package/examples/js/exporters/STLExporter.js +0 -7
  33. package/examples/js/exporters/USDZExporter.js +19 -0
  34. package/examples/js/geometries/ConvexGeometry.js +1 -1
  35. package/examples/js/geometries/DecalGeometry.js +0 -7
  36. package/examples/js/geometries/LightningStrike.js +2 -2
  37. package/examples/js/geometries/ParametricGeometries.js +3 -3
  38. package/examples/js/geometries/ParametricGeometry.js +1 -8
  39. package/examples/js/geometries/TextGeometry.js +12 -10
  40. package/examples/js/helpers/OctreeHelper.js +74 -0
  41. package/examples/js/helpers/VertexNormalsHelper.js +4 -23
  42. package/examples/js/helpers/VertexTangentsHelper.js +3 -13
  43. package/examples/js/helpers/ViewHelper.js +266 -0
  44. package/examples/js/interactive/HTMLMesh.js +249 -42
  45. package/examples/js/interactive/SelectionHelper.js +3 -1
  46. package/examples/js/libs/ktx-parse.umd.js +1 -0
  47. package/examples/js/libs/meshopt_decoder.js +98 -32
  48. package/examples/js/libs/opentype.min.js +1 -118
  49. package/examples/js/lines/Line2.js +1 -2
  50. package/examples/js/lines/LineGeometry.js +10 -21
  51. package/examples/js/lines/LineMaterial.js +2 -3
  52. package/examples/js/lines/LineSegments2.js +214 -140
  53. package/examples/js/lines/LineSegmentsGeometry.js +3 -14
  54. package/examples/js/lines/Wireframe.js +2 -3
  55. package/examples/js/lines/WireframeGeometry2.js +1 -2
  56. package/examples/js/loaders/3MFLoader.js +21 -17
  57. package/examples/js/loaders/AMFLoader.js +1 -1
  58. package/examples/js/loaders/ColladaLoader.js +34 -12
  59. package/examples/js/loaders/DDSLoader.js +23 -30
  60. package/examples/js/loaders/DRACOLoader.js +2 -25
  61. package/examples/js/loaders/EXRLoader.js +279 -276
  62. package/examples/js/loaders/FBXLoader.js +21 -3
  63. package/examples/js/loaders/FontLoader.js +4 -18
  64. package/examples/js/loaders/GCodeLoader.js +0 -1
  65. package/examples/js/loaders/GLTFLoader.js +300 -95
  66. package/examples/js/loaders/HDRCubeTextureLoader.js +0 -11
  67. package/examples/js/loaders/KMZLoader.js +1 -1
  68. package/examples/js/loaders/LDrawLoader.js +653 -480
  69. package/examples/js/loaders/LUT3dlLoader.js +1 -1
  70. package/examples/js/loaders/LUTCubeLoader.js +1 -1
  71. package/examples/js/loaders/LWOLoader.js +4 -2
  72. package/examples/js/loaders/LogLuvLoader.js +1 -2
  73. package/examples/js/loaders/MD2Loader.js +5 -5
  74. package/examples/js/loaders/MMDLoader.js +18 -4
  75. package/examples/js/loaders/MTLLoader.js +10 -3
  76. package/examples/js/loaders/NRRDLoader.js +1 -1
  77. package/examples/js/loaders/OBJLoader.js +16 -18
  78. package/examples/js/loaders/PCDLoader.js +81 -27
  79. package/examples/js/loaders/PDBLoader.js +11 -11
  80. package/examples/js/loaders/PLYLoader.js +8 -4
  81. package/examples/js/loaders/RGBELoader.js +3 -11
  82. package/examples/js/loaders/RGBMLoader.js +12 -15
  83. package/examples/js/loaders/STLLoader.js +1 -1
  84. package/examples/js/loaders/SVGLoader.js +23 -14
  85. package/examples/js/loaders/TIFFLoader.js +31 -0
  86. package/examples/js/loaders/VOXLoader.js +3 -4
  87. package/examples/js/loaders/VRMLLoader.js +33 -24
  88. package/examples/js/loaders/VTKLoader.js +261 -296
  89. package/examples/js/loaders/lwo/LWO2Parser.js +12 -11
  90. package/examples/js/loaders/lwo/LWO3Parser.js +12 -11
  91. package/examples/js/materials/MeshGouraudMaterial.js +385 -0
  92. package/examples/js/math/ColorConverter.js +0 -50
  93. package/examples/js/math/ConvexHull.js +6 -15
  94. package/examples/js/math/Lut.js +27 -26
  95. package/examples/js/misc/GPUComputationRenderer.js +23 -0
  96. package/examples/js/misc/MorphAnimMesh.js +2 -2
  97. package/examples/js/misc/ProgressiveLightMap.js +1 -1
  98. package/examples/js/misc/Volume.js +233 -234
  99. package/examples/js/misc/VolumeSlice.js +108 -106
  100. package/examples/js/modifiers/EdgeSplitModifier.js +0 -13
  101. package/examples/js/modifiers/SimplifyModifier.js +2 -19
  102. package/examples/js/modifiers/TessellateModifier.js +0 -7
  103. package/examples/js/objects/GroundProjectedEnv.js +193 -0
  104. package/examples/js/objects/Lensflare.js +4 -4
  105. package/examples/js/objects/LightningStorm.js +4 -5
  106. package/examples/js/objects/MarchingCubes.js +6 -11
  107. package/examples/js/objects/Reflector.js +18 -5
  108. package/examples/js/objects/ReflectorForSSRPass.js +4 -5
  109. package/examples/js/objects/Refractor.js +19 -7
  110. package/examples/js/objects/ShadowMesh.js +6 -3
  111. package/examples/js/objects/Sky.js +1 -1
  112. package/examples/js/objects/Water.js +1 -2
  113. package/examples/js/objects/Water2.js +1 -1
  114. package/examples/js/postprocessing/AdaptiveToneMappingPass.js +6 -10
  115. package/examples/js/postprocessing/AfterimagePass.js +2 -6
  116. package/examples/js/postprocessing/BloomPass.js +50 -19
  117. package/examples/js/postprocessing/DotScreenPass.js +1 -1
  118. package/examples/js/postprocessing/EffectComposer.js +1 -6
  119. package/examples/js/postprocessing/LUTPass.js +2 -2
  120. package/examples/js/postprocessing/OutlinePass.js +13 -20
  121. package/examples/js/postprocessing/SAOPass.js +2 -7
  122. package/examples/js/postprocessing/SSAARenderPass.js +1 -6
  123. package/examples/js/postprocessing/SSRPass.js +3 -8
  124. package/examples/js/postprocessing/TAARenderPass.js +4 -4
  125. package/examples/js/postprocessing/UnrealBloomPass.js +3 -12
  126. package/examples/js/renderers/CSS2DRenderer.js +22 -21
  127. package/examples/js/renderers/CSS3DRenderer.js +42 -38
  128. package/examples/js/renderers/Projector.js +99 -147
  129. package/examples/js/renderers/SVGRenderer.js +3 -4
  130. package/examples/js/shaders/BlendShader.js +2 -1
  131. package/examples/js/shaders/CopyShader.js +4 -3
  132. package/examples/js/shaders/FXAAShader.js +239 -1069
  133. package/examples/js/shaders/FreiChenShader.js +1 -1
  134. package/examples/js/shaders/HorizontalBlurShader.js +1 -1
  135. package/examples/js/shaders/HorizontalTiltShiftShader.js +1 -1
  136. package/examples/js/shaders/LuminosityShader.js +1 -1
  137. package/examples/js/shaders/MMDToonShader.js +6 -2
  138. package/examples/js/shaders/SSRShader.js +3 -3
  139. package/examples/js/shaders/ToneMapShader.js +2 -2
  140. package/examples/js/utils/BufferGeometryUtils.js +282 -22
  141. package/examples/js/utils/GPUStatsPanel.js +1 -1
  142. package/examples/js/utils/GeometryUtils.js +2 -18
  143. package/examples/js/utils/LDrawUtils.js +182 -0
  144. package/examples/js/utils/PackedPhongMaterial.js +1 -1
  145. package/examples/js/utils/SceneUtils.js +57 -14
  146. package/examples/js/utils/SkeletonUtils.js +1 -1
  147. package/examples/js/utils/UVsDebug.js +23 -33
  148. package/examples/jsm/animation/CCDIKSolver.js +3 -9
  149. package/examples/jsm/animation/MMDPhysics.js +4 -23
  150. package/examples/jsm/capabilities/WebGPU.js +6 -0
  151. package/examples/jsm/controls/ArcballControls.js +19 -2
  152. package/examples/jsm/controls/FirstPersonControls.js +0 -7
  153. package/examples/jsm/controls/FlyControls.js +0 -7
  154. package/examples/jsm/controls/OrbitControls.js +0 -5
  155. package/examples/jsm/controls/PointerLockControls.js +4 -9
  156. package/examples/jsm/controls/TrackballControls.js +1 -7
  157. package/examples/jsm/controls/TransformControls.js +24 -22
  158. package/examples/jsm/csm/CSMFrustum.js +1 -1
  159. package/examples/jsm/csm/CSMShader.js +51 -35
  160. package/examples/jsm/curves/CurveExtras.js +15 -17
  161. package/examples/jsm/effects/AnaglyphEffect.js +6 -6
  162. package/examples/jsm/effects/AsciiEffect.js +9 -22
  163. package/examples/jsm/effects/OutlineEffect.js +4 -25
  164. package/examples/jsm/effects/ParallaxBarrierEffect.js +2 -2
  165. package/examples/jsm/effects/PeppersGhostEffect.js +2 -2
  166. package/examples/jsm/effects/StereoEffect.js +2 -2
  167. package/examples/jsm/environments/RoomEnvironment.js +23 -0
  168. package/examples/jsm/exporters/ColladaExporter.js +35 -19
  169. package/examples/jsm/exporters/DRACOExporter.js +0 -13
  170. package/examples/jsm/exporters/EXRExporter.js +507 -0
  171. package/examples/jsm/exporters/GLTFExporter.js +276 -104
  172. package/examples/jsm/exporters/KTX2Exporter.js +281 -0
  173. package/examples/jsm/exporters/OBJExporter.js +11 -36
  174. package/examples/jsm/exporters/PLYExporter.js +37 -43
  175. package/examples/jsm/exporters/STLExporter.js +1 -9
  176. package/examples/jsm/exporters/USDZExporter.js +26 -3
  177. package/examples/jsm/geometries/ConvexGeometry.js +1 -1
  178. package/examples/jsm/geometries/DecalGeometry.js +0 -7
  179. package/examples/jsm/geometries/LightningStrike.js +2 -2
  180. package/examples/jsm/geometries/ParametricGeometries.js +3 -3
  181. package/examples/jsm/geometries/ParametricGeometry.js +0 -6
  182. package/examples/jsm/geometries/TextGeometry.js +13 -13
  183. package/examples/jsm/helpers/OctreeHelper.js +58 -0
  184. package/examples/jsm/helpers/VertexNormalsHelper.js +4 -25
  185. package/examples/jsm/helpers/VertexTangentsHelper.js +3 -15
  186. package/examples/jsm/helpers/ViewHelper.js +295 -0
  187. package/examples/jsm/interactive/HTMLMesh.js +268 -36
  188. package/examples/jsm/interactive/SelectionHelper.js +6 -4
  189. package/examples/jsm/libs/flow.module.js +947 -183
  190. package/examples/jsm/libs/ktx-parse.module.js +1 -1
  191. package/examples/jsm/libs/meshopt_decoder.module.js +97 -32
  192. package/examples/jsm/libs/mikktspace.module.js +128 -0
  193. package/examples/jsm/libs/opentype.module.js +14568 -0
  194. package/examples/jsm/libs/utif.module.js +1579 -0
  195. package/examples/jsm/libs/zstddec.module.js +1 -0
  196. package/examples/jsm/lines/Line2.js +2 -2
  197. package/examples/jsm/lines/LineGeometry.js +11 -19
  198. package/examples/jsm/lines/LineMaterial.js +3 -3
  199. package/examples/jsm/lines/LineSegments2.js +210 -145
  200. package/examples/jsm/lines/LineSegmentsGeometry.js +3 -12
  201. package/examples/jsm/lines/Wireframe.js +3 -3
  202. package/examples/jsm/lines/WireframeGeometry2.js +2 -2
  203. package/examples/jsm/loaders/3DMLoader.js +3 -2
  204. package/examples/jsm/loaders/3MFLoader.js +21 -17
  205. package/examples/jsm/loaders/AMFLoader.js +1 -1
  206. package/examples/jsm/loaders/ColladaLoader.js +41 -12
  207. package/examples/jsm/loaders/DDSLoader.js +21 -28
  208. package/examples/jsm/loaders/DRACOLoader.js +2 -28
  209. package/examples/jsm/loaders/EXRLoader.js +278 -275
  210. package/examples/jsm/loaders/FBXLoader.js +21 -3
  211. package/examples/jsm/loaders/FontLoader.js +5 -18
  212. package/examples/jsm/loaders/GCodeLoader.js +0 -1
  213. package/examples/jsm/loaders/GLTFLoader.js +314 -101
  214. package/examples/jsm/loaders/HDRCubeTextureLoader.js +0 -13
  215. package/examples/jsm/loaders/KMZLoader.js +1 -1
  216. package/examples/jsm/loaders/KTX2Loader.js +193 -40
  217. package/examples/jsm/loaders/LDrawLoader.js +641 -495
  218. package/examples/jsm/loaders/LUT3dlLoader.js +2 -2
  219. package/examples/jsm/loaders/LUTCubeLoader.js +2 -2
  220. package/examples/jsm/loaders/LWOLoader.js +5 -3
  221. package/examples/jsm/loaders/LogLuvLoader.js +2 -2
  222. package/examples/jsm/loaders/MD2Loader.js +5 -5
  223. package/examples/jsm/loaders/MMDLoader.js +21 -3
  224. package/examples/jsm/loaders/MTLLoader.js +11 -4
  225. package/examples/jsm/loaders/NRRDLoader.js +1 -2
  226. package/examples/jsm/loaders/OBJLoader.js +17 -21
  227. package/examples/jsm/loaders/PCDLoader.js +82 -28
  228. package/examples/jsm/loaders/PDBLoader.js +11 -11
  229. package/examples/jsm/loaders/PLYLoader.js +13 -5
  230. package/examples/jsm/loaders/RGBELoader.js +4 -12
  231. package/examples/jsm/loaders/RGBMLoader.js +14 -11
  232. package/examples/jsm/loaders/STLLoader.js +1 -1
  233. package/examples/jsm/loaders/SVGLoader.js +24 -13
  234. package/examples/jsm/loaders/TIFFLoader.js +36 -0
  235. package/examples/jsm/loaders/TTFLoader.js +1 -1
  236. package/examples/jsm/loaders/USDZLoader.js +393 -0
  237. package/examples/jsm/loaders/VOXLoader.js +5 -5
  238. package/examples/jsm/loaders/VRMLLoader.js +23 -26
  239. package/examples/jsm/loaders/VTKLoader.js +257 -285
  240. package/examples/jsm/loaders/ifc/web-ifc-api.js +9 -8
  241. package/examples/jsm/loaders/lwo/LWO2Parser.js +10 -12
  242. package/examples/jsm/loaders/lwo/LWO3Parser.js +10 -12
  243. package/examples/jsm/materials/MeshGouraudMaterial.js +423 -0
  244. package/examples/jsm/math/ColorConverter.js +1 -49
  245. package/examples/jsm/math/ConvexHull.js +6 -15
  246. package/examples/jsm/math/Lut.js +35 -25
  247. package/examples/jsm/misc/GPUComputationRenderer.js +43 -0
  248. package/examples/jsm/misc/MorphAnimMesh.js +2 -2
  249. package/examples/jsm/misc/ProgressiveLightMap.js +1 -1
  250. package/examples/jsm/misc/Volume.js +204 -213
  251. package/examples/jsm/misc/VolumeSlice.js +96 -98
  252. package/examples/jsm/modifiers/EdgeSplitModifier.js +0 -13
  253. package/examples/jsm/modifiers/SimplifyModifier.js +2 -19
  254. package/examples/jsm/modifiers/TessellateModifier.js +0 -7
  255. package/examples/jsm/node-editor/NodeEditor.js +505 -182
  256. package/examples/jsm/node-editor/accessors/MatcapUVEditor.js +14 -0
  257. package/examples/jsm/node-editor/accessors/NormalEditor.js +9 -9
  258. package/examples/jsm/node-editor/accessors/PositionEditor.js +9 -9
  259. package/examples/jsm/node-editor/accessors/UVEditor.js +7 -8
  260. package/examples/jsm/node-editor/core/BaseNode.js +89 -0
  261. package/examples/jsm/node-editor/core/DataFile.js +59 -0
  262. package/examples/jsm/node-editor/core/FileEditor.js +20 -0
  263. package/examples/jsm/node-editor/core/FileURLEditor.js +29 -0
  264. package/examples/jsm/node-editor/display/BlendEditor.js +10 -9
  265. package/examples/jsm/node-editor/display/NormalMapEditor.js +49 -0
  266. package/examples/jsm/node-editor/examples/animate-uv.json +1 -1
  267. package/examples/jsm/node-editor/examples/fake-top-light.json +1 -1
  268. package/examples/jsm/node-editor/examples/matcap.json +1 -0
  269. package/examples/jsm/node-editor/examples/oscillator-color.json +1 -1
  270. package/examples/jsm/node-editor/examples/rim.json +1 -1
  271. package/examples/jsm/node-editor/inputs/ColorEditor.js +18 -13
  272. package/examples/jsm/node-editor/inputs/FloatEditor.js +8 -9
  273. package/examples/jsm/node-editor/inputs/SliderEditor.js +6 -7
  274. package/examples/jsm/node-editor/inputs/TextureEditor.js +155 -0
  275. package/examples/jsm/node-editor/inputs/Vector2Editor.js +9 -9
  276. package/examples/jsm/node-editor/inputs/Vector3Editor.js +11 -11
  277. package/examples/jsm/node-editor/inputs/Vector4Editor.js +12 -12
  278. package/examples/jsm/node-editor/materials/BasicMaterialEditor.js +87 -0
  279. package/examples/jsm/node-editor/materials/PointsMaterialEditor.js +102 -0
  280. package/examples/jsm/node-editor/materials/StandardMaterialEditor.js +31 -18
  281. package/examples/jsm/node-editor/math/AngleEditor.js +40 -0
  282. package/examples/jsm/node-editor/math/DotEditor.js +8 -9
  283. package/examples/jsm/node-editor/math/InvertEditor.js +8 -7
  284. package/examples/jsm/node-editor/math/LimiterEditor.js +28 -14
  285. package/examples/jsm/node-editor/math/NormalizeEditor.js +9 -7
  286. package/examples/jsm/node-editor/math/OperatorEditor.js +29 -16
  287. package/examples/jsm/node-editor/math/PowerEditor.js +20 -10
  288. package/examples/jsm/node-editor/math/TrigonometryEditor.js +15 -9
  289. package/examples/jsm/node-editor/procedural/CheckerEditor.js +7 -6
  290. package/examples/jsm/node-editor/scene/MeshEditor.js +99 -0
  291. package/examples/jsm/node-editor/scene/Object3DEditor.js +160 -0
  292. package/examples/jsm/node-editor/scene/PointsEditor.js +99 -0
  293. package/examples/jsm/node-editor/utils/JoinEditor.js +58 -0
  294. package/examples/jsm/node-editor/utils/OscillatorEditor.js +9 -8
  295. package/examples/jsm/node-editor/utils/PreviewEditor.js +166 -0
  296. package/examples/jsm/node-editor/utils/SplitEditor.js +39 -0
  297. package/examples/jsm/node-editor/utils/TimerEditor.js +7 -6
  298. package/examples/jsm/nodes/Nodes.js +313 -94
  299. package/examples/jsm/nodes/accessors/BufferNode.js +24 -0
  300. package/examples/jsm/nodes/accessors/CameraNode.js +27 -196
  301. package/examples/jsm/nodes/accessors/CubeTextureNode.js +107 -0
  302. package/examples/jsm/nodes/accessors/InstanceNode.js +58 -0
  303. package/examples/jsm/{renderers/nodes → nodes}/accessors/MaterialNode.js +49 -11
  304. package/examples/jsm/{renderers/nodes → nodes}/accessors/MaterialReferenceNode.js +0 -0
  305. package/examples/jsm/{renderers/nodes → nodes}/accessors/ModelNode.js +8 -0
  306. package/examples/jsm/{renderers/nodes → nodes}/accessors/ModelViewProjectionNode.js +0 -0
  307. package/examples/jsm/nodes/accessors/NormalNode.js +39 -99
  308. package/examples/jsm/{renderers/nodes → nodes}/accessors/Object3DNode.js +34 -17
  309. package/examples/jsm/{renderers/nodes → nodes}/accessors/PointUVNode.js +2 -2
  310. package/examples/jsm/nodes/accessors/PositionNode.js +41 -110
  311. package/examples/jsm/nodes/accessors/ReferenceNode.js +65 -0
  312. package/examples/jsm/nodes/accessors/ReflectVectorNode.js +31 -0
  313. package/examples/jsm/nodes/accessors/SkinningNode.js +102 -0
  314. package/examples/jsm/nodes/accessors/StorageBufferNode.js +21 -0
  315. package/examples/jsm/nodes/accessors/TextureNode.js +100 -0
  316. package/examples/jsm/nodes/accessors/UVNode.js +17 -43
  317. package/examples/jsm/nodes/accessors/UserDataNode.js +23 -0
  318. package/examples/jsm/nodes/core/ArrayUniformNode.js +23 -0
  319. package/examples/jsm/nodes/core/AttributeNode.js +33 -30
  320. package/examples/jsm/{renderers/nodes → nodes}/core/BypassNode.js +2 -2
  321. package/examples/jsm/nodes/core/CodeNode.js +50 -0
  322. package/examples/jsm/nodes/core/ConstNode.js +10 -106
  323. package/examples/jsm/{renderers/nodes → nodes}/core/ContextNode.js +17 -3
  324. package/examples/jsm/nodes/core/ExpressionNode.js +24 -7
  325. package/examples/jsm/nodes/core/FunctionCallNode.js +33 -59
  326. package/examples/jsm/nodes/core/FunctionNode.js +43 -216
  327. package/examples/jsm/nodes/core/InputNode.js +28 -60
  328. package/examples/jsm/nodes/core/InstanceIndexNode.js +21 -0
  329. package/examples/jsm/nodes/core/Node.js +230 -94
  330. package/examples/jsm/{renderers/nodes → nodes}/core/NodeAttribute.js +2 -2
  331. package/examples/jsm/nodes/core/NodeBuilder.js +388 -560
  332. package/examples/jsm/{renderers/nodes → nodes}/core/NodeCode.js +0 -0
  333. package/examples/jsm/nodes/core/NodeFrame.js +30 -23
  334. package/examples/jsm/{renderers/nodes → nodes}/core/NodeFunction.js +0 -0
  335. package/examples/jsm/{renderers/nodes → nodes}/core/NodeFunctionInput.js +0 -0
  336. package/examples/jsm/{renderers/nodes → nodes}/core/NodeKeywords.js +0 -0
  337. package/examples/jsm/{renderers/nodes → nodes}/core/NodeParser.js +0 -0
  338. package/examples/jsm/nodes/core/NodeUniform.js +8 -6
  339. package/examples/jsm/nodes/core/NodeUtils.js +90 -36
  340. package/examples/jsm/{renderers/nodes → nodes}/core/NodeVar.js +2 -2
  341. package/examples/jsm/{renderers/nodes/core/NodeVary.js → nodes/core/NodeVarying.js} +4 -4
  342. package/examples/jsm/{renderers/nodes → nodes}/core/PropertyNode.js +0 -0
  343. package/examples/jsm/nodes/core/TempNode.js +20 -112
  344. package/examples/jsm/nodes/core/UniformNode.js +46 -0
  345. package/examples/jsm/nodes/core/VarNode.js +58 -27
  346. package/examples/jsm/{renderers/nodes/core/VaryNode.js → nodes/core/VaryingNode.js} +7 -7
  347. package/examples/jsm/{renderers/nodes → nodes}/core/constants.js +0 -0
  348. package/examples/jsm/nodes/display/ColorAdjustmentNode.js +94 -0
  349. package/examples/jsm/{renderers/nodes → nodes}/display/ColorSpaceNode.js +10 -11
  350. package/examples/jsm/nodes/display/FrontFacingNode.js +21 -0
  351. package/examples/jsm/nodes/display/NormalMapNode.js +86 -0
  352. package/examples/jsm/nodes/display/ToneMappingNode.js +51 -0
  353. package/examples/jsm/nodes/fog/FogNode.js +31 -0
  354. package/examples/jsm/nodes/fog/FogRangeNode.js +27 -0
  355. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +33 -0
  356. package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +9 -0
  357. package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +27 -0
  358. package/examples/jsm/nodes/functions/BSDF/D_GGX.js +18 -0
  359. package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +18 -0
  360. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +18 -0
  361. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +94 -0
  362. package/examples/jsm/nodes/functions/light/getDistanceAttenuation.js +22 -0
  363. package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +12 -0
  364. package/examples/jsm/nodes/functions/material/getRoughness.js +18 -0
  365. package/examples/jsm/nodes/geometry/RangeNode.js +109 -0
  366. package/examples/jsm/nodes/gpgpu/ComputeNode.js +65 -0
  367. package/examples/jsm/nodes/lighting/AONode.js +25 -0
  368. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +37 -0
  369. package/examples/jsm/nodes/lighting/EnvironmentNode.js +66 -0
  370. package/examples/jsm/nodes/lighting/HemisphereLightNode.js +50 -0
  371. package/examples/jsm/nodes/lighting/LightingContextNode.js +75 -0
  372. package/examples/jsm/nodes/lighting/LightingNode.js +19 -0
  373. package/examples/jsm/nodes/lighting/LightsNode.js +120 -0
  374. package/examples/jsm/nodes/lighting/PunctualLightNode.js +68 -0
  375. package/examples/jsm/nodes/loaders/NodeLoader.js +107 -0
  376. package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +73 -0
  377. package/examples/jsm/nodes/loaders/NodeObjectLoader.js +70 -0
  378. package/examples/jsm/{renderers/nodes → nodes}/materials/LineBasicNodeMaterial.js +11 -4
  379. package/examples/jsm/nodes/materials/Materials.js +53 -0
  380. package/examples/jsm/{renderers/nodes → nodes}/materials/MeshBasicNodeMaterial.js +13 -4
  381. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +70 -0
  382. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +159 -22
  383. package/examples/jsm/nodes/materials/NodeMaterial.js +128 -113
  384. package/examples/jsm/{renderers/nodes → nodes}/materials/PointsNodeMaterial.js +13 -4
  385. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +95 -16
  386. package/examples/jsm/nodes/materialx/Disclaimer.md +199 -0
  387. package/examples/jsm/nodes/materialx/functions/lib/mx_hsv.js +56 -0
  388. package/examples/jsm/nodes/materialx/functions/lib/mx_noise.js +607 -0
  389. package/examples/jsm/nodes/math/CondNode.js +26 -95
  390. package/examples/jsm/nodes/math/MathNode.js +156 -189
  391. package/examples/jsm/nodes/math/OperatorNode.js +161 -41
  392. package/examples/jsm/{renderers/nodes → nodes}/parsers/GLSLNodeFunction.js +23 -8
  393. package/examples/jsm/{renderers/nodes → nodes}/parsers/GLSLNodeParser.js +0 -0
  394. package/examples/jsm/{renderers/nodes → nodes}/parsers/WGSLNodeFunction.js +20 -5
  395. package/examples/jsm/{renderers/nodes → nodes}/parsers/WGSLNodeParser.js +0 -0
  396. package/examples/jsm/nodes/procedural/CheckerNode.js +16 -57
  397. package/examples/jsm/nodes/shadernode/ShaderNode.js +262 -0
  398. package/examples/jsm/nodes/shadernode/ShaderNodeBaseElements.js +277 -0
  399. package/examples/jsm/nodes/shadernode/ShaderNodeElements.js +120 -0
  400. package/examples/jsm/{renderers/nodes → nodes}/utils/ArrayElementNode.js +3 -3
  401. package/examples/jsm/nodes/utils/ConvertNode.js +46 -0
  402. package/examples/jsm/nodes/utils/JoinNode.js +15 -87
  403. package/examples/jsm/nodes/utils/MatcapUVNode.js +25 -0
  404. package/examples/jsm/nodes/utils/MaxMipLevelNode.js +33 -0
  405. package/examples/jsm/{renderers/nodes → nodes}/utils/OscNode.js +18 -2
  406. package/examples/jsm/nodes/utils/RotateUVNode.js +32 -0
  407. package/examples/jsm/nodes/utils/SplitNode.js +102 -0
  408. package/examples/jsm/{renderers/nodes → nodes}/utils/SpriteSheetUVNode.js +3 -3
  409. package/examples/jsm/nodes/utils/TimerNode.js +30 -65
  410. package/examples/jsm/objects/GroundProjectedEnv.js +186 -0
  411. package/examples/jsm/objects/Lensflare.js +2 -2
  412. package/examples/jsm/objects/LightningStorm.js +4 -4
  413. package/examples/jsm/objects/MarchingCubes.js +5 -9
  414. package/examples/jsm/objects/Reflector.js +19 -8
  415. package/examples/jsm/objects/ReflectorForSSRPass.js +5 -7
  416. package/examples/jsm/objects/Refractor.js +19 -9
  417. package/examples/jsm/objects/ShadowMesh.js +10 -4
  418. package/examples/jsm/objects/Sky.js +2 -2
  419. package/examples/jsm/objects/Water.js +2 -2
  420. package/examples/jsm/objects/Water2.js +2 -2
  421. package/examples/jsm/offscreen/jank.js +5 -5
  422. package/examples/jsm/offscreen/offscreen.js +1 -1
  423. package/examples/jsm/offscreen/scene.js +11 -11
  424. package/examples/jsm/postprocessing/AdaptiveToneMappingPass.js +5 -7
  425. package/examples/jsm/postprocessing/AfterimagePass.js +0 -10
  426. package/examples/jsm/postprocessing/BloomPass.js +48 -20
  427. package/examples/jsm/postprocessing/DotScreenPass.js +1 -1
  428. package/examples/jsm/postprocessing/EffectComposer.js +1 -9
  429. package/examples/jsm/postprocessing/LUTPass.js +2 -2
  430. package/examples/jsm/postprocessing/OutlinePass.js +13 -18
  431. package/examples/jsm/postprocessing/SAOPass.js +2 -9
  432. package/examples/jsm/postprocessing/SSAARenderPass.js +1 -4
  433. package/examples/jsm/postprocessing/SSRPass.js +3 -9
  434. package/examples/jsm/postprocessing/TAARenderPass.js +4 -4
  435. package/examples/jsm/postprocessing/UnrealBloomPass.js +3 -8
  436. package/examples/jsm/renderers/CSS2DRenderer.js +23 -21
  437. package/examples/jsm/renderers/CSS3DRenderer.js +41 -36
  438. package/examples/jsm/renderers/Projector.js +103 -152
  439. package/examples/jsm/renderers/SVGRenderer.js +4 -4
  440. package/examples/jsm/renderers/webgl/nodes/SlotNode.js +9 -5
  441. package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +398 -183
  442. package/examples/jsm/renderers/webgl/nodes/WebGLNodes.js +19 -4
  443. package/examples/jsm/renderers/webgpu/WebGPUAttributes.js +4 -4
  444. package/examples/jsm/renderers/webgpu/WebGPUBackground.js +55 -13
  445. package/examples/jsm/renderers/webgpu/WebGPUBindings.js +8 -7
  446. package/examples/jsm/renderers/webgpu/WebGPUBuffer.js +43 -0
  447. package/examples/jsm/renderers/webgpu/WebGPUComputePipelines.js +20 -7
  448. package/examples/jsm/renderers/webgpu/WebGPUGeometries.js +6 -0
  449. package/examples/jsm/renderers/webgpu/WebGPUInfo.js +1 -1
  450. package/examples/jsm/renderers/webgpu/WebGPUObjects.js +1 -7
  451. package/examples/jsm/renderers/webgpu/WebGPURenderPipeline.js +37 -39
  452. package/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js +18 -15
  453. package/examples/jsm/renderers/webgpu/WebGPURenderStates.js +66 -0
  454. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +103 -95
  455. package/examples/jsm/renderers/webgpu/WebGPUSampledTexture.js +14 -14
  456. package/examples/jsm/renderers/webgpu/WebGPUSampler.js +2 -2
  457. package/examples/jsm/renderers/webgpu/WebGPUStorageBuffer.js +5 -8
  458. package/examples/jsm/renderers/webgpu/WebGPUTextureUtils.js +25 -20
  459. package/examples/jsm/renderers/webgpu/WebGPUTextures.js +37 -18
  460. package/examples/jsm/renderers/webgpu/WebGPUUniform.js +14 -14
  461. package/examples/jsm/renderers/webgpu/WebGPUUniformBuffer.js +5 -32
  462. package/examples/jsm/renderers/webgpu/WebGPUUniformsGroup.js +2 -2
  463. package/examples/jsm/renderers/webgpu/WebGPUUtils.js +81 -0
  464. package/examples/jsm/renderers/webgpu/constants.js +3 -2
  465. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js +287 -300
  466. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeSampledTexture.js +20 -2
  467. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodes.js +24 -14
  468. package/examples/jsm/shaders/BlendShader.js +2 -1
  469. package/examples/jsm/shaders/CopyShader.js +4 -3
  470. package/examples/jsm/shaders/FXAAShader.js +219 -1051
  471. package/examples/jsm/shaders/FreiChenShader.js +1 -1
  472. package/examples/jsm/shaders/HorizontalBlurShader.js +1 -1
  473. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +1 -1
  474. package/examples/jsm/shaders/LuminosityShader.js +1 -1
  475. package/examples/jsm/shaders/MMDToonShader.js +2 -2
  476. package/examples/jsm/shaders/SSRShader.js +3 -3
  477. package/examples/jsm/shaders/ToneMapShader.js +2 -2
  478. package/examples/jsm/utils/BufferGeometryUtils.js +293 -22
  479. package/examples/jsm/utils/GPUStatsPanel.js +1 -1
  480. package/examples/jsm/utils/GeometryUtils.js +17 -25
  481. package/examples/jsm/utils/LDrawUtils.js +24 -17
  482. package/examples/jsm/utils/PackedPhongMaterial.js +0 -1
  483. package/examples/jsm/utils/SceneUtils.js +73 -19
  484. package/examples/jsm/utils/SkeletonUtils.js +1 -1
  485. package/examples/jsm/utils/UVsDebug.js +23 -32
  486. package/examples/jsm/webxr/ARButton.js +14 -4
  487. package/examples/jsm/webxr/OculusHandPointerModel.js +9 -4
  488. package/examples/jsm/webxr/Text2D.js +1 -1
  489. package/examples/jsm/webxr/VRButton.js +16 -8
  490. package/examples/jsm/webxr/XRHandMeshModel.js +3 -7
  491. package/examples/jsm/webxr/XRHandModelFactory.js +3 -0
  492. package/package.json +57 -28
  493. package/src/Three.Legacy.js +164 -1809
  494. package/src/Three.js +9 -5
  495. package/src/animation/AnimationAction.js +6 -5
  496. package/src/animation/AnimationClip.js +2 -2
  497. package/src/animation/AnimationMixer.js +5 -3
  498. package/src/animation/AnimationObjectGroup.js +2 -2
  499. package/src/animation/AnimationUtils.js +204 -199
  500. package/src/animation/KeyframeTrack.js +1 -1
  501. package/src/animation/PropertyBinding.js +32 -23
  502. package/src/audio/PositionalAudio.js +8 -0
  503. package/src/cameras/ArrayCamera.js +2 -3
  504. package/src/cameras/Camera.js +2 -2
  505. package/src/cameras/CubeCamera.js +6 -8
  506. package/src/cameras/OrthographicCamera.js +2 -2
  507. package/src/cameras/PerspectiveCamera.js +2 -2
  508. package/src/constants.js +7 -6
  509. package/src/core/BufferAttribute.js +88 -123
  510. package/src/core/BufferGeometry.js +9 -47
  511. package/src/core/GLBufferAttribute.js +2 -2
  512. package/src/core/InstancedBufferAttribute.js +2 -12
  513. package/src/core/InstancedBufferGeometry.js +2 -2
  514. package/src/core/InstancedInterleavedBuffer.js +2 -2
  515. package/src/core/InterleavedBuffer.js +3 -3
  516. package/src/core/InterleavedBufferAttribute.js +61 -18
  517. package/src/core/Object3D.js +28 -8
  518. package/src/core/Raycaster.js +2 -2
  519. package/src/core/Uniform.js +0 -7
  520. package/src/core/UniformsGroup.js +92 -0
  521. package/src/extras/DataUtils.js +144 -41
  522. package/src/extras/Earcut.js +2 -2
  523. package/src/extras/PMREMGenerator.js +132 -104
  524. package/src/extras/core/CurvePath.js +3 -3
  525. package/src/extras/core/Path.js +1 -0
  526. package/src/extras/core/ShapePath.js +6 -10
  527. package/src/extras/curves/ArcCurve.js +2 -2
  528. package/src/extras/curves/CatmullRomCurve3.js +6 -4
  529. package/src/extras/curves/CubicBezierCurve.js +2 -2
  530. package/src/extras/curves/CubicBezierCurve3.js +2 -2
  531. package/src/extras/curves/EllipseCurve.js +2 -2
  532. package/src/extras/curves/LineCurve.js +2 -2
  533. package/src/extras/curves/LineCurve3.js +2 -1
  534. package/src/extras/curves/QuadraticBezierCurve.js +2 -2
  535. package/src/extras/curves/QuadraticBezierCurve3.js +2 -2
  536. package/src/extras/curves/SplineCurve.js +2 -2
  537. package/src/geometries/BoxGeometry.js +1 -1
  538. package/src/geometries/CapsuleGeometry.js +33 -0
  539. package/src/geometries/CircleGeometry.js +1 -1
  540. package/src/geometries/ConeGeometry.js +1 -1
  541. package/src/geometries/CylinderGeometry.js +2 -1
  542. package/src/geometries/DodecahedronGeometry.js +1 -1
  543. package/src/geometries/EdgesGeometry.js +5 -4
  544. package/src/geometries/ExtrudeGeometry.js +4 -11
  545. package/src/geometries/Geometries.js +1 -0
  546. package/src/geometries/IcosahedronGeometry.js +1 -1
  547. package/src/geometries/LatheGeometry.js +3 -3
  548. package/src/geometries/OctahedronGeometry.js +1 -1
  549. package/src/geometries/PlaneGeometry.js +2 -1
  550. package/src/geometries/PolyhedronGeometry.js +1 -1
  551. package/src/geometries/RingGeometry.js +1 -1
  552. package/src/geometries/ShapeGeometry.js +2 -1
  553. package/src/geometries/SphereGeometry.js +2 -1
  554. package/src/geometries/TetrahedronGeometry.js +1 -1
  555. package/src/geometries/TorusGeometry.js +2 -1
  556. package/src/geometries/TorusKnotGeometry.js +4 -3
  557. package/src/geometries/TubeGeometry.js +2 -1
  558. package/src/geometries/WireframeGeometry.js +4 -2
  559. package/src/helpers/BoxHelper.js +2 -2
  560. package/src/helpers/CameraHelper.js +97 -38
  561. package/src/helpers/DirectionalLightHelper.js +1 -0
  562. package/src/helpers/HemisphereLightHelper.js +1 -0
  563. package/src/helpers/PlaneHelper.js +6 -9
  564. package/src/helpers/PointLightHelper.js +1 -1
  565. package/src/helpers/PolarGridHelper.js +18 -14
  566. package/src/helpers/SkeletonHelper.js +3 -2
  567. package/src/helpers/SpotLightHelper.js +1 -0
  568. package/src/lights/AmbientLight.js +2 -2
  569. package/src/lights/AmbientLightProbe.js +2 -2
  570. package/src/lights/DirectionalLight.js +2 -2
  571. package/src/lights/DirectionalLightShadow.js +2 -2
  572. package/src/lights/HemisphereLight.js +4 -4
  573. package/src/lights/HemisphereLightProbe.js +2 -2
  574. package/src/lights/Light.js +4 -4
  575. package/src/lights/LightProbe.js +2 -2
  576. package/src/lights/PointLight.js +4 -4
  577. package/src/lights/PointLightShadow.js +2 -2
  578. package/src/lights/RectAreaLight.js +2 -2
  579. package/src/lights/SpotLight.js +6 -4
  580. package/src/lights/SpotLightShadow.js +2 -2
  581. package/src/loaders/FileLoader.js +35 -5
  582. package/src/loaders/ImageBitmapLoader.js +2 -2
  583. package/src/loaders/ImageLoader.js +1 -1
  584. package/src/loaders/LoaderUtils.js +1 -1
  585. package/src/loaders/LoadingManager.js +1 -1
  586. package/src/loaders/MaterialLoader.js +55 -8
  587. package/src/loaders/ObjectLoader.js +27 -66
  588. package/src/materials/LineBasicMaterial.js +6 -13
  589. package/src/materials/LineDashedMaterial.js +2 -15
  590. package/src/materials/Material.js +26 -24
  591. package/src/materials/Materials.js +39 -18
  592. package/src/materials/MeshBasicMaterial.js +6 -31
  593. package/src/materials/MeshDepthMaterial.js +2 -22
  594. package/src/materials/MeshDistanceMaterial.js +2 -22
  595. package/src/materials/MeshLambertMaterial.js +34 -35
  596. package/src/materials/MeshMatcapMaterial.js +6 -28
  597. package/src/materials/MeshNormalMaterial.js +2 -26
  598. package/src/materials/MeshPhongMaterial.js +6 -48
  599. package/src/materials/MeshPhysicalMaterial.js +32 -35
  600. package/src/materials/MeshStandardMaterial.js +6 -54
  601. package/src/materials/MeshToonMaterial.js +6 -38
  602. package/src/materials/PointsMaterial.js +6 -15
  603. package/src/materials/RawShaderMaterial.js +2 -2
  604. package/src/materials/ShaderMaterial.js +6 -24
  605. package/src/materials/ShadowMaterial.js +6 -8
  606. package/src/materials/SpriteMaterial.js +6 -12
  607. package/src/math/Box2.js +2 -2
  608. package/src/math/Box3.js +29 -15
  609. package/src/math/Color.js +87 -48
  610. package/src/math/ColorManagement.js +74 -0
  611. package/src/math/Euler.js +16 -14
  612. package/src/math/Interpolant.js +4 -9
  613. package/src/math/MathUtils.js +77 -14
  614. package/src/math/Matrix3.js +2 -8
  615. package/src/math/Matrix4.js +3 -28
  616. package/src/math/Plane.js +2 -2
  617. package/src/math/Quaternion.js +12 -23
  618. package/src/math/Spherical.js +1 -1
  619. package/src/math/SphericalHarmonics3.js +2 -2
  620. package/src/math/Vector2.js +5 -25
  621. package/src/math/Vector3.js +17 -47
  622. package/src/math/Vector4.js +5 -25
  623. package/src/math/interpolants/DiscreteInterpolant.js +1 -1
  624. package/src/objects/Bone.js +2 -2
  625. package/src/objects/Group.js +2 -2
  626. package/src/objects/InstancedMesh.js +4 -4
  627. package/src/objects/Line.js +76 -107
  628. package/src/objects/LineLoop.js +2 -2
  629. package/src/objects/LineSegments.js +15 -23
  630. package/src/objects/Mesh.js +82 -104
  631. package/src/objects/Points.js +32 -54
  632. package/src/objects/SkinnedMesh.js +5 -8
  633. package/src/objects/Sprite.js +4 -4
  634. package/src/renderers/WebGL3DRenderTarget.js +22 -0
  635. package/src/renderers/WebGLArrayRenderTarget.js +22 -0
  636. package/src/renderers/WebGLCubeRenderTarget.js +7 -14
  637. package/src/renderers/WebGLMultipleRenderTargets.js +8 -5
  638. package/src/renderers/WebGLRenderTarget.js +19 -18
  639. package/src/renderers/WebGLRenderer.js +195 -74
  640. package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +46 -0
  641. package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +3 -5
  642. package/src/renderers/shaders/ShaderChunk/common.glsl.js +7 -5
  643. package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +35 -36
  644. package/src/renderers/shaders/ShaderChunk/dithering_pars_fragment.glsl.js +1 -1
  645. package/src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl.js +1 -1
  646. package/src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl.js +1 -1
  647. package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +3 -19
  648. package/src/renderers/shaders/ShaderChunk/gradientmap_pars_fragment.glsl.js +2 -1
  649. package/src/renderers/shaders/ShaderChunk/iridescence_fragment.glsl.js +121 -0
  650. package/src/renderers/shaders/ShaderChunk/iridescence_pars_fragment.glsl.js +14 -0
  651. package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +0 -6
  652. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +48 -1
  653. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +0 -6
  654. package/src/renderers/shaders/ShaderChunk/lights_lambert_fragment.glsl.js +5 -0
  655. package/src/renderers/shaders/ShaderChunk/lights_lambert_pars_fragment.glsl.js +30 -0
  656. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +26 -1
  657. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +56 -6
  658. package/src/renderers/shaders/ShaderChunk/morphcolor_vertex.glsl.js +24 -0
  659. package/src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl.js +1 -1
  660. package/src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js +7 -7
  661. package/src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl.js +1 -9
  662. package/src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js +2 -4
  663. package/src/renderers/shaders/ShaderChunk/output_fragment.glsl.js +1 -1
  664. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +18 -7
  665. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +8 -3
  666. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +9 -6
  667. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
  668. package/src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl.js +16 -31
  669. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +14 -10
  670. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +1 -1
  671. package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +1 -1
  672. package/src/renderers/shaders/ShaderChunk.js +10 -2
  673. package/src/renderers/shaders/ShaderLib/background.glsl.js +8 -0
  674. package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +1 -0
  675. package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +3 -3
  676. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +23 -50
  677. package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +1 -0
  678. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +6 -0
  679. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +1 -1
  680. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +10 -0
  681. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +1 -0
  682. package/src/renderers/shaders/ShaderLib/points.glsl.js +1 -0
  683. package/src/renderers/shaders/ShaderLib.js +37 -31
  684. package/src/renderers/shaders/UniformsLib.js +14 -13
  685. package/src/renderers/shaders/UniformsUtils.js +14 -0
  686. package/src/renderers/webgl/WebGLAttributes.js +6 -6
  687. package/src/renderers/webgl/WebGLBackground.js +7 -4
  688. package/src/renderers/webgl/WebGLBindingStates.js +57 -29
  689. package/src/renderers/webgl/WebGLGeometries.js +2 -2
  690. package/src/renderers/webgl/WebGLLights.js +37 -14
  691. package/src/renderers/webgl/WebGLMaterials.js +72 -187
  692. package/src/renderers/webgl/WebGLMorphtargets.js +43 -39
  693. package/src/renderers/webgl/WebGLProgram.js +63 -30
  694. package/src/renderers/webgl/WebGLPrograms.js +97 -104
  695. package/src/renderers/webgl/WebGLRenderLists.js +5 -4
  696. package/src/renderers/webgl/WebGLRenderStates.js +5 -4
  697. package/src/renderers/webgl/WebGLShaderCache.js +12 -8
  698. package/src/renderers/webgl/WebGLShadowMap.js +13 -20
  699. package/src/renderers/webgl/WebGLState.js +49 -2
  700. package/src/renderers/webgl/WebGLTextures.js +576 -386
  701. package/src/renderers/webgl/WebGLUniforms.js +81 -82
  702. package/src/renderers/webgl/WebGLUniformsGroups.js +372 -0
  703. package/src/renderers/webgl/WebGLUtils.js +14 -3
  704. package/src/renderers/webvr/WebVRManager.js +42 -9
  705. package/src/renderers/webvr/WebVRUtils.js +1 -1
  706. package/src/renderers/webxr/WebXRController.js +45 -37
  707. package/src/renderers/webxr/WebXRManager.js +110 -68
  708. package/src/scenes/Fog.js +2 -2
  709. package/src/scenes/FogExp2.js +2 -2
  710. package/src/scenes/Scene.js +18 -5
  711. package/src/textures/CanvasTexture.js +2 -2
  712. package/src/textures/CompressedTexture.js +2 -2
  713. package/src/textures/CubeTexture.js +2 -2
  714. package/src/textures/{DataTexture3D.js → Data3DTexture.js} +4 -4
  715. package/src/textures/{DataTexture2DArray.js → DataArrayTexture.js} +4 -4
  716. package/src/textures/DataTexture.js +2 -5
  717. package/src/textures/DepthTexture.js +5 -5
  718. package/src/textures/FramebufferTexture.js +2 -2
  719. package/src/textures/Source.js +123 -0
  720. package/src/textures/Texture.js +27 -97
  721. package/src/textures/VideoTexture.js +2 -2
  722. package/src/utils.js +15 -1
  723. package/examples/js/controls/experimental/CameraControls.js +0 -1044
  724. package/examples/js/csm/Frustum.js +0 -133
  725. package/examples/js/deprecated/Geometry.js +0 -1656
  726. package/examples/js/loaders/KTX2Loader.js +0 -566
  727. package/examples/js/loaders/VRMLoader.js +0 -72
  728. package/examples/js/objects/ReflectorRTT.js +0 -16
  729. package/examples/js/postprocessing/SSRrPass.js +0 -494
  730. package/examples/js/shaders/SSRrShader.js +0 -336
  731. package/examples/jsm/controls/experimental/CameraControls.js +0 -1248
  732. package/examples/jsm/deprecated/Geometry.js +0 -1869
  733. package/examples/jsm/libs/opentype.module.min.js +0 -119
  734. package/examples/jsm/loaders/NodeMaterialLoader.js +0 -263
  735. package/examples/jsm/loaders/VRMLoader.js +0 -78
  736. package/examples/jsm/nodes/accessors/ColorsNode.js +0 -56
  737. package/examples/jsm/nodes/accessors/LightNode.js +0 -60
  738. package/examples/jsm/nodes/accessors/ReflectNode.js +0 -157
  739. package/examples/jsm/nodes/accessors/ResolutionNode.js +0 -64
  740. package/examples/jsm/nodes/accessors/ScreenUVNode.js +0 -64
  741. package/examples/jsm/nodes/core/NodeLib.js +0 -64
  742. package/examples/jsm/nodes/core/StructNode.js +0 -106
  743. package/examples/jsm/nodes/effects/BlurNode.js +0 -171
  744. package/examples/jsm/nodes/effects/ColorAdjustmentNode.js +0 -140
  745. package/examples/jsm/nodes/effects/LuminanceNode.js +0 -75
  746. package/examples/jsm/nodes/inputs/BoolNode.js +0 -51
  747. package/examples/jsm/nodes/inputs/ColorNode.js +0 -58
  748. package/examples/jsm/nodes/inputs/CubeTextureNode.js +0 -108
  749. package/examples/jsm/nodes/inputs/FloatNode.js +0 -51
  750. package/examples/jsm/nodes/inputs/IntNode.js +0 -51
  751. package/examples/jsm/nodes/inputs/Matrix3Node.js +0 -63
  752. package/examples/jsm/nodes/inputs/Matrix4Node.js +0 -63
  753. package/examples/jsm/nodes/inputs/PropertyNode.js +0 -47
  754. package/examples/jsm/nodes/inputs/RTTNode.js +0 -157
  755. package/examples/jsm/nodes/inputs/ReflectorNode.js +0 -90
  756. package/examples/jsm/nodes/inputs/ScreenNode.js +0 -28
  757. package/examples/jsm/nodes/inputs/TextureNode.js +0 -116
  758. package/examples/jsm/nodes/inputs/Vector2Node.js +0 -57
  759. package/examples/jsm/nodes/inputs/Vector3Node.js +0 -58
  760. package/examples/jsm/nodes/inputs/Vector4Node.js +0 -59
  761. package/examples/jsm/nodes/materials/BasicNodeMaterial.js +0 -26
  762. package/examples/jsm/nodes/materials/PhongNodeMaterial.js +0 -36
  763. package/examples/jsm/nodes/materials/StandardNodeMaterial.js +0 -40
  764. package/examples/jsm/nodes/materials/nodes/BasicNode.js +0 -154
  765. package/examples/jsm/nodes/materials/nodes/MeshStandardNode.js +0 -116
  766. package/examples/jsm/nodes/materials/nodes/PhongNode.js +0 -409
  767. package/examples/jsm/nodes/materials/nodes/RawNode.js +0 -62
  768. package/examples/jsm/nodes/materials/nodes/SpriteNode.js +0 -236
  769. package/examples/jsm/nodes/materials/nodes/StandardNode.js +0 -609
  770. package/examples/jsm/nodes/misc/BumpMapNode.js +0 -163
  771. package/examples/jsm/nodes/misc/NormalMapNode.js +0 -138
  772. package/examples/jsm/nodes/misc/TextureCubeNode.js +0 -86
  773. package/examples/jsm/nodes/misc/TextureCubeUVNode.js +0 -280
  774. package/examples/jsm/nodes/postprocessing/NodePass.js +0 -93
  775. package/examples/jsm/nodes/postprocessing/NodePostProcessing.js +0 -148
  776. package/examples/jsm/nodes/procedural/Fractal3DNode.js +0 -104
  777. package/examples/jsm/nodes/procedural/Noise2DNode.js +0 -149
  778. package/examples/jsm/nodes/procedural/Noise3DNode.js +0 -141
  779. package/examples/jsm/nodes/utils/BypassNode.js +0 -85
  780. package/examples/jsm/nodes/utils/ColorSpaceNode.js +0 -145
  781. package/examples/jsm/nodes/utils/MaxMIPLevelNode.js +0 -56
  782. package/examples/jsm/nodes/utils/RemapNode.js +0 -155
  783. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +0 -101
  784. package/examples/jsm/nodes/utils/SubSlotNode.js +0 -77
  785. package/examples/jsm/nodes/utils/SwitchNode.js +0 -103
  786. package/examples/jsm/nodes/utils/UVTransformNode.js +0 -66
  787. package/examples/jsm/nodes/utils/VelocityNode.js +0 -170
  788. package/examples/jsm/objects/ReflectorRTT.js +0 -15
  789. package/examples/jsm/package.json +0 -3
  790. package/examples/jsm/postprocessing/SSRrPass.js +0 -579
  791. package/examples/jsm/renderers/nodes/Nodes.js +0 -166
  792. package/examples/jsm/renderers/nodes/ShaderNode.js +0 -373
  793. package/examples/jsm/renderers/nodes/accessors/CameraNode.js +0 -68
  794. package/examples/jsm/renderers/nodes/accessors/NormalNode.js +0 -63
  795. package/examples/jsm/renderers/nodes/accessors/PositionNode.js +0 -67
  796. package/examples/jsm/renderers/nodes/accessors/ReferenceNode.js +0 -91
  797. package/examples/jsm/renderers/nodes/accessors/SkinningNode.js +0 -107
  798. package/examples/jsm/renderers/nodes/accessors/UVNode.js +0 -25
  799. package/examples/jsm/renderers/nodes/core/ArrayInputNode.js +0 -23
  800. package/examples/jsm/renderers/nodes/core/AttributeNode.js +0 -54
  801. package/examples/jsm/renderers/nodes/core/CodeNode.js +0 -78
  802. package/examples/jsm/renderers/nodes/core/ExpressionNode.js +0 -32
  803. package/examples/jsm/renderers/nodes/core/FunctionCallNode.js +0 -67
  804. package/examples/jsm/renderers/nodes/core/FunctionNode.js +0 -87
  805. package/examples/jsm/renderers/nodes/core/InputNode.js +0 -66
  806. package/examples/jsm/renderers/nodes/core/Node.js +0 -104
  807. package/examples/jsm/renderers/nodes/core/NodeBuilder.js +0 -633
  808. package/examples/jsm/renderers/nodes/core/NodeFrame.js +0 -59
  809. package/examples/jsm/renderers/nodes/core/NodeUniform.js +0 -28
  810. package/examples/jsm/renderers/nodes/core/TempNode.js +0 -43
  811. package/examples/jsm/renderers/nodes/core/VarNode.js +0 -51
  812. package/examples/jsm/renderers/nodes/display/NormalMapNode.js +0 -87
  813. package/examples/jsm/renderers/nodes/functions/BSDFs.js +0 -122
  814. package/examples/jsm/renderers/nodes/functions/PhysicalMaterialFunctions.js +0 -27
  815. package/examples/jsm/renderers/nodes/inputs/BufferNode.js +0 -25
  816. package/examples/jsm/renderers/nodes/inputs/ColorNode.js +0 -18
  817. package/examples/jsm/renderers/nodes/inputs/FloatNode.js +0 -17
  818. package/examples/jsm/renderers/nodes/inputs/IntNode.js +0 -17
  819. package/examples/jsm/renderers/nodes/inputs/Matrix3Node.js +0 -18
  820. package/examples/jsm/renderers/nodes/inputs/Matrix4Node.js +0 -18
  821. package/examples/jsm/renderers/nodes/inputs/TextureNode.js +0 -74
  822. package/examples/jsm/renderers/nodes/inputs/Vector2Node.js +0 -18
  823. package/examples/jsm/renderers/nodes/inputs/Vector3Node.js +0 -18
  824. package/examples/jsm/renderers/nodes/inputs/Vector4Node.js +0 -18
  825. package/examples/jsm/renderers/nodes/lights/LightContextNode.js +0 -59
  826. package/examples/jsm/renderers/nodes/lights/LightNode.js +0 -79
  827. package/examples/jsm/renderers/nodes/lights/LightsNode.js +0 -44
  828. package/examples/jsm/renderers/nodes/materials/Materials.js +0 -11
  829. package/examples/jsm/renderers/nodes/materials/MeshStandardNodeMaterial.js +0 -63
  830. package/examples/jsm/renderers/nodes/math/CondNode.js +0 -60
  831. package/examples/jsm/renderers/nodes/math/MathNode.js +0 -242
  832. package/examples/jsm/renderers/nodes/math/OperatorNode.js +0 -174
  833. package/examples/jsm/renderers/nodes/procedural/CheckerNode.js +0 -36
  834. package/examples/jsm/renderers/nodes/utils/ConvertNode.js +0 -33
  835. package/examples/jsm/renderers/nodes/utils/JoinNode.js +0 -42
  836. package/examples/jsm/renderers/nodes/utils/SplitNode.js +0 -55
  837. package/examples/jsm/renderers/nodes/utils/TimerNode.js +0 -47
  838. package/examples/jsm/renderers/webgl/nodes/WebGLPhysicalContextNode.js +0 -45
  839. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeUniformsGroup.js +0 -20
  840. package/examples/jsm/shaders/SSRrShader.js +0 -307
  841. package/src/renderers/WebGLMultisampleRenderTarget.js +0 -33
  842. package/src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl.js +0 -122
@@ -7,7 +7,6 @@ import {
7
7
  LineBasicMaterial,
8
8
  LineSegments,
9
9
  Loader,
10
- Matrix3,
11
10
  Matrix4,
12
11
  Mesh,
13
12
  MeshStandardMaterial,
@@ -29,14 +28,17 @@ const FINISH_TYPE_METAL = 5;
29
28
 
30
29
  // State machine to search a subobject path.
31
30
  // The LDraw standard establishes these various possible subfolders.
32
- const FILE_LOCATION_AS_IS = 0;
33
- const FILE_LOCATION_TRY_PARTS = 1;
34
- const FILE_LOCATION_TRY_P = 2;
35
- const FILE_LOCATION_TRY_MODELS = 3;
31
+ const FILE_LOCATION_TRY_PARTS = 0;
32
+ const FILE_LOCATION_TRY_P = 1;
33
+ const FILE_LOCATION_TRY_MODELS = 2;
34
+ const FILE_LOCATION_AS_IS = 3;
36
35
  const FILE_LOCATION_TRY_RELATIVE = 4;
37
36
  const FILE_LOCATION_TRY_ABSOLUTE = 5;
38
37
  const FILE_LOCATION_NOT_FOUND = 6;
39
38
 
39
+ const MAIN_COLOUR_CODE = '16';
40
+ const MAIN_EDGE_COLOUR_CODE = '24';
41
+
40
42
  const _tempVec0 = new Vector3();
41
43
  const _tempVec1 = new Vector3();
42
44
 
@@ -169,6 +171,17 @@ class LDrawConditionalLineMaterial extends ShaderMaterial {
169
171
 
170
172
  }
171
173
 
174
+ class ConditionalLineSegments extends LineSegments {
175
+
176
+ constructor( geometry, material ) {
177
+
178
+ super( geometry, material );
179
+ this.isConditionalLine = true;
180
+
181
+ }
182
+
183
+ }
184
+
172
185
  function generateFaceNormals( faces ) {
173
186
 
174
187
  for ( let i = 0, l = faces.length; i < l; i ++ ) {
@@ -523,13 +536,7 @@ function smoothNormals( faces, lineSegments, checkSubSegments = false ) {
523
536
 
524
537
  function isPartType( type ) {
525
538
 
526
- return type === 'Part';
527
-
528
- }
529
-
530
- function isModelType( type ) {
531
-
532
- return type === 'Model' || type === 'Unofficial_Model';
539
+ return type === 'Part' || type === 'Unofficial_Part';
533
540
 
534
541
  }
535
542
 
@@ -628,12 +635,13 @@ class LineParser {
628
635
 
629
636
  }
630
637
 
638
+ // Fetches and parses an intermediate representation of LDraw parts files.
631
639
  class LDrawParsedCache {
632
640
 
633
641
  constructor( loader ) {
634
642
 
635
643
  this.loader = loader;
636
- this.cache = {};
644
+ this._cache = {};
637
645
 
638
646
  }
639
647
 
@@ -680,10 +688,13 @@ class LDrawParsedCache {
680
688
  result.type = original.type;
681
689
  result.category = original.category;
682
690
  result.keywords = original.keywords;
691
+ result.author = original.author;
683
692
  result.subobjects = original.subobjects;
693
+ result.fileName = original.fileName;
684
694
  result.totalFaces = original.totalFaces;
685
695
  result.startingConstructionStep = original.startingConstructionStep;
686
696
  result.materials = original.materials;
697
+ result.group = null;
687
698
  return result;
688
699
 
689
700
  }
@@ -691,7 +702,7 @@ class LDrawParsedCache {
691
702
  async fetchData( fileName ) {
692
703
 
693
704
  let triedLowerCase = false;
694
- let locationState = FILE_LOCATION_AS_IS;
705
+ let locationState = FILE_LOCATION_TRY_PARTS;
695
706
  while ( locationState !== FILE_LOCATION_NOT_FOUND ) {
696
707
 
697
708
  let subobjectURL = fileName;
@@ -734,7 +745,7 @@ class LDrawParsedCache {
734
745
  fileName = fileName.toLowerCase();
735
746
  subobjectURL = fileName;
736
747
  triedLowerCase = true;
737
- locationState = FILE_LOCATION_AS_IS;
748
+ locationState = FILE_LOCATION_TRY_PARTS;
738
749
 
739
750
  }
740
751
 
@@ -765,7 +776,7 @@ class LDrawParsedCache {
765
776
 
766
777
  }
767
778
 
768
- parse( text ) {
779
+ parse( text, fileName = null ) {
769
780
 
770
781
  const loader = this.loader;
771
782
 
@@ -778,13 +789,14 @@ class LDrawParsedCache {
778
789
 
779
790
  const getLocalMaterial = colorCode => {
780
791
 
781
- return colorCode in materials ? materials[ colorCode ] : null;
792
+ return materials[ colorCode ] || null;
782
793
 
783
794
  };
784
795
 
785
796
  let type = 'Model';
786
797
  let category = null;
787
798
  let keywords = null;
799
+ let author = null;
788
800
  let totalFaces = 0;
789
801
 
790
802
  // split into lines
@@ -986,6 +998,12 @@ class LDrawParsedCache {
986
998
 
987
999
  break;
988
1000
 
1001
+ case 'Author:':
1002
+
1003
+ author = lp.getToken();
1004
+
1005
+ break;
1006
+
989
1007
  default:
990
1008
  // Other meta directives are not implemented
991
1009
  break;
@@ -1212,39 +1230,389 @@ class LDrawParsedCache {
1212
1230
  type,
1213
1231
  category,
1214
1232
  keywords,
1233
+ author,
1215
1234
  subobjects,
1216
1235
  totalFaces,
1217
1236
  startingConstructionStep,
1218
- materials
1237
+ materials,
1238
+ fileName,
1239
+ group: null
1219
1240
  };
1220
1241
 
1221
1242
  }
1222
1243
 
1223
- loadData( fileName ) {
1244
+ // returns an (optionally cloned) instance of the data
1245
+ getData( fileName, clone = true ) {
1224
1246
 
1225
1247
  const key = fileName.toLowerCase();
1226
- if ( ! ( key in this.cache ) ) {
1248
+ const result = this._cache[ key ];
1249
+ if ( result === null || result instanceof Promise ) {
1227
1250
 
1228
- this.cache[ key ] = this.fetchData( fileName ).then( text => {
1251
+ return null;
1229
1252
 
1230
- return this.parse( text );
1253
+ }
1231
1254
 
1232
- } );
1255
+ if ( clone ) {
1256
+
1257
+ return this.cloneResult( result );
1258
+
1259
+ } else {
1260
+
1261
+ return result;
1233
1262
 
1234
1263
  }
1235
1264
 
1236
- return this.cache[ key ].then( result => {
1265
+ }
1237
1266
 
1238
- return this.cloneResult( result );
1267
+ // kicks off a fetch and parse of the requested data if it hasn't already been loaded. Returns when
1268
+ // the data is ready to use and can be retrieved synchronously with "getData".
1269
+ async ensureDataLoaded( fileName ) {
1239
1270
 
1240
- } );
1271
+ const key = fileName.toLowerCase();
1272
+ if ( ! ( key in this._cache ) ) {
1273
+
1274
+ // replace the promise with a copy of the parsed data for immediate processing
1275
+ this._cache[ key ] = this.fetchData( fileName ).then( text => {
1276
+
1277
+ const info = this.parse( text, fileName );
1278
+ this._cache[ key ] = info;
1279
+ return info;
1280
+
1281
+ } );
1282
+
1283
+ }
1284
+
1285
+ await this._cache[ key ];
1241
1286
 
1242
1287
  }
1243
1288
 
1289
+ // sets the data in the cache from parsed data
1244
1290
  setData( fileName, text ) {
1245
1291
 
1246
1292
  const key = fileName.toLowerCase();
1247
- this.cache[ key ] = Promise.resolve( this.parse( text ) );
1293
+ this._cache[ key ] = this.parse( text, fileName );
1294
+
1295
+ }
1296
+
1297
+ }
1298
+
1299
+ // returns the material for an associated color code. If the color code is 16 for a face or 24 for
1300
+ // an edge then the passthroughColorCode is used.
1301
+ function getMaterialFromCode( colorCode, parentColorCode, materialHierarchy, forEdge ) {
1302
+
1303
+ const isPassthrough = ! forEdge && colorCode === MAIN_COLOUR_CODE || forEdge && colorCode === MAIN_EDGE_COLOUR_CODE;
1304
+ if ( isPassthrough ) {
1305
+
1306
+ colorCode = parentColorCode;
1307
+
1308
+ }
1309
+
1310
+ return materialHierarchy[ colorCode ] || null;
1311
+
1312
+ }
1313
+
1314
+ // Class used to parse and build LDraw parts as three.js objects and cache them if they're a "Part" type.
1315
+ class LDrawPartsGeometryCache {
1316
+
1317
+ constructor( loader ) {
1318
+
1319
+ this.loader = loader;
1320
+ this.parseCache = new LDrawParsedCache( loader );
1321
+ this._cache = {};
1322
+
1323
+ }
1324
+
1325
+ // Convert the given file information into a mesh by processing subobjects.
1326
+ async processIntoMesh( info ) {
1327
+
1328
+ const loader = this.loader;
1329
+ const parseCache = this.parseCache;
1330
+ const faceMaterials = new Set();
1331
+
1332
+ // Processes the part subobject information to load child parts and merge geometry onto part
1333
+ // piece object.
1334
+ const processInfoSubobjects = async ( info, subobject = null ) => {
1335
+
1336
+ const subobjects = info.subobjects;
1337
+ const promises = [];
1338
+
1339
+ // Trigger load of all subobjects. If a subobject isn't a primitive then load it as a separate
1340
+ // group which lets instruction steps apply correctly.
1341
+ for ( let i = 0, l = subobjects.length; i < l; i ++ ) {
1342
+
1343
+ const subobject = subobjects[ i ];
1344
+ const promise = parseCache.ensureDataLoaded( subobject.fileName ).then( () => {
1345
+
1346
+ const subobjectInfo = parseCache.getData( subobject.fileName, false );
1347
+ if ( ! isPrimitiveType( subobjectInfo.type ) ) {
1348
+
1349
+ return this.loadModel( subobject.fileName ).catch( error => {
1350
+
1351
+ console.warn( error );
1352
+ return null;
1353
+
1354
+ } );
1355
+
1356
+ }
1357
+
1358
+ return processInfoSubobjects( parseCache.getData( subobject.fileName ), subobject );
1359
+
1360
+ } );
1361
+
1362
+ promises.push( promise );
1363
+
1364
+ }
1365
+
1366
+ const group = new Group();
1367
+ group.userData.category = info.category;
1368
+ group.userData.keywords = info.keywords;
1369
+ group.userData.author = info.author;
1370
+ group.userData.type = info.type;
1371
+ group.userData.fileName = info.fileName;
1372
+ info.group = group;
1373
+
1374
+ const subobjectInfos = await Promise.all( promises );
1375
+ for ( let i = 0, l = subobjectInfos.length; i < l; i ++ ) {
1376
+
1377
+ const subobject = info.subobjects[ i ];
1378
+ const subobjectInfo = subobjectInfos[ i ];
1379
+
1380
+ if ( subobjectInfo === null ) {
1381
+
1382
+ // the subobject failed to load
1383
+ continue;
1384
+
1385
+ }
1386
+
1387
+ // if the subobject was loaded as a separate group then apply the parent scopes materials
1388
+ if ( subobjectInfo.isGroup ) {
1389
+
1390
+ const subobjectGroup = subobjectInfo;
1391
+ subobject.matrix.decompose( subobjectGroup.position, subobjectGroup.quaternion, subobjectGroup.scale );
1392
+ subobjectGroup.userData.startingConstructionStep = subobject.startingConstructionStep;
1393
+ subobjectGroup.name = subobject.fileName;
1394
+
1395
+ loader.applyMaterialsToMesh( subobjectGroup, subobject.colorCode, info.materials );
1396
+ subobjectGroup.userData.colorCode = subobject.colorCode;
1397
+
1398
+ group.add( subobjectGroup );
1399
+ continue;
1400
+
1401
+ }
1402
+
1403
+ // add the subobject group if it has children in case it has both children and primitives
1404
+ if ( subobjectInfo.group.children.length ) {
1405
+
1406
+ group.add( subobjectInfo.group );
1407
+
1408
+ }
1409
+
1410
+ // transform the primitives into the local space of the parent piece and append them to
1411
+ // to the parent primitives list.
1412
+ const parentLineSegments = info.lineSegments;
1413
+ const parentConditionalSegments = info.conditionalSegments;
1414
+ const parentFaces = info.faces;
1415
+
1416
+ const lineSegments = subobjectInfo.lineSegments;
1417
+ const conditionalSegments = subobjectInfo.conditionalSegments;
1418
+
1419
+ const faces = subobjectInfo.faces;
1420
+ const matrix = subobject.matrix;
1421
+ const inverted = subobject.inverted;
1422
+ const matrixScaleInverted = matrix.determinant() < 0;
1423
+ const colorCode = subobject.colorCode;
1424
+
1425
+ const lineColorCode = colorCode === MAIN_COLOUR_CODE ? MAIN_EDGE_COLOUR_CODE : colorCode;
1426
+ for ( let i = 0, l = lineSegments.length; i < l; i ++ ) {
1427
+
1428
+ const ls = lineSegments[ i ];
1429
+ const vertices = ls.vertices;
1430
+ vertices[ 0 ].applyMatrix4( matrix );
1431
+ vertices[ 1 ].applyMatrix4( matrix );
1432
+ ls.colorCode = ls.colorCode === MAIN_EDGE_COLOUR_CODE ? lineColorCode : ls.colorCode;
1433
+ ls.material = ls.material || getMaterialFromCode( ls.colorCode, ls.colorCode, info.materials, true );
1434
+
1435
+ parentLineSegments.push( ls );
1436
+
1437
+ }
1438
+
1439
+ for ( let i = 0, l = conditionalSegments.length; i < l; i ++ ) {
1440
+
1441
+ const os = conditionalSegments[ i ];
1442
+ const vertices = os.vertices;
1443
+ const controlPoints = os.controlPoints;
1444
+ vertices[ 0 ].applyMatrix4( matrix );
1445
+ vertices[ 1 ].applyMatrix4( matrix );
1446
+ controlPoints[ 0 ].applyMatrix4( matrix );
1447
+ controlPoints[ 1 ].applyMatrix4( matrix );
1448
+ os.colorCode = os.colorCode === MAIN_EDGE_COLOUR_CODE ? lineColorCode : os.colorCode;
1449
+ os.material = os.material || getMaterialFromCode( os.colorCode, os.colorCode, info.materials, true );
1450
+
1451
+ parentConditionalSegments.push( os );
1452
+
1453
+ }
1454
+
1455
+ for ( let i = 0, l = faces.length; i < l; i ++ ) {
1456
+
1457
+ const tri = faces[ i ];
1458
+ const vertices = tri.vertices;
1459
+ for ( let i = 0, l = vertices.length; i < l; i ++ ) {
1460
+
1461
+ vertices[ i ].applyMatrix4( matrix );
1462
+
1463
+ }
1464
+
1465
+ tri.colorCode = tri.colorCode === MAIN_COLOUR_CODE ? colorCode : tri.colorCode;
1466
+ tri.material = tri.material || getMaterialFromCode( tri.colorCode, colorCode, info.materials, false );
1467
+ faceMaterials.add( tri.colorCode );
1468
+
1469
+ // If the scale of the object is negated then the triangle winding order
1470
+ // needs to be flipped.
1471
+ if ( matrixScaleInverted !== inverted ) {
1472
+
1473
+ vertices.reverse();
1474
+
1475
+ }
1476
+
1477
+ parentFaces.push( tri );
1478
+
1479
+ }
1480
+
1481
+ info.totalFaces += subobjectInfo.totalFaces;
1482
+
1483
+ }
1484
+
1485
+ // Apply the parent subobjects pass through material code to this object. This is done several times due
1486
+ // to material scoping.
1487
+ if ( subobject ) {
1488
+
1489
+ loader.applyMaterialsToMesh( group, subobject.colorCode, info.materials );
1490
+ group.userData.colorCode = subobject.colorCode;
1491
+
1492
+ }
1493
+
1494
+ return info;
1495
+
1496
+ };
1497
+
1498
+ // Track material use to see if we need to use the normal smooth slow path for hard edges.
1499
+ for ( let i = 0, l = info.faces; i < l; i ++ ) {
1500
+
1501
+ faceMaterials.add( info.faces[ i ].colorCode );
1502
+
1503
+ }
1504
+
1505
+ await processInfoSubobjects( info );
1506
+
1507
+ if ( loader.smoothNormals ) {
1508
+
1509
+ const checkSubSegments = faceMaterials.size > 1;
1510
+ generateFaceNormals( info.faces );
1511
+ smoothNormals( info.faces, info.lineSegments, checkSubSegments );
1512
+
1513
+ }
1514
+
1515
+ // Add the primitive objects and metadata.
1516
+ const group = info.group;
1517
+ if ( info.faces.length > 0 ) {
1518
+
1519
+ group.add( createObject( info.faces, 3, false, info.totalFaces ) );
1520
+
1521
+ }
1522
+
1523
+ if ( info.lineSegments.length > 0 ) {
1524
+
1525
+ group.add( createObject( info.lineSegments, 2 ) );
1526
+
1527
+ }
1528
+
1529
+ if ( info.conditionalSegments.length > 0 ) {
1530
+
1531
+ group.add( createObject( info.conditionalSegments, 2, true ) );
1532
+
1533
+ }
1534
+
1535
+ return group;
1536
+
1537
+ }
1538
+
1539
+ hasCachedModel( fileName ) {
1540
+
1541
+ return fileName !== null && fileName.toLowerCase() in this._cache;
1542
+
1543
+ }
1544
+
1545
+ async getCachedModel( fileName ) {
1546
+
1547
+ if ( fileName !== null && this.hasCachedModel( fileName ) ) {
1548
+
1549
+ const key = fileName.toLowerCase();
1550
+ const group = await this._cache[ key ];
1551
+ return group.clone();
1552
+
1553
+ } else {
1554
+
1555
+ return null;
1556
+
1557
+ }
1558
+
1559
+ }
1560
+
1561
+ // Loads and parses the model with the given file name. Returns a cached copy if available.
1562
+ async loadModel( fileName ) {
1563
+
1564
+ const parseCache = this.parseCache;
1565
+ const key = fileName.toLowerCase();
1566
+ if ( this.hasCachedModel( fileName ) ) {
1567
+
1568
+ // Return cached model if available.
1569
+ return this.getCachedModel( fileName );
1570
+
1571
+ } else {
1572
+
1573
+ // Otherwise parse a new model.
1574
+ // Ensure the file data is loaded and pre parsed.
1575
+ await parseCache.ensureDataLoaded( fileName );
1576
+
1577
+ const info = parseCache.getData( fileName );
1578
+ const promise = this.processIntoMesh( info );
1579
+
1580
+ // Now that the file has loaded it's possible that another part parse has been waiting in parallel
1581
+ // so check the cache again to see if it's been added since the last async operation so we don't
1582
+ // do unnecessary work.
1583
+ if ( this.hasCachedModel( fileName ) ) {
1584
+
1585
+ return this.getCachedModel( fileName );
1586
+
1587
+ }
1588
+
1589
+ // Cache object if it's a part so it can be reused later.
1590
+ if ( isPartType( info.type ) ) {
1591
+
1592
+ this._cache[ key ] = promise;
1593
+
1594
+ }
1595
+
1596
+ // return a copy
1597
+ const group = await promise;
1598
+ return group.clone();
1599
+
1600
+ }
1601
+
1602
+ }
1603
+
1604
+ // parses the given model text into a renderable object. Returns cached copy if available.
1605
+ async parseModel( text ) {
1606
+
1607
+ const parseCache = this.parseCache;
1608
+ const info = parseCache.parse( text );
1609
+ if ( isPartType( info.type ) && this.hasCachedModel( info.fileName ) ) {
1610
+
1611
+ return this.getCachedModel( info.fileName );
1612
+
1613
+ }
1614
+
1615
+ return this.processIntoMesh( info );
1248
1616
 
1249
1617
  }
1250
1618
 
@@ -1367,7 +1735,7 @@ function createObject( elements, elementSize, isConditionalSegments = false, tot
1367
1735
 
1368
1736
  }
1369
1737
 
1370
- if ( prevMaterial !== elem.material ) {
1738
+ if ( prevMaterial !== elem.colorCode ) {
1371
1739
 
1372
1740
  if ( prevMaterial !== null ) {
1373
1741
 
@@ -1376,25 +1744,36 @@ function createObject( elements, elementSize, isConditionalSegments = false, tot
1376
1744
  }
1377
1745
 
1378
1746
  const material = elem.material;
1379
- if ( elementSize === 3 ) {
1380
1747
 
1381
- materials.push( material );
1748
+ if ( material !== null ) {
1382
1749
 
1383
- } else if ( elementSize === 2 ) {
1750
+ if ( elementSize === 3 ) {
1384
1751
 
1385
- if ( isConditionalSegments ) {
1752
+ materials.push( material );
1386
1753
 
1387
- materials.push( material.userData.edgeMaterial.userData.conditionalEdgeMaterial );
1754
+ } else if ( elementSize === 2 ) {
1388
1755
 
1389
- } else {
1756
+ if ( isConditionalSegments ) {
1757
+
1758
+ materials.push( material.userData.edgeMaterial.userData.conditionalEdgeMaterial );
1390
1759
 
1391
- materials.push( material.userData.edgeMaterial );
1760
+ } else {
1761
+
1762
+ materials.push( material.userData.edgeMaterial );
1763
+
1764
+ }
1392
1765
 
1393
1766
  }
1394
1767
 
1768
+ } else {
1769
+
1770
+ // If a material has not been made available yet then keep the color code string in the material array
1771
+ // to save the spot for the material once a parent scopes materials are being applied to the object.
1772
+ materials.push( elem.colorCode );
1773
+
1395
1774
  }
1396
1775
 
1397
- prevMaterial = elem.material;
1776
+ prevMaterial = elem.colorCode;
1398
1777
  index0 = offset / 3;
1399
1778
  numGroupVerts = vertices.length;
1400
1779
 
@@ -1426,7 +1805,15 @@ function createObject( elements, elementSize, isConditionalSegments = false, tot
1426
1805
 
1427
1806
  if ( elementSize === 2 ) {
1428
1807
 
1429
- object3d = new LineSegments( bufferGeometry, materials.length === 1 ? materials[ 0 ] : materials );
1808
+ if ( isConditionalSegments ) {
1809
+
1810
+ object3d = new ConditionalLineSegments( bufferGeometry, materials.length === 1 ? materials[ 0 ] : materials );
1811
+
1812
+ } else {
1813
+
1814
+ object3d = new LineSegments( bufferGeometry, materials.length === 1 ? materials[ 0 ] : materials );
1815
+
1816
+ }
1430
1817
 
1431
1818
  } else if ( elementSize === 3 ) {
1432
1819
 
@@ -1486,9 +1873,6 @@ function createObject( elements, elementSize, isConditionalSegments = false, tot
1486
1873
 
1487
1874
  //
1488
1875
 
1489
- const MAIN_COLOUR_CODE = '16';
1490
- const MAIN_EDGE_COLOUR_CODE = '24';
1491
-
1492
1876
  class LDrawLoader extends Loader {
1493
1877
 
1494
1878
  constructor( manager ) {
@@ -1497,21 +1881,16 @@ class LDrawLoader extends Loader {
1497
1881
 
1498
1882
  // Array of THREE.Material
1499
1883
  this.materials = [];
1884
+ this.materialLibrary = {};
1500
1885
 
1501
- // Not using THREE.Cache here because it returns the previous HTML error response instead of calling onError()
1502
1886
  // This also allows to handle the embedded text files ("0 FILE" lines)
1503
- this.parseCache = new LDrawParsedCache( this );
1887
+ this.partsCache = new LDrawPartsGeometryCache( this );
1504
1888
 
1505
1889
  // This object is a map from file names to paths. It agilizes the paths search. If it is not set then files will be searched by trial and error.
1506
1890
  this.fileMap = {};
1507
1891
 
1508
- this.rootParseScope = this.newParseScopeLevel();
1509
-
1510
- // Add default main triangle and line edge materials (used in pieces that can be colored with a main color)
1511
- this.setMaterials( [
1512
- this.parseColorMetaDirective( new LineParser( 'Main_Colour CODE 16 VALUE #FF8080 EDGE #333333' ) ),
1513
- this.parseColorMetaDirective( new LineParser( 'Edge_Colour CODE 24 VALUE #A0A0A0 EDGE #333333' ) )
1514
- ] );
1892
+ // Initializes the materials library with default materials
1893
+ this.setMaterials( [] );
1515
1894
 
1516
1895
  // If this flag is set to true the vertex normals will be smoothed.
1517
1896
  this.smoothNormals = true;
@@ -1519,6 +1898,16 @@ class LDrawLoader extends Loader {
1519
1898
  // The path to load parts from the LDraw parts library from.
1520
1899
  this.partsLibraryPath = '';
1521
1900
 
1901
+ // Material assigned to not available colors for meshes and edges
1902
+ this.missingColorMaterial = new MeshStandardMaterial( { color: 0xFF00FF, roughness: 0.3, metalness: 0 } );
1903
+ this.missingColorMaterial.name = 'Missing material';
1904
+ this.missingEdgeColorMaterial = new LineBasicMaterial( { color: 0xFF00FF } );
1905
+ this.missingEdgeColorMaterial.name = 'Missing material - Edge';
1906
+ this.missingConditionalEdgeColorMaterial = new LDrawConditionalLineMaterial( { fog: true, color: 0xFF00FF } );
1907
+ this.missingConditionalEdgeColorMaterial.name = 'Missing material - Conditional Edge';
1908
+ this.missingColorMaterial.userData.edgeMaterial = this.missingEdgeColorMaterial;
1909
+ this.missingEdgeColorMaterial.userData.conditionalEdgeMaterial = this.missingConditionalEdgeColorMaterial;
1910
+
1522
1911
  }
1523
1912
 
1524
1913
  setPartsLibraryPath( path ) {
@@ -1564,26 +1953,32 @@ class LDrawLoader extends Loader {
1564
1953
  fileLoader.setWithCredentials( this.withCredentials );
1565
1954
  fileLoader.load( url, text => {
1566
1955
 
1567
- const parsedInfo = this.parseCache.parse( text );
1568
- this.processObject( parsedInfo, null, url, this.rootParseScope )
1569
- .then( function ( result ) {
1956
+ this.partsCache
1957
+ .parseModel( text, this.materialLibrary )
1958
+ .then( group => {
1570
1959
 
1571
- onLoad( result.groupObject );
1960
+ this.applyMaterialsToMesh( group, MAIN_COLOUR_CODE, this.materialLibrary, true );
1961
+ this.computeConstructionSteps( group );
1962
+ group.userData.fileName = url;
1963
+ onLoad( group );
1572
1964
 
1573
- } );
1965
+ } )
1966
+ .catch( onError );
1574
1967
 
1575
1968
  }, onProgress, onError );
1576
1969
 
1577
1970
  }
1578
1971
 
1579
- parse( text, path, onLoad ) {
1972
+ parse( text, onLoad ) {
1580
1973
 
1581
- // Async parse. This function calls onParse with the parsed THREE.Object3D as parameter
1582
- const parsedInfo = this.parseCache.parse( text );
1583
- this.processObject( parsedInfo, null, path, this.rootParseScope )
1584
- .then( function ( result ) {
1974
+ this.partsCache
1975
+ .parseModel( text, this.materialLibrary )
1976
+ .then( group => {
1585
1977
 
1586
- onLoad( result.groupObject );
1978
+ this.applyMaterialsToMesh( group, MAIN_COLOUR_CODE, this.materialLibrary, true );
1979
+ this.computeConstructionSteps( group );
1980
+ group.userData.fileName = '';
1981
+ onLoad( group );
1587
1982
 
1588
1983
  } );
1589
1984
 
@@ -1591,11 +1986,17 @@ class LDrawLoader extends Loader {
1591
1986
 
1592
1987
  setMaterials( materials ) {
1593
1988
 
1594
- // Clears parse scopes stack, adds new scope with material library
1595
- this.rootParseScope = this.newParseScopeLevel( materials );
1596
- this.rootParseScope.isFromParse = false;
1989
+ this.materialLibrary = {};
1990
+ this.materials = [];
1991
+ for ( let i = 0, l = materials.length; i < l; i ++ ) {
1992
+
1993
+ this.addMaterial( materials[ i ] );
1994
+
1995
+ }
1597
1996
 
1598
- this.materials = materials;
1997
+ // Add default main triangle and line edge materials (used in pieces that can be colored with a main color)
1998
+ this.addMaterial( this.parseColorMetaDirective( new LineParser( 'Main_Colour CODE 16 VALUE #FF8080 EDGE #333333' ) ) );
1999
+ this.addMaterial( this.parseColorMetaDirective( new LineParser( 'Edge_Colour CODE 24 VALUE #A0A0A0 EDGE #333333' ) ) );
1599
2000
 
1600
2001
  return this;
1601
2002
 
@@ -1609,121 +2010,148 @@ class LDrawLoader extends Loader {
1609
2010
 
1610
2011
  }
1611
2012
 
1612
- newParseScopeLevel( materials = null, parentScope = null ) {
2013
+ addMaterial( material ) {
1613
2014
 
1614
- // Adds a new scope level, assign materials to it and returns it
2015
+ // Adds a material to the material library which is on top of the parse scopes stack. And also to the materials array
1615
2016
 
1616
- const matLib = {};
2017
+ const matLib = this.materialLibrary;
2018
+ if ( ! matLib[ material.userData.code ] ) {
1617
2019
 
1618
- if ( materials ) {
2020
+ this.materials.push( material );
2021
+ matLib[ material.userData.code ] = material;
1619
2022
 
1620
- for ( let i = 0, n = materials.length; i < n; i ++ ) {
2023
+ }
1621
2024
 
1622
- const material = materials[ i ];
1623
- matLib[ material.userData.code ] = material;
2025
+ return this;
1624
2026
 
1625
- }
2027
+ }
1626
2028
 
1627
- }
2029
+ getMaterial( colorCode ) {
1628
2030
 
1629
- const newParseScope = {
1630
-
1631
- parentScope: parentScope,
1632
- lib: matLib,
1633
- url: null,
1634
-
1635
- // Subobjects
1636
- subobjects: null,
1637
- inverted: false,
1638
- category: null,
1639
- keywords: null,
1640
-
1641
- // Current subobject
1642
- currentFileName: null,
1643
- mainColorCode: parentScope ? parentScope.mainColorCode : MAIN_COLOUR_CODE,
1644
- mainEdgeColorCode: parentScope ? parentScope.mainEdgeColorCode : MAIN_EDGE_COLOUR_CODE,
1645
- matrix: new Matrix4(),
1646
- type: 'Model',
1647
- groupObject: null,
1648
-
1649
- // If false, it is a root material scope previous to parse
1650
- isFromParse: true,
1651
-
1652
- faces: [],
1653
- lineSegments: [],
1654
- conditionalSegments: [],
1655
- totalFaces: 0,
1656
- faceMaterials: new Set(),
1657
-
1658
- // If true, this object is the start of a construction step
1659
- startingConstructionStep: false
1660
- };
2031
+ if ( colorCode.startsWith( '0x2' ) ) {
2032
+
2033
+ // Special 'direct' material value (RGB color)
2034
+ const color = colorCode.substring( 3 );
2035
+
2036
+ return this.parseColorMetaDirective( new LineParser( 'Direct_Color_' + color + ' CODE -1 VALUE #' + color + ' EDGE #' + color + '' ) );
2037
+
2038
+ }
1661
2039
 
1662
- return newParseScope;
2040
+ return this.materialLibrary[ colorCode ] || null;
1663
2041
 
1664
2042
  }
1665
2043
 
1666
- addMaterial( material, parseScope ) {
2044
+ // Applies the appropriate materials to a prebuilt hierarchy of geometry. Assumes that color codes are present
2045
+ // in the material array if they need to be filled in.
2046
+ applyMaterialsToMesh( group, parentColorCode, materialHierarchy, finalMaterialPass = false ) {
1667
2047
 
1668
- // Adds a material to the material library which is on top of the parse scopes stack. And also to the materials array
2048
+ // find any missing materials as indicated by a color code string and replace it with a material from the current material lib
2049
+ const loader = this;
2050
+ const parentIsPassthrough = parentColorCode === MAIN_COLOUR_CODE;
2051
+ group.traverse( c => {
1669
2052
 
1670
- const matLib = parseScope.lib;
2053
+ if ( c.isMesh || c.isLineSegments ) {
1671
2054
 
1672
- if ( ! matLib[ material.userData.code ] ) {
2055
+ if ( Array.isArray( c.material ) ) {
1673
2056
 
1674
- this.materials.push( material );
2057
+ for ( let i = 0, l = c.material.length; i < l; i ++ ) {
1675
2058
 
1676
- }
2059
+ if ( ! c.material[ i ].isMaterial ) {
1677
2060
 
1678
- matLib[ material.userData.code ] = material;
2061
+ c.material[ i ] = getMaterial( c, c.material[ i ] );
1679
2062
 
1680
- return this;
2063
+ }
1681
2064
 
1682
- }
2065
+ }
1683
2066
 
1684
- getMaterial( colorCode, parseScope = this.rootParseScope ) {
2067
+ } else if ( ! c.material.isMaterial ) {
1685
2068
 
1686
- // Given a color code search its material in the parse scopes stack
2069
+ c.material = getMaterial( c, c.material );
1687
2070
 
1688
- if ( colorCode.startsWith( '0x2' ) ) {
2071
+ }
1689
2072
 
1690
- // Special 'direct' material value (RGB color)
2073
+ }
1691
2074
 
1692
- const color = colorCode.substring( 3 );
2075
+ } );
1693
2076
 
1694
- return this.parseColorMetaDirective( new LineParser( 'Direct_Color_' + color + ' CODE -1 VALUE #' + color + ' EDGE #' + color + '' ) );
1695
2077
 
1696
- }
2078
+ // Returns the appropriate material for the object (line or face) given color code. If the code is "pass through"
2079
+ // (24 for lines, 16 for edges) then the pass through color code is used. If that is also pass through then it's
2080
+ // simply returned for the subsequent material application.
2081
+ function getMaterial( c, colorCode ) {
2082
+
2083
+ // if our parent is a passthrough color code and we don't have the current material color available then
2084
+ // return early.
2085
+ if ( parentIsPassthrough && ! ( colorCode in materialHierarchy ) && ! finalMaterialPass ) {
2086
+
2087
+ return colorCode;
2088
+
2089
+ }
2090
+
2091
+ const forEdge = c.isLineSegments || c.isConditionalLine;
2092
+ const isPassthrough = ! forEdge && colorCode === MAIN_COLOUR_CODE || forEdge && colorCode === MAIN_EDGE_COLOUR_CODE;
2093
+ if ( isPassthrough ) {
2094
+
2095
+ colorCode = parentColorCode;
2096
+
2097
+ }
2098
+
2099
+ let material = null;
2100
+ if ( colorCode in materialHierarchy ) {
2101
+
2102
+ material = materialHierarchy[ colorCode ];
2103
+
2104
+ } else if ( finalMaterialPass ) {
2105
+
2106
+ // see if we can get the final material from from the "getMaterial" function which will attempt to
2107
+ // parse the "direct" colors
2108
+ material = loader.getMaterial( colorCode );
2109
+ if ( material === null ) {
1697
2110
 
1698
- while ( parseScope ) {
2111
+ // otherwise throw a warning if this is final opportunity to set the material
2112
+ console.warn( `LDrawLoader: Material properties for code ${ colorCode } not available.` );
1699
2113
 
1700
- const material = parseScope.lib[ colorCode ];
2114
+ // And return the 'missing color' material
2115
+ material = loader.missingColorMaterial;
1701
2116
 
1702
- if ( material ) {
2117
+ }
1703
2118
 
1704
- return material;
1705
2119
 
1706
2120
  } else {
1707
2121
 
1708
- parseScope = parseScope.parentScope;
2122
+ return colorCode;
1709
2123
 
1710
2124
  }
1711
2125
 
1712
- }
2126
+ if ( c.isLineSegments ) {
2127
+
2128
+ material = material.userData.edgeMaterial;
2129
+
2130
+ if ( c.isConditionalLine ) {
2131
+
2132
+ material = material.userData.conditionalEdgeMaterial;
2133
+
2134
+ }
1713
2135
 
1714
- // Material was not found
1715
- return null;
2136
+ }
2137
+
2138
+ return material;
2139
+
2140
+ }
1716
2141
 
1717
2142
  }
1718
2143
 
1719
2144
  getMainMaterial() {
1720
2145
 
1721
2146
  return this.getMaterial( MAIN_COLOUR_CODE );
2147
+
1722
2148
  }
1723
2149
 
1724
2150
  getMainEdgeMaterial() {
1725
2151
 
1726
- return this.getMaterial( MAIN_EDGE_COLOUR_CODE );;
2152
+ const mat = this.getMaterial( MAIN_EDGE_COLOUR_CODE );
2153
+ return mat ? mat.userData.edgeMaterial : null;
2154
+
1727
2155
  }
1728
2156
 
1729
2157
  parseColorMetaDirective( lineParser ) {
@@ -1765,113 +2193,113 @@ class LDrawLoader extends Loader {
1765
2193
 
1766
2194
  }
1767
2195
 
1768
- switch ( token.toUpperCase() ) {
2196
+ if ( ! parseLuminance( token ) ) {
1769
2197
 
1770
- case 'CODE':
2198
+ switch ( token.toUpperCase() ) {
1771
2199
 
1772
- code = lineParser.getToken();
1773
- break;
2200
+ case 'CODE':
1774
2201
 
1775
- case 'VALUE':
2202
+ code = lineParser.getToken();
2203
+ break;
1776
2204
 
1777
- color = lineParser.getToken();
1778
- if ( color.startsWith( '0x' ) ) {
2205
+ case 'VALUE':
1779
2206
 
1780
- color = '#' + color.substring( 2 );
2207
+ color = lineParser.getToken();
2208
+ if ( color.startsWith( '0x' ) ) {
1781
2209
 
1782
- } else if ( ! color.startsWith( '#' ) ) {
2210
+ color = '#' + color.substring( 2 );
1783
2211
 
1784
- throw new Error( 'LDrawLoader: Invalid color while parsing material' + lineParser.getLineNumberString() + '.' );
2212
+ } else if ( ! color.startsWith( '#' ) ) {
1785
2213
 
1786
- }
2214
+ throw new Error( 'LDrawLoader: Invalid color while parsing material' + lineParser.getLineNumberString() + '.' );
1787
2215
 
1788
- break;
2216
+ }
1789
2217
 
1790
- case 'EDGE':
2218
+ break;
1791
2219
 
1792
- edgeColor = lineParser.getToken();
1793
- if ( edgeColor.startsWith( '0x' ) ) {
2220
+ case 'EDGE':
1794
2221
 
1795
- edgeColor = '#' + edgeColor.substring( 2 );
2222
+ edgeColor = lineParser.getToken();
2223
+ if ( edgeColor.startsWith( '0x' ) ) {
1796
2224
 
1797
- } else if ( ! edgeColor.startsWith( '#' ) ) {
2225
+ edgeColor = '#' + edgeColor.substring( 2 );
1798
2226
 
1799
- // Try to see if edge color is a color code
1800
- edgeMaterial = this.getMaterial( edgeColor );
1801
- if ( ! edgeMaterial ) {
2227
+ } else if ( ! edgeColor.startsWith( '#' ) ) {
1802
2228
 
1803
- throw new Error( 'LDrawLoader: Invalid edge color while parsing material' + lineParser.getLineNumberString() + '.' );
2229
+ // Try to see if edge color is a color code
2230
+ edgeMaterial = this.getMaterial( edgeColor );
2231
+ if ( ! edgeMaterial ) {
1804
2232
 
1805
- }
2233
+ throw new Error( 'LDrawLoader: Invalid edge color while parsing material' + lineParser.getLineNumberString() + '.' );
1806
2234
 
1807
- // Get the edge material for this triangle material
1808
- edgeMaterial = edgeMaterial.userData.edgeMaterial;
2235
+ }
1809
2236
 
1810
- }
2237
+ // Get the edge material for this triangle material
2238
+ edgeMaterial = edgeMaterial.userData.edgeMaterial;
1811
2239
 
1812
- break;
2240
+ }
1813
2241
 
1814
- case 'ALPHA':
2242
+ break;
1815
2243
 
1816
- alpha = parseInt( lineParser.getToken() );
2244
+ case 'ALPHA':
1817
2245
 
1818
- if ( isNaN( alpha ) ) {
2246
+ alpha = parseInt( lineParser.getToken() );
1819
2247
 
1820
- throw new Error( 'LDrawLoader: Invalid alpha value in material definition' + lineParser.getLineNumberString() + '.' );
2248
+ if ( isNaN( alpha ) ) {
1821
2249
 
1822
- }
2250
+ throw new Error( 'LDrawLoader: Invalid alpha value in material definition' + lineParser.getLineNumberString() + '.' );
1823
2251
 
1824
- alpha = Math.max( 0, Math.min( 1, alpha / 255 ) );
2252
+ }
1825
2253
 
1826
- if ( alpha < 1 ) {
2254
+ alpha = Math.max( 0, Math.min( 1, alpha / 255 ) );
1827
2255
 
1828
- isTransparent = true;
2256
+ if ( alpha < 1 ) {
1829
2257
 
1830
- }
2258
+ isTransparent = true;
1831
2259
 
1832
- break;
2260
+ }
1833
2261
 
1834
- case 'LUMINANCE':
2262
+ break;
1835
2263
 
1836
- luminance = parseInt( lineParser.getToken() );
2264
+ case 'LUMINANCE':
1837
2265
 
1838
- if ( isNaN( luminance ) ) {
2266
+ if ( ! parseLuminance( lineParser.getToken() ) ) {
1839
2267
 
1840
- throw new Error( 'LDrawLoader: Invalid luminance value in material definition' + LineParser.getLineNumberString() + '.' );
2268
+ throw new Error( 'LDrawLoader: Invalid luminance value in material definition' + LineParser.getLineNumberString() + '.' );
1841
2269
 
1842
- }
2270
+ }
1843
2271
 
1844
- luminance = Math.max( 0, Math.min( 1, luminance / 255 ) );
2272
+ break;
1845
2273
 
1846
- break;
2274
+ case 'CHROME':
2275
+ finishType = FINISH_TYPE_CHROME;
2276
+ break;
1847
2277
 
1848
- case 'CHROME':
1849
- finishType = FINISH_TYPE_CHROME;
1850
- break;
2278
+ case 'PEARLESCENT':
2279
+ finishType = FINISH_TYPE_PEARLESCENT;
2280
+ break;
1851
2281
 
1852
- case 'PEARLESCENT':
1853
- finishType = FINISH_TYPE_PEARLESCENT;
1854
- break;
2282
+ case 'RUBBER':
2283
+ finishType = FINISH_TYPE_RUBBER;
2284
+ break;
1855
2285
 
1856
- case 'RUBBER':
1857
- finishType = FINISH_TYPE_RUBBER;
1858
- break;
2286
+ case 'MATTE_METALLIC':
2287
+ finishType = FINISH_TYPE_MATTE_METALLIC;
2288
+ break;
1859
2289
 
1860
- case 'MATTE_METALLIC':
1861
- finishType = FINISH_TYPE_MATTE_METALLIC;
1862
- break;
2290
+ case 'METAL':
2291
+ finishType = FINISH_TYPE_METAL;
2292
+ break;
1863
2293
 
1864
- case 'METAL':
1865
- finishType = FINISH_TYPE_METAL;
1866
- break;
2294
+ case 'MATERIAL':
2295
+ // Not implemented
2296
+ lineParser.setToEnd();
2297
+ break;
1867
2298
 
1868
- case 'MATERIAL':
1869
- // Not implemented
1870
- lineParser.setToEnd();
1871
- break;
2299
+ default:
2300
+ throw new Error( 'LDrawLoader: Unknown token "' + token + '" while parsing material' + lineParser.getLineNumberString() + '.' );
1872
2301
 
1873
- default:
1874
- throw new Error( 'LDrawLoader: Unknown token "' + token + '" while parsing material' + lineParser.getLineNumberString() + '.' );
2302
+ }
1875
2303
 
1876
2304
  }
1877
2305
 
@@ -1926,6 +2354,7 @@ class LDrawLoader extends Loader {
1926
2354
  material.premultipliedAlpha = true;
1927
2355
  material.opacity = alpha;
1928
2356
  material.depthWrite = ! isTransparent;
2357
+ material.color.convertSRGBToLinear();
1929
2358
 
1930
2359
  material.polygonOffset = true;
1931
2360
  material.polygonOffsetFactor = 1;
@@ -1947,6 +2376,7 @@ class LDrawLoader extends Loader {
1947
2376
  } );
1948
2377
  edgeMaterial.userData.code = code;
1949
2378
  edgeMaterial.name = name + ' - Edge';
2379
+ edgeMaterial.color.convertSRGBToLinear();
1950
2380
 
1951
2381
  // This is the material used for conditional edges
1952
2382
  edgeMaterial.userData.conditionalEdgeMaterial = new LDrawConditionalLineMaterial( {
@@ -1958,6 +2388,9 @@ class LDrawLoader extends Loader {
1958
2388
  opacity: alpha,
1959
2389
 
1960
2390
  } );
2391
+ edgeMaterial.userData.conditionalEdgeMaterial.color.convertSRGBToLinear();
2392
+ edgeMaterial.userData.conditionalEdgeMaterial.userData.code = code;
2393
+ edgeMaterial.userData.conditionalEdgeMaterial.name = name + ' - Conditional Edge';
1961
2394
 
1962
2395
  }
1963
2396
 
@@ -1966,113 +2399,35 @@ class LDrawLoader extends Loader {
1966
2399
 
1967
2400
  material.userData.edgeMaterial = edgeMaterial;
1968
2401
 
1969
- return material;
1970
-
1971
- }
1972
-
1973
- //
1974
-
1975
- objectParse( info, parseScope ) {
1976
-
1977
- // Retrieve data from the parent parse scope
1978
- const currentParseScope = parseScope;
1979
- const parentParseScope = currentParseScope.parentScope;
1980
-
1981
- // Main color codes passed to this subobject (or default codes 16 and 24 if it is the root object)
1982
- const mainColorCode = currentParseScope.mainColorCode;
1983
- const mainEdgeColorCode = currentParseScope.mainEdgeColorCode;
1984
-
1985
- const parseColorCode = ( colorCode, forEdge ) => {
1986
-
1987
- // Parses next color code and returns a THREE.Material
1988
-
1989
- if ( ! forEdge && colorCode === MAIN_COLOUR_CODE ) {
1990
-
1991
- colorCode = mainColorCode;
1992
-
1993
- }
1994
-
1995
- if ( forEdge && colorCode === MAIN_EDGE_COLOUR_CODE ) {
1996
-
1997
- colorCode = mainEdgeColorCode;
1998
-
1999
- }
2000
-
2001
- const material = this.getMaterial( colorCode, currentParseScope );
2002
-
2003
- if ( ! material ) {
2004
-
2005
- throw new Error( 'LDrawLoader: Unknown color code "' + colorCode + '" is used but it was not defined previously.' );
2006
-
2007
- }
2008
-
2009
- return material;
2010
-
2011
- };
2012
-
2013
- const faces = info.faces;
2014
- const lineSegments = info.lineSegments;
2015
- const conditionalSegments = info.conditionalSegments;
2016
- const materials = info.materials;
2017
- if ( currentParseScope.inverted ) {
2018
-
2019
- faces.reverse();
2020
-
2021
- }
2022
-
2023
- for ( const colorCode in materials ) {
2024
-
2025
- this.addMaterial( materials[ colorCode ], currentParseScope );
2402
+ this.addMaterial( material );
2026
2403
 
2027
- }
2404
+ return material;
2028
2405
 
2029
- for ( let i = 0, l = faces.length; i < l; i ++ ) {
2406
+ function parseLuminance( token ) {
2030
2407
 
2031
- const face = faces[ i ];
2032
- if ( face.material === null ) {
2408
+ // Returns success
2033
2409
 
2034
- face.material = parseColorCode( face.colorCode, false );
2410
+ let lum;
2035
2411
 
2036
- }
2412
+ if ( token.startsWith( 'LUMINANCE' ) ) {
2037
2413
 
2038
- }
2414
+ lum = parseInt( token.substring( 9 ) );
2039
2415
 
2040
- for ( let i = 0, l = lineSegments.length; i < l; i ++ ) {
2041
-
2042
- const ls = lineSegments[ i ];
2043
- if ( ls.material === null ) {
2416
+ } else {
2044
2417
 
2045
- ls.material = parseColorCode( ls.colorCode, true );
2418
+ lum = parseInt( token );
2046
2419
 
2047
2420
  }
2048
2421
 
2049
- }
2050
-
2051
- for ( let i = 0, l = conditionalSegments.length; i < l; i ++ ) {
2052
-
2053
- const cs = conditionalSegments[ i ];
2054
- if ( cs.material === null ) {
2422
+ if ( isNaN( lum ) ) {
2055
2423
 
2056
- cs.material = parseColorCode( cs.colorCode, true );
2424
+ return false;
2057
2425
 
2058
2426
  }
2059
2427
 
2060
- }
2061
-
2062
- currentParseScope.faces = info.faces;
2063
- currentParseScope.conditionalSegments = info.conditionalSegments;
2064
- currentParseScope.lineSegments = info.lineSegments;
2065
- currentParseScope.category = info.category;
2066
- currentParseScope.keywords = info.keywords;
2067
- currentParseScope.subobjects = info.subobjects;
2068
- currentParseScope.type = info.type;
2069
- currentParseScope.totalFaces = info.totalFaces;
2428
+ luminance = Math.max( 0, Math.min( 1, lum / 255 ) );
2070
2429
 
2071
- const isRoot = ! parentParseScope.isFromParse;
2072
- if ( isRoot || ! isPrimitiveType( info.type ) ) {
2073
-
2074
- currentParseScope.groupObject = new Group();
2075
- currentParseScope.groupObject.userData.startingConstructionStep = currentParseScope.startingConstructionStep;
2430
+ return true;
2076
2431
 
2077
2432
  }
2078
2433
 
@@ -2104,215 +2459,6 @@ class LDrawLoader extends Loader {
2104
2459
 
2105
2460
  }
2106
2461
 
2107
- finalizeObject( subobjectParseScope ) {
2108
-
2109
- // fail gracefully if an object could not be loaded
2110
- if ( subobjectParseScope === null ) {
2111
-
2112
- return;
2113
-
2114
- }
2115
-
2116
- const parentParseScope = subobjectParseScope.parentScope;
2117
-
2118
- // Smooth the normals if this is a part or if this is a case where the subpart
2119
- // is added directly into the parent model (meaning it will never get smoothed by
2120
- // being added to a part)
2121
- const doSmooth =
2122
- isPartType( subobjectParseScope.type ) ||
2123
- (
2124
- isPrimitiveType( subobjectParseScope.type ) &&
2125
- isModelType( subobjectParseScope.parentScope.type )
2126
- );
2127
-
2128
- if ( this.smoothNormals && doSmooth ) {
2129
-
2130
- generateFaceNormals( subobjectParseScope.faces );
2131
-
2132
- // only check subsetgments if we have multiple materials in a single part because this seems to be the case where it's needed most --
2133
- // there may be cases where a single edge line crosses over polygon edges that are broken up by multiple materials.
2134
- const checkSubSegments = subobjectParseScope.faceMaterials.size > 1;
2135
- smoothNormals( subobjectParseScope.faces, subobjectParseScope.lineSegments, checkSubSegments );
2136
-
2137
- }
2138
-
2139
- const isRoot = ! parentParseScope.isFromParse;
2140
- if ( ! isPrimitiveType( subobjectParseScope.type ) || isRoot ) {
2141
-
2142
- const objGroup = subobjectParseScope.groupObject;
2143
-
2144
- if ( subobjectParseScope.faces.length > 0 ) {
2145
-
2146
- objGroup.add( createObject( subobjectParseScope.faces, 3, false, subobjectParseScope.totalFaces ) );
2147
-
2148
- }
2149
-
2150
- if ( subobjectParseScope.lineSegments.length > 0 ) {
2151
-
2152
- objGroup.add( createObject( subobjectParseScope.lineSegments, 2 ) );
2153
-
2154
- }
2155
-
2156
- if ( subobjectParseScope.conditionalSegments.length > 0 ) {
2157
-
2158
- objGroup.add( createObject( subobjectParseScope.conditionalSegments, 2, true ) );
2159
-
2160
- }
2161
-
2162
- if ( parentParseScope.groupObject ) {
2163
-
2164
- objGroup.name = subobjectParseScope.fileName;
2165
- objGroup.userData.category = subobjectParseScope.category;
2166
- objGroup.userData.keywords = subobjectParseScope.keywords;
2167
- subobjectParseScope.matrix.decompose( objGroup.position, objGroup.quaternion, objGroup.scale );
2168
-
2169
- parentParseScope.groupObject.add( objGroup );
2170
-
2171
- }
2172
-
2173
- } else {
2174
-
2175
- const parentLineSegments = parentParseScope.lineSegments;
2176
- const parentConditionalSegments = parentParseScope.conditionalSegments;
2177
- const parentFaces = parentParseScope.faces;
2178
- const parentFaceMaterials = parentParseScope.faceMaterials;
2179
-
2180
- const lineSegments = subobjectParseScope.lineSegments;
2181
- const conditionalSegments = subobjectParseScope.conditionalSegments;
2182
- const faces = subobjectParseScope.faces;
2183
- const faceMaterials = subobjectParseScope.faceMaterials;
2184
- const matrix = subobjectParseScope.matrix;
2185
- const matrixScaleInverted = matrix.determinant() < 0;
2186
-
2187
- for ( let i = 0, l = lineSegments.length; i < l; i ++ ) {
2188
-
2189
- const ls = lineSegments[ i ];
2190
- const vertices = ls.vertices;
2191
- vertices[ 0 ].applyMatrix4( matrix );
2192
- vertices[ 1 ].applyMatrix4( matrix );
2193
-
2194
- parentLineSegments.push( ls );
2195
-
2196
- }
2197
-
2198
- for ( let i = 0, l = conditionalSegments.length; i < l; i ++ ) {
2199
-
2200
- const os = conditionalSegments[ i ];
2201
- const vertices = os.vertices;
2202
- const controlPoints = os.controlPoints;
2203
- vertices[ 0 ].applyMatrix4( matrix );
2204
- vertices[ 1 ].applyMatrix4( matrix );
2205
- controlPoints[ 0 ].applyMatrix4( matrix );
2206
- controlPoints[ 1 ].applyMatrix4( matrix );
2207
-
2208
- parentConditionalSegments.push( os );
2209
-
2210
- }
2211
-
2212
- for ( let i = 0, l = faces.length; i < l; i ++ ) {
2213
-
2214
- const tri = faces[ i ];
2215
- const vertices = tri.vertices;
2216
- for ( let i = 0, l = vertices.length; i < l; i ++ ) {
2217
-
2218
- vertices[ i ].applyMatrix4( matrix );
2219
-
2220
- }
2221
-
2222
- // If the scale of the object is negated then the triangle winding order
2223
- // needs to be flipped.
2224
- if ( matrixScaleInverted !== subobjectParseScope.inverted ) {
2225
-
2226
- vertices.reverse();
2227
-
2228
- }
2229
-
2230
- parentFaces.push( tri );
2231
-
2232
- }
2233
-
2234
- parentParseScope.totalFaces += subobjectParseScope.totalFaces;
2235
- faceMaterials.forEach( material => parentFaceMaterials.add( material ) );
2236
-
2237
- }
2238
-
2239
- }
2240
-
2241
- async processObject( parsedInfo, subobject, url, parentScope ) {
2242
-
2243
- const scope = this;
2244
-
2245
- const parseScope = this.newParseScopeLevel( null, parentScope );
2246
- parseScope.url = url;
2247
-
2248
- // Set current matrix
2249
- if ( subobject ) {
2250
-
2251
- parseScope.matrix.copy( subobject.matrix );
2252
- parseScope.inverted = subobject.inverted;
2253
- parseScope.startingConstructionStep = subobject.startingConstructionStep;
2254
- parseScope.fileName = subobject.fileName;
2255
- if ( subobject.colorCode === MAIN_COLOUR_CODE && parentScope ) {
2256
-
2257
- parseScope.mainColorCode = parentScope.mainColorCode;
2258
- parseScope.mainEdgeColorCode = parentScope.mainEdgeColorCode;
2259
-
2260
- } else if ( subobject.colorCode !== MAIN_COLOUR_CODE ) {
2261
-
2262
- parseScope.mainColorCode = subobject.colorCode;
2263
- parseScope.mainEdgeColorCode = subobject.colorCode;
2264
-
2265
- }
2266
-
2267
- }
2268
-
2269
- // Parse the object
2270
- this.objectParse( parsedInfo, parseScope );
2271
-
2272
- const subobjects = parseScope.subobjects;
2273
- const promises = [];
2274
- for ( let i = 0, l = subobjects.length; i < l; i ++ ) {
2275
-
2276
- promises.push( loadSubobject( subobjects[ i ] ) );
2277
-
2278
- }
2279
-
2280
- // Kick off of the downloads in parallel but process all the subobjects
2281
- // in order so all the assembly instructions are correct
2282
- const subobjectScopes = await Promise.all( promises );
2283
- for ( let i = 0, l = subobjectScopes.length; i < l; i ++ ) {
2284
-
2285
- this.finalizeObject( subobjectScopes[ i ] );
2286
-
2287
- }
2288
-
2289
- // If it is root object then finalize this object and compute construction steps
2290
- if ( ! parentScope.isFromParse ) {
2291
-
2292
- this.finalizeObject( parseScope );
2293
- this.computeConstructionSteps( parseScope.groupObject );
2294
-
2295
- }
2296
-
2297
- return parseScope;
2298
-
2299
- function loadSubobject( subobject ) {
2300
-
2301
- return scope.parseCache.loadData( subobject.fileName ).then( function ( parsedInfo ) {
2302
-
2303
- return scope.processObject( parsedInfo, subobject, url, parseScope );
2304
-
2305
- } ).catch( function ( err ) {
2306
-
2307
- console.warn( err );
2308
- return null;
2309
-
2310
- } );
2311
-
2312
- }
2313
-
2314
- }
2315
-
2316
2462
  }
2317
2463
 
2318
2464
  export { LDrawLoader };