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
@@ -10,13 +10,15 @@
10
10
  const FINISH_TYPE_METAL = 5; // State machine to search a subobject path.
11
11
  // The LDraw standard establishes these various possible subfolders.
12
12
 
13
- const FILE_LOCATION_AS_IS = 0;
14
- const FILE_LOCATION_TRY_PARTS = 1;
15
- const FILE_LOCATION_TRY_P = 2;
16
- const FILE_LOCATION_TRY_MODELS = 3;
13
+ const FILE_LOCATION_TRY_PARTS = 0;
14
+ const FILE_LOCATION_TRY_P = 1;
15
+ const FILE_LOCATION_TRY_MODELS = 2;
16
+ const FILE_LOCATION_AS_IS = 3;
17
17
  const FILE_LOCATION_TRY_RELATIVE = 4;
18
18
  const FILE_LOCATION_TRY_ABSOLUTE = 5;
19
19
  const FILE_LOCATION_NOT_FOUND = 6;
20
+ const MAIN_COLOUR_CODE = '16';
21
+ const MAIN_EDGE_COLOUR_CODE = '24';
20
22
 
21
23
  const _tempVec0 = new THREE.Vector3();
22
24
 
@@ -142,6 +144,17 @@
142
144
 
143
145
  }
144
146
 
147
+ class ConditionalLineSegments extends THREE.LineSegments {
148
+
149
+ constructor( geometry, material ) {
150
+
151
+ super( geometry, material );
152
+ this.isConditionalLine = true;
153
+
154
+ }
155
+
156
+ }
157
+
145
158
  function generateFaceNormals( faces ) {
146
159
 
147
160
  for ( let i = 0, l = faces.length; i < l; i ++ ) {
@@ -497,13 +510,7 @@
497
510
 
498
511
  function isPartType( type ) {
499
512
 
500
- return type === 'Part';
501
-
502
- }
503
-
504
- function isModelType( type ) {
505
-
506
- return type === 'Model' || type === 'Unofficial_Model';
513
+ return type === 'Part' || type === 'Unofficial_Part';
507
514
 
508
515
  }
509
516
 
@@ -597,14 +604,15 @@
597
604
 
598
605
  }
599
606
 
600
- }
607
+ } // Fetches and parses an intermediate representation of LDraw parts files.
608
+
601
609
 
602
610
  class LDrawParsedCache {
603
611
 
604
612
  constructor( loader ) {
605
613
 
606
614
  this.loader = loader;
607
- this.cache = {};
615
+ this._cache = {};
608
616
 
609
617
  }
610
618
 
@@ -647,10 +655,13 @@
647
655
  result.type = original.type;
648
656
  result.category = original.category;
649
657
  result.keywords = original.keywords;
658
+ result.author = original.author;
650
659
  result.subobjects = original.subobjects;
660
+ result.fileName = original.fileName;
651
661
  result.totalFaces = original.totalFaces;
652
662
  result.startingConstructionStep = original.startingConstructionStep;
653
663
  result.materials = original.materials;
664
+ result.group = null;
654
665
  return result;
655
666
 
656
667
  }
@@ -658,7 +669,7 @@
658
669
  async fetchData( fileName ) {
659
670
 
660
671
  let triedLowerCase = false;
661
- let locationState = FILE_LOCATION_AS_IS;
672
+ let locationState = FILE_LOCATION_TRY_PARTS;
662
673
 
663
674
  while ( locationState !== FILE_LOCATION_NOT_FOUND ) {
664
675
 
@@ -702,7 +713,7 @@
702
713
  fileName = fileName.toLowerCase();
703
714
  subobjectURL = fileName;
704
715
  triedLowerCase = true;
705
- locationState = FILE_LOCATION_AS_IS;
716
+ locationState = FILE_LOCATION_TRY_PARTS;
706
717
 
707
718
  }
708
719
 
@@ -733,7 +744,7 @@
733
744
 
734
745
  }
735
746
 
736
- parse( text ) {
747
+ parse( text, fileName = null ) {
737
748
 
738
749
  const loader = this.loader; // final results
739
750
 
@@ -745,13 +756,14 @@
745
756
 
746
757
  const getLocalMaterial = colorCode => {
747
758
 
748
- return colorCode in materials ? materials[ colorCode ] : null;
759
+ return materials[ colorCode ] || null;
749
760
 
750
761
  };
751
762
 
752
763
  let type = 'Model';
753
764
  let category = null;
754
765
  let keywords = null;
766
+ let author = null;
755
767
  let totalFaces = 0; // split into lines
756
768
 
757
769
  if ( text.indexOf( '\r\n' ) !== - 1 ) {
@@ -927,6 +939,10 @@
927
939
  startingConstructionStep = true;
928
940
  break;
929
941
 
942
+ case 'Author:':
943
+ author = lp.getToken();
944
+ break;
945
+
930
946
  default:
931
947
  // Other meta directives are not implemented
932
948
  break;
@@ -1132,40 +1148,385 @@
1132
1148
  type,
1133
1149
  category,
1134
1150
  keywords,
1151
+ author,
1135
1152
  subobjects,
1136
1153
  totalFaces,
1137
1154
  startingConstructionStep,
1138
- materials
1155
+ materials,
1156
+ fileName,
1157
+ group: null
1139
1158
  };
1140
1159
 
1141
- }
1160
+ } // returns an (optionally cloned) instance of the data
1161
+
1142
1162
 
