three-stdlib 2.22.9 → 2.22.10
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/animation/AnimationClipCreator.js +49 -50
- package/dist/animation/AnimationClipCreator.mjs +49 -50
- package/dist/animation/CCDIKSolver.d.ts +9 -4
- package/dist/animation/CCDIKSolver.js +193 -148
- package/dist/animation/CCDIKSolver.mjs +194 -149
- package/dist/animation/MMDAnimationHelper.js +613 -515
- package/dist/animation/MMDAnimationHelper.mjs +613 -515
- package/dist/animation/MMDPhysics.d.ts +6 -1
- package/dist/animation/MMDPhysics.js +728 -718
- package/dist/animation/MMDPhysics.mjs +729 -719
- package/dist/cameras/CinematicCamera.d.ts +2 -2
- package/dist/controls/ArcballControls.d.ts +1 -1
- package/dist/controls/ArcballControls.js +38 -44
- package/dist/controls/ArcballControls.mjs +39 -45
- package/dist/controls/DeviceOrientationControls.js +2 -1
- package/dist/controls/DeviceOrientationControls.mjs +2 -1
- package/dist/controls/FirstPersonControls.d.ts +1 -1
- package/dist/controls/FirstPersonControls.js +1 -1
- package/dist/controls/FirstPersonControls.mjs +1 -1
- package/dist/controls/PointerLockControls.js +2 -2
- package/dist/controls/PointerLockControls.mjs +2 -2
- package/dist/controls/TransformControls.d.ts +1 -1
- package/dist/controls/experimental/CameraControls.d.ts +1 -1
- package/dist/csm/CSM.js +4 -4
- package/dist/csm/CSM.mjs +4 -4
- package/dist/csm/CSMFrustum.js +1 -1
- package/dist/csm/CSMFrustum.mjs +1 -1
- package/dist/csm/CSMShader.js +14 -10
- package/dist/csm/CSMShader.mjs +14 -10
- package/dist/curves/CurveExtras.js +52 -62
- package/dist/curves/CurveExtras.mjs +53 -63
- package/dist/curves/NURBSUtils.d.ts +18 -20
- package/dist/curves/NURBSUtils.js +17 -17
- package/dist/curves/NURBSUtils.mjs +17 -17
- package/dist/deprecated/Geometry.js +26 -26
- package/dist/deprecated/Geometry.mjs +27 -27
- package/dist/effects/AnaglyphEffect.js +95 -114
- package/dist/effects/AnaglyphEffect.mjs +95 -114
- package/dist/effects/AsciiEffect.js +144 -162
- package/dist/effects/AsciiEffect.mjs +144 -162
- package/dist/effects/OutlineEffect.js +253 -276
- package/dist/effects/OutlineEffect.mjs +253 -276
- package/dist/effects/ParallaxBarrierEffect.js +61 -60
- package/dist/effects/ParallaxBarrierEffect.mjs +61 -60
- package/dist/effects/PeppersGhostEffect.js +84 -81
- package/dist/effects/PeppersGhostEffect.mjs +84 -81
- package/dist/effects/StereoEffect.js +31 -28
- package/dist/effects/StereoEffect.mjs +31 -28
- package/dist/environments/RoomEnvironment.d.ts +6 -5
- package/dist/exporters/GLTFExporter.d.ts +109 -441
- package/dist/exporters/GLTFExporter.js +912 -581
- package/dist/exporters/GLTFExporter.mjs +912 -581
- package/dist/geometries/ConvexGeometry.js +0 -3
- package/dist/geometries/ConvexGeometry.mjs +0 -3
- package/dist/geometries/LightningStrike.d.ts +3 -3
- package/dist/geometries/LightningStrike.js +80 -75
- package/dist/geometries/LightningStrike.mjs +80 -75
- package/dist/geometries/ParametricGeometries.js +75 -74
- package/dist/geometries/ParametricGeometries.mjs +75 -74
- package/dist/geometries/RoundedBoxGeometry.js +1 -1
- package/dist/geometries/RoundedBoxGeometry.mjs +1 -1
- package/dist/geometries/TextGeometry.d.ts +1 -1
- package/dist/helpers/RectAreaLightHelper.d.ts +4 -3
- package/dist/helpers/RectAreaLightHelper.js +2 -2
- package/dist/helpers/RectAreaLightHelper.mjs +2 -2
- package/dist/helpers/VertexNormalsHelper.d.ts +3 -0
- package/dist/helpers/VertexNormalsHelper.js +15 -22
- package/dist/helpers/VertexNormalsHelper.mjs +16 -23
- package/dist/helpers/VertexTangentsHelper.d.ts +3 -0
- package/dist/helpers/VertexTangentsHelper.js +12 -14
- package/dist/helpers/VertexTangentsHelper.mjs +12 -14
- package/dist/index.d.ts +1 -66
- package/dist/index.js +5 -370
- package/dist/index.mjs +9 -374
- package/dist/interactive/InteractiveGroup.js +1 -1
- package/dist/interactive/InteractiveGroup.mjs +1 -1
- package/dist/interactive/SelectionBox.js +122 -125
- package/dist/interactive/SelectionBox.mjs +122 -125
- package/dist/interactive/SelectionHelper.js +45 -48
- package/dist/interactive/SelectionHelper.mjs +45 -48
- package/dist/libs/MeshoptDecoder.d.ts +1 -1
- package/dist/libs/MotionControllers.d.ts +15 -14
- package/dist/libs/MotionControllers.js +10 -10
- package/dist/libs/MotionControllers.mjs +10 -10
- package/dist/lights/LightProbeGenerator.js +43 -43
- package/dist/lights/LightProbeGenerator.mjs +43 -43
- package/dist/lights/RectAreaLightUniformsLib.js +9 -5
- package/dist/lights/RectAreaLightUniformsLib.mjs +9 -5
- package/dist/lines/LineMaterial.js +271 -271
- package/dist/lines/LineMaterial.mjs +272 -272
- package/dist/lines/LineSegments2.js +12 -12
- package/dist/lines/LineSegments2.mjs +12 -12
- package/dist/lines/LineSegmentsGeometry.js +2 -2
- package/dist/lines/LineSegmentsGeometry.mjs +2 -2
- package/dist/lines/Wireframe.js +2 -2
- package/dist/lines/Wireframe.mjs +2 -2
- package/dist/loaders/3DMLoader.d.ts +2 -1
- package/dist/loaders/3MFLoader.d.ts +2 -1
- package/dist/loaders/AMFLoader.d.ts +2 -1
- package/dist/loaders/AssimpLoader.d.ts +20 -0
- package/dist/loaders/AssimpLoader.js +520 -482
- package/dist/loaders/AssimpLoader.mjs +520 -482
- package/dist/loaders/BVHLoader.d.ts +2 -1
- package/dist/loaders/BasisTextureLoader.d.ts +2 -1
- package/dist/loaders/BasisTextureLoader.js +23 -14
- package/dist/loaders/BasisTextureLoader.mjs +24 -15
- package/dist/loaders/ColladaLoader.d.ts +2 -1
- package/dist/loaders/DRACOLoader.d.ts +2 -1
- package/dist/loaders/FBXLoader.d.ts +2 -1
- package/dist/loaders/FBXLoader.js +2 -2
- package/dist/loaders/FBXLoader.mjs +2 -2
- package/dist/loaders/FontLoader.d.ts +4 -4
- package/dist/loaders/FontLoader.js +2 -1
- package/dist/loaders/FontLoader.mjs +2 -1
- package/dist/loaders/GCodeLoader.d.ts +2 -1
- package/dist/loaders/GLTFLoader.d.ts +11 -9
- package/dist/loaders/GLTFLoader.js +2 -2
- package/dist/loaders/GLTFLoader.mjs +2 -2
- package/dist/loaders/HDRCubeTextureLoader.d.ts +2 -1
- package/dist/loaders/KMZLoader.d.ts +2 -1
- package/dist/loaders/KTX2Loader.js +34 -15
- package/dist/loaders/KTX2Loader.mjs +35 -16
- package/dist/loaders/LDrawLoader.d.ts +2 -1
- package/dist/loaders/LDrawLoader.js +3 -3
- package/dist/loaders/LDrawLoader.mjs +3 -3
- package/dist/loaders/LUT3dlLoader.d.ts +3 -2
- package/dist/loaders/LUTCubeLoader.d.ts +3 -2
- package/dist/loaders/LWOLoader.d.ts +2 -1
- package/dist/loaders/LottieLoader.d.ts +2 -1
- package/dist/loaders/MD2Loader.d.ts +2 -1
- package/dist/loaders/MDDLoader.d.ts +2 -1
- package/dist/loaders/MMDLoader.d.ts +2 -1
- package/dist/loaders/MTLLoader.d.ts +2 -1
- package/dist/loaders/OBJLoader.d.ts +2 -1
- package/dist/loaders/OBJLoader.js +5 -5
- package/dist/loaders/OBJLoader.mjs +5 -5
- package/dist/loaders/PCDLoader.d.ts +2 -1
- package/dist/loaders/PDBLoader.d.ts +2 -1
- package/dist/loaders/PLYLoader.d.ts +2 -1
- package/dist/loaders/PRWMLoader.d.ts +2 -1
- package/dist/loaders/RGBMLoader.js +924 -918
- package/dist/loaders/RGBMLoader.mjs +924 -918
- package/dist/loaders/STLLoader.d.ts +2 -1
- package/dist/loaders/SVGLoader.d.ts +2 -1
- package/dist/loaders/TDSLoader.d.ts +2 -1
- package/dist/loaders/TTFLoader.d.ts +2 -1
- package/dist/loaders/TiltLoader.d.ts +2 -1
- package/dist/loaders/TiltLoader.js +3 -1
- package/dist/loaders/TiltLoader.mjs +3 -1
- package/dist/loaders/VOXLoader.d.ts +4 -2
- package/dist/loaders/VRMLLoader.d.ts +2 -1
- package/dist/loaders/VRMLoader.d.ts +20 -0
- package/dist/loaders/VTKLoader.d.ts +2 -1
- package/dist/loaders/XLoader.d.ts +20 -0
- package/dist/loaders/XLoader.js +1 -1
- package/dist/loaders/XLoader.mjs +1 -1
- package/dist/loaders/XYZLoader.d.ts +2 -1
- package/dist/loaders/lwo/IFFParser.js +104 -110
- package/dist/loaders/lwo/IFFParser.mjs +104 -110
- package/dist/loaders/lwo/LWO2Parser.js +18 -33
- package/dist/loaders/lwo/LWO2Parser.mjs +18 -33
- package/dist/loaders/lwo/LWO3Parser.js +17 -33
- package/dist/loaders/lwo/LWO3Parser.mjs +17 -33
- package/dist/math/Capsule.d.ts +1 -1
- package/dist/math/Capsule.js +90 -92
- package/dist/math/Capsule.mjs +90 -92
- package/dist/math/ColorConverter.js +26 -36
- package/dist/math/ColorConverter.mjs +26 -36
- package/dist/math/ConvexHull.js +16 -17
- package/dist/math/ConvexHull.mjs +17 -18
- package/dist/math/ImprovedNoise.js +41 -39
- package/dist/math/ImprovedNoise.mjs +41 -39
- package/dist/math/Lut.js +65 -63
- package/dist/math/Lut.mjs +66 -64
- package/dist/math/MeshSurfaceSampler.d.ts +3 -0
- package/dist/math/MeshSurfaceSampler.js +85 -89
- package/dist/math/MeshSurfaceSampler.mjs +85 -89
- package/dist/math/OBB.js +68 -88
- package/dist/math/OBB.mjs +68 -88
- package/dist/math/Octree.js +240 -245
- package/dist/math/Octree.mjs +240 -245
- package/dist/misc/ConvexObjectBreaker.js +114 -120
- package/dist/misc/ConvexObjectBreaker.mjs +115 -121
- package/dist/misc/GPUComputationRenderer.d.ts +1 -0
- package/dist/misc/GPUComputationRenderer.js +191 -157
- package/dist/misc/GPUComputationRenderer.mjs +192 -158
- package/dist/misc/Gyroscope.js +16 -18
- package/dist/misc/Gyroscope.mjs +17 -19
- package/dist/misc/MD2Character.js +88 -86
- package/dist/misc/MD2Character.mjs +89 -87
- package/dist/misc/MD2CharacterComplex.js +106 -105
- package/dist/misc/MD2CharacterComplex.mjs +107 -106
- package/dist/misc/MorphAnimMesh.d.ts +1 -1
- package/dist/misc/MorphAnimMesh.js +33 -33
- package/dist/misc/MorphAnimMesh.mjs +33 -33
- package/dist/misc/MorphBlendMesh.js +68 -68
- package/dist/misc/MorphBlendMesh.mjs +68 -68
- package/dist/misc/ProgressiveLightmap.d.ts +1 -2
- package/dist/misc/RollerCoaster.js +321 -314
- package/dist/misc/RollerCoaster.mjs +322 -315
- package/dist/misc/Volume.d.ts +1 -1
- package/dist/misc/Volume.js +169 -166
- package/dist/misc/Volume.mjs +170 -167
- package/dist/misc/VolumeSlice.js +50 -51
- package/dist/misc/VolumeSlice.mjs +50 -51
- package/dist/modifiers/CurveModifier.d.ts +2 -2
- package/dist/modifiers/CurveModifier.js +1 -1
- package/dist/modifiers/CurveModifier.mjs +1 -1
- package/dist/modifiers/SimplifyModifier.js +2 -1
- package/dist/modifiers/SimplifyModifier.mjs +2 -1
- package/dist/objects/Lensflare.js +32 -21
- package/dist/objects/Lensflare.mjs +33 -22
- package/dist/objects/LightningStorm.d.ts +3 -3
- package/dist/objects/LightningStorm.js +3 -3
- package/dist/objects/LightningStorm.mjs +3 -3
- package/dist/objects/MarchingCubes.d.ts +1 -0
- package/dist/objects/MarchingCubes.js +4362 -10
- package/dist/objects/MarchingCubes.mjs +4363 -11
- package/dist/objects/Reflector.d.ts +5 -2
- package/dist/objects/Reflector.js +39 -12
- package/dist/objects/Reflector.mjs +40 -13
- package/dist/objects/ReflectorForSSRPass.js +25 -21
- package/dist/objects/ReflectorForSSRPass.mjs +26 -22
- package/dist/objects/ReflectorRTT.d.ts +6 -0
- package/dist/objects/Refractor.d.ts +5 -2
- package/dist/objects/Refractor.js +39 -12
- package/dist/objects/Refractor.mjs +40 -13
- package/dist/objects/ShadowMesh.d.ts +6 -3
- package/dist/objects/ShadowMesh.js +7 -3
- package/dist/objects/ShadowMesh.mjs +8 -4
- package/dist/objects/Sky.js +181 -137
- package/dist/objects/Sky.mjs +182 -138
- package/dist/objects/Water.d.ts +3 -3
- package/dist/objects/Water.js +3 -2
- package/dist/objects/Water.mjs +3 -2
- package/dist/objects/Water2.d.ts +2 -2
- package/dist/objects/Water2.js +16 -18
- package/dist/objects/Water2.mjs +17 -19
- package/dist/postprocessing/AdaptiveToneMappingPass.d.ts +2 -2
- package/dist/postprocessing/AdaptiveToneMappingPass.js +105 -112
- package/dist/postprocessing/AdaptiveToneMappingPass.mjs +107 -114
- package/dist/postprocessing/BokehPass.d.ts +1 -1
- package/dist/postprocessing/ClearPass.d.ts +3 -3
- package/dist/postprocessing/CubeTexturePass.js +37 -33
- package/dist/postprocessing/CubeTexturePass.mjs +37 -33
- package/dist/postprocessing/HalftonePass.d.ts +1 -1
- package/dist/postprocessing/LUTPass.d.ts +3 -3
- package/dist/postprocessing/RenderPixelatedPass.d.ts +28 -0
- package/dist/postprocessing/SAOPass.d.ts +5 -6
- package/dist/postprocessing/SAOPass.js +151 -145
- package/dist/postprocessing/SAOPass.mjs +153 -147
- package/dist/postprocessing/SSAARenderPass.d.ts +5 -5
- package/dist/postprocessing/SSAARenderPass.js +78 -55
- package/dist/postprocessing/SSAARenderPass.mjs +80 -57
- package/dist/postprocessing/SSAOPass.d.ts +4 -5
- package/dist/postprocessing/SSAOPass.js +17 -10
- package/dist/postprocessing/SSAOPass.mjs +17 -10
- package/dist/postprocessing/SSRPass.d.ts +6 -7
- package/dist/postprocessing/SSRPass.js +235 -262
- package/dist/postprocessing/SSRPass.mjs +237 -264
- package/dist/postprocessing/TAARenderPass.d.ts +2 -2
- package/dist/postprocessing/TAARenderPass.js +106 -27
- package/dist/postprocessing/TAARenderPass.mjs +107 -28
- package/dist/postprocessing/TexturePass.d.ts +2 -2
- package/dist/postprocessing/TexturePass.js +24 -22
- package/dist/postprocessing/TexturePass.mjs +25 -23
- package/dist/postprocessing/UnrealBloomPass.js +175 -118
- package/dist/postprocessing/UnrealBloomPass.mjs +177 -120
- package/dist/renderers/CSS2DRenderer.d.ts +2 -1
- package/dist/renderers/CSS2DRenderer.js +5 -4
- package/dist/renderers/CSS2DRenderer.mjs +6 -5
- package/dist/renderers/CSS3DRenderer.d.ts +1 -1
- package/dist/renderers/CSS3DRenderer.js +147 -113
- package/dist/renderers/CSS3DRenderer.mjs +148 -114
- package/dist/renderers/Projector.js +377 -389
- package/dist/renderers/Projector.mjs +377 -389
- package/dist/renderers/SVGRenderer.js +280 -275
- package/dist/renderers/SVGRenderer.mjs +280 -275
- package/dist/shaders/ACESFilmicToneMappingShader.d.ts +1 -1
- package/dist/shaders/AfterimageShader.d.ts +1 -1
- package/dist/shaders/BasicShader.d.ts +1 -1
- package/dist/shaders/BleachBypassShader.d.ts +1 -1
- package/dist/shaders/BokehShader.d.ts +2 -2
- package/dist/shaders/BokehShader2.d.ts +2 -2
- package/dist/shaders/BokehShader2.js +1 -1
- package/dist/shaders/BokehShader2.mjs +1 -1
- package/dist/shaders/ColorCorrectionShader.js +3 -3
- package/dist/shaders/ColorCorrectionShader.mjs +3 -3
- package/dist/shaders/ColorifyShader.js +1 -1
- package/dist/shaders/ColorifyShader.mjs +1 -1
- package/dist/shaders/ConvolutionShader.d.ts +2 -2
- package/dist/shaders/ConvolutionShader.js +1 -1
- package/dist/shaders/ConvolutionShader.mjs +1 -1
- package/dist/shaders/CopyShader.d.ts +1 -1
- package/dist/shaders/DepthLimitedBlurShader.d.ts +2 -2
- package/dist/shaders/DepthLimitedBlurShader.js +2 -2
- package/dist/shaders/DepthLimitedBlurShader.mjs +2 -2
- package/dist/shaders/DotScreenShader.js +2 -2
- package/dist/shaders/DotScreenShader.mjs +2 -2
- package/dist/shaders/FXAAShader.js +1 -1
- package/dist/shaders/FXAAShader.mjs +1 -1
- package/dist/shaders/FreiChenShader.js +1 -1
- package/dist/shaders/FreiChenShader.mjs +1 -1
- package/dist/shaders/GammaCorrectionShader.d.ts +1 -1
- package/dist/shaders/GodRaysShader.js +4 -4
- package/dist/shaders/GodRaysShader.mjs +4 -4
- package/dist/shaders/HorizontalBlurShader.d.ts +1 -1
- package/dist/shaders/LuminosityHighPassShader.js +1 -1
- package/dist/shaders/LuminosityHighPassShader.mjs +1 -1
- package/dist/shaders/NormalMapShader.js +2 -2
- package/dist/shaders/NormalMapShader.mjs +2 -2
- package/dist/shaders/SAOShader.d.ts +2 -2
- package/dist/shaders/SAOShader.js +3 -3
- package/dist/shaders/SAOShader.mjs +3 -3
- package/dist/shaders/SMAAShader.js +3 -3
- package/dist/shaders/SMAAShader.mjs +3 -3
- package/dist/shaders/SSAOShader.js +4 -4
- package/dist/shaders/SSAOShader.mjs +4 -4
- package/dist/shaders/SSRShader.js +4 -4
- package/dist/shaders/SSRShader.mjs +4 -4
- package/dist/shaders/SobelOperatorShader.js +1 -1
- package/dist/shaders/SobelOperatorShader.mjs +1 -1
- package/dist/shaders/SubsurfaceScatteringShader.d.ts +2 -2
- package/dist/shaders/SubsurfaceScatteringShader.js +91 -52
- package/dist/shaders/SubsurfaceScatteringShader.mjs +91 -52
- package/dist/shaders/ToonShader.js +25 -25
- package/dist/shaders/ToonShader.mjs +25 -25
- package/dist/shaders/TriangleBlurShader.js +1 -1
- package/dist/shaders/TriangleBlurShader.mjs +1 -1
- package/dist/shaders/VerticalBlurShader.d.ts +1 -1
- package/dist/shaders/VolumeShader.js +2 -2
- package/dist/shaders/VolumeShader.mjs +2 -2
- package/dist/shaders/types.d.ts +2 -2
- package/dist/types/Loader.d.ts +4 -0
- package/dist/types/Loader.js +26 -0
- package/dist/types/Loader.mjs +9 -0
- package/dist/types/shared.d.ts +2 -2
- package/dist/types/utils.d.ts +1 -1
- package/dist/utils/BufferGeometryUtils.d.ts +2 -2
- package/dist/utils/BufferGeometryUtils.js +1 -1
- package/dist/utils/BufferGeometryUtils.mjs +1 -1
- package/dist/utils/RoughnessMipmapper.d.ts +8 -0
- package/dist/utils/RoughnessMipmapper.js +79 -75
- package/dist/utils/RoughnessMipmapper.mjs +79 -75
- package/dist/utils/ShadowMapViewer.js +103 -106
- package/dist/utils/ShadowMapViewer.mjs +103 -106
- package/dist/utils/SkeletonUtils.d.ts +5 -21
- package/dist/utils/SkeletonUtils.js +182 -263
- package/dist/utils/SkeletonUtils.mjs +183 -264
- package/dist/utils/UVsDebug.js +37 -42
- package/dist/utils/UVsDebug.mjs +37 -42
- package/dist/webxr/ARButton.d.ts +2 -1
- package/dist/webxr/OculusHandModel.d.ts +2 -1
- package/dist/webxr/OculusHandPointerModel.d.ts +2 -2
- package/dist/webxr/OculusHandPointerModel.js +2 -2
- package/dist/webxr/OculusHandPointerModel.mjs +2 -2
- package/dist/webxr/VRButton.d.ts +2 -1
- package/dist/webxr/XRHandPrimitiveModel.js +2 -2
- package/dist/webxr/XRHandPrimitiveModel.mjs +2 -2
- package/package.json +5 -6
- package/dist/custom.d.ts +0 -5
- package/dist/loaders/NodeMaterialLoader.js +0 -146
- package/dist/loaders/NodeMaterialLoader.mjs +0 -146
- package/dist/nodes/Nodes.js +0 -347
- package/dist/nodes/Nodes.mjs +0 -347
- package/dist/nodes/ShaderNode.js +0 -408
- package/dist/nodes/ShaderNode.mjs +0 -408
- package/dist/nodes/accessors/BufferNode.js +0 -14
- package/dist/nodes/accessors/BufferNode.mjs +0 -15
- package/dist/nodes/accessors/CameraNode.js +0 -43
- package/dist/nodes/accessors/CameraNode.mjs +0 -44
- package/dist/nodes/accessors/CubeTextureNode.js +0 -41
- package/dist/nodes/accessors/CubeTextureNode.mjs +0 -42
- package/dist/nodes/accessors/MaterialNode.js +0 -70
- package/dist/nodes/accessors/MaterialNode.mjs +0 -71
- package/dist/nodes/accessors/MaterialReferenceNode.js +0 -13
- package/dist/nodes/accessors/MaterialReferenceNode.mjs +0 -14
- package/dist/nodes/accessors/ModelNode.js +0 -8
- package/dist/nodes/accessors/ModelNode.mjs +0 -9
- package/dist/nodes/accessors/ModelViewProjectionNode.js +0 -23
- package/dist/nodes/accessors/ModelViewProjectionNode.mjs +0 -24
- package/dist/nodes/accessors/NormalNode.js +0 -61
- package/dist/nodes/accessors/NormalNode.mjs +0 -62
- package/dist/nodes/accessors/Object3DNode.js +0 -75
- package/dist/nodes/accessors/Object3DNode.mjs +0 -76
- package/dist/nodes/accessors/PointUVNode.js +0 -12
- package/dist/nodes/accessors/PointUVNode.mjs +0 -13
- package/dist/nodes/accessors/PositionNode.js +0 -64
- package/dist/nodes/accessors/PositionNode.mjs +0 -65
- package/dist/nodes/accessors/ReferenceNode.js +0 -36
- package/dist/nodes/accessors/ReferenceNode.mjs +0 -37
- package/dist/nodes/accessors/ReflectNode.js +0 -42
- package/dist/nodes/accessors/ReflectNode.mjs +0 -43
- package/dist/nodes/accessors/SkinningNode.js +0 -57
- package/dist/nodes/accessors/SkinningNode.mjs +0 -58
- package/dist/nodes/accessors/TextureNode.js +0 -53
- package/dist/nodes/accessors/TextureNode.mjs +0 -54
- package/dist/nodes/accessors/UVNode.js +0 -22
- package/dist/nodes/accessors/UVNode.mjs +0 -23
- package/dist/nodes/core/ArrayUniformNode.js +0 -13
- package/dist/nodes/core/ArrayUniformNode.mjs +0 -14
- package/dist/nodes/core/AttributeNode.js +0 -29
- package/dist/nodes/core/AttributeNode.mjs +0 -30
- package/dist/nodes/core/BypassNode.js +0 -21
- package/dist/nodes/core/BypassNode.mjs +0 -22
- package/dist/nodes/core/CodeNode.js +0 -27
- package/dist/nodes/core/CodeNode.mjs +0 -28
- package/dist/nodes/core/ConstNode.js +0 -13
- package/dist/nodes/core/ConstNode.mjs +0 -14
- package/dist/nodes/core/ContextNode.js +0 -21
- package/dist/nodes/core/ContextNode.mjs +0 -22
- package/dist/nodes/core/ExpressionNode.js +0 -18
- package/dist/nodes/core/ExpressionNode.mjs +0 -19
- package/dist/nodes/core/FunctionCallNode.js +0 -36
- package/dist/nodes/core/FunctionCallNode.mjs +0 -37
- package/dist/nodes/core/FunctionNode.js +0 -55
- package/dist/nodes/core/FunctionNode.mjs +0 -56
- package/dist/nodes/core/InputNode.js +0 -37
- package/dist/nodes/core/InputNode.mjs +0 -38
- package/dist/nodes/core/Node.js +0 -138
- package/dist/nodes/core/Node.mjs +0 -139
- package/dist/nodes/core/NodeAttribute.js +0 -9
- package/dist/nodes/core/NodeAttribute.mjs +0 -10
- package/dist/nodes/core/NodeBuilder.js +0 -402
- package/dist/nodes/core/NodeBuilder.mjs +0 -402
- package/dist/nodes/core/NodeCode.js +0 -10
- package/dist/nodes/core/NodeCode.mjs +0 -11
- package/dist/nodes/core/NodeFrame.js +0 -34
- package/dist/nodes/core/NodeFrame.mjs +0 -35
- package/dist/nodes/core/NodeFunctionInput.js +0 -12
- package/dist/nodes/core/NodeFunctionInput.mjs +0 -13
- package/dist/nodes/core/NodeKeywords.js +0 -43
- package/dist/nodes/core/NodeKeywords.mjs +0 -44
- package/dist/nodes/core/NodeUniform.js +0 -17
- package/dist/nodes/core/NodeUniform.mjs +0 -18
- package/dist/nodes/core/NodeUtils.js +0 -57
- package/dist/nodes/core/NodeUtils.mjs +0 -57
- package/dist/nodes/core/NodeVar.js +0 -9
- package/dist/nodes/core/NodeVar.mjs +0 -10
- package/dist/nodes/core/NodeVary.js +0 -9
- package/dist/nodes/core/NodeVary.mjs +0 -10
- package/dist/nodes/core/PropertyNode.js +0 -20
- package/dist/nodes/core/PropertyNode.mjs +0 -21
- package/dist/nodes/core/TempNode.js +0 -24
- package/dist/nodes/core/TempNode.mjs +0 -25
- package/dist/nodes/core/UniformNode.js +0 -22
- package/dist/nodes/core/UniformNode.mjs +0 -23
- package/dist/nodes/core/VarNode.js +0 -30
- package/dist/nodes/core/VarNode.mjs +0 -31
- package/dist/nodes/core/VaryNode.js +0 -29
- package/dist/nodes/core/VaryNode.mjs +0 -30
- package/dist/nodes/core/constants.js +0 -24
- package/dist/nodes/core/constants.mjs +0 -24
- package/dist/nodes/display/ColorSpaceNode.js +0 -62
- package/dist/nodes/display/ColorSpaceNode.mjs +0 -62
- package/dist/nodes/display/NormalMapNode.js +0 -53
- package/dist/nodes/display/NormalMapNode.mjs +0 -54
- package/dist/nodes/fog/FogNode.js +0 -14
- package/dist/nodes/fog/FogNode.mjs +0 -15
- package/dist/nodes/fog/FogRangeNode.js +0 -16
- package/dist/nodes/fog/FogRangeNode.mjs +0 -17
- package/dist/nodes/functions/BSDFs.js +0 -64
- package/dist/nodes/functions/BSDFs.mjs +0 -64
- package/dist/nodes/lights/LightContextNode.js +0 -34
- package/dist/nodes/lights/LightContextNode.mjs +0 -35
- package/dist/nodes/lights/LightNode.js +0 -57
- package/dist/nodes/lights/LightNode.mjs +0 -58
- package/dist/nodes/lights/LightsNode.js +0 -58
- package/dist/nodes/lights/LightsNode.mjs +0 -59
- package/dist/nodes/loaders/NodeLoader.js +0 -195
- package/dist/nodes/loaders/NodeLoader.mjs +0 -196
- package/dist/nodes/loaders/NodeMaterialLoader.js +0 -23
- package/dist/nodes/loaders/NodeMaterialLoader.mjs +0 -24
- package/dist/nodes/loaders/NodeObjectLoader.js +0 -39
- package/dist/nodes/loaders/NodeObjectLoader.mjs +0 -40
- package/dist/nodes/materials/LineBasicNodeMaterial.js +0 -26
- package/dist/nodes/materials/LineBasicNodeMaterial.mjs +0 -27
- package/dist/nodes/materials/Materials.js +0 -24
- package/dist/nodes/materials/Materials.mjs +0 -24
- package/dist/nodes/materials/MeshBasicNodeMaterial.js +0 -27
- package/dist/nodes/materials/MeshBasicNodeMaterial.mjs +0 -28
- package/dist/nodes/materials/MeshStandardNodeMaterial.js +0 -40
- package/dist/nodes/materials/MeshStandardNodeMaterial.mjs +0 -41
- package/dist/nodes/materials/NodeMaterial.js +0 -63
- package/dist/nodes/materials/NodeMaterial.mjs +0 -64
- package/dist/nodes/materials/PointsNodeMaterial.js +0 -29
- package/dist/nodes/materials/PointsNodeMaterial.mjs +0 -30
- package/dist/nodes/math/CondNode.js +0 -40
- package/dist/nodes/math/CondNode.mjs +0 -41
- package/dist/nodes/math/MathNode.js +0 -165
- package/dist/nodes/math/MathNode.mjs +0 -166
- package/dist/nodes/math/OperatorNode.js +0 -102
- package/dist/nodes/math/OperatorNode.mjs +0 -103
- package/dist/nodes/procedural/CheckerNode.js +0 -20
- package/dist/nodes/procedural/CheckerNode.mjs +0 -21
- package/dist/nodes/utils/ArrayElementNode.js +0 -18
- package/dist/nodes/utils/ArrayElementNode.mjs +0 -19
- package/dist/nodes/utils/ConvertNode.js +0 -24
- package/dist/nodes/utils/ConvertNode.mjs +0 -25
- package/dist/nodes/utils/JoinNode.js +0 -25
- package/dist/nodes/utils/JoinNode.mjs +0 -26
- package/dist/nodes/utils/MatcapUVNode.js +0 -15
- package/dist/nodes/utils/MatcapUVNode.mjs +0 -16
- package/dist/nodes/utils/OscNode.js +0 -49
- package/dist/nodes/utils/OscNode.mjs +0 -50
- package/dist/nodes/utils/SplitNode.js +0 -44
- package/dist/nodes/utils/SplitNode.mjs +0 -45
- package/dist/nodes/utils/SpriteSheetUVNode.js +0 -39
- package/dist/nodes/utils/SpriteSheetUVNode.mjs +0 -40
- package/dist/nodes/utils/TimerNode.js +0 -43
- package/dist/nodes/utils/TimerNode.mjs +0 -44
- package/dist/offscreen/jank.js +0 -26
- package/dist/offscreen/jank.mjs +0 -27
- package/dist/offscreen/offscreen.js +0 -8
- package/dist/offscreen/offscreen.mjs +0 -7
- package/dist/offscreen/scene.js +0 -68
- package/dist/offscreen/scene.mjs +0 -52
- package/dist/renderers/nodes/accessors/CameraNode.js +0 -62
- package/dist/renderers/nodes/accessors/CameraNode.mjs +0 -63
- package/dist/renderers/nodes/accessors/ModelNode.js +0 -60
- package/dist/renderers/nodes/accessors/ModelNode.mjs +0 -61
- package/dist/renderers/nodes/accessors/ModelViewProjectionNode.js +0 -20
- package/dist/renderers/nodes/accessors/ModelViewProjectionNode.mjs +0 -21
- package/dist/renderers/nodes/accessors/NormalNode.js +0 -60
- package/dist/renderers/nodes/accessors/NormalNode.mjs +0 -61
- package/dist/renderers/nodes/accessors/PositionNode.js +0 -29
- package/dist/renderers/nodes/accessors/PositionNode.mjs +0 -30
- package/dist/renderers/nodes/accessors/UVNode.js +0 -12
- package/dist/renderers/nodes/accessors/UVNode.mjs +0 -13
- package/dist/renderers/nodes/core/AttributeNode.js +0 -34
- package/dist/renderers/nodes/core/AttributeNode.mjs +0 -35
- package/dist/renderers/nodes/core/InputNode.js +0 -30
- package/dist/renderers/nodes/core/InputNode.mjs +0 -31
- package/dist/renderers/nodes/core/Node.js +0 -33
- package/dist/renderers/nodes/core/Node.mjs +0 -34
- package/dist/renderers/nodes/core/NodeAttribute.js +0 -9
- package/dist/renderers/nodes/core/NodeAttribute.mjs +0 -10
- package/dist/renderers/nodes/core/NodeBuilder.js +0 -248
- package/dist/renderers/nodes/core/NodeBuilder.mjs +0 -249
- package/dist/renderers/nodes/core/NodeFrame.js +0 -34
- package/dist/renderers/nodes/core/NodeFrame.mjs +0 -35
- package/dist/renderers/nodes/core/NodeSlot.js +0 -9
- package/dist/renderers/nodes/core/NodeSlot.mjs +0 -10
- package/dist/renderers/nodes/core/NodeUniform.js +0 -17
- package/dist/renderers/nodes/core/NodeUniform.mjs +0 -18
- package/dist/renderers/nodes/core/NodeVary.js +0 -10
- package/dist/renderers/nodes/core/NodeVary.mjs +0 -11
- package/dist/renderers/nodes/core/VaryNode.js +0 -21
- package/dist/renderers/nodes/core/VaryNode.mjs +0 -22
- package/dist/renderers/nodes/core/constants.js +0 -22
- package/dist/renderers/nodes/core/constants.mjs +0 -22
- package/dist/renderers/nodes/inputs/ColorNode.js +0 -10
- package/dist/renderers/nodes/inputs/ColorNode.mjs +0 -11
- package/dist/renderers/nodes/inputs/FloatNode.js +0 -10
- package/dist/renderers/nodes/inputs/FloatNode.mjs +0 -11
- package/dist/renderers/nodes/inputs/Matrix3Node.js +0 -11
- package/dist/renderers/nodes/inputs/Matrix3Node.mjs +0 -12
- package/dist/renderers/nodes/inputs/Matrix4Node.js +0 -11
- package/dist/renderers/nodes/inputs/Matrix4Node.mjs +0 -12
- package/dist/renderers/nodes/inputs/TextureNode.js +0 -19
- package/dist/renderers/nodes/inputs/TextureNode.mjs +0 -20
- package/dist/renderers/nodes/inputs/Vector2Node.js +0 -10
- package/dist/renderers/nodes/inputs/Vector2Node.mjs +0 -11
- package/dist/renderers/nodes/inputs/Vector3Node.js +0 -11
- package/dist/renderers/nodes/inputs/Vector3Node.mjs +0 -12
- package/dist/renderers/nodes/inputs/Vector4Node.js +0 -11
- package/dist/renderers/nodes/inputs/Vector4Node.mjs +0 -12
- package/dist/renderers/nodes/math/MathNode.js +0 -54
- package/dist/renderers/nodes/math/MathNode.mjs +0 -55
- package/dist/renderers/nodes/math/OperatorNode.js +0 -41
- package/dist/renderers/nodes/math/OperatorNode.mjs +0 -42
- package/dist/renderers/nodes/utils/SwitchNode.js +0 -19
- package/dist/renderers/nodes/utils/SwitchNode.mjs +0 -20
- package/dist/renderers/nodes/utils/TimerNode.js +0 -13
- package/dist/renderers/nodes/utils/TimerNode.mjs +0 -14
- package/dist/renderers/webgpu/WebGPU.js +0 -23
- package/dist/renderers/webgpu/WebGPU.mjs +0 -24
- package/dist/renderers/webgpu/WebGPUAttributes.js +0 -68
- package/dist/renderers/webgpu/WebGPUAttributes.mjs +0 -69
- package/dist/renderers/webgpu/WebGPUBackground.js +0 -60
- package/dist/renderers/webgpu/WebGPUBackground.mjs +0 -61
- package/dist/renderers/webgpu/WebGPUBinding.js +0 -13
- package/dist/renderers/webgpu/WebGPUBinding.mjs +0 -14
- package/dist/renderers/webgpu/WebGPUBindings.js +0 -154
- package/dist/renderers/webgpu/WebGPUBindings.mjs +0 -155
- package/dist/renderers/webgpu/WebGPUComputePipelines.js +0 -43
- package/dist/renderers/webgpu/WebGPUComputePipelines.mjs +0 -44
- package/dist/renderers/webgpu/WebGPUGeometries.js +0 -40
- package/dist/renderers/webgpu/WebGPUGeometries.mjs +0 -41
- package/dist/renderers/webgpu/WebGPUInfo.js +0 -45
- package/dist/renderers/webgpu/WebGPUInfo.mjs +0 -46
- package/dist/renderers/webgpu/WebGPUObjects.js +0 -24
- package/dist/renderers/webgpu/WebGPUObjects.mjs +0 -25
- package/dist/renderers/webgpu/WebGPUProperties.js +0 -21
- package/dist/renderers/webgpu/WebGPUProperties.mjs +0 -22
- package/dist/renderers/webgpu/WebGPURenderLists.js +0 -118
- package/dist/renderers/webgpu/WebGPURenderLists.mjs +0 -119
- package/dist/renderers/webgpu/WebGPURenderPipelines.js +0 -545
- package/dist/renderers/webgpu/WebGPURenderPipelines.mjs +0 -546
- package/dist/renderers/webgpu/WebGPURenderer.js +0 -596
- package/dist/renderers/webgpu/WebGPURenderer.mjs +0 -575
- package/dist/renderers/webgpu/WebGPUSampledTexture.js +0 -40
- package/dist/renderers/webgpu/WebGPUSampledTexture.mjs +0 -40
- package/dist/renderers/webgpu/WebGPUSampler.js +0 -14
- package/dist/renderers/webgpu/WebGPUSampler.mjs +0 -15
- package/dist/renderers/webgpu/WebGPUStorageBuffer.js +0 -14
- package/dist/renderers/webgpu/WebGPUStorageBuffer.mjs +0 -15
- package/dist/renderers/webgpu/WebGPUTextureRenderer.js +0 -22
- package/dist/renderers/webgpu/WebGPUTextureRenderer.mjs +0 -23
- package/dist/renderers/webgpu/WebGPUTextureUtils.js +0 -97
- package/dist/renderers/webgpu/WebGPUTextureUtils.mjs +0 -98
- package/dist/renderers/webgpu/WebGPUTextures.js +0 -483
- package/dist/renderers/webgpu/WebGPUTextures.mjs +0 -484
- package/dist/renderers/webgpu/WebGPUUniform.js +0 -81
- package/dist/renderers/webgpu/WebGPUUniform.mjs +0 -81
- package/dist/renderers/webgpu/WebGPUUniformsGroup.js +0 -175
- package/dist/renderers/webgpu/WebGPUUniformsGroup.mjs +0 -176
- package/dist/renderers/webgpu/constants.js +0 -241
- package/dist/renderers/webgpu/constants.mjs +0 -241
- package/dist/renderers/webgpu/nodes/ShaderLib.js +0 -41
- package/dist/renderers/webgpu/nodes/ShaderLib.mjs +0 -42
- package/dist/renderers/webgpu/nodes/WebGPUNodeBuilder.js +0 -164
- package/dist/renderers/webgpu/nodes/WebGPUNodeBuilder.mjs +0 -165
- package/dist/renderers/webgpu/nodes/WebGPUNodeUniform.js +0 -73
- package/dist/renderers/webgpu/nodes/WebGPUNodeUniform.mjs +0 -73
- package/dist/renderers/webgpu/nodes/WebGPUNodeUniformsGroup.js +0 -14
- package/dist/renderers/webgpu/nodes/WebGPUNodeUniformsGroup.mjs +0 -15
- package/dist/renderers/webgpu/nodes/WebGPUNodes.js +0 -39
- package/dist/renderers/webgpu/nodes/WebGPUNodes.mjs +0 -40
@@ -1,13 +1,87 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
import { PlaneGeometry, ShaderMaterial, Uniform, Mesh, PerspectiveCamera, Scene, WebGLRenderer, Texture, NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearFilter, LinearMipmapNearestFilter, LinearMipmapLinearFilter, ClampToEdgeWrapping, RepeatWrapping, MirroredRepeatWrapping, Color, MathUtils, Vector3, SRGBColorSpace, CompressedTexture, Source, NoColorSpace, RGBAFormat, DoubleSide, REVISION, BufferAttribute, PropertyBinding, InterpolateDiscrete, Matrix4, InterpolateLinear } from "three";
|
2
|
+
let _renderer;
|
3
|
+
let fullscreenQuadGeometry;
|
4
|
+
let fullscreenQuadMaterial;
|
5
|
+
let fullscreenQuad;
|
6
|
+
function decompress(texture, maxTextureSize = Infinity, renderer = null) {
|
7
|
+
if (!fullscreenQuadGeometry)
|
8
|
+
fullscreenQuadGeometry = new PlaneGeometry(2, 2, 1, 1);
|
9
|
+
if (!fullscreenQuadMaterial)
|
10
|
+
fullscreenQuadMaterial = new ShaderMaterial({
|
11
|
+
uniforms: { blitTexture: new Uniform(texture) },
|
12
|
+
vertexShader: (
|
13
|
+
/* glsl */
|
14
|
+
`
|
15
|
+
varying vec2 vUv;
|
16
|
+
void main(){
|
17
|
+
vUv = uv;
|
18
|
+
gl_Position = vec4(position.xy * 1.0,0.,.999999);
|
19
|
+
}
|
20
|
+
`
|
21
|
+
),
|
22
|
+
fragmentShader: (
|
23
|
+
/* glsl */
|
24
|
+
`
|
25
|
+
uniform sampler2D blitTexture;
|
26
|
+
varying vec2 vUv;
|
27
|
+
|
28
|
+
void main(){
|
29
|
+
gl_FragColor = vec4(vUv.xy, 0, 1);
|
30
|
+
|
31
|
+
#ifdef IS_SRGB
|
32
|
+
gl_FragColor = LinearTosRGB( texture2D( blitTexture, vUv) );
|
33
|
+
#else
|
34
|
+
gl_FragColor = texture2D( blitTexture, vUv);
|
35
|
+
#endif
|
36
|
+
}
|
37
|
+
`
|
38
|
+
)
|
39
|
+
});
|
40
|
+
fullscreenQuadMaterial.uniforms.blitTexture.value = texture;
|
41
|
+
fullscreenQuadMaterial.defines.IS_SRGB = "colorSpace" in texture ? texture.colorSpace === "srgb" : texture.encoding === 3001;
|
42
|
+
fullscreenQuadMaterial.needsUpdate = true;
|
43
|
+
if (!fullscreenQuad) {
|
44
|
+
fullscreenQuad = new Mesh(fullscreenQuadGeometry, fullscreenQuadMaterial);
|
45
|
+
fullscreenQuad.frustrumCulled = false;
|
46
|
+
}
|
47
|
+
const _camera = new PerspectiveCamera();
|
48
|
+
const _scene = new Scene();
|
49
|
+
_scene.add(fullscreenQuad);
|
50
|
+
if (!renderer) {
|
51
|
+
renderer = _renderer = new WebGLRenderer({ antialias: false });
|
52
|
+
}
|
53
|
+
renderer.setSize(Math.min(texture.image.width, maxTextureSize), Math.min(texture.image.height, maxTextureSize));
|
54
|
+
renderer.clear();
|
55
|
+
renderer.render(_scene, _camera);
|
56
|
+
const readableTexture = new Texture(renderer.domElement);
|
57
|
+
readableTexture.minFilter = texture.minFilter;
|
58
|
+
readableTexture.magFilter = texture.magFilter;
|
59
|
+
readableTexture.wrapS = texture.wrapS;
|
60
|
+
readableTexture.wrapT = texture.wrapT;
|
61
|
+
readableTexture.name = texture.name;
|
62
|
+
if (_renderer) {
|
63
|
+
_renderer.dispose();
|
64
|
+
_renderer = null;
|
65
|
+
}
|
66
|
+
return readableTexture;
|
67
|
+
}
|
68
|
+
const KHR_mesh_quantization_ExtraAttrTypes = {
|
69
|
+
POSITION: [
|
70
|
+
"byte",
|
71
|
+
"byte normalized",
|
72
|
+
"unsigned byte",
|
73
|
+
"unsigned byte normalized",
|
74
|
+
"short",
|
75
|
+
"short normalized",
|
76
|
+
"unsigned short",
|
77
|
+
"unsigned short normalized"
|
78
|
+
],
|
79
|
+
NORMAL: ["byte normalized", "short normalized"],
|
80
|
+
TANGENT: ["byte normalized", "short normalized"],
|
81
|
+
TEXCOORD: ["byte", "byte normalized", "unsigned byte", "short", "short normalized", "unsigned short"]
|
6
82
|
};
|
7
|
-
import { PropertyBinding, InterpolateLinear, NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearFilter, LinearMipmapNearestFilter, LinearMipmapLinearFilter, ClampToEdgeWrapping, RepeatWrapping, MirroredRepeatWrapping, Vector3, RGBAFormat, ShaderMaterial, MeshStandardMaterial, MeshBasicMaterial, MeshPhysicalMaterial, MeshMatcapMaterial, MeshNormalMaterial, MeshPhongMaterial, MeshToonMaterial, MeshLambertMaterial, DoubleSide, LineSegments, LineLoop, Line, Points, MeshDepthMaterial, InterleavedBufferAttribute, BufferAttribute, Object3D, Material, OrthographicCamera, PerspectiveCamera, MathUtils, InterpolateDiscrete, SkinnedMesh, Matrix4, Mesh, Camera, Scene, DirectionalLight, PointLight, SpotLight } from "three";
|
8
83
|
class GLTFExporter {
|
9
84
|
constructor() {
|
10
|
-
__publicField(this, "pluginCallbacks");
|
11
85
|
this.pluginCallbacks = [];
|
12
86
|
this.register(function(writer) {
|
13
87
|
return new GLTFLightExtension(writer);
|
@@ -15,15 +89,33 @@ class GLTFExporter {
|
|
15
89
|
this.register(function(writer) {
|
16
90
|
return new GLTFMaterialsUnlitExtension(writer);
|
17
91
|
});
|
18
|
-
this.register(function(writer) {
|
19
|
-
return new GLTFMaterialsPBRSpecularGlossiness(writer);
|
20
|
-
});
|
21
92
|
this.register(function(writer) {
|
22
93
|
return new GLTFMaterialsTransmissionExtension(writer);
|
23
94
|
});
|
24
95
|
this.register(function(writer) {
|
25
96
|
return new GLTFMaterialsVolumeExtension(writer);
|
26
97
|
});
|
98
|
+
this.register(function(writer) {
|
99
|
+
return new GLTFMaterialsIorExtension(writer);
|
100
|
+
});
|
101
|
+
this.register(function(writer) {
|
102
|
+
return new GLTFMaterialsSpecularExtension(writer);
|
103
|
+
});
|
104
|
+
this.register(function(writer) {
|
105
|
+
return new GLTFMaterialsClearcoatExtension(writer);
|
106
|
+
});
|
107
|
+
this.register(function(writer) {
|
108
|
+
return new GLTFMaterialsIridescenceExtension(writer);
|
109
|
+
});
|
110
|
+
this.register(function(writer) {
|
111
|
+
return new GLTFMaterialsSheenExtension(writer);
|
112
|
+
});
|
113
|
+
this.register(function(writer) {
|
114
|
+
return new GLTFMaterialsAnisotropyExtension(writer);
|
115
|
+
});
|
116
|
+
this.register(function(writer) {
|
117
|
+
return new GLTFMaterialsEmissiveStrengthExtension(writer);
|
118
|
+
});
|
27
119
|
}
|
28
120
|
register(callback) {
|
29
121
|
if (this.pluginCallbacks.indexOf(callback) === -1) {
|
@@ -37,126 +129,29 @@ class GLTFExporter {
|
|
37
129
|
}
|
38
130
|
return this;
|
39
131
|
}
|
40
|
-
|
132
|
+
/**
|
133
|
+
* Parse scenes and generate GLTF output
|
134
|
+
* @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
|
135
|
+
* @param {Function} onDone Callback on completed
|
136
|
+
* @param {Function} onError Callback on errors
|
137
|
+
* @param {Object} options options
|
138
|
+
*/
|
139
|
+
parse(input, onDone, onError, options) {
|
41
140
|
const writer = new GLTFWriter();
|
42
141
|
const plugins = [];
|
43
142
|
for (let i = 0, il = this.pluginCallbacks.length; i < il; i++) {
|
44
143
|
plugins.push(this.pluginCallbacks[i](writer));
|
45
144
|
}
|
46
145
|
writer.setPlugins(plugins);
|
47
|
-
writer.write(input, onDone, options);
|
146
|
+
writer.write(input, onDone, options).catch(onError);
|
48
147
|
}
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
insertKeyframe: function(track, time) {
|
55
|
-
const tolerance = 1e-3;
|
56
|
-
const valueSize = track.getValueSize();
|
57
|
-
const times = new track.TimeBufferType(track.times.length + 1);
|
58
|
-
const values = new track.ValueBufferType(track.values.length + valueSize);
|
59
|
-
const interpolant = track.createInterpolant(new track.ValueBufferType(valueSize));
|
60
|
-
let index;
|
61
|
-
if (track.times.length === 0) {
|
62
|
-
times[0] = time;
|
63
|
-
for (let i = 0; i < valueSize; i++) {
|
64
|
-
values[i] = 0;
|
65
|
-
}
|
66
|
-
index = 0;
|
67
|
-
} else if (time < track.times[0]) {
|
68
|
-
if (Math.abs(track.times[0] - time) < tolerance)
|
69
|
-
return 0;
|
70
|
-
times[0] = time;
|
71
|
-
times.set(track.times, 1);
|
72
|
-
values.set(interpolant.evaluate(time), 0);
|
73
|
-
values.set(track.values, valueSize);
|
74
|
-
index = 0;
|
75
|
-
} else if (time > track.times[track.times.length - 1]) {
|
76
|
-
if (Math.abs(track.times[track.times.length - 1] - time) < tolerance) {
|
77
|
-
return track.times.length - 1;
|
78
|
-
}
|
79
|
-
times[times.length - 1] = time;
|
80
|
-
times.set(track.times, 0);
|
81
|
-
values.set(track.values, 0);
|
82
|
-
values.set(interpolant.evaluate(time), track.values.length);
|
83
|
-
index = times.length - 1;
|
84
|
-
} else {
|
85
|
-
for (let i = 0; i < track.times.length; i++) {
|
86
|
-
if (Math.abs(track.times[i] - time) < tolerance)
|
87
|
-
return i;
|
88
|
-
if (track.times[i] < time && track.times[i + 1] > time) {
|
89
|
-
times.set(track.times.slice(0, i + 1), 0);
|
90
|
-
times[i + 1] = time;
|
91
|
-
times.set(track.times.slice(i + 1), i + 2);
|
92
|
-
values.set(track.values.slice(0, (i + 1) * valueSize), 0);
|
93
|
-
values.set(interpolant.evaluate(time), (i + 1) * valueSize);
|
94
|
-
values.set(track.values.slice((i + 1) * valueSize), (i + 2) * valueSize);
|
95
|
-
index = i + 1;
|
96
|
-
break;
|
97
|
-
}
|
98
|
-
}
|
99
|
-
}
|
100
|
-
track.times = times;
|
101
|
-
track.values = values;
|
102
|
-
return index;
|
103
|
-
},
|
104
|
-
mergeMorphTargetTracks: function(clip, root) {
|
105
|
-
const tracks = [];
|
106
|
-
const mergedTracks = {};
|
107
|
-
const sourceTracks = clip.tracks;
|
108
|
-
for (let i = 0; i < sourceTracks.length; ++i) {
|
109
|
-
let sourceTrack = sourceTracks[i];
|
110
|
-
const sourceTrackBinding = PropertyBinding.parseTrackName(sourceTrack.name);
|
111
|
-
const sourceTrackNode = PropertyBinding.findNode(root, sourceTrackBinding.nodeName);
|
112
|
-
if (sourceTrackBinding.propertyName !== "morphTargetInfluences" || sourceTrackBinding.propertyIndex === void 0) {
|
113
|
-
tracks.push(sourceTrack);
|
114
|
-
continue;
|
115
|
-
}
|
116
|
-
if (
|
117
|
-
// @ts-expect-error
|
118
|
-
sourceTrack.createInterpolant !== sourceTrack.InterpolantFactoryMethodDiscrete && // @ts-expect-error
|
119
|
-
sourceTrack.createInterpolant !== sourceTrack.InterpolantFactoryMethodLinear
|
120
|
-
) {
|
121
|
-
if (sourceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
|
122
|
-
throw new Error("THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.");
|
123
|
-
}
|
124
|
-
console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead.");
|
125
|
-
sourceTrack = sourceTrack.clone();
|
126
|
-
sourceTrack.setInterpolation(InterpolateLinear);
|
127
|
-
}
|
128
|
-
const targetCount = sourceTrackNode.morphTargetInfluences.length;
|
129
|
-
const targetIndex = sourceTrackNode.morphTargetDictionary[sourceTrackBinding.propertyIndex];
|
130
|
-
if (targetIndex === void 0) {
|
131
|
-
throw new Error("THREE.GLTFExporter: Morph target name not found: " + sourceTrackBinding.propertyIndex);
|
132
|
-
}
|
133
|
-
let mergedTrack;
|
134
|
-
if (mergedTracks[sourceTrackNode.uuid] === void 0) {
|
135
|
-
mergedTrack = sourceTrack.clone();
|
136
|
-
const values = new mergedTrack.ValueBufferType(targetCount * mergedTrack.times.length);
|
137
|
-
for (let j = 0; j < mergedTrack.times.length; j++) {
|
138
|
-
values[j * targetCount + targetIndex] = mergedTrack.values[j];
|
139
|
-
}
|
140
|
-
mergedTrack.name = (sourceTrackBinding.nodeName || "") + ".morphTargetInfluences";
|
141
|
-
mergedTrack.values = values;
|
142
|
-
mergedTracks[sourceTrackNode.uuid] = mergedTrack;
|
143
|
-
tracks.push(mergedTrack);
|
144
|
-
continue;
|
145
|
-
}
|
146
|
-
const sourceInterpolant = sourceTrack.createInterpolant(new sourceTrack.ValueBufferType(1));
|
147
|
-
mergedTrack = mergedTracks[sourceTrackNode.uuid];
|
148
|
-
for (let j = 0; j < mergedTrack.times.length; j++) {
|
149
|
-
mergedTrack.values[j * targetCount + targetIndex] = sourceInterpolant.evaluate(mergedTrack.times[j]);
|
150
|
-
}
|
151
|
-
for (let j = 0; j < sourceTrack.times.length; j++) {
|
152
|
-
const keyframeIndex = this.insertKeyframe(mergedTrack, sourceTrack.times[j]);
|
153
|
-
mergedTrack.values[keyframeIndex * targetCount + targetIndex] = sourceTrack.values[j];
|
154
|
-
}
|
155
|
-
}
|
156
|
-
clip.tracks = tracks;
|
157
|
-
return clip;
|
148
|
+
parseAsync(input, options) {
|
149
|
+
const scope = this;
|
150
|
+
return new Promise(function(resolve, reject) {
|
151
|
+
scope.parse(input, resolve, reject, options);
|
152
|
+
});
|
158
153
|
}
|
159
|
-
}
|
154
|
+
}
|
160
155
|
const WEBGL_CONSTANTS = {
|
161
156
|
POINTS: 0,
|
162
157
|
LINES: 1,
|
@@ -165,10 +160,13 @@ const WEBGL_CONSTANTS = {
|
|
165
160
|
TRIANGLES: 4,
|
166
161
|
TRIANGLE_STRIP: 5,
|
167
162
|
TRIANGLE_FAN: 6,
|
163
|
+
BYTE: 5120,
|
168
164
|
UNSIGNED_BYTE: 5121,
|
165
|
+
SHORT: 5122,
|
169
166
|
UNSIGNED_SHORT: 5123,
|
170
|
-
|
167
|
+
INT: 5124,
|
171
168
|
UNSIGNED_INT: 5125,
|
169
|
+
FLOAT: 5126,
|
172
170
|
ARRAY_BUFFER: 34962,
|
173
171
|
ELEMENT_ARRAY_BUFFER: 34963,
|
174
172
|
NEAREST: 9728,
|
@@ -181,6 +179,7 @@ const WEBGL_CONSTANTS = {
|
|
181
179
|
MIRRORED_REPEAT: 33648,
|
182
180
|
REPEAT: 10497
|
183
181
|
};
|
182
|
+
const KHR_MESH_QUANTIZATION = "KHR_mesh_quantization";
|
184
183
|
const THREE_TO_WEBGL = {};
|
185
184
|
THREE_TO_WEBGL[NearestFilter] = WEBGL_CONSTANTS.NEAREST;
|
186
185
|
THREE_TO_WEBGL[NearestMipmapNearestFilter] = WEBGL_CONSTANTS.NEAREST_MIPMAP_NEAREST;
|
@@ -197,35 +196,103 @@ const PATH_PROPERTIES = {
|
|
197
196
|
quaternion: "rotation",
|
198
197
|
morphTargetInfluences: "weights"
|
199
198
|
};
|
199
|
+
const DEFAULT_SPECULAR_COLOR = new Color();
|
200
200
|
const GLB_HEADER_BYTES = 12;
|
201
201
|
const GLB_HEADER_MAGIC = 1179937895;
|
202
202
|
const GLB_VERSION = 2;
|
203
203
|
const GLB_CHUNK_PREFIX_BYTES = 8;
|
204
204
|
const GLB_CHUNK_TYPE_JSON = 1313821514;
|
205
205
|
const GLB_CHUNK_TYPE_BIN = 5130562;
|
206
|
+
function equalArray(array1, array2) {
|
207
|
+
return array1.length === array2.length && array1.every(function(element, index) {
|
208
|
+
return element === array2[index];
|
209
|
+
});
|
210
|
+
}
|
211
|
+
function stringToArrayBuffer(text) {
|
212
|
+
return new TextEncoder().encode(text).buffer;
|
213
|
+
}
|
214
|
+
function isIdentityMatrix(matrix) {
|
215
|
+
return equalArray(matrix.elements, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
216
|
+
}
|
217
|
+
function getMinMax(attribute, start, count) {
|
218
|
+
const output = {
|
219
|
+
min: new Array(attribute.itemSize).fill(Number.POSITIVE_INFINITY),
|
220
|
+
max: new Array(attribute.itemSize).fill(Number.NEGATIVE_INFINITY)
|
221
|
+
};
|
222
|
+
for (let i = start; i < start + count; i++) {
|
223
|
+
for (let a = 0; a < attribute.itemSize; a++) {
|
224
|
+
let value;
|
225
|
+
if (attribute.itemSize > 4) {
|
226
|
+
value = attribute.array[i * attribute.itemSize + a];
|
227
|
+
} else {
|
228
|
+
if (a === 0)
|
229
|
+
value = attribute.getX(i);
|
230
|
+
else if (a === 1)
|
231
|
+
value = attribute.getY(i);
|
232
|
+
else if (a === 2)
|
233
|
+
value = attribute.getZ(i);
|
234
|
+
else if (a === 3)
|
235
|
+
value = attribute.getW(i);
|
236
|
+
if (attribute.normalized === true) {
|
237
|
+
value = MathUtils.normalize(value, attribute.array);
|
238
|
+
}
|
239
|
+
}
|
240
|
+
output.min[a] = Math.min(output.min[a], value);
|
241
|
+
output.max[a] = Math.max(output.max[a], value);
|
242
|
+
}
|
243
|
+
}
|
244
|
+
return output;
|
245
|
+
}
|
246
|
+
function getPaddedBufferSize(bufferSize) {
|
247
|
+
return Math.ceil(bufferSize / 4) * 4;
|
248
|
+
}
|
249
|
+
function getPaddedArrayBuffer(arrayBuffer, paddingByte = 0) {
|
250
|
+
const paddedLength = getPaddedBufferSize(arrayBuffer.byteLength);
|
251
|
+
if (paddedLength !== arrayBuffer.byteLength) {
|
252
|
+
const array = new Uint8Array(paddedLength);
|
253
|
+
array.set(new Uint8Array(arrayBuffer));
|
254
|
+
if (paddingByte !== 0) {
|
255
|
+
for (let i = arrayBuffer.byteLength; i < paddedLength; i++) {
|
256
|
+
array[i] = paddingByte;
|
257
|
+
}
|
258
|
+
}
|
259
|
+
return array.buffer;
|
260
|
+
}
|
261
|
+
return arrayBuffer;
|
262
|
+
}
|
263
|
+
function getCanvas() {
|
264
|
+
if (typeof document === "undefined" && typeof OffscreenCanvas !== "undefined") {
|
265
|
+
return new OffscreenCanvas(1, 1);
|
266
|
+
}
|
267
|
+
return document.createElement("canvas");
|
268
|
+
}
|
269
|
+
function getToBlobPromise(canvas, mimeType) {
|
270
|
+
if (canvas.toBlob !== void 0) {
|
271
|
+
return new Promise((resolve) => canvas.toBlob(resolve, mimeType));
|
272
|
+
}
|
273
|
+
let quality;
|
274
|
+
if (mimeType === "image/jpeg") {
|
275
|
+
quality = 0.92;
|
276
|
+
} else if (mimeType === "image/webp") {
|
277
|
+
quality = 0.8;
|
278
|
+
}
|
279
|
+
return canvas.convertToBlob({
|
280
|
+
type: mimeType,
|
281
|
+
quality
|
282
|
+
});
|
283
|
+
}
|
206
284
|
class GLTFWriter {
|
207
285
|
constructor() {
|
208
|
-
__publicField(this, "plugins");
|
209
|
-
__publicField(this, "options");
|
210
|
-
__publicField(this, "pending");
|
211
|
-
__publicField(this, "buffers");
|
212
|
-
__publicField(this, "byteOffset");
|
213
|
-
__publicField(this, "nodeMap");
|
214
|
-
__publicField(this, "skins");
|
215
|
-
__publicField(this, "extensionsUsed");
|
216
|
-
__publicField(this, "uids");
|
217
|
-
__publicField(this, "uid");
|
218
|
-
__publicField(this, "json");
|
219
|
-
__publicField(this, "cache");
|
220
|
-
__publicField(this, "cachedCanvas");
|
221
286
|
this.plugins = [];
|
222
287
|
this.options = {};
|
223
288
|
this.pending = [];
|
224
289
|
this.buffers = [];
|
225
290
|
this.byteOffset = 0;
|
291
|
+
this.buffers = [];
|
226
292
|
this.nodeMap = /* @__PURE__ */ new Map();
|
227
293
|
this.skins = [];
|
228
294
|
this.extensionsUsed = {};
|
295
|
+
this.extensionsRequired = {};
|
229
296
|
this.uids = /* @__PURE__ */ new Map();
|
230
297
|
this.uid = 0;
|
231
298
|
this.json = {
|
@@ -242,7 +309,6 @@ class GLTFWriter {
|
|
242
309
|
textures: /* @__PURE__ */ new Map(),
|
243
310
|
images: /* @__PURE__ */ new Map()
|
244
311
|
};
|
245
|
-
this.cachedCanvas = null;
|
246
312
|
}
|
247
313
|
setPlugins(plugins) {
|
248
314
|
this.plugins = plugins;
|
@@ -253,85 +319,79 @@ class GLTFWriter {
|
|
253
319
|
* @param {Function} onDone Callback on completed
|
254
320
|
* @param {Object} options options
|
255
321
|
*/
|
256
|
-
write(input, onDone, options) {
|
322
|
+
async write(input, onDone, options = {}) {
|
257
323
|
this.options = Object.assign(
|
258
|
-
{},
|
259
324
|
{
|
260
325
|
// default options
|
261
326
|
binary: false,
|
262
327
|
trs: false,
|
263
328
|
onlyVisible: true,
|
264
|
-
truncateDrawRange: true,
|
265
|
-
embedImages: true,
|
266
329
|
maxTextureSize: Infinity,
|
267
330
|
animations: [],
|
268
331
|
includeCustomExtensions: false
|
269
332
|
},
|
270
333
|
options
|
271
334
|
);
|
272
|
-
if (this.options.animations
|
335
|
+
if (this.options.animations.length > 0) {
|
273
336
|
this.options.trs = true;
|
274
337
|
}
|
275
338
|
this.processInput(input);
|
339
|
+
await Promise.all(this.pending);
|
276
340
|
const writer = this;
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
};
|
317
|
-
}
|
341
|
+
const buffers = writer.buffers;
|
342
|
+
const json = writer.json;
|
343
|
+
options = writer.options;
|
344
|
+
const extensionsUsed = writer.extensionsUsed;
|
345
|
+
const extensionsRequired = writer.extensionsRequired;
|
346
|
+
const blob = new Blob(buffers, { type: "application/octet-stream" });
|
347
|
+
const extensionsUsedList = Object.keys(extensionsUsed);
|
348
|
+
const extensionsRequiredList = Object.keys(extensionsRequired);
|
349
|
+
if (extensionsUsedList.length > 0)
|
350
|
+
json.extensionsUsed = extensionsUsedList;
|
351
|
+
if (extensionsRequiredList.length > 0)
|
352
|
+
json.extensionsRequired = extensionsRequiredList;
|
353
|
+
if (json.buffers && json.buffers.length > 0)
|
354
|
+
json.buffers[0].byteLength = blob.size;
|
355
|
+
if (options.binary === true) {
|
356
|
+
const reader = new FileReader();
|
357
|
+
reader.readAsArrayBuffer(blob);
|
358
|
+
reader.onloadend = function() {
|
359
|
+
const binaryChunk = getPaddedArrayBuffer(reader.result);
|
360
|
+
const binaryChunkPrefix = new DataView(new ArrayBuffer(GLB_CHUNK_PREFIX_BYTES));
|
361
|
+
binaryChunkPrefix.setUint32(0, binaryChunk.byteLength, true);
|
362
|
+
binaryChunkPrefix.setUint32(4, GLB_CHUNK_TYPE_BIN, true);
|
363
|
+
const jsonChunk = getPaddedArrayBuffer(stringToArrayBuffer(JSON.stringify(json)), 32);
|
364
|
+
const jsonChunkPrefix = new DataView(new ArrayBuffer(GLB_CHUNK_PREFIX_BYTES));
|
365
|
+
jsonChunkPrefix.setUint32(0, jsonChunk.byteLength, true);
|
366
|
+
jsonChunkPrefix.setUint32(4, GLB_CHUNK_TYPE_JSON, true);
|
367
|
+
const header = new ArrayBuffer(GLB_HEADER_BYTES);
|
368
|
+
const headerView = new DataView(header);
|
369
|
+
headerView.setUint32(0, GLB_HEADER_MAGIC, true);
|
370
|
+
headerView.setUint32(4, GLB_VERSION, true);
|
371
|
+
const totalByteLength = GLB_HEADER_BYTES + jsonChunkPrefix.byteLength + jsonChunk.byteLength + binaryChunkPrefix.byteLength + binaryChunk.byteLength;
|
372
|
+
headerView.setUint32(8, totalByteLength, true);
|
373
|
+
const glbBlob = new Blob([header, jsonChunkPrefix, jsonChunk, binaryChunkPrefix, binaryChunk], {
|
374
|
+
type: "application/octet-stream"
|
375
|
+
});
|
376
|
+
const glbReader = new FileReader();
|
377
|
+
glbReader.readAsArrayBuffer(glbBlob);
|
378
|
+
glbReader.onloadend = function() {
|
379
|
+
onDone(glbReader.result);
|
318
380
|
};
|
319
|
-
}
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
onDone(json);
|
328
|
-
}
|
329
|
-
};
|
330
|
-
} else {
|
381
|
+
};
|
382
|
+
} else {
|
383
|
+
if (json.buffers && json.buffers.length > 0) {
|
384
|
+
const reader = new FileReader();
|
385
|
+
reader.readAsDataURL(blob);
|
386
|
+
reader.onloadend = function() {
|
387
|
+
const base64data = reader.result;
|
388
|
+
json.buffers[0].uri = base64data;
|
331
389
|
onDone(json);
|
332
|
-
}
|
390
|
+
};
|
391
|
+
} else {
|
392
|
+
onDone(json);
|
333
393
|
}
|
334
|
-
}
|
394
|
+
}
|
335
395
|
}
|
336
396
|
/**
|
337
397
|
* Serializes a userData.
|
@@ -358,23 +418,25 @@ class GLTFWriter {
|
|
358
418
|
if (Object.keys(json).length > 0)
|
359
419
|
objectDef.extras = json;
|
360
420
|
} catch (error) {
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
);
|
365
|
-
}
|
421
|
+
console.warn(
|
422
|
+
"THREE.GLTFExporter: userData of '" + object.name + "' won't be serialized because of JSON.stringify error - " + error.message
|
423
|
+
);
|
366
424
|
}
|
367
425
|
}
|
368
426
|
/**
|
369
|
-
*
|
370
|
-
* especially which doesn't have .uuid
|
427
|
+
* Returns ids for buffer attributes.
|
371
428
|
* @param {Object} object
|
372
429
|
* @return {Integer}
|
373
430
|
*/
|
374
|
-
getUID(
|
375
|
-
if (
|
376
|
-
|
377
|
-
|
431
|
+
getUID(attribute, isRelativeCopy = false) {
|
432
|
+
if (this.uids.has(attribute) === false) {
|
433
|
+
const uids2 = /* @__PURE__ */ new Map();
|
434
|
+
uids2.set(true, this.uid++);
|
435
|
+
uids2.set(false, this.uid++);
|
436
|
+
this.uids.set(attribute, uids2);
|
437
|
+
}
|
438
|
+
const uids = this.uids.get(attribute);
|
439
|
+
return uids.get(isRelativeCopy);
|
378
440
|
}
|
379
441
|
/**
|
380
442
|
* Checks if normal attribute values are normalized.
|
@@ -446,6 +508,64 @@ class GLTFWriter {
|
|
446
508
|
this.extensionsUsed["KHR_texture_transform"] = true;
|
447
509
|
}
|
448
510
|
}
|
511
|
+
buildMetalRoughTexture(metalnessMap, roughnessMap) {
|
512
|
+
if (metalnessMap === roughnessMap)
|
513
|
+
return metalnessMap;
|
514
|
+
function getEncodingConversion(map) {
|
515
|
+
if (map.colorSpace === SRGBColorSpace) {
|
516
|
+
return function SRGBToLinear(c) {
|
517
|
+
return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
|
518
|
+
};
|
519
|
+
}
|
520
|
+
return function LinearToLinear(c) {
|
521
|
+
return c;
|
522
|
+
};
|
523
|
+
}
|
524
|
+
console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.");
|
525
|
+
if (metalnessMap instanceof CompressedTexture) {
|
526
|
+
metalnessMap = decompress(metalnessMap);
|
527
|
+
}
|
528
|
+
if (roughnessMap instanceof CompressedTexture) {
|
529
|
+
roughnessMap = decompress(roughnessMap);
|
530
|
+
}
|
531
|
+
const metalness = metalnessMap ? metalnessMap.image : null;
|
532
|
+
const roughness = roughnessMap ? roughnessMap.image : null;
|
533
|
+
const width = Math.max(metalness ? metalness.width : 0, roughness ? roughness.width : 0);
|
534
|
+
const height = Math.max(metalness ? metalness.height : 0, roughness ? roughness.height : 0);
|
535
|
+
const canvas = getCanvas();
|
536
|
+
canvas.width = width;
|
537
|
+
canvas.height = height;
|
538
|
+
const context = canvas.getContext("2d");
|
539
|
+
context.fillStyle = "#00ffff";
|
540
|
+
context.fillRect(0, 0, width, height);
|
541
|
+
const composite = context.getImageData(0, 0, width, height);
|
542
|
+
if (metalness) {
|
543
|
+
context.drawImage(metalness, 0, 0, width, height);
|
544
|
+
const convert = getEncodingConversion(metalnessMap);
|
545
|
+
const data = context.getImageData(0, 0, width, height).data;
|
546
|
+
for (let i = 2; i < data.length; i += 4) {
|
547
|
+
composite.data[i] = convert(data[i] / 256) * 256;
|
548
|
+
}
|
549
|
+
}
|
550
|
+
if (roughness) {
|
551
|
+
context.drawImage(roughness, 0, 0, width, height);
|
552
|
+
const convert = getEncodingConversion(roughnessMap);
|
553
|
+
const data = context.getImageData(0, 0, width, height).data;
|
554
|
+
for (let i = 1; i < data.length; i += 4) {
|
555
|
+
composite.data[i] = convert(data[i] / 256) * 256;
|
556
|
+
}
|
557
|
+
}
|
558
|
+
context.putImageData(composite, 0, 0);
|
559
|
+
const reference = metalnessMap || roughnessMap;
|
560
|
+
const texture = reference.clone();
|
561
|
+
texture.source = new Source(canvas);
|
562
|
+
texture.colorSpace = NoColorSpace;
|
563
|
+
texture.channel = (metalnessMap || roughnessMap).channel;
|
564
|
+
if (metalnessMap && roughnessMap && metalnessMap.channel !== roughnessMap.channel) {
|
565
|
+
console.warn("THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match.");
|
566
|
+
}
|
567
|
+
return texture;
|
568
|
+
}
|
449
569
|
/**
|
450
570
|
* Process a buffer to append to the default one.
|
451
571
|
* @param {ArrayBuffer} buffer
|
@@ -473,14 +593,19 @@ class GLTFWriter {
|
|
473
593
|
if (!json.bufferViews)
|
474
594
|
json.bufferViews = [];
|
475
595
|
let componentSize;
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
596
|
+
switch (componentType) {
|
597
|
+
case WEBGL_CONSTANTS.BYTE:
|
598
|
+
case WEBGL_CONSTANTS.UNSIGNED_BYTE:
|
599
|
+
componentSize = 1;
|
600
|
+
break;
|
601
|
+
case WEBGL_CONSTANTS.SHORT:
|
602
|
+
case WEBGL_CONSTANTS.UNSIGNED_SHORT:
|
603
|
+
componentSize = 2;
|
604
|
+
break;
|
605
|
+
default:
|
606
|
+
componentSize = 4;
|
607
|
+
}
|
608
|
+
const byteLength = getPaddedBufferSize(count * attribute.itemSize * componentSize);
|
484
609
|
const dataView = new DataView(new ArrayBuffer(byteLength));
|
485
610
|
let offset = 0;
|
486
611
|
for (let i = start; i < start + count; i++) {
|
@@ -497,18 +622,25 @@ class GLTFWriter {
|
|
497
622
|
value = attribute.getZ(i);
|
498
623
|
else if (a === 3)
|
499
624
|
value = attribute.getW(i);
|
500
|
-
|
501
|
-
|
502
|
-
if (componentType === WEBGL_CONSTANTS.FLOAT) {
|
503
|
-
dataView.setFloat32(offset, value, true);
|
504
|
-
} else if (componentType === WEBGL_CONSTANTS.UNSIGNED_INT) {
|
505
|
-
dataView.setUint32(offset, value, true);
|
506
|
-
} else if (componentType === WEBGL_CONSTANTS.UNSIGNED_SHORT) {
|
507
|
-
dataView.setUint16(offset, value, true);
|
508
|
-
} else if (componentType === WEBGL_CONSTANTS.UNSIGNED_BYTE) {
|
509
|
-
dataView.setUint8(offset, value);
|
625
|
+
if (attribute.normalized === true) {
|
626
|
+
value = MathUtils.normalize(value, attribute.array);
|
510
627
|
}
|
511
628
|
}
|
629
|
+
if (componentType === WEBGL_CONSTANTS.FLOAT) {
|
630
|
+
dataView.setFloat32(offset, value, true);
|
631
|
+
} else if (componentType === WEBGL_CONSTANTS.INT) {
|
632
|
+
dataView.setInt32(offset, value, true);
|
633
|
+
} else if (componentType === WEBGL_CONSTANTS.UNSIGNED_INT) {
|
634
|
+
dataView.setUint32(offset, value, true);
|
635
|
+
} else if (componentType === WEBGL_CONSTANTS.SHORT) {
|
636
|
+
dataView.setInt16(offset, value, true);
|
637
|
+
} else if (componentType === WEBGL_CONSTANTS.UNSIGNED_SHORT) {
|
638
|
+
dataView.setUint16(offset, value, true);
|
639
|
+
} else if (componentType === WEBGL_CONSTANTS.BYTE) {
|
640
|
+
dataView.setInt8(offset, value);
|
641
|
+
} else if (componentType === WEBGL_CONSTANTS.UNSIGNED_BYTE) {
|
642
|
+
dataView.setUint8(offset, value);
|
643
|
+
}
|
512
644
|
offset += componentSize;
|
513
645
|
}
|
514
646
|
}
|
@@ -540,20 +672,18 @@ class GLTFWriter {
|
|
540
672
|
const json = writer.json;
|
541
673
|
if (!json.bufferViews)
|
542
674
|
json.bufferViews = [];
|
543
|
-
return new Promise((resolve)
|
544
|
-
const reader = new
|
675
|
+
return new Promise(function(resolve) {
|
676
|
+
const reader = new FileReader();
|
545
677
|
reader.readAsArrayBuffer(blob);
|
546
|
-
reader.onloadend = ()
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
resolve(json.bufferViews.push(bufferViewDef) - 1);
|
556
|
-
}
|
678
|
+
reader.onloadend = function() {
|
679
|
+
const buffer = getPaddedArrayBuffer(reader.result);
|
680
|
+
const bufferViewDef = {
|
681
|
+
buffer: writer.processBuffer(buffer),
|
682
|
+
byteOffset: writer.byteOffset,
|
683
|
+
byteLength: buffer.byteLength
|
684
|
+
};
|
685
|
+
writer.byteOffset += buffer.byteLength;
|
686
|
+
resolve(json.bufferViews.push(bufferViewDef) - 1);
|
557
687
|
};
|
558
688
|
});
|
559
689
|
}
|
@@ -566,139 +696,135 @@ class GLTFWriter {
|
|
566
696
|
* @return {Integer|null} Index of the processed accessor on the "accessors" array
|
567
697
|
*/
|
568
698
|
processAccessor(attribute, geometry, start, count) {
|
569
|
-
const options = this.options;
|
570
699
|
const json = this.json;
|
571
700
|
const types = {
|
572
701
|
1: "SCALAR",
|
573
702
|
2: "VEC2",
|
574
703
|
3: "VEC3",
|
575
704
|
4: "VEC4",
|
705
|
+
9: "MAT3",
|
576
706
|
16: "MAT4"
|
577
707
|
};
|
578
708
|
let componentType;
|
579
709
|
if (attribute.array.constructor === Float32Array) {
|
580
710
|
componentType = WEBGL_CONSTANTS.FLOAT;
|
711
|
+
} else if (attribute.array.constructor === Int32Array) {
|
712
|
+
componentType = WEBGL_CONSTANTS.INT;
|
581
713
|
} else if (attribute.array.constructor === Uint32Array) {
|
582
714
|
componentType = WEBGL_CONSTANTS.UNSIGNED_INT;
|
715
|
+
} else if (attribute.array.constructor === Int16Array) {
|
716
|
+
componentType = WEBGL_CONSTANTS.SHORT;
|
583
717
|
} else if (attribute.array.constructor === Uint16Array) {
|
584
718
|
componentType = WEBGL_CONSTANTS.UNSIGNED_SHORT;
|
719
|
+
} else if (attribute.array.constructor === Int8Array) {
|
720
|
+
componentType = WEBGL_CONSTANTS.BYTE;
|
585
721
|
} else if (attribute.array.constructor === Uint8Array) {
|
586
722
|
componentType = WEBGL_CONSTANTS.UNSIGNED_BYTE;
|
587
723
|
} else {
|
588
|
-
throw new Error(
|
724
|
+
throw new Error(
|
725
|
+
"THREE.GLTFExporter: Unsupported bufferAttribute component type: " + attribute.array.constructor.name
|
726
|
+
);
|
589
727
|
}
|
590
728
|
if (start === void 0)
|
591
729
|
start = 0;
|
592
730
|
if (count === void 0)
|
593
731
|
count = attribute.count;
|
594
|
-
if (options.truncateDrawRange && geometry !== void 0 && geometry.index === null) {
|
595
|
-
const end = start + count;
|
596
|
-
const end2 = geometry.drawRange.count === Infinity ? attribute.count : geometry.drawRange.start + geometry.drawRange.count;
|
597
|
-
start = Math.max(start, geometry.drawRange.start);
|
598
|
-
count = Math.min(end, end2) - start;
|
599
|
-
if (count < 0)
|
600
|
-
count = 0;
|
601
|
-
}
|
602
732
|
if (count === 0)
|
603
733
|
return null;
|
604
|
-
const minMax =
|
734
|
+
const minMax = getMinMax(attribute, start, count);
|
605
735
|
let bufferViewTarget;
|
606
736
|
if (geometry !== void 0) {
|
607
737
|
bufferViewTarget = attribute === geometry.index ? WEBGL_CONSTANTS.ELEMENT_ARRAY_BUFFER : WEBGL_CONSTANTS.ARRAY_BUFFER;
|
608
738
|
}
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
return json.accessors.push(accessorDef) - 1;
|
625
|
-
}
|
739
|
+
const bufferView = this.processBufferView(attribute, componentType, start, count, bufferViewTarget);
|
740
|
+
const accessorDef = {
|
741
|
+
bufferView: bufferView.id,
|
742
|
+
byteOffset: bufferView.byteOffset,
|
743
|
+
componentType,
|
744
|
+
count,
|
745
|
+
max: minMax.max,
|
746
|
+
min: minMax.min,
|
747
|
+
type: types[attribute.itemSize]
|
748
|
+
};
|
749
|
+
if (attribute.normalized === true)
|
750
|
+
accessorDef.normalized = true;
|
751
|
+
if (!json.accessors)
|
752
|
+
json.accessors = [];
|
753
|
+
return json.accessors.push(accessorDef) - 1;
|
626
754
|
}
|
627
755
|
/**
|
628
756
|
* Process image
|
629
757
|
* @param {Image} image to process
|
630
758
|
* @param {Integer} format of the image (RGBAFormat)
|
631
759
|
* @param {Boolean} flipY before writing out the image
|
760
|
+
* @param {String} mimeType export format
|
632
761
|
* @return {Integer} Index of the processed texture in the "images" array
|
633
762
|
*/
|
634
|
-
processImage(image, format, flipY) {
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
cache.images.
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
const canvas = this.cachedCanvas = this.cachedCanvas || document.createElement("canvas");
|
763
|
+
processImage(image, format, flipY, mimeType = "image/png") {
|
764
|
+
if (image !== null) {
|
765
|
+
const writer = this;
|
766
|
+
const cache = writer.cache;
|
767
|
+
const json = writer.json;
|
768
|
+
const options = writer.options;
|
769
|
+
const pending = writer.pending;
|
770
|
+
if (!cache.images.has(image))
|
771
|
+
cache.images.set(image, {});
|
772
|
+
const cachedImages = cache.images.get(image);
|
773
|
+
const key = mimeType + ":flipY/" + flipY.toString();
|
774
|
+
if (cachedImages[key] !== void 0)
|
775
|
+
return cachedImages[key];
|
776
|
+
if (!json.images)
|
777
|
+
json.images = [];
|
778
|
+
const imageDef = { mimeType };
|
779
|
+
const canvas = getCanvas();
|
652
780
|
canvas.width = Math.min(image.width, options.maxTextureSize);
|
653
781
|
canvas.height = Math.min(image.height, options.maxTextureSize);
|
654
782
|
const ctx = canvas.getContext("2d");
|
655
|
-
if (flipY) {
|
656
|
-
ctx
|
657
|
-
ctx
|
783
|
+
if (flipY === true) {
|
784
|
+
ctx.translate(0, canvas.height);
|
785
|
+
ctx.scale(1, -1);
|
658
786
|
}
|
659
|
-
if (
|
660
|
-
ctx == null ? void 0 : ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
|
661
|
-
} else {
|
787
|
+
if (image.data !== void 0) {
|
662
788
|
if (format !== RGBAFormat) {
|
663
|
-
console.error("GLTFExporter: Only
|
789
|
+
console.error("GLTFExporter: Only RGBAFormat is supported.", format);
|
664
790
|
}
|
665
791
|
if (image.width > options.maxTextureSize || image.height > options.maxTextureSize) {
|
666
792
|
console.warn("GLTFExporter: Image size is bigger than maxTextureSize", image);
|
667
793
|
}
|
668
794
|
const data = new Uint8ClampedArray(image.height * image.width * 4);
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
data[i + 3] = image.data[i + 3];
|
675
|
-
}
|
795
|
+
for (let i = 0; i < data.length; i += 4) {
|
796
|
+
data[i + 0] = image.data[i + 0];
|
797
|
+
data[i + 1] = image.data[i + 1];
|
798
|
+
data[i + 2] = image.data[i + 2];
|
799
|
+
data[i + 3] = image.data[i + 3];
|
676
800
|
}
|
677
|
-
ctx
|
801
|
+
ctx.putImageData(new ImageData(data, image.width, image.height), 0, 0);
|
802
|
+
} else {
|
803
|
+
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
|
678
804
|
}
|
679
|
-
if (options.binary) {
|
805
|
+
if (options.binary === true) {
|
680
806
|
pending.push(
|
681
|
-
|
682
|
-
|
683
|
-
if (blob !== null) {
|
684
|
-
writer.processBufferViewImage(blob).then(function(bufferViewIndex) {
|
685
|
-
imageDef.bufferView = bufferViewIndex;
|
686
|
-
resolve();
|
687
|
-
});
|
688
|
-
}
|
689
|
-
}, mimeType);
|
807
|
+
getToBlobPromise(canvas, mimeType).then((blob) => writer.processBufferViewImage(blob)).then((bufferViewIndex) => {
|
808
|
+
imageDef.bufferView = bufferViewIndex;
|
690
809
|
})
|
691
810
|
);
|
692
811
|
} else {
|
693
|
-
|
812
|
+
if (canvas.toDataURL !== void 0) {
|
813
|
+
imageDef.uri = canvas.toDataURL(mimeType);
|
814
|
+
} else {
|
815
|
+
pending.push(
|
816
|
+
getToBlobPromise(canvas, mimeType).then((blob) => new FileReader().readAsDataURL(blob)).then((dataURL) => {
|
817
|
+
imageDef.uri = dataURL;
|
818
|
+
})
|
819
|
+
);
|
820
|
+
}
|
694
821
|
}
|
695
|
-
|
696
|
-
imageDef.uri = image.src;
|
697
|
-
}
|
698
|
-
const index = json.images.push(imageDef) - 1;
|
699
|
-
if (cachedImages !== void 0)
|
822
|
+
const index = json.images.push(imageDef) - 1;
|
700
823
|
cachedImages[key] = index;
|
701
|
-
|
824
|
+
return index;
|
825
|
+
} else {
|
826
|
+
throw new Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.");
|
827
|
+
}
|
702
828
|
}
|
703
829
|
/**
|
704
830
|
* Process sampler
|
@@ -723,15 +849,23 @@ class GLTFWriter {
|
|
723
849
|
* @return {Integer} Index of the processed texture in the "textures" array
|
724
850
|
*/
|
725
851
|
processTexture(map) {
|
852
|
+
const writer = this;
|
853
|
+
const options = writer.options;
|
726
854
|
const cache = this.cache;
|
727
855
|
const json = this.json;
|
728
856
|
if (cache.textures.has(map))
|
729
857
|
return cache.textures.get(map);
|
730
858
|
if (!json.textures)
|
731
859
|
json.textures = [];
|
860
|
+
if (map instanceof CompressedTexture) {
|
861
|
+
map = decompress(map, options.maxTextureSize);
|
862
|
+
}
|
863
|
+
let mimeType = map.userData.mimeType;
|
864
|
+
if (mimeType === "image/webp")
|
865
|
+
mimeType = "image/png";
|
732
866
|
const textureDef = {
|
733
867
|
sampler: this.processSampler(map),
|
734
|
-
source: this.processImage(map.image, map.format, map.flipY)
|
868
|
+
source: this.processImage(map.image, map.format, map.flipY, mimeType)
|
735
869
|
};
|
736
870
|
if (map.name)
|
737
871
|
textureDef.name = map.name;
|
@@ -752,74 +886,74 @@ class GLTFWriter {
|
|
752
886
|
const json = this.json;
|
753
887
|
if (cache.materials.has(material))
|
754
888
|
return cache.materials.get(material);
|
755
|
-
if (material
|
889
|
+
if (material.isShaderMaterial) {
|
756
890
|
console.warn("GLTFExporter: THREE.ShaderMaterial not supported.");
|
757
891
|
return null;
|
758
892
|
}
|
759
893
|
if (!json.materials)
|
760
894
|
json.materials = [];
|
761
895
|
const materialDef = { pbrMetallicRoughness: {} };
|
762
|
-
if (
|
763
|
-
material.isMeshBasicMaterial)) {
|
896
|
+
if (material.isMeshStandardMaterial !== true && material.isMeshBasicMaterial !== true) {
|
764
897
|
console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");
|
765
898
|
}
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
materialDef.pbrMetallicRoughness.baseColorFactor = color;
|
770
|
-
}
|
899
|
+
const color = material.color.toArray().concat([material.opacity]);
|
900
|
+
if (!equalArray(color, [1, 1, 1, 1])) {
|
901
|
+
materialDef.pbrMetallicRoughness.baseColorFactor = color;
|
771
902
|
}
|
772
|
-
if (material
|
903
|
+
if (material.isMeshStandardMaterial) {
|
773
904
|
materialDef.pbrMetallicRoughness.metallicFactor = material.metalness;
|
774
905
|
materialDef.pbrMetallicRoughness.roughnessFactor = material.roughness;
|
775
906
|
} else {
|
776
907
|
materialDef.pbrMetallicRoughness.metallicFactor = 0.5;
|
777
908
|
materialDef.pbrMetallicRoughness.roughnessFactor = 0.5;
|
778
909
|
}
|
779
|
-
if (material
|
780
|
-
|
781
|
-
|
782
|
-
this.
|
783
|
-
|
784
|
-
}
|
785
|
-
|
786
|
-
|
787
|
-
);
|
788
|
-
}
|
910
|
+
if (material.metalnessMap || material.roughnessMap) {
|
911
|
+
const metalRoughTexture = this.buildMetalRoughTexture(material.metalnessMap, material.roughnessMap);
|
912
|
+
const metalRoughMapDef = {
|
913
|
+
index: this.processTexture(metalRoughTexture),
|
914
|
+
channel: metalRoughTexture.channel
|
915
|
+
};
|
916
|
+
this.applyTextureTransform(metalRoughMapDef, metalRoughTexture);
|
917
|
+
materialDef.pbrMetallicRoughness.metallicRoughnessTexture = metalRoughMapDef;
|
789
918
|
}
|
790
|
-
if (
|
791
|
-
const baseColorMapDef = {
|
919
|
+
if (material.map) {
|
920
|
+
const baseColorMapDef = {
|
921
|
+
index: this.processTexture(material.map),
|
922
|
+
texCoord: material.map.channel
|
923
|
+
};
|
792
924
|
this.applyTextureTransform(baseColorMapDef, material.map);
|
793
925
|
materialDef.pbrMetallicRoughness.baseColorTexture = baseColorMapDef;
|
794
926
|
}
|
795
|
-
if (
|
796
|
-
const emissive = material.emissive
|
927
|
+
if (material.emissive) {
|
928
|
+
const emissive = material.emissive;
|
797
929
|
const maxEmissiveComponent = Math.max(emissive.r, emissive.g, emissive.b);
|
798
|
-
if (maxEmissiveComponent > 1) {
|
799
|
-
emissive.multiplyScalar(1 / maxEmissiveComponent);
|
800
|
-
console.warn("THREE.GLTFExporter: Some emissive components exceed 1; emissive has been limited");
|
801
|
-
}
|
802
930
|
if (maxEmissiveComponent > 0) {
|
803
|
-
materialDef.emissiveFactor = emissive.toArray();
|
931
|
+
materialDef.emissiveFactor = material.emissive.toArray();
|
804
932
|
}
|
805
933
|
if (material.emissiveMap) {
|
806
|
-
const emissiveMapDef = {
|
934
|
+
const emissiveMapDef = {
|
935
|
+
index: this.processTexture(material.emissiveMap),
|
936
|
+
texCoord: material.emissiveMap.channel
|
937
|
+
};
|
807
938
|
this.applyTextureTransform(emissiveMapDef, material.emissiveMap);
|
808
939
|
materialDef.emissiveTexture = emissiveMapDef;
|
809
940
|
}
|
810
941
|
}
|
811
|
-
if (
|
812
|
-
const normalMapDef = {
|
942
|
+
if (material.normalMap) {
|
943
|
+
const normalMapDef = {
|
944
|
+
index: this.processTexture(material.normalMap),
|
945
|
+
texCoord: material.normalMap.channel
|
946
|
+
};
|
813
947
|
if (material.normalScale && material.normalScale.x !== 1) {
|
814
948
|
normalMapDef.scale = material.normalScale.x;
|
815
949
|
}
|
816
950
|
this.applyTextureTransform(normalMapDef, material.normalMap);
|
817
951
|
materialDef.normalTexture = normalMapDef;
|
818
952
|
}
|
819
|
-
if (
|
953
|
+
if (material.aoMap) {
|
820
954
|
const occlusionMapDef = {
|
821
955
|
index: this.processTexture(material.aoMap),
|
822
|
-
texCoord:
|
956
|
+
texCoord: material.aoMap.channel
|
823
957
|
};
|
824
958
|
if (material.aoMapIntensity !== 1) {
|
825
959
|
occlusionMapDef.strength = material.aoMapIntensity;
|
@@ -868,19 +1002,16 @@ class GLTFWriter {
|
|
868
1002
|
return cache.meshes.get(meshCacheKey);
|
869
1003
|
const geometry = mesh.geometry;
|
870
1004
|
let mode;
|
871
|
-
if (mesh
|
1005
|
+
if (mesh.isLineSegments) {
|
872
1006
|
mode = WEBGL_CONSTANTS.LINES;
|
873
|
-
} else if (mesh
|
1007
|
+
} else if (mesh.isLineLoop) {
|
874
1008
|
mode = WEBGL_CONSTANTS.LINE_LOOP;
|
875
|
-
} else if (mesh
|
1009
|
+
} else if (mesh.isLine) {
|
876
1010
|
mode = WEBGL_CONSTANTS.LINE_STRIP;
|
877
|
-
} else if (mesh
|
1011
|
+
} else if (mesh.isPoints) {
|
878
1012
|
mode = WEBGL_CONSTANTS.POINTS;
|
879
1013
|
} else {
|
880
|
-
mode =
|
881
|
-
}
|
882
|
-
if (!geometry.isBufferGeometry) {
|
883
|
-
throw new Error("THREE.GLTFExporter: Geometry is not of type THREE.BufferGeometry.");
|
1014
|
+
mode = mesh.material.wireframe ? WEBGL_CONSTANTS.LINES : WEBGL_CONSTANTS.TRIANGLES;
|
884
1015
|
}
|
885
1016
|
const meshDef = {};
|
886
1017
|
const attributes = {};
|
@@ -888,19 +1019,19 @@ class GLTFWriter {
|
|
888
1019
|
const targets = [];
|
889
1020
|
const nameConversion = {
|
890
1021
|
uv: "TEXCOORD_0",
|
891
|
-
uv2: "TEXCOORD_1",
|
1022
|
+
[REVISION.replace(/\D+/g, "") >= 152 ? "uv1" : "uv2"]: "TEXCOORD_1",
|
892
1023
|
color: "COLOR_0",
|
893
1024
|
skinWeight: "WEIGHTS_0",
|
894
1025
|
skinIndex: "JOINTS_0"
|
895
1026
|
};
|
896
1027
|
const originalNormal = geometry.getAttribute("normal");
|
897
|
-
if (originalNormal !== void 0 && !
|
1028
|
+
if (originalNormal !== void 0 && !this.isNormalizedNormalAttribute(originalNormal)) {
|
898
1029
|
console.warn("THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one.");
|
899
1030
|
geometry.setAttribute("normal", this.createNormalizedNormalAttribute(originalNormal));
|
900
1031
|
}
|
901
1032
|
let modifiedAttribute = null;
|
902
1033
|
for (let attributeName in geometry.attributes) {
|
903
|
-
if (attributeName.
|
1034
|
+
if (attributeName.slice(0, 5) === "morph")
|
904
1035
|
continue;
|
905
1036
|
const attribute = geometry.attributes[attributeName];
|
906
1037
|
attributeName = nameConversion[attributeName] || attributeName.toUpperCase();
|
@@ -917,8 +1048,11 @@ class GLTFWriter {
|
|
917
1048
|
console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.');
|
918
1049
|
modifiedAttribute = new BufferAttribute(new Uint16Array(array), attribute.itemSize, attribute.normalized);
|
919
1050
|
}
|
920
|
-
const accessor =
|
921
|
-
if (accessor) {
|
1051
|
+
const accessor = this.processAccessor(modifiedAttribute || attribute, geometry);
|
1052
|
+
if (accessor !== null) {
|
1053
|
+
if (!attributeName.startsWith("_")) {
|
1054
|
+
this.detectMeshQuantization(attributeName, attribute);
|
1055
|
+
}
|
922
1056
|
attributes[attributeName] = accessor;
|
923
1057
|
cache.attributes.set(this.getUID(attribute), accessor);
|
924
1058
|
}
|
@@ -950,26 +1084,27 @@ class GLTFWriter {
|
|
950
1084
|
const attribute = geometry.morphAttributes[attributeName][i];
|
951
1085
|
const gltfAttributeName = attributeName.toUpperCase();
|
952
1086
|
const baseAttribute = geometry.attributes[attributeName];
|
953
|
-
if (cache.attributes.has(this.getUID(attribute))) {
|
954
|
-
target[gltfAttributeName] = cache.attributes.get(this.getUID(attribute));
|
1087
|
+
if (cache.attributes.has(this.getUID(attribute, true))) {
|
1088
|
+
target[gltfAttributeName] = cache.attributes.get(this.getUID(attribute, true));
|
955
1089
|
continue;
|
956
1090
|
}
|
957
1091
|
const relativeAttribute = attribute.clone();
|
958
1092
|
if (!geometry.morphTargetsRelative) {
|
959
1093
|
for (let j = 0, jl = attribute.count; j < jl; j++) {
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
1094
|
+
for (let a = 0; a < attribute.itemSize; a++) {
|
1095
|
+
if (a === 0)
|
1096
|
+
relativeAttribute.setX(j, attribute.getX(j) - baseAttribute.getX(j));
|
1097
|
+
if (a === 1)
|
1098
|
+
relativeAttribute.setY(j, attribute.getY(j) - baseAttribute.getY(j));
|
1099
|
+
if (a === 2)
|
1100
|
+
relativeAttribute.setZ(j, attribute.getZ(j) - baseAttribute.getZ(j));
|
1101
|
+
if (a === 3)
|
1102
|
+
relativeAttribute.setW(j, attribute.getW(j) - baseAttribute.getW(j));
|
1103
|
+
}
|
966
1104
|
}
|
967
1105
|
}
|
968
|
-
|
969
|
-
|
970
|
-
target[gltfAttributeName] = accessor;
|
971
|
-
}
|
972
|
-
cache.attributes.set(this.getUID(baseAttribute), target[gltfAttributeName]);
|
1106
|
+
target[gltfAttributeName] = this.processAccessor(relativeAttribute, geometry);
|
1107
|
+
cache.attributes.set(this.getUID(baseAttribute, true), target[gltfAttributeName]);
|
973
1108
|
}
|
974
1109
|
targets.push(target);
|
975
1110
|
weights.push(mesh.morphTargetInfluences[i]);
|
@@ -992,15 +1127,13 @@ class GLTFWriter {
|
|
992
1127
|
mode,
|
993
1128
|
attributes
|
994
1129
|
};
|
995
|
-
|
996
|
-
this.serializeUserData(geometry, primitive);
|
997
|
-
}
|
1130
|
+
this.serializeUserData(geometry, primitive);
|
998
1131
|
if (targets.length > 0)
|
999
1132
|
primitive.targets = targets;
|
1000
1133
|
if (geometry.index !== null) {
|
1001
1134
|
let cacheKey = this.getUID(geometry.index);
|
1002
1135
|
if (groups[i].start !== void 0 || groups[i].count !== void 0) {
|
1003
|
-
cacheKey +=
|
1136
|
+
cacheKey += ":" + groups[i].start + ":" + groups[i].count;
|
1004
1137
|
}
|
1005
1138
|
if (cache.attributes.has(cacheKey)) {
|
1006
1139
|
primitive.indices = cache.attributes.get(cacheKey);
|
@@ -1011,16 +1144,10 @@ class GLTFWriter {
|
|
1011
1144
|
if (primitive.indices === null)
|
1012
1145
|
delete primitive.indices;
|
1013
1146
|
}
|
1014
|
-
const
|
1015
|
-
if (
|
1016
|
-
|
1017
|
-
|
1018
|
-
const material = this.processMaterial(targetMaterials);
|
1019
|
-
if (material !== null)
|
1020
|
-
primitive.material = material;
|
1021
|
-
primitives.push(primitive);
|
1022
|
-
}
|
1023
|
-
}
|
1147
|
+
const material = this.processMaterial(materials[groups[i].materialIndex]);
|
1148
|
+
if (material !== null)
|
1149
|
+
primitive.material = material;
|
1150
|
+
primitives.push(primitive);
|
1024
1151
|
}
|
1025
1152
|
meshDef.primitives = primitives;
|
1026
1153
|
if (!json.meshes)
|
@@ -1032,6 +1159,45 @@ class GLTFWriter {
|
|
1032
1159
|
cache.meshes.set(meshCacheKey, index);
|
1033
1160
|
return index;
|
1034
1161
|
}
|
1162
|
+
/**
|
1163
|
+
* If a vertex attribute with a
|
1164
|
+
* [non-standard data type](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview)
|
1165
|
+
* is used, it is checked whether it is a valid data type according to the
|
1166
|
+
* [KHR_mesh_quantization](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_mesh_quantization/README.md)
|
1167
|
+
* extension.
|
1168
|
+
* In this case the extension is automatically added to the list of used extensions.
|
1169
|
+
*
|
1170
|
+
* @param {string} attributeName
|
1171
|
+
* @param {THREE.BufferAttribute} attribute
|
1172
|
+
*/
|
1173
|
+
detectMeshQuantization(attributeName, attribute) {
|
1174
|
+
if (this.extensionsUsed[KHR_MESH_QUANTIZATION])
|
1175
|
+
return;
|
1176
|
+
let attrType = void 0;
|
1177
|
+
switch (attribute.array.constructor) {
|
1178
|
+
case Int8Array:
|
1179
|
+
attrType = "byte";
|
1180
|
+
break;
|
1181
|
+
case Uint8Array:
|
1182
|
+
attrType = "unsigned byte";
|
1183
|
+
break;
|
1184
|
+
case Int16Array:
|
1185
|
+
attrType = "short";
|
1186
|
+
break;
|
1187
|
+
case Uint16Array:
|
1188
|
+
attrType = "unsigned short";
|
1189
|
+
break;
|
1190
|
+
default:
|
1191
|
+
return;
|
1192
|
+
}
|
1193
|
+
if (attribute.normalized)
|
1194
|
+
attrType += " normalized";
|
1195
|
+
const attrNamePrefix = attributeName.split("_", 1)[0];
|
1196
|
+
if (KHR_mesh_quantization_ExtraAttrTypes[attrNamePrefix] && KHR_mesh_quantization_ExtraAttrTypes[attrNamePrefix].includes(attrType)) {
|
1197
|
+
this.extensionsUsed[KHR_MESH_QUANTIZATION] = true;
|
1198
|
+
this.extensionsRequired[KHR_MESH_QUANTIZATION] = true;
|
1199
|
+
}
|
1200
|
+
}
|
1035
1201
|
/**
|
1036
1202
|
* Process camera
|
1037
1203
|
* @param {THREE.Camera} camera Camera to process
|
@@ -1041,18 +1207,18 @@ class GLTFWriter {
|
|
1041
1207
|
const json = this.json;
|
1042
1208
|
if (!json.cameras)
|
1043
1209
|
json.cameras = [];
|
1044
|
-
const isOrtho = camera
|
1210
|
+
const isOrtho = camera.isOrthographicCamera;
|
1045
1211
|
const cameraDef = {
|
1046
1212
|
type: isOrtho ? "orthographic" : "perspective"
|
1047
1213
|
};
|
1048
|
-
if (
|
1214
|
+
if (isOrtho) {
|
1049
1215
|
cameraDef.orthographic = {
|
1050
1216
|
xmag: camera.right * 2,
|
1051
1217
|
ymag: camera.top * 2,
|
1052
1218
|
zfar: camera.far <= 0 ? 1e-3 : camera.far,
|
1053
1219
|
znear: camera.near < 0 ? 0 : camera.near
|
1054
1220
|
};
|
1055
|
-
} else
|
1221
|
+
} else {
|
1056
1222
|
cameraDef.perspective = {
|
1057
1223
|
aspectRatio: camera.aspect,
|
1058
1224
|
yfov: MathUtils.degToRad(camera.fov),
|
@@ -1089,7 +1255,7 @@ class GLTFWriter {
|
|
1089
1255
|
let trackNode = PropertyBinding.findNode(root, trackBinding.nodeName);
|
1090
1256
|
const trackProperty = PATH_PROPERTIES[trackBinding.propertyName];
|
1091
1257
|
if (trackBinding.objectName === "bones") {
|
1092
|
-
if (trackNode.isSkinnedMesh) {
|
1258
|
+
if (trackNode.isSkinnedMesh === true) {
|
1093
1259
|
trackNode = trackNode.skeleton.getBoneByName(trackBinding.objectIndex);
|
1094
1260
|
} else {
|
1095
1261
|
trackNode = void 0;
|
@@ -1105,7 +1271,7 @@ class GLTFWriter {
|
|
1105
1271
|
outputItemSize /= trackNode.morphTargetInfluences.length;
|
1106
1272
|
}
|
1107
1273
|
let interpolation;
|
1108
|
-
if (track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
|
1274
|
+
if (track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === true) {
|
1109
1275
|
interpolation = "CUBICSPLINE";
|
1110
1276
|
outputItemSize /= 3;
|
1111
1277
|
} else if (track.getInterpolation() === InterpolateDiscrete) {
|
@@ -1140,34 +1306,30 @@ class GLTFWriter {
|
|
1140
1306
|
processSkin(object) {
|
1141
1307
|
const json = this.json;
|
1142
1308
|
const nodeMap = this.nodeMap;
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
if (skeleton === void 0)
|
1147
|
-
return null;
|
1148
|
-
const rootJoint = object.skeleton.bones[0];
|
1149
|
-
if (rootJoint === void 0)
|
1150
|
-
return null;
|
1151
|
-
const joints = [];
|
1152
|
-
const inverseBindMatrices = new Float32Array(skeleton.bones.length * 16);
|
1153
|
-
const temporaryBoneInverse = new Matrix4();
|
1154
|
-
for (let i = 0; i < skeleton.bones.length; ++i) {
|
1155
|
-
joints.push(nodeMap.get(skeleton.bones[i]));
|
1156
|
-
temporaryBoneInverse.copy(skeleton.boneInverses[i]);
|
1157
|
-
temporaryBoneInverse.multiply(object.bindMatrix).toArray(inverseBindMatrices, i * 16);
|
1158
|
-
}
|
1159
|
-
if (json.skins === void 0)
|
1160
|
-
json.skins = [];
|
1161
|
-
json.skins.push({
|
1162
|
-
inverseBindMatrices: this.processAccessor(new BufferAttribute(inverseBindMatrices, 16)),
|
1163
|
-
joints,
|
1164
|
-
skeleton: nodeMap.get(rootJoint)
|
1165
|
-
});
|
1166
|
-
const skinIndex = node.skin = json.skins.length - 1;
|
1167
|
-
return skinIndex;
|
1168
|
-
} else {
|
1309
|
+
const node = json.nodes[nodeMap.get(object)];
|
1310
|
+
const skeleton = object.skeleton;
|
1311
|
+
if (skeleton === void 0)
|
1169
1312
|
return null;
|
1170
|
-
|
1313
|
+
const rootJoint = object.skeleton.bones[0];
|
1314
|
+
if (rootJoint === void 0)
|
1315
|
+
return null;
|
1316
|
+
const joints = [];
|
1317
|
+
const inverseBindMatrices = new Float32Array(skeleton.bones.length * 16);
|
1318
|
+
const temporaryBoneInverse = new Matrix4();
|
1319
|
+
for (let i = 0; i < skeleton.bones.length; ++i) {
|
1320
|
+
joints.push(nodeMap.get(skeleton.bones[i]));
|
1321
|
+
temporaryBoneInverse.copy(skeleton.boneInverses[i]);
|
1322
|
+
temporaryBoneInverse.multiply(object.bindMatrix).toArray(inverseBindMatrices, i * 16);
|
1323
|
+
}
|
1324
|
+
if (json.skins === void 0)
|
1325
|
+
json.skins = [];
|
1326
|
+
json.skins.push({
|
1327
|
+
inverseBindMatrices: this.processAccessor(new BufferAttribute(inverseBindMatrices, 16)),
|
1328
|
+
joints,
|
1329
|
+
skeleton: nodeMap.get(rootJoint)
|
1330
|
+
});
|
1331
|
+
const skinIndex = node.skin = json.skins.length - 1;
|
1332
|
+
return skinIndex;
|
1171
1333
|
}
|
1172
1334
|
/**
|
1173
1335
|
* Process Object3D node
|
@@ -1185,40 +1347,40 @@ class GLTFWriter {
|
|
1185
1347
|
const rotation = object.quaternion.toArray();
|
1186
1348
|
const position = object.position.toArray();
|
1187
1349
|
const scale = object.scale.toArray();
|
1188
|
-
if (!
|
1350
|
+
if (!equalArray(rotation, [0, 0, 0, 1])) {
|
1189
1351
|
nodeDef.rotation = rotation;
|
1190
1352
|
}
|
1191
|
-
if (!
|
1353
|
+
if (!equalArray(position, [0, 0, 0])) {
|
1192
1354
|
nodeDef.translation = position;
|
1193
1355
|
}
|
1194
|
-
if (!
|
1356
|
+
if (!equalArray(scale, [1, 1, 1])) {
|
1195
1357
|
nodeDef.scale = scale;
|
1196
1358
|
}
|
1197
1359
|
} else {
|
1198
1360
|
if (object.matrixAutoUpdate) {
|
1199
1361
|
object.updateMatrix();
|
1200
1362
|
}
|
1201
|
-
if (
|
1363
|
+
if (isIdentityMatrix(object.matrix) === false) {
|
1202
1364
|
nodeDef.matrix = object.matrix.elements;
|
1203
1365
|
}
|
1204
1366
|
}
|
1205
1367
|
if (object.name !== "")
|
1206
1368
|
nodeDef.name = String(object.name);
|
1207
1369
|
this.serializeUserData(object, nodeDef);
|
1208
|
-
if (
|
1370
|
+
if (object.isMesh || object.isLine || object.isPoints) {
|
1209
1371
|
const meshIndex = this.processMesh(object);
|
1210
1372
|
if (meshIndex !== null)
|
1211
1373
|
nodeDef.mesh = meshIndex;
|
1212
|
-
} else if (object
|
1374
|
+
} else if (object.isCamera) {
|
1213
1375
|
nodeDef.camera = this.processCamera(object);
|
1214
1376
|
}
|
1215
|
-
if (object
|
1377
|
+
if (object.isSkinnedMesh)
|
1216
1378
|
this.skins.push(object);
|
1217
1379
|
if (object.children.length > 0) {
|
1218
1380
|
const children = [];
|
1219
1381
|
for (let i = 0, l = object.children.length; i < l; i++) {
|
1220
1382
|
const child = object.children[i];
|
1221
|
-
if (child.visible ||
|
1383
|
+
if (child.visible || options.onlyVisible === false) {
|
1222
1384
|
const nodeIndex2 = this.processNode(child);
|
1223
1385
|
if (nodeIndex2 !== null)
|
1224
1386
|
children.push(nodeIndex2);
|
@@ -1252,7 +1414,7 @@ class GLTFWriter {
|
|
1252
1414
|
const nodes = [];
|
1253
1415
|
for (let i = 0, l = scene.children.length; i < l; i++) {
|
1254
1416
|
const child = scene.children[i];
|
1255
|
-
if (child.visible ||
|
1417
|
+
if (child.visible || options.onlyVisible === false) {
|
1256
1418
|
const nodeIndex = this.processNode(child);
|
1257
1419
|
if (nodeIndex !== null)
|
1258
1420
|
nodes.push(nodeIndex);
|
@@ -1262,6 +1424,10 @@ class GLTFWriter {
|
|
1262
1424
|
sceneDef.nodes = nodes;
|
1263
1425
|
this.serializeUserData(scene, sceneDef);
|
1264
1426
|
}
|
1427
|
+
/**
|
1428
|
+
* Creates a Scene to hold a list of objects and parse it
|
1429
|
+
* @param {Array} objects List of objects to process
|
1430
|
+
*/
|
1265
1431
|
processObjects(objects) {
|
1266
1432
|
const scene = new Scene();
|
1267
1433
|
scene.name = "AuxScene";
|
@@ -1281,9 +1447,8 @@ class GLTFWriter {
|
|
1281
1447
|
});
|
1282
1448
|
const objectsWithoutScene = [];
|
1283
1449
|
for (let i = 0; i < input.length; i++) {
|
1284
|
-
|
1285
|
-
|
1286
|
-
this.processScene(inputScene);
|
1450
|
+
if (input[i] instanceof Scene) {
|
1451
|
+
this.processScene(input[i]);
|
1287
1452
|
} else {
|
1288
1453
|
objectsWithoutScene.push(input[i]);
|
1289
1454
|
}
|
@@ -1293,7 +1458,7 @@ class GLTFWriter {
|
|
1293
1458
|
for (let i = 0; i < this.skins.length; ++i) {
|
1294
1459
|
this.processSkin(this.skins[i]);
|
1295
1460
|
}
|
1296
|
-
for (let i = 0;
|
1461
|
+
for (let i = 0; i < options.animations.length; ++i) {
|
1297
1462
|
this.processAnimation(options.animations[i], input[0]);
|
1298
1463
|
}
|
1299
1464
|
this._invokeAll(function(ext) {
|
@@ -1305,108 +1470,16 @@ class GLTFWriter {
|
|
1305
1470
|
func(this.plugins[i]);
|
1306
1471
|
}
|
1307
1472
|
}
|
1308
|
-
//------------------------------------------------------------------------------
|
1309
|
-
// Utility functions
|
1310
|
-
//------------------------------------------------------------------------------
|
1311
|
-
/**
|
1312
|
-
* Compare two arrays
|
1313
|
-
* @param {Array} array1 Array 1 to compare
|
1314
|
-
* @param {Array} array2 Array 2 to compare
|
1315
|
-
* @return {Boolean} Returns true if both arrays are equal
|
1316
|
-
*/
|
1317
|
-
equalArray(array1, array2) {
|
1318
|
-
return array1.length === array2.length && array1.every(function(element, index) {
|
1319
|
-
return element === array2[index];
|
1320
|
-
});
|
1321
|
-
}
|
1322
|
-
/**
|
1323
|
-
* Converts a string to an ArrayBuffer.
|
1324
|
-
* @param {string} text
|
1325
|
-
* @return {ArrayBuffer}
|
1326
|
-
*/
|
1327
|
-
stringToArrayBuffer(text) {
|
1328
|
-
if (window.TextEncoder !== void 0) {
|
1329
|
-
return new TextEncoder().encode(text).buffer;
|
1330
|
-
}
|
1331
|
-
const array = new Uint8Array(new ArrayBuffer(text.length));
|
1332
|
-
for (let i = 0, il = text.length; i < il; i++) {
|
1333
|
-
const value = text.charCodeAt(i);
|
1334
|
-
array[i] = value > 255 ? 32 : value;
|
1335
|
-
}
|
1336
|
-
return array.buffer;
|
1337
|
-
}
|
1338
|
-
isIdentityMatrix(matrix) {
|
1339
|
-
return this.equalArray(matrix.elements, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
1340
|
-
}
|
1341
|
-
getMinMax(attribute, start, count) {
|
1342
|
-
const output = {
|
1343
|
-
min: new Array(attribute.itemSize).fill(Number.POSITIVE_INFINITY),
|
1344
|
-
max: new Array(attribute.itemSize).fill(Number.NEGATIVE_INFINITY)
|
1345
|
-
};
|
1346
|
-
for (let i = start; i < start + count; i++) {
|
1347
|
-
for (let a = 0; a < attribute.itemSize; a++) {
|
1348
|
-
let value;
|
1349
|
-
if (attribute.itemSize > 4) {
|
1350
|
-
value = attribute.array[i * attribute.itemSize + a];
|
1351
|
-
} else {
|
1352
|
-
if (a === 0)
|
1353
|
-
value = attribute.getX(i);
|
1354
|
-
else if (a === 1)
|
1355
|
-
value = attribute.getY(i);
|
1356
|
-
else if (a === 2)
|
1357
|
-
value = attribute.getZ(i);
|
1358
|
-
else if (a === 3)
|
1359
|
-
value = attribute.getW(i);
|
1360
|
-
}
|
1361
|
-
if (value !== void 0) {
|
1362
|
-
output.min[a] = Math.min(output.min[a], value);
|
1363
|
-
output.max[a] = Math.max(output.max[a], value);
|
1364
|
-
}
|
1365
|
-
}
|
1366
|
-
}
|
1367
|
-
return output;
|
1368
|
-
}
|
1369
|
-
/**
|
1370
|
-
* Get the required size + padding for a buffer, rounded to the next 4-byte boundary.
|
1371
|
-
* https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#data-alignment
|
1372
|
-
*/
|
1373
|
-
getPaddedBufferSize(bufferSize) {
|
1374
|
-
return Math.ceil(bufferSize / 4) * 4;
|
1375
|
-
}
|
1376
|
-
/**
|
1377
|
-
* Returns a buffer aligned to 4-byte boundary.
|
1378
|
-
*
|
1379
|
-
* @param {ArrayBuffer} arrayBuffer Buffer to pad
|
1380
|
-
* @param {Integer} paddingByte (Optional)
|
1381
|
-
* @returns {ArrayBuffer} The same buffer if it's already aligned to 4-byte boundary or a new buffer
|
1382
|
-
*/
|
1383
|
-
getPaddedArrayBuffer(arrayBuffer, paddingByte = 0) {
|
1384
|
-
const paddedLength = this.getPaddedBufferSize(arrayBuffer.byteLength);
|
1385
|
-
if (paddedLength !== arrayBuffer.byteLength) {
|
1386
|
-
const array = new Uint8Array(paddedLength);
|
1387
|
-
array.set(new Uint8Array(arrayBuffer));
|
1388
|
-
if (paddingByte !== 0) {
|
1389
|
-
for (let i = arrayBuffer.byteLength; i < paddedLength; i++) {
|
1390
|
-
array[i] = paddingByte;
|
1391
|
-
}
|
1392
|
-
}
|
1393
|
-
return array.buffer;
|
1394
|
-
}
|
1395
|
-
return arrayBuffer;
|
1396
|
-
}
|
1397
1473
|
}
|
1398
1474
|
class GLTFLightExtension {
|
1399
1475
|
constructor(writer) {
|
1400
|
-
__publicField(this, "writer");
|
1401
|
-
__publicField(this, "name");
|
1402
1476
|
this.writer = writer;
|
1403
1477
|
this.name = "KHR_lights_punctual";
|
1404
1478
|
}
|
1405
1479
|
writeNode(light, nodeDef) {
|
1406
1480
|
if (!light.isLight)
|
1407
1481
|
return;
|
1408
|
-
if (!
|
1409
|
-
!(light instanceof PointLight && light.isPointLight) && !(light instanceof SpotLight && light.isSpotLight)) {
|
1482
|
+
if (!light.isDirectionalLight && !light.isPointLight && !light.isSpotLight) {
|
1410
1483
|
console.warn("THREE.GLTFExporter: Only directional, point, and spot lights are supported.", light);
|
1411
1484
|
return;
|
1412
1485
|
}
|
@@ -1418,14 +1491,13 @@ class GLTFLightExtension {
|
|
1418
1491
|
lightDef.name = light.name;
|
1419
1492
|
lightDef.color = light.color.toArray();
|
1420
1493
|
lightDef.intensity = light.intensity;
|
1421
|
-
if (light
|
1494
|
+
if (light.isDirectionalLight) {
|
1422
1495
|
lightDef.type = "directional";
|
1423
|
-
} else if (light
|
1424
|
-
light.isPointLight) {
|
1496
|
+
} else if (light.isPointLight) {
|
1425
1497
|
lightDef.type = "point";
|
1426
1498
|
if (light.distance > 0)
|
1427
1499
|
lightDef.range = light.distance;
|
1428
|
-
} else if (light
|
1500
|
+
} else if (light.isSpotLight) {
|
1429
1501
|
lightDef.type = "spot";
|
1430
1502
|
if (light.distance > 0)
|
1431
1503
|
lightDef.range = light.distance;
|
@@ -1433,12 +1505,12 @@ class GLTFLightExtension {
|
|
1433
1505
|
lightDef.spot.innerConeAngle = (light.penumbra - 1) * light.angle * -1;
|
1434
1506
|
lightDef.spot.outerConeAngle = light.angle;
|
1435
1507
|
}
|
1436
|
-
if (
|
1508
|
+
if (light.decay !== void 0 && light.decay !== 2) {
|
1437
1509
|
console.warn(
|
1438
1510
|
"THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."
|
1439
1511
|
);
|
1440
1512
|
}
|
1441
|
-
if (
|
1513
|
+
if (light.target && (light.target.parent !== light || light.target.position.x !== 0 || light.target.position.y !== 0 || light.target.position.z !== -1)) {
|
1442
1514
|
console.warn(
|
1443
1515
|
"THREE.GLTFExporter: Light direction may be lost. For best results, make light.target a child of the light with position 0,0,-1."
|
1444
1516
|
);
|
@@ -1448,26 +1520,20 @@ class GLTFLightExtension {
|
|
1448
1520
|
json.extensions[this.name] = { lights: [] };
|
1449
1521
|
extensionsUsed[this.name] = true;
|
1450
1522
|
}
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
nodeDef.extensions[this.name] = { light: lights.length - 1 };
|
1456
|
-
}
|
1523
|
+
const lights = json.extensions[this.name].lights;
|
1524
|
+
lights.push(lightDef);
|
1525
|
+
nodeDef.extensions = nodeDef.extensions || {};
|
1526
|
+
nodeDef.extensions[this.name] = { light: lights.length - 1 };
|
1457
1527
|
}
|
1458
1528
|
}
|
1459
1529
|
class GLTFMaterialsUnlitExtension {
|
1460
1530
|
constructor(writer) {
|
1461
|
-
__publicField(this, "writer");
|
1462
|
-
__publicField(this, "name");
|
1463
1531
|
this.writer = writer;
|
1464
1532
|
this.name = "KHR_materials_unlit";
|
1465
1533
|
}
|
1466
1534
|
writeMaterial(material, materialDef) {
|
1467
|
-
if (!
|
1468
|
-
material.isMeshBasicMaterial)) {
|
1535
|
+
if (!material.isMeshBasicMaterial)
|
1469
1536
|
return;
|
1470
|
-
}
|
1471
1537
|
const writer = this.writer;
|
1472
1538
|
const extensionsUsed = writer.extensionsUsed;
|
1473
1539
|
materialDef.extensions = materialDef.extensions || {};
|
@@ -1477,36 +1543,78 @@ class GLTFMaterialsUnlitExtension {
|
|
1477
1543
|
materialDef.pbrMetallicRoughness.roughnessFactor = 0.9;
|
1478
1544
|
}
|
1479
1545
|
}
|
1480
|
-
class
|
1546
|
+
class GLTFMaterialsClearcoatExtension {
|
1481
1547
|
constructor(writer) {
|
1482
|
-
__publicField(this, "writer");
|
1483
|
-
__publicField(this, "name");
|
1484
1548
|
this.writer = writer;
|
1485
|
-
this.name = "
|
1549
|
+
this.name = "KHR_materials_clearcoat";
|
1486
1550
|
}
|
1487
1551
|
writeMaterial(material, materialDef) {
|
1488
|
-
if (!material.
|
1552
|
+
if (!material.isMeshPhysicalMaterial || material.clearcoat === 0)
|
1489
1553
|
return;
|
1490
1554
|
const writer = this.writer;
|
1491
1555
|
const extensionsUsed = writer.extensionsUsed;
|
1492
1556
|
const extensionDef = {};
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
extensionDef.
|
1501
|
-
|
1557
|
+
extensionDef.clearcoatFactor = material.clearcoat;
|
1558
|
+
if (material.clearcoatMap) {
|
1559
|
+
const clearcoatMapDef = {
|
1560
|
+
index: writer.processTexture(material.clearcoatMap),
|
1561
|
+
texCoord: material.clearcoatMap.channel
|
1562
|
+
};
|
1563
|
+
writer.applyTextureTransform(clearcoatMapDef, material.clearcoatMap);
|
1564
|
+
extensionDef.clearcoatTexture = clearcoatMapDef;
|
1565
|
+
}
|
1566
|
+
extensionDef.clearcoatRoughnessFactor = material.clearcoatRoughness;
|
1567
|
+
if (material.clearcoatRoughnessMap) {
|
1568
|
+
const clearcoatRoughnessMapDef = {
|
1569
|
+
index: writer.processTexture(material.clearcoatRoughnessMap),
|
1570
|
+
texCoord: material.clearcoatRoughnessMap.channel
|
1571
|
+
};
|
1572
|
+
writer.applyTextureTransform(clearcoatRoughnessMapDef, material.clearcoatRoughnessMap);
|
1573
|
+
extensionDef.clearcoatRoughnessTexture = clearcoatRoughnessMapDef;
|
1502
1574
|
}
|
1503
|
-
if (
|
1504
|
-
|
1575
|
+
if (material.clearcoatNormalMap) {
|
1576
|
+
const clearcoatNormalMapDef = {
|
1577
|
+
index: writer.processTexture(material.clearcoatNormalMap),
|
1578
|
+
texCoord: material.clearcoatNormalMap.channel
|
1579
|
+
};
|
1580
|
+
writer.applyTextureTransform(clearcoatNormalMapDef, material.clearcoatNormalMap);
|
1581
|
+
extensionDef.clearcoatNormalTexture = clearcoatNormalMapDef;
|
1505
1582
|
}
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1583
|
+
materialDef.extensions = materialDef.extensions || {};
|
1584
|
+
materialDef.extensions[this.name] = extensionDef;
|
1585
|
+
extensionsUsed[this.name] = true;
|
1586
|
+
}
|
1587
|
+
}
|
1588
|
+
class GLTFMaterialsIridescenceExtension {
|
1589
|
+
constructor(writer) {
|
1590
|
+
this.writer = writer;
|
1591
|
+
this.name = "KHR_materials_iridescence";
|
1592
|
+
}
|
1593
|
+
writeMaterial(material, materialDef) {
|
1594
|
+
if (!material.isMeshPhysicalMaterial || material.iridescence === 0)
|
1595
|
+
return;
|
1596
|
+
const writer = this.writer;
|
1597
|
+
const extensionsUsed = writer.extensionsUsed;
|
1598
|
+
const extensionDef = {};
|
1599
|
+
extensionDef.iridescenceFactor = material.iridescence;
|
1600
|
+
if (material.iridescenceMap) {
|
1601
|
+
const iridescenceMapDef = {
|
1602
|
+
index: writer.processTexture(material.iridescenceMap),
|
1603
|
+
texCoord: material.iridescenceMap.channel
|
1604
|
+
};
|
1605
|
+
writer.applyTextureTransform(iridescenceMapDef, material.iridescenceMap);
|
1606
|
+
extensionDef.iridescenceTexture = iridescenceMapDef;
|
1607
|
+
}
|
1608
|
+
extensionDef.iridescenceIor = material.iridescenceIOR;
|
1609
|
+
extensionDef.iridescenceThicknessMinimum = material.iridescenceThicknessRange[0];
|
1610
|
+
extensionDef.iridescenceThicknessMaximum = material.iridescenceThicknessRange[1];
|
1611
|
+
if (material.iridescenceThicknessMap) {
|
1612
|
+
const iridescenceThicknessMapDef = {
|
1613
|
+
index: writer.processTexture(material.iridescenceThicknessMap),
|
1614
|
+
texCoord: material.iridescenceThicknessMap.channel
|
1615
|
+
};
|
1616
|
+
writer.applyTextureTransform(iridescenceThicknessMapDef, material.iridescenceThicknessMap);
|
1617
|
+
extensionDef.iridescenceThicknessTexture = iridescenceThicknessMapDef;
|
1510
1618
|
}
|
1511
1619
|
materialDef.extensions = materialDef.extensions || {};
|
1512
1620
|
materialDef.extensions[this.name] = extensionDef;
|
@@ -1515,22 +1623,21 @@ class GLTFMaterialsPBRSpecularGlossiness {
|
|
1515
1623
|
}
|
1516
1624
|
class GLTFMaterialsTransmissionExtension {
|
1517
1625
|
constructor(writer) {
|
1518
|
-
__publicField(this, "writer");
|
1519
|
-
__publicField(this, "name");
|
1520
1626
|
this.writer = writer;
|
1521
1627
|
this.name = "KHR_materials_transmission";
|
1522
1628
|
}
|
1523
1629
|
writeMaterial(material, materialDef) {
|
1524
|
-
if (!
|
1525
|
-
material.isMeshPhysicalMaterial) || material.transmission === 0) {
|
1630
|
+
if (!material.isMeshPhysicalMaterial || material.transmission === 0)
|
1526
1631
|
return;
|
1527
|
-
}
|
1528
1632
|
const writer = this.writer;
|
1529
1633
|
const extensionsUsed = writer.extensionsUsed;
|
1530
1634
|
const extensionDef = {};
|
1531
1635
|
extensionDef.transmissionFactor = material.transmission;
|
1532
1636
|
if (material.transmissionMap) {
|
1533
|
-
const transmissionMapDef = {
|
1637
|
+
const transmissionMapDef = {
|
1638
|
+
index: writer.processTexture(material.transmissionMap),
|
1639
|
+
texCoord: material.transmissionMap.channel
|
1640
|
+
};
|
1534
1641
|
writer.applyTextureTransform(transmissionMapDef, material.transmissionMap);
|
1535
1642
|
extensionDef.transmissionTexture = transmissionMapDef;
|
1536
1643
|
}
|
@@ -1541,35 +1648,259 @@ class GLTFMaterialsTransmissionExtension {
|
|
1541
1648
|
}
|
1542
1649
|
class GLTFMaterialsVolumeExtension {
|
1543
1650
|
constructor(writer) {
|
1544
|
-
__publicField(this, "writer");
|
1545
|
-
__publicField(this, "name");
|
1546
1651
|
this.writer = writer;
|
1547
1652
|
this.name = "KHR_materials_volume";
|
1548
1653
|
}
|
1549
1654
|
writeMaterial(material, materialDef) {
|
1550
|
-
if (!
|
1551
|
-
material.isMeshPhysicalMaterial) || material.thickness === 0) {
|
1655
|
+
if (!material.isMeshPhysicalMaterial || material.transmission === 0)
|
1552
1656
|
return;
|
1553
|
-
}
|
1554
1657
|
const writer = this.writer;
|
1555
1658
|
const extensionsUsed = writer.extensionsUsed;
|
1556
1659
|
const extensionDef = {};
|
1557
|
-
extensionDef.
|
1660
|
+
extensionDef.thicknessFactor = material.thickness;
|
1558
1661
|
if (material.thicknessMap) {
|
1559
1662
|
const thicknessMapDef = {
|
1560
|
-
index: writer.processTexture(material.thicknessMap)
|
1663
|
+
index: writer.processTexture(material.thicknessMap),
|
1664
|
+
texCoord: material.thicknessMap.channel
|
1561
1665
|
};
|
1562
1666
|
writer.applyTextureTransform(thicknessMapDef, material.thicknessMap);
|
1563
1667
|
extensionDef.thicknessTexture = thicknessMapDef;
|
1564
1668
|
}
|
1565
1669
|
extensionDef.attenuationDistance = material.attenuationDistance;
|
1566
|
-
extensionDef.attenuationColor =
|
1567
|
-
|
1670
|
+
extensionDef.attenuationColor = material.attenuationColor.toArray();
|
1671
|
+
materialDef.extensions = materialDef.extensions || {};
|
1672
|
+
materialDef.extensions[this.name] = extensionDef;
|
1673
|
+
extensionsUsed[this.name] = true;
|
1674
|
+
}
|
1675
|
+
}
|
1676
|
+
class GLTFMaterialsIorExtension {
|
1677
|
+
constructor(writer) {
|
1678
|
+
this.writer = writer;
|
1679
|
+
this.name = "KHR_materials_ior";
|
1680
|
+
}
|
1681
|
+
writeMaterial(material, materialDef) {
|
1682
|
+
if (!material.isMeshPhysicalMaterial || material.ior === 1.5)
|
1683
|
+
return;
|
1684
|
+
const writer = this.writer;
|
1685
|
+
const extensionsUsed = writer.extensionsUsed;
|
1686
|
+
const extensionDef = {};
|
1687
|
+
extensionDef.ior = material.ior;
|
1688
|
+
materialDef.extensions = materialDef.extensions || {};
|
1689
|
+
materialDef.extensions[this.name] = extensionDef;
|
1690
|
+
extensionsUsed[this.name] = true;
|
1691
|
+
}
|
1692
|
+
}
|
1693
|
+
class GLTFMaterialsSpecularExtension {
|
1694
|
+
constructor(writer) {
|
1695
|
+
this.writer = writer;
|
1696
|
+
this.name = "KHR_materials_specular";
|
1697
|
+
}
|
1698
|
+
writeMaterial(material, materialDef) {
|
1699
|
+
if (!material.isMeshPhysicalMaterial || material.specularIntensity === 1 && material.specularColor.equals(DEFAULT_SPECULAR_COLOR) && !material.specularIntensityMap && !material.specularColorTexture)
|
1700
|
+
return;
|
1701
|
+
const writer = this.writer;
|
1702
|
+
const extensionsUsed = writer.extensionsUsed;
|
1703
|
+
const extensionDef = {};
|
1704
|
+
if (material.specularIntensityMap) {
|
1705
|
+
const specularIntensityMapDef = {
|
1706
|
+
index: writer.processTexture(material.specularIntensityMap),
|
1707
|
+
texCoord: material.specularIntensityMap.channel
|
1708
|
+
};
|
1709
|
+
writer.applyTextureTransform(specularIntensityMapDef, material.specularIntensityMap);
|
1710
|
+
extensionDef.specularTexture = specularIntensityMapDef;
|
1711
|
+
}
|
1712
|
+
if (material.specularColorMap) {
|
1713
|
+
const specularColorMapDef = {
|
1714
|
+
index: writer.processTexture(material.specularColorMap),
|
1715
|
+
texCoord: material.specularColorMap.channel
|
1716
|
+
};
|
1717
|
+
writer.applyTextureTransform(specularColorMapDef, material.specularColorMap);
|
1718
|
+
extensionDef.specularColorTexture = specularColorMapDef;
|
1719
|
+
}
|
1720
|
+
extensionDef.specularFactor = material.specularIntensity;
|
1721
|
+
extensionDef.specularColorFactor = material.specularColor.toArray();
|
1722
|
+
materialDef.extensions = materialDef.extensions || {};
|
1723
|
+
materialDef.extensions[this.name] = extensionDef;
|
1724
|
+
extensionsUsed[this.name] = true;
|
1725
|
+
}
|
1726
|
+
}
|
1727
|
+
class GLTFMaterialsSheenExtension {
|
1728
|
+
constructor(writer) {
|
1729
|
+
this.writer = writer;
|
1730
|
+
this.name = "KHR_materials_sheen";
|
1731
|
+
}
|
1732
|
+
writeMaterial(material, materialDef) {
|
1733
|
+
if (!material.isMeshPhysicalMaterial || material.sheen == 0)
|
1734
|
+
return;
|
1735
|
+
const writer = this.writer;
|
1736
|
+
const extensionsUsed = writer.extensionsUsed;
|
1737
|
+
const extensionDef = {};
|
1738
|
+
if (material.sheenRoughnessMap) {
|
1739
|
+
const sheenRoughnessMapDef = {
|
1740
|
+
index: writer.processTexture(material.sheenRoughnessMap),
|
1741
|
+
texCoord: material.sheenRoughnessMap.channel
|
1742
|
+
};
|
1743
|
+
writer.applyTextureTransform(sheenRoughnessMapDef, material.sheenRoughnessMap);
|
1744
|
+
extensionDef.sheenRoughnessTexture = sheenRoughnessMapDef;
|
1745
|
+
}
|
1746
|
+
if (material.sheenColorMap) {
|
1747
|
+
const sheenColorMapDef = {
|
1748
|
+
index: writer.processTexture(material.sheenColorMap),
|
1749
|
+
texCoord: material.sheenColorMap.channel
|
1750
|
+
};
|
1751
|
+
writer.applyTextureTransform(sheenColorMapDef, material.sheenColorMap);
|
1752
|
+
extensionDef.sheenColorTexture = sheenColorMapDef;
|
1753
|
+
}
|
1754
|
+
extensionDef.sheenRoughnessFactor = material.sheenRoughness;
|
1755
|
+
extensionDef.sheenColorFactor = material.sheenColor.toArray();
|
1756
|
+
materialDef.extensions = materialDef.extensions || {};
|
1757
|
+
materialDef.extensions[this.name] = extensionDef;
|
1758
|
+
extensionsUsed[this.name] = true;
|
1759
|
+
}
|
1760
|
+
}
|
1761
|
+
class GLTFMaterialsAnisotropyExtension {
|
1762
|
+
constructor(writer) {
|
1763
|
+
this.writer = writer;
|
1764
|
+
this.name = "KHR_materials_anisotropy";
|
1765
|
+
}
|
1766
|
+
writeMaterial(material, materialDef) {
|
1767
|
+
if (!material.isMeshPhysicalMaterial || material.anisotropy == 0)
|
1768
|
+
return;
|
1769
|
+
const writer = this.writer;
|
1770
|
+
const extensionsUsed = writer.extensionsUsed;
|
1771
|
+
const extensionDef = {};
|
1772
|
+
if (material.anisotropyMap) {
|
1773
|
+
const anisotropyMapDef = { index: writer.processTexture(material.anisotropyMap) };
|
1774
|
+
writer.applyTextureTransform(anisotropyMapDef, material.anisotropyMap);
|
1775
|
+
extensionDef.anisotropyTexture = anisotropyMapDef;
|
1776
|
+
}
|
1777
|
+
extensionDef.anisotropyStrength = material.anisotropy;
|
1778
|
+
extensionDef.anisotropyRotation = material.anisotropyRotation;
|
1568
1779
|
materialDef.extensions = materialDef.extensions || {};
|
1569
1780
|
materialDef.extensions[this.name] = extensionDef;
|
1570
1781
|
extensionsUsed[this.name] = true;
|
1571
1782
|
}
|
1572
1783
|
}
|
1784
|
+
class GLTFMaterialsEmissiveStrengthExtension {
|
1785
|
+
constructor(writer) {
|
1786
|
+
this.writer = writer;
|
1787
|
+
this.name = "KHR_materials_emissive_strength";
|
1788
|
+
}
|
1789
|
+
writeMaterial(material, materialDef) {
|
1790
|
+
if (!material.isMeshStandardMaterial || material.emissiveIntensity === 1)
|
1791
|
+
return;
|
1792
|
+
const writer = this.writer;
|
1793
|
+
const extensionsUsed = writer.extensionsUsed;
|
1794
|
+
const extensionDef = {};
|
1795
|
+
extensionDef.emissiveStrength = material.emissiveIntensity;
|
1796
|
+
materialDef.extensions = materialDef.extensions || {};
|
1797
|
+
materialDef.extensions[this.name] = extensionDef;
|
1798
|
+
extensionsUsed[this.name] = true;
|
1799
|
+
}
|
1800
|
+
}
|
1801
|
+
GLTFExporter.Utils = {
|
1802
|
+
insertKeyframe: function(track, time) {
|
1803
|
+
const tolerance = 1e-3;
|
1804
|
+
const valueSize = track.getValueSize();
|
1805
|
+
const times = new track.TimeBufferType(track.times.length + 1);
|
1806
|
+
const values = new track.ValueBufferType(track.values.length + valueSize);
|
1807
|
+
const interpolant = track.createInterpolant(new track.ValueBufferType(valueSize));
|
1808
|
+
let index;
|
1809
|
+
if (track.times.length === 0) {
|
1810
|
+
times[0] = time;
|
1811
|
+
for (let i = 0; i < valueSize; i++) {
|
1812
|
+
values[i] = 0;
|
1813
|
+
}
|
1814
|
+
index = 0;
|
1815
|
+
} else if (time < track.times[0]) {
|
1816
|
+
if (Math.abs(track.times[0] - time) < tolerance)
|
1817
|
+
return 0;
|
1818
|
+
times[0] = time;
|
1819
|
+
times.set(track.times, 1);
|
1820
|
+
values.set(interpolant.evaluate(time), 0);
|
1821
|
+
values.set(track.values, valueSize);
|
1822
|
+
index = 0;
|
1823
|
+
} else if (time > track.times[track.times.length - 1]) {
|
1824
|
+
if (Math.abs(track.times[track.times.length - 1] - time) < tolerance) {
|
1825
|
+
return track.times.length - 1;
|
1826
|
+
}
|
1827
|
+
times[times.length - 1] = time;
|
1828
|
+
times.set(track.times, 0);
|
1829
|
+
values.set(track.values, 0);
|
1830
|
+
values.set(interpolant.evaluate(time), track.values.length);
|
1831
|
+
index = times.length - 1;
|
1832
|
+
} else {
|
1833
|
+
for (let i = 0; i < track.times.length; i++) {
|
1834
|
+
if (Math.abs(track.times[i] - time) < tolerance)
|
1835
|
+
return i;
|
1836
|
+
if (track.times[i] < time && track.times[i + 1] > time) {
|
1837
|
+
times.set(track.times.slice(0, i + 1), 0);
|
1838
|
+
times[i + 1] = time;
|
1839
|
+
times.set(track.times.slice(i + 1), i + 2);
|
1840
|
+
values.set(track.values.slice(0, (i + 1) * valueSize), 0);
|
1841
|
+
values.set(interpolant.evaluate(time), (i + 1) * valueSize);
|
1842
|
+
values.set(track.values.slice((i + 1) * valueSize), (i + 2) * valueSize);
|
1843
|
+
index = i + 1;
|
1844
|
+
break;
|
1845
|
+
}
|
1846
|
+
}
|
1847
|
+
}
|
1848
|
+
track.times = times;
|
1849
|
+
track.values = values;
|
1850
|
+
return index;
|
1851
|
+
},
|
1852
|
+
mergeMorphTargetTracks: function(clip, root) {
|
1853
|
+
const tracks = [];
|
1854
|
+
const mergedTracks = {};
|
1855
|
+
const sourceTracks = clip.tracks;
|
1856
|
+
for (let i = 0; i < sourceTracks.length; ++i) {
|
1857
|
+
let sourceTrack = sourceTracks[i];
|
1858
|
+
const sourceTrackBinding = PropertyBinding.parseTrackName(sourceTrack.name);
|
1859
|
+
const sourceTrackNode = PropertyBinding.findNode(root, sourceTrackBinding.nodeName);
|
1860
|
+
if (sourceTrackBinding.propertyName !== "morphTargetInfluences" || sourceTrackBinding.propertyIndex === void 0) {
|
1861
|
+
tracks.push(sourceTrack);
|
1862
|
+
continue;
|
1863
|
+
}
|
1864
|
+
if (sourceTrack.createInterpolant !== sourceTrack.InterpolantFactoryMethodDiscrete && sourceTrack.createInterpolant !== sourceTrack.InterpolantFactoryMethodLinear) {
|
1865
|
+
if (sourceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
|
1866
|
+
throw new Error("THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.");
|
1867
|
+
}
|
1868
|
+
console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead.");
|
1869
|
+
sourceTrack = sourceTrack.clone();
|
1870
|
+
sourceTrack.setInterpolation(InterpolateLinear);
|
1871
|
+
}
|
1872
|
+
const targetCount = sourceTrackNode.morphTargetInfluences.length;
|
1873
|
+
const targetIndex = sourceTrackNode.morphTargetDictionary[sourceTrackBinding.propertyIndex];
|
1874
|
+
if (targetIndex === void 0) {
|
1875
|
+
throw new Error("THREE.GLTFExporter: Morph target name not found: " + sourceTrackBinding.propertyIndex);
|
1876
|
+
}
|
1877
|
+
let mergedTrack;
|
1878
|
+
if (mergedTracks[sourceTrackNode.uuid] === void 0) {
|
1879
|
+
mergedTrack = sourceTrack.clone();
|
1880
|
+
const values = new mergedTrack.ValueBufferType(targetCount * mergedTrack.times.length);
|
1881
|
+
for (let j = 0; j < mergedTrack.times.length; j++) {
|
1882
|
+
values[j * targetCount + targetIndex] = mergedTrack.values[j];
|
1883
|
+
}
|
1884
|
+
mergedTrack.name = (sourceTrackBinding.nodeName || "") + ".morphTargetInfluences";
|
1885
|
+
mergedTrack.values = values;
|
1886
|
+
mergedTracks[sourceTrackNode.uuid] = mergedTrack;
|
1887
|
+
tracks.push(mergedTrack);
|
1888
|
+
continue;
|
1889
|
+
}
|
1890
|
+
const sourceInterpolant = sourceTrack.createInterpolant(new sourceTrack.ValueBufferType(1));
|
1891
|
+
mergedTrack = mergedTracks[sourceTrackNode.uuid];
|
1892
|
+
for (let j = 0; j < mergedTrack.times.length; j++) {
|
1893
|
+
mergedTrack.values[j * targetCount + targetIndex] = sourceInterpolant.evaluate(mergedTrack.times[j]);
|
1894
|
+
}
|
1895
|
+
for (let j = 0; j < sourceTrack.times.length; j++) {
|
1896
|
+
const keyframeIndex = this.insertKeyframe(mergedTrack, sourceTrack.times[j]);
|
1897
|
+
mergedTrack.values[keyframeIndex * targetCount + targetIndex] = sourceTrack.values[j];
|
1898
|
+
}
|
1899
|
+
}
|
1900
|
+
clip.tracks = tracks;
|
1901
|
+
return clip;
|
1902
|
+
}
|
1903
|
+
};
|
1573
1904
|
export {
|
1574
1905
|
GLTFExporter
|
1575
1906
|
};
|