@needle-tools/three 0.145.4 → 0.146.2

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 (393) hide show
  1. package/README.md +1 -1
  2. package/build/three.cjs +32586 -35951
  3. package/build/three.js +32600 -35965
  4. package/build/three.min.js +6 -7
  5. package/build/three.module.js +1547 -1154
  6. package/examples/js/animation/AnimationClipCreator.js +0 -8
  7. package/examples/js/animation/CCDIKSolver.js +49 -66
  8. package/examples/js/animation/MMDAnimationHelper.js +66 -137
  9. package/examples/js/animation/MMDPhysics.js +70 -134
  10. package/examples/js/cameras/CinematicCamera.js +33 -22
  11. package/examples/js/controls/ArcballControls.js +138 -405
  12. package/examples/js/controls/DragControls.js +8 -33
  13. package/examples/js/controls/FirstPersonControls.js +32 -54
  14. package/examples/js/controls/FlyControls.js +29 -55
  15. package/examples/js/controls/OrbitControls.js +85 -95
  16. package/examples/js/controls/PointerLockControls.js +5 -14
  17. package/examples/js/controls/TrackballControls.js +33 -86
  18. package/examples/js/controls/TransformControls.js +84 -169
  19. package/examples/js/csm/CSM.js +4 -39
  20. package/examples/js/csm/CSMFrustum.js +3 -9
  21. package/examples/js/csm/CSMHelper.js +24 -4
  22. package/examples/js/csm/CSMShader.js +2 -6
  23. package/examples/js/curves/CurveExtras.js +27 -27
  24. package/examples/js/curves/NURBSCurve.js +4 -16
  25. package/examples/js/curves/NURBSSurface.js +3 -9
  26. package/examples/js/curves/NURBSUtils.js +8 -45
  27. package/examples/js/effects/AnaglyphEffect.js +4 -18
  28. package/examples/js/effects/AsciiEffect.js +32 -31
  29. package/examples/js/effects/OutlineEffect.js +26 -30
  30. package/examples/js/effects/ParallaxBarrierEffect.js +0 -13
  31. package/examples/js/effects/PeppersGhostEffect.js +12 -39
  32. package/examples/js/effects/StereoEffect.js +0 -4
  33. package/examples/js/environments/RoomEnvironment.js +12 -10
  34. package/examples/js/exporters/ColladaExporter.js +48 -65
  35. package/examples/js/exporters/DRACOExporter.js +22 -22
  36. package/examples/js/exporters/EXRExporter.js +15 -18
  37. package/examples/js/exporters/GLTFExporter.js +143 -261
  38. package/examples/js/exporters/MMDExporter.js +5 -12
  39. package/examples/js/exporters/OBJExporter.js +42 -33
  40. package/examples/js/exporters/PLYExporter.js +38 -33
  41. package/examples/js/exporters/STLExporter.js +5 -7
  42. package/examples/js/exporters/USDZExporter.js +110 -25
  43. package/examples/js/geometries/BoxLineGeometry.js +0 -1
  44. package/examples/js/geometries/ConvexGeometry.js +11 -6
  45. package/examples/js/geometries/DecalGeometry.js +53 -20
  46. package/examples/js/geometries/LightningStrike.js +54 -67
  47. package/examples/js/geometries/ParametricGeometries.js +8 -7
  48. package/examples/js/geometries/ParametricGeometry.js +25 -12
  49. package/examples/js/geometries/RoundedBoxGeometry.js +21 -19
  50. package/examples/js/geometries/TeapotGeometry.js +54 -50
  51. package/examples/js/geometries/TextGeometry.js +6 -4
  52. package/examples/js/helpers/LightProbeHelper.js +1 -2
  53. package/examples/js/helpers/OctreeHelper.js +22 -20
  54. package/examples/js/helpers/PositionalAudioHelper.js +8 -6
  55. package/examples/js/helpers/RectAreaLightHelper.js +6 -7
  56. package/examples/js/helpers/VertexNormalsHelper.js +15 -13
  57. package/examples/js/helpers/VertexTangentsHelper.js +15 -9
  58. package/examples/js/helpers/ViewHelper.js +31 -16
  59. package/examples/js/interactive/HTMLMesh.js +22 -33
  60. package/examples/js/interactive/InteractiveGroup.js +6 -12
  61. package/examples/js/interactive/SelectionBox.js +3 -70
  62. package/examples/js/interactive/SelectionHelper.js +0 -8
  63. package/examples/js/lights/LightProbeGenerator.js +32 -39
  64. package/examples/js/lights/RectAreaLightUniformsLib.js +5 -1
  65. package/examples/js/lines/LineGeometry.js +3 -5
  66. package/examples/js/lines/LineMaterial.js +4 -11
  67. package/examples/js/lines/LineSegments2.js +38 -89
  68. package/examples/js/lines/LineSegmentsGeometry.js +7 -28
  69. package/examples/js/lines/Wireframe.js +2 -7
  70. package/examples/js/lines/WireframeGeometry2.js +3 -1
  71. package/examples/js/loaders/3DMLoader.js +58 -155
  72. package/examples/js/loaders/3MFLoader.js +72 -106
  73. package/examples/js/loaders/AMFLoader.js +0 -25
  74. package/examples/js/loaders/BVHLoader.js +44 -43
  75. package/examples/js/loaders/BasisTextureLoader.js +16 -46
  76. package/examples/js/loaders/ColladaLoader.js +201 -359
  77. package/examples/js/loaders/DDSLoader.js +24 -25
  78. package/examples/js/loaders/DRACOLoader.js +29 -66
  79. package/examples/js/loaders/EXRLoader.js +67 -164
  80. package/examples/js/loaders/FBXLoader.js +286 -441
  81. package/examples/js/loaders/FontLoader.js +6 -15
  82. package/examples/js/loaders/GCodeLoader.js +15 -16
  83. package/examples/js/loaders/GLTFLoader.js +354 -405
  84. package/examples/js/loaders/HDRCubeTextureLoader.js +0 -6
  85. package/examples/js/loaders/KMZLoader.js +3 -7
  86. package/examples/js/loaders/KTXLoader.js +12 -30
  87. package/examples/js/loaders/LDrawLoader.js +178 -289
  88. package/examples/js/loaders/LUT3dlLoader.js +7 -11
  89. package/examples/js/loaders/LUTCubeLoader.js +0 -8
  90. package/examples/js/loaders/LWOLoader.js +59 -124
  91. package/examples/js/loaders/LogLuvLoader.js +27 -77
  92. package/examples/js/loaders/LottieLoader.js +4 -4
  93. package/examples/js/loaders/MD2Loader.js +26 -27
  94. package/examples/js/loaders/MDDLoader.js +6 -10
  95. package/examples/js/loaders/MMDLoader.js +180 -189
  96. package/examples/js/loaders/MTLLoader.js +18 -47
  97. package/examples/js/loaders/MaterialXLoader.js +392 -0
  98. package/examples/js/loaders/NRRDLoader.js +44 -84
  99. package/examples/js/loaders/OBJLoader.js +50 -65
  100. package/examples/js/loaders/PCDLoader.js +34 -29
  101. package/examples/js/loaders/PDBLoader.js +17 -13
  102. package/examples/js/loaders/PLYLoader.js +9 -39
  103. package/examples/js/loaders/PRWMLoader.js +11 -22
  104. package/examples/js/loaders/PVRLoader.js +7 -16
  105. package/examples/js/loaders/RGBELoader.js +36 -61
  106. package/examples/js/loaders/RGBMLoader.js +26 -87
  107. package/examples/js/loaders/STLLoader.js +20 -27
  108. package/examples/js/loaders/SVGLoader.js +361 -233
  109. package/examples/js/loaders/TDSLoader.js +81 -118
  110. package/examples/js/loaders/TGALoader.js +39 -41
  111. package/examples/js/loaders/TIFFLoader.js +0 -1
  112. package/examples/js/loaders/TTFLoader.js +0 -8
  113. package/examples/js/loaders/TiltLoader.js +14 -15
  114. package/examples/js/loaders/VOXLoader.js +8 -16
  115. package/examples/js/loaders/VRMLLoader.js +243 -340
  116. package/examples/js/loaders/VTKLoader.js +101 -118
  117. package/examples/js/loaders/XYZLoader.js +2 -4
  118. package/examples/js/loaders/lwo/IFFParser.js +55 -136
  119. package/examples/js/loaders/lwo/LWO2Parser.js +32 -83
  120. package/examples/js/loaders/lwo/LWO3Parser.js +31 -73
  121. package/examples/js/materials/MeshGouraudMaterial.js +15 -13
  122. package/examples/js/math/Capsule.js +0 -17
  123. package/examples/js/math/ColorConverter.js +3 -3
  124. package/examples/js/math/ConvexHull.js +183 -139
  125. package/examples/js/math/ImprovedNoise.js +1 -1
  126. package/examples/js/math/Lut.js +8 -15
  127. package/examples/js/math/MeshSurfaceSampler.js +6 -28
  128. package/examples/js/math/OBB.js +90 -49
  129. package/examples/js/math/Octree.js +2 -57
  130. package/examples/js/math/SimplexNoise.js +74 -88
  131. package/examples/js/misc/ConvexObjectBreaker.js +37 -48
  132. package/examples/js/misc/GPUComputationRenderer.js +14 -18
  133. package/examples/js/misc/Gyroscope.js +5 -9
  134. package/examples/js/misc/MD2Character.js +14 -23
  135. package/examples/js/misc/MD2CharacterComplex.js +73 -54
  136. package/examples/js/misc/MorphAnimMesh.js +0 -6
  137. package/examples/js/misc/MorphBlendMesh.js +3 -30
  138. package/examples/js/misc/ProgressiveLightMap.js +47 -43
  139. package/examples/js/misc/RollerCoaster.js +17 -24
  140. package/examples/js/misc/TubePainter.js +18 -12
  141. package/examples/js/misc/Volume.js +16 -45
  142. package/examples/js/misc/VolumeSlice.js +14 -24
  143. package/examples/js/modifiers/CurveModifier.js +19 -21
  144. package/examples/js/modifiers/EdgeSplitModifier.js +0 -30
  145. package/examples/js/modifiers/SimplifyModifier.js +56 -59
  146. package/examples/js/modifiers/TessellateModifier.js +2 -9
  147. package/examples/js/objects/GroundProjectedEnv.js +2 -14
  148. package/examples/js/objects/Lensflare.js +47 -38
  149. package/examples/js/objects/LightningStorm.js +10 -13
  150. package/examples/js/objects/MarchingCubes.js +80 -59
  151. package/examples/js/objects/Reflector.js +22 -20
  152. package/examples/js/objects/ReflectorForSSRPass.js +19 -23
  153. package/examples/js/objects/Refractor.js +52 -30
  154. package/examples/js/objects/ShadowMesh.js +1 -2
  155. package/examples/js/objects/Sky.js +2 -7
  156. package/examples/js/objects/Water.js +23 -18
  157. package/examples/js/objects/Water2.js +20 -19
  158. package/examples/js/physics/AmmoPhysics.js +23 -20
  159. package/examples/js/physics/OimoPhysics.js +19 -17
  160. package/examples/js/postprocessing/AdaptiveToneMappingPass.js +13 -20
  161. package/examples/js/postprocessing/AfterimagePass.js +19 -12
  162. package/examples/js/postprocessing/BloomPass.js +38 -17
  163. package/examples/js/postprocessing/BokehPass.js +29 -12
  164. package/examples/js/postprocessing/ClearPass.js +1 -6
  165. package/examples/js/postprocessing/CubeTexturePass.js +12 -9
  166. package/examples/js/postprocessing/DotScreenPass.js +7 -5
  167. package/examples/js/postprocessing/EffectComposer.js +25 -32
  168. package/examples/js/postprocessing/FilmPass.js +7 -5
  169. package/examples/js/postprocessing/GlitchPass.js +10 -11
  170. package/examples/js/postprocessing/HalftonePass.js +9 -9
  171. package/examples/js/postprocessing/LUTPass.js +2 -15
  172. package/examples/js/postprocessing/MaskPass.js +20 -17
  173. package/examples/js/postprocessing/OutlinePass.js +45 -36
  174. package/examples/js/postprocessing/Pass.js +11 -14
  175. package/examples/js/postprocessing/RenderPass.js +3 -7
  176. package/examples/js/postprocessing/SAOPass.js +40 -32
  177. package/examples/js/postprocessing/SMAAPass.js +34 -17
  178. package/examples/js/postprocessing/SSAARenderPass.js +14 -14
  179. package/examples/js/postprocessing/SSAOPass.js +56 -42
  180. package/examples/js/postprocessing/SSRPass.js +78 -61
  181. package/examples/js/postprocessing/SavePass.js +14 -6
  182. package/examples/js/postprocessing/ShaderPass.js +9 -8
  183. package/examples/js/postprocessing/TAARenderPass.js +11 -9
  184. package/examples/js/postprocessing/TexturePass.js +7 -4
  185. package/examples/js/postprocessing/UnrealBloomPass.js +43 -25
  186. package/examples/js/renderers/CSS2DRenderer.js +2 -21
  187. package/examples/js/renderers/CSS3DRenderer.js +3 -24
  188. package/examples/js/renderers/Projector.js +29 -85
  189. package/examples/js/renderers/SVGRenderer.js +4 -50
  190. package/examples/js/shaders/ACESFilmicToneMappingShader.js +3 -6
  191. package/examples/js/shaders/AfterimageShader.js +3 -6
  192. package/examples/js/shaders/BasicShader.js +3 -6
  193. package/examples/js/shaders/BleachBypassShader.js +3 -6
  194. package/examples/js/shaders/BlendShader.js +3 -6
  195. package/examples/js/shaders/BokehShader.js +3 -6
  196. package/examples/js/shaders/BokehShader2.js +4 -13
  197. package/examples/js/shaders/BrightnessContrastShader.js +3 -6
  198. package/examples/js/shaders/ColorCorrectionShader.js +2 -6
  199. package/examples/js/shaders/ColorifyShader.js +2 -6
  200. package/examples/js/shaders/ConvolutionShader.js +5 -10
  201. package/examples/js/shaders/CopyShader.js +3 -6
  202. package/examples/js/shaders/DOFMipMapShader.js +3 -6
  203. package/examples/js/shaders/DepthLimitedBlurShader.js +2 -9
  204. package/examples/js/shaders/DigitalGlitch.js +3 -6
  205. package/examples/js/shaders/DotScreenShader.js +2 -6
  206. package/examples/js/shaders/FXAAShader.js +1 -3
  207. package/examples/js/shaders/FilmShader.js +3 -6
  208. package/examples/js/shaders/FocusShader.js +3 -6
  209. package/examples/js/shaders/FreiChenShader.js +2 -6
  210. package/examples/js/shaders/GammaCorrectionShader.js +3 -6
  211. package/examples/js/shaders/GodRaysShader.js +11 -24
  212. package/examples/js/shaders/HalftoneShader.js +3 -6
  213. package/examples/js/shaders/HorizontalBlurShader.js +3 -6
  214. package/examples/js/shaders/HorizontalTiltShiftShader.js +3 -6
  215. package/examples/js/shaders/HueSaturationShader.js +3 -6
  216. package/examples/js/shaders/KaleidoShader.js +3 -6
  217. package/examples/js/shaders/LuminosityHighPassShader.js +2 -6
  218. package/examples/js/shaders/LuminosityShader.js +3 -6
  219. package/examples/js/shaders/MMDToonShader.js +2 -6
  220. package/examples/js/shaders/MirrorShader.js +3 -6
  221. package/examples/js/shaders/NormalMapShader.js +2 -6
  222. package/examples/js/shaders/RGBShiftShader.js +3 -6
  223. package/examples/js/shaders/SAOShader.js +2 -6
  224. package/examples/js/shaders/SMAAShader.js +6 -18
  225. package/examples/js/shaders/SSAOShader.js +2 -6
  226. package/examples/js/shaders/SSRShader.js +6 -18
  227. package/examples/js/shaders/SepiaShader.js +3 -6
  228. package/examples/js/shaders/SobelOperatorShader.js +2 -6
  229. package/examples/js/shaders/TechnicolorShader.js +3 -6
  230. package/examples/js/shaders/ToneMapShader.js +3 -6
  231. package/examples/js/shaders/ToonShader.js +8 -24
  232. package/examples/js/shaders/TriangleBlurShader.js +2 -6
  233. package/examples/js/shaders/UnpackDepthRGBAShader.js +3 -6
  234. package/examples/js/shaders/VelocityShader.js +126 -0
  235. package/examples/js/shaders/VerticalBlurShader.js +3 -6
  236. package/examples/js/shaders/VerticalTiltShiftShader.js +3 -6
  237. package/examples/js/shaders/VignetteShader.js +3 -6
  238. package/examples/js/shaders/VolumeShader.js +2 -6
  239. package/examples/js/shaders/WaterRefractionShader.js +2 -6
  240. package/examples/js/textures/FlakesTexture.js +0 -1
  241. package/examples/js/utils/BufferGeometryUtils.js +234 -168
  242. package/examples/js/utils/CameraUtils.js +5 -20
  243. package/examples/js/utils/GPUStatsPanel.js +3 -12
  244. package/examples/js/utils/GeometryCompressionUtils.js +19 -44
  245. package/examples/js/utils/GeometryUtils.js +13 -18
  246. package/examples/js/utils/LDrawUtils.js +8 -11
  247. package/examples/js/utils/PackedPhongMaterial.js +6 -4
  248. package/examples/js/utils/SceneUtils.js +117 -6
  249. package/examples/js/utils/ShadowMapViewer.js +17 -14
  250. package/examples/js/utils/SkeletonUtils.js +13 -27
  251. package/examples/js/utils/UVsDebug.js +20 -12
  252. package/examples/js/utils/WorkerPool.js +1 -11
  253. package/examples/jsm/animation/CCDIKSolver.js +1 -1
  254. package/examples/jsm/capabilities/WebGPU.js +3 -1
  255. package/examples/jsm/controls/OrbitControls.js +44 -4
  256. package/examples/jsm/exporters/GLTFExporter.js +17 -131
  257. package/examples/jsm/exporters/USDZExporter.js +75 -19
  258. package/examples/jsm/interactive/HTMLMesh.js +2 -0
  259. package/examples/jsm/libs/lottie_canvas.module.js +14844 -0
  260. package/examples/jsm/loaders/3DMLoader.js +1 -2
  261. package/examples/jsm/loaders/ColladaLoader.js +28 -0
  262. package/examples/jsm/loaders/FBXLoader.js +16 -2
  263. package/examples/jsm/loaders/GLTFLoader.js +204 -377
  264. package/examples/jsm/loaders/KTX2Loader.js +68 -29
  265. package/examples/jsm/loaders/LDrawLoader.js +14 -13
  266. package/examples/jsm/loaders/LottieLoader.js +4 -2
  267. package/examples/jsm/loaders/MaterialXLoader.js +728 -0
  268. package/examples/jsm/loaders/PCDLoader.js +1 -1
  269. package/examples/jsm/loaders/PLYLoader.js +68 -16
  270. package/examples/jsm/loaders/SVGLoader.js +227 -14
  271. package/examples/jsm/loaders/USDZLoader.js +31 -16
  272. package/examples/jsm/nodes/Nodes.js +14 -2
  273. package/examples/jsm/nodes/accessors/Object3DNode.js +1 -1
  274. package/examples/jsm/nodes/accessors/PositionNode.js +6 -0
  275. package/examples/jsm/nodes/accessors/ReferenceNode.js +1 -1
  276. package/examples/jsm/nodes/accessors/SkinningNode.js +1 -1
  277. package/examples/jsm/nodes/core/Node.js +1 -1
  278. package/examples/jsm/nodes/core/NodeBuilder.js +36 -4
  279. package/examples/jsm/nodes/core/NodeFrame.js +2 -2
  280. package/examples/jsm/nodes/core/NodeVarying.js +7 -4
  281. package/examples/jsm/nodes/core/VaryingNode.js +6 -4
  282. package/examples/jsm/nodes/core/constants.js +13 -13
  283. package/examples/jsm/nodes/display/PosterizeNode.js +25 -0
  284. package/examples/jsm/nodes/display/ViewportNode.js +106 -0
  285. package/examples/jsm/nodes/gpgpu/ComputeNode.js +1 -1
  286. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +1 -1
  287. package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +3 -1
  288. package/examples/jsm/nodes/materials/Materials.js +9 -7
  289. package/examples/jsm/nodes/materials/NodeMaterial.js +9 -1
  290. package/examples/jsm/nodes/materialx/MaterialXNodes.js +6 -2
  291. package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +18 -0
  292. package/examples/jsm/nodes/math/MathNode.js +5 -0
  293. package/examples/jsm/nodes/math/OperatorNode.js +6 -1
  294. package/examples/jsm/nodes/shadernode/ShaderNode.js +26 -13
  295. package/examples/jsm/nodes/shadernode/ShaderNodeBaseElements.js +2 -0
  296. package/examples/jsm/nodes/shadernode/ShaderNodeElements.js +18 -0
  297. package/examples/jsm/nodes/utils/EquirectUVNode.js +27 -0
  298. package/examples/jsm/nodes/utils/JoinNode.js +8 -2
  299. package/examples/jsm/nodes/utils/MatcapUVNode.js +2 -4
  300. package/examples/jsm/nodes/utils/MaxMipLevelNode.js +1 -1
  301. package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +8 -10
  302. package/examples/jsm/nodes/utils/TimerNode.js +1 -1
  303. package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +51 -0
  304. package/examples/jsm/postprocessing/AfterimagePass.js +17 -4
  305. package/examples/jsm/postprocessing/BloomPass.js +22 -3
  306. package/examples/jsm/postprocessing/BokehPass.js +18 -4
  307. package/examples/jsm/postprocessing/CubeTexturePass.js +12 -5
  308. package/examples/jsm/postprocessing/DotScreenPass.js +8 -0
  309. package/examples/jsm/postprocessing/EffectComposer.js +9 -0
  310. package/examples/jsm/postprocessing/FilmPass.js +8 -0
  311. package/examples/jsm/postprocessing/GlitchPass.js +13 -1
  312. package/examples/jsm/postprocessing/HalftonePass.js +8 -0
  313. package/examples/jsm/postprocessing/OutlinePass.js +10 -0
  314. package/examples/jsm/postprocessing/Pass.js +2 -0
  315. package/examples/jsm/postprocessing/RenderPixelatedPass.js +234 -0
  316. package/examples/jsm/postprocessing/SAOPass.js +20 -0
  317. package/examples/jsm/postprocessing/SMAAPass.js +16 -0
  318. package/examples/jsm/postprocessing/SSAARenderPass.js +4 -0
  319. package/examples/jsm/postprocessing/SavePass.js +17 -1
  320. package/examples/jsm/postprocessing/ShaderPass.js +8 -0
  321. package/examples/jsm/postprocessing/TAARenderPass.js +9 -0
  322. package/examples/jsm/postprocessing/TexturePass.js +8 -0
  323. package/examples/jsm/postprocessing/UnrealBloomPass.js +16 -0
  324. package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +39 -16
  325. package/examples/jsm/renderers/webgpu/WebGPUAnimation.js +58 -0
  326. package/examples/jsm/renderers/webgpu/WebGPUAttributes.js +63 -5
  327. package/examples/jsm/renderers/webgpu/WebGPUBackground.js +36 -7
  328. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +47 -12
  329. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js +35 -5
  330. package/examples/jsm/shaders/MMDToonShader.js +0 -2
  331. package/examples/jsm/shaders/VelocityShader.js +128 -0
  332. package/examples/jsm/utils/BufferGeometryUtils.js +130 -6
  333. package/examples/jsm/utils/SceneUtils.js +129 -4
  334. package/examples/jsm/utils/TextureUtils.js +85 -0
  335. package/examples/jsm/webxr/OculusHandModel.js +1 -1
  336. package/examples/jsm/webxr/XRHandMeshModel.js +6 -3
  337. package/package.json +11 -12
  338. package/src/Three.js +1 -0
  339. package/src/audio/AudioContext.js +5 -5
  340. package/src/cameras/CubeCamera.js +14 -14
  341. package/src/constants.js +1 -1
  342. package/src/core/InstancedBufferGeometry.js +1 -7
  343. package/src/extras/Earcut.js +67 -67
  344. package/src/helpers/DirectionalLightHelper.js +5 -1
  345. package/src/helpers/HemisphereLightHelper.js +4 -1
  346. package/src/helpers/PointLightHelper.js +2 -1
  347. package/src/helpers/SpotLightHelper.js +4 -2
  348. package/src/lights/PointLight.js +2 -2
  349. package/src/lights/SpotLight.js +2 -2
  350. package/src/loaders/FileLoader.js +4 -1
  351. package/src/loaders/ObjectLoader.js +5 -1
  352. package/src/materials/Material.js +1 -1
  353. package/src/math/Color.js +5 -5
  354. package/src/math/Matrix3.js +53 -18
  355. package/src/math/Ray.js +2 -5
  356. package/src/math/Sphere.js +19 -26
  357. package/src/objects/InstancedMesh.js +7 -0
  358. package/src/objects/LOD.js +25 -6
  359. package/src/renderers/WebGL3DRenderTarget.js +1 -1
  360. package/src/renderers/WebGLArrayRenderTarget.js +1 -1
  361. package/src/renderers/WebGLCubeRenderTarget.js +1 -1
  362. package/src/renderers/WebGLMultipleRenderTargets.js +1 -1
  363. package/src/renderers/WebGLRenderTarget.js +1 -1
  364. package/src/renderers/WebGLRenderer.js +36 -62
  365. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +0 -4
  366. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +0 -1
  367. package/src/renderers/shaders/ShaderChunk/lights_lambert_pars_fragment.glsl.js +0 -2
  368. package/src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl.js +0 -2
  369. package/src/renderers/shaders/ShaderChunk/lights_toon_pars_fragment.glsl.js +0 -2
  370. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +8 -0
  371. package/src/renderers/shaders/ShaderChunk.js +3 -0
  372. package/src/renderers/shaders/ShaderLib/background.glsl.js +7 -2
  373. package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +62 -0
  374. package/src/renderers/shaders/ShaderLib/cube.glsl.js +4 -6
  375. package/src/renderers/shaders/ShaderLib.js +20 -6
  376. package/src/renderers/shaders/UniformsLib.js +1 -1
  377. package/src/renderers/shaders/UniformsUtils.js +15 -0
  378. package/src/renderers/webgl/WebGLAttributes.js +2 -0
  379. package/src/renderers/webgl/WebGLBackground.js +15 -7
  380. package/src/renderers/webgl/WebGLLights.js +0 -4
  381. package/src/renderers/webgl/WebGLMaterials.js +2 -1
  382. package/src/renderers/webgl/WebGLShadowMap.js +3 -1
  383. package/src/renderers/webgl/WebGLState.js +31 -1
  384. package/src/renderers/webgl/WebGLTextures.js +71 -18
  385. package/src/renderers/webgl/WebGLUniforms.js +116 -20
  386. package/src/renderers/webgl/WebGLUtils.js +1 -1
  387. package/src/renderers/webxr/WebXRController.js +46 -13
  388. package/src/renderers/webxr/WebXRManager.js +85 -3
  389. package/src/scenes/Scene.js +8 -0
  390. package/src/textures/CompressedArrayTexture.js +18 -0
  391. package/examples/js/libs/lottie_canvas.js +0 -12751
  392. package/examples/js/shaders/PixelShader.js +0 -51
  393. package/examples/jsm/shaders/PixelShader.js +0 -44
