@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
@@ -32,7 +32,6 @@
32
32
  /**
33
33
  * @param {THREE.LoadingManager} manager
34
34
  */
35
-
36
35
  class MMDLoader extends THREE.Loader {
37
36
 
38
37
  constructor( manager ) {
@@ -40,23 +39,23 @@
40
39
  super( manager );
41
40
  this.loader = new THREE.FileLoader( this.manager );
42
41
  this.parser = null; // lazy generation
43
-
44
42
  this.meshBuilder = new MeshBuilder( this.manager );
45
43
  this.animationBuilder = new AnimationBuilder();
46
44
 
47
45
  }
46
+
48
47
  /**
49
48
  * @param {string} animationPath
50
49
  * @return {MMDLoader}
51
50
  */
52
-
53
-
54
51
  setAnimationPath( animationPath ) {
55
52
 
56
53
  this.animationPath = animationPath;
57
54
  return this;
58
55
 
59
- } // Load MMD assets as Three.js Object
56
+ }
57
+
58
+ // Load MMD assets as Three.js Object
60
59
 
61
60
  /**
62
61
  * Loads Model file (.pmd or .pmx) as a THREE.SkinnedMesh.
@@ -66,14 +65,13 @@
66
65
  * @param {function} onProgress
67
66
  * @param {function} onError
68
67
  */
69
-
70
-
71
68
  load( url, onLoad, onProgress, onError ) {
72
69
 
73
- const builder = this.meshBuilder.setCrossOrigin( this.crossOrigin ); // resource path
70
+ const builder = this.meshBuilder.setCrossOrigin( this.crossOrigin );
74
71
 
75
- let resourcePath;
72
+ // resource path
76
73
 
74
+ let resourcePath;
77
75
  if ( this.resourcePath !== '' ) {
78
76
 
79
77
  resourcePath = this.resourcePath;
@@ -88,9 +86,9 @@
88
86
 
89
87
  }
90
88
 
91
- const modelExtension = this._extractExtension( url ).toLowerCase(); // Should I detect by seeing header?
92
-
89
+ const modelExtension = this._extractExtension( url ).toLowerCase();
93
90
 
91
+ // Should I detect by seeing header?
94
92
  if ( modelExtension !== 'pmd' && modelExtension !== 'pmx' ) {
95
93
 
96
94
  if ( onError ) onError( new Error( 'THREE.MMDLoader: Unknown model file extension .' + modelExtension + '.' ) );
@@ -105,6 +103,7 @@
105
103
  }, onProgress, onError );
106
104
 
107
105
  }
106
+
108
107
  /**
109
108
  * Loads Motion file(s) (.vmd) as a THREE.AnimationClip.
110
109
  * If two or more files are specified, they'll be merged.
@@ -115,8 +114,6 @@
115
114
  * @param {function} onProgress
116
115
  * @param {function} onError
117
116
  */
118
-
119
-
120
117
  loadAnimation( url, object, onLoad, onProgress, onError ) {
121
118
 
122
119
  const builder = this.animationBuilder;
@@ -127,6 +124,7 @@
127
124
  }, onProgress, onError );
128
125
 
129
126
  }
127
+
130
128
  /**
131
129
  * Loads mode file and motion file(s) as an object containing
132
130
  * a THREE.SkinnedMesh and a THREE.AnimationClip.
@@ -138,8 +136,6 @@
138
136
  * @param {function} onProgress
139
137
  * @param {function} onError
140
138
  */
141
-
142
-
143
139
  loadWithAnimation( modelUrl, vmdUrl, onLoad, onProgress, onError ) {
144
140
 
145
141
  const scope = this;
@@ -156,7 +152,9 @@
156
152
 
157
153
  }, onProgress, onError );
158
154
 
159
- } // Load MMD assets as Object data parsed by MMDParser
155
+ }
156
+
157
+ // Load MMD assets as Object data parsed by MMDParser
160
158
 
161
159
  /**
162
160
  * Loads .pmd file as an Object.
@@ -166,12 +164,9 @@
166
164
  * @param {function} onProgress
167
165
  * @param {function} onError
168
166
  */
169
-
170
-
171
167
  loadPMD( url, onLoad, onProgress, onError ) {
172
168
 
173
169
  const parser = this._getParser();
174
-
175
170
  this.loader.setMimeType( undefined ).setPath( this.path ).setResponseType( 'arraybuffer' ).setRequestHeader( this.requestHeader ).setWithCredentials( this.withCredentials ).load( url, function ( buffer ) {
176
171
 
177
172
  onLoad( parser.parsePmd( buffer, true ) );
@@ -179,6 +174,7 @@
179
174
  }, onProgress, onError );
180
175
 
181
176
  }
177
+
182
178
  /**
183
179
  * Loads .pmx file as an Object.
184
180
  *
@@ -187,12 +183,9 @@
187
183
  * @param {function} onProgress
188
184
  * @param {function} onError
189
185
  */
190
-
191
-
192
186
  loadPMX( url, onLoad, onProgress, onError ) {
193
187
 
194
188
  const parser = this._getParser();
195
-
196
189
  this.loader.setMimeType( undefined ).setPath( this.path ).setResponseType( 'arraybuffer' ).setRequestHeader( this.requestHeader ).setWithCredentials( this.withCredentials ).load( url, function ( buffer ) {
197
190
 
198
191
  onLoad( parser.parsePmx( buffer, true ) );
@@ -200,6 +193,7 @@
200
193
  }, onProgress, onError );
201
194
 
202
195
  }
196
+
203
197
  /**
204
198
  * Loads .vmd file as an Object. If two or more files are specified
205
199
  * they'll be merged.
@@ -209,18 +203,13 @@
209
203
  * @param {function} onProgress
210
204
  * @param {function} onError
211
205
  */
212
-
213
-
214
206
  loadVMD( url, onLoad, onProgress, onError ) {
215
207
 
216
208
  const urls = Array.isArray( url ) ? url : [ url ];
217
209
  const vmds = [];
218
210
  const vmdNum = urls.length;
219
-
220
211
  const parser = this._getParser();
221
-
222
212
  this.loader.setMimeType( undefined ).setPath( this.animationPath ).setResponseType( 'arraybuffer' ).setRequestHeader( this.requestHeader ).setWithCredentials( this.withCredentials );
223
-
224
213
  for ( let i = 0, il = urls.length; i < il; i ++ ) {
225
214
 
226
215
  this.loader.load( urls[ i ], function ( buffer ) {
@@ -233,6 +222,7 @@
233
222
  }
234
223
 
235
224
  }
225
+
236
226
  /**
237
227
  * Loads .vpd file as an Object.
238
228
  *
@@ -242,20 +232,18 @@
242
232
  * @param {function} onProgress
243
233
  * @param {function} onError
244
234
  */
245
-
246
-
247
235
  loadVPD( url, isUnicode, onLoad, onProgress, onError ) {
248
236
 
249
237
  const parser = this._getParser();
250
-
251
238
  this.loader.setMimeType( isUnicode ? undefined : 'text/plain; charset=shift_jis' ).setPath( this.animationPath ).setResponseType( 'text' ).setRequestHeader( this.requestHeader ).setWithCredentials( this.withCredentials ).load( url, function ( text ) {
252
239
 
253
240
  onLoad( parser.parseVpd( text, true ) );
254
241
 
255
242
  }, onProgress, onError );
256
243
 
257
- } // private methods
244
+ }
258
245
 
246
+ // private methods
259
247
 
260
248
  _extractExtension( url ) {
261
249
 
@@ -263,7 +251,6 @@
263
251
  return index < 0 ? '' : url.slice( index + 1 );
264
252
 
265
253
  }
266
-
267
254
  _getParser() {
268
255
 
269
256
  if ( this.parser === null ) {
@@ -282,21 +269,22 @@
282
269
 
283
270
  }
284
271
 
285
- } // Utilities
272
+ }
273
+
274
+ // Utilities
286
275
 
