super-three 0.147.0 → 0.152.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 (757) hide show
  1. package/LICENSE +1 -1
  2. package/build/three.cjs +36408 -21117
  3. package/build/three.js +37007 -21715
  4. package/build/three.min.js +3 -2
  5. package/build/three.module.js +6387 -5510
  6. package/build/three.module.min.js +6 -0
  7. package/examples/jsm/animation/AnimationClipCreator.js +5 -3
  8. package/examples/jsm/capabilities/WebGPU.js +2 -4
  9. package/examples/jsm/controls/ArcballControls.js +1828 -1821
  10. package/examples/jsm/controls/MapControls.js +28 -0
  11. package/examples/jsm/controls/OrbitControls.js +20 -45
  12. package/examples/jsm/controls/PointerLockControls.js +70 -65
  13. package/examples/jsm/controls/TrackballControls.js +18 -4
  14. package/examples/jsm/controls/TransformControls.js +0 -1
  15. package/examples/jsm/csm/CSM.js +11 -3
  16. package/examples/jsm/csm/CSMShader.js +7 -6
  17. package/examples/jsm/effects/AsciiEffect.js +3 -6
  18. package/examples/jsm/effects/OutlineEffect.js +1 -15
  19. package/examples/jsm/exporters/ColladaExporter.js +26 -14
  20. package/examples/jsm/exporters/DRACOExporter.js +53 -11
  21. package/examples/jsm/exporters/EXRExporter.js +3 -9
  22. package/examples/jsm/exporters/GLTFExporter.js +524 -111
  23. package/examples/jsm/exporters/KTX2Exporter.js +34 -23
  24. package/examples/jsm/exporters/MMDExporter.js +1 -1
  25. package/examples/jsm/exporters/PLYExporter.js +8 -1
  26. package/examples/jsm/exporters/STLExporter.js +8 -4
  27. package/examples/jsm/exporters/USDZExporter.js +22 -3
  28. package/examples/jsm/geometries/ConvexGeometry.js +0 -6
  29. package/examples/jsm/geometries/ParametricGeometry.js +10 -0
  30. package/examples/jsm/helpers/OctreeHelper.js +1 -0
  31. package/examples/jsm/helpers/ViewHelper.js +70 -56
  32. package/examples/jsm/interactive/HTMLMesh.js +16 -3
  33. package/examples/jsm/interactive/InteractiveGroup.js +1 -1
  34. package/examples/{js → jsm}/libs/basis/README.md +4 -4
  35. package/examples/jsm/libs/draco/draco_decoder.js +34 -0
  36. package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
  37. package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -0
  38. package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -0
  39. package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
  40. package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -0
  41. package/examples/jsm/libs/lil-gui.module.min.js +2 -2
  42. package/examples/jsm/libs/tween.module.js +803 -0
  43. package/examples/jsm/lights/IESSpotLight.js +25 -0
  44. package/examples/jsm/lights/LightProbeGenerator.js +11 -9
  45. package/examples/jsm/lines/LineSegments2.js +12 -10
  46. package/examples/jsm/loaders/3DMLoader.js +8 -5
  47. package/examples/jsm/loaders/3MFLoader.js +12 -11
  48. package/examples/jsm/loaders/AMFLoader.js +2 -3
  49. package/examples/jsm/loaders/BVHLoader.js +2 -2
  50. package/examples/jsm/loaders/ColladaLoader.js +15 -16
  51. package/examples/jsm/loaders/DRACOLoader.js +67 -18
  52. package/examples/jsm/loaders/EXRLoader.js +23 -24
  53. package/examples/jsm/loaders/FBXLoader.js +32 -50
  54. package/examples/jsm/loaders/GCodeLoader.js +1 -2
  55. package/examples/jsm/loaders/GLTFLoader.js +249 -215
  56. package/examples/jsm/loaders/HDRCubeTextureLoader.js +4 -4
  57. package/examples/jsm/loaders/IESLoader.js +337 -0
  58. package/examples/jsm/loaders/KMZLoader.js +4 -4
  59. package/examples/jsm/loaders/KTX2Loader.js +41 -24
  60. package/examples/jsm/loaders/LDrawLoader.js +20 -18
  61. package/examples/jsm/loaders/LWOLoader.js +12 -29
  62. package/examples/jsm/loaders/LottieLoader.js +3 -1
  63. package/examples/jsm/loaders/MMDLoader.js +17 -13
  64. package/examples/jsm/loaders/MTLLoader.js +2 -2
  65. package/examples/jsm/loaders/MaterialXLoader.js +9 -3
  66. package/examples/jsm/loaders/NRRDLoader.js +33 -5
  67. package/examples/jsm/loaders/OBJLoader.js +1 -1
  68. package/examples/jsm/loaders/PCDLoader.js +1 -2
  69. package/examples/jsm/loaders/PLYLoader.js +238 -105
  70. package/examples/jsm/loaders/RGBELoader.js +3 -3
  71. package/examples/jsm/loaders/STLLoader.js +1 -2
  72. package/examples/jsm/loaders/SVGLoader.js +36 -27
  73. package/examples/jsm/loaders/TTFLoader.js +1 -8
  74. package/examples/jsm/loaders/TiltLoader.js +13 -7
  75. package/examples/jsm/loaders/USDZLoader.js +5 -5
  76. package/examples/jsm/loaders/VOXLoader.js +8 -2
  77. package/examples/jsm/loaders/VRMLLoader.js +5 -13
  78. package/examples/jsm/loaders/VTKLoader.js +7 -6
  79. package/examples/jsm/loaders/lwo/IFFParser.js +19 -19
  80. package/examples/jsm/materials/MeshGouraudMaterial.js +0 -3
  81. package/examples/jsm/math/MeshSurfaceSampler.js +0 -6
  82. package/examples/jsm/misc/ConvexObjectBreaker.js +2 -8
  83. package/examples/jsm/misc/GPUComputationRenderer.js +5 -5
  84. package/examples/jsm/misc/MD2Character.js +2 -2
  85. package/examples/jsm/misc/MD2CharacterComplex.js +2 -2
  86. package/examples/jsm/misc/ProgressiveLightMap.js +12 -10
  87. package/examples/jsm/misc/RollerCoaster.js +7 -1
  88. package/examples/jsm/misc/Volume.js +20 -5
  89. package/examples/jsm/modifiers/CurveModifier.js +1 -0
  90. package/examples/jsm/modifiers/TessellateModifier.js +19 -19
  91. package/examples/jsm/nodes/Nodes.js +143 -335
  92. package/examples/jsm/nodes/accessors/BitangentNode.js +43 -16
  93. package/examples/jsm/nodes/accessors/BufferNode.js +6 -0
  94. package/examples/jsm/nodes/accessors/CameraNode.js +12 -2
  95. package/examples/jsm/nodes/accessors/CubeTextureNode.js +27 -33
  96. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +58 -0
  97. package/examples/jsm/nodes/accessors/InstanceNode.js +17 -21
  98. package/examples/jsm/nodes/accessors/MaterialNode.js +155 -38
  99. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +16 -0
  100. package/examples/jsm/nodes/accessors/ModelNode.js +11 -0
  101. package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +12 -8
  102. package/examples/jsm/nodes/accessors/NormalNode.js +35 -19
  103. package/examples/jsm/nodes/accessors/Object3DNode.js +32 -12
  104. package/examples/jsm/nodes/accessors/PointUVNode.js +6 -1
  105. package/examples/jsm/nodes/accessors/PositionNode.js +38 -23
  106. package/examples/jsm/nodes/accessors/ReferenceNode.js +21 -14
  107. package/examples/jsm/nodes/accessors/ReflectVectorNode.js +11 -7
  108. package/examples/jsm/nodes/accessors/SkinningNode.js +43 -40
  109. package/examples/jsm/nodes/accessors/StorageBufferNode.js +6 -0
  110. package/examples/jsm/nodes/accessors/TangentNode.js +28 -20
  111. package/examples/jsm/nodes/accessors/TextureNode.js +80 -12
  112. package/examples/jsm/nodes/accessors/UVNode.js +6 -0
  113. package/examples/jsm/nodes/accessors/UserDataNode.js +6 -0
  114. package/examples/jsm/nodes/{core → code}/CodeNode.js +27 -2
  115. package/examples/jsm/nodes/code/ExpressionNode.js +37 -0
  116. package/examples/jsm/nodes/{core → code}/FunctionCallNode.js +15 -1
  117. package/examples/jsm/nodes/{core → code}/FunctionNode.js +8 -7
  118. package/examples/jsm/nodes/code/ScriptableNode.js +488 -0
  119. package/examples/jsm/nodes/code/ScriptableValueNode.js +167 -0
  120. package/examples/jsm/nodes/core/ArrayUniformNode.js +3 -0
  121. package/examples/jsm/nodes/core/AttributeNode.js +16 -8
  122. package/examples/jsm/nodes/core/BypassNode.js +9 -2
  123. package/examples/jsm/nodes/core/CacheNode.js +46 -0
  124. package/examples/jsm/nodes/core/ConstNode.js +3 -0
  125. package/examples/jsm/nodes/core/ContextNode.js +8 -1
  126. package/examples/jsm/nodes/core/InputNode.js +26 -5
  127. package/examples/jsm/nodes/core/InstanceIndexNode.js +6 -1
  128. package/examples/jsm/nodes/core/LightingModel.js +16 -0
  129. package/examples/jsm/nodes/core/Node.js +128 -34
  130. package/examples/jsm/nodes/core/NodeBuilder.js +209 -118
  131. package/examples/jsm/nodes/core/NodeCache.js +26 -0
  132. package/examples/jsm/nodes/core/NodeFrame.js +56 -5
  133. package/examples/jsm/nodes/core/NodeUtils.js +105 -28
  134. package/examples/jsm/nodes/core/PropertyNode.js +19 -2
  135. package/examples/jsm/nodes/core/StackNode.js +92 -0
  136. package/examples/jsm/nodes/core/TempNode.js +11 -3
  137. package/examples/jsm/nodes/core/UniformNode.js +15 -0
  138. package/examples/jsm/nodes/core/VarNode.js +21 -29
  139. package/examples/jsm/nodes/core/VaryingNode.js +15 -2
  140. package/examples/jsm/nodes/core/constants.js +6 -0
  141. package/examples/jsm/nodes/display/BlendModeNode.js +25 -11
  142. package/examples/jsm/nodes/display/ColorAdjustmentNode.js +30 -14
  143. package/examples/jsm/nodes/display/ColorSpaceNode.js +39 -27
  144. package/examples/jsm/nodes/display/FrontFacingNode.js +7 -1
  145. package/examples/jsm/nodes/display/NormalMapNode.js +31 -18
  146. package/examples/jsm/nodes/display/PosterizeNode.js +10 -3
  147. package/examples/jsm/nodes/display/ToneMappingNode.js +92 -11
  148. package/examples/jsm/nodes/display/ViewportNode.js +27 -18
  149. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +30 -0
  150. package/examples/jsm/nodes/display/ViewportTextureNode.js +61 -0
  151. package/examples/jsm/nodes/fog/FogExp2Node.js +35 -0
  152. package/examples/jsm/nodes/fog/FogNode.js +12 -6
  153. package/examples/jsm/nodes/fog/FogRangeNode.js +12 -5
  154. package/examples/jsm/nodes/functions/BSDF/BRDF_BlinnPhong.js +30 -0
  155. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +10 -13
  156. package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
  157. package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +8 -6
  158. package/examples/jsm/nodes/functions/BSDF/D_GGX.js +4 -4
  159. package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +3 -3
  160. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +7 -5
  161. package/examples/jsm/nodes/functions/PhongLightingModel.js +28 -0
  162. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +33 -36
  163. package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +4 -3
  164. package/examples/jsm/nodes/functions/material/getRoughness.js +4 -4
  165. package/examples/jsm/nodes/geometry/RangeNode.js +32 -19
  166. package/examples/jsm/nodes/gpgpu/ComputeNode.js +9 -2
  167. package/examples/jsm/nodes/lighting/AONode.js +5 -3
  168. package/examples/jsm/nodes/lighting/AmbientLightNode.js +27 -0
  169. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +112 -6
  170. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +43 -0
  171. package/examples/jsm/nodes/lighting/EnvironmentNode.js +104 -34
  172. package/examples/jsm/nodes/lighting/HemisphereLightNode.js +15 -10
  173. package/examples/jsm/nodes/lighting/IESSpotLightNode.js +39 -0
  174. package/examples/jsm/nodes/lighting/LightNode.js +57 -0
  175. package/examples/jsm/nodes/lighting/LightUtils.js +17 -0
  176. package/examples/jsm/nodes/lighting/LightingContextNode.js +30 -8
  177. package/examples/jsm/nodes/lighting/LightingNode.js +3 -1
  178. package/examples/jsm/nodes/lighting/LightsNode.js +18 -10
  179. package/examples/jsm/nodes/lighting/PointLightNode.js +71 -0
  180. package/examples/jsm/nodes/lighting/SpotLightNode.js +92 -0
  181. package/examples/jsm/nodes/loaders/NodeLoader.js +5 -4
  182. package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +4 -20
  183. package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +6 -9
  184. package/examples/jsm/nodes/materials/Materials.js +11 -55
  185. package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +5 -11
  186. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +48 -0
  187. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +74 -0
  188. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +6 -6
  189. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +21 -96
  190. package/examples/jsm/nodes/materials/NodeMaterial.js +244 -61
  191. package/examples/jsm/nodes/materials/PointsNodeMaterial.js +7 -1
  192. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +29 -25
  193. package/examples/jsm/nodes/materialx/MaterialXNodes.js +31 -22
  194. package/examples/jsm/nodes/materialx/lib/mx_hsv.js +1 -1
  195. package/examples/jsm/nodes/materialx/lib/mx_noise.js +2 -1
  196. package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +2 -1
  197. package/examples/jsm/nodes/math/CondNode.js +43 -17
  198. package/examples/jsm/nodes/math/MathNode.js +178 -73
  199. package/examples/jsm/nodes/math/OperatorNode.js +52 -2
  200. package/examples/jsm/nodes/procedural/CheckerNode.js +14 -6
  201. package/examples/jsm/nodes/shadernode/ShaderNode.js +158 -42
  202. package/examples/jsm/nodes/utils/ArrayElementNode.js +4 -2
  203. package/examples/jsm/nodes/utils/ConvertNode.js +19 -1
  204. package/examples/jsm/nodes/utils/DiscardNode.js +26 -0
  205. package/examples/jsm/nodes/utils/EquirectUVNode.js +11 -4
  206. package/examples/jsm/nodes/utils/JoinNode.js +4 -1
  207. package/examples/jsm/nodes/utils/MatcapUVNode.js +11 -4
  208. package/examples/jsm/nodes/utils/MaxMipLevelNode.js +18 -5
  209. package/examples/jsm/nodes/utils/OscNode.js +21 -14
  210. package/examples/jsm/nodes/utils/PackingNode.js +55 -0
  211. package/examples/jsm/nodes/utils/RemapNode.js +13 -5
  212. package/examples/jsm/nodes/utils/RotateUVNode.js +18 -7
  213. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +37 -0
  214. package/examples/jsm/nodes/utils/SplitNode.js +7 -5
  215. package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +15 -30
  216. package/examples/jsm/nodes/utils/TimerNode.js +16 -6
  217. package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +21 -10
  218. package/examples/jsm/objects/GroundProjectedSkybox.js +172 -0
  219. package/examples/jsm/objects/Reflector.js +4 -4
  220. package/examples/jsm/objects/Refractor.js +4 -4
  221. package/examples/jsm/objects/ShadowMesh.js +3 -3
  222. package/examples/jsm/physics/AmmoPhysics.js +27 -28
  223. package/examples/jsm/physics/{OimoPhysics.js → RapierPhysics.js} +59 -51
  224. package/examples/jsm/postprocessing/AdaptiveToneMappingPass.js +0 -8
  225. package/examples/jsm/postprocessing/AfterimagePass.js +0 -2
  226. package/examples/jsm/postprocessing/BloomPass.js +0 -2
  227. package/examples/jsm/postprocessing/BokehPass.js +0 -6
  228. package/examples/jsm/postprocessing/DotScreenPass.js +0 -2
  229. package/examples/jsm/postprocessing/EffectComposer.js +3 -94
  230. package/examples/jsm/postprocessing/FilmPass.js +0 -2
  231. package/examples/jsm/postprocessing/GlitchPass.js +0 -2
  232. package/examples/jsm/postprocessing/HalftonePass.js +0 -6
  233. package/examples/jsm/postprocessing/OutlinePass.js +0 -1
  234. package/examples/jsm/postprocessing/Pass.js +2 -0
  235. package/examples/jsm/postprocessing/SAOPass.js +0 -24
  236. package/examples/jsm/postprocessing/SMAAPass.js +0 -6
  237. package/examples/jsm/postprocessing/SSAARenderPass.js +13 -5
  238. package/examples/jsm/postprocessing/SSAOPass.js +0 -12
  239. package/examples/jsm/postprocessing/SSRPass.js +0 -6
  240. package/examples/jsm/postprocessing/SavePass.js +0 -2
  241. package/examples/jsm/postprocessing/TexturePass.js +0 -2
  242. package/examples/jsm/postprocessing/UnrealBloomPass.js +0 -8
  243. package/examples/jsm/renderers/CSS2DRenderer.js +6 -1
  244. package/examples/jsm/renderers/CSS3DRenderer.js +27 -5
  245. package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +35 -31
  246. package/examples/jsm/renderers/webgpu/WebGPUAnimation.js +2 -2
  247. package/examples/jsm/renderers/webgpu/WebGPUAttributes.js +14 -4
  248. package/examples/jsm/renderers/webgpu/WebGPUBackground.js +72 -55
  249. package/examples/jsm/renderers/webgpu/WebGPUBindings.js +34 -19
  250. package/examples/jsm/renderers/webgpu/WebGPUComputePipelines.js +1 -1
  251. package/examples/jsm/renderers/webgpu/WebGPUGeometries.js +158 -26
  252. package/examples/jsm/renderers/webgpu/WebGPUProgrammableStage.js +1 -1
  253. package/examples/jsm/renderers/webgpu/WebGPUProperties.js +6 -0
  254. package/examples/jsm/renderers/webgpu/WebGPURenderLists.js +30 -14
  255. package/examples/jsm/renderers/webgpu/WebGPURenderObject.js +40 -0
  256. package/examples/jsm/renderers/webgpu/WebGPURenderObjects.js +50 -0
  257. package/examples/jsm/renderers/webgpu/WebGPURenderPipeline.js +49 -111
  258. package/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js +40 -62
  259. package/examples/jsm/renderers/webgpu/WebGPURenderStates.js +14 -26
  260. package/examples/jsm/renderers/webgpu/WebGPURenderTarget.js +15 -0
  261. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +244 -100
  262. package/examples/jsm/renderers/webgpu/WebGPUSampledTexture.js +3 -1
  263. package/examples/jsm/renderers/webgpu/WebGPUTextureRenderer.js +2 -4
  264. package/examples/jsm/renderers/webgpu/WebGPUTextureUtils.js +2 -0
  265. package/examples/jsm/renderers/webgpu/WebGPUTextures.js +366 -110
  266. package/examples/jsm/renderers/webgpu/WebGPUUniformsGroup.js +1 -1
  267. package/examples/jsm/renderers/webgpu/WebGPUUtils.js +13 -6
  268. package/examples/jsm/renderers/webgpu/WebGPUWeakMap.js +83 -0
  269. package/examples/jsm/renderers/webgpu/constants.js +68 -6
  270. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js +74 -57
  271. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodes.js +241 -22
  272. package/examples/jsm/shaders/MMDToonShader.js +15 -4
  273. package/examples/jsm/shaders/RGBShiftShader.js +2 -2
  274. package/examples/jsm/shaders/VelocityShader.js +1 -1
  275. package/examples/jsm/utils/BufferGeometryUtils.js +37 -35
  276. package/examples/jsm/utils/LDrawUtils.js +4 -4
  277. package/examples/jsm/utils/PackedPhongMaterial.js +5 -78
  278. package/examples/jsm/utils/SceneUtils.js +8 -4
  279. package/examples/jsm/utils/SkeletonUtils.js +27 -210
  280. package/examples/jsm/webxr/VRButton.js +1 -2
  281. package/examples/jsm/webxr/XRButton.js +198 -0
  282. package/package.json +33 -87
  283. package/src/Three.Legacy.js +19 -110
  284. package/src/Three.js +4 -3
  285. package/src/animation/AnimationUtils.js +13 -1
  286. package/src/animation/PropertyBinding.js +2 -2
  287. package/src/audio/Audio.js +7 -2
  288. package/src/constants.js +10 -2
  289. package/src/core/BufferAttribute.js +147 -8
  290. package/src/core/BufferGeometry.js +3 -9
  291. package/src/core/GLBufferAttribute.js +2 -0
  292. package/src/core/InterleavedBufferAttribute.js +1 -1
  293. package/src/core/Object3D.js +36 -7
  294. package/src/extras/DataUtils.js +7 -1
  295. package/src/extras/ImageUtils.js +2 -2
  296. package/src/extras/PMREMGenerator.js +5 -5
  297. package/src/extras/curves/LineCurve.js +6 -4
  298. package/src/extras/curves/LineCurve3.js +13 -0
  299. package/src/geometries/BoxGeometry.js +10 -0
  300. package/src/geometries/CircleGeometry.js +11 -1
  301. package/src/geometries/ConeGeometry.js +1 -1
  302. package/src/geometries/CylinderGeometry.js +11 -1
  303. package/src/geometries/EdgesGeometry.js +10 -0
  304. package/src/geometries/ExtrudeGeometry.js +11 -1
  305. package/src/geometries/LatheGeometry.js +10 -0
  306. package/src/geometries/PlaneGeometry.js +10 -0
  307. package/src/geometries/PolyhedronGeometry.js +10 -0
  308. package/src/geometries/RingGeometry.js +11 -1
  309. package/src/geometries/ShapeGeometry.js +10 -0
  310. package/src/geometries/SphereGeometry.js +12 -2
  311. package/src/geometries/TorusGeometry.js +11 -1
  312. package/src/geometries/TorusKnotGeometry.js +10 -0
  313. package/src/geometries/TubeGeometry.js +10 -0
  314. package/src/geometries/WireframeGeometry.js +10 -0
  315. package/src/helpers/Box3Helper.js +1 -2
  316. package/src/lights/DirectionalLight.js +1 -1
  317. package/src/lights/HemisphereLight.js +1 -1
  318. package/src/lights/SpotLight.js +1 -1
  319. package/src/loaders/AudioLoader.js +14 -8
  320. package/src/loaders/DataTextureLoader.js +5 -1
  321. package/src/loaders/MaterialLoader.js +4 -0
  322. package/src/loaders/ObjectLoader.js +9 -2
  323. package/src/materials/LineBasicMaterial.js +4 -0
  324. package/src/materials/Material.js +6 -3
  325. package/src/materials/MeshDistanceMaterial.js +0 -9
  326. package/src/materials/ShaderMaterial.js +6 -1
  327. package/src/math/Box2.js +3 -2
  328. package/src/math/Box3.js +49 -64
  329. package/src/math/Color.js +72 -55
  330. package/src/math/ColorManagement.js +75 -16
  331. package/src/math/Euler.js +2 -11
  332. package/src/math/Frustum.js +13 -3
  333. package/src/math/MathUtils.js +27 -1
  334. package/src/math/Plane.js +2 -2
  335. package/src/math/Quaternion.js +6 -0
  336. package/src/math/Ray.js +7 -7
  337. package/src/math/Triangle.js +37 -7
  338. package/src/math/Vector2.js +16 -0
  339. package/src/math/Vector3.js +10 -0
  340. package/src/math/interpolants/CubicInterpolant.js +1 -2
  341. package/src/objects/InstancedMesh.js +79 -1
  342. package/src/objects/Mesh.js +101 -73
  343. package/src/objects/SkinnedMesh.js +95 -8
  344. package/src/objects/Sprite.js +1 -1
  345. package/src/renderers/WebGLCubeRenderTarget.js +12 -3
  346. package/src/renderers/WebGLMultipleRenderTargets.js +4 -2
  347. package/src/renderers/WebGLRenderTarget.js +14 -2
  348. package/src/renderers/WebGLRenderer.js +1340 -1258
  349. package/src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl.js +1 -1
  350. package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +1 -1
  351. package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +0 -271
  352. package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +5 -5
  353. package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js +2 -10
  354. package/src/renderers/shaders/ShaderChunk/clearcoat_pars_fragment.glsl.js +5 -5
  355. package/src/renderers/shaders/ShaderChunk/common.glsl.js +32 -0
  356. package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +1 -1
  357. package/src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl.js +1 -1
  358. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +1 -1
  359. package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +1 -1
  360. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +3 -3
  361. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +1 -1
  362. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +11 -11
  363. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +13 -13
  364. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +256 -10
  365. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +1 -11
  366. package/src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl.js +9 -1
  367. package/src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl.js +10 -2
  368. package/src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl.js +1 -1
  369. package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +32 -10
  370. package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +5 -13
  371. package/src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js +7 -7
  372. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +11 -5
  373. package/src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl.js +1 -1
  374. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +4 -11
  375. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +2 -2
  376. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +39 -34
  377. package/src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl.js +1 -1
  378. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +2 -2
  379. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +91 -11
  380. package/src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js +108 -1
  381. package/src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js +128 -6
  382. package/src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js +111 -1
  383. package/src/renderers/shaders/ShaderChunk.js +0 -6
  384. package/src/renderers/shaders/ShaderLib/background.glsl.js +0 -8
  385. package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +5 -0
  386. package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +1 -4
  387. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +0 -3
  388. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +3 -3
  389. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +0 -3
  390. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +8 -12
  391. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -3
  392. package/src/renderers/shaders/ShaderLib/points.glsl.js +13 -0
  393. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +5 -0
  394. package/src/renderers/shaders/ShaderLib.js +15 -4
  395. package/src/renderers/shaders/UniformsLib.js +25 -15
  396. package/src/renderers/shaders/UniformsUtils.js +12 -3
  397. package/src/renderers/webgl/WebGLBackground.js +23 -12
  398. package/src/renderers/webgl/WebGLCapabilities.js +1 -2
  399. package/src/renderers/webgl/WebGLClipping.js +7 -3
  400. package/src/renderers/webgl/WebGLLights.js +2 -2
  401. package/src/renderers/webgl/WebGLMaterials.js +105 -234
  402. package/src/renderers/webgl/WebGLMorphtargets.js +1 -1
  403. package/src/renderers/webgl/WebGLProgram.js +111 -48
  404. package/src/renderers/webgl/WebGLPrograms.js +200 -129
  405. package/src/renderers/webgl/WebGLRenderStates.js +2 -2
  406. package/src/renderers/webgl/WebGLShadowMap.js +40 -27
  407. package/src/renderers/webgl/WebGLState.js +23 -9
  408. package/src/renderers/webgl/WebGLTextures.js +21 -19
  409. package/src/renderers/webgl/WebGLUniformsGroups.js +74 -33
  410. package/src/renderers/webgl/WebGLUtils.js +41 -29
  411. package/src/renderers/webxr/WebXRController.js +3 -0
  412. package/src/renderers/webxr/WebXRManager.js +70 -48
  413. package/src/scenes/Scene.js +4 -6
  414. package/src/textures/CompressedTexture.js +2 -2
  415. package/src/textures/CubeTexture.js +2 -2
  416. package/src/textures/DataTexture.js +2 -2
  417. package/src/textures/Texture.js +41 -12
  418. package/src/utils.js +13 -1
  419. package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff +0 -0
  420. package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff2 +0 -0
  421. package/examples/fonts/open-sans/open-sans.css +0 -9
  422. package/examples/fonts/tabler-icons/fonts/tabler-icons.eot +0 -0
  423. package/examples/fonts/tabler-icons/fonts/tabler-icons.svg +0 -3966
  424. package/examples/fonts/tabler-icons/fonts/tabler-icons.ttf +0 -0
  425. package/examples/fonts/tabler-icons/fonts/tabler-icons.woff +0 -0
  426. package/examples/fonts/tabler-icons/fonts/tabler-icons.woff2 +0 -0
  427. package/examples/fonts/tabler-icons/tabler-icons.min.css +0 -4
  428. package/examples/js/animation/AnimationClipCreator.js +0 -89
  429. package/examples/js/animation/CCDIKSolver.js +0 -416
  430. package/examples/js/animation/MMDAnimationHelper.js +0 -1046
  431. package/examples/js/animation/MMDPhysics.js +0 -1174
  432. package/examples/js/cameras/CinematicCamera.js +0 -168
  433. package/examples/js/controls/ArcballControls.js +0 -2770
  434. package/examples/js/controls/DragControls.js +0 -205
  435. package/examples/js/controls/FirstPersonControls.js +0 -312
  436. package/examples/js/controls/FlyControls.js +0 -321
  437. package/examples/js/controls/OrbitControls.js +0 -1101
  438. package/examples/js/controls/PointerLockControls.js +0 -144
  439. package/examples/js/controls/TrackballControls.js +0 -729
  440. package/examples/js/controls/TransformControls.js +0 -1301
  441. package/examples/js/csm/CSM.js +0 -347
  442. package/examples/js/csm/CSMFrustum.js +0 -127
  443. package/examples/js/csm/CSMHelper.js +0 -165
  444. package/examples/js/csm/CSMShader.js +0 -253
  445. package/examples/js/curves/CurveExtras.js +0 -348
  446. package/examples/js/curves/NURBSCurve.js +0 -63
  447. package/examples/js/curves/NURBSSurface.js +0 -48
  448. package/examples/js/curves/NURBSUtils.js +0 -439
  449. package/examples/js/effects/AnaglyphEffect.js +0 -86
  450. package/examples/js/effects/AsciiEffect.js +0 -260
  451. package/examples/js/effects/OutlineEffect.js +0 -450
  452. package/examples/js/effects/ParallaxBarrierEffect.js +0 -62
  453. package/examples/js/effects/PeppersGhostEffect.js +0 -139
  454. package/examples/js/effects/StereoEffect.js +0 -46
  455. package/examples/js/environments/DebugEnvironment.js +0 -53
  456. package/examples/js/environments/RoomEnvironment.js +0 -124
  457. package/examples/js/exporters/ColladaExporter.js +0 -487
  458. package/examples/js/exporters/DRACOExporter.js +0 -212
  459. package/examples/js/exporters/EXRExporter.js +0 -455
  460. package/examples/js/exporters/GLTFExporter.js +0 -2367
  461. package/examples/js/exporters/MMDExporter.js +0 -187
  462. package/examples/js/exporters/OBJExporter.js +0 -260
  463. package/examples/js/exporters/PLYExporter.js +0 -427
  464. package/examples/js/exporters/STLExporter.js +0 -188
  465. package/examples/js/exporters/USDZExporter.js +0 -608
  466. package/examples/js/geometries/BoxLineGeometry.js +0 -59
  467. package/examples/js/geometries/ConvexGeometry.js +0 -53
  468. package/examples/js/geometries/DecalGeometry.js +0 -324
  469. package/examples/js/geometries/LightningStrike.js +0 -861
  470. package/examples/js/geometries/ParametricGeometries.js +0 -216
  471. package/examples/js/geometries/ParametricGeometry.js +0 -121
  472. package/examples/js/geometries/RoundedBoxGeometry.js +0 -142
  473. package/examples/js/geometries/TeapotGeometry.js +0 -335
  474. package/examples/js/geometries/TextGeometry.js +0 -53
  475. package/examples/js/helpers/LightProbeHelper.js +0 -48
  476. package/examples/js/helpers/OctreeHelper.js +0 -76
  477. package/examples/js/helpers/PositionalAudioHelper.js +0 -91
  478. package/examples/js/helpers/RectAreaLightHelper.js +0 -73
  479. package/examples/js/helpers/VertexNormalsHelper.js +0 -74
  480. package/examples/js/helpers/VertexTangentsHelper.js +0 -68
  481. package/examples/js/helpers/ViewHelper.js +0 -281
  482. package/examples/js/interactive/HTMLMesh.js +0 -497
  483. package/examples/js/interactive/InteractiveGroup.js +0 -95
  484. package/examples/js/interactive/SelectionBox.js +0 -195
  485. package/examples/js/interactive/SelectionHelper.js +0 -83
  486. package/examples/js/libs/chevrotain.min.js +0 -3
  487. package/examples/js/libs/draco/draco_decoder.js +0 -52
  488. package/examples/js/libs/draco/draco_decoder.wasm +0 -0
  489. package/examples/js/libs/draco/draco_wasm_wrapper.js +0 -104
  490. package/examples/js/libs/draco/gltf/draco_decoder.js +0 -48
  491. package/examples/js/libs/draco/gltf/draco_decoder.wasm +0 -0
  492. package/examples/js/libs/draco/gltf/draco_wasm_wrapper.js +0 -104
  493. package/examples/js/libs/fflate.min.js +0 -7
  494. package/examples/js/libs/ktx-parse.umd.js +0 -1
  495. package/examples/js/libs/meshopt_decoder.js +0 -188
  496. package/examples/js/libs/opentype.min.js +0 -1
  497. package/examples/js/libs/stats.min.js +0 -5
  498. package/examples/js/lights/LightProbeGenerator.js +0 -221
  499. package/examples/js/lights/RectAreaLightUniformsLib.js +0 -60
  500. package/examples/js/lines/Line2.js +0 -19
  501. package/examples/js/lines/LineGeometry.js +0 -69
  502. package/examples/js/lines/LineMaterial.js +0 -635
  503. package/examples/js/lines/LineSegments2.js +0 -313
  504. package/examples/js/lines/LineSegmentsGeometry.js +0 -198
  505. package/examples/js/lines/Wireframe.js +0 -47
  506. package/examples/js/lines/WireframeGeometry2.js +0 -20
  507. package/examples/js/loaders/3DMLoader.js +0 -1273
  508. package/examples/js/loaders/3MFLoader.js +0 -1306
  509. package/examples/js/loaders/AMFLoader.js +0 -504
  510. package/examples/js/loaders/BVHLoader.js +0 -395
  511. package/examples/js/loaders/BasisTextureLoader.js +0 -706
  512. package/examples/js/loaders/ColladaLoader.js +0 -3690
  513. package/examples/js/loaders/DDSLoader.js +0 -244
  514. package/examples/js/loaders/DRACOLoader.js +0 -511
  515. package/examples/js/loaders/EXRLoader.js +0 -2039
  516. package/examples/js/loaders/FBXLoader.js +0 -3681
  517. package/examples/js/loaders/FontLoader.js +0 -160
  518. package/examples/js/loaders/GCodeLoader.js +0 -255
  519. package/examples/js/loaders/GLTFLoader.js +0 -3862
  520. package/examples/js/loaders/HDRCubeTextureLoader.js +0 -87
  521. package/examples/js/loaders/KMZLoader.js +0 -121
  522. package/examples/js/loaders/KTXLoader.js +0 -159
  523. package/examples/js/loaders/LDrawLoader.js +0 -2263
  524. package/examples/js/loaders/LUT3dlLoader.js +0 -135
  525. package/examples/js/loaders/LUTCubeLoader.js +0 -132
  526. package/examples/js/loaders/LWOLoader.js +0 -901
  527. package/examples/js/loaders/LogLuvLoader.js +0 -715
  528. package/examples/js/loaders/LottieLoader.js +0 -62
  529. package/examples/js/loaders/MD2Loader.js +0 -248
  530. package/examples/js/loaders/MDDLoader.js +0 -91
  531. package/examples/js/loaders/MMDLoader.js +0 -1915
  532. package/examples/js/loaders/MTLLoader.js +0 -472
  533. package/examples/js/loaders/NRRDLoader.js +0 -609
  534. package/examples/js/loaders/OBJLoader.js +0 -789
  535. package/examples/js/loaders/PCDLoader.js +0 -413
  536. package/examples/js/loaders/PDBLoader.js +0 -317
  537. package/examples/js/loaders/PLYLoader.js +0 -576
  538. package/examples/js/loaders/PRWMLoader.js +0 -249
  539. package/examples/js/loaders/PVRLoader.js +0 -218
  540. package/examples/js/loaders/RGBELoader.js +0 -442
  541. package/examples/js/loaders/RGBMLoader.js +0 -1354
  542. package/examples/js/loaders/STLLoader.js +0 -364
  543. package/examples/js/loaders/SVGLoader.js +0 -2783
  544. package/examples/js/loaders/TDSLoader.js +0 -992
  545. package/examples/js/loaders/TGALoader.js +0 -484
  546. package/examples/js/loaders/TIFFLoader.js +0 -30
  547. package/examples/js/loaders/TTFLoader.js +0 -203
  548. package/examples/js/loaders/TiltLoader.js +0 -459
  549. package/examples/js/loaders/VOXLoader.js +0 -240
  550. package/examples/js/loaders/VRMLLoader.js +0 -3140
  551. package/examples/js/loaders/VTKLoader.js +0 -1078
  552. package/examples/js/loaders/XYZLoader.js +0 -89
  553. package/examples/js/loaders/lwo/IFFParser.js +0 -1067
  554. package/examples/js/loaders/lwo/LWO2Parser.js +0 -397
  555. package/examples/js/loaders/lwo/LWO3Parser.js +0 -360
  556. package/examples/js/materials/MeshGouraudMaterial.js +0 -387
  557. package/examples/js/math/Capsule.js +0 -103
  558. package/examples/js/math/ColorConverter.js +0 -33
  559. package/examples/js/math/ConvexHull.js +0 -1154
  560. package/examples/js/math/ImprovedNoise.js +0 -66
  561. package/examples/js/math/Lut.js +0 -164
  562. package/examples/js/math/MeshSurfaceSampler.js +0 -171
  563. package/examples/js/math/OBB.js +0 -382
  564. package/examples/js/math/Octree.js +0 -410
  565. package/examples/js/math/SimplexNoise.js +0 -445
  566. package/examples/js/misc/ConvexObjectBreaker.js +0 -474
  567. package/examples/js/misc/GPUComputationRenderer.js +0 -393
  568. package/examples/js/misc/Gyroscope.js +0 -56
  569. package/examples/js/misc/MD2Character.js +0 -235
  570. package/examples/js/misc/MD2CharacterComplex.js +0 -513
  571. package/examples/js/misc/MorphAnimMesh.js +0 -63
  572. package/examples/js/misc/MorphBlendMesh.js +0 -265
  573. package/examples/js/misc/ProgressiveLightMap.js +0 -335
  574. package/examples/js/misc/RollerCoaster.js +0 -430
  575. package/examples/js/misc/TubePainter.js +0 -167
  576. package/examples/js/misc/Volume.js +0 -437
  577. package/examples/js/misc/VolumeSlice.js +0 -214
  578. package/examples/js/modifiers/CurveModifier.js +0 -309
  579. package/examples/js/modifiers/EdgeSplitModifier.js +0 -228
  580. package/examples/js/modifiers/SimplifyModifier.js +0 -465
  581. package/examples/js/modifiers/TessellateModifier.js +0 -276
  582. package/examples/js/objects/GroundProjectedEnv.js +0 -181
  583. package/examples/js/objects/Lensflare.js +0 -356
  584. package/examples/js/objects/LightningStorm.js +0 -206
  585. package/examples/js/objects/MarchingCubes.js +0 -759
  586. package/examples/js/objects/Reflector.js +0 -216
  587. package/examples/js/objects/ReflectorForSSRPass.js +0 -315
  588. package/examples/js/objects/Refractor.js +0 -283
  589. package/examples/js/objects/ShadowMesh.js +0 -59
  590. package/examples/js/objects/Sky.js +0 -218
  591. package/examples/js/objects/Water.js +0 -292
  592. package/examples/js/objects/Water2.js +0 -307
  593. package/examples/js/physics/AmmoPhysics.js +0 -259
  594. package/examples/js/physics/OimoPhysics.js +0 -217
  595. package/examples/js/postprocessing/AdaptiveToneMappingPass.js +0 -335
  596. package/examples/js/postprocessing/AfterimagePass.js +0 -77
  597. package/examples/js/postprocessing/BloomPass.js +0 -135
  598. package/examples/js/postprocessing/BokehPass.js +0 -120
  599. package/examples/js/postprocessing/ClearPass.js +0 -39
  600. package/examples/js/postprocessing/CubeTexturePass.js +0 -60
  601. package/examples/js/postprocessing/DotScreenPass.js +0 -51
  602. package/examples/js/postprocessing/EffectComposer.js +0 -272
  603. package/examples/js/postprocessing/FilmPass.js +0 -52
  604. package/examples/js/postprocessing/GlitchPass.js +0 -104
  605. package/examples/js/postprocessing/HalftonePass.js +0 -75
  606. package/examples/js/postprocessing/LUTPass.js +0 -171
  607. package/examples/js/postprocessing/MaskPass.js +0 -95
  608. package/examples/js/postprocessing/OutlinePass.js +0 -598
  609. package/examples/js/postprocessing/Pass.js +0 -72
  610. package/examples/js/postprocessing/RenderPass.js +0 -70
  611. package/examples/js/postprocessing/RenderPixelatedPass.js +0 -215
  612. package/examples/js/postprocessing/SAOPass.js +0 -374
  613. package/examples/js/postprocessing/SMAAPass.js +0 -170
  614. package/examples/js/postprocessing/SSAARenderPass.js +0 -156
  615. package/examples/js/postprocessing/SSAOPass.js +0 -365
  616. package/examples/js/postprocessing/SSRPass.js +0 -567
  617. package/examples/js/postprocessing/SavePass.js +0 -59
  618. package/examples/js/postprocessing/ShaderPass.js +0 -64
  619. package/examples/js/postprocessing/TAARenderPass.js +0 -130
  620. package/examples/js/postprocessing/TexturePass.js +0 -49
  621. package/examples/js/postprocessing/UnrealBloomPass.js +0 -375
  622. package/examples/js/renderers/CSS2DRenderer.js +0 -178
  623. package/examples/js/renderers/CSS3DRenderer.js +0 -237
  624. package/examples/js/renderers/Projector.js +0 -818
  625. package/examples/js/renderers/SVGRenderer.js +0 -491
  626. package/examples/js/shaders/ACESFilmicToneMappingShader.js +0 -89
  627. package/examples/js/shaders/AfterimageShader.js +0 -60
  628. package/examples/js/shaders/BasicShader.js +0 -27
  629. package/examples/js/shaders/BleachBypassShader.js +0 -62
  630. package/examples/js/shaders/BlendShader.js +0 -54
  631. package/examples/js/shaders/BokehShader.js +0 -156
  632. package/examples/js/shaders/BokehShader2.js +0 -419
  633. package/examples/js/shaders/BrightnessContrastShader.js +0 -58
  634. package/examples/js/shaders/ColorCorrectionShader.js +0 -52
  635. package/examples/js/shaders/ColorifyShader.js +0 -47
  636. package/examples/js/shaders/ConvolutionShader.js +0 -92
  637. package/examples/js/shaders/CopyShader.js +0 -45
  638. package/examples/js/shaders/DOFMipMapShader.js +0 -60
  639. package/examples/js/shaders/DepthLimitedBlurShader.js +0 -173
  640. package/examples/js/shaders/DigitalGlitch.js +0 -127
  641. package/examples/js/shaders/DotScreenShader.js +0 -72
  642. package/examples/js/shaders/FXAAShader.js +0 -284
  643. package/examples/js/shaders/FilmShader.js +0 -110
  644. package/examples/js/shaders/FocusShader.js +0 -95
  645. package/examples/js/shaders/FreiChenShader.js +0 -93
  646. package/examples/js/shaders/GammaCorrectionShader.js +0 -41
  647. package/examples/js/shaders/GodRaysShader.js +0 -284
  648. package/examples/js/shaders/HalftoneShader.js +0 -336
  649. package/examples/js/shaders/HorizontalBlurShader.js +0 -59
  650. package/examples/js/shaders/HorizontalTiltShiftShader.js +0 -65
  651. package/examples/js/shaders/HueSaturationShader.js +0 -69
  652. package/examples/js/shaders/KaleidoShader.js +0 -60
  653. package/examples/js/shaders/LuminosityHighPassShader.js +0 -67
  654. package/examples/js/shaders/LuminosityShader.js +0 -46
  655. package/examples/js/shaders/MMDToonShader.js +0 -94
  656. package/examples/js/shaders/MirrorShader.js +0 -56
  657. package/examples/js/shaders/NormalMapShader.js +0 -55
  658. package/examples/js/shaders/RGBShiftShader.js +0 -56
  659. package/examples/js/shaders/SAOShader.js +0 -209
  660. package/examples/js/shaders/SMAAShader.js +0 -454
  661. package/examples/js/shaders/SSAOShader.js +0 -295
  662. package/examples/js/shaders/SSRShader.js +0 -381
  663. package/examples/js/shaders/SepiaShader.js +0 -52
  664. package/examples/js/shaders/SobelOperatorShader.js +0 -88
  665. package/examples/js/shaders/SubsurfaceScatteringShader.js +0 -49
  666. package/examples/js/shaders/TechnicolorShader.js +0 -43
  667. package/examples/js/shaders/ToneMapShader.js +0 -84
  668. package/examples/js/shaders/ToonShader.js +0 -335
  669. package/examples/js/shaders/TriangleBlurShader.js +0 -70
  670. package/examples/js/shaders/UnpackDepthRGBAShader.js +0 -47
  671. package/examples/js/shaders/VelocityShader.js +0 -126
  672. package/examples/js/shaders/VerticalBlurShader.js +0 -59
  673. package/examples/js/shaders/VerticalTiltShiftShader.js +0 -65
  674. package/examples/js/shaders/VignetteShader.js +0 -53
  675. package/examples/js/shaders/VolumeShader.js +0 -296
  676. package/examples/js/shaders/WaterRefractionShader.js +0 -84
  677. package/examples/js/textures/FlakesTexture.js +0 -40
  678. package/examples/js/utils/BufferGeometryUtils.js +0 -1160
  679. package/examples/js/utils/CameraUtils.js +0 -71
  680. package/examples/js/utils/GPUStatsPanel.js +0 -125
  681. package/examples/js/utils/GeometryCompressionUtils.js +0 -549
  682. package/examples/js/utils/GeometryUtils.js +0 -168
  683. package/examples/js/utils/LDrawUtils.js +0 -179
  684. package/examples/js/utils/PackedPhongMaterial.js +0 -109
  685. package/examples/js/utils/SceneUtils.js +0 -214
  686. package/examples/js/utils/ShadowMapViewer.js +0 -183
  687. package/examples/js/utils/SkeletonUtils.js +0 -493
  688. package/examples/js/utils/UVsDebug.js +0 -143
  689. package/examples/js/utils/WorkerPool.js +0 -105
  690. package/examples/jsm/libs/OimoPhysics/OimoPhysics.js +0 -37071
  691. package/examples/jsm/libs/OimoPhysics/index.js +0 -43
  692. package/examples/jsm/libs/flow.module.js +0 -4552
  693. package/examples/jsm/libs/tween.module.min.js +0 -3
  694. package/examples/jsm/loaders/BasisTextureLoader.js +0 -790
  695. package/examples/jsm/loaders/IFCLoader.js +0 -2431
  696. package/examples/jsm/loaders/ifc/web-ifc-api.js +0 -47504
  697. package/examples/jsm/loaders/ifc/web-ifc.wasm +0 -0
  698. package/examples/jsm/node-editor/NodeEditor.js +0 -857
  699. package/examples/jsm/node-editor/accessors/MatcapUVEditor.js +0 -14
  700. package/examples/jsm/node-editor/accessors/NormalEditor.js +0 -30
  701. package/examples/jsm/node-editor/accessors/PositionEditor.js +0 -30
  702. package/examples/jsm/node-editor/accessors/UVEditor.js +0 -25
  703. package/examples/jsm/node-editor/core/BaseNode.js +0 -96
  704. package/examples/jsm/node-editor/core/DataFile.js +0 -59
  705. package/examples/jsm/node-editor/core/FileEditor.js +0 -20
  706. package/examples/jsm/node-editor/core/FileURLEditor.js +0 -29
  707. package/examples/jsm/node-editor/display/BlendEditor.js +0 -44
  708. package/examples/jsm/node-editor/display/NormalMapEditor.js +0 -49
  709. package/examples/jsm/node-editor/examples/animate-uv.json +0 -1
  710. package/examples/jsm/node-editor/examples/fake-top-light.json +0 -1
  711. package/examples/jsm/node-editor/examples/matcap.json +0 -1
  712. package/examples/jsm/node-editor/examples/oscillator-color.json +0 -1
  713. package/examples/jsm/node-editor/examples/rim.json +0 -1
  714. package/examples/jsm/node-editor/inputs/ColorEditor.js +0 -96
  715. package/examples/jsm/node-editor/inputs/FloatEditor.js +0 -23
  716. package/examples/jsm/node-editor/inputs/SliderEditor.js +0 -67
  717. package/examples/jsm/node-editor/inputs/TextureEditor.js +0 -155
  718. package/examples/jsm/node-editor/inputs/Vector2Editor.js +0 -28
  719. package/examples/jsm/node-editor/inputs/Vector3Editor.js +0 -30
  720. package/examples/jsm/node-editor/inputs/Vector4Editor.js +0 -37
  721. package/examples/jsm/node-editor/materials/BasicMaterialEditor.js +0 -84
  722. package/examples/jsm/node-editor/materials/PointsMaterialEditor.js +0 -102
  723. package/examples/jsm/node-editor/materials/StandardMaterialEditor.js +0 -118
  724. package/examples/jsm/node-editor/math/AngleEditor.js +0 -40
  725. package/examples/jsm/node-editor/math/DotEditor.js +0 -35
  726. package/examples/jsm/node-editor/math/InvertEditor.js +0 -39
  727. package/examples/jsm/node-editor/math/LimiterEditor.js +0 -62
  728. package/examples/jsm/node-editor/math/NormalizeEditor.js +0 -28
  729. package/examples/jsm/node-editor/math/OperatorEditor.js +0 -63
  730. package/examples/jsm/node-editor/math/PowerEditor.js +0 -44
  731. package/examples/jsm/node-editor/math/TrigonometryEditor.js +0 -45
  732. package/examples/jsm/node-editor/procedural/CheckerEditor.js +0 -27
  733. package/examples/jsm/node-editor/scene/MeshEditor.js +0 -102
  734. package/examples/jsm/node-editor/scene/Object3DEditor.js +0 -160
  735. package/examples/jsm/node-editor/scene/PointsEditor.js +0 -99
  736. package/examples/jsm/node-editor/utils/JoinEditor.js +0 -58
  737. package/examples/jsm/node-editor/utils/OscillatorEditor.js +0 -43
  738. package/examples/jsm/node-editor/utils/PreviewEditor.js +0 -170
  739. package/examples/jsm/node-editor/utils/SplitEditor.js +0 -39
  740. package/examples/jsm/node-editor/utils/TimerEditor.js +0 -58
  741. package/examples/jsm/nodes/core/ExpressionNode.js +0 -32
  742. package/examples/jsm/nodes/functions/light/getDistanceAttenuation.js +0 -22
  743. package/examples/jsm/nodes/lighting/PunctualLightNode.js +0 -68
  744. package/examples/jsm/nodes/shadernode/ShaderNodeBaseElements.js +0 -301
  745. package/examples/jsm/nodes/shadernode/ShaderNodeElements.js +0 -149
  746. package/examples/jsm/objects/GroundProjectedEnv.js +0 -186
  747. package/examples/jsm/renderers/webgpu/WebGPUObjects.js +0 -36
  748. package/src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl.js +0 -7
  749. package/src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl.js +0 -10
  750. package/src/renderers/shaders/ShaderChunk/uv2_vertex.glsl.js +0 -7
  751. /package/examples/{js → jsm}/libs/ammo.wasm.js +0 -0
  752. /package/examples/{js → jsm}/libs/ammo.wasm.wasm +0 -0
  753. /package/examples/{js → jsm}/libs/basis/basis_transcoder.js +0 -0
  754. /package/examples/{js → jsm}/libs/basis/basis_transcoder.wasm +0 -0
  755. /package/examples/{js → jsm}/libs/draco/README.md +0 -0
  756. /package/examples/{js → jsm}/libs/draco/draco_encoder.js +0 -0
  757. /package/examples/{js → jsm}/libs/draco/gltf/draco_encoder.js +0 -0
