@needle-tools/three 0.146.10 → 0.153.1
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 +1 -1
- package/build/three.cjs +40124 -20919
- package/build/three.js +40120 -20914
- package/build/three.min.js +8 -6
- package/build/three.module.js +7298 -6003
- package/build/three.module.min.js +7 -0
- package/examples/jsm/animation/AnimationClipCreator.js +5 -3
- package/examples/jsm/cameras/CinematicCamera.js +1 -2
- package/examples/jsm/capabilities/WebGPU.js +17 -5
- package/examples/jsm/controls/ArcballControls.js +1828 -1821
- package/examples/jsm/controls/MapControls.js +28 -0
- package/examples/jsm/controls/OrbitControls.js +26 -53
- package/examples/jsm/controls/PointerLockControls.js +70 -65
- package/examples/jsm/controls/TrackballControls.js +18 -4
- package/examples/jsm/controls/TransformControls.js +0 -1
- package/examples/jsm/csm/CSM.js +11 -5
- package/examples/jsm/csm/CSMShader.js +7 -6
- package/examples/jsm/effects/AnaglyphEffect.js +6 -20
- package/examples/jsm/effects/AsciiEffect.js +3 -6
- package/examples/jsm/effects/OutlineEffect.js +1 -15
- package/examples/jsm/effects/ParallaxBarrierEffect.js +3 -0
- package/examples/jsm/exporters/DRACOExporter.js +53 -11
- package/examples/jsm/exporters/EXRExporter.js +3 -9
- package/examples/jsm/exporters/GLTFExporter.js +561 -154
- package/examples/jsm/exporters/KTX2Exporter.js +34 -23
- package/examples/jsm/exporters/MMDExporter.js +1 -1
- package/examples/jsm/exporters/PLYExporter.js +8 -1
- package/examples/jsm/exporters/STLExporter.js +8 -4
- package/examples/jsm/exporters/USDZExporter.js +305 -792
- package/examples/jsm/geometries/ConvexGeometry.js +0 -6
- package/examples/jsm/geometries/ParametricGeometry.js +10 -0
- package/examples/jsm/helpers/OctreeHelper.js +1 -0
- package/examples/jsm/helpers/ViewHelper.js +71 -57
- package/examples/jsm/interactive/HTMLMesh.js +16 -3
- package/examples/jsm/interactive/InteractiveGroup.js +1 -1
- package/examples/{js → jsm}/libs/basis/README.md +4 -4
- package/examples/jsm/libs/draco/draco_decoder.js +34 -0
- package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
- package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -0
- package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -0
- package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
- package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -0
- package/examples/jsm/libs/lil-gui.module.min.js +2 -2
- package/examples/jsm/libs/tween.module.js +803 -0
- package/examples/jsm/lights/IESSpotLight.js +25 -0
- package/examples/jsm/lights/LightProbeGenerator.js +11 -9
- package/examples/jsm/lines/LineSegments2.js +16 -10
- package/examples/jsm/loaders/3DMLoader.js +8 -5
- package/examples/jsm/loaders/3MFLoader.js +12 -11
- package/examples/jsm/loaders/AMFLoader.js +2 -3
- package/examples/jsm/loaders/BVHLoader.js +2 -2
- package/examples/jsm/loaders/ColladaLoader.js +15 -16
- package/examples/jsm/loaders/DRACOLoader.js +69 -18
- package/examples/jsm/loaders/EXRLoader.js +23 -24
- package/examples/jsm/loaders/FBXLoader.js +34 -50
- package/examples/jsm/loaders/GCodeLoader.js +1 -2
- package/examples/jsm/loaders/GLTFLoader.js +417 -895
- package/examples/jsm/loaders/GLTFLoaderAnimationPointer.js +684 -0
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +4 -4
- package/examples/jsm/loaders/IESLoader.js +337 -0
- package/examples/jsm/loaders/KMZLoader.js +4 -4
- package/examples/jsm/loaders/KTX2Loader.js +145 -69
- package/examples/jsm/loaders/LDrawLoader.js +20 -18
- package/examples/jsm/loaders/LWOLoader.js +12 -29
- package/examples/jsm/loaders/LottieLoader.js +3 -1
- package/examples/jsm/loaders/MMDLoader.js +49 -18
- package/examples/jsm/loaders/MTLLoader.js +2 -2
- package/examples/jsm/loaders/MaterialXLoader.js +9 -3
- package/examples/jsm/loaders/NRRDLoader.js +33 -5
- package/examples/jsm/loaders/OBJLoader.js +1 -1
- package/examples/jsm/loaders/PCDLoader.js +26 -12
- package/examples/jsm/loaders/PDBLoader.js +7 -2
- package/examples/jsm/loaders/PLYLoader.js +254 -109
- package/examples/jsm/loaders/RGBELoader.js +3 -3
- package/examples/jsm/loaders/STLLoader.js +9 -5
- package/examples/jsm/loaders/SVGLoader.js +36 -27
- package/examples/jsm/loaders/TTFLoader.js +1 -8
- package/examples/jsm/loaders/TiltLoader.js +13 -7
- package/examples/jsm/loaders/USDZLoader.js +6 -6
- package/examples/jsm/loaders/VOXLoader.js +8 -2
- package/examples/jsm/loaders/VRMLLoader.js +44 -16
- package/examples/jsm/loaders/VTKLoader.js +19 -10
- package/examples/jsm/loaders/XYZLoader.js +9 -3
- package/examples/jsm/loaders/lwo/IFFParser.js +19 -19
- package/examples/jsm/materials/MeshGouraudMaterial.js +0 -3
- package/examples/jsm/math/ConvexHull.js +3 -3
- package/examples/jsm/math/Lut.js +5 -4
- package/examples/jsm/math/MeshSurfaceSampler.js +7 -9
- package/examples/jsm/math/Octree.js +1 -1
- package/examples/jsm/misc/ConvexObjectBreaker.js +2 -8
- package/examples/jsm/misc/GPUComputationRenderer.js +6 -5
- package/examples/jsm/misc/MD2Character.js +2 -2
- package/examples/jsm/misc/MD2CharacterComplex.js +2 -2
- package/examples/jsm/misc/ProgressiveLightMap.js +12 -10
- package/examples/jsm/misc/RollerCoaster.js +7 -1
- package/examples/jsm/misc/Volume.js +20 -5
- package/examples/jsm/misc/VolumeSlice.js +3 -1
- package/examples/jsm/modifiers/CurveModifier.js +1 -0
- package/examples/jsm/modifiers/TessellateModifier.js +19 -19
- package/examples/jsm/nodes/Nodes.js +144 -335
- package/examples/jsm/nodes/accessors/BitangentNode.js +43 -16
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +86 -0
- package/examples/jsm/nodes/accessors/BufferNode.js +6 -0
- package/examples/jsm/nodes/accessors/CameraNode.js +12 -2
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +27 -33
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +58 -0
- package/examples/jsm/nodes/accessors/InstanceNode.js +41 -26
- package/examples/jsm/nodes/accessors/MaterialNode.js +155 -38
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +16 -0
- package/examples/jsm/nodes/accessors/ModelNode.js +11 -0
- package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +13 -14
- package/examples/jsm/nodes/accessors/NormalNode.js +35 -19
- package/examples/jsm/nodes/accessors/Object3DNode.js +32 -12
- package/examples/jsm/nodes/accessors/PointUVNode.js +6 -1
- package/examples/jsm/nodes/accessors/PositionNode.js +38 -23
- package/examples/jsm/nodes/accessors/ReferenceNode.js +21 -14
- package/examples/jsm/nodes/accessors/ReflectVectorNode.js +11 -7
- package/examples/jsm/nodes/accessors/SkinningNode.js +43 -40
- package/examples/jsm/nodes/accessors/StorageBufferNode.js +6 -0
- package/examples/jsm/nodes/accessors/TangentNode.js +28 -20
- package/examples/jsm/nodes/accessors/TextureNode.js +80 -12
- package/examples/jsm/nodes/accessors/UVNode.js +6 -0
- package/examples/jsm/nodes/accessors/UserDataNode.js +6 -0
- package/examples/jsm/nodes/code/CodeNode.js +75 -0
- package/examples/jsm/nodes/code/ExpressionNode.js +37 -0
- package/examples/jsm/nodes/{core → code}/FunctionCallNode.js +15 -1
- package/examples/jsm/nodes/{core → code}/FunctionNode.js +8 -7
- package/examples/jsm/nodes/code/ScriptableNode.js +488 -0
- package/examples/jsm/nodes/code/ScriptableValueNode.js +167 -0
- package/examples/jsm/nodes/core/ArrayUniformNode.js +3 -0
- package/examples/jsm/nodes/core/AttributeNode.js +17 -9
- package/examples/jsm/nodes/core/BypassNode.js +9 -2
- package/examples/jsm/nodes/core/CacheNode.js +46 -0
- package/examples/jsm/nodes/core/ConstNode.js +3 -0
- package/examples/jsm/nodes/core/ContextNode.js +8 -1
- package/examples/jsm/nodes/core/InputNode.js +26 -5
- package/examples/jsm/nodes/core/InstanceIndexNode.js +26 -2
- package/examples/jsm/nodes/core/LightingModel.js +16 -0
- package/examples/jsm/nodes/core/Node.js +129 -35
- package/examples/jsm/nodes/core/NodeAttribute.js +2 -1
- package/examples/jsm/nodes/core/NodeBuilder.js +271 -121
- package/examples/jsm/nodes/core/NodeCache.js +26 -0
- package/examples/jsm/nodes/core/NodeFrame.js +56 -5
- package/examples/jsm/nodes/core/NodeUtils.js +115 -28
- package/examples/jsm/nodes/core/PropertyNode.js +19 -2
- package/examples/jsm/nodes/core/StackNode.js +99 -0
- package/examples/jsm/nodes/core/TempNode.js +11 -3
- package/examples/jsm/nodes/core/UniformNode.js +16 -1
- package/examples/jsm/nodes/core/VarNode.js +21 -29
- package/examples/jsm/nodes/core/VaryingNode.js +15 -2
- package/examples/jsm/nodes/core/constants.js +6 -0
- package/examples/jsm/nodes/display/BlendModeNode.js +25 -11
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +30 -14
- package/examples/jsm/nodes/display/ColorSpaceNode.js +39 -27
- package/examples/jsm/nodes/display/FrontFacingNode.js +7 -1
- package/examples/jsm/nodes/display/NormalMapNode.js +31 -18
- package/examples/jsm/nodes/display/PosterizeNode.js +10 -3
- package/examples/jsm/nodes/display/ToneMappingNode.js +101 -11
- package/examples/jsm/nodes/display/ViewportNode.js +27 -18
- package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +30 -0
- package/examples/jsm/nodes/display/ViewportTextureNode.js +67 -0
- package/examples/jsm/nodes/fog/FogExp2Node.js +35 -0
- package/examples/jsm/nodes/fog/FogNode.js +12 -6
- package/examples/jsm/nodes/fog/FogRangeNode.js +12 -5
- package/examples/jsm/nodes/functions/BSDF/BRDF_BlinnPhong.js +30 -0
- package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +10 -13
- package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
- package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +8 -6
- package/examples/jsm/nodes/functions/BSDF/D_GGX.js +4 -4
- package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +3 -3
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +7 -5
- package/examples/jsm/nodes/functions/PhongLightingModel.js +28 -0
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +35 -36
- package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +4 -3
- package/examples/jsm/nodes/functions/material/getRoughness.js +4 -4
- package/examples/jsm/nodes/geometry/RangeNode.js +50 -55
- package/examples/jsm/nodes/gpgpu/ComputeNode.js +9 -2
- package/examples/jsm/nodes/lighting/AONode.js +5 -3
- package/examples/jsm/nodes/lighting/AmbientLightNode.js +27 -0
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +114 -5
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +43 -0
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +121 -35
- package/examples/jsm/nodes/lighting/HemisphereLightNode.js +15 -10
- package/examples/jsm/nodes/lighting/IESSpotLightNode.js +39 -0
- package/examples/jsm/nodes/lighting/LightNode.js +57 -0
- package/examples/jsm/nodes/lighting/LightUtils.js +17 -0
- package/examples/jsm/nodes/lighting/LightingContextNode.js +30 -8
- package/examples/jsm/nodes/lighting/LightingNode.js +3 -1
- package/examples/jsm/nodes/lighting/LightsNode.js +18 -10
- package/examples/jsm/nodes/lighting/PointLightNode.js +71 -0
- package/examples/jsm/nodes/lighting/SpotLightNode.js +92 -0
- package/examples/jsm/nodes/loaders/NodeLoader.js +5 -4
- package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +4 -20
- package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +6 -9
- package/examples/jsm/nodes/materials/Materials.js +11 -55
- package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +5 -11
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +48 -0
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +74 -0
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +6 -6
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +21 -96
- package/examples/jsm/nodes/materials/NodeMaterial.js +284 -62
- package/examples/jsm/nodes/materials/PointsNodeMaterial.js +7 -1
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +29 -25
- package/examples/jsm/nodes/materialx/MaterialXNodes.js +31 -22
- package/examples/jsm/nodes/materialx/lib/mx_hsv.js +1 -1
- package/examples/jsm/nodes/materialx/lib/mx_noise.js +2 -1
- package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +2 -1
- package/examples/jsm/nodes/math/CondNode.js +43 -17
- package/examples/jsm/nodes/math/MathNode.js +178 -73
- package/examples/jsm/nodes/math/OperatorNode.js +52 -2
- package/examples/jsm/nodes/procedural/CheckerNode.js +14 -6
- package/examples/jsm/nodes/shadernode/ShaderNode.js +186 -63
- package/examples/jsm/nodes/utils/ArrayElementNode.js +4 -2
- package/examples/jsm/nodes/utils/ConvertNode.js +19 -1
- package/examples/jsm/nodes/utils/DiscardNode.js +26 -0
- package/examples/jsm/nodes/utils/EquirectUVNode.js +10 -4
- package/examples/jsm/nodes/utils/JoinNode.js +4 -1
- package/examples/jsm/nodes/utils/LoopNode.js +186 -0
- package/examples/jsm/nodes/utils/MatcapUVNode.js +11 -4
- package/examples/jsm/nodes/utils/MaxMipLevelNode.js +18 -5
- package/examples/jsm/nodes/utils/OscNode.js +21 -14
- package/examples/jsm/nodes/utils/PackingNode.js +55 -0
- package/examples/jsm/nodes/utils/RemapNode.js +13 -5
- package/examples/jsm/nodes/utils/RotateUVNode.js +18 -7
- package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +37 -0
- package/examples/jsm/nodes/utils/SplitNode.js +7 -5
- package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +15 -30
- package/examples/jsm/nodes/utils/TimerNode.js +16 -6
- package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +21 -10
- package/examples/jsm/objects/GroundProjectedSkybox.js +172 -0
- package/examples/jsm/objects/Lensflare.js +3 -4
- package/examples/jsm/objects/MarchingCubes.js +5 -1
- package/examples/jsm/objects/Reflector.js +7 -4
- package/examples/jsm/objects/Refractor.js +4 -4
- package/examples/jsm/objects/ShadowMesh.js +3 -3
- package/examples/jsm/objects/Water.js +2 -1
- package/examples/jsm/physics/AmmoPhysics.js +27 -28
- package/examples/jsm/physics/RapierPhysics.js +199 -0
- package/examples/jsm/postprocessing/AfterimagePass.js +3 -2
- package/examples/jsm/postprocessing/BloomPass.js +7 -4
- package/examples/jsm/postprocessing/BokehPass.js +3 -8
- package/examples/jsm/postprocessing/DotScreenPass.js +1 -2
- package/examples/jsm/postprocessing/EffectComposer.js +5 -95
- package/examples/jsm/postprocessing/FilmPass.js +1 -2
- package/examples/jsm/postprocessing/GlitchPass.js +0 -2
- package/examples/jsm/postprocessing/HalftonePass.js +0 -6
- package/examples/jsm/postprocessing/OutlinePass.js +7 -7
- package/examples/jsm/postprocessing/OutputPass.js +72 -0
- package/examples/jsm/postprocessing/Pass.js +2 -0
- package/examples/jsm/postprocessing/RenderPixelatedPass.js +4 -3
- package/examples/jsm/postprocessing/SAOPass.js +4 -26
- package/examples/jsm/postprocessing/SMAAPass.js +5 -8
- package/examples/jsm/postprocessing/SSAARenderPass.js +15 -6
- package/examples/jsm/postprocessing/SSAOPass.js +4 -14
- package/examples/jsm/postprocessing/SSRPass.js +3 -7
- package/examples/jsm/postprocessing/SavePass.js +2 -3
- package/examples/jsm/postprocessing/ShaderPass.js +1 -0
- package/examples/jsm/postprocessing/TAARenderPass.js +3 -2
- package/examples/jsm/postprocessing/TexturePass.js +0 -2
- package/examples/jsm/postprocessing/UnrealBloomPass.js +4 -11
- package/examples/jsm/renderers/CSS2DRenderer.js +6 -1
- package/examples/jsm/renderers/CSS3DRenderer.js +27 -5
- package/examples/jsm/renderers/{webgpu/WebGPUAnimation.js → common/Animation.js} +4 -4
- package/examples/jsm/renderers/common/Attributes.js +75 -0
- package/examples/jsm/renderers/common/Backend.js +160 -0
- package/examples/jsm/renderers/common/Background.js +133 -0
- package/examples/jsm/renderers/common/Binding.js +11 -0
- package/examples/jsm/renderers/common/Bindings.js +169 -0
- package/examples/jsm/renderers/common/Buffer.js +38 -0
- package/examples/jsm/renderers/{webgpu/WebGPUBufferUtils.js → common/BufferUtils.js} +2 -2
- package/examples/jsm/renderers/common/ChainMap.js +89 -0
- package/examples/jsm/renderers/common/ComputePipeline.js +17 -0
- package/examples/jsm/renderers/common/Constants.js +14 -0
- package/examples/jsm/renderers/common/CubeRenderTarget.js +65 -0
- package/examples/jsm/renderers/common/DataMap.js +54 -0
- package/examples/jsm/renderers/common/Geometries.js +215 -0
- package/examples/jsm/renderers/{webgpu/WebGPUInfo.js → common/Info.js} +2 -3
- package/examples/jsm/renderers/common/Pipeline.js +13 -0
- package/examples/jsm/renderers/common/Pipelines.js +309 -0
- package/examples/jsm/renderers/common/ProgrammableStage.js +18 -0
- package/examples/jsm/renderers/common/RenderContext.js +37 -0
- package/examples/jsm/renderers/common/RenderContexts.js +38 -0
- package/examples/jsm/renderers/{webgpu/WebGPURenderLists.js → common/RenderList.js} +26 -47
- package/examples/jsm/renderers/common/RenderLists.js +38 -0
- package/examples/jsm/renderers/common/RenderObject.js +95 -0
- package/examples/jsm/renderers/common/RenderObjects.js +92 -0
- package/examples/jsm/renderers/common/RenderPipeline.js +16 -0
- package/examples/jsm/renderers/common/RenderTarget.js +15 -0
- package/examples/jsm/renderers/common/Renderer.js +822 -0
- package/examples/jsm/renderers/common/SampledTexture.js +80 -0
- package/examples/jsm/renderers/common/Sampler.js +18 -0
- package/examples/jsm/renderers/common/StorageBuffer.js +17 -0
- package/examples/jsm/renderers/common/Textures.js +206 -0
- package/examples/jsm/renderers/{webgpu/WebGPUUniform.js → common/Uniform.js} +13 -9
- package/examples/jsm/renderers/common/UniformBuffer.js +15 -0
- package/examples/jsm/renderers/{webgpu/WebGPUUniformsGroup.js → common/UniformsGroup.js} +13 -13
- package/examples/jsm/renderers/common/nodes/NodeRender.js +302 -0
- package/examples/jsm/renderers/{webgpu/nodes/WebGPUNodeSampledTexture.js → common/nodes/NodeSampledTexture.js} +4 -4
- package/examples/jsm/renderers/{webgpu/nodes/WebGPUNodeSampler.js → common/nodes/NodeSampler.js} +3 -3
- package/examples/jsm/renderers/{webgpu/nodes/WebGPUNodeUniform.js → common/nodes/NodeUniform.js} +1 -1
- package/examples/jsm/renderers/common/nodes/Nodes.js +319 -0
- package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +35 -31
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +765 -0
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +15 -987
- package/examples/jsm/renderers/webgpu/nodes/{WebGPUNodeBuilder.js → WGSLNodeBuilder.js} +117 -90
- package/examples/jsm/{nodes/parsers → renderers/webgpu/nodes}/WGSLNodeFunction.js +2 -2
- package/examples/jsm/{nodes/parsers → renderers/webgpu/nodes}/WGSLNodeParser.js +1 -1
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +251 -0
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +145 -0
- package/examples/jsm/renderers/webgpu/{constants.js → utils/WebGPUConstants.js} +73 -12
- package/examples/jsm/renderers/webgpu/{WebGPURenderPipeline.js → utils/WebGPUPipelineUtils.js} +135 -285
- package/examples/jsm/renderers/webgpu/{WebGPUTextureUtils.js → utils/WebGPUTextureMipmapUtils.js} +5 -25
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +855 -0
- package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +88 -0
- package/examples/jsm/shaders/BleachBypassShader.js +2 -0
- package/examples/jsm/shaders/BokehShader2.js +3 -0
- package/examples/jsm/shaders/ColorifyShader.js +2 -0
- package/examples/jsm/shaders/ConvolutionShader.js +2 -0
- package/examples/jsm/shaders/CopyShader.js +2 -0
- package/examples/jsm/shaders/DotScreenShader.js +2 -0
- package/examples/jsm/shaders/ExposureShader.js +44 -0
- package/examples/jsm/shaders/FilmShader.js +2 -0
- package/examples/jsm/shaders/GammaCorrectionShader.js +2 -0
- package/examples/jsm/shaders/HorizontalBlurShader.js +2 -0
- package/examples/jsm/shaders/MMDToonShader.js +15 -4
- package/examples/jsm/shaders/OutputShader.js +61 -0
- package/examples/jsm/shaders/RGBShiftShader.js +4 -2
- package/examples/jsm/shaders/SepiaShader.js +2 -0
- package/examples/jsm/shaders/ToonShader.js +13 -5
- package/examples/jsm/shaders/VelocityShader.js +1 -1
- package/examples/jsm/shaders/VerticalBlurShader.js +2 -0
- package/examples/jsm/shaders/VignetteShader.js +2 -0
- package/examples/jsm/shaders/WaterRefractionShader.js +5 -2
- package/examples/jsm/utils/BufferGeometryUtils.js +54 -36
- package/examples/jsm/utils/LDrawUtils.js +4 -4
- package/examples/jsm/utils/PackedPhongMaterial.js +5 -78
- package/examples/jsm/utils/SceneUtils.js +8 -4
- package/examples/jsm/utils/SkeletonUtils.js +27 -210
- package/examples/jsm/utils/TextureUtils.js +41 -40
- package/examples/jsm/webxr/VRButton.js +1 -2
- package/examples/jsm/webxr/XRButton.js +198 -0
- package/examples/jsm/webxr/XRHandPrimitiveModel.js +1 -0
- package/examples/jsm/webxr/XRPlanes.js +100 -0
- package/package.json +34 -87
- package/src/Three.Legacy.js +19 -110
- package/src/Three.js +4 -3
- package/src/animation/AnimationUtils.js +13 -1
- package/src/audio/Audio.js +7 -2
- package/src/audio/PositionalAudio.js +8 -0
- package/src/cameras/Camera.js +5 -0
- package/src/cameras/CubeCamera.js +76 -13
- package/src/cameras/OrthographicCamera.js +1 -1
- package/src/cameras/PerspectiveCamera.js +1 -1
- package/src/constants.js +22 -2
- package/src/core/BufferAttribute.js +150 -9
- package/src/core/BufferGeometry.js +4 -10
- package/src/core/GLBufferAttribute.js +2 -0
- package/src/core/InterleavedBufferAttribute.js +5 -5
- package/src/core/Object3D.js +37 -8
- package/src/extras/DataUtils.js +7 -1
- package/src/extras/ImageUtils.js +2 -2
- package/src/extras/PMREMGenerator.js +5 -5
- package/src/extras/core/Curve.js +1 -1
- package/src/extras/curves/LineCurve.js +6 -4
- package/src/extras/curves/LineCurve3.js +13 -0
- package/src/geometries/BoxGeometry.js +10 -0
- package/src/geometries/CircleGeometry.js +11 -1
- package/src/geometries/ConeGeometry.js +1 -1
- package/src/geometries/CylinderGeometry.js +11 -1
- package/src/geometries/EdgesGeometry.js +10 -0
- package/src/geometries/ExtrudeGeometry.js +11 -1
- package/src/geometries/LatheGeometry.js +10 -0
- package/src/geometries/PlaneGeometry.js +10 -0
- package/src/geometries/PolyhedronGeometry.js +11 -1
- package/src/geometries/RingGeometry.js +11 -1
- package/src/geometries/ShapeGeometry.js +11 -1
- package/src/geometries/SphereGeometry.js +12 -2
- package/src/geometries/TorusGeometry.js +11 -1
- package/src/geometries/TorusKnotGeometry.js +10 -0
- package/src/geometries/TubeGeometry.js +10 -0
- package/src/geometries/WireframeGeometry.js +10 -0
- package/src/helpers/Box3Helper.js +1 -2
- package/src/lights/DirectionalLight.js +1 -1
- package/src/lights/HemisphereLight.js +1 -1
- package/src/lights/SpotLight.js +1 -1
- package/src/loaders/AudioLoader.js +14 -8
- package/src/loaders/CubeTextureLoader.js +2 -0
- package/src/loaders/DataTextureLoader.js +5 -1
- package/src/loaders/MaterialLoader.js +8 -0
- package/src/loaders/ObjectLoader.js +10 -2
- package/src/materials/LineBasicMaterial.js +4 -0
- package/src/materials/Material.js +16 -4
- package/src/materials/MeshDistanceMaterial.js +0 -9
- package/src/materials/MeshPhysicalMaterial.js +32 -6
- package/src/materials/ShaderMaterial.js +6 -1
- package/src/math/Box2.js +3 -2
- package/src/math/Box3.js +49 -64
- package/src/math/Color.js +88 -66
- package/src/math/ColorManagement.js +75 -16
- package/src/math/Euler.js +2 -11
- package/src/math/Frustum.js +29 -5
- package/src/math/MathUtils.js +43 -1
- package/src/math/Matrix3.js +26 -6
- package/src/math/Matrix4.js +74 -19
- package/src/math/Plane.js +2 -2
- package/src/math/Quaternion.js +6 -0
- package/src/math/Ray.js +7 -7
- package/src/math/Triangle.js +37 -7
- package/src/math/Vector2.js +16 -0
- package/src/math/Vector3.js +10 -0
- package/src/math/interpolants/CubicInterpolant.js +1 -2
- package/src/objects/InstancedMesh.js +82 -1
- package/src/objects/Mesh.js +108 -76
- package/src/objects/Skeleton.js +1 -1
- package/src/objects/SkinnedMesh.js +123 -8
- package/src/objects/Sprite.js +1 -1
- package/src/renderers/WebGLCubeRenderTarget.js +12 -3
- package/src/renderers/WebGLMultipleRenderTargets.js +4 -2
- package/src/renderers/WebGLRenderTarget.js +14 -2
- package/src/renderers/WebGLRenderer.js +1433 -1236
- package/src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +0 -271
- package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +5 -5
- package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js +2 -10
- package/src/renderers/shaders/ShaderChunk/clearcoat_pars_fragment.glsl.js +5 -5
- package/src/renderers/shaders/ShaderChunk/common.glsl.js +32 -0
- package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +26 -3
- package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +3 -3
- package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +10 -2
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +11 -11
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +39 -13
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +306 -10
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -10
- package/src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl.js +9 -1
- package/src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl.js +10 -2
- package/src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +32 -10
- package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +5 -13
- package/src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/output_fragment.glsl.js +1 -2
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +11 -5
- package/src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +4 -11
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +39 -34
- package/src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +5 -5
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +101 -16
- package/src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js +113 -1
- package/src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js +134 -6
- package/src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js +116 -1
- package/src/renderers/shaders/ShaderChunk.js +0 -6
- package/src/renderers/shaders/ShaderLib/background.glsl.js +0 -8
- package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +5 -0
- package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +1 -4
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +0 -3
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +3 -3
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +0 -3
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +16 -12
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -3
- package/src/renderers/shaders/ShaderLib/points.glsl.js +13 -0
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +5 -0
- package/src/renderers/shaders/ShaderLib.js +18 -4
- package/src/renderers/shaders/UniformsLib.js +27 -15
- package/src/renderers/shaders/UniformsUtils.js +12 -3
- package/src/renderers/webgl/WebGLBackground.js +23 -12
- package/src/renderers/webgl/WebGLBindingStates.js +13 -5
- package/src/renderers/webgl/WebGLCapabilities.js +1 -2
- package/src/renderers/webgl/WebGLClipping.js +7 -3
- package/src/renderers/webgl/WebGLGeometries.js +12 -0
- package/src/renderers/webgl/WebGLInfo.js +0 -1
- package/src/renderers/webgl/WebGLLights.js +2 -2
- package/src/renderers/webgl/WebGLMaterials.js +123 -234
- package/src/renderers/webgl/WebGLMorphtargets.js +1 -1
- package/src/renderers/webgl/WebGLProgram.js +130 -48
- package/src/renderers/webgl/WebGLPrograms.js +210 -130
- package/src/renderers/webgl/WebGLRenderStates.js +2 -2
- package/src/renderers/webgl/WebGLShadowMap.js +40 -27
- package/src/renderers/webgl/WebGLState.js +23 -9
- package/src/renderers/webgl/WebGLTextures.js +39 -19
- package/src/renderers/webgl/WebGLUniformsGroups.js +74 -33
- package/src/renderers/webgl/WebGLUtils.js +41 -29
- package/src/renderers/webxr/WebXRController.js +3 -0
- package/src/renderers/webxr/WebXRManager.js +89 -141
- package/src/scenes/Scene.js +4 -6
- package/src/textures/CompressedTexture.js +2 -2
- package/src/textures/CubeTexture.js +2 -2
- package/src/textures/DataTexture.js +2 -2
- package/src/textures/DepthTexture.js +22 -0
- package/src/textures/FramebufferTexture.js +1 -3
- package/src/textures/Source.js +4 -0
- package/src/textures/Texture.js +43 -13
- package/src/utils.js +13 -1
- package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff +0 -0
- package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff2 +0 -0
- package/examples/fonts/open-sans/open-sans.css +0 -9
- package/examples/fonts/tabler-icons/fonts/tabler-icons.eot +0 -0
- package/examples/fonts/tabler-icons/fonts/tabler-icons.svg +0 -3966
- package/examples/fonts/tabler-icons/fonts/tabler-icons.ttf +0 -0
- package/examples/fonts/tabler-icons/fonts/tabler-icons.woff +0 -0
- package/examples/fonts/tabler-icons/fonts/tabler-icons.woff2 +0 -0
- package/examples/fonts/tabler-icons/tabler-icons.min.css +0 -4
- package/examples/js/animation/AnimationClipCreator.js +0 -89
- package/examples/js/animation/CCDIKSolver.js +0 -416
- package/examples/js/animation/MMDAnimationHelper.js +0 -1046
- package/examples/js/animation/MMDPhysics.js +0 -1174
- package/examples/js/cameras/CinematicCamera.js +0 -168
- package/examples/js/controls/ArcballControls.js +0 -2770
- package/examples/js/controls/DragControls.js +0 -205
- package/examples/js/controls/FirstPersonControls.js +0 -312
- package/examples/js/controls/FlyControls.js +0 -321
- package/examples/js/controls/OrbitControls.js +0 -1065
- package/examples/js/controls/PointerLockControls.js +0 -144
- package/examples/js/controls/TrackballControls.js +0 -729
- package/examples/js/controls/TransformControls.js +0 -1301
- package/examples/js/csm/CSM.js +0 -347
- package/examples/js/csm/CSMFrustum.js +0 -127
- package/examples/js/csm/CSMHelper.js +0 -165
- package/examples/js/csm/CSMShader.js +0 -253
- package/examples/js/curves/CurveExtras.js +0 -348
- package/examples/js/curves/NURBSCurve.js +0 -63
- package/examples/js/curves/NURBSSurface.js +0 -48
- package/examples/js/curves/NURBSUtils.js +0 -439
- package/examples/js/effects/AnaglyphEffect.js +0 -86
- package/examples/js/effects/AsciiEffect.js +0 -260
- package/examples/js/effects/OutlineEffect.js +0 -450
- package/examples/js/effects/ParallaxBarrierEffect.js +0 -62
- package/examples/js/effects/PeppersGhostEffect.js +0 -139
- package/examples/js/effects/StereoEffect.js +0 -46
- package/examples/js/environments/DebugEnvironment.js +0 -53
- package/examples/js/environments/RoomEnvironment.js +0 -124
- package/examples/js/exporters/ColladaExporter.js +0 -487
- package/examples/js/exporters/DRACOExporter.js +0 -212
- package/examples/js/exporters/EXRExporter.js +0 -455
- package/examples/js/exporters/GLTFExporter.js +0 -2425
- package/examples/js/exporters/MMDExporter.js +0 -187
- package/examples/js/exporters/OBJExporter.js +0 -260
- package/examples/js/exporters/PLYExporter.js +0 -427
- package/examples/js/exporters/STLExporter.js +0 -188
- package/examples/js/exporters/USDZExporter.js +0 -608
- package/examples/js/geometries/BoxLineGeometry.js +0 -59
- package/examples/js/geometries/ConvexGeometry.js +0 -53
- package/examples/js/geometries/DecalGeometry.js +0 -324
- package/examples/js/geometries/LightningStrike.js +0 -861
- package/examples/js/geometries/ParametricGeometries.js +0 -216
- package/examples/js/geometries/ParametricGeometry.js +0 -121
- package/examples/js/geometries/RoundedBoxGeometry.js +0 -142
- package/examples/js/geometries/TeapotGeometry.js +0 -335
- package/examples/js/geometries/TextGeometry.js +0 -53
- package/examples/js/helpers/LightProbeHelper.js +0 -48
- package/examples/js/helpers/OctreeHelper.js +0 -76
- package/examples/js/helpers/PositionalAudioHelper.js +0 -91
- package/examples/js/helpers/RectAreaLightHelper.js +0 -73
- package/examples/js/helpers/VertexNormalsHelper.js +0 -74
- package/examples/js/helpers/VertexTangentsHelper.js +0 -68
- package/examples/js/helpers/ViewHelper.js +0 -281
- package/examples/js/interactive/HTMLMesh.js +0 -497
- package/examples/js/interactive/InteractiveGroup.js +0 -95
- package/examples/js/interactive/SelectionBox.js +0 -195
- package/examples/js/interactive/SelectionHelper.js +0 -83
- package/examples/js/libs/chevrotain.min.js +0 -3
- package/examples/js/libs/draco/draco_decoder.js +0 -52
- package/examples/js/libs/draco/draco_decoder.wasm +0 -0
- package/examples/js/libs/draco/draco_wasm_wrapper.js +0 -104
- package/examples/js/libs/draco/gltf/draco_decoder.js +0 -48
- package/examples/js/libs/draco/gltf/draco_decoder.wasm +0 -0
- package/examples/js/libs/draco/gltf/draco_wasm_wrapper.js +0 -104
- package/examples/js/libs/fflate.min.js +0 -7
- package/examples/js/libs/ktx-parse.umd.js +0 -1
- package/examples/js/libs/meshopt_decoder.js +0 -188
- package/examples/js/libs/opentype.min.js +0 -1
- package/examples/js/libs/stats.min.js +0 -5
- package/examples/js/lights/LightProbeGenerator.js +0 -221
- package/examples/js/lights/RectAreaLightUniformsLib.js +0 -60
- package/examples/js/lines/Line2.js +0 -19
- package/examples/js/lines/LineGeometry.js +0 -69
- package/examples/js/lines/LineMaterial.js +0 -635
- package/examples/js/lines/LineSegments2.js +0 -311
- package/examples/js/lines/LineSegmentsGeometry.js +0 -198
- package/examples/js/lines/Wireframe.js +0 -47
- package/examples/js/lines/WireframeGeometry2.js +0 -20
- package/examples/js/loaders/3DMLoader.js +0 -1273
- package/examples/js/loaders/3MFLoader.js +0 -1306
- package/examples/js/loaders/AMFLoader.js +0 -504
- package/examples/js/loaders/BVHLoader.js +0 -395
- package/examples/js/loaders/BasisTextureLoader.js +0 -706
- package/examples/js/loaders/ColladaLoader.js +0 -3663
- package/examples/js/loaders/DDSLoader.js +0 -244
- package/examples/js/loaders/DRACOLoader.js +0 -511
- package/examples/js/loaders/EXRLoader.js +0 -2039
- package/examples/js/loaders/FBXLoader.js +0 -3680
- package/examples/js/loaders/FontLoader.js +0 -160
- package/examples/js/loaders/GCodeLoader.js +0 -255
- package/examples/js/loaders/GLTFLoader.js +0 -4108
- package/examples/js/loaders/HDRCubeTextureLoader.js +0 -87
- package/examples/js/loaders/KMZLoader.js +0 -121
- package/examples/js/loaders/KTXLoader.js +0 -159
- package/examples/js/loaders/LDrawLoader.js +0 -2263
- package/examples/js/loaders/LUT3dlLoader.js +0 -135
- package/examples/js/loaders/LUTCubeLoader.js +0 -132
- package/examples/js/loaders/LWOLoader.js +0 -901
- package/examples/js/loaders/LogLuvLoader.js +0 -715
- package/examples/js/loaders/LottieLoader.js +0 -62
- package/examples/js/loaders/MD2Loader.js +0 -248
- package/examples/js/loaders/MDDLoader.js +0 -91
- package/examples/js/loaders/MMDLoader.js +0 -1915
- package/examples/js/loaders/MTLLoader.js +0 -472
- package/examples/js/loaders/MaterialXLoader.js +0 -392
- package/examples/js/loaders/NRRDLoader.js +0 -609
- package/examples/js/loaders/OBJLoader.js +0 -789
- package/examples/js/loaders/PCDLoader.js +0 -413
- package/examples/js/loaders/PDBLoader.js +0 -317
- package/examples/js/loaders/PLYLoader.js +0 -532
- package/examples/js/loaders/PRWMLoader.js +0 -249
- package/examples/js/loaders/PVRLoader.js +0 -218
- package/examples/js/loaders/RGBELoader.js +0 -442
- package/examples/js/loaders/RGBMLoader.js +0 -1354
- package/examples/js/loaders/STLLoader.js +0 -364
- package/examples/js/loaders/SVGLoader.js +0 -2783
- package/examples/js/loaders/TDSLoader.js +0 -992
- package/examples/js/loaders/TGALoader.js +0 -484
- package/examples/js/loaders/TIFFLoader.js +0 -30
- package/examples/js/loaders/TTFLoader.js +0 -203
- package/examples/js/loaders/TiltLoader.js +0 -459
- package/examples/js/loaders/VOXLoader.js +0 -240
- package/examples/js/loaders/VRMLLoader.js +0 -3140
- package/examples/js/loaders/VTKLoader.js +0 -1078
- package/examples/js/loaders/XYZLoader.js +0 -89
- package/examples/js/loaders/lwo/IFFParser.js +0 -1067
- package/examples/js/loaders/lwo/LWO2Parser.js +0 -397
- package/examples/js/loaders/lwo/LWO3Parser.js +0 -360
- package/examples/js/materials/MeshGouraudMaterial.js +0 -387
- package/examples/js/math/Capsule.js +0 -103
- package/examples/js/math/ColorConverter.js +0 -33
- package/examples/js/math/ConvexHull.js +0 -1154
- package/examples/js/math/ImprovedNoise.js +0 -66
- package/examples/js/math/Lut.js +0 -164
- package/examples/js/math/MeshSurfaceSampler.js +0 -171
- package/examples/js/math/OBB.js +0 -382
- package/examples/js/math/Octree.js +0 -410
- package/examples/js/math/SimplexNoise.js +0 -445
- package/examples/js/misc/ConvexObjectBreaker.js +0 -474
- package/examples/js/misc/GPUComputationRenderer.js +0 -393
- package/examples/js/misc/Gyroscope.js +0 -56
- package/examples/js/misc/MD2Character.js +0 -235
- package/examples/js/misc/MD2CharacterComplex.js +0 -513
- package/examples/js/misc/MorphAnimMesh.js +0 -63
- package/examples/js/misc/MorphBlendMesh.js +0 -265
- package/examples/js/misc/ProgressiveLightMap.js +0 -335
- package/examples/js/misc/RollerCoaster.js +0 -430
- package/examples/js/misc/TubePainter.js +0 -167
- package/examples/js/misc/Volume.js +0 -437
- package/examples/js/misc/VolumeSlice.js +0 -214
- package/examples/js/modifiers/CurveModifier.js +0 -309
- package/examples/js/modifiers/EdgeSplitModifier.js +0 -228
- package/examples/js/modifiers/SimplifyModifier.js +0 -465
- package/examples/js/modifiers/TessellateModifier.js +0 -276
- package/examples/js/objects/GroundProjectedEnv.js +0 -181
- package/examples/js/objects/Lensflare.js +0 -356
- package/examples/js/objects/LightningStorm.js +0 -206
- package/examples/js/objects/MarchingCubes.js +0 -759
- package/examples/js/objects/Reflector.js +0 -216
- package/examples/js/objects/ReflectorForSSRPass.js +0 -315
- package/examples/js/objects/Refractor.js +0 -283
- package/examples/js/objects/ShadowMesh.js +0 -59
- package/examples/js/objects/Sky.js +0 -218
- package/examples/js/objects/Water.js +0 -292
- package/examples/js/objects/Water2.js +0 -307
- package/examples/js/physics/AmmoPhysics.js +0 -259
- package/examples/js/physics/OimoPhysics.js +0 -217
- package/examples/js/postprocessing/AdaptiveToneMappingPass.js +0 -335
- package/examples/js/postprocessing/AfterimagePass.js +0 -77
- package/examples/js/postprocessing/BloomPass.js +0 -135
- package/examples/js/postprocessing/BokehPass.js +0 -120
- package/examples/js/postprocessing/ClearPass.js +0 -39
- package/examples/js/postprocessing/CubeTexturePass.js +0 -60
- package/examples/js/postprocessing/DotScreenPass.js +0 -51
- package/examples/js/postprocessing/EffectComposer.js +0 -272
- package/examples/js/postprocessing/FilmPass.js +0 -52
- package/examples/js/postprocessing/GlitchPass.js +0 -104
- package/examples/js/postprocessing/HalftonePass.js +0 -75
- package/examples/js/postprocessing/LUTPass.js +0 -171
- package/examples/js/postprocessing/MaskPass.js +0 -95
- package/examples/js/postprocessing/OutlinePass.js +0 -598
- package/examples/js/postprocessing/Pass.js +0 -72
- package/examples/js/postprocessing/RenderPass.js +0 -70
- package/examples/js/postprocessing/SAOPass.js +0 -374
- package/examples/js/postprocessing/SMAAPass.js +0 -170
- package/examples/js/postprocessing/SSAARenderPass.js +0 -156
- package/examples/js/postprocessing/SSAOPass.js +0 -365
- package/examples/js/postprocessing/SSRPass.js +0 -567
- package/examples/js/postprocessing/SavePass.js +0 -59
- package/examples/js/postprocessing/ShaderPass.js +0 -64
- package/examples/js/postprocessing/TAARenderPass.js +0 -130
- package/examples/js/postprocessing/TexturePass.js +0 -49
- package/examples/js/postprocessing/UnrealBloomPass.js +0 -375
- package/examples/js/renderers/CSS2DRenderer.js +0 -178
- package/examples/js/renderers/CSS3DRenderer.js +0 -237
- package/examples/js/renderers/Projector.js +0 -818
- package/examples/js/renderers/SVGRenderer.js +0 -491
- package/examples/js/shaders/ACESFilmicToneMappingShader.js +0 -89
- package/examples/js/shaders/AfterimageShader.js +0 -60
- package/examples/js/shaders/BasicShader.js +0 -27
- package/examples/js/shaders/BleachBypassShader.js +0 -62
- package/examples/js/shaders/BlendShader.js +0 -54
- package/examples/js/shaders/BokehShader.js +0 -156
- package/examples/js/shaders/BokehShader2.js +0 -419
- package/examples/js/shaders/BrightnessContrastShader.js +0 -58
- package/examples/js/shaders/ColorCorrectionShader.js +0 -52
- package/examples/js/shaders/ColorifyShader.js +0 -47
- package/examples/js/shaders/ConvolutionShader.js +0 -92
- package/examples/js/shaders/CopyShader.js +0 -45
- package/examples/js/shaders/DOFMipMapShader.js +0 -60
- package/examples/js/shaders/DepthLimitedBlurShader.js +0 -173
- package/examples/js/shaders/DigitalGlitch.js +0 -127
- package/examples/js/shaders/DotScreenShader.js +0 -72
- package/examples/js/shaders/FXAAShader.js +0 -284
- package/examples/js/shaders/FilmShader.js +0 -110
- package/examples/js/shaders/FocusShader.js +0 -95
- package/examples/js/shaders/FreiChenShader.js +0 -93
- package/examples/js/shaders/GammaCorrectionShader.js +0 -41
- package/examples/js/shaders/GodRaysShader.js +0 -284
- package/examples/js/shaders/HalftoneShader.js +0 -336
- package/examples/js/shaders/HorizontalBlurShader.js +0 -59
- package/examples/js/shaders/HorizontalTiltShiftShader.js +0 -65
- package/examples/js/shaders/HueSaturationShader.js +0 -69
- package/examples/js/shaders/KaleidoShader.js +0 -60
- package/examples/js/shaders/LuminosityHighPassShader.js +0 -67
- package/examples/js/shaders/LuminosityShader.js +0 -46
- package/examples/js/shaders/MMDToonShader.js +0 -96
- package/examples/js/shaders/MirrorShader.js +0 -56
- package/examples/js/shaders/NormalMapShader.js +0 -55
- package/examples/js/shaders/RGBShiftShader.js +0 -56
- package/examples/js/shaders/SAOShader.js +0 -209
- package/examples/js/shaders/SMAAShader.js +0 -454
- package/examples/js/shaders/SSAOShader.js +0 -295
- package/examples/js/shaders/SSRShader.js +0 -381
- package/examples/js/shaders/SepiaShader.js +0 -52
- package/examples/js/shaders/SobelOperatorShader.js +0 -88
- package/examples/js/shaders/SubsurfaceScatteringShader.js +0 -49
- package/examples/js/shaders/TechnicolorShader.js +0 -43
- package/examples/js/shaders/ToneMapShader.js +0 -84
- package/examples/js/shaders/ToonShader.js +0 -335
- package/examples/js/shaders/TriangleBlurShader.js +0 -70
- package/examples/js/shaders/UnpackDepthRGBAShader.js +0 -47
- package/examples/js/shaders/VelocityShader.js +0 -126
- package/examples/js/shaders/VerticalBlurShader.js +0 -59
- package/examples/js/shaders/VerticalTiltShiftShader.js +0 -65
- package/examples/js/shaders/VignetteShader.js +0 -53
- package/examples/js/shaders/VolumeShader.js +0 -296
- package/examples/js/shaders/WaterRefractionShader.js +0 -84
- package/examples/js/textures/FlakesTexture.js +0 -40
- package/examples/js/utils/BufferGeometryUtils.js +0 -1160
- package/examples/js/utils/CameraUtils.js +0 -71
- package/examples/js/utils/GPUStatsPanel.js +0 -125
- package/examples/js/utils/GeometryCompressionUtils.js +0 -549
- package/examples/js/utils/GeometryUtils.js +0 -168
- package/examples/js/utils/LDrawUtils.js +0 -179
- package/examples/js/utils/PackedPhongMaterial.js +0 -109
- package/examples/js/utils/SceneUtils.js +0 -214
- package/examples/js/utils/ShadowMapViewer.js +0 -183
- package/examples/js/utils/SkeletonUtils.js +0 -493
- package/examples/js/utils/UVsDebug.js +0 -143
- package/examples/js/utils/WorkerPool.js +0 -105
- package/examples/jsm/exporters/ColladaExporter.js +0 -713
- package/examples/jsm/geometries/LightningStrike.js +0 -1017
- package/examples/jsm/libs/OimoPhysics/OimoPhysics.js +0 -37071
- package/examples/jsm/libs/OimoPhysics/index.js +0 -43
- package/examples/jsm/libs/flow.module.js +0 -4552
- package/examples/jsm/libs/tween.module.min.js +0 -3
- package/examples/jsm/loaders/BasisTextureLoader.js +0 -790
- package/examples/jsm/loaders/IFCLoader.js +0 -2431
- package/examples/jsm/loaders/PRWMLoader.js +0 -299
- package/examples/jsm/loaders/ifc/web-ifc-api.js +0 -47504
- package/examples/jsm/loaders/ifc/web-ifc.wasm +0 -0
- package/examples/jsm/node-editor/NodeEditor.js +0 -857
- package/examples/jsm/node-editor/accessors/MatcapUVEditor.js +0 -14
- package/examples/jsm/node-editor/accessors/NormalEditor.js +0 -30
- package/examples/jsm/node-editor/accessors/PositionEditor.js +0 -30
- package/examples/jsm/node-editor/accessors/UVEditor.js +0 -25
- package/examples/jsm/node-editor/core/BaseNode.js +0 -96
- package/examples/jsm/node-editor/core/DataFile.js +0 -59
- package/examples/jsm/node-editor/core/FileEditor.js +0 -20
- package/examples/jsm/node-editor/core/FileURLEditor.js +0 -29
- package/examples/jsm/node-editor/display/BlendEditor.js +0 -44
- package/examples/jsm/node-editor/display/NormalMapEditor.js +0 -49
- package/examples/jsm/node-editor/examples/animate-uv.json +0 -1
- package/examples/jsm/node-editor/examples/fake-top-light.json +0 -1
- package/examples/jsm/node-editor/examples/matcap.json +0 -1
- package/examples/jsm/node-editor/examples/oscillator-color.json +0 -1
- package/examples/jsm/node-editor/examples/rim.json +0 -1
- package/examples/jsm/node-editor/inputs/ColorEditor.js +0 -96
- package/examples/jsm/node-editor/inputs/FloatEditor.js +0 -23
- package/examples/jsm/node-editor/inputs/SliderEditor.js +0 -67
- package/examples/jsm/node-editor/inputs/TextureEditor.js +0 -155
- package/examples/jsm/node-editor/inputs/Vector2Editor.js +0 -28
- package/examples/jsm/node-editor/inputs/Vector3Editor.js +0 -30
- package/examples/jsm/node-editor/inputs/Vector4Editor.js +0 -37
- package/examples/jsm/node-editor/materials/BasicMaterialEditor.js +0 -84
- package/examples/jsm/node-editor/materials/PointsMaterialEditor.js +0 -102
- package/examples/jsm/node-editor/materials/StandardMaterialEditor.js +0 -118
- package/examples/jsm/node-editor/math/AngleEditor.js +0 -40
- package/examples/jsm/node-editor/math/DotEditor.js +0 -35
- package/examples/jsm/node-editor/math/InvertEditor.js +0 -39
- package/examples/jsm/node-editor/math/LimiterEditor.js +0 -62
- package/examples/jsm/node-editor/math/NormalizeEditor.js +0 -28
- package/examples/jsm/node-editor/math/OperatorEditor.js +0 -63
- package/examples/jsm/node-editor/math/PowerEditor.js +0 -44
- package/examples/jsm/node-editor/math/TrigonometryEditor.js +0 -45
- package/examples/jsm/node-editor/procedural/CheckerEditor.js +0 -27
- package/examples/jsm/node-editor/scene/MeshEditor.js +0 -102
- package/examples/jsm/node-editor/scene/Object3DEditor.js +0 -160
- package/examples/jsm/node-editor/scene/PointsEditor.js +0 -99
- package/examples/jsm/node-editor/utils/JoinEditor.js +0 -58
- package/examples/jsm/node-editor/utils/OscillatorEditor.js +0 -43
- package/examples/jsm/node-editor/utils/PreviewEditor.js +0 -170
- package/examples/jsm/node-editor/utils/SplitEditor.js +0 -39
- package/examples/jsm/node-editor/utils/TimerEditor.js +0 -58
- package/examples/jsm/nodes/core/CodeNode.js +0 -50
- package/examples/jsm/nodes/core/ExpressionNode.js +0 -32
- package/examples/jsm/nodes/functions/light/getDistanceAttenuation.js +0 -22
- package/examples/jsm/nodes/lighting/PunctualLightNode.js +0 -68
- package/examples/jsm/nodes/shadernode/ShaderNodeBaseElements.js +0 -301
- package/examples/jsm/nodes/shadernode/ShaderNodeElements.js +0 -149
- package/examples/jsm/objects/GroundProjectedEnv.js +0 -186
- package/examples/jsm/objects/LightningStorm.js +0 -245
- package/examples/jsm/physics/OimoPhysics.js +0 -231
- package/examples/jsm/postprocessing/AdaptiveToneMappingPass.js +0 -369
- package/examples/jsm/renderers/webgpu/WebGPUAttributes.js +0 -187
- package/examples/jsm/renderers/webgpu/WebGPUBackground.js +0 -173
- package/examples/jsm/renderers/webgpu/WebGPUBinding.js +0 -22
- package/examples/jsm/renderers/webgpu/WebGPUBindings.js +0 -255
- package/examples/jsm/renderers/webgpu/WebGPUBuffer.js +0 -43
- package/examples/jsm/renderers/webgpu/WebGPUComputePipelines.js +0 -78
- package/examples/jsm/renderers/webgpu/WebGPUGeometries.js +0 -82
- package/examples/jsm/renderers/webgpu/WebGPUObjects.js +0 -36
- package/examples/jsm/renderers/webgpu/WebGPUProgrammableStage.js +0 -22
- package/examples/jsm/renderers/webgpu/WebGPUProperties.js +0 -38
- package/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js +0 -296
- package/examples/jsm/renderers/webgpu/WebGPURenderStates.js +0 -66
- package/examples/jsm/renderers/webgpu/WebGPUSampledTexture.js +0 -73
- package/examples/jsm/renderers/webgpu/WebGPUSampler.js +0 -29
- package/examples/jsm/renderers/webgpu/WebGPUStorageBuffer.js +0 -20
- package/examples/jsm/renderers/webgpu/WebGPUTextureRenderer.js +0 -40
- package/examples/jsm/renderers/webgpu/WebGPUTextures.js +0 -794
- package/examples/jsm/renderers/webgpu/WebGPUUniformBuffer.js +0 -18
- package/examples/jsm/renderers/webgpu/WebGPUUtils.js +0 -81
- package/examples/jsm/renderers/webgpu/nodes/WebGPUNodes.js +0 -83
- package/examples/jsm/shaders/ToneMapShader.js +0 -73
- package/src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl.js +0 -7
- package/src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl.js +0 -10
- package/src/renderers/shaders/ShaderChunk/uv2_vertex.glsl.js +0 -7
- /package/examples/{js → jsm}/libs/ammo.wasm.js +0 -0
- /package/examples/{js → jsm}/libs/ammo.wasm.wasm +0 -0
- /package/examples/{js → jsm}/libs/basis/basis_transcoder.js +0 -0
- /package/examples/{js → jsm}/libs/basis/basis_transcoder.wasm +0 -0
- /package/examples/{js → jsm}/libs/draco/README.md +0 -0
- /package/examples/{js → jsm}/libs/draco/draco_encoder.js +0 -0
- /package/examples/{js → jsm}/libs/draco/gltf/draco_encoder.js +0 -0
|
@@ -1,1915 +0,0 @@
|
|
|
1
|
-
( function () {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Dependencies
|
|
5
|
-
* - mmd-parser https://github.com/takahirox/mmd-parser
|
|
6
|
-
* - THREE.TGALoader
|
|
7
|
-
* - OutlineEffect
|
|
8
|
-
*
|
|
9
|
-
* MMDLoader creates Three.js Objects from MMD resources as
|
|
10
|
-
* PMD, PMX, VMD, and VPD files.
|
|
11
|
-
*
|
|
12
|
-
* PMD/PMX is a model data format, VMD is a motion data format
|
|
13
|
-
* VPD is a posing data format used in MMD(Miku Miku Dance).
|
|
14
|
-
*
|
|
15
|
-
* MMD official site
|
|
16
|
-
* - https://sites.google.com/view/evpvp/
|
|
17
|
-
*
|
|
18
|
-
* PMD, VMD format (in Japanese)
|
|
19
|
-
* - http://blog.goo.ne.jp/torisu_tetosuki/e/209ad341d3ece2b1b4df24abf619d6e4
|
|
20
|
-
*
|
|
21
|
-
* PMX format
|
|
22
|
-
* - https://gist.github.com/felixjones/f8a06bd48f9da9a4539f
|
|
23
|
-
*
|
|
24
|
-
* TODO
|
|
25
|
-
* - light motion in vmd support.
|
|
26
|
-
* - SDEF support.
|
|
27
|
-
* - uv/material/bone morphing support.
|
|
28
|
-
* - more precise grant skinning support.
|
|
29
|
-
* - shadow support.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @param {THREE.LoadingManager} manager
|
|
34
|
-
*/
|
|
35
|
-
class MMDLoader extends THREE.Loader {
|
|
36
|
-
|
|
37
|
-
constructor( manager ) {
|
|
38
|
-
|
|
39
|
-
super( manager );
|
|
40
|
-
this.loader = new THREE.FileLoader( this.manager );
|
|
41
|
-
this.parser = null; // lazy generation
|
|
42
|
-
this.meshBuilder = new MeshBuilder( this.manager );
|
|
43
|
-
this.animationBuilder = new AnimationBuilder();
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @param {string} animationPath
|
|
49
|
-
* @return {MMDLoader}
|
|
50
|
-
*/
|
|
51
|
-
setAnimationPath( animationPath ) {
|
|
52
|
-
|
|
53
|
-
this.animationPath = animationPath;
|
|
54
|
-
return this;
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Load MMD assets as Three.js Object
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Loads Model file (.pmd or .pmx) as a THREE.SkinnedMesh.
|
|
62
|
-
*
|
|
63
|
-
* @param {string} url - url to Model(.pmd or .pmx) file
|
|
64
|
-
* @param {function} onLoad
|
|
65
|
-
* @param {function} onProgress
|
|
66
|
-
* @param {function} onError
|
|
67
|
-
*/
|
|
68
|
-
load( url, onLoad, onProgress, onError ) {
|
|
69
|
-
|
|
70
|
-
const builder = this.meshBuilder.setCrossOrigin( this.crossOrigin );
|
|
71
|
-
|
|
72
|
-
// resource path
|
|
73
|
-
|
|
74
|
-
let resourcePath;
|
|
75
|
-
if ( this.resourcePath !== '' ) {
|
|
76
|
-
|
|
77
|
-
resourcePath = this.resourcePath;
|
|
78
|
-
|
|
79
|
-
} else if ( this.path !== '' ) {
|
|
80
|
-
|
|
81
|
-
resourcePath = this.path;
|
|
82
|
-
|
|
83
|
-
} else {
|
|
84
|
-
|
|
85
|
-
resourcePath = THREE.LoaderUtils.extractUrlBase( url );
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const modelExtension = this._extractExtension( url ).toLowerCase();
|
|
90
|
-
|
|
91
|
-
// Should I detect by seeing header?
|
|
92
|
-
if ( modelExtension !== 'pmd' && modelExtension !== 'pmx' ) {
|
|
93
|
-
|
|
94
|
-
if ( onError ) onError( new Error( 'THREE.MMDLoader: Unknown model file extension .' + modelExtension + '.' ) );
|
|
95
|
-
return;
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
this[ modelExtension === 'pmd' ? 'loadPMD' : 'loadPMX' ]( url, function ( data ) {
|
|
100
|
-
|
|
101
|
-
onLoad( builder.build( data, resourcePath, onProgress, onError ) );
|
|
102
|
-
|
|
103
|
-
}, onProgress, onError );
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Loads Motion file(s) (.vmd) as a THREE.AnimationClip.
|
|
109
|
-
* If two or more files are specified, they'll be merged.
|
|
110
|
-
*
|
|
111
|
-
* @param {string|Array<string>} url - url(s) to animation(.vmd) file(s)
|
|
112
|
-
* @param {SkinnedMesh|THREE.Camera} object - tracks will be fitting to this object
|
|
113
|
-
* @param {function} onLoad
|
|
114
|
-
* @param {function} onProgress
|
|
115
|
-
* @param {function} onError
|
|
116
|
-
*/
|
|
117
|
-
loadAnimation( url, object, onLoad, onProgress, onError ) {
|
|
118
|
-
|
|
119
|
-
const builder = this.animationBuilder;
|
|
120
|
-
this.loadVMD( url, function ( vmd ) {
|
|
121
|
-
|
|
122
|
-
onLoad( object.isCamera ? builder.buildCameraAnimation( vmd ) : builder.build( vmd, object ) );
|
|
123
|
-
|
|
124
|
-
}, onProgress, onError );
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Loads mode file and motion file(s) as an object containing
|
|
130
|
-
* a THREE.SkinnedMesh and a THREE.AnimationClip.
|
|
131
|
-
* Tracks of THREE.AnimationClip are fitting to the model.
|
|
132
|
-
*
|
|
133
|
-
* @param {string} modelUrl - url to Model(.pmd or .pmx) file
|
|
134
|
-
* @param {string|Array{string}} vmdUrl - url(s) to animation(.vmd) file
|
|
135
|
-
* @param {function} onLoad
|
|
136
|
-
* @param {function} onProgress
|
|
137
|
-
* @param {function} onError
|
|
138
|
-
*/
|
|
139
|
-
loadWithAnimation( modelUrl, vmdUrl, onLoad, onProgress, onError ) {
|
|
140
|
-
|
|
141
|
-
const scope = this;
|
|
142
|
-
this.load( modelUrl, function ( mesh ) {
|
|
143
|
-
|
|
144
|
-
scope.loadAnimation( vmdUrl, mesh, function ( animation ) {
|
|
145
|
-
|
|
146
|
-
onLoad( {
|
|
147
|
-
mesh: mesh,
|
|
148
|
-
animation: animation
|
|
149
|
-
} );
|
|
150
|
-
|
|
151
|
-
}, onProgress, onError );
|
|
152
|
-
|
|
153
|
-
}, onProgress, onError );
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Load MMD assets as Object data parsed by MMDParser
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Loads .pmd file as an Object.
|
|
161
|
-
*
|
|
162
|
-
* @param {string} url - url to .pmd file
|
|
163
|
-
* @param {function} onLoad
|
|
164
|
-
* @param {function} onProgress
|
|
165
|
-
* @param {function} onError
|
|
166
|
-
*/
|
|
167
|
-
loadPMD( url, onLoad, onProgress, onError ) {
|
|
168
|
-
|
|
169
|
-
const parser = this._getParser();
|
|
170
|
-
this.loader.setMimeType( undefined ).setPath( this.path ).setResponseType( 'arraybuffer' ).setRequestHeader( this.requestHeader ).setWithCredentials( this.withCredentials ).load( url, function ( buffer ) {
|
|
171
|
-
|
|
172
|
-
onLoad( parser.parsePmd( buffer, true ) );
|
|
173
|
-
|
|
174
|
-
}, onProgress, onError );
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Loads .pmx file as an Object.
|
|
180
|
-
*
|
|
181
|
-
* @param {string} url - url to .pmx file
|
|
182
|
-
* @param {function} onLoad
|
|
183
|
-
* @param {function} onProgress
|
|
184
|
-
* @param {function} onError
|
|
185
|
-
*/
|
|
186
|
-
loadPMX( url, onLoad, onProgress, onError ) {
|
|
187
|
-
|
|
188
|
-
const parser = this._getParser();
|
|
189
|
-
this.loader.setMimeType( undefined ).setPath( this.path ).setResponseType( 'arraybuffer' ).setRequestHeader( this.requestHeader ).setWithCredentials( this.withCredentials ).load( url, function ( buffer ) {
|
|
190
|
-
|
|
191
|
-
onLoad( parser.parsePmx( buffer, true ) );
|
|
192
|
-
|
|
193
|
-
}, onProgress, onError );
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Loads .vmd file as an Object. If two or more files are specified
|
|
199
|
-
* they'll be merged.
|
|
200
|
-
*
|
|
201
|
-
* @param {string|Array<string>} url - url(s) to .vmd file(s)
|
|
202
|
-
* @param {function} onLoad
|
|
203
|
-
* @param {function} onProgress
|
|
204
|
-
* @param {function} onError
|
|
205
|
-
*/
|
|
206
|
-
loadVMD( url, onLoad, onProgress, onError ) {
|
|
207
|
-
|
|
208
|
-
const urls = Array.isArray( url ) ? url : [ url ];
|
|
209
|
-
const vmds = [];
|
|
210
|
-
const vmdNum = urls.length;
|
|
211
|
-
const parser = this._getParser();
|
|
212
|
-
this.loader.setMimeType( undefined ).setPath( this.animationPath ).setResponseType( 'arraybuffer' ).setRequestHeader( this.requestHeader ).setWithCredentials( this.withCredentials );
|
|
213
|
-
for ( let i = 0, il = urls.length; i < il; i ++ ) {
|
|
214
|
-
|
|
215
|
-
this.loader.load( urls[ i ], function ( buffer ) {
|
|
216
|
-
|
|
217
|
-
vmds.push( parser.parseVmd( buffer, true ) );
|
|
218
|
-
if ( vmds.length === vmdNum ) onLoad( parser.mergeVmds( vmds ) );
|
|
219
|
-
|
|
220
|
-
}, onProgress, onError );
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Loads .vpd file as an Object.
|
|
228
|
-
*
|
|
229
|
-
* @param {string} url - url to .vpd file
|
|
230
|
-
* @param {boolean} isUnicode
|
|
231
|
-
* @param {function} onLoad
|
|
232
|
-
* @param {function} onProgress
|
|
233
|
-
* @param {function} onError
|
|
234
|
-
*/
|
|
235
|
-
loadVPD( url, isUnicode, onLoad, onProgress, onError ) {
|
|
236
|
-
|
|
237
|
-
const parser = this._getParser();
|
|
238
|
-
this.loader.setMimeType( isUnicode ? undefined : 'text/plain; charset=shift_jis' ).setPath( this.animationPath ).setResponseType( 'text' ).setRequestHeader( this.requestHeader ).setWithCredentials( this.withCredentials ).load( url, function ( text ) {
|
|
239
|
-
|
|
240
|
-
onLoad( parser.parseVpd( text, true ) );
|
|
241
|
-
|
|
242
|
-
}, onProgress, onError );
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// private methods
|
|
247
|
-
|
|
248
|
-
_extractExtension( url ) {
|
|
249
|
-
|
|
250
|
-
const index = url.lastIndexOf( '.' );
|
|
251
|
-
return index < 0 ? '' : url.slice( index + 1 );
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
_getParser() {
|
|
255
|
-
|
|
256
|
-
if ( this.parser === null ) {
|
|
257
|
-
|
|
258
|
-
if ( typeof MMDParser === 'undefined' ) {
|
|
259
|
-
|
|
260
|
-
throw new Error( 'THREE.MMDLoader: Import MMDParser https://github.com/takahirox/mmd-parser' );
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
this.parser = new MMDParser.Parser(); // eslint-disable-line no-undef
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return this.parser;
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// Utilities
|
|
275
|
-
|
|
276
|
-
/*
|
|
277
|
-
* base64 encoded defalut toon textures toon00.bmp - toon10.bmp.
|
|
278
|
-
* We don't need to request external toon image files.
|
|
279
|
-
*/
|
|
280
|
-
const DEFAULT_TOON_TEXTURES = [ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAN0lEQVRYR+3WQREAMBACsZ5/bWiiMvgEBTt5cW37hjsBBAgQIECAwFwgyfYPCCBAgAABAgTWAh8aBHZBl14e8wAAAABJRU5ErkJggg==', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAOUlEQVRYR+3WMREAMAwDsYY/yoDI7MLwIiP40+RJklfcCCBAgAABAgTqArfb/QMCCBAgQIAAgbbAB3z/e0F3js2cAAAAAElFTkSuQmCC', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAN0lEQVRYR+3WQREAMBACsZ5/B5ilMvgEBTt5cW37hjsBBAgQIECAwFwgyfYPCCBAgAABAgTWAh81dWyx0gFwKAAAAABJRU5ErkJggg==', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAOklEQVRYR+3WoREAMAwDsWb/UQtCy9wxTOQJ/oQ8SXKKGwEECBAgQIBAXeDt7f4BAQQIECBAgEBb4AOz8Hzx7WLY4wAAAABJRU5ErkJggg==', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABPUlEQVRYR+1XwW7CMAy1+f9fZOMysSEOEweEOPRNdm3HbdOyIhAcklPrOs/PLy9RygBALxzcCDQFmgJNgaZAU6Ap0BR4PwX8gsRMVLssMRH5HcpzJEaWL7EVg9F1IHRlyqQohgVr4FGUlUcMJSjcUlDw0zvjeun70cLWmneoyf7NgBTQSniBTQQSuJAZsOnnaczjIMb5hCiuHKxokCrJfVnrctyZL0PkJAJe1HMil4nxeyi3Ypfn1kX51jpPvo/JeCNC4PhVdHdJw2XjBR8brF8PEIhNVn12AgP7uHsTBguBn53MUZCqv7Lp07Pn5k1Ro+uWmUNn7D+M57rtk7aG0Vo73xyF/fbFf0bPJjDXngnGocDTdFhygZjwUQrMNrDcmZlQT50VJ/g/UwNyHpu778+yW+/ksOz/BFo54P4AsUXMfRq7XWsAAAAASUVORK5CYII=', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACMElEQVRYR+2Xv4pTQRTGf2dubhLdICiii2KnYKHVolhauKWPoGAnNr6BD6CvIVaihYuI2i1ia0BY0MZGRHQXjZj/mSPnnskfNWiWZUlzJ5k7M2cm833nO5Mziej2DWWJRUoCpQKlAntSQCqgw39/iUWAGmh37jrRnVsKlgpiqmkoGVABA7E57fvY+pJDdgKqF6HzFCSADkDq+F6AHABtQ+UMVE5D7zXod7fFNhTEckTbj5XQgHzNN+5tQvc5NG7C6BNkp6D3EmpXHDR+dQAjFLchW3VS9rlw3JBh+B7ys5Cf9z0GW1C/7P32AyBAOAz1q4jGliIH3YPuBnSfQX4OGreTIgEYQb/pBDtPnEQ4CivXYPAWBk13oHrB54yA9QuSn2H4AcKRpEILDt0BUzj+RLR1V5EqjD66NPRBVpLcQwjHoHYJOhsQv6U4mnzmrIXJCFr4LDwm/xBUoboG9XX4cc9VKdYoSA2yk5NQLJaKDUjTBoveG3Z2TElTxwjNK4M3LEZgUdDdruvcXzKBpStgp2NPiWi3ks9ZXxIoFVi+AvHLdc9TqtjL3/aYjpPlrzOcEnK62Szhimdd7xX232zFDTgtxezOu3WNMRLjiKgjtOhHVMd1loynVHvOgjuIIJMaELEqhJAV/RCSLbWTcfPFakFgFlALTRRvx+ok6Hlp/Q+v3fmx90bMyUzaEAhmM3KvHlXTL5DxnbGf/1M8RNNACLL5MNtPxP/mypJAqcDSFfgFhpYqWUzhTEAAAAAASUVORK5CYII=', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=' ];
|
|
281
|
-
const NON_ALPHA_CHANNEL_FORMATS = [ THREE.RGB_S3TC_DXT1_Format, THREE.RGB_PVRTC_4BPPV1_Format, THREE.RGB_PVRTC_2BPPV1_Format, THREE.RGB_ETC1_Format, THREE.RGB_ETC2_Format ];
|
|
282
|
-
|
|
283
|
-
// Builders. They build Three.js object from Object data parsed by MMDParser.
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* @param {THREE.LoadingManager} manager
|
|
287
|
-
*/
|
|
288
|
-
class MeshBuilder {
|
|
289
|
-
|
|
290
|
-
constructor( manager ) {
|
|
291
|
-
|
|
292
|
-
this.crossOrigin = 'anonymous';
|
|
293
|
-
this.geometryBuilder = new GeometryBuilder();
|
|
294
|
-
this.materialBuilder = new MaterialBuilder( manager );
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* @param {string} crossOrigin
|
|
300
|
-
* @return {MeshBuilder}
|
|
301
|
-
*/
|
|
302
|
-
setCrossOrigin( crossOrigin ) {
|
|
303
|
-
|
|
304
|
-
this.crossOrigin = crossOrigin;
|
|
305
|
-
return this;
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* @param {Object} data - parsed PMD/PMX data
|
|
311
|
-
* @param {string} resourcePath
|
|
312
|
-
* @param {function} onProgress
|
|
313
|
-
* @param {function} onError
|
|
314
|
-
* @return {SkinnedMesh}
|
|
315
|
-
*/
|
|
316
|
-
build( data, resourcePath, onProgress, onError ) {
|
|
317
|
-
|
|
318
|
-
const geometry = this.geometryBuilder.build( data );
|
|
319
|
-
const material = this.materialBuilder.setCrossOrigin( this.crossOrigin ).setResourcePath( resourcePath ).build( data, geometry, onProgress, onError );
|
|
320
|
-
const mesh = new THREE.SkinnedMesh( geometry, material );
|
|
321
|
-
const skeleton = new THREE.Skeleton( initBones( mesh ) );
|
|
322
|
-
mesh.bind( skeleton );
|
|
323
|
-
|
|
324
|
-
// console.log( mesh ); // for console debug
|
|
325
|
-
|
|
326
|
-
return mesh;
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// TODO: Try to remove this function
|
|
333
|
-
|
|
334
|
-
function initBones( mesh ) {
|
|
335
|
-
|
|
336
|
-
const geometry = mesh.geometry;
|
|
337
|
-
const bones = [];
|
|
338
|
-
if ( geometry && geometry.bones !== undefined ) {
|
|
339
|
-
|
|
340
|
-
// first, create array of 'Bone' objects from geometry data
|
|
341
|
-
|
|
342
|
-
for ( let i = 0, il = geometry.bones.length; i < il; i ++ ) {
|
|
343
|
-
|
|
344
|
-
const gbone = geometry.bones[ i ];
|
|
345
|
-
|
|
346
|
-
// create new 'Bone' object
|
|
347
|
-
|
|
348
|
-
const bone = new THREE.Bone();
|
|
349
|
-
bones.push( bone );
|
|
350
|
-
|
|
351
|
-
// apply values
|
|
352
|
-
|
|
353
|
-
bone.name = gbone.name;
|
|
354
|
-
bone.position.fromArray( gbone.pos );
|
|
355
|
-
bone.quaternion.fromArray( gbone.rotq );
|
|
356
|
-
if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
|
|
357
|
-
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// second, create bone hierarchy
|
|
361
|
-
|
|
362
|
-
for ( let i = 0, il = geometry.bones.length; i < il; i ++ ) {
|
|
363
|
-
|
|
364
|
-
const gbone = geometry.bones[ i ];
|
|
365
|
-
if ( gbone.parent !== - 1 && gbone.parent !== null && bones[ gbone.parent ] !== undefined ) {
|
|
366
|
-
|
|
367
|
-
// subsequent bones in the hierarchy
|
|
368
|
-
|
|
369
|
-
bones[ gbone.parent ].add( bones[ i ] );
|
|
370
|
-
|
|
371
|
-
} else {
|
|
372
|
-
|
|
373
|
-
// topmost bone, immediate child of the skinned mesh
|
|
374
|
-
|
|
375
|
-
mesh.add( bones[ i ] );
|
|
376
|
-
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
// now the bones are part of the scene graph and children of the skinned mesh.
|
|
384
|
-
// let's update the corresponding matrices
|
|
385
|
-
|
|
386
|
-
mesh.updateMatrixWorld( true );
|
|
387
|
-
return bones;
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
//
|
|
392
|
-
|
|
393
|
-
class GeometryBuilder {
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* @param {Object} data - parsed PMD/PMX data
|
|
397
|
-
* @return {BufferGeometry}
|
|
398
|
-
*/
|
|
399
|
-
build( data ) {
|
|
400
|
-
|
|
401
|
-
// for geometry
|
|
402
|
-
const positions = [];
|
|
403
|
-
const uvs = [];
|
|
404
|
-
const normals = [];
|
|
405
|
-
const indices = [];
|
|
406
|
-
const groups = [];
|
|
407
|
-
const bones = [];
|
|
408
|
-
const skinIndices = [];
|
|
409
|
-
const skinWeights = [];
|
|
410
|
-
const morphTargets = [];
|
|
411
|
-
const morphPositions = [];
|
|
412
|
-
const iks = [];
|
|
413
|
-
const grants = [];
|
|
414
|
-
const rigidBodies = [];
|
|
415
|
-
const constraints = [];
|
|
416
|
-
|
|
417
|
-
// for work
|
|
418
|
-
let offset = 0;
|
|
419
|
-
const boneTypeTable = {};
|
|
420
|
-
|
|
421
|
-
// positions, normals, uvs, skinIndices, skinWeights
|
|
422
|
-
|
|
423
|
-
for ( let i = 0; i < data.metadata.vertexCount; i ++ ) {
|
|
424
|
-
|
|
425
|
-
const v = data.vertices[ i ];
|
|
426
|
-
for ( let j = 0, jl = v.position.length; j < jl; j ++ ) {
|
|
427
|
-
|
|
428
|
-
positions.push( v.position[ j ] );
|
|
429
|
-
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
for ( let j = 0, jl = v.normal.length; j < jl; j ++ ) {
|
|
433
|
-
|
|
434
|
-
normals.push( v.normal[ j ] );
|
|
435
|
-
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
for ( let j = 0, jl = v.uv.length; j < jl; j ++ ) {
|
|
439
|
-
|
|
440
|
-
uvs.push( v.uv[ j ] );
|
|
441
|
-
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
for ( let j = 0; j < 4; j ++ ) {
|
|
445
|
-
|
|
446
|
-
skinIndices.push( v.skinIndices.length - 1 >= j ? v.skinIndices[ j ] : 0.0 );
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
for ( let j = 0; j < 4; j ++ ) {
|
|
451
|
-
|
|
452
|
-
skinWeights.push( v.skinWeights.length - 1 >= j ? v.skinWeights[ j ] : 0.0 );
|
|
453
|
-
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
// indices
|
|
459
|
-
|
|
460
|
-
for ( let i = 0; i < data.metadata.faceCount; i ++ ) {
|
|
461
|
-
|
|
462
|
-
const face = data.faces[ i ];
|
|
463
|
-
for ( let j = 0, jl = face.indices.length; j < jl; j ++ ) {
|
|
464
|
-
|
|
465
|
-
indices.push( face.indices[ j ] );
|
|
466
|
-
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
// groups
|
|
472
|
-
|
|
473
|
-
for ( let i = 0; i < data.metadata.materialCount; i ++ ) {
|
|
474
|
-
|
|
475
|
-
const material = data.materials[ i ];
|
|
476
|
-
groups.push( {
|
|
477
|
-
offset: offset * 3,
|
|
478
|
-
count: material.faceCount * 3
|
|
479
|
-
} );
|
|
480
|
-
offset += material.faceCount;
|
|
481
|
-
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
// bones
|
|
485
|
-
|
|
486
|
-
for ( let i = 0; i < data.metadata.rigidBodyCount; i ++ ) {
|
|
487
|
-
|
|
488
|
-
const body = data.rigidBodies[ i ];
|
|
489
|
-
let value = boneTypeTable[ body.boneIndex ];
|
|
490
|
-
|
|
491
|
-
// keeps greater number if already value is set without any special reasons
|
|
492
|
-
value = value === undefined ? body.type : Math.max( body.type, value );
|
|
493
|
-
boneTypeTable[ body.boneIndex ] = value;
|
|
494
|
-
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
for ( let i = 0; i < data.metadata.boneCount; i ++ ) {
|
|
498
|
-
|
|
499
|
-
const boneData = data.bones[ i ];
|
|
500
|
-
const bone = {
|
|
501
|
-
index: i,
|
|
502
|
-
transformationClass: boneData.transformationClass,
|
|
503
|
-
parent: boneData.parentIndex,
|
|
504
|
-
name: boneData.name,
|
|
505
|
-
pos: boneData.position.slice( 0, 3 ),
|
|
506
|
-
rotq: [ 0, 0, 0, 1 ],
|
|
507
|
-
scl: [ 1, 1, 1 ],
|
|
508
|
-
rigidBodyType: boneTypeTable[ i ] !== undefined ? boneTypeTable[ i ] : - 1
|
|
509
|
-
};
|
|
510
|
-
if ( bone.parent !== - 1 ) {
|
|
511
|
-
|
|
512
|
-
bone.pos[ 0 ] -= data.bones[ bone.parent ].position[ 0 ];
|
|
513
|
-
bone.pos[ 1 ] -= data.bones[ bone.parent ].position[ 1 ];
|
|
514
|
-
bone.pos[ 2 ] -= data.bones[ bone.parent ].position[ 2 ];
|
|
515
|
-
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
bones.push( bone );
|
|
519
|
-
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
// iks
|
|
523
|
-
|
|
524
|
-
// TODO: remove duplicated codes between PMD and PMX
|
|
525
|
-
if ( data.metadata.format === 'pmd' ) {
|
|
526
|
-
|
|
527
|
-
for ( let i = 0; i < data.metadata.ikCount; i ++ ) {
|
|
528
|
-
|
|
529
|
-
const ik = data.iks[ i ];
|
|
530
|
-
const param = {
|
|
531
|
-
target: ik.target,
|
|
532
|
-
effector: ik.effector,
|
|
533
|
-
iteration: ik.iteration,
|
|
534
|
-
maxAngle: ik.maxAngle * 4,
|
|
535
|
-
links: []
|
|
536
|
-
};
|
|
537
|
-
for ( let j = 0, jl = ik.links.length; j < jl; j ++ ) {
|
|
538
|
-
|
|
539
|
-
const link = {};
|
|
540
|
-
link.index = ik.links[ j ].index;
|
|
541
|
-
link.enabled = true;
|
|
542
|
-
if ( data.bones[ link.index ].name.indexOf( 'ひざ' ) >= 0 ) {
|
|
543
|
-
|
|
544
|
-
link.limitation = new THREE.Vector3( 1.0, 0.0, 0.0 );
|
|
545
|
-
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
param.links.push( link );
|
|
549
|
-
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
iks.push( param );
|
|
553
|
-
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
} else {
|
|
557
|
-
|
|
558
|
-
for ( let i = 0; i < data.metadata.boneCount; i ++ ) {
|
|
559
|
-
|
|
560
|
-
const ik = data.bones[ i ].ik;
|
|
561
|
-
if ( ik === undefined ) continue;
|
|
562
|
-
const param = {
|
|
563
|
-
target: i,
|
|
564
|
-
effector: ik.effector,
|
|
565
|
-
iteration: ik.iteration,
|
|
566
|
-
maxAngle: ik.maxAngle,
|
|
567
|
-
links: []
|
|
568
|
-
};
|
|
569
|
-
for ( let j = 0, jl = ik.links.length; j < jl; j ++ ) {
|
|
570
|
-
|
|
571
|
-
const link = {};
|
|
572
|
-
link.index = ik.links[ j ].index;
|
|
573
|
-
link.enabled = true;
|
|
574
|
-
if ( ik.links[ j ].angleLimitation === 1 ) {
|
|
575
|
-
|
|
576
|
-
// Revert if rotationMin/Max doesn't work well
|
|
577
|
-
// link.limitation = new THREE.Vector3( 1.0, 0.0, 0.0 );
|
|
578
|
-
|
|
579
|
-
const rotationMin = ik.links[ j ].lowerLimitationAngle;
|
|
580
|
-
const rotationMax = ik.links[ j ].upperLimitationAngle;
|
|
581
|
-
|
|
582
|
-
// Convert Left to Right coordinate by myself because
|
|
583
|
-
// MMDParser doesn't convert. It's a MMDParser's bug
|
|
584
|
-
|
|
585
|
-
const tmp1 = - rotationMax[ 0 ];
|
|
586
|
-
const tmp2 = - rotationMax[ 1 ];
|
|
587
|
-
rotationMax[ 0 ] = - rotationMin[ 0 ];
|
|
588
|
-
rotationMax[ 1 ] = - rotationMin[ 1 ];
|
|
589
|
-
rotationMin[ 0 ] = tmp1;
|
|
590
|
-
rotationMin[ 1 ] = tmp2;
|
|
591
|
-
link.rotationMin = new THREE.Vector3().fromArray( rotationMin );
|
|
592
|
-
link.rotationMax = new THREE.Vector3().fromArray( rotationMax );
|
|
593
|
-
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
param.links.push( link );
|
|
597
|
-
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
iks.push( param );
|
|
601
|
-
|
|
602
|
-
// Save the reference even from bone data for efficiently
|
|
603
|
-
// simulating PMX animation system
|
|
604
|
-
bones[ i ].ik = param;
|
|
605
|
-
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
// grants
|
|
611
|
-
|
|
612
|
-
if ( data.metadata.format === 'pmx' ) {
|
|
613
|
-
|
|
614
|
-
// bone index -> grant entry map
|
|
615
|
-
const grantEntryMap = {};
|
|
616
|
-
for ( let i = 0; i < data.metadata.boneCount; i ++ ) {
|
|
617
|
-
|
|
618
|
-
const boneData = data.bones[ i ];
|
|
619
|
-
const grant = boneData.grant;
|
|
620
|
-
if ( grant === undefined ) continue;
|
|
621
|
-
const param = {
|
|
622
|
-
index: i,
|
|
623
|
-
parentIndex: grant.parentIndex,
|
|
624
|
-
ratio: grant.ratio,
|
|
625
|
-
isLocal: grant.isLocal,
|
|
626
|
-
affectRotation: grant.affectRotation,
|
|
627
|
-
affectPosition: grant.affectPosition,
|
|
628
|
-
transformationClass: boneData.transformationClass
|
|
629
|
-
};
|
|
630
|
-
grantEntryMap[ i ] = {
|
|
631
|
-
parent: null,
|
|
632
|
-
children: [],
|
|
633
|
-
param: param,
|
|
634
|
-
visited: false
|
|
635
|
-
};
|
|
636
|
-
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
const rootEntry = {
|
|
640
|
-
parent: null,
|
|
641
|
-
children: [],
|
|
642
|
-
param: null,
|
|
643
|
-
visited: false
|
|
644
|
-
};
|
|
645
|
-
|
|
646
|
-
// Build a tree representing grant hierarchy
|
|
647
|
-
|
|
648
|
-
for ( const boneIndex in grantEntryMap ) {
|
|
649
|
-
|
|
650
|
-
const grantEntry = grantEntryMap[ boneIndex ];
|
|
651
|
-
const parentGrantEntry = grantEntryMap[ grantEntry.parentIndex ] || rootEntry;
|
|
652
|
-
grantEntry.parent = parentGrantEntry;
|
|
653
|
-
parentGrantEntry.children.push( grantEntry );
|
|
654
|
-
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
// Sort grant parameters from parents to children because
|
|
658
|
-
// grant uses parent's transform that parent's grant is already applied
|
|
659
|
-
// so grant should be applied in order from parents to children
|
|
660
|
-
|
|
661
|
-
function traverse( entry ) {
|
|
662
|
-
|
|
663
|
-
if ( entry.param ) {
|
|
664
|
-
|
|
665
|
-
grants.push( entry.param );
|
|
666
|
-
|
|
667
|
-
// Save the reference even from bone data for efficiently
|
|
668
|
-
// simulating PMX animation system
|
|
669
|
-
bones[ entry.param.index ].grant = entry.param;
|
|
670
|
-
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
entry.visited = true;
|
|
674
|
-
for ( let i = 0, il = entry.children.length; i < il; i ++ ) {
|
|
675
|
-
|
|
676
|
-
const child = entry.children[ i ];
|
|
677
|
-
|
|
678
|
-
// Cut off a loop if exists. (Is a grant loop invalid?)
|
|
679
|
-
if ( ! child.visited ) traverse( child );
|
|
680
|
-
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
traverse( rootEntry );
|
|
686
|
-
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
// morph
|
|
690
|
-
|
|
691
|
-
function updateAttributes( attribute, morph, ratio ) {
|
|
692
|
-
|
|
693
|
-
for ( let i = 0; i < morph.elementCount; i ++ ) {
|
|
694
|
-
|
|
695
|
-
const element = morph.elements[ i ];
|
|
696
|
-
let index;
|
|
697
|
-
if ( data.metadata.format === 'pmd' ) {
|
|
698
|
-
|
|
699
|
-
index = data.morphs[ 0 ].elements[ element.index ].index;
|
|
700
|
-
|
|
701
|
-
} else {
|
|
702
|
-
|
|
703
|
-
index = element.index;
|
|
704
|
-
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
attribute.array[ index * 3 + 0 ] += element.position[ 0 ] * ratio;
|
|
708
|
-
attribute.array[ index * 3 + 1 ] += element.position[ 1 ] * ratio;
|
|
709
|
-
attribute.array[ index * 3 + 2 ] += element.position[ 2 ] * ratio;
|
|
710
|
-
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
for ( let i = 0; i < data.metadata.morphCount; i ++ ) {
|
|
716
|
-
|
|
717
|
-
const morph = data.morphs[ i ];
|
|
718
|
-
const params = {
|
|
719
|
-
name: morph.name
|
|
720
|
-
};
|
|
721
|
-
const attribute = new THREE.Float32BufferAttribute( data.metadata.vertexCount * 3, 3 );
|
|
722
|
-
attribute.name = morph.name;
|
|
723
|
-
for ( let j = 0; j < data.metadata.vertexCount * 3; j ++ ) {
|
|
724
|
-
|
|
725
|
-
attribute.array[ j ] = positions[ j ];
|
|
726
|
-
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
if ( data.metadata.format === 'pmd' ) {
|
|
730
|
-
|
|
731
|
-
if ( i !== 0 ) {
|
|
732
|
-
|
|
733
|
-
updateAttributes( attribute, morph, 1.0 );
|
|
734
|
-
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
} else {
|
|
738
|
-
|
|
739
|
-
if ( morph.type === 0 ) {
|
|
740
|
-
|
|
741
|
-
// group
|
|
742
|
-
|
|
743
|
-
for ( let j = 0; j < morph.elementCount; j ++ ) {
|
|
744
|
-
|
|
745
|
-
const morph2 = data.morphs[ morph.elements[ j ].index ];
|
|
746
|
-
const ratio = morph.elements[ j ].ratio;
|
|
747
|
-
if ( morph2.type === 1 ) {
|
|
748
|
-
|
|
749
|
-
updateAttributes( attribute, morph2, ratio );
|
|
750
|
-
|
|
751
|
-
} else {
|
|
752
|
-
|
|
753
|
-
// TODO: implement
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
} else if ( morph.type === 1 ) {
|
|
759
|
-
|
|
760
|
-
// vertex
|
|
761
|
-
|
|
762
|
-
updateAttributes( attribute, morph, 1.0 );
|
|
763
|
-
|
|
764
|
-
} else if ( morph.type === 2 ) { // bone
|
|
765
|
-
|
|
766
|
-
// TODO: implement
|
|
767
|
-
} else if ( morph.type === 3 ) { // uv
|
|
768
|
-
|
|
769
|
-
// TODO: implement
|
|
770
|
-
} else if ( morph.type === 4 ) { // additional uv1
|
|
771
|
-
|
|
772
|
-
// TODO: implement
|
|
773
|
-
} else if ( morph.type === 5 ) { // additional uv2
|
|
774
|
-
|
|
775
|
-
// TODO: implement
|
|
776
|
-
} else if ( morph.type === 6 ) { // additional uv3
|
|
777
|
-
|
|
778
|
-
// TODO: implement
|
|
779
|
-
} else if ( morph.type === 7 ) { // additional uv4
|
|
780
|
-
|
|
781
|
-
// TODO: implement
|
|
782
|
-
} else if ( morph.type === 8 ) { // material
|
|
783
|
-
|
|
784
|
-
// TODO: implement
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
morphTargets.push( params );
|
|
790
|
-
morphPositions.push( attribute );
|
|
791
|
-
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
// rigid bodies from rigidBodies field.
|
|
795
|
-
|
|
796
|
-
for ( let i = 0; i < data.metadata.rigidBodyCount; i ++ ) {
|
|
797
|
-
|
|
798
|
-
const rigidBody = data.rigidBodies[ i ];
|
|
799
|
-
const params = {};
|
|
800
|
-
for ( const key in rigidBody ) {
|
|
801
|
-
|
|
802
|
-
params[ key ] = rigidBody[ key ];
|
|
803
|
-
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
/*
|
|
807
|
-
* RigidBody position parameter in PMX seems global position
|
|
808
|
-
* while the one in PMD seems offset from corresponding bone.
|
|
809
|
-
* So unify being offset.
|
|
810
|
-
*/
|
|
811
|
-
if ( data.metadata.format === 'pmx' ) {
|
|
812
|
-
|
|
813
|
-
if ( params.boneIndex !== - 1 ) {
|
|
814
|
-
|
|
815
|
-
const bone = data.bones[ params.boneIndex ];
|
|
816
|
-
params.position[ 0 ] -= bone.position[ 0 ];
|
|
817
|
-
params.position[ 1 ] -= bone.position[ 1 ];
|
|
818
|
-
params.position[ 2 ] -= bone.position[ 2 ];
|
|
819
|
-
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
rigidBodies.push( params );
|
|
825
|
-
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
// constraints from constraints field.
|
|
829
|
-
|
|
830
|
-
for ( let i = 0; i < data.metadata.constraintCount; i ++ ) {
|
|
831
|
-
|
|
832
|
-
const constraint = data.constraints[ i ];
|
|
833
|
-
const params = {};
|
|
834
|
-
for ( const key in constraint ) {
|
|
835
|
-
|
|
836
|
-
params[ key ] = constraint[ key ];
|
|
837
|
-
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
const bodyA = rigidBodies[ params.rigidBodyIndex1 ];
|
|
841
|
-
const bodyB = rigidBodies[ params.rigidBodyIndex2 ];
|
|
842
|
-
|
|
843
|
-
// Refer to http://www20.atpages.jp/katwat/wp/?p=4135
|
|
844
|
-
if ( bodyA.type !== 0 && bodyB.type === 2 ) {
|
|
845
|
-
|
|
846
|
-
if ( bodyA.boneIndex !== - 1 && bodyB.boneIndex !== - 1 && data.bones[ bodyB.boneIndex ].parentIndex === bodyA.boneIndex ) {
|
|
847
|
-
|
|
848
|
-
bodyB.type = 1;
|
|
849
|
-
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
constraints.push( params );
|
|
855
|
-
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
// build THREE.BufferGeometry.
|
|
859
|
-
|
|
860
|
-
const geometry = new THREE.BufferGeometry();
|
|
861
|
-
geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( positions, 3 ) );
|
|
862
|
-
geometry.setAttribute( 'normal', new THREE.Float32BufferAttribute( normals, 3 ) );
|
|
863
|
-
geometry.setAttribute( 'uv', new THREE.Float32BufferAttribute( uvs, 2 ) );
|
|
864
|
-
geometry.setAttribute( 'skinIndex', new THREE.Uint16BufferAttribute( skinIndices, 4 ) );
|
|
865
|
-
geometry.setAttribute( 'skinWeight', new THREE.Float32BufferAttribute( skinWeights, 4 ) );
|
|
866
|
-
geometry.setIndex( indices );
|
|
867
|
-
for ( let i = 0, il = groups.length; i < il; i ++ ) {
|
|
868
|
-
|
|
869
|
-
geometry.addGroup( groups[ i ].offset, groups[ i ].count, i );
|
|
870
|
-
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
geometry.bones = bones;
|
|
874
|
-
geometry.morphTargets = morphTargets;
|
|
875
|
-
geometry.morphAttributes.position = morphPositions;
|
|
876
|
-
geometry.morphTargetsRelative = false;
|
|
877
|
-
geometry.userData.MMD = {
|
|
878
|
-
bones: bones,
|
|
879
|
-
iks: iks,
|
|
880
|
-
grants: grants,
|
|
881
|
-
rigidBodies: rigidBodies,
|
|
882
|
-
constraints: constraints,
|
|
883
|
-
format: data.metadata.format
|
|
884
|
-
};
|
|
885
|
-
geometry.computeBoundingSphere();
|
|
886
|
-
return geometry;
|
|
887
|
-
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
//
|
|
893
|
-
|
|
894
|
-
/**
|
|
895
|
-
* @param {THREE.LoadingManager} manager
|
|
896
|
-
*/
|
|
897
|
-
class MaterialBuilder {
|
|
898
|
-
|
|
899
|
-
constructor( manager ) {
|
|
900
|
-
|
|
901
|
-
this.manager = manager;
|
|
902
|
-
this.textureLoader = new THREE.TextureLoader( this.manager );
|
|
903
|
-
this.tgaLoader = null; // lazy generation
|
|
904
|
-
|
|
905
|
-
this.crossOrigin = 'anonymous';
|
|
906
|
-
this.resourcePath = undefined;
|
|
907
|
-
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
/**
|
|
911
|
-
* @param {string} crossOrigin
|
|
912
|
-
* @return {MaterialBuilder}
|
|
913
|
-
*/
|
|
914
|
-
setCrossOrigin( crossOrigin ) {
|
|
915
|
-
|
|
916
|
-
this.crossOrigin = crossOrigin;
|
|
917
|
-
return this;
|
|
918
|
-
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
/**
|
|
922
|
-
* @param {string} resourcePath
|
|
923
|
-
* @return {MaterialBuilder}
|
|
924
|
-
*/
|
|
925
|
-
setResourcePath( resourcePath ) {
|
|
926
|
-
|
|
927
|
-
this.resourcePath = resourcePath;
|
|
928
|
-
return this;
|
|
929
|
-
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
/**
|
|
933
|
-
* @param {Object} data - parsed PMD/PMX data
|
|
934
|
-
* @param {BufferGeometry} geometry - some properties are dependend on geometry
|
|
935
|
-
* @param {function} onProgress
|
|
936
|
-
* @param {function} onError
|
|
937
|
-
* @return {Array<MMDToonMaterial>}
|
|
938
|
-
*/
|
|
939
|
-
build( data, geometry /*, onProgress, onError */ ) {
|
|
940
|
-
|
|
941
|
-
const materials = [];
|
|
942
|
-
const textures = {};
|
|
943
|
-
this.textureLoader.setCrossOrigin( this.crossOrigin );
|
|
944
|
-
|
|
945
|
-
// materials
|
|
946
|
-
|
|
947
|
-
for ( let i = 0; i < data.metadata.materialCount; i ++ ) {
|
|
948
|
-
|
|
949
|
-
const material = data.materials[ i ];
|
|
950
|
-
const params = {
|
|
951
|
-
userData: {
|
|
952
|
-
MMD: {}
|
|
953
|
-
}
|
|
954
|
-
};
|
|
955
|
-
if ( material.name !== undefined ) params.name = material.name;
|
|
956
|
-
|
|
957
|
-
/*
|
|
958
|
-
* THREE.Color
|
|
959
|
-
*
|
|
960
|
-
* MMD MMDToonMaterial
|
|
961
|
-
* ambient - emissive * a
|
|
962
|
-
* (a = 1.0 without map texture or 0.2 with map texture)
|
|
963
|
-
*
|
|
964
|
-
* MMDToonMaterial doesn't have ambient. Set it to emissive instead.
|
|
965
|
-
* It'll be too bright if material has map texture so using coef 0.2.
|
|
966
|
-
*/
|
|
967
|
-
params.diffuse = new THREE.Color().fromArray( material.diffuse );
|
|
968
|
-
params.opacity = material.diffuse[ 3 ];
|
|
969
|
-
params.specular = new THREE.Color().fromArray( material.specular );
|
|
970
|
-
params.shininess = material.shininess;
|
|
971
|
-
params.emissive = new THREE.Color().fromArray( material.ambient );
|
|
972
|
-
params.transparent = params.opacity !== 1.0;
|
|
973
|
-
|
|
974
|
-
//
|
|
975
|
-
|
|
976
|
-
params.fog = true;
|
|
977
|
-
|
|
978
|
-
// blend
|
|
979
|
-
|
|
980
|
-
params.blending = THREE.CustomBlending;
|
|
981
|
-
params.blendSrc = THREE.SrcAlphaFactor;
|
|
982
|
-
params.blendDst = THREE.OneMinusSrcAlphaFactor;
|
|
983
|
-
params.blendSrcAlpha = THREE.SrcAlphaFactor;
|
|
984
|
-
params.blendDstAlpha = THREE.DstAlphaFactor;
|
|
985
|
-
|
|
986
|
-
// side
|
|
987
|
-
|
|
988
|
-
if ( data.metadata.format === 'pmx' && ( material.flag & 0x1 ) === 1 ) {
|
|
989
|
-
|
|
990
|
-
params.side = THREE.DoubleSide;
|
|
991
|
-
|
|
992
|
-
} else {
|
|
993
|
-
|
|
994
|
-
params.side = params.opacity === 1.0 ? THREE.FrontSide : THREE.DoubleSide;
|
|
995
|
-
|
|
996
|
-
}
|
|
997
|
-
|
|
998
|
-
if ( data.metadata.format === 'pmd' ) {
|
|
999
|
-
|
|
1000
|
-
// map, envMap
|
|
1001
|
-
|
|
1002
|
-
if ( material.fileName ) {
|
|
1003
|
-
|
|
1004
|
-
const fileName = material.fileName;
|
|
1005
|
-
const fileNames = fileName.split( '*' );
|
|
1006
|
-
|
|
1007
|
-
// fileNames[ 0 ]: mapFileName
|
|
1008
|
-
// fileNames[ 1 ]: envMapFileName( optional )
|
|
1009
|
-
|
|
1010
|
-
params.map = this._loadTexture( fileNames[ 0 ], textures );
|
|
1011
|
-
if ( fileNames.length > 1 ) {
|
|
1012
|
-
|
|
1013
|
-
const extension = fileNames[ 1 ].slice( - 4 ).toLowerCase();
|
|
1014
|
-
params.envMap = this._loadTexture( fileNames[ 1 ], textures );
|
|
1015
|
-
params.combine = extension === '.sph' ? THREE.MultiplyOperation : THREE.AddOperation;
|
|
1016
|
-
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
// gradientMap
|
|
1022
|
-
|
|
1023
|
-
const toonFileName = material.toonIndex === - 1 ? 'toon00.bmp' : data.toonTextures[ material.toonIndex ].fileName;
|
|
1024
|
-
params.gradientMap = this._loadTexture( toonFileName, textures, {
|
|
1025
|
-
isToonTexture: true,
|
|
1026
|
-
isDefaultToonTexture: this._isDefaultToonTexture( toonFileName )
|
|
1027
|
-
} );
|
|
1028
|
-
|
|
1029
|
-
// parameters for OutlineEffect
|
|
1030
|
-
|
|
1031
|
-
params.userData.outlineParameters = {
|
|
1032
|
-
thickness: material.edgeFlag === 1 ? 0.003 : 0.0,
|
|
1033
|
-
color: [ 0, 0, 0 ],
|
|
1034
|
-
alpha: 1.0,
|
|
1035
|
-
visible: material.edgeFlag === 1
|
|
1036
|
-
};
|
|
1037
|
-
|
|
1038
|
-
} else {
|
|
1039
|
-
|
|
1040
|
-
// map
|
|
1041
|
-
|
|
1042
|
-
if ( material.textureIndex !== - 1 ) {
|
|
1043
|
-
|
|
1044
|
-
params.map = this._loadTexture( data.textures[ material.textureIndex ], textures );
|
|
1045
|
-
|
|
1046
|
-
// Since PMX spec don't have standard to list map files except color map and env map,
|
|
1047
|
-
// we need to save file name for further mapping, like matching normal map file names after model loaded.
|
|
1048
|
-
// ref: https://gist.github.com/felixjones/f8a06bd48f9da9a4539f#texture
|
|
1049
|
-
params.userData.MMD.mapFileName = data.textures[ material.textureIndex ];
|
|
1050
|
-
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
// envMap TODO: support m.envFlag === 3
|
|
1054
|
-
|
|
1055
|
-
if ( material.envTextureIndex !== - 1 && ( material.envFlag === 1 || material.envFlag == 2 ) ) {
|
|
1056
|
-
|
|
1057
|
-
params.matcap = this._loadTexture( data.textures[ material.envTextureIndex ], textures );
|
|
1058
|
-
|
|
1059
|
-
// Same as color map above, keep file name in userData for further usage.
|
|
1060
|
-
params.userData.MMD.matcapFileName = data.textures[ material.envTextureIndex ];
|
|
1061
|
-
params.matcapCombine = material.envFlag === 1 ? THREE.MultiplyOperation : THREE.AddOperation;
|
|
1062
|
-
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
// gradientMap
|
|
1066
|
-
|
|
1067
|
-
let toonFileName, isDefaultToon;
|
|
1068
|
-
if ( material.toonIndex === - 1 || material.toonFlag !== 0 ) {
|
|
1069
|
-
|
|
1070
|
-
toonFileName = 'toon' + ( '0' + ( material.toonIndex + 1 ) ).slice( - 2 ) + '.bmp';
|
|
1071
|
-
isDefaultToon = true;
|
|
1072
|
-
|
|
1073
|
-
} else {
|
|
1074
|
-
|
|
1075
|
-
toonFileName = data.textures[ material.toonIndex ];
|
|
1076
|
-
isDefaultToon = false;
|
|
1077
|
-
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
params.gradientMap = this._loadTexture( toonFileName, textures, {
|
|
1081
|
-
isToonTexture: true,
|
|
1082
|
-
isDefaultToonTexture: isDefaultToon
|
|
1083
|
-
} );
|
|
1084
|
-
|
|
1085
|
-
// parameters for OutlineEffect
|
|
1086
|
-
params.userData.outlineParameters = {
|
|
1087
|
-
thickness: material.edgeSize / 300,
|
|
1088
|
-
// TODO: better calculation?
|
|
1089
|
-
color: material.edgeColor.slice( 0, 3 ),
|
|
1090
|
-
alpha: material.edgeColor[ 3 ],
|
|
1091
|
-
visible: ( material.flag & 0x10 ) !== 0 && material.edgeSize > 0.0
|
|
1092
|
-
};
|
|
1093
|
-
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
if ( params.map !== undefined ) {
|
|
1097
|
-
|
|
1098
|
-
if ( ! params.transparent ) {
|
|
1099
|
-
|
|
1100
|
-
this._checkImageTransparency( params.map, geometry, i );
|
|
1101
|
-
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
params.emissive.multiplyScalar( 0.2 );
|
|
1105
|
-
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
materials.push( new MMDToonMaterial( params ) );
|
|
1109
|
-
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
if ( data.metadata.format === 'pmx' ) {
|
|
1113
|
-
|
|
1114
|
-
// set transparent true if alpha morph is defined.
|
|
1115
|
-
|
|
1116
|
-
function checkAlphaMorph( elements, materials ) {
|
|
1117
|
-
|
|
1118
|
-
for ( let i = 0, il = elements.length; i < il; i ++ ) {
|
|
1119
|
-
|
|
1120
|
-
const element = elements[ i ];
|
|
1121
|
-
if ( element.index === - 1 ) continue;
|
|
1122
|
-
const material = materials[ element.index ];
|
|
1123
|
-
if ( material.opacity !== element.diffuse[ 3 ] ) {
|
|
1124
|
-
|
|
1125
|
-
material.transparent = true;
|
|
1126
|
-
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
for ( let i = 0, il = data.morphs.length; i < il; i ++ ) {
|
|
1134
|
-
|
|
1135
|
-
const morph = data.morphs[ i ];
|
|
1136
|
-
const elements = morph.elements;
|
|
1137
|
-
if ( morph.type === 0 ) {
|
|
1138
|
-
|
|
1139
|
-
for ( let j = 0, jl = elements.length; j < jl; j ++ ) {
|
|
1140
|
-
|
|
1141
|
-
const morph2 = data.morphs[ elements[ j ].index ];
|
|
1142
|
-
if ( morph2.type !== 8 ) continue;
|
|
1143
|
-
checkAlphaMorph( morph2.elements, materials );
|
|
1144
|
-
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
} else if ( morph.type === 8 ) {
|
|
1148
|
-
|
|
1149
|
-
checkAlphaMorph( elements, materials );
|
|
1150
|
-
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
return materials;
|
|
1158
|
-
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
// private methods
|
|
1162
|
-
|
|
1163
|
-
_getTGALoader() {
|
|
1164
|
-
|
|
1165
|
-
if ( this.tgaLoader === null ) {
|
|
1166
|
-
|
|
1167
|
-
if ( THREE.TGALoader === undefined ) {
|
|
1168
|
-
|
|
1169
|
-
throw new Error( 'THREE.MMDLoader: Import THREE.TGALoader' );
|
|
1170
|
-
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
this.tgaLoader = new THREE.TGALoader( this.manager );
|
|
1174
|
-
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
return this.tgaLoader;
|
|
1178
|
-
|
|
1179
|
-
}
|
|
1180
|
-
_isDefaultToonTexture( name ) {
|
|
1181
|
-
|
|
1182
|
-
if ( name.length !== 10 ) return false;
|
|
1183
|
-
return /toon(10|0[0-9])\.bmp/.test( name );
|
|
1184
|
-
|
|
1185
|
-
}
|
|
1186
|
-
_loadTexture( filePath, textures, params, onProgress, onError ) {
|
|
1187
|
-
|
|
1188
|
-
params = params || {};
|
|
1189
|
-
const scope = this;
|
|
1190
|
-
let fullPath;
|
|
1191
|
-
if ( params.isDefaultToonTexture === true ) {
|
|
1192
|
-
|
|
1193
|
-
let index;
|
|
1194
|
-
try {
|
|
1195
|
-
|
|
1196
|
-
index = parseInt( filePath.match( /toon([0-9]{2})\.bmp$/ )[ 1 ] );
|
|
1197
|
-
|
|
1198
|
-
} catch ( e ) {
|
|
1199
|
-
|
|
1200
|
-
console.warn( 'THREE.MMDLoader: ' + filePath + ' seems like a ' + 'not right default texture path. Using toon00.bmp instead.' );
|
|
1201
|
-
index = 0;
|
|
1202
|
-
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
fullPath = DEFAULT_TOON_TEXTURES[ index ];
|
|
1206
|
-
|
|
1207
|
-
} else {
|
|
1208
|
-
|
|
1209
|
-
fullPath = this.resourcePath + filePath;
|
|
1210
|
-
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
if ( textures[ fullPath ] !== undefined ) return textures[ fullPath ];
|
|
1214
|
-
let loader = this.manager.getHandler( fullPath );
|
|
1215
|
-
if ( loader === null ) {
|
|
1216
|
-
|
|
1217
|
-
loader = filePath.slice( - 4 ).toLowerCase() === '.tga' ? this._getTGALoader() : this.textureLoader;
|
|
1218
|
-
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
const texture = loader.load( fullPath, function ( t ) {
|
|
1222
|
-
|
|
1223
|
-
// MMD toon texture is Axis-Y oriented
|
|
1224
|
-
// but Three.js gradient map is Axis-X oriented.
|
|
1225
|
-
// So here replaces the toon texture image with the rotated one.
|
|
1226
|
-
if ( params.isToonTexture === true ) {
|
|
1227
|
-
|
|
1228
|
-
t.image = scope._getRotatedImage( t.image );
|
|
1229
|
-
t.magFilter = THREE.NearestFilter;
|
|
1230
|
-
t.minFilter = THREE.NearestFilter;
|
|
1231
|
-
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
t.flipY = false;
|
|
1235
|
-
t.wrapS = THREE.RepeatWrapping;
|
|
1236
|
-
t.wrapT = THREE.RepeatWrapping;
|
|
1237
|
-
for ( let i = 0; i < texture.readyCallbacks.length; i ++ ) {
|
|
1238
|
-
|
|
1239
|
-
texture.readyCallbacks[ i ]( texture );
|
|
1240
|
-
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
delete texture.readyCallbacks;
|
|
1244
|
-
|
|
1245
|
-
}, onProgress, onError );
|
|
1246
|
-
texture.readyCallbacks = [];
|
|
1247
|
-
textures[ fullPath ] = texture;
|
|
1248
|
-
return texture;
|
|
1249
|
-
|
|
1250
|
-
}
|
|
1251
|
-
_getRotatedImage( image ) {
|
|
1252
|
-
|
|
1253
|
-
const canvas = document.createElement( 'canvas' );
|
|
1254
|
-
const context = canvas.getContext( '2d' );
|
|
1255
|
-
const width = image.width;
|
|
1256
|
-
const height = image.height;
|
|
1257
|
-
canvas.width = width;
|
|
1258
|
-
canvas.height = height;
|
|
1259
|
-
context.clearRect( 0, 0, width, height );
|
|
1260
|
-
context.translate( width / 2.0, height / 2.0 );
|
|
1261
|
-
context.rotate( 0.5 * Math.PI ); // 90.0 * Math.PI / 180.0
|
|
1262
|
-
context.translate( - width / 2.0, - height / 2.0 );
|
|
1263
|
-
context.drawImage( image, 0, 0 );
|
|
1264
|
-
return context.getImageData( 0, 0, width, height );
|
|
1265
|
-
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
// Check if the partial image area used by the texture is transparent.
|
|
1269
|
-
_checkImageTransparency( map, geometry, groupIndex ) {
|
|
1270
|
-
|
|
1271
|
-
map.readyCallbacks.push( function ( texture ) {
|
|
1272
|
-
|
|
1273
|
-
// Is there any efficient ways?
|
|
1274
|
-
function createImageData( image ) {
|
|
1275
|
-
|
|
1276
|
-
const canvas = document.createElement( 'canvas' );
|
|
1277
|
-
canvas.width = image.width;
|
|
1278
|
-
canvas.height = image.height;
|
|
1279
|
-
const context = canvas.getContext( '2d' );
|
|
1280
|
-
context.drawImage( image, 0, 0 );
|
|
1281
|
-
return context.getImageData( 0, 0, canvas.width, canvas.height );
|
|
1282
|
-
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
|
-
function detectImageTransparency( image, uvs, indices ) {
|
|
1286
|
-
|
|
1287
|
-
const width = image.width;
|
|
1288
|
-
const height = image.height;
|
|
1289
|
-
const data = image.data;
|
|
1290
|
-
const threshold = 253;
|
|
1291
|
-
if ( data.length / ( width * height ) !== 4 ) return false;
|
|
1292
|
-
for ( let i = 0; i < indices.length; i += 3 ) {
|
|
1293
|
-
|
|
1294
|
-
const centerUV = {
|
|
1295
|
-
x: 0.0,
|
|
1296
|
-
y: 0.0
|
|
1297
|
-
};
|
|
1298
|
-
for ( let j = 0; j < 3; j ++ ) {
|
|
1299
|
-
|
|
1300
|
-
const index = indices[ i * 3 + j ];
|
|
1301
|
-
const uv = {
|
|
1302
|
-
x: uvs[ index * 2 + 0 ],
|
|
1303
|
-
y: uvs[ index * 2 + 1 ]
|
|
1304
|
-
};
|
|
1305
|
-
if ( getAlphaByUv( image, uv ) < threshold ) return true;
|
|
1306
|
-
centerUV.x += uv.x;
|
|
1307
|
-
centerUV.y += uv.y;
|
|
1308
|
-
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
centerUV.x /= 3;
|
|
1312
|
-
centerUV.y /= 3;
|
|
1313
|
-
if ( getAlphaByUv( image, centerUV ) < threshold ) return true;
|
|
1314
|
-
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
return false;
|
|
1318
|
-
|
|
1319
|
-
}
|
|
1320
|
-
|
|
1321
|
-
/*
|
|
1322
|
-
* This method expects
|
|
1323
|
-
* texture.flipY = false
|
|
1324
|
-
* texture.wrapS = THREE.RepeatWrapping
|
|
1325
|
-
* texture.wrapT = THREE.RepeatWrapping
|
|
1326
|
-
* TODO: more precise
|
|
1327
|
-
*/
|
|
1328
|
-
function getAlphaByUv( image, uv ) {
|
|
1329
|
-
|
|
1330
|
-
const width = image.width;
|
|
1331
|
-
const height = image.height;
|
|
1332
|
-
let x = Math.round( uv.x * width ) % width;
|
|
1333
|
-
let y = Math.round( uv.y * height ) % height;
|
|
1334
|
-
if ( x < 0 ) x += width;
|
|
1335
|
-
if ( y < 0 ) y += height;
|
|
1336
|
-
const index = y * width + x;
|
|
1337
|
-
return image.data[ index * 4 + 3 ];
|
|
1338
|
-
|
|
1339
|
-
}
|
|
1340
|
-
|
|
1341
|
-
if ( texture.isCompressedTexture === true ) {
|
|
1342
|
-
|
|
1343
|
-
if ( NON_ALPHA_CHANNEL_FORMATS.includes( texture.format ) ) {
|
|
1344
|
-
|
|
1345
|
-
map.transparent = false;
|
|
1346
|
-
|
|
1347
|
-
} else {
|
|
1348
|
-
|
|
1349
|
-
// any other way to check transparency of CompressedTexture?
|
|
1350
|
-
map.transparent = true;
|
|
1351
|
-
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
return;
|
|
1355
|
-
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
const imageData = texture.image.data !== undefined ? texture.image : createImageData( texture.image );
|
|
1359
|
-
const group = geometry.groups[ groupIndex ];
|
|
1360
|
-
if ( detectImageTransparency( imageData, geometry.attributes.uv.array, geometry.index.array.slice( group.start, group.start + group.count ) ) ) {
|
|
1361
|
-
|
|
1362
|
-
map.transparent = true;
|
|
1363
|
-
|
|
1364
|
-
}
|
|
1365
|
-
|
|
1366
|
-
} );
|
|
1367
|
-
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
//
|
|
1373
|
-
|
|
1374
|
-
class AnimationBuilder {
|
|
1375
|
-
|
|
1376
|
-
/**
|
|
1377
|
-
* @param {Object} vmd - parsed VMD data
|
|
1378
|
-
* @param {SkinnedMesh} mesh - tracks will be fitting to mesh
|
|
1379
|
-
* @return {AnimationClip}
|
|
1380
|
-
*/
|
|
1381
|
-
build( vmd, mesh ) {
|
|
1382
|
-
|
|
1383
|
-
// combine skeletal and morph animations
|
|
1384
|
-
|
|
1385
|
-
const tracks = this.buildSkeletalAnimation( vmd, mesh ).tracks;
|
|
1386
|
-
const tracks2 = this.buildMorphAnimation( vmd, mesh ).tracks;
|
|
1387
|
-
for ( let i = 0, il = tracks2.length; i < il; i ++ ) {
|
|
1388
|
-
|
|
1389
|
-
tracks.push( tracks2[ i ] );
|
|
1390
|
-
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
return new THREE.AnimationClip( '', - 1, tracks );
|
|
1394
|
-
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
/**
|
|
1398
|
-
* @param {Object} vmd - parsed VMD data
|
|
1399
|
-
* @param {SkinnedMesh} mesh - tracks will be fitting to mesh
|
|
1400
|
-
* @return {AnimationClip}
|
|
1401
|
-
*/
|
|
1402
|
-
buildSkeletalAnimation( vmd, mesh ) {
|
|
1403
|
-
|
|
1404
|
-
function pushInterpolation( array, interpolation, index ) {
|
|
1405
|
-
|
|
1406
|
-
array.push( interpolation[ index + 0 ] / 127 ); // x1
|
|
1407
|
-
array.push( interpolation[ index + 8 ] / 127 ); // x2
|
|
1408
|
-
array.push( interpolation[ index + 4 ] / 127 ); // y1
|
|
1409
|
-
array.push( interpolation[ index + 12 ] / 127 ); // y2
|
|
1410
|
-
|
|
1411
|
-
}
|
|
1412
|
-
|
|
1413
|
-
const tracks = [];
|
|
1414
|
-
const motions = {};
|
|
1415
|
-
const bones = mesh.skeleton.bones;
|
|
1416
|
-
const boneNameDictionary = {};
|
|
1417
|
-
for ( let i = 0, il = bones.length; i < il; i ++ ) {
|
|
1418
|
-
|
|
1419
|
-
boneNameDictionary[ bones[ i ].name ] = true;
|
|
1420
|
-
|
|
1421
|
-
}
|
|
1422
|
-
|
|
1423
|
-
for ( let i = 0; i < vmd.metadata.motionCount; i ++ ) {
|
|
1424
|
-
|
|
1425
|
-
const motion = vmd.motions[ i ];
|
|
1426
|
-
const boneName = motion.boneName;
|
|
1427
|
-
if ( boneNameDictionary[ boneName ] === undefined ) continue;
|
|
1428
|
-
motions[ boneName ] = motions[ boneName ] || [];
|
|
1429
|
-
motions[ boneName ].push( motion );
|
|
1430
|
-
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
for ( const key in motions ) {
|
|
1434
|
-
|
|
1435
|
-
const array = motions[ key ];
|
|
1436
|
-
array.sort( function ( a, b ) {
|
|
1437
|
-
|
|
1438
|
-
return a.frameNum - b.frameNum;
|
|
1439
|
-
|
|
1440
|
-
} );
|
|
1441
|
-
const times = [];
|
|
1442
|
-
const positions = [];
|
|
1443
|
-
const rotations = [];
|
|
1444
|
-
const pInterpolations = [];
|
|
1445
|
-
const rInterpolations = [];
|
|
1446
|
-
const basePosition = mesh.skeleton.getBoneByName( key ).position.toArray();
|
|
1447
|
-
for ( let i = 0, il = array.length; i < il; i ++ ) {
|
|
1448
|
-
|
|
1449
|
-
const time = array[ i ].frameNum / 30;
|
|
1450
|
-
const position = array[ i ].position;
|
|
1451
|
-
const rotation = array[ i ].rotation;
|
|
1452
|
-
const interpolation = array[ i ].interpolation;
|
|
1453
|
-
times.push( time );
|
|
1454
|
-
for ( let j = 0; j < 3; j ++ ) positions.push( basePosition[ j ] + position[ j ] );
|
|
1455
|
-
for ( let j = 0; j < 4; j ++ ) rotations.push( rotation[ j ] );
|
|
1456
|
-
for ( let j = 0; j < 3; j ++ ) pushInterpolation( pInterpolations, interpolation, j );
|
|
1457
|
-
pushInterpolation( rInterpolations, interpolation, 3 );
|
|
1458
|
-
|
|
1459
|
-
}
|
|
1460
|
-
|
|
1461
|
-
const targetName = '.bones[' + key + ']';
|
|
1462
|
-
tracks.push( this._createTrack( targetName + '.position', THREE.VectorKeyframeTrack, times, positions, pInterpolations ) );
|
|
1463
|
-
tracks.push( this._createTrack( targetName + '.quaternion', THREE.QuaternionKeyframeTrack, times, rotations, rInterpolations ) );
|
|
1464
|
-
|
|
1465
|
-
}
|
|
1466
|
-
|
|
1467
|
-
return new THREE.AnimationClip( '', - 1, tracks );
|
|
1468
|
-
|
|
1469
|
-
}
|
|
1470
|
-
|
|
1471
|
-
/**
|
|
1472
|
-
* @param {Object} vmd - parsed VMD data
|
|
1473
|
-
* @param {SkinnedMesh} mesh - tracks will be fitting to mesh
|
|
1474
|
-
* @return {AnimationClip}
|
|
1475
|
-
*/
|
|
1476
|
-
buildMorphAnimation( vmd, mesh ) {
|
|
1477
|
-
|
|
1478
|
-
const tracks = [];
|
|
1479
|
-
const morphs = {};
|
|
1480
|
-
const morphTargetDictionary = mesh.morphTargetDictionary;
|
|
1481
|
-
for ( let i = 0; i < vmd.metadata.morphCount; i ++ ) {
|
|
1482
|
-
|
|
1483
|
-
const morph = vmd.morphs[ i ];
|
|
1484
|
-
const morphName = morph.morphName;
|
|
1485
|
-
if ( morphTargetDictionary[ morphName ] === undefined ) continue;
|
|
1486
|
-
morphs[ morphName ] = morphs[ morphName ] || [];
|
|
1487
|
-
morphs[ morphName ].push( morph );
|
|
1488
|
-
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
for ( const key in morphs ) {
|
|
1492
|
-
|
|
1493
|
-
const array = morphs[ key ];
|
|
1494
|
-
array.sort( function ( a, b ) {
|
|
1495
|
-
|
|
1496
|
-
return a.frameNum - b.frameNum;
|
|
1497
|
-
|
|
1498
|
-
} );
|
|
1499
|
-
const times = [];
|
|
1500
|
-
const values = [];
|
|
1501
|
-
for ( let i = 0, il = array.length; i < il; i ++ ) {
|
|
1502
|
-
|
|
1503
|
-
times.push( array[ i ].frameNum / 30 );
|
|
1504
|
-
values.push( array[ i ].weight );
|
|
1505
|
-
|
|
1506
|
-
}
|
|
1507
|
-
|
|
1508
|
-
tracks.push( new THREE.NumberKeyframeTrack( '.morphTargetInfluences[' + morphTargetDictionary[ key ] + ']', times, values ) );
|
|
1509
|
-
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
return new THREE.AnimationClip( '', - 1, tracks );
|
|
1513
|
-
|
|
1514
|
-
}
|
|
1515
|
-
|
|
1516
|
-
/**
|
|
1517
|
-
* @param {Object} vmd - parsed VMD data
|
|
1518
|
-
* @return {AnimationClip}
|
|
1519
|
-
*/
|
|
1520
|
-
buildCameraAnimation( vmd ) {
|
|
1521
|
-
|
|
1522
|
-
function pushVector3( array, vec ) {
|
|
1523
|
-
|
|
1524
|
-
array.push( vec.x );
|
|
1525
|
-
array.push( vec.y );
|
|
1526
|
-
array.push( vec.z );
|
|
1527
|
-
|
|
1528
|
-
}
|
|
1529
|
-
|
|
1530
|
-
function pushQuaternion( array, q ) {
|
|
1531
|
-
|
|
1532
|
-
array.push( q.x );
|
|
1533
|
-
array.push( q.y );
|
|
1534
|
-
array.push( q.z );
|
|
1535
|
-
array.push( q.w );
|
|
1536
|
-
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
function pushInterpolation( array, interpolation, index ) {
|
|
1540
|
-
|
|
1541
|
-
array.push( interpolation[ index * 4 + 0 ] / 127 ); // x1
|
|
1542
|
-
array.push( interpolation[ index * 4 + 1 ] / 127 ); // x2
|
|
1543
|
-
array.push( interpolation[ index * 4 + 2 ] / 127 ); // y1
|
|
1544
|
-
array.push( interpolation[ index * 4 + 3 ] / 127 ); // y2
|
|
1545
|
-
|
|
1546
|
-
}
|
|
1547
|
-
|
|
1548
|
-
const cameras = vmd.cameras === undefined ? [] : vmd.cameras.slice();
|
|
1549
|
-
cameras.sort( function ( a, b ) {
|
|
1550
|
-
|
|
1551
|
-
return a.frameNum - b.frameNum;
|
|
1552
|
-
|
|
1553
|
-
} );
|
|
1554
|
-
const times = [];
|
|
1555
|
-
const centers = [];
|
|
1556
|
-
const quaternions = [];
|
|
1557
|
-
const positions = [];
|
|
1558
|
-
const fovs = [];
|
|
1559
|
-
const cInterpolations = [];
|
|
1560
|
-
const qInterpolations = [];
|
|
1561
|
-
const pInterpolations = [];
|
|
1562
|
-
const fInterpolations = [];
|
|
1563
|
-
const quaternion = new THREE.Quaternion();
|
|
1564
|
-
const euler = new THREE.Euler();
|
|
1565
|
-
const position = new THREE.Vector3();
|
|
1566
|
-
const center = new THREE.Vector3();
|
|
1567
|
-
for ( let i = 0, il = cameras.length; i < il; i ++ ) {
|
|
1568
|
-
|
|
1569
|
-
const motion = cameras[ i ];
|
|
1570
|
-
const time = motion.frameNum / 30;
|
|
1571
|
-
const pos = motion.position;
|
|
1572
|
-
const rot = motion.rotation;
|
|
1573
|
-
const distance = motion.distance;
|
|
1574
|
-
const fov = motion.fov;
|
|
1575
|
-
const interpolation = motion.interpolation;
|
|
1576
|
-
times.push( time );
|
|
1577
|
-
position.set( 0, 0, - distance );
|
|
1578
|
-
center.set( pos[ 0 ], pos[ 1 ], pos[ 2 ] );
|
|
1579
|
-
euler.set( - rot[ 0 ], - rot[ 1 ], - rot[ 2 ] );
|
|
1580
|
-
quaternion.setFromEuler( euler );
|
|
1581
|
-
position.add( center );
|
|
1582
|
-
position.applyQuaternion( quaternion );
|
|
1583
|
-
pushVector3( centers, center );
|
|
1584
|
-
pushQuaternion( quaternions, quaternion );
|
|
1585
|
-
pushVector3( positions, position );
|
|
1586
|
-
fovs.push( fov );
|
|
1587
|
-
for ( let j = 0; j < 3; j ++ ) {
|
|
1588
|
-
|
|
1589
|
-
pushInterpolation( cInterpolations, interpolation, j );
|
|
1590
|
-
|
|
1591
|
-
}
|
|
1592
|
-
|
|
1593
|
-
pushInterpolation( qInterpolations, interpolation, 3 );
|
|
1594
|
-
|
|
1595
|
-
// use the same parameter for x, y, z axis.
|
|
1596
|
-
for ( let j = 0; j < 3; j ++ ) {
|
|
1597
|
-
|
|
1598
|
-
pushInterpolation( pInterpolations, interpolation, 4 );
|
|
1599
|
-
|
|
1600
|
-
}
|
|
1601
|
-
|
|
1602
|
-
pushInterpolation( fInterpolations, interpolation, 5 );
|
|
1603
|
-
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1606
|
-
const tracks = [];
|
|
1607
|
-
|
|
1608
|
-
// I expect an object whose name 'target' exists under THREE.Camera
|
|
1609
|
-
tracks.push( this._createTrack( 'target.position', THREE.VectorKeyframeTrack, times, centers, cInterpolations ) );
|
|
1610
|
-
tracks.push( this._createTrack( '.quaternion', THREE.QuaternionKeyframeTrack, times, quaternions, qInterpolations ) );
|
|
1611
|
-
tracks.push( this._createTrack( '.position', THREE.VectorKeyframeTrack, times, positions, pInterpolations ) );
|
|
1612
|
-
tracks.push( this._createTrack( '.fov', THREE.NumberKeyframeTrack, times, fovs, fInterpolations ) );
|
|
1613
|
-
return new THREE.AnimationClip( '', - 1, tracks );
|
|
1614
|
-
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
// private method
|
|
1618
|
-
|
|
1619
|
-
_createTrack( node, typedKeyframeTrack, times, values, interpolations ) {
|
|
1620
|
-
|
|
1621
|
-
/*
|
|
1622
|
-
* optimizes here not to let KeyframeTrackPrototype optimize
|
|
1623
|
-
* because KeyframeTrackPrototype optimizes times and values but
|
|
1624
|
-
* doesn't optimize interpolations.
|
|
1625
|
-
*/
|
|
1626
|
-
if ( times.length > 2 ) {
|
|
1627
|
-
|
|
1628
|
-
times = times.slice();
|
|
1629
|
-
values = values.slice();
|
|
1630
|
-
interpolations = interpolations.slice();
|
|
1631
|
-
const stride = values.length / times.length;
|
|
1632
|
-
const interpolateStride = interpolations.length / times.length;
|
|
1633
|
-
let index = 1;
|
|
1634
|
-
for ( let aheadIndex = 2, endIndex = times.length; aheadIndex < endIndex; aheadIndex ++ ) {
|
|
1635
|
-
|
|
1636
|
-
for ( let i = 0; i < stride; i ++ ) {
|
|
1637
|
-
|
|
1638
|
-
if ( values[ index * stride + i ] !== values[ ( index - 1 ) * stride + i ] || values[ index * stride + i ] !== values[ aheadIndex * stride + i ] ) {
|
|
1639
|
-
|
|
1640
|
-
index ++;
|
|
1641
|
-
break;
|
|
1642
|
-
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
|
-
}
|
|
1646
|
-
|
|
1647
|
-
if ( aheadIndex > index ) {
|
|
1648
|
-
|
|
1649
|
-
times[ index ] = times[ aheadIndex ];
|
|
1650
|
-
for ( let i = 0; i < stride; i ++ ) {
|
|
1651
|
-
|
|
1652
|
-
values[ index * stride + i ] = values[ aheadIndex * stride + i ];
|
|
1653
|
-
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
for ( let i = 0; i < interpolateStride; i ++ ) {
|
|
1657
|
-
|
|
1658
|
-
interpolations[ index * interpolateStride + i ] = interpolations[ aheadIndex * interpolateStride + i ];
|
|
1659
|
-
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
|
-
}
|
|
1663
|
-
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
times.length = index + 1;
|
|
1667
|
-
values.length = ( index + 1 ) * stride;
|
|
1668
|
-
interpolations.length = ( index + 1 ) * interpolateStride;
|
|
1669
|
-
|
|
1670
|
-
}
|
|
1671
|
-
|
|
1672
|
-
const track = new typedKeyframeTrack( node, times, values );
|
|
1673
|
-
track.createInterpolant = function InterpolantFactoryMethodCubicBezier( result ) {
|
|
1674
|
-
|
|
1675
|
-
return new CubicBezierInterpolation( this.times, this.values, this.getValueSize(), result, new Float32Array( interpolations ) );
|
|
1676
|
-
|
|
1677
|
-
};
|
|
1678
|
-
|
|
1679
|
-
return track;
|
|
1680
|
-
|
|
1681
|
-
}
|
|
1682
|
-
|
|
1683
|
-
}
|
|
1684
|
-
|
|
1685
|
-
// interpolation
|
|
1686
|
-
|
|
1687
|
-
class CubicBezierInterpolation extends THREE.Interpolant {
|
|
1688
|
-
|
|
1689
|
-
constructor( parameterPositions, sampleValues, sampleSize, resultBuffer, params ) {
|
|
1690
|
-
|
|
1691
|
-
super( parameterPositions, sampleValues, sampleSize, resultBuffer );
|
|
1692
|
-
this.interpolationParams = params;
|
|
1693
|
-
|
|
1694
|
-
}
|
|
1695
|
-
interpolate_( i1, t0, t, t1 ) {
|
|
1696
|
-
|
|
1697
|
-
const result = this.resultBuffer;
|
|
1698
|
-
const values = this.sampleValues;
|
|
1699
|
-
const stride = this.valueSize;
|
|
1700
|
-
const params = this.interpolationParams;
|
|
1701
|
-
const offset1 = i1 * stride;
|
|
1702
|
-
const offset0 = offset1 - stride;
|
|
1703
|
-
|
|
1704
|
-
// No interpolation if next key frame is in one frame in 30fps.
|
|
1705
|
-
// This is from MMD animation spec.
|
|
1706
|
-
// '1.5' is for precision loss. times are Float32 in Three.js Animation system.
|
|
1707
|
-
const weight1 = t1 - t0 < 1 / 30 * 1.5 ? 0.0 : ( t - t0 ) / ( t1 - t0 );
|
|
1708
|
-
if ( stride === 4 ) {
|
|
1709
|
-
|
|
1710
|
-
// THREE.Quaternion
|
|
1711
|
-
|
|
1712
|
-
const x1 = params[ i1 * 4 + 0 ];
|
|
1713
|
-
const x2 = params[ i1 * 4 + 1 ];
|
|
1714
|
-
const y1 = params[ i1 * 4 + 2 ];
|
|
1715
|
-
const y2 = params[ i1 * 4 + 3 ];
|
|
1716
|
-
const ratio = this._calculate( x1, x2, y1, y2, weight1 );
|
|
1717
|
-
THREE.Quaternion.slerpFlat( result, 0, values, offset0, values, offset1, ratio );
|
|
1718
|
-
|
|
1719
|
-
} else if ( stride === 3 ) {
|
|
1720
|
-
|
|
1721
|
-
// THREE.Vector3
|
|
1722
|
-
|
|
1723
|
-
for ( let i = 0; i !== stride; ++ i ) {
|
|
1724
|
-
|
|
1725
|
-
const x1 = params[ i1 * 12 + i * 4 + 0 ];
|
|
1726
|
-
const x2 = params[ i1 * 12 + i * 4 + 1 ];
|
|
1727
|
-
const y1 = params[ i1 * 12 + i * 4 + 2 ];
|
|
1728
|
-
const y2 = params[ i1 * 12 + i * 4 + 3 ];
|
|
1729
|
-
const ratio = this._calculate( x1, x2, y1, y2, weight1 );
|
|
1730
|
-
result[ i ] = values[ offset0 + i ] * ( 1 - ratio ) + values[ offset1 + i ] * ratio;
|
|
1731
|
-
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
|
-
} else {
|
|
1735
|
-
|
|
1736
|
-
// Number
|
|
1737
|
-
|
|
1738
|
-
const x1 = params[ i1 * 4 + 0 ];
|
|
1739
|
-
const x2 = params[ i1 * 4 + 1 ];
|
|
1740
|
-
const y1 = params[ i1 * 4 + 2 ];
|
|
1741
|
-
const y2 = params[ i1 * 4 + 3 ];
|
|
1742
|
-
const ratio = this._calculate( x1, x2, y1, y2, weight1 );
|
|
1743
|
-
result[ 0 ] = values[ offset0 ] * ( 1 - ratio ) + values[ offset1 ] * ratio;
|
|
1744
|
-
|
|
1745
|
-
}
|
|
1746
|
-
|
|
1747
|
-
return result;
|
|
1748
|
-
|
|
1749
|
-
}
|
|
1750
|
-
_calculate( x1, x2, y1, y2, x ) {
|
|
1751
|
-
|
|
1752
|
-
/*
|
|
1753
|
-
* Cubic Bezier curves
|
|
1754
|
-
* https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves
|
|
1755
|
-
*
|
|
1756
|
-
* B(t) = ( 1 - t ) ^ 3 * P0
|
|
1757
|
-
* + 3 * ( 1 - t ) ^ 2 * t * P1
|
|
1758
|
-
* + 3 * ( 1 - t ) * t^2 * P2
|
|
1759
|
-
* + t ^ 3 * P3
|
|
1760
|
-
* ( 0 <= t <= 1 )
|
|
1761
|
-
*
|
|
1762
|
-
* MMD uses Cubic Bezier curves for bone and camera animation interpolation.
|
|
1763
|
-
* http://d.hatena.ne.jp/edvakf/20111016/1318716097
|
|
1764
|
-
*
|
|
1765
|
-
* x = ( 1 - t ) ^ 3 * x0
|
|
1766
|
-
* + 3 * ( 1 - t ) ^ 2 * t * x1
|
|
1767
|
-
* + 3 * ( 1 - t ) * t^2 * x2
|
|
1768
|
-
* + t ^ 3 * x3
|
|
1769
|
-
* y = ( 1 - t ) ^ 3 * y0
|
|
1770
|
-
* + 3 * ( 1 - t ) ^ 2 * t * y1
|
|
1771
|
-
* + 3 * ( 1 - t ) * t^2 * y2
|
|
1772
|
-
* + t ^ 3 * y3
|
|
1773
|
-
* ( x0 = 0, y0 = 0 )
|
|
1774
|
-
* ( x3 = 1, y3 = 1 )
|
|
1775
|
-
* ( 0 <= t, x1, x2, y1, y2 <= 1 )
|
|
1776
|
-
*
|
|
1777
|
-
* Here solves this equation with Bisection method,
|
|
1778
|
-
* https://en.wikipedia.org/wiki/Bisection_method
|
|
1779
|
-
* gets t, and then calculate y.
|
|
1780
|
-
*
|
|
1781
|
-
* f(t) = 3 * ( 1 - t ) ^ 2 * t * x1
|
|
1782
|
-
* + 3 * ( 1 - t ) * t^2 * x2
|
|
1783
|
-
* + t ^ 3 - x = 0
|
|
1784
|
-
*
|
|
1785
|
-
* (Another option: Newton's method
|
|
1786
|
-
* https://en.wikipedia.org/wiki/Newton%27s_method)
|
|
1787
|
-
*/
|
|
1788
|
-
|
|
1789
|
-
let c = 0.5;
|
|
1790
|
-
let t = c;
|
|
1791
|
-
let s = 1.0 - t;
|
|
1792
|
-
const loop = 15;
|
|
1793
|
-
const eps = 1e-5;
|
|
1794
|
-
const math = Math;
|
|
1795
|
-
let sst3, stt3, ttt;
|
|
1796
|
-
for ( let i = 0; i < loop; i ++ ) {
|
|
1797
|
-
|
|
1798
|
-
sst3 = 3.0 * s * s * t;
|
|
1799
|
-
stt3 = 3.0 * s * t * t;
|
|
1800
|
-
ttt = t * t * t;
|
|
1801
|
-
const ft = sst3 * x1 + stt3 * x2 + ttt - x;
|
|
1802
|
-
if ( math.abs( ft ) < eps ) break;
|
|
1803
|
-
c /= 2.0;
|
|
1804
|
-
t += ft < 0 ? c : - c;
|
|
1805
|
-
s = 1.0 - t;
|
|
1806
|
-
|
|
1807
|
-
}
|
|
1808
|
-
|
|
1809
|
-
return sst3 * y1 + stt3 * y2 + ttt;
|
|
1810
|
-
|
|
1811
|
-
}
|
|
1812
|
-
|
|
1813
|
-
}
|
|
1814
|
-
class MMDToonMaterial extends THREE.ShaderMaterial {
|
|
1815
|
-
|
|
1816
|
-
constructor( parameters ) {
|
|
1817
|
-
|
|
1818
|
-
super();
|
|
1819
|
-
this.isMMDToonMaterial = true;
|
|
1820
|
-
this._matcapCombine = THREE.AddOperation;
|
|
1821
|
-
this.emissiveIntensity = 1.0;
|
|
1822
|
-
this.normalMapType = THREE.TangentSpaceNormalMap;
|
|
1823
|
-
this.combine = THREE.MultiplyOperation;
|
|
1824
|
-
this.wireframeLinecap = 'round';
|
|
1825
|
-
this.wireframeLinejoin = 'round';
|
|
1826
|
-
this.flatShading = false;
|
|
1827
|
-
this.lights = true;
|
|
1828
|
-
this.vertexShader = THREE.MMDToonShader.vertexShader;
|
|
1829
|
-
this.fragmentShader = THREE.MMDToonShader.fragmentShader;
|
|
1830
|
-
this.defines = Object.assign( {}, THREE.MMDToonShader.defines );
|
|
1831
|
-
Object.defineProperty( this, 'matcapCombine', {
|
|
1832
|
-
get: function () {
|
|
1833
|
-
|
|
1834
|
-
return this._matcapCombine;
|
|
1835
|
-
|
|
1836
|
-
},
|
|
1837
|
-
set: function ( value ) {
|
|
1838
|
-
|
|
1839
|
-
this._matcapCombine = value;
|
|
1840
|
-
switch ( value ) {
|
|
1841
|
-
|
|
1842
|
-
case THREE.MultiplyOperation:
|
|
1843
|
-
this.defines.MATCAP_BLENDING_MULTIPLY = true;
|
|
1844
|
-
delete this.defines.MATCAP_BLENDING_ADD;
|
|
1845
|
-
break;
|
|
1846
|
-
default:
|
|
1847
|
-
case THREE.AddOperation:
|
|
1848
|
-
this.defines.MATCAP_BLENDING_ADD = true;
|
|
1849
|
-
delete this.defines.MATCAP_BLENDING_MULTIPLY;
|
|
1850
|
-
break;
|
|
1851
|
-
|
|
1852
|
-
}
|
|
1853
|
-
|
|
1854
|
-
}
|
|
1855
|
-
} );
|
|
1856
|
-
this.uniforms = THREE.UniformsUtils.clone( THREE.MMDToonShader.uniforms );
|
|
1857
|
-
|
|
1858
|
-
// merged from MeshToon/Phong/MatcapMaterial
|
|
1859
|
-
const exposePropertyNames = [ 'specular', 'opacity', 'diffuse', 'map', 'matcap', 'gradientMap', 'lightMap', 'lightMapIntensity', 'aoMap', 'aoMapIntensity', 'emissive', 'emissiveMap', 'bumpMap', 'bumpScale', 'normalMap', 'normalScale', 'displacemantBias', 'displacemantMap', 'displacemantScale', 'specularMap', 'alphaMap', 'envMap', 'reflectivity', 'refractionRatio' ];
|
|
1860
|
-
for ( const propertyName of exposePropertyNames ) {
|
|
1861
|
-
|
|
1862
|
-
Object.defineProperty( this, propertyName, {
|
|
1863
|
-
get: function () {
|
|
1864
|
-
|
|
1865
|
-
return this.uniforms[ propertyName ].value;
|
|
1866
|
-
|
|
1867
|
-
},
|
|
1868
|
-
set: function ( value ) {
|
|
1869
|
-
|
|
1870
|
-
this.uniforms[ propertyName ].value = value;
|
|
1871
|
-
|
|
1872
|
-
}
|
|
1873
|
-
} );
|
|
1874
|
-
|
|
1875
|
-
}
|
|
1876
|
-
|
|
1877
|
-
// Special path for shininess to handle zero shininess properly
|
|
1878
|
-
this._shininess = 30;
|
|
1879
|
-
Object.defineProperty( this, 'shininess', {
|
|
1880
|
-
get: function () {
|
|
1881
|
-
|
|
1882
|
-
return this._shininess;
|
|
1883
|
-
|
|
1884
|
-
},
|
|
1885
|
-
set: function ( value ) {
|
|
1886
|
-
|
|
1887
|
-
this._shininess = value;
|
|
1888
|
-
this.uniforms.shininess.value = Math.max( this._shininess, 1e-4 ); // To prevent pow( 0.0, 0.0 )
|
|
1889
|
-
|
|
1890
|
-
}
|
|
1891
|
-
} );
|
|
1892
|
-
|
|
1893
|
-
Object.defineProperty( this, 'color', Object.getOwnPropertyDescriptor( this, 'diffuse' ) );
|
|
1894
|
-
this.setValues( parameters );
|
|
1895
|
-
|
|
1896
|
-
}
|
|
1897
|
-
copy( source ) {
|
|
1898
|
-
|
|
1899
|
-
super.copy( source );
|
|
1900
|
-
this.matcapCombine = source.matcapCombine;
|
|
1901
|
-
this.emissiveIntensity = source.emissiveIntensity;
|
|
1902
|
-
this.normalMapType = source.normalMapType;
|
|
1903
|
-
this.combine = source.combine;
|
|
1904
|
-
this.wireframeLinecap = source.wireframeLinecap;
|
|
1905
|
-
this.wireframeLinejoin = source.wireframeLinejoin;
|
|
1906
|
-
this.flatShading = source.flatShading;
|
|
1907
|
-
return this;
|
|
1908
|
-
|
|
1909
|
-
}
|
|
1910
|
-
|
|
1911
|
-
}
|
|
1912
|
-
|
|
1913
|
-
THREE.MMDLoader = MMDLoader;
|
|
1914
|
-
|
|
1915
|
-
} )();
|