287
276
  /*
288
277
  * base64 encoded defalut toon textures toon00.bmp - toon10.bmp.
289
278
  * We don't need to request external toon image files.
290
279
  */
291
-
292
-
293
280
  const DEFAULT_TOON_TEXTURES = [ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAN0lEQVRYR+3WQREAMBACsZ5/bWiiMvgEBTt5cW37hjsBBAgQIECAwFwgyfYPCCBAgAABAgTWAh8aBHZBl14e8wAAAABJRU5ErkJggg==', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAOUlEQVRYR+3WMREAMAwDsYY/yoDI7MLwIiP40+RJklfcCCBAgAABAgTqArfb/QMCCBAgQIAAgbbAB3z/e0F3js2cAAAAAElFTkSuQmCC', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAN0lEQVRYR+3WQREAMBACsZ5/B5ilMvgEBTt5cW37hjsBBAgQIECAwFwgyfYPCCBAgAABAgTWAh81dWyx0gFwKAAAAABJRU5ErkJggg==', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAOklEQVRYR+3WoREAMAwDsWb/UQtCy9wxTOQJ/oQ8SXKKGwEECBAgQIBAXeDt7f4BAQQIECBAgEBb4AOz8Hzx7WLY4wAAAABJRU5ErkJggg==', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABPUlEQVRYR+1XwW7CMAy1+f9fZOMysSEOEweEOPRNdm3HbdOyIhAcklPrOs/PLy9RygBALxzcCDQFmgJNgaZAU6Ap0BR4PwX8gsRMVLssMRH5HcpzJEaWL7EVg9F1IHRlyqQohgVr4FGUlUcMJSjcUlDw0zvjeun70cLWmneoyf7NgBTQSniBTQQSuJAZsOnnaczjIMb5hCiuHKxokCrJfVnrctyZL0PkJAJe1HMil4nxeyi3Ypfn1kX51jpPvo/JeCNC4PhVdHdJw2XjBR8brF8PEIhNVn12AgP7uHsTBguBn53MUZCqv7Lp07Pn5k1Ro+uWmUNn7D+M57rtk7aG0Vo73xyF/fbFf0bPJjDXngnGocDTdFhygZjwUQrMNrDcmZlQT50VJ/g/UwNyHpu778+yW+/ksOz/BFo54P4AsUXMfRq7XWsAAAAASUVORK5CYII=', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACMElEQVRYR+2Xv4pTQRTGf2dubhLdICiii2KnYKHVolhauKWPoGAnNr6BD6CvIVaihYuI2i1ia0BY0MZGRHQXjZj/mSPnnskfNWiWZUlzJ5k7M2cm833nO5Mziej2DWWJRUoCpQKlAntSQCqgw39/iUWAGmh37jrRnVsKlgpiqmkoGVABA7E57fvY+pJDdgKqF6HzFCSADkDq+F6AHABtQ+UMVE5D7zXod7fFNhTEckTbj5XQgHzNN+5tQvc5NG7C6BNkp6D3EmpXHDR+dQAjFLchW3VS9rlw3JBh+B7ys5Cf9z0GW1C/7P32AyBAOAz1q4jGliIH3YPuBnSfQX4OGreTIgEYQb/pBDtPnEQ4CivXYPAWBk13oHrB54yA9QuSn2H4AcKRpEILDt0BUzj+RLR1V5EqjD66NPRBVpLcQwjHoHYJOhsQv6U4mnzmrIXJCFr4LDwm/xBUoboG9XX4cc9VKdYoSA2yk5NQLJaKDUjTBoveG3Z2TElTxwjNK4M3LEZgUdDdruvcXzKBpStgp2NPiWi3ks9ZXxIoFVi+AvHLdc9TqtjL3/aYjpPlrzOcEnK62Szhimdd7xX232zFDTgtxezOu3WNMRLjiKgjtOhHVMd1loynVHvOgjuIIJMaELEqhJAV/RCSLbWTcfPFakFgFlALTRRvx+ok6Hlp/Q+v3fmx90bMyUzaEAhmM3KvHlXTL5DxnbGf/1M8RNNACLL5MNtPxP/mypJAqcDSFfgFhpYqWUzhTEAAAAAASUVORK5CYII=', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=' ];
294
- const NON_ALPHA_CHANNEL_FORMATS = [ THREE.RGB_S3TC_DXT1_Format, THREE.RGB_PVRTC_4BPPV1_Format, THREE.RGB_PVRTC_2BPPV1_Format, THREE.RGB_ETC1_Format, THREE.RGB_ETC2_Format ]; // Builders. They build Three.js object from Object data parsed by MMDParser.
281
+ const NON_ALPHA_CHANNEL_FORMATS = [ THREE.RGB_S3TC_DXT1_Format, THREE.RGB_PVRTC_4BPPV1_Format, THREE.RGB_PVRTC_2BPPV1_Format, THREE.RGB_ETC1_Format, THREE.RGB_ETC2_Format ];
282
+
283
+ // Builders. They build Three.js object from Object data parsed by MMDParser.
295
284
 
296
285
  /**
297
286
  * @param {THREE.LoadingManager} manager
298
287
  */
299
-
300
288
  class MeshBuilder {
301
289
 
302
290
  constructor( manager ) {
@@ -306,18 +294,18 @@
306
294
  this.materialBuilder = new MaterialBuilder( manager );
307
295
 
308
296
  }
297
+
309
298
  /**
310
299
  * @param {string} crossOrigin
311
300
  * @return {MeshBuilder}
312
301
  */
313
-
314
-
315
302
  setCrossOrigin( crossOrigin ) {
316
303
 
317
304
  this.crossOrigin = crossOrigin;
318
305
  return this;
319
306
 
320
307
  }
308
+
321
309
  /**
322
310
  * @param {Object} data - parsed PMD/PMX data
323
311
  * @param {string} resourcePath
@@ -325,73 +313,82 @@
325
313
  * @param {function} onError
326
314
  * @return {SkinnedMesh}
327
315
  */
328
-
329
-
330
316
  build( data, resourcePath, onProgress, onError ) {
331
317
 
332
318
  const geometry = this.geometryBuilder.build( data );
333
319
  const material = this.materialBuilder.setCrossOrigin( this.crossOrigin ).setResourcePath( resourcePath ).build( data, geometry, onProgress, onError );
334
320
  const mesh = new THREE.SkinnedMesh( geometry, material );
335
321
  const skeleton = new THREE.Skeleton( initBones( mesh ) );
336
- mesh.bind( skeleton ); // console.log( mesh ); // for console debug
322
+ mesh.bind( skeleton );
323
+
324
+ // console.log( mesh ); // for console debug
337
325
 
338
326
  return mesh;
339
327
 
340
328
  }
341
329
 
342
- } // TODO: Try to remove this function
330
+ }
343
331
 
332
+ // TODO: Try to remove this function
344
333
 
