@plastic-software/three 0.167.3 → 0.174.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (748) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/build/three.cjs +36277 -24023
  4. package/build/three.core.js +48830 -0
  5. package/build/three.core.min.js +6 -0
  6. package/build/three.module.js +10175 -46743
  7. package/build/three.module.min.js +2 -2
  8. package/build/three.tsl.js +550 -0
  9. package/build/three.tsl.min.js +6 -0
  10. package/build/three.webgpu.js +44348 -50670
  11. package/build/three.webgpu.min.js +2 -2
  12. package/build/three.webgpu.nodes.js +70301 -0
  13. package/build/three.webgpu.nodes.min.js +6 -0
  14. package/examples/jsm/Addons.js +3 -15
  15. package/examples/jsm/animation/AnimationClipCreator.js +1 -1
  16. package/examples/jsm/animation/CCDIKSolver.js +61 -11
  17. package/examples/jsm/capabilities/WebGL.js +27 -21
  18. package/examples/jsm/capabilities/WebGPU.js +1 -10
  19. package/examples/jsm/controls/ArcballControls.js +262 -231
  20. package/examples/jsm/controls/DragControls.js +1 -1
  21. package/examples/jsm/controls/FirstPersonControls.js +175 -163
  22. package/examples/jsm/controls/FlyControls.js +194 -188
  23. package/examples/jsm/controls/OrbitControls.js +801 -777
  24. package/examples/jsm/controls/PointerLockControls.js +26 -20
  25. package/examples/jsm/controls/TrackballControls.js +469 -448
  26. package/examples/jsm/controls/TransformControls.js +119 -68
  27. package/examples/jsm/csm/CSM.js +2 -2
  28. package/examples/jsm/csm/CSMFrustum.js +7 -4
  29. package/examples/jsm/csm/CSMHelper.js +2 -0
  30. package/examples/jsm/csm/CSMShadowNode.js +442 -0
  31. package/examples/jsm/curves/NURBSCurve.js +33 -2
  32. package/examples/jsm/curves/NURBSUtils.js +3 -0
  33. package/examples/jsm/effects/AnaglyphEffect.js +6 -13
  34. package/examples/jsm/effects/OutlineEffect.js +1 -1
  35. package/examples/jsm/effects/ParallaxBarrierEffect.js +17 -11
  36. package/examples/jsm/effects/StereoEffect.js +6 -1
  37. package/examples/jsm/exporters/DRACOExporter.js +4 -2
  38. package/examples/jsm/exporters/EXRExporter.js +19 -11
  39. package/examples/jsm/exporters/GLTFExporter.js +181 -109
  40. package/examples/jsm/exporters/KTX2Exporter.js +54 -23
  41. package/examples/jsm/exporters/OBJExporter.js +5 -1
  42. package/examples/jsm/exporters/PLYExporter.js +11 -9
  43. package/examples/jsm/exporters/USDZExporter.js +50 -11
  44. package/examples/jsm/geometries/DecalGeometry.js +73 -21
  45. package/examples/jsm/geometries/TextGeometry.js +1 -12
  46. package/examples/jsm/helpers/LightProbeHelper.js +43 -44
  47. package/examples/jsm/helpers/LightProbeHelperGPU.js +65 -0
  48. package/examples/jsm/helpers/TextureHelperGPU.js +185 -0
  49. package/examples/jsm/helpers/VertexNormalsHelper.js +2 -0
  50. package/examples/jsm/interactive/HTMLMesh.js +1 -0
  51. package/examples/jsm/interactive/InteractiveGroup.js +108 -51
  52. package/examples/jsm/interactive/SelectionHelper.js +3 -1
  53. package/examples/jsm/libs/basis/basis_transcoder.js +8 -10
  54. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  55. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  56. package/examples/jsm/libs/ktx-parse.module.js +1 -1
  57. package/examples/jsm/lighting/TiledLighting.js +18 -0
  58. package/examples/jsm/lights/LightProbeGenerator.js +26 -12
  59. package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
  60. package/examples/jsm/lines/LineGeometry.js +25 -0
  61. package/examples/jsm/lines/LineMaterial.js +0 -1
  62. package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
  63. package/examples/jsm/lines/webgpu/Line2.js +2 -1
  64. package/examples/jsm/lines/webgpu/LineSegments2.js +16 -21
  65. package/examples/jsm/lines/webgpu/Wireframe.js +57 -0
  66. package/examples/jsm/loaders/3DMLoader.js +1 -0
  67. package/examples/jsm/loaders/3MFLoader.js +104 -2
  68. package/examples/jsm/loaders/BVHLoader.js +1 -1
  69. package/examples/jsm/loaders/ColladaLoader.js +15 -12
  70. package/examples/jsm/loaders/DDSLoader.js +42 -0
  71. package/examples/jsm/loaders/DRACOLoader.js +3 -1
  72. package/examples/jsm/loaders/FBXLoader.js +71 -22
  73. package/examples/jsm/loaders/GCodeLoader.js +4 -2
  74. package/examples/jsm/loaders/GLTFLoader.js +29 -14
  75. package/examples/jsm/loaders/KTX2Loader.js +160 -58
  76. package/examples/jsm/loaders/KTXLoader.js +4 -4
  77. package/examples/jsm/loaders/LDrawLoader.js +22 -136
  78. package/examples/jsm/loaders/LottieLoader.js +2 -1
  79. package/examples/jsm/loaders/MTLLoader.js +27 -7
  80. package/examples/jsm/loaders/MaterialXLoader.js +40 -14
  81. package/examples/jsm/loaders/NRRDLoader.js +1 -1
  82. package/examples/jsm/loaders/OBJLoader.js +5 -3
  83. package/examples/jsm/loaders/PCDLoader.js +14 -13
  84. package/examples/jsm/loaders/PDBLoader.js +3 -2
  85. package/examples/jsm/loaders/PLYLoader.js +15 -12
  86. package/examples/jsm/loaders/PVRLoader.js +1 -1
  87. package/examples/jsm/loaders/STLLoader.js +3 -2
  88. package/examples/jsm/loaders/SVGLoader.js +2 -2
  89. package/examples/jsm/loaders/TDSLoader.js +17 -18
  90. package/examples/jsm/loaders/VRMLLoader.js +17 -17
  91. package/examples/jsm/loaders/VTKLoader.js +4 -3
  92. package/examples/jsm/loaders/XYZLoader.js +3 -2
  93. package/examples/jsm/loaders/lwo/IFFParser.js +4 -4
  94. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
  95. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
  96. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
  97. package/examples/jsm/math/ColorSpaces.js +76 -0
  98. package/examples/jsm/math/ConvexHull.js +1 -1
  99. package/examples/jsm/math/OBB.js +17 -0
  100. package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
  101. package/examples/jsm/misc/ProgressiveLightMap.js +54 -41
  102. package/examples/jsm/misc/ProgressiveLightMapGPU.js +294 -0
  103. package/examples/jsm/misc/Timer.js +27 -12
  104. package/examples/jsm/misc/Volume.js +28 -18
  105. package/examples/jsm/misc/VolumeSlice.js +19 -16
  106. package/examples/jsm/modifiers/CurveModifier.js +10 -8
  107. package/examples/jsm/modifiers/CurveModifierGPU.js +235 -0
  108. package/examples/jsm/modifiers/SimplifyModifier.js +2 -2
  109. package/examples/jsm/objects/GroundedSkybox.js +4 -4
  110. package/examples/jsm/objects/LensflareMesh.js +324 -0
  111. package/examples/jsm/objects/Reflector.js +5 -2
  112. package/examples/jsm/objects/Sky.js +2 -2
  113. package/examples/jsm/objects/SkyMesh.js +14 -14
  114. package/examples/jsm/objects/Water2.js +1 -1
  115. package/examples/jsm/objects/Water2Mesh.js +11 -9
  116. package/examples/jsm/objects/WaterMesh.js +38 -33
  117. package/examples/jsm/physics/JoltPhysics.js +8 -8
  118. package/examples/jsm/physics/RapierPhysics.js +5 -5
  119. package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
  120. package/examples/jsm/postprocessing/BloomPass.js +2 -2
  121. package/examples/jsm/postprocessing/EffectComposer.js +1 -2
  122. package/examples/jsm/postprocessing/OutlinePass.js +37 -51
  123. package/examples/jsm/postprocessing/OutputPass.js +2 -0
  124. package/examples/jsm/postprocessing/SAOPass.js +1 -2
  125. package/examples/jsm/postprocessing/SMAAPass.js +1 -3
  126. package/examples/jsm/postprocessing/SSAARenderPass.js +3 -1
  127. package/examples/jsm/postprocessing/SSAOPass.js +2 -4
  128. package/examples/jsm/postprocessing/SSRPass.js +8 -4
  129. package/examples/jsm/postprocessing/UnrealBloomPass.js +2 -2
  130. package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
  131. package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
  132. package/examples/jsm/renderers/SVGRenderer.js +6 -4
  133. package/examples/jsm/shaders/BokehShader2.js +1 -1
  134. package/examples/jsm/shaders/FXAAShader.js +225 -224
  135. package/examples/jsm/shaders/GodRaysShader.js +3 -3
  136. package/examples/jsm/shaders/OutputShader.js +6 -2
  137. package/examples/jsm/shaders/SobelOperatorShader.js +1 -1
  138. package/examples/jsm/transpiler/AST.js +12 -2
  139. package/examples/jsm/transpiler/GLSLDecoder.js +77 -31
  140. package/examples/jsm/transpiler/ShaderToyDecoder.js +3 -3
  141. package/examples/jsm/transpiler/TSLEncoder.js +96 -21
  142. package/examples/jsm/tsl/display/AfterImageNode.js +243 -0
  143. package/examples/jsm/tsl/display/AnaglyphPassNode.js +106 -0
  144. package/examples/jsm/tsl/display/AnamorphicNode.js +257 -0
  145. package/{src/nodes/display/BleachBypassNode.js → examples/jsm/tsl/display/BleachBypass.js} +11 -6
  146. package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +252 -67
  147. package/examples/jsm/tsl/display/DenoiseNode.js +332 -0
  148. package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +92 -14
  149. package/examples/jsm/tsl/display/DotScreenNode.js +103 -0
  150. package/examples/jsm/tsl/display/FXAANode.js +364 -0
  151. package/examples/jsm/tsl/display/FilmNode.js +100 -0
  152. package/examples/jsm/tsl/display/GTAONode.js +521 -0
  153. package/examples/jsm/tsl/display/GaussianBlurNode.js +393 -0
  154. package/examples/jsm/tsl/display/LensflareNode.js +278 -0
  155. package/examples/jsm/tsl/display/Lut3DNode.js +108 -0
  156. package/examples/jsm/tsl/display/MotionBlur.js +33 -0
  157. package/examples/jsm/tsl/display/OutlineNode.js +750 -0
  158. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +88 -0
  159. package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +160 -28
  160. package/examples/jsm/tsl/display/RGBShiftNode.js +95 -0
  161. package/examples/jsm/tsl/display/SMAANode.js +767 -0
  162. package/examples/jsm/tsl/display/SSAAPassNode.js +357 -0
  163. package/examples/jsm/tsl/display/SSRNode.js +538 -0
  164. package/examples/jsm/tsl/display/Sepia.js +24 -0
  165. package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +66 -20
  166. package/examples/jsm/tsl/display/StereoCompositePassNode.js +184 -0
  167. package/examples/jsm/tsl/display/StereoPassNode.js +119 -0
  168. package/examples/jsm/tsl/display/TRAAPassNode.js +451 -0
  169. package/examples/jsm/tsl/display/TransitionNode.js +140 -0
  170. package/examples/jsm/tsl/display/hashBlur.js +34 -0
  171. package/examples/jsm/tsl/lighting/TiledLightsNode.js +395 -0
  172. package/examples/jsm/tsl/math/Bayer.js +18 -0
  173. package/examples/jsm/tsl/utils/Raymarching.js +65 -0
  174. package/examples/jsm/utils/BufferGeometryUtils.js +2 -2
  175. package/examples/jsm/utils/CameraUtils.js +4 -1
  176. package/examples/jsm/utils/GeometryCompressionUtils.js +38 -123
  177. package/examples/jsm/utils/GeometryUtils.js +22 -19
  178. package/examples/jsm/utils/SceneOptimizer.js +410 -0
  179. package/examples/jsm/utils/SceneUtils.js +2 -2
  180. package/examples/jsm/utils/ShadowMapViewer.js +3 -8
  181. package/examples/jsm/utils/ShadowMapViewerGPU.js +201 -0
  182. package/examples/jsm/utils/SkeletonUtils.js +84 -66
  183. package/examples/jsm/utils/UVsDebug.js +1 -1
  184. package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +1 -0
  185. package/examples/jsm/utils/WebGPUTextureUtils.js +64 -0
  186. package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
  187. package/examples/jsm/webxr/Text2D.js +6 -6
  188. package/examples/jsm/webxr/XRControllerModelFactory.js +7 -2
  189. package/examples/jsm/webxr/XREstimatedLight.js +1 -1
  190. package/package.json +14 -9
  191. package/src/Three.Core.js +182 -0
  192. package/src/Three.Legacy.js +0 -21
  193. package/src/Three.TSL.js +543 -0
  194. package/src/Three.WebGPU.Nodes.js +23 -0
  195. package/src/Three.WebGPU.js +13 -184
  196. package/src/Three.js +1 -176
  197. package/src/animation/AnimationClip.js +2 -2
  198. package/src/animation/AnimationObjectGroup.js +2 -2
  199. package/src/animation/AnimationUtils.js +1 -1
  200. package/src/animation/PropertyBinding.js +2 -2
  201. package/src/audio/Audio.js +379 -2
  202. package/src/audio/AudioAnalyser.js +58 -1
  203. package/src/audio/AudioContext.js +15 -0
  204. package/src/audio/AudioListener.js +76 -0
  205. package/src/audio/PositionalAudio.js +107 -0
  206. package/src/cameras/ArrayCamera.js +29 -0
  207. package/src/cameras/Camera.js +47 -0
  208. package/src/cameras/CubeCamera.js +66 -0
  209. package/src/cameras/OrthographicCamera.js +109 -0
  210. package/src/cameras/PerspectiveCamera.js +173 -34
  211. package/src/cameras/StereoCamera.js +48 -2
  212. package/src/constants.js +6 -6
  213. package/src/core/BufferAttribute.js +4 -9
  214. package/src/core/BufferGeometry.js +48 -8
  215. package/src/core/Clock.js +1 -1
  216. package/src/core/EventDispatcher.js +52 -8
  217. package/src/core/InterleavedBuffer.js +4 -13
  218. package/src/core/Object3D.js +573 -3
  219. package/src/core/RenderTarget.js +22 -4
  220. package/src/core/RenderTarget3D.js +22 -0
  221. package/src/core/RenderTargetArray.js +22 -0
  222. package/src/extras/Controls.js +104 -0
  223. package/src/extras/DataUtils.js +48 -8
  224. package/src/extras/Earcut.js +18 -7
  225. package/src/extras/ImageUtils.js +18 -11
  226. package/src/extras/PMREMGenerator.js +40 -9
  227. package/src/extras/ShapeUtils.js +24 -2
  228. package/src/extras/TextureUtils.js +96 -10
  229. package/src/extras/core/Curve.js +153 -53
  230. package/src/extras/core/CurvePath.js +63 -22
  231. package/src/extras/core/Interpolations.js +29 -3
  232. package/src/extras/core/Path.js +134 -1
  233. package/src/extras/core/Shape.js +66 -3
  234. package/src/extras/core/ShapePath.js +76 -0
  235. package/src/extras/curves/ArcCurve.js +22 -0
  236. package/src/extras/curves/CatmullRomCurve3.js +89 -18
  237. package/src/extras/curves/CubicBezierCurve.js +67 -0
  238. package/src/extras/curves/CubicBezierCurve3.js +50 -0
  239. package/src/extras/curves/EllipseCurve.js +102 -0
  240. package/src/extras/curves/LineCurve.js +36 -0
  241. package/src/extras/curves/LineCurve3.js +36 -0
  242. package/src/extras/curves/QuadraticBezierCurve.js +59 -0
  243. package/src/extras/curves/QuadraticBezierCurve3.js +43 -0
  244. package/src/extras/curves/SplineCurve.js +48 -0
  245. package/src/geometries/BoxGeometry.js +38 -0
  246. package/src/geometries/CapsuleGeometry.js +34 -0
  247. package/src/geometries/CircleGeometry.js +40 -0
  248. package/src/geometries/ConeGeometry.js +38 -0
  249. package/src/geometries/CylinderGeometry.js +50 -4
  250. package/src/geometries/DodecahedronGeometry.js +32 -0
  251. package/src/geometries/EdgesGeometry.js +30 -2
  252. package/src/geometries/ExtrudeGeometry.js +52 -0
  253. package/src/geometries/IcosahedronGeometry.js +32 -0
  254. package/src/geometries/LatheGeometry.js +43 -3
  255. package/src/geometries/OctahedronGeometry.js +32 -0
  256. package/src/geometries/PlaneGeometry.js +34 -0
  257. package/src/geometries/PolyhedronGeometry.js +29 -0
  258. package/src/geometries/RingGeometry.js +36 -0
  259. package/src/geometries/ShapeGeometry.js +37 -0
  260. package/src/geometries/SphereGeometry.js +37 -0
  261. package/src/geometries/TetrahedronGeometry.js +32 -0
  262. package/src/geometries/TorusGeometry.js +35 -0
  263. package/src/geometries/TorusKnotGeometry.js +38 -0
  264. package/src/geometries/TubeGeometry.js +49 -0
  265. package/src/geometries/WireframeGeometry.js +32 -0
  266. package/src/helpers/ArrowHelper.js +60 -3
  267. package/src/helpers/AxesHelper.js +28 -0
  268. package/src/helpers/Box3Helper.js +28 -0
  269. package/src/helpers/BoxHelper.js +43 -7
  270. package/src/helpers/CameraHelper.js +61 -18
  271. package/src/helpers/DirectionalLightHelper.js +52 -0
  272. package/src/helpers/GridHelper.js +26 -0
  273. package/src/helpers/HemisphereLightHelper.js +39 -0
  274. package/src/helpers/PlaneHelper.js +33 -0
  275. package/src/helpers/PointLightHelper.js +43 -0
  276. package/src/helpers/PolarGridHelper.js +30 -0
  277. package/src/helpers/SkeletonHelper.js +39 -2
  278. package/src/helpers/SpotLightHelper.js +40 -0
  279. package/src/lights/AmbientLight.js +25 -0
  280. package/src/lights/DirectionalLight.js +57 -0
  281. package/src/lights/DirectionalLightShadow.js +15 -0
  282. package/src/lights/HemisphereLight.js +32 -0
  283. package/src/lights/Light.js +36 -0
  284. package/src/lights/LightProbe.js +43 -0
  285. package/src/lights/LightShadow.js +159 -0
  286. package/src/lights/PointLight.js +59 -0
  287. package/src/lights/PointLightShadow.js +21 -0
  288. package/src/lights/RectAreaLight.js +59 -0
  289. package/src/lights/SpotLight.js +102 -0
  290. package/src/lights/SpotLightShadow.js +24 -2
  291. package/src/lights/webgpu/IESSpotLight.js +21 -0
  292. package/src/loaders/Loader.js +132 -0
  293. package/src/loaders/MaterialLoader.js +7 -1
  294. package/src/loaders/nodes/NodeLoader.js +189 -0
  295. package/src/loaders/nodes/NodeMaterialLoader.js +108 -0
  296. package/src/loaders/nodes/NodeObjectLoader.js +151 -0
  297. package/src/materials/LineDashedMaterial.js +0 -1
  298. package/src/materials/Material.js +469 -7
  299. package/src/materials/MeshPhongMaterial.js +1 -1
  300. package/src/materials/MeshPhysicalMaterial.js +2 -2
  301. package/src/materials/MeshStandardMaterial.js +2 -2
  302. package/src/{nodes/materials → materials/nodes}/Line2NodeMaterial.js +192 -82
  303. package/src/materials/nodes/LineBasicNodeMaterial.js +46 -0
  304. package/src/materials/nodes/LineDashedNodeMaterial.js +132 -0
  305. package/src/materials/nodes/MeshBasicNodeMaterial.js +133 -0
  306. package/src/materials/nodes/MeshLambertNodeMaterial.js +82 -0
  307. package/src/materials/nodes/MeshMatcapNodeMaterial.js +77 -0
  308. package/src/materials/nodes/MeshNormalNodeMaterial.js +67 -0
  309. package/src/materials/nodes/MeshPhongNodeMaterial.js +141 -0
  310. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +517 -0
  311. package/src/materials/nodes/MeshSSSNodeMaterial.js +175 -0
  312. package/src/materials/nodes/MeshStandardNodeMaterial.js +186 -0
  313. package/src/materials/nodes/MeshToonNodeMaterial.js +66 -0
  314. package/src/materials/nodes/NodeMaterial.js +1180 -0
  315. package/src/{nodes/materials/Materials.js → materials/nodes/NodeMaterials.js} +3 -2
  316. package/src/materials/nodes/PointsNodeMaterial.js +153 -0
  317. package/src/materials/nodes/ShadowNodeMaterial.js +67 -0
  318. package/src/materials/nodes/SpriteNodeMaterial.js +198 -0
  319. package/src/materials/nodes/VolumeNodeMaterial.js +72 -0
  320. package/src/materials/nodes/manager/NodeMaterialObserver.js +509 -0
  321. package/src/math/Box2.js +177 -0
  322. package/src/math/Box3.js +243 -0
  323. package/src/math/Color.js +343 -0
  324. package/src/math/ColorManagement.js +143 -102
  325. package/src/math/Cylindrical.js +65 -6
  326. package/src/math/Euler.js +137 -4
  327. package/src/math/Frustum.js +83 -0
  328. package/src/math/Interpolant.js +87 -8
  329. package/src/math/Line3.js +96 -2
  330. package/src/math/MathUtils.js +182 -19
  331. package/src/math/Matrix2.js +70 -0
  332. package/src/math/Matrix3.js +229 -4
  333. package/src/math/Matrix4.js +368 -3
  334. package/src/math/Plane.js +164 -2
  335. package/src/math/Quaternion.js +265 -9
  336. package/src/math/Ray.js +160 -0
  337. package/src/math/Sphere.js +147 -0
  338. package/src/math/Spherical.js +73 -11
  339. package/src/math/SphericalHarmonics3.js +112 -14
  340. package/src/math/Triangle.js +230 -2
  341. package/src/math/Vector2.js +396 -10
  342. package/src/math/Vector3.js +550 -13
  343. package/src/math/Vector4.js +415 -9
  344. package/src/math/interpolants/CubicInterpolant.js +10 -1
  345. package/src/math/interpolants/DiscreteInterpolant.js +10 -2
  346. package/src/math/interpolants/LinearInterpolant.js +13 -0
  347. package/src/math/interpolants/QuaternionLinearInterpolant.js +10 -1
  348. package/src/nodes/Nodes.js +84 -166
  349. package/src/nodes/TSL.js +167 -0
  350. package/src/nodes/accessors/AccessorsUtils.js +39 -10
  351. package/src/nodes/accessors/Arrays.js +68 -0
  352. package/src/nodes/accessors/BatchNode.js +93 -26
  353. package/src/nodes/accessors/Bitangent.js +54 -0
  354. package/src/nodes/accessors/BufferAttributeNode.js +189 -11
  355. package/src/nodes/accessors/BufferNode.js +70 -5
  356. package/src/nodes/accessors/BuiltinNode.js +63 -0
  357. package/src/nodes/accessors/Camera.js +129 -0
  358. package/src/nodes/accessors/ClippingNode.js +152 -43
  359. package/src/nodes/accessors/CubeTextureNode.js +76 -13
  360. package/src/nodes/accessors/InstanceNode.js +118 -35
  361. package/src/nodes/accessors/InstancedMeshNode.js +50 -0
  362. package/src/nodes/accessors/Lights.js +129 -0
  363. package/src/nodes/accessors/MaterialNode.js +394 -58
  364. package/src/nodes/accessors/MaterialProperties.js +57 -1
  365. package/src/nodes/accessors/MaterialReferenceNode.js +60 -18
  366. package/src/nodes/accessors/ModelNode.js +159 -12
  367. package/src/nodes/accessors/ModelViewProjectionNode.js +10 -36
  368. package/src/nodes/accessors/MorphNode.js +60 -13
  369. package/src/nodes/accessors/Normal.js +156 -0
  370. package/src/nodes/accessors/Object3DNode.js +154 -35
  371. package/src/nodes/accessors/PointUVNode.js +35 -6
  372. package/src/nodes/accessors/Position.js +64 -0
  373. package/src/nodes/accessors/ReferenceBaseNode.js +357 -0
  374. package/src/nodes/accessors/ReferenceNode.js +243 -6
  375. package/src/nodes/accessors/ReflectVector.js +36 -0
  376. package/src/nodes/accessors/RendererReferenceNode.js +57 -7
  377. package/src/nodes/accessors/SceneNode.js +98 -6
  378. package/src/nodes/accessors/SkinningNode.js +214 -21
  379. package/src/nodes/accessors/StorageBufferNode.js +288 -28
  380. package/src/nodes/accessors/StorageTextureNode.js +139 -12
  381. package/src/nodes/accessors/Tangent.js +62 -0
  382. package/src/nodes/accessors/Texture3DNode.js +98 -12
  383. package/src/nodes/accessors/{TextureBicubicNode.js → TextureBicubic.js} +14 -34
  384. package/src/nodes/accessors/TextureNode.js +347 -34
  385. package/src/nodes/accessors/TextureSizeNode.js +51 -9
  386. package/src/nodes/accessors/UV.js +11 -0
  387. package/src/nodes/accessors/UniformArrayNode.js +241 -32
  388. package/src/nodes/accessors/UserDataNode.js +55 -7
  389. package/src/nodes/accessors/VelocityNode.js +223 -0
  390. package/src/nodes/accessors/VertexColorNode.js +45 -6
  391. package/src/nodes/code/CodeNode.js +108 -8
  392. package/src/nodes/code/ExpressionNode.js +38 -7
  393. package/src/nodes/code/FunctionCallNode.js +62 -11
  394. package/src/nodes/code/FunctionNode.js +54 -24
  395. package/src/nodes/code/ScriptableNode.js +241 -17
  396. package/src/nodes/code/ScriptableValueNode.js +93 -8
  397. package/src/nodes/core/ArrayNode.js +142 -0
  398. package/src/nodes/core/AssignNode.js +60 -12
  399. package/src/nodes/core/AttributeNode.js +55 -22
  400. package/src/nodes/core/BypassNode.js +59 -11
  401. package/src/nodes/core/CacheNode.js +64 -10
  402. package/src/nodes/core/ConstNode.js +38 -3
  403. package/src/nodes/core/ContextNode.js +87 -12
  404. package/src/nodes/core/IndexNode.js +102 -10
  405. package/src/nodes/core/InputNode.js +55 -3
  406. package/src/nodes/core/LightingModel.js +65 -5
  407. package/src/nodes/core/MRTNode.js +81 -7
  408. package/src/nodes/core/Node.js +368 -50
  409. package/src/nodes/core/NodeAttribute.js +38 -0
  410. package/src/nodes/core/NodeBuilder.js +1317 -83
  411. package/src/nodes/core/NodeCache.js +41 -2
  412. package/src/nodes/core/NodeCode.js +31 -0
  413. package/src/nodes/core/NodeFrame.js +123 -2
  414. package/src/nodes/core/NodeFunction.js +46 -0
  415. package/src/nodes/core/NodeFunctionInput.js +44 -0
  416. package/src/nodes/core/NodeParser.js +11 -0
  417. package/src/nodes/core/NodeUniform.js +52 -0
  418. package/src/nodes/core/NodeUtils.js +226 -6
  419. package/src/nodes/core/NodeVar.js +47 -1
  420. package/src/nodes/core/NodeVarying.js +28 -0
  421. package/src/nodes/core/OutputStructNode.js +61 -17
  422. package/src/nodes/core/ParameterNode.js +34 -4
  423. package/src/nodes/core/PropertyNode.js +296 -32
  424. package/src/nodes/core/StackNode.js +108 -8
  425. package/src/nodes/core/StructNode.js +120 -0
  426. package/src/nodes/core/StructType.js +13 -0
  427. package/src/nodes/core/StructTypeNode.js +116 -9
  428. package/src/nodes/core/TempNode.js +37 -7
  429. package/src/nodes/core/UniformGroupNode.js +98 -17
  430. package/src/nodes/core/UniformNode.js +72 -4
  431. package/src/nodes/core/VarNode.js +170 -13
  432. package/src/nodes/core/VaryingNode.js +109 -8
  433. package/src/nodes/core/constants.js +40 -0
  434. package/src/nodes/display/BlendModes.js +193 -0
  435. package/src/nodes/display/BumpMapNode.js +47 -10
  436. package/src/nodes/display/ColorAdjustment.js +141 -0
  437. package/src/nodes/display/ColorSpaceFunctions.js +54 -0
  438. package/src/nodes/display/ColorSpaceNode.js +147 -68
  439. package/src/nodes/display/FrontFacingNode.js +39 -6
  440. package/src/nodes/display/NormalMapNode.js +55 -13
  441. package/src/nodes/display/PassNode.js +420 -19
  442. package/src/nodes/display/PosterizeNode.js +40 -7
  443. package/src/nodes/display/RenderOutputNode.js +81 -13
  444. package/src/nodes/display/ScreenNode.js +286 -0
  445. package/src/nodes/display/ToneMappingFunctions.js +242 -0
  446. package/src/nodes/display/ToneMappingNode.js +68 -175
  447. package/src/nodes/display/ToonOutlinePassNode.js +183 -0
  448. package/src/nodes/display/ViewportDepthNode.js +210 -36
  449. package/src/nodes/display/ViewportDepthTextureNode.js +32 -9
  450. package/src/nodes/display/ViewportSharedTextureNode.js +32 -9
  451. package/src/nodes/display/ViewportTextureNode.js +68 -11
  452. package/src/nodes/fog/Fog.js +113 -0
  453. package/src/nodes/functions/BSDF/BRDF_GGX.js +4 -4
  454. package/src/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
  455. package/src/nodes/functions/BSDF/BRDF_Sheen.js +6 -6
  456. package/src/nodes/functions/BSDF/DFGApprox.js +2 -2
  457. package/src/nodes/functions/BSDF/D_GGX.js +2 -2
  458. package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +3 -3
  459. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
  460. package/src/nodes/functions/BSDF/F_Schlick.js +2 -2
  461. package/src/nodes/functions/BSDF/LTC.js +50 -6
  462. package/src/nodes/functions/BSDF/Schlick_to_F0.js +2 -2
  463. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +2 -2
  464. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
  465. package/src/nodes/functions/BasicLightingModel.js +27 -6
  466. package/src/nodes/functions/PhongLightingModel.js +38 -8
  467. package/src/nodes/functions/PhysicalLightingModel.js +215 -51
  468. package/src/nodes/functions/ShadowMaskModel.js +24 -1
  469. package/src/nodes/functions/ToonLightingModel.js +24 -5
  470. package/src/nodes/functions/VolumetricLightingModel.js +183 -0
  471. package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
  472. package/src/nodes/functions/material/getGeometryRoughness.js +10 -4
  473. package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
  474. package/src/nodes/functions/material/getRoughness.js +2 -2
  475. package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
  476. package/src/nodes/geometry/RangeNode.js +62 -7
  477. package/src/nodes/gpgpu/AtomicFunctionNode.js +280 -0
  478. package/src/nodes/gpgpu/BarrierNode.js +89 -0
  479. package/src/nodes/gpgpu/ComputeBuiltinNode.js +227 -0
  480. package/src/nodes/gpgpu/ComputeNode.js +124 -9
  481. package/src/nodes/gpgpu/WorkgroupInfoNode.js +208 -0
  482. package/src/nodes/lighting/AONode.js +24 -3
  483. package/src/nodes/lighting/AmbientLightNode.js +16 -8
  484. package/src/nodes/lighting/AnalyticLightNode.js +151 -231
  485. package/src/nodes/lighting/BasicEnvironmentNode.js +25 -3
  486. package/src/nodes/lighting/BasicLightMapNode.js +25 -5
  487. package/src/nodes/lighting/DirectionalLightNode.js +19 -20
  488. package/src/nodes/lighting/EnvironmentNode.js +34 -17
  489. package/src/nodes/lighting/HemisphereLightNode.js +42 -11
  490. package/src/nodes/lighting/IESSpotLightNode.js +18 -9
  491. package/src/nodes/lighting/IrradianceNode.js +23 -3
  492. package/src/nodes/lighting/LightProbeNode.js +29 -36
  493. package/src/nodes/lighting/LightUtils.js +12 -4
  494. package/src/nodes/lighting/LightingContextNode.js +70 -21
  495. package/src/nodes/lighting/LightingNode.js +22 -9
  496. package/src/nodes/lighting/LightsNode.js +309 -86
  497. package/src/nodes/lighting/PointLightNode.js +66 -32
  498. package/src/nodes/lighting/PointShadowNode.js +306 -0
  499. package/src/nodes/lighting/RectAreaLightNode.js +61 -25
  500. package/src/nodes/lighting/ShadowBaseNode.js +92 -0
  501. package/src/nodes/lighting/ShadowNode.js +812 -0
  502. package/src/nodes/lighting/SpotLightNode.js +73 -31
  503. package/src/nodes/materialx/MaterialXNodes.js +2 -2
  504. package/src/nodes/materialx/lib/mx_hsv.js +27 -22
  505. package/src/nodes/materialx/lib/mx_noise.js +70 -70
  506. package/src/nodes/materialx/lib/mx_transform_color.js +2 -2
  507. package/src/nodes/math/ConditionalNode.js +230 -0
  508. package/src/nodes/math/Hash.js +21 -0
  509. package/src/nodes/math/MathNode.js +812 -131
  510. package/src/nodes/math/MathUtils.js +47 -8
  511. package/src/nodes/math/OperatorNode.js +410 -66
  512. package/src/nodes/math/TriNoise3D.js +32 -32
  513. package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
  514. package/src/nodes/parsers/GLSLNodeParser.js +11 -0
  515. package/src/nodes/pmrem/PMREMNode.js +188 -28
  516. package/src/nodes/pmrem/PMREMUtils.js +24 -24
  517. package/src/nodes/procedural/Checker.js +22 -0
  518. package/src/nodes/shapes/Shapes.js +32 -0
  519. package/src/nodes/tsl/TSLBase.js +31 -0
  520. package/src/nodes/{shadernode/ShaderNode.js → tsl/TSLCore.js} +114 -98
  521. package/src/nodes/utils/ArrayElementNode.js +45 -5
  522. package/src/nodes/utils/ConvertNode.js +39 -4
  523. package/src/nodes/utils/CubeMapNode.js +88 -8
  524. package/src/nodes/utils/Discard.js +24 -0
  525. package/src/nodes/utils/EquirectUVNode.js +39 -7
  526. package/src/nodes/utils/FlipNode.js +106 -0
  527. package/src/nodes/utils/FunctionOverloadingNode.js +61 -6
  528. package/src/nodes/utils/JoinNode.js +31 -3
  529. package/src/nodes/utils/LoopNode.js +95 -9
  530. package/src/nodes/utils/MatcapUVNode.js +27 -8
  531. package/src/nodes/utils/MaxMipLevelNode.js +57 -6
  532. package/src/nodes/utils/MemberNode.js +68 -0
  533. package/src/nodes/utils/Oscillators.js +41 -0
  534. package/src/nodes/utils/Packing.js +21 -0
  535. package/src/nodes/utils/PostProcessingUtils.js +95 -0
  536. package/src/nodes/utils/RTTNode.js +141 -9
  537. package/src/nodes/utils/ReflectorNode.js +295 -21
  538. package/src/nodes/utils/RemapNode.js +93 -10
  539. package/src/nodes/utils/RotateNode.js +48 -13
  540. package/src/nodes/utils/SetNode.js +50 -4
  541. package/src/nodes/utils/SplitNode.js +62 -6
  542. package/src/nodes/utils/SpriteSheetUVNode.js +56 -7
  543. package/src/nodes/utils/SpriteUtils.js +21 -5
  544. package/src/nodes/utils/StorageArrayElementNode.js +64 -12
  545. package/src/nodes/utils/Timer.js +73 -0
  546. package/src/nodes/utils/TriplanarTexturesNode.js +96 -10
  547. package/src/nodes/utils/UVUtils.js +27 -9
  548. package/src/nodes/utils/ViewportUtils.js +16 -4
  549. package/src/objects/BatchedMesh.js +808 -281
  550. package/src/objects/Bone.js +24 -0
  551. package/src/objects/ClippingGroup.js +68 -0
  552. package/src/objects/Group.js +24 -0
  553. package/src/objects/InstancedMesh.js +120 -2
  554. package/src/objects/LOD.js +120 -5
  555. package/src/objects/Line.js +89 -6
  556. package/src/objects/LineLoop.js +20 -0
  557. package/src/objects/LineSegments.js +18 -0
  558. package/src/objects/Mesh.js +82 -23
  559. package/src/objects/Points.js +62 -0
  560. package/src/objects/Skeleton.js +107 -2
  561. package/src/objects/SkinnedMesh.js +99 -5
  562. package/src/objects/Sprite.js +54 -0
  563. package/src/renderers/WebGLRenderer.js +274 -157
  564. package/src/renderers/common/Animation.js +109 -12
  565. package/src/renderers/common/Attributes.js +40 -0
  566. package/src/renderers/common/Backend.js +504 -44
  567. package/src/renderers/common/Background.js +67 -9
  568. package/src/renderers/common/BindGroup.js +45 -1
  569. package/src/renderers/common/Binding.js +35 -0
  570. package/src/renderers/common/Bindings.js +136 -19
  571. package/src/renderers/common/Buffer.js +49 -0
  572. package/src/renderers/common/BufferUtils.js +25 -0
  573. package/src/renderers/common/BundleGroup.js +83 -0
  574. package/src/renderers/common/ChainMap.js +45 -6
  575. package/src/renderers/common/ClippingContext.js +175 -80
  576. package/src/renderers/common/Color4.js +40 -0
  577. package/src/renderers/common/ComputePipeline.js +24 -0
  578. package/src/renderers/common/Constants.js +2 -1
  579. package/src/renderers/common/CubeRenderTarget.js +22 -3
  580. package/src/renderers/common/DataMap.js +37 -1
  581. package/src/renderers/common/Geometries.js +111 -14
  582. package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
  583. package/src/renderers/common/Info.js +78 -35
  584. package/src/renderers/common/Lighting.js +73 -0
  585. package/src/renderers/common/Pipeline.js +22 -0
  586. package/src/renderers/common/Pipelines.js +148 -5
  587. package/src/renderers/common/PostProcessing.js +112 -11
  588. package/src/renderers/common/ProgrammableStage.js +60 -2
  589. package/src/renderers/common/QuadMesh.js +56 -5
  590. package/src/renderers/common/RenderBundle.js +14 -8
  591. package/src/renderers/common/RenderBundles.js +39 -10
  592. package/src/renderers/common/RenderContext.js +205 -7
  593. package/src/renderers/common/RenderContexts.js +59 -6
  594. package/src/renderers/common/RenderList.js +230 -21
  595. package/src/renderers/common/RenderLists.js +45 -6
  596. package/src/renderers/common/RenderObject.js +552 -41
  597. package/src/renderers/common/RenderObjects.js +118 -9
  598. package/src/renderers/common/RenderPipeline.js +24 -0
  599. package/src/renderers/common/Renderer.js +1537 -239
  600. package/src/renderers/common/RendererUtils.js +191 -0
  601. package/src/renderers/common/SampledTexture.js +132 -3
  602. package/src/renderers/common/Sampler.js +30 -0
  603. package/src/renderers/common/StorageBuffer.js +24 -0
  604. package/src/renderers/common/StorageBufferAttribute.js +31 -2
  605. package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
  606. package/src/renderers/common/StorageTexture.js +38 -0
  607. package/src/renderers/common/Textures.js +142 -32
  608. package/src/renderers/common/TimestampQueryPool.js +98 -0
  609. package/src/renderers/common/Uniform.js +225 -3
  610. package/src/renderers/common/UniformBuffer.js +19 -0
  611. package/src/renderers/common/UniformsGroup.js +157 -6
  612. package/src/renderers/common/XRManager.js +1185 -0
  613. package/src/renderers/common/XRRenderTarget.js +74 -0
  614. package/src/renderers/common/extras/PMREMGenerator.js +211 -53
  615. package/src/renderers/common/nodes/NodeBuilderState.js +100 -6
  616. package/src/renderers/common/nodes/NodeLibrary.js +194 -0
  617. package/src/renderers/common/nodes/NodeSampledTexture.js +92 -4
  618. package/src/renderers/common/nodes/NodeSampler.js +28 -0
  619. package/src/renderers/common/nodes/NodeStorageBuffer.js +37 -3
  620. package/src/renderers/common/nodes/NodeUniform.js +285 -2
  621. package/src/renderers/common/nodes/NodeUniformBuffer.js +29 -0
  622. package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
  623. package/src/renderers/common/nodes/Nodes.js +390 -70
  624. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
  625. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
  626. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
  627. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
  628. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +2 -2
  629. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
  630. package/src/renderers/shaders/ShaderLib/points.glsl.js +2 -0
  631. package/src/renderers/shaders/ShaderLib/sprite.glsl.js +2 -4
  632. package/src/renderers/webgl/WebGLAttributes.js +45 -14
  633. package/src/renderers/webgl/WebGLBackground.js +24 -1
  634. package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
  635. package/src/renderers/webgl/WebGLCapabilities.js +2 -0
  636. package/src/renderers/webgl/WebGLGeometries.js +0 -28
  637. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
  638. package/src/renderers/webgl/WebGLProgram.js +27 -29
  639. package/src/renderers/webgl/WebGLPrograms.js +24 -16
  640. package/src/renderers/webgl/WebGLState.js +68 -11
  641. package/src/renderers/webgl/WebGLTextures.js +49 -10
  642. package/src/renderers/webgl-fallback/WebGLBackend.js +1055 -238
  643. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +5 -10
  644. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +425 -48
  645. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +64 -1
  646. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
  647. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
  648. package/src/renderers/webgl-fallback/utils/WebGLState.js +419 -14
  649. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +281 -59
  650. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +367 -0
  651. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
  652. package/src/renderers/webgpu/WebGPUBackend.js +816 -236
  653. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +78 -0
  654. package/src/renderers/webgpu/WebGPURenderer.js +45 -6
  655. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +63 -0
  656. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +97 -0
  657. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +954 -147
  658. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +29 -4
  659. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
  660. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +147 -31
  661. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +213 -31
  662. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +146 -28
  663. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +161 -7
  664. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +333 -50
  665. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +287 -0
  666. package/src/renderers/webgpu/utils/WebGPUUtils.js +131 -3
  667. package/src/renderers/webxr/WebXRDepthSensing.js +1 -1
  668. package/src/renderers/webxr/WebXRManager.js +54 -32
  669. package/src/scenes/Fog.js +60 -0
  670. package/src/scenes/FogExp2.js +51 -0
  671. package/src/scenes/Scene.js +87 -0
  672. package/src/textures/Data3DTexture.js +2 -2
  673. package/src/textures/DepthTexture.js +2 -0
  674. package/src/textures/Source.js +2 -2
  675. package/src/textures/Texture.js +368 -5
  676. package/src/textures/VideoFrameTexture.js +35 -0
  677. package/src/utils.js +33 -1
  678. package/examples/jsm/animation/MMDAnimationHelper.js +0 -1207
  679. package/examples/jsm/animation/MMDPhysics.js +0 -1406
  680. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  681. package/examples/jsm/controls/Controls.js +0 -32
  682. package/examples/jsm/exporters/MMDExporter.js +0 -217
  683. package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -174
  684. package/examples/jsm/geometries/SDFGeometryGenerator.js +0 -144
  685. package/examples/jsm/libs/mmdparser.module.js +0 -11530
  686. package/examples/jsm/loaders/LogLuvLoader.js +0 -606
  687. package/examples/jsm/loaders/MMDLoader.js +0 -2295
  688. package/examples/jsm/loaders/TiltLoader.js +0 -520
  689. package/examples/jsm/objects/InstancedPoints.js +0 -21
  690. package/examples/jsm/shaders/MMDToonShader.js +0 -134
  691. package/examples/jsm/utils/GPUStatsPanel.js +0 -95
  692. package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
  693. package/src/nodes/accessors/BitangentNode.js +0 -13
  694. package/src/nodes/accessors/CameraNode.js +0 -19
  695. package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -21
  696. package/src/nodes/accessors/NormalNode.js +0 -14
  697. package/src/nodes/accessors/PositionNode.js +0 -10
  698. package/src/nodes/accessors/ReflectVectorNode.js +0 -10
  699. package/src/nodes/accessors/TangentNode.js +0 -23
  700. package/src/nodes/accessors/UVNode.js +0 -3
  701. package/src/nodes/core/NodeKeywords.js +0 -80
  702. package/src/nodes/core/UniformGroup.js +0 -13
  703. package/src/nodes/display/AfterImageNode.js +0 -152
  704. package/src/nodes/display/AnamorphicNode.js +0 -145
  705. package/src/nodes/display/BlendModeNode.js +0 -128
  706. package/src/nodes/display/ColorAdjustmentNode.js +0 -104
  707. package/src/nodes/display/DenoiseNode.js +0 -198
  708. package/src/nodes/display/DotScreenNode.js +0 -75
  709. package/src/nodes/display/FXAANode.js +0 -327
  710. package/src/nodes/display/FilmNode.js +0 -52
  711. package/src/nodes/display/GTAONode.js +0 -324
  712. package/src/nodes/display/GaussianBlurNode.js +0 -207
  713. package/src/nodes/display/Lut3DNode.js +0 -53
  714. package/src/nodes/display/RGBShiftNode.js +0 -49
  715. package/src/nodes/display/SepiaNode.js +0 -18
  716. package/src/nodes/display/TransitionNode.js +0 -76
  717. package/src/nodes/display/ViewportNode.js +0 -137
  718. package/src/nodes/fog/FogExp2Node.js +0 -34
  719. package/src/nodes/fog/FogNode.js +0 -48
  720. package/src/nodes/fog/FogRangeNode.js +0 -35
  721. package/src/nodes/lighting/LightNode.js +0 -57
  722. package/src/nodes/loaders/NodeLoader.js +0 -110
  723. package/src/nodes/loaders/NodeMaterialLoader.js +0 -60
  724. package/src/nodes/loaders/NodeObjectLoader.js +0 -71
  725. package/src/nodes/materials/InstancedPointsNodeMaterial.js +0 -162
  726. package/src/nodes/materials/LineBasicNodeMaterial.js +0 -28
  727. package/src/nodes/materials/LineDashedNodeMaterial.js +0 -55
  728. package/src/nodes/materials/MeshBasicNodeMaterial.js +0 -73
  729. package/src/nodes/materials/MeshLambertNodeMaterial.js +0 -43
  730. package/src/nodes/materials/MeshMatcapNodeMaterial.js +0 -53
  731. package/src/nodes/materials/MeshNormalNodeMaterial.js +0 -40
  732. package/src/nodes/materials/MeshPhongNodeMaterial.js +0 -74
  733. package/src/nodes/materials/MeshPhysicalNodeMaterial.js +0 -244
  734. package/src/nodes/materials/MeshSSSNodeMaterial.js +0 -84
  735. package/src/nodes/materials/MeshStandardNodeMaterial.js +0 -104
  736. package/src/nodes/materials/MeshToonNodeMaterial.js +0 -34
  737. package/src/nodes/materials/NodeMaterial.js +0 -680
  738. package/src/nodes/materials/PointsNodeMaterial.js +0 -39
  739. package/src/nodes/materials/ShadowNodeMaterial.js +0 -34
  740. package/src/nodes/materials/SpriteNodeMaterial.js +0 -90
  741. package/src/nodes/materials/VolumeNodeMaterial.js +0 -106
  742. package/src/nodes/math/CondNode.js +0 -139
  743. package/src/nodes/math/HashNode.js +0 -34
  744. package/src/nodes/procedural/CheckerNode.js +0 -42
  745. package/src/nodes/utils/DiscardNode.js +0 -28
  746. package/src/nodes/utils/OscNode.js +0 -81
  747. package/src/nodes/utils/PackingNode.js +0 -55
  748. package/src/nodes/utils/TimerNode.js +0 -94