@@ -1,8 +1,8 @@
1
1
  ( function () {
2
2
 
3
3
  // https://cs.nyu.edu/~perlin/noise/
4
- const _p = [ 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180 ];
5
4
 
5
+ const _p = [ 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180 ];
6
6
  for ( let i = 0; i < 256; i ++ ) {
7
7
 
8
8
  _p[ 256 + i ] = _p[ i ];
@@ -13,7 +13,6 @@
13
13
  this.setColorMap( colormap, count );
14
14
 
15
15
  }
16
-
17
16
  set( value ) {
18
17
 
19
18
  if ( value.isLut === true ) {
@@ -25,21 +24,18 @@
25
24
  return this;
26
25
 
27
26
  }
28
-
29
27
  setMin( min ) {
30
28
 
31
29
  this.minV = min;
32
30
  return this;
33
31
 
34
32
  }
35
-
36
33
  setMax( max ) {
37
34
 
38
35
  this.maxV = max;
39
36
  return this;
40
37
 
41
38
  }
42
-
43
39
  setColorMap( colormap, count = 32 ) {
44
40
 
45
41
  this.map = ColorMapKeywords[ colormap ] || ColorMapKeywords.rainbow;
@@ -47,14 +43,17 @@
47
43
  const step = 1.0 / this.n;
48
44
  const minColor = new THREE.Color();
49
45
  const maxColor = new THREE.Color();
50
- this.lut.length = 0; // sample at 0
46
+ this.lut.length = 0;
51
47
 
52
- this.lut.push( new THREE.Color( this.map[ 0 ][ 1 ] ) ); // sample at 1/n, ..., (n-1)/n
48
+ // sample at 0
49
+
50
+ this.lut.push( new THREE.Color( this.map[ 0 ][ 1 ] ) );
51
+
52
+ // sample at 1/n, ..., (n-1)/n
53
53
 
54
54
  for ( let i = 1; i < count; i ++ ) {
55
55
 
56
56
  const alpha = i * step;
57
-
58
57
  for ( let j = 0; j < this.map.length - 1; j ++ ) {
59
58
 
60
59
  if ( alpha > this.map[ j ][ 0 ] && alpha <= this.map[ j + 1 ][ 0 ] ) {
@@ -70,14 +69,14 @@
70
69
 
71
70
  }
72
71
 
73
- } // sample at 1
72
+ }
74
73
 
74
+ // sample at 1
75
75
 
76
76
  this.lut.push( new THREE.Color( this.map[ this.map.length - 1 ][ 1 ] ) );
77
77
  return this;
78
78
 
79
79
  }
80
-
81
80
  copy( lut ) {
82
81
 
83
82
  this.lut = lut.lut;
@@ -88,7 +87,6 @@
88
87
  return this;
89
88
 
90
89
  }
91
-
92
90
  getColor( alpha ) {
93
91
 
94
92
  alpha = THREE.MathUtils.clamp( alpha, this.minV, this.maxV );
@@ -97,14 +95,12 @@
97
95
  return this.lut[ colorPosition ];
98
96
 
99
97
  }
100
-
101
98
  addColorMap( name, arrayOfColors ) {
102
99
 
103
100
  ColorMapKeywords[ name ] = arrayOfColors;
104
101
  return this;
105
102
 
106
103
  }
107
-
108
104
  createCanvas() {
109
105
 
110
106
  const canvas = document.createElement( 'canvas' );
@@ -114,7 +110,6 @@
114
110
  return canvas;
115
111
 
116
112
  }
117
-
118
113
  updateCanvas( canvas ) {
119
114
 
120
115
  const ctx = canvas.getContext( '2d', {
@@ -127,7 +122,6 @@
127
122
  const minColor = new THREE.Color();
128
123
  const maxColor = new THREE.Color();
129
124
  const finalColor = new THREE.Color();
130
-
131
125
  for ( let i = 1; i >= 0; i -= step ) {
132
126
 
133
127
  for ( let j = this.map.length - 1; j >= 0; j -- ) {
@@ -157,7 +151,6 @@
157
151
  }
158
152
 
159
153
  }
160
-
161
154
  const ColorMapKeywords = {
162
155
  'rainbow': [[ 0.0, 0x0000FF ], [ 0.2, 0x00FFFF ], [ 0.5, 0x00FF00 ], [ 0.8, 0xFFFF00 ], [ 1.0, 0xFF0000 ]],
163
156
  'cooltowarm': [[ 0.0, 0x3C4EC2 ], [ 0.2, 0x9BBCFF ], [ 0.5, 0xDCDCDC ], [ 0.8, 0xF6A385 ], [ 1.0, 0xB40426 ]],
@@ -12,15 +12,12 @@
12
12
  */
13
13
 
14
14
  const _face = new THREE.Triangle();
15
-
16
15
  const _color = new THREE.Vector3();
17
-
18
16
  class MeshSurfaceSampler {
19
17
 
20
18
  constructor( mesh ) {
21
19
 
22
20
  let geometry = mesh.geometry;
23
-
24
21
  if ( ! geometry.isBufferGeometry || geometry.attributes.position.itemSize !== 3 ) {
25
22
 
26
23
  throw new Error( 'THREE.MeshSurfaceSampler: Requires BufferGeometry triangle mesh.' );
@@ -42,24 +39,23 @@
42
39
  this.distribution = null;
43
40
 
44
41
  }
45
-
46
42
  setWeightAttribute( name ) {
47
43
 
48
44
  this.weightAttribute = name ? this.geometry.getAttribute( name ) : null;
49
45
  return this;
50
46
 
51
47
  }
52
-
53
48
  build() {
54
49
 
55
50
  const positionAttribute = this.positionAttribute;
56
51
  const weightAttribute = this.weightAttribute;
57
- const faceWeights = new Float32Array( positionAttribute.count / 3 ); // Accumulate weights for each mesh face.
52
+ const faceWeights = new Float32Array( positionAttribute.count / 3 );
53
+
54
+ // Accumulate weights for each mesh face.
58
55
 
59
56
  for ( let i = 0; i < positionAttribute.count; i += 3 ) {
60
57
 
61
58
  let faceWeight = 1;
62
-
63
59
  if ( weightAttribute ) {
64
60
 
65
61
  faceWeight = weightAttribute.getX( i ) + weightAttribute.getX( i + 1 ) + weightAttribute.getX( i + 2 );
@@ -67,21 +63,18 @@
67
63
  }
68
64
 
69
65
  _face.a.fromBufferAttribute( positionAttribute, i );
70
-
71
66
  _face.b.fromBufferAttribute( positionAttribute, i + 1 );
72
-
73
67
  _face.c.fromBufferAttribute( positionAttribute, i + 2 );
74
-
75
68
  faceWeight *= _face.getArea();
76
69
  faceWeights[ i / 3 ] = faceWeight;
77
70
 
78
- } // Store cumulative total face weights in an array, where weight index
79
- // corresponds to face index.
71
+ }
80
72
 
73
+ // Store cumulative total face weights in an array, where weight index
74
+ // corresponds to face index.
81
75
 
82
76
  this.distribution = new Float32Array( positionAttribute.count / 3 );
83
77
  let cumulativeTotal = 0;
84
-
85
78
  for ( let i = 0; i < faceWeights.length; i ++ ) {
86
79
 
87
80
  cumulativeTotal += faceWeights[ i ];
@@ -92,14 +85,12 @@
92
85
  return this;
93
86
 
94
87
  }
95
-
96
88
  setRandomGenerator( randomFunction ) {
97
89
 
98
90
  this.randomFunction = randomFunction;
99
91
  return this;
100
92
 
101
93
  }
102
-
103
94
  sample( targetPosition, targetNormal, targetColor ) {
104
95
 
105
96
  const cumulativeTotal = this.distribution[ this.distribution.length - 1 ];
@@ -107,18 +98,15 @@
107
98
  return this.sampleFace( faceIndex, targetPosition, targetNormal, targetColor );
108
99
 
109
100
  }
110
-
111
101
  binarySearch( x ) {
112
102
 
113
103
  const dist = this.distribution;
114
104
  let start = 0;
115
105
  let end = dist.length - 1;
116
106
  let index = - 1;
117
-
118
107
  while ( start <= end ) {
119
108
 
120
109
  const mid = Math.ceil( ( start + end ) / 2 );
121
-
122
110
  if ( mid === 0 || dist[ mid - 1 ] <= x && dist[ mid ] > x ) {
123
111
 
124
112
  index = mid;
@@ -139,12 +127,10 @@
139
127
  return index;
140
128
 
141
129
  }
142
-
143
130
  sampleFace( faceIndex, targetPosition, targetNormal, targetColor ) {
144
131
 
145
132
  let u = this.randomFunction();
146
133
  let v = this.randomFunction();
147
-
148
134
  if ( u + v > 1 ) {
149
135
 
150
136
  u = 1 - u;
@@ -153,13 +139,9 @@
153
139
  }
154
140
 
155
141
  _face.a.fromBufferAttribute( this.positionAttribute, faceIndex * 3 );
156
-
157
142
  _face.b.fromBufferAttribute( this.positionAttribute, faceIndex * 3 + 1 );
158
-
159
143
  _face.c.fromBufferAttribute( this.positionAttribute, faceIndex * 3 + 2 );
160
-
161
144
  targetPosition.set( 0, 0, 0 ).addScaledVector( _face.a, u ).addScaledVector( _face.b, v ).addScaledVector( _face.c, 1 - ( u + v ) );
162
-
163
145
  if ( targetNormal !== undefined ) {
164
146
 
165
147
  _face.getNormal( targetNormal );
@@ -169,13 +151,9 @@
169
151
  if ( targetColor !== undefined && this.colorAttribute !== undefined ) {
170
152
 
171
153
  _face.a.fromBufferAttribute( this.colorAttribute, faceIndex * 3 );
172
-
173
154
  _face.b.fromBufferAttribute( this.colorAttribute, faceIndex * 3 + 1 );
174
-
175
155
  _face.c.fromBufferAttribute( this.colorAttribute, faceIndex * 3 + 2 );
176
-
177
156
  _color.set( 0, 0, 0 ).addScaledVector( _face.a, u ).addScaledVector( _face.b, v ).addScaledVector( _face.c, 1 - ( u + v ) );
178
-
179
157
  targetColor.r = _color.x;
180
158
  targetColor.g = _color.y;
181
159
  targetColor.b = _color.z;
@@ -1,21 +1,23 @@
1
1
  ( function () {
2
2
 
3
+ // module scope helper variables
4
+
3
5
  const a = {
4
6
  c: null,
5
7
  // center
6
8
  u: [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ],
7
9
  // basis vectors
8
10
  e: [] // half width
9
-
10
11
  };
12
+
11
13
  const b = {
12
14
  c: null,
13
15
  // center
14
16
  u: [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ],
15
17
  // basis vectors
16
18
  e: [] // half width
17
-
18
19
  };
20
+
19
21
  const R = [[], [], []];
20
22
  const AbsR = [[], [], []];
21
23
  const t = [];
@@ -29,7 +31,9 @@
29
31
  const aabb = new THREE.Box3();
30
32
  const matrix = new THREE.Matrix4();
31
33
  const inverse = new THREE.Matrix4();
32
- const localRay = new THREE.Ray(); // OBB
34
+ const localRay = new THREE.Ray();
35
+
36
+ // OBB
33
37
 
34
38
  class OBB {
35
39
 
@@ -40,7 +44,6 @@
40
44
  this.rotation = rotation;
41
45
 
42
46
  }
43
-
44
47
  set( center, halfSize, rotation ) {
45
48
 
46
49
  this.center = center;
@@ -49,7 +52,6 @@
49
52
  return this;
50
53
 
51
54
  }
52
-
53
55
  copy( obb ) {
54
56
 
55
57
  this.center.copy( obb.center );
@@ -58,31 +60,32 @@
58
60
  return this;
59
61
 
60
62
  }
61
-
62
63
  clone() {
63
64
 
64
65
  return new this.constructor().copy( this );
65
66
 
66
67
  }
67
-
68
68
  getSize( result ) {
69
69
 
70
70
  return result.copy( this.halfSize ).multiplyScalar( 2 );
71
71
 
72
72
  }
73
+
73
74
  /**
74
75
  * Reference: Closest Point on OBB to Point in Real-Time Collision Detection
75
76
  * by Christer Ericson (chapter 5.1.4)
76
77
  */
77
-
78
-
79
78
  clampPoint( point, result ) {
80
79
 
81
80
  const halfSize = this.halfSize;
82
81
  v1.subVectors( point, this.center );
83
- this.rotation.extractBasis( xAxis, yAxis, zAxis ); // start at the center position of the OBB
82
+ this.rotation.extractBasis( xAxis, yAxis, zAxis );
83
+
84
+ // start at the center position of the OBB
85
+
86
+ result.copy( this.center );
84
87
 
85
- result.copy( this.center ); // project the target onto the OBB axes and walk towards that point
88
+ // project the target onto the OBB axes and walk towards that point
86
89
 
87
90
  const x = THREE.MathUtils.clamp( v1.dot( xAxis ), - halfSize.x, halfSize.x );
88
91
  result.add( xAxis.multiplyScalar( x ) );
@@ -93,40 +96,42 @@
93
96
  return result;
94
97
 
95
98
  }
96
-
97
99
  containsPoint( point ) {
98
100
 
99
101
  v1.subVectors( point, this.center );
100
- this.rotation.extractBasis( xAxis, yAxis, zAxis ); // project v1 onto each axis and check if these points lie inside the OBB
102
+ this.rotation.extractBasis( xAxis, yAxis, zAxis );
103
+
104
+ // project v1 onto each axis and check if these points lie inside the OBB
101
105
 
102
106
  return Math.abs( v1.dot( xAxis ) ) <= this.halfSize.x && Math.abs( v1.dot( yAxis ) ) <= this.halfSize.y && Math.abs( v1.dot( zAxis ) ) <= this.halfSize.z;
103
107
 
104
108
  }
105
-
106
109
  intersectsBox3( box3 ) {
107
110
 
108
111
  return this.intersectsOBB( obb.fromBox3( box3 ) );
109
112
 
110
113
  }
111
-
112
114
  intersectsSphere( sphere ) {
113
115
 
114
116
  // find the point on the OBB closest to the sphere center
115
- this.clampPoint( sphere.center, closestPoint ); // if that point is inside the sphere, the OBB and sphere intersect
117
+
118
+ this.clampPoint( sphere.center, closestPoint );
119
+
120
+ // if that point is inside the sphere, the OBB and sphere intersect
116
121
 
117
122
  return closestPoint.distanceToSquared( sphere.center ) <= sphere.radius * sphere.radius;
118
123
 
119
124
  }
125
+
120
126
  /**
121
127
  * Reference: OBB-OBB Intersection in Real-Time Collision Detection
122
128
  * by Christer Ericson (chapter 4.4.1)
123
129
  *
124
130
  */
125
-
126
-
127
131
  intersectsOBB( obb, epsilon = Number.EPSILON ) {
128
132
 
129
133
  // prepare data structures (the code uses the same nomenclature like the reference)
134
+
130
135
  a.c = this.center;
131
136
  a.e[ 0 ] = this.halfSize.x;
132
137
  a.e[ 1 ] = this.halfSize.y;
@@ -136,7 +141,9 @@
136
141
  b.e[ 0 ] = obb.halfSize.x;
137
142
  b.e[ 1 ] = obb.halfSize.y;
138
143
  b.e[ 2 ] = obb.halfSize.z;
139
- obb.rotation.extractBasis( b.u[ 0 ], b.u[ 1 ], b.u[ 2 ] ); // compute rotation matrix expressing b in a's coordinate frame
144
+ obb.rotation.extractBasis( b.u[ 0 ], b.u[ 1 ], b.u[ 2 ] );
145
+
146
+ // compute rotation matrix expressing b in a's coordinate frame
140
147
 
141
148
  for ( let i = 0; i < 3; i ++ ) {
142
149
 
@@ -146,14 +153,19 @@
146
153
 
147
154
  }
148
155
 
149
- } // compute translation vector
156
+ }
150
157
 
158
+ // compute translation vector
151
159
 
152
- v1.subVectors( b.c, a.c ); // bring translation into a's coordinate frame
160
+ v1.subVectors( b.c, a.c );
161
+
162
+ // bring translation into a's coordinate frame
153
163
 
154
164
  t[ 0 ] = v1.dot( a.u[ 0 ] );
155
165
  t[ 1 ] = v1.dot( a.u[ 1 ] );
156
- t[ 2 ] = v1.dot( a.u[ 2 ] ); // compute common subexpressions. Add in an epsilon term to
166
+ t[ 2 ] = v1.dot( a.u[ 2 ] );
167
+
168
+ // compute common subexpressions. Add in an epsilon term to
157
169
  // counteract arithmetic errors when two edges are parallel and
158
170
  // their cross product is (near) null
159
171
 
@@ -167,7 +179,9 @@
167
179
 
168
180
  }
169
181
 
170
- let ra, rb; // test axes L = A0, L = A1, L = A2
182
+ let ra, rb;
183
+
184
+ // test axes L = A0, L = A1, L = A2
171
185
 
172
186
  for ( let i = 0; i < 3; i ++ ) {
173
187
 
@@ -175,8 +189,9 @@
175
189
  rb = b.e[ 0 ] * AbsR[ i ][ 0 ] + b.e[ 1 ] * AbsR[ i ][ 1 ] + b.e[ 2 ] * AbsR[ i ][ 2 ];
176
190
  if ( Math.abs( t[ i ] ) > ra + rb ) return false;
177
191
 
178
- } // test axes L = B0, L = B1, L = B2
192
+ }
179
193
 
194
+ // test axes L = B0, L = B1, L = B2
180
195
 
181
196
  for ( let i = 0; i < 3; i ++ ) {
182
197
 
@@ -184,87 +199,118 @@
184
199
  rb = b.e[ i ];
185
200
  if ( Math.abs( t[ 0 ] * R[ 0 ][ i ] + t[ 1 ] * R[ 1 ][ i ] + t[ 2 ] * R[ 2 ][ i ] ) > ra + rb ) return false;
186
201
 
187
- } // test axis L = A0 x B0
202
+ }
188
203
 
204
+ // test axis L = A0 x B0
189
205
 
190
206
  ra = a.e[ 1 ] * AbsR[ 2 ][ 0 ] + a.e[ 2 ] * AbsR[ 1 ][ 0 ];
191
207
  rb = b.e[ 1 ] * AbsR[ 0 ][ 2 ] + b.e[ 2 ] * AbsR[ 0 ][ 1 ];
192
- if ( Math.abs( t[ 2 ] * R[ 1 ][ 0 ] - t[ 1 ] * R[ 2 ][ 0 ] ) > ra + rb ) return false; // test axis L = A0 x B1
208
+ if ( Math.abs( t[ 2 ] * R[ 1 ][ 0 ] - t[ 1 ] * R[ 2 ][ 0 ] ) > ra + rb ) return false;
209
+
210
+ // test axis L = A0 x B1
193
211
 
194
212
  ra = a.e[ 1 ] * AbsR[ 2 ][ 1 ] + a.e[ 2 ] * AbsR[ 1 ][ 1 ];
195
213
  rb = b.e[ 0 ] * AbsR[ 0 ][ 2 ] + b.e[ 2 ] * AbsR[ 0 ][ 0 ];
196
- if ( Math.abs( t[ 2 ] * R[ 1 ][ 1 ] - t[ 1 ] * R[ 2 ][ 1 ] ) > ra + rb ) return false; // test axis L = A0 x B2
214
+ if ( Math.abs( t[ 2 ] * R[ 1 ][ 1 ] - t[ 1 ] * R[ 2 ][ 1 ] ) > ra + rb ) return false;
215
+
216
+ // test axis L = A0 x B2
197
217
 
198
218
  ra = a.e[ 1 ] * AbsR[ 2 ][ 2 ] + a.e[ 2 ] * AbsR[ 1 ][ 2 ];
199
219
  rb = b.e[ 0 ] * AbsR[ 0 ][ 1 ] + b.e[ 1 ] * AbsR[ 0 ][ 0 ];
200
- if ( Math.abs( t[ 2 ] * R[ 1 ][ 2 ] - t[ 1 ] * R[ 2 ][ 2 ] ) > ra + rb ) return false; // test axis L = A1 x B0
220
+ if ( Math.abs( t[ 2 ] * R[ 1 ][ 2 ] - t[ 1 ] * R[ 2 ][ 2 ] ) > ra + rb ) return false;
221
+
222
+ // test axis L = A1 x B0
201
223
 
202
224
  ra = a.e[ 0 ] * AbsR[ 2 ][ 0 ] + a.e[ 2 ] * AbsR[ 0 ][ 0 ];
203
225
  rb = b.e[ 1 ] * AbsR[ 1 ][ 2 ] + b.e[ 2 ] * AbsR[ 1 ][ 1 ];
204
- if ( Math.abs( t[ 0 ] * R[ 2 ][ 0 ] - t[ 2 ] * R[ 0 ][ 0 ] ) > ra + rb ) return false; // test axis L = A1 x B1
226
+ if ( Math.abs( t[ 0 ] * R[ 2 ][ 0 ] - t[ 2 ] * R[ 0 ][ 0 ] ) > ra + rb ) return false;
227
+
228
+ // test axis L = A1 x B1
205
229
 
206
230
  ra = a.e[ 0 ] * AbsR[ 2 ][ 1 ] + a.e[ 2 ] * AbsR[ 0 ][ 1 ];
207
231
  rb = b.e[ 0 ] * AbsR[ 1 ][ 2 ] + b.e[ 2 ] * AbsR[ 1 ][ 0 ];
208
- if ( Math.abs( t[ 0 ] * R[ 2 ][ 1 ] - t[ 2 ] * R[ 0 ][ 1 ] ) > ra + rb ) return false; // test axis L = A1 x B2
232
+ if ( Math.abs( t[ 0 ] * R[ 2 ][ 1 ] - t[ 2 ] * R[ 0 ][ 1 ] ) > ra + rb ) return false;
233
+
234
+ // test axis L = A1 x B2
209
235
 
210
236
  ra = a.e[ 0 ] * AbsR[ 2 ][ 2 ] + a.e[ 2 ] * AbsR[ 0 ][ 2 ];
211
237
  rb = b.e[ 0 ] * AbsR[ 1 ][ 1 ] + b.e[ 1 ] * AbsR[ 1 ][ 0 ];
212
- if ( Math.abs( t[ 0 ] * R[ 2 ][ 2 ] - t[ 2 ] * R[ 0 ][ 2 ] ) > ra + rb ) return false; // test axis L = A2 x B0
238
+ if ( Math.abs( t[ 0 ] * R[ 2 ][ 2 ] - t[ 2 ] * R[ 0 ][ 2 ] ) > ra + rb ) return false;
239
+
240
+ // test axis L = A2 x B0
213
241
 
214
242
  ra = a.e[ 0 ] * AbsR[ 1 ][ 0 ] + a.e[ 1 ] * AbsR[ 0 ][ 0 ];
215
243
  rb = b.e[ 1 ] * AbsR[ 2 ][ 2 ] + b.e[ 2 ] * AbsR[ 2 ][ 1 ];
216
- if ( Math.abs( t[ 1 ] * R[ 0 ][ 0 ] - t[ 0 ] * R[ 1 ][ 0 ] ) > ra + rb ) return false; // test axis L = A2 x B1
244
+ if ( Math.abs( t[ 1 ] * R[ 0 ][ 0 ] - t[ 0 ] * R[ 1 ][ 0 ] ) > ra + rb ) return false;
245
+
246
+ // test axis L = A2 x B1
217
247
 
218
248
  ra = a.e[ 0 ] * AbsR[ 1 ][ 1 ] + a.e[ 1 ] * AbsR[ 0 ][ 1 ];
219
249
  rb = b.e[ 0 ] * AbsR[ 2 ][ 2 ] + b.e[ 2 ] * AbsR[ 2 ][ 0 ];
220
- if ( Math.abs( t[ 1 ] * R[ 0 ][ 1 ] - t[ 0 ] * R[ 1 ][ 1 ] ) > ra + rb ) return false; // test axis L = A2 x B2
250
+ if ( Math.abs( t[ 1 ] * R[ 0 ][ 1 ] - t[ 0 ] * R[ 1 ][ 1 ] ) > ra + rb ) return false;
251
+
252
+ // test axis L = A2 x B2
221
253
 
222
254
  ra = a.e[ 0 ] * AbsR[ 1 ][ 2 ] + a.e[ 1 ] * AbsR[ 0 ][ 2 ];
223
255
  rb = b.e[ 0 ] * AbsR[ 2 ][ 1 ] + b.e[ 1 ] * AbsR[ 2 ][ 0 ];
224
- if ( Math.abs( t[ 1 ] * R[ 0 ][ 2 ] - t[ 0 ] * R[ 1 ][ 2 ] ) > ra + rb ) return false; // since no separating axis is found, the OBBs must be intersecting
256
+ if ( Math.abs( t[ 1 ] * R[ 0 ][ 2 ] - t[ 0 ] * R[ 1 ][ 2 ] ) > ra + rb ) return false;
257
+
258
+ // since no separating axis is found, the OBBs must be intersecting
225
259
 
226
260
  return true;
227
261
 
228
262
  }
263
+
229
264
  /**
230
265
  * Reference: Testing Box Against Plane in Real-Time Collision Detection
231
266
  * by Christer Ericson (chapter 5.2.3)
232
267
  */
268
+ intersectsPlane( plane ) {
233
269
 
270
+ this.rotation.extractBasis( xAxis, yAxis, zAxis );
234
271
 
235
- intersectsPlane( plane ) {
272
+ // compute the projection interval radius of this OBB onto L(t) = this->center + t * p.normal;
273
+
274
+ const r = this.halfSize.x * Math.abs( plane.normal.dot( xAxis ) ) + this.halfSize.y * Math.abs( plane.normal.dot( yAxis ) ) + this.halfSize.z * Math.abs( plane.normal.dot( zAxis ) );
236
275
 
237
- this.rotation.extractBasis( xAxis, yAxis, zAxis ); // compute the projection interval radius of this OBB onto L(t) = this->center + t * p.normal;
276
+ // compute distance of the OBB's center from the plane
238
277
 
239
- const r = this.halfSize.x * Math.abs( plane.normal.dot( xAxis ) ) + this.halfSize.y * Math.abs( plane.normal.dot( yAxis ) ) + this.halfSize.z * Math.abs( plane.normal.dot( zAxis ) ); // compute distance of the OBB's center from the plane
278
+ const d = plane.normal.dot( this.center ) - plane.constant;
240
279
 
241
- const d = plane.normal.dot( this.center ) - plane.constant; // Intersection occurs when distance d falls within [-r,+r] interval
280
+ // Intersection occurs when distance d falls within [-r,+r] interval
242
281
 
243
282
  return Math.abs( d ) <= r;
244
283
 
245
284
  }
285
+
246
286
  /**
247
287
  * Performs a ray/OBB intersection test and stores the intersection point
248
288
  * to the given 3D vector. If no intersection is detected, *null* is returned.
249
289
  */
250
-
251
-
252
290
  intersectRay( ray, result ) {
253
291
 
254
292
  // the idea is to perform the intersection test in the local space
255
293
  // of the OBB.
294
+
256
295
  this.getSize( size );
257
- aabb.setFromCenterAndSize( v1.set( 0, 0, 0 ), size ); // create a 4x4 transformation matrix
296
+ aabb.setFromCenterAndSize( v1.set( 0, 0, 0 ), size );
297
+
298
+ // create a 4x4 transformation matrix
258
299
 
259
300
  matrix.setFromMatrix3( this.rotation );
260
- matrix.setPosition( this.center ); // transform ray to the local space of the OBB
301
+ matrix.setPosition( this.center );
302
+
303
+ // transform ray to the local space of the OBB
261
304
 
262
305
  inverse.copy( matrix ).invert();
263
- localRay.copy( ray ).applyMatrix4( inverse ); // perform ray <-> AABB intersection test
306
+ localRay.copy( ray ).applyMatrix4( inverse );
307
+
308
+ // perform ray <-> AABB intersection test
264
309
 
265
310
  if ( localRay.intersectBox( aabb, result ) ) {
266
311
 
267
312
  // transform the intersection point back to world space
313
+
268
314
  return result.applyMatrix4( matrix );
269
315
 
270
316
  } else {
@@ -274,18 +320,16 @@
274
320
  }
275
321
 
276
322
  }
323
+
277
324
  /**
278
325
  * Performs a ray/OBB intersection test. Returns either true or false if
279
326
  * there is a intersection or not.
280
327
  */
281
-
282
-
283
328
  intersectsRay( ray ) {
284
329
 
285
330
  return this.intersectRay( ray, v1 ) !== null;
286
331
 
287
332
  }
288
-
289
333
  fromBox3( box3 ) {
290
334
 
291
335
  box3.getCenter( this.center );
@@ -294,13 +338,11 @@
294
338
  return this;
295
339
 
296
340
  }
297
-
298
341
  equals( obb ) {
299
342
 
300
343
  return obb.center.equals( this.center ) && obb.halfSize.equals( this.halfSize ) && obb.rotation.equals( this.rotation );
301
344
 
302
345
  }
303
-
304
346
  applyMatrix4( matrix ) {
305
347
 
306
348
  const e = matrix.elements;
@@ -333,7 +375,6 @@
333
375
  }
334
376
 
335
377
  }
336
-
337
378
  const obb = new OBB();
338
379
 
339
380
  THREE.OBB = OBB;