345
334
  function initBones( mesh ) {
346
335
 
347
336
  const geometry = mesh.geometry;
348
337
  const bones = [];
349
-
350
338
  if ( geometry && geometry.bones !== undefined ) {
351
339
 
352
340
  // first, create array of 'Bone' objects from geometry data
341
+
353
342
  for ( let i = 0, il = geometry.bones.length; i < il; i ++ ) {
354
343
 
355
- const gbone = geometry.bones[ i ]; // create new 'Bone' object
344
+ const gbone = geometry.bones[ i ];
345
+
346
+ // create new 'Bone' object
356
347
 
357
348
  const bone = new THREE.Bone();
358
- bones.push( bone ); // apply values
349
+ bones.push( bone );
350
+
351
+ // apply values
359
352
 
360
353
  bone.name = gbone.name;
361
354
  bone.position.fromArray( gbone.pos );
362
355
  bone.quaternion.fromArray( gbone.rotq );
363
356
  if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
364
357
 
365
- } // second, create bone hierarchy
358
+ }
366
359
 
360
+ // second, create bone hierarchy
367
361
 
368
362
  for ( let i = 0, il = geometry.bones.length; i < il; i ++ ) {
369
363
 
370
364
  const gbone = geometry.bones[ i ];
371
-
372
365
  if ( gbone.parent !== - 1 && gbone.parent !== null && bones[ gbone.parent ] !== undefined ) {
373
366
 
374
367
  // subsequent bones in the hierarchy
368
+
375
369
  bones[ gbone.parent ].add( bones[ i ] );
376
370
 
377
371
  } else {
378
372
 
379
373
  // topmost bone, immediate child of the skinned mesh
374
+
380
375
  mesh.add( bones[ i ] );
381
376
 
382
377
  }
383
378
 
384
379
  }
385
380
 
386
- } // now the bones are part of the scene graph and children of the skinned mesh.
387
- // let's update the corresponding matrices
381
+ }
388
382
 
383
+ // now the bones are part of the scene graph and children of the skinned mesh.
384
+ // let's update the corresponding matrices
389
385
 
390
386
  mesh.updateMatrixWorld( true );
391
387
  return bones;
392
388
 
393
- } //
389
+ }
394
390
 
391
+ //
395
392
 
396
393
  class GeometryBuilder {
397
394
 
@@ -415,15 +412,17 @@
415
412
  const iks = [];
416
413
  const grants = [];
417
414
  const rigidBodies = [];
418
- const constraints = []; // for work
415
+ const constraints = [];
419
416
 
417
+ // for work
420
418
  let offset = 0;
421
- const boneTypeTable = {}; // positions, normals, uvs, skinIndices, skinWeights
419
+ const boneTypeTable = {};
420
+
421
+ // positions, normals, uvs, skinIndices, skinWeights
422
422
 
423
423
  for ( let i = 0; i < data.metadata.vertexCount; i ++ ) {
424
424
 
425
425
  const v = data.vertices[ i ];
426
-
427
426
  for ( let j = 0, jl = v.position.length; j < jl; j ++ ) {
428
427
 
429
428
  positions.push( v.position[ j ] );
@@ -454,21 +453,22 @@
454
453
 
455
454
  }
456
455
 
457
- } // indices
456
+ }
458
457
 
458
+ // indices
459
459
 
460
460
  for ( let i = 0; i < data.metadata.faceCount; i ++ ) {
461
461
 
462
462
  const face = data.faces[ i ];
463
-
464
463
  for ( let j = 0, jl = face.indices.length; j < jl; j ++ ) {
465
464
 
466
465
  indices.push( face.indices[ j ] );
467
466
 
468
467
  }
469
468
 
470
- } // groups
469
+ }
471
470
 
471
+ // groups
472
472
 
473
473
  for ( let i = 0; i < data.metadata.materialCount; i ++ ) {
474
474
 
@@ -479,14 +479,16 @@
479
479
  } );
480
480
  offset += material.faceCount;
481
481
 
482
- } // bones
482
+ }
483
483
 
484
+ // bones
484
485
 
485
486
  for ( let i = 0; i < data.metadata.rigidBodyCount; i ++ ) {
486
487
 
487
488
  const body = data.rigidBodies[ i ];
488
- let value = boneTypeTable[ body.boneIndex ]; // keeps greater number if already value is set without any special reasons
489
+ let value = boneTypeTable[ body.boneIndex ];
489
490
 
491
+ // keeps greater number if already value is set without any special reasons
490
492
  value = value === undefined ? body.type : Math.max( body.type, value );
491
493
  boneTypeTable[ body.boneIndex ] = value;
492
494
 
@@ -505,7 +507,6 @@
505
507
  scl: [ 1, 1, 1 ],
506
508
  rigidBodyType: boneTypeTable[ i ] !== undefined ? boneTypeTable[ i ] : - 1
507
509
  };
508
-
509
510
  if ( bone.parent !== - 1 ) {
510
511
 
511
512
  bone.pos[ 0 ] -= data.bones[ bone.parent ].position[ 0 ];
@@ -516,10 +517,11 @@
516
517
 
517
518
  bones.push( bone );
518
519
 
519
- } // iks
520
- // TODO: remove duplicated codes between PMD and PMX
520
+ }
521
521
 
522
+ // iks
522
523
 
524
+ // TODO: remove duplicated codes between PMD and PMX
523
525
  if ( data.metadata.format === 'pmd' ) {
524
526
 
525
527
  for ( let i = 0; i < data.metadata.ikCount; i ++ ) {
@@ -532,13 +534,11 @@
532
534
  maxAngle: ik.maxAngle * 4,
533
535
  links: []
534
536
  };
535
-
536
537
  for ( let j = 0, jl = ik.links.length; j < jl; j ++ ) {
537
538
 
538
539
  const link = {};
539
540
  link.index = ik.links[ j ].index;
540
541
  link.enabled = true;
541
-
542
542
  if ( data.bones[ link.index ].name.indexOf( 'ひざ' ) >= 0 ) {
543
543
 
544
544
  link.limitation = new THREE.Vector3( 1.0, 0.0, 0.0 );
@@ -566,19 +566,20 @@
566
566
  maxAngle: ik.maxAngle,
567
567
  links: []
568
568
  };
569
-
570
569
  for ( let j = 0, jl = ik.links.length; j < jl; j ++ ) {
571
570
 
572
571
  const link = {};
573
572
  link.index = ik.links[ j ].index;
574
573
  link.enabled = true;
575
-
576
574
  if ( ik.links[ j ].angleLimitation === 1 ) {
577
575
 
578
576
  // Revert if rotationMin/Max doesn't work well
579
577
  // link.limitation = new THREE.Vector3( 1.0, 0.0, 0.0 );
578
+
580
579
  const rotationMin = ik.links[ j ].lowerLimitationAngle;
581
- const rotationMax = ik.links[ j ].upperLimitationAngle; // Convert Left to Right coordinate by myself because
580
+ const rotationMax = ik.links[ j ].upperLimitationAngle;
581
+
582
+ // Convert Left to Right coordinate by myself because
582
583
  // MMDParser doesn't convert. It's a MMDParser's bug
583
584
 
584
585
  const tmp1 = - rotationMax[ 0 ];
@@ -596,21 +597,22 @@
596
597
 
597
598
  }
598
599
 
599
- iks.push( param ); // Save the reference even from bone data for efficiently
600
- // simulating PMX animation system
600
+ iks.push( param );
601
601
 
602
+ // Save the reference even from bone data for efficiently
603
+ // simulating PMX animation system
602
604
  bones[ i ].ik = param;
603
605
 
604
606
  }
605
607
 
606
- } // grants
608
+ }
607
609
 
610
+ // grants
608
611
 
609
612
  if ( data.metadata.format === 'pmx' ) {
610
613
 
611
614
  // bone index -> grant entry map
612
615
  const grantEntryMap = {};
613
-
614
616
  for ( let i = 0; i < data.metadata.boneCount; i ++ ) {
615
617
 
616
618
  const boneData = data.bones[ i ];
@@ -639,7 +641,9 @@
639
641
  children: [],
640
642
  param: null,
641
643
  visited: false
642
- }; // Build a tree representing grant hierarchy
644
+ };
645
+
646
+ // Build a tree representing grant hierarchy
643
647
 
