super-three 0.141.0 → 0.147.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -9
- package/build/three.cjs +2441 -1569
- package/build/three.js +2441 -1569
- package/build/three.min.js +1 -1
- package/build/three.module.js +2847 -1576
- package/examples/js/animation/AnimationClipCreator.js +0 -8
- package/examples/js/animation/CCDIKSolver.js +50 -67
- package/examples/js/animation/MMDAnimationHelper.js +66 -137
- package/examples/js/animation/MMDPhysics.js +71 -150
- package/examples/js/cameras/CinematicCamera.js +33 -22
- package/examples/js/controls/ArcballControls.js +149 -403
- package/examples/js/controls/DragControls.js +8 -33
- package/examples/js/controls/FirstPersonControls.js +32 -61
- package/examples/js/controls/FlyControls.js +29 -63
- package/examples/js/controls/OrbitControls.js +125 -103
- package/examples/js/controls/PointerLockControls.js +5 -22
- package/examples/js/controls/TrackballControls.js +33 -88
- package/examples/js/controls/TransformControls.js +101 -182
- package/examples/js/csm/CSM.js +4 -39
- package/examples/js/csm/CSMFrustum.js +3 -9
- package/examples/js/csm/CSMHelper.js +24 -4
- package/examples/js/csm/CSMShader.js +2 -6
- package/examples/js/curves/CurveExtras.js +27 -27
- package/examples/js/curves/NURBSCurve.js +4 -16
- package/examples/js/curves/NURBSSurface.js +3 -9
- package/examples/js/curves/NURBSUtils.js +8 -45
- package/examples/js/effects/AnaglyphEffect.js +6 -20
- package/examples/js/effects/AsciiEffect.js +32 -31
- package/examples/js/effects/OutlineEffect.js +30 -54
- package/examples/js/effects/ParallaxBarrierEffect.js +2 -15
- package/examples/js/effects/PeppersGhostEffect.js +14 -41
- package/examples/js/effects/StereoEffect.js +2 -6
- package/examples/js/environments/RoomEnvironment.js +32 -8
- package/examples/js/exporters/ColladaExporter.js +52 -78
- package/examples/js/exporters/DRACOExporter.js +22 -34
- package/examples/js/exporters/EXRExporter.js +15 -18
- package/examples/js/exporters/GLTFExporter.js +168 -345
- package/examples/js/exporters/MMDExporter.js +5 -12
- package/examples/js/exporters/OBJExporter.js +40 -52
- package/examples/js/exporters/PLYExporter.js +50 -57
- package/examples/js/exporters/STLExporter.js +5 -14
- package/examples/js/exporters/USDZExporter.js +119 -27
- package/examples/js/geometries/BoxLineGeometry.js +0 -1
- package/examples/js/geometries/ConvexGeometry.js +12 -7
- package/examples/js/geometries/DecalGeometry.js +53 -20
- package/examples/js/geometries/LightningStrike.js +54 -67
- package/examples/js/geometries/ParametricGeometries.js +8 -7
- package/examples/js/geometries/ParametricGeometry.js +23 -17
- package/examples/js/geometries/RoundedBoxGeometry.js +21 -19
- package/examples/js/geometries/TeapotGeometry.js +54 -50
- package/examples/js/geometries/TextGeometry.js +6 -4
- package/examples/js/helpers/LightProbeHelper.js +1 -2
- package/examples/js/helpers/OctreeHelper.js +22 -20
- package/examples/js/helpers/PositionalAudioHelper.js +8 -6
- package/examples/js/helpers/RectAreaLightHelper.js +6 -7
- package/examples/js/helpers/VertexNormalsHelper.js +15 -13
- package/examples/js/helpers/VertexTangentsHelper.js +15 -9
- package/examples/js/helpers/ViewHelper.js +31 -16
- package/examples/js/interactive/HTMLMesh.js +25 -39
- package/examples/js/interactive/InteractiveGroup.js +9 -14
- package/examples/js/interactive/SelectionBox.js +3 -70
- package/examples/js/interactive/SelectionHelper.js +2 -8
- package/examples/js/libs/ktx-parse.umd.js +1 -0
- package/examples/js/libs/meshopt_decoder.js +98 -32
- package/examples/js/lights/LightProbeGenerator.js +32 -39
- package/examples/js/lights/RectAreaLightUniformsLib.js +5 -1
- package/examples/js/lines/LineGeometry.js +3 -5
- package/examples/js/lines/LineMaterial.js +4 -11
- package/examples/js/lines/LineSegments2.js +40 -89
- package/examples/js/lines/LineSegmentsGeometry.js +7 -28
- package/examples/js/lines/Wireframe.js +2 -7
- package/examples/js/lines/WireframeGeometry2.js +3 -1
- package/examples/js/loaders/3DMLoader.js +58 -155
- package/examples/js/loaders/3MFLoader.js +72 -106
- package/examples/js/loaders/AMFLoader.js +0 -25
- package/examples/js/loaders/BVHLoader.js +44 -43
- package/examples/js/loaders/BasisTextureLoader.js +16 -46
- package/examples/js/loaders/ColladaLoader.js +229 -359
- package/examples/js/loaders/DDSLoader.js +24 -25
- package/examples/js/loaders/DRACOLoader.js +30 -90
- package/examples/js/loaders/EXRLoader.js +69 -177
- package/examples/js/loaders/FBXLoader.js +294 -441
- package/examples/js/loaders/FontLoader.js +9 -31
- package/examples/js/loaders/GCodeLoader.js +15 -16
- package/examples/js/loaders/GLTFLoader.js +458 -739
- package/examples/js/loaders/HDRCubeTextureLoader.js +0 -17
- package/examples/js/loaders/KMZLoader.js +3 -7
- package/examples/js/loaders/KTXLoader.js +12 -30
- package/examples/js/loaders/LDrawLoader.js +309 -355
- package/examples/js/loaders/LUT3dlLoader.js +7 -11
- package/examples/js/loaders/LUTCubeLoader.js +0 -8
- package/examples/js/loaders/LWOLoader.js +59 -124
- package/examples/js/loaders/LogLuvLoader.js +27 -77
- package/examples/js/loaders/LottieLoader.js +4 -4
- package/examples/js/loaders/MD2Loader.js +26 -27
- package/examples/js/loaders/MDDLoader.js +6 -10
- package/examples/js/loaders/MMDLoader.js +180 -189
- package/examples/js/loaders/MTLLoader.js +18 -47
- package/examples/js/loaders/NRRDLoader.js +44 -84
- package/examples/js/loaders/OBJLoader.js +56 -77
- package/examples/js/loaders/PCDLoader.js +92 -42
- package/examples/js/loaders/PDBLoader.js +17 -13
- package/examples/js/loaders/PLYLoader.js +65 -51
- package/examples/js/loaders/PRWMLoader.js +11 -22
- package/examples/js/loaders/PVRLoader.js +7 -16
- package/examples/js/loaders/RGBELoader.js +36 -61
- package/examples/js/loaders/RGBMLoader.js +26 -87
- package/examples/js/loaders/STLLoader.js +20 -27
- package/examples/js/loaders/SVGLoader.js +365 -236
- package/examples/js/loaders/TDSLoader.js +81 -118
- package/examples/js/loaders/TGALoader.js +39 -41
- package/examples/js/loaders/TIFFLoader.js +30 -0
- package/examples/js/loaders/TTFLoader.js +0 -8
- package/examples/js/loaders/TiltLoader.js +14 -15
- package/examples/js/loaders/VOXLoader.js +8 -16
- package/examples/js/loaders/VRMLLoader.js +266 -354
- package/examples/js/loaders/VTKLoader.js +102 -119
- package/examples/js/loaders/XYZLoader.js +2 -4
- package/examples/js/loaders/lwo/IFFParser.js +55 -136
- package/examples/js/loaders/lwo/LWO2Parser.js +39 -89
- package/examples/js/loaders/lwo/LWO3Parser.js +38 -79
- package/examples/js/materials/MeshGouraudMaterial.js +387 -0
- package/examples/js/math/Capsule.js +0 -17
- package/examples/js/math/ColorConverter.js +3 -53
- package/examples/js/math/ConvexHull.js +185 -141
- package/examples/js/math/ImprovedNoise.js +1 -1
- package/examples/js/math/Lut.js +8 -15
- package/examples/js/math/MeshSurfaceSampler.js +6 -28
- package/examples/js/math/OBB.js +90 -49
- package/examples/js/math/Octree.js +2 -57
- package/examples/js/math/SimplexNoise.js +74 -88
- package/examples/js/misc/ConvexObjectBreaker.js +37 -48
- package/examples/js/misc/GPUComputationRenderer.js +47 -14
- package/examples/js/misc/Gyroscope.js +5 -9
- package/examples/js/misc/MD2Character.js +14 -23
- package/examples/js/misc/MD2CharacterComplex.js +73 -54
- package/examples/js/misc/MorphAnimMesh.js +0 -6
- package/examples/js/misc/MorphBlendMesh.js +3 -30
- package/examples/js/misc/ProgressiveLightMap.js +47 -43
- package/examples/js/misc/RollerCoaster.js +17 -24
- package/examples/js/misc/TubePainter.js +18 -12
- package/examples/js/misc/Volume.js +173 -194
- package/examples/js/misc/VolumeSlice.js +91 -99
- package/examples/js/modifiers/CurveModifier.js +19 -21
- package/examples/js/modifiers/EdgeSplitModifier.js +0 -30
- package/examples/js/modifiers/SimplifyModifier.js +57 -60
- package/examples/js/modifiers/TessellateModifier.js +2 -9
- package/examples/js/objects/GroundProjectedEnv.js +181 -0
- package/examples/js/objects/Lensflare.js +47 -38
- package/examples/js/objects/LightningStorm.js +10 -13
- package/examples/js/objects/MarchingCubes.js +80 -59
- package/examples/js/objects/Reflector.js +31 -22
- package/examples/js/objects/ReflectorForSSRPass.js +20 -25
- package/examples/js/objects/Refractor.js +61 -33
- package/examples/js/objects/ShadowMesh.js +6 -3
- package/examples/js/objects/Sky.js +2 -7
- package/examples/js/objects/Water.js +23 -18
- package/examples/js/objects/Water2.js +20 -19
- package/examples/js/physics/AmmoPhysics.js +23 -20
- package/examples/js/physics/OimoPhysics.js +19 -17
- package/examples/js/postprocessing/AdaptiveToneMappingPass.js +13 -20
- package/examples/js/postprocessing/AfterimagePass.js +19 -12
- package/examples/js/postprocessing/BloomPass.js +38 -17
- package/examples/js/postprocessing/BokehPass.js +29 -12
- package/examples/js/postprocessing/ClearPass.js +1 -6
- package/examples/js/postprocessing/CubeTexturePass.js +12 -9
- package/examples/js/postprocessing/DotScreenPass.js +7 -5
- package/examples/js/postprocessing/EffectComposer.js +25 -32
- package/examples/js/postprocessing/FilmPass.js +7 -5
- package/examples/js/postprocessing/GlitchPass.js +10 -11
- package/examples/js/postprocessing/HalftonePass.js +9 -9
- package/examples/js/postprocessing/LUTPass.js +2 -15
- package/examples/js/postprocessing/MaskPass.js +20 -17
- package/examples/js/postprocessing/OutlinePass.js +49 -38
- package/examples/js/postprocessing/Pass.js +11 -14
- package/examples/js/postprocessing/RenderPass.js +3 -7
- package/examples/js/postprocessing/RenderPixelatedPass.js +215 -0
- package/examples/js/postprocessing/SAOPass.js +40 -32
- package/examples/js/postprocessing/SMAAPass.js +34 -17
- package/examples/js/postprocessing/SSAARenderPass.js +14 -14
- package/examples/js/postprocessing/SSAOPass.js +56 -42
- package/examples/js/postprocessing/SSRPass.js +78 -61
- package/examples/js/postprocessing/SavePass.js +14 -6
- package/examples/js/postprocessing/ShaderPass.js +9 -8
- package/examples/js/postprocessing/TAARenderPass.js +11 -9
- package/examples/js/postprocessing/TexturePass.js +7 -4
- package/examples/js/postprocessing/UnrealBloomPass.js +43 -25
- package/examples/js/renderers/CSS2DRenderer.js +4 -23
- package/examples/js/renderers/CSS3DRenderer.js +5 -26
- package/examples/js/renderers/Projector.js +31 -108
- package/examples/js/renderers/SVGRenderer.js +4 -50
- package/examples/js/shaders/ACESFilmicToneMappingShader.js +3 -6
- package/examples/js/shaders/AfterimageShader.js +3 -6
- package/examples/js/shaders/BasicShader.js +3 -6
- package/examples/js/shaders/BleachBypassShader.js +3 -6
- package/examples/js/shaders/BlendShader.js +3 -6
- package/examples/js/shaders/BokehShader.js +3 -6
- package/examples/js/shaders/BokehShader2.js +4 -13
- package/examples/js/shaders/BrightnessContrastShader.js +3 -6
- package/examples/js/shaders/ColorCorrectionShader.js +2 -6
- package/examples/js/shaders/ColorifyShader.js +2 -6
- package/examples/js/shaders/ConvolutionShader.js +5 -10
- package/examples/js/shaders/CopyShader.js +3 -6
- package/examples/js/shaders/DOFMipMapShader.js +3 -6
- package/examples/js/shaders/DepthLimitedBlurShader.js +2 -9
- package/examples/js/shaders/DigitalGlitch.js +3 -6
- package/examples/js/shaders/DotScreenShader.js +2 -6
- package/examples/js/shaders/FXAAShader.js +1 -3
- package/examples/js/shaders/FilmShader.js +3 -6
- package/examples/js/shaders/FocusShader.js +3 -6
- package/examples/js/shaders/FreiChenShader.js +2 -6
- package/examples/js/shaders/GammaCorrectionShader.js +3 -6
- package/examples/js/shaders/GodRaysShader.js +11 -24
- package/examples/js/shaders/HalftoneShader.js +3 -6
- package/examples/js/shaders/HorizontalBlurShader.js +3 -6
- package/examples/js/shaders/HorizontalTiltShiftShader.js +3 -6
- package/examples/js/shaders/HueSaturationShader.js +3 -6
- package/examples/js/shaders/KaleidoShader.js +3 -6
- package/examples/js/shaders/LuminosityHighPassShader.js +2 -6
- package/examples/js/shaders/LuminosityShader.js +4 -7
- package/examples/js/shaders/MMDToonShader.js +2 -4
- package/examples/js/shaders/MirrorShader.js +3 -6
- package/examples/js/shaders/NormalMapShader.js +2 -6
- package/examples/js/shaders/RGBShiftShader.js +3 -6
- package/examples/js/shaders/SAOShader.js +2 -6
- package/examples/js/shaders/SMAAShader.js +6 -18
- package/examples/js/shaders/SSAOShader.js +2 -6
- package/examples/js/shaders/SSRShader.js +6 -18
- package/examples/js/shaders/SepiaShader.js +3 -6
- package/examples/js/shaders/SobelOperatorShader.js +2 -6
- package/examples/js/shaders/TechnicolorShader.js +3 -6
- package/examples/js/shaders/ToneMapShader.js +4 -7
- package/examples/js/shaders/ToonShader.js +8 -24
- package/examples/js/shaders/TriangleBlurShader.js +2 -6
- package/examples/js/shaders/UnpackDepthRGBAShader.js +3 -6
- package/examples/js/shaders/VelocityShader.js +126 -0
- package/examples/js/shaders/VerticalBlurShader.js +3 -6
- package/examples/js/shaders/VerticalTiltShiftShader.js +3 -6
- package/examples/js/shaders/VignetteShader.js +3 -6
- package/examples/js/shaders/VolumeShader.js +2 -6
- package/examples/js/shaders/WaterRefractionShader.js +2 -6
- package/examples/js/textures/FlakesTexture.js +0 -1
- package/examples/js/utils/BufferGeometryUtils.js +237 -171
- package/examples/js/utils/CameraUtils.js +5 -20
- package/examples/js/utils/GPUStatsPanel.js +3 -12
- package/examples/js/utils/GeometryCompressionUtils.js +19 -44
- package/examples/js/utils/GeometryUtils.js +15 -36
- package/examples/js/utils/LDrawUtils.js +8 -11
- package/examples/js/utils/PackedPhongMaterial.js +6 -4
- package/examples/js/utils/SceneUtils.js +109 -14
- package/examples/js/utils/ShadowMapViewer.js +17 -14
- package/examples/js/utils/SkeletonUtils.js +13 -27
- package/examples/js/utils/UVsDebug.js +20 -12
- package/examples/js/utils/WorkerPool.js +1 -11
- package/examples/jsm/animation/CCDIKSolver.js +27 -3
- package/examples/jsm/animation/MMDPhysics.js +28 -22
- package/examples/jsm/capabilities/WebGPU.js +3 -1
- package/examples/jsm/controls/ArcballControls.js +17 -2
- package/examples/jsm/controls/FirstPersonControls.js +20 -27
- package/examples/jsm/controls/FlyControls.js +16 -24
- package/examples/jsm/controls/OrbitControls.js +44 -9
- package/examples/jsm/controls/PointerLockControls.js +0 -7
- package/examples/jsm/controls/TrackballControls.js +14 -5
- package/examples/jsm/controls/TransformControls.js +18 -16
- package/examples/jsm/csm/CSM.js +1 -0
- package/examples/jsm/csm/CSMHelper.js +30 -0
- package/examples/jsm/effects/AnaglyphEffect.js +2 -2
- package/examples/jsm/effects/OutlineEffect.js +4 -25
- package/examples/jsm/effects/ParallaxBarrierEffect.js +2 -2
- package/examples/jsm/effects/PeppersGhostEffect.js +2 -2
- package/examples/jsm/effects/StereoEffect.js +2 -2
- package/examples/jsm/environments/RoomEnvironment.js +23 -0
- package/examples/jsm/exporters/ColladaExporter.js +4 -13
- package/examples/jsm/exporters/DRACOExporter.js +0 -13
- package/examples/jsm/exporters/GLTFExporter.js +29 -110
- package/examples/jsm/exporters/KTX2Exporter.js +29 -29
- package/examples/jsm/exporters/OBJExporter.js +0 -18
- package/examples/jsm/exporters/PLYExporter.js +14 -22
- package/examples/jsm/exporters/STLExporter.js +1 -9
- package/examples/jsm/exporters/USDZExporter.js +107 -4
- package/examples/jsm/geometries/ConvexGeometry.js +1 -1
- package/examples/jsm/geometries/ParametricGeometry.js +0 -6
- package/examples/jsm/helpers/OctreeHelper.js +22 -8
- package/examples/jsm/helpers/VertexNormalsHelper.js +7 -1
- package/examples/jsm/helpers/VertexTangentsHelper.js +7 -0
- package/examples/jsm/helpers/ViewHelper.js +24 -0
- package/examples/jsm/interactive/HTMLMesh.js +14 -15
- package/examples/jsm/interactive/InteractiveGroup.js +4 -2
- package/examples/jsm/interactive/SelectionHelper.js +5 -3
- package/examples/jsm/libs/flow.module.js +610 -160
- package/examples/jsm/libs/lottie_canvas.module.js +14844 -0
- package/examples/jsm/libs/meshopt_decoder.module.js +97 -32
- package/examples/jsm/libs/utif.module.js +1579 -0
- package/examples/jsm/libs/zstddec.module.js +1 -0
- package/examples/jsm/lines/LineSegments2.js +4 -0
- package/examples/jsm/loaders/3DMLoader.js +1 -2
- package/examples/jsm/loaders/ColladaLoader.js +29 -0
- package/examples/jsm/loaders/DRACOLoader.js +2 -28
- package/examples/jsm/loaders/EXRLoader.js +3 -13
- package/examples/jsm/loaders/FBXLoader.js +26 -3
- package/examples/jsm/loaders/FontLoader.js +3 -16
- package/examples/jsm/loaders/GLTFLoader.js +321 -464
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +0 -13
- package/examples/jsm/loaders/KTX2Loader.js +254 -53
- package/examples/jsm/loaders/LDrawLoader.js +149 -87
- package/examples/jsm/loaders/LottieLoader.js +4 -2
- package/examples/jsm/loaders/MaterialXLoader.js +728 -0
- package/examples/jsm/loaders/OBJLoader.js +6 -14
- package/examples/jsm/loaders/PCDLoader.js +60 -14
- package/examples/jsm/loaders/PLYLoader.js +71 -19
- package/examples/jsm/loaders/RGBELoader.js +1 -1
- package/examples/jsm/loaders/SVGLoader.js +231 -17
- package/examples/jsm/loaders/TIFFLoader.js +36 -0
- package/examples/jsm/loaders/USDZLoader.js +633 -0
- package/examples/jsm/loaders/VRMLLoader.js +36 -26
- package/examples/jsm/loaders/VTKLoader.js +1 -1
- package/examples/jsm/loaders/lwo/LWO2Parser.js +6 -8
- package/examples/jsm/loaders/lwo/LWO3Parser.js +6 -8
- package/examples/jsm/materials/MeshGouraudMaterial.js +423 -0
- package/examples/jsm/math/ColorConverter.js +1 -49
- package/examples/jsm/math/ConvexHull.js +4 -4
- package/examples/jsm/math/Octree.js +1 -1
- package/examples/jsm/misc/GPUComputationRenderer.js +43 -0
- package/examples/jsm/misc/Volume.js +169 -171
- package/examples/jsm/misc/VolumeSlice.js +78 -80
- package/examples/jsm/modifiers/SimplifyModifier.js +1 -1
- package/examples/jsm/node-editor/NodeEditor.js +91 -12
- package/examples/jsm/node-editor/accessors/MatcapUVEditor.js +1 -1
- package/examples/jsm/node-editor/accessors/NormalEditor.js +1 -1
- package/examples/jsm/node-editor/accessors/PositionEditor.js +1 -1
- package/examples/jsm/node-editor/accessors/UVEditor.js +1 -1
- package/examples/jsm/node-editor/core/BaseNode.js +10 -3
- package/examples/jsm/node-editor/display/BlendEditor.js +1 -1
- package/examples/jsm/node-editor/display/NormalMapEditor.js +1 -1
- package/examples/jsm/node-editor/inputs/ColorEditor.js +1 -1
- package/examples/jsm/node-editor/inputs/FloatEditor.js +1 -1
- package/examples/jsm/node-editor/inputs/SliderEditor.js +1 -1
- package/examples/jsm/node-editor/inputs/TextureEditor.js +1 -1
- package/examples/jsm/node-editor/inputs/Vector2Editor.js +1 -1
- package/examples/jsm/node-editor/inputs/Vector3Editor.js +1 -1
- package/examples/jsm/node-editor/inputs/Vector4Editor.js +1 -1
- package/examples/jsm/node-editor/materials/BasicMaterialEditor.js +7 -10
- package/examples/jsm/node-editor/materials/PointsMaterialEditor.js +1 -1
- package/examples/jsm/node-editor/materials/StandardMaterialEditor.js +7 -10
- package/examples/jsm/node-editor/math/AngleEditor.js +4 -4
- package/examples/jsm/node-editor/math/DotEditor.js +1 -1
- package/examples/jsm/node-editor/math/InvertEditor.js +3 -3
- package/examples/jsm/node-editor/math/LimiterEditor.js +1 -1
- package/examples/jsm/node-editor/math/NormalizeEditor.js +1 -1
- package/examples/jsm/node-editor/math/OperatorEditor.js +1 -1
- package/examples/jsm/node-editor/math/PowerEditor.js +1 -1
- package/examples/jsm/node-editor/math/TrigonometryEditor.js +1 -1
- package/examples/jsm/node-editor/procedural/CheckerEditor.js +1 -1
- package/examples/jsm/node-editor/scene/MeshEditor.js +11 -8
- package/examples/jsm/node-editor/utils/JoinEditor.js +1 -1
- package/examples/jsm/node-editor/utils/OscillatorEditor.js +1 -1
- package/examples/jsm/node-editor/utils/PreviewEditor.js +7 -3
- package/examples/jsm/node-editor/utils/SplitEditor.js +1 -1
- package/examples/jsm/node-editor/utils/TimerEditor.js +1 -1
- package/examples/jsm/nodes/Nodes.js +70 -13
- package/examples/jsm/nodes/accessors/BitangentNode.js +62 -0
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +9 -5
- package/examples/jsm/nodes/accessors/NormalNode.js +8 -8
- package/examples/jsm/nodes/accessors/Object3DNode.js +1 -1
- package/examples/jsm/nodes/accessors/PositionNode.js +11 -5
- package/examples/jsm/nodes/accessors/ReferenceNode.js +1 -1
- package/examples/jsm/nodes/accessors/ReflectVectorNode.js +31 -0
- package/examples/jsm/nodes/accessors/SkinningNode.js +8 -1
- package/examples/jsm/nodes/accessors/TangentNode.js +95 -0
- package/examples/jsm/nodes/core/AttributeNode.js +32 -9
- package/examples/jsm/nodes/core/CodeNode.js +3 -3
- package/examples/jsm/nodes/core/FunctionCallNode.js +20 -5
- package/examples/jsm/nodes/core/FunctionNode.js +2 -2
- package/examples/jsm/nodes/core/Node.js +15 -13
- package/examples/jsm/nodes/core/NodeBuilder.js +67 -18
- package/examples/jsm/nodes/core/NodeFrame.js +2 -2
- package/examples/jsm/nodes/core/NodeUtils.js +23 -1
- package/examples/jsm/nodes/core/NodeVarying.js +17 -0
- package/examples/jsm/nodes/core/VaryingNode.js +56 -0
- package/examples/jsm/nodes/core/constants.js +13 -13
- package/examples/jsm/nodes/display/BlendModeNode.js +85 -0
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +84 -0
- package/examples/jsm/nodes/display/NormalMapNode.js +19 -12
- package/examples/jsm/nodes/display/PosterizeNode.js +25 -0
- package/examples/jsm/nodes/display/ViewportNode.js +106 -0
- package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +5 -5
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +3 -3
- package/examples/jsm/nodes/functions/light/getDistanceAttenuation.js +2 -2
- package/examples/jsm/nodes/geometry/RangeNode.js +109 -0
- package/examples/jsm/nodes/gpgpu/ComputeNode.js +3 -1
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +8 -7
- package/examples/jsm/nodes/lighting/LightingContextNode.js +4 -4
- package/examples/jsm/nodes/loaders/NodeLoader.js +2 -2
- package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +33 -0
- package/examples/jsm/nodes/materials/Materials.js +21 -31
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +70 -0
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +4 -7
- package/examples/jsm/nodes/materials/NodeMaterial.js +11 -3
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +28 -17
- package/examples/jsm/nodes/materialx/DISCLAIMER.md +199 -0
- package/examples/jsm/nodes/materialx/MaterialXNodes.js +59 -0
- package/examples/jsm/nodes/materialx/lib/mx_hsv.js +56 -0
- package/examples/jsm/nodes/materialx/lib/mx_noise.js +617 -0
- package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +18 -0
- package/examples/jsm/nodes/math/MathNode.js +7 -17
- package/examples/jsm/nodes/math/OperatorNode.js +16 -3
- package/examples/jsm/nodes/parsers/GLSLNodeFunction.js +21 -6
- package/examples/jsm/nodes/procedural/CheckerNode.js +2 -2
- package/examples/jsm/nodes/shadernode/ShaderNode.js +40 -25
- package/examples/jsm/nodes/shadernode/ShaderNodeBaseElements.js +95 -68
- package/examples/jsm/nodes/shadernode/ShaderNodeElements.js +49 -6
- package/examples/jsm/nodes/utils/ConvertNode.js +18 -12
- package/examples/jsm/nodes/utils/EquirectUVNode.js +27 -0
- package/examples/jsm/nodes/utils/JoinNode.js +15 -9
- package/examples/jsm/nodes/utils/MatcapUVNode.js +2 -4
- package/examples/jsm/nodes/utils/MaxMipLevelNode.js +3 -2
- package/examples/jsm/nodes/utils/OscNode.js +2 -2
- package/examples/jsm/nodes/utils/RemapNode.js +34 -0
- package/examples/jsm/nodes/utils/RotateUVNode.js +32 -0
- package/examples/jsm/nodes/utils/SplitNode.js +21 -5
- package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +8 -10
- package/examples/jsm/nodes/utils/TimerNode.js +23 -3
- package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +51 -0
- package/examples/jsm/objects/GroundProjectedEnv.js +186 -0
- package/examples/jsm/objects/Reflector.js +12 -5
- package/examples/jsm/objects/ReflectorForSSRPass.js +3 -5
- package/examples/jsm/objects/Refractor.js +12 -6
- package/examples/jsm/objects/ShadowMesh.js +8 -2
- package/examples/jsm/postprocessing/AfterimagePass.js +17 -4
- package/examples/jsm/postprocessing/BloomPass.js +22 -3
- package/examples/jsm/postprocessing/BokehPass.js +18 -4
- package/examples/jsm/postprocessing/CubeTexturePass.js +12 -5
- package/examples/jsm/postprocessing/DotScreenPass.js +8 -0
- package/examples/jsm/postprocessing/EffectComposer.js +9 -0
- package/examples/jsm/postprocessing/FilmPass.js +8 -0
- package/examples/jsm/postprocessing/GlitchPass.js +13 -1
- package/examples/jsm/postprocessing/HalftonePass.js +8 -0
- package/examples/jsm/postprocessing/OutlinePass.js +25 -3
- package/examples/jsm/postprocessing/Pass.js +2 -0
- package/examples/jsm/postprocessing/RenderPixelatedPass.js +234 -0
- package/examples/jsm/postprocessing/SAOPass.js +20 -0
- package/examples/jsm/postprocessing/SMAAPass.js +16 -0
- package/examples/jsm/postprocessing/SSAARenderPass.js +4 -0
- package/examples/jsm/postprocessing/SavePass.js +17 -1
- package/examples/jsm/postprocessing/ShaderPass.js +8 -0
- package/examples/jsm/postprocessing/TAARenderPass.js +9 -0
- package/examples/jsm/postprocessing/TexturePass.js +8 -0
- package/examples/jsm/postprocessing/UnrealBloomPass.js +16 -0
- package/examples/jsm/renderers/CSS2DRenderer.js +2 -2
- package/examples/jsm/renderers/CSS3DRenderer.js +2 -2
- package/examples/jsm/renderers/Projector.js +2 -24
- package/examples/jsm/renderers/webgl/nodes/SlotNode.js +9 -5
- package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +363 -231
- package/examples/jsm/renderers/webgl/nodes/WebGLNodes.js +7 -3
- package/examples/jsm/renderers/webgpu/WebGPUAnimation.js +58 -0
- package/examples/jsm/renderers/webgpu/WebGPUAttributes.js +63 -5
- package/examples/jsm/renderers/webgpu/WebGPUBackground.js +68 -3
- package/examples/jsm/renderers/webgpu/WebGPUComputePipelines.js +6 -0
- package/examples/jsm/renderers/webgpu/WebGPUGeometries.js +6 -0
- package/examples/jsm/renderers/webgpu/WebGPUObjects.js +1 -1
- package/examples/jsm/renderers/webgpu/WebGPURenderPipeline.js +17 -19
- package/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js +16 -14
- package/examples/jsm/renderers/webgpu/WebGPURenderStates.js +2 -2
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +113 -93
- package/examples/jsm/renderers/webgpu/WebGPUTextureUtils.js +5 -3
- package/examples/jsm/renderers/webgpu/WebGPUTextures.js +2 -2
- package/examples/jsm/renderers/webgpu/WebGPUUtils.js +81 -0
- package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js +63 -36
- package/examples/jsm/renderers/webgpu/nodes/WebGPUNodes.js +1 -1
- package/examples/jsm/shaders/LuminosityShader.js +1 -1
- package/examples/jsm/shaders/MMDToonShader.js +2 -4
- package/examples/jsm/shaders/ToneMapShader.js +1 -1
- package/examples/jsm/shaders/VelocityShader.js +128 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +176 -43
- package/examples/jsm/utils/GeometryUtils.js +17 -25
- package/examples/jsm/utils/PackedPhongMaterial.js +0 -1
- package/examples/jsm/utils/SceneUtils.js +117 -12
- package/examples/jsm/webxr/OculusHandModel.js +3 -2
- package/examples/jsm/webxr/OculusHandPointerModel.js +6 -1
- package/examples/jsm/webxr/VRButton.js +1 -7
- package/examples/jsm/webxr/XRHandMeshModel.js +8 -3
- package/package.json +22 -18
- package/src/Three.Legacy.js +262 -36
- package/src/Three.js +4 -2
- package/src/animation/AnimationAction.js +6 -5
- package/src/animation/AnimationClip.js +1 -1
- package/src/animation/AnimationMixer.js +1 -1
- package/src/animation/AnimationUtils.js +204 -199
- package/src/animation/KeyframeTrack.js +1 -1
- package/src/animation/PropertyBinding.js +31 -5
- package/src/audio/AudioContext.js +5 -5
- package/src/cameras/CubeCamera.js +14 -21
- package/src/constants.js +2 -4
- package/src/core/BufferAttribute.js +81 -111
- package/src/core/BufferGeometry.js +3 -41
- package/src/core/InstancedBufferAttribute.js +0 -10
- package/src/core/InstancedBufferGeometry.js +1 -7
- package/src/core/InterleavedBuffer.js +1 -1
- package/src/core/InterleavedBufferAttribute.js +57 -8
- package/src/core/Object3D.js +22 -5
- package/src/core/Uniform.js +0 -7
- package/src/core/UniformsGroup.js +92 -0
- package/src/extras/DataUtils.js +104 -88
- package/src/extras/Earcut.js +67 -67
- package/src/extras/core/Path.js +1 -0
- package/src/extras/core/ShapePath.js +1 -4
- package/src/extras/curves/CatmullRomCurve3.js +4 -2
- package/src/geometries/BoxGeometry.js +1 -1
- package/src/geometries/CapsuleGeometry.js +1 -1
- package/src/geometries/CircleGeometry.js +1 -1
- package/src/geometries/ConeGeometry.js +1 -1
- package/src/geometries/CylinderGeometry.js +2 -1
- package/src/geometries/DodecahedronGeometry.js +1 -1
- package/src/geometries/EdgesGeometry.js +5 -4
- package/src/geometries/ExtrudeGeometry.js +2 -11
- package/src/geometries/IcosahedronGeometry.js +1 -1
- package/src/geometries/LatheGeometry.js +2 -2
- package/src/geometries/OctahedronGeometry.js +1 -1
- package/src/geometries/PlaneGeometry.js +2 -1
- package/src/geometries/PolyhedronGeometry.js +2 -2
- package/src/geometries/RingGeometry.js +1 -1
- package/src/geometries/ShapeGeometry.js +3 -2
- package/src/geometries/SphereGeometry.js +2 -1
- package/src/geometries/TetrahedronGeometry.js +1 -1
- package/src/geometries/TorusGeometry.js +2 -1
- package/src/geometries/TorusKnotGeometry.js +2 -1
- package/src/geometries/TubeGeometry.js +2 -1
- package/src/geometries/WireframeGeometry.js +1 -0
- package/src/helpers/ArrowHelper.js +9 -0
- package/src/helpers/Box3Helper.js +7 -0
- package/src/helpers/BoxHelper.js +7 -1
- package/src/helpers/CameraHelper.js +97 -38
- package/src/helpers/DirectionalLightHelper.js +6 -1
- package/src/helpers/GridHelper.js +7 -0
- package/src/helpers/HemisphereLightHelper.js +5 -1
- package/src/helpers/PlaneHelper.js +15 -9
- package/src/helpers/PointLightHelper.js +2 -1
- package/src/helpers/PolarGridHelper.js +25 -14
- package/src/helpers/SkeletonHelper.js +7 -0
- package/src/helpers/SpotLightHelper.js +5 -2
- package/src/lights/LightShadow.js +1 -2
- package/src/lights/PointLight.js +2 -2
- package/src/lights/SpotLight.js +4 -2
- package/src/loaders/FileLoader.js +16 -2
- package/src/loaders/LoadingManager.js +1 -1
- package/src/loaders/MaterialLoader.js +49 -7
- package/src/loaders/ObjectLoader.js +9 -42
- package/src/materials/Material.js +2 -34
- package/src/materials/Materials.js +0 -27
- package/src/materials/MeshLambertMaterial.js +28 -1
- package/src/materials/MeshPhysicalMaterial.js +1 -1
- package/src/materials/ShaderMaterial.js +3 -7
- package/src/math/Color.js +8 -18
- package/src/math/MathUtils.js +1 -7
- package/src/math/Matrix3.js +54 -25
- package/src/math/Matrix4.js +3 -27
- package/src/math/Quaternion.js +1 -21
- package/src/math/Ray.js +2 -5
- package/src/math/Sphere.js +36 -21
- package/src/math/Vector2.js +4 -24
- package/src/math/Vector3.js +7 -46
- package/src/math/Vector4.js +4 -24
- package/src/objects/InstancedMesh.js +7 -0
- package/src/objects/LOD.js +25 -6
- package/src/renderers/WebGL3DRenderTarget.js +1 -1
- package/src/renderers/WebGLArrayRenderTarget.js +1 -1
- package/src/renderers/WebGLCubeRenderTarget.js +1 -1
- package/src/renderers/WebGLMultipleRenderTargets.js +1 -1
- package/src/renderers/WebGLRenderTarget.js +1 -1
- package/src/renderers/WebGLRenderer.js +119 -69
- package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +12 -12
- package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +3 -5
- package/src/renderers/shaders/ShaderChunk/common.glsl.js +6 -5
- package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +24 -24
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +0 -4
- package/src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/gradientmap_pars_fragment.glsl.js +2 -1
- package/src/renderers/shaders/ShaderChunk/iridescence_fragment.glsl.js +113 -99
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +34 -13
- package/src/renderers/shaders/ShaderChunk/lights_lambert_fragment.glsl.js +5 -0
- package/src/renderers/shaders/ShaderChunk/lights_lambert_pars_fragment.glsl.js +28 -0
- package/src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl.js +0 -2
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +3 -1
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +13 -1
- package/src/renderers/shaders/ShaderChunk/lights_toon_pars_fragment.glsl.js +0 -2
- package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +2 -4
- package/src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js +2 -4
- package/src/renderers/shaders/ShaderChunk/output_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +18 -7
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +8 -3
- package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +9 -6
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +14 -10
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk.js +7 -2
- package/src/renderers/shaders/ShaderLib/background.glsl.js +7 -2
- package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +62 -0
- package/src/renderers/shaders/ShaderLib/cube.glsl.js +4 -6
- package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +22 -50
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/vsm.glsl.js +0 -3
- package/src/renderers/shaders/ShaderLib.js +50 -36
- package/src/renderers/shaders/UniformsLib.js +13 -12
- package/src/renderers/shaders/UniformsUtils.js +29 -0
- package/src/renderers/webgl/WebGLAttributes.js +2 -0
- package/src/renderers/webgl/WebGLBackground.js +17 -9
- package/src/renderers/webgl/WebGLLights.js +37 -17
- package/src/renderers/webgl/WebGLMaterials.js +2 -1
- package/src/renderers/webgl/WebGLMorphtargets.js +0 -20
- package/src/renderers/webgl/WebGLProgram.js +6 -11
- package/src/renderers/webgl/WebGLPrograms.js +30 -26
- package/src/renderers/webgl/WebGLRenderLists.js +5 -4
- package/src/renderers/webgl/WebGLRenderStates.js +5 -4
- package/src/renderers/webgl/WebGLShaderCache.js +9 -6
- package/src/renderers/webgl/WebGLShadowMap.js +13 -16
- package/src/renderers/webgl/WebGLState.js +125 -41
- package/src/renderers/webgl/WebGLTextures.js +94 -39
- package/src/renderers/webgl/WebGLUniforms.js +156 -28
- package/src/renderers/webgl/WebGLUniformsGroups.js +372 -0
- package/src/renderers/webgl/WebGLUtils.js +3 -1
- package/src/renderers/webvr/WebVRManager.js +42 -9
- package/src/renderers/webvr/WebVRUtils.js +1 -1
- package/src/renderers/webxr/WebXRController.js +91 -50
- package/src/renderers/webxr/WebXRManager.js +127 -34
- package/src/scenes/Scene.js +24 -3
- package/src/textures/CompressedArrayTexture.js +18 -0
- package/src/textures/Source.js +1 -1
- package/src/textures/Texture.js +2 -1
- package/src/utils.js +1 -1
- package/examples/js/controls/experimental/CameraControls.js +0 -1048
- package/examples/js/libs/lottie_canvas.js +0 -12751
- package/examples/js/loaders/KTX2Loader.js +0 -558
- package/examples/js/shaders/PixelShader.js +0 -51
- package/examples/jsm/controls/experimental/CameraControls.js +0 -1248
- package/examples/jsm/nodes/accessors/ReflectNode.js +0 -70
- package/examples/jsm/nodes/core/NodeVary.js +0 -14
- package/examples/jsm/nodes/core/VaryNode.js +0 -54
- package/examples/jsm/package.json +0 -3
- package/examples/jsm/renderers/webgl/nodes/WebGLPhysicalContextNode.js +0 -45
- package/examples/jsm/shaders/PixelShader.js +0 -44
- package/src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl.js +0 -122
|
@@ -14,11 +14,6 @@
|
|
|
14
14
|
|
|
15
15
|
return new GLTFMaterialsUnlitExtension( writer );
|
|
16
16
|
|
|
17
|
-
} );
|
|
18
|
-
this.register( function ( writer ) {
|
|
19
|
-
|
|
20
|
-
return new GLTFMaterialsPBRSpecularGlossiness( writer );
|
|
21
|
-
|
|
22
17
|
} );
|
|
23
18
|
this.register( function ( writer ) {
|
|
24
19
|
|
|
@@ -42,7 +37,6 @@
|
|
|
42
37
|
} );
|
|
43
38
|
|
|
44
39
|
}
|
|
45
|
-
|
|
46
40
|
register( callback ) {
|
|
47
41
|
|
|
48
42
|
if ( this.pluginCallbacks.indexOf( callback ) === - 1 ) {
|
|
@@ -54,7 +48,6 @@
|
|
|
54
48
|
return this;
|
|
55
49
|
|
|
56
50
|
}
|
|
57
|
-
|
|
58
51
|
unregister( callback ) {
|
|
59
52
|
|
|
60
53
|
if ( this.pluginCallbacks.indexOf( callback ) !== - 1 ) {
|
|
@@ -66,6 +59,7 @@
|
|
|
66
59
|
return this;
|
|
67
60
|
|
|
68
61
|
}
|
|
62
|
+
|
|
69
63
|
/**
|
|
70
64
|
* Parse scenes and generate GLTF output
|
|
71
65
|
* @param {Scene or [THREE.Scenes]} input THREE.Scene or Array of THREE.Scenes
|
|
@@ -73,20 +67,10 @@
|
|
|
73
67
|
* @param {Function} onError Callback on errors
|
|
74
68
|
* @param {Object} options options
|
|
75
69
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
70
|
parse( input, onDone, onError, options ) {
|
|
79
71
|
|
|
80
|
-
if ( typeof onError === 'object' ) {
|
|
81
|
-
|
|
82
|
-
console.warn( 'THREE.GLTFExporter: parse() expects options as the fourth argument now.' );
|
|
83
|
-
options = onError;
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
72
|
const writer = new GLTFWriter();
|
|
88
73
|
const plugins = [];
|
|
89
|
-
|
|
90
74
|
for ( let i = 0, il = this.pluginCallbacks.length; i < il; i ++ ) {
|
|
91
75
|
|
|
92
76
|
plugins.push( this.pluginCallbacks[ i ]( writer ) );
|
|
@@ -97,7 +81,6 @@
|
|
|
97
81
|
writer.write( input, onDone, options ).catch( onError );
|
|
98
82
|
|
|
99
83
|
}
|
|
100
|
-
|
|
101
84
|
parseAsync( input, options ) {
|
|
102
85
|
|
|
103
86
|
const scope = this;
|
|
@@ -109,11 +92,12 @@
|
|
|
109
92
|
|
|
110
93
|
}
|
|
111
94
|
|
|
112
|
-
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//------------------------------------------------------------------------------
|
|
113
98
|
// Constants
|
|
114
99
|
//------------------------------------------------------------------------------
|
|
115
100
|
|
|
116
|
-
|
|
117
101
|
const WEBGL_CONSTANTS = {
|
|
118
102
|
POINTS: 0x0000,
|
|
119
103
|
LINES: 0x0001,
|
|
@@ -153,7 +137,9 @@
|
|
|
153
137
|
position: 'translation',
|
|
154
138
|
quaternion: 'rotation',
|
|
155
139
|
morphTargetInfluences: 'weights'
|
|
156
|
-
};
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// GLB constants
|
|
157
143
|
// https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#glb-file-format-specification
|
|
158
144
|
|
|
159
145
|
const GLB_HEADER_BYTES = 12;
|
|
@@ -161,7 +147,9 @@
|
|
|
161
147
|
const GLB_VERSION = 2;
|
|
162
148
|
const GLB_CHUNK_PREFIX_BYTES = 8;
|
|
163
149
|
const GLB_CHUNK_TYPE_JSON = 0x4E4F534A;
|
|
164
|
-
const GLB_CHUNK_TYPE_BIN = 0x004E4942;
|
|
150
|
+
const GLB_CHUNK_TYPE_BIN = 0x004E4942;
|
|
151
|
+
|
|
152
|
+
//------------------------------------------------------------------------------
|
|
165
153
|
// Utility functions
|
|
166
154
|
//------------------------------------------------------------------------------
|
|
167
155
|
|
|
@@ -171,7 +159,6 @@
|
|
|
171
159
|
* @param {Array} array2 Array 2 to compare
|
|
172
160
|
* @return {Boolean} Returns true if both arrays are equal
|
|
173
161
|
*/
|
|
174
|
-
|
|
175
162
|
function equalArray( array1, array2 ) {
|
|
176
163
|
|
|
177
164
|
return array1.length === array2.length && array1.every( function ( element, index ) {
|
|
@@ -181,31 +168,30 @@
|
|
|
181
168
|
} );
|
|
182
169
|
|
|
183
170
|
}
|
|
171
|
+
|
|
184
172
|
/**
|
|
185
173
|
* Converts a string to an ArrayBuffer.
|
|
186
174
|
* @param {string} text
|
|
187
175
|
* @return {ArrayBuffer}
|
|
188
176
|
*/
|
|
189
|
-
|
|
190
|
-
|
|
191
177
|
function stringToArrayBuffer( text ) {
|
|
192
178
|
|
|
193
179
|
return new TextEncoder().encode( text ).buffer;
|
|
194
180
|
|
|
195
181
|
}
|
|
182
|
+
|
|
196
183
|
/**
|
|
197
184
|
* Is identity matrix
|
|
198
185
|
*
|
|
199
186
|
* @param {Matrix4} matrix
|
|
200
187
|
* @returns {Boolean} Returns true, if parameter is identity matrix
|
|
201
188
|
*/
|
|
202
|
-
|
|
203
|
-
|
|
204
189
|
function isIdentityMatrix( matrix ) {
|
|
205
190
|
|
|
206
191
|
return equalArray( matrix.elements, [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ] );
|
|
207
192
|
|
|
208
193
|
}
|
|
194
|
+
|
|
209
195
|
/**
|
|
210
196
|
* Get the min and max vectors from the given attribute
|
|
211
197
|
* @param {BufferAttribute} attribute Attribute to find the min/max in range from start to start + count
|
|
@@ -213,24 +199,21 @@
|
|
|
213
199
|
* @param {Integer} count
|
|
214
200
|
* @return {Object} Object containing the `min` and `max` values (As an array of attribute.itemSize components)
|
|
215
201
|
*/
|
|
216
|
-
|
|
217
|
-
|
|
218
202
|
function getMinMax( attribute, start, count ) {
|
|
219
203
|
|
|
220
204
|
const output = {
|
|
221
205
|
min: new Array( attribute.itemSize ).fill( Number.POSITIVE_INFINITY ),
|
|
222
206
|
max: new Array( attribute.itemSize ).fill( Number.NEGATIVE_INFINITY )
|
|
223
207
|
};
|
|
224
|
-
|
|
225
208
|
for ( let i = start; i < start + count; i ++ ) {
|
|
226
209
|
|
|
227
210
|
for ( let a = 0; a < attribute.itemSize; a ++ ) {
|
|
228
211
|
|
|
229
212
|
let value;
|
|
230
|
-
|
|
231
213
|
if ( attribute.itemSize > 4 ) {
|
|
232
214
|
|
|
233
215
|
// no support for interleaved data for itemSize > 4
|
|
216
|
+
|
|
234
217
|
value = attribute.array[ i * attribute.itemSize + a ];
|
|
235
218
|
|
|
236
219
|
} else {
|
|
@@ -249,6 +232,7 @@
|
|
|
249
232
|
return output;
|
|
250
233
|
|
|
251
234
|
}
|
|
235
|
+
|
|
252
236
|
/**
|
|
253
237
|
* Get the required size + padding for a buffer, rounded to the next 4-byte boundary.
|
|
254
238
|
* https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#data-alignment
|
|
@@ -257,13 +241,12 @@
|
|
|
257
241
|
* @returns {Integer} new buffer size with required padding.
|
|
258
242
|
*
|
|
259
243
|
*/
|
|
260
|
-
|
|
261
|
-
|
|
262
244
|
function getPaddedBufferSize( bufferSize ) {
|
|
263
245
|
|
|
264
246
|
return Math.ceil( bufferSize / 4 ) * 4;
|
|
265
247
|
|
|
266
248
|
}
|
|
249
|
+
|
|
267
250
|
/**
|
|
268
251
|
* Returns a buffer aligned to 4-byte boundary.
|
|
269
252
|
*
|
|
@@ -271,17 +254,13 @@
|
|
|
271
254
|
* @param {Integer} paddingByte (Optional)
|
|
272
255
|
* @returns {ArrayBuffer} The same buffer if it's already aligned to 4-byte boundary or a new buffer
|
|
273
256
|
*/
|
|
274
|
-
|
|
275
|
-
|
|
276
257
|
function getPaddedArrayBuffer( arrayBuffer, paddingByte = 0 ) {
|
|
277
258
|
|
|
278
259
|
const paddedLength = getPaddedBufferSize( arrayBuffer.byteLength );
|
|
279
|
-
|
|
280
260
|
if ( paddedLength !== arrayBuffer.byteLength ) {
|
|
281
261
|
|
|
282
262
|
const array = new Uint8Array( paddedLength );
|
|
283
263
|
array.set( new Uint8Array( arrayBuffer ) );
|
|
284
|
-
|
|
285
264
|
if ( paddingByte !== 0 ) {
|
|
286
265
|
|
|
287
266
|
for ( let i = arrayBuffer.byteLength; i < paddedLength; i ++ ) {
|
|
@@ -300,27 +279,15 @@
|
|
|
300
279
|
|
|
301
280
|
}
|
|
302
281
|
|
|
303
|
-
let cachedCanvas = null;
|
|
304
|
-
|
|
305
282
|
function getCanvas() {
|
|
306
283
|
|
|
307
|
-
if ( cachedCanvas ) {
|
|
308
|
-
|
|
309
|
-
return cachedCanvas;
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
|
|
313
284
|
if ( typeof document === 'undefined' && typeof OffscreenCanvas !== 'undefined' ) {
|
|
314
285
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
} else {
|
|
318
|
-
|
|
319
|
-
cachedCanvas = document.createElement( 'canvas' );
|
|
286
|
+
return new OffscreenCanvas( 1, 1 );
|
|
320
287
|
|
|
321
288
|
}
|
|
322
289
|
|
|
323
|
-
return
|
|
290
|
+
return document.createElement( 'canvas' );
|
|
324
291
|
|
|
325
292
|
}
|
|
326
293
|
|
|
@@ -332,9 +299,10 @@
|
|
|
332
299
|
|
|
333
300
|
}
|
|
334
301
|
|
|
335
|
-
let quality;
|
|
336
|
-
// Use the Blink default quality levels of toBlob instead so that file sizes are comparable.
|
|
302
|
+
let quality;
|
|
337
303
|
|
|
304
|
+
// Blink's implementation of convertToBlob seems to default to a quality level of 100%
|
|
305
|
+
// Use the Blink default quality levels of toBlob instead so that file sizes are comparable.
|
|
338
306
|
if ( mimeType === 'image/jpeg' ) {
|
|
339
307
|
|
|
340
308
|
quality = 0.92;
|
|
@@ -351,11 +319,10 @@
|
|
|
351
319
|
} );
|
|
352
320
|
|
|
353
321
|
}
|
|
322
|
+
|
|
354
323
|
/**
|
|
355
324
|
* Writer
|
|
356
325
|
*/
|
|
357
|
-
|
|
358
|
-
|
|
359
326
|
class GLTFWriter {
|
|
360
327
|
|
|
361
328
|
constructor() {
|
|
@@ -387,20 +354,18 @@
|
|
|
387
354
|
};
|
|
388
355
|
|
|
389
356
|
}
|
|
390
|
-
|
|
391
357
|
setPlugins( plugins ) {
|
|
392
358
|
|
|
393
359
|
this.plugins = plugins;
|
|
394
360
|
|
|
395
361
|
}
|
|
362
|
+
|
|
396
363
|
/**
|
|
397
364
|
* Parse scenes and generate GLTF output
|
|
398
365
|
* @param {Scene or [THREE.Scenes]} input THREE.Scene or Array of THREE.Scenes
|
|
399
366
|
* @param {Function} onDone Callback on completed
|
|
400
367
|
* @param {Object} options options
|
|
401
368
|
*/
|
|
402
|
-
|
|
403
|
-
|
|
404
369
|
async write( input, onDone, options ) {
|
|
405
370
|
|
|
406
371
|
this.options = Object.assign( {}, {
|
|
@@ -408,12 +373,10 @@
|
|
|
408
373
|
binary: false,
|
|
409
374
|
trs: false,
|
|
410
375
|
onlyVisible: true,
|
|
411
|
-
truncateDrawRange: true,
|
|
412
376
|
maxTextureSize: Infinity,
|
|
413
377
|
animations: [],
|
|
414
378
|
includeCustomExtensions: false
|
|
415
379
|
}, options );
|
|
416
|
-
|
|
417
380
|
if ( this.options.animations.length > 0 ) {
|
|
418
381
|
|
|
419
382
|
// Only TRS properties, and not matrices, may be targeted by animation.
|
|
@@ -427,36 +390,40 @@
|
|
|
427
390
|
const buffers = writer.buffers;
|
|
428
391
|
const json = writer.json;
|
|
429
392
|
options = writer.options;
|
|
430
|
-
const extensionsUsed = writer.extensionsUsed;
|
|
393
|
+
const extensionsUsed = writer.extensionsUsed;
|
|
431
394
|
|
|
395
|
+
// Merge buffers.
|
|
432
396
|
const blob = new Blob( buffers, {
|
|
433
397
|
type: 'application/octet-stream'
|
|
434
|
-
} );
|
|
398
|
+
} );
|
|
435
399
|
|
|
400
|
+
// Declare extensions.
|
|
436
401
|
const extensionsUsedList = Object.keys( extensionsUsed );
|
|
437
|
-
if ( extensionsUsedList.length > 0 ) json.extensionsUsed = extensionsUsedList;
|
|
402
|
+
if ( extensionsUsedList.length > 0 ) json.extensionsUsed = extensionsUsedList;
|
|
438
403
|
|
|
404
|
+
// Update bytelength of the single buffer.
|
|
439
405
|
if ( json.buffers && json.buffers.length > 0 ) json.buffers[ 0 ].byteLength = blob.size;
|
|
440
|
-
|
|
441
406
|
if ( options.binary === true ) {
|
|
442
407
|
|
|
443
408
|
// https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#glb-file-format-specification
|
|
409
|
+
|
|
444
410
|
const reader = new FileReader();
|
|
445
411
|
reader.readAsArrayBuffer( blob );
|
|
446
|
-
|
|
447
412
|
reader.onloadend = function () {
|
|
448
413
|
|
|
449
414
|
// Binary chunk.
|
|
450
415
|
const binaryChunk = getPaddedArrayBuffer( reader.result );
|
|
451
416
|
const binaryChunkPrefix = new DataView( new ArrayBuffer( GLB_CHUNK_PREFIX_BYTES ) );
|
|
452
417
|
binaryChunkPrefix.setUint32( 0, binaryChunk.byteLength, true );
|
|
453
|
-
binaryChunkPrefix.setUint32( 4, GLB_CHUNK_TYPE_BIN, true );
|
|
418
|
+
binaryChunkPrefix.setUint32( 4, GLB_CHUNK_TYPE_BIN, true );
|
|
454
419
|
|
|
420
|
+
// JSON chunk.
|
|
455
421
|
const jsonChunk = getPaddedArrayBuffer( stringToArrayBuffer( JSON.stringify( json ) ), 0x20 );
|
|
456
422
|
const jsonChunkPrefix = new DataView( new ArrayBuffer( GLB_CHUNK_PREFIX_BYTES ) );
|
|
457
423
|
jsonChunkPrefix.setUint32( 0, jsonChunk.byteLength, true );
|
|
458
|
-
jsonChunkPrefix.setUint32( 4, GLB_CHUNK_TYPE_JSON, true );
|
|
424
|
+
jsonChunkPrefix.setUint32( 4, GLB_CHUNK_TYPE_JSON, true );
|
|
459
425
|
|
|
426
|
+
// GLB header.
|
|
460
427
|
const header = new ArrayBuffer( GLB_HEADER_BYTES );
|
|
461
428
|
const headerView = new DataView( header );
|
|
462
429
|
headerView.setUint32( 0, GLB_HEADER_MAGIC, true );
|
|
@@ -468,7 +435,6 @@
|
|
|
468
435
|
} );
|
|
469
436
|
const glbReader = new FileReader();
|
|
470
437
|
glbReader.readAsArrayBuffer( glbBlob );
|
|
471
|
-
|
|
472
438
|
glbReader.onloadend = function () {
|
|
473
439
|
|
|
474
440
|
onDone( glbReader.result );
|
|
@@ -483,7 +449,6 @@
|
|
|
483
449
|
|
|
484
450
|
const reader = new FileReader();
|
|
485
451
|
reader.readAsDataURL( blob );
|
|
486
|
-
|
|
487
452
|
reader.onloadend = function () {
|
|
488
453
|
|
|
489
454
|
const base64data = reader.result;
|
|
@@ -501,28 +466,24 @@
|
|
|
501
466
|
}
|
|
502
467
|
|
|
503
468
|
}
|
|
469
|
+
|
|
504
470
|
/**
|
|
505
471
|
* Serializes a userData.
|
|
506
472
|
*
|
|
507
473
|
* @param {THREE.Object3D|THREE.Material} object
|
|
508
474
|
* @param {Object} objectDef
|
|
509
475
|
*/
|
|
510
|
-
|
|
511
|
-
|
|
512
476
|
serializeUserData( object, objectDef ) {
|
|
513
477
|
|
|
514
478
|
if ( Object.keys( object.userData ).length === 0 ) return;
|
|
515
479
|
const options = this.options;
|
|
516
480
|
const extensionsUsed = this.extensionsUsed;
|
|
517
|
-
|
|
518
481
|
try {
|
|
519
482
|
|
|
520
483
|
const json = JSON.parse( JSON.stringify( object.userData ) );
|
|
521
|
-
|
|
522
484
|
if ( options.includeCustomExtensions && json.gltfExtensions ) {
|
|
523
485
|
|
|
524
486
|
if ( objectDef.extensions === undefined ) objectDef.extensions = {};
|
|
525
|
-
|
|
526
487
|
for ( const extensionName in json.gltfExtensions ) {
|
|
527
488
|
|
|
528
489
|
objectDef.extensions[ extensionName ] = json.gltfExtensions[ extensionName ];
|
|
@@ -543,13 +504,12 @@
|
|
|
543
504
|
}
|
|
544
505
|
|
|
545
506
|
}
|
|
507
|
+
|
|
546
508
|
/**
|
|
547
509
|
* Returns ids for buffer attributes.
|
|
548
510
|
* @param {Object} object
|
|
549
511
|
* @return {Integer}
|
|
550
512
|
*/
|
|
551
|
-
|
|
552
|
-
|
|
553
513
|
getUID( attribute, isRelativeCopy = false ) {
|
|
554
514
|
|
|
555
515
|
if ( this.uids.has( attribute ) === false ) {
|
|
@@ -565,20 +525,18 @@
|
|
|
565
525
|
return uids.get( isRelativeCopy );
|
|
566
526
|
|
|
567
527
|
}
|
|
528
|
+
|
|
568
529
|
/**
|
|
569
530
|
* Checks if normal attribute values are normalized.
|
|
570
531
|
*
|
|
571
532
|
* @param {BufferAttribute} normal
|
|
572
533
|
* @returns {Boolean}
|
|
573
534
|
*/
|
|
574
|
-
|
|
575
|
-
|
|
576
535
|
isNormalizedNormalAttribute( normal ) {
|
|
577
536
|
|
|
578
537
|
const cache = this.cache;
|
|
579
538
|
if ( cache.attributesNormalized.has( normal ) ) return false;
|
|
580
539
|
const v = new THREE.Vector3();
|
|
581
|
-
|
|
582
540
|
for ( let i = 0, il = normal.count; i < il; i ++ ) {
|
|
583
541
|
|
|
584
542
|
// 0.0005 is from glTF-validator
|
|
@@ -589,6 +547,7 @@
|
|
|
589
547
|
return true;
|
|
590
548
|
|
|
591
549
|
}
|
|
550
|
+
|
|
592
551
|
/**
|
|
593
552
|
* Creates normalized normal buffer attribute.
|
|
594
553
|
*
|
|
@@ -596,19 +555,15 @@
|
|
|
596
555
|
* @returns {BufferAttribute}
|
|
597
556
|
*
|
|
598
557
|
*/
|
|
599
|
-
|
|
600
|
-
|
|
601
558
|
createNormalizedNormalAttribute( normal ) {
|
|
602
559
|
|
|
603
560
|
const cache = this.cache;
|
|
604
561
|
if ( cache.attributesNormalized.has( normal ) ) return cache.attributesNormalized.get( normal );
|
|
605
562
|
const attribute = normal.clone();
|
|
606
563
|
const v = new THREE.Vector3();
|
|
607
|
-
|
|
608
564
|
for ( let i = 0, il = attribute.count; i < il; i ++ ) {
|
|
609
565
|
|
|
610
566
|
v.fromBufferAttribute( attribute, i );
|
|
611
|
-
|
|
612
567
|
if ( v.x === 0 && v.y === 0 && v.z === 0 ) {
|
|
613
568
|
|
|
614
569
|
// if values can't be normalized set (1, 0, 0)
|
|
@@ -628,6 +583,7 @@
|
|
|
628
583
|
return attribute;
|
|
629
584
|
|
|
630
585
|
}
|
|
586
|
+
|
|
631
587
|
/**
|
|
632
588
|
* Applies a texture transform, if present, to the map definition. Requires
|
|
633
589
|
* the KHR_texture_transform extension.
|
|
@@ -635,13 +591,10 @@
|
|
|
635
591
|
* @param {Object} mapDef
|
|
636
592
|
* @param {THREE.Texture} texture
|
|
637
593
|
*/
|
|
638
|
-
|
|
639
|
-
|
|
640
594
|
applyTextureTransform( mapDef, texture ) {
|
|
641
595
|
|
|
642
596
|
let didTransform = false;
|
|
643
597
|
const transformDef = {};
|
|
644
|
-
|
|
645
598
|
if ( texture.offset.x !== 0 || texture.offset.y !== 0 ) {
|
|
646
599
|
|
|
647
600
|
transformDef.offset = texture.offset.toArray();
|
|
@@ -672,10 +625,29 @@
|
|
|
672
625
|
}
|
|
673
626
|
|
|
674
627
|
}
|
|
675
|
-
|
|
676
628
|
buildMetalRoughTexture( metalnessMap, roughnessMap ) {
|
|
677
629
|
|
|
678
630
|
if ( metalnessMap === roughnessMap ) return metalnessMap;
|
|
631
|
+
function getEncodingConversion( map ) {
|
|
632
|
+
|
|
633
|
+
if ( map.encoding === THREE.sRGBEncoding ) {
|
|
634
|
+
|
|
635
|
+
return function SRGBToLinear( c ) {
|
|
636
|
+
|
|
637
|
+
return c < 0.04045 ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
|
|
638
|
+
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
return function LinearToLinear( c ) {
|
|
644
|
+
|
|
645
|
+
return c;
|
|
646
|
+
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
}
|
|
650
|
+
|
|
679
651
|
console.warn( 'THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.' );
|
|
680
652
|
const metalness = metalnessMap?.image;
|
|
681
653
|
const roughness = roughnessMap?.image;
|
|
@@ -688,15 +660,14 @@
|
|
|
688
660
|
context.fillStyle = '#00ffff';
|
|
689
661
|
context.fillRect( 0, 0, width, height );
|
|
690
662
|
const composite = context.getImageData( 0, 0, width, height );
|
|
691
|
-
|
|
692
663
|
if ( metalness ) {
|
|
693
664
|
|
|
694
665
|
context.drawImage( metalness, 0, 0, width, height );
|
|
666
|
+
const convert = getEncodingConversion( metalnessMap );
|
|
695
667
|
const data = context.getImageData( 0, 0, width, height ).data;
|
|
696
|
-
|
|
697
668
|
for ( let i = 2; i < data.length; i += 4 ) {
|
|
698
669
|
|
|
699
|
-
composite.data[ i ] = data[ i ];
|
|
670
|
+
composite.data[ i ] = convert( data[ i ] / 256 ) * 256;
|
|
700
671
|
|
|
701
672
|
}
|
|
702
673
|
|
|
@@ -705,43 +676,47 @@
|
|
|
705
676
|
if ( roughness ) {
|
|
706
677
|
|
|
707
678
|
context.drawImage( roughness, 0, 0, width, height );
|
|
679
|
+
const convert = getEncodingConversion( roughnessMap );
|
|
708
680
|
const data = context.getImageData( 0, 0, width, height ).data;
|
|
709
|
-
|
|
710
681
|
for ( let i = 1; i < data.length; i += 4 ) {
|
|
711
682
|
|
|
712
|
-
composite.data[ i ] = data[ i ];
|
|
683
|
+
composite.data[ i ] = convert( data[ i ] / 256 ) * 256;
|
|
713
684
|
|
|
714
685
|
}
|
|
715
686
|
|
|
716
687
|
}
|
|
717
688
|
|
|
718
|
-
context.putImageData( composite, 0, 0 );
|
|
689
|
+
context.putImageData( composite, 0, 0 );
|
|
690
|
+
|
|
691
|
+
//
|
|
719
692
|
|
|
720
693
|
const reference = metalnessMap || roughnessMap;
|
|
721
694
|
const texture = reference.clone();
|
|
722
695
|
texture.source = new THREE.Source( canvas );
|
|
696
|
+
texture.encoding = THREE.LinearEncoding;
|
|
723
697
|
return texture;
|
|
724
698
|
|
|
725
699
|
}
|
|
700
|
+
|
|
726
701
|
/**
|
|
727
702
|
* Process a buffer to append to the default one.
|
|
728
703
|
* @param {ArrayBuffer} buffer
|
|
729
704
|
* @return {Integer}
|
|
730
705
|
*/
|
|
731
|
-
|
|
732
|
-
|
|
733
706
|
processBuffer( buffer ) {
|
|
734
707
|
|
|
735
708
|
const json = this.json;
|
|
736
709
|
const buffers = this.buffers;
|
|
737
710
|
if ( ! json.buffers ) json.buffers = [ {
|
|
738
711
|
byteLength: 0
|
|
739
|
-
} ];
|
|
712
|
+
} ];
|
|
740
713
|
|
|
714
|
+
// All buffers are merged before export.
|
|
741
715
|
buffers.push( buffer );
|
|
742
716
|
return 0;
|
|
743
717
|
|
|
744
718
|
}
|
|
719
|
+
|
|
745
720
|
/**
|
|
746
721
|
* Process and generate a BufferView
|
|
747
722
|
* @param {BufferAttribute} attribute
|
|
@@ -751,15 +726,14 @@
|
|
|
751
726
|
* @param {number} target (Optional) Target usage of the BufferView
|
|
752
727
|
* @return {Object}
|
|
753
728
|
*/
|
|
754
|
-
|
|
755
|
-
|
|
756
729
|
processBufferView( attribute, componentType, start, count, target ) {
|
|
757
730
|
|
|
758
731
|
const json = this.json;
|
|
759
|
-
if ( ! json.bufferViews ) json.bufferViews = [];
|
|
732
|
+
if ( ! json.bufferViews ) json.bufferViews = [];
|
|
760
733
|
|
|
761
|
-
|
|
734
|
+
// Create a new dataview and dump the attribute's array into it
|
|
762
735
|
|
|
736
|
+
let componentSize;
|
|
763
737
|
if ( componentType === WEBGL_CONSTANTS.UNSIGNED_BYTE ) {
|
|
764
738
|
|
|
765
739
|
componentSize = 1;
|
|
@@ -777,16 +751,15 @@
|
|
|
777
751
|
const byteLength = getPaddedBufferSize( count * attribute.itemSize * componentSize );
|
|
778
752
|
const dataView = new DataView( new ArrayBuffer( byteLength ) );
|
|
779
753
|
let offset = 0;
|
|
780
|
-
|
|
781
754
|
for ( let i = start; i < start + count; i ++ ) {
|
|
782
755
|
|
|
783
756
|
for ( let a = 0; a < attribute.itemSize; a ++ ) {
|
|
784
757
|
|
|
785
758
|
let value;
|
|
786
|
-
|
|
787
759
|
if ( attribute.itemSize > 4 ) {
|
|
788
760
|
|
|
789
761
|
// no support for interleaved data for itemSize > 4
|
|
762
|
+
|
|
790
763
|
value = attribute.array[ i * attribute.itemSize + a ];
|
|
791
764
|
|
|
792
765
|
} else {
|
|
@@ -825,7 +798,6 @@
|
|
|
825
798
|
byteLength: byteLength
|
|
826
799
|
};
|
|
827
800
|
if ( target !== undefined ) bufferViewDef.target = target;
|
|
828
|
-
|
|
829
801
|
if ( target === WEBGL_CONSTANTS.ARRAY_BUFFER ) {
|
|
830
802
|
|
|
831
803
|
// Only define byteStride for vertex attributes.
|
|
@@ -834,8 +806,9 @@
|
|
|
834
806
|
}
|
|
835
807
|
|
|
836
808
|
this.byteOffset += byteLength;
|
|
837
|
-
json.bufferViews.push( bufferViewDef );
|
|
809
|
+
json.bufferViews.push( bufferViewDef );
|
|
838
810
|
|
|
811
|
+
// @TODO Merge bufferViews where possible.
|
|
839
812
|
const output = {
|
|
840
813
|
id: json.bufferViews.length - 1,
|
|
841
814
|
byteLength: 0
|
|
@@ -843,13 +816,12 @@
|
|
|
843
816
|
return output;
|
|
844
817
|
|
|
845
818
|
}
|
|
819
|
+
|
|
846
820
|
/**
|
|
847
821
|
* Process and generate a BufferView from an image Blob.
|
|
848
822
|
* @param {Blob} blob
|
|
849
823
|
* @return {Promise<Integer>}
|
|
850
824
|
*/
|
|
851
|
-
|
|
852
|
-
|
|
853
825
|
processBufferViewImage( blob ) {
|
|
854
826
|
|
|
855
827
|
const writer = this;
|
|
@@ -859,7 +831,6 @@
|
|
|
859
831
|
|
|
860
832
|
const reader = new FileReader();
|
|
861
833
|
reader.readAsArrayBuffer( blob );
|
|
862
|
-
|
|
863
834
|
reader.onloadend = function () {
|
|
864
835
|
|
|
865
836
|
const buffer = getPaddedArrayBuffer( reader.result );
|
|
@@ -876,6 +847,7 @@
|
|
|
876
847
|
} );
|
|
877
848
|
|
|
878
849
|
}
|
|
850
|
+
|
|
879
851
|
/**
|
|
880
852
|
* Process attribute to generate an accessor
|
|
881
853
|
* @param {BufferAttribute} attribute Attribute to process
|
|
@@ -884,11 +856,8 @@
|
|
|
884
856
|
* @param {Integer} count (Optional)
|
|
885
857
|
* @return {Integer|null} Index of the processed accessor on the "accessors" array
|
|
886
858
|
*/
|
|
887
|
-
|
|
888
|
-
|
|
889
859
|
processAccessor( attribute, geometry, start, count ) {
|
|
890
860
|
|
|
891
|
-
const options = this.options;
|
|
892
861
|
const json = this.json;
|
|
893
862
|
const types = {
|
|
894
863
|
1: 'SCALAR',
|
|
@@ -897,8 +866,9 @@
|
|
|
897
866
|
4: 'VEC4',
|
|
898
867
|
16: 'MAT4'
|
|
899
868
|
};
|
|
900
|
-
let componentType;
|
|
869
|
+
let componentType;
|
|
901
870
|
|
|
871
|
+
// Detect the component type of the attribute array (float, uint or ushort)
|
|
902
872
|
if ( attribute.array.constructor === Float32Array ) {
|
|
903
873
|
|
|
904
874
|
componentType = WEBGL_CONSTANTS.FLOAT;
|
|
@@ -922,24 +892,15 @@
|
|
|
922
892
|
}
|
|
923
893
|
|
|
924
894
|
if ( start === undefined ) start = 0;
|
|
925
|
-
if ( count === undefined ) count = attribute.count;
|
|
926
|
-
|
|
927
|
-
if ( options.truncateDrawRange && geometry !== undefined && geometry.index === null ) {
|
|
928
|
-
|
|
929
|
-
const end = start + count;
|
|
930
|
-
const end2 = geometry.drawRange.count === Infinity ? attribute.count : geometry.drawRange.start + geometry.drawRange.count;
|
|
931
|
-
start = Math.max( start, geometry.drawRange.start );
|
|
932
|
-
count = Math.min( end, end2 ) - start;
|
|
933
|
-
if ( count < 0 ) count = 0;
|
|
934
|
-
|
|
935
|
-
} // Skip creating an accessor if the attribute doesn't have data to export
|
|
936
|
-
|
|
895
|
+
if ( count === undefined ) count = attribute.count;
|
|
937
896
|
|
|
897
|
+
// Skip creating an accessor if the attribute doesn't have data to export
|
|
938
898
|
if ( count === 0 ) return null;
|
|
939
899
|
const minMax = getMinMax( attribute, start, count );
|
|
940
|
-
let bufferViewTarget;
|
|
941
|
-
// animation samplers, target must not be set.
|
|
900
|
+
let bufferViewTarget;
|
|
942
901
|
|
|
902
|
+
// If geometry isn't provided, don't infer the target usage of the bufferView. For
|
|
903
|
+
// animation samplers, target must not be set.
|
|
943
904
|
if ( geometry !== undefined ) {
|
|
944
905
|
|
|
945
906
|
bufferViewTarget = attribute === geometry.index ? WEBGL_CONSTANTS.ELEMENT_ARRAY_BUFFER : WEBGL_CONSTANTS.ARRAY_BUFFER;
|
|
@@ -961,6 +922,7 @@
|
|
|
961
922
|
return json.accessors.push( accessorDef ) - 1;
|
|
962
923
|
|
|
963
924
|
}
|
|
925
|
+
|
|
964
926
|
/**
|
|
965
927
|
* Process image
|
|
966
928
|
* @param {Image} image to process
|
|
@@ -969,8 +931,6 @@
|
|
|
969
931
|
* @param {String} mimeType export format
|
|
970
932
|
* @return {Integer} Index of the processed texture in the "images" array
|
|
971
933
|
*/
|
|
972
|
-
|
|
973
|
-
|
|
974
934
|
processImage( image, format, flipY, mimeType = 'image/png' ) {
|
|
975
935
|
|
|
976
936
|
const writer = this;
|
|
@@ -990,7 +950,6 @@
|
|
|
990
950
|
canvas.width = Math.min( image.width, options.maxTextureSize );
|
|
991
951
|
canvas.height = Math.min( image.height, options.maxTextureSize );
|
|
992
952
|
const ctx = canvas.getContext( '2d' );
|
|
993
|
-
|
|
994
953
|
if ( flipY === true ) {
|
|
995
954
|
|
|
996
955
|
ctx.translate( 0, canvas.height );
|
|
@@ -1001,6 +960,7 @@
|
|
|
1001
960
|
if ( image.data !== undefined ) {
|
|
1002
961
|
|
|
1003
962
|
// THREE.DataTexture
|
|
963
|
+
|
|
1004
964
|
if ( format !== THREE.RGBAFormat ) {
|
|
1005
965
|
|
|
1006
966
|
console.error( 'GLTFExporter: Only THREE.RGBAFormat is supported.' );
|
|
@@ -1014,7 +974,6 @@
|
|
|
1014
974
|
}
|
|
1015
975
|
|
|
1016
976
|
const data = new Uint8ClampedArray( image.height * image.width * 4 );
|
|
1017
|
-
|
|
1018
977
|
for ( let i = 0; i < data.length; i += 4 ) {
|
|
1019
978
|
|
|
1020
979
|
data[ i + 0 ] = image.data[ i + 0 ];
|
|
@@ -1063,13 +1022,12 @@
|
|
|
1063
1022
|
return index;
|
|
1064
1023
|
|
|
1065
1024
|
}
|
|
1025
|
+
|
|
1066
1026
|
/**
|
|
1067
1027
|
* Process sampler
|
|
1068
1028
|
* @param {Texture} map Texture to process
|
|
1069
1029
|
* @return {Integer} Index of the processed texture in the "samplers" array
|
|
1070
1030
|
*/
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
1031
|
processSampler( map ) {
|
|
1074
1032
|
|
|
1075
1033
|
const json = this.json;
|
|
@@ -1083,13 +1041,12 @@
|
|
|
1083
1041
|
return json.samplers.push( samplerDef ) - 1;
|
|
1084
1042
|
|
|
1085
1043
|
}
|
|
1044
|
+
|
|
1086
1045
|
/**
|
|
1087
1046
|
* Process texture
|
|
1088
1047
|
* @param {Texture} map Map to process
|
|
1089
1048
|
* @return {Integer} Index of the processed texture in the "textures" array
|
|
1090
1049
|
*/
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
1050
|
processTexture( map ) {
|
|
1094
1051
|
|
|
1095
1052
|
const cache = this.cache;
|
|
@@ -1103,31 +1060,27 @@
|
|
|
1103
1060
|
source: this.processImage( map.image, map.format, map.flipY, mimeType )
|
|
1104
1061
|
};
|
|
1105
1062
|
if ( map.name ) textureDef.name = map.name;
|
|
1106
|
-
|
|
1107
1063
|
this._invokeAll( function ( ext ) {
|
|
1108
1064
|
|
|
1109
1065
|
ext.writeTexture && ext.writeTexture( map, textureDef );
|
|
1110
1066
|
|
|
1111
1067
|
} );
|
|
1112
|
-
|
|
1113
1068
|
const index = json.textures.push( textureDef ) - 1;
|
|
1114
1069
|
cache.textures.set( map, index );
|
|
1115
1070
|
return index;
|
|
1116
1071
|
|
|
1117
1072
|
}
|
|
1073
|
+
|
|
1118
1074
|
/**
|
|
1119
1075
|
* Process material
|
|
1120
1076
|
* @param {THREE.Material} material Material to process
|
|
1121
1077
|
* @return {Integer|null} Index of the processed material in the "materials" array
|
|
1122
1078
|
*/
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
1079
|
processMaterial( material ) {
|
|
1126
1080
|
|
|
1127
1081
|
const cache = this.cache;
|
|
1128
1082
|
const json = this.json;
|
|
1129
1083
|
if ( cache.materials.has( material ) ) return cache.materials.get( material );
|
|
1130
|
-
|
|
1131
1084
|
if ( material.isShaderMaterial ) {
|
|
1132
1085
|
|
|
1133
1086
|
console.warn( 'GLTFExporter: THREE.ShaderMaterial not supported.' );
|
|
@@ -1135,21 +1088,20 @@
|
|
|
1135
1088
|
|
|
1136
1089
|
}
|
|
1137
1090
|
|
|
1138
|
-
if ( ! json.materials ) json.materials = [];
|
|
1091
|
+
if ( ! json.materials ) json.materials = [];
|
|
1139
1092
|
|
|
1093
|
+
// @QUESTION Should we avoid including any attribute that has the default value?
|
|
1140
1094
|
const materialDef = {
|
|
1141
1095
|
pbrMetallicRoughness: {}
|
|
1142
1096
|
};
|
|
1143
|
-
|
|
1144
1097
|
if ( material.isMeshStandardMaterial !== true && material.isMeshBasicMaterial !== true ) {
|
|
1145
1098
|
|
|
1146
1099
|
console.warn( 'GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.' );
|
|
1147
1100
|
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1101
|
+
}
|
|
1150
1102
|
|
|
1103
|
+
// pbrMetallicRoughness.baseColorFactor
|
|
1151
1104
|
const color = material.color.toArray().concat( [ material.opacity ] );
|
|
1152
|
-
|
|
1153
1105
|
if ( ! equalArray( color, [ 1, 1, 1, 1 ] ) ) {
|
|
1154
1106
|
|
|
1155
1107
|
materialDef.pbrMetallicRoughness.baseColorFactor = color;
|
|
@@ -1166,9 +1118,9 @@
|
|
|
1166
1118
|
materialDef.pbrMetallicRoughness.metallicFactor = 0.5;
|
|
1167
1119
|
materialDef.pbrMetallicRoughness.roughnessFactor = 0.5;
|
|
1168
1120
|
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1121
|
+
}
|
|
1171
1122
|
|
|
1123
|
+
// pbrMetallicRoughness.metallicRoughnessTexture
|
|
1172
1124
|
if ( material.metalnessMap || material.roughnessMap ) {
|
|
1173
1125
|
|
|
1174
1126
|
const metalRoughTexture = this.buildMetalRoughTexture( material.metalnessMap, material.roughnessMap );
|
|
@@ -1178,9 +1130,9 @@
|
|
|
1178
1130
|
this.applyTextureTransform( metalRoughMapDef, metalRoughTexture );
|
|
1179
1131
|
materialDef.pbrMetallicRoughness.metallicRoughnessTexture = metalRoughMapDef;
|
|
1180
1132
|
|
|
1181
|
-
}
|
|
1182
|
-
|
|
1133
|
+
}
|
|
1183
1134
|
|
|
1135
|
+
// pbrMetallicRoughness.baseColorTexture or pbrSpecularGlossiness diffuseTexture
|
|
1184
1136
|
if ( material.map ) {
|
|
1185
1137
|
|
|
1186
1138
|
const baseColorMapDef = {
|
|
@@ -1196,7 +1148,6 @@
|
|
|
1196
1148
|
// note: emissive components are limited to stay within the 0 - 1 range to accommodate glTF spec. see #21849 and #22000.
|
|
1197
1149
|
const emissive = material.emissive.clone().multiplyScalar( material.emissiveIntensity );
|
|
1198
1150
|
const maxEmissiveComponent = Math.max( emissive.r, emissive.g, emissive.b );
|
|
1199
|
-
|
|
1200
1151
|
if ( maxEmissiveComponent > 1 ) {
|
|
1201
1152
|
|
|
1202
1153
|
emissive.multiplyScalar( 1 / maxEmissiveComponent );
|
|
@@ -1208,9 +1159,9 @@
|
|
|
1208
1159
|
|
|
1209
1160
|
materialDef.emissiveFactor = emissive.toArray();
|
|
1210
1161
|
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1162
|
+
}
|
|
1213
1163
|
|
|
1164
|
+
// emissiveTexture
|
|
1214
1165
|
if ( material.emissiveMap ) {
|
|
1215
1166
|
|
|
1216
1167
|
const emissiveMapDef = {
|
|
@@ -1221,15 +1172,14 @@
|
|
|
1221
1172
|
|
|
1222
1173
|
}
|
|
1223
1174
|
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1175
|
+
}
|
|
1226
1176
|
|
|
1177
|
+
// normalTexture
|
|
1227
1178
|
if ( material.normalMap ) {
|
|
1228
1179
|
|
|
1229
1180
|
const normalMapDef = {
|
|
1230
1181
|
index: this.processTexture( material.normalMap )
|
|
1231
1182
|
};
|
|
1232
|
-
|
|
1233
1183
|
if ( material.normalScale && material.normalScale.x !== 1 ) {
|
|
1234
1184
|
|
|
1235
1185
|
// glTF normal scale is univariate. Ignore `y`, which may be flipped.
|
|
@@ -1241,16 +1191,15 @@
|
|
|
1241
1191
|
this.applyTextureTransform( normalMapDef, material.normalMap );
|
|
1242
1192
|
materialDef.normalTexture = normalMapDef;
|
|
1243
1193
|
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1194
|
+
}
|
|
1246
1195
|
|
|
1196
|
+
// occlusionTexture
|
|
1247
1197
|
if ( material.aoMap ) {
|
|
1248
1198
|
|
|
1249
1199
|
const occlusionMapDef = {
|
|
1250
1200
|
index: this.processTexture( material.aoMap ),
|
|
1251
1201
|
texCoord: 1
|
|
1252
1202
|
};
|
|
1253
|
-
|
|
1254
1203
|
if ( material.aoMapIntensity !== 1.0 ) {
|
|
1255
1204
|
|
|
1256
1205
|
occlusionMapDef.strength = material.aoMapIntensity;
|
|
@@ -1260,9 +1209,9 @@
|
|
|
1260
1209
|
this.applyTextureTransform( occlusionMapDef, material.aoMap );
|
|
1261
1210
|
materialDef.occlusionTexture = occlusionMapDef;
|
|
1262
1211
|
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1212
|
+
}
|
|
1265
1213
|
|
|
1214
|
+
// alphaMode
|
|
1266
1215
|
if ( material.transparent ) {
|
|
1267
1216
|
|
|
1268
1217
|
materialDef.alphaMode = 'BLEND';
|
|
@@ -1276,37 +1225,33 @@
|
|
|
1276
1225
|
|
|
1277
1226
|
}
|
|
1278
1227
|
|
|
1279
|
-
}
|
|
1280
|
-
|
|
1228
|
+
}
|
|
1281
1229
|
|
|
1230
|
+
// doubleSided
|
|
1282
1231
|
if ( material.side === THREE.DoubleSide ) materialDef.doubleSided = true;
|
|
1283
1232
|
if ( material.name !== '' ) materialDef.name = material.name;
|
|
1284
1233
|
this.serializeUserData( material, materialDef );
|
|
1285
|
-
|
|
1286
1234
|
this._invokeAll( function ( ext ) {
|
|
1287
1235
|
|
|
1288
1236
|
ext.writeMaterial && ext.writeMaterial( material, materialDef );
|
|
1289
1237
|
|
|
1290
1238
|
} );
|
|
1291
|
-
|
|
1292
1239
|
const index = json.materials.push( materialDef ) - 1;
|
|
1293
1240
|
cache.materials.set( material, index );
|
|
1294
1241
|
return index;
|
|
1295
1242
|
|
|
1296
1243
|
}
|
|
1244
|
+
|
|
1297
1245
|
/**
|
|
1298
1246
|
* Process mesh
|
|
1299
1247
|
* @param {THREE.Mesh} mesh Mesh to process
|
|
1300
1248
|
* @return {Integer|null} Index of the processed mesh in the "meshes" array
|
|
1301
1249
|
*/
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
1250
|
processMesh( mesh ) {
|
|
1305
1251
|
|
|
1306
1252
|
const cache = this.cache;
|
|
1307
1253
|
const json = this.json;
|
|
1308
1254
|
const meshCacheKeyParts = [ mesh.geometry.uuid ];
|
|
1309
|
-
|
|
1310
1255
|
if ( Array.isArray( mesh.material ) ) {
|
|
1311
1256
|
|
|
1312
1257
|
for ( let i = 0, l = mesh.material.length; i < l; i ++ ) {
|
|
@@ -1324,8 +1269,9 @@
|
|
|
1324
1269
|
const meshCacheKey = meshCacheKeyParts.join( ':' );
|
|
1325
1270
|
if ( cache.meshes.has( meshCacheKey ) ) return cache.meshes.get( meshCacheKey );
|
|
1326
1271
|
const geometry = mesh.geometry;
|
|
1327
|
-
let mode;
|
|
1272
|
+
let mode;
|
|
1328
1273
|
|
|
1274
|
+
// Use the correct mode
|
|
1329
1275
|
if ( mesh.isLineSegments ) {
|
|
1330
1276
|
|
|
1331
1277
|
mode = WEBGL_CONSTANTS.LINES;
|
|
@@ -1348,17 +1294,12 @@
|
|
|
1348
1294
|
|
|
1349
1295
|
}
|
|
1350
1296
|
|
|
1351
|
-
if ( geometry.isBufferGeometry !== true ) {
|
|
1352
|
-
|
|
1353
|
-
throw new Error( 'THREE.GLTFExporter: Geometry is not of type THREE.BufferGeometry.' );
|
|
1354
|
-
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
1297
|
const meshDef = {};
|
|
1358
1298
|
const attributes = {};
|
|
1359
1299
|
const primitives = [];
|
|
1360
|
-
const targets = [];
|
|
1300
|
+
const targets = [];
|
|
1361
1301
|
|
|
1302
|
+
// Conversion between attributes names in threejs and gltf spec
|
|
1362
1303
|
const nameConversion = {
|
|
1363
1304
|
uv: 'TEXCOORD_0',
|
|
1364
1305
|
uv2: 'TEXCOORD_1',
|
|
@@ -1367,40 +1308,37 @@
|
|
|
1367
1308
|
skinIndex: 'JOINTS_0'
|
|
1368
1309
|
};
|
|
1369
1310
|
const originalNormal = geometry.getAttribute( 'normal' );
|
|
1370
|
-
|
|
1371
1311
|
if ( originalNormal !== undefined && ! this.isNormalizedNormalAttribute( originalNormal ) ) {
|
|
1372
1312
|
|
|
1373
1313
|
console.warn( 'THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one.' );
|
|
1374
1314
|
geometry.setAttribute( 'normal', this.createNormalizedNormalAttribute( originalNormal ) );
|
|
1375
1315
|
|
|
1376
|
-
}
|
|
1377
|
-
// For every attribute create an accessor
|
|
1378
|
-
|
|
1316
|
+
}
|
|
1379
1317
|
|
|
1318
|
+
// @QUESTION Detect if .vertexColors = true?
|
|
1319
|
+
// For every attribute create an accessor
|
|
1380
1320
|
let modifiedAttribute = null;
|
|
1381
|
-
|
|
1382
1321
|
for ( let attributeName in geometry.attributes ) {
|
|
1383
1322
|
|
|
1384
1323
|
// Ignore morph target attributes, which are exported later.
|
|
1385
1324
|
if ( attributeName.slice( 0, 5 ) === 'morph' ) continue;
|
|
1386
1325
|
const attribute = geometry.attributes[ attributeName ];
|
|
1387
|
-
attributeName = nameConversion[ attributeName ] || attributeName.toUpperCase();
|
|
1388
|
-
// listed in the spec; non-spec attributes are considered custom.
|
|
1326
|
+
attributeName = nameConversion[ attributeName ] || attributeName.toUpperCase();
|
|
1389
1327
|
|
|
1328
|
+
// Prefix all geometry attributes except the ones specifically
|
|
1329
|
+
// listed in the spec; non-spec attributes are considered custom.
|
|
1390
1330
|
const validVertexAttributes = /^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/;
|
|
1391
1331
|
if ( ! validVertexAttributes.test( attributeName ) ) attributeName = '_' + attributeName;
|
|
1392
|
-
|
|
1393
1332
|
if ( cache.attributes.has( this.getUID( attribute ) ) ) {
|
|
1394
1333
|
|
|
1395
1334
|
attributes[ attributeName ] = cache.attributes.get( this.getUID( attribute ) );
|
|
1396
1335
|
continue;
|
|
1397
1336
|
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1337
|
+
}
|
|
1400
1338
|
|
|
1339
|
+
// JOINTS_0 must be UNSIGNED_BYTE or UNSIGNED_SHORT.
|
|
1401
1340
|
modifiedAttribute = null;
|
|
1402
1341
|
const array = attribute.array;
|
|
1403
|
-
|
|
1404
1342
|
if ( attributeName === 'JOINTS_0' && ! ( array instanceof Uint16Array ) && ! ( array instanceof Uint8Array ) ) {
|
|
1405
1343
|
|
|
1406
1344
|
console.warn( 'GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.' );
|
|
@@ -1409,7 +1347,6 @@
|
|
|
1409
1347
|
}
|
|
1410
1348
|
|
|
1411
1349
|
const accessor = this.processAccessor( modifiedAttribute || attribute, geometry );
|
|
1412
|
-
|
|
1413
1350
|
if ( accessor !== null ) {
|
|
1414
1351
|
|
|
1415
1352
|
attributes[ attributeName ] = accessor;
|
|
@@ -1419,16 +1356,17 @@
|
|
|
1419
1356
|
|
|
1420
1357
|
}
|
|
1421
1358
|
|
|
1422
|
-
if ( originalNormal !== undefined ) geometry.setAttribute( 'normal', originalNormal );
|
|
1359
|
+
if ( originalNormal !== undefined ) geometry.setAttribute( 'normal', originalNormal );
|
|
1423
1360
|
|
|
1424
|
-
if
|
|
1361
|
+
// Skip if no exportable attributes found
|
|
1362
|
+
if ( Object.keys( attributes ).length === 0 ) return null;
|
|
1425
1363
|
|
|
1364
|
+
// Morph targets
|
|
1426
1365
|
if ( mesh.morphTargetInfluences !== undefined && mesh.morphTargetInfluences.length > 0 ) {
|
|
1427
1366
|
|
|
1428
1367
|
const weights = [];
|
|
1429
1368
|
const targetNames = [];
|
|
1430
1369
|
const reverseDictionary = {};
|
|
1431
|
-
|
|
1432
1370
|
if ( mesh.morphTargetDictionary !== undefined ) {
|
|
1433
1371
|
|
|
1434
1372
|
for ( const key in mesh.morphTargetDictionary ) {
|
|
@@ -1443,11 +1381,11 @@
|
|
|
1443
1381
|
|
|
1444
1382
|
const target = {};
|
|
1445
1383
|
let warned = false;
|
|
1446
|
-
|
|
1447
1384
|
for ( const attributeName in geometry.morphAttributes ) {
|
|
1448
1385
|
|
|
1449
1386
|
// glTF 2.0 morph supports only POSITION/NORMAL/TANGENT.
|
|
1450
1387
|
// Three.js doesn't support TANGENT yet.
|
|
1388
|
+
|
|
1451
1389
|
if ( attributeName !== 'position' && attributeName !== 'normal' ) {
|
|
1452
1390
|
|
|
1453
1391
|
if ( ! warned ) {
|
|
@@ -1462,23 +1400,23 @@
|
|
|
1462
1400
|
}
|
|
1463
1401
|
|
|
1464
1402
|
const attribute = geometry.morphAttributes[ attributeName ][ i ];
|
|
1465
|
-
const gltfAttributeName = attributeName.toUpperCase();
|
|
1403
|
+
const gltfAttributeName = attributeName.toUpperCase();
|
|
1404
|
+
|
|
1405
|
+
// Three.js morph attribute has absolute values while the one of glTF has relative values.
|
|
1466
1406
|
//
|
|
1467
1407
|
// glTF 2.0 Specification:
|
|
1468
1408
|
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#morph-targets
|
|
1469
1409
|
|
|
1470
1410
|
const baseAttribute = geometry.attributes[ attributeName ];
|
|
1471
|
-
|
|
1472
1411
|
if ( cache.attributes.has( this.getUID( attribute, true ) ) ) {
|
|
1473
1412
|
|
|
1474
1413
|
target[ gltfAttributeName ] = cache.attributes.get( this.getUID( attribute, true ) );
|
|
1475
1414
|
continue;
|
|
1476
1415
|
|
|
1477
|
-
}
|
|
1478
|
-
|
|
1416
|
+
}
|
|
1479
1417
|
|
|
1418
|
+
// Clones attribute not to override
|
|
1480
1419
|
const relativeAttribute = attribute.clone();
|
|
1481
|
-
|
|
1482
1420
|
if ( ! geometry.morphTargetsRelative ) {
|
|
1483
1421
|
|
|
1484
1422
|
for ( let j = 0, jl = attribute.count; j < jl; j ++ ) {
|
|
@@ -1501,7 +1439,6 @@
|
|
|
1501
1439
|
}
|
|
1502
1440
|
|
|
1503
1441
|
meshDef.weights = weights;
|
|
1504
|
-
|
|
1505
1442
|
if ( targetNames.length > 0 ) {
|
|
1506
1443
|
|
|
1507
1444
|
meshDef.extras = {};
|
|
@@ -1519,7 +1456,6 @@
|
|
|
1519
1456
|
start: undefined,
|
|
1520
1457
|
count: undefined
|
|
1521
1458
|
} ];
|
|
1522
|
-
|
|
1523
1459
|
for ( let i = 0, il = groups.length; i < il; i ++ ) {
|
|
1524
1460
|
|
|
1525
1461
|
const primitive = {
|
|
@@ -1528,11 +1464,9 @@
|
|
|
1528
1464
|
};
|
|
1529
1465
|
this.serializeUserData( geometry, primitive );
|
|
1530
1466
|
if ( targets.length > 0 ) primitive.targets = targets;
|
|
1531
|
-
|
|
1532
1467
|
if ( geometry.index !== null ) {
|
|
1533
1468
|
|
|
1534
1469
|
let cacheKey = this.getUID( geometry.index );
|
|
1535
|
-
|
|
1536
1470
|
if ( groups[ i ].start !== undefined || groups[ i ].count !== undefined ) {
|
|
1537
1471
|
|
|
1538
1472
|
cacheKey += ':' + groups[ i ].start + ':' + groups[ i ].count;
|
|
@@ -1562,25 +1496,22 @@
|
|
|
1562
1496
|
|
|
1563
1497
|
meshDef.primitives = primitives;
|
|
1564
1498
|
if ( ! json.meshes ) json.meshes = [];
|
|
1565
|
-
|
|
1566
1499
|
this._invokeAll( function ( ext ) {
|
|
1567
1500
|
|
|
1568
1501
|
ext.writeMesh && ext.writeMesh( mesh, meshDef );
|
|
1569
1502
|
|
|
1570
1503
|
} );
|
|
1571
|
-
|
|
1572
1504
|
const index = json.meshes.push( meshDef ) - 1;
|
|
1573
1505
|
cache.meshes.set( meshCacheKey, index );
|
|
1574
1506
|
return index;
|
|
1575
1507
|
|
|
1576
1508
|
}
|
|
1509
|
+
|
|
1577
1510
|
/**
|
|
1578
1511
|
* Process camera
|
|
1579
1512
|
* @param {THREE.Camera} camera Camera to process
|
|
1580
1513
|
* @return {Integer} Index of the processed mesh in the "camera" array
|
|
1581
1514
|
*/
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
1515
|
processCamera( camera ) {
|
|
1585
1516
|
|
|
1586
1517
|
const json = this.json;
|
|
@@ -1589,7 +1520,6 @@
|
|
|
1589
1520
|
const cameraDef = {
|
|
1590
1521
|
type: isOrtho ? 'orthographic' : 'perspective'
|
|
1591
1522
|
};
|
|
1592
|
-
|
|
1593
1523
|
if ( isOrtho ) {
|
|
1594
1524
|
|
|
1595
1525
|
cameraDef.orthographic = {
|
|
@@ -1608,13 +1538,14 @@
|
|
|
1608
1538
|
znear: camera.near < 0 ? 0 : camera.near
|
|
1609
1539
|
};
|
|
1610
1540
|
|
|
1611
|
-
}
|
|
1612
|
-
|
|
1541
|
+
}
|
|
1613
1542
|
|
|
1543
|
+
// Question: Is saving "type" as name intentional?
|
|
1614
1544
|
if ( camera.name !== '' ) cameraDef.name = camera.type;
|
|
1615
1545
|
return json.cameras.push( cameraDef ) - 1;
|
|
1616
1546
|
|
|
1617
1547
|
}
|
|
1548
|
+
|
|
1618
1549
|
/**
|
|
1619
1550
|
* Creates glTF animation entry from AnimationClip object.
|
|
1620
1551
|
*
|
|
@@ -1625,8 +1556,6 @@
|
|
|
1625
1556
|
* @param {THREE.Object3D} root
|
|
1626
1557
|
* @return {number|null}
|
|
1627
1558
|
*/
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
1559
|
processAnimation( clip, root ) {
|
|
1631
1560
|
|
|
1632
1561
|
const json = this.json;
|
|
@@ -1636,14 +1565,12 @@
|
|
|
1636
1565
|
const tracks = clip.tracks;
|
|
1637
1566
|
const channels = [];
|
|
1638
1567
|
const samplers = [];
|
|
1639
|
-
|
|
1640
1568
|
for ( let i = 0; i < tracks.length; ++ i ) {
|
|
1641
1569
|
|
|
1642
1570
|
const track = tracks[ i ];
|
|
1643
1571
|
const trackBinding = THREE.PropertyBinding.parseTrackName( track.name );
|
|
1644
1572
|
let trackNode = THREE.PropertyBinding.findNode( root, trackBinding.nodeName );
|
|
1645
1573
|
const trackProperty = PATH_PROPERTIES[ trackBinding.propertyName ];
|
|
1646
|
-
|
|
1647
1574
|
if ( trackBinding.objectName === 'bones' ) {
|
|
1648
1575
|
|
|
1649
1576
|
if ( trackNode.isSkinnedMesh === true ) {
|
|
@@ -1667,24 +1594,26 @@
|
|
|
1667
1594
|
|
|
1668
1595
|
const inputItemSize = 1;
|
|
1669
1596
|
let outputItemSize = track.values.length / track.times.length;
|
|
1670
|
-
|
|
1671
1597
|
if ( trackProperty === PATH_PROPERTIES.morphTargetInfluences ) {
|
|
1672
1598
|
|
|
1673
1599
|
outputItemSize /= trackNode.morphTargetInfluences.length;
|
|
1674
1600
|
|
|
1675
1601
|
}
|
|
1676
1602
|
|
|
1677
|
-
let interpolation;
|
|
1603
|
+
let interpolation;
|
|
1604
|
+
|
|
1605
|
+
// @TODO export CubicInterpolant(InterpolateSmooth) as CUBICSPLINE
|
|
1606
|
+
|
|
1678
1607
|
// Detecting glTF cubic spline interpolant by checking factory method's special property
|
|
1679
1608
|
// GLTFCubicSplineInterpolant is a custom interpolant and track doesn't return
|
|
1680
1609
|
// valid value from .getInterpolation().
|
|
1681
|
-
|
|
1682
1610
|
if ( track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === true ) {
|
|
1683
1611
|
|
|
1684
|
-
interpolation = 'CUBICSPLINE';
|
|
1612
|
+
interpolation = 'CUBICSPLINE';
|
|
1613
|
+
|
|
1614
|
+
// itemSize of CUBICSPLINE keyframe is 9
|
|
1685
1615
|
// (VEC3 * 3: inTangent, splineVertex, and outTangent)
|
|
1686
1616
|
// but needs to be stored as VEC3 so dividing by 3 here.
|
|
1687
|
-
|
|
1688
1617
|
outputItemSize /= 3;
|
|
1689
1618
|
|
|
1690
1619
|
} else if ( track.getInterpolation() === THREE.InterpolateDiscrete ) {
|
|
@@ -1720,12 +1649,11 @@
|
|
|
1720
1649
|
return json.animations.length - 1;
|
|
1721
1650
|
|
|
1722
1651
|
}
|
|
1652
|
+
|
|
1723
1653
|
/**
|
|
1724
1654
|
* @param {THREE.Object3D} object
|
|
1725
1655
|
* @return {number|null}
|
|
1726
1656
|
*/
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
1657
|
processSkin( object ) {
|
|
1730
1658
|
|
|
1731
1659
|
const json = this.json;
|
|
@@ -1738,7 +1666,6 @@
|
|
|
1738
1666
|
const joints = [];
|
|
1739
1667
|
const inverseBindMatrices = new Float32Array( skeleton.bones.length * 16 );
|
|
1740
1668
|
const temporaryBoneInverse = new THREE.Matrix4();
|
|
1741
|
-
|
|
1742
1669
|
for ( let i = 0; i < skeleton.bones.length; ++ i ) {
|
|
1743
1670
|
|
|
1744
1671
|
joints.push( nodeMap.get( skeleton.bones[ i ] ) );
|
|
@@ -1757,13 +1684,12 @@
|
|
|
1757
1684
|
return skinIndex;
|
|
1758
1685
|
|
|
1759
1686
|
}
|
|
1687
|
+
|
|
1760
1688
|
/**
|
|
1761
1689
|
* Process Object3D node
|
|
1762
1690
|
* @param {THREE.Object3D} node Object3D to processNode
|
|
1763
1691
|
* @return {Integer} Index of the node in the nodes list
|
|
1764
1692
|
*/
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
1693
|
processNode( object ) {
|
|
1768
1694
|
|
|
1769
1695
|
const json = this.json;
|
|
@@ -1771,13 +1697,11 @@
|
|
|
1771
1697
|
const nodeMap = this.nodeMap;
|
|
1772
1698
|
if ( ! json.nodes ) json.nodes = [];
|
|
1773
1699
|
const nodeDef = {};
|
|
1774
|
-
|
|
1775
1700
|
if ( options.trs ) {
|
|
1776
1701
|
|
|
1777
1702
|
const rotation = object.quaternion.toArray();
|
|
1778
1703
|
const position = object.position.toArray();
|
|
1779
1704
|
const scale = object.scale.toArray();
|
|
1780
|
-
|
|
1781
1705
|
if ( ! equalArray( rotation, [ 0, 0, 0, 1 ] ) ) {
|
|
1782
1706
|
|
|
1783
1707
|
nodeDef.rotation = rotation;
|
|
@@ -1810,12 +1734,11 @@
|
|
|
1810
1734
|
|
|
1811
1735
|
}
|
|
1812
1736
|
|
|
1813
|
-
}
|
|
1814
|
-
|
|
1737
|
+
}
|
|
1815
1738
|
|
|
1739
|
+
// We don't export empty strings name because it represents no-name in Three.js.
|
|
1816
1740
|
if ( object.name !== '' ) nodeDef.name = String( object.name );
|
|
1817
1741
|
this.serializeUserData( object, nodeDef );
|
|
1818
|
-
|
|
1819
1742
|
if ( object.isMesh || object.isLine || object.isPoints ) {
|
|
1820
1743
|
|
|
1821
1744
|
const meshIndex = this.processMesh( object );
|
|
@@ -1828,15 +1751,12 @@
|
|
|
1828
1751
|
}
|
|
1829
1752
|
|
|
1830
1753
|
if ( object.isSkinnedMesh ) this.skins.push( object );
|
|
1831
|
-
|
|
1832
1754
|
if ( object.children.length > 0 ) {
|
|
1833
1755
|
|
|
1834
1756
|
const children = [];
|
|
1835
|
-
|
|
1836
1757
|
for ( let i = 0, l = object.children.length; i < l; i ++ ) {
|
|
1837
1758
|
|
|
1838
1759
|
const child = object.children[ i ];
|
|
1839
|
-
|
|
1840
1760
|
if ( child.visible || options.onlyVisible === false ) {
|
|
1841
1761
|
|
|
1842
1762
|
const nodeIndex = this.processNode( child );
|
|
@@ -1855,23 +1775,20 @@
|
|
|
1855
1775
|
ext.writeNode && ext.writeNode( object, nodeDef );
|
|
1856
1776
|
|
|
1857
1777
|
} );
|
|
1858
|
-
|
|
1859
1778
|
const nodeIndex = json.nodes.push( nodeDef ) - 1;
|
|
1860
1779
|
nodeMap.set( object, nodeIndex );
|
|
1861
1780
|
return nodeIndex;
|
|
1862
1781
|
|
|
1863
1782
|
}
|
|
1783
|
+
|
|
1864
1784
|
/**
|
|
1865
1785
|
* Process THREE.Scene
|
|
1866
1786
|
* @param {Scene} node THREE.Scene to process
|
|
1867
1787
|
*/
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
1788
|
processScene( scene ) {
|
|
1871
1789
|
|
|
1872
1790
|
const json = this.json;
|
|
1873
1791
|
const options = this.options;
|
|
1874
|
-
|
|
1875
1792
|
if ( ! json.scenes ) {
|
|
1876
1793
|
|
|
1877
1794
|
json.scenes = [];
|
|
@@ -1883,11 +1800,9 @@
|
|
|
1883
1800
|
if ( scene.name !== '' ) sceneDef.name = scene.name;
|
|
1884
1801
|
json.scenes.push( sceneDef );
|
|
1885
1802
|
const nodes = [];
|
|
1886
|
-
|
|
1887
1803
|
for ( let i = 0, l = scene.children.length; i < l; i ++ ) {
|
|
1888
1804
|
|
|
1889
1805
|
const child = scene.children[ i ];
|
|
1890
|
-
|
|
1891
1806
|
if ( child.visible || options.onlyVisible === false ) {
|
|
1892
1807
|
|
|
1893
1808
|
const nodeIndex = this.processNode( child );
|
|
@@ -1901,17 +1816,15 @@
|
|
|
1901
1816
|
this.serializeUserData( scene, sceneDef );
|
|
1902
1817
|
|
|
1903
1818
|
}
|
|
1819
|
+
|
|
1904
1820
|
/**
|
|
1905
1821
|
* Creates a THREE.Scene to hold a list of objects and parse it
|
|
1906
1822
|
* @param {Array} objects List of objects to process
|
|
1907
1823
|
*/
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
1824
|
processObjects( objects ) {
|
|
1911
1825
|
|
|
1912
1826
|
const scene = new THREE.Scene();
|
|
1913
1827
|
scene.name = 'AuxScene';
|
|
1914
|
-
|
|
1915
1828
|
for ( let i = 0; i < objects.length; i ++ ) {
|
|
1916
1829
|
|
|
1917
1830
|
// We push directly to children instead of calling `add` to prevent
|
|
@@ -1923,24 +1836,20 @@
|
|
|
1923
1836
|
this.processScene( scene );
|
|
1924
1837
|
|
|
1925
1838
|
}
|
|
1839
|
+
|
|
1926
1840
|
/**
|
|
1927
1841
|
* @param {THREE.Object3D|Array<THREE.Object3D>} input
|
|
1928
1842
|
*/
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
1843
|
processInput( input ) {
|
|
1932
1844
|
|
|
1933
1845
|
const options = this.options;
|
|
1934
1846
|
input = input instanceof Array ? input : [ input ];
|
|
1935
|
-
|
|
1936
1847
|
this._invokeAll( function ( ext ) {
|
|
1937
1848
|
|
|
1938
1849
|
ext.beforeParse && ext.beforeParse( input );
|
|
1939
1850
|
|
|
1940
1851
|
} );
|
|
1941
|
-
|
|
1942
1852
|
const objectsWithoutScene = [];
|
|
1943
|
-
|
|
1944
1853
|
for ( let i = 0; i < input.length; i ++ ) {
|
|
1945
1854
|
|
|
1946
1855
|
if ( input[ i ] instanceof THREE.Scene ) {
|
|
@@ -1956,7 +1865,6 @@
|
|
|
1956
1865
|
}
|
|
1957
1866
|
|
|
1958
1867
|
if ( objectsWithoutScene.length > 0 ) this.processObjects( objectsWithoutScene );
|
|
1959
|
-
|
|
1960
1868
|
for ( let i = 0; i < this.skins.length; ++ i ) {
|
|
1961
1869
|
|
|
1962
1870
|
this.processSkin( this.skins[ i ] );
|
|
@@ -1976,7 +1884,6 @@
|
|
|
1976
1884
|
} );
|
|
1977
1885
|
|
|
1978
1886
|
}
|
|
1979
|
-
|
|
1980
1887
|
_invokeAll( func ) {
|
|
1981
1888
|
|
|
1982
1889
|
for ( let i = 0, il = this.plugins.length; i < il; i ++ ) {
|
|
@@ -1988,13 +1895,12 @@
|
|
|
1988
1895
|
}
|
|
1989
1896
|
|
|
1990
1897
|
}
|
|
1898
|
+
|
|
1991
1899
|
/**
|
|
1992
1900
|
* Punctual Lights Extension
|
|
1993
1901
|
*
|
|
1994
1902
|
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
|
|
1995
1903
|
*/
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
1904
|
class GLTFLightExtension {
|
|
1999
1905
|
|
|
2000
1906
|
constructor( writer ) {
|
|
@@ -2003,11 +1909,9 @@
|
|
|
2003
1909
|
this.name = 'KHR_lights_punctual';
|
|
2004
1910
|
|
|
2005
1911
|
}
|
|
2006
|
-
|
|
2007
1912
|
writeNode( light, nodeDef ) {
|
|
2008
1913
|
|
|
2009
1914
|
if ( ! light.isLight ) return;
|
|
2010
|
-
|
|
2011
1915
|
if ( ! light.isDirectionalLight && ! light.isPointLight && ! light.isSpotLight ) {
|
|
2012
1916
|
|
|
2013
1917
|
console.warn( 'THREE.GLTFExporter: Only directional, point, and spot lights are supported.', light );
|
|
@@ -2022,7 +1926,6 @@
|
|
|
2022
1926
|
if ( light.name ) lightDef.name = light.name;
|
|
2023
1927
|
lightDef.color = light.color.toArray();
|
|
2024
1928
|
lightDef.intensity = light.intensity;
|
|
2025
|
-
|
|
2026
1929
|
if ( light.isDirectionalLight ) {
|
|
2027
1930
|
|
|
2028
1931
|
lightDef.type = 'directional';
|
|
@@ -2074,13 +1977,12 @@
|
|
|
2074
1977
|
}
|
|
2075
1978
|
|
|
2076
1979
|
}
|
|
1980
|
+
|
|
2077
1981
|
/**
|
|
2078
1982
|
* Unlit Materials Extension
|
|
2079
1983
|
*
|
|
2080
1984
|
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
|
|
2081
1985
|
*/
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
1986
|
class GLTFMaterialsUnlitExtension {
|
|
2085
1987
|
|
|
2086
1988
|
constructor( writer ) {
|
|
@@ -2089,7 +1991,6 @@
|
|
|
2089
1991
|
this.name = 'KHR_materials_unlit';
|
|
2090
1992
|
|
|
2091
1993
|
}
|
|
2092
|
-
|
|
2093
1994
|
writeMaterial( material, materialDef ) {
|
|
2094
1995
|
|
|
2095
1996
|
if ( ! material.isMeshBasicMaterial ) return;
|
|
@@ -2104,70 +2005,12 @@
|
|
|
2104
2005
|
}
|
|
2105
2006
|
|
|
2106
2007
|
}
|
|
2107
|
-
/**
|
|
2108
|
-
* Specular-Glossiness Extension
|
|
2109
|
-
*
|
|
2110
|
-
* Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness
|
|
2111
|
-
*/
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
class GLTFMaterialsPBRSpecularGlossiness {
|
|
2115
2008
|
|
|
2116
|
-
constructor( writer ) {
|
|
2117
|
-
|
|
2118
|
-
this.writer = writer;
|
|
2119
|
-
this.name = 'KHR_materials_pbrSpecularGlossiness';
|
|
2120
|
-
|
|
2121
|
-
}
|
|
2122
|
-
|
|
2123
|
-
writeMaterial( material, materialDef ) {
|
|
2124
|
-
|
|
2125
|
-
if ( ! material.isGLTFSpecularGlossinessMaterial ) return;
|
|
2126
|
-
const writer = this.writer;
|
|
2127
|
-
const extensionsUsed = writer.extensionsUsed;
|
|
2128
|
-
const extensionDef = {};
|
|
2129
|
-
|
|
2130
|
-
if ( materialDef.pbrMetallicRoughness.baseColorFactor ) {
|
|
2131
|
-
|
|
2132
|
-
extensionDef.diffuseFactor = materialDef.pbrMetallicRoughness.baseColorFactor;
|
|
2133
|
-
|
|
2134
|
-
}
|
|
2135
|
-
|
|
2136
|
-
const specularFactor = [ 1, 1, 1 ];
|
|
2137
|
-
material.specular.toArray( specularFactor, 0 );
|
|
2138
|
-
extensionDef.specularFactor = specularFactor;
|
|
2139
|
-
extensionDef.glossinessFactor = material.glossiness;
|
|
2140
|
-
|
|
2141
|
-
if ( materialDef.pbrMetallicRoughness.baseColorTexture ) {
|
|
2142
|
-
|
|
2143
|
-
extensionDef.diffuseTexture = materialDef.pbrMetallicRoughness.baseColorTexture;
|
|
2144
|
-
|
|
2145
|
-
}
|
|
2146
|
-
|
|
2147
|
-
if ( material.specularMap ) {
|
|
2148
|
-
|
|
2149
|
-
const specularMapDef = {
|
|
2150
|
-
index: writer.processTexture( material.specularMap )
|
|
2151
|
-
};
|
|
2152
|
-
writer.applyTextureTransform( specularMapDef, material.specularMap );
|
|
2153
|
-
extensionDef.specularGlossinessTexture = specularMapDef;
|
|
2154
|
-
|
|
2155
|
-
}
|
|
2156
|
-
|
|
2157
|
-
materialDef.extensions = materialDef.extensions || {};
|
|
2158
|
-
materialDef.extensions[ this.name ] = extensionDef;
|
|
2159
|
-
extensionsUsed[ this.name ] = true;
|
|
2160
|
-
|
|
2161
|
-
}
|
|
2162
|
-
|
|
2163
|
-
}
|
|
2164
2009
|
/**
|
|
2165
2010
|
* Clearcoat Materials Extension
|
|
2166
2011
|
*
|
|
2167
2012
|
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat
|
|
2168
2013
|
*/
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
2014
|
class GLTFMaterialsClearcoatExtension {
|
|
2172
2015
|
|
|
2173
2016
|
constructor( writer ) {
|
|
@@ -2176,7 +2019,6 @@
|
|
|
2176
2019
|
this.name = 'KHR_materials_clearcoat';
|
|
2177
2020
|
|
|
2178
2021
|
}
|
|
2179
|
-
|
|
2180
2022
|
writeMaterial( material, materialDef ) {
|
|
2181
2023
|
|
|
2182
2024
|
if ( ! material.isMeshPhysicalMaterial ) return;
|
|
@@ -2184,7 +2026,6 @@
|
|
|
2184
2026
|
const extensionsUsed = writer.extensionsUsed;
|
|
2185
2027
|
const extensionDef = {};
|
|
2186
2028
|
extensionDef.clearcoatFactor = material.clearcoat;
|
|
2187
|
-
|
|
2188
2029
|
if ( material.clearcoatMap ) {
|
|
2189
2030
|
|
|
2190
2031
|
const clearcoatMapDef = {
|
|
@@ -2196,7 +2037,6 @@
|
|
|
2196
2037
|
}
|
|
2197
2038
|
|
|
2198
2039
|
extensionDef.clearcoatRoughnessFactor = material.clearcoatRoughness;
|
|
2199
|
-
|
|
2200
2040
|
if ( material.clearcoatRoughnessMap ) {
|
|
2201
2041
|
|
|
2202
2042
|
const clearcoatRoughnessMapDef = {
|
|
@@ -2224,13 +2064,12 @@
|
|
|
2224
2064
|
}
|
|
2225
2065
|
|
|
2226
2066
|
}
|
|
2067
|
+
|
|
2227
2068
|
/**
|
|
2228
2069
|
* Iridescence Materials Extension
|
|
2229
2070
|
*
|
|
2230
2071
|
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_iridescence
|
|
2231
2072
|
*/
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
2073
|
class GLTFMaterialsIridescenceExtension {
|
|
2235
2074
|
|
|
2236
2075
|
constructor( writer ) {
|
|
@@ -2239,7 +2078,6 @@
|
|
|
2239
2078
|
this.name = 'KHR_materials_iridescence';
|
|
2240
2079
|
|
|
2241
2080
|
}
|
|
2242
|
-
|
|
2243
2081
|
writeMaterial( material, materialDef ) {
|
|
2244
2082
|
|
|
2245
2083
|
if ( ! material.isMeshPhysicalMaterial ) return;
|
|
@@ -2247,7 +2085,6 @@
|
|
|
2247
2085
|
const extensionsUsed = writer.extensionsUsed;
|
|
2248
2086
|
const extensionDef = {};
|
|
2249
2087
|
extensionDef.iridescenceFactor = material.iridescence;
|
|
2250
|
-
|
|
2251
2088
|
if ( material.iridescenceMap ) {
|
|
2252
2089
|
|
|
2253
2090
|
const iridescenceMapDef = {
|
|
@@ -2261,7 +2098,6 @@
|
|
|
2261
2098
|
extensionDef.iridescenceIor = material.iridescenceIOR;
|
|
2262
2099
|
extensionDef.iridescenceThicknessMinimum = material.iridescenceThicknessRange[ 0 ];
|
|
2263
2100
|
extensionDef.iridescenceThicknessMaximum = material.iridescenceThicknessRange[ 1 ];
|
|
2264
|
-
|
|
2265
2101
|
if ( material.iridescenceThicknessMap ) {
|
|
2266
2102
|
|
|
2267
2103
|
const iridescenceThicknessMapDef = {
|
|
@@ -2279,13 +2115,12 @@
|
|
|
2279
2115
|
}
|
|
2280
2116
|
|
|
2281
2117
|
}
|
|
2118
|
+
|
|
2282
2119
|
/**
|
|
2283
2120
|
* Transmission Materials Extension
|
|
2284
2121
|
*
|
|
2285
2122
|
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission
|
|
2286
2123
|
*/
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
2124
|
class GLTFMaterialsTransmissionExtension {
|
|
2290
2125
|
|
|
2291
2126
|
constructor( writer ) {
|
|
@@ -2294,7 +2129,6 @@
|
|
|
2294
2129
|
this.name = 'KHR_materials_transmission';
|
|
2295
2130
|
|
|
2296
2131
|
}
|
|
2297
|
-
|
|
2298
2132
|
writeMaterial( material, materialDef ) {
|
|
2299
2133
|
|
|
2300
2134
|
if ( ! material.isMeshPhysicalMaterial || material.transmission === 0 ) return;
|
|
@@ -2302,7 +2136,6 @@
|
|
|
2302
2136
|
const extensionsUsed = writer.extensionsUsed;
|
|
2303
2137
|
const extensionDef = {};
|
|
2304
2138
|
extensionDef.transmissionFactor = material.transmission;
|
|
2305
|
-
|
|
2306
2139
|
if ( material.transmissionMap ) {
|
|
2307
2140
|
|
|
2308
2141
|
const transmissionMapDef = {
|
|
@@ -2320,13 +2153,12 @@
|
|
|
2320
2153
|
}
|
|
2321
2154
|
|
|
2322
2155
|
}
|
|
2156
|
+
|
|
2323
2157
|
/**
|
|
2324
2158
|
* Materials Volume Extension
|
|
2325
2159
|
*
|
|
2326
2160
|
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume
|
|
2327
2161
|
*/
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
2162
|
class GLTFMaterialsVolumeExtension {
|
|
2331
2163
|
|
|
2332
2164
|
constructor( writer ) {
|
|
@@ -2335,7 +2167,6 @@
|
|
|
2335
2167
|
this.name = 'KHR_materials_volume';
|
|
2336
2168
|
|
|
2337
2169
|
}
|
|
2338
|
-
|
|
2339
2170
|
writeMaterial( material, materialDef ) {
|
|
2340
2171
|
|
|
2341
2172
|
if ( ! material.isMeshPhysicalMaterial || material.transmission === 0 ) return;
|
|
@@ -2343,7 +2174,6 @@
|
|
|
2343
2174
|
const extensionsUsed = writer.extensionsUsed;
|
|
2344
2175
|
const extensionDef = {};
|
|
2345
2176
|
extensionDef.thicknessFactor = material.thickness;
|
|
2346
|
-
|
|
2347
2177
|
if ( material.thicknessMap ) {
|
|
2348
2178
|
|
|
2349
2179
|
const thicknessMapDef = {
|
|
@@ -2363,26 +2193,22 @@
|
|
|
2363
2193
|
}
|
|
2364
2194
|
|
|
2365
2195
|
}
|
|
2196
|
+
|
|
2366
2197
|
/**
|
|
2367
2198
|
* Static utility functions
|
|
2368
2199
|
*/
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
2200
|
GLTFExporter.Utils = {
|
|
2372
2201
|
insertKeyframe: function ( track, time ) {
|
|
2373
2202
|
|
|
2374
2203
|
const tolerance = 0.001; // 1ms
|
|
2375
|
-
|
|
2376
2204
|
const valueSize = track.getValueSize();
|
|
2377
2205
|
const times = new track.TimeBufferType( track.times.length + 1 );
|
|
2378
2206
|
const values = new track.ValueBufferType( track.values.length + valueSize );
|
|
2379
2207
|
const interpolant = track.createInterpolant( new track.ValueBufferType( valueSize ) );
|
|
2380
2208
|
let index;
|
|
2381
|
-
|
|
2382
2209
|
if ( track.times.length === 0 ) {
|
|
2383
2210
|
|
|
2384
2211
|
times[ 0 ] = time;
|
|
2385
|
-
|
|
2386
2212
|
for ( let i = 0; i < valueSize; i ++ ) {
|
|
2387
2213
|
|
|
2388
2214
|
values[ i ] = 0;
|
|
@@ -2419,7 +2245,6 @@
|
|
|
2419
2245
|
for ( let i = 0; i < track.times.length; i ++ ) {
|
|
2420
2246
|
|
|
2421
2247
|
if ( Math.abs( track.times[ i ] - time ) < tolerance ) return i;
|
|
2422
|
-
|
|
2423
2248
|
if ( track.times[ i ] < time && track.times[ i + 1 ] > time ) {
|
|
2424
2249
|
|
|
2425
2250
|
times.set( track.times.slice( 0, i + 1 ), 0 );
|
|
@@ -2447,13 +2272,11 @@
|
|
|
2447
2272
|
const tracks = [];
|
|
2448
2273
|
const mergedTracks = {};
|
|
2449
2274
|
const sourceTracks = clip.tracks;
|
|
2450
|
-
|
|
2451
2275
|
for ( let i = 0; i < sourceTracks.length; ++ i ) {
|
|
2452
2276
|
|
|
2453
2277
|
let sourceTrack = sourceTracks[ i ];
|
|
2454
2278
|
const sourceTrackBinding = THREE.PropertyBinding.parseTrackName( sourceTrack.name );
|
|
2455
2279
|
const sourceTrackNode = THREE.PropertyBinding.findNode( root, sourceTrackBinding.nodeName );
|
|
2456
|
-
|
|
2457
2280
|
if ( sourceTrackBinding.propertyName !== 'morphTargetInfluences' || sourceTrackBinding.propertyIndex === undefined ) {
|
|
2458
2281
|
|
|
2459
2282
|
// Tracks that don't affect morph targets, or that affect all morph targets together, can be left as-is.
|
|
@@ -2480,29 +2303,28 @@
|
|
|
2480
2303
|
|
|
2481
2304
|
const targetCount = sourceTrackNode.morphTargetInfluences.length;
|
|
2482
2305
|
const targetIndex = sourceTrackNode.morphTargetDictionary[ sourceTrackBinding.propertyIndex ];
|
|
2483
|
-
|
|
2484
2306
|
if ( targetIndex === undefined ) {
|
|
2485
2307
|
|
|
2486
2308
|
throw new Error( 'THREE.GLTFExporter: Morph target name not found: ' + sourceTrackBinding.propertyIndex );
|
|
2487
2309
|
|
|
2488
2310
|
}
|
|
2489
2311
|
|
|
2490
|
-
let mergedTrack;
|
|
2491
|
-
// track to store merged keyframe data for each morph target.
|
|
2312
|
+
let mergedTrack;
|
|
2492
2313
|
|
|
2314
|
+
// If this is the first time we've seen this object, create a new
|
|
2315
|
+
// track to store merged keyframe data for each morph target.
|
|
2493
2316
|
if ( mergedTracks[ sourceTrackNode.uuid ] === undefined ) {
|
|
2494
2317
|
|
|
2495
2318
|
mergedTrack = sourceTrack.clone();
|
|
2496
2319
|
const values = new mergedTrack.ValueBufferType( targetCount * mergedTrack.times.length );
|
|
2497
|
-
|
|
2498
2320
|
for ( let j = 0; j < mergedTrack.times.length; j ++ ) {
|
|
2499
2321
|
|
|
2500
2322
|
values[ j * targetCount + targetIndex ] = mergedTrack.values[ j ];
|
|
2501
2323
|
|
|
2502
|
-
}
|
|
2503
|
-
// of our original un-merged morphTarget animation.
|
|
2504
|
-
|
|
2324
|
+
}
|
|
2505
2325
|
|
|
2326
|
+
// We need to take into consideration the intended target node
|
|
2327
|
+
// of our original un-merged morphTarget animation.
|
|
2506
2328
|
mergedTrack.name = ( sourceTrackBinding.nodeName || '' ) + '.morphTargetInfluences';
|
|
2507
2329
|
mergedTrack.values = values;
|
|
2508
2330
|
mergedTracks[ sourceTrackNode.uuid ] = mergedTrack;
|
|
@@ -2512,18 +2334,19 @@
|
|
|
2512
2334
|
}
|
|
2513
2335
|
|
|
2514
2336
|
const sourceInterpolant = sourceTrack.createInterpolant( new sourceTrack.ValueBufferType( 1 ) );
|
|
2515
|
-
mergedTrack = mergedTracks[ sourceTrackNode.uuid ];
|
|
2516
|
-
// interpolated) value from the source track.
|
|
2337
|
+
mergedTrack = mergedTracks[ sourceTrackNode.uuid ];
|
|
2517
2338
|
|
|
2339
|
+
// For every existing keyframe of the merged track, write a (possibly
|
|
2340
|
+
// interpolated) value from the source track.
|
|
2518
2341
|
for ( let j = 0; j < mergedTrack.times.length; j ++ ) {
|
|
2519
2342
|
|
|
2520
2343
|
mergedTrack.values[ j * targetCount + targetIndex ] = sourceInterpolant.evaluate( mergedTrack.times[ j ] );
|
|
2521
2344
|
|
|
2522
|
-
}
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
// For every existing keyframe of the source track, write a (possibly
|
|
2523
2348
|
// new) keyframe to the merged track. Values from the previous loop may
|
|
2524
2349
|
// be written again, but keyframes are de-duplicated.
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
2350
|
for ( let j = 0; j < sourceTrack.times.length; j ++ ) {
|
|
2528
2351
|
|
|
2529
2352
|
const keyframeIndex = this.insertKeyframe( mergedTrack, sourceTrack.times[ j ] );
|