super-three 0.171.0 → 0.173.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 (455) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/build/three.cjs +594 -427
  4. package/build/three.core.js +515 -81
  5. package/build/three.core.min.js +2 -2
  6. package/build/three.module.js +79 -350
  7. package/build/three.module.min.js +2 -2
  8. package/build/three.tsl.js +20 -7
  9. package/build/three.tsl.min.js +2 -2
  10. package/build/three.webgpu.js +29362 -3427
  11. package/build/three.webgpu.min.js +2 -2
  12. package/build/three.webgpu.nodes.js +29361 -3427
  13. package/build/three.webgpu.nodes.min.js +2 -2
  14. package/examples/jsm/Addons.js +0 -5
  15. package/examples/jsm/animation/CCDIKSolver.js +9 -7
  16. package/examples/jsm/capabilities/WebGPU.js +1 -1
  17. package/examples/jsm/controls/ArcballControls.js +48 -37
  18. package/examples/jsm/controls/OrbitControls.js +5 -4
  19. package/examples/jsm/csm/CSMShadowNode.js +16 -11
  20. package/examples/jsm/curves/NURBSCurve.js +1 -1
  21. package/examples/jsm/curves/NURBSUtils.js +3 -0
  22. package/examples/jsm/effects/OutlineEffect.js +1 -1
  23. package/examples/jsm/exporters/GLTFExporter.js +34 -29
  24. package/examples/jsm/exporters/KTX2Exporter.js +1 -1
  25. package/examples/jsm/exporters/PLYExporter.js +2 -2
  26. package/examples/jsm/geometries/TextGeometry.js +1 -12
  27. package/examples/jsm/helpers/TextureHelperGPU.js +15 -5
  28. package/examples/jsm/helpers/VertexNormalsHelper.js +2 -0
  29. package/examples/jsm/interactive/InteractiveGroup.js +108 -51
  30. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  31. package/examples/jsm/lights/LightProbeGenerator.js +3 -3
  32. package/examples/jsm/lines/webgpu/LineSegments2.js +15 -6
  33. package/examples/jsm/loaders/3MFLoader.js +6 -3
  34. package/examples/jsm/loaders/BVHLoader.js +1 -1
  35. package/examples/jsm/loaders/ColladaLoader.js +5 -5
  36. package/examples/jsm/loaders/DDSLoader.js +42 -0
  37. package/examples/jsm/loaders/GCodeLoader.js +4 -2
  38. package/examples/jsm/loaders/GLTFLoader.js +22 -4
  39. package/examples/jsm/loaders/KTX2Loader.js +6 -1
  40. package/examples/jsm/loaders/KTXLoader.js +4 -4
  41. package/examples/jsm/loaders/LDrawLoader.js +1 -1
  42. package/examples/jsm/loaders/LottieLoader.js +1 -1
  43. package/examples/jsm/loaders/MTLLoader.js +1 -0
  44. package/examples/jsm/loaders/NRRDLoader.js +1 -1
  45. package/examples/jsm/loaders/PLYLoader.js +7 -7
  46. package/examples/jsm/loaders/PVRLoader.js +1 -1
  47. package/examples/jsm/loaders/SVGLoader.js +2 -2
  48. package/examples/jsm/loaders/TDSLoader.js +1 -2
  49. package/examples/jsm/loaders/VRMLLoader.js +7 -7
  50. package/examples/jsm/loaders/lwo/IFFParser.js +4 -4
  51. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +1 -1
  52. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
  53. package/examples/jsm/math/ConvexHull.js +1 -1
  54. package/examples/jsm/math/OBB.js +17 -0
  55. package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
  56. package/examples/jsm/misc/ProgressiveLightMap.js +4 -3
  57. package/examples/jsm/misc/ProgressiveLightMapGPU.js +14 -13
  58. package/examples/jsm/misc/Volume.js +27 -17
  59. package/examples/jsm/misc/VolumeSlice.js +7 -5
  60. package/examples/jsm/modifiers/CurveModifier.js +10 -8
  61. package/examples/jsm/modifiers/CurveModifierGPU.js +9 -7
  62. package/examples/jsm/modifiers/SimplifyModifier.js +2 -2
  63. package/examples/jsm/objects/GroundedSkybox.js +4 -4
  64. package/examples/jsm/objects/Sky.js +2 -2
  65. package/examples/jsm/objects/SkyMesh.js +3 -3
  66. package/examples/jsm/objects/Water2.js +1 -1
  67. package/examples/jsm/objects/Water2Mesh.js +2 -2
  68. package/examples/jsm/objects/WaterMesh.js +29 -24
  69. package/examples/jsm/physics/JoltPhysics.js +7 -7
  70. package/examples/jsm/physics/RapierPhysics.js +4 -4
  71. package/examples/jsm/postprocessing/BloomPass.js +2 -2
  72. package/examples/jsm/postprocessing/EffectComposer.js +1 -2
  73. package/examples/jsm/postprocessing/OutlinePass.js +4 -4
  74. package/examples/jsm/postprocessing/OutputPass.js +2 -0
  75. package/examples/jsm/postprocessing/SAOPass.js +1 -2
  76. package/examples/jsm/postprocessing/SMAAPass.js +1 -3
  77. package/examples/jsm/postprocessing/SSAOPass.js +2 -4
  78. package/examples/jsm/postprocessing/SSRPass.js +2 -4
  79. package/examples/jsm/postprocessing/UnrealBloomPass.js +2 -2
  80. package/examples/jsm/renderers/SVGRenderer.js +6 -4
  81. package/examples/jsm/shaders/BokehShader2.js +1 -1
  82. package/examples/jsm/shaders/GodRaysShader.js +3 -3
  83. package/examples/jsm/shaders/OutputShader.js +5 -1
  84. package/examples/jsm/shaders/SobelOperatorShader.js +1 -1
  85. package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
  86. package/examples/jsm/transpiler/TSLEncoder.js +2 -0
  87. package/examples/jsm/tsl/display/AfterImageNode.js +93 -4
  88. package/examples/jsm/tsl/display/AnaglyphPassNode.js +46 -2
  89. package/examples/jsm/tsl/display/AnamorphicNode.js +118 -5
  90. package/examples/jsm/tsl/display/BleachBypass.js +10 -0
  91. package/examples/jsm/tsl/display/BloomNode.js +233 -26
  92. package/examples/jsm/tsl/display/DenoiseNode.js +141 -25
  93. package/examples/jsm/tsl/display/DepthOfFieldNode.js +80 -1
  94. package/examples/jsm/tsl/display/DotScreenNode.js +50 -5
  95. package/examples/jsm/tsl/display/FXAANode.js +52 -3
  96. package/examples/jsm/tsl/display/FilmNode.js +47 -1
  97. package/examples/jsm/tsl/display/GTAONode.js +210 -14
  98. package/examples/jsm/tsl/display/GaussianBlurNode.js +152 -8
  99. package/examples/jsm/tsl/display/LensflareNode.js +131 -13
  100. package/examples/jsm/tsl/display/Lut3DNode.js +55 -1
  101. package/examples/jsm/tsl/display/MotionBlur.js +12 -2
  102. package/examples/jsm/tsl/display/OutlineNode.js +343 -26
  103. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +36 -2
  104. package/examples/jsm/tsl/display/PixelationPassNode.js +142 -9
  105. package/examples/jsm/tsl/display/RGBShiftNode.js +49 -2
  106. package/examples/jsm/tsl/display/SMAANode.js +187 -46
  107. package/examples/jsm/tsl/display/SSAAPassNode.js +110 -25
  108. package/examples/jsm/tsl/display/SSRNode.js +194 -21
  109. package/examples/jsm/tsl/display/Sepia.js +9 -0
  110. package/examples/jsm/tsl/display/SobelOperatorNode.js +54 -4
  111. package/examples/jsm/tsl/display/StereoCompositePassNode.js +79 -3
  112. package/examples/jsm/tsl/display/StereoPassNode.js +41 -3
  113. package/examples/jsm/tsl/display/TRAAPassNode.js +116 -21
  114. package/examples/jsm/tsl/display/TransitionNode.js +71 -6
  115. package/examples/jsm/tsl/display/hashBlur.js +14 -3
  116. package/examples/jsm/tsl/lighting/TiledLightsNode.js +40 -34
  117. package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
  118. package/examples/jsm/utils/CameraUtils.js +4 -1
  119. package/examples/jsm/utils/GeometryUtils.js +22 -19
  120. package/examples/jsm/utils/SceneUtils.js +2 -2
  121. package/examples/jsm/webxr/XRControllerModelFactory.js +6 -1
  122. package/examples/jsm/webxr/XREstimatedLight.js +1 -1
  123. package/package.json +8 -3
  124. package/src/Three.Core.js +4 -0
  125. package/src/Three.Legacy.js +0 -21
  126. package/src/Three.TSL.js +18 -5
  127. package/src/Three.WebGPU.Nodes.js +2 -2
  128. package/src/Three.WebGPU.js +2 -2
  129. package/src/animation/PropertyBinding.js +2 -2
  130. package/src/cameras/ArrayCamera.js +1 -0
  131. package/src/cameras/PerspectiveCamera.js +18 -2
  132. package/src/constants.js +6 -1
  133. package/src/core/BufferAttribute.js +4 -0
  134. package/src/core/EventDispatcher.js +8 -6
  135. package/src/core/RenderTarget.js +18 -0
  136. package/src/core/RenderTarget3D.js +22 -0
  137. package/src/core/RenderTargetArray.js +22 -0
  138. package/src/extras/Earcut.js +1 -1
  139. package/src/extras/ImageUtils.js +1 -11
  140. package/src/extras/PMREMGenerator.js +20 -0
  141. package/src/extras/TextureUtils.js +6 -0
  142. package/src/helpers/CameraHelper.js +16 -13
  143. package/src/loaders/nodes/NodeLoader.js +59 -0
  144. package/src/loaders/nodes/NodeMaterialLoader.js +45 -0
  145. package/src/loaders/nodes/NodeObjectLoader.js +61 -0
  146. package/src/materials/nodes/Line2NodeMaterial.js +128 -34
  147. package/src/materials/nodes/LineBasicNodeMaterial.js +17 -2
  148. package/src/materials/nodes/LineDashedNodeMaterial.js +78 -5
  149. package/src/materials/nodes/MeshBasicNodeMaterial.js +56 -0
  150. package/src/materials/nodes/MeshLambertNodeMaterial.js +35 -0
  151. package/src/materials/nodes/MeshMatcapNodeMaterial.js +22 -2
  152. package/src/materials/nodes/MeshNormalNodeMaterial.js +21 -2
  153. package/src/materials/nodes/MeshPhongNodeMaterial.js +64 -1
  154. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +269 -0
  155. package/src/materials/nodes/MeshSSSNodeMaterial.js +97 -6
  156. package/src/materials/nodes/MeshStandardNodeMaterial.js +78 -0
  157. package/src/materials/nodes/MeshToonNodeMaterial.js +28 -0
  158. package/src/materials/nodes/NodeMaterial.js +476 -23
  159. package/src/materials/nodes/NodeMaterials.js +0 -1
  160. package/src/materials/nodes/PointsNodeMaterial.js +121 -10
  161. package/src/materials/nodes/ShadowNodeMaterial.js +29 -0
  162. package/src/materials/nodes/SpriteNodeMaterial.js +78 -20
  163. package/src/materials/nodes/VolumeNodeMaterial.js +80 -4
  164. package/src/materials/nodes/manager/NodeMaterialObserver.js +95 -0
  165. package/src/nodes/Nodes.js +5 -6
  166. package/src/nodes/TSL.js +6 -3
  167. package/src/nodes/accessors/AccessorsUtils.js +27 -0
  168. package/src/nodes/accessors/Arrays.js +47 -6
  169. package/src/nodes/accessors/BatchNode.js +42 -6
  170. package/src/nodes/accessors/Bitangent.js +37 -0
  171. package/src/nodes/accessors/BufferAttributeNode.js +178 -5
  172. package/src/nodes/accessors/BufferNode.js +63 -0
  173. package/src/nodes/accessors/BuiltinNode.js +38 -0
  174. package/src/nodes/accessors/Camera.js +113 -3
  175. package/src/nodes/accessors/ClippingNode.js +71 -2
  176. package/src/nodes/accessors/CubeTextureNode.js +64 -0
  177. package/src/nodes/accessors/InstanceNode.js +85 -2
  178. package/src/nodes/accessors/InstancedMeshNode.js +28 -3
  179. package/src/nodes/accessors/Lights.js +50 -1
  180. package/src/nodes/accessors/MaterialNode.js +306 -12
  181. package/src/nodes/accessors/MaterialProperties.js +7 -0
  182. package/src/nodes/accessors/MaterialReferenceNode.js +53 -13
  183. package/src/nodes/accessors/ModelNode.js +100 -5
  184. package/src/nodes/accessors/ModelViewProjectionNode.js +10 -38
  185. package/src/nodes/accessors/MorphNode.js +48 -4
  186. package/src/nodes/accessors/Normal.js +65 -5
  187. package/src/nodes/accessors/Object3DNode.js +101 -1
  188. package/src/nodes/accessors/PointUVNode.js +26 -0
  189. package/src/nodes/accessors/Position.js +56 -7
  190. package/src/nodes/accessors/ReferenceBaseNode.js +186 -0
  191. package/src/nodes/accessors/ReferenceNode.js +201 -2
  192. package/src/nodes/accessors/ReflectVector.js +24 -0
  193. package/src/nodes/accessors/RendererReferenceNode.js +46 -1
  194. package/src/nodes/accessors/SceneNode.js +54 -0
  195. package/src/nodes/accessors/SkinningNode.js +127 -1
  196. package/src/nodes/accessors/StorageBufferNode.js +209 -8
  197. package/src/nodes/accessors/StorageTextureNode.js +118 -0
  198. package/src/nodes/accessors/Tangent.js +38 -2
  199. package/src/nodes/accessors/Texture3DNode.js +91 -7
  200. package/src/nodes/accessors/TextureBicubic.js +12 -2
  201. package/src/nodes/accessors/TextureNode.js +316 -10
  202. package/src/nodes/accessors/TextureSizeNode.js +42 -0
  203. package/src/nodes/accessors/UV.js +10 -1
  204. package/src/nodes/accessors/UniformArrayNode.js +231 -25
  205. package/src/nodes/accessors/UserDataNode.js +46 -0
  206. package/src/nodes/accessors/VelocityNode.js +80 -0
  207. package/src/nodes/accessors/VertexColorNode.js +39 -2
  208. package/src/nodes/code/CodeNode.js +95 -1
  209. package/src/nodes/code/ExpressionNode.js +28 -0
  210. package/src/nodes/code/FunctionCallNode.js +37 -0
  211. package/src/nodes/code/FunctionNode.js +45 -0
  212. package/src/nodes/code/ScriptableNode.js +223 -1
  213. package/src/nodes/code/ScriptableValueNode.js +85 -1
  214. package/src/nodes/core/ArrayNode.js +125 -0
  215. package/src/nodes/core/AssignNode.js +48 -2
  216. package/src/nodes/core/AttributeNode.js +43 -0
  217. package/src/nodes/core/BypassNode.js +47 -2
  218. package/src/nodes/core/CacheNode.js +53 -2
  219. package/src/nodes/core/ConstNode.js +32 -0
  220. package/src/nodes/core/ContextNode.js +65 -0
  221. package/src/nodes/core/IndexNode.js +68 -7
  222. package/src/nodes/core/InputNode.js +48 -0
  223. package/src/nodes/core/LightingModel.js +60 -0
  224. package/src/nodes/core/MRTNode.js +66 -0
  225. package/src/nodes/core/Node.js +350 -12
  226. package/src/nodes/core/NodeAttribute.js +38 -0
  227. package/src/nodes/core/NodeBuilder.js +1166 -26
  228. package/src/nodes/core/NodeCache.js +41 -2
  229. package/src/nodes/core/NodeCode.js +31 -0
  230. package/src/nodes/core/NodeFrame.js +123 -2
  231. package/src/nodes/core/NodeFunction.js +46 -0
  232. package/src/nodes/core/NodeFunctionInput.js +44 -0
  233. package/src/nodes/core/NodeParser.js +11 -0
  234. package/src/nodes/core/NodeUniform.js +52 -0
  235. package/src/nodes/core/NodeUtils.js +152 -1
  236. package/src/nodes/core/NodeVar.js +47 -1
  237. package/src/nodes/core/NodeVarying.js +28 -0
  238. package/src/nodes/core/OutputStructNode.js +51 -10
  239. package/src/nodes/core/ParameterNode.js +28 -0
  240. package/src/nodes/core/PropertyNode.js +232 -0
  241. package/src/nodes/core/StackNode.js +98 -1
  242. package/src/nodes/core/StructNode.js +121 -0
  243. package/src/nodes/core/StructType.js +13 -0
  244. package/src/nodes/core/StructTypeNode.js +105 -6
  245. package/src/nodes/core/TempNode.js +31 -5
  246. package/src/nodes/core/UniformGroupNode.js +82 -7
  247. package/src/nodes/core/UniformNode.js +66 -0
  248. package/src/nodes/core/VarNode.js +146 -7
  249. package/src/nodes/core/VaryingNode.js +100 -3
  250. package/src/nodes/core/constants.js +36 -0
  251. package/src/nodes/display/BlendModes.js +88 -1
  252. package/src/nodes/display/BumpMapNode.js +37 -0
  253. package/src/nodes/display/ColorAdjustment.js +53 -11
  254. package/src/nodes/display/ColorSpaceFunctions.js +16 -0
  255. package/src/nodes/display/ColorSpaceNode.js +82 -0
  256. package/src/nodes/display/FrontFacingNode.js +29 -0
  257. package/src/nodes/display/NormalMapNode.js +43 -0
  258. package/src/nodes/display/PassNode.js +300 -7
  259. package/src/nodes/display/PosterizeNode.js +33 -0
  260. package/src/nodes/display/RenderOutputNode.js +66 -1
  261. package/src/nodes/display/ScreenNode.js +96 -0
  262. package/src/nodes/display/ToneMappingFunctions.js +58 -10
  263. package/src/nodes/display/ToneMappingNode.js +55 -2
  264. package/src/nodes/display/ToonOutlinePassNode.js +73 -0
  265. package/src/nodes/display/ViewportDepthNode.js +122 -8
  266. package/src/nodes/display/ViewportDepthTextureNode.js +23 -0
  267. package/src/nodes/display/ViewportSharedTextureNode.js +23 -0
  268. package/src/nodes/display/ViewportTextureNode.js +57 -0
  269. package/src/nodes/fog/Fog.js +110 -0
  270. package/src/nodes/functions/BasicLightingModel.js +24 -0
  271. package/src/nodes/functions/PhongLightingModel.js +34 -2
  272. package/src/nodes/functions/PhysicalLightingModel.js +167 -8
  273. package/src/nodes/functions/ShadowMaskModel.js +23 -0
  274. package/src/nodes/functions/ToonLightingModel.js +20 -0
  275. package/src/nodes/functions/material/getAlphaHashThreshold.js +1 -3
  276. package/src/nodes/functions/material/getParallaxCorrectNormal.js +16 -1
  277. package/src/nodes/geometry/RangeNode.js +54 -2
  278. package/src/nodes/gpgpu/AtomicFunctionNode.js +174 -2
  279. package/src/nodes/gpgpu/BarrierNode.js +47 -0
  280. package/src/nodes/gpgpu/ComputeBuiltinNode.js +134 -0
  281. package/src/nodes/gpgpu/ComputeNode.js +106 -2
  282. package/src/nodes/gpgpu/WorkgroupInfoNode.js +115 -6
  283. package/src/nodes/lighting/AONode.js +18 -0
  284. package/src/nodes/lighting/AmbientLightNode.js +10 -0
  285. package/src/nodes/lighting/AnalyticLightNode.js +97 -2
  286. package/src/nodes/lighting/BasicEnvironmentNode.js +19 -0
  287. package/src/nodes/lighting/BasicLightMapNode.js +17 -0
  288. package/src/nodes/lighting/DirectionalLightNode.js +10 -0
  289. package/src/nodes/lighting/EnvironmentNode.js +18 -0
  290. package/src/nodes/lighting/HemisphereLightNode.js +31 -0
  291. package/src/nodes/lighting/IESSpotLightNode.js +11 -0
  292. package/src/nodes/lighting/IrradianceNode.js +17 -0
  293. package/src/nodes/lighting/LightProbeNode.js +20 -0
  294. package/src/nodes/lighting/LightUtils.js +12 -0
  295. package/src/nodes/lighting/LightingContextNode.js +48 -0
  296. package/src/nodes/lighting/LightingNode.js +15 -6
  297. package/src/nodes/lighting/LightsNode.js +132 -1
  298. package/src/nodes/lighting/PointLightNode.js +32 -1
  299. package/src/nodes/lighting/PointShadowNode.js +54 -1
  300. package/src/nodes/lighting/RectAreaLightNode.js +44 -6
  301. package/src/nodes/lighting/ShadowBaseNode.js +93 -0
  302. package/src/nodes/lighting/ShadowNode.js +241 -35
  303. package/src/nodes/lighting/SpotLightNode.js +43 -0
  304. package/src/nodes/math/ConditionalNode.js +78 -4
  305. package/src/nodes/math/Hash.js +9 -0
  306. package/src/nodes/math/MathNode.js +627 -11
  307. package/src/nodes/math/MathUtils.js +45 -1
  308. package/src/nodes/math/OperatorNode.js +329 -18
  309. package/src/nodes/math/TriNoise3D.js +18 -7
  310. package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
  311. package/src/nodes/parsers/GLSLNodeParser.js +11 -0
  312. package/src/nodes/pmrem/PMREMNode.js +133 -0
  313. package/src/nodes/pmrem/PMREMUtils.js +2 -2
  314. package/src/nodes/procedural/Checker.js +9 -0
  315. package/src/nodes/shapes/Shapes.js +33 -0
  316. package/src/nodes/tsl/TSLBase.js +3 -2
  317. package/src/nodes/tsl/TSLCore.js +22 -2
  318. package/src/nodes/utils/ArrayElementNode.js +39 -3
  319. package/src/nodes/utils/ConvertNode.js +31 -0
  320. package/src/nodes/utils/CubeMapNode.js +78 -0
  321. package/src/nodes/utils/Discard.js +16 -0
  322. package/src/nodes/utils/EquirectUVNode.js +31 -1
  323. package/src/nodes/utils/FlipNode.js +38 -0
  324. package/src/nodes/utils/FunctionOverloadingNode.js +53 -1
  325. package/src/nodes/utils/JoinNode.js +25 -0
  326. package/src/nodes/utils/LoopNode.js +82 -2
  327. package/src/nodes/utils/MatcapUVNode.js +17 -0
  328. package/src/nodes/utils/MaxMipLevelNode.js +49 -0
  329. package/src/nodes/utils/MemberNode.js +68 -0
  330. package/src/nodes/utils/Oscillators.js +33 -0
  331. package/src/nodes/utils/Packing.js +17 -0
  332. package/src/nodes/utils/PostProcessingUtils.js +28 -23
  333. package/src/nodes/utils/RTTNode.js +123 -2
  334. package/src/nodes/utils/ReflectorNode.js +174 -4
  335. package/src/nodes/utils/RemapNode.js +79 -0
  336. package/src/nodes/utils/RotateNode.js +41 -0
  337. package/src/nodes/utils/SetNode.js +44 -1
  338. package/src/nodes/utils/SplitNode.js +55 -3
  339. package/src/nodes/utils/SpriteSheetUVNode.js +46 -0
  340. package/src/nodes/utils/SpriteUtils.js +17 -0
  341. package/src/nodes/utils/StorageArrayElementNode.js +54 -0
  342. package/src/nodes/utils/Timer.js +40 -0
  343. package/src/nodes/utils/TriplanarTexturesNode.js +84 -0
  344. package/src/nodes/utils/UVUtils.js +20 -0
  345. package/src/nodes/utils/ViewportUtils.js +13 -0
  346. package/src/objects/BatchedMesh.js +2 -3
  347. package/src/objects/ClippingGroup.js +49 -0
  348. package/src/objects/Line.js +6 -6
  349. package/src/renderers/WebGLRenderer.js +30 -4
  350. package/src/renderers/common/Animation.js +85 -0
  351. package/src/renderers/common/Attributes.js +36 -0
  352. package/src/renderers/common/Backend.js +502 -44
  353. package/src/renderers/common/Background.js +48 -1
  354. package/src/renderers/common/BindGroup.js +43 -0
  355. package/src/renderers/common/Binding.js +35 -0
  356. package/src/renderers/common/Bindings.js +93 -1
  357. package/src/renderers/common/Buffer.js +49 -0
  358. package/src/renderers/common/BufferUtils.js +27 -0
  359. package/src/renderers/common/BundleGroup.js +57 -0
  360. package/src/renderers/common/ChainMap.js +45 -6
  361. package/src/renderers/common/ClippingContext.js +108 -15
  362. package/src/renderers/common/Color4.js +40 -0
  363. package/src/renderers/common/ComputePipeline.js +24 -0
  364. package/src/renderers/common/CubeRenderTarget.js +13 -0
  365. package/src/renderers/common/DataMap.js +37 -1
  366. package/src/renderers/common/Geometries.js +91 -14
  367. package/src/renderers/common/IndirectStorageBufferAttribute.js +25 -2
  368. package/src/renderers/common/Info.js +78 -35
  369. package/src/renderers/common/Lighting.js +34 -6
  370. package/src/renderers/common/Pipeline.js +22 -0
  371. package/src/renderers/common/Pipelines.js +148 -5
  372. package/src/renderers/common/PostProcessing.js +99 -11
  373. package/src/renderers/common/ProgrammableStage.js +60 -2
  374. package/src/renderers/common/QuadMesh.js +54 -5
  375. package/src/renderers/common/RenderBundle.js +14 -8
  376. package/src/renderers/common/RenderBundles.js +39 -10
  377. package/src/renderers/common/RenderContext.js +201 -2
  378. package/src/renderers/common/RenderContexts.js +59 -6
  379. package/src/renderers/common/RenderList.js +178 -0
  380. package/src/renderers/common/RenderLists.js +40 -3
  381. package/src/renderers/common/RenderObject.js +400 -17
  382. package/src/renderers/common/RenderObjects.js +103 -7
  383. package/src/renderers/common/RenderPipeline.js +24 -0
  384. package/src/renderers/common/Renderer.js +1170 -86
  385. package/src/renderers/common/RendererUtils.js +193 -0
  386. package/src/renderers/common/SampledTexture.js +120 -0
  387. package/src/renderers/common/Sampler.js +30 -0
  388. package/src/renderers/common/StorageBuffer.js +24 -0
  389. package/src/renderers/common/StorageBufferAttribute.js +31 -2
  390. package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
  391. package/src/renderers/common/StorageTexture.js +38 -0
  392. package/src/renderers/common/Textures.js +97 -7
  393. package/src/renderers/common/TimestampQueryPool.js +39 -0
  394. package/src/renderers/common/Uniform.js +225 -3
  395. package/src/renderers/common/UniformBuffer.js +19 -0
  396. package/src/renderers/common/UniformsGroup.js +141 -2
  397. package/src/renderers/common/XRManager.js +1193 -0
  398. package/src/renderers/common/XRRenderTarget.js +74 -0
  399. package/src/renderers/common/extras/PMREMGenerator.js +76 -10
  400. package/src/renderers/common/nodes/NodeBuilderState.js +99 -5
  401. package/src/renderers/common/nodes/NodeLibrary.js +89 -0
  402. package/src/renderers/common/nodes/NodeSampledTexture.js +90 -2
  403. package/src/renderers/common/nodes/NodeSampler.js +28 -0
  404. package/src/renderers/common/nodes/NodeStorageBuffer.js +35 -0
  405. package/src/renderers/common/nodes/NodeUniform.js +243 -2
  406. package/src/renderers/common/nodes/NodeUniformBuffer.js +29 -0
  407. package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
  408. package/src/renderers/common/nodes/Nodes.js +352 -78
  409. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
  410. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
  411. package/src/renderers/webgl/WebGLBackground.js +4 -0
  412. package/src/renderers/webgl-fallback/WebGLBackend.js +819 -116
  413. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +347 -18
  414. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +58 -1
  415. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
  416. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
  417. package/src/renderers/webgl-fallback/utils/WebGLState.js +323 -11
  418. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +168 -22
  419. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +359 -0
  420. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
  421. package/src/renderers/webgpu/WebGPUBackend.js +578 -164
  422. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +36 -0
  423. package/src/renderers/webgpu/WebGPURenderer.js +36 -0
  424. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +20 -8
  425. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +21 -8
  426. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +674 -52
  427. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +17 -0
  428. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
  429. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +95 -14
  430. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +94 -1
  431. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +102 -3
  432. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +98 -1
  433. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +262 -18
  434. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +274 -0
  435. package/src/renderers/webgpu/utils/WebGPUUtils.js +116 -4
  436. package/src/renderers/webxr/WebXRDepthSensing.js +1 -1
  437. package/src/renderers/webxr/WebXRManager.js +19 -2
  438. package/src/textures/Data3DTexture.js +2 -2
  439. package/src/textures/Texture.js +4 -0
  440. package/src/textures/VideoFrameTexture.js +35 -0
  441. package/examples/jsm/animation/MMDAnimationHelper.js +0 -1209
  442. package/examples/jsm/animation/MMDPhysics.js +0 -1408
  443. package/examples/jsm/exporters/MMDExporter.js +0 -223
  444. package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -176
  445. package/examples/jsm/libs/mmdparser.module.js +0 -11530
  446. package/examples/jsm/loaders/MMDLoader.js +0 -2298
  447. package/examples/jsm/objects/InstancedPoints.js +0 -19
  448. package/examples/jsm/shaders/MMDToonShader.js +0 -134
  449. package/src/materials/nodes/InstancedPointsNodeMaterial.js +0 -156
  450. package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -24
  451. package/src/nodes/core/UniformGroup.js +0 -13
  452. package/src/nodes/fog/FogExp2Node.js +0 -35
  453. package/src/nodes/fog/FogNode.js +0 -50
  454. package/src/nodes/fog/FogRangeNode.js +0 -36
  455. package/src/renderers/common/PostProcessingUtils.js +0 -86