@@ -1,2295 +0,0 @@
1
- import {
2
- AddOperation,
3
- AnimationClip,
4
- Bone,
5
- BufferGeometry,
6
- Color,
7
- CustomBlending,
8
- TangentSpaceNormalMap,
9
- DoubleSide,
10
- DstAlphaFactor,
11
- Euler,
12
- FileLoader,
13
- Float32BufferAttribute,
14
- FrontSide,
15
- Interpolant,
16
- Loader,
17
- LoaderUtils,
18
- UniformsUtils,
19
- ShaderMaterial,
20
- MultiplyOperation,
21
- NearestFilter,
22
- NumberKeyframeTrack,
23
- OneMinusSrcAlphaFactor,
24
- Quaternion,
25
- QuaternionKeyframeTrack,
26
- RepeatWrapping,
27
- Skeleton,
28
- SkinnedMesh,
29
- SrcAlphaFactor,
30
- SRGBColorSpace,
31
- TextureLoader,
32
- Uint16BufferAttribute,
33
- Vector3,
34
- VectorKeyframeTrack,
35
- RGB_S3TC_DXT1_Format,
36
- RGB_PVRTC_4BPPV1_Format,
37
- RGB_PVRTC_2BPPV1_Format,
38
- RGB_ETC1_Format,
39
- RGB_ETC2_Format
40
- } from 'three';
41
- import { MMDToonShader } from '../shaders/MMDToonShader.js';
42
- import { TGALoader } from '../loaders/TGALoader.js';
43
- import { MMDParser } from '../libs/mmdparser.module.js';
44
-
45
- /**
46
- * Dependencies
47
- * - mmd-parser https://github.com/takahirox/mmd-parser
48
- * - TGALoader
49
- * - OutlineEffect
50
- *
51
- * MMDLoader creates Three.js Objects from MMD resources as
52
- * PMD, PMX, VMD, and VPD files.
53
- *
54
- * PMD/PMX is a model data format, VMD is a motion data format
55
- * VPD is a posing data format used in MMD(Miku Miku Dance).
56
- *
57
- * MMD official site
58
- * - https://sites.google.com/view/evpvp/
59
- *
60
- * PMD, VMD format (in Japanese)
61
- * - http://blog.goo.ne.jp/torisu_tetosuki/e/209ad341d3ece2b1b4df24abf619d6e4
62
- *
63
- * PMX format
64
- * - https://gist.github.com/felixjones/f8a06bd48f9da9a4539f
65
- *
66
- * TODO
67
- * - light motion in vmd support.
68
- * - SDEF support.
69
- * - uv/material/bone morphing support.
70
- * - more precise grant skinning support.
71
- * - shadow support.
72
- */
73
-
74
- /**
75
- * @param {THREE.LoadingManager} manager
76
- */
77
- class MMDLoader extends Loader {
78
-
79
- constructor( manager ) {
80
-
81
- super( manager );
82
-
83
- this.loader = new FileLoader( this.manager );
84
-
85
- this.parser = null; // lazy generation
86
- this.meshBuilder = new MeshBuilder( this.manager );
87
- this.animationBuilder = new AnimationBuilder();
88
-
89
- }
90
-
91
- /**
92
- * @param {string} animationPath
93
- * @return {MMDLoader}
94
- */
95
- setAnimationPath( animationPath ) {
96
-
97
- this.animationPath = animationPath;
98
- return this;
99
-
100
- }
101
-
102
- // Load MMD assets as Three.js Object
103
-
104
- /**
105
- * Loads Model file (.pmd or .pmx) as a SkinnedMesh.
106
- *
107
- * @param {string} url - url to Model(.pmd or .pmx) file
108
- * @param {function} onLoad
109
- * @param {function} onProgress
110
- * @param {function} onError
111
- */
112
- load( url, onLoad, onProgress, onError ) {
113
-
114
- const builder = this.meshBuilder.setCrossOrigin( this.crossOrigin );
115
-
116
- // resource path
117
-
118
- let resourcePath;
119
-
120
- if ( this.resourcePath !== '' ) {
121
-
122
- resourcePath = this.resourcePath;
123
-
124
- } else if ( this.path !== '' ) {
125
-
126
- resourcePath = this.path;
127
-
128
- } else {
129
-
130
- resourcePath = LoaderUtils.extractUrlBase( url );
131
-
132
- }
133
-
134
- const parser = this._getParser();
135
- const extractModelExtension = this._extractModelExtension;
136
-
137
- this.loader
138
- .setMimeType( undefined )
139
- .setPath( this.path )
140
- .setResponseType( 'arraybuffer' )
141
- .setRequestHeader( this.requestHeader )
142
- .setWithCredentials( this.withCredentials )
143
- .load( url, function ( buffer ) {
144
-
145
- try {
146
-
147
- const modelExtension = extractModelExtension( buffer );
148
-
149
- if ( modelExtension !== 'pmd' && modelExtension !== 'pmx' ) {
150
-
151
- if ( onError ) onError( new Error( 'THREE.MMDLoader: Unknown model file extension .' + modelExtension + '.' ) );
152
-
153
- return;
154
-
155
- }
156
-
157
- const data = modelExtension === 'pmd' ? parser.parsePmd( buffer, true ) : parser.parsePmx( buffer, true );
158
-
159
- onLoad( builder.build( data, resourcePath, onProgress, onError ) );
160
-
161
- } catch ( e ) {
162
-
163
- if ( onError ) onError( e );
164
-
165
- }
166
-
167
- }, onProgress, onError );
168
-
169
- }
170
-
171
- /**
172
- * Loads Motion file(s) (.vmd) as a AnimationClip.
173
- * If two or more files are specified, they'll be merged.
174
- *
175
- * @param {string|Array<string>} url - url(s) to animation(.vmd) file(s)
176
- * @param {SkinnedMesh|THREE.Camera} object - tracks will be fitting to this object
177
- * @param {function} onLoad
178
- * @param {function} onProgress
179
- * @param {function} onError
180
- */
181
- loadAnimation( url, object, onLoad, onProgress, onError ) {
182
-
183
- const builder = this.animationBuilder;
184
-
185
- this.loadVMD( url, function ( vmd ) {
186
-
187
- onLoad( object.isCamera
188
- ? builder.buildCameraAnimation( vmd )
189
- : builder.build( vmd, object ) );
190
-
191
- }, onProgress, onError );
192
-
193
- }
194
-
195
- /**
196
- * Loads mode file and motion file(s) as an object containing
197
- * a SkinnedMesh and a AnimationClip.
198
- * Tracks of AnimationClip are fitting to the model.
199
- *
200
- * @param {string} modelUrl - url to Model(.pmd or .pmx) file
201
- * @param {string|Array{string}} vmdUrl - url(s) to animation(.vmd) file
202
- * @param {function} onLoad
203
- * @param {function} onProgress
204
- * @param {function} onError
205
- */
206
- loadWithAnimation( modelUrl, vmdUrl, onLoad, onProgress, onError ) {
207
-
208
- const scope = this;
209
-
210
- this.load( modelUrl, function ( mesh ) {
211
-
212
- scope.loadAnimation( vmdUrl, mesh, function ( animation ) {
213
-
214
- onLoad( {
215
- mesh: mesh,
216
- animation: animation
217
- } );
218
-
219
- }, onProgress, onError );
220
-
221
- }, onProgress, onError );
222
-
223
- }
224
-
225
- // Load MMD assets as Object data parsed by MMDParser
226
-
227
- /**
228
- * Loads .pmd file as an Object.
229
- *
230
- * @param {string} url - url to .pmd file
231
- * @param {function} onLoad
232
- * @param {function} onProgress
233
- * @param {function} onError
234
- */
235
- loadPMD( url, onLoad, onProgress, onError ) {
236
-
237
- const parser = this._getParser();
238
-
239
- this.loader
240
- .setMimeType( undefined )
241
- .setPath( this.path )
242
- .setResponseType( 'arraybuffer' )
243
- .setRequestHeader( this.requestHeader )
244
- .setWithCredentials( this.withCredentials )
245
- .load( url, function ( buffer ) {
246
-
247
- try {
248
-
249
- onLoad( parser.parsePmd( buffer, true ) );
250
-
251
- } catch ( e ) {
252
-
253
- if ( onError ) onError( e );
254
-
255
- }
256
-
257
- }, onProgress, onError );
258
-
259
- }
260
-
261
- /**
262
- * Loads .pmx file as an Object.
263
- *
264
- * @param {string} url - url to .pmx file
265
- * @param {function} onLoad
266
- * @param {function} onProgress
267
- * @param {function} onError
268
- */
269
- loadPMX( url, onLoad, onProgress, onError ) {
270
-
271
- const parser = this._getParser();
272
-
273
- this.loader
274
- .setMimeType( undefined )
275
- .setPath( this.path )
276
- .setResponseType( 'arraybuffer' )
277
- .setRequestHeader( this.requestHeader )
278
- .setWithCredentials( this.withCredentials )
279
- .load( url, function ( buffer ) {
280
-
281
- try {
282
-
283
- onLoad( parser.parsePmx( buffer, true ) );
284
-
285
- } catch ( e ) {
286
-
287
- if ( onError ) onError( e );
288
-
289
- }
290
-
291
- }, onProgress, onError );
292
-
293
- }
294
-
295
- /**
296
- * Loads .vmd file as an Object. If two or more files are specified
297
- * they'll be merged.
298
- *
299
- * @param {string|Array<string>} url - url(s) to .vmd file(s)
300
- * @param {function} onLoad
301
- * @param {function} onProgress
302
- * @param {function} onError
303
- */
304
- loadVMD( url, onLoad, onProgress, onError ) {
305
-
306
- const urls = Array.isArray( url ) ? url : [ url ];
307
-
308
- const vmds = [];
309
- const vmdNum = urls.length;
310
-
311
- const parser = this._getParser();
312
-
313
- this.loader
314
- .setMimeType( undefined )
315
- .setPath( this.animationPath )
316
- .setResponseType( 'arraybuffer' )
317
- .setRequestHeader( this.requestHeader )
318
- .setWithCredentials( this.withCredentials );
319
-
320
- for ( let i = 0, il = urls.length; i < il; i ++ ) {
321
-
322
- this.loader.load( urls[ i ], function ( buffer ) {
323
-
324
- try {
325
-
326
- vmds.push( parser.parseVmd( buffer, true ) );
327
-
328
- if ( vmds.length === vmdNum ) onLoad( parser.mergeVmds( vmds ) );
329
-
330
- } catch ( e ) {
331
-
332
- if ( onError ) onError( e );
333
-
334
- }
335
-
336
- }, onProgress, onError );
337
-
338
- }
339
-
340
- }
341
-
342
- /**
343
- * Loads .vpd file as an Object.
344
- *
345
- * @param {string} url - url to .vpd file
346
- * @param {boolean} isUnicode
347
- * @param {function} onLoad
348
- * @param {function} onProgress
349
- * @param {function} onError
350
- */
351
- loadVPD( url, isUnicode, onLoad, onProgress, onError ) {
352
-
353
- const parser = this._getParser();
354
-
355
- this.loader
356
- .setMimeType( isUnicode ? undefined : 'text/plain; charset=shift_jis' )
357
- .setPath( this.animationPath )
358
- .setResponseType( 'text' )
359
- .setRequestHeader( this.requestHeader )
360
- .setWithCredentials( this.withCredentials )
361
- .load( url, function ( text ) {
362
-
363
- try {
364
-
365
- onLoad( parser.parseVpd( text, true ) );
366
-
367
- } catch ( e ) {
368
-
369
- if ( onError ) onError( e );
370
-
371
- }
372
-
373
- }, onProgress, onError );
374
-
375
- }
376
-
377
- // private methods
378
-
379
- _extractModelExtension( buffer ) {
380
-
381
- const decoder = new TextDecoder( 'utf-8' );
382
- const bytes = new Uint8Array( buffer, 0, 3 );
383
- return decoder.decode( bytes ).toLowerCase();
384
-
385
- }
386
-
387
- _getParser() {
388
-
389
- if ( this.parser === null ) {
390
-
391
- this.parser = new MMDParser.Parser();
392
-
393
- }
394
-
395
- return this.parser;
396
-
397
- }
398
-
399
- }
400
-
401
- // Utilities
402
-
403
- /*
404
- * base64 encoded defalut toon textures toon00.bmp - toon10.bmp.
405
- * We don't need to request external toon image files.
406
- */
407
- const DEFAULT_TOON_TEXTURES = [
408
- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=',
409
- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAN0lEQVRYR+3WQREAMBACsZ5/bWiiMvgEBTt5cW37hjsBBAgQIECAwFwgyfYPCCBAgAABAgTWAh8aBHZBl14e8wAAAABJRU5ErkJggg==',
410
- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAOUlEQVRYR+3WMREAMAwDsYY/yoDI7MLwIiP40+RJklfcCCBAgAABAgTqArfb/QMCCBAgQIAAgbbAB3z/e0F3js2cAAAAAElFTkSuQmCC',
411
- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAN0lEQVRYR+3WQREAMBACsZ5/B5ilMvgEBTt5cW37hjsBBAgQIECAwFwgyfYPCCBAgAABAgTWAh81dWyx0gFwKAAAAABJRU5ErkJggg==',
412
- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAOklEQVRYR+3WoREAMAwDsWb/UQtCy9wxTOQJ/oQ8SXKKGwEECBAgQIBAXeDt7f4BAQQIECBAgEBb4AOz8Hzx7WLY4wAAAABJRU5ErkJggg==',
413
- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABPUlEQVRYR+1XwW7CMAy1+f9fZOMysSEOEweEOPRNdm3HbdOyIhAcklPrOs/PLy9RygBALxzcCDQFmgJNgaZAU6Ap0BR4PwX8gsRMVLssMRH5HcpzJEaWL7EVg9F1IHRlyqQohgVr4FGUlUcMJSjcUlDw0zvjeun70cLWmneoyf7NgBTQSniBTQQSuJAZsOnnaczjIMb5hCiuHKxokCrJfVnrctyZL0PkJAJe1HMil4nxeyi3Ypfn1kX51jpPvo/JeCNC4PhVdHdJw2XjBR8brF8PEIhNVn12AgP7uHsTBguBn53MUZCqv7Lp07Pn5k1Ro+uWmUNn7D+M57rtk7aG0Vo73xyF/fbFf0bPJjDXngnGocDTdFhygZjwUQrMNrDcmZlQT50VJ/g/UwNyHpu778+yW+/ksOz/BFo54P4AsUXMfRq7XWsAAAAASUVORK5CYII=',
414
- '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=',
415
- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=',
416
- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=',
417
- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=',
418
- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII='
419
- ];
420
-
421
- const NON_ALPHA_CHANNEL_FORMATS = [
422
- RGB_S3TC_DXT1_Format,
423
- RGB_PVRTC_4BPPV1_Format,
424
- RGB_PVRTC_2BPPV1_Format,
425
- RGB_ETC1_Format,
426
- RGB_ETC2_Format
427
- ];
428
-
429
- // Builders. They build Three.js object from Object data parsed by MMDParser.
430
-
431
- /**
432
- * @param {THREE.LoadingManager} manager
433
- */
434
- class MeshBuilder {
435
-
436
- constructor( manager ) {
437
-
438
- this.crossOrigin = 'anonymous';
439
- this.geometryBuilder = new GeometryBuilder();
440
- this.materialBuilder = new MaterialBuilder( manager );
441
-
442
- }
443
-
444
- /**
445
- * @param {string} crossOrigin
446
- * @return {MeshBuilder}
447
- */
448
- setCrossOrigin( crossOrigin ) {
449
-
450
- this.crossOrigin = crossOrigin;
451
- return this;
452
-
453
- }
454
-
455
- /**
456
- * @param {Object} data - parsed PMD/PMX data
457
- * @param {string} resourcePath
458
- * @param {function} onProgress
459
- * @param {function} onError
460
- * @return {SkinnedMesh}
461
- */
462
- build( data, resourcePath, onProgress, onError ) {
463
-
464
- const geometry = this.geometryBuilder.build( data );
465
- const material = this.materialBuilder
466
- .setCrossOrigin( this.crossOrigin )
467
- .setResourcePath( resourcePath )
468
- .build( data, geometry, onProgress, onError );
469
-
470
- const mesh = new SkinnedMesh( geometry, material );
471
-
472
- const skeleton = new Skeleton( initBones( mesh ) );
473
- mesh.bind( skeleton );
474
-
475
- // console.log( mesh ); // for console debug
476
-
477
- return mesh;
478
-
479
- }
480
-
481
- }
482
-
483
- // TODO: Try to remove this function
484
-
485
- function initBones( mesh ) {
486
-
487
- const geometry = mesh.geometry;
488
-
489
- const bones = [];
490
-
491
- if ( geometry && geometry.bones !== undefined ) {
492
-
493
- // first, create array of 'Bone' objects from geometry data
494
-
495
- for ( let i = 0, il = geometry.bones.length; i < il; i ++ ) {
496
-
497
- const gbone = geometry.bones[ i ];
498
-
499
- // create new 'Bone' object
500
-
501
- const bone = new Bone();
502
- bones.push( bone );
503
-
504
- // apply values
505
-
506
- bone.name = gbone.name;
507
- bone.position.fromArray( gbone.pos );
508
- bone.quaternion.fromArray( gbone.rotq );
509
- if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
510
-
511
- }
512
-
513
- // second, create bone hierarchy
514
-
515
- for ( let i = 0, il = geometry.bones.length; i < il; i ++ ) {
516
-
517
- const gbone = geometry.bones[ i ];
518
-
519
- if ( ( gbone.parent !== - 1 ) && ( gbone.parent !== null ) && ( bones[ gbone.parent ] !== undefined ) ) {
520
-
521
- // subsequent bones in the hierarchy
522
-
523
- bones[ gbone.parent ].add( bones[ i ] );
524
-
525
- } else {
526
-
527
- // topmost bone, immediate child of the skinned mesh
528
-
529
- mesh.add( bones[ i ] );
530
-
531
- }
532
-
533
- }
534
-
535
- }
536
-
537
- // now the bones are part of the scene graph and children of the skinned mesh.
538
- // let's update the corresponding matrices
539
-
540
- mesh.updateMatrixWorld( true );
541
-
542
- return bones;
543
-
544
- }
545
-
546
- //
547
-
548
- class GeometryBuilder {
549
-
550
- /**
551
- * @param {Object} data - parsed PMD/PMX data
552
- * @return {BufferGeometry}
553
- */
554
- build( data ) {
555
-
556
- // for geometry
557
- const positions = [];
558
- const uvs = [];
559
- const normals = [];
560
-
561
- const indices = [];
562
-
563
- const groups = [];
564
-
565
- const bones = [];
566
- const skinIndices = [];
567
- const skinWeights = [];
568
-
569
- const morphTargets = [];
570
- const morphPositions = [];
571
-
572
- const iks = [];
573
- const grants = [];
574
-
575
- const rigidBodies = [];
576
- const constraints = [];
577
-
578
- // for work
579
- let offset = 0;
580
- const boneTypeTable = {};
581
-
582
- // positions, normals, uvs, skinIndices, skinWeights
583
-
584
- for ( let i = 0; i < data.metadata.vertexCount; i ++ ) {
585
-
586
- const v = data.vertices[ i ];
587
-
588
- for ( let j = 0, jl = v.position.length; j < jl; j ++ ) {
589
-
590
- positions.push( v.position[ j ] );
591
-
592
- }
593
-
594
- for ( let j = 0, jl = v.normal.length; j < jl; j ++ ) {
595
-
596
- normals.push( v.normal[ j ] );
597
-
598
- }
599
-
600
- for ( let j = 0, jl = v.uv.length; j < jl; j ++ ) {
601
-
602
- uvs.push( v.uv[ j ] );
603
-
604
- }
605
-
606
- for ( let j = 0; j < 4; j ++ ) {
607
-
608
- skinIndices.push( v.skinIndices.length - 1 >= j ? v.skinIndices[ j ] : 0.0 );
609
-
610
- }
611
-
612
- for ( let j = 0; j < 4; j ++ ) {
613
-
614
- skinWeights.push( v.skinWeights.length - 1 >= j ? v.skinWeights[ j ] : 0.0 );
615
-
616
- }
617
-
618
- }
619
-
620
- // indices
621
-
622
- for ( let i = 0; i < data.metadata.faceCount; i ++ ) {
623
-
624
- const face = data.faces[ i ];
625
-
626
- for ( let j = 0, jl = face.indices.length; j < jl; j ++ ) {
627
-
628
- indices.push( face.indices[ j ] );
629
-
630
- }
631
-
632
- }
633
-
634
- // groups
635
-
636
- for ( let i = 0; i < data.metadata.materialCount; i ++ ) {
637
-
638
- const material = data.materials[ i ];
639
-
640
- groups.push( {
641
- offset: offset * 3,
642
- count: material.faceCount * 3
643
- } );
644
-
645
- offset += material.faceCount;
646
-
647
- }
648
-
649
- // bones
650
-
651
- for ( let i = 0; i < data.metadata.rigidBodyCount; i ++ ) {
652
-
653
- const body = data.rigidBodies[ i ];
654
- let value = boneTypeTable[ body.boneIndex ];
655
-
656
- // keeps greater number if already value is set without any special reasons
657
- value = value === undefined ? body.type : Math.max( body.type, value );
658
-
659
- boneTypeTable[ body.boneIndex ] = value;
660
-
661
- }
662
-
663
- for ( let i = 0; i < data.metadata.boneCount; i ++ ) {
664
-
665
- const boneData = data.bones[ i ];
666
-
667
- const bone = {
668
- index: i,
669
- transformationClass: boneData.transformationClass,
670
- parent: boneData.parentIndex,
671
- name: boneData.name,
672
- pos: boneData.position.slice( 0, 3 ),
673
- rotq: [ 0, 0, 0, 1 ],
674
- scl: [ 1, 1, 1 ],
675
- rigidBodyType: boneTypeTable[ i ] !== undefined ? boneTypeTable[ i ] : - 1
676
- };
677
-
678
- if ( bone.parent !== - 1 ) {
679
-
680
- bone.pos[ 0 ] -= data.bones[ bone.parent ].position[ 0 ];
681
- bone.pos[ 1 ] -= data.bones[ bone.parent ].position[ 1 ];
682
- bone.pos[ 2 ] -= data.bones[ bone.parent ].position[ 2 ];
683
-
684
- }
685
-
686
- bones.push( bone );
687
-
688
- }
689
-
690
- // iks
691
-
692
- // TODO: remove duplicated codes between PMD and PMX
693
- if ( data.metadata.format === 'pmd' ) {
694
-
695
- for ( let i = 0; i < data.metadata.ikCount; i ++ ) {
696
-
697
- const ik = data.iks[ i ];
698
-
699
- const param = {
700
- target: ik.target,
701
- effector: ik.effector,
702
- iteration: ik.iteration,
703
- maxAngle: ik.maxAngle * 4,
704
- links: []
705
- };
706
-
707
- for ( let j = 0, jl = ik.links.length; j < jl; j ++ ) {
708
-
709
- const link = {};
710
- link.index = ik.links[ j ].index;
711
- link.enabled = true;
712
-
713
- if ( data.bones[ link.index ].name.indexOf( 'ひざ' ) >= 0 ) {
714
-
715
- link.limitation = new Vector3( 1.0, 0.0, 0.0 );
716
-
717
- }
718
-
719
- param.links.push( link );
720
-
721
- }
722
-
723
- iks.push( param );
724
-
725
- }
726
-
727
- } else {
728
-
729
- for ( let i = 0; i < data.metadata.boneCount; i ++ ) {
730
-
731
- const ik = data.bones[ i ].ik;
732
-
733
- if ( ik === undefined ) continue;
734
-
735
- const param = {
736
- target: i,
737
- effector: ik.effector,
738
- iteration: ik.iteration,
739
- maxAngle: ik.maxAngle,
740
- links: []
741
- };
742
-
743
- for ( let j = 0, jl = ik.links.length; j < jl; j ++ ) {
744
-
745
- const link = {};
746
- link.index = ik.links[ j ].index;
747
- link.enabled = true;
748
-
749
- if ( ik.links[ j ].angleLimitation === 1 ) {
750
-
751
- // Revert if rotationMin/Max doesn't work well
752
- // link.limitation = new Vector3( 1.0, 0.0, 0.0 );
753
-
754
- const rotationMin = ik.links[ j ].lowerLimitationAngle;
755
- const rotationMax = ik.links[ j ].upperLimitationAngle;
756
-
757
- // Convert Left to Right coordinate by myself because
758
- // MMDParser doesn't convert. It's a MMDParser's bug
759
-
760
- const tmp1 = - rotationMax[ 0 ];
761
- const tmp2 = - rotationMax[ 1 ];
762
- rotationMax[ 0 ] = - rotationMin[ 0 ];
763
- rotationMax[ 1 ] = - rotationMin[ 1 ];
764
- rotationMin[ 0 ] = tmp1;
765
- rotationMin[ 1 ] = tmp2;
766
-
767
- link.rotationMin = new Vector3().fromArray( rotationMin );
768
- link.rotationMax = new Vector3().fromArray( rotationMax );
769
-
770
- }
771
-
772
- param.links.push( link );
773
-
774
- }
775
-
776
- iks.push( param );
777
-
778
- // Save the reference even from bone data for efficiently
779
- // simulating PMX animation system
780
- bones[ i ].ik = param;
781
-
782
- }
783
-
784
- }
785
-
786
- // grants
787
-
788
- if ( data.metadata.format === 'pmx' ) {
789
-
790
- // bone index -> grant entry map
791
- const grantEntryMap = {};
792
-
793
- for ( let i = 0; i < data.metadata.boneCount; i ++ ) {
794
-
795
- const boneData = data.bones[ i ];
796
- const grant = boneData.grant;
797
-
798
- if ( grant === undefined ) continue;
799
-
800
- const param = {
801
- index: i,
802
- parentIndex: grant.parentIndex,
803
- ratio: grant.ratio,
804
- isLocal: grant.isLocal,
805
- affectRotation: grant.affectRotation,
806
- affectPosition: grant.affectPosition,
807
- transformationClass: boneData.transformationClass
808
- };
809
-
810
- grantEntryMap[ i ] = { parent: null, children: [], param: param, visited: false };
811
-
812
- }
813
-
814
- const rootEntry = { parent: null, children: [], param: null, visited: false };
815
-
816
- // Build a tree representing grant hierarchy
817
-
818
- for ( const boneIndex in grantEntryMap ) {
819
-
820
- const grantEntry = grantEntryMap[ boneIndex ];
821
- const parentGrantEntry = grantEntryMap[ grantEntry.parentIndex ] || rootEntry;
822
-
823
- grantEntry.parent = parentGrantEntry;
824
- parentGrantEntry.children.push( grantEntry );
825
-
826
- }
827
-
828
- // Sort grant parameters from parents to children because
829
- // grant uses parent's transform that parent's grant is already applied
830
- // so grant should be applied in order from parents to children
831
-
832
- function traverse( entry ) {
833
-
834
- if ( entry.param ) {
835
-
836
- grants.push( entry.param );
837
-
838
- // Save the reference even from bone data for efficiently
839
- // simulating PMX animation system
840
- bones[ entry.param.index ].grant = entry.param;
841
-
842
- }
843
-
844
- entry.visited = true;
845
-
846
- for ( let i = 0, il = entry.children.length; i < il; i ++ ) {
847
-
848
- const child = entry.children[ i ];
849
-
850
- // Cut off a loop if exists. (Is a grant loop invalid?)
851
- if ( ! child.visited ) traverse( child );
852
-
853
- }
854
-
855
- }
856
-
857
- traverse( rootEntry );
858
-
859
- }
860
-
861
- // morph
862
-
863
- function updateAttributes( attribute, morph, ratio ) {
864
-
865
- for ( let i = 0; i < morph.elementCount; i ++ ) {
866
-
867
- const element = morph.elements[ i ];
868
-
869
- let index;
870
-
871
- if ( data.metadata.format === 'pmd' ) {
872
-
873
- index = data.morphs[ 0 ].elements[ element.index ].index;
874
-
875
- } else {
876
-
877
- index = element.index;
878
-
879
- }
880
-
881
- attribute.array[ index * 3 + 0 ] += element.position[ 0 ] * ratio;
882
- attribute.array[ index * 3 + 1 ] += element.position[ 1 ] * ratio;
883
- attribute.array[ index * 3 + 2 ] += element.position[ 2 ] * ratio;
884
-
885
- }
886
-
887
- }
888
-
889
- for ( let i = 0; i < data.metadata.morphCount; i ++ ) {
890
-
891
- const morph = data.morphs[ i ];
892
- const params = { name: morph.name };
893
-
894
- const attribute = new Float32BufferAttribute( data.metadata.vertexCount * 3, 3 );
895
- attribute.name = morph.name;
896
-
897
- for ( let j = 0; j < data.metadata.vertexCount * 3; j ++ ) {
898
-
899
- attribute.array[ j ] = positions[ j ];
900
-
901
- }
902
-
903
- if ( data.metadata.format === 'pmd' ) {
904
-
905
- if ( i !== 0 ) {
906
-
907
- updateAttributes( attribute, morph, 1.0 );
908
-
909
- }
910
-
911
- } else {
912
-
913
- if ( morph.type === 0 ) { // group
914
-
915
- for ( let j = 0; j < morph.elementCount; j ++ ) {
916
-
917
- const morph2 = data.morphs[ morph.elements[ j ].index ];
918
- const ratio = morph.elements[ j ].ratio;
919
-
920
- if ( morph2.type === 1 ) {
921
-
922
- updateAttributes( attribute, morph2, ratio );
923
-
924
- } else {
925
-
926
- // TODO: implement
927
-
928
- }
929
-
930
- }
931
-
932
- } else if ( morph.type === 1 ) { // vertex
933
-
934
- updateAttributes( attribute, morph, 1.0 );
935
-
936
- } else if ( morph.type === 2 ) { // bone
937
-
938
- // TODO: implement
939
-
940
- } else if ( morph.type === 3 ) { // uv
941
-
942
- // TODO: implement
943
-
944
- } else if ( morph.type === 4 ) { // additional uv1
945
-
946
- // TODO: implement
947
-
948
- } else if ( morph.type === 5 ) { // additional uv2
949
-
950
- // TODO: implement
951
-
952
- } else if ( morph.type === 6 ) { // additional uv3
953
-
954
- // TODO: implement
955
-
956
- } else if ( morph.type === 7 ) { // additional uv4
957
-
958
- // TODO: implement
959
-
960
- } else if ( morph.type === 8 ) { // material
961
-
962
- // TODO: implement
963
-
964
- }
965
-
966
- }
967
-
968
- morphTargets.push( params );
969
- morphPositions.push( attribute );
970
-
971
- }
972
-
973
- // rigid bodies from rigidBodies field.
974
-
975
- for ( let i = 0; i < data.metadata.rigidBodyCount; i ++ ) {
976
-
977
- const rigidBody = data.rigidBodies[ i ];
978
- const params = {};
979
-
980
- for ( const key in rigidBody ) {
981
-
982
- params[ key ] = rigidBody[ key ];
983
-
984
- }
985
-
986
- /*
987
- * RigidBody position parameter in PMX seems global position
988
- * while the one in PMD seems offset from corresponding bone.
989
- * So unify being offset.
990
- */
991
- if ( data.metadata.format === 'pmx' ) {
992
-
993
- if ( params.boneIndex !== - 1 ) {
994
-
995
- const bone = data.bones[ params.boneIndex ];
996
- params.position[ 0 ] -= bone.position[ 0 ];
997
- params.position[ 1 ] -= bone.position[ 1 ];
998
- params.position[ 2 ] -= bone.position[ 2 ];
999
-
1000
- }
1001
-
1002
- }
1003
-
1004
- rigidBodies.push( params );
1005
-
1006
- }
1007
-
1008
- // constraints from constraints field.
1009
-
1010
- for ( let i = 0; i < data.metadata.constraintCount; i ++ ) {
1011
-
1012
- const constraint = data.constraints[ i ];
1013
- const params = {};
1014
-
1015
- for ( const key in constraint ) {
1016
-
1017
- params[ key ] = constraint[ key ];
1018
-
1019
- }
1020
-
1021
- const bodyA = rigidBodies[ params.rigidBodyIndex1 ];
1022
- const bodyB = rigidBodies[ params.rigidBodyIndex2 ];
1023
-
1024
- // Refer to http://www20.atpages.jp/katwat/wp/?p=4135
1025
- if ( bodyA.type !== 0 && bodyB.type === 2 ) {
1026
-
1027
- if ( bodyA.boneIndex !== - 1 && bodyB.boneIndex !== - 1 &&
1028
- data.bones[ bodyB.boneIndex ].parentIndex === bodyA.boneIndex ) {
1029
-
1030
- bodyB.type = 1;
1031
-
1032
- }
1033
-
1034
- }
1035
-
1036
- constraints.push( params );
1037
-
1038
- }
1039
-
1040
- // build BufferGeometry.
1041
-
1042
- const geometry = new BufferGeometry();
1043
-
1044
- geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
1045
- geometry.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
1046
- geometry.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
1047
- geometry.setAttribute( 'skinIndex', new Uint16BufferAttribute( skinIndices, 4 ) );
1048
- geometry.setAttribute( 'skinWeight', new Float32BufferAttribute( skinWeights, 4 ) );
1049
- geometry.setIndex( indices );
1050
-
1051
- for ( let i = 0, il = groups.length; i < il; i ++ ) {
1052
-
1053
- geometry.addGroup( groups[ i ].offset, groups[ i ].count, i );
1054
-
1055
- }
1056
-
1057
- geometry.bones = bones;
1058
-
1059
- geometry.morphTargets = morphTargets;
1060
- geometry.morphAttributes.position = morphPositions;
1061
- geometry.morphTargetsRelative = false;
1062
-
1063
- geometry.userData.MMD = {
1064
- bones: bones,
1065
- iks: iks,
1066
- grants: grants,
1067
- rigidBodies: rigidBodies,
1068
- constraints: constraints,
1069
- format: data.metadata.format
1070
- };
1071
-
1072
- geometry.computeBoundingSphere();
1073
-
1074
- return geometry;
1075
-
1076
- }
1077
-
1078
- }
1079
-
1080
- //
1081
-
1082
- /**
1083
- * @param {THREE.LoadingManager} manager
1084
- */
1085
- class MaterialBuilder {
1086
-
1087
- constructor( manager ) {
1088
-
1089
- this.manager = manager;
1090
-
1091
- this.textureLoader = new TextureLoader( this.manager );
1092
- this.tgaLoader = null; // lazy generation
1093
-
1094
- this.crossOrigin = 'anonymous';
1095
- this.resourcePath = undefined;
1096
-
1097
- }
1098
-
1099
- /**
1100
- * @param {string} crossOrigin
1101
- * @return {MaterialBuilder}
1102
- */
1103
- setCrossOrigin( crossOrigin ) {
1104
-
1105
- this.crossOrigin = crossOrigin;
1106
- return this;
1107
-
1108
- }
1109
-
1110
- /**
1111
- * @param {string} resourcePath
1112
- * @return {MaterialBuilder}
1113
- */
1114
- setResourcePath( resourcePath ) {
1115
-
1116
- this.resourcePath = resourcePath;
1117
- return this;
1118
-
1119
- }
1120
-
1121
- /**
1122
- * @param {Object} data - parsed PMD/PMX data
1123
- * @param {BufferGeometry} geometry - some properties are dependend on geometry
1124
- * @param {function} onProgress
1125
- * @param {function} onError
1126
- * @return {Array<MMDToonMaterial>}
1127
- */
1128
- build( data, geometry /*, onProgress, onError */ ) {
1129
-
1130
- const materials = [];
1131
-
1132
- const textures = {};
1133
-
1134
- this.textureLoader.setCrossOrigin( this.crossOrigin );
1135
-
1136
- // materials
1137
-
1138
- for ( let i = 0; i < data.metadata.materialCount; i ++ ) {
1139
-
1140
- const material = data.materials[ i ];
1141
-
1142
- const params = { userData: { MMD: {} } };
1143
-
1144
- if ( material.name !== undefined ) params.name = material.name;
1145
-
1146
- /*
1147
- * Color
1148
- *
1149
- * MMD MMDToonMaterial
1150
- * ambient - emissive * a
1151
- * (a = 1.0 without map texture or 0.2 with map texture)
1152
- *
1153
- * MMDToonMaterial doesn't have ambient. Set it to emissive instead.
1154
- * It'll be too bright if material has map texture so using coef 0.2.
1155
- */
1156
- params.diffuse = new Color().setRGB(
1157
- material.diffuse[ 0 ],
1158
- material.diffuse[ 1 ],
1159
- material.diffuse[ 2 ],
1160
- SRGBColorSpace
1161
- );
1162
- params.opacity = material.diffuse[ 3 ];
1163
- params.specular = new Color().setRGB( ...material.specular, SRGBColorSpace );
1164
- params.shininess = material.shininess;
1165
- params.emissive = new Color().setRGB( ...material.ambient, SRGBColorSpace );
1166
- params.transparent = params.opacity !== 1.0;
1167
-
1168
- //
1169
-
1170
- params.fog = true;
1171
-
1172
- // blend
1173
-
1174
- params.blending = CustomBlending;
1175
- params.blendSrc = SrcAlphaFactor;
1176
- params.blendDst = OneMinusSrcAlphaFactor;
1177
- params.blendSrcAlpha = SrcAlphaFactor;
1178
- params.blendDstAlpha = DstAlphaFactor;
1179
-
1180
- // side
1181
-
1182
- if ( data.metadata.format === 'pmx' && ( material.flag & 0x1 ) === 1 ) {
1183
-
1184
- params.side = DoubleSide;
1185
-
1186
- } else {
1187
-
1188
- params.side = params.opacity === 1.0 ? FrontSide : DoubleSide;
1189
-
1190
- }
1191
-
1192
- if ( data.metadata.format === 'pmd' ) {
1193
-
1194
- // map, matcap
1195
-
1196
- if ( material.fileName ) {
1197
-
1198
- const fileName = material.fileName;
1199
- const fileNames = fileName.split( '*' );
1200
-
1201
- // fileNames[ 0 ]: mapFileName
1202
- // fileNames[ 1 ]: matcapFileName( optional )
1203
-
1204
- params.map = this._loadTexture( fileNames[ 0 ], textures );
1205
-
1206
- if ( fileNames.length > 1 ) {
1207
-
1208
- const extension = fileNames[ 1 ].slice( - 4 ).toLowerCase();
1209
-
1210
- params.matcap = this._loadTexture(
1211
- fileNames[ 1 ],
1212
- textures
1213
- );
1214
-
1215
- params.matcapCombine = extension === '.sph'
1216
- ? MultiplyOperation
1217
- : AddOperation;
1218
-
1219
- }
1220
-
1221
- }
1222
-
1223
- // gradientMap
1224
-
1225
- const toonFileName = ( material.toonIndex === - 1 )
1226
- ? 'toon00.bmp'
1227
- : data.toonTextures[ material.toonIndex ].fileName;
1228
-
1229
- params.gradientMap = this._loadTexture(
1230
- toonFileName,
1231
- textures,
1232
- {
1233
- isToonTexture: true,
1234
- isDefaultToonTexture: this._isDefaultToonTexture( toonFileName )
1235
- }
1236
- );
1237
-
1238
- // parameters for OutlineEffect
1239
-
1240
- params.userData.outlineParameters = {
1241
- thickness: material.edgeFlag === 1 ? 0.003 : 0.0,
1242
- color: [ 0, 0, 0 ],
1243
- alpha: 1.0,
1244
- visible: material.edgeFlag === 1
1245
- };
1246
-
1247
- } else {
1248
-
1249
- // map
1250
-
1251
- if ( material.textureIndex !== - 1 ) {
1252
-
1253
- params.map = this._loadTexture( data.textures[ material.textureIndex ], textures );
1254
-
1255
- // Since PMX spec don't have standard to list map files except color map and env map,
1256
- // we need to save file name for further mapping, like matching normal map file names after model loaded.
1257
- // ref: https://gist.github.com/felixjones/f8a06bd48f9da9a4539f#texture
1258
- params.userData.MMD.mapFileName = data.textures[ material.textureIndex ];
1259
-
1260
- }
1261
-
1262
- // matcap TODO: support m.envFlag === 3
1263
-
1264
- if ( material.envTextureIndex !== - 1 && ( material.envFlag === 1 || material.envFlag == 2 ) ) {
1265
-
1266
- params.matcap = this._loadTexture(
1267
- data.textures[ material.envTextureIndex ],
1268
- textures
1269
- );
1270
-
1271
- // Same as color map above, keep file name in userData for further usage.
1272
- params.userData.MMD.matcapFileName = data.textures[ material.envTextureIndex ];
1273
-
1274
- params.matcapCombine = material.envFlag === 1
1275
- ? MultiplyOperation
1276
- : AddOperation;
1277
-
1278
- }
1279
-
1280
- // gradientMap
1281
-
1282
- let toonFileName, isDefaultToon;
1283
-
1284
- if ( material.toonIndex === - 1 || material.toonFlag !== 0 ) {
1285
-
1286
- toonFileName = 'toon' + ( '0' + ( material.toonIndex + 1 ) ).slice( - 2 ) + '.bmp';
1287
- isDefaultToon = true;
1288
-
1289
- } else {
1290
-
1291
- toonFileName = data.textures[ material.toonIndex ];
1292
- isDefaultToon = false;
1293
-
1294
- }
1295
-
1296
- params.gradientMap = this._loadTexture(
1297
- toonFileName,
1298
- textures,
1299
- {
1300
- isToonTexture: true,
1301
- isDefaultToonTexture: isDefaultToon
1302
- }
1303
- );
1304
-
1305
- // parameters for OutlineEffect
1306
- params.userData.outlineParameters = {
1307
- thickness: material.edgeSize / 300, // TODO: better calculation?
1308
- color: material.edgeColor.slice( 0, 3 ),
1309
- alpha: material.edgeColor[ 3 ],
1310
- visible: ( material.flag & 0x10 ) !== 0 && material.edgeSize > 0.0
1311
- };
1312
-
1313
- }
1314
-
1315
- if ( params.map !== undefined ) {
1316
-
1317
- if ( ! params.transparent ) {
1318
-
1319
- this._checkImageTransparency( params.map, geometry, i );
1320
-
1321
- }
1322
-
1323
- params.emissive.multiplyScalar( 0.2 );
1324
-
1325
- }
1326
-
1327
- materials.push( new MMDToonMaterial( params ) );
1328
-
1329
- }
1330
-
1331
- if ( data.metadata.format === 'pmx' ) {
1332
-
1333
- // set transparent true if alpha morph is defined.
1334
-
1335
- function checkAlphaMorph( elements, materials ) {
1336
-
1337
- for ( let i = 0, il = elements.length; i < il; i ++ ) {
1338
-
1339
- const element = elements[ i ];
1340
-
1341
- if ( element.index === - 1 ) continue;
1342
-
1343
- const material = materials[ element.index ];
1344
-
1345
- if ( material.opacity !== element.diffuse[ 3 ] ) {
1346
-
1347
- material.transparent = true;
1348
-
1349
- }
1350
-
1351
- }
1352
-
1353
- }
1354
-
1355
- for ( let i = 0, il = data.morphs.length; i < il; i ++ ) {
1356
-
1357
- const morph = data.morphs[ i ];
1358
- const elements = morph.elements;
1359
-
1360
- if ( morph.type === 0 ) {
1361
-
1362
- for ( let j = 0, jl = elements.length; j < jl; j ++ ) {
1363
-
1364
- const morph2 = data.morphs[ elements[ j ].index ];
1365
-
1366
- if ( morph2.type !== 8 ) continue;
1367
-
1368
- checkAlphaMorph( morph2.elements, materials );
1369
-
1370
- }
1371
-
1372
- } else if ( morph.type === 8 ) {
1373
-
1374
- checkAlphaMorph( elements, materials );
1375
-
1376
- }
1377
-
1378
- }
1379
-
1380
- }
1381
-
1382
- return materials;
1383
-
1384
- }
1385
-
1386
- // private methods
1387
-
1388
- _getTGALoader() {
1389
-
1390
- if ( this.tgaLoader === null ) {
1391
-
1392
- if ( TGALoader === undefined ) {
1393
-
1394
- throw new Error( 'THREE.MMDLoader: Import TGALoader' );
1395
-
1396
- }
1397
-
1398
- this.tgaLoader = new TGALoader( this.manager );
1399
-
1400
- }
1401
-
1402
- return this.tgaLoader;
1403
-
1404
- }
1405
-
1406
- _isDefaultToonTexture( name ) {
1407
-
1408
- if ( name.length !== 10 ) return false;
1409
-
1410
- return /toon(10|0[0-9])\.bmp/.test( name );
1411
-
1412
- }
1413
-
1414
- _loadTexture( filePath, textures, params, onProgress, onError ) {
1415
-
1416
- params = params || {};
1417
-
1418
- const scope = this;
1419
-
1420
- let fullPath;
1421
-
1422
- if ( params.isDefaultToonTexture === true ) {
1423
-
1424
- let index;
1425
-
1426
- try {
1427
-
1428
- index = parseInt( filePath.match( /toon([0-9]{2})\.bmp$/ )[ 1 ] );
1429
-
1430
- } catch ( e ) {
1431
-
1432
- console.warn( 'THREE.MMDLoader: ' + filePath + ' seems like a '
1433
- + 'not right default texture path. Using toon00.bmp instead.' );
1434
-
1435
- index = 0;
1436
-
1437
- }
1438
-
1439
- fullPath = DEFAULT_TOON_TEXTURES[ index ];
1440
-
1441
- } else {
1442
-
1443
- fullPath = this.resourcePath + filePath;
1444
-
1445
- }
1446
-
1447
- if ( textures[ fullPath ] !== undefined ) return textures[ fullPath ];
1448
-
1449
- let loader = this.manager.getHandler( fullPath );
1450
-
1451
- if ( loader === null ) {
1452
-
1453
- loader = ( filePath.slice( - 4 ).toLowerCase() === '.tga' )
1454
- ? this._getTGALoader()
1455
- : this.textureLoader;
1456
-
1457
- }
1458
-
1459
- const texture = loader.load( fullPath, function ( t ) {
1460
-
1461
- // MMD toon texture is Axis-Y oriented
1462
- // but Three.js gradient map is Axis-X oriented.
1463
- // So here replaces the toon texture image with the rotated one.
1464
- if ( params.isToonTexture === true ) {
1465
-
1466
- t.image = scope._getRotatedImage( t.image );
1467
-
1468
- t.magFilter = NearestFilter;
1469
- t.minFilter = NearestFilter;
1470
-
1471
- }
1472
-
1473
- t.flipY = false;
1474
- t.wrapS = RepeatWrapping;
1475
- t.wrapT = RepeatWrapping;
1476
- t.colorSpace = SRGBColorSpace;
1477
-
1478
- for ( let i = 0; i < texture.readyCallbacks.length; i ++ ) {
1479
-
1480
- texture.readyCallbacks[ i ]( texture );
1481
-
1482
- }
1483
-
1484
- delete texture.readyCallbacks;
1485
-
1486
- }, onProgress, onError );
1487
-
1488
- texture.readyCallbacks = [];
1489
-
1490
- textures[ fullPath ] = texture;
1491
-
1492
- return texture;
1493
-
1494
- }
1495
-
1496
- _getRotatedImage( image ) {
1497
-
1498
- const canvas = document.createElement( 'canvas' );
1499
- const context = canvas.getContext( '2d' );
1500
-
1501
- const width = image.width;
1502
- const height = image.height;
1503
-
1504
- canvas.width = width;
1505
- canvas.height = height;
1506
-
1507
- context.clearRect( 0, 0, width, height );
1508
- context.translate( width / 2.0, height / 2.0 );
1509
- context.rotate( 0.5 * Math.PI ); // 90.0 * Math.PI / 180.0
1510
- context.translate( - width / 2.0, - height / 2.0 );
1511
- context.drawImage( image, 0, 0 );
1512
-
1513
- return context.getImageData( 0, 0, width, height );
1514
-
1515
- }
1516
-
1517
- // Check if the partial image area used by the texture is transparent.
1518
- _checkImageTransparency( map, geometry, groupIndex ) {
1519
-
1520
- map.readyCallbacks.push( function ( texture ) {
1521
-
1522
- // Is there any efficient ways?
1523
- function createImageData( image ) {
1524
-
1525
- const canvas = document.createElement( 'canvas' );
1526
- canvas.width = image.width;
1527
- canvas.height = image.height;
1528
-
1529
- const context = canvas.getContext( '2d' );
1530
- context.drawImage( image, 0, 0 );
1531
-
1532
- return context.getImageData( 0, 0, canvas.width, canvas.height );
1533
-
1534
- }
1535
-
1536
- function detectImageTransparency( image, uvs, indices ) {
1537
-
1538
- const width = image.width;
1539
- const height = image.height;
1540
- const data = image.data;
1541
- const threshold = 253;
1542
-
1543
- if ( data.length / ( width * height ) !== 4 ) return false;
1544
-
1545
- for ( let i = 0; i < indices.length; i += 3 ) {
1546
-
1547
- const centerUV = { x: 0.0, y: 0.0 };
1548
-
1549
- for ( let j = 0; j < 3; j ++ ) {
1550
-
1551
- const index = indices[ i * 3 + j ];
1552
- const uv = { x: uvs[ index * 2 + 0 ], y: uvs[ index * 2 + 1 ] };
1553
-
1554
- if ( getAlphaByUv( image, uv ) < threshold ) return true;
1555
-
1556
- centerUV.x += uv.x;
1557
- centerUV.y += uv.y;
1558
-
1559
- }
1560
-
1561
- centerUV.x /= 3;
1562
- centerUV.y /= 3;
1563
-
1564
- if ( getAlphaByUv( image, centerUV ) < threshold ) return true;
1565
-
1566
- }
1567
-
1568
- return false;
1569
-
1570
- }
1571
-
1572
- /*
1573
- * This method expects
1574
- * texture.flipY = false
1575
- * texture.wrapS = RepeatWrapping
1576
- * texture.wrapT = RepeatWrapping
1577
- * TODO: more precise
1578
- */
1579
- function getAlphaByUv( image, uv ) {
1580
-
1581
- const width = image.width;
1582
- const height = image.height;
1583
-
1584
- let x = Math.round( uv.x * width ) % width;
1585
- let y = Math.round( uv.y * height ) % height;
1586
-
1587
- if ( x < 0 ) x += width;
1588
- if ( y < 0 ) y += height;
1589
-
1590
- const index = y * width + x;
1591
-
1592
- return image.data[ index * 4 + 3 ];
1593
-
1594
- }
1595
-
1596
- if ( texture.isCompressedTexture === true ) {
1597
-
1598
- if ( NON_ALPHA_CHANNEL_FORMATS.includes( texture.format ) ) {
1599
-
1600
- map.transparent = false;
1601
-
1602
- } else {
1603
-
1604
- // any other way to check transparency of CompressedTexture?
1605
- map.transparent = true;
1606
-
1607
- }
1608
-
1609
- return;
1610
-
1611
- }
1612
-
1613
- const imageData = texture.image.data !== undefined
1614
- ? texture.image
1615
- : createImageData( texture.image );
1616
-
1617
- const group = geometry.groups[ groupIndex ];
1618
-
1619
- if ( detectImageTransparency(
1620
- imageData,
1621
- geometry.attributes.uv.array,
1622
- geometry.index.array.slice( group.start, group.start + group.count ) ) ) {
1623
-
1624
- map.transparent = true;
1625
-
1626
- }
1627
-
1628
- } );
1629
-
1630
- }
1631
-
1632
- }
1633
-
1634
- //
1635
-
1636
- class AnimationBuilder {
1637
-
1638
- /**
1639
- * @param {Object} vmd - parsed VMD data
1640
- * @param {SkinnedMesh} mesh - tracks will be fitting to mesh
1641
- * @return {AnimationClip}
1642
- */
1643
- build( vmd, mesh ) {
1644
-
1645
- // combine skeletal and morph animations
1646
-
1647
- const tracks = this.buildSkeletalAnimation( vmd, mesh ).tracks;
1648
- const tracks2 = this.buildMorphAnimation( vmd, mesh ).tracks;
1649
-
1650
- for ( let i = 0, il = tracks2.length; i < il; i ++ ) {
1651
-
1652
- tracks.push( tracks2[ i ] );
1653
-
1654
- }
1655
-
1656
- return new AnimationClip( '', - 1, tracks );
1657
-
1658
- }
1659
-
1660
- /**
1661
- * @param {Object} vmd - parsed VMD data
1662
- * @param {SkinnedMesh} mesh - tracks will be fitting to mesh
1663
- * @return {AnimationClip}
1664
- */
1665
- buildSkeletalAnimation( vmd, mesh ) {
1666
-
1667
- function pushInterpolation( array, interpolation, index ) {
1668
-
1669
- array.push( interpolation[ index + 0 ] / 127 ); // x1
1670
- array.push( interpolation[ index + 8 ] / 127 ); // x2
1671
- array.push( interpolation[ index + 4 ] / 127 ); // y1
1672
- array.push( interpolation[ index + 12 ] / 127 ); // y2
1673
-
1674
- }
1675
-
1676
- const tracks = [];
1677
-
1678
- const motions = {};
1679
- const bones = mesh.skeleton.bones;
1680
- const boneNameDictionary = {};
1681
-
1682
- for ( let i = 0, il = bones.length; i < il; i ++ ) {
1683
-
1684
- boneNameDictionary[ bones[ i ].name ] = true;
1685
-
1686
- }
1687
-
1688
- for ( let i = 0; i < vmd.metadata.motionCount; i ++ ) {
1689
-
1690
- const motion = vmd.motions[ i ];
1691
- const boneName = motion.boneName;
1692
-
1693
- if ( boneNameDictionary[ boneName ] === undefined ) continue;
1694
-
1695
- motions[ boneName ] = motions[ boneName ] || [];
1696
- motions[ boneName ].push( motion );
1697
-
1698
- }
1699
-
1700
- for ( const key in motions ) {
1701
-
1702
- const array = motions[ key ];
1703
-
1704
- array.sort( function ( a, b ) {
1705
-
1706
- return a.frameNum - b.frameNum;
1707
-
1708
- } );
1709
-
1710
- const times = [];
1711
- const positions = [];
1712
- const rotations = [];
1713
- const pInterpolations = [];
1714
- const rInterpolations = [];
1715
-
1716
- const basePosition = mesh.skeleton.getBoneByName( key ).position.toArray();
1717
-
1718
- for ( let i = 0, il = array.length; i < il; i ++ ) {
1719
-
1720
- const time = array[ i ].frameNum / 30;
1721
- const position = array[ i ].position;
1722
- const rotation = array[ i ].rotation;
1723
- const interpolation = array[ i ].interpolation;
1724
-
1725
- times.push( time );
1726
-
1727
- for ( let j = 0; j < 3; j ++ ) positions.push( basePosition[ j ] + position[ j ] );
1728
- for ( let j = 0; j < 4; j ++ ) rotations.push( rotation[ j ] );
1729
- for ( let j = 0; j < 3; j ++ ) pushInterpolation( pInterpolations, interpolation, j );
1730
-
1731
- pushInterpolation( rInterpolations, interpolation, 3 );
1732
-
1733
- }
1734
-
1735
- const targetName = '.bones[' + key + ']';
1736
-
1737
- tracks.push( this._createTrack( targetName + '.position', VectorKeyframeTrack, times, positions, pInterpolations ) );
1738
- tracks.push( this._createTrack( targetName + '.quaternion', QuaternionKeyframeTrack, times, rotations, rInterpolations ) );
1739
-
1740
- }
1741
-
1742
- return new AnimationClip( '', - 1, tracks );
1743
-
1744
- }
1745
-
1746
- /**
1747
- * @param {Object} vmd - parsed VMD data
1748
- * @param {SkinnedMesh} mesh - tracks will be fitting to mesh
1749
- * @return {AnimationClip}
1750
- */
1751
- buildMorphAnimation( vmd, mesh ) {
1752
-
1753
- const tracks = [];
1754
-
1755
- const morphs = {};
1756
- const morphTargetDictionary = mesh.morphTargetDictionary;
1757
-
1758
- for ( let i = 0; i < vmd.metadata.morphCount; i ++ ) {
1759
-
1760
- const morph = vmd.morphs[ i ];
1761
- const morphName = morph.morphName;
1762
-
1763
- if ( morphTargetDictionary[ morphName ] === undefined ) continue;
1764
-
1765
- morphs[ morphName ] = morphs[ morphName ] || [];
1766
- morphs[ morphName ].push( morph );
1767
-
1768
- }
1769
-
1770
- for ( const key in morphs ) {
1771
-
1772
- const array = morphs[ key ];
1773
-
1774
- array.sort( function ( a, b ) {
1775
-
1776
- return a.frameNum - b.frameNum;
1777
-
1778
- } );
1779
-
1780
- const times = [];
1781
- const values = [];
1782
-
1783
- for ( let i = 0, il = array.length; i < il; i ++ ) {
1784
-
1785
- times.push( array[ i ].frameNum / 30 );
1786
- values.push( array[ i ].weight );
1787
-
1788
- }
1789
-
1790
- tracks.push( new NumberKeyframeTrack( '.morphTargetInfluences[' + morphTargetDictionary[ key ] + ']', times, values ) );
1791
-
1792
- }
1793
-
1794
- return new AnimationClip( '', - 1, tracks );
1795
-
1796
- }
1797
-
1798
- /**
1799
- * @param {Object} vmd - parsed VMD data
1800
- * @return {AnimationClip}
1801
- */
1802
- buildCameraAnimation( vmd ) {
1803
-
1804
- function pushVector3( array, vec ) {
1805
-
1806
- array.push( vec.x );
1807
- array.push( vec.y );
1808
- array.push( vec.z );
1809
-
1810
- }
1811
-
1812
- function pushQuaternion( array, q ) {
1813
-
1814
- array.push( q.x );
1815
- array.push( q.y );
1816
- array.push( q.z );
1817
- array.push( q.w );
1818
-
1819
- }
1820
-
1821
- function pushInterpolation( array, interpolation, index ) {
1822
-
1823
- array.push( interpolation[ index * 4 + 0 ] / 127 ); // x1
1824
- array.push( interpolation[ index * 4 + 1 ] / 127 ); // x2
1825
- array.push( interpolation[ index * 4 + 2 ] / 127 ); // y1
1826
- array.push( interpolation[ index * 4 + 3 ] / 127 ); // y2
1827
-
1828
- }
1829
-
1830
- const cameras = vmd.cameras === undefined ? [] : vmd.cameras.slice();
1831
-
1832
- cameras.sort( function ( a, b ) {
1833
-
1834
- return a.frameNum - b.frameNum;
1835
-
1836
- } );
1837
-
1838
- const times = [];
1839
- const centers = [];
1840
- const quaternions = [];
1841
- const positions = [];
1842
- const fovs = [];
1843
-
1844
- const cInterpolations = [];
1845
- const qInterpolations = [];
1846
- const pInterpolations = [];
1847
- const fInterpolations = [];
1848
-
1849
- const quaternion = new Quaternion();
1850
- const euler = new Euler();
1851
- const position = new Vector3();
1852
- const center = new Vector3();
1853
-
1854
- for ( let i = 0, il = cameras.length; i < il; i ++ ) {
1855
-
1856
- const motion = cameras[ i ];
1857
-
1858
- const time = motion.frameNum / 30;
1859
- const pos = motion.position;
1860
- const rot = motion.rotation;
1861
- const distance = motion.distance;
1862
- const fov = motion.fov;
1863
- const interpolation = motion.interpolation;
1864
-
1865
- times.push( time );
1866
-
1867
- position.set( 0, 0, - distance );
1868
- center.set( pos[ 0 ], pos[ 1 ], pos[ 2 ] );
1869
-
1870
- euler.set( - rot[ 0 ], - rot[ 1 ], - rot[ 2 ] );
1871
- quaternion.setFromEuler( euler );
1872
-
1873
- position.add( center );
1874
- position.applyQuaternion( quaternion );
1875
-
1876
- pushVector3( centers, center );
1877
- pushQuaternion( quaternions, quaternion );
1878
- pushVector3( positions, position );
1879
-
1880
- fovs.push( fov );
1881
-
1882
- for ( let j = 0; j < 3; j ++ ) {
1883
-
1884
- pushInterpolation( cInterpolations, interpolation, j );
1885
-
1886
- }
1887
-
1888
- pushInterpolation( qInterpolations, interpolation, 3 );
1889
-
1890
- // use the same parameter for x, y, z axis.
1891
- for ( let j = 0; j < 3; j ++ ) {
1892
-
1893
- pushInterpolation( pInterpolations, interpolation, 4 );
1894
-
1895
- }
1896
-
1897
- pushInterpolation( fInterpolations, interpolation, 5 );
1898
-
1899
- }
1900
-
1901
- const tracks = [];
1902
-
1903
- // I expect an object whose name 'target' exists under THREE.Camera
1904
- tracks.push( this._createTrack( 'target.position', VectorKeyframeTrack, times, centers, cInterpolations ) );
1905
-
1906
- tracks.push( this._createTrack( '.quaternion', QuaternionKeyframeTrack, times, quaternions, qInterpolations ) );
1907
- tracks.push( this._createTrack( '.position', VectorKeyframeTrack, times, positions, pInterpolations ) );
1908
- tracks.push( this._createTrack( '.fov', NumberKeyframeTrack, times, fovs, fInterpolations ) );
1909
-
1910
- return new AnimationClip( '', - 1, tracks );
1911
-
1912
- }
1913
-
1914
- // private method
1915
-
1916
- _createTrack( node, typedKeyframeTrack, times, values, interpolations ) {
1917
-
1918
- /*
1919
- * optimizes here not to let KeyframeTrackPrototype optimize
1920
- * because KeyframeTrackPrototype optimizes times and values but
1921
- * doesn't optimize interpolations.
1922
- */
1923
- if ( times.length > 2 ) {
1924
-
1925
- times = times.slice();
1926
- values = values.slice();
1927
- interpolations = interpolations.slice();
1928
-
1929
- const stride = values.length / times.length;
1930
- const interpolateStride = interpolations.length / times.length;
1931
-
1932
- let index = 1;
1933
-
1934
- for ( let aheadIndex = 2, endIndex = times.length; aheadIndex < endIndex; aheadIndex ++ ) {
1935
-
1936
- for ( let i = 0; i < stride; i ++ ) {
1937
-
1938
- if ( values[ index * stride + i ] !== values[ ( index - 1 ) * stride + i ] ||
1939
- values[ index * stride + i ] !== values[ aheadIndex * stride + i ] ) {
1940
-
1941
- index ++;
1942
- break;
1943
-
1944
- }
1945
-
1946
- }
1947
-
1948
- if ( aheadIndex > index ) {
1949
-
1950
- times[ index ] = times[ aheadIndex ];
1951
-
1952
- for ( let i = 0; i < stride; i ++ ) {
1953
-
1954
- values[ index * stride + i ] = values[ aheadIndex * stride + i ];
1955
-
1956
- }
1957
-
1958
- for ( let i = 0; i < interpolateStride; i ++ ) {
1959
-
1960
- interpolations[ index * interpolateStride + i ] = interpolations[ aheadIndex * interpolateStride + i ];
1961
-
1962
- }
1963
-
1964
- }
1965
-
1966
- }
1967
-
1968
- times.length = index + 1;
1969
- values.length = ( index + 1 ) * stride;
1970
- interpolations.length = ( index + 1 ) * interpolateStride;
1971
-
1972
- }
1973
-
1974
- const track = new typedKeyframeTrack( node, times, values );
1975
-
1976
- track.createInterpolant = function InterpolantFactoryMethodCubicBezier( result ) {
1977
-
1978
- return new CubicBezierInterpolation( this.times, this.values, this.getValueSize(), result, new Float32Array( interpolations ) );
1979
-
1980
- };
1981
-
1982
- return track;
1983
-
1984
- }
1985
-
1986
- }
1987
-
1988
- // interpolation
1989
-
1990
- class CubicBezierInterpolation extends Interpolant {
1991
-
1992
- constructor( parameterPositions, sampleValues, sampleSize, resultBuffer, params ) {
1993
-
1994
- super( parameterPositions, sampleValues, sampleSize, resultBuffer );
1995
-
1996
- this.interpolationParams = params;
1997
-
1998
- }
1999
-
2000
- interpolate_( i1, t0, t, t1 ) {
2001
-
2002
- const result = this.resultBuffer;
2003
- const values = this.sampleValues;
2004
- const stride = this.valueSize;
2005
- const params = this.interpolationParams;
2006
-
2007
- const offset1 = i1 * stride;
2008
- const offset0 = offset1 - stride;
2009
-
2010
- // No interpolation if next key frame is in one frame in 30fps.
2011
- // This is from MMD animation spec.
2012
- // '1.5' is for precision loss. times are Float32 in Three.js Animation system.
2013
- const weight1 = ( ( t1 - t0 ) < 1 / 30 * 1.5 ) ? 0.0 : ( t - t0 ) / ( t1 - t0 );
2014
-
2015
- if ( stride === 4 ) { // Quaternion
2016
-
2017
- const x1 = params[ i1 * 4 + 0 ];
2018
- const x2 = params[ i1 * 4 + 1 ];
2019
- const y1 = params[ i1 * 4 + 2 ];
2020
- const y2 = params[ i1 * 4 + 3 ];
2021
-
2022
- const ratio = this._calculate( x1, x2, y1, y2, weight1 );
2023
-
2024
- Quaternion.slerpFlat( result, 0, values, offset0, values, offset1, ratio );
2025
-
2026
- } else if ( stride === 3 ) { // Vector3
2027
-
2028
- for ( let i = 0; i !== stride; ++ i ) {
2029
-
2030
- const x1 = params[ i1 * 12 + i * 4 + 0 ];
2031
- const x2 = params[ i1 * 12 + i * 4 + 1 ];
2032
- const y1 = params[ i1 * 12 + i * 4 + 2 ];
2033
- const y2 = params[ i1 * 12 + i * 4 + 3 ];
2034
-
2035
- const ratio = this._calculate( x1, x2, y1, y2, weight1 );
2036
-
2037
- result[ i ] = values[ offset0 + i ] * ( 1 - ratio ) + values[ offset1 + i ] * ratio;
2038
-
2039
- }
2040
-
2041
- } else { // Number
2042
-
2043
- const x1 = params[ i1 * 4 + 0 ];
2044
- const x2 = params[ i1 * 4 + 1 ];
2045
- const y1 = params[ i1 * 4 + 2 ];
2046
- const y2 = params[ i1 * 4 + 3 ];
2047
-
2048
- const ratio = this._calculate( x1, x2, y1, y2, weight1 );
2049
-
2050
- result[ 0 ] = values[ offset0 ] * ( 1 - ratio ) + values[ offset1 ] * ratio;
2051
-
2052
- }
2053
-
2054
- return result;
2055
-
2056
- }
2057
-
2058
- _calculate( x1, x2, y1, y2, x ) {
2059
-
2060
- /*
2061
- * Cubic Bezier curves
2062
- * https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves
2063
- *
2064
- * B(t) = ( 1 - t ) ^ 3 * P0
2065
- * + 3 * ( 1 - t ) ^ 2 * t * P1
2066
- * + 3 * ( 1 - t ) * t^2 * P2
2067
- * + t ^ 3 * P3
2068
- * ( 0 <= t <= 1 )
2069
- *
2070
- * MMD uses Cubic Bezier curves for bone and camera animation interpolation.
2071
- * http://d.hatena.ne.jp/edvakf/20111016/1318716097
2072
- *
2073
- * x = ( 1 - t ) ^ 3 * x0
2074
- * + 3 * ( 1 - t ) ^ 2 * t * x1
2075
- * + 3 * ( 1 - t ) * t^2 * x2
2076
- * + t ^ 3 * x3
2077
- * y = ( 1 - t ) ^ 3 * y0
2078
- * + 3 * ( 1 - t ) ^ 2 * t * y1
2079
- * + 3 * ( 1 - t ) * t^2 * y2
2080
- * + t ^ 3 * y3
2081
- * ( x0 = 0, y0 = 0 )
2082
- * ( x3 = 1, y3 = 1 )
2083
- * ( 0 <= t, x1, x2, y1, y2 <= 1 )
2084
- *
2085
- * Here solves this equation with Bisection method,
2086
- * https://en.wikipedia.org/wiki/Bisection_method
2087
- * gets t, and then calculate y.
2088
- *
2089
- * f(t) = 3 * ( 1 - t ) ^ 2 * t * x1
2090
- * + 3 * ( 1 - t ) * t^2 * x2
2091
- * + t ^ 3 - x = 0
2092
- *
2093
- * (Another option: Newton's method
2094
- * https://en.wikipedia.org/wiki/Newton%27s_method)
2095
- */
2096
-
2097
- let c = 0.5;
2098
- let t = c;
2099
- let s = 1.0 - t;
2100
- const loop = 15;
2101
- const eps = 1e-5;
2102
- const math = Math;
2103
-
2104
- let sst3, stt3, ttt;
2105
-
2106
- for ( let i = 0; i < loop; i ++ ) {
2107
-
2108
- sst3 = 3.0 * s * s * t;
2109
- stt3 = 3.0 * s * t * t;
2110
- ttt = t * t * t;
2111
-
2112
- const ft = ( sst3 * x1 ) + ( stt3 * x2 ) + ( ttt ) - x;
2113
-
2114
- if ( math.abs( ft ) < eps ) break;
2115
-
2116
- c /= 2.0;
2117
-
2118
- t += ( ft < 0 ) ? c : - c;
2119
- s = 1.0 - t;
2120
-
2121
- }
2122
-
2123
- return ( sst3 * y1 ) + ( stt3 * y2 ) + ttt;
2124
-
2125
- }
2126
-
2127
- }
2128
-
2129
- class MMDToonMaterial extends ShaderMaterial {
2130
-
2131
- constructor( parameters ) {
2132
-
2133
- super();
2134
-
2135
- this.isMMDToonMaterial = true;
2136
-
2137
- this.type = 'MMDToonMaterial';
2138
-
2139
- this._matcapCombine = AddOperation;
2140
- this.emissiveIntensity = 1.0;
2141
- this.normalMapType = TangentSpaceNormalMap;
2142
-
2143
- this.combine = MultiplyOperation;
2144
-
2145
- this.wireframeLinecap = 'round';
2146
- this.wireframeLinejoin = 'round';
2147
-
2148
- this.flatShading = false;
2149
-
2150
- this.lights = true;
2151
-
2152
- this.vertexShader = MMDToonShader.vertexShader;
2153
- this.fragmentShader = MMDToonShader.fragmentShader;
2154
-
2155
- this.defines = Object.assign( {}, MMDToonShader.defines );
2156
- Object.defineProperty( this, 'matcapCombine', {
2157
-
2158
- get: function () {
2159
-
2160
- return this._matcapCombine;
2161
-
2162
- },
2163
-
2164
- set: function ( value ) {
2165
-
2166
- this._matcapCombine = value;
2167
-
2168
- switch ( value ) {
2169
-
2170
- case MultiplyOperation:
2171
- this.defines.MATCAP_BLENDING_MULTIPLY = true;
2172
- delete this.defines.MATCAP_BLENDING_ADD;
2173
- break;
2174
-
2175
- default:
2176
- case AddOperation:
2177
- this.defines.MATCAP_BLENDING_ADD = true;
2178
- delete this.defines.MATCAP_BLENDING_MULTIPLY;
2179
- break;
2180
-
2181
- }
2182
-
2183
- },
2184
-
2185
- } );
2186
-
2187
- this.uniforms = UniformsUtils.clone( MMDToonShader.uniforms );
2188
-
2189
- // merged from MeshToon/Phong/MatcapMaterial
2190
- const exposePropertyNames = [
2191
- 'specular',
2192
- 'opacity',
2193
- 'diffuse',
2194
-
2195
- 'map',
2196
- 'matcap',
2197
- 'gradientMap',
2198
-
2199
- 'lightMap',
2200
- 'lightMapIntensity',
2201
-
2202
- 'aoMap',
2203
- 'aoMapIntensity',
2204
-
2205
- 'emissive',
2206
- 'emissiveMap',
2207
-
2208
- 'bumpMap',
2209
- 'bumpScale',
2210
-
2211
- 'normalMap',
2212
- 'normalScale',
2213
-
2214
- 'displacemantBias',
2215
- 'displacemantMap',
2216
- 'displacemantScale',
2217
-
2218
- 'specularMap',
2219
-
2220
- 'alphaMap',
2221
-
2222
- 'reflectivity',
2223
- 'refractionRatio',
2224
- ];
2225
- for ( const propertyName of exposePropertyNames ) {
2226
-
2227
- Object.defineProperty( this, propertyName, {
2228
-
2229
- get: function () {
2230
-
2231
- return this.uniforms[ propertyName ].value;
2232
-
2233
- },
2234
-
2235
- set: function ( value ) {
2236
-
2237
- this.uniforms[ propertyName ].value = value;
2238
-
2239
- },
2240
-
2241
- } );
2242
-
2243
- }
2244
-
2245
- // Special path for shininess to handle zero shininess properly
2246
- this._shininess = 30;
2247
- Object.defineProperty( this, 'shininess', {
2248
-
2249
- get: function () {
2250
-
2251
- return this._shininess;
2252
-
2253
- },
2254
-
2255
- set: function ( value ) {
2256
-
2257
- this._shininess = value;
2258
- this.uniforms.shininess.value = Math.max( this._shininess, 1e-4 ); // To prevent pow( 0.0, 0.0 )
2259
-
2260
- },
2261
-
2262
- } );
2263
-
2264
- Object.defineProperty(
2265
- this,
2266
- 'color',
2267
- Object.getOwnPropertyDescriptor( this, 'diffuse' )
2268
- );
2269
-
2270
- this.setValues( parameters );
2271
-
2272
- }
2273
-
2274
- copy( source ) {
2275
-
2276
- super.copy( source );
2277
-
2278
- this.matcapCombine = source.matcapCombine;
2279
- this.emissiveIntensity = source.emissiveIntensity;
2280
- this.normalMapType = source.normalMapType;
2281
-
2282
- this.combine = source.combine;
2283
-
2284
- this.wireframeLinecap = source.wireframeLinecap;
2285
- this.wireframeLinejoin = source.wireframeLinejoin;
2286
-
2287
- this.flatShading = source.flatShading;
2288
-
2289
- return this;
2290
-
2291
- }
2292
-
2293
- }
2294
-
2295
- export { MMDLoader };