@needle-tools/three 0.154.3 → 0.160.3
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.
- package/LICENSE +21 -21
- package/README.md +86 -84
- package/build/three.cjs +53679 -51654
- package/build/three.module.js +53263 -51253
- package/build/three.module.min.js +6 -6
- package/examples/fonts/LICENSE +13 -13
- package/examples/fonts/README.md +11 -11
- package/examples/fonts/droid/NOTICE +190 -190
- package/examples/fonts/droid/README.txt +18 -18
- package/examples/fonts/ttf/README.md +9 -9
- package/examples/jsm/Addons.js +294 -0
- package/examples/jsm/animation/AnimationClipCreator.js +116 -116
- package/examples/jsm/animation/CCDIKSolver.js +482 -482
- package/examples/jsm/animation/MMDAnimationHelper.js +1207 -1207
- package/examples/jsm/animation/MMDPhysics.js +1406 -1406
- package/examples/jsm/cameras/CinematicCamera.js +208 -208
- package/examples/jsm/capabilities/WebGL.js +108 -91
- package/examples/jsm/capabilities/WebGPU.js +57 -53
- package/examples/jsm/controls/ArcballControls.js +3224 -3224
- package/examples/jsm/controls/DragControls.js +221 -220
- package/examples/jsm/controls/FirstPersonControls.js +325 -325
- package/examples/jsm/controls/FlyControls.js +326 -300
- package/examples/jsm/controls/MapControls.js +28 -28
- package/examples/jsm/controls/OrbitControls.js +1521 -1279
- package/examples/jsm/controls/PointerLockControls.js +162 -162
- package/examples/jsm/controls/TrackballControls.js +828 -828
- package/examples/jsm/controls/TransformControls.js +1573 -1557
- package/examples/jsm/csm/CSM.js +384 -384
- package/examples/jsm/csm/CSMFrustum.js +152 -152
- package/examples/jsm/csm/CSMHelper.js +193 -193
- package/examples/jsm/csm/CSMShader.js +295 -252
- package/examples/jsm/curves/CurveExtras.js +422 -422
- package/examples/jsm/curves/NURBSCurve.js +80 -80
- package/examples/jsm/curves/NURBSSurface.js +52 -52
- package/examples/jsm/curves/NURBSUtils.js +487 -487
- package/examples/jsm/effects/AnaglyphEffect.js +154 -154
- package/examples/jsm/effects/AsciiEffect.js +263 -263
- package/examples/jsm/effects/OutlineEffect.js +539 -539
- package/examples/jsm/effects/ParallaxBarrierEffect.js +119 -119
- package/examples/jsm/effects/PeppersGhostEffect.js +153 -153
- package/examples/jsm/effects/StereoEffect.js +55 -55
- package/examples/jsm/environments/DebugEnvironment.js +52 -52
- package/examples/jsm/environments/RoomEnvironment.js +148 -148
- package/examples/jsm/exporters/DRACOExporter.js +267 -267
- package/examples/jsm/exporters/EXRExporter.js +579 -501
- package/examples/jsm/exporters/GLTFExporter.js +3311 -3163
- package/examples/jsm/exporters/KTX2Exporter.js +292 -292
- package/examples/jsm/exporters/MMDExporter.js +217 -217
- package/examples/jsm/exporters/OBJExporter.js +284 -284
- package/examples/jsm/exporters/PLYExporter.js +528 -528
- package/examples/jsm/exporters/STLExporter.js +199 -199
- package/examples/jsm/exporters/USDZExporter.js +720 -710
- package/examples/jsm/geometries/BoxLineGeometry.js +69 -69
- package/examples/jsm/geometries/ConvexGeometry.js +53 -53
- package/examples/jsm/geometries/DecalGeometry.js +356 -356
- package/examples/jsm/geometries/InstancedPointsGeometry.js +174 -0
- package/examples/jsm/geometries/ParametricGeometries.js +254 -254
- package/examples/jsm/geometries/ParametricGeometry.js +139 -139
- package/examples/jsm/geometries/RoundedBoxGeometry.js +155 -155
- package/examples/jsm/geometries/SDFGeometryGenerator.js +144 -0
- package/examples/jsm/geometries/TeapotGeometry.js +704 -704
- package/examples/jsm/geometries/TextGeometry.js +57 -57
- package/examples/jsm/helpers/LightProbeHelper.js +130 -130
- package/examples/jsm/helpers/OctreeHelper.js +73 -73
- package/examples/jsm/helpers/PositionalAudioHelper.js +109 -109
- package/examples/jsm/helpers/RectAreaLightHelper.js +85 -85
- package/examples/jsm/helpers/TextureHelper.js +237 -0
- package/examples/jsm/helpers/VertexNormalsHelper.js +96 -96
- package/examples/jsm/helpers/VertexTangentsHelper.js +88 -88
- package/examples/jsm/helpers/ViewHelper.js +333 -333
- package/examples/jsm/interactive/HTMLMesh.js +572 -565
- package/examples/jsm/interactive/InteractiveGroup.js +116 -116
- package/examples/jsm/interactive/SelectionBox.js +227 -227
- package/examples/jsm/interactive/SelectionHelper.js +104 -97
- package/examples/jsm/libs/ammo.wasm.js +822 -822
- package/examples/jsm/libs/basis/README.md +46 -46
- package/examples/jsm/libs/basis/basis_transcoder.js +21 -21
- package/examples/jsm/libs/chevrotain.module.min.js +141 -141
- package/examples/jsm/libs/draco/README.md +32 -32
- package/examples/jsm/libs/draco/draco_decoder.js +34 -34
- package/examples/jsm/libs/draco/draco_encoder.js +33 -33
- package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -117
- package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -33
- package/examples/jsm/libs/draco/gltf/draco_encoder.js +33 -33
- package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -116
- package/examples/jsm/libs/ecsy.module.js +1792 -1792
- package/examples/jsm/libs/fflate.module.js +2474 -2474
- package/examples/jsm/libs/ktx-parse.module.js +1 -1
- package/examples/jsm/libs/lil-gui.module.min.js +8 -8
- package/examples/jsm/libs/lottie_canvas.module.js +14849 -14844
- package/examples/jsm/libs/meshopt_decoder.module.js +178 -178
- package/examples/jsm/libs/mikktspace.module.js +128 -128
- package/examples/jsm/libs/mmdparser.module.js +11530 -11530
- package/examples/jsm/libs/motion-controllers.module.js +397 -397
- package/examples/jsm/libs/opentype.module.js +14506 -14568
- package/examples/jsm/libs/potpack.module.js +124 -124
- package/examples/jsm/libs/rhino3dm/rhino3dm.js +8743 -21
- package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +8748 -15
- package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
- package/examples/jsm/libs/stats.module.js +167 -167
- package/examples/jsm/libs/surfaceNet.js +201 -0
- package/examples/jsm/libs/tween.module.js +858 -803
- package/examples/jsm/libs/utif.module.js +1664 -1578
- package/examples/jsm/libs/zstddec.module.js +1 -1
- package/examples/jsm/lights/IESSpotLight.js +25 -25
- package/examples/jsm/lights/LightProbeGenerator.js +286 -252
- package/examples/jsm/lights/RectAreaLightUniformsLib.js +79 -79
- package/examples/jsm/lines/Line2.js +19 -19
- package/examples/jsm/lines/LineGeometry.js +79 -79
- package/examples/jsm/lines/LineMaterial.js +619 -702
- package/examples/jsm/lines/LineSegments2.js +361 -361
- package/examples/jsm/lines/LineSegmentsGeometry.js +241 -241
- package/examples/jsm/lines/Wireframe.js +56 -56
- package/examples/jsm/lines/WireframeGeometry2.js +24 -24
- package/examples/jsm/loaders/3DMLoader.js +1772 -1497
- package/examples/jsm/loaders/3MFLoader.js +1478 -1478
- package/examples/jsm/loaders/AMFLoader.js +521 -521
- package/examples/jsm/loaders/BVHLoader.js +437 -437
- package/examples/jsm/loaders/ColladaLoader.js +4116 -4122
- package/examples/jsm/loaders/DDSLoader.js +318 -274
- package/examples/jsm/loaders/DRACOLoader.js +613 -612
- package/examples/jsm/loaders/EXRLoader.js +2309 -2309
- package/examples/jsm/loaders/FBXLoader.js +4314 -4142
- package/examples/jsm/loaders/FontLoader.js +183 -183
- package/examples/jsm/loaders/GCodeLoader.js +261 -261
- package/examples/jsm/loaders/GLTFLoader.js +4666 -4579
- package/examples/jsm/loaders/GLTFLoaderAnimationPointer.js +719 -719
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +115 -115
- package/examples/jsm/loaders/IESLoader.js +337 -337
- package/examples/jsm/loaders/KMZLoader.js +130 -130
- package/examples/jsm/loaders/KTX2Loader.js +932 -868
- package/examples/jsm/loaders/KTXLoader.js +176 -176
- package/examples/jsm/loaders/LDrawLoader.js +2470 -2464
- package/examples/jsm/loaders/LUT3dlLoader.js +183 -151
- package/examples/jsm/loaders/LUTCubeLoader.js +167 -153
- package/examples/jsm/loaders/LUTImageLoader.js +163 -0
- package/examples/jsm/loaders/LWOLoader.js +1052 -1052
- package/examples/jsm/loaders/LogLuvLoader.js +606 -606
- package/examples/jsm/loaders/LottieLoader.js +77 -77
- package/examples/jsm/loaders/MD2Loader.js +399 -399
- package/examples/jsm/loaders/MDDLoader.js +102 -102
- package/examples/jsm/loaders/MMDLoader.js +2276 -2273
- package/examples/jsm/loaders/MTLLoader.js +567 -567
- package/examples/jsm/loaders/MaterialXLoader.js +852 -734
- package/examples/jsm/loaders/NRRDLoader.js +686 -699
- package/examples/jsm/loaders/OBJLoader.js +905 -905
- package/examples/jsm/loaders/PCDLoader.js +467 -467
- package/examples/jsm/loaders/PDBLoader.js +232 -232
- package/examples/jsm/loaders/PLYLoader.js +771 -771
- package/examples/jsm/loaders/PVRLoader.js +251 -251
- package/examples/jsm/loaders/RGBELoader.js +450 -468
- package/examples/jsm/loaders/RGBMLoader.js +1065 -1065
- package/examples/jsm/loaders/STLLoader.js +410 -403
- package/examples/jsm/loaders/SVGLoader.js +3173 -3172
- package/examples/jsm/loaders/TDSLoader.js +1124 -1124
- package/examples/jsm/loaders/TGALoader.js +517 -517
- package/examples/jsm/loaders/TIFFLoader.js +36 -36
- package/examples/jsm/loaders/TTFLoader.js +214 -214
- package/examples/jsm/loaders/TiltLoader.js +520 -520
- package/examples/jsm/loaders/USDZLoader.js +822 -633
- package/examples/jsm/loaders/VOXLoader.js +311 -311
- package/examples/jsm/loaders/VRMLLoader.js +3533 -3533
- package/examples/jsm/loaders/VTKLoader.js +1163 -1163
- package/examples/jsm/loaders/XYZLoader.js +106 -106
- package/examples/jsm/loaders/lwo/IFFParser.js +1214 -1218
- package/examples/jsm/loaders/lwo/LWO2Parser.js +414 -414
- package/examples/jsm/loaders/lwo/LWO3Parser.js +373 -373
- package/examples/jsm/materials/MeshGouraudMaterial.js +426 -420
- package/examples/jsm/materials/MeshPostProcessingMaterial.js +144 -0
- package/examples/jsm/math/Capsule.js +82 -137
- package/examples/jsm/math/ColorConverter.js +36 -36
- package/examples/jsm/math/ConvexHull.js +1271 -1271
- package/examples/jsm/math/ImprovedNoise.js +71 -71
- package/examples/jsm/math/Lut.js +204 -204
- package/examples/jsm/math/MeshSurfaceSampler.js +250 -250
- package/examples/jsm/math/OBB.js +423 -423
- package/examples/jsm/math/Octree.js +540 -462
- package/examples/jsm/math/SimplexNoise.js +444 -444
- package/examples/jsm/misc/ConvexObjectBreaker.js +519 -519
- package/examples/jsm/misc/GPUComputationRenderer.js +446 -455
- package/examples/jsm/misc/Gyroscope.js +66 -66
- package/examples/jsm/misc/MD2Character.js +276 -276
- package/examples/jsm/misc/MD2CharacterComplex.js +576 -576
- package/examples/jsm/misc/MorphAnimMesh.js +75 -75
- package/examples/jsm/misc/MorphBlendMesh.js +322 -322
- package/examples/jsm/misc/ProgressiveLightMap.js +323 -323
- package/examples/jsm/misc/RollerCoaster.js +566 -566
- package/examples/jsm/misc/Timer.js +119 -0
- package/examples/jsm/misc/TubePainter.js +202 -205
- package/examples/jsm/misc/Volume.js +473 -475
- package/examples/jsm/misc/VolumeSlice.js +229 -229
- package/examples/jsm/modifiers/CurveModifier.js +344 -326
- package/examples/jsm/modifiers/EdgeSplitModifier.js +279 -279
- package/examples/jsm/modifiers/SimplifyModifier.js +617 -525
- package/examples/jsm/modifiers/TessellateModifier.js +307 -307
- package/examples/jsm/nodes/Nodes.js +189 -172
- package/examples/jsm/nodes/accessors/BitangentNode.js +89 -89
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +127 -99
- package/examples/jsm/nodes/accessors/BufferNode.js +30 -30
- package/examples/jsm/nodes/accessors/CameraNode.js +120 -98
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +61 -101
- package/examples/jsm/nodes/accessors/InstanceNode.js +71 -71
- package/examples/jsm/nodes/accessors/InstancedPointsMaterialNode.js +21 -0
- package/examples/jsm/nodes/accessors/MaterialNode.js +314 -277
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +51 -39
- package/examples/jsm/nodes/accessors/ModelNode.js +33 -34
- package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +39 -29
- package/examples/jsm/nodes/accessors/MorphNode.js +245 -70
- package/examples/jsm/nodes/accessors/NormalNode.js +96 -96
- package/examples/jsm/nodes/accessors/Object3DNode.js +150 -150
- package/examples/jsm/nodes/accessors/PointUVNode.js +26 -26
- package/examples/jsm/nodes/accessors/PositionNode.js +104 -104
- package/examples/jsm/nodes/accessors/ReferenceNode.js +102 -72
- package/examples/jsm/nodes/accessors/ReflectVectorNode.js +35 -35
- package/examples/jsm/nodes/accessors/SceneNode.js +52 -46
- package/examples/jsm/nodes/accessors/SkinningNode.js +103 -93
- package/examples/jsm/nodes/accessors/StorageBufferNode.js +54 -27
- package/examples/jsm/nodes/accessors/TangentNode.js +103 -103
- package/examples/jsm/nodes/accessors/TextureBicubicNode.js +94 -94
- package/examples/jsm/nodes/accessors/TextureNode.js +367 -230
- package/examples/jsm/nodes/accessors/TextureSizeNode.js +35 -35
- package/examples/jsm/nodes/accessors/TextureStoreNode.js +82 -0
- package/examples/jsm/nodes/accessors/UVNode.js +47 -47
- package/examples/jsm/nodes/accessors/UserDataNode.js +29 -29
- package/examples/jsm/nodes/accessors/VertexColorNode.js +70 -0
- package/examples/jsm/nodes/code/CodeNode.js +78 -78
- package/examples/jsm/nodes/code/ExpressionNode.js +37 -37
- package/examples/jsm/nodes/code/FunctionCallNode.js +96 -96
- package/examples/jsm/nodes/code/FunctionNode.js +138 -127
- package/examples/jsm/nodes/code/ScriptableNode.js +488 -488
- package/examples/jsm/nodes/code/ScriptableValueNode.js +167 -167
- package/examples/jsm/nodes/core/ArrayUniformNode.js +26 -26
- package/examples/jsm/nodes/core/AssignNode.js +72 -0
- package/examples/jsm/nodes/core/AttributeNode.js +108 -102
- package/examples/jsm/nodes/core/BypassNode.js +45 -45
- package/examples/jsm/nodes/core/CacheNode.js +49 -46
- package/examples/jsm/nodes/core/ConstNode.js +32 -32
- package/examples/jsm/nodes/core/ContextNode.js +61 -61
- package/examples/jsm/nodes/core/IndexNode.js +66 -66
- package/examples/jsm/nodes/core/InputNode.js +83 -83
- package/examples/jsm/nodes/core/LightingModel.js +17 -17
- package/examples/jsm/nodes/core/Node.js +483 -445
- package/examples/jsm/nodes/core/NodeAttribute.js +15 -15
- package/examples/jsm/nodes/core/NodeBuilder.js +1267 -1016
- package/examples/jsm/nodes/core/NodeCache.js +26 -26
- package/examples/jsm/nodes/core/NodeCode.js +15 -15
- package/examples/jsm/nodes/core/NodeFrame.js +135 -110
- package/examples/jsm/nodes/core/NodeFunction.js +22 -22
- package/examples/jsm/nodes/core/NodeFunctionInput.js +17 -17
- package/examples/jsm/nodes/core/NodeKeywords.js +80 -80
- package/examples/jsm/nodes/core/NodeParser.js +11 -11
- package/examples/jsm/nodes/core/NodeUniform.js +40 -28
- package/examples/jsm/nodes/core/NodeUtils.js +210 -212
- package/examples/jsm/nodes/core/NodeVar.js +14 -14
- package/examples/jsm/nodes/core/NodeVarying.js +17 -17
- package/examples/jsm/nodes/core/OutputStructNode.js +62 -0
- package/examples/jsm/nodes/core/ParameterNode.js +33 -0
- package/examples/jsm/nodes/core/PropertyNode.js +72 -57
- package/examples/jsm/nodes/core/StackNode.js +89 -99
- package/examples/jsm/nodes/core/StructTypeNode.js +24 -0
- package/examples/jsm/nodes/core/TempNode.js +58 -58
- package/examples/jsm/nodes/core/UniformGroup.js +13 -0
- package/examples/jsm/nodes/core/UniformGroupNode.js +36 -0
- package/examples/jsm/nodes/core/UniformNode.js +80 -61
- package/examples/jsm/nodes/core/VarNode.js +60 -87
- package/examples/jsm/nodes/core/VaryingNode.js +65 -69
- package/examples/jsm/nodes/core/constants.js +27 -27
- package/examples/jsm/nodes/display/AfterImageNode.js +134 -0
- package/examples/jsm/nodes/display/BlendModeNode.js +99 -99
- package/examples/jsm/nodes/display/BumpMapNode.js +99 -0
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +96 -100
- package/examples/jsm/nodes/display/ColorSpaceNode.js +108 -108
- package/examples/jsm/nodes/display/FrontFacingNode.js +27 -27
- package/examples/jsm/nodes/display/GaussianBlurNode.js +177 -0
- package/examples/jsm/nodes/display/NormalMapNode.js +108 -106
- package/examples/jsm/nodes/display/PassNode.js +182 -0
- package/examples/jsm/nodes/display/PosterizeNode.js +32 -32
- package/examples/jsm/nodes/display/ToneMappingNode.js +184 -141
- package/examples/jsm/nodes/display/ViewportDepthNode.js +97 -69
- package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +31 -34
- package/examples/jsm/nodes/display/ViewportNode.js +134 -115
- package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +31 -31
- package/examples/jsm/nodes/display/ViewportTextureNode.js +75 -75
- package/examples/jsm/nodes/fog/FogExp2Node.js +35 -35
- package/examples/jsm/nodes/fog/FogNode.js +38 -37
- package/examples/jsm/nodes/fog/FogRangeNode.js +34 -34
- package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +40 -32
- package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +9 -9
- package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +57 -43
- package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +30 -29
- package/examples/jsm/nodes/functions/BSDF/D_GGX.js +23 -18
- package/examples/jsm/nodes/functions/BSDF/EnvironmentBRDF.js +13 -13
- package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +16 -16
- package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +21 -0
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +28 -20
- package/examples/jsm/nodes/functions/PhongLightingModel.js +67 -28
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +393 -204
- package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +13 -13
- package/examples/jsm/nodes/functions/material/getRoughness.js +18 -18
- package/examples/jsm/nodes/geometry/RangeNode.js +104 -104
- package/examples/jsm/nodes/gpgpu/ComputeNode.js +85 -72
- package/examples/jsm/nodes/lighting/AONode.js +27 -27
- package/examples/jsm/nodes/lighting/AmbientLightNode.js +27 -27
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +238 -146
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +40 -43
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +181 -181
- package/examples/jsm/nodes/lighting/HemisphereLightNode.js +55 -55
- package/examples/jsm/nodes/lighting/IESSpotLightNode.js +39 -39
- package/examples/jsm/nodes/lighting/LightNode.js +57 -57
- package/examples/jsm/nodes/lighting/LightUtils.js +17 -17
- package/examples/jsm/nodes/lighting/LightingContextNode.js +66 -99
- package/examples/jsm/nodes/lighting/LightingNode.js +21 -21
- package/examples/jsm/nodes/lighting/LightsNode.js +188 -128
- package/examples/jsm/nodes/lighting/PointLightNode.js +68 -71
- package/examples/jsm/nodes/lighting/SpotLightNode.js +89 -92
- package/examples/jsm/nodes/loaders/NodeLoader.js +108 -108
- package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +59 -59
- package/examples/jsm/nodes/loaders/NodeObjectLoader.js +70 -70
- package/examples/jsm/nodes/materials/InstancedPointsNodeMaterial.js +162 -0
- package/examples/jsm/nodes/materials/Line2NodeMaterial.js +436 -0
- package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +28 -28
- package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +54 -0
- package/examples/jsm/nodes/materials/Materials.js +16 -11
- package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +28 -27
- package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +34 -0
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +40 -38
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +65 -65
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +155 -111
- package/examples/jsm/nodes/materials/MeshSSSNodeMaterial.js +84 -0
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +80 -80
- package/examples/jsm/nodes/materials/NodeMaterial.js +568 -510
- package/examples/jsm/nodes/materials/PointsNodeMaterial.js +39 -49
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +96 -103
- package/examples/jsm/nodes/materialx/DISCLAIMER.md +199 -199
- package/examples/jsm/nodes/materialx/MaterialXNodes.js +68 -68
- package/examples/jsm/nodes/materialx/lib/mx_hsv.js +130 -56
- package/examples/jsm/nodes/materialx/lib/mx_noise.js +1430 -618
- package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +29 -19
- package/examples/jsm/nodes/math/CondNode.js +86 -86
- package/examples/jsm/nodes/math/HashNode.js +34 -0
- package/examples/jsm/nodes/math/MathNode.js +382 -359
- package/examples/jsm/nodes/math/OperatorNode.js +266 -269
- package/examples/jsm/nodes/math/TriNoise3D.js +71 -0
- package/examples/jsm/nodes/parsers/GLSLNodeFunction.js +152 -152
- package/examples/jsm/nodes/parsers/GLSLNodeParser.js +14 -14
- package/examples/jsm/nodes/procedural/CheckerNode.js +42 -42
- package/examples/jsm/nodes/shadernode/ShaderNode.js +625 -420
- package/examples/jsm/nodes/utils/ArrayElementNode.js +41 -33
- package/examples/jsm/nodes/utils/ConvertNode.js +65 -65
- package/examples/jsm/nodes/utils/DiscardNode.js +27 -26
- package/examples/jsm/nodes/utils/EquirectUVNode.js +33 -33
- package/examples/jsm/nodes/utils/FunctionOverloadingNode.js +95 -0
- package/examples/jsm/nodes/utils/JoinNode.js +61 -51
- package/examples/jsm/nodes/utils/LoopNode.js +198 -186
- package/examples/jsm/nodes/utils/MatcapUVNode.js +30 -30
- package/examples/jsm/nodes/utils/MaxMipLevelNode.js +46 -46
- package/examples/jsm/nodes/utils/OscNode.js +81 -81
- package/examples/jsm/nodes/utils/PackingNode.js +55 -55
- package/examples/jsm/nodes/utils/RemapNode.js +42 -42
- package/examples/jsm/nodes/utils/RotateNode.js +43 -0
- package/examples/jsm/nodes/utils/RotateUVNode.js +43 -43
- package/examples/jsm/nodes/utils/SetNode.js +62 -0
- package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +37 -37
- package/examples/jsm/nodes/utils/SplitNode.js +112 -104
- package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +41 -41
- package/examples/jsm/nodes/utils/TimerNode.js +94 -94
- package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +62 -62
- package/examples/jsm/objects/GroundedSkybox.js +50 -0
- package/examples/jsm/objects/InstancedPoints.js +21 -0
- package/examples/jsm/objects/Lensflare.js +397 -377
- package/examples/jsm/objects/MarchingCubes.js +1176 -1176
- package/examples/jsm/objects/QuadMesh.js +66 -0
- package/examples/jsm/objects/Reflector.js +264 -272
- package/examples/jsm/objects/ReflectorForSSRPass.js +352 -349
- package/examples/jsm/objects/Refractor.js +327 -332
- package/examples/jsm/objects/ShadowMesh.js +80 -80
- package/examples/jsm/objects/Sky.js +219 -219
- package/examples/jsm/objects/Water.js +333 -330
- package/examples/jsm/objects/Water2.js +361 -358
- package/examples/jsm/offscreen/jank.js +45 -45
- package/examples/jsm/offscreen/offscreen.js +8 -8
- package/examples/jsm/offscreen/scene.js +86 -87
- package/examples/jsm/physics/AmmoPhysics.js +306 -285
- package/examples/jsm/physics/RapierPhysics.js +220 -199
- package/examples/jsm/postprocessing/AfterimagePass.js +104 -104
- package/examples/jsm/postprocessing/BloomPass.js +172 -172
- package/examples/jsm/postprocessing/BokehPass.js +141 -140
- package/examples/jsm/postprocessing/ClearPass.js +46 -46
- package/examples/jsm/postprocessing/CubeTexturePass.js +85 -85
- package/examples/jsm/postprocessing/DotScreenPass.js +65 -65
- package/examples/jsm/postprocessing/EffectComposer.js +231 -231
- package/examples/jsm/postprocessing/FilmPass.js +64 -66
- package/examples/jsm/postprocessing/GTAOPass.js +582 -0
- package/examples/jsm/postprocessing/GlitchPass.js +128 -128
- package/examples/jsm/postprocessing/HalftonePass.js +79 -79
- package/examples/jsm/postprocessing/LUTPass.js +174 -173
- package/examples/jsm/postprocessing/MaskPass.js +104 -101
- package/examples/jsm/postprocessing/OutlinePass.js +654 -654
- package/examples/jsm/postprocessing/OutputPass.js +95 -72
- package/examples/jsm/postprocessing/Pass.js +95 -84
- package/examples/jsm/postprocessing/RenderPass.js +99 -81
- package/examples/jsm/postprocessing/RenderPixelatedPass.js +235 -235
- package/examples/jsm/postprocessing/SAOPass.js +335 -411
- package/examples/jsm/postprocessing/SMAAPass.js +199 -201
- package/examples/jsm/postprocessing/SSAARenderPass.js +228 -228
- package/examples/jsm/postprocessing/SSAOPass.js +420 -440
- package/examples/jsm/postprocessing/SSRPass.js +641 -641
- package/examples/jsm/postprocessing/SavePass.js +79 -79
- package/examples/jsm/postprocessing/ShaderPass.js +77 -77
- package/examples/jsm/postprocessing/TAARenderPass.js +188 -189
- package/examples/jsm/postprocessing/TexturePass.js +67 -67
- package/examples/jsm/postprocessing/UnrealBloomPass.js +415 -411
- package/examples/jsm/renderers/CSS2DRenderer.js +215 -215
- package/examples/jsm/renderers/CSS3DRenderer.js +329 -335
- package/examples/jsm/renderers/Projector.js +918 -918
- package/examples/jsm/renderers/SVGRenderer.js +556 -553
- package/examples/jsm/renderers/common/Animation.js +47 -58
- package/examples/jsm/renderers/common/Attributes.js +75 -75
- package/examples/jsm/renderers/common/Backend.js +193 -162
- package/examples/jsm/renderers/common/Background.js +134 -134
- package/examples/jsm/renderers/common/Binding.js +25 -11
- package/examples/jsm/renderers/common/Bindings.js +173 -169
- package/examples/jsm/renderers/common/Buffer.js +38 -38
- package/examples/jsm/renderers/common/BufferUtils.js +33 -33
- package/examples/jsm/renderers/common/ChainMap.js +89 -89
- package/examples/jsm/renderers/common/Color4.js +37 -0
- package/examples/jsm/renderers/common/ComputePipeline.js +17 -17
- package/examples/jsm/renderers/common/Constants.js +14 -14
- package/examples/jsm/renderers/common/CubeRenderTarget.js +65 -65
- package/examples/jsm/renderers/common/DataMap.js +54 -54
- package/examples/jsm/renderers/common/Geometries.js +215 -215
- package/examples/jsm/renderers/common/Info.js +107 -73
- package/examples/jsm/renderers/common/Pipeline.js +13 -13
- package/examples/jsm/renderers/common/Pipelines.js +322 -321
- package/examples/jsm/renderers/common/PostProcessing.js +25 -0
- package/examples/jsm/renderers/common/ProgrammableStage.js +20 -18
- package/examples/jsm/renderers/common/RenderContext.js +41 -37
- package/examples/jsm/renderers/common/RenderContexts.js +74 -38
- package/examples/jsm/renderers/common/RenderList.js +186 -178
- package/examples/jsm/renderers/common/RenderLists.js +38 -38
- package/examples/jsm/renderers/common/RenderObject.js +178 -113
- package/examples/jsm/renderers/common/RenderObjects.js +91 -92
- package/examples/jsm/renderers/common/RenderPipeline.js +16 -16
- package/examples/jsm/renderers/common/Renderer.js +1062 -864
- package/examples/jsm/renderers/common/SampledTexture.js +83 -80
- package/examples/jsm/renderers/common/Sampler.js +18 -18
- package/examples/jsm/renderers/common/StorageBuffer.js +17 -17
- package/examples/jsm/renderers/common/StorageBufferAttribute.js +21 -0
- package/examples/jsm/renderers/common/StorageTexture.js +20 -0
- package/examples/jsm/renderers/common/Textures.js +354 -206
- package/examples/jsm/renderers/common/Uniform.js +140 -140
- package/examples/jsm/renderers/common/UniformBuffer.js +15 -15
- package/examples/jsm/renderers/common/UniformsGroup.js +299 -299
- package/examples/jsm/renderers/common/nodes/NodeBuilderState.js +44 -0
- package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +49 -39
- package/examples/jsm/renderers/common/nodes/NodeSampler.js +15 -21
- package/examples/jsm/renderers/common/nodes/NodeUniform.js +135 -135
- package/examples/jsm/renderers/common/nodes/NodeUniformsGroup.js +44 -0
- package/examples/jsm/renderers/common/nodes/Nodes.js +495 -319
- package/examples/jsm/renderers/webgl/WebGLBackend.js +1290 -0
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +679 -340
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +252 -0
- package/examples/jsm/renderers/webgl/utils/WebGLCapabilities.js +36 -0
- package/examples/jsm/renderers/webgl/utils/WebGLConstants.js +11 -0
- package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +36 -0
- package/examples/jsm/renderers/webgl/utils/WebGLState.js +738 -0
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +647 -0
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +284 -0
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +320 -0
- package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/SlotNode.js +26 -26
- package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodeBuilder.js +794 -764
- package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodes.js +51 -49
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +1321 -847
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +53 -32
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +1098 -878
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +104 -104
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeParser.js +14 -14
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +287 -255
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +244 -145
- package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +324 -322
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +570 -580
- package/examples/jsm/renderers/webgpu/utils/WebGPUTexturePassUtils.js +285 -0
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +1040 -937
- package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +93 -92
- package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +89 -87
- package/examples/jsm/shaders/AfterimageShader.js +58 -56
- package/examples/jsm/shaders/BasicShader.js +29 -27
- package/examples/jsm/shaders/BleachBypassShader.js +62 -62
- package/examples/jsm/shaders/BlendShader.js +49 -47
- package/examples/jsm/shaders/BokehShader.js +145 -143
- package/examples/jsm/shaders/BokehShader2.js +397 -393
- package/examples/jsm/shaders/BrightnessContrastShader.js +56 -54
- package/examples/jsm/shaders/ColorCorrectionShader.js +52 -50
- package/examples/jsm/shaders/ColorifyShader.js +51 -51
- package/examples/jsm/shaders/ConvolutionShader.js +103 -103
- package/examples/jsm/shaders/CopyShader.js +45 -45
- package/examples/jsm/shaders/DOFMipMapShader.js +56 -54
- package/examples/jsm/shaders/DepthLimitedBlurShader.js +171 -166
- package/examples/jsm/shaders/DigitalGlitch.js +101 -101
- package/examples/jsm/shaders/DotScreenShader.js +70 -70
- package/examples/jsm/shaders/ExposureShader.js +44 -44
- package/examples/jsm/shaders/FXAAShader.js +288 -286
- package/examples/jsm/shaders/FilmShader.js +59 -102
- package/examples/jsm/shaders/FocusShader.js +89 -87
- package/examples/jsm/shaders/FreiChenShader.js +96 -94
- package/examples/jsm/shaders/GTAOShader.js +424 -0
- package/examples/jsm/shaders/GammaCorrectionShader.js +43 -43
- package/examples/jsm/shaders/GodRaysShader.js +321 -313
- package/examples/jsm/shaders/HalftoneShader.js +312 -310
- package/examples/jsm/shaders/HorizontalBlurShader.js +59 -59
- package/examples/jsm/shaders/HorizontalTiltShiftShader.js +63 -61
- package/examples/jsm/shaders/HueSaturationShader.js +67 -65
- package/examples/jsm/shaders/KaleidoShader.js +58 -56
- package/examples/jsm/shaders/LuminosityHighPassShader.js +66 -64
- package/examples/jsm/shaders/LuminosityShader.js +48 -46
- package/examples/jsm/shaders/MMDToonShader.js +134 -132
- package/examples/jsm/shaders/MirrorShader.js +56 -54
- package/examples/jsm/shaders/NormalMapShader.js +55 -53
- package/examples/jsm/shaders/OutputShader.js +81 -61
- package/examples/jsm/shaders/PoissonDenoiseShader.js +226 -0
- package/examples/jsm/shaders/RGBShiftShader.js +54 -54
- package/examples/jsm/shaders/SAOShader.js +179 -188
- package/examples/jsm/shaders/SMAAShader.js +466 -460
- package/examples/jsm/shaders/SSAOShader.js +300 -288
- package/examples/jsm/shaders/SSRShader.js +370 -364
- package/examples/jsm/shaders/SepiaShader.js +52 -52
- package/examples/jsm/shaders/SobelOperatorShader.js +92 -90
- package/examples/jsm/shaders/SubsurfaceScatteringShader.js +90 -88
- package/examples/jsm/shaders/TechnicolorShader.js +45 -43
- package/examples/jsm/shaders/ToonShader.js +326 -326
- package/examples/jsm/shaders/TriangleBlurShader.js +74 -72
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +47 -45
- package/examples/jsm/shaders/VelocityShader.js +130 -128
- package/examples/jsm/shaders/VerticalBlurShader.js +59 -59
- package/examples/jsm/shaders/VerticalTiltShiftShader.js +63 -61
- package/examples/jsm/shaders/VignetteShader.js +51 -51
- package/examples/jsm/shaders/VolumeShader.js +289 -289
- package/examples/jsm/shaders/WaterRefractionShader.js +95 -93
- package/examples/jsm/textures/FlakesTexture.js +40 -40
- package/examples/jsm/transpiler/AST.js +270 -0
- package/examples/jsm/transpiler/GLSLDecoder.js +941 -0
- package/examples/jsm/transpiler/ShaderToyDecoder.js +49 -0
- package/examples/jsm/transpiler/TSLEncoder.js +715 -0
- package/examples/jsm/transpiler/Transpiler.js +18 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +1371 -1364
- package/examples/jsm/utils/CameraUtils.js +73 -73
- package/examples/jsm/utils/GPUStatsPanel.js +128 -128
- package/examples/jsm/utils/GeometryCompressionUtils.js +639 -639
- package/examples/jsm/utils/GeometryUtils.js +221 -221
- package/examples/jsm/utils/LDrawUtils.js +202 -202
- package/examples/jsm/utils/PackedPhongMaterial.js +178 -178
- package/examples/jsm/utils/SceneUtils.js +254 -254
- package/examples/jsm/utils/ShadowMapViewer.js +210 -210
- package/examples/jsm/utils/SkeletonUtils.js +413 -413
- package/examples/jsm/utils/SortUtils.js +160 -0
- package/examples/jsm/utils/TextureUtils.js +98 -86
- package/examples/jsm/utils/UVsDebug.js +165 -165
- package/examples/jsm/utils/WorkerPool.js +102 -102
- package/examples/jsm/webxr/ARButton.js +232 -208
- package/examples/jsm/webxr/OculusHandModel.js +109 -109
- package/examples/jsm/webxr/OculusHandPointerModel.js +416 -415
- package/examples/jsm/webxr/Text2D.js +38 -38
- package/examples/jsm/webxr/VRButton.js +225 -200
- package/examples/jsm/webxr/XRButton.js +224 -198
- package/examples/jsm/webxr/XRControllerModelFactory.js +315 -310
- package/examples/jsm/webxr/XREstimatedLight.js +223 -223
- package/examples/jsm/webxr/XRHandMeshModel.js +116 -113
- package/examples/jsm/webxr/XRHandModelFactory.js +105 -105
- package/examples/jsm/webxr/XRHandPrimitiveModel.js +105 -104
- package/examples/jsm/webxr/XRPlanes.js +100 -100
- package/package.json +129 -126
- package/src/Three.Legacy.js +1 -1
- package/src/Three.js +184 -182
- package/src/animation/AnimationAction.js +700 -700
- package/src/animation/AnimationClip.js +473 -473
- package/src/animation/AnimationMixer.js +770 -770
- package/src/animation/AnimationObjectGroup.js +387 -387
- package/src/animation/AnimationUtils.js +356 -373
- package/src/animation/KeyframeTrack.js +462 -462
- package/src/animation/PropertyBinding.js +719 -719
- package/src/animation/PropertyMixer.js +318 -318
- package/src/animation/tracks/BooleanKeyframeTrack.js +19 -19
- package/src/animation/tracks/ColorKeyframeTrack.js +15 -15
- package/src/animation/tracks/NumberKeyframeTrack.js +12 -12
- package/src/animation/tracks/QuaternionKeyframeTrack.js +23 -23
- package/src/animation/tracks/StringKeyframeTrack.js +15 -15
- package/src/animation/tracks/VectorKeyframeTrack.js +12 -12
- package/src/audio/Audio.js +400 -396
- package/src/audio/AudioAnalyser.js +40 -40
- package/src/audio/AudioContext.js +25 -25
- package/src/audio/AudioListener.js +140 -137
- package/src/audio/PositionalAudio.js +146 -146
- package/src/cameras/ArrayCamera.js +17 -17
- package/src/cameras/Camera.js +69 -73
- package/src/cameras/CubeCamera.js +173 -170
- package/src/cameras/OrthographicCamera.js +136 -136
- package/src/cameras/PerspectiveCamera.js +268 -233
- package/src/cameras/StereoCamera.js +100 -100
- package/src/constants.js +216 -201
- package/src/core/BufferAttribute.js +650 -610
- package/src/core/BufferGeometry.js +1079 -1079
- package/src/core/Clock.js +74 -74
- package/src/core/EventDispatcher.js +87 -87
- package/src/core/GLBufferAttribute.js +60 -60
- package/src/core/InstancedBufferAttribute.js +39 -39
- package/src/core/InstancedBufferGeometry.js +40 -40
- package/src/core/InstancedInterleavedBuffer.js +48 -48
- package/src/core/InterleavedBuffer.js +166 -145
- package/src/core/InterleavedBufferAttribute.js +351 -331
- package/src/core/Layers.js +60 -60
- package/src/core/Object3D.js +1008 -973
- package/src/core/Raycaster.js +110 -110
- package/src/core/RenderTarget.js +131 -0
- package/src/core/Uniform.js +17 -17
- package/src/core/UniformsGroup.js +98 -92
- package/src/extras/DataUtils.js +176 -176
- package/src/extras/Earcut.js +789 -789
- package/src/extras/ImageUtils.js +129 -129
- package/src/extras/PMREMGenerator.js +910 -903
- package/src/extras/ShapeUtils.js +92 -92
- package/src/extras/core/Curve.js +416 -416
- package/src/extras/core/CurvePath.js +255 -252
- package/src/extras/core/Interpolations.js +79 -79
- package/src/extras/core/Path.js +196 -196
- package/src/extras/core/Shape.js +102 -102
- package/src/extras/core/ShapePath.js +291 -291
- package/src/extras/curves/ArcCurve.js +17 -17
- package/src/extras/curves/CatmullRomCurve3.js +255 -255
- package/src/extras/curves/CubicBezierCurve.js +78 -78
- package/src/extras/curves/CubicBezierCurve3.js +79 -79
- package/src/extras/curves/Curves.js +10 -10
- package/src/extras/curves/EllipseCurve.js +156 -156
- package/src/extras/curves/LineCurve.js +92 -92
- package/src/extras/curves/LineCurve3.js +92 -88
- package/src/extras/curves/QuadraticBezierCurve.js +74 -74
- package/src/extras/curves/QuadraticBezierCurve3.js +75 -75
- package/src/extras/curves/SplineCurve.js +97 -97
- package/src/geometries/BoxGeometry.js +180 -180
- package/src/geometries/CapsuleGeometry.js +33 -33
- package/src/geometries/CircleGeometry.js +101 -101
- package/src/geometries/ConeGeometry.js +31 -31
- package/src/geometries/CylinderGeometry.js +286 -286
- package/src/geometries/DodecahedronGeometry.js +66 -66
- package/src/geometries/EdgesGeometry.js +152 -152
- package/src/geometries/ExtrudeGeometry.js +814 -814
- package/src/geometries/Geometries.js +21 -21
- package/src/geometries/IcosahedronGeometry.js +42 -42
- package/src/geometries/LatheGeometry.js +189 -189
- package/src/geometries/OctahedronGeometry.js +37 -37
- package/src/geometries/PlaneGeometry.js +98 -98
- package/src/geometries/PolyhedronGeometry.js +319 -319
- package/src/geometries/RingGeometry.js +128 -128
- package/src/geometries/ShapeGeometry.js +195 -195
- package/src/geometries/SphereGeometry.js +137 -137
- package/src/geometries/TetrahedronGeometry.js +34 -34
- package/src/geometries/TorusGeometry.js +120 -120
- package/src/geometries/TorusKnotGeometry.js +167 -167
- package/src/geometries/TubeGeometry.js +203 -203
- package/src/geometries/WireframeGeometry.js +147 -147
- package/src/helpers/ArrowHelper.js +114 -114
- package/src/helpers/AxesHelper.js +68 -68
- package/src/helpers/Box3Helper.js +55 -55
- package/src/helpers/BoxHelper.js +113 -113
- package/src/helpers/CameraHelper.js +269 -269
- package/src/helpers/DirectionalLightHelper.js +93 -93
- package/src/helpers/GridHelper.js +56 -56
- package/src/helpers/HemisphereLightHelper.js +88 -88
- package/src/helpers/PlaneHelper.js +63 -63
- package/src/helpers/PointLightHelper.js +92 -92
- package/src/helpers/PolarGridHelper.js +96 -96
- package/src/helpers/SkeletonHelper.js +128 -128
- package/src/helpers/SpotLightHelper.js +94 -94
- package/src/lights/AmbientLight.js +17 -17
- package/src/lights/DirectionalLight.js +43 -43
- package/src/lights/DirectionalLightShadow.js +16 -16
- package/src/lights/HemisphereLight.js +34 -34
- package/src/lights/Light.js +58 -58
- package/src/lights/LightProbe.js +47 -47
- package/src/lights/LightShadow.js +147 -147
- package/src/lights/PointLight.js +57 -57
- package/src/lights/PointLightShadow.js +96 -96
- package/src/lights/RectAreaLight.js +56 -56
- package/src/lights/SpotLight.js +71 -71
- package/src/lights/SpotLightShadow.js +50 -50
- package/src/loaders/AnimationLoader.js +66 -66
- package/src/loaders/AudioLoader.js +66 -66
- package/src/loaders/BufferGeometryLoader.js +217 -224
- package/src/loaders/Cache.js +42 -42
- package/src/loaders/CompressedTextureLoader.js +134 -134
- package/src/loaders/CubeTextureLoader.js +58 -58
- package/src/loaders/DataTextureLoader.js +135 -118
- package/src/loaders/FileLoader.js +284 -284
- package/src/loaders/ImageBitmapLoader.js +123 -99
- package/src/loaders/ImageLoader.js +91 -91
- package/src/loaders/Loader.js +72 -72
- package/src/loaders/LoaderUtils.js +75 -75
- package/src/loaders/LoadingManager.js +142 -142
- package/src/loaders/MaterialLoader.js +372 -364
- package/src/loaders/ObjectLoader.js +1148 -1093
- package/src/loaders/TextureLoader.js +41 -41
- package/src/materials/LineBasicMaterial.js +53 -49
- package/src/materials/LineDashedMaterial.js +35 -35
- package/src/materials/Material.js +522 -508
- package/src/materials/Materials.js +39 -39
- package/src/materials/MeshBasicMaterial.js +85 -81
- package/src/materials/MeshDepthMaterial.js +54 -54
- package/src/materials/MeshDistanceMaterial.js +43 -43
- package/src/materials/MeshLambertMaterial.js +120 -116
- package/src/materials/MeshMatcapMaterial.js +85 -81
- package/src/materials/MeshNormalMaterial.js +61 -61
- package/src/materials/MeshPhongMaterial.js +124 -120
- package/src/materials/MeshPhysicalMaterial.js +224 -224
- package/src/materials/MeshStandardMaterial.js +128 -124
- package/src/materials/MeshToonMaterial.js +106 -102
- package/src/materials/PointsMaterial.js +54 -50
- package/src/materials/RawShaderMaterial.js +17 -17
- package/src/materials/ShaderMaterial.js +190 -187
- package/src/materials/ShadowMaterial.js +37 -37
- package/src/materials/SpriteMaterial.js +54 -54
- package/src/math/Box2.js +204 -204
- package/src/math/Box3.js +534 -517
- package/src/math/Color.js +623 -627
- package/src/math/ColorManagement.js +139 -133
- package/src/math/Cylindrical.js +61 -61
- package/src/math/Euler.js +315 -315
- package/src/math/Frustum.js +186 -186
- package/src/math/Interpolant.js +241 -241
- package/src/math/Line3.js +115 -115
- package/src/math/MathUtils.js +363 -363
- package/src/math/Matrix3.js +388 -388
- package/src/math/Matrix4.js +915 -915
- package/src/math/Plane.js +205 -205
- package/src/math/Quaternion.js +685 -684
- package/src/math/Ray.js +493 -493
- package/src/math/Sphere.js +245 -243
- package/src/math/Spherical.js +86 -86
- package/src/math/SphericalHarmonics3.js +243 -243
- package/src/math/Triangle.js +311 -329
- package/src/math/Vector2.js +480 -480
- package/src/math/Vector3.js +724 -725
- package/src/math/Vector4.js +644 -644
- package/src/math/interpolants/CubicInterpolant.js +150 -150
- package/src/math/interpolants/DiscreteInterpolant.js +26 -26
- package/src/math/interpolants/LinearInterpolant.js +38 -38
- package/src/math/interpolants/QuaternionLinearInterpolant.js +39 -39
- package/src/objects/BatchedMesh.js +1019 -0
- package/src/objects/Bone.js +17 -17
- package/src/objects/Group.js +17 -17
- package/src/objects/InstancedMesh.js +214 -214
- package/src/objects/LOD.js +214 -214
- package/src/objects/Line.js +222 -222
- package/src/objects/LineLoop.js +17 -17
- package/src/objects/LineSegments.js +55 -55
- package/src/objects/Mesh.js +429 -429
- package/src/objects/Points.js +166 -166
- package/src/objects/Skeleton.js +277 -279
- package/src/objects/SkinnedMesh.js +257 -266
- package/src/objects/Sprite.js +181 -181
- package/src/renderers/WebGL1Renderer.js +7 -7
- package/src/renderers/WebGL3DRenderTarget.js +22 -22
- package/src/renderers/WebGLArrayRenderTarget.js +22 -22
- package/src/renderers/WebGLCubeRenderTarget.js +155 -155
- package/src/renderers/WebGLMultipleRenderTargets.js +82 -84
- package/src/renderers/WebGLRenderTarget.js +15 -122
- package/src/renderers/WebGLRenderer.js +2631 -2439
- package/src/renderers/shaders/ShaderChunk/alphahash_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/alphahash_pars_fragment.glsl.js +68 -68
- package/src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl.js +16 -7
- package/src/renderers/shaders/ShaderChunk/alphatest_pars_fragment.glsl.js +5 -5
- package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +26 -18
- package/src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl.js +8 -8
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +19 -0
- package/src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js +5 -0
- package/src/renderers/shaders/ShaderChunk/begin_vertex.glsl.js +9 -9
- package/src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl.js +9 -9
- package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +33 -33
- package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +43 -42
- package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_begin.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js +10 -10
- package/src/renderers/shaders/ShaderChunk/clearcoat_pars_fragment.glsl.js +21 -21
- package/src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl.js +78 -33
- package/src/renderers/shaders/ShaderChunk/clipping_planes_pars_fragment.glsl.js +9 -9
- package/src/renderers/shaders/ShaderChunk/clipping_planes_pars_vertex.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/clipping_planes_vertex.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +11 -11
- package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +11 -11
- package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +11 -11
- package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +23 -23
- package/src/renderers/shaders/ShaderChunk/colorspace_fragment.glsl.js +3 -3
- package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +44 -11
- package/src/renderers/shaders/ShaderChunk/common.glsl.js +147 -156
- package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +186 -191
- package/src/renderers/shaders/ShaderChunk/default_fragment.glsl.js +5 -5
- package/src/renderers/shaders/ShaderChunk/default_vertex.glsl.js +5 -5
- package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +63 -36
- package/src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl.js +9 -9
- package/src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/dithering_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/dithering_pars_fragment.glsl.js +20 -20
- package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +9 -9
- package/src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +14 -14
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +62 -62
- package/src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl.js +21 -21
- package/src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl.js +22 -22
- package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +69 -69
- package/src/renderers/shaders/ShaderChunk/envmap_vertex.glsl.js +37 -37
- package/src/renderers/shaders/ShaderChunk/fog_fragment.glsl.js +17 -17
- package/src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl.js +19 -19
- package/src/renderers/shaders/ShaderChunk/fog_pars_vertex.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/fog_vertex.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/gradientmap_pars_fragment.glsl.js +27 -27
- package/src/renderers/shaders/ShaderChunk/iridescence_fragment.glsl.js +120 -121
- package/src/renderers/shaders/ShaderChunk/iridescence_pars_fragment.glsl.js +14 -14
- package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +10 -10
- package/src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl.js +8 -8
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +202 -198
- package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +13 -13
- package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +40 -40
- package/src/renderers/shaders/ShaderChunk/lights_lambert_fragment.glsl.js +5 -5
- package/src/renderers/shaders/ShaderChunk/lights_lambert_pars_fragment.glsl.js +28 -28
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +228 -223
- package/src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl.js +32 -32
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +151 -146
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +562 -560
- package/src/renderers/shaders/ShaderChunk/lights_toon_fragment.glsl.js +4 -4
- package/src/renderers/shaders/ShaderChunk/lights_toon_pars_fragment.glsl.js +26 -26
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +9 -9
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +9 -9
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +16 -16
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +22 -22
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +21 -13
- package/src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl.js +11 -11
- package/src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl.js +27 -27
- package/src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl.js +27 -27
- package/src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl.js +12 -12
- package/src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/morphcolor_vertex.glsl.js +24 -24
- package/src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl.js +27 -27
- package/src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js +38 -38
- package/src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl.js +36 -36
- package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +76 -76
- package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +33 -33
- package/src/renderers/shaders/ShaderChunk/normal_pars_fragment.glsl.js +14 -14
- package/src/renderers/shaders/ShaderChunk/normal_pars_vertex.glsl.js +14 -14
- package/src/renderers/shaders/ShaderChunk/normal_vertex.glsl.js +14 -14
- package/src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js +43 -43
- package/src/renderers/shaders/ShaderChunk/occlusion_fragment.glsl.js +20 -0
- package/src/renderers/shaders/ShaderChunk/occlusion_pars_fragment.glsl.js +97 -0
- package/src/renderers/shaders/ShaderChunk/opaque_fragment.glsl.js +11 -11
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +68 -68
- package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +8 -8
- package/src/renderers/shaders/ShaderChunk/project_vertex.glsl.js +19 -13
- package/src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl.js +12 -12
- package/src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +314 -314
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +68 -68
- package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +68 -68
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +66 -66
- package/src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl.js +10 -10
- package/src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl.js +25 -33
- package/src/renderers/shaders/ShaderChunk/skinning_vertex.glsl.js +15 -15
- package/src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl.js +20 -20
- package/src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl.js +14 -14
- package/src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/tonemapping_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +169 -77
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +36 -36
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +201 -201
- package/src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js +119 -119
- package/src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js +145 -145
- package/src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js +122 -122
- package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +21 -15
- package/src/renderers/shaders/ShaderChunk.js +274 -266
- package/src/renderers/shaders/ShaderLib/background.glsl.js +40 -32
- package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +62 -62
- package/src/renderers/shaders/ShaderLib/cube.glsl.js +36 -36
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +95 -94
- package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +76 -75
- package/src/renderers/shaders/ShaderLib/equirect.glsl.js +35 -35
- package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +77 -75
- package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +117 -114
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +126 -122
- package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +113 -109
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +89 -82
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +128 -124
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +226 -222
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +120 -116
- package/src/renderers/shaders/ShaderLib/points.glsl.js +88 -86
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +57 -54
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +81 -81
- package/src/renderers/shaders/ShaderLib/vsm.glsl.js +53 -53
- package/src/renderers/shaders/ShaderLib.js +367 -359
- package/src/renderers/shaders/UniformsLib.js +236 -230
- package/src/renderers/shaders/UniformsUtils.js +104 -104
- package/src/renderers/webgl/WebGLAnimation.js +53 -53
- package/src/renderers/webgl/WebGLAttributes.js +229 -195
- package/src/renderers/webgl/WebGLBackground.js +239 -247
- package/src/renderers/webgl/WebGLBindingStates.js +631 -631
- package/src/renderers/webgl/WebGLBufferRenderer.js +92 -61
- package/src/renderers/webgl/WebGLCapabilities.js +120 -120
- package/src/renderers/webgl/WebGLClipping.js +171 -171
- package/src/renderers/webgl/WebGLCubeMaps.js +99 -99
- package/src/renderers/webgl/WebGLCubeUVMaps.js +132 -130
- package/src/renderers/webgl/WebGLExtensions.js +97 -96
- package/src/renderers/webgl/WebGLGeometries.js +211 -207
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +102 -71
- package/src/renderers/webgl/WebGLInfo.js +71 -71
- package/src/renderers/webgl/WebGLLights.js +590 -570
- package/src/renderers/webgl/WebGLMaterials.js +576 -567
- package/src/renderers/webgl/WebGLMorphtargets.js +300 -300
- package/src/renderers/webgl/WebGLObjects.js +92 -92
- package/src/renderers/webgl/WebGLProgram.js +1112 -1002
- package/src/renderers/webgl/WebGLPrograms.js +663 -625
- package/src/renderers/webgl/WebGLProperties.js +48 -48
- package/src/renderers/webgl/WebGLRenderLists.js +238 -238
- package/src/renderers/webgl/WebGLRenderStates.js +107 -107
- package/src/renderers/webgl/WebGLShader.js +12 -12
- package/src/renderers/webgl/WebGLShaderCache.js +124 -124
- package/src/renderers/webgl/WebGLShadowMap.js +424 -389
- package/src/renderers/webgl/WebGLState.js +1328 -1307
- package/src/renderers/webgl/WebGLTextures.js +2117 -2017
- package/src/renderers/webgl/WebGLUniforms.js +1156 -1146
- package/src/renderers/webgl/WebGLUniformsGroups.js +392 -413
- package/src/renderers/webgl/WebGLUtils.js +283 -278
- package/src/renderers/webxr/WebXRController.js +343 -343
- package/src/renderers/webxr/WebXRManager.js +840 -770
- package/src/scenes/Fog.js +38 -37
- package/src/scenes/FogExp2.js +35 -34
- package/src/scenes/Scene.js +63 -63
- package/src/textures/CanvasTexture.js +17 -17
- package/src/textures/CompressedArrayTexture.js +18 -18
- package/src/textures/CompressedCubeTexture.js +19 -0
- package/src/textures/CompressedTexture.js +28 -28
- package/src/textures/CubeTexture.js +33 -33
- package/src/textures/Data3DTexture.js +35 -35
- package/src/textures/DataArrayTexture.js +27 -27
- package/src/textures/DataTexture.js +22 -22
- package/src/textures/DepthTexture.js +58 -58
- package/src/textures/FramebufferTexture.js +23 -23
- package/src/textures/Source.js +127 -127
- package/src/textures/Texture.js +338 -338
- package/src/textures/VideoTexture.js +55 -55
- package/src/utils.js +91 -83
- package/build/three.js +0 -51661
- package/build/three.min.js +0 -7
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +0 -64
- package/examples/jsm/nodes/functions/BSDF/BRDF_BlinnPhong.js +0 -30
- package/examples/jsm/objects/GroundProjectedSkybox.js +0 -172
- package/examples/jsm/renderers/common/RenderTarget.js +0 -15
- package/examples/jsm/renderers/common/nodes/NodeRender.js +0 -302
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureMipmapUtils.js +0 -163
- package/src/lights/AmbientLightProbe.js +0 -21
- package/src/lights/HemisphereLightProbe.js +0 -30
|
@@ -1,1207 +1,1207 @@
|
|
|
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
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Adds an Three.js Object to helper and setups animation.
|
|
68
|
-
* The anmation durations of added objects are synched
|
|
69
|
-
* if this.configuration.sync is true.
|
|
70
|
-
*
|
|
71
|
-
* @param {THREE.SkinnedMesh|THREE.Camera|THREE.Audio} object
|
|
72
|
-
* @param {Object} params - (optional)
|
|
73
|
-
* @param {THREE.AnimationClip|Array<THREE.AnimationClip>} params.animation - Only for THREE.SkinnedMesh and THREE.Camera. Default is undefined.
|
|
74
|
-
* @param {boolean} params.physics - Only for THREE.SkinnedMesh. Default is true.
|
|
75
|
-
* @param {Integer} params.warmup - Only for THREE.SkinnedMesh and physics is true. Default is 60.
|
|
76
|
-
* @param {Number} params.unitStep - Only for THREE.SkinnedMesh and physics is true. Default is 1 / 65.
|
|
77
|
-
* @param {Integer} params.maxStepNum - Only for THREE.SkinnedMesh and physics is true. Default is 3.
|
|
78
|
-
* @param {Vector3} params.gravity - Only for THREE.SkinnedMesh and physics is true. Default ( 0, - 9.8 * 10, 0 ).
|
|
79
|
-
* @param {Number} params.delayTime - Only for THREE.Audio. Default is 0.0.
|
|
80
|
-
* @return {MMDAnimationHelper}
|
|
81
|
-
*/
|
|
82
|
-
add( object, params = {} ) {
|
|
83
|
-
|
|
84
|
-
if ( object.isSkinnedMesh ) {
|
|
85
|
-
|
|
86
|
-
this._addMesh( object, params );
|
|
87
|
-
|
|
88
|
-
} else if ( object.isCamera ) {
|
|
89
|
-
|
|
90
|
-
this._setupCamera( object, params );
|
|
91
|
-
|
|
92
|
-
} else if ( object.type === 'Audio' ) {
|
|
93
|
-
|
|
94
|
-
this._setupAudio( object, params );
|
|
95
|
-
|
|
96
|
-
} else {
|
|
97
|
-
|
|
98
|
-
throw new Error( 'THREE.MMDAnimationHelper.add: '
|
|
99
|
-
+ 'accepts only '
|
|
100
|
-
+ 'THREE.SkinnedMesh or '
|
|
101
|
-
+ 'THREE.Camera or '
|
|
102
|
-
+ 'THREE.Audio instance.' );
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if ( this.configuration.sync ) this._syncDuration();
|
|
107
|
-
|
|
108
|
-
return this;
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Removes an Three.js Object from helper.
|
|
114
|
-
*
|
|
115
|
-
* @param {THREE.SkinnedMesh|THREE.Camera|THREE.Audio} object
|
|
116
|
-
* @return {MMDAnimationHelper}
|
|
117
|
-
*/
|
|
118
|
-
remove( object ) {
|
|
119
|
-
|
|
120
|
-
if ( object.isSkinnedMesh ) {
|
|
121
|
-
|
|
122
|
-
this._removeMesh( object );
|
|
123
|
-
|
|
124
|
-
} else if ( object.isCamera ) {
|
|
125
|
-
|
|
126
|
-
this._clearCamera( object );
|
|
127
|
-
|
|
128
|
-
} else if ( object.type === 'Audio' ) {
|
|
129
|
-
|
|
130
|
-
this._clearAudio( object );
|
|
131
|
-
|
|
132
|
-
} else {
|
|
133
|
-
|
|
134
|
-
throw new Error( 'THREE.MMDAnimationHelper.remove: '
|
|
135
|
-
+ 'accepts only '
|
|
136
|
-
+ 'THREE.SkinnedMesh or '
|
|
137
|
-
+ 'THREE.Camera or '
|
|
138
|
-
+ 'THREE.Audio instance.' );
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if ( this.configuration.sync ) this._syncDuration();
|
|
143
|
-
|
|
144
|
-
return this;
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Updates the animation.
|
|
150
|
-
*
|
|
151
|
-
* @param {Number} delta
|
|
152
|
-
* @return {MMDAnimationHelper}
|
|
153
|
-
*/
|
|
154
|
-
update( delta ) {
|
|
155
|
-
|
|
156
|
-
if ( this.audioManager !== null ) this.audioManager.control( delta );
|
|
157
|
-
|
|
158
|
-
for ( let i = 0; i < this.meshes.length; i ++ ) {
|
|
159
|
-
|
|
160
|
-
this._animateMesh( this.meshes[ i ], delta );
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if ( this.sharedPhysics ) this._updateSharedPhysics( delta );
|
|
165
|
-
|
|
166
|
-
if ( this.camera !== null ) this._animateCamera( this.camera, delta );
|
|
167
|
-
|
|
168
|
-
return this;
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Changes the pose of SkinnedMesh as VPD specifies.
|
|
174
|
-
*
|
|
175
|
-
* @param {THREE.SkinnedMesh} mesh
|
|
176
|
-
* @param {Object} vpd - VPD content parsed MMDParser
|
|
177
|
-
* @param {Object} params - (optional)
|
|
178
|
-
* @param {boolean} params.resetPose - Default is true.
|
|
179
|
-
* @param {boolean} params.ik - Default is true.
|
|
180
|
-
* @param {boolean} params.grant - Default is true.
|
|
181
|
-
* @return {MMDAnimationHelper}
|
|
182
|
-
*/
|
|
183
|
-
pose( mesh, vpd, params = {} ) {
|
|
184
|
-
|
|
185
|
-
if ( params.resetPose !== false ) mesh.pose();
|
|
186
|
-
|
|
187
|
-
const bones = mesh.skeleton.bones;
|
|
188
|
-
const boneParams = vpd.bones;
|
|
189
|
-
|
|
190
|
-
const boneNameDictionary = {};
|
|
191
|
-
|
|
192
|
-
for ( let i = 0, il = bones.length; i < il; i ++ ) {
|
|
193
|
-
|
|
194
|
-
boneNameDictionary[ bones[ i ].name ] = i;
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const vector = new Vector3();
|
|
199
|
-
const quaternion = new Quaternion();
|
|
200
|
-
|
|
201
|
-
for ( let i = 0, il = boneParams.length; i < il; i ++ ) {
|
|
202
|
-
|
|
203
|
-
const boneParam = boneParams[ i ];
|
|
204
|
-
const boneIndex = boneNameDictionary[ boneParam.name ];
|
|
205
|
-
|
|
206
|
-
if ( boneIndex === undefined ) continue;
|
|
207
|
-
|
|
208
|
-
const bone = bones[ boneIndex ];
|
|
209
|
-
bone.position.add( vector.fromArray( boneParam.translation ) );
|
|
210
|
-
bone.quaternion.multiply( quaternion.fromArray( boneParam.quaternion ) );
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
mesh.updateMatrixWorld( true );
|
|
215
|
-
|
|
216
|
-
// PMX animation system special path
|
|
217
|
-
if ( this.configuration.pmxAnimation &&
|
|
218
|
-
mesh.geometry.userData.MMD && mesh.geometry.userData.MMD.format === 'pmx' ) {
|
|
219
|
-
|
|
220
|
-
const sortedBonesData = this._sortBoneDataArray( mesh.geometry.userData.MMD.bones.slice() );
|
|
221
|
-
const ikSolver = params.ik !== false ? this._createCCDIKSolver( mesh ) : null;
|
|
222
|
-
const grantSolver = params.grant !== false ? this.createGrantSolver( mesh ) : null;
|
|
223
|
-
this._animatePMXMesh( mesh, sortedBonesData, ikSolver, grantSolver );
|
|
224
|
-
|
|
225
|
-
} else {
|
|
226
|
-
|
|
227
|
-
if ( params.ik !== false ) {
|
|
228
|
-
|
|
229
|
-
this._createCCDIKSolver( mesh ).update();
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if ( params.grant !== false ) {
|
|
234
|
-
|
|
235
|
-
this.createGrantSolver( mesh ).update();
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return this;
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Enabes/Disables an animation feature.
|
|
247
|
-
*
|
|
248
|
-
* @param {string} key
|
|
249
|
-
* @param {boolean} enabled
|
|
250
|
-
* @return {MMDAnimationHelper}
|
|
251
|
-
*/
|
|
252
|
-
enable( key, enabled ) {
|
|
253
|
-
|
|
254
|
-
if ( this.enabled[ key ] === undefined ) {
|
|
255
|
-
|
|
256
|
-
throw new Error( 'THREE.MMDAnimationHelper.enable: '
|
|
257
|
-
+ 'unknown key ' + key );
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
this.enabled[ key ] = enabled;
|
|
262
|
-
|
|
263
|
-
if ( key === 'physics' ) {
|
|
264
|
-
|
|
265
|
-
for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
|
|
266
|
-
|
|
267
|
-
this._optimizeIK( this.meshes[ i ], enabled );
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return this;
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Creates an GrantSolver instance.
|
|
279
|
-
*
|
|
280
|
-
* @param {THREE.SkinnedMesh} mesh
|
|
281
|
-
* @return {GrantSolver}
|
|
282
|
-
*/
|
|
283
|
-
createGrantSolver( mesh ) {
|
|
284
|
-
|
|
285
|
-
return new GrantSolver( mesh, mesh.geometry.userData.MMD.grants );
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// private methods
|
|
290
|
-
|
|
291
|
-
_addMesh( mesh, params ) {
|
|
292
|
-
|
|
293
|
-
if ( this.meshes.indexOf( mesh ) >= 0 ) {
|
|
294
|
-
|
|
295
|
-
throw new Error( 'THREE.MMDAnimationHelper._addMesh: '
|
|
296
|
-
+ 'SkinnedMesh \'' + mesh.name + '\' has already been added.' );
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
this.meshes.push( mesh );
|
|
301
|
-
this.objects.set( mesh, { looped: false } );
|
|
302
|
-
|
|
303
|
-
this._setupMeshAnimation( mesh, params.animation );
|
|
304
|
-
|
|
305
|
-
if ( params.physics !== false ) {
|
|
306
|
-
|
|
307
|
-
this._setupMeshPhysics( mesh, params );
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return this;
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
_setupCamera( camera, params ) {
|
|
316
|
-
|
|
317
|
-
if ( this.camera === camera ) {
|
|
318
|
-
|
|
319
|
-
throw new Error( 'THREE.MMDAnimationHelper._setupCamera: '
|
|
320
|
-
+ 'Camera \'' + camera.name + '\' has already been set.' );
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if ( this.camera ) this.clearCamera( this.camera );
|
|
325
|
-
|
|
326
|
-
this.camera = camera;
|
|
327
|
-
|
|
328
|
-
camera.add( this.cameraTarget );
|
|
329
|
-
|
|
330
|
-
this.objects.set( camera, {} );
|
|
331
|
-
|
|
332
|
-
if ( params.animation !== undefined ) {
|
|
333
|
-
|
|
334
|
-
this._setupCameraAnimation( camera, params.animation );
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
return this;
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
_setupAudio( audio, params ) {
|
|
343
|
-
|
|
344
|
-
if ( this.audio === audio ) {
|
|
345
|
-
|
|
346
|
-
throw new Error( 'THREE.MMDAnimationHelper._setupAudio: '
|
|
347
|
-
+ 'Audio \'' + audio.name + '\' has already been set.' );
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
if ( this.audio ) this.clearAudio( this.audio );
|
|
352
|
-
|
|
353
|
-
this.audio = audio;
|
|
354
|
-
this.audioManager = new AudioManager( audio, params );
|
|
355
|
-
|
|
356
|
-
this.objects.set( this.audioManager, {
|
|
357
|
-
duration: this.audioManager.duration
|
|
358
|
-
} );
|
|
359
|
-
|
|
360
|
-
return this;
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
_removeMesh( mesh ) {
|
|
365
|
-
|
|
366
|
-
let found = false;
|
|
367
|
-
let writeIndex = 0;
|
|
368
|
-
|
|
369
|
-
for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
|
|
370
|
-
|
|
371
|
-
if ( this.meshes[ i ] === mesh ) {
|
|
372
|
-
|
|
373
|
-
this.objects.delete( mesh );
|
|
374
|
-
found = true;
|
|
375
|
-
|
|
376
|
-
continue;
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
this.meshes[ writeIndex ++ ] = this.meshes[ i ];
|
|
381
|
-
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
if ( ! found ) {
|
|
385
|
-
|
|
386
|
-
throw new Error( 'THREE.MMDAnimationHelper._removeMesh: '
|
|
387
|
-
+ 'SkinnedMesh \'' + mesh.name + '\' has not been added yet.' );
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
this.meshes.length = writeIndex;
|
|
392
|
-
|
|
393
|
-
return this;
|
|
394
|
-
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
_clearCamera( camera ) {
|
|
398
|
-
|
|
399
|
-
if ( camera !== this.camera ) {
|
|
400
|
-
|
|
401
|
-
throw new Error( 'THREE.MMDAnimationHelper._clearCamera: '
|
|
402
|
-
+ 'Camera \'' + camera.name + '\' has not been set yet.' );
|
|
403
|
-
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
this.camera.remove( this.cameraTarget );
|
|
407
|
-
|
|
408
|
-
this.objects.delete( this.camera );
|
|
409
|
-
this.camera = null;
|
|
410
|
-
|
|
411
|
-
return this;
|
|
412
|
-
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
_clearAudio( audio ) {
|
|
416
|
-
|
|
417
|
-
if ( audio !== this.audio ) {
|
|
418
|
-
|
|
419
|
-
throw new Error( 'THREE.MMDAnimationHelper._clearAudio: '
|
|
420
|
-
+ 'Audio \'' + audio.name + '\' has not been set yet.' );
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
this.objects.delete( this.audioManager );
|
|
425
|
-
|
|
426
|
-
this.audio = null;
|
|
427
|
-
this.audioManager = null;
|
|
428
|
-
|
|
429
|
-
return this;
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
_setupMeshAnimation( mesh, animation ) {
|
|
434
|
-
|
|
435
|
-
const objects = this.objects.get( mesh );
|
|
436
|
-
|
|
437
|
-
if ( animation !== undefined ) {
|
|
438
|
-
|
|
439
|
-
const animations = Array.isArray( animation )
|
|
440
|
-
? animation : [ animation ];
|
|
441
|
-
|
|
442
|
-
objects.mixer = new AnimationMixer( mesh );
|
|
443
|
-
|
|
444
|
-
for ( let i = 0, il = animations.length; i < il; i ++ ) {
|
|
445
|
-
|
|
446
|
-
objects.mixer.clipAction( animations[ i ] ).play();
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// TODO: find a workaround not to access ._clip looking like a private property
|
|
451
|
-
objects.mixer.addEventListener( 'loop', function ( event ) {
|
|
452
|
-
|
|
453
|
-
const tracks = event.action._clip.tracks;
|
|
454
|
-
|
|
455
|
-
if ( tracks.length > 0 && tracks[ 0 ].name.slice( 0, 6 ) !== '.bones' ) return;
|
|
456
|
-
|
|
457
|
-
objects.looped = true;
|
|
458
|
-
|
|
459
|
-
} );
|
|
460
|
-
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
objects.ikSolver = this._createCCDIKSolver( mesh );
|
|
464
|
-
objects.grantSolver = this.createGrantSolver( mesh );
|
|
465
|
-
|
|
466
|
-
return this;
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
_setupCameraAnimation( camera, animation ) {
|
|
471
|
-
|
|
472
|
-
const animations = Array.isArray( animation )
|
|
473
|
-
? animation : [ animation ];
|
|
474
|
-
|
|
475
|
-
const objects = this.objects.get( camera );
|
|
476
|
-
|
|
477
|
-
objects.mixer = new AnimationMixer( camera );
|
|
478
|
-
|
|
479
|
-
for ( let i = 0, il = animations.length; i < il; i ++ ) {
|
|
480
|
-
|
|
481
|
-
objects.mixer.clipAction( animations[ i ] ).play();
|
|
482
|
-
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
_setupMeshPhysics( mesh, params ) {
|
|
488
|
-
|
|
489
|
-
const objects = this.objects.get( mesh );
|
|
490
|
-
|
|
491
|
-
// shared physics is experimental
|
|
492
|
-
|
|
493
|
-
if ( params.world === undefined && this.sharedPhysics ) {
|
|
494
|
-
|
|
495
|
-
const masterPhysics = this._getMasterPhysics();
|
|
496
|
-
|
|
497
|
-
if ( masterPhysics !== null ) world = masterPhysics.world; // eslint-disable-line no-undef
|
|
498
|
-
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
objects.physics = this._createMMDPhysics( mesh, params );
|
|
502
|
-
|
|
503
|
-
if ( objects.mixer && params.animationWarmup !== false ) {
|
|
504
|
-
|
|
505
|
-
this._animateMesh( mesh, 0 );
|
|
506
|
-
objects.physics.reset();
|
|
507
|
-
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
objects.physics.warmup( params.warmup !== undefined ? params.warmup : 60 );
|
|
511
|
-
|
|
512
|
-
this._optimizeIK( mesh, true );
|
|
513
|
-
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
_animateMesh( mesh, delta ) {
|
|
517
|
-
|
|
518
|
-
const objects = this.objects.get( mesh );
|
|
519
|
-
|
|
520
|
-
const mixer = objects.mixer;
|
|
521
|
-
const ikSolver = objects.ikSolver;
|
|
522
|
-
const grantSolver = objects.grantSolver;
|
|
523
|
-
const physics = objects.physics;
|
|
524
|
-
const looped = objects.looped;
|
|
525
|
-
|
|
526
|
-
if ( mixer && this.enabled.animation ) {
|
|
527
|
-
|
|
528
|
-
// alternate solution to save/restore bones but less performant?
|
|
529
|
-
//mesh.pose();
|
|
530
|
-
//this._updatePropertyMixersBuffer( mesh );
|
|
531
|
-
|
|
532
|
-
this._restoreBones( mesh );
|
|
533
|
-
|
|
534
|
-
mixer.update( delta );
|
|
535
|
-
|
|
536
|
-
this._saveBones( mesh );
|
|
537
|
-
|
|
538
|
-
// PMX animation system special path
|
|
539
|
-
if ( this.configuration.pmxAnimation &&
|
|
540
|
-
mesh.geometry.userData.MMD && mesh.geometry.userData.MMD.format === 'pmx' ) {
|
|
541
|
-
|
|
542
|
-
if ( ! objects.sortedBonesData ) objects.sortedBonesData = this._sortBoneDataArray( mesh.geometry.userData.MMD.bones.slice() );
|
|
543
|
-
|
|
544
|
-
this._animatePMXMesh(
|
|
545
|
-
mesh,
|
|
546
|
-
objects.sortedBonesData,
|
|
547
|
-
ikSolver && this.enabled.ik ? ikSolver : null,
|
|
548
|
-
grantSolver && this.enabled.grant ? grantSolver : null
|
|
549
|
-
);
|
|
550
|
-
|
|
551
|
-
} else {
|
|
552
|
-
|
|
553
|
-
if ( ikSolver && this.enabled.ik ) {
|
|
554
|
-
|
|
555
|
-
mesh.updateMatrixWorld( true );
|
|
556
|
-
ikSolver.update();
|
|
557
|
-
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
if ( grantSolver && this.enabled.grant ) {
|
|
561
|
-
|
|
562
|
-
grantSolver.update();
|
|
563
|
-
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
if ( looped === true && this.enabled.physics ) {
|
|
571
|
-
|
|
572
|
-
if ( physics && this.configuration.resetPhysicsOnLoop ) physics.reset();
|
|
573
|
-
|
|
574
|
-
objects.looped = false;
|
|
575
|
-
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
if ( physics && this.enabled.physics && ! this.sharedPhysics ) {
|
|
579
|
-
|
|
580
|
-
this.onBeforePhysics( mesh );
|
|
581
|
-
physics.update( delta );
|
|
582
|
-
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
// Sort bones in order by 1. transformationClass and 2. bone index.
|
|
588
|
-
// In PMX animation system, bone transformations should be processed
|
|
589
|
-
// in this order.
|
|
590
|
-
_sortBoneDataArray( boneDataArray ) {
|
|
591
|
-
|
|
592
|
-
return boneDataArray.sort( function ( a, b ) {
|
|
593
|
-
|
|
594
|
-
if ( a.transformationClass !== b.transformationClass ) {
|
|
595
|
-
|
|
596
|
-
return a.transformationClass - b.transformationClass;
|
|
597
|
-
|
|
598
|
-
} else {
|
|
599
|
-
|
|
600
|
-
return a.index - b.index;
|
|
601
|
-
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
} );
|
|
605
|
-
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
// PMX Animation system is a bit too complex and doesn't great match to
|
|
609
|
-
// Three.js Animation system. This method attempts to simulate it as much as
|
|
610
|
-
// possible but doesn't perfectly simulate.
|
|
611
|
-
// This method is more costly than the regular one so
|
|
612
|
-
// you are recommended to set constructor parameter "pmxAnimation: true"
|
|
613
|
-
// only if your PMX model animation doesn't work well.
|
|
614
|
-
// If you need better method you would be required to write your own.
|
|
615
|
-
_animatePMXMesh( mesh, sortedBonesData, ikSolver, grantSolver ) {
|
|
616
|
-
|
|
617
|
-
_quaternionIndex = 0;
|
|
618
|
-
_grantResultMap.clear();
|
|
619
|
-
|
|
620
|
-
for ( let i = 0, il = sortedBonesData.length; i < il; i ++ ) {
|
|
621
|
-
|
|
622
|
-
updateOne( mesh, sortedBonesData[ i ].index, ikSolver, grantSolver );
|
|
623
|
-
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
mesh.updateMatrixWorld( true );
|
|
627
|
-
return this;
|
|
628
|
-
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
_animateCamera( camera, delta ) {
|
|
632
|
-
|
|
633
|
-
const mixer = this.objects.get( camera ).mixer;
|
|
634
|
-
|
|
635
|
-
if ( mixer && this.enabled.cameraAnimation ) {
|
|
636
|
-
|
|
637
|
-
mixer.update( delta );
|
|
638
|
-
|
|
639
|
-
camera.updateProjectionMatrix();
|
|
640
|
-
|
|
641
|
-
camera.up.set( 0, 1, 0 );
|
|
642
|
-
camera.up.applyQuaternion( camera.quaternion );
|
|
643
|
-
camera.lookAt( this.cameraTarget.position );
|
|
644
|
-
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
_optimizeIK( mesh, physicsEnabled ) {
|
|
650
|
-
|
|
651
|
-
const iks = mesh.geometry.userData.MMD.iks;
|
|
652
|
-
const bones = mesh.geometry.userData.MMD.bones;
|
|
653
|
-
|
|
654
|
-
for ( let i = 0, il = iks.length; i < il; i ++ ) {
|
|
655
|
-
|
|
656
|
-
const ik = iks[ i ];
|
|
657
|
-
const links = ik.links;
|
|
658
|
-
|
|
659
|
-
for ( let j = 0, jl = links.length; j < jl; j ++ ) {
|
|
660
|
-
|
|
661
|
-
const link = links[ j ];
|
|
662
|
-
|
|
663
|
-
if ( physicsEnabled === true ) {
|
|
664
|
-
|
|
665
|
-
// disable IK of the bone the corresponding rigidBody type of which is 1 or 2
|
|
666
|
-
// because its rotation will be overriden by physics
|
|
667
|
-
link.enabled = bones[ link.index ].rigidBodyType > 0 ? false : true;
|
|
668
|
-
|
|
669
|
-
} else {
|
|
670
|
-
|
|
671
|
-
link.enabled = true;
|
|
672
|
-
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
_createCCDIKSolver( mesh ) {
|
|
682
|
-
|
|
683
|
-
if ( CCDIKSolver === undefined ) {
|
|
684
|
-
|
|
685
|
-
throw new Error( 'THREE.MMDAnimationHelper: Import CCDIKSolver.' );
|
|
686
|
-
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
return new CCDIKSolver( mesh, mesh.geometry.userData.MMD.iks );
|
|
690
|
-
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
_createMMDPhysics( mesh, params ) {
|
|
694
|
-
|
|
695
|
-
if ( MMDPhysics === undefined ) {
|
|
696
|
-
|
|
697
|
-
throw new Error( 'THREE.MMDPhysics: Import MMDPhysics.' );
|
|
698
|
-
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
return new MMDPhysics(
|
|
702
|
-
mesh,
|
|
703
|
-
mesh.geometry.userData.MMD.rigidBodies,
|
|
704
|
-
mesh.geometry.userData.MMD.constraints,
|
|
705
|
-
params );
|
|
706
|
-
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
/*
|
|
710
|
-
* Detects the longest duration and then sets it to them to sync.
|
|
711
|
-
* TODO: Not to access private properties ( ._actions and ._clip )
|
|
712
|
-
*/
|
|
713
|
-
_syncDuration() {
|
|
714
|
-
|
|
715
|
-
let max = 0.0;
|
|
716
|
-
|
|
717
|
-
const objects = this.objects;
|
|
718
|
-
const meshes = this.meshes;
|
|
719
|
-
const camera = this.camera;
|
|
720
|
-
const audioManager = this.audioManager;
|
|
721
|
-
|
|
722
|
-
// get the longest duration
|
|
723
|
-
|
|
724
|
-
for ( let i = 0, il = meshes.length; i < il; i ++ ) {
|
|
725
|
-
|
|
726
|
-
const mixer = this.objects.get( meshes[ i ] ).mixer;
|
|
727
|
-
|
|
728
|
-
if ( mixer === undefined ) continue;
|
|
729
|
-
|
|
730
|
-
for ( let j = 0; j < mixer._actions.length; j ++ ) {
|
|
731
|
-
|
|
732
|
-
const clip = mixer._actions[ j ]._clip;
|
|
733
|
-
|
|
734
|
-
if ( ! objects.has( clip ) ) {
|
|
735
|
-
|
|
736
|
-
objects.set( clip, {
|
|
737
|
-
duration: clip.duration
|
|
738
|
-
} );
|
|
739
|
-
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
max = Math.max( max, objects.get( clip ).duration );
|
|
743
|
-
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
if ( camera !== null ) {
|
|
749
|
-
|
|
750
|
-
const mixer = this.objects.get( camera ).mixer;
|
|
751
|
-
|
|
752
|
-
if ( mixer !== undefined ) {
|
|
753
|
-
|
|
754
|
-
for ( let i = 0, il = mixer._actions.length; i < il; i ++ ) {
|
|
755
|
-
|
|
756
|
-
const clip = mixer._actions[ i ]._clip;
|
|
757
|
-
|
|
758
|
-
if ( ! objects.has( clip ) ) {
|
|
759
|
-
|
|
760
|
-
objects.set( clip, {
|
|
761
|
-
duration: clip.duration
|
|
762
|
-
} );
|
|
763
|
-
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
max = Math.max( max, objects.get( clip ).duration );
|
|
767
|
-
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
if ( audioManager !== null ) {
|
|
775
|
-
|
|
776
|
-
max = Math.max( max, objects.get( audioManager ).duration );
|
|
777
|
-
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
max += this.configuration.afterglow;
|
|
781
|
-
|
|
782
|
-
// update the duration
|
|
783
|
-
|
|
784
|
-
for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
|
|
785
|
-
|
|
786
|
-
const mixer = this.objects.get( this.meshes[ i ] ).mixer;
|
|
787
|
-
|
|
788
|
-
if ( mixer === undefined ) continue;
|
|
789
|
-
|
|
790
|
-
for ( let j = 0, jl = mixer._actions.length; j < jl; j ++ ) {
|
|
791
|
-
|
|
792
|
-
mixer._actions[ j ]._clip.duration = max;
|
|
793
|
-
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
if ( camera !== null ) {
|
|
799
|
-
|
|
800
|
-
const mixer = this.objects.get( camera ).mixer;
|
|
801
|
-
|
|
802
|
-
if ( mixer !== undefined ) {
|
|
803
|
-
|
|
804
|
-
for ( let i = 0, il = mixer._actions.length; i < il; i ++ ) {
|
|
805
|
-
|
|
806
|
-
mixer._actions[ i ]._clip.duration = max;
|
|
807
|
-
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
if ( audioManager !== null ) {
|
|
815
|
-
|
|
816
|
-
audioManager.duration = max;
|
|
817
|
-
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
// workaround
|
|
823
|
-
|
|
824
|
-
_updatePropertyMixersBuffer( mesh ) {
|
|
825
|
-
|
|
826
|
-
const mixer = this.objects.get( mesh ).mixer;
|
|
827
|
-
|
|
828
|
-
const propertyMixers = mixer._bindings;
|
|
829
|
-
const accuIndex = mixer._accuIndex;
|
|
830
|
-
|
|
831
|
-
for ( let i = 0, il = propertyMixers.length; i < il; i ++ ) {
|
|
832
|
-
|
|
833
|
-
const propertyMixer = propertyMixers[ i ];
|
|
834
|
-
const buffer = propertyMixer.buffer;
|
|
835
|
-
const stride = propertyMixer.valueSize;
|
|
836
|
-
const offset = ( accuIndex + 1 ) * stride;
|
|
837
|
-
|
|
838
|
-
propertyMixer.binding.getValue( buffer, offset );
|
|
839
|
-
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
/*
|
|
845
|
-
* Avoiding these two issues by restore/save bones before/after mixer animation.
|
|
846
|
-
*
|
|
847
|
-
* 1. PropertyMixer used by AnimationMixer holds cache value in .buffer.
|
|
848
|
-
* Calculating IK, Grant, and Physics after mixer animation can break
|
|
849
|
-
* the cache coherency.
|
|
850
|
-
*
|
|
851
|
-
* 2. Applying Grant two or more times without reset the posing breaks model.
|
|
852
|
-
*/
|
|
853
|
-
_saveBones( mesh ) {
|
|
854
|
-
|
|
855
|
-
const objects = this.objects.get( mesh );
|
|
856
|
-
|
|
857
|
-
const bones = mesh.skeleton.bones;
|
|
858
|
-
|
|
859
|
-
let backupBones = objects.backupBones;
|
|
860
|
-
|
|
861
|
-
if ( backupBones === undefined ) {
|
|
862
|
-
|
|
863
|
-
backupBones = new Float32Array( bones.length * 7 );
|
|
864
|
-
objects.backupBones = backupBones;
|
|
865
|
-
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
for ( let i = 0, il = bones.length; i < il; i ++ ) {
|
|
869
|
-
|
|
870
|
-
const bone = bones[ i ];
|
|
871
|
-
bone.position.toArray( backupBones, i * 7 );
|
|
872
|
-
bone.quaternion.toArray( backupBones, i * 7 + 3 );
|
|
873
|
-
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
_restoreBones( mesh ) {
|
|
879
|
-
|
|
880
|
-
const objects = this.objects.get( mesh );
|
|
881
|
-
|
|
882
|
-
const backupBones = objects.backupBones;
|
|
883
|
-
|
|
884
|
-
if ( backupBones === undefined ) return;
|
|
885
|
-
|
|
886
|
-
const bones = mesh.skeleton.bones;
|
|
887
|
-
|
|
888
|
-
for ( let i = 0, il = bones.length; i < il; i ++ ) {
|
|
889
|
-
|
|
890
|
-
const bone = bones[ i ];
|
|
891
|
-
bone.position.fromArray( backupBones, i * 7 );
|
|
892
|
-
bone.quaternion.fromArray( backupBones, i * 7 + 3 );
|
|
893
|
-
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
// experimental
|
|
899
|
-
|
|
900
|
-
_getMasterPhysics() {
|
|
901
|
-
|
|
902
|
-
if ( this.masterPhysics !== null ) return this.masterPhysics;
|
|
903
|
-
|
|
904
|
-
for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
|
|
905
|
-
|
|
906
|
-
const physics = this.meshes[ i ].physics;
|
|
907
|
-
|
|
908
|
-
if ( physics !== undefined && physics !== null ) {
|
|
909
|
-
|
|
910
|
-
this.masterPhysics = physics;
|
|
911
|
-
return this.masterPhysics;
|
|
912
|
-
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
return null;
|
|
918
|
-
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
_updateSharedPhysics( delta ) {
|
|
922
|
-
|
|
923
|
-
if ( this.meshes.length === 0 || ! this.enabled.physics || ! this.sharedPhysics ) return;
|
|
924
|
-
|
|
925
|
-
const physics = this._getMasterPhysics();
|
|
926
|
-
|
|
927
|
-
if ( physics === null ) return;
|
|
928
|
-
|
|
929
|
-
for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
|
|
930
|
-
|
|
931
|
-
const p = this.meshes[ i ].physics;
|
|
932
|
-
|
|
933
|
-
if ( p !== null && p !== undefined ) {
|
|
934
|
-
|
|
935
|
-
p.updateRigidBodies();
|
|
936
|
-
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
physics.stepSimulation( delta );
|
|
942
|
-
|
|
943
|
-
for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
|
|
944
|
-
|
|
945
|
-
const p = this.meshes[ i ].physics;
|
|
946
|
-
|
|
947
|
-
if ( p !== null && p !== undefined ) {
|
|
948
|
-
|
|
949
|
-
p.updateBones();
|
|
950
|
-
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
// Keep working quaternions for less GC
|
|
960
|
-
const _quaternions = [];
|
|
961
|
-
let _quaternionIndex = 0;
|
|
962
|
-
|
|
963
|
-
function getQuaternion() {
|
|
964
|
-
|
|
965
|
-
if ( _quaternionIndex >= _quaternions.length ) {
|
|
966
|
-
|
|
967
|
-
_quaternions.push( new Quaternion() );
|
|
968
|
-
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
return _quaternions[ _quaternionIndex ++ ];
|
|
972
|
-
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
// Save rotation whose grant and IK are already applied
|
|
976
|
-
// used by grant children
|
|
977
|
-
const _grantResultMap = new Map();
|
|
978
|
-
|
|
979
|
-
function updateOne( mesh, boneIndex, ikSolver, grantSolver ) {
|
|
980
|
-
|
|
981
|
-
const bones = mesh.skeleton.bones;
|
|
982
|
-
const bonesData = mesh.geometry.userData.MMD.bones;
|
|
983
|
-
const boneData = bonesData[ boneIndex ];
|
|
984
|
-
const bone = bones[ boneIndex ];
|
|
985
|
-
|
|
986
|
-
// Return if already updated by being referred as a grant parent.
|
|
987
|
-
if ( _grantResultMap.has( boneIndex ) ) return;
|
|
988
|
-
|
|
989
|
-
const quaternion = getQuaternion();
|
|
990
|
-
|
|
991
|
-
// Initialize grant result here to prevent infinite loop.
|
|
992
|
-
// If it's referred before updating with actual result later
|
|
993
|
-
// result without applyting IK or grant is gotten
|
|
994
|
-
// but better than composing of infinite loop.
|
|
995
|
-
_grantResultMap.set( boneIndex, quaternion.copy( bone.quaternion ) );
|
|
996
|
-
|
|
997
|
-
// @TODO: Support global grant and grant position
|
|
998
|
-
if ( grantSolver && boneData.grant &&
|
|
999
|
-
! boneData.grant.isLocal && boneData.grant.affectRotation ) {
|
|
1000
|
-
|
|
1001
|
-
const parentIndex = boneData.grant.parentIndex;
|
|
1002
|
-
const ratio = boneData.grant.ratio;
|
|
1003
|
-
|
|
1004
|
-
if ( ! _grantResultMap.has( parentIndex ) ) {
|
|
1005
|
-
|
|
1006
|
-
updateOne( mesh, parentIndex, ikSolver, grantSolver );
|
|
1007
|
-
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
grantSolver.addGrantRotation( bone, _grantResultMap.get( parentIndex ), ratio );
|
|
1011
|
-
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
if ( ikSolver && boneData.ik ) {
|
|
1015
|
-
|
|
1016
|
-
// @TODO: Updating world matrices every time solving an IK bone is
|
|
1017
|
-
// costly. Optimize if possible.
|
|
1018
|
-
mesh.updateMatrixWorld( true );
|
|
1019
|
-
ikSolver.updateOne( boneData.ik );
|
|
1020
|
-
|
|
1021
|
-
// No confident, but it seems the grant results with ik links should be updated?
|
|
1022
|
-
const links = boneData.ik.links;
|
|
1023
|
-
|
|
1024
|
-
for ( let i = 0, il = links.length; i < il; i ++ ) {
|
|
1025
|
-
|
|
1026
|
-
const link = links[ i ];
|
|
1027
|
-
|
|
1028
|
-
if ( link.enabled === false ) continue;
|
|
1029
|
-
|
|
1030
|
-
const linkIndex = link.index;
|
|
1031
|
-
|
|
1032
|
-
if ( _grantResultMap.has( linkIndex ) ) {
|
|
1033
|
-
|
|
1034
|
-
_grantResultMap.set( linkIndex, _grantResultMap.get( linkIndex ).copy( bones[ linkIndex ].quaternion ) );
|
|
1035
|
-
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
// Update with the actual result here
|
|
1043
|
-
quaternion.copy( bone.quaternion );
|
|
1044
|
-
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
//
|
|
1048
|
-
|
|
1049
|
-
class AudioManager {
|
|
1050
|
-
|
|
1051
|
-
/**
|
|
1052
|
-
* @param {THREE.Audio} audio
|
|
1053
|
-
* @param {Object} params - (optional)
|
|
1054
|
-
* @param {Nuumber} params.delayTime
|
|
1055
|
-
*/
|
|
1056
|
-
constructor( audio, params = {} ) {
|
|
1057
|
-
|
|
1058
|
-
this.audio = audio;
|
|
1059
|
-
|
|
1060
|
-
this.elapsedTime = 0.0;
|
|
1061
|
-
this.currentTime = 0.0;
|
|
1062
|
-
this.delayTime = params.delayTime !== undefined
|
|
1063
|
-
? params.delayTime : 0.0;
|
|
1064
|
-
|
|
1065
|
-
this.audioDuration = this.audio.buffer.duration;
|
|
1066
|
-
this.duration = this.audioDuration + this.delayTime;
|
|
1067
|
-
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
/**
|
|
1071
|
-
* @param {Number} delta
|
|
1072
|
-
* @return {AudioManager}
|
|
1073
|
-
*/
|
|
1074
|
-
control( delta ) {
|
|
1075
|
-
|
|
1076
|
-
this.elapsed += delta;
|
|
1077
|
-
this.currentTime += delta;
|
|
1078
|
-
|
|
1079
|
-
if ( this._shouldStopAudio() ) this.audio.stop();
|
|
1080
|
-
if ( this._shouldStartAudio() ) this.audio.play();
|
|
1081
|
-
|
|
1082
|
-
return this;
|
|
1083
|
-
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
// private methods
|
|
1087
|
-
|
|
1088
|
-
_shouldStartAudio() {
|
|
1089
|
-
|
|
1090
|
-
if ( this.audio.isPlaying ) return false;
|
|
1091
|
-
|
|
1092
|
-
while ( this.currentTime >= this.duration ) {
|
|
1093
|
-
|
|
1094
|
-
this.currentTime -= this.duration;
|
|
1095
|
-
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
if ( this.currentTime < this.delayTime ) return false;
|
|
1099
|
-
|
|
1100
|
-
// 'duration' can be bigger than 'audioDuration + delayTime' because of sync configuration
|
|
1101
|
-
if ( ( this.currentTime - this.delayTime ) > this.audioDuration ) return false;
|
|
1102
|
-
|
|
1103
|
-
return true;
|
|
1104
|
-
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
_shouldStopAudio() {
|
|
1108
|
-
|
|
1109
|
-
return this.audio.isPlaying &&
|
|
1110
|
-
this.currentTime >= this.duration;
|
|
1111
|
-
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
const _q = new Quaternion();
|
|
1117
|
-
|
|
1118
|
-
/**
|
|
1119
|
-
* Solver for Grant (Fuyo in Japanese. I just google translated because
|
|
1120
|
-
* Fuyo may be MMD specific term and may not be common word in 3D CG terms.)
|
|
1121
|
-
* Grant propagates a bone's transform to other bones transforms even if
|
|
1122
|
-
* they are not children.
|
|
1123
|
-
* @param {THREE.SkinnedMesh} mesh
|
|
1124
|
-
* @param {Array<Object>} grants
|
|
1125
|
-
*/
|
|
1126
|
-
class GrantSolver {
|
|
1127
|
-
|
|
1128
|
-
constructor( mesh, grants = [] ) {
|
|
1129
|
-
|
|
1130
|
-
this.mesh = mesh;
|
|
1131
|
-
this.grants = grants;
|
|
1132
|
-
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
/**
|
|
1136
|
-
* Solve all the grant bones
|
|
1137
|
-
* @return {GrantSolver}
|
|
1138
|
-
*/
|
|
1139
|
-
update() {
|
|
1140
|
-
|
|
1141
|
-
const grants = this.grants;
|
|
1142
|
-
|
|
1143
|
-
for ( let i = 0, il = grants.length; i < il; i ++ ) {
|
|
1144
|
-
|
|
1145
|
-
this.updateOne( grants[ i ] );
|
|
1146
|
-
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
return this;
|
|
1150
|
-
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
|
-
/**
|
|
1154
|
-
* Solve a grant bone
|
|
1155
|
-
* @param {Object} grant - grant parameter
|
|
1156
|
-
* @return {GrantSolver}
|
|
1157
|
-
*/
|
|
1158
|
-
updateOne( grant ) {
|
|
1159
|
-
|
|
1160
|
-
const bones = this.mesh.skeleton.bones;
|
|
1161
|
-
const bone = bones[ grant.index ];
|
|
1162
|
-
const parentBone = bones[ grant.parentIndex ];
|
|
1163
|
-
|
|
1164
|
-
if ( grant.isLocal ) {
|
|
1165
|
-
|
|
1166
|
-
// TODO: implement
|
|
1167
|
-
if ( grant.affectPosition ) {
|
|
1168
|
-
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
// TODO: implement
|
|
1172
|
-
if ( grant.affectRotation ) {
|
|
1173
|
-
|
|
1174
|
-
}
|
|
1175
|
-
|
|
1176
|
-
} else {
|
|
1177
|
-
|
|
1178
|
-
// TODO: implement
|
|
1179
|
-
if ( grant.affectPosition ) {
|
|
1180
|
-
|
|
1181
|
-
}
|
|
1182
|
-
|
|
1183
|
-
if ( grant.affectRotation ) {
|
|
1184
|
-
|
|
1185
|
-
this.addGrantRotation( bone, parentBone.quaternion, grant.ratio );
|
|
1186
|
-
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
|
-
}
|
|
1190
|
-
|
|
1191
|
-
return this;
|
|
1192
|
-
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
addGrantRotation( bone, q, ratio ) {
|
|
1196
|
-
|
|
1197
|
-
_q.set( 0, 0, 0, 1 );
|
|
1198
|
-
_q.slerp( q, ratio );
|
|
1199
|
-
bone.quaternion.multiply( _q );
|
|
1200
|
-
|
|
1201
|
-
return this;
|
|
1202
|
-
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
export { MMDAnimationHelper };
|
|
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
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Adds an Three.js Object to helper and setups animation.
|
|
68
|
+
* The anmation durations of added objects are synched
|
|
69
|
+
* if this.configuration.sync is true.
|
|
70
|
+
*
|
|
71
|
+
* @param {THREE.SkinnedMesh|THREE.Camera|THREE.Audio} object
|
|
72
|
+
* @param {Object} params - (optional)
|
|
73
|
+
* @param {THREE.AnimationClip|Array<THREE.AnimationClip>} params.animation - Only for THREE.SkinnedMesh and THREE.Camera. Default is undefined.
|
|
74
|
+
* @param {boolean} params.physics - Only for THREE.SkinnedMesh. Default is true.
|
|
75
|
+
* @param {Integer} params.warmup - Only for THREE.SkinnedMesh and physics is true. Default is 60.
|
|
76
|
+
* @param {Number} params.unitStep - Only for THREE.SkinnedMesh and physics is true. Default is 1 / 65.
|
|
77
|
+
* @param {Integer} params.maxStepNum - Only for THREE.SkinnedMesh and physics is true. Default is 3.
|
|
78
|
+
* @param {Vector3} params.gravity - Only for THREE.SkinnedMesh and physics is true. Default ( 0, - 9.8 * 10, 0 ).
|
|
79
|
+
* @param {Number} params.delayTime - Only for THREE.Audio. Default is 0.0.
|
|
80
|
+
* @return {MMDAnimationHelper}
|
|
81
|
+
*/
|
|
82
|
+
add( object, params = {} ) {
|
|
83
|
+
|
|
84
|
+
if ( object.isSkinnedMesh ) {
|
|
85
|
+
|
|
86
|
+
this._addMesh( object, params );
|
|
87
|
+
|
|
88
|
+
} else if ( object.isCamera ) {
|
|
89
|
+
|
|
90
|
+
this._setupCamera( object, params );
|
|
91
|
+
|
|
92
|
+
} else if ( object.type === 'Audio' ) {
|
|
93
|
+
|
|
94
|
+
this._setupAudio( object, params );
|
|
95
|
+
|
|
96
|
+
} else {
|
|
97
|
+
|
|
98
|
+
throw new Error( 'THREE.MMDAnimationHelper.add: '
|
|
99
|
+
+ 'accepts only '
|
|
100
|
+
+ 'THREE.SkinnedMesh or '
|
|
101
|
+
+ 'THREE.Camera or '
|
|
102
|
+
+ 'THREE.Audio instance.' );
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if ( this.configuration.sync ) this._syncDuration();
|
|
107
|
+
|
|
108
|
+
return this;
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Removes an Three.js Object from helper.
|
|
114
|
+
*
|
|
115
|
+
* @param {THREE.SkinnedMesh|THREE.Camera|THREE.Audio} object
|
|
116
|
+
* @return {MMDAnimationHelper}
|
|
117
|
+
*/
|
|
118
|
+
remove( object ) {
|
|
119
|
+
|
|
120
|
+
if ( object.isSkinnedMesh ) {
|
|
121
|
+
|
|
122
|
+
this._removeMesh( object );
|
|
123
|
+
|
|
124
|
+
} else if ( object.isCamera ) {
|
|
125
|
+
|
|
126
|
+
this._clearCamera( object );
|
|
127
|
+
|
|
128
|
+
} else if ( object.type === 'Audio' ) {
|
|
129
|
+
|
|
130
|
+
this._clearAudio( object );
|
|
131
|
+
|
|
132
|
+
} else {
|
|
133
|
+
|
|
134
|
+
throw new Error( 'THREE.MMDAnimationHelper.remove: '
|
|
135
|
+
+ 'accepts only '
|
|
136
|
+
+ 'THREE.SkinnedMesh or '
|
|
137
|
+
+ 'THREE.Camera or '
|
|
138
|
+
+ 'THREE.Audio instance.' );
|
|
139
|
+
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if ( this.configuration.sync ) this._syncDuration();
|
|
143
|
+
|
|
144
|
+
return this;
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Updates the animation.
|
|
150
|
+
*
|
|
151
|
+
* @param {Number} delta
|
|
152
|
+
* @return {MMDAnimationHelper}
|
|
153
|
+
*/
|
|
154
|
+
update( delta ) {
|
|
155
|
+
|
|
156
|
+
if ( this.audioManager !== null ) this.audioManager.control( delta );
|
|
157
|
+
|
|
158
|
+
for ( let i = 0; i < this.meshes.length; i ++ ) {
|
|
159
|
+
|
|
160
|
+
this._animateMesh( this.meshes[ i ], delta );
|
|
161
|
+
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if ( this.sharedPhysics ) this._updateSharedPhysics( delta );
|
|
165
|
+
|
|
166
|
+
if ( this.camera !== null ) this._animateCamera( this.camera, delta );
|
|
167
|
+
|
|
168
|
+
return this;
|
|
169
|
+
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Changes the pose of SkinnedMesh as VPD specifies.
|
|
174
|
+
*
|
|
175
|
+
* @param {THREE.SkinnedMesh} mesh
|
|
176
|
+
* @param {Object} vpd - VPD content parsed MMDParser
|
|
177
|
+
* @param {Object} params - (optional)
|
|
178
|
+
* @param {boolean} params.resetPose - Default is true.
|
|
179
|
+
* @param {boolean} params.ik - Default is true.
|
|
180
|
+
* @param {boolean} params.grant - Default is true.
|
|
181
|
+
* @return {MMDAnimationHelper}
|
|
182
|
+
*/
|
|
183
|
+
pose( mesh, vpd, params = {} ) {
|
|
184
|
+
|
|
185
|
+
if ( params.resetPose !== false ) mesh.pose();
|
|
186
|
+
|
|
187
|
+
const bones = mesh.skeleton.bones;
|
|
188
|
+
const boneParams = vpd.bones;
|
|
189
|
+
|
|
190
|
+
const boneNameDictionary = {};
|
|
191
|
+
|
|
192
|
+
for ( let i = 0, il = bones.length; i < il; i ++ ) {
|
|
193
|
+
|
|
194
|
+
boneNameDictionary[ bones[ i ].name ] = i;
|
|
195
|
+
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const vector = new Vector3();
|
|
199
|
+
const quaternion = new Quaternion();
|
|
200
|
+
|
|
201
|
+
for ( let i = 0, il = boneParams.length; i < il; i ++ ) {
|
|
202
|
+
|
|
203
|
+
const boneParam = boneParams[ i ];
|
|
204
|
+
const boneIndex = boneNameDictionary[ boneParam.name ];
|
|
205
|
+
|
|
206
|
+
if ( boneIndex === undefined ) continue;
|
|
207
|
+
|
|
208
|
+
const bone = bones[ boneIndex ];
|
|
209
|
+
bone.position.add( vector.fromArray( boneParam.translation ) );
|
|
210
|
+
bone.quaternion.multiply( quaternion.fromArray( boneParam.quaternion ) );
|
|
211
|
+
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
mesh.updateMatrixWorld( true );
|
|
215
|
+
|
|
216
|
+
// PMX animation system special path
|
|
217
|
+
if ( this.configuration.pmxAnimation &&
|
|
218
|
+
mesh.geometry.userData.MMD && mesh.geometry.userData.MMD.format === 'pmx' ) {
|
|
219
|
+
|
|
220
|
+
const sortedBonesData = this._sortBoneDataArray( mesh.geometry.userData.MMD.bones.slice() );
|
|
221
|
+
const ikSolver = params.ik !== false ? this._createCCDIKSolver( mesh ) : null;
|
|
222
|
+
const grantSolver = params.grant !== false ? this.createGrantSolver( mesh ) : null;
|
|
223
|
+
this._animatePMXMesh( mesh, sortedBonesData, ikSolver, grantSolver );
|
|
224
|
+
|
|
225
|
+
} else {
|
|
226
|
+
|
|
227
|
+
if ( params.ik !== false ) {
|
|
228
|
+
|
|
229
|
+
this._createCCDIKSolver( mesh ).update();
|
|
230
|
+
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if ( params.grant !== false ) {
|
|
234
|
+
|
|
235
|
+
this.createGrantSolver( mesh ).update();
|
|
236
|
+
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return this;
|
|
242
|
+
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Enabes/Disables an animation feature.
|
|
247
|
+
*
|
|
248
|
+
* @param {string} key
|
|
249
|
+
* @param {boolean} enabled
|
|
250
|
+
* @return {MMDAnimationHelper}
|
|
251
|
+
*/
|
|
252
|
+
enable( key, enabled ) {
|
|
253
|
+
|
|
254
|
+
if ( this.enabled[ key ] === undefined ) {
|
|
255
|
+
|
|
256
|
+
throw new Error( 'THREE.MMDAnimationHelper.enable: '
|
|
257
|
+
+ 'unknown key ' + key );
|
|
258
|
+
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
this.enabled[ key ] = enabled;
|
|
262
|
+
|
|
263
|
+
if ( key === 'physics' ) {
|
|
264
|
+
|
|
265
|
+
for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
|
|
266
|
+
|
|
267
|
+
this._optimizeIK( this.meshes[ i ], enabled );
|
|
268
|
+
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return this;
|
|
274
|
+
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Creates an GrantSolver instance.
|
|
279
|
+
*
|
|
280
|
+
* @param {THREE.SkinnedMesh} mesh
|
|
281
|
+
* @return {GrantSolver}
|
|
282
|
+
*/
|
|
283
|
+
createGrantSolver( mesh ) {
|
|
284
|
+
|
|
285
|
+
return new GrantSolver( mesh, mesh.geometry.userData.MMD.grants );
|
|
286
|
+
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// private methods
|
|
290
|
+
|
|
291
|
+
_addMesh( mesh, params ) {
|
|
292
|
+
|
|
293
|
+
if ( this.meshes.indexOf( mesh ) >= 0 ) {
|
|
294
|
+
|
|
295
|
+
throw new Error( 'THREE.MMDAnimationHelper._addMesh: '
|
|
296
|
+
+ 'SkinnedMesh \'' + mesh.name + '\' has already been added.' );
|
|
297
|
+
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
this.meshes.push( mesh );
|
|
301
|
+
this.objects.set( mesh, { looped: false } );
|
|
302
|
+
|
|
303
|
+
this._setupMeshAnimation( mesh, params.animation );
|
|
304
|
+
|
|
305
|
+
if ( params.physics !== false ) {
|
|
306
|
+
|
|
307
|
+
this._setupMeshPhysics( mesh, params );
|
|
308
|
+
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return this;
|
|
312
|
+
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
_setupCamera( camera, params ) {
|
|
316
|
+
|
|
317
|
+
if ( this.camera === camera ) {
|
|
318
|
+
|
|
319
|
+
throw new Error( 'THREE.MMDAnimationHelper._setupCamera: '
|
|
320
|
+
+ 'Camera \'' + camera.name + '\' has already been set.' );
|
|
321
|
+
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if ( this.camera ) this.clearCamera( this.camera );
|
|
325
|
+
|
|
326
|
+
this.camera = camera;
|
|
327
|
+
|
|
328
|
+
camera.add( this.cameraTarget );
|
|
329
|
+
|
|
330
|
+
this.objects.set( camera, {} );
|
|
331
|
+
|
|
332
|
+
if ( params.animation !== undefined ) {
|
|
333
|
+
|
|
334
|
+
this._setupCameraAnimation( camera, params.animation );
|
|
335
|
+
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return this;
|
|
339
|
+
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
_setupAudio( audio, params ) {
|
|
343
|
+
|
|
344
|
+
if ( this.audio === audio ) {
|
|
345
|
+
|
|
346
|
+
throw new Error( 'THREE.MMDAnimationHelper._setupAudio: '
|
|
347
|
+
+ 'Audio \'' + audio.name + '\' has already been set.' );
|
|
348
|
+
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if ( this.audio ) this.clearAudio( this.audio );
|
|
352
|
+
|
|
353
|
+
this.audio = audio;
|
|
354
|
+
this.audioManager = new AudioManager( audio, params );
|
|
355
|
+
|
|
356
|
+
this.objects.set( this.audioManager, {
|
|
357
|
+
duration: this.audioManager.duration
|
|
358
|
+
} );
|
|
359
|
+
|
|
360
|
+
return this;
|
|
361
|
+
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
_removeMesh( mesh ) {
|
|
365
|
+
|
|
366
|
+
let found = false;
|
|
367
|
+
let writeIndex = 0;
|
|
368
|
+
|
|
369
|
+
for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
|
|
370
|
+
|
|
371
|
+
if ( this.meshes[ i ] === mesh ) {
|
|
372
|
+
|
|
373
|
+
this.objects.delete( mesh );
|
|
374
|
+
found = true;
|
|
375
|
+
|
|
376
|
+
continue;
|
|
377
|
+
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
this.meshes[ writeIndex ++ ] = this.meshes[ i ];
|
|
381
|
+
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if ( ! found ) {
|
|
385
|
+
|
|
386
|
+
throw new Error( 'THREE.MMDAnimationHelper._removeMesh: '
|
|
387
|
+
+ 'SkinnedMesh \'' + mesh.name + '\' has not been added yet.' );
|
|
388
|
+
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
this.meshes.length = writeIndex;
|
|
392
|
+
|
|
393
|
+
return this;
|
|
394
|
+
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
_clearCamera( camera ) {
|
|
398
|
+
|
|
399
|
+
if ( camera !== this.camera ) {
|
|
400
|
+
|
|
401
|
+
throw new Error( 'THREE.MMDAnimationHelper._clearCamera: '
|
|
402
|
+
+ 'Camera \'' + camera.name + '\' has not been set yet.' );
|
|
403
|
+
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
this.camera.remove( this.cameraTarget );
|
|
407
|
+
|
|
408
|
+
this.objects.delete( this.camera );
|
|
409
|
+
this.camera = null;
|
|
410
|
+
|
|
411
|
+
return this;
|
|
412
|
+
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
_clearAudio( audio ) {
|
|
416
|
+
|
|
417
|
+
if ( audio !== this.audio ) {
|
|
418
|
+
|
|
419
|
+
throw new Error( 'THREE.MMDAnimationHelper._clearAudio: '
|
|
420
|
+
+ 'Audio \'' + audio.name + '\' has not been set yet.' );
|
|
421
|
+
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
this.objects.delete( this.audioManager );
|
|
425
|
+
|
|
426
|
+
this.audio = null;
|
|
427
|
+
this.audioManager = null;
|
|
428
|
+
|
|
429
|
+
return this;
|
|
430
|
+
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
_setupMeshAnimation( mesh, animation ) {
|
|
434
|
+
|
|
435
|
+
const objects = this.objects.get( mesh );
|
|
436
|
+
|
|
437
|
+
if ( animation !== undefined ) {
|
|
438
|
+
|
|
439
|
+
const animations = Array.isArray( animation )
|
|
440
|
+
? animation : [ animation ];
|
|
441
|
+
|
|
442
|
+
objects.mixer = new AnimationMixer( mesh );
|
|
443
|
+
|
|
444
|
+
for ( let i = 0, il = animations.length; i < il; i ++ ) {
|
|
445
|
+
|
|
446
|
+
objects.mixer.clipAction( animations[ i ] ).play();
|
|
447
|
+
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// TODO: find a workaround not to access ._clip looking like a private property
|
|
451
|
+
objects.mixer.addEventListener( 'loop', function ( event ) {
|
|
452
|
+
|
|
453
|
+
const tracks = event.action._clip.tracks;
|
|
454
|
+
|
|
455
|
+
if ( tracks.length > 0 && tracks[ 0 ].name.slice( 0, 6 ) !== '.bones' ) return;
|
|
456
|
+
|
|
457
|
+
objects.looped = true;
|
|
458
|
+
|
|
459
|
+
} );
|
|
460
|
+
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
objects.ikSolver = this._createCCDIKSolver( mesh );
|
|
464
|
+
objects.grantSolver = this.createGrantSolver( mesh );
|
|
465
|
+
|
|
466
|
+
return this;
|
|
467
|
+
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
_setupCameraAnimation( camera, animation ) {
|
|
471
|
+
|
|
472
|
+
const animations = Array.isArray( animation )
|
|
473
|
+
? animation : [ animation ];
|
|
474
|
+
|
|
475
|
+
const objects = this.objects.get( camera );
|
|
476
|
+
|
|
477
|
+
objects.mixer = new AnimationMixer( camera );
|
|
478
|
+
|
|
479
|
+
for ( let i = 0, il = animations.length; i < il; i ++ ) {
|
|
480
|
+
|
|
481
|
+
objects.mixer.clipAction( animations[ i ] ).play();
|
|
482
|
+
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
_setupMeshPhysics( mesh, params ) {
|
|
488
|
+
|
|
489
|
+
const objects = this.objects.get( mesh );
|
|
490
|
+
|
|
491
|
+
// shared physics is experimental
|
|
492
|
+
|
|
493
|
+
if ( params.world === undefined && this.sharedPhysics ) {
|
|
494
|
+
|
|
495
|
+
const masterPhysics = this._getMasterPhysics();
|
|
496
|
+
|
|
497
|
+
if ( masterPhysics !== null ) world = masterPhysics.world; // eslint-disable-line no-undef
|
|
498
|
+
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
objects.physics = this._createMMDPhysics( mesh, params );
|
|
502
|
+
|
|
503
|
+
if ( objects.mixer && params.animationWarmup !== false ) {
|
|
504
|
+
|
|
505
|
+
this._animateMesh( mesh, 0 );
|
|
506
|
+
objects.physics.reset();
|
|
507
|
+
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
objects.physics.warmup( params.warmup !== undefined ? params.warmup : 60 );
|
|
511
|
+
|
|
512
|
+
this._optimizeIK( mesh, true );
|
|
513
|
+
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
_animateMesh( mesh, delta ) {
|
|
517
|
+
|
|
518
|
+
const objects = this.objects.get( mesh );
|
|
519
|
+
|
|
520
|
+
const mixer = objects.mixer;
|
|
521
|
+
const ikSolver = objects.ikSolver;
|
|
522
|
+
const grantSolver = objects.grantSolver;
|
|
523
|
+
const physics = objects.physics;
|
|
524
|
+
const looped = objects.looped;
|
|
525
|
+
|
|
526
|
+
if ( mixer && this.enabled.animation ) {
|
|
527
|
+
|
|
528
|
+
// alternate solution to save/restore bones but less performant?
|
|
529
|
+
//mesh.pose();
|
|
530
|
+
//this._updatePropertyMixersBuffer( mesh );
|
|
531
|
+
|
|
532
|
+
this._restoreBones( mesh );
|
|
533
|
+
|
|
534
|
+
mixer.update( delta );
|
|
535
|
+
|
|
536
|
+
this._saveBones( mesh );
|
|
537
|
+
|
|
538
|
+
// PMX animation system special path
|
|
539
|
+
if ( this.configuration.pmxAnimation &&
|
|
540
|
+
mesh.geometry.userData.MMD && mesh.geometry.userData.MMD.format === 'pmx' ) {
|
|
541
|
+
|
|
542
|
+
if ( ! objects.sortedBonesData ) objects.sortedBonesData = this._sortBoneDataArray( mesh.geometry.userData.MMD.bones.slice() );
|
|
543
|
+
|
|
544
|
+
this._animatePMXMesh(
|
|
545
|
+
mesh,
|
|
546
|
+
objects.sortedBonesData,
|
|
547
|
+
ikSolver && this.enabled.ik ? ikSolver : null,
|
|
548
|
+
grantSolver && this.enabled.grant ? grantSolver : null
|
|
549
|
+
);
|
|
550
|
+
|
|
551
|
+
} else {
|
|
552
|
+
|
|
553
|
+
if ( ikSolver && this.enabled.ik ) {
|
|
554
|
+
|
|
555
|
+
mesh.updateMatrixWorld( true );
|
|
556
|
+
ikSolver.update();
|
|
557
|
+
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
if ( grantSolver && this.enabled.grant ) {
|
|
561
|
+
|
|
562
|
+
grantSolver.update();
|
|
563
|
+
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
if ( looped === true && this.enabled.physics ) {
|
|
571
|
+
|
|
572
|
+
if ( physics && this.configuration.resetPhysicsOnLoop ) physics.reset();
|
|
573
|
+
|
|
574
|
+
objects.looped = false;
|
|
575
|
+
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
if ( physics && this.enabled.physics && ! this.sharedPhysics ) {
|
|
579
|
+
|
|
580
|
+
this.onBeforePhysics( mesh );
|
|
581
|
+
physics.update( delta );
|
|
582
|
+
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// Sort bones in order by 1. transformationClass and 2. bone index.
|
|
588
|
+
// In PMX animation system, bone transformations should be processed
|
|
589
|
+
// in this order.
|
|
590
|
+
_sortBoneDataArray( boneDataArray ) {
|
|
591
|
+
|
|
592
|
+
return boneDataArray.sort( function ( a, b ) {
|
|
593
|
+
|
|
594
|
+
if ( a.transformationClass !== b.transformationClass ) {
|
|
595
|
+
|
|
596
|
+
return a.transformationClass - b.transformationClass;
|
|
597
|
+
|
|
598
|
+
} else {
|
|
599
|
+
|
|
600
|
+
return a.index - b.index;
|
|
601
|
+
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
} );
|
|
605
|
+
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// PMX Animation system is a bit too complex and doesn't great match to
|
|
609
|
+
// Three.js Animation system. This method attempts to simulate it as much as
|
|
610
|
+
// possible but doesn't perfectly simulate.
|
|
611
|
+
// This method is more costly than the regular one so
|
|
612
|
+
// you are recommended to set constructor parameter "pmxAnimation: true"
|
|
613
|
+
// only if your PMX model animation doesn't work well.
|
|
614
|
+
// If you need better method you would be required to write your own.
|
|
615
|
+
_animatePMXMesh( mesh, sortedBonesData, ikSolver, grantSolver ) {
|
|
616
|
+
|
|
617
|
+
_quaternionIndex = 0;
|
|
618
|
+
_grantResultMap.clear();
|
|
619
|
+
|
|
620
|
+
for ( let i = 0, il = sortedBonesData.length; i < il; i ++ ) {
|
|
621
|
+
|
|
622
|
+
updateOne( mesh, sortedBonesData[ i ].index, ikSolver, grantSolver );
|
|
623
|
+
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
mesh.updateMatrixWorld( true );
|
|
627
|
+
return this;
|
|
628
|
+
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
_animateCamera( camera, delta ) {
|
|
632
|
+
|
|
633
|
+
const mixer = this.objects.get( camera ).mixer;
|
|
634
|
+
|
|
635
|
+
if ( mixer && this.enabled.cameraAnimation ) {
|
|
636
|
+
|
|
637
|
+
mixer.update( delta );
|
|
638
|
+
|
|
639
|
+
camera.updateProjectionMatrix();
|
|
640
|
+
|
|
641
|
+
camera.up.set( 0, 1, 0 );
|
|
642
|
+
camera.up.applyQuaternion( camera.quaternion );
|
|
643
|
+
camera.lookAt( this.cameraTarget.position );
|
|
644
|
+
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
_optimizeIK( mesh, physicsEnabled ) {
|
|
650
|
+
|
|
651
|
+
const iks = mesh.geometry.userData.MMD.iks;
|
|
652
|
+
const bones = mesh.geometry.userData.MMD.bones;
|
|
653
|
+
|
|
654
|
+
for ( let i = 0, il = iks.length; i < il; i ++ ) {
|
|
655
|
+
|
|
656
|
+
const ik = iks[ i ];
|
|
657
|
+
const links = ik.links;
|
|
658
|
+
|
|
659
|
+
for ( let j = 0, jl = links.length; j < jl; j ++ ) {
|
|
660
|
+
|
|
661
|
+
const link = links[ j ];
|
|
662
|
+
|
|
663
|
+
if ( physicsEnabled === true ) {
|
|
664
|
+
|
|
665
|
+
// disable IK of the bone the corresponding rigidBody type of which is 1 or 2
|
|
666
|
+
// because its rotation will be overriden by physics
|
|
667
|
+
link.enabled = bones[ link.index ].rigidBodyType > 0 ? false : true;
|
|
668
|
+
|
|
669
|
+
} else {
|
|
670
|
+
|
|
671
|
+
link.enabled = true;
|
|
672
|
+
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
_createCCDIKSolver( mesh ) {
|
|
682
|
+
|
|
683
|
+
if ( CCDIKSolver === undefined ) {
|
|
684
|
+
|
|
685
|
+
throw new Error( 'THREE.MMDAnimationHelper: Import CCDIKSolver.' );
|
|
686
|
+
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
return new CCDIKSolver( mesh, mesh.geometry.userData.MMD.iks );
|
|
690
|
+
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
_createMMDPhysics( mesh, params ) {
|
|
694
|
+
|
|
695
|
+
if ( MMDPhysics === undefined ) {
|
|
696
|
+
|
|
697
|
+
throw new Error( 'THREE.MMDPhysics: Import MMDPhysics.' );
|
|
698
|
+
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
return new MMDPhysics(
|
|
702
|
+
mesh,
|
|
703
|
+
mesh.geometry.userData.MMD.rigidBodies,
|
|
704
|
+
mesh.geometry.userData.MMD.constraints,
|
|
705
|
+
params );
|
|
706
|
+
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/*
|
|
710
|
+
* Detects the longest duration and then sets it to them to sync.
|
|
711
|
+
* TODO: Not to access private properties ( ._actions and ._clip )
|
|
712
|
+
*/
|
|
713
|
+
_syncDuration() {
|
|
714
|
+
|
|
715
|
+
let max = 0.0;
|
|
716
|
+
|
|
717
|
+
const objects = this.objects;
|
|
718
|
+
const meshes = this.meshes;
|
|
719
|
+
const camera = this.camera;
|
|
720
|
+
const audioManager = this.audioManager;
|
|
721
|
+
|
|
722
|
+
// get the longest duration
|
|
723
|
+
|
|
724
|
+
for ( let i = 0, il = meshes.length; i < il; i ++ ) {
|
|
725
|
+
|
|
726
|
+
const mixer = this.objects.get( meshes[ i ] ).mixer;
|
|
727
|
+
|
|
728
|
+
if ( mixer === undefined ) continue;
|
|
729
|
+
|
|
730
|
+
for ( let j = 0; j < mixer._actions.length; j ++ ) {
|
|
731
|
+
|
|
732
|
+
const clip = mixer._actions[ j ]._clip;
|
|
733
|
+
|
|
734
|
+
if ( ! objects.has( clip ) ) {
|
|
735
|
+
|
|
736
|
+
objects.set( clip, {
|
|
737
|
+
duration: clip.duration
|
|
738
|
+
} );
|
|
739
|
+
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
max = Math.max( max, objects.get( clip ).duration );
|
|
743
|
+
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
if ( camera !== null ) {
|
|
749
|
+
|
|
750
|
+
const mixer = this.objects.get( camera ).mixer;
|
|
751
|
+
|
|
752
|
+
if ( mixer !== undefined ) {
|
|
753
|
+
|
|
754
|
+
for ( let i = 0, il = mixer._actions.length; i < il; i ++ ) {
|
|
755
|
+
|
|
756
|
+
const clip = mixer._actions[ i ]._clip;
|
|
757
|
+
|
|
758
|
+
if ( ! objects.has( clip ) ) {
|
|
759
|
+
|
|
760
|
+
objects.set( clip, {
|
|
761
|
+
duration: clip.duration
|
|
762
|
+
} );
|
|
763
|
+
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
max = Math.max( max, objects.get( clip ).duration );
|
|
767
|
+
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
if ( audioManager !== null ) {
|
|
775
|
+
|
|
776
|
+
max = Math.max( max, objects.get( audioManager ).duration );
|
|
777
|
+
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
max += this.configuration.afterglow;
|
|
781
|
+
|
|
782
|
+
// update the duration
|
|
783
|
+
|
|
784
|
+
for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
|
|
785
|
+
|
|
786
|
+
const mixer = this.objects.get( this.meshes[ i ] ).mixer;
|
|
787
|
+
|
|
788
|
+
if ( mixer === undefined ) continue;
|
|
789
|
+
|
|
790
|
+
for ( let j = 0, jl = mixer._actions.length; j < jl; j ++ ) {
|
|
791
|
+
|
|
792
|
+
mixer._actions[ j ]._clip.duration = max;
|
|
793
|
+
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
if ( camera !== null ) {
|
|
799
|
+
|
|
800
|
+
const mixer = this.objects.get( camera ).mixer;
|
|
801
|
+
|
|
802
|
+
if ( mixer !== undefined ) {
|
|
803
|
+
|
|
804
|
+
for ( let i = 0, il = mixer._actions.length; i < il; i ++ ) {
|
|
805
|
+
|
|
806
|
+
mixer._actions[ i ]._clip.duration = max;
|
|
807
|
+
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
if ( audioManager !== null ) {
|
|
815
|
+
|
|
816
|
+
audioManager.duration = max;
|
|
817
|
+
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
// workaround
|
|
823
|
+
|
|
824
|
+
_updatePropertyMixersBuffer( mesh ) {
|
|
825
|
+
|
|
826
|
+
const mixer = this.objects.get( mesh ).mixer;
|
|
827
|
+
|
|
828
|
+
const propertyMixers = mixer._bindings;
|
|
829
|
+
const accuIndex = mixer._accuIndex;
|
|
830
|
+
|
|
831
|
+
for ( let i = 0, il = propertyMixers.length; i < il; i ++ ) {
|
|
832
|
+
|
|
833
|
+
const propertyMixer = propertyMixers[ i ];
|
|
834
|
+
const buffer = propertyMixer.buffer;
|
|
835
|
+
const stride = propertyMixer.valueSize;
|
|
836
|
+
const offset = ( accuIndex + 1 ) * stride;
|
|
837
|
+
|
|
838
|
+
propertyMixer.binding.getValue( buffer, offset );
|
|
839
|
+
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/*
|
|
845
|
+
* Avoiding these two issues by restore/save bones before/after mixer animation.
|
|
846
|
+
*
|
|
847
|
+
* 1. PropertyMixer used by AnimationMixer holds cache value in .buffer.
|
|
848
|
+
* Calculating IK, Grant, and Physics after mixer animation can break
|
|
849
|
+
* the cache coherency.
|
|
850
|
+
*
|
|
851
|
+
* 2. Applying Grant two or more times without reset the posing breaks model.
|
|
852
|
+
*/
|
|
853
|
+
_saveBones( mesh ) {
|
|
854
|
+
|
|
855
|
+
const objects = this.objects.get( mesh );
|
|
856
|
+
|
|
857
|
+
const bones = mesh.skeleton.bones;
|
|
858
|
+
|
|
859
|
+
let backupBones = objects.backupBones;
|
|
860
|
+
|
|
861
|
+
if ( backupBones === undefined ) {
|
|
862
|
+
|
|
863
|
+
backupBones = new Float32Array( bones.length * 7 );
|
|
864
|
+
objects.backupBones = backupBones;
|
|
865
|
+
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
for ( let i = 0, il = bones.length; i < il; i ++ ) {
|
|
869
|
+
|
|
870
|
+
const bone = bones[ i ];
|
|
871
|
+
bone.position.toArray( backupBones, i * 7 );
|
|
872
|
+
bone.quaternion.toArray( backupBones, i * 7 + 3 );
|
|
873
|
+
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
_restoreBones( mesh ) {
|
|
879
|
+
|
|
880
|
+
const objects = this.objects.get( mesh );
|
|
881
|
+
|
|
882
|
+
const backupBones = objects.backupBones;
|
|
883
|
+
|
|
884
|
+
if ( backupBones === undefined ) return;
|
|
885
|
+
|
|
886
|
+
const bones = mesh.skeleton.bones;
|
|
887
|
+
|
|
888
|
+
for ( let i = 0, il = bones.length; i < il; i ++ ) {
|
|
889
|
+
|
|
890
|
+
const bone = bones[ i ];
|
|
891
|
+
bone.position.fromArray( backupBones, i * 7 );
|
|
892
|
+
bone.quaternion.fromArray( backupBones, i * 7 + 3 );
|
|
893
|
+
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
// experimental
|
|
899
|
+
|
|
900
|
+
_getMasterPhysics() {
|
|
901
|
+
|
|
902
|
+
if ( this.masterPhysics !== null ) return this.masterPhysics;
|
|
903
|
+
|
|
904
|
+
for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
|
|
905
|
+
|
|
906
|
+
const physics = this.meshes[ i ].physics;
|
|
907
|
+
|
|
908
|
+
if ( physics !== undefined && physics !== null ) {
|
|
909
|
+
|
|
910
|
+
this.masterPhysics = physics;
|
|
911
|
+
return this.masterPhysics;
|
|
912
|
+
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
return null;
|
|
918
|
+
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
_updateSharedPhysics( delta ) {
|
|
922
|
+
|
|
923
|
+
if ( this.meshes.length === 0 || ! this.enabled.physics || ! this.sharedPhysics ) return;
|
|
924
|
+
|
|
925
|
+
const physics = this._getMasterPhysics();
|
|
926
|
+
|
|
927
|
+
if ( physics === null ) return;
|
|
928
|
+
|
|
929
|
+
for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
|
|
930
|
+
|
|
931
|
+
const p = this.meshes[ i ].physics;
|
|
932
|
+
|
|
933
|
+
if ( p !== null && p !== undefined ) {
|
|
934
|
+
|
|
935
|
+
p.updateRigidBodies();
|
|
936
|
+
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
physics.stepSimulation( delta );
|
|
942
|
+
|
|
943
|
+
for ( let i = 0, il = this.meshes.length; i < il; i ++ ) {
|
|
944
|
+
|
|
945
|
+
const p = this.meshes[ i ].physics;
|
|
946
|
+
|
|
947
|
+
if ( p !== null && p !== undefined ) {
|
|
948
|
+
|
|
949
|
+
p.updateBones();
|
|
950
|
+
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
// Keep working quaternions for less GC
|
|
960
|
+
const _quaternions = [];
|
|
961
|
+
let _quaternionIndex = 0;
|
|
962
|
+
|
|
963
|
+
function getQuaternion() {
|
|
964
|
+
|
|
965
|
+
if ( _quaternionIndex >= _quaternions.length ) {
|
|
966
|
+
|
|
967
|
+
_quaternions.push( new Quaternion() );
|
|
968
|
+
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
return _quaternions[ _quaternionIndex ++ ];
|
|
972
|
+
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
// Save rotation whose grant and IK are already applied
|
|
976
|
+
// used by grant children
|
|
977
|
+
const _grantResultMap = new Map();
|
|
978
|
+
|
|
979
|
+
function updateOne( mesh, boneIndex, ikSolver, grantSolver ) {
|
|
980
|
+
|
|
981
|
+
const bones = mesh.skeleton.bones;
|
|
982
|
+
const bonesData = mesh.geometry.userData.MMD.bones;
|
|
983
|
+
const boneData = bonesData[ boneIndex ];
|
|
984
|
+
const bone = bones[ boneIndex ];
|
|
985
|
+
|
|
986
|
+
// Return if already updated by being referred as a grant parent.
|
|
987
|
+
if ( _grantResultMap.has( boneIndex ) ) return;
|
|
988
|
+
|
|
989
|
+
const quaternion = getQuaternion();
|
|
990
|
+
|
|
991
|
+
// Initialize grant result here to prevent infinite loop.
|
|
992
|
+
// If it's referred before updating with actual result later
|
|
993
|
+
// result without applyting IK or grant is gotten
|
|
994
|
+
// but better than composing of infinite loop.
|
|
995
|
+
_grantResultMap.set( boneIndex, quaternion.copy( bone.quaternion ) );
|
|
996
|
+
|
|
997
|
+
// @TODO: Support global grant and grant position
|
|
998
|
+
if ( grantSolver && boneData.grant &&
|
|
999
|
+
! boneData.grant.isLocal && boneData.grant.affectRotation ) {
|
|
1000
|
+
|
|
1001
|
+
const parentIndex = boneData.grant.parentIndex;
|
|
1002
|
+
const ratio = boneData.grant.ratio;
|
|
1003
|
+
|
|
1004
|
+
if ( ! _grantResultMap.has( parentIndex ) ) {
|
|
1005
|
+
|
|
1006
|
+
updateOne( mesh, parentIndex, ikSolver, grantSolver );
|
|
1007
|
+
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
grantSolver.addGrantRotation( bone, _grantResultMap.get( parentIndex ), ratio );
|
|
1011
|
+
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
if ( ikSolver && boneData.ik ) {
|
|
1015
|
+
|
|
1016
|
+
// @TODO: Updating world matrices every time solving an IK bone is
|
|
1017
|
+
// costly. Optimize if possible.
|
|
1018
|
+
mesh.updateMatrixWorld( true );
|
|
1019
|
+
ikSolver.updateOne( boneData.ik );
|
|
1020
|
+
|
|
1021
|
+
// No confident, but it seems the grant results with ik links should be updated?
|
|
1022
|
+
const links = boneData.ik.links;
|
|
1023
|
+
|
|
1024
|
+
for ( let i = 0, il = links.length; i < il; i ++ ) {
|
|
1025
|
+
|
|
1026
|
+
const link = links[ i ];
|
|
1027
|
+
|
|
1028
|
+
if ( link.enabled === false ) continue;
|
|
1029
|
+
|
|
1030
|
+
const linkIndex = link.index;
|
|
1031
|
+
|
|
1032
|
+
if ( _grantResultMap.has( linkIndex ) ) {
|
|
1033
|
+
|
|
1034
|
+
_grantResultMap.set( linkIndex, _grantResultMap.get( linkIndex ).copy( bones[ linkIndex ].quaternion ) );
|
|
1035
|
+
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
// Update with the actual result here
|
|
1043
|
+
quaternion.copy( bone.quaternion );
|
|
1044
|
+
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
//
|
|
1048
|
+
|
|
1049
|
+
class AudioManager {
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* @param {THREE.Audio} audio
|
|
1053
|
+
* @param {Object} params - (optional)
|
|
1054
|
+
* @param {Nuumber} params.delayTime
|
|
1055
|
+
*/
|
|
1056
|
+
constructor( audio, params = {} ) {
|
|
1057
|
+
|
|
1058
|
+
this.audio = audio;
|
|
1059
|
+
|
|
1060
|
+
this.elapsedTime = 0.0;
|
|
1061
|
+
this.currentTime = 0.0;
|
|
1062
|
+
this.delayTime = params.delayTime !== undefined
|
|
1063
|
+
? params.delayTime : 0.0;
|
|
1064
|
+
|
|
1065
|
+
this.audioDuration = this.audio.buffer.duration;
|
|
1066
|
+
this.duration = this.audioDuration + this.delayTime;
|
|
1067
|
+
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
/**
|
|
1071
|
+
* @param {Number} delta
|
|
1072
|
+
* @return {AudioManager}
|
|
1073
|
+
*/
|
|
1074
|
+
control( delta ) {
|
|
1075
|
+
|
|
1076
|
+
this.elapsed += delta;
|
|
1077
|
+
this.currentTime += delta;
|
|
1078
|
+
|
|
1079
|
+
if ( this._shouldStopAudio() ) this.audio.stop();
|
|
1080
|
+
if ( this._shouldStartAudio() ) this.audio.play();
|
|
1081
|
+
|
|
1082
|
+
return this;
|
|
1083
|
+
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
// private methods
|
|
1087
|
+
|
|
1088
|
+
_shouldStartAudio() {
|
|
1089
|
+
|
|
1090
|
+
if ( this.audio.isPlaying ) return false;
|
|
1091
|
+
|
|
1092
|
+
while ( this.currentTime >= this.duration ) {
|
|
1093
|
+
|
|
1094
|
+
this.currentTime -= this.duration;
|
|
1095
|
+
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
if ( this.currentTime < this.delayTime ) return false;
|
|
1099
|
+
|
|
1100
|
+
// 'duration' can be bigger than 'audioDuration + delayTime' because of sync configuration
|
|
1101
|
+
if ( ( this.currentTime - this.delayTime ) > this.audioDuration ) return false;
|
|
1102
|
+
|
|
1103
|
+
return true;
|
|
1104
|
+
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
_shouldStopAudio() {
|
|
1108
|
+
|
|
1109
|
+
return this.audio.isPlaying &&
|
|
1110
|
+
this.currentTime >= this.duration;
|
|
1111
|
+
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
const _q = new Quaternion();
|
|
1117
|
+
|
|
1118
|
+
/**
|
|
1119
|
+
* Solver for Grant (Fuyo in Japanese. I just google translated because
|
|
1120
|
+
* Fuyo may be MMD specific term and may not be common word in 3D CG terms.)
|
|
1121
|
+
* Grant propagates a bone's transform to other bones transforms even if
|
|
1122
|
+
* they are not children.
|
|
1123
|
+
* @param {THREE.SkinnedMesh} mesh
|
|
1124
|
+
* @param {Array<Object>} grants
|
|
1125
|
+
*/
|
|
1126
|
+
class GrantSolver {
|
|
1127
|
+
|
|
1128
|
+
constructor( mesh, grants = [] ) {
|
|
1129
|
+
|
|
1130
|
+
this.mesh = mesh;
|
|
1131
|
+
this.grants = grants;
|
|
1132
|
+
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* Solve all the grant bones
|
|
1137
|
+
* @return {GrantSolver}
|
|
1138
|
+
*/
|
|
1139
|
+
update() {
|
|
1140
|
+
|
|
1141
|
+
const grants = this.grants;
|
|
1142
|
+
|
|
1143
|
+
for ( let i = 0, il = grants.length; i < il; i ++ ) {
|
|
1144
|
+
|
|
1145
|
+
this.updateOne( grants[ i ] );
|
|
1146
|
+
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
return this;
|
|
1150
|
+
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
/**
|
|
1154
|
+
* Solve a grant bone
|
|
1155
|
+
* @param {Object} grant - grant parameter
|
|
1156
|
+
* @return {GrantSolver}
|
|
1157
|
+
*/
|
|
1158
|
+
updateOne( grant ) {
|
|
1159
|
+
|
|
1160
|
+
const bones = this.mesh.skeleton.bones;
|
|
1161
|
+
const bone = bones[ grant.index ];
|
|
1162
|
+
const parentBone = bones[ grant.parentIndex ];
|
|
1163
|
+
|
|
1164
|
+
if ( grant.isLocal ) {
|
|
1165
|
+
|
|
1166
|
+
// TODO: implement
|
|
1167
|
+
if ( grant.affectPosition ) {
|
|
1168
|
+
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
// TODO: implement
|
|
1172
|
+
if ( grant.affectRotation ) {
|
|
1173
|
+
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
} else {
|
|
1177
|
+
|
|
1178
|
+
// TODO: implement
|
|
1179
|
+
if ( grant.affectPosition ) {
|
|
1180
|
+
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
if ( grant.affectRotation ) {
|
|
1184
|
+
|
|
1185
|
+
this.addGrantRotation( bone, parentBone.quaternion, grant.ratio );
|
|
1186
|
+
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
return this;
|
|
1192
|
+
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
addGrantRotation( bone, q, ratio ) {
|
|
1196
|
+
|
|
1197
|
+
_q.set( 0, 0, 0, 1 );
|
|
1198
|
+
_q.slerp( q, ratio );
|
|
1199
|
+
bone.quaternion.multiply( _q );
|
|
1200
|
+
|
|
1201
|
+
return this;
|
|
1202
|
+
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
export { MMDAnimationHelper };
|