644
648
  for ( const boneIndex in grantEntryMap ) {
645
649
 
@@ -648,28 +652,30 @@
648
652
  grantEntry.parent = parentGrantEntry;
649
653
  parentGrantEntry.children.push( grantEntry );
650
654
 
651
- } // Sort grant parameters from parents to children because
655
+ }
656
+
657
+ // Sort grant parameters from parents to children because
652
658
  // grant uses parent's transform that parent's grant is already applied
653
659
  // so grant should be applied in order from parents to children
654
660
 
655
-
656
661
  function traverse( entry ) {
657
662
 
658
663
  if ( entry.param ) {
659
664
 
660
- grants.push( entry.param ); // Save the reference even from bone data for efficiently
661
- // simulating PMX animation system
665
+ grants.push( entry.param );
662
666
 
667
+ // Save the reference even from bone data for efficiently
668
+ // simulating PMX animation system
663
669
  bones[ entry.param.index ].grant = entry.param;
664
670
 
665
671
  }
666
672
 
667
673
  entry.visited = true;
668
-
669
674
  for ( let i = 0, il = entry.children.length; i < il; i ++ ) {
670
675
 
671
- const child = entry.children[ i ]; // Cut off a loop if exists. (Is a grant loop invalid?)
676
+ const child = entry.children[ i ];
672
677
 
678
+ // Cut off a loop if exists. (Is a grant loop invalid?)
673
679
  if ( ! child.visited ) traverse( child );
674
680
 
675
681
  }
@@ -678,8 +684,9 @@
678
684
 
679
685
  traverse( rootEntry );
680
686
 
681
- } // morph
687
+ }
682
688
 
689
+ // morph
683
690
 
684
691
  function updateAttributes( attribute, morph, ratio ) {
685
692
 
@@ -687,7 +694,6 @@
687
694
 
688
695
  const element = morph.elements[ i ];
689
696
  let index;
690
-
691
697
  if ( data.metadata.format === 'pmd' ) {
692
698
 
693
699
  index = data.morphs[ 0 ].elements[ element.index ].index;
@@ -714,7 +720,6 @@
714
720
  };
715
721
  const attribute = new THREE.Float32BufferAttribute( data.metadata.vertexCount * 3, 3 );
716
722
  attribute.name = morph.name;
717
-
718
723
  for ( let j = 0; j < data.metadata.vertexCount * 3; j ++ ) {
719
724
 
720
725
  attribute.array[ j ] = positions[ j ];
@@ -734,16 +739,18 @@
734
739
  if ( morph.type === 0 ) {
735
740
 
736
741
  // group
742
+
737
743
  for ( let j = 0; j < morph.elementCount; j ++ ) {
738
744
 
739
745
  const morph2 = data.morphs[ morph.elements[ j ].index ];
740
746
  const ratio = morph.elements[ j ].ratio;
741
-
742
747
  if ( morph2.type === 1 ) {
743
748
 
744
749
  updateAttributes( attribute, morph2, ratio );
745
750
 
746
- } else { // TODO: implement
751
+ } else {
752
+
753
+ // TODO: implement
747
754
  }
748
755
 
749
756
  }
@@ -751,21 +758,29 @@
751
758
  } else if ( morph.type === 1 ) {
752
759
 
753
760
  // vertex
761
+
754
762
  updateAttributes( attribute, morph, 1.0 );
755
763
 
756
764
  } else if ( morph.type === 2 ) { // bone
765
+
757
766
  // TODO: implement
758
767
  } else if ( morph.type === 3 ) { // uv
768
+
759
769
  // TODO: implement
760
770
  } else if ( morph.type === 4 ) { // additional uv1
771
+
761
772
  // TODO: implement
762
773
  } else if ( morph.type === 5 ) { // additional uv2
774
+
763
775
  // TODO: implement
764
776
  } else if ( morph.type === 6 ) { // additional uv3
777
+
765
778
  // TODO: implement
766
779
  } else if ( morph.type === 7 ) { // additional uv4
780
+
767
781
  // TODO: implement
768
782
  } else if ( morph.type === 8 ) { // material
783
+
769
784
  // TODO: implement
770
785
  }
771
786
 
@@ -774,26 +789,25 @@
774
789
  morphTargets.push( params );
775
790
  morphPositions.push( attribute );
776
791
 
777
- } // rigid bodies from rigidBodies field.
792
+ }
778
793
 
794
+ // rigid bodies from rigidBodies field.
779
795
 
780
796
  for ( let i = 0; i < data.metadata.rigidBodyCount; i ++ ) {
781
797
 
782
798
  const rigidBody = data.rigidBodies[ i ];
783
799
  const params = {};
784
-
785
800
  for ( const key in rigidBody ) {
786
801
 
787
802
  params[ key ] = rigidBody[ key ];
788
803
 
789
804
  }
805
+
790
806
  /*
791
807
  * RigidBody position parameter in PMX seems global position
792
808
  * while the one in PMD seems offset from corresponding bone.
793
809
  * So unify being offset.
794
810
  */
795
-
796
-
797
811
  if ( data.metadata.format === 'pmx' ) {
798
812
 
799
813
  if ( params.boneIndex !== - 1 ) {
@@ -809,14 +823,14 @@
809
823
 
810
824
  rigidBodies.push( params );
811
825
 
812
- } // constraints from constraints field.
826
+ }
813
827
 
828
+ // constraints from constraints field.
814
829
 
815
830
  for ( let i = 0; i < data.metadata.constraintCount; i ++ ) {
816
831
 
817
832
  const constraint = data.constraints[ i ];
818
833
  const params = {};
819
-
820
834
  for ( const key in constraint ) {
821
835
 
822
836
  params[ key ] = constraint[ key ];
@@ -824,8 +838,9 @@
824
838
  }
825
839
 
826
840
  const bodyA = rigidBodies[ params.rigidBodyIndex1 ];
827
- const bodyB = rigidBodies[ params.rigidBodyIndex2 ]; // Refer to http://www20.atpages.jp/katwat/wp/?p=4135
841
+ const bodyB = rigidBodies[ params.rigidBodyIndex2 ];
828
842
 
843
+ // Refer to http://www20.atpages.jp/katwat/wp/?p=4135
829
844
  if ( bodyA.type !== 0 && bodyB.type === 2 ) {
830
845
 
831
846
  if ( bodyA.boneIndex !== - 1 && bodyB.boneIndex !== - 1 && data.bones[ bodyB.boneIndex ].parentIndex === bodyA.boneIndex ) {
@@ -838,8 +853,9 @@
838
853
 
839
854
  constraints.push( params );
840
855
 
841
- } // build THREE.BufferGeometry.
856
+ }
842
857
 
858
+ // build THREE.BufferGeometry.
843
859
 
844
860
  const geometry = new THREE.BufferGeometry();
845
861
  geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( positions, 3 ) );
@@ -848,7 +864,6 @@
848
864
  geometry.setAttribute( 'skinIndex', new THREE.Uint16BufferAttribute( skinIndices, 4 ) );
849
865
  geometry.setAttribute( 'skinWeight', new THREE.Float32BufferAttribute( skinWeights, 4 ) );
850
866
  geometry.setIndex( indices );
851
-
852
867
  for ( let i = 0, il = groups.length; i < il; i ++ ) {
853
868
 
854
869
  geometry.addGroup( groups[ i ].offset, groups[ i ].count, i );
@@ -872,13 +887,13 @@
872
887
 
873
888
  }
874
889
 
875
- } //
890
+ }
891
+
892
+ //
876
893
 
877
894
  /**
878
895
  * @param {THREE.LoadingManager} manager
879
896
  */