@@ -1,2263 +0,0 @@
1
- ( function () {
2
-
3
- // Special surface finish tag types.
4
- // Note: "MATERIAL" tag (e.g. GLITTER, SPECKLE) is not implemented
5
- const FINISH_TYPE_DEFAULT = 0;
6
- const FINISH_TYPE_CHROME = 1;
7
- const FINISH_TYPE_PEARLESCENT = 2;
8
- const FINISH_TYPE_RUBBER = 3;
9
- const FINISH_TYPE_MATTE_METALLIC = 4;
10
- const FINISH_TYPE_METAL = 5;
11
-
12
- // State machine to search a subobject path.
13
- // The LDraw standard establishes these various possible subfolders.
14
- const FILE_LOCATION_TRY_PARTS = 0;
15
- const FILE_LOCATION_TRY_P = 1;
16
- const FILE_LOCATION_TRY_MODELS = 2;
17
- const FILE_LOCATION_AS_IS = 3;
18
- const FILE_LOCATION_TRY_RELATIVE = 4;
19
- const FILE_LOCATION_TRY_ABSOLUTE = 5;
20
- const FILE_LOCATION_NOT_FOUND = 6;
21
- const MAIN_COLOUR_CODE = '16';
22
- const MAIN_EDGE_COLOUR_CODE = '24';
23
- const _tempVec0 = new THREE.Vector3();
24
- const _tempVec1 = new THREE.Vector3();
25
- class LDrawConditionalLineMaterial extends THREE.ShaderMaterial {
26
-
27
- constructor( parameters ) {
28
-
29
- super( {
30
- uniforms: THREE.UniformsUtils.merge( [ THREE.UniformsLib.fog, {
31
- diffuse: {
32
- value: new THREE.Color()
33
- },
34
- opacity: {
35
- value: 1.0
36
- }
37
- } ] ),
38
- vertexShader: /* glsl */`
39
- attribute vec3 control0;
40
- attribute vec3 control1;
41
- attribute vec3 direction;
42
- varying float discardFlag;
43
-
44
- #include <common>
45
- #include <color_pars_vertex>
46
- #include <fog_pars_vertex>
47
- #include <logdepthbuf_pars_vertex>
48
- #include <clipping_planes_pars_vertex>
49
- void main() {
50
- #include <color_vertex>
51
-
52
- vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
53
- gl_Position = projectionMatrix * mvPosition;
54
-
55
- // Transform the line segment ends and control points into camera clip space
56
- vec4 c0 = projectionMatrix * modelViewMatrix * vec4( control0, 1.0 );
57
- vec4 c1 = projectionMatrix * modelViewMatrix * vec4( control1, 1.0 );
58
- vec4 p0 = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
59
- vec4 p1 = projectionMatrix * modelViewMatrix * vec4( position + direction, 1.0 );
60
-
61
- c0.xy /= c0.w;
62
- c1.xy /= c1.w;
63
- p0.xy /= p0.w;
64
- p1.xy /= p1.w;
65
-
66
- // Get the direction of the segment and an orthogonal vector
67
- vec2 dir = p1.xy - p0.xy;
68
- vec2 norm = vec2( -dir.y, dir.x );
69
-
70
- // Get control point directions from the line
71
- vec2 c0dir = c0.xy - p1.xy;
72
- vec2 c1dir = c1.xy - p1.xy;
73
-
74
- // If the vectors to the controls points are pointed in different directions away
75
- // from the line segment then the line should not be drawn.
76
- float d0 = dot( normalize( norm ), normalize( c0dir ) );
77
- float d1 = dot( normalize( norm ), normalize( c1dir ) );
78
- discardFlag = float( sign( d0 ) != sign( d1 ) );
79
-
80
- #include <logdepthbuf_vertex>
81
- #include <clipping_planes_vertex>
82
- #include <fog_vertex>
83
- }
84
- `,
85
- fragmentShader: /* glsl */`
86
- uniform vec3 diffuse;
87
- uniform float opacity;
88
- varying float discardFlag;
89
-
90
- #include <common>
91
- #include <color_pars_fragment>
92
- #include <fog_pars_fragment>
93
- #include <logdepthbuf_pars_fragment>
94
- #include <clipping_planes_pars_fragment>
95
- void main() {
96
-
97
- if ( discardFlag > 0.5 ) discard;
98
-
99
- #include <clipping_planes_fragment>
100
- vec3 outgoingLight = vec3( 0.0 );
101
- vec4 diffuseColor = vec4( diffuse, opacity );
102
- #include <logdepthbuf_fragment>
103
- #include <color_fragment>
104
- outgoingLight = diffuseColor.rgb; // simple shader
105
- gl_FragColor = vec4( outgoingLight, diffuseColor.a );
106
- #include <tonemapping_fragment>
107
- #include <encodings_fragment>
108
- #include <fog_fragment>
109
- #include <premultiplied_alpha_fragment>
110
- }
111
- `
112
- } );
113
- Object.defineProperties( this, {
114
- opacity: {
115
- get: function () {
116
-
117
- return this.uniforms.opacity.value;
118
-
119
- },
120
- set: function ( value ) {
121
-
122
- this.uniforms.opacity.value = value;
123
-
124
- }
125
- },
126
- color: {
127
- get: function () {
128
-
129
- return this.uniforms.diffuse.value;
130
-
131
- }
132
- }
133
- } );
134
- this.setValues( parameters );
135
- this.isLDrawConditionalLineMaterial = true;
136
-
137
- }
138
-
139
- }
140
- class ConditionalLineSegments extends THREE.LineSegments {
141
-
142
- constructor( geometry, material ) {
143
-
144
- super( geometry, material );
145
- this.isConditionalLine = true;
146
-
147
- }
148
-
149
- }
150
- function generateFaceNormals( faces ) {
151
-
152
- for ( let i = 0, l = faces.length; i < l; i ++ ) {
153
-
154
- const face = faces[ i ];
155
- const vertices = face.vertices;
156
- const v0 = vertices[ 0 ];
157
- const v1 = vertices[ 1 ];
158
- const v2 = vertices[ 2 ];
159
- _tempVec0.subVectors( v1, v0 );
160
- _tempVec1.subVectors( v2, v1 );
161
- face.faceNormal = new THREE.Vector3().crossVectors( _tempVec0, _tempVec1 ).normalize();
162
-
163
- }
164
-
165
- }
166
-
167
- const _ray = new THREE.Ray();
168
- function smoothNormals( faces, lineSegments, checkSubSegments = false ) {
169
-
170
- // NOTE: 1e2 is pretty coarse but was chosen to quantize the resulting value because
171
- // it allows edges to be smoothed as expected (see minifig arms).
172
- // --
173
- // And the vector values are initialize multiplied by 1 + 1e-10 to account for floating
174
- // point errors on vertices along quantization boundaries. Ie after matrix multiplication
175
- // vertices that should be merged might be set to "1.7" and "1.6999..." meaning they won't
176
- // get merged. This added epsilon attempts to push these error values to the same quantized
177
- // value for the sake of hashing. See "AT-ST mini" dishes. See mrdoob/three#23169.
178
-
179
- const hashMultiplier = ( 1 + 1e-10 ) * 1e2;
180
- function hashVertex( v ) {
181
-
182
- const x = ~ ~ ( v.x * hashMultiplier );
183
- const y = ~ ~ ( v.y * hashMultiplier );
184
- const z = ~ ~ ( v.z * hashMultiplier );
185
- return `${x},${y},${z}`;
186
-
187
- }
188
-
189
- function hashEdge( v0, v1 ) {
190
-
191
- return `${hashVertex( v0 )}_${hashVertex( v1 )}`;
192
-
193
- }
194
-
195
- // converts the two vertices to a ray with a normalized direction and origin of 0, 0, 0 projected
196
- // onto the original line.
197
- function toNormalizedRay( v0, v1, targetRay ) {
198
-
199
- targetRay.direction.subVectors( v1, v0 ).normalize();
200
- const scalar = v0.dot( targetRay.direction );
201
- targetRay.origin.copy( v0 ).addScaledVector( targetRay.direction, - scalar );
202
- return targetRay;
203
-
204
- }
205
-
206
- function hashRay( ray ) {
207
-
208
- return hashEdge( ray.origin, ray.direction );
209
-
210
- }
211
-
212
- const hardEdges = new Set();
213
- const hardEdgeRays = new Map();
214
- const halfEdgeList = {};
215
- const normals = [];
216
-
217
- // Save the list of hard edges by hash
218
- for ( let i = 0, l = lineSegments.length; i < l; i ++ ) {
219
-
220
- const ls = lineSegments[ i ];
221
- const vertices = ls.vertices;
222
- const v0 = vertices[ 0 ];
223
- const v1 = vertices[ 1 ];
224
- hardEdges.add( hashEdge( v0, v1 ) );
225
- hardEdges.add( hashEdge( v1, v0 ) );
226
-
227
- // only generate the hard edge ray map if we're checking subsegments because it's more expensive to check
228
- // and requires more memory.
229
- if ( checkSubSegments ) {
230
-
231
- // add both ray directions to the map
232
- const ray = toNormalizedRay( v0, v1, new THREE.Ray() );
233
- const rh1 = hashRay( ray );
234
- if ( ! hardEdgeRays.has( rh1 ) ) {
235
-
236
- toNormalizedRay( v1, v0, ray );
237
- const rh2 = hashRay( ray );
238
- const info = {
239
- ray,
240
- distances: []
241
- };
242
- hardEdgeRays.set( rh1, info );
243
- hardEdgeRays.set( rh2, info );
244
-
245
- }
246
-
247
- // store both segments ends in min, max order in the distances array to check if a face edge is a
248
- // subsegment later.
249
- const info = hardEdgeRays.get( rh1 );
250
- let d0 = info.ray.direction.dot( v0 );
251
- let d1 = info.ray.direction.dot( v1 );
252
- if ( d0 > d1 ) {
253
-
254
- [ d0, d1 ] = [ d1, d0 ];
255
-
256
- }
257
-
258
- info.distances.push( d0, d1 );
259
-
260
- }
261
-
262
- }
263
-
264
- // track the half edges associated with each triangle
265
- for ( let i = 0, l = faces.length; i < l; i ++ ) {
266
-
267
- const tri = faces[ i ];
268
- const vertices = tri.vertices;
269
- const vertCount = vertices.length;
270
- for ( let i2 = 0; i2 < vertCount; i2 ++ ) {
271
-
272
- const index = i2;
273
- const next = ( i2 + 1 ) % vertCount;
274
- const v0 = vertices[ index ];
275
- const v1 = vertices[ next ];
276
- const hash = hashEdge( v0, v1 );
277
-
278
- // don't add the triangle if the edge is supposed to be hard
279
- if ( hardEdges.has( hash ) ) {
280
-
281
- continue;
282
-
283
- }
284
-
285
- // if checking subsegments then check to see if this edge lies on a hard edge ray and whether its within any ray bounds
286
- if ( checkSubSegments ) {
287
-
288
- toNormalizedRay( v0, v1, _ray );
289
- const rayHash = hashRay( _ray );
290
- if ( hardEdgeRays.has( rayHash ) ) {
291
-
292
- const info = hardEdgeRays.get( rayHash );
293
- const {
294
- ray,
295
- distances
296
- } = info;
297
- let d0 = ray.direction.dot( v0 );
298
- let d1 = ray.direction.dot( v1 );
299
- if ( d0 > d1 ) {
300
-
301
- [ d0, d1 ] = [ d1, d0 ];
302
-
303
- }
304
-
305
- // return early if the face edge is found to be a subsegment of a line edge meaning the edge will have "hard" normals
306
- let found = false;
307
- for ( let i = 0, l = distances.length; i < l; i += 2 ) {
308
-
309
- if ( d0 >= distances[ i ] && d1 <= distances[ i + 1 ] ) {
310
-
311
- found = true;
312
- break;
313
-
314
- }
315
-
316
- }
317
-
318
- if ( found ) {
319
-
320
- continue;
321
-
322
- }
323
-
324
- }
325
-
326
- }
327
-
328
- const info = {
329
- index: index,
330
- tri: tri
331
- };
332
- halfEdgeList[ hash ] = info;
333
-
334
- }
335
-
336
- }
337
-
338
- // Iterate until we've tried to connect all faces to share normals
339
- while ( true ) {
340
-
341
- // Stop if there are no more faces left
342
- let halfEdge = null;
343
- for ( const key in halfEdgeList ) {
344
-
345
- halfEdge = halfEdgeList[ key ];
346
- break;
347
-
348
- }
349
-
350
- if ( halfEdge === null ) {
351
-
352
- break;
353
-
354
- }
355
-
356
- // Exhaustively find all connected faces
357
- const queue = [ halfEdge ];
358
- while ( queue.length > 0 ) {
359
-
360
- // initialize all vertex normals in this triangle
361
- const tri = queue.pop().tri;
362
- const vertices = tri.vertices;
363
- const vertNormals = tri.normals;
364
- const faceNormal = tri.faceNormal;
365
-
366
- // Check if any edge is connected to another triangle edge
367
- const vertCount = vertices.length;
368
- for ( let i2 = 0; i2 < vertCount; i2 ++ ) {
369
-
370
- const index = i2;
371
- const next = ( i2 + 1 ) % vertCount;
372
- const v0 = vertices[ index ];
373
- const v1 = vertices[ next ];
374
-
375
- // delete this triangle from the list so it won't be found again
376
- const hash = hashEdge( v0, v1 );
377
- delete halfEdgeList[ hash ];
378
- const reverseHash = hashEdge( v1, v0 );
379
- const otherInfo = halfEdgeList[ reverseHash ];
380
- if ( otherInfo ) {
381
-
382
- const otherTri = otherInfo.tri;
383
- const otherIndex = otherInfo.index;
384
- const otherNormals = otherTri.normals;
385
- const otherVertCount = otherNormals.length;
386
- const otherFaceNormal = otherTri.faceNormal;
387
-
388
- // NOTE: If the angle between faces is > 67.5 degrees then assume it's
389
- // hard edge. There are some cases where the line segments do not line up exactly
390
- // with or span multiple triangle edges (see Lunar Vehicle wheels).
391
- if ( Math.abs( otherTri.faceNormal.dot( tri.faceNormal ) ) < 0.25 ) {
392
-
393
- continue;
394
-
395
- }
396
-
397
- // if this triangle has already been traversed then it won't be in
398
- // the halfEdgeList. If it has not then add it to the queue and delete
399
- // it so it won't be found again.
400
- if ( reverseHash in halfEdgeList ) {
401
-
402
- queue.push( otherInfo );
403
- delete halfEdgeList[ reverseHash ];
404
-
405
- }
406
-
407
- // share the first normal
408
- const otherNext = ( otherIndex + 1 ) % otherVertCount;
409
- if ( vertNormals[ index ] && otherNormals[ otherNext ] && vertNormals[ index ] !== otherNormals[ otherNext ] ) {
410
-
411
- otherNormals[ otherNext ].norm.add( vertNormals[ index ].norm );
412
- vertNormals[ index ].norm = otherNormals[ otherNext ].norm;
413
-
414
- }
415
-
416
- let sharedNormal1 = vertNormals[ index ] || otherNormals[ otherNext ];
417
- if ( sharedNormal1 === null ) {
418
-
419
- // it's possible to encounter an edge of a triangle that has already been traversed meaning
420
- // both edges already have different normals defined and shared. To work around this we create
421
- // a wrapper object so when those edges are merged the normals can be updated everywhere.
422
- sharedNormal1 = {
423
- norm: new THREE.Vector3()
424
- };
425
- normals.push( sharedNormal1.norm );
426
-
427
- }
428
-
429
- if ( vertNormals[ index ] === null ) {
430
-
431
- vertNormals[ index ] = sharedNormal1;
432
- sharedNormal1.norm.add( faceNormal );
433
-
434
- }
435
-
436
- if ( otherNormals[ otherNext ] === null ) {
437
-
438
- otherNormals[ otherNext ] = sharedNormal1;
439
- sharedNormal1.norm.add( otherFaceNormal );
440
-
441
- }
442
-
443
- // share the second normal
444
- if ( vertNormals[ next ] && otherNormals[ otherIndex ] && vertNormals[ next ] !== otherNormals[ otherIndex ] ) {
445
-
446
- otherNormals[ otherIndex ].norm.add( vertNormals[ next ].norm );
447
- vertNormals[ next ].norm = otherNormals[ otherIndex ].norm;
448
-
449
- }
450
-
451
- let sharedNormal2 = vertNormals[ next ] || otherNormals[ otherIndex ];
452
- if ( sharedNormal2 === null ) {
453
-
454
- sharedNormal2 = {
455
- norm: new THREE.Vector3()
456
- };
457
- normals.push( sharedNormal2.norm );
458
-
459
- }
460
-
461
- if ( vertNormals[ next ] === null ) {
462
-
463
- vertNormals[ next ] = sharedNormal2;
464
- sharedNormal2.norm.add( faceNormal );
465
-
466
- }
467
-
468
- if ( otherNormals[ otherIndex ] === null ) {
469
-
470
- otherNormals[ otherIndex ] = sharedNormal2;
471
- sharedNormal2.norm.add( otherFaceNormal );
472
-
473
- }
474
-
475
- }
476
-
477
- }
478
-
479
- }
480
-
481
- }
482
-
483
- // The normals of each face have been added up so now we average them by normalizing the vector.
484
- for ( let i = 0, l = normals.length; i < l; i ++ ) {
485
-
486
- normals[ i ].normalize();
487
-
488
- }
489
-
490
- }
491
-
492
- function isPartType( type ) {
493
-
494
- return type === 'Part' || type === 'Unofficial_Part';
495
-
496
- }
497
-
498
- function isPrimitiveType( type ) {
499
-
500
- return /primitive/i.test( type ) || type === 'Subpart';
501
-
502
- }
503
-
504
- class LineParser {
505
-
506
- constructor( line, lineNumber ) {
507
-
508
- this.line = line;
509
- this.lineLength = line.length;
510
- this.currentCharIndex = 0;
511
- this.currentChar = ' ';
512
- this.lineNumber = lineNumber;
513
-
514
- }
515
- seekNonSpace() {
516
-
517
- while ( this.currentCharIndex < this.lineLength ) {
518
-
519
- this.currentChar = this.line.charAt( this.currentCharIndex );
520
- if ( this.currentChar !== ' ' && this.currentChar !== '\t' ) {
521
-
522
- return;
523
-
524
- }
525
-
526
- this.currentCharIndex ++;
527
-
528
- }
529
-
530
- }
531
- getToken() {
532
-
533
- const pos0 = this.currentCharIndex ++;
534
-
535
- // Seek space
536
- while ( this.currentCharIndex < this.lineLength ) {
537
-
538
- this.currentChar = this.line.charAt( this.currentCharIndex );
539
- if ( this.currentChar === ' ' || this.currentChar === '\t' ) {
540
-
541
- break;
542
-
543
- }
544
-
545
- this.currentCharIndex ++;
546
-
547
- }
548
-
549
- const pos1 = this.currentCharIndex;
550
- this.seekNonSpace();
551
- return this.line.substring( pos0, pos1 );
552
-
553
- }
554
- getVector() {
555
-
556
- return new THREE.Vector3( parseFloat( this.getToken() ), parseFloat( this.getToken() ), parseFloat( this.getToken() ) );
557
-
558
- }
559
- getRemainingString() {
560
-
561
- return this.line.substring( this.currentCharIndex, this.lineLength );
562
-
563
- }
564
- isAtTheEnd() {
565
-
566
- return this.currentCharIndex >= this.lineLength;
567
-
568
- }
569
- setToEnd() {
570
-
571
- this.currentCharIndex = this.lineLength;
572
-
573
- }
574
- getLineNumberString() {
575
-
576
- return this.lineNumber >= 0 ? ' at line ' + this.lineNumber : '';
577
-
578
- }
579
-
580
- }
581
-
582
- // Fetches and parses an intermediate representation of LDraw parts files.
583
- class LDrawParsedCache {
584
-
585
- constructor( loader ) {
586
-
587
- this.loader = loader;
588
- this._cache = {};
589
-
590
- }
591
- cloneResult( original ) {
592
-
593
- const result = {};
594
-
595
- // vertices are transformed and normals computed before being converted to geometry
596
- // so these pieces must be cloned.
597
- result.faces = original.faces.map( face => {
598
-
599
- return {
600
- colorCode: face.colorCode,
601
- material: face.material,
602
- vertices: face.vertices.map( v => v.clone() ),
603
- normals: face.normals.map( () => null ),
604
- faceNormal: null
605
- };
606
-
607
- } );
608
- result.conditionalSegments = original.conditionalSegments.map( face => {
609
-
610
- return {
611
- colorCode: face.colorCode,
612
- material: face.material,
613
- vertices: face.vertices.map( v => v.clone() ),
614
- controlPoints: face.controlPoints.map( v => v.clone() )
615
- };
616
-
617
- } );
618
- result.lineSegments = original.lineSegments.map( face => {
619
-
620
- return {
621
- colorCode: face.colorCode,
622
- material: face.material,
623
- vertices: face.vertices.map( v => v.clone() )
624
- };
625
-
626
- } );
627
-
628
- // none if this is subsequently modified
629
- result.type = original.type;
630
- result.category = original.category;
631
- result.keywords = original.keywords;
632
- result.author = original.author;
633
- result.subobjects = original.subobjects;
634
- result.fileName = original.fileName;
635
- result.totalFaces = original.totalFaces;
636
- result.startingBuildingStep = original.startingBuildingStep;
637
- result.materials = original.materials;
638
- result.group = null;
639
- return result;
640
-
641
- }
642
- async fetchData( fileName ) {
643
-
644
- let triedLowerCase = false;
645
- let locationState = FILE_LOCATION_TRY_PARTS;
646
- while ( locationState !== FILE_LOCATION_NOT_FOUND ) {
647
-
648
- let subobjectURL = fileName;
649
- switch ( locationState ) {
650
-
651
- case FILE_LOCATION_AS_IS:
652
- locationState = locationState + 1;
653
- break;
654
- case FILE_LOCATION_TRY_PARTS:
655
- subobjectURL = 'parts/' + subobjectURL;
656
- locationState = locationState + 1;
657
- break;
658
- case FILE_LOCATION_TRY_P:
659
- subobjectURL = 'p/' + subobjectURL;
660
- locationState = locationState + 1;
661
- break;
662
- case FILE_LOCATION_TRY_MODELS:
663
- subobjectURL = 'models/' + subobjectURL;
664
- locationState = locationState + 1;
665
- break;
666
- case FILE_LOCATION_TRY_RELATIVE:
667
- subobjectURL = fileName.substring( 0, fileName.lastIndexOf( '/' ) + 1 ) + subobjectURL;
668
- locationState = locationState + 1;
669
- break;
670
- case FILE_LOCATION_TRY_ABSOLUTE:
671
- if ( triedLowerCase ) {
672
-
673
- // Try absolute path
674
- locationState = FILE_LOCATION_NOT_FOUND;
675
-
676
- } else {
677
-
678
- // Next attempt is lower case
679
- fileName = fileName.toLowerCase();
680
- subobjectURL = fileName;
681
- triedLowerCase = true;
682
- locationState = FILE_LOCATION_TRY_PARTS;
683
-
684
- }
685
-
686
- break;
687
-
688
- }
689
-
690
- const loader = this.loader;
691
- const fileLoader = new THREE.FileLoader( loader.manager );
692
- fileLoader.setPath( loader.partsLibraryPath );
693
- fileLoader.setRequestHeader( loader.requestHeader );
694
- fileLoader.setWithCredentials( loader.withCredentials );
695
- try {
696
-
697
- const text = await fileLoader.loadAsync( subobjectURL );
698
- return text;
699
-
700
- } catch {
701
-
702
- continue;
703
-
704
- }
705
-
706
- }
707
-
708
- throw new Error( 'LDrawLoader: Subobject "' + fileName + '" could not be loaded.' );
709
-
710
- }
711
- parse( text, fileName = null ) {
712
-
713
- const loader = this.loader;
714
-
715
- // final results
716
- const faces = [];
717
- const lineSegments = [];
718
- const conditionalSegments = [];
719
- const subobjects = [];
720
- const materials = {};
721
- const getLocalMaterial = colorCode => {
722
-
723
- return materials[ colorCode ] || null;
724
-
725
- };
726
-
727
- let type = 'Model';
728
- let category = null;
729
- let keywords = null;
730
- let author = null;
731
- let totalFaces = 0;
732
-
733
- // split into lines
734
- if ( text.indexOf( '\r\n' ) !== - 1 ) {
735
-
736
- // This is faster than String.split with regex that splits on both
737
- text = text.replace( /\r\n/g, '\n' );
738
-
739
- }
740
-
741
- const lines = text.split( '\n' );
742
- const numLines = lines.length;
743
- let parsingEmbeddedFiles = false;
744
- let currentEmbeddedFileName = null;
745
- let currentEmbeddedText = null;
746
- let bfcCertified = false;
747
- let bfcCCW = true;
748
- let bfcInverted = false;
749
- let bfcCull = true;
750
- let startingBuildingStep = false;
751
-
752
- // Parse all line commands
753
- for ( let lineIndex = 0; lineIndex < numLines; lineIndex ++ ) {
754
-
755
- const line = lines[ lineIndex ];
756
- if ( line.length === 0 ) continue;
757
- if ( parsingEmbeddedFiles ) {
758
-
759
- if ( line.startsWith( '0 FILE ' ) ) {
760
-
761
- // Save previous embedded file in the cache
762
- this.setData( currentEmbeddedFileName, currentEmbeddedText );
763
-
764
- // New embedded text file
765
- currentEmbeddedFileName = line.substring( 7 );
766
- currentEmbeddedText = '';
767
-
768
- } else {
769
-
770
- currentEmbeddedText += line + '\n';
771
-
772
- }
773
-
774
- continue;
775
-
776
- }
777
-
778
- const lp = new LineParser( line, lineIndex + 1 );
779
- lp.seekNonSpace();
780
- if ( lp.isAtTheEnd() ) {
781
-
782
- // Empty line
783
- continue;
784
-
785
- }
786
-
787
- // Parse the line type
788
- const lineType = lp.getToken();
789
- let material;
790
- let colorCode;
791
- let segment;
792
- let ccw;
793
- let doubleSided;
794
- let v0, v1, v2, v3, c0, c1;
795
- switch ( lineType ) {
796
-
797
- // Line type 0: Comment or META
798
- case '0':
799
- // Parse meta directive
800
- const meta = lp.getToken();
801
- if ( meta ) {
802
-
803
- switch ( meta ) {
804
-
805
- case '!LDRAW_ORG':
806
- type = lp.getToken();
807
- break;
808
- case '!COLOUR':
809
- material = loader.parseColorMetaDirective( lp );
810
- if ( material ) {
811
-
812
- materials[ material.userData.code ] = material;
813
-
814
- } else {
815
-
816
- console.warn( 'LDrawLoader: Error parsing material' + lp.getLineNumberString() );
817
-
818
- }
819
-
820
- break;
821
- case '!CATEGORY':
822
- category = lp.getToken();
823
- break;
824
- case '!KEYWORDS':
825
- const newKeywords = lp.getRemainingString().split( ',' );
826
- if ( newKeywords.length > 0 ) {
827
-
828
- if ( ! keywords ) {
829
-
830
- keywords = [];
831
-
832
- }
833
-
834
- newKeywords.forEach( function ( keyword ) {
835
-
836
- keywords.push( keyword.trim() );
837
-
838
- } );
839
-
840
- }
841
-
842
- break;
843
- case 'FILE':
844
- if ( lineIndex > 0 ) {
845
-
846
- // Start embedded text files parsing
847
- parsingEmbeddedFiles = true;
848
- currentEmbeddedFileName = lp.getRemainingString();
849
- currentEmbeddedText = '';
850
- bfcCertified = false;
851
- bfcCCW = true;
852
-
853
- }
854
-
855
- break;
856
- case 'BFC':
857
- // Changes to the backface culling state
858
- while ( ! lp.isAtTheEnd() ) {
859
-
860
- const token = lp.getToken();
861
- switch ( token ) {
862
-
863
- case 'CERTIFY':
864
- case 'NOCERTIFY':
865
- bfcCertified = token === 'CERTIFY';
866
- bfcCCW = true;
867
- break;
868
- case 'CW':
869
- case 'CCW':
870
- bfcCCW = token === 'CCW';
871
- break;
872
- case 'INVERTNEXT':
873
- bfcInverted = true;
874
- break;
875
- case 'CLIP':
876
- case 'NOCLIP':
877
- bfcCull = token === 'CLIP';
878
- break;
879
- default:
880
- console.warn( 'THREE.LDrawLoader: BFC directive "' + token + '" is unknown.' );
881
- break;
882
-
883
- }
884
-
885
- }
886
-
887
- break;
888
- case 'STEP':
889
- startingBuildingStep = true;
890
- break;
891
- case 'Author:':
892
- author = lp.getToken();
893
- break;
894
- default:
895
- // Other meta directives are not implemented
896
- break;
897
-
898
- }
899
-
900
- }
901
-
902
- break;
903
-
904
- // Line type 1: Sub-object file
905
- case '1':
906
- colorCode = lp.getToken();
907
- material = getLocalMaterial( colorCode );
908
- const posX = parseFloat( lp.getToken() );
909
- const posY = parseFloat( lp.getToken() );
910
- const posZ = parseFloat( lp.getToken() );
911
- const m0 = parseFloat( lp.getToken() );
912
- const m1 = parseFloat( lp.getToken() );
913
- const m2 = parseFloat( lp.getToken() );
914
- const m3 = parseFloat( lp.getToken() );
915
- const m4 = parseFloat( lp.getToken() );
916
- const m5 = parseFloat( lp.getToken() );
917
- const m6 = parseFloat( lp.getToken() );
918
- const m7 = parseFloat( lp.getToken() );
919
- const m8 = parseFloat( lp.getToken() );
920
- const matrix = new THREE.Matrix4().set( m0, m1, m2, posX, m3, m4, m5, posY, m6, m7, m8, posZ, 0, 0, 0, 1 );
921
- let fileName = lp.getRemainingString().trim().replace( /\\/g, '/' );
922
- if ( loader.fileMap[ fileName ] ) {
923
-
924
- // Found the subobject path in the preloaded file path map
925
- fileName = loader.fileMap[ fileName ];
926
-
927
- } else {
928
-
929
- // Standardized subfolders
930
- if ( fileName.startsWith( 's/' ) ) {
931
-
932
- fileName = 'parts/' + fileName;
933
-
934
- } else if ( fileName.startsWith( '48/' ) ) {
935
-
936
- fileName = 'p/' + fileName;
937
-
938
- }
939
-
940
- }
941
-
942
- subobjects.push( {
943
- material: material,
944
- colorCode: colorCode,
945
- matrix: matrix,
946
- fileName: fileName,
947
- inverted: bfcInverted,
948
- startingBuildingStep: startingBuildingStep
949
- } );
950
- startingBuildingStep = false;
951
- bfcInverted = false;
952
- break;
953
-
954
- // Line type 2: Line segment
955
- case '2':
956
- colorCode = lp.getToken();
957
- material = getLocalMaterial( colorCode );
958
- v0 = lp.getVector();
959
- v1 = lp.getVector();
960
- segment = {
961
- material: material,
962
- colorCode: colorCode,
963
- vertices: [ v0, v1 ]
964
- };
965
- lineSegments.push( segment );
966
- break;
967
-
968
- // Line type 5: Conditional Line segment
969
- case '5':
970
- colorCode = lp.getToken();
971
- material = getLocalMaterial( colorCode );
972
- v0 = lp.getVector();
973
- v1 = lp.getVector();
974
- c0 = lp.getVector();
975
- c1 = lp.getVector();
976
- segment = {
977
- material: material,
978
- colorCode: colorCode,
979
- vertices: [ v0, v1 ],
980
- controlPoints: [ c0, c1 ]
981
- };
982
- conditionalSegments.push( segment );
983
- break;
984
-
985
- // Line type 3: Triangle
986
- case '3':
987
- colorCode = lp.getToken();
988
- material = getLocalMaterial( colorCode );
989
- ccw = bfcCCW;
990
- doubleSided = ! bfcCertified || ! bfcCull;
991
- if ( ccw === true ) {
992
-
993
- v0 = lp.getVector();
994
- v1 = lp.getVector();
995
- v2 = lp.getVector();
996
-
997
- } else {
998
-
999
- v2 = lp.getVector();
1000
- v1 = lp.getVector();
1001
- v0 = lp.getVector();
1002
-
1003
- }
1004
-
1005
- faces.push( {
1006
- material: material,
1007
- colorCode: colorCode,
1008
- faceNormal: null,
1009
- vertices: [ v0, v1, v2 ],
1010
- normals: [ null, null, null ]
1011
- } );
1012
- totalFaces ++;
1013
- if ( doubleSided === true ) {
1014
-
1015
- faces.push( {
1016
- material: material,
1017
- colorCode: colorCode,
1018
- faceNormal: null,
1019
- vertices: [ v2, v1, v0 ],
1020
- normals: [ null, null, null ]
1021
- } );
1022
- totalFaces ++;
1023
-
1024
- }
1025
-
1026
- break;
1027
-
1028
- // Line type 4: Quadrilateral
1029
- case '4':
1030
- colorCode = lp.getToken();
1031
- material = getLocalMaterial( colorCode );
1032
- ccw = bfcCCW;
1033
- doubleSided = ! bfcCertified || ! bfcCull;
1034
- if ( ccw === true ) {
1035
-
1036
- v0 = lp.getVector();
1037
- v1 = lp.getVector();
1038
- v2 = lp.getVector();
1039
- v3 = lp.getVector();
1040
-
1041
- } else {
1042
-
1043
- v3 = lp.getVector();
1044
- v2 = lp.getVector();
1045
- v1 = lp.getVector();
1046
- v0 = lp.getVector();
1047
-
1048
- }
1049
-
1050
- // specifically place the triangle diagonal in the v0 and v1 slots so we can
1051
- // account for the doubling of vertices later when smoothing normals.
1052
- faces.push( {
1053
- material: material,
1054
- colorCode: colorCode,
1055
- faceNormal: null,
1056
- vertices: [ v0, v1, v2, v3 ],
1057
- normals: [ null, null, null, null ]
1058
- } );
1059
- totalFaces += 2;
1060
- if ( doubleSided === true ) {
1061
-
1062
- faces.push( {
1063
- material: material,
1064
- colorCode: colorCode,
1065
- faceNormal: null,
1066
- vertices: [ v3, v2, v1, v0 ],
1067
- normals: [ null, null, null, null ]
1068
- } );
1069
- totalFaces += 2;
1070
-
1071
- }
1072
-
1073
- break;
1074
- default:
1075
- throw new Error( 'LDrawLoader: Unknown line type "' + lineType + '"' + lp.getLineNumberString() + '.' );
1076
-
1077
- }
1078
-
1079
- }
1080
-
1081
- if ( parsingEmbeddedFiles ) {
1082
-
1083
- this.setData( currentEmbeddedFileName, currentEmbeddedText );
1084
-
1085
- }
1086
-
1087
- return {
1088
- faces,
1089
- conditionalSegments,
1090
- lineSegments,
1091
- type,
1092
- category,
1093
- keywords,
1094
- author,
1095
- subobjects,
1096
- totalFaces,
1097
- startingBuildingStep,
1098
- materials,
1099
- fileName,
1100
- group: null
1101
- };
1102
-
1103
- }
1104
-
1105
- // returns an (optionally cloned) instance of the data
1106
- getData( fileName, clone = true ) {
1107
-
1108
- const key = fileName.toLowerCase();
1109
- const result = this._cache[ key ];
1110
- if ( result === null || result instanceof Promise ) {
1111
-
1112
- return null;
1113
-
1114
- }
1115
-
1116
- if ( clone ) {
1117
-
1118
- return this.cloneResult( result );
1119
-
1120
- } else {
1121
-
1122
- return result;
1123
-
1124
- }
1125
-
1126
- }
1127
-
1128
- // kicks off a fetch and parse of the requested data if it hasn't already been loaded. Returns when
1129
- // the data is ready to use and can be retrieved synchronously with "getData".
1130
- async ensureDataLoaded( fileName ) {
1131
-
1132
- const key = fileName.toLowerCase();
1133
- if ( ! ( key in this._cache ) ) {
1134
-
1135
- // replace the promise with a copy of the parsed data for immediate processing
1136
- this._cache[ key ] = this.fetchData( fileName ).then( text => {
1137
-
1138
- const info = this.parse( text, fileName );
1139
- this._cache[ key ] = info;
1140
- return info;
1141
-
1142
- } );
1143
-
1144
- }
1145
-
1146
- await this._cache[ key ];
1147
-
1148
- }
1149
-
1150
- // sets the data in the cache from parsed data
1151
- setData( fileName, text ) {
1152
-
1153
- const key = fileName.toLowerCase();
1154
- this._cache[ key ] = this.parse( text, fileName );
1155
-
1156
- }
1157
-
1158
- }
1159
-
1160
- // returns the material for an associated color code. If the color code is 16 for a face or 24 for
1161
- // an edge then the passthroughColorCode is used.
1162
- function getMaterialFromCode( colorCode, parentColorCode, materialHierarchy, forEdge ) {
1163
-
1164
- const isPassthrough = ! forEdge && colorCode === MAIN_COLOUR_CODE || forEdge && colorCode === MAIN_EDGE_COLOUR_CODE;
1165
- if ( isPassthrough ) {
1166
-
1167
- colorCode = parentColorCode;
1168
-
1169
- }
1170
-
1171
- return materialHierarchy[ colorCode ] || null;
1172
-
1173
- }
1174
-
1175
- // Class used to parse and build LDraw parts as three.js objects and cache them if they're a "Part" type.
1176
- class LDrawPartsGeometryCache {
1177
-
1178
- constructor( loader ) {
1179
-
1180
- this.loader = loader;
1181
- this.parseCache = new LDrawParsedCache( loader );
1182
- this._cache = {};
1183
-
1184
- }
1185
-
1186
- // Convert the given file information into a mesh by processing subobjects.
1187
- async processIntoMesh( info ) {
1188
-
1189
- const loader = this.loader;
1190
- const parseCache = this.parseCache;
1191
- const faceMaterials = new Set();
1192
-
1193
- // Processes the part subobject information to load child parts and merge geometry onto part
1194
- // piece object.
1195
- const processInfoSubobjects = async ( info, subobject = null ) => {
1196
-
1197
- const subobjects = info.subobjects;
1198
- const promises = [];
1199
-
1200
- // Trigger load of all subobjects. If a subobject isn't a primitive then load it as a separate
1201
- // group which lets instruction steps apply correctly.
1202
- for ( let i = 0, l = subobjects.length; i < l; i ++ ) {
1203
-
1204
- const subobject = subobjects[ i ];
1205
- const promise = parseCache.ensureDataLoaded( subobject.fileName ).then( () => {
1206
-
1207
- const subobjectInfo = parseCache.getData( subobject.fileName, false );
1208
- if ( ! isPrimitiveType( subobjectInfo.type ) ) {
1209
-
1210
- return this.loadModel( subobject.fileName ).catch( error => {
1211
-
1212
- console.warn( error );
1213
- return null;
1214
-
1215
- } );
1216
-
1217
- }
1218
-
1219
- return processInfoSubobjects( parseCache.getData( subobject.fileName ), subobject );
1220
-
1221
- } );
1222
- promises.push( promise );
1223
-
1224
- }
1225
-
1226
- const group = new THREE.Group();
1227
- group.userData.category = info.category;
1228
- group.userData.keywords = info.keywords;
1229
- group.userData.author = info.author;
1230
- group.userData.type = info.type;
1231
- group.userData.fileName = info.fileName;
1232
- info.group = group;
1233
- const subobjectInfos = await Promise.all( promises );
1234
- for ( let i = 0, l = subobjectInfos.length; i < l; i ++ ) {
1235
-
1236
- const subobject = info.subobjects[ i ];
1237
- const subobjectInfo = subobjectInfos[ i ];
1238
- if ( subobjectInfo === null ) {
1239
-
1240
- // the subobject failed to load
1241
- continue;
1242
-
1243
- }
1244
-
1245
- // if the subobject was loaded as a separate group then apply the parent scopes materials
1246
- if ( subobjectInfo.isGroup ) {
1247
-
1248
- const subobjectGroup = subobjectInfo;
1249
- subobject.matrix.decompose( subobjectGroup.position, subobjectGroup.quaternion, subobjectGroup.scale );
1250
- subobjectGroup.userData.startingBuildingStep = subobject.startingBuildingStep;
1251
- subobjectGroup.name = subobject.fileName;
1252
- loader.applyMaterialsToMesh( subobjectGroup, subobject.colorCode, info.materials );
1253
- subobjectGroup.userData.colorCode = subobject.colorCode;
1254
- group.add( subobjectGroup );
1255
- continue;
1256
-
1257
- }
1258
-
1259
- // add the subobject group if it has children in case it has both children and primitives
1260
- if ( subobjectInfo.group.children.length ) {
1261
-
1262
- group.add( subobjectInfo.group );
1263
-
1264
- }
1265
-
1266
- // transform the primitives into the local space of the parent piece and append them to
1267
- // to the parent primitives list.
1268
- const parentLineSegments = info.lineSegments;
1269
- const parentConditionalSegments = info.conditionalSegments;
1270
- const parentFaces = info.faces;
1271
- const lineSegments = subobjectInfo.lineSegments;
1272
- const conditionalSegments = subobjectInfo.conditionalSegments;
1273
- const faces = subobjectInfo.faces;
1274
- const matrix = subobject.matrix;
1275
- const inverted = subobject.inverted;
1276
- const matrixScaleInverted = matrix.determinant() < 0;
1277
- const colorCode = subobject.colorCode;
1278
- const lineColorCode = colorCode === MAIN_COLOUR_CODE ? MAIN_EDGE_COLOUR_CODE : colorCode;
1279
- for ( let i = 0, l = lineSegments.length; i < l; i ++ ) {
1280
-
1281
- const ls = lineSegments[ i ];
1282
- const vertices = ls.vertices;
1283
- vertices[ 0 ].applyMatrix4( matrix );
1284
- vertices[ 1 ].applyMatrix4( matrix );
1285
- ls.colorCode = ls.colorCode === MAIN_EDGE_COLOUR_CODE ? lineColorCode : ls.colorCode;
1286
- ls.material = ls.material || getMaterialFromCode( ls.colorCode, ls.colorCode, info.materials, true );
1287
- parentLineSegments.push( ls );
1288
-
1289
- }
1290
-
1291
- for ( let i = 0, l = conditionalSegments.length; i < l; i ++ ) {
1292
-
1293
- const os = conditionalSegments[ i ];
1294
- const vertices = os.vertices;
1295
- const controlPoints = os.controlPoints;
1296
- vertices[ 0 ].applyMatrix4( matrix );
1297
- vertices[ 1 ].applyMatrix4( matrix );
1298
- controlPoints[ 0 ].applyMatrix4( matrix );
1299
- controlPoints[ 1 ].applyMatrix4( matrix );
1300
- os.colorCode = os.colorCode === MAIN_EDGE_COLOUR_CODE ? lineColorCode : os.colorCode;
1301
- os.material = os.material || getMaterialFromCode( os.colorCode, os.colorCode, info.materials, true );
1302
- parentConditionalSegments.push( os );
1303
-
1304
- }
1305
-
1306
- for ( let i = 0, l = faces.length; i < l; i ++ ) {
1307
-
1308
- const tri = faces[ i ];
1309
- const vertices = tri.vertices;
1310
- for ( let i = 0, l = vertices.length; i < l; i ++ ) {
1311
-
1312
- vertices[ i ].applyMatrix4( matrix );
1313
-
1314
- }
1315
-
1316
- tri.colorCode = tri.colorCode === MAIN_COLOUR_CODE ? colorCode : tri.colorCode;
1317
- tri.material = tri.material || getMaterialFromCode( tri.colorCode, colorCode, info.materials, false );
1318
- faceMaterials.add( tri.colorCode );
1319
-
1320
- // If the scale of the object is negated then the triangle winding order
1321
- // needs to be flipped.
1322
- if ( matrixScaleInverted !== inverted ) {
1323
-
1324
- vertices.reverse();
1325
-
1326
- }
1327
-
1328
- parentFaces.push( tri );
1329
-
1330
- }
1331
-
1332
- info.totalFaces += subobjectInfo.totalFaces;
1333
-
1334
- }
1335
-
1336
- // Apply the parent subobjects pass through material code to this object. This is done several times due
1337
- // to material scoping.
1338
- if ( subobject ) {
1339
-
1340
- loader.applyMaterialsToMesh( group, subobject.colorCode, info.materials );
1341
- group.userData.colorCode = subobject.colorCode;
1342
-
1343
- }
1344
-
1345
- return info;
1346
-
1347
- };
1348
-
1349
- // Track material use to see if we need to use the normal smooth slow path for hard edges.
1350
- for ( let i = 0, l = info.faces; i < l; i ++ ) {
1351
-
1352
- faceMaterials.add( info.faces[ i ].colorCode );
1353
-
1354
- }
1355
-
1356
- await processInfoSubobjects( info );
1357
- if ( loader.smoothNormals ) {
1358
-
1359
- const checkSubSegments = faceMaterials.size > 1;
1360
- generateFaceNormals( info.faces );
1361
- smoothNormals( info.faces, info.lineSegments, checkSubSegments );
1362
-
1363
- }
1364
-
1365
- // Add the primitive objects and metadata.
1366
- const group = info.group;
1367
- if ( info.faces.length > 0 ) {
1368
-
1369
- group.add( createObject( info.faces, 3, false, info.totalFaces ) );
1370
-
1371
- }
1372
-
1373
- if ( info.lineSegments.length > 0 ) {
1374
-
1375
- group.add( createObject( info.lineSegments, 2 ) );
1376
-
1377
- }
1378
-
1379
- if ( info.conditionalSegments.length > 0 ) {
1380
-
1381
- group.add( createObject( info.conditionalSegments, 2, true ) );
1382
-
1383
- }
1384
-
1385
- return group;
1386
-
1387
- }
1388
- hasCachedModel( fileName ) {
1389
-
1390
- return fileName !== null && fileName.toLowerCase() in this._cache;
1391
-
1392
- }
1393
- async getCachedModel( fileName ) {
1394
-
1395
- if ( fileName !== null && this.hasCachedModel( fileName ) ) {
1396
-
1397
- const key = fileName.toLowerCase();
1398
- const group = await this._cache[ key ];
1399
- return group.clone();
1400
-
1401
- } else {
1402
-
1403
- return null;
1404
-
1405
- }
1406
-
1407
- }
1408
-
1409
- // Loads and parses the model with the given file name. Returns a cached copy if available.
1410
- async loadModel( fileName ) {
1411
-
1412
- const parseCache = this.parseCache;
1413
- const key = fileName.toLowerCase();
1414
- if ( this.hasCachedModel( fileName ) ) {
1415
-
1416
- // Return cached model if available.
1417
- return this.getCachedModel( fileName );
1418
-
1419
- } else {
1420
-
1421
- // Otherwise parse a new model.
1422
- // Ensure the file data is loaded and pre parsed.
1423
- await parseCache.ensureDataLoaded( fileName );
1424
- const info = parseCache.getData( fileName );
1425
- const promise = this.processIntoMesh( info );
1426
-
1427
- // Now that the file has loaded it's possible that another part parse has been waiting in parallel
1428
- // so check the cache again to see if it's been added since the last async operation so we don't
1429
- // do unnecessary work.
1430
- if ( this.hasCachedModel( fileName ) ) {
1431
-
1432
- return this.getCachedModel( fileName );
1433
-
1434
- }
1435
-
1436
- // Cache object if it's a part so it can be reused later.
1437
- if ( isPartType( info.type ) ) {
1438
-
1439
- this._cache[ key ] = promise;
1440
-
1441
- }
1442
-
1443
- // return a copy
1444
- const group = await promise;
1445
- return group.clone();
1446
-
1447
- }
1448
-
1449
- }
1450
-
1451
- // parses the given model text into a renderable object. Returns cached copy if available.
1452
- async parseModel( text ) {
1453
-
1454
- const parseCache = this.parseCache;
1455
- const info = parseCache.parse( text );
1456
- if ( isPartType( info.type ) && this.hasCachedModel( info.fileName ) ) {
1457
-
1458
- return this.getCachedModel( info.fileName );
1459
-
1460
- }
1461
-
1462
- return this.processIntoMesh( info );
1463
-
1464
- }
1465
-
1466
- }
1467
- function sortByMaterial( a, b ) {
1468
-
1469
- if ( a.colorCode === b.colorCode ) {
1470
-
1471
- return 0;
1472
-
1473
- }
1474
-
1475
- if ( a.colorCode < b.colorCode ) {
1476
-
1477
- return - 1;
1478
-
1479
- }
1480
-
1481
- return 1;
1482
-
1483
- }
1484
-
1485
- function createObject( elements, elementSize, isConditionalSegments = false, totalElements = null ) {
1486
-
1487
- // Creates a THREE.LineSegments (elementSize = 2) or a THREE.Mesh (elementSize = 3 )
1488
- // With per face / segment material, implemented with mesh groups and materials array
1489
-
1490
- // Sort the faces or line segments by color code to make later the mesh groups
1491
- elements.sort( sortByMaterial );
1492
- if ( totalElements === null ) {
1493
-
1494
- totalElements = elements.length;
1495
-
1496
- }
1497
-
1498
- const positions = new Float32Array( elementSize * totalElements * 3 );
1499
- const normals = elementSize === 3 ? new Float32Array( elementSize * totalElements * 3 ) : null;
1500
- const materials = [];
1501
- const quadArray = new Array( 6 );
1502
- const bufferGeometry = new THREE.BufferGeometry();
1503
- let prevMaterial = null;
1504
- let index0 = 0;
1505
- let numGroupVerts = 0;
1506
- let offset = 0;
1507
- for ( let iElem = 0, nElem = elements.length; iElem < nElem; iElem ++ ) {
1508
-
1509
- const elem = elements[ iElem ];
1510
- let vertices = elem.vertices;
1511
- if ( vertices.length === 4 ) {
1512
-
1513
- quadArray[ 0 ] = vertices[ 0 ];
1514
- quadArray[ 1 ] = vertices[ 1 ];
1515
- quadArray[ 2 ] = vertices[ 2 ];
1516
- quadArray[ 3 ] = vertices[ 0 ];
1517
- quadArray[ 4 ] = vertices[ 2 ];
1518
- quadArray[ 5 ] = vertices[ 3 ];
1519
- vertices = quadArray;
1520
-
1521
- }
1522
-
1523
- for ( let j = 0, l = vertices.length; j < l; j ++ ) {
1524
-
1525
- const v = vertices[ j ];
1526
- const index = offset + j * 3;
1527
- positions[ index + 0 ] = v.x;
1528
- positions[ index + 1 ] = v.y;
1529
- positions[ index + 2 ] = v.z;
1530
-
1531
- }
1532
-
1533
- // create the normals array if this is a set of faces
1534
- if ( elementSize === 3 ) {
1535
-
1536
- if ( ! elem.faceNormal ) {
1537
-
1538
- const v0 = vertices[ 0 ];
1539
- const v1 = vertices[ 1 ];
1540
- const v2 = vertices[ 2 ];
1541
- _tempVec0.subVectors( v1, v0 );
1542
- _tempVec1.subVectors( v2, v1 );
1543
- elem.faceNormal = new THREE.Vector3().crossVectors( _tempVec0, _tempVec1 ).normalize();
1544
-
1545
- }
1546
-
1547
- let elemNormals = elem.normals;
1548
- if ( elemNormals.length === 4 ) {
1549
-
1550
- quadArray[ 0 ] = elemNormals[ 0 ];
1551
- quadArray[ 1 ] = elemNormals[ 1 ];
1552
- quadArray[ 2 ] = elemNormals[ 2 ];
1553
- quadArray[ 3 ] = elemNormals[ 0 ];
1554
- quadArray[ 4 ] = elemNormals[ 2 ];
1555
- quadArray[ 5 ] = elemNormals[ 3 ];
1556
- elemNormals = quadArray;
1557
-
1558
- }
1559
-
1560
- for ( let j = 0, l = elemNormals.length; j < l; j ++ ) {
1561
-
1562
- // use face normal if a vertex normal is not provided
1563
- let n = elem.faceNormal;
1564
- if ( elemNormals[ j ] ) {
1565
-
1566
- n = elemNormals[ j ].norm;
1567
-
1568
- }
1569
-
1570
- const index = offset + j * 3;
1571
- normals[ index + 0 ] = n.x;
1572
- normals[ index + 1 ] = n.y;
1573
- normals[ index + 2 ] = n.z;
1574
-
1575
- }
1576
-
1577
- }
1578
-
1579
- if ( prevMaterial !== elem.colorCode ) {
1580
-
1581
- if ( prevMaterial !== null ) {
1582
-
1583
- bufferGeometry.addGroup( index0, numGroupVerts, materials.length - 1 );
1584
-
1585
- }
1586
-
1587
- const material = elem.material;
1588
- if ( material !== null ) {
1589
-
1590
- if ( elementSize === 3 ) {
1591
-
1592
- materials.push( material );
1593
-
1594
- } else if ( elementSize === 2 ) {
1595
-
1596
- if ( isConditionalSegments ) {
1597
-
1598
- materials.push( material.userData.edgeMaterial.userData.conditionalEdgeMaterial );
1599
-
1600
- } else {
1601
-
1602
- materials.push( material.userData.edgeMaterial );
1603
-
1604
- }
1605
-
1606
- }
1607
-
1608
- } else {
1609
-
1610
- // If a material has not been made available yet then keep the color code string in the material array
1611
- // to save the spot for the material once a parent scopes materials are being applied to the object.
1612
- materials.push( elem.colorCode );
1613
-
1614
- }
1615
-
1616
- prevMaterial = elem.colorCode;
1617
- index0 = offset / 3;
1618
- numGroupVerts = vertices.length;
1619
-
1620
- } else {
1621
-
1622
- numGroupVerts += vertices.length;
1623
-
1624
- }
1625
-
1626
- offset += 3 * vertices.length;
1627
-
1628
- }
1629
-
1630
- if ( numGroupVerts > 0 ) {
1631
-
1632
- bufferGeometry.addGroup( index0, Infinity, materials.length - 1 );
1633
-
1634
- }
1635
-
1636
- bufferGeometry.setAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
1637
- if ( normals !== null ) {
1638
-
1639
- bufferGeometry.setAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
1640
-
1641
- }
1642
-
1643
- let object3d = null;
1644
- if ( elementSize === 2 ) {
1645
-
1646
- if ( isConditionalSegments ) {
1647
-
1648
- object3d = new ConditionalLineSegments( bufferGeometry, materials.length === 1 ? materials[ 0 ] : materials );
1649
-
1650
- } else {
1651
-
1652
- object3d = new THREE.LineSegments( bufferGeometry, materials.length === 1 ? materials[ 0 ] : materials );
1653
-
1654
- }
1655
-
1656
- } else if ( elementSize === 3 ) {
1657
-
1658
- object3d = new THREE.Mesh( bufferGeometry, materials.length === 1 ? materials[ 0 ] : materials );
1659
-
1660
- }
1661
-
1662
- if ( isConditionalSegments ) {
1663
-
1664
- object3d.isConditionalLine = true;
1665
- const controlArray0 = new Float32Array( elements.length * 3 * 2 );
1666
- const controlArray1 = new Float32Array( elements.length * 3 * 2 );
1667
- const directionArray = new Float32Array( elements.length * 3 * 2 );
1668
- for ( let i = 0, l = elements.length; i < l; i ++ ) {
1669
-
1670
- const os = elements[ i ];
1671
- const vertices = os.vertices;
1672
- const controlPoints = os.controlPoints;
1673
- const c0 = controlPoints[ 0 ];
1674
- const c1 = controlPoints[ 1 ];
1675
- const v0 = vertices[ 0 ];
1676
- const v1 = vertices[ 1 ];
1677
- const index = i * 3 * 2;
1678
- controlArray0[ index + 0 ] = c0.x;
1679
- controlArray0[ index + 1 ] = c0.y;
1680
- controlArray0[ index + 2 ] = c0.z;
1681
- controlArray0[ index + 3 ] = c0.x;
1682
- controlArray0[ index + 4 ] = c0.y;
1683
- controlArray0[ index + 5 ] = c0.z;
1684
- controlArray1[ index + 0 ] = c1.x;
1685
- controlArray1[ index + 1 ] = c1.y;
1686
- controlArray1[ index + 2 ] = c1.z;
1687
- controlArray1[ index + 3 ] = c1.x;
1688
- controlArray1[ index + 4 ] = c1.y;
1689
- controlArray1[ index + 5 ] = c1.z;
1690
- directionArray[ index + 0 ] = v1.x - v0.x;
1691
- directionArray[ index + 1 ] = v1.y - v0.y;
1692
- directionArray[ index + 2 ] = v1.z - v0.z;
1693
- directionArray[ index + 3 ] = v1.x - v0.x;
1694
- directionArray[ index + 4 ] = v1.y - v0.y;
1695
- directionArray[ index + 5 ] = v1.z - v0.z;
1696
-
1697
- }
1698
-
1699
- bufferGeometry.setAttribute( 'control0', new THREE.BufferAttribute( controlArray0, 3, false ) );
1700
- bufferGeometry.setAttribute( 'control1', new THREE.BufferAttribute( controlArray1, 3, false ) );
1701
- bufferGeometry.setAttribute( 'direction', new THREE.BufferAttribute( directionArray, 3, false ) );
1702
-
1703
- }
1704
-
1705
- return object3d;
1706
-
1707
- }
1708
-
1709
- //
1710
-
1711
- class LDrawLoader extends THREE.Loader {
1712
-
1713
- constructor( manager ) {
1714
-
1715
- super( manager );
1716
-
1717
- // Array of THREE.Material
1718
- this.materials = [];
1719
- this.materialLibrary = {};
1720
-
1721
- // This also allows to handle the embedded text files ("0 FILE" lines)
1722
- this.partsCache = new LDrawPartsGeometryCache( this );
1723
-
1724
- // 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.
1725
- this.fileMap = {};
1726
-
1727
- // Initializes the materials library with default materials
1728
- this.setMaterials( [] );
1729
-
1730
- // If this flag is set to true the vertex normals will be smoothed.
1731
- this.smoothNormals = true;
1732
-
1733
- // The path to load parts from the LDraw parts library from.
1734
- this.partsLibraryPath = '';
1735
-
1736
- // Material assigned to not available colors for meshes and edges
1737
- this.missingColorMaterial = new THREE.MeshStandardMaterial( {
1738
- color: 0xFF00FF,
1739
- roughness: 0.3,
1740
- metalness: 0
1741
- } );
1742
- this.missingColorMaterial.name = 'Missing material';
1743
- this.missingEdgeColorMaterial = new THREE.LineBasicMaterial( {
1744
- color: 0xFF00FF
1745
- } );
1746
- this.missingEdgeColorMaterial.name = 'Missing material - Edge';
1747
- this.missingConditionalEdgeColorMaterial = new LDrawConditionalLineMaterial( {
1748
- fog: true,
1749
- color: 0xFF00FF
1750
- } );
1751
- this.missingConditionalEdgeColorMaterial.name = 'Missing material - Conditional Edge';
1752
- this.missingColorMaterial.userData.edgeMaterial = this.missingEdgeColorMaterial;
1753
- this.missingEdgeColorMaterial.userData.conditionalEdgeMaterial = this.missingConditionalEdgeColorMaterial;
1754
-
1755
- }
1756
- setPartsLibraryPath( path ) {
1757
-
1758
- this.partsLibraryPath = path;
1759
- return this;
1760
-
1761
- }
1762
- async preloadMaterials( url ) {
1763
-
1764
- const fileLoader = new THREE.FileLoader( this.manager );
1765
- fileLoader.setPath( this.path );
1766
- fileLoader.setRequestHeader( this.requestHeader );
1767
- fileLoader.setWithCredentials( this.withCredentials );
1768
- const text = await fileLoader.loadAsync( url );
1769
- const colorLineRegex = /^0 !COLOUR/;
1770
- const lines = text.split( /[\n\r]/g );
1771
- const materials = [];
1772
- for ( let i = 0, l = lines.length; i < l; i ++ ) {
1773
-
1774
- const line = lines[ i ];
1775
- if ( colorLineRegex.test( line ) ) {
1776
-
1777
- const directive = line.replace( colorLineRegex, '' );
1778
- const material = this.parseColorMetaDirective( new LineParser( directive ) );
1779
- materials.push( material );
1780
-
1781
- }
1782
-
1783
- }
1784
-
1785
- this.setMaterials( materials );
1786
-
1787
- }
1788
- load( url, onLoad, onProgress, onError ) {
1789
-
1790
- const fileLoader = new THREE.FileLoader( this.manager );
1791
- fileLoader.setPath( this.path );
1792
- fileLoader.setRequestHeader( this.requestHeader );
1793
- fileLoader.setWithCredentials( this.withCredentials );
1794
- fileLoader.load( url, text => {
1795
-
1796
- this.partsCache.parseModel( text, this.materialLibrary ).then( group => {
1797
-
1798
- this.applyMaterialsToMesh( group, MAIN_COLOUR_CODE, this.materialLibrary, true );
1799
- this.computeBuildingSteps( group );
1800
- group.userData.fileName = url;
1801
- onLoad( group );
1802
-
1803
- } ).catch( onError );
1804
-
1805
- }, onProgress, onError );
1806
-
1807
- }
1808
- parse( text, onLoad ) {
1809
-
1810
- this.partsCache.parseModel( text, this.materialLibrary ).then( group => {
1811
-
1812
- this.applyMaterialsToMesh( group, MAIN_COLOUR_CODE, this.materialLibrary, true );
1813
- this.computeBuildingSteps( group );
1814
- group.userData.fileName = '';
1815
- onLoad( group );
1816
-
1817
- } );
1818
-
1819
- }
1820
- setMaterials( materials ) {
1821
-
1822
- this.materialLibrary = {};
1823
- this.materials = [];
1824
- for ( let i = 0, l = materials.length; i < l; i ++ ) {
1825
-
1826
- this.addMaterial( materials[ i ] );
1827
-
1828
- }
1829
-
1830
- // Add default main triangle and line edge materials (used in pieces that can be colored with a main color)
1831
- this.addMaterial( this.parseColorMetaDirective( new LineParser( 'Main_Colour CODE 16 VALUE #FF8080 EDGE #333333' ) ) );
1832
- this.addMaterial( this.parseColorMetaDirective( new LineParser( 'Edge_Colour CODE 24 VALUE #A0A0A0 EDGE #333333' ) ) );
1833
- return this;
1834
-
1835
- }
1836
- setFileMap( fileMap ) {
1837
-
1838
- this.fileMap = fileMap;
1839
- return this;
1840
-
1841
- }
1842
- addMaterial( material ) {
1843
-
1844
- // Adds a material to the material library which is on top of the parse scopes stack. And also to the materials array
1845
-
1846
- const matLib = this.materialLibrary;
1847
- if ( ! matLib[ material.userData.code ] ) {
1848
-
1849
- this.materials.push( material );
1850
- matLib[ material.userData.code ] = material;
1851
-
1852
- }
1853
-
1854
- return this;
1855
-
1856
- }
1857
- getMaterial( colorCode ) {
1858
-
1859
- if ( colorCode.startsWith( '0x2' ) ) {
1860
-
1861
- // Special 'direct' material value (RGB color)
1862
- const color = colorCode.substring( 3 );
1863
- return this.parseColorMetaDirective( new LineParser( 'Direct_Color_' + color + ' CODE -1 VALUE #' + color + ' EDGE #' + color + '' ) );
1864
-
1865
- }
1866
-
1867
- return this.materialLibrary[ colorCode ] || null;
1868
-
1869
- }
1870
-
1871
- // Applies the appropriate materials to a prebuilt hierarchy of geometry. Assumes that color codes are present
1872
- // in the material array if they need to be filled in.
1873
- applyMaterialsToMesh( group, parentColorCode, materialHierarchy, finalMaterialPass = false ) {
1874
-
1875
- // find any missing materials as indicated by a color code string and replace it with a material from the current material lib
1876
- const loader = this;
1877
- const parentIsPassthrough = parentColorCode === MAIN_COLOUR_CODE;
1878
- group.traverse( c => {
1879
-
1880
- if ( c.isMesh || c.isLineSegments ) {
1881
-
1882
- if ( Array.isArray( c.material ) ) {
1883
-
1884
- for ( let i = 0, l = c.material.length; i < l; i ++ ) {
1885
-
1886
- if ( ! c.material[ i ].isMaterial ) {
1887
-
1888
- c.material[ i ] = getMaterial( c, c.material[ i ] );
1889
-
1890
- }
1891
-
1892
- }
1893
-
1894
- } else if ( ! c.material.isMaterial ) {
1895
-
1896
- c.material = getMaterial( c, c.material );
1897
-
1898
- }
1899
-
1900
- }
1901
-
1902
- } );
1903
-
1904
- // Returns the appropriate material for the object (line or face) given color code. If the code is "pass through"
1905
- // (24 for lines, 16 for edges) then the pass through color code is used. If that is also pass through then it's
1906
- // simply returned for the subsequent material application.
1907
- function getMaterial( c, colorCode ) {
1908
-
1909
- // if our parent is a passthrough color code and we don't have the current material color available then
1910
- // return early.
1911
- if ( parentIsPassthrough && ! ( colorCode in materialHierarchy ) && ! finalMaterialPass ) {
1912
-
1913
- return colorCode;
1914
-
1915
- }
1916
-
1917
- const forEdge = c.isLineSegments || c.isConditionalLine;
1918
- const isPassthrough = ! forEdge && colorCode === MAIN_COLOUR_CODE || forEdge && colorCode === MAIN_EDGE_COLOUR_CODE;
1919
- if ( isPassthrough ) {
1920
-
1921
- colorCode = parentColorCode;
1922
-
1923
- }
1924
-
1925
- let material = null;
1926
- if ( colorCode in materialHierarchy ) {
1927
-
1928
- material = materialHierarchy[ colorCode ];
1929
-
1930
- } else if ( finalMaterialPass ) {
1931
-
1932
- // see if we can get the final material from from the "getMaterial" function which will attempt to
1933
- // parse the "direct" colors
1934
- material = loader.getMaterial( colorCode );
1935
- if ( material === null ) {
1936
-
1937
- // otherwise throw a warning if this is final opportunity to set the material
1938
- console.warn( `LDrawLoader: Material properties for code ${colorCode} not available.` );
1939
-
1940
- // And return the 'missing color' material
1941
- material = loader.missingColorMaterial;
1942
-
1943
- }
1944
-
1945
- } else {
1946
-
1947
- return colorCode;
1948
-
1949
- }
1950
-
1951
- if ( c.isLineSegments ) {
1952
-
1953
- material = material.userData.edgeMaterial;
1954
- if ( c.isConditionalLine ) {
1955
-
1956
- material = material.userData.conditionalEdgeMaterial;
1957
-
1958
- }
1959
-
1960
- }
1961
-
1962
- return material;
1963
-
1964
- }
1965
-
1966
- }
1967
- getMainMaterial() {
1968
-
1969
- return this.getMaterial( MAIN_COLOUR_CODE );
1970
-
1971
- }
1972
- getMainEdgeMaterial() {
1973
-
1974
- const mat = this.getMaterial( MAIN_EDGE_COLOUR_CODE );
1975
- return mat ? mat.userData.edgeMaterial : null;
1976
-
1977
- }
1978
- parseColorMetaDirective( lineParser ) {
1979
-
1980
- // Parses a color definition and returns a THREE.Material
1981
-
1982
- let code = null;
1983
-
1984
- // Triangle and line colors
1985
- let color = 0xFF00FF;
1986
- let edgeColor = 0xFF00FF;
1987
-
1988
- // Transparency
1989
- let alpha = 1;
1990
- let isTransparent = false;
1991
- // Self-illumination:
1992
- let luminance = 0;
1993
- let finishType = FINISH_TYPE_DEFAULT;
1994
- let edgeMaterial = null;
1995
- const name = lineParser.getToken();
1996
- if ( ! name ) {
1997
-
1998
- throw new Error( 'LDrawLoader: Material name was expected after "!COLOUR tag' + lineParser.getLineNumberString() + '.' );
1999
-
2000
- }
2001
-
2002
- // Parse tag tokens and their parameters
2003
- let token = null;
2004
- while ( true ) {
2005
-
2006
- token = lineParser.getToken();
2007
- if ( ! token ) {
2008
-
2009
- break;
2010
-
2011
- }
2012
-
2013
- if ( ! parseLuminance( token ) ) {
2014
-
2015
- switch ( token.toUpperCase() ) {
2016
-
2017
- case 'CODE':
2018
- code = lineParser.getToken();
2019
- break;
2020
- case 'VALUE':
2021
- color = lineParser.getToken();
2022
- if ( color.startsWith( '0x' ) ) {
2023
-
2024
- color = '#' + color.substring( 2 );
2025
-
2026
- } else if ( ! color.startsWith( '#' ) ) {
2027
-
2028
- throw new Error( 'LDrawLoader: Invalid color while parsing material' + lineParser.getLineNumberString() + '.' );
2029
-
2030
- }
2031
-
2032
- break;
2033
- case 'EDGE':
2034
- edgeColor = lineParser.getToken();
2035
- if ( edgeColor.startsWith( '0x' ) ) {
2036
-
2037
- edgeColor = '#' + edgeColor.substring( 2 );
2038
-
2039
- } else if ( ! edgeColor.startsWith( '#' ) ) {
2040
-
2041
- // Try to see if edge color is a color code
2042
- edgeMaterial = this.getMaterial( edgeColor );
2043
- if ( ! edgeMaterial ) {
2044
-
2045
- throw new Error( 'LDrawLoader: Invalid edge color while parsing material' + lineParser.getLineNumberString() + '.' );
2046
-
2047
- }
2048
-
2049
- // Get the edge material for this triangle material
2050
- edgeMaterial = edgeMaterial.userData.edgeMaterial;
2051
-
2052
- }
2053
-
2054
- break;
2055
- case 'ALPHA':
2056
- alpha = parseInt( lineParser.getToken() );
2057
- if ( isNaN( alpha ) ) {
2058
-
2059
- throw new Error( 'LDrawLoader: Invalid alpha value in material definition' + lineParser.getLineNumberString() + '.' );
2060
-
2061
- }
2062
-
2063
- alpha = Math.max( 0, Math.min( 1, alpha / 255 ) );
2064
- if ( alpha < 1 ) {
2065
-
2066
- isTransparent = true;
2067
-
2068
- }
2069
-
2070
- break;
2071
- case 'LUMINANCE':
2072
- if ( ! parseLuminance( lineParser.getToken() ) ) {
2073
-
2074
- throw new Error( 'LDrawLoader: Invalid luminance value in material definition' + LineParser.getLineNumberString() + '.' );
2075
-
2076
- }
2077
-
2078
- break;
2079
- case 'CHROME':
2080
- finishType = FINISH_TYPE_CHROME;
2081
- break;
2082
- case 'PEARLESCENT':
2083
- finishType = FINISH_TYPE_PEARLESCENT;
2084
- break;
2085
- case 'RUBBER':
2086
- finishType = FINISH_TYPE_RUBBER;
2087
- break;
2088
- case 'MATTE_METALLIC':
2089
- finishType = FINISH_TYPE_MATTE_METALLIC;
2090
- break;
2091
- case 'METAL':
2092
- finishType = FINISH_TYPE_METAL;
2093
- break;
2094
- case 'MATERIAL':
2095
- // Not implemented
2096
- lineParser.setToEnd();
2097
- break;
2098
- default:
2099
- throw new Error( 'LDrawLoader: Unknown token "' + token + '" while parsing material' + lineParser.getLineNumberString() + '.' );
2100
-
2101
- }
2102
-
2103
- }
2104
-
2105
- }
2106
-
2107
- let material = null;
2108
- switch ( finishType ) {
2109
-
2110
- case FINISH_TYPE_DEFAULT:
2111
- material = new THREE.MeshStandardMaterial( {
2112
- color: color,
2113
- roughness: 0.3,
2114
- metalness: 0
2115
- } );
2116
- break;
2117
- case FINISH_TYPE_PEARLESCENT:
2118
- // Try to imitate pearlescency by making the surface glossy
2119
- material = new THREE.MeshStandardMaterial( {
2120
- color: color,
2121
- roughness: 0.3,
2122
- metalness: 0.25
2123
- } );
2124
- break;
2125
- case FINISH_TYPE_CHROME:
2126
- // Mirror finish surface
2127
- material = new THREE.MeshStandardMaterial( {
2128
- color: color,
2129
- roughness: 0,
2130
- metalness: 1
2131
- } );
2132
- break;
2133
- case FINISH_TYPE_RUBBER:
2134
- // Rubber finish
2135
- material = new THREE.MeshStandardMaterial( {
2136
- color: color,
2137
- roughness: 0.9,
2138
- metalness: 0
2139
- } );
2140
- break;
2141
- case FINISH_TYPE_MATTE_METALLIC:
2142
- // Brushed metal finish
2143
- material = new THREE.MeshStandardMaterial( {
2144
- color: color,
2145
- roughness: 0.8,
2146
- metalness: 0.4
2147
- } );
2148
- break;
2149
- case FINISH_TYPE_METAL:
2150
- // Average metal finish
2151
- material = new THREE.MeshStandardMaterial( {
2152
- color: color,
2153
- roughness: 0.2,
2154
- metalness: 0.85
2155
- } );
2156
- break;
2157
- default:
2158
- // Should not happen
2159
- break;
2160
-
2161
- }
2162
-
2163
- material.transparent = isTransparent;
2164
- material.premultipliedAlpha = true;
2165
- material.opacity = alpha;
2166
- material.depthWrite = ! isTransparent;
2167
- material.color.convertSRGBToLinear();
2168
- material.polygonOffset = true;
2169
- material.polygonOffsetFactor = 1;
2170
- if ( luminance !== 0 ) {
2171
-
2172
- material.emissive.set( material.color ).multiplyScalar( luminance );
2173
-
2174
- }
2175
-
2176
- if ( ! edgeMaterial ) {
2177
-
2178
- // This is the material used for edges
2179
- edgeMaterial = new THREE.LineBasicMaterial( {
2180
- color: edgeColor,
2181
- transparent: isTransparent,
2182
- opacity: alpha,
2183
- depthWrite: ! isTransparent
2184
- } );
2185
- edgeMaterial.userData.code = code;
2186
- edgeMaterial.name = name + ' - Edge';
2187
- edgeMaterial.color.convertSRGBToLinear();
2188
-
2189
- // This is the material used for conditional edges
2190
- edgeMaterial.userData.conditionalEdgeMaterial = new LDrawConditionalLineMaterial( {
2191
- fog: true,
2192
- transparent: isTransparent,
2193
- depthWrite: ! isTransparent,
2194
- color: edgeColor,
2195
- opacity: alpha
2196
- } );
2197
- edgeMaterial.userData.conditionalEdgeMaterial.color.convertSRGBToLinear();
2198
- edgeMaterial.userData.conditionalEdgeMaterial.userData.code = code;
2199
- edgeMaterial.userData.conditionalEdgeMaterial.name = name + ' - Conditional Edge';
2200
-
2201
- }
2202
-
2203
- material.userData.code = code;
2204
- material.name = name;
2205
- material.userData.edgeMaterial = edgeMaterial;
2206
- this.addMaterial( material );
2207
- return material;
2208
- function parseLuminance( token ) {
2209
-
2210
- // Returns success
2211
-
2212
- let lum;
2213
- if ( token.startsWith( 'LUMINANCE' ) ) {
2214
-
2215
- lum = parseInt( token.substring( 9 ) );
2216
-
2217
- } else {
2218
-
2219
- lum = parseInt( token );
2220
-
2221
- }
2222
-
2223
- if ( isNaN( lum ) ) {
2224
-
2225
- return false;
2226
-
2227
- }
2228
-
2229
- luminance = Math.max( 0, Math.min( 1, lum / 255 ) );
2230
- return true;
2231
-
2232
- }
2233
-
2234
- }
2235
- computeBuildingSteps( model ) {
2236
-
2237
- // Sets userdata.buildingStep number in THREE.Group objects and userData.numBuildingSteps number in the root THREE.Group object.
2238
-
2239
- let stepNumber = 0;
2240
- model.traverse( c => {
2241
-
2242
- if ( c.isGroup ) {
2243
-
2244
- if ( c.userData.startingBuildingStep ) {
2245
-
2246
- stepNumber ++;
2247
-
2248
- }
2249
-
2250
- c.userData.buildingStep = stepNumber;
2251
-
2252
- }
2253
-
2254
- } );
2255
- model.userData.numBuildingSteps = stepNumber + 1;
2256
-
2257
- }
2258
-
2259
- }
2260
-
2261
- THREE.LDrawLoader = LDrawLoader;
2262
-
2263
- } )();