three-stdlib 2.22.9 → 2.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/TrackballControls.d.ts +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 +915 -581
- package/dist/exporters/GLTFExporter.mjs +915 -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, CompressedTexture, Source, 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,67 @@ 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 ("colorSpace" in map ? map.colorSpace === "srgb" : map.encoding === 3001) {
|
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
|
+
if ("colorSpace" in texture)
|
563
|
+
texture.colorSpace = "";
|
564
|
+
else
|
565
|
+
texture.encoding = 3e3;
|
566
|
+
texture.channel = (metalnessMap || roughnessMap).channel;
|
567
|
+
if (metalnessMap && roughnessMap && metalnessMap.channel !== roughnessMap.channel) {
|
568
|
+
console.warn("THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match.");
|
569
|
+
}
|
570
|
+
return texture;
|
571
|
+
}
|
449
572
|
/**
|
450
573
|
* Process a buffer to append to the default one.
|
451
574
|
* @param {ArrayBuffer} buffer
|
@@ -473,14 +596,19 @@ class GLTFWriter {
|
|
473
596
|
if (!json.bufferViews)
|
474
597
|
json.bufferViews = [];
|
475
598
|
let componentSize;
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
599
|
+
switch (componentType) {
|
600
|
+
case WEBGL_CONSTANTS.BYTE:
|
601
|
+
case WEBGL_CONSTANTS.UNSIGNED_BYTE:
|
602
|
+
componentSize = 1;
|
603
|
+
break;
|
604
|
+
case WEBGL_CONSTANTS.SHORT:
|
605
|
+
case WEBGL_CONSTANTS.UNSIGNED_SHORT:
|
606
|
+
componentSize = 2;
|
607
|
+
break;
|
608
|
+
default:
|
609
|
+
componentSize = 4;
|
610
|
+
}
|
611
|
+
const byteLength = getPaddedBufferSize(count * attribute.itemSize * componentSize);
|
484
612
|
const dataView = new DataView(new ArrayBuffer(byteLength));
|
485
613
|
let offset = 0;
|
486
614
|
for (let i = start; i < start + count; i++) {
|
@@ -497,18 +625,25 @@ class GLTFWriter {
|
|
497
625
|
value = attribute.getZ(i);
|
498
626
|
else if (a === 3)
|
499
627
|
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);
|
628
|
+
if (attribute.normalized === true) {
|
629
|
+
value = MathUtils.normalize(value, attribute.array);
|
510
630
|
}
|
511
631
|
}
|
632
|
+
if (componentType === WEBGL_CONSTANTS.FLOAT) {
|
633
|
+
dataView.setFloat32(offset, value, true);
|
634
|
+
} else if (componentType === WEBGL_CONSTANTS.INT) {
|
635
|
+
dataView.setInt32(offset, value, true);
|
636
|
+
} else if (componentType === WEBGL_CONSTANTS.UNSIGNED_INT) {
|
637
|
+
dataView.setUint32(offset, value, true);
|
638
|
+
} else if (componentType === WEBGL_CONSTANTS.SHORT) {
|
639
|
+
dataView.setInt16(offset, value, true);
|
640
|
+
} else if (componentType === WEBGL_CONSTANTS.UNSIGNED_SHORT) {
|
641
|
+
dataView.setUint16(offset, value, true);
|
642
|
+
} else if (componentType === WEBGL_CONSTANTS.BYTE) {
|
643
|
+
dataView.setInt8(offset, value);
|
644
|
+
} else if (componentType === WEBGL_CONSTANTS.UNSIGNED_BYTE) {
|
645
|
+
dataView.setUint8(offset, value);
|
646
|
+
}
|
512
647
|
offset += componentSize;
|
513
648
|
}
|
514
649
|
}
|
@@ -540,20 +675,18 @@ class GLTFWriter {
|
|
540
675
|
const json = writer.json;
|
541
676
|
if (!json.bufferViews)
|
542
677
|
json.bufferViews = [];
|
543
|
-
return new Promise((resolve)
|
544
|
-
const reader = new
|
678
|
+
return new Promise(function(resolve) {
|
679
|
+
const reader = new FileReader();
|
545
680
|
reader.readAsArrayBuffer(blob);
|
546
|
-
reader.onloadend = ()
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
resolve(json.bufferViews.push(bufferViewDef) - 1);
|
556
|
-
}
|
681
|
+
reader.onloadend = function() {
|
682
|
+
const buffer = getPaddedArrayBuffer(reader.result);
|
683
|
+
const bufferViewDef = {
|
684
|
+
buffer: writer.processBuffer(buffer),
|
685
|
+
byteOffset: writer.byteOffset,
|
686
|
+
byteLength: buffer.byteLength
|
687
|
+
};
|
688
|
+
writer.byteOffset += buffer.byteLength;
|
689
|
+
resolve(json.bufferViews.push(bufferViewDef) - 1);
|
557
690
|
};
|
558
691
|
});
|
559
692
|
}
|
@@ -566,139 +699,135 @@ class GLTFWriter {
|
|
566
699
|
* @return {Integer|null} Index of the processed accessor on the "accessors" array
|
567
700
|
*/
|
568
701
|
processAccessor(attribute, geometry, start, count) {
|
569
|
-
const options = this.options;
|
570
702
|
const json = this.json;
|
571
703
|
const types = {
|
572
704
|
1: "SCALAR",
|
573
705
|
2: "VEC2",
|
574
706
|
3: "VEC3",
|
575
707
|
4: "VEC4",
|
708
|
+
9: "MAT3",
|
576
709
|
16: "MAT4"
|
577
710
|
};
|
578
711
|
let componentType;
|
579
712
|
if (attribute.array.constructor === Float32Array) {
|
580
713
|
componentType = WEBGL_CONSTANTS.FLOAT;
|
714
|
+
} else if (attribute.array.constructor === Int32Array) {
|
715
|
+
componentType = WEBGL_CONSTANTS.INT;
|
581
716
|
} else if (attribute.array.constructor === Uint32Array) {
|
582
717
|
componentType = WEBGL_CONSTANTS.UNSIGNED_INT;
|
718
|
+
} else if (attribute.array.constructor === Int16Array) {
|
719
|
+
componentType = WEBGL_CONSTANTS.SHORT;
|
583
720
|
} else if (attribute.array.constructor === Uint16Array) {
|
584
721
|
componentType = WEBGL_CONSTANTS.UNSIGNED_SHORT;
|
722
|
+
} else if (attribute.array.constructor === Int8Array) {
|
723
|
+
componentType = WEBGL_CONSTANTS.BYTE;
|
585
724
|
} else if (attribute.array.constructor === Uint8Array) {
|
586
725
|
componentType = WEBGL_CONSTANTS.UNSIGNED_BYTE;
|
587
726
|
} else {
|
588
|
-
throw new Error(
|
727
|
+
throw new Error(
|
728
|
+
"THREE.GLTFExporter: Unsupported bufferAttribute component type: " + attribute.array.constructor.name
|
729
|
+
);
|
589
730
|
}
|
590
731
|
if (start === void 0)
|
591
732
|
start = 0;
|
592
733
|
if (count === void 0)
|
593
734
|
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
735
|
if (count === 0)
|
603
736
|
return null;
|
604
|
-
const minMax =
|
737
|
+
const minMax = getMinMax(attribute, start, count);
|
605
738
|
let bufferViewTarget;
|
606
739
|
if (geometry !== void 0) {
|
607
740
|
bufferViewTarget = attribute === geometry.index ? WEBGL_CONSTANTS.ELEMENT_ARRAY_BUFFER : WEBGL_CONSTANTS.ARRAY_BUFFER;
|
608
741
|
}
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
return json.accessors.push(accessorDef) - 1;
|
625
|
-
}
|
742
|
+
const bufferView = this.processBufferView(attribute, componentType, start, count, bufferViewTarget);
|
743
|
+
const accessorDef = {
|
744
|
+
bufferView: bufferView.id,
|
745
|
+
byteOffset: bufferView.byteOffset,
|
746
|
+
componentType,
|
747
|
+
count,
|
748
|
+
max: minMax.max,
|
749
|
+
min: minMax.min,
|
750
|
+
type: types[attribute.itemSize]
|
751
|
+
};
|
752
|
+
if (attribute.normalized === true)
|
753
|
+
accessorDef.normalized = true;
|
754
|
+
if (!json.accessors)
|
755
|
+
json.accessors = [];
|
756
|
+
return json.accessors.push(accessorDef) - 1;
|
626
757
|
}
|
627
758
|
/**
|
628
759
|
* Process image
|
629
760
|
* @param {Image} image to process
|
630
761
|
* @param {Integer} format of the image (RGBAFormat)
|
631
762
|
* @param {Boolean} flipY before writing out the image
|
763
|
+
* @param {String} mimeType export format
|
632
764
|
* @return {Integer} Index of the processed texture in the "images" array
|
633
765
|
*/
|
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");
|
766
|
+
processImage(image, format, flipY, mimeType = "image/png") {
|
767
|
+
if (image !== null) {
|
768
|
+
const writer = this;
|
769
|
+
const cache = writer.cache;
|
770
|
+
const json = writer.json;
|
771
|
+
const options = writer.options;
|
772
|
+
const pending = writer.pending;
|
773
|
+
if (!cache.images.has(image))
|
774
|
+
cache.images.set(image, {});
|
775
|
+
const cachedImages = cache.images.get(image);
|
776
|
+
const key = mimeType + ":flipY/" + flipY.toString();
|
777
|
+
if (cachedImages[key] !== void 0)
|
778
|
+
return cachedImages[key];
|
779
|
+
if (!json.images)
|
780
|
+
json.images = [];
|
781
|
+
const imageDef = { mimeType };
|
782
|
+
const canvas = getCanvas();
|
652
783
|
canvas.width = Math.min(image.width, options.maxTextureSize);
|
653
784
|
canvas.height = Math.min(image.height, options.maxTextureSize);
|
654
785
|
const ctx = canvas.getContext("2d");
|
655
|
-
if (flipY) {
|
656
|
-
ctx
|
657
|
-
ctx
|
786
|
+
if (flipY === true) {
|
787
|
+
ctx.translate(0, canvas.height);
|
788
|
+
ctx.scale(1, -1);
|
658
789
|
}
|
659
|
-
if (
|
660
|
-
ctx == null ? void 0 : ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
|
661
|
-
} else {
|
790
|
+
if (image.data !== void 0) {
|
662
791
|
if (format !== RGBAFormat) {
|
663
|
-
console.error("GLTFExporter: Only
|
792
|
+
console.error("GLTFExporter: Only RGBAFormat is supported.", format);
|
664
793
|
}
|
665
794
|
if (image.width > options.maxTextureSize || image.height > options.maxTextureSize) {
|
666
795
|
console.warn("GLTFExporter: Image size is bigger than maxTextureSize", image);
|
667
796
|
}
|
668
797
|
const data = new Uint8ClampedArray(image.height * image.width * 4);
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
data[i + 3] = image.data[i + 3];
|
675
|
-
}
|
798
|
+
for (let i = 0; i < data.length; i += 4) {
|
799
|
+
data[i + 0] = image.data[i + 0];
|
800
|
+
data[i + 1] = image.data[i + 1];
|
801
|
+
data[i + 2] = image.data[i + 2];
|
802
|
+
data[i + 3] = image.data[i + 3];
|
676
803
|
}
|
677
|
-
ctx
|
804
|
+
ctx.putImageData(new ImageData(data, image.width, image.height), 0, 0);
|
805
|
+
} else {
|
806
|
+
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
|
678
807
|
}
|
679
|
-
if (options.binary) {
|
808
|
+
if (options.binary === true) {
|
680
809
|
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);
|
810
|
+
getToBlobPromise(canvas, mimeType).then((blob) => writer.processBufferViewImage(blob)).then((bufferViewIndex) => {
|
811
|
+
imageDef.bufferView = bufferViewIndex;
|
690
812
|
})
|
691
813
|
);
|
692
814
|
} else {
|
693
|
-
|
815
|
+
if (canvas.toDataURL !== void 0) {
|
816
|
+
imageDef.uri = canvas.toDataURL(mimeType);
|
817
|
+
} else {
|
818
|
+
pending.push(
|
819
|
+
getToBlobPromise(canvas, mimeType).then((blob) => new FileReader().readAsDataURL(blob)).then((dataURL) => {
|
820
|
+
imageDef.uri = dataURL;
|
821
|
+
})
|
822
|
+
);
|
823
|
+
}
|
694
824
|
}
|
695
|
-
|
696
|
-
imageDef.uri = image.src;
|
697
|
-
}
|
698
|
-
const index = json.images.push(imageDef) - 1;
|
699
|
-
if (cachedImages !== void 0)
|
825
|
+
const index = json.images.push(imageDef) - 1;
|
700
826
|
cachedImages[key] = index;
|
701
|
-
|
827
|
+
return index;
|
828
|
+
} else {
|
829
|
+
throw new Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.");
|
830
|
+
}
|
702
831
|
}
|
703
832
|
/**
|
704
833
|
* Process sampler
|
@@ -723,15 +852,23 @@ class GLTFWriter {
|
|
723
852
|
* @return {Integer} Index of the processed texture in the "textures" array
|
724
853
|
*/
|
725
854
|
processTexture(map) {
|
855
|
+
const writer = this;
|
856
|
+
const options = writer.options;
|
726
857
|
const cache = this.cache;
|
727
858
|
const json = this.json;
|
728
859
|
if (cache.textures.has(map))
|
729
860
|
return cache.textures.get(map);
|
730
861
|
if (!json.textures)
|
731
862
|
json.textures = [];
|
863
|
+
if (map instanceof CompressedTexture) {
|
864
|
+
map = decompress(map, options.maxTextureSize);
|
865
|
+
}
|
866
|
+
let mimeType = map.userData.mimeType;
|
867
|
+
if (mimeType === "image/webp")
|
868
|
+
mimeType = "image/png";
|
732
869
|
const textureDef = {
|
733
870
|
sampler: this.processSampler(map),
|
734
|
-
source: this.processImage(map.image, map.format, map.flipY)
|
871
|
+
source: this.processImage(map.image, map.format, map.flipY, mimeType)
|
735
872
|
};
|
736
873
|
if (map.name)
|
737
874
|
textureDef.name = map.name;
|
@@ -752,74 +889,74 @@ class GLTFWriter {
|
|
752
889
|
const json = this.json;
|
753
890
|
if (cache.materials.has(material))
|
754
891
|
return cache.materials.get(material);
|
755
|
-
if (material
|
892
|
+
if (material.isShaderMaterial) {
|
756
893
|
console.warn("GLTFExporter: THREE.ShaderMaterial not supported.");
|
757
894
|
return null;
|
758
895
|
}
|
759
896
|
if (!json.materials)
|
760
897
|
json.materials = [];
|
761
898
|
const materialDef = { pbrMetallicRoughness: {} };
|
762
|
-
if (
|
763
|
-
material.isMeshBasicMaterial)) {
|
899
|
+
if (material.isMeshStandardMaterial !== true && material.isMeshBasicMaterial !== true) {
|
764
900
|
console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");
|
765
901
|
}
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
materialDef.pbrMetallicRoughness.baseColorFactor = color;
|
770
|
-
}
|
902
|
+
const color = material.color.toArray().concat([material.opacity]);
|
903
|
+
if (!equalArray(color, [1, 1, 1, 1])) {
|
904
|
+
materialDef.pbrMetallicRoughness.baseColorFactor = color;
|
771
905
|
}
|
772
|
-
if (material
|
906
|
+
if (material.isMeshStandardMaterial) {
|
773
907
|
materialDef.pbrMetallicRoughness.metallicFactor = material.metalness;
|
774
908
|
materialDef.pbrMetallicRoughness.roughnessFactor = material.roughness;
|
775
909
|
} else {
|
776
910
|
materialDef.pbrMetallicRoughness.metallicFactor = 0.5;
|
777
911
|
materialDef.pbrMetallicRoughness.roughnessFactor = 0.5;
|
778
912
|
}
|
779
|
-
if (material
|
780
|
-
|
781
|
-
|
782
|
-
this.
|
783
|
-
|
784
|
-
}
|
785
|
-
|
786
|
-
|
787
|
-
);
|
788
|
-
}
|
913
|
+
if (material.metalnessMap || material.roughnessMap) {
|
914
|
+
const metalRoughTexture = this.buildMetalRoughTexture(material.metalnessMap, material.roughnessMap);
|
915
|
+
const metalRoughMapDef = {
|
916
|
+
index: this.processTexture(metalRoughTexture),
|
917
|
+
channel: metalRoughTexture.channel
|
918
|
+
};
|
919
|
+
this.applyTextureTransform(metalRoughMapDef, metalRoughTexture);
|
920
|
+
materialDef.pbrMetallicRoughness.metallicRoughnessTexture = metalRoughMapDef;
|
789
921
|
}
|
790
|
-
if (
|
791
|
-
const baseColorMapDef = {
|
922
|
+
if (material.map) {
|
923
|
+
const baseColorMapDef = {
|
924
|
+
index: this.processTexture(material.map),
|
925
|
+
texCoord: material.map.channel
|
926
|
+
};
|
792
927
|
this.applyTextureTransform(baseColorMapDef, material.map);
|
793
928
|
materialDef.pbrMetallicRoughness.baseColorTexture = baseColorMapDef;
|
794
929
|
}
|
795
|
-
if (
|
796
|
-
const emissive = material.emissive
|
930
|
+
if (material.emissive) {
|
931
|
+
const emissive = material.emissive;
|
797
932
|
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
933
|
if (maxEmissiveComponent > 0) {
|
803
|
-
materialDef.emissiveFactor = emissive.toArray();
|
934
|
+
materialDef.emissiveFactor = material.emissive.toArray();
|
804
935
|
}
|
805
936
|
if (material.emissiveMap) {
|
806
|
-
const emissiveMapDef = {
|
937
|
+
const emissiveMapDef = {
|
938
|
+
index: this.processTexture(material.emissiveMap),
|
939
|
+
texCoord: material.emissiveMap.channel
|
940
|
+
};
|
807
941
|
this.applyTextureTransform(emissiveMapDef, material.emissiveMap);
|
808
942
|
materialDef.emissiveTexture = emissiveMapDef;
|
809
943
|
}
|
810
944
|
}
|
811
|
-
if (
|
812
|
-
const normalMapDef = {
|
945
|
+
if (material.normalMap) {
|
946
|
+
const normalMapDef = {
|
947
|
+
index: this.processTexture(material.normalMap),
|
948
|
+
texCoord: material.normalMap.channel
|
949
|
+
};
|
813
950
|
if (material.normalScale && material.normalScale.x !== 1) {
|
814
951
|
normalMapDef.scale = material.normalScale.x;
|
815
952
|
}
|
816
953
|
this.applyTextureTransform(normalMapDef, material.normalMap);
|
817
954
|
materialDef.normalTexture = normalMapDef;
|
818
955
|
}
|
819
|
-
if (
|
956
|
+
if (material.aoMap) {
|
820
957
|
const occlusionMapDef = {
|
821
958
|
index: this.processTexture(material.aoMap),
|
822
|
-
texCoord:
|
959
|
+
texCoord: material.aoMap.channel
|
823
960
|
};
|
824
961
|
if (material.aoMapIntensity !== 1) {
|
825
962
|
occlusionMapDef.strength = material.aoMapIntensity;
|
@@ -868,19 +1005,16 @@ class GLTFWriter {
|
|
868
1005
|
return cache.meshes.get(meshCacheKey);
|
869
1006
|
const geometry = mesh.geometry;
|
870
1007
|
let mode;
|
871
|
-
if (mesh
|
1008
|
+
if (mesh.isLineSegments) {
|
872
1009
|
mode = WEBGL_CONSTANTS.LINES;
|
873
|
-
} else if (mesh
|
1010
|
+
} else if (mesh.isLineLoop) {
|
874
1011
|
mode = WEBGL_CONSTANTS.LINE_LOOP;
|
875
|
-
} else if (mesh
|
1012
|
+
} else if (mesh.isLine) {
|
876
1013
|
mode = WEBGL_CONSTANTS.LINE_STRIP;
|
877
|
-
} else if (mesh
|
1014
|
+
} else if (mesh.isPoints) {
|
878
1015
|
mode = WEBGL_CONSTANTS.POINTS;
|
879
1016
|
} else {
|
880
|
-
mode =
|
881
|
-
}
|
882
|
-
if (!geometry.isBufferGeometry) {
|
883
|
-
throw new Error("THREE.GLTFExporter: Geometry is not of type THREE.BufferGeometry.");
|
1017
|
+
mode = mesh.material.wireframe ? WEBGL_CONSTANTS.LINES : WEBGL_CONSTANTS.TRIANGLES;
|
884
1018
|
}
|
885
1019
|
const meshDef = {};
|
886
1020
|
const attributes = {};
|
@@ -888,19 +1022,19 @@ class GLTFWriter {
|
|
888
1022
|
const targets = [];
|
889
1023
|
const nameConversion = {
|
890
1024
|
uv: "TEXCOORD_0",
|
891
|
-
uv2: "TEXCOORD_1",
|
1025
|
+
[REVISION.replace(/\D+/g, "") >= 152 ? "uv1" : "uv2"]: "TEXCOORD_1",
|
892
1026
|
color: "COLOR_0",
|
893
1027
|
skinWeight: "WEIGHTS_0",
|
894
1028
|
skinIndex: "JOINTS_0"
|
895
1029
|
};
|
896
1030
|
const originalNormal = geometry.getAttribute("normal");
|
897
|
-
if (originalNormal !== void 0 && !
|
1031
|
+
if (originalNormal !== void 0 && !this.isNormalizedNormalAttribute(originalNormal)) {
|
898
1032
|
console.warn("THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one.");
|
899
1033
|
geometry.setAttribute("normal", this.createNormalizedNormalAttribute(originalNormal));
|
900
1034
|
}
|
901
1035
|
let modifiedAttribute = null;
|
902
1036
|
for (let attributeName in geometry.attributes) {
|
903
|
-
if (attributeName.
|
1037
|
+
if (attributeName.slice(0, 5) === "morph")
|
904
1038
|
continue;
|
905
1039
|
const attribute = geometry.attributes[attributeName];
|
906
1040
|
attributeName = nameConversion[attributeName] || attributeName.toUpperCase();
|
@@ -917,8 +1051,11 @@ class GLTFWriter {
|
|
917
1051
|
console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.');
|
918
1052
|
modifiedAttribute = new BufferAttribute(new Uint16Array(array), attribute.itemSize, attribute.normalized);
|
919
1053
|
}
|
920
|
-
const accessor =
|
921
|
-
if (accessor) {
|
1054
|
+
const accessor = this.processAccessor(modifiedAttribute || attribute, geometry);
|
1055
|
+
if (accessor !== null) {
|
1056
|
+
if (!attributeName.startsWith("_")) {
|
1057
|
+
this.detectMeshQuantization(attributeName, attribute);
|
1058
|
+
}
|
922
1059
|
attributes[attributeName] = accessor;
|
923
1060
|
cache.attributes.set(this.getUID(attribute), accessor);
|
924
1061
|
}
|
@@ -950,26 +1087,27 @@ class GLTFWriter {
|
|
950
1087
|
const attribute = geometry.morphAttributes[attributeName][i];
|
951
1088
|
const gltfAttributeName = attributeName.toUpperCase();
|
952
1089
|
const baseAttribute = geometry.attributes[attributeName];
|
953
|
-
if (cache.attributes.has(this.getUID(attribute))) {
|
954
|
-
target[gltfAttributeName] = cache.attributes.get(this.getUID(attribute));
|
1090
|
+
if (cache.attributes.has(this.getUID(attribute, true))) {
|
1091
|
+
target[gltfAttributeName] = cache.attributes.get(this.getUID(attribute, true));
|
955
1092
|
continue;
|
956
1093
|
}
|
957
1094
|
const relativeAttribute = attribute.clone();
|
958
1095
|
if (!geometry.morphTargetsRelative) {
|
959
1096
|
for (let j = 0, jl = attribute.count; j < jl; j++) {
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
1097
|
+
for (let a = 0; a < attribute.itemSize; a++) {
|
1098
|
+
if (a === 0)
|
1099
|
+
relativeAttribute.setX(j, attribute.getX(j) - baseAttribute.getX(j));
|
1100
|
+
if (a === 1)
|
1101
|
+
relativeAttribute.setY(j, attribute.getY(j) - baseAttribute.getY(j));
|
1102
|
+
if (a === 2)
|
1103
|
+
relativeAttribute.setZ(j, attribute.getZ(j) - baseAttribute.getZ(j));
|
1104
|
+
if (a === 3)
|
1105
|
+
relativeAttribute.setW(j, attribute.getW(j) - baseAttribute.getW(j));
|
1106
|
+
}
|
966
1107
|
}
|
967
1108
|
}
|
968
|
-
|
969
|
-
|
970
|
-
target[gltfAttributeName] = accessor;
|
971
|
-
}
|
972
|
-
cache.attributes.set(this.getUID(baseAttribute), target[gltfAttributeName]);
|
1109
|
+
target[gltfAttributeName] = this.processAccessor(relativeAttribute, geometry);
|
1110
|
+
cache.attributes.set(this.getUID(baseAttribute, true), target[gltfAttributeName]);
|
973
1111
|
}
|
974
1112
|
targets.push(target);
|
975
1113
|
weights.push(mesh.morphTargetInfluences[i]);
|
@@ -992,15 +1130,13 @@ class GLTFWriter {
|
|
992
1130
|
mode,
|
993
1131
|
attributes
|
994
1132
|
};
|
995
|
-
|
996
|
-
this.serializeUserData(geometry, primitive);
|
997
|
-
}
|
1133
|
+
this.serializeUserData(geometry, primitive);
|
998
1134
|
if (targets.length > 0)
|
999
1135
|
primitive.targets = targets;
|
1000
1136
|
if (geometry.index !== null) {
|
1001
1137
|
let cacheKey = this.getUID(geometry.index);
|
1002
1138
|
if (groups[i].start !== void 0 || groups[i].count !== void 0) {
|
1003
|
-
cacheKey +=
|
1139
|
+
cacheKey += ":" + groups[i].start + ":" + groups[i].count;
|
1004
1140
|
}
|
1005
1141
|
if (cache.attributes.has(cacheKey)) {
|
1006
1142
|
primitive.indices = cache.attributes.get(cacheKey);
|
@@ -1011,16 +1147,10 @@ class GLTFWriter {
|
|
1011
1147
|
if (primitive.indices === null)
|
1012
1148
|
delete primitive.indices;
|
1013
1149
|
}
|
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
|
-
}
|
1150
|
+
const material = this.processMaterial(materials[groups[i].materialIndex]);
|
1151
|
+
if (material !== null)
|
1152
|
+
primitive.material = material;
|
1153
|
+
primitives.push(primitive);
|
1024
1154
|
}
|
1025
1155
|
meshDef.primitives = primitives;
|
1026
1156
|
if (!json.meshes)
|
@@ -1032,6 +1162,45 @@ class GLTFWriter {
|
|
1032
1162
|
cache.meshes.set(meshCacheKey, index);
|
1033
1163
|
return index;
|
1034
1164
|
}
|
1165
|
+
/**
|
1166
|
+
* If a vertex attribute with a
|
1167
|
+
* [non-standard data type](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview)
|
1168
|
+
* is used, it is checked whether it is a valid data type according to the
|
1169
|
+
* [KHR_mesh_quantization](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_mesh_quantization/README.md)
|
1170
|
+
* extension.
|
1171
|
+
* In this case the extension is automatically added to the list of used extensions.
|
1172
|
+
*
|
1173
|
+
* @param {string} attributeName
|
1174
|
+
* @param {THREE.BufferAttribute} attribute
|
1175
|
+
*/
|
1176
|
+
detectMeshQuantization(attributeName, attribute) {
|
1177
|
+
if (this.extensionsUsed[KHR_MESH_QUANTIZATION])
|
1178
|
+
return;
|
1179
|
+
let attrType = void 0;
|
1180
|
+
switch (attribute.array.constructor) {
|
1181
|
+
case Int8Array:
|
1182
|
+
attrType = "byte";
|
1183
|
+
break;
|
1184
|
+
case Uint8Array:
|
1185
|
+
attrType = "unsigned byte";
|
1186
|
+
break;
|
1187
|
+
case Int16Array:
|
1188
|
+
attrType = "short";
|
1189
|
+
break;
|
1190
|
+
case Uint16Array:
|
1191
|
+
attrType = "unsigned short";
|
1192
|
+
break;
|
1193
|
+
default:
|
1194
|
+
return;
|
1195
|
+
}
|
1196
|
+
if (attribute.normalized)
|
1197
|
+
attrType += " normalized";
|
1198
|
+
const attrNamePrefix = attributeName.split("_", 1)[0];
|
1199
|
+
if (KHR_mesh_quantization_ExtraAttrTypes[attrNamePrefix] && KHR_mesh_quantization_ExtraAttrTypes[attrNamePrefix].includes(attrType)) {
|
1200
|
+
this.extensionsUsed[KHR_MESH_QUANTIZATION] = true;
|
1201
|
+
this.extensionsRequired[KHR_MESH_QUANTIZATION] = true;
|
1202
|
+
}
|
1203
|
+
}
|
1035
1204
|
/**
|
1036
1205
|
* Process camera
|
1037
1206
|
* @param {THREE.Camera} camera Camera to process
|
@@ -1041,18 +1210,18 @@ class GLTFWriter {
|
|
1041
1210
|
const json = this.json;
|
1042
1211
|
if (!json.cameras)
|
1043
1212
|
json.cameras = [];
|
1044
|
-
const isOrtho = camera
|
1213
|
+
const isOrtho = camera.isOrthographicCamera;
|
1045
1214
|
const cameraDef = {
|
1046
1215
|
type: isOrtho ? "orthographic" : "perspective"
|
1047
1216
|
};
|
1048
|
-
if (
|
1217
|
+
if (isOrtho) {
|
1049
1218
|
cameraDef.orthographic = {
|
1050
1219
|
xmag: camera.right * 2,
|
1051
1220
|
ymag: camera.top * 2,
|
1052
1221
|
zfar: camera.far <= 0 ? 1e-3 : camera.far,
|
1053
1222
|
znear: camera.near < 0 ? 0 : camera.near
|
1054
1223
|
};
|
1055
|
-
} else
|
1224
|
+
} else {
|
1056
1225
|
cameraDef.perspective = {
|
1057
1226
|
aspectRatio: camera.aspect,
|
1058
1227
|
yfov: MathUtils.degToRad(camera.fov),
|
@@ -1089,7 +1258,7 @@ class GLTFWriter {
|
|
1089
1258
|
let trackNode = PropertyBinding.findNode(root, trackBinding.nodeName);
|
1090
1259
|
const trackProperty = PATH_PROPERTIES[trackBinding.propertyName];
|
1091
1260
|
if (trackBinding.objectName === "bones") {
|
1092
|
-
if (trackNode.isSkinnedMesh) {
|
1261
|
+
if (trackNode.isSkinnedMesh === true) {
|
1093
1262
|
trackNode = trackNode.skeleton.getBoneByName(trackBinding.objectIndex);
|
1094
1263
|
} else {
|
1095
1264
|
trackNode = void 0;
|
@@ -1105,7 +1274,7 @@ class GLTFWriter {
|
|
1105
1274
|
outputItemSize /= trackNode.morphTargetInfluences.length;
|
1106
1275
|
}
|
1107
1276
|
let interpolation;
|
1108
|
-
if (track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
|
1277
|
+
if (track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === true) {
|
1109
1278
|
interpolation = "CUBICSPLINE";
|
1110
1279
|
outputItemSize /= 3;
|
1111
1280
|
} else if (track.getInterpolation() === InterpolateDiscrete) {
|
@@ -1140,34 +1309,30 @@ class GLTFWriter {
|
|
1140
1309
|
processSkin(object) {
|
1141
1310
|
const json = this.json;
|
1142
1311
|
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 {
|
1312
|
+
const node = json.nodes[nodeMap.get(object)];
|
1313
|
+
const skeleton = object.skeleton;
|
1314
|
+
if (skeleton === void 0)
|
1169
1315
|
return null;
|
1170
|
-
|
1316
|
+
const rootJoint = object.skeleton.bones[0];
|
1317
|
+
if (rootJoint === void 0)
|
1318
|
+
return null;
|
1319
|
+
const joints = [];
|
1320
|
+
const inverseBindMatrices = new Float32Array(skeleton.bones.length * 16);
|
1321
|
+
const temporaryBoneInverse = new Matrix4();
|
1322
|
+
for (let i = 0; i < skeleton.bones.length; ++i) {
|
1323
|
+
joints.push(nodeMap.get(skeleton.bones[i]));
|
1324
|
+
temporaryBoneInverse.copy(skeleton.boneInverses[i]);
|
1325
|
+
temporaryBoneInverse.multiply(object.bindMatrix).toArray(inverseBindMatrices, i * 16);
|
1326
|
+
}
|
1327
|
+
if (json.skins === void 0)
|
1328
|
+
json.skins = [];
|
1329
|
+
json.skins.push({
|
1330
|
+
inverseBindMatrices: this.processAccessor(new BufferAttribute(inverseBindMatrices, 16)),
|
1331
|
+
joints,
|
1332
|
+
skeleton: nodeMap.get(rootJoint)
|
1333
|
+
});
|
1334
|
+
const skinIndex = node.skin = json.skins.length - 1;
|
1335
|
+
return skinIndex;
|
1171
1336
|
}
|
1172
1337
|
/**
|
1173
1338
|
* Process Object3D node
|
@@ -1185,40 +1350,40 @@ class GLTFWriter {
|
|
1185
1350
|
const rotation = object.quaternion.toArray();
|
1186
1351
|
const position = object.position.toArray();
|
1187
1352
|
const scale = object.scale.toArray();
|
1188
|
-
if (!
|
1353
|
+
if (!equalArray(rotation, [0, 0, 0, 1])) {
|
1189
1354
|
nodeDef.rotation = rotation;
|
1190
1355
|
}
|
1191
|
-
if (!
|
1356
|
+
if (!equalArray(position, [0, 0, 0])) {
|
1192
1357
|
nodeDef.translation = position;
|
1193
1358
|
}
|
1194
|
-
if (!
|
1359
|
+
if (!equalArray(scale, [1, 1, 1])) {
|
1195
1360
|
nodeDef.scale = scale;
|
1196
1361
|
}
|
1197
1362
|
} else {
|
1198
1363
|
if (object.matrixAutoUpdate) {
|
1199
1364
|
object.updateMatrix();
|
1200
1365
|
}
|
1201
|
-
if (
|
1366
|
+
if (isIdentityMatrix(object.matrix) === false) {
|
1202
1367
|
nodeDef.matrix = object.matrix.elements;
|
1203
1368
|
}
|
1204
1369
|
}
|
1205
1370
|
if (object.name !== "")
|
1206
1371
|
nodeDef.name = String(object.name);
|
1207
1372
|
this.serializeUserData(object, nodeDef);
|
1208
|
-
if (
|
1373
|
+
if (object.isMesh || object.isLine || object.isPoints) {
|
1209
1374
|
const meshIndex = this.processMesh(object);
|
1210
1375
|
if (meshIndex !== null)
|
1211
1376
|
nodeDef.mesh = meshIndex;
|
1212
|
-
} else if (object
|
1377
|
+
} else if (object.isCamera) {
|
1213
1378
|
nodeDef.camera = this.processCamera(object);
|
1214
1379
|
}
|
1215
|
-
if (object
|
1380
|
+
if (object.isSkinnedMesh)
|
1216
1381
|
this.skins.push(object);
|
1217
1382
|
if (object.children.length > 0) {
|
1218
1383
|
const children = [];
|
1219
1384
|
for (let i = 0, l = object.children.length; i < l; i++) {
|
1220
1385
|
const child = object.children[i];
|
1221
|
-
if (child.visible ||
|
1386
|
+
if (child.visible || options.onlyVisible === false) {
|
1222
1387
|
const nodeIndex2 = this.processNode(child);
|
1223
1388
|
if (nodeIndex2 !== null)
|
1224
1389
|
children.push(nodeIndex2);
|
@@ -1252,7 +1417,7 @@ class GLTFWriter {
|
|
1252
1417
|
const nodes = [];
|
1253
1418
|
for (let i = 0, l = scene.children.length; i < l; i++) {
|
1254
1419
|
const child = scene.children[i];
|
1255
|
-
if (child.visible ||
|
1420
|
+
if (child.visible || options.onlyVisible === false) {
|
1256
1421
|
const nodeIndex = this.processNode(child);
|
1257
1422
|
if (nodeIndex !== null)
|
1258
1423
|
nodes.push(nodeIndex);
|
@@ -1262,6 +1427,10 @@ class GLTFWriter {
|
|
1262
1427
|
sceneDef.nodes = nodes;
|
1263
1428
|
this.serializeUserData(scene, sceneDef);
|
1264
1429
|
}
|
1430
|
+
/**
|
1431
|
+
* Creates a Scene to hold a list of objects and parse it
|
1432
|
+
* @param {Array} objects List of objects to process
|
1433
|
+
*/
|
1265
1434
|
processObjects(objects) {
|
1266
1435
|
const scene = new Scene();
|
1267
1436
|
scene.name = "AuxScene";
|
@@ -1281,9 +1450,8 @@ class GLTFWriter {
|
|
1281
1450
|
});
|
1282
1451
|
const objectsWithoutScene = [];
|
1283
1452
|
for (let i = 0; i < input.length; i++) {
|
1284
|
-
|
1285
|
-
|
1286
|
-
this.processScene(inputScene);
|
1453
|
+
if (input[i] instanceof Scene) {
|
1454
|
+
this.processScene(input[i]);
|
1287
1455
|
} else {
|
1288
1456
|
objectsWithoutScene.push(input[i]);
|
1289
1457
|
}
|
@@ -1293,7 +1461,7 @@ class GLTFWriter {
|
|
1293
1461
|
for (let i = 0; i < this.skins.length; ++i) {
|
1294
1462
|
this.processSkin(this.skins[i]);
|
1295
1463
|
}
|
1296
|
-
for (let i = 0;
|
1464
|
+
for (let i = 0; i < options.animations.length; ++i) {
|
1297
1465
|
this.processAnimation(options.animations[i], input[0]);
|
1298
1466
|
}
|
1299
1467
|
this._invokeAll(function(ext) {
|
@@ -1305,108 +1473,16 @@ class GLTFWriter {
|
|
1305
1473
|
func(this.plugins[i]);
|
1306
1474
|
}
|
1307
1475
|
}
|
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
1476
|
}
|
1398
1477
|
class GLTFLightExtension {
|
1399
1478
|
constructor(writer) {
|
1400
|
-
__publicField(this, "writer");
|
1401
|
-
__publicField(this, "name");
|
1402
1479
|
this.writer = writer;
|
1403
1480
|
this.name = "KHR_lights_punctual";
|
1404
1481
|
}
|
1405
1482
|
writeNode(light, nodeDef) {
|
1406
1483
|
if (!light.isLight)
|
1407
1484
|
return;
|
1408
|
-
if (!
|
1409
|
-
!(light instanceof PointLight && light.isPointLight) && !(light instanceof SpotLight && light.isSpotLight)) {
|
1485
|
+
if (!light.isDirectionalLight && !light.isPointLight && !light.isSpotLight) {
|
1410
1486
|
console.warn("THREE.GLTFExporter: Only directional, point, and spot lights are supported.", light);
|
1411
1487
|
return;
|
1412
1488
|
}
|
@@ -1418,14 +1494,13 @@ class GLTFLightExtension {
|
|
1418
1494
|
lightDef.name = light.name;
|
1419
1495
|
lightDef.color = light.color.toArray();
|
1420
1496
|
lightDef.intensity = light.intensity;
|
1421
|
-
if (light
|
1497
|
+
if (light.isDirectionalLight) {
|
1422
1498
|
lightDef.type = "directional";
|
1423
|
-
} else if (light
|
1424
|
-
light.isPointLight) {
|
1499
|
+
} else if (light.isPointLight) {
|
1425
1500
|
lightDef.type = "point";
|
1426
1501
|
if (light.distance > 0)
|
1427
1502
|
lightDef.range = light.distance;
|
1428
|
-
} else if (light
|
1503
|
+
} else if (light.isSpotLight) {
|
1429
1504
|
lightDef.type = "spot";
|
1430
1505
|
if (light.distance > 0)
|
1431
1506
|
lightDef.range = light.distance;
|
@@ -1433,12 +1508,12 @@ class GLTFLightExtension {
|
|
1433
1508
|
lightDef.spot.innerConeAngle = (light.penumbra - 1) * light.angle * -1;
|
1434
1509
|
lightDef.spot.outerConeAngle = light.angle;
|
1435
1510
|
}
|
1436
|
-
if (
|
1511
|
+
if (light.decay !== void 0 && light.decay !== 2) {
|
1437
1512
|
console.warn(
|
1438
1513
|
"THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."
|
1439
1514
|
);
|
1440
1515
|
}
|
1441
|
-
if (
|
1516
|
+
if (light.target && (light.target.parent !== light || light.target.position.x !== 0 || light.target.position.y !== 0 || light.target.position.z !== -1)) {
|
1442
1517
|
console.warn(
|
1443
1518
|
"THREE.GLTFExporter: Light direction may be lost. For best results, make light.target a child of the light with position 0,0,-1."
|
1444
1519
|
);
|
@@ -1448,26 +1523,20 @@ class GLTFLightExtension {
|
|
1448
1523
|
json.extensions[this.name] = { lights: [] };
|
1449
1524
|
extensionsUsed[this.name] = true;
|
1450
1525
|
}
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
nodeDef.extensions[this.name] = { light: lights.length - 1 };
|
1456
|
-
}
|
1526
|
+
const lights = json.extensions[this.name].lights;
|
1527
|
+
lights.push(lightDef);
|
1528
|
+
nodeDef.extensions = nodeDef.extensions || {};
|
1529
|
+
nodeDef.extensions[this.name] = { light: lights.length - 1 };
|
1457
1530
|
}
|
1458
1531
|
}
|
1459
1532
|
class GLTFMaterialsUnlitExtension {
|
1460
1533
|
constructor(writer) {
|
1461
|
-
__publicField(this, "writer");
|
1462
|
-
__publicField(this, "name");
|
1463
1534
|
this.writer = writer;
|
1464
1535
|
this.name = "KHR_materials_unlit";
|
1465
1536
|
}
|
1466
1537
|
writeMaterial(material, materialDef) {
|
1467
|
-
if (!
|
1468
|
-
material.isMeshBasicMaterial)) {
|
1538
|
+
if (!material.isMeshBasicMaterial)
|
1469
1539
|
return;
|
1470
|
-
}
|
1471
1540
|
const writer = this.writer;
|
1472
1541
|
const extensionsUsed = writer.extensionsUsed;
|
1473
1542
|
materialDef.extensions = materialDef.extensions || {};
|
@@ -1477,36 +1546,78 @@ class GLTFMaterialsUnlitExtension {
|
|
1477
1546
|
materialDef.pbrMetallicRoughness.roughnessFactor = 0.9;
|
1478
1547
|
}
|
1479
1548
|
}
|
1480
|
-
class
|
1549
|
+
class GLTFMaterialsClearcoatExtension {
|
1481
1550
|
constructor(writer) {
|
1482
|
-
__publicField(this, "writer");
|
1483
|
-
__publicField(this, "name");
|
1484
1551
|
this.writer = writer;
|
1485
|
-
this.name = "
|
1552
|
+
this.name = "KHR_materials_clearcoat";
|
1486
1553
|
}
|
1487
1554
|
writeMaterial(material, materialDef) {
|
1488
|
-
if (!material.
|
1555
|
+
if (!material.isMeshPhysicalMaterial || material.clearcoat === 0)
|
1489
1556
|
return;
|
1490
1557
|
const writer = this.writer;
|
1491
1558
|
const extensionsUsed = writer.extensionsUsed;
|
1492
1559
|
const extensionDef = {};
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
extensionDef.
|
1501
|
-
|
1560
|
+
extensionDef.clearcoatFactor = material.clearcoat;
|
1561
|
+
if (material.clearcoatMap) {
|
1562
|
+
const clearcoatMapDef = {
|
1563
|
+
index: writer.processTexture(material.clearcoatMap),
|
1564
|
+
texCoord: material.clearcoatMap.channel
|
1565
|
+
};
|
1566
|
+
writer.applyTextureTransform(clearcoatMapDef, material.clearcoatMap);
|
1567
|
+
extensionDef.clearcoatTexture = clearcoatMapDef;
|
1568
|
+
}
|
1569
|
+
extensionDef.clearcoatRoughnessFactor = material.clearcoatRoughness;
|
1570
|
+
if (material.clearcoatRoughnessMap) {
|
1571
|
+
const clearcoatRoughnessMapDef = {
|
1572
|
+
index: writer.processTexture(material.clearcoatRoughnessMap),
|
1573
|
+
texCoord: material.clearcoatRoughnessMap.channel
|
1574
|
+
};
|
1575
|
+
writer.applyTextureTransform(clearcoatRoughnessMapDef, material.clearcoatRoughnessMap);
|
1576
|
+
extensionDef.clearcoatRoughnessTexture = clearcoatRoughnessMapDef;
|
1502
1577
|
}
|
1503
|
-
if (
|
1504
|
-
|
1578
|
+
if (material.clearcoatNormalMap) {
|
1579
|
+
const clearcoatNormalMapDef = {
|
1580
|
+
index: writer.processTexture(material.clearcoatNormalMap),
|
1581
|
+
texCoord: material.clearcoatNormalMap.channel
|
1582
|
+
};
|
1583
|
+
writer.applyTextureTransform(clearcoatNormalMapDef, material.clearcoatNormalMap);
|
1584
|
+
extensionDef.clearcoatNormalTexture = clearcoatNormalMapDef;
|
1505
1585
|
}
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1586
|
+
materialDef.extensions = materialDef.extensions || {};
|
1587
|
+
materialDef.extensions[this.name] = extensionDef;
|
1588
|
+
extensionsUsed[this.name] = true;
|
1589
|
+
}
|
1590
|
+
}
|
1591
|
+
class GLTFMaterialsIridescenceExtension {
|
1592
|
+
constructor(writer) {
|
1593
|
+
this.writer = writer;
|
1594
|
+
this.name = "KHR_materials_iridescence";
|
1595
|
+
}
|
1596
|
+
writeMaterial(material, materialDef) {
|
1597
|
+
if (!material.isMeshPhysicalMaterial || material.iridescence === 0)
|
1598
|
+
return;
|
1599
|
+
const writer = this.writer;
|
1600
|
+
const extensionsUsed = writer.extensionsUsed;
|
1601
|
+
const extensionDef = {};
|
1602
|
+
extensionDef.iridescenceFactor = material.iridescence;
|
1603
|
+
if (material.iridescenceMap) {
|
1604
|
+
const iridescenceMapDef = {
|
1605
|
+
index: writer.processTexture(material.iridescenceMap),
|
1606
|
+
texCoord: material.iridescenceMap.channel
|
1607
|
+
};
|
1608
|
+
writer.applyTextureTransform(iridescenceMapDef, material.iridescenceMap);
|
1609
|
+
extensionDef.iridescenceTexture = iridescenceMapDef;
|
1610
|
+
}
|
1611
|
+
extensionDef.iridescenceIor = material.iridescenceIOR;
|
1612
|
+
extensionDef.iridescenceThicknessMinimum = material.iridescenceThicknessRange[0];
|
1613
|
+
extensionDef.iridescenceThicknessMaximum = material.iridescenceThicknessRange[1];
|
1614
|
+
if (material.iridescenceThicknessMap) {
|
1615
|
+
const iridescenceThicknessMapDef = {
|
1616
|
+
index: writer.processTexture(material.iridescenceThicknessMap),
|
1617
|
+
texCoord: material.iridescenceThicknessMap.channel
|
1618
|
+
};
|
1619
|
+
writer.applyTextureTransform(iridescenceThicknessMapDef, material.iridescenceThicknessMap);
|
1620
|
+
extensionDef.iridescenceThicknessTexture = iridescenceThicknessMapDef;
|
1510
1621
|
}
|
1511
1622
|
materialDef.extensions = materialDef.extensions || {};
|
1512
1623
|
materialDef.extensions[this.name] = extensionDef;
|
@@ -1515,22 +1626,21 @@ class GLTFMaterialsPBRSpecularGlossiness {
|
|
1515
1626
|
}
|
1516
1627
|
class GLTFMaterialsTransmissionExtension {
|
1517
1628
|
constructor(writer) {
|
1518
|
-
__publicField(this, "writer");
|
1519
|
-
__publicField(this, "name");
|
1520
1629
|
this.writer = writer;
|
1521
1630
|
this.name = "KHR_materials_transmission";
|
1522
1631
|
}
|
1523
1632
|
writeMaterial(material, materialDef) {
|
1524
|
-
if (!
|
1525
|
-
material.isMeshPhysicalMaterial) || material.transmission === 0) {
|
1633
|
+
if (!material.isMeshPhysicalMaterial || material.transmission === 0)
|
1526
1634
|
return;
|
1527
|
-
}
|
1528
1635
|
const writer = this.writer;
|
1529
1636
|
const extensionsUsed = writer.extensionsUsed;
|
1530
1637
|
const extensionDef = {};
|
1531
1638
|
extensionDef.transmissionFactor = material.transmission;
|
1532
1639
|
if (material.transmissionMap) {
|
1533
|
-
const transmissionMapDef = {
|
1640
|
+
const transmissionMapDef = {
|
1641
|
+
index: writer.processTexture(material.transmissionMap),
|
1642
|
+
texCoord: material.transmissionMap.channel
|
1643
|
+
};
|
1534
1644
|
writer.applyTextureTransform(transmissionMapDef, material.transmissionMap);
|
1535
1645
|
extensionDef.transmissionTexture = transmissionMapDef;
|
1536
1646
|
}
|
@@ -1541,35 +1651,259 @@ class GLTFMaterialsTransmissionExtension {
|
|
1541
1651
|
}
|
1542
1652
|
class GLTFMaterialsVolumeExtension {
|
1543
1653
|
constructor(writer) {
|
1544
|
-
__publicField(this, "writer");
|
1545
|
-
__publicField(this, "name");
|
1546
1654
|
this.writer = writer;
|
1547
1655
|
this.name = "KHR_materials_volume";
|
1548
1656
|
}
|
1549
1657
|
writeMaterial(material, materialDef) {
|
1550
|
-
if (!
|
1551
|
-
material.isMeshPhysicalMaterial) || material.thickness === 0) {
|
1658
|
+
if (!material.isMeshPhysicalMaterial || material.transmission === 0)
|
1552
1659
|
return;
|
1553
|
-
}
|
1554
1660
|
const writer = this.writer;
|
1555
1661
|
const extensionsUsed = writer.extensionsUsed;
|
1556
1662
|
const extensionDef = {};
|
1557
|
-
extensionDef.
|
1663
|
+
extensionDef.thicknessFactor = material.thickness;
|
1558
1664
|
if (material.thicknessMap) {
|
1559
1665
|
const thicknessMapDef = {
|
1560
|
-
index: writer.processTexture(material.thicknessMap)
|
1666
|
+
index: writer.processTexture(material.thicknessMap),
|
1667
|
+
texCoord: material.thicknessMap.channel
|
1561
1668
|
};
|
1562
1669
|
writer.applyTextureTransform(thicknessMapDef, material.thicknessMap);
|
1563
1670
|
extensionDef.thicknessTexture = thicknessMapDef;
|
1564
1671
|
}
|
1565
1672
|
extensionDef.attenuationDistance = material.attenuationDistance;
|
1566
|
-
extensionDef.attenuationColor =
|
1567
|
-
material.attenuationTint.toArray();
|
1673
|
+
extensionDef.attenuationColor = material.attenuationColor.toArray();
|
1568
1674
|
materialDef.extensions = materialDef.extensions || {};
|
1569
1675
|
materialDef.extensions[this.name] = extensionDef;
|
1570
1676
|
extensionsUsed[this.name] = true;
|
1571
1677
|
}
|
1572
1678
|
}
|
1679
|
+
class GLTFMaterialsIorExtension {
|
1680
|
+
constructor(writer) {
|
1681
|
+
this.writer = writer;
|
1682
|
+
this.name = "KHR_materials_ior";
|
1683
|
+
}
|
1684
|
+
writeMaterial(material, materialDef) {
|
1685
|
+
if (!material.isMeshPhysicalMaterial || material.ior === 1.5)
|
1686
|
+
return;
|
1687
|
+
const writer = this.writer;
|
1688
|
+
const extensionsUsed = writer.extensionsUsed;
|
1689
|
+
const extensionDef = {};
|
1690
|
+
extensionDef.ior = material.ior;
|
1691
|
+
materialDef.extensions = materialDef.extensions || {};
|
1692
|
+
materialDef.extensions[this.name] = extensionDef;
|
1693
|
+
extensionsUsed[this.name] = true;
|
1694
|
+
}
|
1695
|
+
}
|
1696
|
+
class GLTFMaterialsSpecularExtension {
|
1697
|
+
constructor(writer) {
|
1698
|
+
this.writer = writer;
|
1699
|
+
this.name = "KHR_materials_specular";
|
1700
|
+
}
|
1701
|
+
writeMaterial(material, materialDef) {
|
1702
|
+
if (!material.isMeshPhysicalMaterial || material.specularIntensity === 1 && material.specularColor.equals(DEFAULT_SPECULAR_COLOR) && !material.specularIntensityMap && !material.specularColorTexture)
|
1703
|
+
return;
|
1704
|
+
const writer = this.writer;
|
1705
|
+
const extensionsUsed = writer.extensionsUsed;
|
1706
|
+
const extensionDef = {};
|
1707
|
+
if (material.specularIntensityMap) {
|
1708
|
+
const specularIntensityMapDef = {
|
1709
|
+
index: writer.processTexture(material.specularIntensityMap),
|
1710
|
+
texCoord: material.specularIntensityMap.channel
|
1711
|
+
};
|
1712
|
+
writer.applyTextureTransform(specularIntensityMapDef, material.specularIntensityMap);
|
1713
|
+
extensionDef.specularTexture = specularIntensityMapDef;
|
1714
|
+
}
|
1715
|
+
if (material.specularColorMap) {
|
1716
|
+
const specularColorMapDef = {
|
1717
|
+
index: writer.processTexture(material.specularColorMap),
|
1718
|
+
texCoord: material.specularColorMap.channel
|
1719
|
+
};
|
1720
|
+
writer.applyTextureTransform(specularColorMapDef, material.specularColorMap);
|
1721
|
+
extensionDef.specularColorTexture = specularColorMapDef;
|
1722
|
+
}
|
1723
|
+
extensionDef.specularFactor = material.specularIntensity;
|
1724
|
+
extensionDef.specularColorFactor = material.specularColor.toArray();
|
1725
|
+
materialDef.extensions = materialDef.extensions || {};
|
1726
|
+
materialDef.extensions[this.name] = extensionDef;
|
1727
|
+
extensionsUsed[this.name] = true;
|
1728
|
+
}
|
1729
|
+
}
|
1730
|
+
class GLTFMaterialsSheenExtension {
|
1731
|
+
constructor(writer) {
|
1732
|
+
this.writer = writer;
|
1733
|
+
this.name = "KHR_materials_sheen";
|
1734
|
+
}
|
1735
|
+
writeMaterial(material, materialDef) {
|
1736
|
+
if (!material.isMeshPhysicalMaterial || material.sheen == 0)
|
1737
|
+
return;
|
1738
|
+
const writer = this.writer;
|
1739
|
+
const extensionsUsed = writer.extensionsUsed;
|
1740
|
+
const extensionDef = {};
|
1741
|
+
if (material.sheenRoughnessMap) {
|
1742
|
+
const sheenRoughnessMapDef = {
|
1743
|
+
index: writer.processTexture(material.sheenRoughnessMap),
|
1744
|
+
texCoord: material.sheenRoughnessMap.channel
|
1745
|
+
};
|
1746
|
+
writer.applyTextureTransform(sheenRoughnessMapDef, material.sheenRoughnessMap);
|
1747
|
+
extensionDef.sheenRoughnessTexture = sheenRoughnessMapDef;
|
1748
|
+
}
|
1749
|
+
if (material.sheenColorMap) {
|
1750
|
+
const sheenColorMapDef = {
|
1751
|
+
index: writer.processTexture(material.sheenColorMap),
|
1752
|
+
texCoord: material.sheenColorMap.channel
|
1753
|
+
};
|
1754
|
+
writer.applyTextureTransform(sheenColorMapDef, material.sheenColorMap);
|
1755
|
+
extensionDef.sheenColorTexture = sheenColorMapDef;
|
1756
|
+
}
|
1757
|
+
extensionDef.sheenRoughnessFactor = material.sheenRoughness;
|
1758
|
+
extensionDef.sheenColorFactor = material.sheenColor.toArray();
|
1759
|
+
materialDef.extensions = materialDef.extensions || {};
|
1760
|
+
materialDef.extensions[this.name] = extensionDef;
|
1761
|
+
extensionsUsed[this.name] = true;
|
1762
|
+
}
|
1763
|
+
}
|
1764
|
+
class GLTFMaterialsAnisotropyExtension {
|
1765
|
+
constructor(writer) {
|
1766
|
+
this.writer = writer;
|
1767
|
+
this.name = "KHR_materials_anisotropy";
|
1768
|
+
}
|
1769
|
+
writeMaterial(material, materialDef) {
|
1770
|
+
if (!material.isMeshPhysicalMaterial || material.anisotropy == 0)
|
1771
|
+
return;
|
1772
|
+
const writer = this.writer;
|
1773
|
+
const extensionsUsed = writer.extensionsUsed;
|
1774
|
+
const extensionDef = {};
|
1775
|
+
if (material.anisotropyMap) {
|
1776
|
+
const anisotropyMapDef = { index: writer.processTexture(material.anisotropyMap) };
|
1777
|
+
writer.applyTextureTransform(anisotropyMapDef, material.anisotropyMap);
|
1778
|
+
extensionDef.anisotropyTexture = anisotropyMapDef;
|
1779
|
+
}
|
1780
|
+
extensionDef.anisotropyStrength = material.anisotropy;
|
1781
|
+
extensionDef.anisotropyRotation = material.anisotropyRotation;
|
1782
|
+
materialDef.extensions = materialDef.extensions || {};
|
1783
|
+
materialDef.extensions[this.name] = extensionDef;
|
1784
|
+
extensionsUsed[this.name] = true;
|
1785
|
+
}
|
1786
|
+
}
|
1787
|
+
class GLTFMaterialsEmissiveStrengthExtension {
|
1788
|
+
constructor(writer) {
|
1789
|
+
this.writer = writer;
|
1790
|
+
this.name = "KHR_materials_emissive_strength";
|
1791
|
+
}
|
1792
|
+
writeMaterial(material, materialDef) {
|
1793
|
+
if (!material.isMeshStandardMaterial || material.emissiveIntensity === 1)
|
1794
|
+
return;
|
1795
|
+
const writer = this.writer;
|
1796
|
+
const extensionsUsed = writer.extensionsUsed;
|
1797
|
+
const extensionDef = {};
|
1798
|
+
extensionDef.emissiveStrength = material.emissiveIntensity;
|
1799
|
+
materialDef.extensions = materialDef.extensions || {};
|
1800
|
+
materialDef.extensions[this.name] = extensionDef;
|
1801
|
+
extensionsUsed[this.name] = true;
|
1802
|
+
}
|
1803
|
+
}
|
1804
|
+
GLTFExporter.Utils = {
|
1805
|
+
insertKeyframe: function(track, time) {
|
1806
|
+
const tolerance = 1e-3;
|
1807
|
+
const valueSize = track.getValueSize();
|
1808
|
+
const times = new track.TimeBufferType(track.times.length + 1);
|
1809
|
+
const values = new track.ValueBufferType(track.values.length + valueSize);
|
1810
|
+
const interpolant = track.createInterpolant(new track.ValueBufferType(valueSize));
|
1811
|
+
let index;
|
1812
|
+
if (track.times.length === 0) {
|
1813
|
+
times[0] = time;
|
1814
|
+
for (let i = 0; i < valueSize; i++) {
|
1815
|
+
values[i] = 0;
|
1816
|
+
}
|
1817
|
+
index = 0;
|
1818
|
+
} else if (time < track.times[0]) {
|
1819
|
+
if (Math.abs(track.times[0] - time) < tolerance)
|
1820
|
+
return 0;
|
1821
|
+
times[0] = time;
|
1822
|
+
times.set(track.times, 1);
|
1823
|
+
values.set(interpolant.evaluate(time), 0);
|
1824
|
+
values.set(track.values, valueSize);
|
1825
|
+
index = 0;
|
1826
|
+
} else if (time > track.times[track.times.length - 1]) {
|
1827
|
+
if (Math.abs(track.times[track.times.length - 1] - time) < tolerance) {
|
1828
|
+
return track.times.length - 1;
|
1829
|
+
}
|
1830
|
+
times[times.length - 1] = time;
|
1831
|
+
times.set(track.times, 0);
|
1832
|
+
values.set(track.values, 0);
|
1833
|
+
values.set(interpolant.evaluate(time), track.values.length);
|
1834
|
+
index = times.length - 1;
|
1835
|
+
} else {
|
1836
|
+
for (let i = 0; i < track.times.length; i++) {
|
1837
|
+
if (Math.abs(track.times[i] - time) < tolerance)
|
1838
|
+
return i;
|
1839
|
+
if (track.times[i] < time && track.times[i + 1] > time) {
|
1840
|
+
times.set(track.times.slice(0, i + 1), 0);
|
1841
|
+
times[i + 1] = time;
|
1842
|
+
times.set(track.times.slice(i + 1), i + 2);
|
1843
|
+
values.set(track.values.slice(0, (i + 1) * valueSize), 0);
|
1844
|
+
values.set(interpolant.evaluate(time), (i + 1) * valueSize);
|
1845
|
+
values.set(track.values.slice((i + 1) * valueSize), (i + 2) * valueSize);
|
1846
|
+
index = i + 1;
|
1847
|
+
break;
|
1848
|
+
}
|
1849
|
+
}
|
1850
|
+
}
|
1851
|
+
track.times = times;
|
1852
|
+
track.values = values;
|
1853
|
+
return index;
|
1854
|
+
},
|
1855
|
+
mergeMorphTargetTracks: function(clip, root) {
|
1856
|
+
const tracks = [];
|
1857
|
+
const mergedTracks = {};
|
1858
|
+
const sourceTracks = clip.tracks;
|
1859
|
+
for (let i = 0; i < sourceTracks.length; ++i) {
|
1860
|
+
let sourceTrack = sourceTracks[i];
|
1861
|
+
const sourceTrackBinding = PropertyBinding.parseTrackName(sourceTrack.name);
|
1862
|
+
const sourceTrackNode = PropertyBinding.findNode(root, sourceTrackBinding.nodeName);
|
1863
|
+
if (sourceTrackBinding.propertyName !== "morphTargetInfluences" || sourceTrackBinding.propertyIndex === void 0) {
|
1864
|
+
tracks.push(sourceTrack);
|
1865
|
+
continue;
|
1866
|
+
}
|
1867
|
+
if (sourceTrack.createInterpolant !== sourceTrack.InterpolantFactoryMethodDiscrete && sourceTrack.createInterpolant !== sourceTrack.InterpolantFactoryMethodLinear) {
|
1868
|
+
if (sourceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
|
1869
|
+
throw new Error("THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.");
|
1870
|
+
}
|
1871
|
+
console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead.");
|
1872
|
+
sourceTrack = sourceTrack.clone();
|
1873
|
+
sourceTrack.setInterpolation(InterpolateLinear);
|
1874
|
+
}
|
1875
|
+
const targetCount = sourceTrackNode.morphTargetInfluences.length;
|
1876
|
+
const targetIndex = sourceTrackNode.morphTargetDictionary[sourceTrackBinding.propertyIndex];
|
1877
|
+
if (targetIndex === void 0) {
|
1878
|
+
throw new Error("THREE.GLTFExporter: Morph target name not found: " + sourceTrackBinding.propertyIndex);
|
1879
|
+
}
|
1880
|
+
let mergedTrack;
|
1881
|
+
if (mergedTracks[sourceTrackNode.uuid] === void 0) {
|
1882
|
+
mergedTrack = sourceTrack.clone();
|
1883
|
+
const values = new mergedTrack.ValueBufferType(targetCount * mergedTrack.times.length);
|
1884
|
+
for (let j = 0; j < mergedTrack.times.length; j++) {
|
1885
|
+
values[j * targetCount + targetIndex] = mergedTrack.values[j];
|
1886
|
+
}
|
1887
|
+
mergedTrack.name = (sourceTrackBinding.nodeName || "") + ".morphTargetInfluences";
|
1888
|
+
mergedTrack.values = values;
|
1889
|
+
mergedTracks[sourceTrackNode.uuid] = mergedTrack;
|
1890
|
+
tracks.push(mergedTrack);
|
1891
|
+
continue;
|
1892
|
+
}
|
1893
|
+
const sourceInterpolant = sourceTrack.createInterpolant(new sourceTrack.ValueBufferType(1));
|
1894
|
+
mergedTrack = mergedTracks[sourceTrackNode.uuid];
|
1895
|
+
for (let j = 0; j < mergedTrack.times.length; j++) {
|
1896
|
+
mergedTrack.values[j * targetCount + targetIndex] = sourceInterpolant.evaluate(mergedTrack.times[j]);
|
1897
|
+
}
|
1898
|
+
for (let j = 0; j < sourceTrack.times.length; j++) {
|
1899
|
+
const keyframeIndex = this.insertKeyframe(mergedTrack, sourceTrack.times[j]);
|
1900
|
+
mergedTrack.values[keyframeIndex * targetCount + targetIndex] = sourceTrack.values[j];
|
1901
|
+
}
|
1902
|
+
}
|
1903
|
+
clip.tracks = tracks;
|
1904
|
+
return clip;
|
1905
|
+
}
|
1906
|
+
};
|
1573
1907
|
export {
|
1574
1908
|
GLTFExporter
|
1575
1909
|
};
|