three-stdlib 2.22.9 → 2.22.10
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/TransformControls.d.ts +1 -1
- package/dist/controls/experimental/CameraControls.d.ts +1 -1
- package/dist/csm/CSM.js +4 -4
- package/dist/csm/CSM.mjs +4 -4
- package/dist/csm/CSMFrustum.js +1 -1
- package/dist/csm/CSMFrustum.mjs +1 -1
- package/dist/csm/CSMShader.js +14 -10
- package/dist/csm/CSMShader.mjs +14 -10
- package/dist/curves/CurveExtras.js +52 -62
- package/dist/curves/CurveExtras.mjs +53 -63
- package/dist/curves/NURBSUtils.d.ts +18 -20
- package/dist/curves/NURBSUtils.js +17 -17
- package/dist/curves/NURBSUtils.mjs +17 -17
- package/dist/deprecated/Geometry.js +26 -26
- package/dist/deprecated/Geometry.mjs +27 -27
- package/dist/effects/AnaglyphEffect.js +95 -114
- package/dist/effects/AnaglyphEffect.mjs +95 -114
- package/dist/effects/AsciiEffect.js +144 -162
- package/dist/effects/AsciiEffect.mjs +144 -162
- package/dist/effects/OutlineEffect.js +253 -276
- package/dist/effects/OutlineEffect.mjs +253 -276
- package/dist/effects/ParallaxBarrierEffect.js +61 -60
- package/dist/effects/ParallaxBarrierEffect.mjs +61 -60
- package/dist/effects/PeppersGhostEffect.js +84 -81
- package/dist/effects/PeppersGhostEffect.mjs +84 -81
- package/dist/effects/StereoEffect.js +31 -28
- package/dist/effects/StereoEffect.mjs +31 -28
- package/dist/environments/RoomEnvironment.d.ts +6 -5
- package/dist/exporters/GLTFExporter.d.ts +109 -441
- package/dist/exporters/GLTFExporter.js +912 -581
- package/dist/exporters/GLTFExporter.mjs +912 -581
- package/dist/geometries/ConvexGeometry.js +0 -3
- package/dist/geometries/ConvexGeometry.mjs +0 -3
- package/dist/geometries/LightningStrike.d.ts +3 -3
- package/dist/geometries/LightningStrike.js +80 -75
- package/dist/geometries/LightningStrike.mjs +80 -75
- package/dist/geometries/ParametricGeometries.js +75 -74
- package/dist/geometries/ParametricGeometries.mjs +75 -74
- package/dist/geometries/RoundedBoxGeometry.js +1 -1
- package/dist/geometries/RoundedBoxGeometry.mjs +1 -1
- package/dist/geometries/TextGeometry.d.ts +1 -1
- package/dist/helpers/RectAreaLightHelper.d.ts +4 -3
- package/dist/helpers/RectAreaLightHelper.js +2 -2
- package/dist/helpers/RectAreaLightHelper.mjs +2 -2
- package/dist/helpers/VertexNormalsHelper.d.ts +3 -0
- package/dist/helpers/VertexNormalsHelper.js +15 -22
- package/dist/helpers/VertexNormalsHelper.mjs +16 -23
- package/dist/helpers/VertexTangentsHelper.d.ts +3 -0
- package/dist/helpers/VertexTangentsHelper.js +12 -14
- package/dist/helpers/VertexTangentsHelper.mjs +12 -14
- package/dist/index.d.ts +1 -66
- package/dist/index.js +5 -370
- package/dist/index.mjs +9 -374
- package/dist/interactive/InteractiveGroup.js +1 -1
- package/dist/interactive/InteractiveGroup.mjs +1 -1
- package/dist/interactive/SelectionBox.js +122 -125
- package/dist/interactive/SelectionBox.mjs +122 -125
- package/dist/interactive/SelectionHelper.js +45 -48
- package/dist/interactive/SelectionHelper.mjs +45 -48
- package/dist/libs/MeshoptDecoder.d.ts +1 -1
- package/dist/libs/MotionControllers.d.ts +15 -14
- package/dist/libs/MotionControllers.js +10 -10
- package/dist/libs/MotionControllers.mjs +10 -10
- package/dist/lights/LightProbeGenerator.js +43 -43
- package/dist/lights/LightProbeGenerator.mjs +43 -43
- package/dist/lights/RectAreaLightUniformsLib.js +9 -5
- package/dist/lights/RectAreaLightUniformsLib.mjs +9 -5
- package/dist/lines/LineMaterial.js +271 -271
- package/dist/lines/LineMaterial.mjs +272 -272
- package/dist/lines/LineSegments2.js +12 -12
- package/dist/lines/LineSegments2.mjs +12 -12
- package/dist/lines/LineSegmentsGeometry.js +2 -2
- package/dist/lines/LineSegmentsGeometry.mjs +2 -2
- package/dist/lines/Wireframe.js +2 -2
- package/dist/lines/Wireframe.mjs +2 -2
- package/dist/loaders/3DMLoader.d.ts +2 -1
- package/dist/loaders/3MFLoader.d.ts +2 -1
- package/dist/loaders/AMFLoader.d.ts +2 -1
- package/dist/loaders/AssimpLoader.d.ts +20 -0
- package/dist/loaders/AssimpLoader.js +520 -482
- package/dist/loaders/AssimpLoader.mjs +520 -482
- package/dist/loaders/BVHLoader.d.ts +2 -1
- package/dist/loaders/BasisTextureLoader.d.ts +2 -1
- package/dist/loaders/BasisTextureLoader.js +23 -14
- package/dist/loaders/BasisTextureLoader.mjs +24 -15
- package/dist/loaders/ColladaLoader.d.ts +2 -1
- package/dist/loaders/DRACOLoader.d.ts +2 -1
- package/dist/loaders/FBXLoader.d.ts +2 -1
- package/dist/loaders/FBXLoader.js +2 -2
- package/dist/loaders/FBXLoader.mjs +2 -2
- package/dist/loaders/FontLoader.d.ts +4 -4
- package/dist/loaders/FontLoader.js +2 -1
- package/dist/loaders/FontLoader.mjs +2 -1
- package/dist/loaders/GCodeLoader.d.ts +2 -1
- package/dist/loaders/GLTFLoader.d.ts +11 -9
- package/dist/loaders/GLTFLoader.js +2 -2
- package/dist/loaders/GLTFLoader.mjs +2 -2
- package/dist/loaders/HDRCubeTextureLoader.d.ts +2 -1
- package/dist/loaders/KMZLoader.d.ts +2 -1
- package/dist/loaders/KTX2Loader.js +34 -15
- package/dist/loaders/KTX2Loader.mjs +35 -16
- package/dist/loaders/LDrawLoader.d.ts +2 -1
- package/dist/loaders/LDrawLoader.js +3 -3
- package/dist/loaders/LDrawLoader.mjs +3 -3
- package/dist/loaders/LUT3dlLoader.d.ts +3 -2
- package/dist/loaders/LUTCubeLoader.d.ts +3 -2
- package/dist/loaders/LWOLoader.d.ts +2 -1
- package/dist/loaders/LottieLoader.d.ts +2 -1
- package/dist/loaders/MD2Loader.d.ts +2 -1
- package/dist/loaders/MDDLoader.d.ts +2 -1
- package/dist/loaders/MMDLoader.d.ts +2 -1
- package/dist/loaders/MTLLoader.d.ts +2 -1
- package/dist/loaders/OBJLoader.d.ts +2 -1
- package/dist/loaders/OBJLoader.js +5 -5
- package/dist/loaders/OBJLoader.mjs +5 -5
- package/dist/loaders/PCDLoader.d.ts +2 -1
- package/dist/loaders/PDBLoader.d.ts +2 -1
- package/dist/loaders/PLYLoader.d.ts +2 -1
- package/dist/loaders/PRWMLoader.d.ts +2 -1
- package/dist/loaders/RGBMLoader.js +924 -918
- package/dist/loaders/RGBMLoader.mjs +924 -918
- package/dist/loaders/STLLoader.d.ts +2 -1
- package/dist/loaders/SVGLoader.d.ts +2 -1
- package/dist/loaders/TDSLoader.d.ts +2 -1
- package/dist/loaders/TTFLoader.d.ts +2 -1
- package/dist/loaders/TiltLoader.d.ts +2 -1
- package/dist/loaders/TiltLoader.js +3 -1
- package/dist/loaders/TiltLoader.mjs +3 -1
- package/dist/loaders/VOXLoader.d.ts +4 -2
- package/dist/loaders/VRMLLoader.d.ts +2 -1
- package/dist/loaders/VRMLoader.d.ts +20 -0
- package/dist/loaders/VTKLoader.d.ts +2 -1
- package/dist/loaders/XLoader.d.ts +20 -0
- package/dist/loaders/XLoader.js +1 -1
- package/dist/loaders/XLoader.mjs +1 -1
- package/dist/loaders/XYZLoader.d.ts +2 -1
- package/dist/loaders/lwo/IFFParser.js +104 -110
- package/dist/loaders/lwo/IFFParser.mjs +104 -110
- package/dist/loaders/lwo/LWO2Parser.js +18 -33
- package/dist/loaders/lwo/LWO2Parser.mjs +18 -33
- package/dist/loaders/lwo/LWO3Parser.js +17 -33
- package/dist/loaders/lwo/LWO3Parser.mjs +17 -33
- package/dist/math/Capsule.d.ts +1 -1
- package/dist/math/Capsule.js +90 -92
- package/dist/math/Capsule.mjs +90 -92
- package/dist/math/ColorConverter.js +26 -36
- package/dist/math/ColorConverter.mjs +26 -36
- package/dist/math/ConvexHull.js +16 -17
- package/dist/math/ConvexHull.mjs +17 -18
- package/dist/math/ImprovedNoise.js +41 -39
- package/dist/math/ImprovedNoise.mjs +41 -39
- package/dist/math/Lut.js +65 -63
- package/dist/math/Lut.mjs +66 -64
- package/dist/math/MeshSurfaceSampler.d.ts +3 -0
- package/dist/math/MeshSurfaceSampler.js +85 -89
- package/dist/math/MeshSurfaceSampler.mjs +85 -89
- package/dist/math/OBB.js +68 -88
- package/dist/math/OBB.mjs +68 -88
- package/dist/math/Octree.js +240 -245
- package/dist/math/Octree.mjs +240 -245
- package/dist/misc/ConvexObjectBreaker.js +114 -120
- package/dist/misc/ConvexObjectBreaker.mjs +115 -121
- package/dist/misc/GPUComputationRenderer.d.ts +1 -0
- package/dist/misc/GPUComputationRenderer.js +191 -157
- package/dist/misc/GPUComputationRenderer.mjs +192 -158
- package/dist/misc/Gyroscope.js +16 -18
- package/dist/misc/Gyroscope.mjs +17 -19
- package/dist/misc/MD2Character.js +88 -86
- package/dist/misc/MD2Character.mjs +89 -87
- package/dist/misc/MD2CharacterComplex.js +106 -105
- package/dist/misc/MD2CharacterComplex.mjs +107 -106
- package/dist/misc/MorphAnimMesh.d.ts +1 -1
- package/dist/misc/MorphAnimMesh.js +33 -33
- package/dist/misc/MorphAnimMesh.mjs +33 -33
- package/dist/misc/MorphBlendMesh.js +68 -68
- package/dist/misc/MorphBlendMesh.mjs +68 -68
- package/dist/misc/ProgressiveLightmap.d.ts +1 -2
- package/dist/misc/RollerCoaster.js +321 -314
- package/dist/misc/RollerCoaster.mjs +322 -315
- package/dist/misc/Volume.d.ts +1 -1
- package/dist/misc/Volume.js +169 -166
- package/dist/misc/Volume.mjs +170 -167
- package/dist/misc/VolumeSlice.js +50 -51
- package/dist/misc/VolumeSlice.mjs +50 -51
- package/dist/modifiers/CurveModifier.d.ts +2 -2
- package/dist/modifiers/CurveModifier.js +1 -1
- package/dist/modifiers/CurveModifier.mjs +1 -1
- package/dist/modifiers/SimplifyModifier.js +2 -1
- package/dist/modifiers/SimplifyModifier.mjs +2 -1
- package/dist/objects/Lensflare.js +32 -21
- package/dist/objects/Lensflare.mjs +33 -22
- package/dist/objects/LightningStorm.d.ts +3 -3
- package/dist/objects/LightningStorm.js +3 -3
- package/dist/objects/LightningStorm.mjs +3 -3
- package/dist/objects/MarchingCubes.d.ts +1 -0
- package/dist/objects/MarchingCubes.js +4362 -10
- package/dist/objects/MarchingCubes.mjs +4363 -11
- package/dist/objects/Reflector.d.ts +5 -2
- package/dist/objects/Reflector.js +39 -12
- package/dist/objects/Reflector.mjs +40 -13
- package/dist/objects/ReflectorForSSRPass.js +25 -21
- package/dist/objects/ReflectorForSSRPass.mjs +26 -22
- package/dist/objects/ReflectorRTT.d.ts +6 -0
- package/dist/objects/Refractor.d.ts +5 -2
- package/dist/objects/Refractor.js +39 -12
- package/dist/objects/Refractor.mjs +40 -13
- package/dist/objects/ShadowMesh.d.ts +6 -3
- package/dist/objects/ShadowMesh.js +7 -3
- package/dist/objects/ShadowMesh.mjs +8 -4
- package/dist/objects/Sky.js +181 -137
- package/dist/objects/Sky.mjs +182 -138
- package/dist/objects/Water.d.ts +3 -3
- package/dist/objects/Water.js +3 -2
- package/dist/objects/Water.mjs +3 -2
- package/dist/objects/Water2.d.ts +2 -2
- package/dist/objects/Water2.js +16 -18
- package/dist/objects/Water2.mjs +17 -19
- package/dist/postprocessing/AdaptiveToneMappingPass.d.ts +2 -2
- package/dist/postprocessing/AdaptiveToneMappingPass.js +105 -112
- package/dist/postprocessing/AdaptiveToneMappingPass.mjs +107 -114
- package/dist/postprocessing/BokehPass.d.ts +1 -1
- package/dist/postprocessing/ClearPass.d.ts +3 -3
- package/dist/postprocessing/CubeTexturePass.js +37 -33
- package/dist/postprocessing/CubeTexturePass.mjs +37 -33
- package/dist/postprocessing/HalftonePass.d.ts +1 -1
- package/dist/postprocessing/LUTPass.d.ts +3 -3
- package/dist/postprocessing/RenderPixelatedPass.d.ts +28 -0
- package/dist/postprocessing/SAOPass.d.ts +5 -6
- package/dist/postprocessing/SAOPass.js +151 -145
- package/dist/postprocessing/SAOPass.mjs +153 -147
- package/dist/postprocessing/SSAARenderPass.d.ts +5 -5
- package/dist/postprocessing/SSAARenderPass.js +78 -55
- package/dist/postprocessing/SSAARenderPass.mjs +80 -57
- package/dist/postprocessing/SSAOPass.d.ts +4 -5
- package/dist/postprocessing/SSAOPass.js +17 -10
- package/dist/postprocessing/SSAOPass.mjs +17 -10
- package/dist/postprocessing/SSRPass.d.ts +6 -7
- package/dist/postprocessing/SSRPass.js +235 -262
- package/dist/postprocessing/SSRPass.mjs +237 -264
- package/dist/postprocessing/TAARenderPass.d.ts +2 -2
- package/dist/postprocessing/TAARenderPass.js +106 -27
- package/dist/postprocessing/TAARenderPass.mjs +107 -28
- package/dist/postprocessing/TexturePass.d.ts +2 -2
- package/dist/postprocessing/TexturePass.js +24 -22
- package/dist/postprocessing/TexturePass.mjs +25 -23
- package/dist/postprocessing/UnrealBloomPass.js +175 -118
- package/dist/postprocessing/UnrealBloomPass.mjs +177 -120
- package/dist/renderers/CSS2DRenderer.d.ts +2 -1
- package/dist/renderers/CSS2DRenderer.js +5 -4
- package/dist/renderers/CSS2DRenderer.mjs +6 -5
- package/dist/renderers/CSS3DRenderer.d.ts +1 -1
- package/dist/renderers/CSS3DRenderer.js +147 -113
- package/dist/renderers/CSS3DRenderer.mjs +148 -114
- package/dist/renderers/Projector.js +377 -389
- package/dist/renderers/Projector.mjs +377 -389
- package/dist/renderers/SVGRenderer.js +280 -275
- package/dist/renderers/SVGRenderer.mjs +280 -275
- package/dist/shaders/ACESFilmicToneMappingShader.d.ts +1 -1
- package/dist/shaders/AfterimageShader.d.ts +1 -1
- package/dist/shaders/BasicShader.d.ts +1 -1
- package/dist/shaders/BleachBypassShader.d.ts +1 -1
- package/dist/shaders/BokehShader.d.ts +2 -2
- package/dist/shaders/BokehShader2.d.ts +2 -2
- package/dist/shaders/BokehShader2.js +1 -1
- package/dist/shaders/BokehShader2.mjs +1 -1
- package/dist/shaders/ColorCorrectionShader.js +3 -3
- package/dist/shaders/ColorCorrectionShader.mjs +3 -3
- package/dist/shaders/ColorifyShader.js +1 -1
- package/dist/shaders/ColorifyShader.mjs +1 -1
- package/dist/shaders/ConvolutionShader.d.ts +2 -2
- package/dist/shaders/ConvolutionShader.js +1 -1
- package/dist/shaders/ConvolutionShader.mjs +1 -1
- package/dist/shaders/CopyShader.d.ts +1 -1
- package/dist/shaders/DepthLimitedBlurShader.d.ts +2 -2
- package/dist/shaders/DepthLimitedBlurShader.js +2 -2
- package/dist/shaders/DepthLimitedBlurShader.mjs +2 -2
- package/dist/shaders/DotScreenShader.js +2 -2
- package/dist/shaders/DotScreenShader.mjs +2 -2
- package/dist/shaders/FXAAShader.js +1 -1
- package/dist/shaders/FXAAShader.mjs +1 -1
- package/dist/shaders/FreiChenShader.js +1 -1
- package/dist/shaders/FreiChenShader.mjs +1 -1
- package/dist/shaders/GammaCorrectionShader.d.ts +1 -1
- package/dist/shaders/GodRaysShader.js +4 -4
- package/dist/shaders/GodRaysShader.mjs +4 -4
- package/dist/shaders/HorizontalBlurShader.d.ts +1 -1
- package/dist/shaders/LuminosityHighPassShader.js +1 -1
- package/dist/shaders/LuminosityHighPassShader.mjs +1 -1
- package/dist/shaders/NormalMapShader.js +2 -2
- package/dist/shaders/NormalMapShader.mjs +2 -2
- package/dist/shaders/SAOShader.d.ts +2 -2
- package/dist/shaders/SAOShader.js +3 -3
- package/dist/shaders/SAOShader.mjs +3 -3
- package/dist/shaders/SMAAShader.js +3 -3
- package/dist/shaders/SMAAShader.mjs +3 -3
- package/dist/shaders/SSAOShader.js +4 -4
- package/dist/shaders/SSAOShader.mjs +4 -4
- package/dist/shaders/SSRShader.js +4 -4
- package/dist/shaders/SSRShader.mjs +4 -4
- package/dist/shaders/SobelOperatorShader.js +1 -1
- package/dist/shaders/SobelOperatorShader.mjs +1 -1
- package/dist/shaders/SubsurfaceScatteringShader.d.ts +2 -2
- package/dist/shaders/SubsurfaceScatteringShader.js +91 -52
- package/dist/shaders/SubsurfaceScatteringShader.mjs +91 -52
- package/dist/shaders/ToonShader.js +25 -25
- package/dist/shaders/ToonShader.mjs +25 -25
- package/dist/shaders/TriangleBlurShader.js +1 -1
- package/dist/shaders/TriangleBlurShader.mjs +1 -1
- package/dist/shaders/VerticalBlurShader.d.ts +1 -1
- package/dist/shaders/VolumeShader.js +2 -2
- package/dist/shaders/VolumeShader.mjs +2 -2
- package/dist/shaders/types.d.ts +2 -2
- package/dist/types/Loader.d.ts +4 -0
- package/dist/types/Loader.js +26 -0
- package/dist/types/Loader.mjs +9 -0
- package/dist/types/shared.d.ts +2 -2
- package/dist/types/utils.d.ts +1 -1
- package/dist/utils/BufferGeometryUtils.d.ts +2 -2
- package/dist/utils/BufferGeometryUtils.js +1 -1
- package/dist/utils/BufferGeometryUtils.mjs +1 -1
- package/dist/utils/RoughnessMipmapper.d.ts +8 -0
- package/dist/utils/RoughnessMipmapper.js +79 -75
- package/dist/utils/RoughnessMipmapper.mjs +79 -75
- package/dist/utils/ShadowMapViewer.js +103 -106
- package/dist/utils/ShadowMapViewer.mjs +103 -106
- package/dist/utils/SkeletonUtils.d.ts +5 -21
- package/dist/utils/SkeletonUtils.js +182 -263
- package/dist/utils/SkeletonUtils.mjs +183 -264
- package/dist/utils/UVsDebug.js +37 -42
- package/dist/utils/UVsDebug.mjs +37 -42
- package/dist/webxr/ARButton.d.ts +2 -1
- package/dist/webxr/OculusHandModel.d.ts +2 -1
- package/dist/webxr/OculusHandPointerModel.d.ts +2 -2
- package/dist/webxr/OculusHandPointerModel.js +2 -2
- package/dist/webxr/OculusHandPointerModel.mjs +2 -2
- package/dist/webxr/VRButton.d.ts +2 -1
- package/dist/webxr/XRHandPrimitiveModel.js +2 -2
- package/dist/webxr/XRHandPrimitiveModel.mjs +2 -2
- package/package.json +5 -6
- package/dist/custom.d.ts +0 -5
- package/dist/loaders/NodeMaterialLoader.js +0 -146
- package/dist/loaders/NodeMaterialLoader.mjs +0 -146
- package/dist/nodes/Nodes.js +0 -347
- package/dist/nodes/Nodes.mjs +0 -347
- package/dist/nodes/ShaderNode.js +0 -408
- package/dist/nodes/ShaderNode.mjs +0 -408
- package/dist/nodes/accessors/BufferNode.js +0 -14
- package/dist/nodes/accessors/BufferNode.mjs +0 -15
- package/dist/nodes/accessors/CameraNode.js +0 -43
- package/dist/nodes/accessors/CameraNode.mjs +0 -44
- package/dist/nodes/accessors/CubeTextureNode.js +0 -41
- package/dist/nodes/accessors/CubeTextureNode.mjs +0 -42
- package/dist/nodes/accessors/MaterialNode.js +0 -70
- package/dist/nodes/accessors/MaterialNode.mjs +0 -71
- package/dist/nodes/accessors/MaterialReferenceNode.js +0 -13
- package/dist/nodes/accessors/MaterialReferenceNode.mjs +0 -14
- package/dist/nodes/accessors/ModelNode.js +0 -8
- package/dist/nodes/accessors/ModelNode.mjs +0 -9
- package/dist/nodes/accessors/ModelViewProjectionNode.js +0 -23
- package/dist/nodes/accessors/ModelViewProjectionNode.mjs +0 -24
- package/dist/nodes/accessors/NormalNode.js +0 -61
- package/dist/nodes/accessors/NormalNode.mjs +0 -62
- package/dist/nodes/accessors/Object3DNode.js +0 -75
- package/dist/nodes/accessors/Object3DNode.mjs +0 -76
- package/dist/nodes/accessors/PointUVNode.js +0 -12
- package/dist/nodes/accessors/PointUVNode.mjs +0 -13
- package/dist/nodes/accessors/PositionNode.js +0 -64
- package/dist/nodes/accessors/PositionNode.mjs +0 -65
- package/dist/nodes/accessors/ReferenceNode.js +0 -36
- package/dist/nodes/accessors/ReferenceNode.mjs +0 -37
- package/dist/nodes/accessors/ReflectNode.js +0 -42
- package/dist/nodes/accessors/ReflectNode.mjs +0 -43
- package/dist/nodes/accessors/SkinningNode.js +0 -57
- package/dist/nodes/accessors/SkinningNode.mjs +0 -58
- package/dist/nodes/accessors/TextureNode.js +0 -53
- package/dist/nodes/accessors/TextureNode.mjs +0 -54
- package/dist/nodes/accessors/UVNode.js +0 -22
- package/dist/nodes/accessors/UVNode.mjs +0 -23
- package/dist/nodes/core/ArrayUniformNode.js +0 -13
- package/dist/nodes/core/ArrayUniformNode.mjs +0 -14
- package/dist/nodes/core/AttributeNode.js +0 -29
- package/dist/nodes/core/AttributeNode.mjs +0 -30
- package/dist/nodes/core/BypassNode.js +0 -21
- package/dist/nodes/core/BypassNode.mjs +0 -22
- package/dist/nodes/core/CodeNode.js +0 -27
- package/dist/nodes/core/CodeNode.mjs +0 -28
- package/dist/nodes/core/ConstNode.js +0 -13
- package/dist/nodes/core/ConstNode.mjs +0 -14
- package/dist/nodes/core/ContextNode.js +0 -21
- package/dist/nodes/core/ContextNode.mjs +0 -22
- package/dist/nodes/core/ExpressionNode.js +0 -18
- package/dist/nodes/core/ExpressionNode.mjs +0 -19
- package/dist/nodes/core/FunctionCallNode.js +0 -36
- package/dist/nodes/core/FunctionCallNode.mjs +0 -37
- package/dist/nodes/core/FunctionNode.js +0 -55
- package/dist/nodes/core/FunctionNode.mjs +0 -56
- package/dist/nodes/core/InputNode.js +0 -37
- package/dist/nodes/core/InputNode.mjs +0 -38
- package/dist/nodes/core/Node.js +0 -138
- package/dist/nodes/core/Node.mjs +0 -139
- package/dist/nodes/core/NodeAttribute.js +0 -9
- package/dist/nodes/core/NodeAttribute.mjs +0 -10
- package/dist/nodes/core/NodeBuilder.js +0 -402
- package/dist/nodes/core/NodeBuilder.mjs +0 -402
- package/dist/nodes/core/NodeCode.js +0 -10
- package/dist/nodes/core/NodeCode.mjs +0 -11
- package/dist/nodes/core/NodeFrame.js +0 -34
- package/dist/nodes/core/NodeFrame.mjs +0 -35
- package/dist/nodes/core/NodeFunctionInput.js +0 -12
- package/dist/nodes/core/NodeFunctionInput.mjs +0 -13
- package/dist/nodes/core/NodeKeywords.js +0 -43
- package/dist/nodes/core/NodeKeywords.mjs +0 -44
- package/dist/nodes/core/NodeUniform.js +0 -17
- package/dist/nodes/core/NodeUniform.mjs +0 -18
- package/dist/nodes/core/NodeUtils.js +0 -57
- package/dist/nodes/core/NodeUtils.mjs +0 -57
- package/dist/nodes/core/NodeVar.js +0 -9
- package/dist/nodes/core/NodeVar.mjs +0 -10
- package/dist/nodes/core/NodeVary.js +0 -9
- package/dist/nodes/core/NodeVary.mjs +0 -10
- package/dist/nodes/core/PropertyNode.js +0 -20
- package/dist/nodes/core/PropertyNode.mjs +0 -21
- package/dist/nodes/core/TempNode.js +0 -24
- package/dist/nodes/core/TempNode.mjs +0 -25
- package/dist/nodes/core/UniformNode.js +0 -22
- package/dist/nodes/core/UniformNode.mjs +0 -23
- package/dist/nodes/core/VarNode.js +0 -30
- package/dist/nodes/core/VarNode.mjs +0 -31
- package/dist/nodes/core/VaryNode.js +0 -29
- package/dist/nodes/core/VaryNode.mjs +0 -30
- package/dist/nodes/core/constants.js +0 -24
- package/dist/nodes/core/constants.mjs +0 -24
- package/dist/nodes/display/ColorSpaceNode.js +0 -62
- package/dist/nodes/display/ColorSpaceNode.mjs +0 -62
- package/dist/nodes/display/NormalMapNode.js +0 -53
- package/dist/nodes/display/NormalMapNode.mjs +0 -54
- package/dist/nodes/fog/FogNode.js +0 -14
- package/dist/nodes/fog/FogNode.mjs +0 -15
- package/dist/nodes/fog/FogRangeNode.js +0 -16
- package/dist/nodes/fog/FogRangeNode.mjs +0 -17
- package/dist/nodes/functions/BSDFs.js +0 -64
- package/dist/nodes/functions/BSDFs.mjs +0 -64
- package/dist/nodes/lights/LightContextNode.js +0 -34
- package/dist/nodes/lights/LightContextNode.mjs +0 -35
- package/dist/nodes/lights/LightNode.js +0 -57
- package/dist/nodes/lights/LightNode.mjs +0 -58
- package/dist/nodes/lights/LightsNode.js +0 -58
- package/dist/nodes/lights/LightsNode.mjs +0 -59
- package/dist/nodes/loaders/NodeLoader.js +0 -195
- package/dist/nodes/loaders/NodeLoader.mjs +0 -196
- package/dist/nodes/loaders/NodeMaterialLoader.js +0 -23
- package/dist/nodes/loaders/NodeMaterialLoader.mjs +0 -24
- package/dist/nodes/loaders/NodeObjectLoader.js +0 -39
- package/dist/nodes/loaders/NodeObjectLoader.mjs +0 -40
- package/dist/nodes/materials/LineBasicNodeMaterial.js +0 -26
- package/dist/nodes/materials/LineBasicNodeMaterial.mjs +0 -27
- package/dist/nodes/materials/Materials.js +0 -24
- package/dist/nodes/materials/Materials.mjs +0 -24
- package/dist/nodes/materials/MeshBasicNodeMaterial.js +0 -27
- package/dist/nodes/materials/MeshBasicNodeMaterial.mjs +0 -28
- package/dist/nodes/materials/MeshStandardNodeMaterial.js +0 -40
- package/dist/nodes/materials/MeshStandardNodeMaterial.mjs +0 -41
- package/dist/nodes/materials/NodeMaterial.js +0 -63
- package/dist/nodes/materials/NodeMaterial.mjs +0 -64
- package/dist/nodes/materials/PointsNodeMaterial.js +0 -29
- package/dist/nodes/materials/PointsNodeMaterial.mjs +0 -30
- package/dist/nodes/math/CondNode.js +0 -40
- package/dist/nodes/math/CondNode.mjs +0 -41
- package/dist/nodes/math/MathNode.js +0 -165
- package/dist/nodes/math/MathNode.mjs +0 -166
- package/dist/nodes/math/OperatorNode.js +0 -102
- package/dist/nodes/math/OperatorNode.mjs +0 -103
- package/dist/nodes/procedural/CheckerNode.js +0 -20
- package/dist/nodes/procedural/CheckerNode.mjs +0 -21
- package/dist/nodes/utils/ArrayElementNode.js +0 -18
- package/dist/nodes/utils/ArrayElementNode.mjs +0 -19
- package/dist/nodes/utils/ConvertNode.js +0 -24
- package/dist/nodes/utils/ConvertNode.mjs +0 -25
- package/dist/nodes/utils/JoinNode.js +0 -25
- package/dist/nodes/utils/JoinNode.mjs +0 -26
- package/dist/nodes/utils/MatcapUVNode.js +0 -15
- package/dist/nodes/utils/MatcapUVNode.mjs +0 -16
- package/dist/nodes/utils/OscNode.js +0 -49
- package/dist/nodes/utils/OscNode.mjs +0 -50
- package/dist/nodes/utils/SplitNode.js +0 -44
- package/dist/nodes/utils/SplitNode.mjs +0 -45
- package/dist/nodes/utils/SpriteSheetUVNode.js +0 -39
- package/dist/nodes/utils/SpriteSheetUVNode.mjs +0 -40
- package/dist/nodes/utils/TimerNode.js +0 -43
- package/dist/nodes/utils/TimerNode.mjs +0 -44
- package/dist/offscreen/jank.js +0 -26
- package/dist/offscreen/jank.mjs +0 -27
- package/dist/offscreen/offscreen.js +0 -8
- package/dist/offscreen/offscreen.mjs +0 -7
- package/dist/offscreen/scene.js +0 -68
- package/dist/offscreen/scene.mjs +0 -52
- package/dist/renderers/nodes/accessors/CameraNode.js +0 -62
- package/dist/renderers/nodes/accessors/CameraNode.mjs +0 -63
- package/dist/renderers/nodes/accessors/ModelNode.js +0 -60
- package/dist/renderers/nodes/accessors/ModelNode.mjs +0 -61
- package/dist/renderers/nodes/accessors/ModelViewProjectionNode.js +0 -20
- package/dist/renderers/nodes/accessors/ModelViewProjectionNode.mjs +0 -21
- package/dist/renderers/nodes/accessors/NormalNode.js +0 -60
- package/dist/renderers/nodes/accessors/NormalNode.mjs +0 -61
- package/dist/renderers/nodes/accessors/PositionNode.js +0 -29
- package/dist/renderers/nodes/accessors/PositionNode.mjs +0 -30
- package/dist/renderers/nodes/accessors/UVNode.js +0 -12
- package/dist/renderers/nodes/accessors/UVNode.mjs +0 -13
- package/dist/renderers/nodes/core/AttributeNode.js +0 -34
- package/dist/renderers/nodes/core/AttributeNode.mjs +0 -35
- package/dist/renderers/nodes/core/InputNode.js +0 -30
- package/dist/renderers/nodes/core/InputNode.mjs +0 -31
- package/dist/renderers/nodes/core/Node.js +0 -33
- package/dist/renderers/nodes/core/Node.mjs +0 -34
- package/dist/renderers/nodes/core/NodeAttribute.js +0 -9
- package/dist/renderers/nodes/core/NodeAttribute.mjs +0 -10
- package/dist/renderers/nodes/core/NodeBuilder.js +0 -248
- package/dist/renderers/nodes/core/NodeBuilder.mjs +0 -249
- package/dist/renderers/nodes/core/NodeFrame.js +0 -34
- package/dist/renderers/nodes/core/NodeFrame.mjs +0 -35
- package/dist/renderers/nodes/core/NodeSlot.js +0 -9
- package/dist/renderers/nodes/core/NodeSlot.mjs +0 -10
- package/dist/renderers/nodes/core/NodeUniform.js +0 -17
- package/dist/renderers/nodes/core/NodeUniform.mjs +0 -18
- package/dist/renderers/nodes/core/NodeVary.js +0 -10
- package/dist/renderers/nodes/core/NodeVary.mjs +0 -11
- package/dist/renderers/nodes/core/VaryNode.js +0 -21
- package/dist/renderers/nodes/core/VaryNode.mjs +0 -22
- package/dist/renderers/nodes/core/constants.js +0 -22
- package/dist/renderers/nodes/core/constants.mjs +0 -22
- package/dist/renderers/nodes/inputs/ColorNode.js +0 -10
- package/dist/renderers/nodes/inputs/ColorNode.mjs +0 -11
- package/dist/renderers/nodes/inputs/FloatNode.js +0 -10
- package/dist/renderers/nodes/inputs/FloatNode.mjs +0 -11
- package/dist/renderers/nodes/inputs/Matrix3Node.js +0 -11
- package/dist/renderers/nodes/inputs/Matrix3Node.mjs +0 -12
- package/dist/renderers/nodes/inputs/Matrix4Node.js +0 -11
- package/dist/renderers/nodes/inputs/Matrix4Node.mjs +0 -12
- package/dist/renderers/nodes/inputs/TextureNode.js +0 -19
- package/dist/renderers/nodes/inputs/TextureNode.mjs +0 -20
- package/dist/renderers/nodes/inputs/Vector2Node.js +0 -10
- package/dist/renderers/nodes/inputs/Vector2Node.mjs +0 -11
- package/dist/renderers/nodes/inputs/Vector3Node.js +0 -11
- package/dist/renderers/nodes/inputs/Vector3Node.mjs +0 -12
- package/dist/renderers/nodes/inputs/Vector4Node.js +0 -11
- package/dist/renderers/nodes/inputs/Vector4Node.mjs +0 -12
- package/dist/renderers/nodes/math/MathNode.js +0 -54
- package/dist/renderers/nodes/math/MathNode.mjs +0 -55
- package/dist/renderers/nodes/math/OperatorNode.js +0 -41
- package/dist/renderers/nodes/math/OperatorNode.mjs +0 -42
- package/dist/renderers/nodes/utils/SwitchNode.js +0 -19
- package/dist/renderers/nodes/utils/SwitchNode.mjs +0 -20
- package/dist/renderers/nodes/utils/TimerNode.js +0 -13
- package/dist/renderers/nodes/utils/TimerNode.mjs +0 -14
- package/dist/renderers/webgpu/WebGPU.js +0 -23
- package/dist/renderers/webgpu/WebGPU.mjs +0 -24
- package/dist/renderers/webgpu/WebGPUAttributes.js +0 -68
- package/dist/renderers/webgpu/WebGPUAttributes.mjs +0 -69
- package/dist/renderers/webgpu/WebGPUBackground.js +0 -60
- package/dist/renderers/webgpu/WebGPUBackground.mjs +0 -61
- package/dist/renderers/webgpu/WebGPUBinding.js +0 -13
- package/dist/renderers/webgpu/WebGPUBinding.mjs +0 -14
- package/dist/renderers/webgpu/WebGPUBindings.js +0 -154
- package/dist/renderers/webgpu/WebGPUBindings.mjs +0 -155
- package/dist/renderers/webgpu/WebGPUComputePipelines.js +0 -43
- package/dist/renderers/webgpu/WebGPUComputePipelines.mjs +0 -44
- package/dist/renderers/webgpu/WebGPUGeometries.js +0 -40
- package/dist/renderers/webgpu/WebGPUGeometries.mjs +0 -41
- package/dist/renderers/webgpu/WebGPUInfo.js +0 -45
- package/dist/renderers/webgpu/WebGPUInfo.mjs +0 -46
- package/dist/renderers/webgpu/WebGPUObjects.js +0 -24
- package/dist/renderers/webgpu/WebGPUObjects.mjs +0 -25
- package/dist/renderers/webgpu/WebGPUProperties.js +0 -21
- package/dist/renderers/webgpu/WebGPUProperties.mjs +0 -22
- package/dist/renderers/webgpu/WebGPURenderLists.js +0 -118
- package/dist/renderers/webgpu/WebGPURenderLists.mjs +0 -119
- package/dist/renderers/webgpu/WebGPURenderPipelines.js +0 -545
- package/dist/renderers/webgpu/WebGPURenderPipelines.mjs +0 -546
- package/dist/renderers/webgpu/WebGPURenderer.js +0 -596
- package/dist/renderers/webgpu/WebGPURenderer.mjs +0 -575
- package/dist/renderers/webgpu/WebGPUSampledTexture.js +0 -40
- package/dist/renderers/webgpu/WebGPUSampledTexture.mjs +0 -40
- package/dist/renderers/webgpu/WebGPUSampler.js +0 -14
- package/dist/renderers/webgpu/WebGPUSampler.mjs +0 -15
- package/dist/renderers/webgpu/WebGPUStorageBuffer.js +0 -14
- package/dist/renderers/webgpu/WebGPUStorageBuffer.mjs +0 -15
- package/dist/renderers/webgpu/WebGPUTextureRenderer.js +0 -22
- package/dist/renderers/webgpu/WebGPUTextureRenderer.mjs +0 -23
- package/dist/renderers/webgpu/WebGPUTextureUtils.js +0 -97
- package/dist/renderers/webgpu/WebGPUTextureUtils.mjs +0 -98
- package/dist/renderers/webgpu/WebGPUTextures.js +0 -483
- package/dist/renderers/webgpu/WebGPUTextures.mjs +0 -484
- package/dist/renderers/webgpu/WebGPUUniform.js +0 -81
- package/dist/renderers/webgpu/WebGPUUniform.mjs +0 -81
- package/dist/renderers/webgpu/WebGPUUniformsGroup.js +0 -175
- package/dist/renderers/webgpu/WebGPUUniformsGroup.mjs +0 -176
- package/dist/renderers/webgpu/constants.js +0 -241
- package/dist/renderers/webgpu/constants.mjs +0 -241
- package/dist/renderers/webgpu/nodes/ShaderLib.js +0 -41
- package/dist/renderers/webgpu/nodes/ShaderLib.mjs +0 -42
- package/dist/renderers/webgpu/nodes/WebGPUNodeBuilder.js +0 -164
- package/dist/renderers/webgpu/nodes/WebGPUNodeBuilder.mjs +0 -165
- package/dist/renderers/webgpu/nodes/WebGPUNodeUniform.js +0 -73
- package/dist/renderers/webgpu/nodes/WebGPUNodeUniform.mjs +0 -73
- package/dist/renderers/webgpu/nodes/WebGPUNodeUniformsGroup.js +0 -14
- package/dist/renderers/webgpu/nodes/WebGPUNodeUniformsGroup.mjs +0 -15
- package/dist/renderers/webgpu/nodes/WebGPUNodes.js +0 -39
- package/dist/renderers/webgpu/nodes/WebGPUNodes.mjs +0 -40
|
@@ -1,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,64 @@ 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 (map.colorSpace === THREE.SRGBColorSpace) {
|
|
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
|
+
texture.colorSpace = THREE.NoColorSpace;
|
|
565
|
+
texture.channel = (metalnessMap || roughnessMap).channel;
|
|
566
|
+
if (metalnessMap && roughnessMap && metalnessMap.channel !== roughnessMap.channel) {
|
|
567
|
+
console.warn("THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match.");
|
|
568
|
+
}
|
|
569
|
+
return texture;
|
|
570
|
+
}
|
|
451
571
|
/**
|
|
452
572
|
* Process a buffer to append to the default one.
|
|
453
573
|
* @param {ArrayBuffer} buffer
|
|
@@ -475,14 +595,19 @@ class GLTFWriter {
|
|
|
475
595
|
if (!json.bufferViews)
|
|
476
596
|
json.bufferViews = [];
|
|
477
597
|
let componentSize;
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
598
|
+
switch (componentType) {
|
|
599
|
+
case WEBGL_CONSTANTS.BYTE:
|
|
600
|
+
case WEBGL_CONSTANTS.UNSIGNED_BYTE:
|
|
601
|
+
componentSize = 1;
|
|
602
|
+
break;
|
|
603
|
+
case WEBGL_CONSTANTS.SHORT:
|
|
604
|
+
case WEBGL_CONSTANTS.UNSIGNED_SHORT:
|
|
605
|
+
componentSize = 2;
|
|
606
|
+
break;
|
|
607
|
+
default:
|
|
608
|
+
componentSize = 4;
|
|
609
|
+
}
|
|
610
|
+
const byteLength = getPaddedBufferSize(count * attribute.itemSize * componentSize);
|
|
486
611
|
const dataView = new DataView(new ArrayBuffer(byteLength));
|
|
487
612
|
let offset = 0;
|
|
488
613
|
for (let i = start; i < start + count; i++) {
|
|
@@ -499,18 +624,25 @@ class GLTFWriter {
|
|
|
499
624
|
value = attribute.getZ(i);
|
|
500
625
|
else if (a === 3)
|
|
501
626
|
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);
|
|
627
|
+
if (attribute.normalized === true) {
|
|
628
|
+
value = THREE.MathUtils.normalize(value, attribute.array);
|
|
512
629
|
}
|
|
513
630
|
}
|
|
631
|
+
if (componentType === WEBGL_CONSTANTS.FLOAT) {
|
|
632
|
+
dataView.setFloat32(offset, value, true);
|
|
633
|
+
} else if (componentType === WEBGL_CONSTANTS.INT) {
|
|
634
|
+
dataView.setInt32(offset, value, true);
|
|
635
|
+
} else if (componentType === WEBGL_CONSTANTS.UNSIGNED_INT) {
|
|
636
|
+
dataView.setUint32(offset, value, true);
|
|
637
|
+
} else if (componentType === WEBGL_CONSTANTS.SHORT) {
|
|
638
|
+
dataView.setInt16(offset, value, true);
|
|
639
|
+
} else if (componentType === WEBGL_CONSTANTS.UNSIGNED_SHORT) {
|
|
640
|
+
dataView.setUint16(offset, value, true);
|
|
641
|
+
} else if (componentType === WEBGL_CONSTANTS.BYTE) {
|
|
642
|
+
dataView.setInt8(offset, value);
|
|
643
|
+
} else if (componentType === WEBGL_CONSTANTS.UNSIGNED_BYTE) {
|
|
644
|
+
dataView.setUint8(offset, value);
|
|
645
|
+
}
|
|
514
646
|
offset += componentSize;
|
|
515
647
|
}
|
|
516
648
|
}
|
|
@@ -542,20 +674,18 @@ class GLTFWriter {
|
|
|
542
674
|
const json = writer.json;
|
|
543
675
|
if (!json.bufferViews)
|
|
544
676
|
json.bufferViews = [];
|
|
545
|
-
return new Promise((resolve)
|
|
546
|
-
const reader = new
|
|
677
|
+
return new Promise(function(resolve) {
|
|
678
|
+
const reader = new FileReader();
|
|
547
679
|
reader.readAsArrayBuffer(blob);
|
|
548
|
-
reader.onloadend = ()
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
resolve(json.bufferViews.push(bufferViewDef) - 1);
|
|
558
|
-
}
|
|
680
|
+
reader.onloadend = function() {
|
|
681
|
+
const buffer = getPaddedArrayBuffer(reader.result);
|
|
682
|
+
const bufferViewDef = {
|
|
683
|
+
buffer: writer.processBuffer(buffer),
|
|
684
|
+
byteOffset: writer.byteOffset,
|
|
685
|
+
byteLength: buffer.byteLength
|
|
686
|
+
};
|
|
687
|
+
writer.byteOffset += buffer.byteLength;
|
|
688
|
+
resolve(json.bufferViews.push(bufferViewDef) - 1);
|
|
559
689
|
};
|
|
560
690
|
});
|
|
561
691
|
}
|
|
@@ -568,139 +698,135 @@ class GLTFWriter {
|
|
|
568
698
|
* @return {Integer|null} Index of the processed accessor on the "accessors" array
|
|
569
699
|
*/
|
|
570
700
|
processAccessor(attribute, geometry, start, count) {
|
|
571
|
-
const options = this.options;
|
|
572
701
|
const json = this.json;
|
|
573
702
|
const types = {
|
|
574
703
|
1: "SCALAR",
|
|
575
704
|
2: "VEC2",
|
|
576
705
|
3: "VEC3",
|
|
577
706
|
4: "VEC4",
|
|
707
|
+
9: "MAT3",
|
|
578
708
|
16: "MAT4"
|
|
579
709
|
};
|
|
580
710
|
let componentType;
|
|
581
711
|
if (attribute.array.constructor === Float32Array) {
|
|
582
712
|
componentType = WEBGL_CONSTANTS.FLOAT;
|
|
713
|
+
} else if (attribute.array.constructor === Int32Array) {
|
|
714
|
+
componentType = WEBGL_CONSTANTS.INT;
|
|
583
715
|
} else if (attribute.array.constructor === Uint32Array) {
|
|
584
716
|
componentType = WEBGL_CONSTANTS.UNSIGNED_INT;
|
|
717
|
+
} else if (attribute.array.constructor === Int16Array) {
|
|
718
|
+
componentType = WEBGL_CONSTANTS.SHORT;
|
|
585
719
|
} else if (attribute.array.constructor === Uint16Array) {
|
|
586
720
|
componentType = WEBGL_CONSTANTS.UNSIGNED_SHORT;
|
|
721
|
+
} else if (attribute.array.constructor === Int8Array) {
|
|
722
|
+
componentType = WEBGL_CONSTANTS.BYTE;
|
|
587
723
|
} else if (attribute.array.constructor === Uint8Array) {
|
|
588
724
|
componentType = WEBGL_CONSTANTS.UNSIGNED_BYTE;
|
|
589
725
|
} else {
|
|
590
|
-
throw new Error(
|
|
726
|
+
throw new Error(
|
|
727
|
+
"THREE.GLTFExporter: Unsupported bufferAttribute component type: " + attribute.array.constructor.name
|
|
728
|
+
);
|
|
591
729
|
}
|
|
592
730
|
if (start === void 0)
|
|
593
731
|
start = 0;
|
|
594
732
|
if (count === void 0)
|
|
595
733
|
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
734
|
if (count === 0)
|
|
605
735
|
return null;
|
|
606
|
-
const minMax =
|
|
736
|
+
const minMax = getMinMax(attribute, start, count);
|
|
607
737
|
let bufferViewTarget;
|
|
608
738
|
if (geometry !== void 0) {
|
|
609
739
|
bufferViewTarget = attribute === geometry.index ? WEBGL_CONSTANTS.ELEMENT_ARRAY_BUFFER : WEBGL_CONSTANTS.ARRAY_BUFFER;
|
|
610
740
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
return json.accessors.push(accessorDef) - 1;
|
|
627
|
-
}
|
|
741
|
+
const bufferView = this.processBufferView(attribute, componentType, start, count, bufferViewTarget);
|
|
742
|
+
const accessorDef = {
|
|
743
|
+
bufferView: bufferView.id,
|
|
744
|
+
byteOffset: bufferView.byteOffset,
|
|
745
|
+
componentType,
|
|
746
|
+
count,
|
|
747
|
+
max: minMax.max,
|
|
748
|
+
min: minMax.min,
|
|
749
|
+
type: types[attribute.itemSize]
|
|
750
|
+
};
|
|
751
|
+
if (attribute.normalized === true)
|
|
752
|
+
accessorDef.normalized = true;
|
|
753
|
+
if (!json.accessors)
|
|
754
|
+
json.accessors = [];
|
|
755
|
+
return json.accessors.push(accessorDef) - 1;
|
|
628
756
|
}
|
|
629
757
|
/**
|
|
630
758
|
* Process image
|
|
631
759
|
* @param {Image} image to process
|
|
632
760
|
* @param {Integer} format of the image (RGBAFormat)
|
|
633
761
|
* @param {Boolean} flipY before writing out the image
|
|
762
|
+
* @param {String} mimeType export format
|
|
634
763
|
* @return {Integer} Index of the processed texture in the "images" array
|
|
635
764
|
*/
|
|
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");
|
|
765
|
+
processImage(image, format, flipY, mimeType = "image/png") {
|
|
766
|
+
if (image !== null) {
|
|
767
|
+
const writer = this;
|
|
768
|
+
const cache = writer.cache;
|
|
769
|
+
const json = writer.json;
|
|
770
|
+
const options = writer.options;
|
|
771
|
+
const pending = writer.pending;
|
|
772
|
+
if (!cache.images.has(image))
|
|
773
|
+
cache.images.set(image, {});
|
|
774
|
+
const cachedImages = cache.images.get(image);
|
|
775
|
+
const key = mimeType + ":flipY/" + flipY.toString();
|
|
776
|
+
if (cachedImages[key] !== void 0)
|
|
777
|
+
return cachedImages[key];
|
|
778
|
+
if (!json.images)
|
|
779
|
+
json.images = [];
|
|
780
|
+
const imageDef = { mimeType };
|
|
781
|
+
const canvas = getCanvas();
|
|
654
782
|
canvas.width = Math.min(image.width, options.maxTextureSize);
|
|
655
783
|
canvas.height = Math.min(image.height, options.maxTextureSize);
|
|
656
784
|
const ctx = canvas.getContext("2d");
|
|
657
|
-
if (flipY) {
|
|
658
|
-
ctx
|
|
659
|
-
ctx
|
|
785
|
+
if (flipY === true) {
|
|
786
|
+
ctx.translate(0, canvas.height);
|
|
787
|
+
ctx.scale(1, -1);
|
|
660
788
|
}
|
|
661
|
-
if (
|
|
662
|
-
ctx == null ? void 0 : ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
663
|
-
} else {
|
|
789
|
+
if (image.data !== void 0) {
|
|
664
790
|
if (format !== THREE.RGBAFormat) {
|
|
665
|
-
console.error("GLTFExporter: Only
|
|
791
|
+
console.error("GLTFExporter: Only RGBAFormat is supported.", format);
|
|
666
792
|
}
|
|
667
793
|
if (image.width > options.maxTextureSize || image.height > options.maxTextureSize) {
|
|
668
794
|
console.warn("GLTFExporter: Image size is bigger than maxTextureSize", image);
|
|
669
795
|
}
|
|
670
796
|
const data = new Uint8ClampedArray(image.height * image.width * 4);
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
data[i + 3] = image.data[i + 3];
|
|
677
|
-
}
|
|
797
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
798
|
+
data[i + 0] = image.data[i + 0];
|
|
799
|
+
data[i + 1] = image.data[i + 1];
|
|
800
|
+
data[i + 2] = image.data[i + 2];
|
|
801
|
+
data[i + 3] = image.data[i + 3];
|
|
678
802
|
}
|
|
679
|
-
ctx
|
|
803
|
+
ctx.putImageData(new ImageData(data, image.width, image.height), 0, 0);
|
|
804
|
+
} else {
|
|
805
|
+
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
680
806
|
}
|
|
681
|
-
if (options.binary) {
|
|
807
|
+
if (options.binary === true) {
|
|
682
808
|
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);
|
|
809
|
+
getToBlobPromise(canvas, mimeType).then((blob) => writer.processBufferViewImage(blob)).then((bufferViewIndex) => {
|
|
810
|
+
imageDef.bufferView = bufferViewIndex;
|
|
692
811
|
})
|
|
693
812
|
);
|
|
694
813
|
} else {
|
|
695
|
-
|
|
814
|
+
if (canvas.toDataURL !== void 0) {
|
|
815
|
+
imageDef.uri = canvas.toDataURL(mimeType);
|
|
816
|
+
} else {
|
|
817
|
+
pending.push(
|
|
818
|
+
getToBlobPromise(canvas, mimeType).then((blob) => new FileReader().readAsDataURL(blob)).then((dataURL) => {
|
|
819
|
+
imageDef.uri = dataURL;
|
|
820
|
+
})
|
|
821
|
+
);
|
|
822
|
+
}
|
|
696
823
|
}
|
|
697
|
-
|
|
698
|
-
imageDef.uri = image.src;
|
|
699
|
-
}
|
|
700
|
-
const index = json.images.push(imageDef) - 1;
|
|
701
|
-
if (cachedImages !== void 0)
|
|
824
|
+
const index = json.images.push(imageDef) - 1;
|
|
702
825
|
cachedImages[key] = index;
|
|
703
|
-
|
|
826
|
+
return index;
|
|
827
|
+
} else {
|
|
828
|
+
throw new Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.");
|
|
829
|
+
}
|
|
704
830
|
}
|
|
705
831
|
/**
|
|
706
832
|
* Process sampler
|
|
@@ -725,15 +851,23 @@ class GLTFWriter {
|
|
|
725
851
|
* @return {Integer} Index of the processed texture in the "textures" array
|
|
726
852
|
*/
|
|
727
853
|
processTexture(map) {
|
|
854
|
+
const writer = this;
|
|
855
|
+
const options = writer.options;
|
|
728
856
|
const cache = this.cache;
|
|
729
857
|
const json = this.json;
|
|
730
858
|
if (cache.textures.has(map))
|
|
731
859
|
return cache.textures.get(map);
|
|
732
860
|
if (!json.textures)
|
|
733
861
|
json.textures = [];
|
|
862
|
+
if (map instanceof THREE.CompressedTexture) {
|
|
863
|
+
map = decompress(map, options.maxTextureSize);
|
|
864
|
+
}
|
|
865
|
+
let mimeType = map.userData.mimeType;
|
|
866
|
+
if (mimeType === "image/webp")
|
|
867
|
+
mimeType = "image/png";
|
|
734
868
|
const textureDef = {
|
|
735
869
|
sampler: this.processSampler(map),
|
|
736
|
-
source: this.processImage(map.image, map.format, map.flipY)
|
|
870
|
+
source: this.processImage(map.image, map.format, map.flipY, mimeType)
|
|
737
871
|
};
|
|
738
872
|
if (map.name)
|
|
739
873
|
textureDef.name = map.name;
|
|
@@ -754,74 +888,74 @@ class GLTFWriter {
|
|
|
754
888
|
const json = this.json;
|
|
755
889
|
if (cache.materials.has(material))
|
|
756
890
|
return cache.materials.get(material);
|
|
757
|
-
if (material
|
|
891
|
+
if (material.isShaderMaterial) {
|
|
758
892
|
console.warn("GLTFExporter: THREE.ShaderMaterial not supported.");
|
|
759
893
|
return null;
|
|
760
894
|
}
|
|
761
895
|
if (!json.materials)
|
|
762
896
|
json.materials = [];
|
|
763
897
|
const materialDef = { pbrMetallicRoughness: {} };
|
|
764
|
-
if (
|
|
765
|
-
material.isMeshBasicMaterial)) {
|
|
898
|
+
if (material.isMeshStandardMaterial !== true && material.isMeshBasicMaterial !== true) {
|
|
766
899
|
console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");
|
|
767
900
|
}
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
materialDef.pbrMetallicRoughness.baseColorFactor = color;
|
|
772
|
-
}
|
|
901
|
+
const color = material.color.toArray().concat([material.opacity]);
|
|
902
|
+
if (!equalArray(color, [1, 1, 1, 1])) {
|
|
903
|
+
materialDef.pbrMetallicRoughness.baseColorFactor = color;
|
|
773
904
|
}
|
|
774
|
-
if (material
|
|
905
|
+
if (material.isMeshStandardMaterial) {
|
|
775
906
|
materialDef.pbrMetallicRoughness.metallicFactor = material.metalness;
|
|
776
907
|
materialDef.pbrMetallicRoughness.roughnessFactor = material.roughness;
|
|
777
908
|
} else {
|
|
778
909
|
materialDef.pbrMetallicRoughness.metallicFactor = 0.5;
|
|
779
910
|
materialDef.pbrMetallicRoughness.roughnessFactor = 0.5;
|
|
780
911
|
}
|
|
781
|
-
if (material
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
this.
|
|
785
|
-
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
);
|
|
790
|
-
}
|
|
912
|
+
if (material.metalnessMap || material.roughnessMap) {
|
|
913
|
+
const metalRoughTexture = this.buildMetalRoughTexture(material.metalnessMap, material.roughnessMap);
|
|
914
|
+
const metalRoughMapDef = {
|
|
915
|
+
index: this.processTexture(metalRoughTexture),
|
|
916
|
+
channel: metalRoughTexture.channel
|
|
917
|
+
};
|
|
918
|
+
this.applyTextureTransform(metalRoughMapDef, metalRoughTexture);
|
|
919
|
+
materialDef.pbrMetallicRoughness.metallicRoughnessTexture = metalRoughMapDef;
|
|
791
920
|
}
|
|
792
|
-
if (
|
|
793
|
-
const baseColorMapDef = {
|
|
921
|
+
if (material.map) {
|
|
922
|
+
const baseColorMapDef = {
|
|
923
|
+
index: this.processTexture(material.map),
|
|
924
|
+
texCoord: material.map.channel
|
|
925
|
+
};
|
|
794
926
|
this.applyTextureTransform(baseColorMapDef, material.map);
|
|
795
927
|
materialDef.pbrMetallicRoughness.baseColorTexture = baseColorMapDef;
|
|
796
928
|
}
|
|
797
|
-
if (
|
|
798
|
-
const emissive = material.emissive
|
|
929
|
+
if (material.emissive) {
|
|
930
|
+
const emissive = material.emissive;
|
|
799
931
|
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
932
|
if (maxEmissiveComponent > 0) {
|
|
805
|
-
materialDef.emissiveFactor = emissive.toArray();
|
|
933
|
+
materialDef.emissiveFactor = material.emissive.toArray();
|
|
806
934
|
}
|
|
807
935
|
if (material.emissiveMap) {
|
|
808
|
-
const emissiveMapDef = {
|
|
936
|
+
const emissiveMapDef = {
|
|
937
|
+
index: this.processTexture(material.emissiveMap),
|
|
938
|
+
texCoord: material.emissiveMap.channel
|
|
939
|
+
};
|
|
809
940
|
this.applyTextureTransform(emissiveMapDef, material.emissiveMap);
|
|
810
941
|
materialDef.emissiveTexture = emissiveMapDef;
|
|
811
942
|
}
|
|
812
943
|
}
|
|
813
|
-
if (
|
|
814
|
-
const normalMapDef = {
|
|
944
|
+
if (material.normalMap) {
|
|
945
|
+
const normalMapDef = {
|
|
946
|
+
index: this.processTexture(material.normalMap),
|
|
947
|
+
texCoord: material.normalMap.channel
|
|
948
|
+
};
|
|
815
949
|
if (material.normalScale && material.normalScale.x !== 1) {
|
|
816
950
|
normalMapDef.scale = material.normalScale.x;
|
|
817
951
|
}
|
|
818
952
|
this.applyTextureTransform(normalMapDef, material.normalMap);
|
|
819
953
|
materialDef.normalTexture = normalMapDef;
|
|
820
954
|
}
|
|
821
|
-
if (
|
|
955
|
+
if (material.aoMap) {
|
|
822
956
|
const occlusionMapDef = {
|
|
823
957
|
index: this.processTexture(material.aoMap),
|
|
824
|
-
texCoord:
|
|
958
|
+
texCoord: material.aoMap.channel
|
|
825
959
|
};
|
|
826
960
|
if (material.aoMapIntensity !== 1) {
|
|
827
961
|
occlusionMapDef.strength = material.aoMapIntensity;
|
|
@@ -870,19 +1004,16 @@ class GLTFWriter {
|
|
|
870
1004
|
return cache.meshes.get(meshCacheKey);
|
|
871
1005
|
const geometry = mesh.geometry;
|
|
872
1006
|
let mode;
|
|
873
|
-
if (mesh
|
|
1007
|
+
if (mesh.isLineSegments) {
|
|
874
1008
|
mode = WEBGL_CONSTANTS.LINES;
|
|
875
|
-
} else if (mesh
|
|
1009
|
+
} else if (mesh.isLineLoop) {
|
|
876
1010
|
mode = WEBGL_CONSTANTS.LINE_LOOP;
|
|
877
|
-
} else if (mesh
|
|
1011
|
+
} else if (mesh.isLine) {
|
|
878
1012
|
mode = WEBGL_CONSTANTS.LINE_STRIP;
|
|
879
|
-
} else if (mesh
|
|
1013
|
+
} else if (mesh.isPoints) {
|
|
880
1014
|
mode = WEBGL_CONSTANTS.POINTS;
|
|
881
1015
|
} else {
|
|
882
|
-
mode =
|
|
883
|
-
}
|
|
884
|
-
if (!geometry.isBufferGeometry) {
|
|
885
|
-
throw new Error("THREE.GLTFExporter: Geometry is not of type THREE.BufferGeometry.");
|
|
1016
|
+
mode = mesh.material.wireframe ? WEBGL_CONSTANTS.LINES : WEBGL_CONSTANTS.TRIANGLES;
|
|
886
1017
|
}
|
|
887
1018
|
const meshDef = {};
|
|
888
1019
|
const attributes = {};
|
|
@@ -890,19 +1021,19 @@ class GLTFWriter {
|
|
|
890
1021
|
const targets = [];
|
|
891
1022
|
const nameConversion = {
|
|
892
1023
|
uv: "TEXCOORD_0",
|
|
893
|
-
uv2: "TEXCOORD_1",
|
|
1024
|
+
[THREE.REVISION.replace(/\D+/g, "") >= 152 ? "uv1" : "uv2"]: "TEXCOORD_1",
|
|
894
1025
|
color: "COLOR_0",
|
|
895
1026
|
skinWeight: "WEIGHTS_0",
|
|
896
1027
|
skinIndex: "JOINTS_0"
|
|
897
1028
|
};
|
|
898
1029
|
const originalNormal = geometry.getAttribute("normal");
|
|
899
|
-
if (originalNormal !== void 0 && !
|
|
1030
|
+
if (originalNormal !== void 0 && !this.isNormalizedNormalAttribute(originalNormal)) {
|
|
900
1031
|
console.warn("THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one.");
|
|
901
1032
|
geometry.setAttribute("normal", this.createNormalizedNormalAttribute(originalNormal));
|
|
902
1033
|
}
|
|
903
1034
|
let modifiedAttribute = null;
|
|
904
1035
|
for (let attributeName in geometry.attributes) {
|
|
905
|
-
if (attributeName.
|
|
1036
|
+
if (attributeName.slice(0, 5) === "morph")
|
|
906
1037
|
continue;
|
|
907
1038
|
const attribute = geometry.attributes[attributeName];
|
|
908
1039
|
attributeName = nameConversion[attributeName] || attributeName.toUpperCase();
|
|
@@ -919,8 +1050,11 @@ class GLTFWriter {
|
|
|
919
1050
|
console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.');
|
|
920
1051
|
modifiedAttribute = new THREE.BufferAttribute(new Uint16Array(array), attribute.itemSize, attribute.normalized);
|
|
921
1052
|
}
|
|
922
|
-
const accessor =
|
|
923
|
-
if (accessor) {
|
|
1053
|
+
const accessor = this.processAccessor(modifiedAttribute || attribute, geometry);
|
|
1054
|
+
if (accessor !== null) {
|
|
1055
|
+
if (!attributeName.startsWith("_")) {
|
|
1056
|
+
this.detectMeshQuantization(attributeName, attribute);
|
|
1057
|
+
}
|
|
924
1058
|
attributes[attributeName] = accessor;
|
|
925
1059
|
cache.attributes.set(this.getUID(attribute), accessor);
|
|
926
1060
|
}
|
|
@@ -952,26 +1086,27 @@ class GLTFWriter {
|
|
|
952
1086
|
const attribute = geometry.morphAttributes[attributeName][i];
|
|
953
1087
|
const gltfAttributeName = attributeName.toUpperCase();
|
|
954
1088
|
const baseAttribute = geometry.attributes[attributeName];
|
|
955
|
-
if (cache.attributes.has(this.getUID(attribute))) {
|
|
956
|
-
target[gltfAttributeName] = cache.attributes.get(this.getUID(attribute));
|
|
1089
|
+
if (cache.attributes.has(this.getUID(attribute, true))) {
|
|
1090
|
+
target[gltfAttributeName] = cache.attributes.get(this.getUID(attribute, true));
|
|
957
1091
|
continue;
|
|
958
1092
|
}
|
|
959
1093
|
const relativeAttribute = attribute.clone();
|
|
960
1094
|
if (!geometry.morphTargetsRelative) {
|
|
961
1095
|
for (let j = 0, jl = attribute.count; j < jl; j++) {
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
1096
|
+
for (let a = 0; a < attribute.itemSize; a++) {
|
|
1097
|
+
if (a === 0)
|
|
1098
|
+
relativeAttribute.setX(j, attribute.getX(j) - baseAttribute.getX(j));
|
|
1099
|
+
if (a === 1)
|
|
1100
|
+
relativeAttribute.setY(j, attribute.getY(j) - baseAttribute.getY(j));
|
|
1101
|
+
if (a === 2)
|
|
1102
|
+
relativeAttribute.setZ(j, attribute.getZ(j) - baseAttribute.getZ(j));
|
|
1103
|
+
if (a === 3)
|
|
1104
|
+
relativeAttribute.setW(j, attribute.getW(j) - baseAttribute.getW(j));
|
|
1105
|
+
}
|
|
968
1106
|
}
|
|
969
1107
|
}
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
target[gltfAttributeName] = accessor;
|
|
973
|
-
}
|
|
974
|
-
cache.attributes.set(this.getUID(baseAttribute), target[gltfAttributeName]);
|
|
1108
|
+
target[gltfAttributeName] = this.processAccessor(relativeAttribute, geometry);
|
|
1109
|
+
cache.attributes.set(this.getUID(baseAttribute, true), target[gltfAttributeName]);
|
|
975
1110
|
}
|
|
976
1111
|
targets.push(target);
|
|
977
1112
|
weights.push(mesh.morphTargetInfluences[i]);
|
|
@@ -994,15 +1129,13 @@ class GLTFWriter {
|
|
|
994
1129
|
mode,
|
|
995
1130
|
attributes
|
|
996
1131
|
};
|
|
997
|
-
|
|
998
|
-
this.serializeUserData(geometry, primitive);
|
|
999
|
-
}
|
|
1132
|
+
this.serializeUserData(geometry, primitive);
|
|
1000
1133
|
if (targets.length > 0)
|
|
1001
1134
|
primitive.targets = targets;
|
|
1002
1135
|
if (geometry.index !== null) {
|
|
1003
1136
|
let cacheKey = this.getUID(geometry.index);
|
|
1004
1137
|
if (groups[i].start !== void 0 || groups[i].count !== void 0) {
|
|
1005
|
-
cacheKey +=
|
|
1138
|
+
cacheKey += ":" + groups[i].start + ":" + groups[i].count;
|
|
1006
1139
|
}
|
|
1007
1140
|
if (cache.attributes.has(cacheKey)) {
|
|
1008
1141
|
primitive.indices = cache.attributes.get(cacheKey);
|
|
@@ -1013,16 +1146,10 @@ class GLTFWriter {
|
|
|
1013
1146
|
if (primitive.indices === null)
|
|
1014
1147
|
delete primitive.indices;
|
|
1015
1148
|
}
|
|
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
|
-
}
|
|
1149
|
+
const material = this.processMaterial(materials[groups[i].materialIndex]);
|
|
1150
|
+
if (material !== null)
|
|
1151
|
+
primitive.material = material;
|
|
1152
|
+
primitives.push(primitive);
|
|
1026
1153
|
}
|
|
1027
1154
|
meshDef.primitives = primitives;
|
|
1028
1155
|
if (!json.meshes)
|
|
@@ -1034,6 +1161,45 @@ class GLTFWriter {
|
|
|
1034
1161
|
cache.meshes.set(meshCacheKey, index);
|
|
1035
1162
|
return index;
|
|
1036
1163
|
}
|
|
1164
|
+
/**
|
|
1165
|
+
* If a vertex attribute with a
|
|
1166
|
+
* [non-standard data type](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview)
|
|
1167
|
+
* is used, it is checked whether it is a valid data type according to the
|
|
1168
|
+
* [KHR_mesh_quantization](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_mesh_quantization/README.md)
|
|
1169
|
+
* extension.
|
|
1170
|
+
* In this case the extension is automatically added to the list of used extensions.
|
|
1171
|
+
*
|
|
1172
|
+
* @param {string} attributeName
|
|
1173
|
+
* @param {THREE.BufferAttribute} attribute
|
|
1174
|
+
*/
|
|
1175
|
+
detectMeshQuantization(attributeName, attribute) {
|
|
1176
|
+
if (this.extensionsUsed[KHR_MESH_QUANTIZATION])
|
|
1177
|
+
return;
|
|
1178
|
+
let attrType = void 0;
|
|
1179
|
+
switch (attribute.array.constructor) {
|
|
1180
|
+
case Int8Array:
|
|
1181
|
+
attrType = "byte";
|
|
1182
|
+
break;
|
|
1183
|
+
case Uint8Array:
|
|
1184
|
+
attrType = "unsigned byte";
|
|
1185
|
+
break;
|
|
1186
|
+
case Int16Array:
|
|
1187
|
+
attrType = "short";
|
|
1188
|
+
break;
|
|
1189
|
+
case Uint16Array:
|
|
1190
|
+
attrType = "unsigned short";
|
|
1191
|
+
break;
|
|
1192
|
+
default:
|
|
1193
|
+
return;
|
|
1194
|
+
}
|
|
1195
|
+
if (attribute.normalized)
|
|
1196
|
+
attrType += " normalized";
|
|
1197
|
+
const attrNamePrefix = attributeName.split("_", 1)[0];
|
|
1198
|
+
if (KHR_mesh_quantization_ExtraAttrTypes[attrNamePrefix] && KHR_mesh_quantization_ExtraAttrTypes[attrNamePrefix].includes(attrType)) {
|
|
1199
|
+
this.extensionsUsed[KHR_MESH_QUANTIZATION] = true;
|
|
1200
|
+
this.extensionsRequired[KHR_MESH_QUANTIZATION] = true;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1037
1203
|
/**
|
|
1038
1204
|
* Process camera
|
|
1039
1205
|
* @param {THREE.Camera} camera Camera to process
|
|
@@ -1043,18 +1209,18 @@ class GLTFWriter {
|
|
|
1043
1209
|
const json = this.json;
|
|
1044
1210
|
if (!json.cameras)
|
|
1045
1211
|
json.cameras = [];
|
|
1046
|
-
const isOrtho = camera
|
|
1212
|
+
const isOrtho = camera.isOrthographicCamera;
|
|
1047
1213
|
const cameraDef = {
|
|
1048
1214
|
type: isOrtho ? "orthographic" : "perspective"
|
|
1049
1215
|
};
|
|
1050
|
-
if (
|
|
1216
|
+
if (isOrtho) {
|
|
1051
1217
|
cameraDef.orthographic = {
|
|
1052
1218
|
xmag: camera.right * 2,
|
|
1053
1219
|
ymag: camera.top * 2,
|
|
1054
1220
|
zfar: camera.far <= 0 ? 1e-3 : camera.far,
|
|
1055
1221
|
znear: camera.near < 0 ? 0 : camera.near
|
|
1056
1222
|
};
|
|
1057
|
-
} else
|
|
1223
|
+
} else {
|
|
1058
1224
|
cameraDef.perspective = {
|
|
1059
1225
|
aspectRatio: camera.aspect,
|
|
1060
1226
|
yfov: THREE.MathUtils.degToRad(camera.fov),
|
|
@@ -1091,7 +1257,7 @@ class GLTFWriter {
|
|
|
1091
1257
|
let trackNode = THREE.PropertyBinding.findNode(root, trackBinding.nodeName);
|
|
1092
1258
|
const trackProperty = PATH_PROPERTIES[trackBinding.propertyName];
|
|
1093
1259
|
if (trackBinding.objectName === "bones") {
|
|
1094
|
-
if (trackNode.isSkinnedMesh) {
|
|
1260
|
+
if (trackNode.isSkinnedMesh === true) {
|
|
1095
1261
|
trackNode = trackNode.skeleton.getBoneByName(trackBinding.objectIndex);
|
|
1096
1262
|
} else {
|
|
1097
1263
|
trackNode = void 0;
|
|
@@ -1107,7 +1273,7 @@ class GLTFWriter {
|
|
|
1107
1273
|
outputItemSize /= trackNode.morphTargetInfluences.length;
|
|
1108
1274
|
}
|
|
1109
1275
|
let interpolation;
|
|
1110
|
-
if (track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
|
|
1276
|
+
if (track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === true) {
|
|
1111
1277
|
interpolation = "CUBICSPLINE";
|
|
1112
1278
|
outputItemSize /= 3;
|
|
1113
1279
|
} else if (track.getInterpolation() === THREE.InterpolateDiscrete) {
|
|
@@ -1142,34 +1308,30 @@ class GLTFWriter {
|
|
|
1142
1308
|
processSkin(object) {
|
|
1143
1309
|
const json = this.json;
|
|
1144
1310
|
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 {
|
|
1311
|
+
const node = json.nodes[nodeMap.get(object)];
|
|
1312
|
+
const skeleton = object.skeleton;
|
|
1313
|
+
if (skeleton === void 0)
|
|
1171
1314
|
return null;
|
|
1172
|
-
|
|
1315
|
+
const rootJoint = object.skeleton.bones[0];
|
|
1316
|
+
if (rootJoint === void 0)
|
|
1317
|
+
return null;
|
|
1318
|
+
const joints = [];
|
|
1319
|
+
const inverseBindMatrices = new Float32Array(skeleton.bones.length * 16);
|
|
1320
|
+
const temporaryBoneInverse = new THREE.Matrix4();
|
|
1321
|
+
for (let i = 0; i < skeleton.bones.length; ++i) {
|
|
1322
|
+
joints.push(nodeMap.get(skeleton.bones[i]));
|
|
1323
|
+
temporaryBoneInverse.copy(skeleton.boneInverses[i]);
|
|
1324
|
+
temporaryBoneInverse.multiply(object.bindMatrix).toArray(inverseBindMatrices, i * 16);
|
|
1325
|
+
}
|
|
1326
|
+
if (json.skins === void 0)
|
|
1327
|
+
json.skins = [];
|
|
1328
|
+
json.skins.push({
|
|
1329
|
+
inverseBindMatrices: this.processAccessor(new THREE.BufferAttribute(inverseBindMatrices, 16)),
|
|
1330
|
+
joints,
|
|
1331
|
+
skeleton: nodeMap.get(rootJoint)
|
|
1332
|
+
});
|
|
1333
|
+
const skinIndex = node.skin = json.skins.length - 1;
|
|
1334
|
+
return skinIndex;
|
|
1173
1335
|
}
|
|
1174
1336
|
/**
|
|
1175
1337
|
* Process Object3D node
|
|
@@ -1187,40 +1349,40 @@ class GLTFWriter {
|
|
|
1187
1349
|
const rotation = object.quaternion.toArray();
|
|
1188
1350
|
const position = object.position.toArray();
|
|
1189
1351
|
const scale = object.scale.toArray();
|
|
1190
|
-
if (!
|
|
1352
|
+
if (!equalArray(rotation, [0, 0, 0, 1])) {
|
|
1191
1353
|
nodeDef.rotation = rotation;
|
|
1192
1354
|
}
|
|
1193
|
-
if (!
|
|
1355
|
+
if (!equalArray(position, [0, 0, 0])) {
|
|
1194
1356
|
nodeDef.translation = position;
|
|
1195
1357
|
}
|
|
1196
|
-
if (!
|
|
1358
|
+
if (!equalArray(scale, [1, 1, 1])) {
|
|
1197
1359
|
nodeDef.scale = scale;
|
|
1198
1360
|
}
|
|
1199
1361
|
} else {
|
|
1200
1362
|
if (object.matrixAutoUpdate) {
|
|
1201
1363
|
object.updateMatrix();
|
|
1202
1364
|
}
|
|
1203
|
-
if (
|
|
1365
|
+
if (isIdentityMatrix(object.matrix) === false) {
|
|
1204
1366
|
nodeDef.matrix = object.matrix.elements;
|
|
1205
1367
|
}
|
|
1206
1368
|
}
|
|
1207
1369
|
if (object.name !== "")
|
|
1208
1370
|
nodeDef.name = String(object.name);
|
|
1209
1371
|
this.serializeUserData(object, nodeDef);
|
|
1210
|
-
if (
|
|
1372
|
+
if (object.isMesh || object.isLine || object.isPoints) {
|
|
1211
1373
|
const meshIndex = this.processMesh(object);
|
|
1212
1374
|
if (meshIndex !== null)
|
|
1213
1375
|
nodeDef.mesh = meshIndex;
|
|
1214
|
-
} else if (object
|
|
1376
|
+
} else if (object.isCamera) {
|
|
1215
1377
|
nodeDef.camera = this.processCamera(object);
|
|
1216
1378
|
}
|
|
1217
|
-
if (object
|
|
1379
|
+
if (object.isSkinnedMesh)
|
|
1218
1380
|
this.skins.push(object);
|
|
1219
1381
|
if (object.children.length > 0) {
|
|
1220
1382
|
const children = [];
|
|
1221
1383
|
for (let i = 0, l = object.children.length; i < l; i++) {
|
|
1222
1384
|
const child = object.children[i];
|
|
1223
|
-
if (child.visible ||
|
|
1385
|
+
if (child.visible || options.onlyVisible === false) {
|
|
1224
1386
|
const nodeIndex2 = this.processNode(child);
|
|
1225
1387
|
if (nodeIndex2 !== null)
|
|
1226
1388
|
children.push(nodeIndex2);
|
|
@@ -1254,7 +1416,7 @@ class GLTFWriter {
|
|
|
1254
1416
|
const nodes = [];
|
|
1255
1417
|
for (let i = 0, l = scene.children.length; i < l; i++) {
|
|
1256
1418
|
const child = scene.children[i];
|
|
1257
|
-
if (child.visible ||
|
|
1419
|
+
if (child.visible || options.onlyVisible === false) {
|
|
1258
1420
|
const nodeIndex = this.processNode(child);
|
|
1259
1421
|
if (nodeIndex !== null)
|
|
1260
1422
|
nodes.push(nodeIndex);
|
|
@@ -1264,6 +1426,10 @@ class GLTFWriter {
|
|
|
1264
1426
|
sceneDef.nodes = nodes;
|
|
1265
1427
|
this.serializeUserData(scene, sceneDef);
|
|
1266
1428
|
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Creates a Scene to hold a list of objects and parse it
|
|
1431
|
+
* @param {Array} objects List of objects to process
|
|
1432
|
+
*/
|
|
1267
1433
|
processObjects(objects) {
|
|
1268
1434
|
const scene = new THREE.Scene();
|
|
1269
1435
|
scene.name = "AuxScene";
|
|
@@ -1283,9 +1449,8 @@ class GLTFWriter {
|
|
|
1283
1449
|
});
|
|
1284
1450
|
const objectsWithoutScene = [];
|
|
1285
1451
|
for (let i = 0; i < input.length; i++) {
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
this.processScene(inputScene);
|
|
1452
|
+
if (input[i] instanceof THREE.Scene) {
|
|
1453
|
+
this.processScene(input[i]);
|
|
1289
1454
|
} else {
|
|
1290
1455
|
objectsWithoutScene.push(input[i]);
|
|
1291
1456
|
}
|
|
@@ -1295,7 +1460,7 @@ class GLTFWriter {
|
|
|
1295
1460
|
for (let i = 0; i < this.skins.length; ++i) {
|
|
1296
1461
|
this.processSkin(this.skins[i]);
|
|
1297
1462
|
}
|
|
1298
|
-
for (let i = 0;
|
|
1463
|
+
for (let i = 0; i < options.animations.length; ++i) {
|
|
1299
1464
|
this.processAnimation(options.animations[i], input[0]);
|
|
1300
1465
|
}
|
|
1301
1466
|
this._invokeAll(function(ext) {
|
|
@@ -1307,108 +1472,16 @@ class GLTFWriter {
|
|
|
1307
1472
|
func(this.plugins[i]);
|
|
1308
1473
|
}
|
|
1309
1474
|
}
|
|
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
1475
|
}
|
|
1400
1476
|
class GLTFLightExtension {
|
|
1401
1477
|
constructor(writer) {
|
|
1402
|
-
__publicField(this, "writer");
|
|
1403
|
-
__publicField(this, "name");
|
|
1404
1478
|
this.writer = writer;
|
|
1405
1479
|
this.name = "KHR_lights_punctual";
|
|
1406
1480
|
}
|
|
1407
1481
|
writeNode(light, nodeDef) {
|
|
1408
1482
|
if (!light.isLight)
|
|
1409
1483
|
return;
|
|
1410
|
-
if (!
|
|
1411
|
-
!(light instanceof THREE.PointLight && light.isPointLight) && !(light instanceof THREE.SpotLight && light.isSpotLight)) {
|
|
1484
|
+
if (!light.isDirectionalLight && !light.isPointLight && !light.isSpotLight) {
|
|
1412
1485
|
console.warn("THREE.GLTFExporter: Only directional, point, and spot lights are supported.", light);
|
|
1413
1486
|
return;
|
|
1414
1487
|
}
|
|
@@ -1420,14 +1493,13 @@ class GLTFLightExtension {
|
|
|
1420
1493
|
lightDef.name = light.name;
|
|
1421
1494
|
lightDef.color = light.color.toArray();
|
|
1422
1495
|
lightDef.intensity = light.intensity;
|
|
1423
|
-
if (light
|
|
1496
|
+
if (light.isDirectionalLight) {
|
|
1424
1497
|
lightDef.type = "directional";
|
|
1425
|
-
} else if (light
|
|
1426
|
-
light.isPointLight) {
|
|
1498
|
+
} else if (light.isPointLight) {
|
|
1427
1499
|
lightDef.type = "point";
|
|
1428
1500
|
if (light.distance > 0)
|
|
1429
1501
|
lightDef.range = light.distance;
|
|
1430
|
-
} else if (light
|
|
1502
|
+
} else if (light.isSpotLight) {
|
|
1431
1503
|
lightDef.type = "spot";
|
|
1432
1504
|
if (light.distance > 0)
|
|
1433
1505
|
lightDef.range = light.distance;
|
|
@@ -1435,12 +1507,12 @@ class GLTFLightExtension {
|
|
|
1435
1507
|
lightDef.spot.innerConeAngle = (light.penumbra - 1) * light.angle * -1;
|
|
1436
1508
|
lightDef.spot.outerConeAngle = light.angle;
|
|
1437
1509
|
}
|
|
1438
|
-
if (
|
|
1510
|
+
if (light.decay !== void 0 && light.decay !== 2) {
|
|
1439
1511
|
console.warn(
|
|
1440
1512
|
"THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."
|
|
1441
1513
|
);
|
|
1442
1514
|
}
|
|
1443
|
-
if (
|
|
1515
|
+
if (light.target && (light.target.parent !== light || light.target.position.x !== 0 || light.target.position.y !== 0 || light.target.position.z !== -1)) {
|
|
1444
1516
|
console.warn(
|
|
1445
1517
|
"THREE.GLTFExporter: Light direction may be lost. For best results, make light.target a child of the light with position 0,0,-1."
|
|
1446
1518
|
);
|
|
@@ -1450,26 +1522,20 @@ class GLTFLightExtension {
|
|
|
1450
1522
|
json.extensions[this.name] = { lights: [] };
|
|
1451
1523
|
extensionsUsed[this.name] = true;
|
|
1452
1524
|
}
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
nodeDef.extensions[this.name] = { light: lights.length - 1 };
|
|
1458
|
-
}
|
|
1525
|
+
const lights = json.extensions[this.name].lights;
|
|
1526
|
+
lights.push(lightDef);
|
|
1527
|
+
nodeDef.extensions = nodeDef.extensions || {};
|
|
1528
|
+
nodeDef.extensions[this.name] = { light: lights.length - 1 };
|
|
1459
1529
|
}
|
|
1460
1530
|
}
|
|
1461
1531
|
class GLTFMaterialsUnlitExtension {
|
|
1462
1532
|
constructor(writer) {
|
|
1463
|
-
__publicField(this, "writer");
|
|
1464
|
-
__publicField(this, "name");
|
|
1465
1533
|
this.writer = writer;
|
|
1466
1534
|
this.name = "KHR_materials_unlit";
|
|
1467
1535
|
}
|
|
1468
1536
|
writeMaterial(material, materialDef) {
|
|
1469
|
-
if (!
|
|
1470
|
-
material.isMeshBasicMaterial)) {
|
|
1537
|
+
if (!material.isMeshBasicMaterial)
|
|
1471
1538
|
return;
|
|
1472
|
-
}
|
|
1473
1539
|
const writer = this.writer;
|
|
1474
1540
|
const extensionsUsed = writer.extensionsUsed;
|
|
1475
1541
|
materialDef.extensions = materialDef.extensions || {};
|
|
@@ -1479,36 +1545,78 @@ class GLTFMaterialsUnlitExtension {
|
|
|
1479
1545
|
materialDef.pbrMetallicRoughness.roughnessFactor = 0.9;
|
|
1480
1546
|
}
|
|
1481
1547
|
}
|
|
1482
|
-
class
|
|
1548
|
+
class GLTFMaterialsClearcoatExtension {
|
|
1483
1549
|
constructor(writer) {
|
|
1484
|
-
__publicField(this, "writer");
|
|
1485
|
-
__publicField(this, "name");
|
|
1486
1550
|
this.writer = writer;
|
|
1487
|
-
this.name = "
|
|
1551
|
+
this.name = "KHR_materials_clearcoat";
|
|
1488
1552
|
}
|
|
1489
1553
|
writeMaterial(material, materialDef) {
|
|
1490
|
-
if (!material.
|
|
1554
|
+
if (!material.isMeshPhysicalMaterial || material.clearcoat === 0)
|
|
1491
1555
|
return;
|
|
1492
1556
|
const writer = this.writer;
|
|
1493
1557
|
const extensionsUsed = writer.extensionsUsed;
|
|
1494
1558
|
const extensionDef = {};
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
extensionDef.
|
|
1503
|
-
|
|
1559
|
+
extensionDef.clearcoatFactor = material.clearcoat;
|
|
1560
|
+
if (material.clearcoatMap) {
|
|
1561
|
+
const clearcoatMapDef = {
|
|
1562
|
+
index: writer.processTexture(material.clearcoatMap),
|
|
1563
|
+
texCoord: material.clearcoatMap.channel
|
|
1564
|
+
};
|
|
1565
|
+
writer.applyTextureTransform(clearcoatMapDef, material.clearcoatMap);
|
|
1566
|
+
extensionDef.clearcoatTexture = clearcoatMapDef;
|
|
1567
|
+
}
|
|
1568
|
+
extensionDef.clearcoatRoughnessFactor = material.clearcoatRoughness;
|
|
1569
|
+
if (material.clearcoatRoughnessMap) {
|
|
1570
|
+
const clearcoatRoughnessMapDef = {
|
|
1571
|
+
index: writer.processTexture(material.clearcoatRoughnessMap),
|
|
1572
|
+
texCoord: material.clearcoatRoughnessMap.channel
|
|
1573
|
+
};
|
|
1574
|
+
writer.applyTextureTransform(clearcoatRoughnessMapDef, material.clearcoatRoughnessMap);
|
|
1575
|
+
extensionDef.clearcoatRoughnessTexture = clearcoatRoughnessMapDef;
|
|
1504
1576
|
}
|
|
1505
|
-
if (
|
|
1506
|
-
|
|
1577
|
+
if (material.clearcoatNormalMap) {
|
|
1578
|
+
const clearcoatNormalMapDef = {
|
|
1579
|
+
index: writer.processTexture(material.clearcoatNormalMap),
|
|
1580
|
+
texCoord: material.clearcoatNormalMap.channel
|
|
1581
|
+
};
|
|
1582
|
+
writer.applyTextureTransform(clearcoatNormalMapDef, material.clearcoatNormalMap);
|
|
1583
|
+
extensionDef.clearcoatNormalTexture = clearcoatNormalMapDef;
|
|
1507
1584
|
}
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1585
|
+
materialDef.extensions = materialDef.extensions || {};
|
|
1586
|
+
materialDef.extensions[this.name] = extensionDef;
|
|
1587
|
+
extensionsUsed[this.name] = true;
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
class GLTFMaterialsIridescenceExtension {
|
|
1591
|
+
constructor(writer) {
|
|
1592
|
+
this.writer = writer;
|
|
1593
|
+
this.name = "KHR_materials_iridescence";
|
|
1594
|
+
}
|
|
1595
|
+
writeMaterial(material, materialDef) {
|
|
1596
|
+
if (!material.isMeshPhysicalMaterial || material.iridescence === 0)
|
|
1597
|
+
return;
|
|
1598
|
+
const writer = this.writer;
|
|
1599
|
+
const extensionsUsed = writer.extensionsUsed;
|
|
1600
|
+
const extensionDef = {};
|
|
1601
|
+
extensionDef.iridescenceFactor = material.iridescence;
|
|
1602
|
+
if (material.iridescenceMap) {
|
|
1603
|
+
const iridescenceMapDef = {
|
|
1604
|
+
index: writer.processTexture(material.iridescenceMap),
|
|
1605
|
+
texCoord: material.iridescenceMap.channel
|
|
1606
|
+
};
|
|
1607
|
+
writer.applyTextureTransform(iridescenceMapDef, material.iridescenceMap);
|
|
1608
|
+
extensionDef.iridescenceTexture = iridescenceMapDef;
|
|
1609
|
+
}
|
|
1610
|
+
extensionDef.iridescenceIor = material.iridescenceIOR;
|
|
1611
|
+
extensionDef.iridescenceThicknessMinimum = material.iridescenceThicknessRange[0];
|
|
1612
|
+
extensionDef.iridescenceThicknessMaximum = material.iridescenceThicknessRange[1];
|
|
1613
|
+
if (material.iridescenceThicknessMap) {
|
|
1614
|
+
const iridescenceThicknessMapDef = {
|
|
1615
|
+
index: writer.processTexture(material.iridescenceThicknessMap),
|
|
1616
|
+
texCoord: material.iridescenceThicknessMap.channel
|
|
1617
|
+
};
|
|
1618
|
+
writer.applyTextureTransform(iridescenceThicknessMapDef, material.iridescenceThicknessMap);
|
|
1619
|
+
extensionDef.iridescenceThicknessTexture = iridescenceThicknessMapDef;
|
|
1512
1620
|
}
|
|
1513
1621
|
materialDef.extensions = materialDef.extensions || {};
|
|
1514
1622
|
materialDef.extensions[this.name] = extensionDef;
|
|
@@ -1517,22 +1625,21 @@ class GLTFMaterialsPBRSpecularGlossiness {
|
|
|
1517
1625
|
}
|
|
1518
1626
|
class GLTFMaterialsTransmissionExtension {
|
|
1519
1627
|
constructor(writer) {
|
|
1520
|
-
__publicField(this, "writer");
|
|
1521
|
-
__publicField(this, "name");
|
|
1522
1628
|
this.writer = writer;
|
|
1523
1629
|
this.name = "KHR_materials_transmission";
|
|
1524
1630
|
}
|
|
1525
1631
|
writeMaterial(material, materialDef) {
|
|
1526
|
-
if (!
|
|
1527
|
-
material.isMeshPhysicalMaterial) || material.transmission === 0) {
|
|
1632
|
+
if (!material.isMeshPhysicalMaterial || material.transmission === 0)
|
|
1528
1633
|
return;
|
|
1529
|
-
}
|
|
1530
1634
|
const writer = this.writer;
|
|
1531
1635
|
const extensionsUsed = writer.extensionsUsed;
|
|
1532
1636
|
const extensionDef = {};
|
|
1533
1637
|
extensionDef.transmissionFactor = material.transmission;
|
|
1534
1638
|
if (material.transmissionMap) {
|
|
1535
|
-
const transmissionMapDef = {
|
|
1639
|
+
const transmissionMapDef = {
|
|
1640
|
+
index: writer.processTexture(material.transmissionMap),
|
|
1641
|
+
texCoord: material.transmissionMap.channel
|
|
1642
|
+
};
|
|
1536
1643
|
writer.applyTextureTransform(transmissionMapDef, material.transmissionMap);
|
|
1537
1644
|
extensionDef.transmissionTexture = transmissionMapDef;
|
|
1538
1645
|
}
|
|
@@ -1543,33 +1650,257 @@ class GLTFMaterialsTransmissionExtension {
|
|
|
1543
1650
|
}
|
|
1544
1651
|
class GLTFMaterialsVolumeExtension {
|
|
1545
1652
|
constructor(writer) {
|
|
1546
|
-
__publicField(this, "writer");
|
|
1547
|
-
__publicField(this, "name");
|
|
1548
1653
|
this.writer = writer;
|
|
1549
1654
|
this.name = "KHR_materials_volume";
|
|
1550
1655
|
}
|
|
1551
1656
|
writeMaterial(material, materialDef) {
|
|
1552
|
-
if (!
|
|
1553
|
-
material.isMeshPhysicalMaterial) || material.thickness === 0) {
|
|
1657
|
+
if (!material.isMeshPhysicalMaterial || material.transmission === 0)
|
|
1554
1658
|
return;
|
|
1555
|
-
}
|
|
1556
1659
|
const writer = this.writer;
|
|
1557
1660
|
const extensionsUsed = writer.extensionsUsed;
|
|
1558
1661
|
const extensionDef = {};
|
|
1559
|
-
extensionDef.
|
|
1662
|
+
extensionDef.thicknessFactor = material.thickness;
|
|
1560
1663
|
if (material.thicknessMap) {
|
|
1561
1664
|
const thicknessMapDef = {
|
|
1562
|
-
index: writer.processTexture(material.thicknessMap)
|
|
1665
|
+
index: writer.processTexture(material.thicknessMap),
|
|
1666
|
+
texCoord: material.thicknessMap.channel
|
|
1563
1667
|
};
|
|
1564
1668
|
writer.applyTextureTransform(thicknessMapDef, material.thicknessMap);
|
|
1565
1669
|
extensionDef.thicknessTexture = thicknessMapDef;
|
|
1566
1670
|
}
|
|
1567
1671
|
extensionDef.attenuationDistance = material.attenuationDistance;
|
|
1568
|
-
extensionDef.attenuationColor =
|
|
1569
|
-
material.attenuationTint.toArray();
|
|
1672
|
+
extensionDef.attenuationColor = material.attenuationColor.toArray();
|
|
1570
1673
|
materialDef.extensions = materialDef.extensions || {};
|
|
1571
1674
|
materialDef.extensions[this.name] = extensionDef;
|
|
1572
1675
|
extensionsUsed[this.name] = true;
|
|
1573
1676
|
}
|
|
1574
1677
|
}
|
|
1678
|
+
class GLTFMaterialsIorExtension {
|
|
1679
|
+
constructor(writer) {
|
|
1680
|
+
this.writer = writer;
|
|
1681
|
+
this.name = "KHR_materials_ior";
|
|
1682
|
+
}
|
|
1683
|
+
writeMaterial(material, materialDef) {
|
|
1684
|
+
if (!material.isMeshPhysicalMaterial || material.ior === 1.5)
|
|
1685
|
+
return;
|
|
1686
|
+
const writer = this.writer;
|
|
1687
|
+
const extensionsUsed = writer.extensionsUsed;
|
|
1688
|
+
const extensionDef = {};
|
|
1689
|
+
extensionDef.ior = material.ior;
|
|
1690
|
+
materialDef.extensions = materialDef.extensions || {};
|
|
1691
|
+
materialDef.extensions[this.name] = extensionDef;
|
|
1692
|
+
extensionsUsed[this.name] = true;
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
class GLTFMaterialsSpecularExtension {
|
|
1696
|
+
constructor(writer) {
|
|
1697
|
+
this.writer = writer;
|
|
1698
|
+
this.name = "KHR_materials_specular";
|
|
1699
|
+
}
|
|
1700
|
+
writeMaterial(material, materialDef) {
|
|
1701
|
+
if (!material.isMeshPhysicalMaterial || material.specularIntensity === 1 && material.specularColor.equals(DEFAULT_SPECULAR_COLOR) && !material.specularIntensityMap && !material.specularColorTexture)
|
|
1702
|
+
return;
|
|
1703
|
+
const writer = this.writer;
|
|
1704
|
+
const extensionsUsed = writer.extensionsUsed;
|
|
1705
|
+
const extensionDef = {};
|
|
1706
|
+
if (material.specularIntensityMap) {
|
|
1707
|
+
const specularIntensityMapDef = {
|
|
1708
|
+
index: writer.processTexture(material.specularIntensityMap),
|
|
1709
|
+
texCoord: material.specularIntensityMap.channel
|
|
1710
|
+
};
|
|
1711
|
+
writer.applyTextureTransform(specularIntensityMapDef, material.specularIntensityMap);
|
|
1712
|
+
extensionDef.specularTexture = specularIntensityMapDef;
|
|
1713
|
+
}
|
|
1714
|
+
if (material.specularColorMap) {
|
|
1715
|
+
const specularColorMapDef = {
|
|
1716
|
+
index: writer.processTexture(material.specularColorMap),
|
|
1717
|
+
texCoord: material.specularColorMap.channel
|
|
1718
|
+
};
|
|
1719
|
+
writer.applyTextureTransform(specularColorMapDef, material.specularColorMap);
|
|
1720
|
+
extensionDef.specularColorTexture = specularColorMapDef;
|
|
1721
|
+
}
|
|
1722
|
+
extensionDef.specularFactor = material.specularIntensity;
|
|
1723
|
+
extensionDef.specularColorFactor = material.specularColor.toArray();
|
|
1724
|
+
materialDef.extensions = materialDef.extensions || {};
|
|
1725
|
+
materialDef.extensions[this.name] = extensionDef;
|
|
1726
|
+
extensionsUsed[this.name] = true;
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
class GLTFMaterialsSheenExtension {
|
|
1730
|
+
constructor(writer) {
|
|
1731
|
+
this.writer = writer;
|
|
1732
|
+
this.name = "KHR_materials_sheen";
|
|
1733
|
+
}
|
|
1734
|
+
writeMaterial(material, materialDef) {
|
|
1735
|
+
if (!material.isMeshPhysicalMaterial || material.sheen == 0)
|
|
1736
|
+
return;
|
|
1737
|
+
const writer = this.writer;
|
|
1738
|
+
const extensionsUsed = writer.extensionsUsed;
|
|
1739
|
+
const extensionDef = {};
|
|
1740
|
+
if (material.sheenRoughnessMap) {
|
|
1741
|
+
const sheenRoughnessMapDef = {
|
|
1742
|
+
index: writer.processTexture(material.sheenRoughnessMap),
|
|
1743
|
+
texCoord: material.sheenRoughnessMap.channel
|
|
1744
|
+
};
|
|
1745
|
+
writer.applyTextureTransform(sheenRoughnessMapDef, material.sheenRoughnessMap);
|
|
1746
|
+
extensionDef.sheenRoughnessTexture = sheenRoughnessMapDef;
|
|
1747
|
+
}
|
|
1748
|
+
if (material.sheenColorMap) {
|
|
1749
|
+
const sheenColorMapDef = {
|
|
1750
|
+
index: writer.processTexture(material.sheenColorMap),
|
|
1751
|
+
texCoord: material.sheenColorMap.channel
|
|
1752
|
+
};
|
|
1753
|
+
writer.applyTextureTransform(sheenColorMapDef, material.sheenColorMap);
|
|
1754
|
+
extensionDef.sheenColorTexture = sheenColorMapDef;
|
|
1755
|
+
}
|
|
1756
|
+
extensionDef.sheenRoughnessFactor = material.sheenRoughness;
|
|
1757
|
+
extensionDef.sheenColorFactor = material.sheenColor.toArray();
|
|
1758
|
+
materialDef.extensions = materialDef.extensions || {};
|
|
1759
|
+
materialDef.extensions[this.name] = extensionDef;
|
|
1760
|
+
extensionsUsed[this.name] = true;
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
class GLTFMaterialsAnisotropyExtension {
|
|
1764
|
+
constructor(writer) {
|
|
1765
|
+
this.writer = writer;
|
|
1766
|
+
this.name = "KHR_materials_anisotropy";
|
|
1767
|
+
}
|
|
1768
|
+
writeMaterial(material, materialDef) {
|
|
1769
|
+
if (!material.isMeshPhysicalMaterial || material.anisotropy == 0)
|
|
1770
|
+
return;
|
|
1771
|
+
const writer = this.writer;
|
|
1772
|
+
const extensionsUsed = writer.extensionsUsed;
|
|
1773
|
+
const extensionDef = {};
|
|
1774
|
+
if (material.anisotropyMap) {
|
|
1775
|
+
const anisotropyMapDef = { index: writer.processTexture(material.anisotropyMap) };
|
|
1776
|
+
writer.applyTextureTransform(anisotropyMapDef, material.anisotropyMap);
|
|
1777
|
+
extensionDef.anisotropyTexture = anisotropyMapDef;
|
|
1778
|
+
}
|
|
1779
|
+
extensionDef.anisotropyStrength = material.anisotropy;
|
|
1780
|
+
extensionDef.anisotropyRotation = material.anisotropyRotation;
|
|
1781
|
+
materialDef.extensions = materialDef.extensions || {};
|
|
1782
|
+
materialDef.extensions[this.name] = extensionDef;
|
|
1783
|
+
extensionsUsed[this.name] = true;
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
class GLTFMaterialsEmissiveStrengthExtension {
|
|
1787
|
+
constructor(writer) {
|
|
1788
|
+
this.writer = writer;
|
|
1789
|
+
this.name = "KHR_materials_emissive_strength";
|
|
1790
|
+
}
|
|
1791
|
+
writeMaterial(material, materialDef) {
|
|
1792
|
+
if (!material.isMeshStandardMaterial || material.emissiveIntensity === 1)
|
|
1793
|
+
return;
|
|
1794
|
+
const writer = this.writer;
|
|
1795
|
+
const extensionsUsed = writer.extensionsUsed;
|
|
1796
|
+
const extensionDef = {};
|
|
1797
|
+
extensionDef.emissiveStrength = material.emissiveIntensity;
|
|
1798
|
+
materialDef.extensions = materialDef.extensions || {};
|
|
1799
|
+
materialDef.extensions[this.name] = extensionDef;
|
|
1800
|
+
extensionsUsed[this.name] = true;
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
GLTFExporter.Utils = {
|
|
1804
|
+
insertKeyframe: function(track, time) {
|
|
1805
|
+
const tolerance = 1e-3;
|
|
1806
|
+
const valueSize = track.getValueSize();
|
|
1807
|
+
const times = new track.TimeBufferType(track.times.length + 1);
|
|
1808
|
+
const values = new track.ValueBufferType(track.values.length + valueSize);
|
|
1809
|
+
const interpolant = track.createInterpolant(new track.ValueBufferType(valueSize));
|
|
1810
|
+
let index;
|
|
1811
|
+
if (track.times.length === 0) {
|
|
1812
|
+
times[0] = time;
|
|
1813
|
+
for (let i = 0; i < valueSize; i++) {
|
|
1814
|
+
values[i] = 0;
|
|
1815
|
+
}
|
|
1816
|
+
index = 0;
|
|
1817
|
+
} else if (time < track.times[0]) {
|
|
1818
|
+
if (Math.abs(track.times[0] - time) < tolerance)
|
|
1819
|
+
return 0;
|
|
1820
|
+
times[0] = time;
|
|
1821
|
+
times.set(track.times, 1);
|
|
1822
|
+
values.set(interpolant.evaluate(time), 0);
|
|
1823
|
+
values.set(track.values, valueSize);
|
|
1824
|
+
index = 0;
|
|
1825
|
+
} else if (time > track.times[track.times.length - 1]) {
|
|
1826
|
+
if (Math.abs(track.times[track.times.length - 1] - time) < tolerance) {
|
|
1827
|
+
return track.times.length - 1;
|
|
1828
|
+
}
|
|
1829
|
+
times[times.length - 1] = time;
|
|
1830
|
+
times.set(track.times, 0);
|
|
1831
|
+
values.set(track.values, 0);
|
|
1832
|
+
values.set(interpolant.evaluate(time), track.values.length);
|
|
1833
|
+
index = times.length - 1;
|
|
1834
|
+
} else {
|
|
1835
|
+
for (let i = 0; i < track.times.length; i++) {
|
|
1836
|
+
if (Math.abs(track.times[i] - time) < tolerance)
|
|
1837
|
+
return i;
|
|
1838
|
+
if (track.times[i] < time && track.times[i + 1] > time) {
|
|
1839
|
+
times.set(track.times.slice(0, i + 1), 0);
|
|
1840
|
+
times[i + 1] = time;
|
|
1841
|
+
times.set(track.times.slice(i + 1), i + 2);
|
|
1842
|
+
values.set(track.values.slice(0, (i + 1) * valueSize), 0);
|
|
1843
|
+
values.set(interpolant.evaluate(time), (i + 1) * valueSize);
|
|
1844
|
+
values.set(track.values.slice((i + 1) * valueSize), (i + 2) * valueSize);
|
|
1845
|
+
index = i + 1;
|
|
1846
|
+
break;
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
track.times = times;
|
|
1851
|
+
track.values = values;
|
|
1852
|
+
return index;
|
|
1853
|
+
},
|
|
1854
|
+
mergeMorphTargetTracks: function(clip, root) {
|
|
1855
|
+
const tracks = [];
|
|
1856
|
+
const mergedTracks = {};
|
|
1857
|
+
const sourceTracks = clip.tracks;
|
|
1858
|
+
for (let i = 0; i < sourceTracks.length; ++i) {
|
|
1859
|
+
let sourceTrack = sourceTracks[i];
|
|
1860
|
+
const sourceTrackBinding = THREE.PropertyBinding.parseTrackName(sourceTrack.name);
|
|
1861
|
+
const sourceTrackNode = THREE.PropertyBinding.findNode(root, sourceTrackBinding.nodeName);
|
|
1862
|
+
if (sourceTrackBinding.propertyName !== "morphTargetInfluences" || sourceTrackBinding.propertyIndex === void 0) {
|
|
1863
|
+
tracks.push(sourceTrack);
|
|
1864
|
+
continue;
|
|
1865
|
+
}
|
|
1866
|
+
if (sourceTrack.createInterpolant !== sourceTrack.InterpolantFactoryMethodDiscrete && sourceTrack.createInterpolant !== sourceTrack.InterpolantFactoryMethodLinear) {
|
|
1867
|
+
if (sourceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
|
|
1868
|
+
throw new Error("THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.");
|
|
1869
|
+
}
|
|
1870
|
+
console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead.");
|
|
1871
|
+
sourceTrack = sourceTrack.clone();
|
|
1872
|
+
sourceTrack.setInterpolation(THREE.InterpolateLinear);
|
|
1873
|
+
}
|
|
1874
|
+
const targetCount = sourceTrackNode.morphTargetInfluences.length;
|
|
1875
|
+
const targetIndex = sourceTrackNode.morphTargetDictionary[sourceTrackBinding.propertyIndex];
|
|
1876
|
+
if (targetIndex === void 0) {
|
|
1877
|
+
throw new Error("THREE.GLTFExporter: Morph target name not found: " + sourceTrackBinding.propertyIndex);
|
|
1878
|
+
}
|
|
1879
|
+
let mergedTrack;
|
|
1880
|
+
if (mergedTracks[sourceTrackNode.uuid] === void 0) {
|
|
1881
|
+
mergedTrack = sourceTrack.clone();
|
|
1882
|
+
const values = new mergedTrack.ValueBufferType(targetCount * mergedTrack.times.length);
|
|
1883
|
+
for (let j = 0; j < mergedTrack.times.length; j++) {
|
|
1884
|
+
values[j * targetCount + targetIndex] = mergedTrack.values[j];
|
|
1885
|
+
}
|
|
1886
|
+
mergedTrack.name = (sourceTrackBinding.nodeName || "") + ".morphTargetInfluences";
|
|
1887
|
+
mergedTrack.values = values;
|
|
1888
|
+
mergedTracks[sourceTrackNode.uuid] = mergedTrack;
|
|
1889
|
+
tracks.push(mergedTrack);
|
|
1890
|
+
continue;
|
|
1891
|
+
}
|
|
1892
|
+
const sourceInterpolant = sourceTrack.createInterpolant(new sourceTrack.ValueBufferType(1));
|
|
1893
|
+
mergedTrack = mergedTracks[sourceTrackNode.uuid];
|
|
1894
|
+
for (let j = 0; j < mergedTrack.times.length; j++) {
|
|
1895
|
+
mergedTrack.values[j * targetCount + targetIndex] = sourceInterpolant.evaluate(mergedTrack.times[j]);
|
|
1896
|
+
}
|
|
1897
|
+
for (let j = 0; j < sourceTrack.times.length; j++) {
|
|
1898
|
+
const keyframeIndex = this.insertKeyframe(mergedTrack, sourceTrack.times[j]);
|
|
1899
|
+
mergedTrack.values[keyframeIndex * targetCount + targetIndex] = sourceTrack.values[j];
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
clip.tracks = tracks;
|
|
1903
|
+
return clip;
|
|
1904
|
+
}
|
|
1905
|
+
};
|
|
1575
1906
|
exports.GLTFExporter = GLTFExporter;
|