@@ -1,1209 +0,0 @@
1
- import {
2
- AnimationMixer,
3
- Object3D,
4
- Quaternion,
5
- Vector3
6
- } from 'three';
7
- import { CCDIKSolver } from '../animation/CCDIKSolver.js';
8
- import { MMDPhysics } from '../animation/MMDPhysics.js';
9
-
10
- /**
11
- * MMDAnimationHelper handles animation of MMD assets loaded by MMDLoader
12
- * with MMD special features as IK, Grant, and Physics.
13
- *
14
- * Dependencies
15
- * - ammo.js https://github.com/kripken/ammo.js
16
- * - MMDPhysics
17
- * - CCDIKSolver
18
- *
19
- * TODO
20
- * - more precise grant skinning support.
21
- */
22
- class MMDAnimationHelper {
23
-
24
- /**
25
- * @param {Object} params - (optional)
26
- * @param {boolean} params.sync - Whether animation durations of added objects are synched. Default is true.
27
- * @param {Number} params.afterglow - Default is 0.0.
28
- * @param {boolean} params.resetPhysicsOnLoop - Default is true.
29
- */
30
- constructor( params = {} ) {
31
-
32
- this.meshes = [];
33
-
34
- this.camera = null;
35
- this.cameraTarget = new Object3D();
36
- this.cameraTarget.name = 'target';
37
-
38
- this.audio = null;
39
- this.audioManager = null;
40
-
41
- this.objects = new WeakMap();
42
-
43
- this.configuration = {
44
- sync: params.sync !== undefined ? params.sync : true,
45
- afterglow: params.afterglow !== undefined ? params.afterglow : 0.0,
46
- resetPhysicsOnLoop: params.resetPhysicsOnLoop !== undefined ? params.resetPhysicsOnLoop : true,
47
- pmxAnimation: params.pmxAnimation !== undefined ? params.pmxAnimation : false
48
- };
49
-
50
- this.enabled = {
51
- animation: true,
52
- ik: true,
53
- grant: true,
54
- physics: true,
55
- cameraAnimation: true
56
- };
57
-
58
- this.onBeforePhysics = function ( /* mesh */ ) {};
59
-
60
- // experimental
61
- this.sharedPhysics = false;
62
- this.masterPhysics = null;
63
-
64
- console.warn( 'THREE.MMDAnimationHelper: The module has been deprecated and will be removed with r172. Please migrate to https://github.com/takahirox/three-mmd-loader instead.' );
65
-
66
- }
67
-
68
- /**
69
- * Adds an Three.js Object to helper and setups animation.
70
- * The anmation durations of added objects are synched
71
- * if this.configuration.sync is true.
72
- *
73
- * @param {THREE.SkinnedMesh|THREE.Camera|THREE.Audio} object
74
- * @param {Object} params - (optional)
75
- * @param {THREE.AnimationClip|Array<THREE.AnimationClip>} params.animation - Only for THREE.SkinnedMesh and THREE.Camera. Default is undefined.
76
- * @param {boolean} params.physics - Only for THREE.SkinnedMesh. Default is true.
77
- * @param {Integer} params.warmup - Only for THREE.SkinnedMesh and physics is true. Default is 60.
78
- * @param {Number} params.unitStep - Only for THREE.SkinnedMesh and physics is true. Default is 1 / 65.
79
- * @param {Integer} params.maxStepNum - Only for THREE.SkinnedMesh and physics is true. Default is 3.
80
- * @param {Vector3} params.gravity - Only for THREE.SkinnedMesh and physics is true. Default ( 0, - 9.8 * 10, 0 ).
81
- * @param {Number} params.delayTime - Only for THREE.Audio. Default is 0.0.
82
- * @return {MMDAnimationHelper}
83
- */
84
- add( object, params = {} ) {
85
-
86
- if ( object.isSkinnedMesh ) {
87
-
88
- this._addMesh( object, params );
89
-
90
- } else if ( object.isCamera ) {
91
-
92
- this._setupCamera( object, params );
93
-
94
- } else if ( object.type === 'Audio' ) {
95
-
96
- this._setupAudio( object, params );
97
-
98
- } else {
99
-
100
- throw new Error( 'THREE.MMDAnimationHelper.add: '
101
- + 'accepts only '
102
- + 'THREE.SkinnedMesh or '
103
- + 'THREE.Camera or '
104
- + 'THREE.Audio instance.' );
105
-
106
- }
107
-
108
- if ( this.configuration.sync ) this._syncDuration();
109
-
110
- return this;
111
-
112
- }
113
-
114
- /**
115
- * Removes an Three.js Object from helper.
116
- *
117
- * @param {THREE.SkinnedMesh|THREE.Camera|THREE.Audio} object
118
- * @return {MMDAnimationHelper}
119
- */
120
- remove( object ) {
121
-
122
- if ( object.isSkinnedMesh ) {
123
-
124
- this._removeMesh( object );
125
-
126
- } else if ( object.isCamera ) {
127
-
128
- this._clearCamera( object );
129
-
130
- } else if ( object.type === 'Audio' ) {
131
-
132
- this._clearAudio( object );
133
-
134
- } else {
135
-
136
- throw new Error( 'THREE.MMDAnimationHelper.remove: '
137
- + 'accepts only '
138
- + 'THREE.SkinnedMesh or '
139
- + 'THREE.Camera or '
140
- + 'THREE.Audio instance.' );
141
-
142
- }
143
-
144
- if ( this.configuration.sync ) this._syncDuration();
145
-
146
- return this;
147
-
148
- }
149
-
150
- /**
151
- * Updates the animation.
152
- *
153
- * @param {Number} delta
154
- * @return {MMDAnimationHelper}
155
- */
156
- update( delta ) {
157
-
158
- if ( this.audioManager !== null ) this.audioManager.control( delta );
159
-
160
- for ( let i = 0; i < this.meshes.length; i ++ ) {
161
-
162
- this._animateMesh( this.meshes[ i ], delta );
163
-
164
- }
165
-
166
- if ( this.sharedPhysics ) this._updateSharedPhysics( delta );
167
-
168
- if ( this.camera !== null ) this._animateCamera( this.camera, delta );
169
-
170
- return this;
171
-
172
- }
173
-
174
- /**
175
- * Changes the pose of SkinnedMesh as VPD specifies.
176
- *
177
- * @param {THREE.SkinnedMesh} mesh
178
- * @param {Object} vpd - VPD content parsed MMDParser
179
- * @param {Object} params - (optional)
180
- * @param {boolean} params.resetPose - Default is true.
181
- * @param {boolean} params.ik - Default is true.
182
- * @param {boolean} params.grant - Default is true.
183
- * @return {MMDAnimationHelper}
184
- */
185
- pose( mesh, vpd, params = {} ) {
186
-
187
- if ( params.resetPose !== false ) mesh.pose();
188
-
189
- const bones = mesh.skeleton.bones;
190
- const boneParams = vpd.bones;
191
-
192
- const boneNameDictionary = {};
193
-
194
- for ( let i = 0, il = bones.length; i < il; i ++ ) {
195
-
196
- boneNameDictionary[ bones[ i ].name ] = i;
197
-
198
- }
199
-
200
- const vector = new Vector3();
201
- const quaternion = new Quaternion();
202
-
203
- for ( let i = 0, il = boneParams.length; i < il; i ++ ) {
204
-
205
- const boneParam = boneParams[ i ];
206
- const boneIndex = boneNameDictionary[ boneParam.name ];
207
-
208
- if ( boneIndex === undefined ) continue;
209
-
210
- const bone = bones[ boneIndex ];
211
- bone.position.add( vector.fromArray( boneParam.translation ) );
212
- bone.quaternion.multiply( quaternion.fromArray( boneParam.quaternion ) );
213
-
214
- }
215
-
216
- mesh.updateMatrixWorld( true );
217
-
218
- // PMX animation system special path
219
- if ( this.configuration.pmxAnimation &&
220
- mesh.geometry.userData.MMD && mesh.geometry.userData.MMD.format === 'pmx' ) {
221
-
222
- const sortedBonesData = this._sortBoneDataArray( mesh.geometry.userData.MMD.bones.slice() );
223
- const ikSolver = params.ik !== false ? this._createCCDIKSolver( mesh ) : null;
224
- const grantSolver = params.grant !== false ? this.createGrantSolver( mesh ) : null;
225
- this._animatePMXMesh( mesh, sortedBonesData, ikSolver, grantSolver );
226
-
227
- } else {
228
-
229
- if ( params.ik !== false ) {
230
-
231
- this._createCCDIKSolver( mesh ).update();
232
-
233
- }
234
-
235
- if ( params.grant !== false ) {
236
-
237
- this.createGrantSolver( mesh ).update();
238
-
239
- }
240
-
241
- }
242
-
243
- return this;
244
-
245
- }
246
-
247
- /**
248
- * Enabes/Disables an animation feature.
249
- *
250
- * @param {string} key
251
- * @param {boolean} enabled
252
- * @return {MMDAnimationHelper}
253
- */
254
- enable( key, enabled ) {
255
-
256
- if ( this.enabled[ key ] === undefined ) {
257
-
258
- throw new Error( 'THREE.MMDAnimationHelper.enable: '
259
- + 'unknown key ' + key );
260
-
261
- }
262
-
263
- this.enabled[ key ] = enabled;
264
-
265
- if ( key === 'physics' ) {
266
-
267
- for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
268
-
269
- this._optimizeIK( this.meshes[ i ], enabled );
270
-
271
- }
272
-
273
- }
274
-
275
- return this;
276
-
277
- }
278
-
279
- /**
280
- * Creates an GrantSolver instance.
281
- *
282
- * @param {THREE.SkinnedMesh} mesh
283
- * @return {GrantSolver}
284
- */
285
- createGrantSolver( mesh ) {
286
-
287
- return new GrantSolver( mesh, mesh.geometry.userData.MMD.grants );
288
-
289
- }
290
-
291
- // private methods
292
-
293
- _addMesh( mesh, params ) {
294
-
295
- if ( this.meshes.indexOf( mesh ) >= 0 ) {
296
-
297
- throw new Error( 'THREE.MMDAnimationHelper._addMesh: '
298
- + 'SkinnedMesh \'' + mesh.name + '\' has already been added.' );
299
-
300
- }
301
-
302
- this.meshes.push( mesh );
303
- this.objects.set( mesh, { looped: false } );
304
-
305
- this._setupMeshAnimation( mesh, params.animation );
306
-
307
- if ( params.physics !== false ) {
308
-
309
- this._setupMeshPhysics( mesh, params );
310
-
311
- }
312
-
313
- return this;
314
-
315
- }
316
-
317
- _setupCamera( camera, params ) {
318
-
319
- if ( this.camera === camera ) {
320
-
321
- throw new Error( 'THREE.MMDAnimationHelper._setupCamera: '
322
- + 'Camera \'' + camera.name + '\' has already been set.' );
323
-
324
- }
325
-
326
- if ( this.camera ) this.clearCamera( this.camera );
327
-
328
- this.camera = camera;
329
-
330
- camera.add( this.cameraTarget );
331
-
332
- this.objects.set( camera, {} );
333
-
334
- if ( params.animation !== undefined ) {
335
-
336
- this._setupCameraAnimation( camera, params.animation );
337
-
338
- }
339
-
340
- return this;
341
-
342
- }
343
-
344
- _setupAudio( audio, params ) {
345
-
346
- if ( this.audio === audio ) {
347
-
348
- throw new Error( 'THREE.MMDAnimationHelper._setupAudio: '
349
- + 'Audio \'' + audio.name + '\' has already been set.' );
350
-
351
- }
352
-
353
- if ( this.audio ) this.clearAudio( this.audio );
354
-
355
- this.audio = audio;
356
- this.audioManager = new AudioManager( audio, params );
357
-
358
- this.objects.set( this.audioManager, {
359
- duration: this.audioManager.duration
360
- } );
361
-
362
- return this;
363
-
364
- }
365
-
366
- _removeMesh( mesh ) {
367
-
368
- let found = false;
369
- let writeIndex = 0;
370
-
371
- for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
372
-
373
- if ( this.meshes[ i ] === mesh ) {
374
-
375
- this.objects.delete( mesh );
376
- found = true;
377
-
378
- continue;
379
-
380
- }
381
-
382
- this.meshes[ writeIndex ++ ] = this.meshes[ i ];
383
-
384
- }
385
-
386
- if ( ! found ) {
387
-
388
- throw new Error( 'THREE.MMDAnimationHelper._removeMesh: '
389
- + 'SkinnedMesh \'' + mesh.name + '\' has not been added yet.' );
390
-
391
- }
392
-
393
- this.meshes.length = writeIndex;
394
-
395
- return this;
396
-
397
- }
398
-
399
- _clearCamera( camera ) {
400
-
401
- if ( camera !== this.camera ) {
402
-
403
- throw new Error( 'THREE.MMDAnimationHelper._clearCamera: '
404
- + 'Camera \'' + camera.name + '\' has not been set yet.' );
405
-
406
- }
407
-
408
- this.camera.remove( this.cameraTarget );
409
-
410
- this.objects.delete( this.camera );
411
- this.camera = null;
412
-
413
- return this;
414
-
415
- }
416
-
417
- _clearAudio( audio ) {
418
-
419
- if ( audio !== this.audio ) {
420
-
421
- throw new Error( 'THREE.MMDAnimationHelper._clearAudio: '
422
- + 'Audio \'' + audio.name + '\' has not been set yet.' );
423
-
424
- }
425
-
426
- this.objects.delete( this.audioManager );
427
-
428
- this.audio = null;
429
- this.audioManager = null;
430
-
431
- return this;
432
-
433
- }
434
-
435
- _setupMeshAnimation( mesh, animation ) {
436
-
437
- const objects = this.objects.get( mesh );
438
-
439
- if ( animation !== undefined ) {
440
-
441
- const animations = Array.isArray( animation )
442
- ? animation : [ animation ];
443
-
444
- objects.mixer = new AnimationMixer( mesh );
445
-
446
- for ( let i = 0, il = animations.length; i < il; i ++ ) {
447
-
448
- objects.mixer.clipAction( animations[ i ] ).play();
449
-
450
- }
451
-
452
- // TODO: find a workaround not to access ._clip looking like a private property
453
- objects.mixer.addEventListener( 'loop', function ( event ) {
454
-
455
- const tracks = event.action._clip.tracks;
456
-
457
- if ( tracks.length > 0 && tracks[ 0 ].name.slice( 0, 6 ) !== '.bones' ) return;
458
-
459
- objects.looped = true;
460
-
461
- } );
462
-
463
- }
464
-
465
- objects.ikSolver = this._createCCDIKSolver( mesh );
466
- objects.grantSolver = this.createGrantSolver( mesh );
467
-
468
- return this;
469
-
470
- }
471
-
472
- _setupCameraAnimation( camera, animation ) {
473
-
474
- const animations = Array.isArray( animation )
475
- ? animation : [ animation ];
476
-
477
- const objects = this.objects.get( camera );
478
-
479
- objects.mixer = new AnimationMixer( camera );
480
-
481
- for ( let i = 0, il = animations.length; i < il; i ++ ) {
482
-
483
- objects.mixer.clipAction( animations[ i ] ).play();
484
-
485
- }
486
-
487
- }
488
-
489
- _setupMeshPhysics( mesh, params ) {
490
-
491
- const objects = this.objects.get( mesh );
492
-
493
- // shared physics is experimental
494
-
495
- if ( params.world === undefined && this.sharedPhysics ) {
496
-
497
- const masterPhysics = this._getMasterPhysics();
498
-
499
- if ( masterPhysics !== null ) world = masterPhysics.world; // eslint-disable-line no-undef
500
-
501
- }
502
-
503
- objects.physics = this._createMMDPhysics( mesh, params );
504
-
505
- if ( objects.mixer && params.animationWarmup !== false ) {
506
-
507
- this._animateMesh( mesh, 0 );
508
- objects.physics.reset();
509
-
510
- }
511
-
512
- objects.physics.warmup( params.warmup !== undefined ? params.warmup : 60 );
513
-
514
- this._optimizeIK( mesh, true );
515
-
516
- }
517
-
518
- _animateMesh( mesh, delta ) {
519
-
520
- const objects = this.objects.get( mesh );
521
-
522
- const mixer = objects.mixer;
523
- const ikSolver = objects.ikSolver;
524
- const grantSolver = objects.grantSolver;
525
- const physics = objects.physics;
526
- const looped = objects.looped;
527
-
528
- if ( mixer && this.enabled.animation ) {
529
-
530
- // alternate solution to save/restore bones but less performant?
531
- //mesh.pose();
532
- //this._updatePropertyMixersBuffer( mesh );
533
-
534
- this._restoreBones( mesh );
535
-
536
- mixer.update( delta );
537
-
538
- this._saveBones( mesh );
539
-
540
- // PMX animation system special path
541
- if ( this.configuration.pmxAnimation &&
542
- mesh.geometry.userData.MMD && mesh.geometry.userData.MMD.format === 'pmx' ) {
543
-
544
- if ( ! objects.sortedBonesData ) objects.sortedBonesData = this._sortBoneDataArray( mesh.geometry.userData.MMD.bones.slice() );
545
-
546
- this._animatePMXMesh(
547
- mesh,
548
- objects.sortedBonesData,
549
- ikSolver && this.enabled.ik ? ikSolver : null,
550
- grantSolver && this.enabled.grant ? grantSolver : null
551
- );
552
-
553
- } else {
554
-
555
- if ( ikSolver && this.enabled.ik ) {
556
-
557
- mesh.updateMatrixWorld( true );
558
- ikSolver.update();
559
-
560
- }
561
-
562
- if ( grantSolver && this.enabled.grant ) {
563
-
564
- grantSolver.update();
565
-
566
- }
567
-
568
- }
569
-
570
- }
571
-
572
- if ( looped === true && this.enabled.physics ) {
573
-
574
- if ( physics && this.configuration.resetPhysicsOnLoop ) physics.reset();
575
-
576
- objects.looped = false;
577
-
578
- }
579
-
580
- if ( physics && this.enabled.physics && ! this.sharedPhysics ) {
581
-
582
- this.onBeforePhysics( mesh );
583
- physics.update( delta );
584
-
585
- }
586
-
587
- }
588
-
589
- // Sort bones in order by 1. transformationClass and 2. bone index.
590
- // In PMX animation system, bone transformations should be processed
591
- // in this order.
592
- _sortBoneDataArray( boneDataArray ) {
593
-
594
- return boneDataArray.sort( function ( a, b ) {
595
-
596
- if ( a.transformationClass !== b.transformationClass ) {
597
-
598
- return a.transformationClass - b.transformationClass;
599
-
600
- } else {
601
-
602
- return a.index - b.index;
603
-
604
- }
605
-
606
- } );
607
-
608
- }
609
-
610
- // PMX Animation system is a bit too complex and doesn't great match to
611
- // Three.js Animation system. This method attempts to simulate it as much as
612
- // possible but doesn't perfectly simulate.
613
- // This method is more costly than the regular one so
614
- // you are recommended to set constructor parameter "pmxAnimation: true"
615
- // only if your PMX model animation doesn't work well.
616
- // If you need better method you would be required to write your own.
617
- _animatePMXMesh( mesh, sortedBonesData, ikSolver, grantSolver ) {
618
-
619
- _quaternionIndex = 0;
620
- _grantResultMap.clear();
621
-
622
- for ( let i = 0, il = sortedBonesData.length; i < il; i ++ ) {
623
-
624
- updateOne( mesh, sortedBonesData[ i ].index, ikSolver, grantSolver );
625
-
626
- }
627
-
628
- mesh.updateMatrixWorld( true );
629
- return this;
630
-
631
- }
632
-
633
- _animateCamera( camera, delta ) {
634
-
635
- const mixer = this.objects.get( camera ).mixer;
636
-
637
- if ( mixer && this.enabled.cameraAnimation ) {
638
-
639
- mixer.update( delta );
640
-
641
- camera.updateProjectionMatrix();
642
-
643
- camera.up.set( 0, 1, 0 );
644
- camera.up.applyQuaternion( camera.quaternion );
645
- camera.lookAt( this.cameraTarget.position );
646
-
647
- }
648
-
649
- }
650
-
651
- _optimizeIK( mesh, physicsEnabled ) {
652
-
653
- const iks = mesh.geometry.userData.MMD.iks;
654
- const bones = mesh.geometry.userData.MMD.bones;
655
-
656
- for ( let i = 0, il = iks.length; i < il; i ++ ) {
657
-
658
- const ik = iks[ i ];
659
- const links = ik.links;
660
-
661
- for ( let j = 0, jl = links.length; j < jl; j ++ ) {
662
-
663
- const link = links[ j ];
664
-
665
- if ( physicsEnabled === true ) {
666
-
667
- // disable IK of the bone the corresponding rigidBody type of which is 1 or 2
668
- // because its rotation will be overriden by physics
669
- link.enabled = bones[ link.index ].rigidBodyType > 0 ? false : true;
670
-
671
- } else {
672
-
673
- link.enabled = true;
674
-
675
- }
676
-
677
- }
678
-
679
- }
680
-
681
- }
682
-
683
- _createCCDIKSolver( mesh ) {
684
-
685
- if ( CCDIKSolver === undefined ) {
686
-
687
- throw new Error( 'THREE.MMDAnimationHelper: Import CCDIKSolver.' );
688
-
689
- }
690
-
691
- return new CCDIKSolver( mesh, mesh.geometry.userData.MMD.iks );
692
-
693
- }
694
-
695
- _createMMDPhysics( mesh, params ) {
696
-
697
- if ( MMDPhysics === undefined ) {
698
-
699
- throw new Error( 'THREE.MMDPhysics: Import MMDPhysics.' );
700
-
701
- }
702
-
703
- return new MMDPhysics(
704
- mesh,
705
- mesh.geometry.userData.MMD.rigidBodies,
706
- mesh.geometry.userData.MMD.constraints,
707
- params );
708
-
709
- }
710
-
711
- /*
712
- * Detects the longest duration and then sets it to them to sync.
713
- * TODO: Not to access private properties ( ._actions and ._clip )
714
- */
715
- _syncDuration() {
716
-
717
- let max = 0.0;
718
-
719
- const objects = this.objects;
720
- const meshes = this.meshes;
721
- const camera = this.camera;
722
- const audioManager = this.audioManager;
723
-
724
- // get the longest duration
725
-
726
- for ( let i = 0, il = meshes.length; i < il; i ++ ) {
727
-
728
- const mixer = this.objects.get( meshes[ i ] ).mixer;
729
-
730
- if ( mixer === undefined ) continue;
731
-
732
- for ( let j = 0; j < mixer._actions.length; j ++ ) {
733
-
734
- const clip = mixer._actions[ j ]._clip;
735
-
736
- if ( ! objects.has( clip ) ) {
737
-
738
- objects.set( clip, {
739
- duration: clip.duration
740
- } );
741
-
742
- }
743
-
744
- max = Math.max( max, objects.get( clip ).duration );
745
-
746
- }
747
-
748
- }
749
-
750
- if ( camera !== null ) {
751
-
752
- const mixer = this.objects.get( camera ).mixer;
753
-
754
- if ( mixer !== undefined ) {
755
-
756
- for ( let i = 0, il = mixer._actions.length; i < il; i ++ ) {
757
-
758
- const clip = mixer._actions[ i ]._clip;
759
-
760
- if ( ! objects.has( clip ) ) {
761
-
762
- objects.set( clip, {
763
- duration: clip.duration
764
- } );
765
-
766
- }
767
-
768
- max = Math.max( max, objects.get( clip ).duration );
769
-
770
- }
771
-
772
- }
773
-
774
- }
775
-
776
- if ( audioManager !== null ) {
777
-
778
- max = Math.max( max, objects.get( audioManager ).duration );
779
-
780
- }
781
-
782
- max += this.configuration.afterglow;
783
-
784
- // update the duration
785
-
786
- for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
787
-
788
- const mixer = this.objects.get( this.meshes[ i ] ).mixer;
789
-
790
- if ( mixer === undefined ) continue;
791
-
792
- for ( let j = 0, jl = mixer._actions.length; j < jl; j ++ ) {
793
-
794
- mixer._actions[ j ]._clip.duration = max;
795
-
796
- }
797
-
798
- }
799
-
800
- if ( camera !== null ) {
801
-
802
- const mixer = this.objects.get( camera ).mixer;
803
-
804
- if ( mixer !== undefined ) {
805
-
806
- for ( let i = 0, il = mixer._actions.length; i < il; i ++ ) {
807
-
808
- mixer._actions[ i ]._clip.duration = max;
809
-
810
- }
811
-
812
- }
813
-
814
- }
815
-
816
- if ( audioManager !== null ) {
817
-
818
- audioManager.duration = max;
819
-
820
- }
821
-
822
- }
823
-
824
- // workaround
825
-
826
- _updatePropertyMixersBuffer( mesh ) {
827
-
828
- const mixer = this.objects.get( mesh ).mixer;
829
-
830
- const propertyMixers = mixer._bindings;
831
- const accuIndex = mixer._accuIndex;
832
-
833
- for ( let i = 0, il = propertyMixers.length; i < il; i ++ ) {
834
-
835
- const propertyMixer = propertyMixers[ i ];
836
- const buffer = propertyMixer.buffer;
837
- const stride = propertyMixer.valueSize;
838
- const offset = ( accuIndex + 1 ) * stride;
839
-
840
- propertyMixer.binding.getValue( buffer, offset );
841
-
842
- }
843
-
844
- }
845
-
846
- /*
847
- * Avoiding these two issues by restore/save bones before/after mixer animation.
848
- *
849
- * 1. PropertyMixer used by AnimationMixer holds cache value in .buffer.
850
- * Calculating IK, Grant, and Physics after mixer animation can break
851
- * the cache coherency.
852
- *
853
- * 2. Applying Grant two or more times without reset the posing breaks model.
854
- */
855
- _saveBones( mesh ) {
856
-
857
- const objects = this.objects.get( mesh );
858
-
859
- const bones = mesh.skeleton.bones;
860
-
861
- let backupBones = objects.backupBones;
862
-
863
- if ( backupBones === undefined ) {
864
-
865
- backupBones = new Float32Array( bones.length * 7 );
866
- objects.backupBones = backupBones;
867
-
868
- }
869
-
870
- for ( let i = 0, il = bones.length; i < il; i ++ ) {
871
-
872
- const bone = bones[ i ];
873
- bone.position.toArray( backupBones, i * 7 );
874
- bone.quaternion.toArray( backupBones, i * 7 + 3 );
875
-
876
- }
877
-
878
- }
879
-
880
- _restoreBones( mesh ) {
881
-
882
- const objects = this.objects.get( mesh );
883
-
884
- const backupBones = objects.backupBones;
885
-
886
- if ( backupBones === undefined ) return;
887
-
888
- const bones = mesh.skeleton.bones;
889
-
890
- for ( let i = 0, il = bones.length; i < il; i ++ ) {
891
-
892
- const bone = bones[ i ];
893
- bone.position.fromArray( backupBones, i * 7 );
894
- bone.quaternion.fromArray( backupBones, i * 7 + 3 );
895
-
896
- }
897
-
898
- }
899
-
900
- // experimental
901
-
902
- _getMasterPhysics() {
903
-
904
- if ( this.masterPhysics !== null ) return this.masterPhysics;
905
-
906
- for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
907
-
908
- const physics = this.meshes[ i ].physics;
909
-
910
- if ( physics !== undefined && physics !== null ) {
911
-
912
- this.masterPhysics = physics;
913
- return this.masterPhysics;
914
-
915
- }
916
-
917
- }
918
-
919
- return null;
920
-
921
- }
922
-
923
- _updateSharedPhysics( delta ) {
924
-
925
- if ( this.meshes.length === 0 || ! this.enabled.physics || ! this.sharedPhysics ) return;
926
-
927
- const physics = this._getMasterPhysics();
928
-
929
- if ( physics === null ) return;
930
-
931
- for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
932
-
933
- const p = this.meshes[ i ].physics;
934
-
935
- if ( p !== null && p !== undefined ) {
936
-
937
- p.updateRigidBodies();
938
-
939
- }
940
-
941
- }
942
-
943
- physics.stepSimulation( delta );
944
-
945
- for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
946
-
947
- const p = this.meshes[ i ].physics;
948
-
949
- if ( p !== null && p !== undefined ) {
950
-
951
- p.updateBones();
952
-
953
- }
954
-
955
- }
956
-
957
- }
958
-
959
- }
960
-
961
- // Keep working quaternions for less GC
962
- const _quaternions = [];
963
- let _quaternionIndex = 0;
964
-
965
- function getQuaternion() {
966
-
967
- if ( _quaternionIndex >= _quaternions.length ) {
968
-
969
- _quaternions.push( new Quaternion() );
970
-
971
- }
972
-
973
- return _quaternions[ _quaternionIndex ++ ];
974
-
975
- }
976
-
977
- // Save rotation whose grant and IK are already applied
978
- // used by grant children
979
- const _grantResultMap = new Map();
980
-
981
- function updateOne( mesh, boneIndex, ikSolver, grantSolver ) {
982
-
983
- const bones = mesh.skeleton.bones;
984
- const bonesData = mesh.geometry.userData.MMD.bones;
985
- const boneData = bonesData[ boneIndex ];
986
- const bone = bones[ boneIndex ];
987
-
988
- // Return if already updated by being referred as a grant parent.
989
- if ( _grantResultMap.has( boneIndex ) ) return;
990
-
991
- const quaternion = getQuaternion();
992
-
993
- // Initialize grant result here to prevent infinite loop.
994
- // If it's referred before updating with actual result later
995
- // result without applyting IK or grant is gotten
996
- // but better than composing of infinite loop.
997
- _grantResultMap.set( boneIndex, quaternion.copy( bone.quaternion ) );
998
-
999
- // @TODO: Support global grant and grant position
1000
- if ( grantSolver && boneData.grant &&
1001
- ! boneData.grant.isLocal && boneData.grant.affectRotation ) {
1002
-
1003
- const parentIndex = boneData.grant.parentIndex;
1004
- const ratio = boneData.grant.ratio;
1005
-
1006
- if ( ! _grantResultMap.has( parentIndex ) ) {
1007
-
1008
- updateOne( mesh, parentIndex, ikSolver, grantSolver );
1009
-
1010
- }
1011
-
1012
- grantSolver.addGrantRotation( bone, _grantResultMap.get( parentIndex ), ratio );
1013
-
1014
- }
1015
-
1016
- if ( ikSolver && boneData.ik ) {
1017
-
1018
- // @TODO: Updating world matrices every time solving an IK bone is
1019
- // costly. Optimize if possible.
1020
- mesh.updateMatrixWorld( true );
1021
- ikSolver.updateOne( boneData.ik );
1022
-
1023
- // No confident, but it seems the grant results with ik links should be updated?
1024
- const links = boneData.ik.links;
1025
-
1026
- for ( let i = 0, il = links.length; i < il; i ++ ) {
1027
-
1028
- const link = links[ i ];
1029
-
1030
- if ( link.enabled === false ) continue;
1031
-
1032
- const linkIndex = link.index;
1033
-
1034
- if ( _grantResultMap.has( linkIndex ) ) {
1035
-
1036
- _grantResultMap.set( linkIndex, _grantResultMap.get( linkIndex ).copy( bones[ linkIndex ].quaternion ) );
1037
-
1038
- }
1039
-
1040
- }
1041
-
1042
- }
1043
-
1044
- // Update with the actual result here
1045
- quaternion.copy( bone.quaternion );
1046
-
1047
- }
1048
-
1049
- //
1050
-
1051
- class AudioManager {
1052
-
1053
- /**
1054
- * @param {THREE.Audio} audio
1055
- * @param {Object} params - (optional)
1056
- * @param {Nuumber} params.delayTime
1057
- */
1058
- constructor( audio, params = {} ) {
1059
-
1060
- this.audio = audio;
1061
-
1062
- this.elapsedTime = 0.0;
1063
- this.currentTime = 0.0;
1064
- this.delayTime = params.delayTime !== undefined
1065
- ? params.delayTime : 0.0;
1066
-
1067
- this.audioDuration = this.audio.buffer.duration;
1068
- this.duration = this.audioDuration + this.delayTime;
1069
-
1070
- }
1071
-
1072
- /**
1073
- * @param {Number} delta
1074
- * @return {AudioManager}
1075
- */
1076
- control( delta ) {
1077
-
1078
- this.elapsed += delta;
1079
- this.currentTime += delta;
1080
-
1081
- if ( this._shouldStopAudio() ) this.audio.stop();
1082
- if ( this._shouldStartAudio() ) this.audio.play();
1083
-
1084
- return this;
1085
-
1086
- }
1087
-
1088
- // private methods
1089
-
1090
- _shouldStartAudio() {
1091
-
1092
- if ( this.audio.isPlaying ) return false;
1093
-
1094
- while ( this.currentTime >= this.duration ) {
1095
-
1096
- this.currentTime -= this.duration;
1097
-
1098
- }
1099
-
1100
- if ( this.currentTime < this.delayTime ) return false;
1101
-
1102
- // 'duration' can be bigger than 'audioDuration + delayTime' because of sync configuration
1103
- if ( ( this.currentTime - this.delayTime ) > this.audioDuration ) return false;
1104
-
1105
- return true;
1106
-
1107
- }
1108
-
1109
- _shouldStopAudio() {
1110
-
1111
- return this.audio.isPlaying &&
1112
- this.currentTime >= this.duration;
1113
-
1114
- }
1115
-
1116
- }
1117
-
1118
- const _q = new Quaternion();
1119
-
1120
- /**
1121
- * Solver for Grant (Fuyo in Japanese. I just google translated because
1122
- * Fuyo may be MMD specific term and may not be common word in 3D CG terms.)
1123
- * Grant propagates a bone's transform to other bones transforms even if
1124
- * they are not children.
1125
- * @param {THREE.SkinnedMesh} mesh
1126
- * @param {Array<Object>} grants
1127
- */
1128
- class GrantSolver {
1129
-
1130
- constructor( mesh, grants = [] ) {
1131
-
1132
- this.mesh = mesh;
1133
- this.grants = grants;
1134
-
1135
- }
1136
-
1137
- /**
1138
- * Solve all the grant bones
1139
- * @return {GrantSolver}
1140
- */
1141
- update() {
1142
-
1143
- const grants = this.grants;
1144
-
1145
- for ( let i = 0, il = grants.length; i < il; i ++ ) {
1146
-
1147
- this.updateOne( grants[ i ] );
1148
-
1149
- }
1150
-
1151
- return this;
1152
-
1153
- }
1154
-
1155
- /**
1156
- * Solve a grant bone
1157
- * @param {Object} grant - grant parameter
1158
- * @return {GrantSolver}
1159
- */
1160
- updateOne( grant ) {
1161
-
1162
- const bones = this.mesh.skeleton.bones;
1163
- const bone = bones[ grant.index ];
1164
- const parentBone = bones[ grant.parentIndex ];
1165
-
1166
- if ( grant.isLocal ) {
1167
-
1168
- // TODO: implement
1169
- if ( grant.affectPosition ) {
1170
-
1171
- }
1172
-
1173
- // TODO: implement
1174
- if ( grant.affectRotation ) {
1175
-
1176
- }
1177
-
1178
- } else {
1179
-
1180
- // TODO: implement
1181
- if ( grant.affectPosition ) {
1182
-
1183
- }
1184
-
1185
- if ( grant.affectRotation ) {
1186
-
1187
- this.addGrantRotation( bone, parentBone.quaternion, grant.ratio );
1188
-
1189
- }
1190
-
1191
- }
1192
-
1193
- return this;
1194
-
1195
- }
1196
-
1197
- addGrantRotation( bone, q, ratio ) {
1198
-
1199
- _q.set( 0, 0, 0, 1 );
1200
- _q.slerp( q, ratio );
1201
- bone.quaternion.multiply( _q );
1202
-
1203
- return this;
1204
-
1205
- }
1206
-
1207
- }
1208
-
1209
- export { MMDAnimationHelper };