880
-
881
-
882
897
  class MaterialBuilder {
883
898
 
884
899
  constructor( manager ) {
@@ -891,30 +906,29 @@
891
906
  this.resourcePath = undefined;
892
907
 
893
908
  }
909
+
894
910
  /**
895
911
  * @param {string} crossOrigin
896
912
  * @return {MaterialBuilder}
897
913
  */
898
-
899
-
900
914
  setCrossOrigin( crossOrigin ) {
901
915
 
902
916
  this.crossOrigin = crossOrigin;
903
917
  return this;
904
918
 
905
919
  }
920
+
906
921
  /**
907
922
  * @param {string} resourcePath
908
923
  * @return {MaterialBuilder}
909
924
  */
910
-
911
-
912
925
  setResourcePath( resourcePath ) {
913
926
 
914
927
  this.resourcePath = resourcePath;
915
928
  return this;
916
929
 
917
930
  }
931
+
918
932
  /**
919
933
  * @param {Object} data - parsed PMD/PMX data
920
934
  * @param {BufferGeometry} geometry - some properties are dependend on geometry
@@ -922,15 +936,13 @@
922
936
  * @param {function} onError
923
937
  * @return {Array<MMDToonMaterial>}
924
938
  */
925
-
926
-
927
- build( data, geometry
928
- /*, onProgress, onError */
929
- ) {
939
+ build( data, geometry /*, onProgress, onError */ ) {
930
940
 
931
941
  const materials = [];
932
942
  const textures = {};
933
- this.textureLoader.setCrossOrigin( this.crossOrigin ); // materials
943
+ this.textureLoader.setCrossOrigin( this.crossOrigin );
944
+
945
+ // materials
934
946
 
935
947
  for ( let i = 0; i < data.metadata.materialCount; i ++ ) {
936
948
 
@@ -941,6 +953,7 @@
941
953
  }
942
954
  };
943
955
  if ( material.name !== undefined ) params.name = material.name;
956
+
944
957
  /*
945
958
  * THREE.Color
946
959
  *
@@ -951,21 +964,26 @@
951
964
  * MMDToonMaterial doesn't have ambient. Set it to emissive instead.
952
965
  * It'll be too bright if material has map texture so using coef 0.2.
953
966
  */
954
-
955
967
  params.diffuse = new THREE.Color().fromArray( material.diffuse );
956
968
  params.opacity = material.diffuse[ 3 ];
957
969
  params.specular = new THREE.Color().fromArray( material.specular );
958
970
  params.shininess = material.shininess;
959
971
  params.emissive = new THREE.Color().fromArray( material.ambient );
960
- params.transparent = params.opacity !== 1.0; //
972
+ params.transparent = params.opacity !== 1.0;
973
+
974
+ //
975
+
976
+ params.fog = true;
961
977
 
962
- params.fog = true; // blend
978
+ // blend
963
979
 
964
980
  params.blending = THREE.CustomBlending;
965
981
  params.blendSrc = THREE.SrcAlphaFactor;
966
982
  params.blendDst = THREE.OneMinusSrcAlphaFactor;
967
983
  params.blendSrcAlpha = THREE.SrcAlphaFactor;
968
- params.blendDstAlpha = THREE.DstAlphaFactor; // side
984
+ params.blendDstAlpha = THREE.DstAlphaFactor;
985
+
986
+ // side
969
987
 
970
988
  if ( data.metadata.format === 'pmx' && ( material.flag & 0x1 ) === 1 ) {
971
989
 
@@ -980,14 +998,16 @@
980
998
  if ( data.metadata.format === 'pmd' ) {
981
999
 
982
1000
  // map, envMap
1001
+
983
1002
  if ( material.fileName ) {
984
1003
 
985
1004
  const fileName = material.fileName;
986
- const fileNames = fileName.split( '*' ); // fileNames[ 0 ]: mapFileName
1005
+ const fileNames = fileName.split( '*' );
1006
+
1007
+ // fileNames[ 0 ]: mapFileName
987
1008
  // fileNames[ 1 ]: envMapFileName( optional )
988
1009
 
989
1010
  params.map = this._loadTexture( fileNames[ 0 ], textures );
990
-
991
1011
  if ( fileNames.length > 1 ) {
992
1012
 
993
1013
  const extension = fileNames[ 1 ].slice( - 4 ).toLowerCase();
@@ -996,14 +1016,17 @@
996
1016
 
997
1017
  }
998
1018
 
999
- } // gradientMap
1019
+ }
1000
1020
 
1021
+ // gradientMap
1001
1022
 
1002
1023
  const toonFileName = material.toonIndex === - 1 ? 'toon00.bmp' : data.toonTextures[ material.toonIndex ].fileName;
1003
1024
  params.gradientMap = this._loadTexture( toonFileName, textures, {
1004
1025
  isToonTexture: true,
1005
1026
  isDefaultToonTexture: this._isDefaultToonTexture( toonFileName )
1006
- } ); // parameters for OutlineEffect
1027
+ } );
1028
+
1029
+ // parameters for OutlineEffect
1007
1030
 
1008
1031
  params.userData.outlineParameters = {
1009
1032
  thickness: material.edgeFlag === 1 ? 0.003 : 0.0,
@@ -1015,29 +1038,33 @@
1015
1038
  } else {
1016
1039
 
1017
1040
  // map
1041
+
1018
1042
  if ( material.textureIndex !== - 1 ) {
1019
1043
 
1020
- params.map = this._loadTexture( data.textures[ material.textureIndex ], textures ); // Since PMX spec don't have standard to list map files except color map and env map,
1044
+ params.map = this._loadTexture( data.textures[ material.textureIndex ], textures );
1045
+
1046
+ // Since PMX spec don't have standard to list map files except color map and env map,
1021
1047
  // we need to save file name for further mapping, like matching normal map file names after model loaded.
1022
1048
  // ref: https://gist.github.com/felixjones/f8a06bd48f9da9a4539f#texture
1023
-
1024
1049
  params.userData.MMD.mapFileName = data.textures[ material.textureIndex ];
1025
1050
 
1026
- } // envMap TODO: support m.envFlag === 3
1051
+ }
1027
1052
 
1053
+ // envMap TODO: support m.envFlag === 3
1028
1054
 
1029
1055
  if ( material.envTextureIndex !== - 1 && ( material.envFlag === 1 || material.envFlag == 2 ) ) {
1030
1056
 
1031
- params.matcap = this._loadTexture( data.textures[ material.envTextureIndex ], textures ); // Same as color map above, keep file name in userData for further usage.
1057
+ params.matcap = this._loadTexture( data.textures[ material.envTextureIndex ], textures );
1032
1058
 
1059
+ // Same as color map above, keep file name in userData for further usage.
1033
1060
  params.userData.MMD.matcapFileName = data.textures[ material.envTextureIndex ];
1034
1061
  params.matcapCombine = material.envFlag === 1 ? THREE.MultiplyOperation : THREE.AddOperation;
1035
1062
 
1036
- } // gradientMap
1063
+ }
1037
1064
 
1065
+ // gradientMap
1038
1066
 
1039
1067
  let toonFileName, isDefaultToon;
1040
-
1041
1068
  if ( material.toonIndex === - 1 || material.toonFlag !== 0 ) {
1042
1069
 
1043
1070
  toonFileName = 'toon' + ( '0' + ( material.toonIndex + 1 ) ).slice( - 2 ) + '.bmp';
@@ -1053,8 +1080,9 @@
1053
1080
  params.gradientMap = this._loadTexture( toonFileName, textures, {
1054
1081
  isToonTexture: true,
1055
1082
  isDefaultToonTexture: isDefaultToon
1056
- } ); // parameters for OutlineEffect
1083
+ } );
1057
1084
 
