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