1143
- loadData( fileName ) {
1163
+ getData( fileName, clone = true ) {
1144
1164
 
1145
1165
  const key = fileName.toLowerCase();
1166
+ const result = this._cache[ key ];
1167
+
1168
+ if ( result === null || result instanceof Promise ) {
1169
+
1170
+ return null;
1171
+
1172
+ }
1173
+
1174
+ if ( clone ) {
1175
+
1176
+ return this.cloneResult( result );
1177
+
1178
+ } else {
1179
+
1180
+ return result;
1181
+
1182
+ }
1146
1183
 
1147
- if ( ! ( key in this.cache ) ) {
1184
+ } // kicks off a fetch and parse of the requested data if it hasn't already been loaded. Returns when
1185
+ // the data is ready to use and can be retrieved synchronously with "getData".
1148
1186
 
1149
- this.cache[ key ] = this.fetchData( fileName ).then( text => {
1150
1187
 
1151
- return this.parse( text );
1188
+ async ensureDataLoaded( fileName ) {
1189
+
1190
+ const key = fileName.toLowerCase();
1191
+
1192
+ if ( ! ( key in this._cache ) ) {
1193
+
1194
+ // replace the promise with a copy of the parsed data for immediate processing
1195
+ this._cache[ key ] = this.fetchData( fileName ).then( text => {
1196
+
1197
+ const info = this.parse( text, fileName );
1198
+ this._cache[ key ] = info;
1199
+ return info;
1152
1200
 
1153
1201
  } );
1154
1202
 
1155
1203
  }
1156
1204
 
1157
- return this.cache[ key ].then( result => {
1205
+ await this._cache[ key ];
1158
1206
 
1159
- return this.cloneResult( result );
1207
+ } // sets the data in the cache from parsed data
1160
1208
 
1161
- } );
1209
+
1210
+ setData( fileName, text ) {
1211
+
1212
+ const key = fileName.toLowerCase();
1213
+ this._cache[ key ] = this.parse( text, fileName );
1162
1214
 
1163
1215
  }
1164
1216
 
1165
- setData( fileName, text ) {
1217
+ } // returns the material for an associated color code. If the color code is 16 for a face or 24 for
1218
+ // an edge then the passthroughColorCode is used.
1219
+
1220
+
1221
+ function getMaterialFromCode( colorCode, parentColorCode, materialHierarchy, forEdge ) {
1222
+
1223
+ const isPassthrough = ! forEdge && colorCode === MAIN_COLOUR_CODE || forEdge && colorCode === MAIN_EDGE_COLOUR_CODE;
1224
+
1225
+ if ( isPassthrough ) {
1226
+
1227
+ colorCode = parentColorCode;
1228
+
1229
+ }
1230
+
1231
+ return materialHierarchy[ colorCode ] || null;
1232
+
1233
+ } // Class used to parse and build LDraw parts as three.js objects and cache them if they're a "Part" type.
1234
+
1235
+
1236
+ class LDrawPartsGeometryCache {
1237
+
1238
+ constructor( loader ) {
1239
+
1240
+ this.loader = loader;
1241
+ this.parseCache = new LDrawParsedCache( loader );
1242
+ this._cache = {};
1243
+
1244
+ } // Convert the given file information into a mesh by processing subobjects.
1245
+
1246
+
1247
+ async processIntoMesh( info ) {
1248
+
1249
+ const loader = this.loader;
1250
+ const parseCache = this.parseCache;
1251
+ const faceMaterials = new Set(); // Processes the part subobject information to load child parts and merge geometry onto part
1252
+ // piece object.
1253
+
1254
+ const processInfoSubobjects = async ( info, subobject = null ) => {
1255
+
1256
+ const subobjects = info.subobjects;
1257
+ const promises = []; // Trigger load of all subobjects. If a subobject isn't a primitive then load it as a separate
1258
+ // group which lets instruction steps apply correctly.
1259
+
1260
+ for ( let i = 0, l = subobjects.length; i < l; i ++ ) {
1261
+
1262
+ const subobject = subobjects[ i ];
1263
+ const promise = parseCache.ensureDataLoaded( subobject.fileName ).then( () => {
1264
+
1265
+ const subobjectInfo = parseCache.getData( subobject.fileName, false );
1266
+
1267
+ if ( ! isPrimitiveType( subobjectInfo.type ) ) {
1268
+
1269
+ return this.loadModel( subobject.fileName ).catch( error => {
1270
+
1271
+ console.warn( error );
1272
+ return null;
1273
+
1274
+ } );
1275
+
1276
+ }
1277
+
1278
+ return processInfoSubobjects( parseCache.getData( subobject.fileName ), subobject );
1279
+
1280
+ } );
1281
+ promises.push( promise );
1282
+
1283
+ }
1284
+
1285
+ const group = new THREE.Group();
1286
+ group.userData.category = info.category;
1287
+ group.userData.keywords = info.keywords;
1288
+ group.userData.author = info.author;
1289
+ group.userData.type = info.type;
1290
+ group.userData.fileName = info.fileName;
1291
+ info.group = group;
1292
+ const subobjectInfos = await Promise.all( promises );
1293
+
1294
+ for ( let i = 0, l = subobjectInfos.length; i < l; i ++ ) {
1295
+
1296
+ const subobject = info.subobjects[ i ];
1297
+ const subobjectInfo = subobjectInfos[ i ];
1298
+
1299
+ if ( subobjectInfo === null ) {
1300
+
1301
+ // the subobject failed to load
1302
+ continue;
1303
+
1304
+ } // if the subobject was loaded as a separate group then apply the parent scopes materials
1305
+
1306
+
1307
+ if ( subobjectInfo.isGroup ) {
1308
+
1309
+ const subobjectGroup = subobjectInfo;
1310
+ subobject.matrix.decompose( subobjectGroup.position, subobjectGroup.quaternion, subobjectGroup.scale );
1311
+ subobjectGroup.userData.startingConstructionStep = subobject.startingConstructionStep;
1312
+ subobjectGroup.name = subobject.fileName;
1313
+ loader.applyMaterialsToMesh( subobjectGroup, subobject.colorCode, info.materials );
1314
+ subobjectGroup.userData.colorCode = subobject.colorCode;
1315
+ group.add( subobjectGroup );
1316
+ continue;
1317
+
1318
+ } // add the subobject group if it has children in case it has both children and primitives
1319
+
1320
+
1321
+ if ( subobjectInfo.group.children.length ) {
1322
+
1323
+ group.add( subobjectInfo.group );
1324
+
1325
+ } // transform the primitives into the local space of the parent piece and append them to
1326
+ // to the parent primitives list.
1327
+
1328
+
1329
+ const parentLineSegments = info.lineSegments;
1330
+ const parentConditionalSegments = info.conditionalSegments;
1331
+ const parentFaces = info.faces;
1332
+ const lineSegments = subobjectInfo.lineSegments;
1333
+ const conditionalSegments = subobjectInfo.conditionalSegments;
1334
+ const faces = subobjectInfo.faces;
1335
+ const matrix = subobject.matrix;
1336
+ const inverted = subobject.inverted;
1337
+ const matrixScaleInverted = matrix.determinant() < 0;
1338
+ const colorCode = subobject.colorCode;
1339
+ const lineColorCode = colorCode === MAIN_COLOUR_CODE ? MAIN_EDGE_COLOUR_CODE : colorCode;
1340
+
1341
+ for ( let i = 0, l = lineSegments.length; i < l; i ++ ) {
1342
+
1343
+ const ls = lineSegments[ i ];
1344
+ const vertices = ls.vertices;
1345
+ vertices[ 0 ].applyMatrix4( matrix );
1346
+ vertices[ 1 ].applyMatrix4( matrix );
1347
+ ls.colorCode = ls.colorCode === MAIN_EDGE_COLOUR_CODE ? lineColorCode : ls.colorCode;
1348
+ ls.material = ls.material || getMaterialFromCode( ls.colorCode, ls.colorCode, info.materials, true );
1349
+ parentLineSegments.push( ls );
1350
+
1351
+ }
1352
+
1353
+ for ( let i = 0, l = conditionalSegments.length; i < l; i ++ ) {
1354
+
1355
+ const os = conditionalSegments[ i ];
1356
+ const vertices = os.vertices;
1357
+ const controlPoints = os.controlPoints;
1358
+ vertices[ 0 ].applyMatrix4( matrix );
1359
+ vertices[ 1 ].applyMatrix4( matrix );
1360
+ controlPoints[ 0 ].applyMatrix4( matrix );
1361
+ controlPoints[ 1 ].applyMatrix4( matrix );
1362
+ os.colorCode = os.colorCode === MAIN_EDGE_COLOUR_CODE ? lineColorCode : os.colorCode;
1363
+ os.material = os.material || getMaterialFromCode( os.colorCode, os.colorCode, info.materials, true );
1364
+ parentConditionalSegments.push( os );
1365
+
1366
+ }
1367
+
1368
+ for ( let i = 0, l = faces.length; i < l; i ++ ) {
1369
+
1370
+ const tri = faces[ i ];
1371
+ const vertices = tri.vertices;
1372
+
1373
+ for ( let i = 0, l = vertices.length; i < l; i ++ ) {
1374
+
1375
+ vertices[ i ].applyMatrix4( matrix );
1376
+
1377
+ }
1378
+
1379
+ tri.colorCode = tri.colorCode === MAIN_COLOUR_CODE ? colorCode : tri.colorCode;
1380
+ tri.material = tri.material || getMaterialFromCode( tri.colorCode, colorCode, info.materials, false );
1381
+ faceMaterials.add( tri.colorCode ); // If the scale of the object is negated then the triangle winding order
1382
+ // needs to be flipped.
1383
+
1384
+ if ( matrixScaleInverted !== inverted ) {
1385
+
1386
+ vertices.reverse();
1387
+
1388
+ }
1389
+
1390
+ parentFaces.push( tri );
1166
1391
 
1392
+ }
1393
+
1394
+ info.totalFaces += subobjectInfo.totalFaces;
1395
+
1396
+ } // Apply the parent subobjects pass through material code to this object. This is done several times due
1397
+ // to material scoping.
1398
+
1399
+
1400
+ if ( subobject ) {
1401
+
1402
+ loader.applyMaterialsToMesh( group, subobject.colorCode, info.materials );
1403
+ group.userData.colorCode = subobject.colorCode;
1404
+
1405
+ }
1406
+
1407
+ return info;
1408
+
1409
+ }; // Track material use to see if we need to use the normal smooth slow path for hard edges.
1410
+
1411
+
1412
+ for ( let i = 0, l = info.faces; i < l; i ++ ) {
1413
+
1414
+ faceMaterials.add( info.faces[ i ].colorCode );
1415
+
1416
+ }
1417
+
1418
+ await processInfoSubobjects( info );
1419
+
1420
+ if ( loader.smoothNormals ) {
1421
+
1422
+ const checkSubSegments = faceMaterials.size > 1;
1423
+ generateFaceNormals( info.faces );
1424
+ smoothNormals( info.faces, info.lineSegments, checkSubSegments );
1425
+
1426
+ } // Add the primitive objects and metadata.
1427
+
1428
+
1429
+ const group = info.group;
1430
+
1431
+ if ( info.faces.length > 0 ) {
1432
+
1433
+ group.add( createObject( info.faces, 3, false, info.totalFaces ) );
1434
+
1435
+ }
1436
+
1437
+ if ( info.lineSegments.length > 0 ) {
1438
+
1439
+ group.add( createObject( info.lineSegments, 2 ) );
1440
+
1441
+ }
1442
+
1443
+ if ( info.conditionalSegments.length > 0 ) {
1444
+
1445
+ group.add( createObject( info.conditionalSegments, 2, true ) );
1446
+
1447
+ }
1448
+
1449
+ return group;
1450
+
1451
+ }
1452
+
1453
+ hasCachedModel( fileName ) {
1454
+
1455
+ return fileName !== null && fileName.toLowerCase() in this._cache;
1456
+
1457
+ }
1458
+
1459
+ async getCachedModel( fileName ) {
1460
+
1461
+ if ( fileName !== null && this.hasCachedModel( fileName ) ) {
1462
+
1463
+ const key = fileName.toLowerCase();
1464
+ const group = await this._cache[ key ];
1465
+ return group.clone();
1466
+
1467
+ } else {
1468
+
1469
+ return null;
1470
+
1471
+ }
1472
+
1473
+ } // Loads and parses the model with the given file name. Returns a cached copy if available.
1474
+
1475
+
1476
+ async loadModel( fileName ) {
1477
+
1478
+ const parseCache = this.parseCache;
1167
1479
  const key = fileName.toLowerCase();
1168
- this.cache[ key ] = Promise.resolve( this.parse( text ) );
1480
+
1481
+ if ( this.hasCachedModel( fileName ) ) {
1482
+
1483
+ // Return cached model if available.
1484
+ return this.getCachedModel( fileName );
1485
+
1486
+ } else {
1487
+
1488
+ // Otherwise parse a new model.
1489
+ // Ensure the file data is loaded and pre parsed.
1490
+ await parseCache.ensureDataLoaded( fileName );
1491
+ const info = parseCache.getData( fileName );
1492
+ const promise = this.processIntoMesh( info ); // Now that the file has loaded it's possible that another part parse has been waiting in parallel
1493
+ // so check the cache again to see if it's been added since the last async operation so we don't
1494
+ // do unnecessary work.
1495
+
1496
+ if ( this.hasCachedModel( fileName ) ) {
1497
+
1498
+ return this.getCachedModel( fileName );
1499
+
1500
+ } // Cache object if it's a part so it can be reused later.
1501
+
1502
+
1503
+ if ( isPartType( info.type ) ) {
1504
+
1505
+ this._cache[ key ] = promise;
1506
+
1507
+ } // return a copy
1508
+
1509
+
1510
+ const group = await promise;
1511
+ return group.clone();
1512
+
1513
+ }
1514
+
1515
+ } // parses the given model text into a renderable object. Returns cached copy if available.
1516
+
1517
+
1518
+ async parseModel( text ) {
1519
+
1520
+ const parseCache = this.parseCache;
1521
+ const info = parseCache.parse( text );
1522
+
1523
+ if ( isPartType( info.type ) && this.hasCachedModel( info.fileName ) ) {
1524
+
1525
+ return this.getCachedModel( info.fileName );
1526
+
1527
+ }
1528
+
1529
+ return this.processIntoMesh( info );
1169
1530
 
1170
1531
  }
1171
1532
 
@@ -1290,7 +1651,7 @@
1290
1651
 
1291
1652
  }
1292
1653
 
1293
- if ( prevMaterial !== elem.material ) {
1654
+ if ( prevMaterial !== elem.colorCode ) {
1294
1655
 
1295
1656
  if ( prevMaterial !== null ) {
1296
1657
 
@@ -1300,25 +1661,35 @@
1300
1661
 
1301
1662
  const material = elem.material;
1302
1663
 
1303
- if ( elementSize === 3 ) {
1664
+ if ( material !== null ) {
1304
1665
 
1305
- materials.push( material );
1666
+ if ( elementSize === 3 ) {
1306
1667
 
1307
- } else if ( elementSize === 2 ) {
1668
+ materials.push( material );
1308
1669
 
1309
- if ( isConditionalSegments ) {
1670
+ } else if ( elementSize === 2 ) {
1310
1671
 
1311
- materials.push( material.userData.edgeMaterial.userData.conditionalEdgeMaterial );
1672
+ if ( isConditionalSegments ) {
1312
1673
 
1313
- } else {
1674
+ materials.push( material.userData.edgeMaterial.userData.conditionalEdgeMaterial );
1675
+
1676
+ } else {
1314
1677
 
1315
- materials.push( material.userData.edgeMaterial );
1678
+ materials.push( material.userData.edgeMaterial );
1679
+
1680
+ }
1316
1681
 
1317
1682
  }
1318
1683
 
1684
+ } else {
1685
+
1686
+ // If a material has not been made available yet then keep the color code string in the material array
1687
+ // to save the spot for the material once a parent scopes materials are being applied to the object.
1688
+ materials.push( elem.colorCode );
1689
+
1319
1690
  }
1320
1691
 
1321
- prevMaterial = elem.material;
1692
+ prevMaterial = elem.colorCode;
1322
1693
  index0 = offset / 3;
1323
1694
  numGroupVerts = vertices.length;
1324
1695
 
@@ -1350,7 +1721,15 @@
1350
1721
 
1351
1722
  if ( elementSize === 2 ) {
1352
1723
 
1353
- object3d = new THREE.LineSegments( bufferGeometry, materials.length === 1 ? materials[ 0 ] : materials );
1724
+ if ( isConditionalSegments ) {
1725
+
1726
+ object3d = new ConditionalLineSegments( bufferGeometry, materials.length === 1 ? materials[ 0 ] : materials );
1727
+
1728
+ } else {
1729
+
1730
+ object3d = new THREE.LineSegments( bufferGeometry, materials.length === 1 ? materials[ 0 ] : materials );
1731
+
1732
+ }
1354
1733
 
1355
1734
  } else if ( elementSize === 3 ) {
1356
1735
 
@@ -1413,19 +1792,36 @@
1413
1792
 
1414
1793
  super( manager ); // Array of THREE.Material
1415
1794
 
1416
- this.materials = []; // Not using THREE.Cache here because it returns the previous HTML error response instead of calling onError()
1417
- // This also allows to handle the embedded text files ("0 FILE" lines)
1795
+ this.materials = [];
1796
+ this.materialLibrary = {}; // This also allows to handle the embedded text files ("0 FILE" lines)
1418
1797
 
1419
- this.parseCache = new LDrawParsedCache( this ); // 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.
1798
+ this.partsCache = new LDrawPartsGeometryCache( this ); // 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.
1420
1799
 
1421
- this.fileMap = {};
1422
- this.rootParseScope = this.newParseScopeLevel(); // Add default main triangle and line edge materials (used in pieces that can be colored with a main color)
1800
+ this.fileMap = {}; // Initializes the materials library with default materials
1423
1801
 
1424
- this.setMaterials( [ this.parseColorMetaDirective( new LineParser( 'Main_Colour CODE 16 VALUE #FF8080 EDGE #333333' ) ), this.parseColorMetaDirective( new LineParser( 'Edge_Colour CODE 24 VALUE #A0A0A0 EDGE #333333' ) ) ] ); // If this flag is set to true the vertex normals will be smoothed.
1802
+ this.setMaterials( [] ); // If this flag is set to true the vertex normals will be smoothed.
1425
1803
 
1426
1804
  this.smoothNormals = true; // The path to load parts from the LDraw parts library from.
1427
1805
 
1428
- this.partsLibraryPath = '';
1806
+ this.partsLibraryPath = ''; // Material assigned to not available colors for meshes and edges
1807
+
1808
+ this.missingColorMaterial = new THREE.MeshStandardMaterial( {
1809
+ color: 0xFF00FF,
1810
+ roughness: 0.3,
1811
+ metalness: 0
1812
+ } );
1813
+ this.missingColorMaterial.name = 'Missing material';
1814
+ this.missingEdgeColorMaterial = new THREE.LineBasicMaterial( {
1815
+ color: 0xFF00FF
1816
+ } );
1817
+ this.missingEdgeColorMaterial.name = 'Missing material - Edge';
1818
+ this.missingConditionalEdgeColorMaterial = new LDrawConditionalLineMaterial( {
1819
+ fog: true,
1820
+ color: 0xFF00FF
1821
+ } );
1822
+ this.missingConditionalEdgeColorMaterial.name = 'Missing material - Conditional Edge';
1823
+ this.missingColorMaterial.userData.edgeMaterial = this.missingEdgeColorMaterial;
1824
+ this.missingEdgeColorMaterial.userData.conditionalEdgeMaterial = this.missingConditionalEdgeColorMaterial;
1429
1825
 
1430
1826
  }
1431
1827
 
@@ -1473,24 +1869,27 @@
1473
1869
  fileLoader.setWithCredentials( this.withCredentials );
1474
1870
  fileLoader.load( url, text => {
1475
1871
 
1476
- const parsedInfo = this.parseCache.parse( text );
1477
- this.processObject( parsedInfo, null, url, this.rootParseScope ).then( function ( result ) {
1872
+ this.partsCache.parseModel( text, this.materialLibrary ).then( group => {
1478
1873
 
1479
- onLoad( result.groupObject );
1874
+ this.applyMaterialsToMesh( group, MAIN_COLOUR_CODE, this.materialLibrary, true );
1875
+ this.computeConstructionSteps( group );
1876
+ group.userData.fileName = url;
1877
+ onLoad( group );
1480
1878
 
1481
- } );
1879
+ } ).catch( onError );
1482
1880
 
1483
1881
  }, onProgress, onError );
1484
1882
 
1485
1883
  }
1486
1884
 
1487
- parse( text, path, onLoad ) {
1885
+ parse( text, onLoad ) {
1488
1886
 
1489
- // Async parse. This function calls onParse with the parsed THREE.Object3D as parameter
1490
- const parsedInfo = this.parseCache.parse( text );
1491
- this.processObject( parsedInfo, null, path, this.rootParseScope ).then( function ( result ) {
1887
+ this.partsCache.parseModel( text, this.materialLibrary ).then( group => {
1492
1888
 
1493
- onLoad( result.groupObject );
1889
+ this.applyMaterialsToMesh( group, MAIN_COLOUR_CODE, this.materialLibrary, true );
1890
+ this.computeConstructionSteps( group );
1891
+ group.userData.fileName = '';
1892
+ onLoad( group );
1494
1893
 
1495
1894
  } );
1496
1895
 
@@ -1498,88 +1897,47 @@
1498
1897
 
1499
1898
  setMaterials( materials ) {
1500
1899
 
1501
- // Clears parse scopes stack, adds new scope with material library
1502
- this.rootParseScope = this.newParseScopeLevel( materials );
1503
- this.rootParseScope.isFromParse = false;
1504
- this.materials = materials;
1505
- return this;
1506
-
1507
- }
1508
-
1509
- setFileMap( fileMap ) {
1510
-
1511
- this.fileMap = fileMap;
1512
- return this;
1513
-
1514
- }
1900
+ this.materialLibrary = {};
1901
+ this.materials = [];
1515
1902
 
1516
- newParseScopeLevel( materials = null, parentScope = null ) {
1903
+ for ( let i = 0, l = materials.length; i < l; i ++ ) {
1517
1904
 
1518
- // Adds a new scope level, assign materials to it and returns it
1519
- const matLib = {};
1905
+ this.addMaterial( materials[ i ] );
1520
1906
 
1521
- if ( materials ) {
1907
+ } // Add default main triangle and line edge materials (used in pieces that can be colored with a main color)
1522
1908
 
1523
- for ( let i = 0, n = materials.length; i < n; i ++ ) {
1524
1909
 
1525
- const material = materials[ i ];
1526
- matLib[ material.userData.code ] = material;
1910
+ this.addMaterial( this.parseColorMetaDirective( new LineParser( 'Main_Colour CODE 16 VALUE #FF8080 EDGE #333333' ) ) );
1911
+ this.addMaterial( this.parseColorMetaDirective( new LineParser( 'Edge_Colour CODE 24 VALUE #A0A0A0 EDGE #333333' ) ) );
1912
+ return this;
1527
1913
 
1528
- }
1914
+ }
1529
1915
 
1530
- }
1916
+ setFileMap( fileMap ) {
1531
1917
 
1532
- const newParseScope = {
1533
- parentScope: parentScope,
1534
- lib: matLib,
1535
- url: null,
1536
- // Subobjects
1537
- subobjects: null,
1538
- numSubobjects: 0,
1539
- subobjectIndex: 0,
1540
- inverted: false,
1541
- category: null,
1542
- keywords: null,
1543
- // Current subobject
1544
- currentFileName: null,
1545
- mainColorCode: parentScope ? parentScope.mainColorCode : '16',
1546
- mainEdgeColorCode: parentScope ? parentScope.mainEdgeColorCode : '24',
1547
- matrix: new THREE.Matrix4(),
1548
- type: 'Model',
1549
- groupObject: null,
1550
- // If false, it is a root material scope previous to parse
1551
- isFromParse: true,
1552
- faces: [],
1553
- lineSegments: [],
1554
- conditionalSegments: [],
1555
- totalFaces: 0,
1556
- faceMaterials: new Set(),
1557
- // If true, this object is the start of a construction step
1558
- startingConstructionStep: false
1559
- };
1560
- return newParseScope;
1918
+ this.fileMap = fileMap;
1919
+ return this;
1561
1920
 
1562
1921
  }
1563
1922
 
1564
- addMaterial( material, parseScope ) {
1923
+ addMaterial( material ) {
1565
1924
 
1566
1925
  // Adds a material to the material library which is on top of the parse scopes stack. And also to the materials array
1567
- const matLib = parseScope.lib;
1926
+ const matLib = this.materialLibrary;
1568
1927
 
1569
1928
  if ( ! matLib[ material.userData.code ] ) {
1570
1929
 
1571
1930
  this.materials.push( material );
1931
+ matLib[ material.userData.code ] = material;
1572
1932
 
1573
1933
  }
1574
1934
 
1575
- matLib[ material.userData.code ] = material;
1576
1935
  return this;
1577
1936
 
1578
1937
  }
1579
1938
 
1580
- getMaterial( colorCode, parseScope = this.rootParseScope ) {
1939
+ getMaterial( colorCode ) {
1581
1940
 
1582
- // Given a color code search its material in the parse scopes stack
1583
1941
  if ( colorCode.startsWith( '0x2' ) ) {
1584
1942
 
1585
1943
  // Special 'direct' material value (RGB color)
@@ -1588,24 +1946,119 @@
1588
1946
 
1589
1947
  }
1590
1948
 
1591
- while ( parseScope ) {
1949
+ return this.materialLibrary[ colorCode ] || null;
1950
+
1951
+ } // Applies the appropriate materials to a prebuilt hierarchy of geometry. Assumes that color codes are present
1952
+ // in the material array if they need to be filled in.
1953
+
1954
+
1955
+ applyMaterialsToMesh( group, parentColorCode, materialHierarchy, finalMaterialPass = false ) {
1956
+
1957
+ // find any missing materials as indicated by a color code string and replace it with a material from the current material lib
1958
+ const loader = this;
1959
+ const parentIsPassthrough = parentColorCode === MAIN_COLOUR_CODE;
1960
+ group.traverse( c => {
1961
+
1962
+ if ( c.isMesh || c.isLineSegments ) {
1963
+
1964
+ if ( Array.isArray( c.material ) ) {
1965
+
1966
+ for ( let i = 0, l = c.material.length; i < l; i ++ ) {
1967
+
1968
+ if ( ! c.material[ i ].isMaterial ) {
1969
+
1970
+ c.material[ i ] = getMaterial( c, c.material[ i ] );
1971
+
1972
+ }
1973
+
1974
+ }
1975
+
1976
+ } else if ( ! c.material.isMaterial ) {
1977
+
1978
+ c.material = getMaterial( c, c.material );
1979
+
1980
+ }
1981
+
1982
+ }
1983
+
1984
+ } ); // Returns the appropriate material for the object (line or face) given color code. If the code is "pass through"
1985
+ // (24 for lines, 16 for edges) then the pass through color code is used. If that is also pass through then it's
1986
+ // simply returned for the subsequent material application.
1987
+
1988
+ function getMaterial( c, colorCode ) {
1989
+
1990
+ // if our parent is a passthrough color code and we don't have the current material color available then
1991
+ // return early.
1992
+ if ( parentIsPassthrough && ! ( colorCode in materialHierarchy ) && ! finalMaterialPass ) {
1993
+
1994
+ return colorCode;
1995
+
1996
+ }
1997
+
1998
+ const forEdge = c.isLineSegments || c.isConditionalLine;
1999
+ const isPassthrough = ! forEdge && colorCode === MAIN_COLOUR_CODE || forEdge && colorCode === MAIN_EDGE_COLOUR_CODE;
2000
+
2001
+ if ( isPassthrough ) {
2002
+
2003
+ colorCode = parentColorCode;
2004
+
2005
+ }
2006
+
2007
+ let material = null;
2008
+
2009
+ if ( colorCode in materialHierarchy ) {
1592
2010
 
1593
- const material = parseScope.lib[ colorCode ];
2011
+ material = materialHierarchy[ colorCode ];
1594
2012
 
1595
- if ( material ) {
2013
+ } else if ( finalMaterialPass ) {
1596
2014
 
1597
- return material;
2015
+ // see if we can get the final material from from the "getMaterial" function which will attempt to
2016
+ // parse the "direct" colors
2017
+ material = loader.getMaterial( colorCode );
2018
+
2019
+ if ( material === null ) {
2020
+
2021
+ // otherwise throw a warning if this is final opportunity to set the material
2022
+ console.warn( `LDrawLoader: Material properties for code ${colorCode} not available.` ); // And return the 'missing color' material
2023
+
2024
+ material = loader.missingColorMaterial;
2025
+
2026
+ }
1598
2027
 
1599
2028
  } else {
1600
2029
 
1601
- parseScope = parseScope.parentScope;
2030
+ return colorCode;
2031
+
2032
+ }
2033
+
2034
+ if ( c.isLineSegments ) {
2035
+
2036
+ material = material.userData.edgeMaterial;
2037
+
2038
+ if ( c.isConditionalLine ) {
2039
+
2040
+ material = material.userData.conditionalEdgeMaterial;
2041
+
2042
+ }
1602
2043
 
1603
2044
  }
1604
2045
 
1605
- } // Material was not found
2046
+ return material;
2047
+
2048
+ }
2049
+
2050
+ }
2051
+
2052
+ getMainMaterial() {
2053
+
2054
+ return this.getMaterial( MAIN_COLOUR_CODE );
2055
+
2056
+ }
1606
2057
 
2058
+ getMainEdgeMaterial() {
1607
2059
 
1608
- return null;
2060
+ const mat = this.getMaterial( MAIN_EDGE_COLOUR_CODE );
2061
+ return mat ? mat.userData.edgeMaterial : null;
1609
2062
 
1610
2063
  }
1611
2064
 
@@ -1644,110 +2097,111 @@
1644
2097
 
1645
2098
  }
1646
2099
 
1647
- switch ( token.toUpperCase() ) {
2100
+ if ( ! parseLuminance( token ) ) {
1648
2101
 
1649
- case 'CODE':
1650
- code = lineParser.getToken();
1651
- break;
2102
+ switch ( token.toUpperCase() ) {
1652
2103
 
1653
- case 'VALUE':
1654
- color = lineParser.getToken();
2104
+ case 'CODE':
2105
+ code = lineParser.getToken();
2106
+ break;
1655
2107
 
1656
- if ( color.startsWith( '0x' ) ) {
2108
+ case 'VALUE':
2109
+ color = lineParser.getToken();
1657
2110
 
1658
- color = '#' + color.substring( 2 );
2111
+ if ( color.startsWith( '0x' ) ) {
1659
2112
 
1660
- } else if ( ! color.startsWith( '#' ) ) {
2113
+ color = '#' + color.substring( 2 );
1661
2114
 
1662
- throw new Error( 'LDrawLoader: Invalid color while parsing material' + lineParser.getLineNumberString() + '.' );
2115
+ } else if ( ! color.startsWith( '#' ) ) {
1663
2116
 
1664
- }
2117
+ throw new Error( 'LDrawLoader: Invalid color while parsing material' + lineParser.getLineNumberString() + '.' );
1665
2118
 
1666
- break;
2119
+ }
1667
2120
 
1668
- case 'EDGE':
1669
- edgeColor = lineParser.getToken();
2121
+ break;
1670
2122
 
1671
- if ( edgeColor.startsWith( '0x' ) ) {
2123
+ case 'EDGE':
2124
+ edgeColor = lineParser.getToken();
1672
2125
 
1673
- edgeColor = '#' + edgeColor.substring( 2 );
2126
+ if ( edgeColor.startsWith( '0x' ) ) {
1674
2127
 
1675
- } else if ( ! edgeColor.startsWith( '#' ) ) {
2128
+ edgeColor = '#' + edgeColor.substring( 2 );
1676
2129
 
1677
- // Try to see if edge color is a color code
1678
- edgeMaterial = this.getMaterial( edgeColor );
2130
+ } else if ( ! edgeColor.startsWith( '#' ) ) {
1679
2131
 
1680
- if ( ! edgeMaterial ) {
2132
+ // Try to see if edge color is a color code
2133
+ edgeMaterial = this.getMaterial( edgeColor );
1681
2134
 
1682
- throw new Error( 'LDrawLoader: Invalid edge color while parsing material' + lineParser.getLineNumberString() + '.' );
2135
+ if ( ! edgeMaterial ) {
1683
2136
 
1684
- } // Get the edge material for this triangle material
2137
+ throw new Error( 'LDrawLoader: Invalid edge color while parsing material' + lineParser.getLineNumberString() + '.' );
1685
2138
 
2139
+ } // Get the edge material for this triangle material
1686
2140
 
1687
- edgeMaterial = edgeMaterial.userData.edgeMaterial;
1688
2141
 
1689
- }
2142
+ edgeMaterial = edgeMaterial.userData.edgeMaterial;
1690
2143
 
1691
- break;
2144
+ }
1692
2145
 
1693
- case 'ALPHA':
1694
- alpha = parseInt( lineParser.getToken() );
2146
+ break;
1695
2147
 
1696
- if ( isNaN( alpha ) ) {
2148
+ case 'ALPHA':
2149
+ alpha = parseInt( lineParser.getToken() );
1697
2150
 
1698
- throw new Error( 'LDrawLoader: Invalid alpha value in material definition' + lineParser.getLineNumberString() + '.' );
2151
+ if ( isNaN( alpha ) ) {
1699
2152
 
1700
- }
2153
+ throw new Error( 'LDrawLoader: Invalid alpha value in material definition' + lineParser.getLineNumberString() + '.' );
1701
2154
 
1702
- alpha = Math.max( 0, Math.min( 1, alpha / 255 ) );
2155
+ }
1703
2156
 
1704
- if ( alpha < 1 ) {
2157
+ alpha = Math.max( 0, Math.min( 1, alpha / 255 ) );
1705
2158
 
1706
- isTransparent = true;
2159
+ if ( alpha < 1 ) {
1707
2160
 
1708
- }
2161
+ isTransparent = true;
1709
2162
 
1710
- break;
2163
+ }
1711
2164
 
1712
- case 'LUMINANCE':
1713
- luminance = parseInt( lineParser.getToken() );
2165
+ break;
1714
2166
 
1715
- if ( isNaN( luminance ) ) {
2167
+ case 'LUMINANCE':
2168
+ if ( ! parseLuminance( lineParser.getToken() ) ) {
1716
2169
 
1717
- throw new Error( 'LDrawLoader: Invalid luminance value in material definition' + LineParser.getLineNumberString() + '.' );
2170
+ throw new Error( 'LDrawLoader: Invalid luminance value in material definition' + LineParser.getLineNumberString() + '.' );
1718
2171
 
1719
- }
2172
+ }
1720
2173
 
1721
- luminance = Math.max( 0, Math.min( 1, luminance / 255 ) );
1722
- break;
2174
+ break;
1723
2175
 
1724
- case 'CHROME':
1725
- finishType = FINISH_TYPE_CHROME;
1726
- break;
2176
+ case 'CHROME':
2177
+ finishType = FINISH_TYPE_CHROME;
2178
+ break;
1727
2179
 
1728
- case 'PEARLESCENT':
1729
- finishType = FINISH_TYPE_PEARLESCENT;
1730
- break;
2180
+ case 'PEARLESCENT':
2181
+ finishType = FINISH_TYPE_PEARLESCENT;
2182
+ break;
1731
2183
 
1732
- case 'RUBBER':
1733
- finishType = FINISH_TYPE_RUBBER;
1734
- break;
2184
+ case 'RUBBER':
2185
+ finishType = FINISH_TYPE_RUBBER;
2186
+ break;
1735
2187
 
1736
- case 'MATTE_METALLIC':
1737
- finishType = FINISH_TYPE_MATTE_METALLIC;
1738
- break;
2188
+ case 'MATTE_METALLIC':
2189
+ finishType = FINISH_TYPE_MATTE_METALLIC;
2190
+ break;
1739
2191
 
1740
- case 'METAL':
1741
- finishType = FINISH_TYPE_METAL;
1742
- break;
2192
+ case 'METAL':
2193
+ finishType = FINISH_TYPE_METAL;
2194
+ break;
1743
2195
 
1744
- case 'MATERIAL':
1745
- // Not implemented
1746
- lineParser.setToEnd();
1747
- break;
2196
+ case 'MATERIAL':
2197
+ // Not implemented
2198
+ lineParser.setToEnd();
2199
+ break;
1748
2200
 
1749
- default:
1750
- throw new Error( 'LDrawLoader: Unknown token "' + token + '" while parsing material' + lineParser.getLineNumberString() + '.' );
2201
+ default:
2202
+ throw new Error( 'LDrawLoader: Unknown token "' + token + '" while parsing material' + lineParser.getLineNumberString() + '.' );
2203
+
2204
+ }
1751
2205
 
1752
2206
  }
1753
2207
 
@@ -1820,6 +2274,7 @@
1820
2274
  material.premultipliedAlpha = true;
1821
2275
  material.opacity = alpha;
1822
2276
  material.depthWrite = ! isTransparent;
2277
+ material.color.convertSRGBToLinear();
1823
2278
  material.polygonOffset = true;
1824
2279
  material.polygonOffsetFactor = 1;
1825
2280
 
@@ -1839,7 +2294,8 @@
1839
2294
  depthWrite: ! isTransparent
1840
2295
  } );
1841
2296
  edgeMaterial.userData.code = code;
1842
- edgeMaterial.name = name + ' - Edge'; // This is the material used for conditional edges
2297
+ edgeMaterial.name = name + ' - Edge';
2298
+ edgeMaterial.color.convertSRGBToLinear(); // This is the material used for conditional edges
1843
2299
 
1844
2300
  edgeMaterial.userData.conditionalEdgeMaterial = new LDrawConditionalLineMaterial( {
1845
2301
  fog: true,
@@ -1848,122 +2304,41 @@
1848
2304
  color: edgeColor,
1849
2305
  opacity: alpha
1850
2306
  } );
2307
+ edgeMaterial.userData.conditionalEdgeMaterial.color.convertSRGBToLinear();
2308
+ edgeMaterial.userData.conditionalEdgeMaterial.userData.code = code;
2309
+ edgeMaterial.userData.conditionalEdgeMaterial.name = name + ' - Conditional Edge';
1851
2310
 
1852
2311
  }
1853
2312
 
1854
2313
  material.userData.code = code;
1855
2314
  material.name = name;
1856
2315
  material.userData.edgeMaterial = edgeMaterial;
2316
+ this.addMaterial( material );
1857
2317
  return material;
1858
2318
 
1859
- } //
1860
-
1861
-
1862
- objectParse( info, parseScope ) {
1863
-
1864
- // Retrieve data from the parent parse scope
1865
- const currentParseScope = parseScope;
1866
- const parentParseScope = currentParseScope.parentScope; // Main color codes passed to this subobject (or default codes 16 and 24 if it is the root object)
1867
-
1868
- const mainColorCode = currentParseScope.mainColorCode;
1869
- const mainEdgeColorCode = currentParseScope.mainEdgeColorCode;
1870
-
1871
- const parseColorCode = ( colorCode, forEdge ) => {
1872
-
1873
- // Parses next color code and returns a THREE.Material
1874
- if ( ! forEdge && colorCode === '16' ) {
1875
-
1876
- colorCode = mainColorCode;
1877
-
1878
- }
1879
-
1880
- if ( forEdge && colorCode === '24' ) {
1881
-
1882
- colorCode = mainEdgeColorCode;
1883
-
1884
- }
1885
-
1886
- const material = this.getMaterial( colorCode, currentParseScope );
1887
-
1888
- if ( ! material ) {
1889
-
1890
- throw new Error( 'LDrawLoader: Unknown color code "' + colorCode + '" is used but it was not defined previously.' );
1891
-
1892
- }
1893
-
1894
- return material;
1895
-
1896
- };
1897
-
1898
- const faces = info.faces;
1899
- const lineSegments = info.lineSegments;
1900
- const conditionalSegments = info.conditionalSegments;
1901
- const materials = info.materials;
1902
-
1903
- if ( currentParseScope.inverted ) {
1904
-
1905
- faces.reverse();
1906
-
1907
- }
1908
-
1909
- for ( const colorCode in materials ) {
1910
-
1911
- this.addMaterial( materials[ colorCode ], currentParseScope );
1912
-
1913
- }
1914
-
1915
- for ( let i = 0, l = faces.length; i < l; i ++ ) {
1916
-
1917
- const face = faces[ i ];
1918
-
1919
- if ( face.material === null ) {
1920
-
1921
- face.material = parseColorCode( face.colorCode, false );
2319
+ function parseLuminance( token ) {
1922
2320
 
1923
- }
1924
-
1925
- }
2321
+ // Returns success
2322
+ let lum;
1926
2323
 
1927
- for ( let i = 0, l = lineSegments.length; i < l; i ++ ) {
2324
+ if ( token.startsWith( 'LUMINANCE' ) ) {
1928
2325
 
1929
- const ls = lineSegments[ i ];
2326
+ lum = parseInt( token.substring( 9 ) );
1930
2327
 
1931
- if ( ls.material === null ) {
2328
+ } else {
1932
2329
 
1933
- ls.material = parseColorCode( ls.colorCode, true );
2330
+ lum = parseInt( token );
1934
2331
 
1935
2332
  }
1936
2333
 
1937
- }
1938
-
1939
- for ( let i = 0, l = conditionalSegments.length; i < l; i ++ ) {
1940
-
1941
- const cs = conditionalSegments[ i ];
2334
+ if ( isNaN( lum ) ) {
1942
2335
 
1943
- if ( cs.material === null ) {
1944
-
1945
- cs.material = parseColorCode( cs.colorCode, true );
2336
+ return false;
1946
2337
 
1947
2338
  }
1948
2339
 
1949
- }
1950
-
1951
- currentParseScope.faces = info.faces;
1952
- currentParseScope.conditionalSegments = info.conditionalSegments;
1953
- currentParseScope.lineSegments = info.lineSegments;
1954
- currentParseScope.category = info.category;
1955
- currentParseScope.keywords = info.keywords;
1956
- currentParseScope.subobjects = info.subobjects;
1957
- currentParseScope.numSubobjects = info.subobjects.length;
1958
- currentParseScope.subobjectIndex = 0;
1959
- currentParseScope.type = info.type;
1960
- currentParseScope.totalFaces = info.totalFaces;
1961
- const isRoot = ! parentParseScope.isFromParse;
1962
-
1963
- if ( isRoot || ! isPrimitiveType( info.type ) ) {
1964
-
1965
- currentParseScope.groupObject = new THREE.Group();
1966
- currentParseScope.groupObject.userData.startingConstructionStep = currentParseScope.startingConstructionStep;
2340
+ luminance = Math.max( 0, Math.min( 1, lum / 255 ) );
2341
+ return true;
1967
2342
 
1968
2343
  }
1969
2344
 
@@ -1992,208 +2367,6 @@
1992
2367
 
1993
2368
  }
1994
2369
 
1995
- finalizeObject( subobjectParseScope ) {
1996
-
1997
- // fail gracefully if an object could not be loaded
1998
- if ( subobjectParseScope === null ) {
1999
-
2000
- return;
2001
-
2002
- }
2003
-
2004
- const parentParseScope = subobjectParseScope.parentScope; // Smooth the normals if this is a part or if this is a case where the subpart
2005
- // is added directly into the parent model (meaning it will never get smoothed by
2006
- // being added to a part)
2007
-
2008
- const doSmooth = isPartType( subobjectParseScope.type ) || isPrimitiveType( subobjectParseScope.type ) && isModelType( subobjectParseScope.parentScope.type );
2009
-
2010
- if ( this.smoothNormals && doSmooth ) {
2011
-
2012
- generateFaceNormals( subobjectParseScope.faces ); // only check subsetgments if we have multiple materials in a single part because this seems to be the case where it's needed most --
2013
- // there may be cases where a single edge line crosses over polygon edges that are broken up by multiple materials.
2014
-
2015
- const checkSubSegments = subobjectParseScope.faceMaterials.size > 1;
2016
- smoothNormals( subobjectParseScope.faces, subobjectParseScope.lineSegments, checkSubSegments );
2017
-
2018
- }
2019
-
2020
- const isRoot = ! parentParseScope.isFromParse;
2021
-
2022
- if ( ! isPrimitiveType( subobjectParseScope.type ) || isRoot ) {
2023
-
2024
- const objGroup = subobjectParseScope.groupObject;
2025
-
2026
- if ( subobjectParseScope.faces.length > 0 ) {
2027
-
2028
- objGroup.add( createObject( subobjectParseScope.faces, 3, false, subobjectParseScope.totalFaces ) );
2029
-
2030
- }
2031
-
2032
- if ( subobjectParseScope.lineSegments.length > 0 ) {
2033
-
2034
- objGroup.add( createObject( subobjectParseScope.lineSegments, 2 ) );
2035
-
2036
- }
2037
-
2038
- if ( subobjectParseScope.conditionalSegments.length > 0 ) {
2039
-
2040
- objGroup.add( createObject( subobjectParseScope.conditionalSegments, 2, true ) );
2041
-
2042
- }
2043
-
2044
- if ( parentParseScope.groupObject ) {
2045
-
2046
- objGroup.name = subobjectParseScope.fileName;
2047
- objGroup.userData.category = subobjectParseScope.category;
2048
- objGroup.userData.keywords = subobjectParseScope.keywords;
2049
- subobjectParseScope.matrix.decompose( objGroup.position, objGroup.quaternion, objGroup.scale );
2050
- parentParseScope.groupObject.add( objGroup );
2051
-
2052
- }
2053
-
2054
- } else {
2055
-
2056
- const parentLineSegments = parentParseScope.lineSegments;
2057
- const parentConditionalSegments = parentParseScope.conditionalSegments;
2058
- const parentFaces = parentParseScope.faces;
2059
- const parentFaceMaterials = parentParseScope.faceMaterials;
2060
- const lineSegments = subobjectParseScope.lineSegments;
2061
- const conditionalSegments = subobjectParseScope.conditionalSegments;
2062
- const faces = subobjectParseScope.faces;
2063
- const faceMaterials = subobjectParseScope.faceMaterials;
2064
- const matrix = subobjectParseScope.matrix;
2065
- const matrixScaleInverted = matrix.determinant() < 0;
2066
-
2067
- for ( let i = 0, l = lineSegments.length; i < l; i ++ ) {
2068
-
2069
- const ls = lineSegments[ i ];
2070
- const vertices = ls.vertices;
2071
- vertices[ 0 ].applyMatrix4( matrix );
2072
- vertices[ 1 ].applyMatrix4( matrix );
2073
- parentLineSegments.push( ls );
2074
-
2075
- }
2076
-
2077
- for ( let i = 0, l = conditionalSegments.length; i < l; i ++ ) {
2078
-
2079
- const os = conditionalSegments[ i ];
2080
- const vertices = os.vertices;
2081
- const controlPoints = os.controlPoints;
2082
- vertices[ 0 ].applyMatrix4( matrix );
2083
- vertices[ 1 ].applyMatrix4( matrix );
2084
- controlPoints[ 0 ].applyMatrix4( matrix );
2085
- controlPoints[ 1 ].applyMatrix4( matrix );
2086
- parentConditionalSegments.push( os );
2087
-
2088
- }
2089
-
2090
- for ( let i = 0, l = faces.length; i < l; i ++ ) {
2091
-
2092
- const tri = faces[ i ];
2093
- const vertices = tri.vertices;
2094
-
2095
- for ( let i = 0, l = vertices.length; i < l; i ++ ) {
2096
-
2097
- vertices[ i ].applyMatrix4( matrix );
2098
-
2099
- } // If the scale of the object is negated then the triangle winding order
2100
- // needs to be flipped.
2101
-
2102
-
2103
- if ( matrixScaleInverted !== subobjectParseScope.inverted ) {
2104
-
2105
- vertices.reverse();
2106
-
2107
- }
2108
-
2109
- parentFaces.push( tri );
2110
-
2111
- }
2112
-
2113
- parentParseScope.totalFaces += subobjectParseScope.totalFaces;
2114
- faceMaterials.forEach( material => parentFaceMaterials.add( material ) );
2115
-
2116
- }
2117
-
2118
- }
2119
-
2120
- async processObject( parsedInfo, subobject, url, parentScope ) {
2121
-
2122
- const scope = this;
2123
- const parseScope = this.newParseScopeLevel( null, parentScope );
2124
- parseScope.url = url;
2125
- const parentParseScope = parseScope.parentScope; // Set current matrix
2126
-
2127
- if ( subobject ) {
2128
-
2129
- parseScope.matrix.copy( subobject.matrix );
2130
- parseScope.inverted = subobject.inverted;
2131
- parseScope.startingConstructionStep = subobject.startingConstructionStep;
2132
- parseScope.fileName = subobject.fileName;
2133
-
2134
- if ( subobject.colorCode === '16' && parseScope.parentScope ) {
2135
-
2136
- const parentScope = parseScope.parentScope;
2137
- parseScope.mainColorCode = parentScope.mainColorCode;
2138
- parseScope.mainEdgeColorCode = parentScope.mainEdgeColorCode;
2139
-
2140
- } else if ( subobject.colorCode !== '16' ) {
2141
-
2142
- parseScope.mainColorCode = subobject.colorCode;
2143
- parseScope.mainEdgeColorCode = subobject.colorCode;
2144
-
2145
- }
2146
-
2147
- } // Parse the object
2148
-
2149
-
2150
- this.objectParse( parsedInfo, parseScope );
2151
- const subobjects = parseScope.subobjects;
2152
- const promises = [];
2153
-
2154
- for ( let i = 0, l = subobjects.length; i < l; i ++ ) {
2155
-
2156
- promises.push( loadSubobject( parseScope.subobjects[ i ] ) );
2157
-
2158
- } // Kick off of the downloads in parallel but process all the subobjects
2159
- // in order so all the assembly instructions are correct
2160
-
2161
-
2162
- const subobjectScopes = await Promise.all( promises );
2163
-
2164
- for ( let i = 0, l = subobjectScopes.length; i < l; i ++ ) {
2165
-
2166
- this.finalizeObject( subobjectScopes[ i ] );
2167
-
2168
- } // If it is root object then finalize this object and compute construction steps
2169
-
2170
-
2171
- if ( ! parentParseScope.isFromParse ) {
2172
-
2173
- this.finalizeObject( parseScope );
2174
- this.computeConstructionSteps( parseScope.groupObject );
2175
-
2176
- }
2177
-
2178
- return parseScope;
2179
-
2180
- function loadSubobject( subobject ) {
2181
-
2182
- return scope.parseCache.loadData( subobject.fileName ).then( function ( parsedInfo ) {
2183
-
2184
- return scope.processObject( parsedInfo, subobject, url, parseScope );
2185
-
2186
- } ).catch( function ( err ) {
2187
-
2188
- console.warn( err );
2189
- return null;
2190
-
2191
- } );
2192
-
2193
- }
2194
-
2195
- }
2196
-
2197
2370
  }
2198
2371
 
2199
2372
  THREE.LDrawLoader = LDrawLoader;