1085
+ // parameters for OutlineEffect
1058
1086
  params.userData.outlineParameters = {
1059
1087
  thickness: material.edgeSize / 300,
1060
1088
  // TODO: better calculation?
@@ -1084,6 +1112,7 @@
1084
1112
  if ( data.metadata.format === 'pmx' ) {
1085
1113
 
1086
1114
  // set transparent true if alpha morph is defined.
1115
+
1087
1116
  function checkAlphaMorph( elements, materials ) {
1088
1117
 
1089
1118
  for ( let i = 0, il = elements.length; i < il; i ++ ) {
@@ -1091,7 +1120,6 @@
1091
1120
  const element = elements[ i ];
1092
1121
  if ( element.index === - 1 ) continue;
1093
1122
  const material = materials[ element.index ];
1094
-
1095
1123
  if ( material.opacity !== element.diffuse[ 3 ] ) {
1096
1124
 
1097
1125
  material.transparent = true;
@@ -1106,7 +1134,6 @@
1106
1134
 
1107
1135
  const morph = data.morphs[ i ];
1108
1136
  const elements = morph.elements;
1109
-
1110
1137
  if ( morph.type === 0 ) {
1111
1138
 
1112
1139
  for ( let j = 0, jl = elements.length; j < jl; j ++ ) {
@@ -1129,8 +1156,9 @@
1129
1156
 
1130
1157
  return materials;
1131
1158
 
1132
- } // private methods
1159
+ }
1133
1160
 
1161
+ // private methods
1134
1162
 
1135
1163
  _getTGALoader() {
1136
1164
 
@@ -1149,24 +1177,20 @@
1149
1177
  return this.tgaLoader;
1150
1178
 
1151
1179
  }
1152
-
1153
1180
  _isDefaultToonTexture( name ) {
1154
1181
 
1155
1182
  if ( name.length !== 10 ) return false;
1156
1183
  return /toon(10|0[0-9])\.bmp/.test( name );
1157
1184
 
1158
1185
  }
1159
-
1160
1186
  _loadTexture( filePath, textures, params, onProgress, onError ) {
1161
1187
 
1162
1188
  params = params || {};
1163
1189
  const scope = this;
1164
1190
  let fullPath;
1165
-
1166
1191
  if ( params.isDefaultToonTexture === true ) {
1167
1192
 
1168
1193
  let index;
1169
-
1170
1194
  try {
1171
1195
 
1172
1196
  index = parseInt( filePath.match( /toon([0-9]{2})\.bmp$/ )[ 1 ] );
@@ -1188,7 +1212,6 @@
1188
1212
 
1189
1213
  if ( textures[ fullPath ] !== undefined ) return textures[ fullPath ];
1190
1214
  let loader = this.manager.getHandler( fullPath );
1191
-
1192
1215
  if ( loader === null ) {
1193
1216
 
1194
1217
  loader = filePath.slice( - 4 ).toLowerCase() === '.tga' ? this._getTGALoader() : this.textureLoader;
@@ -1211,7 +1234,6 @@
1211
1234
  t.flipY = false;
1212
1235
  t.wrapS = THREE.RepeatWrapping;
1213
1236
  t.wrapT = THREE.RepeatWrapping;
1214
-
1215
1237
  for ( let i = 0; i < texture.readyCallbacks.length; i ++ ) {
1216
1238
 
1217
1239
  texture.readyCallbacks[ i ]( texture );
@@ -1226,7 +1248,6 @@
1226
1248
  return texture;
1227
1249
 
1228
1250
  }
1229
-
1230
1251
  _getRotatedImage( image ) {
1231
1252
 
1232
1253
  const canvas = document.createElement( 'canvas' );
@@ -1238,14 +1259,13 @@
1238
1259
  context.clearRect( 0, 0, width, height );
1239
1260
  context.translate( width / 2.0, height / 2.0 );
1240
1261
  context.rotate( 0.5 * Math.PI ); // 90.0 * Math.PI / 180.0
1241
-
1242
1262
  context.translate( - width / 2.0, - height / 2.0 );
1243
1263
  context.drawImage( image, 0, 0 );
1244
1264
  return context.getImageData( 0, 0, width, height );
1245
1265
 
1246
- } // Check if the partial image area used by the texture is transparent.
1247
-
1266
+ }
1248
1267
 
1268
+ // Check if the partial image area used by the texture is transparent.
1249
1269
  _checkImageTransparency( map, geometry, groupIndex ) {
1250
1270
 
1251
1271
  map.readyCallbacks.push( function ( texture ) {
@@ -1269,14 +1289,12 @@
1269
1289
  const data = image.data;
1270
1290
  const threshold = 253;
1271
1291
  if ( data.length / ( width * height ) !== 4 ) return false;
1272
-
1273
1292
  for ( let i = 0; i < indices.length; i += 3 ) {
1274
1293
 
1275
1294
  const centerUV = {
1276
1295
  x: 0.0,
1277
1296
  y: 0.0
1278
1297
  };
1279
-
1280
1298
  for ( let j = 0; j < 3; j ++ ) {
1281
1299
 
1282
1300
  const index = indices[ i * 3 + j ];
@@ -1299,6 +1317,7 @@
1299
1317
  return false;
1300
1318
 
1301
1319
  }
1320
+
1302
1321
  /*
1303
1322
  * This method expects
1304
1323
  * texture.flipY = false
@@ -1306,8 +1325,6 @@
1306
1325
  * texture.wrapT = THREE.RepeatWrapping
1307
1326
  * TODO: more precise
1308
1327
  */
1309
-
1310
-
1311
1328
  function getAlphaByUv( image, uv ) {
1312
1329
 
1313
1330
  const width = image.width;
@@ -1340,7 +1357,6 @@
1340
1357
 
1341
1358
  const imageData = texture.image.data !== undefined ? texture.image : createImageData( texture.image );
1342
1359
  const group = geometry.groups[ groupIndex ];
1343
-
1344
1360
  if ( detectImageTransparency( imageData, geometry.attributes.uv.array, geometry.index.array.slice( group.start, group.start + group.count ) ) ) {
1345
1361
 
1346
1362
  map.transparent = true;
@@ -1351,8 +1367,9 @@
1351
1367
 
1352
1368
  }
1353
1369
 
1354
- } //
1370
+ }
1355
1371
 
1372
+ //
1356
1373
 
1357
1374
  class AnimationBuilder {
1358
1375
 
@@ -1364,9 +1381,9 @@
1364
1381
  build( vmd, mesh ) {
1365
1382
 
1366
1383
  // combine skeletal and morph animations
1384
+
1367
1385
  const tracks = this.buildSkeletalAnimation( vmd, mesh ).tracks;
1368
1386
  const tracks2 = this.buildMorphAnimation( vmd, mesh ).tracks;
1369
-
1370
1387
  for ( let i = 0, il = tracks2.length; i < il; i ++ ) {
1371
1388
 
1372
1389
  tracks.push( tracks2[ i ] );
@@ -1376,23 +1393,19 @@
1376
1393
  return new THREE.AnimationClip( '', - 1, tracks );
1377
1394
 
1378
1395
  }
1396
+
1379
1397
  /**
1380
1398
  * @param {Object} vmd - parsed VMD data
1381
1399
  * @param {SkinnedMesh} mesh - tracks will be fitting to mesh
1382
1400
  * @return {AnimationClip}
1383
1401
  */
1384
-
1385
-
1386
1402
  buildSkeletalAnimation( vmd, mesh ) {
1387
1403
 
1388
1404
  function pushInterpolation( array, interpolation, index ) {
1389
1405
 
1390
1406
  array.push( interpolation[ index + 0 ] / 127 ); // x1
1391
-
1392
1407
  array.push( interpolation[ index + 8 ] / 127 ); // x2
1393
-
1394
1408
  array.push( interpolation[ index + 4 ] / 127 ); // y1
1395
-
1396
1409
  array.push( interpolation[ index + 12 ] / 127 ); // y2
1397
1410
 
1398
1411
  }
@@ -1401,7 +1414,6 @@
1401
1414
  const motions = {};
1402
1415
  const bones = mesh.skeleton.bones;
1403
1416
  const boneNameDictionary = {};
1404
-
1405
1417
  for ( let i = 0, il = bones.length; i < il; i ++ ) {
1406
1418
 
1407
1419
  boneNameDictionary[ bones[ i ].name ] = true;
@@ -1432,7 +1444,6 @@
1432
1444
  const pInterpolations = [];
1433
1445
  const rInterpolations = [];
1434
1446
  const basePosition = mesh.skeleton.getBoneByName( key ).position.toArray();
1435
-
1436
1447
  for ( let i = 0, il = array.length; i < il; i ++ ) {
1437
1448
 
1438
1449
  const time = array[ i ].frameNum / 30;
@@ -1440,13 +1451,9 @@
1440
1451
  const rotation = array[ i ].rotation;
1441
1452
  const interpolation = array[ i ].interpolation;
1442
1453
  times.push( time );
1443
-
1444
1454
  for ( let j = 0; j < 3; j ++ ) positions.push( basePosition[ j ] + position[ j ] );
1445
-
1446
1455
  for ( let j = 0; j < 4; j ++ ) rotations.push( rotation[ j ] );
1447
-
1448
1456
  for ( let j = 0; j < 3; j ++ ) pushInterpolation( pInterpolations, interpolation, j );
1449
-
1450
1457
  pushInterpolation( rInterpolations, interpolation, 3 );
1451
1458
 
1452
1459
  }
@@ -1460,19 +1467,17 @@
1460
1467
  return new THREE.AnimationClip( '', - 1, tracks );
1461
1468
 
1462
1469
  }
1470
+
1463
1471
  /**
1464
1472
  * @param {Object} vmd - parsed VMD data
1465
1473
  * @param {SkinnedMesh} mesh - tracks will be fitting to mesh
1466
1474
  * @return {AnimationClip}
1467
1475
  */
1468
-
1469
-
1470
1476
  buildMorphAnimation( vmd, mesh ) {
1471
1477
 
1472
1478
  const tracks = [];
1473
1479
  const morphs = {};
1474
1480
  const morphTargetDictionary = mesh.morphTargetDictionary;
1475
-
1476
1481
  for ( let i = 0; i < vmd.metadata.morphCount; i ++ ) {
1477
1482
 
1478
1483
  const morph = vmd.morphs[ i ];
@@ -1493,7 +1498,6 @@
1493
1498
  } );
1494
1499
  const times = [];
1495
1500
  const values = [];
1496
-
1497
1501
  for ( let i = 0, il = array.length; i < il; i ++ ) {
1498
1502
 
1499
1503
  times.push( array[ i ].frameNum / 30 );
@@ -1508,12 +1512,11 @@
1508
1512
  return new THREE.AnimationClip( '', - 1, tracks );
1509
1513
 
1510
1514
  }
1515
+
1511
1516
  /**
1512
1517
  * @param {Object} vmd - parsed VMD data
1513
1518
  * @return {AnimationClip}
1514
1519
  */
1515
-
1516
-
1517
1520
  buildCameraAnimation( vmd ) {
1518
1521
 
1519
1522
  function pushVector3( array, vec ) {
@@ -1536,11 +1539,8 @@
1536
1539
  function pushInterpolation( array, interpolation, index ) {
1537
1540
 
1538
1541
  array.push( interpolation[ index * 4 + 0 ] / 127 ); // x1
1539
-
1540
1542
  array.push( interpolation[ index * 4 + 1 ] / 127 ); // x2
1541
-
1542
1543
  array.push( interpolation[ index * 4 + 2 ] / 127 ); // y1
1543
-
1544
1544
  array.push( interpolation[ index * 4 + 3 ] / 127 ); // y2
1545
1545
 
1546
1546
  }
@@ -1564,7 +1564,6 @@
1564
1564
  const euler = new THREE.Euler();
1565
1565
  const position = new THREE.Vector3();
1566
1566
  const center = new THREE.Vector3();
1567
-
1568
1567
  for ( let i = 0, il = cameras.length; i < il; i ++ ) {
1569
1568
 
1570
1569
  const motion = cameras[ i ];
@@ -1585,15 +1584,15 @@
1585
1584
  pushQuaternion( quaternions, quaternion );
1586
1585
  pushVector3( positions, position );
1587
1586
  fovs.push( fov );
1588
-
1589
1587
  for ( let j = 0; j < 3; j ++ ) {
1590
1588
 
1591
1589
  pushInterpolation( cInterpolations, interpolation, j );
1592
1590
 
1593
1591
  }
1594
1592
 
1595
- pushInterpolation( qInterpolations, interpolation, 3 ); // use the same parameter for x, y, z axis.
1593
+ pushInterpolation( qInterpolations, interpolation, 3 );
1596
1594
 
1595
+ // use the same parameter for x, y, z axis.
1597
1596
  for ( let j = 0; j < 3; j ++ ) {
1598
1597
 
1599
1598
  pushInterpolation( pInterpolations, interpolation, 4 );
@@ -1604,16 +1603,18 @@
1604
1603
 
1605
1604
  }
1606
1605
 
1607
- const tracks = []; // I expect an object whose name 'target' exists under THREE.Camera
1606
+ const tracks = [];
1608
1607
 
1608
+ // I expect an object whose name 'target' exists under THREE.Camera
1609
1609
  tracks.push( this._createTrack( 'target.position', THREE.VectorKeyframeTrack, times, centers, cInterpolations ) );
1610
1610
  tracks.push( this._createTrack( '.quaternion', THREE.QuaternionKeyframeTrack, times, quaternions, qInterpolations ) );
1611
1611
  tracks.push( this._createTrack( '.position', THREE.VectorKeyframeTrack, times, positions, pInterpolations ) );
1612
1612
  tracks.push( this._createTrack( '.fov', THREE.NumberKeyframeTrack, times, fovs, fInterpolations ) );
1613
1613
  return new THREE.AnimationClip( '', - 1, tracks );
1614
1614
 
1615
- } // private method
1615
+ }
1616
1616
 
1617
+ // private method
1617
1618
 
1618
1619
  _createTrack( node, typedKeyframeTrack, times, values, interpolations ) {
1619
1620
 
@@ -1630,7 +1631,6 @@
1630
1631
  const stride = values.length / times.length;
1631
1632
  const interpolateStride = interpolations.length / times.length;
1632
1633
  let index = 1;
1633
-
1634
1634
  for ( let aheadIndex = 2, endIndex = times.length; aheadIndex < endIndex; aheadIndex ++ ) {
1635
1635
 
1636
1636
  for ( let i = 0; i < stride; i ++ ) {
@@ -1647,7 +1647,6 @@
1647
1647
  if ( aheadIndex > index ) {
1648
1648
 
1649
1649
  times[ index ] = times[ aheadIndex ];
1650
-
1651
1650
  for ( let i = 0; i < stride; i ++ ) {
1652
1651
 
1653
1652
  values[ index * stride + i ] = values[ aheadIndex * stride + i ];
@@ -1671,7 +1670,6 @@
1671
1670
  }
1672
1671
 
1673
1672
  const track = new typedKeyframeTrack( node, times, values );
1674
-
1675
1673
  track.createInterpolant = function InterpolantFactoryMethodCubicBezier( result ) {
1676
1674
 
1677
1675
  return new CubicBezierInterpolation( this.times, this.values, this.getValueSize(), result, new Float32Array( interpolations ) );
@@ -1682,8 +1680,9 @@
1682
1680
 
1683
1681
  }
1684
1682
 
1685
- } // interpolation
1683
+ }
1686
1684
 
1685
+ // interpolation
1687
1686
 
1688
1687
  class CubicBezierInterpolation extends THREE.Interpolant {
1689
1688
 
@@ -1693,7 +1692,6 @@
1693
1692
  this.interpolationParams = params;
1694
1693
 
1695
1694
  }
1696
-
1697
1695
  interpolate_( i1, t0, t, t1 ) {
1698
1696
 
1699
1697
  const result = this.resultBuffer;
@@ -1701,36 +1699,34 @@
1701
1699
  const stride = this.valueSize;
1702
1700
  const params = this.interpolationParams;
1703
1701
  const offset1 = i1 * stride;
1704
- const offset0 = offset1 - stride; // No interpolation if next key frame is in one frame in 30fps.
1702
+ const offset0 = offset1 - stride;
1703
+
1704
+ // No interpolation if next key frame is in one frame in 30fps.
1705
1705
  // This is from MMD animation spec.
1706
1706
  // '1.5' is for precision loss. times are Float32 in Three.js Animation system.
1707
-
1708
1707
  const weight1 = t1 - t0 < 1 / 30 * 1.5 ? 0.0 : ( t - t0 ) / ( t1 - t0 );
1709
-
1710
1708
  if ( stride === 4 ) {
1711
1709
 
1712
1710
  // THREE.Quaternion
1711
+
1713
1712
  const x1 = params[ i1 * 4 + 0 ];
1714
1713
  const x2 = params[ i1 * 4 + 1 ];
1715
1714
  const y1 = params[ i1 * 4 + 2 ];
1716
1715
  const y2 = params[ i1 * 4 + 3 ];
1717
-
1718
1716
  const ratio = this._calculate( x1, x2, y1, y2, weight1 );
1719
-
1720
1717
  THREE.Quaternion.slerpFlat( result, 0, values, offset0, values, offset1, ratio );
1721
1718
 
1722
1719
  } else if ( stride === 3 ) {
1723
1720
 
1724
1721
  // THREE.Vector3
1722
+
1725
1723
  for ( let i = 0; i !== stride; ++ i ) {
1726
1724
 
1727
1725
  const x1 = params[ i1 * 12 + i * 4 + 0 ];
1728
1726
  const x2 = params[ i1 * 12 + i * 4 + 1 ];
1729
1727
  const y1 = params[ i1 * 12 + i * 4 + 2 ];
1730
1728
  const y2 = params[ i1 * 12 + i * 4 + 3 ];
1731
-
1732
1729
  const ratio = this._calculate( x1, x2, y1, y2, weight1 );
1733
-
1734
1730
  result[ i ] = values[ offset0 + i ] * ( 1 - ratio ) + values[ offset1 + i ] * ratio;
1735
1731
 
1736
1732
  }
@@ -1738,13 +1734,12 @@
1738
1734
  } else {
1739
1735
 
1740
1736
  // Number
1737
+
1741
1738
  const x1 = params[ i1 * 4 + 0 ];
1742
1739
  const x2 = params[ i1 * 4 + 1 ];
1743
1740
  const y1 = params[ i1 * 4 + 2 ];
1744
1741
  const y2 = params[ i1 * 4 + 3 ];
1745
-
1746
1742
  const ratio = this._calculate( x1, x2, y1, y2, weight1 );
1747
-
1748
1743
  result[ 0 ] = values[ offset0 ] * ( 1 - ratio ) + values[ offset1 ] * ratio;
1749
1744
 
1750
1745
  }
@@ -1752,7 +1747,6 @@
1752
1747
  return result;
1753
1748
 
1754
1749
  }
1755
-
1756
1750
  _calculate( x1, x2, y1, y2, x ) {
1757
1751
 
1758
1752
  /*
@@ -1791,6 +1785,7 @@
1791
1785
  * (Another option: Newton's method
1792
1786
  * https://en.wikipedia.org/wiki/Newton%27s_method)
1793
1787
  */
1788
+
1794
1789
  let c = 0.5;
1795
1790
  let t = c;
1796
1791
  let s = 1.0 - t;
@@ -1798,7 +1793,6 @@
1798
1793
  const eps = 1e-5;
1799
1794
  const math = Math;
1800
1795
  let sst3, stt3, ttt;
1801
-
1802
1796
  for ( let i = 0; i < loop; i ++ ) {
1803
1797
 
1804
1798
  sst3 = 3.0 * s * s * t;
@@ -1817,7 +1811,6 @@
1817
1811
  }
1818
1812
 
1819
1813
  }
1820
-
1821
1814
  class MMDToonMaterial extends THREE.ShaderMaterial {
1822
1815
 
1823
1816
  constructor( parameters ) {
@@ -1844,14 +1837,12 @@
1844
1837
  set: function ( value ) {
1845
1838
 
1846
1839
  this._matcapCombine = value;
1847
-
1848
1840
  switch ( value ) {
1849
1841
 
1850
1842
  case THREE.MultiplyOperation:
1851
1843
  this.defines.MATCAP_BLENDING_MULTIPLY = true;
1852
1844
  delete this.defines.MATCAP_BLENDING_ADD;
1853
1845
  break;
1854
-
1855
1846
  default:
1856
1847
  case THREE.AddOperation:
1857
1848
  this.defines.MATCAP_BLENDING_ADD = true;
@@ -1862,10 +1853,10 @@
1862
1853
 
1863
1854
  }
1864
1855
  } );
1865
- this.uniforms = THREE.UniformsUtils.clone( THREE.MMDToonShader.uniforms ); // merged from MeshToon/Phong/MatcapMaterial
1856
+ this.uniforms = THREE.UniformsUtils.clone( THREE.MMDToonShader.uniforms );
1866
1857
 
1858
+ // merged from MeshToon/Phong/MatcapMaterial
1867
1859
  const exposePropertyNames = [ 'specular', 'opacity', 'diffuse', 'map', 'matcap', 'gradientMap', 'lightMap', 'lightMapIntensity', 'aoMap', 'aoMapIntensity', 'emissive', 'emissiveMap', 'bumpMap', 'bumpScale', 'normalMap', 'normalScale', 'displacemantBias', 'displacemantMap', 'displacemantScale', 'specularMap', 'alphaMap', 'envMap', 'reflectivity', 'refractionRatio' ];
1868
-
1869
1860
  for ( const propertyName of exposePropertyNames ) {
1870
1861
 
1871
1862
  Object.defineProperty( this, propertyName, {
@@ -1881,9 +1872,9 @@
1881
1872
  }
1882
1873
  } );
1883
1874
 
1884
- } // Special path for shininess to handle zero shininess properly
1885
-
1875
+ }
1886
1876
 
1877
+ // Special path for shininess to handle zero shininess properly
1887
1878
  this._shininess = 30;
1888
1879
  Object.defineProperty( this, 'shininess', {
1889
1880
  get: function () {
@@ -1898,11 +1889,11 @@
1898
1889
 
1899
1890
  }
1900
1891
  } );
1892
+
1901
1893
  Object.defineProperty( this, 'color', Object.getOwnPropertyDescriptor( this, 'diffuse' ) );
1902
1894
  this.setValues( parameters );
1903
1895
 
1904
1896
  }
1905
-
1906
1897
  copy( source ) {
1907
1898
 
1908
1899
  super.copy( source );