three-stdlib 2.25.0 → 2.26.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/controls/OrbitControls.d.ts +1 -0
- package/index.cjs +116465 -611
- package/index.js +116101 -263
- package/package.json +17 -4
- package/_polyfill/CapsuleGeometry.cjs +0 -22
- package/_polyfill/CapsuleGeometry.js +0 -22
- package/_polyfill/CompressedArrayTexture.cjs +0 -12
- package/_polyfill/CompressedArrayTexture.js +0 -12
- package/_polyfill/Data3DTexture.cjs +0 -17
- package/_polyfill/Data3DTexture.js +0 -17
- package/animation/AnimationClipCreator.cjs +0 -56
- package/animation/AnimationClipCreator.js +0 -56
- package/animation/CCDIKSolver.cjs +0 -269
- package/animation/CCDIKSolver.js +0 -269
- package/animation/MMDAnimationHelper.cjs +0 -688
- package/animation/MMDAnimationHelper.js +0 -688
- package/animation/MMDPhysics.cjs +0 -830
- package/animation/MMDPhysics.js +0 -830
- package/cameras/CinematicCamera.cjs +0 -131
- package/cameras/CinematicCamera.js +0 -131
- package/controls/ArcballControls.cjs +0 -2033
- package/controls/ArcballControls.js +0 -2033
- package/controls/DeviceOrientationControls.cjs +0 -85
- package/controls/DeviceOrientationControls.js +0 -85
- package/controls/DragControls.cjs +0 -182
- package/controls/DragControls.js +0 -182
- package/controls/FirstPersonControls.cjs +0 -229
- package/controls/FirstPersonControls.js +0 -229
- package/controls/FlyControls.cjs +0 -248
- package/controls/FlyControls.js +0 -248
- package/controls/OrbitControls.cjs +0 -791
- package/controls/OrbitControls.js +0 -791
- package/controls/PointerLockControls.cjs +0 -103
- package/controls/PointerLockControls.js +0 -103
- package/controls/TrackballControls.cjs +0 -502
- package/controls/TrackballControls.js +0 -502
- package/controls/TransformControls.cjs +0 -1089
- package/controls/TransformControls.js +0 -1089
- package/controls/experimental/CameraControls.cjs +0 -736
- package/controls/experimental/CameraControls.js +0 -736
- package/csm/CSM.cjs +0 -244
- package/csm/CSM.js +0 -244
- package/csm/CSMFrustum.cjs +0 -75
- package/csm/CSMFrustum.js +0 -75
- package/csm/CSMHelper.cjs +0 -114
- package/csm/CSMHelper.js +0 -114
- package/csm/CSMShader.cjs +0 -261
- package/csm/CSMShader.js +0 -261
- package/curves/CurveExtras.cjs +0 -214
- package/curves/CurveExtras.js +0 -214
- package/curves/NURBSCurve.cjs +0 -35
- package/curves/NURBSCurve.js +0 -35
- package/curves/NURBSSurface.cjs +0 -28
- package/curves/NURBSSurface.js +0 -28
- package/curves/NURBSUtils.cjs +0 -226
- package/curves/NURBSUtils.js +0 -226
- package/deprecated/Geometry.cjs +0 -971
- package/deprecated/Geometry.js +0 -971
- package/effects/AnaglyphEffect.cjs +0 -102
- package/effects/AnaglyphEffect.js +0 -102
- package/effects/AsciiEffect.cjs +0 -155
- package/effects/AsciiEffect.js +0 -155
- package/effects/OutlineEffect.cjs +0 -275
- package/effects/OutlineEffect.js +0 -275
- package/effects/ParallaxBarrierEffect.cjs +0 -65
- package/effects/ParallaxBarrierEffect.js +0 -65
- package/effects/PeppersGhostEffect.cjs +0 -88
- package/effects/PeppersGhostEffect.js +0 -88
- package/effects/StereoEffect.cjs +0 -35
- package/effects/StereoEffect.js +0 -35
- package/environments/RoomEnvironment.cjs +0 -95
- package/environments/RoomEnvironment.js +0 -78
- package/exporters/ColladaExporter.cjs +0 -331
- package/exporters/ColladaExporter.js +0 -331
- package/exporters/DRACOExporter.cjs +0 -141
- package/exporters/DRACOExporter.js +0 -141
- package/exporters/GLTFExporter.cjs +0 -1909
- package/exporters/GLTFExporter.js +0 -1909
- package/exporters/MMDExporter.cjs +0 -131
- package/exporters/MMDExporter.js +0 -131
- package/exporters/OBJExporter.cjs +0 -181
- package/exporters/OBJExporter.js +0 -181
- package/exporters/PLYExporter.cjs +0 -280
- package/exporters/PLYExporter.js +0 -280
- package/exporters/STLExporter.cjs +0 -146
- package/exporters/STLExporter.js +0 -146
- package/exporters/USDZExporter.cjs +0 -340
- package/exporters/USDZExporter.js +0 -340
- package/geometries/BoxLineGeometry.cjs +0 -45
- package/geometries/BoxLineGeometry.js +0 -45
- package/geometries/ConvexGeometry.cjs +0 -26
- package/geometries/ConvexGeometry.js +0 -26
- package/geometries/DecalGeometry.cjs +0 -184
- package/geometries/DecalGeometry.js +0 -184
- package/geometries/LightningStrike.cjs +0 -553
- package/geometries/LightningStrike.js +0 -553
- package/geometries/ParametricGeometries.cjs +0 -130
- package/geometries/ParametricGeometries.js +0 -130
- package/geometries/ParametricGeometry.cjs +0 -63
- package/geometries/ParametricGeometry.js +0 -63
- package/geometries/RoundedBoxGeometry.cjs +0 -91
- package/geometries/RoundedBoxGeometry.js +0 -91
- package/geometries/TeapotGeometry.cjs +0 -1563
- package/geometries/TeapotGeometry.js +0 -1563
- package/geometries/TextGeometry.cjs +0 -27
- package/geometries/TextGeometry.js +0 -27
- package/helpers/LightProbeHelper.cjs +0 -73
- package/helpers/LightProbeHelper.js +0 -73
- package/helpers/PositionalAudioHelper.cjs +0 -68
- package/helpers/PositionalAudioHelper.js +0 -68
- package/helpers/RectAreaLightHelper.cjs +0 -44
- package/helpers/RectAreaLightHelper.js +0 -44
- package/helpers/VertexNormalsHelper.cjs +0 -47
- package/helpers/VertexNormalsHelper.js +0 -47
- package/helpers/VertexTangentsHelper.cjs +0 -43
- package/helpers/VertexTangentsHelper.js +0 -43
- package/interactive/HTMLMesh.cjs +0 -325
- package/interactive/HTMLMesh.js +0 -325
- package/interactive/InteractiveGroup.cjs +0 -68
- package/interactive/InteractiveGroup.js +0 -68
- package/interactive/SelectionBox.cjs +0 -134
- package/interactive/SelectionBox.js +0 -134
- package/interactive/SelectionHelper.cjs +0 -51
- package/interactive/SelectionHelper.js +0 -51
- package/libs/MeshoptDecoder.cjs +0 -221
- package/libs/MeshoptDecoder.js +0 -221
- package/libs/MotionControllers.cjs +0 -325
- package/libs/MotionControllers.js +0 -325
- package/lights/LightProbeGenerator.cjs +0 -145
- package/lights/LightProbeGenerator.js +0 -145
- package/lights/RectAreaLightUniformsLib.cjs +0 -32846
- package/lights/RectAreaLightUniformsLib.js +0 -32846
- package/lines/Line2.cjs +0 -13
- package/lines/Line2.js +0 -13
- package/lines/LineGeometry.cjs +0 -44
- package/lines/LineGeometry.js +0 -44
- package/lines/LineMaterial.cjs +0 -547
- package/lines/LineMaterial.js +0 -547
- package/lines/LineSegments2.cjs +0 -203
- package/lines/LineSegments2.js +0 -203
- package/lines/LineSegmentsGeometry.cjs +0 -124
- package/lines/LineSegmentsGeometry.js +0 -124
- package/lines/Wireframe.cjs +0 -32
- package/lines/Wireframe.js +0 -32
- package/lines/WireframeGeometry2.cjs +0 -13
- package/lines/WireframeGeometry2.js +0 -13
- package/loaders/3DMLoader.cjs +0 -803
- package/loaders/3DMLoader.js +0 -803
- package/loaders/3MFLoader.cjs +0 -854
- package/loaders/3MFLoader.js +0 -854
- package/loaders/AMFLoader.cjs +0 -284
- package/loaders/AMFLoader.js +0 -284
- package/loaders/AssimpLoader.cjs +0 -1434
- package/loaders/AssimpLoader.js +0 -1434
- package/loaders/BVHLoader.cjs +0 -207
- package/loaders/BVHLoader.js +0 -207
- package/loaders/BasisTextureLoader.cjs +0 -489
- package/loaders/BasisTextureLoader.js +0 -489
- package/loaders/ColladaLoader.cjs +0 -2405
- package/loaders/ColladaLoader.js +0 -2405
- package/loaders/DDSLoader.cjs +0 -148
- package/loaders/DDSLoader.js +0 -148
- package/loaders/DRACOLoader.cjs +0 -341
- package/loaders/DRACOLoader.js +0 -341
- package/loaders/EXRLoader.cjs +0 -1356
- package/loaders/EXRLoader.js +0 -1356
- package/loaders/FBXLoader.cjs +0 -2457
- package/loaders/FBXLoader.js +0 -2457
- package/loaders/FontLoader.cjs +0 -123
- package/loaders/FontLoader.js +0 -123
- package/loaders/GCodeLoader.cjs +0 -141
- package/loaders/GCodeLoader.js +0 -141
- package/loaders/GLTFLoader.cjs +0 -2504
- package/loaders/GLTFLoader.js +0 -2504
- package/loaders/HDRCubeTextureLoader.cjs +0 -75
- package/loaders/HDRCubeTextureLoader.js +0 -75
- package/loaders/KMZLoader.cjs +0 -75
- package/loaders/KMZLoader.js +0 -75
- package/loaders/KTX2Loader.cjs +0 -480
- package/loaders/KTX2Loader.js +0 -480
- package/loaders/KTXLoader.cjs +0 -93
- package/loaders/KTXLoader.js +0 -93
- package/loaders/LDrawLoader.cjs +0 -1424
- package/loaders/LDrawLoader.js +0 -1424
- package/loaders/LUT3dlLoader.cjs +0 -103
- package/loaders/LUT3dlLoader.js +0 -103
- package/loaders/LUTCubeLoader.cjs +0 -107
- package/loaders/LUTCubeLoader.js +0 -107
- package/loaders/LWOLoader.cjs +0 -645
- package/loaders/LWOLoader.js +0 -645
- package/loaders/LottieLoader.cjs +0 -47
- package/loaders/LottieLoader.js +0 -47
- package/loaders/MD2Loader.cjs +0 -359
- package/loaders/MD2Loader.js +0 -359
- package/loaders/MDDLoader.cjs +0 -58
- package/loaders/MDDLoader.js +0 -58
- package/loaders/MMDLoader.cjs +0 -1121
- package/loaders/MMDLoader.js +0 -1121
- package/loaders/MTLLoader.cjs +0 -304
- package/loaders/MTLLoader.js +0 -304
- package/loaders/NRRDLoader.cjs +0 -401
- package/loaders/NRRDLoader.js +0 -401
- package/loaders/OBJLoader.cjs +0 -487
- package/loaders/OBJLoader.js +0 -487
- package/loaders/PCDLoader.cjs +0 -248
- package/loaders/PCDLoader.js +0 -248
- package/loaders/PDBLoader.cjs +0 -247
- package/loaders/PDBLoader.js +0 -247
- package/loaders/PLYLoader.cjs +0 -317
- package/loaders/PLYLoader.js +0 -317
- package/loaders/PRWMLoader.cjs +0 -160
- package/loaders/PRWMLoader.js +0 -160
- package/loaders/PVRLoader.cjs +0 -131
- package/loaders/PVRLoader.js +0 -131
- package/loaders/RGBELoader.cjs +0 -252
- package/loaders/RGBELoader.js +0 -252
- package/loaders/RGBMLoader.cjs +0 -1004
- package/loaders/RGBMLoader.js +0 -1004
- package/loaders/STLLoader.cjs +0 -190
- package/loaders/STLLoader.js +0 -190
- package/loaders/SVGLoader.cjs +0 -1712
- package/loaders/SVGLoader.js +0 -1712
- package/loaders/TDSLoader.cjs +0 -650
- package/loaders/TDSLoader.js +0 -650
- package/loaders/TGALoader.cjs +0 -285
- package/loaders/TGALoader.js +0 -285
- package/loaders/TTFLoader.cjs +0 -131
- package/loaders/TTFLoader.js +0 -131
- package/loaders/TiltLoader.cjs +0 -375
- package/loaders/TiltLoader.js +0 -375
- package/loaders/VOXLoader.cjs +0 -432
- package/loaders/VOXLoader.js +0 -432
- package/loaders/VRMLLoader.cjs +0 -2105
- package/loaders/VRMLLoader.js +0 -2105
- package/loaders/VRMLoader.cjs +0 -38
- package/loaders/VRMLoader.js +0 -38
- package/loaders/VTKLoader.cjs +0 -648
- package/loaders/VTKLoader.js +0 -648
- package/loaders/XLoader.cjs +0 -1258
- package/loaders/XLoader.js +0 -1258
- package/loaders/XYZLoader.cjs +0 -60
- package/loaders/XYZLoader.js +0 -60
- package/loaders/lwo/IFFParser.cjs +0 -743
- package/loaders/lwo/IFFParser.js +0 -743
- package/loaders/lwo/LWO2Parser.cjs +0 -312
- package/loaders/lwo/LWO2Parser.js +0 -312
- package/loaders/lwo/LWO3Parser.cjs +0 -282
- package/loaders/lwo/LWO3Parser.js +0 -282
- package/math/Capsule.cjs +0 -98
- package/math/Capsule.js +0 -98
- package/math/ColorConverter.cjs +0 -42
- package/math/ColorConverter.js +0 -42
- package/math/ConvexHull.cjs +0 -596
- package/math/ConvexHull.js +0 -596
- package/math/ImprovedNoise.cjs +0 -304
- package/math/ImprovedNoise.js +0 -304
- package/math/Lut.cjs +0 -137
- package/math/Lut.js +0 -137
- package/math/MeshSurfaceSampler.cjs +0 -103
- package/math/MeshSurfaceSampler.js +0 -103
- package/math/OBB.cjs +0 -242
- package/math/OBB.js +0 -242
- package/math/Octree.cjs +0 -273
- package/math/Octree.js +0 -273
- package/math/SimplexNoise.cjs +0 -440
- package/math/SimplexNoise.js +0 -440
- package/misc/ConvexObjectBreaker.cjs +0 -292
- package/misc/ConvexObjectBreaker.js +0 -292
- package/misc/GPUComputationRenderer.cjs +0 -205
- package/misc/GPUComputationRenderer.js +0 -205
- package/misc/Gyroscope.cjs +0 -33
- package/misc/Gyroscope.js +0 -33
- package/misc/MD2Character.cjs +0 -167
- package/misc/MD2Character.js +0 -167
- package/misc/MD2CharacterComplex.cjs +0 -332
- package/misc/MD2CharacterComplex.js +0 -332
- package/misc/MorphAnimMesh.cjs +0 -40
- package/misc/MorphAnimMesh.js +0 -40
- package/misc/MorphBlendMesh.cjs +0 -179
- package/misc/MorphBlendMesh.js +0 -179
- package/misc/ProgressiveLightmap.cjs +0 -186
- package/misc/ProgressiveLightmap.js +0 -186
- package/misc/RollerCoaster.cjs +0 -353
- package/misc/RollerCoaster.js +0 -353
- package/misc/Timer.cjs +0 -101
- package/misc/Timer.js +0 -101
- package/misc/TubePainter.cjs +0 -123
- package/misc/TubePainter.js +0 -123
- package/misc/Volume.cjs +0 -305
- package/misc/Volume.js +0 -305
- package/misc/VolumeSlice.cjs +0 -114
- package/misc/VolumeSlice.js +0 -114
- package/misc/WebGL.cjs +0 -74
- package/misc/WebGL.js +0 -74
- package/modifiers/CurveModifier.cjs +0 -232
- package/modifiers/CurveModifier.js +0 -232
- package/modifiers/EdgeSplitModifier.cjs +0 -167
- package/modifiers/EdgeSplitModifier.js +0 -168
- package/modifiers/SimplifyModifier.cjs +0 -301
- package/modifiers/SimplifyModifier.js +0 -301
- package/modifiers/TessellateModifier.cjs +0 -214
- package/modifiers/TessellateModifier.js +0 -214
- package/objects/GroundProjectedEnv.cjs +0 -134
- package/objects/GroundProjectedEnv.js +0 -134
- package/objects/Lensflare.cjs +0 -291
- package/objects/Lensflare.js +0 -291
- package/objects/LightningStorm.cjs +0 -110
- package/objects/LightningStorm.js +0 -110
- package/objects/MarchingCubes.cjs +0 -4809
- package/objects/MarchingCubes.js +0 -4809
- package/objects/Reflector.cjs +0 -202
- package/objects/Reflector.js +0 -202
- package/objects/ReflectorForSSRPass.cjs +0 -260
- package/objects/ReflectorForSSRPass.js +0 -260
- package/objects/ReflectorRTT.cjs +0 -10
- package/objects/ReflectorRTT.js +0 -10
- package/objects/Refractor.cjs +0 -215
- package/objects/Refractor.js +0 -215
- package/objects/ShadowMesh.cjs +0 -45
- package/objects/ShadowMesh.js +0 -45
- package/objects/Sky.cjs +0 -200
- package/objects/Sky.js +0 -200
- package/objects/Water.cjs +0 -242
- package/objects/Water.js +0 -242
- package/objects/Water2.cjs +0 -256
- package/objects/Water2.js +0 -256
- package/physics/AmmoPhysics.cjs +0 -166
- package/physics/AmmoPhysics.js +0 -166
- package/postprocessing/AdaptiveToneMappingPass.cjs +0 -218
- package/postprocessing/AdaptiveToneMappingPass.js +0 -218
- package/postprocessing/AfterimagePass.cjs +0 -68
- package/postprocessing/AfterimagePass.js +0 -68
- package/postprocessing/BloomPass.cjs +0 -109
- package/postprocessing/BloomPass.js +0 -109
- package/postprocessing/BokehPass.cjs +0 -90
- package/postprocessing/BokehPass.js +0 -90
- package/postprocessing/ClearPass.cjs +0 -36
- package/postprocessing/ClearPass.js +0 -36
- package/postprocessing/CubeTexturePass.cjs +0 -53
- package/postprocessing/CubeTexturePass.js +0 -53
- package/postprocessing/DotScreenPass.cjs +0 -49
- package/postprocessing/DotScreenPass.js +0 -49
- package/postprocessing/EffectComposer.cjs +0 -157
- package/postprocessing/EffectComposer.js +0 -157
- package/postprocessing/FilmPass.cjs +0 -51
- package/postprocessing/FilmPass.js +0 -51
- package/postprocessing/GlitchPass.cjs +0 -84
- package/postprocessing/GlitchPass.js +0 -84
- package/postprocessing/HalftonePass.cjs +0 -53
- package/postprocessing/HalftonePass.js +0 -53
- package/postprocessing/LUTPass.cjs +0 -142
- package/postprocessing/LUTPass.js +0 -142
- package/postprocessing/MaskPass.cjs +0 -69
- package/postprocessing/MaskPass.js +0 -69
- package/postprocessing/OutlinePass.cjs +0 -479
- package/postprocessing/OutlinePass.js +0 -479
- package/postprocessing/Pass.cjs +0 -48
- package/postprocessing/Pass.js +0 -48
- package/postprocessing/RenderPass.cjs +0 -59
- package/postprocessing/RenderPass.js +0 -59
- package/postprocessing/RenderPixelatedPass.cjs +0 -199
- package/postprocessing/RenderPixelatedPass.js +0 -199
- package/postprocessing/SAOPass.cjs +0 -288
- package/postprocessing/SAOPass.js +0 -288
- package/postprocessing/SMAAPass.cjs +0 -112
- package/postprocessing/SMAAPass.js +0 -112
- package/postprocessing/SSAARenderPass.cjs +0 -189
- package/postprocessing/SSAARenderPass.js +0 -189
- package/postprocessing/SSAOPass.cjs +0 -272
- package/postprocessing/SSAOPass.js +0 -272
- package/postprocessing/SSRPass.cjs +0 -411
- package/postprocessing/SSRPass.js +0 -411
- package/postprocessing/SavePass.cjs +0 -38
- package/postprocessing/SavePass.js +0 -38
- package/postprocessing/ShaderPass.cjs +0 -49
- package/postprocessing/ShaderPass.js +0 -49
- package/postprocessing/TAARenderPass.cjs +0 -174
- package/postprocessing/TAARenderPass.js +0 -174
- package/postprocessing/TexturePass.cjs +0 -42
- package/postprocessing/TexturePass.js +0 -42
- package/postprocessing/UnrealBloomPass.cjs +0 -277
- package/postprocessing/UnrealBloomPass.js +0 -277
- package/postprocessing/WaterPass.cjs +0 -72
- package/postprocessing/WaterPass.js +0 -72
- package/renderers/CSS2DRenderer.cjs +0 -122
- package/renderers/CSS2DRenderer.js +0 -122
- package/renderers/CSS3DRenderer.cjs +0 -167
- package/renderers/CSS3DRenderer.js +0 -167
- package/renderers/Projector.cjs +0 -499
- package/renderers/Projector.js +0 -499
- package/renderers/SVGRenderer.cjs +0 -311
- package/renderers/SVGRenderer.js +0 -311
- package/shaders/ACESFilmicToneMappingShader.cjs +0 -55
- package/shaders/ACESFilmicToneMappingShader.js +0 -55
- package/shaders/AfterimageShader.cjs +0 -32
- package/shaders/AfterimageShader.js +0 -32
- package/shaders/BasicShader.cjs +0 -12
- package/shaders/BasicShader.js +0 -12
- package/shaders/BleachBypassShader.cjs +0 -35
- package/shaders/BleachBypassShader.js +0 -35
- package/shaders/BlendShader.cjs +0 -30
- package/shaders/BlendShader.js +0 -30
- package/shaders/BokehShader.cjs +0 -109
- package/shaders/BokehShader.js +0 -109
- package/shaders/BokehShader2.cjs +0 -269
- package/shaders/BokehShader2.js +0 -269
- package/shaders/BrightnessContrastShader.cjs +0 -32
- package/shaders/BrightnessContrastShader.js +0 -32
- package/shaders/ColorCorrectionShader.cjs +0 -30
- package/shaders/ColorCorrectionShader.js +0 -30
- package/shaders/ColorifyShader.cjs +0 -28
- package/shaders/ColorifyShader.js +0 -28
- package/shaders/ConvolutionShader.cjs +0 -55
- package/shaders/ConvolutionShader.js +0 -55
- package/shaders/CopyShader.cjs +0 -25
- package/shaders/CopyShader.js +0 -25
- package/shaders/DOFMipMapShader.cjs +0 -32
- package/shaders/DOFMipMapShader.js +0 -32
- package/shaders/DepthLimitedBlurShader.cjs +0 -114
- package/shaders/DepthLimitedBlurShader.js +0 -114
- package/shaders/DigitalGlitch.cjs +0 -85
- package/shaders/DigitalGlitch.js +0 -85
- package/shaders/DotScreenShader.cjs +0 -39
- package/shaders/DotScreenShader.js +0 -39
- package/shaders/FXAAShader.cjs +0 -1098
- package/shaders/FXAAShader.js +0 -1098
- package/shaders/FilmShader.cjs +0 -53
- package/shaders/FilmShader.js +0 -53
- package/shaders/FocusShader.cjs +0 -55
- package/shaders/FocusShader.js +0 -55
- package/shaders/FreiChenShader.cjs +0 -64
- package/shaders/FreiChenShader.js +0 -64
- package/shaders/FresnelShader.cjs +0 -47
- package/shaders/FresnelShader.js +0 -47
- package/shaders/GammaCorrectionShader.cjs +0 -23
- package/shaders/GammaCorrectionShader.js +0 -23
- package/shaders/GodRaysShader.cjs +0 -183
- package/shaders/GodRaysShader.js +0 -183
- package/shaders/HalftoneShader.cjs +0 -228
- package/shaders/HalftoneShader.js +0 -228
- package/shaders/HorizontalBlurShader.cjs +0 -49
- package/shaders/HorizontalBlurShader.js +0 -49
- package/shaders/HorizontalTiltShiftShader.cjs +0 -37
- package/shaders/HorizontalTiltShiftShader.js +0 -37
- package/shaders/HueSaturationShader.cjs +0 -43
- package/shaders/HueSaturationShader.js +0 -43
- package/shaders/KaleidoShader.cjs +0 -34
- package/shaders/KaleidoShader.js +0 -34
- package/shaders/LuminosityHighPassShader.cjs +0 -37
- package/shaders/LuminosityHighPassShader.js +0 -37
- package/shaders/LuminosityShader.cjs +0 -25
- package/shaders/LuminosityShader.js +0 -25
- package/shaders/MirrorShader.cjs +0 -35
- package/shaders/MirrorShader.js +0 -35
- package/shaders/NormalMapShader.cjs +0 -31
- package/shaders/NormalMapShader.js +0 -31
- package/shaders/ParallaxShader.cjs +0 -133
- package/shaders/ParallaxShader.js +0 -133
- package/shaders/PixelShader.cjs +0 -28
- package/shaders/PixelShader.js +0 -28
- package/shaders/RGBShiftShader.cjs +0 -30
- package/shaders/RGBShiftShader.js +0 -30
- package/shaders/SAOShader.cjs +0 -144
- package/shaders/SAOShader.js +0 -144
- package/shaders/SMAAShader.cjs +0 -358
- package/shaders/SMAAShader.js +0 -358
- package/shaders/SSAOShader.cjs +0 -182
- package/shaders/SSAOShader.js +0 -182
- package/shaders/SSRShader.cjs +0 -342
- package/shaders/SSRShader.js +0 -342
- package/shaders/SepiaShader.cjs +0 -29
- package/shaders/SepiaShader.js +0 -29
- package/shaders/SobelOperatorShader.cjs +0 -54
- package/shaders/SobelOperatorShader.js +0 -54
- package/shaders/SubsurfaceScatteringShader.cjs +0 -98
- package/shaders/SubsurfaceScatteringShader.js +0 -98
- package/shaders/TechnicolorShader.cjs +0 -24
- package/shaders/TechnicolorShader.js +0 -24
- package/shaders/ToneMapShader.cjs +0 -51
- package/shaders/ToneMapShader.js +0 -51
- package/shaders/ToonShader.cjs +0 -188
- package/shaders/ToonShader.js +0 -188
- package/shaders/TriangleBlurShader.cjs +0 -37
- package/shaders/TriangleBlurShader.js +0 -37
- package/shaders/UnpackDepthRGBAShader.cjs +0 -26
- package/shaders/UnpackDepthRGBAShader.js +0 -26
- package/shaders/VerticalBlurShader.cjs +0 -50
- package/shaders/VerticalBlurShader.js +0 -50
- package/shaders/VerticalTiltShiftShader.cjs +0 -37
- package/shaders/VerticalTiltShiftShader.js +0 -37
- package/shaders/VignetteShader.cjs +0 -38
- package/shaders/VignetteShader.js +0 -38
- package/shaders/VolumeShader.cjs +0 -225
- package/shaders/VolumeShader.js +0 -225
- package/shaders/WaterRefractionShader.cjs +0 -59
- package/shaders/WaterRefractionShader.js +0 -59
- package/shaders/types.cjs +0 -1
- package/shaders/types.js +0 -1
- package/textures/FlakesTexture.cjs +0 -30
- package/textures/FlakesTexture.js +0 -30
- package/types/helpers.cjs +0 -4
- package/types/helpers.js +0 -4
- package/utils/BufferGeometryUtils.cjs +0 -636
- package/utils/BufferGeometryUtils.js +0 -636
- package/utils/GeometryCompressionUtils.cjs +0 -573
- package/utils/GeometryCompressionUtils.js +0 -573
- package/utils/GeometryUtils.cjs +0 -109
- package/utils/GeometryUtils.js +0 -109
- package/utils/RoughnessMipmapper.cjs +0 -223
- package/utils/RoughnessMipmapper.js +0 -223
- package/utils/SceneUtils.cjs +0 -36
- package/utils/SceneUtils.js +0 -36
- package/utils/ShadowMapViewer.cjs +0 -111
- package/utils/ShadowMapViewer.js +0 -111
- package/utils/SkeletonUtils.cjs +0 -211
- package/utils/SkeletonUtils.js +0 -211
- package/utils/UVsDebug.cjs +0 -80
- package/utils/UVsDebug.js +0 -80
- package/utils/WorkerPool.cjs +0 -62
- package/utils/WorkerPool.js +0 -62
- package/webxr/ARButton.cjs +0 -119
- package/webxr/ARButton.js +0 -119
- package/webxr/OculusHandModel.cjs +0 -82
- package/webxr/OculusHandModel.js +0 -82
- package/webxr/OculusHandPointerModel.cjs +0 -241
- package/webxr/OculusHandPointerModel.js +0 -224
- package/webxr/Text2D.cjs +0 -48
- package/webxr/Text2D.js +0 -31
- package/webxr/VRButton.cjs +0 -111
- package/webxr/VRButton.js +0 -111
- package/webxr/XRControllerModelFactory.cjs +0 -174
- package/webxr/XRControllerModelFactory.js +0 -174
- package/webxr/XREstimatedLight.cjs +0 -126
- package/webxr/XREstimatedLight.js +0 -126
- package/webxr/XRHandMeshModel.cjs +0 -82
- package/webxr/XRHandMeshModel.js +0 -82
- package/webxr/XRHandModelFactory.cjs +0 -61
- package/webxr/XRHandModelFactory.js +0 -61
- package/webxr/XRHandPrimitiveModel.cjs +0 -68
- package/webxr/XRHandPrimitiveModel.js +0 -68
package/loaders/GLTFLoader.js
DELETED
|
@@ -1,2504 +0,0 @@
|
|
|
1
|
-
import { Loader, LoaderUtils, FileLoader, Color, SpotLight, PointLight, DirectionalLight, MeshBasicMaterial, MeshPhysicalMaterial, Vector2, Matrix4, Vector3, Quaternion, InstancedMesh, Object3D, Interpolant, NearestFilter, LinearFilter, NearestMipmapNearestFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapLinearFilter, ClampToEdgeWrapping, MirroredRepeatWrapping, RepeatWrapping, REVISION, InterpolateLinear, InterpolateDiscrete, MeshStandardMaterial, FrontSide, TextureLoader, ImageBitmapLoader, BufferAttribute, InterleavedBuffer, InterleavedBufferAttribute, Texture, PointsMaterial, Material, LineBasicMaterial, DoubleSide, PropertyBinding, BufferGeometry, SkinnedMesh, Mesh, TriangleStripDrawMode, TriangleFanDrawMode, LineSegments, Line, LineLoop, Points, Group, PerspectiveCamera, MathUtils, OrthographicCamera, Skeleton, VectorKeyframeTrack, QuaternionKeyframeTrack, NumberKeyframeTrack, AnimationClip, Bone, Box3, Sphere } from "three";
|
|
2
|
-
import { toTrianglesDrawMode } from "../utils/BufferGeometryUtils.js";
|
|
3
|
-
class GLTFLoader extends Loader {
|
|
4
|
-
constructor(manager) {
|
|
5
|
-
super(manager);
|
|
6
|
-
this.dracoLoader = null;
|
|
7
|
-
this.ktx2Loader = null;
|
|
8
|
-
this.meshoptDecoder = null;
|
|
9
|
-
this.pluginCallbacks = [];
|
|
10
|
-
this.register(function(parser) {
|
|
11
|
-
return new GLTFMaterialsClearcoatExtension(parser);
|
|
12
|
-
});
|
|
13
|
-
this.register(function(parser) {
|
|
14
|
-
return new GLTFTextureBasisUExtension(parser);
|
|
15
|
-
});
|
|
16
|
-
this.register(function(parser) {
|
|
17
|
-
return new GLTFTextureWebPExtension(parser);
|
|
18
|
-
});
|
|
19
|
-
this.register(function(parser) {
|
|
20
|
-
return new GLTFTextureAVIFExtension(parser);
|
|
21
|
-
});
|
|
22
|
-
this.register(function(parser) {
|
|
23
|
-
return new GLTFMaterialsSheenExtension(parser);
|
|
24
|
-
});
|
|
25
|
-
this.register(function(parser) {
|
|
26
|
-
return new GLTFMaterialsTransmissionExtension(parser);
|
|
27
|
-
});
|
|
28
|
-
this.register(function(parser) {
|
|
29
|
-
return new GLTFMaterialsVolumeExtension(parser);
|
|
30
|
-
});
|
|
31
|
-
this.register(function(parser) {
|
|
32
|
-
return new GLTFMaterialsIorExtension(parser);
|
|
33
|
-
});
|
|
34
|
-
this.register(function(parser) {
|
|
35
|
-
return new GLTFMaterialsEmissiveStrengthExtension(parser);
|
|
36
|
-
});
|
|
37
|
-
this.register(function(parser) {
|
|
38
|
-
return new GLTFMaterialsSpecularExtension(parser);
|
|
39
|
-
});
|
|
40
|
-
this.register(function(parser) {
|
|
41
|
-
return new GLTFMaterialsIridescenceExtension(parser);
|
|
42
|
-
});
|
|
43
|
-
this.register(function(parser) {
|
|
44
|
-
return new GLTFMaterialsAnisotropyExtension(parser);
|
|
45
|
-
});
|
|
46
|
-
this.register(function(parser) {
|
|
47
|
-
return new GLTFLightsExtension(parser);
|
|
48
|
-
});
|
|
49
|
-
this.register(function(parser) {
|
|
50
|
-
return new GLTFMeshoptCompression(parser);
|
|
51
|
-
});
|
|
52
|
-
this.register(function(parser) {
|
|
53
|
-
return new GLTFMeshGpuInstancing(parser);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
load(url, onLoad, onProgress, onError) {
|
|
57
|
-
const scope = this;
|
|
58
|
-
let resourcePath;
|
|
59
|
-
if (this.resourcePath !== "") {
|
|
60
|
-
resourcePath = this.resourcePath;
|
|
61
|
-
} else if (this.path !== "") {
|
|
62
|
-
resourcePath = this.path;
|
|
63
|
-
} else {
|
|
64
|
-
resourcePath = LoaderUtils.extractUrlBase(url);
|
|
65
|
-
}
|
|
66
|
-
this.manager.itemStart(url);
|
|
67
|
-
const _onError = function(e) {
|
|
68
|
-
if (onError) {
|
|
69
|
-
onError(e);
|
|
70
|
-
} else {
|
|
71
|
-
console.error(e);
|
|
72
|
-
}
|
|
73
|
-
scope.manager.itemError(url);
|
|
74
|
-
scope.manager.itemEnd(url);
|
|
75
|
-
};
|
|
76
|
-
const loader = new FileLoader(this.manager);
|
|
77
|
-
loader.setPath(this.path);
|
|
78
|
-
loader.setResponseType("arraybuffer");
|
|
79
|
-
loader.setRequestHeader(this.requestHeader);
|
|
80
|
-
loader.setWithCredentials(this.withCredentials);
|
|
81
|
-
loader.load(
|
|
82
|
-
url,
|
|
83
|
-
function(data) {
|
|
84
|
-
try {
|
|
85
|
-
scope.parse(
|
|
86
|
-
data,
|
|
87
|
-
resourcePath,
|
|
88
|
-
function(gltf) {
|
|
89
|
-
onLoad(gltf);
|
|
90
|
-
scope.manager.itemEnd(url);
|
|
91
|
-
},
|
|
92
|
-
_onError
|
|
93
|
-
);
|
|
94
|
-
} catch (e) {
|
|
95
|
-
_onError(e);
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
onProgress,
|
|
99
|
-
_onError
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
setDRACOLoader(dracoLoader) {
|
|
103
|
-
this.dracoLoader = dracoLoader;
|
|
104
|
-
return this;
|
|
105
|
-
}
|
|
106
|
-
setDDSLoader() {
|
|
107
|
-
throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".');
|
|
108
|
-
}
|
|
109
|
-
setKTX2Loader(ktx2Loader) {
|
|
110
|
-
this.ktx2Loader = ktx2Loader;
|
|
111
|
-
return this;
|
|
112
|
-
}
|
|
113
|
-
setMeshoptDecoder(meshoptDecoder) {
|
|
114
|
-
this.meshoptDecoder = meshoptDecoder;
|
|
115
|
-
return this;
|
|
116
|
-
}
|
|
117
|
-
register(callback) {
|
|
118
|
-
if (this.pluginCallbacks.indexOf(callback) === -1) {
|
|
119
|
-
this.pluginCallbacks.push(callback);
|
|
120
|
-
}
|
|
121
|
-
return this;
|
|
122
|
-
}
|
|
123
|
-
unregister(callback) {
|
|
124
|
-
if (this.pluginCallbacks.indexOf(callback) !== -1) {
|
|
125
|
-
this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(callback), 1);
|
|
126
|
-
}
|
|
127
|
-
return this;
|
|
128
|
-
}
|
|
129
|
-
parse(data, path, onLoad, onError) {
|
|
130
|
-
let json;
|
|
131
|
-
const extensions = {};
|
|
132
|
-
const plugins = {};
|
|
133
|
-
if (typeof data === "string") {
|
|
134
|
-
json = JSON.parse(data);
|
|
135
|
-
} else if (data instanceof ArrayBuffer) {
|
|
136
|
-
const magic = LoaderUtils.decodeText(new Uint8Array(data.slice(0, 4)));
|
|
137
|
-
if (magic === BINARY_EXTENSION_HEADER_MAGIC) {
|
|
138
|
-
try {
|
|
139
|
-
extensions[EXTENSIONS.KHR_BINARY_GLTF] = new GLTFBinaryExtension(data);
|
|
140
|
-
} catch (error) {
|
|
141
|
-
if (onError)
|
|
142
|
-
onError(error);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
json = JSON.parse(extensions[EXTENSIONS.KHR_BINARY_GLTF].content);
|
|
146
|
-
} else {
|
|
147
|
-
json = JSON.parse(LoaderUtils.decodeText(new Uint8Array(data)));
|
|
148
|
-
}
|
|
149
|
-
} else {
|
|
150
|
-
json = data;
|
|
151
|
-
}
|
|
152
|
-
if (json.asset === void 0 || json.asset.version[0] < 2) {
|
|
153
|
-
if (onError)
|
|
154
|
-
onError(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
const parser = new GLTFParser(json, {
|
|
158
|
-
path: path || this.resourcePath || "",
|
|
159
|
-
crossOrigin: this.crossOrigin,
|
|
160
|
-
requestHeader: this.requestHeader,
|
|
161
|
-
manager: this.manager,
|
|
162
|
-
ktx2Loader: this.ktx2Loader,
|
|
163
|
-
meshoptDecoder: this.meshoptDecoder
|
|
164
|
-
});
|
|
165
|
-
parser.fileLoader.setRequestHeader(this.requestHeader);
|
|
166
|
-
for (let i = 0; i < this.pluginCallbacks.length; i++) {
|
|
167
|
-
const plugin = this.pluginCallbacks[i](parser);
|
|
168
|
-
plugins[plugin.name] = plugin;
|
|
169
|
-
extensions[plugin.name] = true;
|
|
170
|
-
}
|
|
171
|
-
if (json.extensionsUsed) {
|
|
172
|
-
for (let i = 0; i < json.extensionsUsed.length; ++i) {
|
|
173
|
-
const extensionName = json.extensionsUsed[i];
|
|
174
|
-
const extensionsRequired = json.extensionsRequired || [];
|
|
175
|
-
switch (extensionName) {
|
|
176
|
-
case EXTENSIONS.KHR_MATERIALS_UNLIT:
|
|
177
|
-
extensions[extensionName] = new GLTFMaterialsUnlitExtension();
|
|
178
|
-
break;
|
|
179
|
-
case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
|
|
180
|
-
extensions[extensionName] = new GLTFDracoMeshCompressionExtension(json, this.dracoLoader);
|
|
181
|
-
break;
|
|
182
|
-
case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
|
|
183
|
-
extensions[extensionName] = new GLTFTextureTransformExtension();
|
|
184
|
-
break;
|
|
185
|
-
case EXTENSIONS.KHR_MESH_QUANTIZATION:
|
|
186
|
-
extensions[extensionName] = new GLTFMeshQuantizationExtension();
|
|
187
|
-
break;
|
|
188
|
-
default:
|
|
189
|
-
if (extensionsRequired.indexOf(extensionName) >= 0 && plugins[extensionName] === void 0) {
|
|
190
|
-
console.warn('THREE.GLTFLoader: Unknown extension "' + extensionName + '".');
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
parser.setExtensions(extensions);
|
|
196
|
-
parser.setPlugins(plugins);
|
|
197
|
-
parser.parse(onLoad, onError);
|
|
198
|
-
}
|
|
199
|
-
parseAsync(data, path) {
|
|
200
|
-
const scope = this;
|
|
201
|
-
return new Promise(function(resolve, reject) {
|
|
202
|
-
scope.parse(data, path, resolve, reject);
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
function GLTFRegistry() {
|
|
207
|
-
let objects = {};
|
|
208
|
-
return {
|
|
209
|
-
get: function(key) {
|
|
210
|
-
return objects[key];
|
|
211
|
-
},
|
|
212
|
-
add: function(key, object) {
|
|
213
|
-
objects[key] = object;
|
|
214
|
-
},
|
|
215
|
-
remove: function(key) {
|
|
216
|
-
delete objects[key];
|
|
217
|
-
},
|
|
218
|
-
removeAll: function() {
|
|
219
|
-
objects = {};
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
const EXTENSIONS = {
|
|
224
|
-
KHR_BINARY_GLTF: "KHR_binary_glTF",
|
|
225
|
-
KHR_DRACO_MESH_COMPRESSION: "KHR_draco_mesh_compression",
|
|
226
|
-
KHR_LIGHTS_PUNCTUAL: "KHR_lights_punctual",
|
|
227
|
-
KHR_MATERIALS_CLEARCOAT: "KHR_materials_clearcoat",
|
|
228
|
-
KHR_MATERIALS_IOR: "KHR_materials_ior",
|
|
229
|
-
KHR_MATERIALS_SHEEN: "KHR_materials_sheen",
|
|
230
|
-
KHR_MATERIALS_SPECULAR: "KHR_materials_specular",
|
|
231
|
-
KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission",
|
|
232
|
-
KHR_MATERIALS_IRIDESCENCE: "KHR_materials_iridescence",
|
|
233
|
-
KHR_MATERIALS_ANISOTROPY: "KHR_materials_anisotropy",
|
|
234
|
-
KHR_MATERIALS_UNLIT: "KHR_materials_unlit",
|
|
235
|
-
KHR_MATERIALS_VOLUME: "KHR_materials_volume",
|
|
236
|
-
KHR_TEXTURE_BASISU: "KHR_texture_basisu",
|
|
237
|
-
KHR_TEXTURE_TRANSFORM: "KHR_texture_transform",
|
|
238
|
-
KHR_MESH_QUANTIZATION: "KHR_mesh_quantization",
|
|
239
|
-
KHR_MATERIALS_EMISSIVE_STRENGTH: "KHR_materials_emissive_strength",
|
|
240
|
-
EXT_TEXTURE_WEBP: "EXT_texture_webp",
|
|
241
|
-
EXT_TEXTURE_AVIF: "EXT_texture_avif",
|
|
242
|
-
EXT_MESHOPT_COMPRESSION: "EXT_meshopt_compression",
|
|
243
|
-
EXT_MESH_GPU_INSTANCING: "EXT_mesh_gpu_instancing"
|
|
244
|
-
};
|
|
245
|
-
class GLTFLightsExtension {
|
|
246
|
-
constructor(parser) {
|
|
247
|
-
this.parser = parser;
|
|
248
|
-
this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL;
|
|
249
|
-
this.cache = { refs: {}, uses: {} };
|
|
250
|
-
}
|
|
251
|
-
_markDefs() {
|
|
252
|
-
const parser = this.parser;
|
|
253
|
-
const nodeDefs = this.parser.json.nodes || [];
|
|
254
|
-
for (let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {
|
|
255
|
-
const nodeDef = nodeDefs[nodeIndex];
|
|
256
|
-
if (nodeDef.extensions && nodeDef.extensions[this.name] && nodeDef.extensions[this.name].light !== void 0) {
|
|
257
|
-
parser._addNodeRef(this.cache, nodeDef.extensions[this.name].light);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
_loadLight(lightIndex) {
|
|
262
|
-
const parser = this.parser;
|
|
263
|
-
const cacheKey = "light:" + lightIndex;
|
|
264
|
-
let dependency = parser.cache.get(cacheKey);
|
|
265
|
-
if (dependency)
|
|
266
|
-
return dependency;
|
|
267
|
-
const json = parser.json;
|
|
268
|
-
const extensions = json.extensions && json.extensions[this.name] || {};
|
|
269
|
-
const lightDefs = extensions.lights || [];
|
|
270
|
-
const lightDef = lightDefs[lightIndex];
|
|
271
|
-
let lightNode;
|
|
272
|
-
const color = new Color(16777215);
|
|
273
|
-
if (lightDef.color !== void 0)
|
|
274
|
-
color.fromArray(lightDef.color);
|
|
275
|
-
const range = lightDef.range !== void 0 ? lightDef.range : 0;
|
|
276
|
-
switch (lightDef.type) {
|
|
277
|
-
case "directional":
|
|
278
|
-
lightNode = new DirectionalLight(color);
|
|
279
|
-
lightNode.target.position.set(0, 0, -1);
|
|
280
|
-
lightNode.add(lightNode.target);
|
|
281
|
-
break;
|
|
282
|
-
case "point":
|
|
283
|
-
lightNode = new PointLight(color);
|
|
284
|
-
lightNode.distance = range;
|
|
285
|
-
break;
|
|
286
|
-
case "spot":
|
|
287
|
-
lightNode = new SpotLight(color);
|
|
288
|
-
lightNode.distance = range;
|
|
289
|
-
lightDef.spot = lightDef.spot || {};
|
|
290
|
-
lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== void 0 ? lightDef.spot.innerConeAngle : 0;
|
|
291
|
-
lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== void 0 ? lightDef.spot.outerConeAngle : Math.PI / 4;
|
|
292
|
-
lightNode.angle = lightDef.spot.outerConeAngle;
|
|
293
|
-
lightNode.penumbra = 1 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
|
|
294
|
-
lightNode.target.position.set(0, 0, -1);
|
|
295
|
-
lightNode.add(lightNode.target);
|
|
296
|
-
break;
|
|
297
|
-
default:
|
|
298
|
-
throw new Error("THREE.GLTFLoader: Unexpected light type: " + lightDef.type);
|
|
299
|
-
}
|
|
300
|
-
lightNode.position.set(0, 0, 0);
|
|
301
|
-
lightNode.decay = 2;
|
|
302
|
-
assignExtrasToUserData(lightNode, lightDef);
|
|
303
|
-
if (lightDef.intensity !== void 0)
|
|
304
|
-
lightNode.intensity = lightDef.intensity;
|
|
305
|
-
lightNode.name = parser.createUniqueName(lightDef.name || "light_" + lightIndex);
|
|
306
|
-
dependency = Promise.resolve(lightNode);
|
|
307
|
-
parser.cache.add(cacheKey, dependency);
|
|
308
|
-
return dependency;
|
|
309
|
-
}
|
|
310
|
-
getDependency(type, index) {
|
|
311
|
-
if (type !== "light")
|
|
312
|
-
return;
|
|
313
|
-
return this._loadLight(index);
|
|
314
|
-
}
|
|
315
|
-
createNodeAttachment(nodeIndex) {
|
|
316
|
-
const self2 = this;
|
|
317
|
-
const parser = this.parser;
|
|
318
|
-
const json = parser.json;
|
|
319
|
-
const nodeDef = json.nodes[nodeIndex];
|
|
320
|
-
const lightDef = nodeDef.extensions && nodeDef.extensions[this.name] || {};
|
|
321
|
-
const lightIndex = lightDef.light;
|
|
322
|
-
if (lightIndex === void 0)
|
|
323
|
-
return null;
|
|
324
|
-
return this._loadLight(lightIndex).then(function(light) {
|
|
325
|
-
return parser._getNodeRef(self2.cache, lightIndex, light);
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
class GLTFMaterialsUnlitExtension {
|
|
330
|
-
constructor() {
|
|
331
|
-
this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;
|
|
332
|
-
}
|
|
333
|
-
getMaterialType() {
|
|
334
|
-
return MeshBasicMaterial;
|
|
335
|
-
}
|
|
336
|
-
extendParams(materialParams, materialDef, parser) {
|
|
337
|
-
const pending = [];
|
|
338
|
-
materialParams.color = new Color(1, 1, 1);
|
|
339
|
-
materialParams.opacity = 1;
|
|
340
|
-
const metallicRoughness = materialDef.pbrMetallicRoughness;
|
|
341
|
-
if (metallicRoughness) {
|
|
342
|
-
if (Array.isArray(metallicRoughness.baseColorFactor)) {
|
|
343
|
-
const array = metallicRoughness.baseColorFactor;
|
|
344
|
-
materialParams.color.fromArray(array);
|
|
345
|
-
materialParams.opacity = array[3];
|
|
346
|
-
}
|
|
347
|
-
if (metallicRoughness.baseColorTexture !== void 0) {
|
|
348
|
-
pending.push(parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture, 3001));
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
return Promise.all(pending);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
class GLTFMaterialsEmissiveStrengthExtension {
|
|
355
|
-
constructor(parser) {
|
|
356
|
-
this.parser = parser;
|
|
357
|
-
this.name = EXTENSIONS.KHR_MATERIALS_EMISSIVE_STRENGTH;
|
|
358
|
-
}
|
|
359
|
-
extendMaterialParams(materialIndex, materialParams) {
|
|
360
|
-
const parser = this.parser;
|
|
361
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
362
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
363
|
-
return Promise.resolve();
|
|
364
|
-
}
|
|
365
|
-
const emissiveStrength = materialDef.extensions[this.name].emissiveStrength;
|
|
366
|
-
if (emissiveStrength !== void 0) {
|
|
367
|
-
materialParams.emissiveIntensity = emissiveStrength;
|
|
368
|
-
}
|
|
369
|
-
return Promise.resolve();
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
class GLTFMaterialsClearcoatExtension {
|
|
373
|
-
constructor(parser) {
|
|
374
|
-
this.parser = parser;
|
|
375
|
-
this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT;
|
|
376
|
-
}
|
|
377
|
-
getMaterialType(materialIndex) {
|
|
378
|
-
const parser = this.parser;
|
|
379
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
380
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
381
|
-
return null;
|
|
382
|
-
return MeshPhysicalMaterial;
|
|
383
|
-
}
|
|
384
|
-
extendMaterialParams(materialIndex, materialParams) {
|
|
385
|
-
const parser = this.parser;
|
|
386
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
387
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
388
|
-
return Promise.resolve();
|
|
389
|
-
}
|
|
390
|
-
const pending = [];
|
|
391
|
-
const extension = materialDef.extensions[this.name];
|
|
392
|
-
if (extension.clearcoatFactor !== void 0) {
|
|
393
|
-
materialParams.clearcoat = extension.clearcoatFactor;
|
|
394
|
-
}
|
|
395
|
-
if (extension.clearcoatTexture !== void 0) {
|
|
396
|
-
pending.push(parser.assignTexture(materialParams, "clearcoatMap", extension.clearcoatTexture));
|
|
397
|
-
}
|
|
398
|
-
if (extension.clearcoatRoughnessFactor !== void 0) {
|
|
399
|
-
materialParams.clearcoatRoughness = extension.clearcoatRoughnessFactor;
|
|
400
|
-
}
|
|
401
|
-
if (extension.clearcoatRoughnessTexture !== void 0) {
|
|
402
|
-
pending.push(parser.assignTexture(materialParams, "clearcoatRoughnessMap", extension.clearcoatRoughnessTexture));
|
|
403
|
-
}
|
|
404
|
-
if (extension.clearcoatNormalTexture !== void 0) {
|
|
405
|
-
pending.push(parser.assignTexture(materialParams, "clearcoatNormalMap", extension.clearcoatNormalTexture));
|
|
406
|
-
if (extension.clearcoatNormalTexture.scale !== void 0) {
|
|
407
|
-
const scale = extension.clearcoatNormalTexture.scale;
|
|
408
|
-
materialParams.clearcoatNormalScale = new Vector2(scale, scale);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
return Promise.all(pending);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
class GLTFMaterialsIridescenceExtension {
|
|
415
|
-
constructor(parser) {
|
|
416
|
-
this.parser = parser;
|
|
417
|
-
this.name = EXTENSIONS.KHR_MATERIALS_IRIDESCENCE;
|
|
418
|
-
}
|
|
419
|
-
getMaterialType(materialIndex) {
|
|
420
|
-
const parser = this.parser;
|
|
421
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
422
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
423
|
-
return null;
|
|
424
|
-
return MeshPhysicalMaterial;
|
|
425
|
-
}
|
|
426
|
-
extendMaterialParams(materialIndex, materialParams) {
|
|
427
|
-
const parser = this.parser;
|
|
428
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
429
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
430
|
-
return Promise.resolve();
|
|
431
|
-
}
|
|
432
|
-
const pending = [];
|
|
433
|
-
const extension = materialDef.extensions[this.name];
|
|
434
|
-
if (extension.iridescenceFactor !== void 0) {
|
|
435
|
-
materialParams.iridescence = extension.iridescenceFactor;
|
|
436
|
-
}
|
|
437
|
-
if (extension.iridescenceTexture !== void 0) {
|
|
438
|
-
pending.push(parser.assignTexture(materialParams, "iridescenceMap", extension.iridescenceTexture));
|
|
439
|
-
}
|
|
440
|
-
if (extension.iridescenceIor !== void 0) {
|
|
441
|
-
materialParams.iridescenceIOR = extension.iridescenceIor;
|
|
442
|
-
}
|
|
443
|
-
if (materialParams.iridescenceThicknessRange === void 0) {
|
|
444
|
-
materialParams.iridescenceThicknessRange = [100, 400];
|
|
445
|
-
}
|
|
446
|
-
if (extension.iridescenceThicknessMinimum !== void 0) {
|
|
447
|
-
materialParams.iridescenceThicknessRange[0] = extension.iridescenceThicknessMinimum;
|
|
448
|
-
}
|
|
449
|
-
if (extension.iridescenceThicknessMaximum !== void 0) {
|
|
450
|
-
materialParams.iridescenceThicknessRange[1] = extension.iridescenceThicknessMaximum;
|
|
451
|
-
}
|
|
452
|
-
if (extension.iridescenceThicknessTexture !== void 0) {
|
|
453
|
-
pending.push(
|
|
454
|
-
parser.assignTexture(materialParams, "iridescenceThicknessMap", extension.iridescenceThicknessTexture)
|
|
455
|
-
);
|
|
456
|
-
}
|
|
457
|
-
return Promise.all(pending);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
class GLTFMaterialsSheenExtension {
|
|
461
|
-
constructor(parser) {
|
|
462
|
-
this.parser = parser;
|
|
463
|
-
this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
|
|
464
|
-
}
|
|
465
|
-
getMaterialType(materialIndex) {
|
|
466
|
-
const parser = this.parser;
|
|
467
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
468
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
469
|
-
return null;
|
|
470
|
-
return MeshPhysicalMaterial;
|
|
471
|
-
}
|
|
472
|
-
extendMaterialParams(materialIndex, materialParams) {
|
|
473
|
-
const parser = this.parser;
|
|
474
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
475
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
476
|
-
return Promise.resolve();
|
|
477
|
-
}
|
|
478
|
-
const pending = [];
|
|
479
|
-
materialParams.sheenColor = new Color(0, 0, 0);
|
|
480
|
-
materialParams.sheenRoughness = 0;
|
|
481
|
-
materialParams.sheen = 1;
|
|
482
|
-
const extension = materialDef.extensions[this.name];
|
|
483
|
-
if (extension.sheenColorFactor !== void 0) {
|
|
484
|
-
materialParams.sheenColor.fromArray(extension.sheenColorFactor);
|
|
485
|
-
}
|
|
486
|
-
if (extension.sheenRoughnessFactor !== void 0) {
|
|
487
|
-
materialParams.sheenRoughness = extension.sheenRoughnessFactor;
|
|
488
|
-
}
|
|
489
|
-
if (extension.sheenColorTexture !== void 0) {
|
|
490
|
-
pending.push(parser.assignTexture(materialParams, "sheenColorMap", extension.sheenColorTexture, 3001));
|
|
491
|
-
}
|
|
492
|
-
if (extension.sheenRoughnessTexture !== void 0) {
|
|
493
|
-
pending.push(parser.assignTexture(materialParams, "sheenRoughnessMap", extension.sheenRoughnessTexture));
|
|
494
|
-
}
|
|
495
|
-
return Promise.all(pending);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
class GLTFMaterialsTransmissionExtension {
|
|
499
|
-
constructor(parser) {
|
|
500
|
-
this.parser = parser;
|
|
501
|
-
this.name = EXTENSIONS.KHR_MATERIALS_TRANSMISSION;
|
|
502
|
-
}
|
|
503
|
-
getMaterialType(materialIndex) {
|
|
504
|
-
const parser = this.parser;
|
|
505
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
506
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
507
|
-
return null;
|
|
508
|
-
return MeshPhysicalMaterial;
|
|
509
|
-
}
|
|
510
|
-
extendMaterialParams(materialIndex, materialParams) {
|
|
511
|
-
const parser = this.parser;
|
|
512
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
513
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
514
|
-
return Promise.resolve();
|
|
515
|
-
}
|
|
516
|
-
const pending = [];
|
|
517
|
-
const extension = materialDef.extensions[this.name];
|
|
518
|
-
if (extension.transmissionFactor !== void 0) {
|
|
519
|
-
materialParams.transmission = extension.transmissionFactor;
|
|
520
|
-
}
|
|
521
|
-
if (extension.transmissionTexture !== void 0) {
|
|
522
|
-
pending.push(parser.assignTexture(materialParams, "transmissionMap", extension.transmissionTexture));
|
|
523
|
-
}
|
|
524
|
-
return Promise.all(pending);
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
class GLTFMaterialsVolumeExtension {
|
|
528
|
-
constructor(parser) {
|
|
529
|
-
this.parser = parser;
|
|
530
|
-
this.name = EXTENSIONS.KHR_MATERIALS_VOLUME;
|
|
531
|
-
}
|
|
532
|
-
getMaterialType(materialIndex) {
|
|
533
|
-
const parser = this.parser;
|
|
534
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
535
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
536
|
-
return null;
|
|
537
|
-
return MeshPhysicalMaterial;
|
|
538
|
-
}
|
|
539
|
-
extendMaterialParams(materialIndex, materialParams) {
|
|
540
|
-
const parser = this.parser;
|
|
541
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
542
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
543
|
-
return Promise.resolve();
|
|
544
|
-
}
|
|
545
|
-
const pending = [];
|
|
546
|
-
const extension = materialDef.extensions[this.name];
|
|
547
|
-
materialParams.thickness = extension.thicknessFactor !== void 0 ? extension.thicknessFactor : 0;
|
|
548
|
-
if (extension.thicknessTexture !== void 0) {
|
|
549
|
-
pending.push(parser.assignTexture(materialParams, "thicknessMap", extension.thicknessTexture));
|
|
550
|
-
}
|
|
551
|
-
materialParams.attenuationDistance = extension.attenuationDistance || Infinity;
|
|
552
|
-
const colorArray = extension.attenuationColor || [1, 1, 1];
|
|
553
|
-
materialParams.attenuationColor = new Color(colorArray[0], colorArray[1], colorArray[2]);
|
|
554
|
-
return Promise.all(pending);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
class GLTFMaterialsIorExtension {
|
|
558
|
-
constructor(parser) {
|
|
559
|
-
this.parser = parser;
|
|
560
|
-
this.name = EXTENSIONS.KHR_MATERIALS_IOR;
|
|
561
|
-
}
|
|
562
|
-
getMaterialType(materialIndex) {
|
|
563
|
-
const parser = this.parser;
|
|
564
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
565
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
566
|
-
return null;
|
|
567
|
-
return MeshPhysicalMaterial;
|
|
568
|
-
}
|
|
569
|
-
extendMaterialParams(materialIndex, materialParams) {
|
|
570
|
-
const parser = this.parser;
|
|
571
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
572
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
573
|
-
return Promise.resolve();
|
|
574
|
-
}
|
|
575
|
-
const extension = materialDef.extensions[this.name];
|
|
576
|
-
materialParams.ior = extension.ior !== void 0 ? extension.ior : 1.5;
|
|
577
|
-
return Promise.resolve();
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
class GLTFMaterialsSpecularExtension {
|
|
581
|
-
constructor(parser) {
|
|
582
|
-
this.parser = parser;
|
|
583
|
-
this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR;
|
|
584
|
-
}
|
|
585
|
-
getMaterialType(materialIndex) {
|
|
586
|
-
const parser = this.parser;
|
|
587
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
588
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
589
|
-
return null;
|
|
590
|
-
return MeshPhysicalMaterial;
|
|
591
|
-
}
|
|
592
|
-
extendMaterialParams(materialIndex, materialParams) {
|
|
593
|
-
const parser = this.parser;
|
|
594
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
595
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
596
|
-
return Promise.resolve();
|
|
597
|
-
}
|
|
598
|
-
const pending = [];
|
|
599
|
-
const extension = materialDef.extensions[this.name];
|
|
600
|
-
materialParams.specularIntensity = extension.specularFactor !== void 0 ? extension.specularFactor : 1;
|
|
601
|
-
if (extension.specularTexture !== void 0) {
|
|
602
|
-
pending.push(parser.assignTexture(materialParams, "specularIntensityMap", extension.specularTexture));
|
|
603
|
-
}
|
|
604
|
-
const colorArray = extension.specularColorFactor || [1, 1, 1];
|
|
605
|
-
materialParams.specularColor = new Color(colorArray[0], colorArray[1], colorArray[2]);
|
|
606
|
-
if (extension.specularColorTexture !== void 0) {
|
|
607
|
-
pending.push(
|
|
608
|
-
parser.assignTexture(materialParams, "specularColorMap", extension.specularColorTexture, 3001)
|
|
609
|
-
// sRGBEncoding
|
|
610
|
-
);
|
|
611
|
-
}
|
|
612
|
-
return Promise.all(pending);
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
class GLTFMaterialsAnisotropyExtension {
|
|
616
|
-
constructor(parser) {
|
|
617
|
-
this.parser = parser;
|
|
618
|
-
this.name = EXTENSIONS.KHR_MATERIALS_ANISOTROPY;
|
|
619
|
-
}
|
|
620
|
-
getMaterialType(materialIndex) {
|
|
621
|
-
const parser = this.parser;
|
|
622
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
623
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
624
|
-
return null;
|
|
625
|
-
return MeshPhysicalMaterial;
|
|
626
|
-
}
|
|
627
|
-
extendMaterialParams(materialIndex, materialParams) {
|
|
628
|
-
const parser = this.parser;
|
|
629
|
-
const materialDef = parser.json.materials[materialIndex];
|
|
630
|
-
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
631
|
-
return Promise.resolve();
|
|
632
|
-
}
|
|
633
|
-
const pending = [];
|
|
634
|
-
const extension = materialDef.extensions[this.name];
|
|
635
|
-
if (extension.anisotropyStrength !== void 0) {
|
|
636
|
-
materialParams.anisotropy = extension.anisotropyStrength;
|
|
637
|
-
}
|
|
638
|
-
if (extension.anisotropyRotation !== void 0) {
|
|
639
|
-
materialParams.anisotropyRotation = extension.anisotropyRotation;
|
|
640
|
-
}
|
|
641
|
-
if (extension.anisotropyTexture !== void 0) {
|
|
642
|
-
pending.push(parser.assignTexture(materialParams, "anisotropyMap", extension.anisotropyTexture));
|
|
643
|
-
}
|
|
644
|
-
return Promise.all(pending);
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
class GLTFTextureBasisUExtension {
|
|
648
|
-
constructor(parser) {
|
|
649
|
-
this.parser = parser;
|
|
650
|
-
this.name = EXTENSIONS.KHR_TEXTURE_BASISU;
|
|
651
|
-
}
|
|
652
|
-
loadTexture(textureIndex) {
|
|
653
|
-
const parser = this.parser;
|
|
654
|
-
const json = parser.json;
|
|
655
|
-
const textureDef = json.textures[textureIndex];
|
|
656
|
-
if (!textureDef.extensions || !textureDef.extensions[this.name]) {
|
|
657
|
-
return null;
|
|
658
|
-
}
|
|
659
|
-
const extension = textureDef.extensions[this.name];
|
|
660
|
-
const loader = parser.options.ktx2Loader;
|
|
661
|
-
if (!loader) {
|
|
662
|
-
if (json.extensionsRequired && json.extensionsRequired.indexOf(this.name) >= 0) {
|
|
663
|
-
throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");
|
|
664
|
-
} else {
|
|
665
|
-
return null;
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
return parser.loadTextureImage(textureIndex, extension.source, loader);
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
class GLTFTextureWebPExtension {
|
|
672
|
-
constructor(parser) {
|
|
673
|
-
this.parser = parser;
|
|
674
|
-
this.name = EXTENSIONS.EXT_TEXTURE_WEBP;
|
|
675
|
-
this.isSupported = null;
|
|
676
|
-
}
|
|
677
|
-
loadTexture(textureIndex) {
|
|
678
|
-
const name = this.name;
|
|
679
|
-
const parser = this.parser;
|
|
680
|
-
const json = parser.json;
|
|
681
|
-
const textureDef = json.textures[textureIndex];
|
|
682
|
-
if (!textureDef.extensions || !textureDef.extensions[name]) {
|
|
683
|
-
return null;
|
|
684
|
-
}
|
|
685
|
-
const extension = textureDef.extensions[name];
|
|
686
|
-
const source = json.images[extension.source];
|
|
687
|
-
let loader = parser.textureLoader;
|
|
688
|
-
if (source.uri) {
|
|
689
|
-
const handler = parser.options.manager.getHandler(source.uri);
|
|
690
|
-
if (handler !== null)
|
|
691
|
-
loader = handler;
|
|
692
|
-
}
|
|
693
|
-
return this.detectSupport().then(function(isSupported) {
|
|
694
|
-
if (isSupported)
|
|
695
|
-
return parser.loadTextureImage(textureIndex, extension.source, loader);
|
|
696
|
-
if (json.extensionsRequired && json.extensionsRequired.indexOf(name) >= 0) {
|
|
697
|
-
throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");
|
|
698
|
-
}
|
|
699
|
-
return parser.loadTexture(textureIndex);
|
|
700
|
-
});
|
|
701
|
-
}
|
|
702
|
-
detectSupport() {
|
|
703
|
-
if (!this.isSupported) {
|
|
704
|
-
this.isSupported = new Promise(function(resolve) {
|
|
705
|
-
const image = new Image();
|
|
706
|
-
image.src = "data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA";
|
|
707
|
-
image.onload = image.onerror = function() {
|
|
708
|
-
resolve(image.height === 1);
|
|
709
|
-
};
|
|
710
|
-
});
|
|
711
|
-
}
|
|
712
|
-
return this.isSupported;
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
class GLTFTextureAVIFExtension {
|
|
716
|
-
constructor(parser) {
|
|
717
|
-
this.parser = parser;
|
|
718
|
-
this.name = EXTENSIONS.EXT_TEXTURE_AVIF;
|
|
719
|
-
this.isSupported = null;
|
|
720
|
-
}
|
|
721
|
-
loadTexture(textureIndex) {
|
|
722
|
-
const name = this.name;
|
|
723
|
-
const parser = this.parser;
|
|
724
|
-
const json = parser.json;
|
|
725
|
-
const textureDef = json.textures[textureIndex];
|
|
726
|
-
if (!textureDef.extensions || !textureDef.extensions[name]) {
|
|
727
|
-
return null;
|
|
728
|
-
}
|
|
729
|
-
const extension = textureDef.extensions[name];
|
|
730
|
-
const source = json.images[extension.source];
|
|
731
|
-
let loader = parser.textureLoader;
|
|
732
|
-
if (source.uri) {
|
|
733
|
-
const handler = parser.options.manager.getHandler(source.uri);
|
|
734
|
-
if (handler !== null)
|
|
735
|
-
loader = handler;
|
|
736
|
-
}
|
|
737
|
-
return this.detectSupport().then(function(isSupported) {
|
|
738
|
-
if (isSupported)
|
|
739
|
-
return parser.loadTextureImage(textureIndex, extension.source, loader);
|
|
740
|
-
if (json.extensionsRequired && json.extensionsRequired.indexOf(name) >= 0) {
|
|
741
|
-
throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");
|
|
742
|
-
}
|
|
743
|
-
return parser.loadTexture(textureIndex);
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
detectSupport() {
|
|
747
|
-
if (!this.isSupported) {
|
|
748
|
-
this.isSupported = new Promise(function(resolve) {
|
|
749
|
-
const image = new Image();
|
|
750
|
-
image.src = "data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=";
|
|
751
|
-
image.onload = image.onerror = function() {
|
|
752
|
-
resolve(image.height === 1);
|
|
753
|
-
};
|
|
754
|
-
});
|
|
755
|
-
}
|
|
756
|
-
return this.isSupported;
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
class GLTFMeshoptCompression {
|
|
760
|
-
constructor(parser) {
|
|
761
|
-
this.name = EXTENSIONS.EXT_MESHOPT_COMPRESSION;
|
|
762
|
-
this.parser = parser;
|
|
763
|
-
}
|
|
764
|
-
loadBufferView(index) {
|
|
765
|
-
const json = this.parser.json;
|
|
766
|
-
const bufferView = json.bufferViews[index];
|
|
767
|
-
if (bufferView.extensions && bufferView.extensions[this.name]) {
|
|
768
|
-
const extensionDef = bufferView.extensions[this.name];
|
|
769
|
-
const buffer = this.parser.getDependency("buffer", extensionDef.buffer);
|
|
770
|
-
const decoder = this.parser.options.meshoptDecoder;
|
|
771
|
-
if (!decoder || !decoder.supported) {
|
|
772
|
-
if (json.extensionsRequired && json.extensionsRequired.indexOf(this.name) >= 0) {
|
|
773
|
-
throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");
|
|
774
|
-
} else {
|
|
775
|
-
return null;
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
return buffer.then(function(res) {
|
|
779
|
-
const byteOffset = extensionDef.byteOffset || 0;
|
|
780
|
-
const byteLength = extensionDef.byteLength || 0;
|
|
781
|
-
const count = extensionDef.count;
|
|
782
|
-
const stride = extensionDef.byteStride;
|
|
783
|
-
const source = new Uint8Array(res, byteOffset, byteLength);
|
|
784
|
-
if (decoder.decodeGltfBufferAsync) {
|
|
785
|
-
return decoder.decodeGltfBufferAsync(count, stride, source, extensionDef.mode, extensionDef.filter).then(function(res2) {
|
|
786
|
-
return res2.buffer;
|
|
787
|
-
});
|
|
788
|
-
} else {
|
|
789
|
-
return decoder.ready.then(function() {
|
|
790
|
-
const result = new ArrayBuffer(count * stride);
|
|
791
|
-
decoder.decodeGltfBuffer(
|
|
792
|
-
new Uint8Array(result),
|
|
793
|
-
count,
|
|
794
|
-
stride,
|
|
795
|
-
source,
|
|
796
|
-
extensionDef.mode,
|
|
797
|
-
extensionDef.filter
|
|
798
|
-
);
|
|
799
|
-
return result;
|
|
800
|
-
});
|
|
801
|
-
}
|
|
802
|
-
});
|
|
803
|
-
} else {
|
|
804
|
-
return null;
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
class GLTFMeshGpuInstancing {
|
|
809
|
-
constructor(parser) {
|
|
810
|
-
this.name = EXTENSIONS.EXT_MESH_GPU_INSTANCING;
|
|
811
|
-
this.parser = parser;
|
|
812
|
-
}
|
|
813
|
-
createNodeMesh(nodeIndex) {
|
|
814
|
-
const json = this.parser.json;
|
|
815
|
-
const nodeDef = json.nodes[nodeIndex];
|
|
816
|
-
if (!nodeDef.extensions || !nodeDef.extensions[this.name] || nodeDef.mesh === void 0) {
|
|
817
|
-
return null;
|
|
818
|
-
}
|
|
819
|
-
const meshDef = json.meshes[nodeDef.mesh];
|
|
820
|
-
for (const primitive of meshDef.primitives) {
|
|
821
|
-
if (primitive.mode !== WEBGL_CONSTANTS.TRIANGLES && primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_STRIP && primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_FAN && primitive.mode !== void 0) {
|
|
822
|
-
return null;
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
const extensionDef = nodeDef.extensions[this.name];
|
|
826
|
-
const attributesDef = extensionDef.attributes;
|
|
827
|
-
const pending = [];
|
|
828
|
-
const attributes = {};
|
|
829
|
-
for (const key in attributesDef) {
|
|
830
|
-
pending.push(
|
|
831
|
-
this.parser.getDependency("accessor", attributesDef[key]).then((accessor) => {
|
|
832
|
-
attributes[key] = accessor;
|
|
833
|
-
return attributes[key];
|
|
834
|
-
})
|
|
835
|
-
);
|
|
836
|
-
}
|
|
837
|
-
if (pending.length < 1) {
|
|
838
|
-
return null;
|
|
839
|
-
}
|
|
840
|
-
pending.push(this.parser.createNodeMesh(nodeIndex));
|
|
841
|
-
return Promise.all(pending).then((results) => {
|
|
842
|
-
const nodeObject = results.pop();
|
|
843
|
-
const meshes = nodeObject.isGroup ? nodeObject.children : [nodeObject];
|
|
844
|
-
const count = results[0].count;
|
|
845
|
-
const instancedMeshes = [];
|
|
846
|
-
for (const mesh of meshes) {
|
|
847
|
-
const m = new Matrix4();
|
|
848
|
-
const p = new Vector3();
|
|
849
|
-
const q = new Quaternion();
|
|
850
|
-
const s = new Vector3(1, 1, 1);
|
|
851
|
-
const instancedMesh = new InstancedMesh(mesh.geometry, mesh.material, count);
|
|
852
|
-
for (let i = 0; i < count; i++) {
|
|
853
|
-
if (attributes.TRANSLATION) {
|
|
854
|
-
p.fromBufferAttribute(attributes.TRANSLATION, i);
|
|
855
|
-
}
|
|
856
|
-
if (attributes.ROTATION) {
|
|
857
|
-
q.fromBufferAttribute(attributes.ROTATION, i);
|
|
858
|
-
}
|
|
859
|
-
if (attributes.SCALE) {
|
|
860
|
-
s.fromBufferAttribute(attributes.SCALE, i);
|
|
861
|
-
}
|
|
862
|
-
instancedMesh.setMatrixAt(i, m.compose(p, q, s));
|
|
863
|
-
}
|
|
864
|
-
for (const attributeName in attributes) {
|
|
865
|
-
if (attributeName !== "TRANSLATION" && attributeName !== "ROTATION" && attributeName !== "SCALE") {
|
|
866
|
-
mesh.geometry.setAttribute(attributeName, attributes[attributeName]);
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
Object3D.prototype.copy.call(instancedMesh, mesh);
|
|
870
|
-
this.parser.assignFinalMaterial(instancedMesh);
|
|
871
|
-
instancedMeshes.push(instancedMesh);
|
|
872
|
-
}
|
|
873
|
-
if (nodeObject.isGroup) {
|
|
874
|
-
nodeObject.clear();
|
|
875
|
-
nodeObject.add(...instancedMeshes);
|
|
876
|
-
return nodeObject;
|
|
877
|
-
}
|
|
878
|
-
return instancedMeshes[0];
|
|
879
|
-
});
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
const BINARY_EXTENSION_HEADER_MAGIC = "glTF";
|
|
883
|
-
const BINARY_EXTENSION_HEADER_LENGTH = 12;
|
|
884
|
-
const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 1313821514, BIN: 5130562 };
|
|
885
|
-
class GLTFBinaryExtension {
|
|
886
|
-
constructor(data) {
|
|
887
|
-
this.name = EXTENSIONS.KHR_BINARY_GLTF;
|
|
888
|
-
this.content = null;
|
|
889
|
-
this.body = null;
|
|
890
|
-
const headerView = new DataView(data, 0, BINARY_EXTENSION_HEADER_LENGTH);
|
|
891
|
-
this.header = {
|
|
892
|
-
magic: LoaderUtils.decodeText(new Uint8Array(data.slice(0, 4))),
|
|
893
|
-
version: headerView.getUint32(4, true),
|
|
894
|
-
length: headerView.getUint32(8, true)
|
|
895
|
-
};
|
|
896
|
-
if (this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {
|
|
897
|
-
throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");
|
|
898
|
-
} else if (this.header.version < 2) {
|
|
899
|
-
throw new Error("THREE.GLTFLoader: Legacy binary file detected.");
|
|
900
|
-
}
|
|
901
|
-
const chunkContentsLength = this.header.length - BINARY_EXTENSION_HEADER_LENGTH;
|
|
902
|
-
const chunkView = new DataView(data, BINARY_EXTENSION_HEADER_LENGTH);
|
|
903
|
-
let chunkIndex = 0;
|
|
904
|
-
while (chunkIndex < chunkContentsLength) {
|
|
905
|
-
const chunkLength = chunkView.getUint32(chunkIndex, true);
|
|
906
|
-
chunkIndex += 4;
|
|
907
|
-
const chunkType = chunkView.getUint32(chunkIndex, true);
|
|
908
|
-
chunkIndex += 4;
|
|
909
|
-
if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
|
|
910
|
-
const contentArray = new Uint8Array(data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength);
|
|
911
|
-
this.content = LoaderUtils.decodeText(contentArray);
|
|
912
|
-
} else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
|
|
913
|
-
const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
|
|
914
|
-
this.body = data.slice(byteOffset, byteOffset + chunkLength);
|
|
915
|
-
}
|
|
916
|
-
chunkIndex += chunkLength;
|
|
917
|
-
}
|
|
918
|
-
if (this.content === null) {
|
|
919
|
-
throw new Error("THREE.GLTFLoader: JSON content not found.");
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
class GLTFDracoMeshCompressionExtension {
|
|
924
|
-
constructor(json, dracoLoader) {
|
|
925
|
-
if (!dracoLoader) {
|
|
926
|
-
throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");
|
|
927
|
-
}
|
|
928
|
-
this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
|
|
929
|
-
this.json = json;
|
|
930
|
-
this.dracoLoader = dracoLoader;
|
|
931
|
-
this.dracoLoader.preload();
|
|
932
|
-
}
|
|
933
|
-
decodePrimitive(primitive, parser) {
|
|
934
|
-
const json = this.json;
|
|
935
|
-
const dracoLoader = this.dracoLoader;
|
|
936
|
-
const bufferViewIndex = primitive.extensions[this.name].bufferView;
|
|
937
|
-
const gltfAttributeMap = primitive.extensions[this.name].attributes;
|
|
938
|
-
const threeAttributeMap = {};
|
|
939
|
-
const attributeNormalizedMap = {};
|
|
940
|
-
const attributeTypeMap = {};
|
|
941
|
-
for (const attributeName in gltfAttributeMap) {
|
|
942
|
-
const threeAttributeName = ATTRIBUTES[attributeName] || attributeName.toLowerCase();
|
|
943
|
-
threeAttributeMap[threeAttributeName] = gltfAttributeMap[attributeName];
|
|
944
|
-
}
|
|
945
|
-
for (const attributeName in primitive.attributes) {
|
|
946
|
-
const threeAttributeName = ATTRIBUTES[attributeName] || attributeName.toLowerCase();
|
|
947
|
-
if (gltfAttributeMap[attributeName] !== void 0) {
|
|
948
|
-
const accessorDef = json.accessors[primitive.attributes[attributeName]];
|
|
949
|
-
const componentType = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
|
|
950
|
-
attributeTypeMap[threeAttributeName] = componentType.name;
|
|
951
|
-
attributeNormalizedMap[threeAttributeName] = accessorDef.normalized === true;
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
return parser.getDependency("bufferView", bufferViewIndex).then(function(bufferView) {
|
|
955
|
-
return new Promise(function(resolve) {
|
|
956
|
-
dracoLoader.decodeDracoFile(
|
|
957
|
-
bufferView,
|
|
958
|
-
function(geometry) {
|
|
959
|
-
for (const attributeName in geometry.attributes) {
|
|
960
|
-
const attribute = geometry.attributes[attributeName];
|
|
961
|
-
const normalized = attributeNormalizedMap[attributeName];
|
|
962
|
-
if (normalized !== void 0)
|
|
963
|
-
attribute.normalized = normalized;
|
|
964
|
-
}
|
|
965
|
-
resolve(geometry);
|
|
966
|
-
},
|
|
967
|
-
threeAttributeMap,
|
|
968
|
-
attributeTypeMap
|
|
969
|
-
);
|
|
970
|
-
});
|
|
971
|
-
});
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
class GLTFTextureTransformExtension {
|
|
975
|
-
constructor() {
|
|
976
|
-
this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;
|
|
977
|
-
}
|
|
978
|
-
extendTexture(texture, transform) {
|
|
979
|
-
if ((transform.texCoord === void 0 || transform.texCoord === texture.channel) && transform.offset === void 0 && transform.rotation === void 0 && transform.scale === void 0) {
|
|
980
|
-
return texture;
|
|
981
|
-
}
|
|
982
|
-
texture = texture.clone();
|
|
983
|
-
if (transform.texCoord !== void 0) {
|
|
984
|
-
texture.channel = transform.texCoord;
|
|
985
|
-
}
|
|
986
|
-
if (transform.offset !== void 0) {
|
|
987
|
-
texture.offset.fromArray(transform.offset);
|
|
988
|
-
}
|
|
989
|
-
if (transform.rotation !== void 0) {
|
|
990
|
-
texture.rotation = transform.rotation;
|
|
991
|
-
}
|
|
992
|
-
if (transform.scale !== void 0) {
|
|
993
|
-
texture.repeat.fromArray(transform.scale);
|
|
994
|
-
}
|
|
995
|
-
texture.needsUpdate = true;
|
|
996
|
-
return texture;
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
class GLTFMeshQuantizationExtension {
|
|
1000
|
-
constructor() {
|
|
1001
|
-
this.name = EXTENSIONS.KHR_MESH_QUANTIZATION;
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
class GLTFCubicSplineInterpolant extends Interpolant {
|
|
1005
|
-
constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) {
|
|
1006
|
-
super(parameterPositions, sampleValues, sampleSize, resultBuffer);
|
|
1007
|
-
}
|
|
1008
|
-
copySampleValue_(index) {
|
|
1009
|
-
const result = this.resultBuffer, values = this.sampleValues, valueSize = this.valueSize, offset = index * valueSize * 3 + valueSize;
|
|
1010
|
-
for (let i = 0; i !== valueSize; i++) {
|
|
1011
|
-
result[i] = values[offset + i];
|
|
1012
|
-
}
|
|
1013
|
-
return result;
|
|
1014
|
-
}
|
|
1015
|
-
interpolate_(i1, t0, t, t1) {
|
|
1016
|
-
const result = this.resultBuffer;
|
|
1017
|
-
const values = this.sampleValues;
|
|
1018
|
-
const stride = this.valueSize;
|
|
1019
|
-
const stride2 = stride * 2;
|
|
1020
|
-
const stride3 = stride * 3;
|
|
1021
|
-
const td = t1 - t0;
|
|
1022
|
-
const p = (t - t0) / td;
|
|
1023
|
-
const pp = p * p;
|
|
1024
|
-
const ppp = pp * p;
|
|
1025
|
-
const offset1 = i1 * stride3;
|
|
1026
|
-
const offset0 = offset1 - stride3;
|
|
1027
|
-
const s2 = -2 * ppp + 3 * pp;
|
|
1028
|
-
const s3 = ppp - pp;
|
|
1029
|
-
const s0 = 1 - s2;
|
|
1030
|
-
const s1 = s3 - pp + p;
|
|
1031
|
-
for (let i = 0; i !== stride; i++) {
|
|
1032
|
-
const p0 = values[offset0 + i + stride];
|
|
1033
|
-
const m0 = values[offset0 + i + stride2] * td;
|
|
1034
|
-
const p1 = values[offset1 + i + stride];
|
|
1035
|
-
const m1 = values[offset1 + i] * td;
|
|
1036
|
-
result[i] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
|
|
1037
|
-
}
|
|
1038
|
-
return result;
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
const _q = /* @__PURE__ */ new Quaternion();
|
|
1042
|
-
class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {
|
|
1043
|
-
interpolate_(i1, t0, t, t1) {
|
|
1044
|
-
const result = super.interpolate_(i1, t0, t, t1);
|
|
1045
|
-
_q.fromArray(result).normalize().toArray(result);
|
|
1046
|
-
return result;
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
const WEBGL_CONSTANTS = {
|
|
1050
|
-
FLOAT: 5126,
|
|
1051
|
-
//FLOAT_MAT2: 35674,
|
|
1052
|
-
FLOAT_MAT3: 35675,
|
|
1053
|
-
FLOAT_MAT4: 35676,
|
|
1054
|
-
FLOAT_VEC2: 35664,
|
|
1055
|
-
FLOAT_VEC3: 35665,
|
|
1056
|
-
FLOAT_VEC4: 35666,
|
|
1057
|
-
LINEAR: 9729,
|
|
1058
|
-
REPEAT: 10497,
|
|
1059
|
-
SAMPLER_2D: 35678,
|
|
1060
|
-
POINTS: 0,
|
|
1061
|
-
LINES: 1,
|
|
1062
|
-
LINE_LOOP: 2,
|
|
1063
|
-
LINE_STRIP: 3,
|
|
1064
|
-
TRIANGLES: 4,
|
|
1065
|
-
TRIANGLE_STRIP: 5,
|
|
1066
|
-
TRIANGLE_FAN: 6,
|
|
1067
|
-
UNSIGNED_BYTE: 5121,
|
|
1068
|
-
UNSIGNED_SHORT: 5123
|
|
1069
|
-
};
|
|
1070
|
-
const WEBGL_COMPONENT_TYPES = {
|
|
1071
|
-
5120: Int8Array,
|
|
1072
|
-
5121: Uint8Array,
|
|
1073
|
-
5122: Int16Array,
|
|
1074
|
-
5123: Uint16Array,
|
|
1075
|
-
5125: Uint32Array,
|
|
1076
|
-
5126: Float32Array
|
|
1077
|
-
};
|
|
1078
|
-
const WEBGL_FILTERS = {
|
|
1079
|
-
9728: NearestFilter,
|
|
1080
|
-
9729: LinearFilter,
|
|
1081
|
-
9984: NearestMipmapNearestFilter,
|
|
1082
|
-
9985: LinearMipmapNearestFilter,
|
|
1083
|
-
9986: NearestMipmapLinearFilter,
|
|
1084
|
-
9987: LinearMipmapLinearFilter
|
|
1085
|
-
};
|
|
1086
|
-
const WEBGL_WRAPPINGS = {
|
|
1087
|
-
33071: ClampToEdgeWrapping,
|
|
1088
|
-
33648: MirroredRepeatWrapping,
|
|
1089
|
-
10497: RepeatWrapping
|
|
1090
|
-
};
|
|
1091
|
-
const WEBGL_TYPE_SIZES = {
|
|
1092
|
-
SCALAR: 1,
|
|
1093
|
-
VEC2: 2,
|
|
1094
|
-
VEC3: 3,
|
|
1095
|
-
VEC4: 4,
|
|
1096
|
-
MAT2: 4,
|
|
1097
|
-
MAT3: 9,
|
|
1098
|
-
MAT4: 16
|
|
1099
|
-
};
|
|
1100
|
-
const ATTRIBUTES = {
|
|
1101
|
-
POSITION: "position",
|
|
1102
|
-
NORMAL: "normal",
|
|
1103
|
-
TANGENT: "tangent",
|
|
1104
|
-
// uv => uv1, 4 uv channels
|
|
1105
|
-
// https://github.com/mrdoob/three.js/pull/25943
|
|
1106
|
-
// https://github.com/mrdoob/three.js/pull/25788
|
|
1107
|
-
...REVISION.replace(/\D+/g, "") >= 152 ? {
|
|
1108
|
-
TEXCOORD_0: "uv",
|
|
1109
|
-
TEXCOORD_1: "uv1",
|
|
1110
|
-
TEXCOORD_2: "uv2",
|
|
1111
|
-
TEXCOORD_3: "uv3"
|
|
1112
|
-
} : {
|
|
1113
|
-
TEXCOORD_0: "uv",
|
|
1114
|
-
TEXCOORD_1: "uv2"
|
|
1115
|
-
},
|
|
1116
|
-
COLOR_0: "color",
|
|
1117
|
-
WEIGHTS_0: "skinWeight",
|
|
1118
|
-
JOINTS_0: "skinIndex"
|
|
1119
|
-
};
|
|
1120
|
-
const PATH_PROPERTIES = {
|
|
1121
|
-
scale: "scale",
|
|
1122
|
-
translation: "position",
|
|
1123
|
-
rotation: "quaternion",
|
|
1124
|
-
weights: "morphTargetInfluences"
|
|
1125
|
-
};
|
|
1126
|
-
const INTERPOLATION = {
|
|
1127
|
-
CUBICSPLINE: void 0,
|
|
1128
|
-
// We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
|
|
1129
|
-
// keyframe track will be initialized with a default interpolation type, then modified.
|
|
1130
|
-
LINEAR: InterpolateLinear,
|
|
1131
|
-
STEP: InterpolateDiscrete
|
|
1132
|
-
};
|
|
1133
|
-
const ALPHA_MODES = {
|
|
1134
|
-
OPAQUE: "OPAQUE",
|
|
1135
|
-
MASK: "MASK",
|
|
1136
|
-
BLEND: "BLEND"
|
|
1137
|
-
};
|
|
1138
|
-
function createDefaultMaterial(cache) {
|
|
1139
|
-
if (cache["DefaultMaterial"] === void 0) {
|
|
1140
|
-
cache["DefaultMaterial"] = new MeshStandardMaterial({
|
|
1141
|
-
color: 16777215,
|
|
1142
|
-
emissive: 0,
|
|
1143
|
-
metalness: 1,
|
|
1144
|
-
roughness: 1,
|
|
1145
|
-
transparent: false,
|
|
1146
|
-
depthTest: true,
|
|
1147
|
-
side: FrontSide
|
|
1148
|
-
});
|
|
1149
|
-
}
|
|
1150
|
-
return cache["DefaultMaterial"];
|
|
1151
|
-
}
|
|
1152
|
-
function addUnknownExtensionsToUserData(knownExtensions, object, objectDef) {
|
|
1153
|
-
for (const name in objectDef.extensions) {
|
|
1154
|
-
if (knownExtensions[name] === void 0) {
|
|
1155
|
-
object.userData.gltfExtensions = object.userData.gltfExtensions || {};
|
|
1156
|
-
object.userData.gltfExtensions[name] = objectDef.extensions[name];
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
function assignExtrasToUserData(object, gltfDef) {
|
|
1161
|
-
if (gltfDef.extras !== void 0) {
|
|
1162
|
-
if (typeof gltfDef.extras === "object") {
|
|
1163
|
-
Object.assign(object.userData, gltfDef.extras);
|
|
1164
|
-
} else {
|
|
1165
|
-
console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + gltfDef.extras);
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
function addMorphTargets(geometry, targets, parser) {
|
|
1170
|
-
let hasMorphPosition = false;
|
|
1171
|
-
let hasMorphNormal = false;
|
|
1172
|
-
let hasMorphColor = false;
|
|
1173
|
-
for (let i = 0, il = targets.length; i < il; i++) {
|
|
1174
|
-
const target = targets[i];
|
|
1175
|
-
if (target.POSITION !== void 0)
|
|
1176
|
-
hasMorphPosition = true;
|
|
1177
|
-
if (target.NORMAL !== void 0)
|
|
1178
|
-
hasMorphNormal = true;
|
|
1179
|
-
if (target.COLOR_0 !== void 0)
|
|
1180
|
-
hasMorphColor = true;
|
|
1181
|
-
if (hasMorphPosition && hasMorphNormal && hasMorphColor)
|
|
1182
|
-
break;
|
|
1183
|
-
}
|
|
1184
|
-
if (!hasMorphPosition && !hasMorphNormal && !hasMorphColor)
|
|
1185
|
-
return Promise.resolve(geometry);
|
|
1186
|
-
const pendingPositionAccessors = [];
|
|
1187
|
-
const pendingNormalAccessors = [];
|
|
1188
|
-
const pendingColorAccessors = [];
|
|
1189
|
-
for (let i = 0, il = targets.length; i < il; i++) {
|
|
1190
|
-
const target = targets[i];
|
|
1191
|
-
if (hasMorphPosition) {
|
|
1192
|
-
const pendingAccessor = target.POSITION !== void 0 ? parser.getDependency("accessor", target.POSITION) : geometry.attributes.position;
|
|
1193
|
-
pendingPositionAccessors.push(pendingAccessor);
|
|
1194
|
-
}
|
|
1195
|
-
if (hasMorphNormal) {
|
|
1196
|
-
const pendingAccessor = target.NORMAL !== void 0 ? parser.getDependency("accessor", target.NORMAL) : geometry.attributes.normal;
|
|
1197
|
-
pendingNormalAccessors.push(pendingAccessor);
|
|
1198
|
-
}
|
|
1199
|
-
if (hasMorphColor) {
|
|
1200
|
-
const pendingAccessor = target.COLOR_0 !== void 0 ? parser.getDependency("accessor", target.COLOR_0) : geometry.attributes.color;
|
|
1201
|
-
pendingColorAccessors.push(pendingAccessor);
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
return Promise.all([
|
|
1205
|
-
Promise.all(pendingPositionAccessors),
|
|
1206
|
-
Promise.all(pendingNormalAccessors),
|
|
1207
|
-
Promise.all(pendingColorAccessors)
|
|
1208
|
-
]).then(function(accessors) {
|
|
1209
|
-
const morphPositions = accessors[0];
|
|
1210
|
-
const morphNormals = accessors[1];
|
|
1211
|
-
const morphColors = accessors[2];
|
|
1212
|
-
if (hasMorphPosition)
|
|
1213
|
-
geometry.morphAttributes.position = morphPositions;
|
|
1214
|
-
if (hasMorphNormal)
|
|
1215
|
-
geometry.morphAttributes.normal = morphNormals;
|
|
1216
|
-
if (hasMorphColor)
|
|
1217
|
-
geometry.morphAttributes.color = morphColors;
|
|
1218
|
-
geometry.morphTargetsRelative = true;
|
|
1219
|
-
return geometry;
|
|
1220
|
-
});
|
|
1221
|
-
}
|
|
1222
|
-
function updateMorphTargets(mesh, meshDef) {
|
|
1223
|
-
mesh.updateMorphTargets();
|
|
1224
|
-
if (meshDef.weights !== void 0) {
|
|
1225
|
-
for (let i = 0, il = meshDef.weights.length; i < il; i++) {
|
|
1226
|
-
mesh.morphTargetInfluences[i] = meshDef.weights[i];
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
if (meshDef.extras && Array.isArray(meshDef.extras.targetNames)) {
|
|
1230
|
-
const targetNames = meshDef.extras.targetNames;
|
|
1231
|
-
if (mesh.morphTargetInfluences.length === targetNames.length) {
|
|
1232
|
-
mesh.morphTargetDictionary = {};
|
|
1233
|
-
for (let i = 0, il = targetNames.length; i < il; i++) {
|
|
1234
|
-
mesh.morphTargetDictionary[targetNames[i]] = i;
|
|
1235
|
-
}
|
|
1236
|
-
} else {
|
|
1237
|
-
console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.");
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
function createPrimitiveKey(primitiveDef) {
|
|
1242
|
-
let geometryKey;
|
|
1243
|
-
const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION];
|
|
1244
|
-
if (dracoExtension) {
|
|
1245
|
-
geometryKey = "draco:" + dracoExtension.bufferView + ":" + dracoExtension.indices + ":" + createAttributesKey(dracoExtension.attributes);
|
|
1246
|
-
} else {
|
|
1247
|
-
geometryKey = primitiveDef.indices + ":" + createAttributesKey(primitiveDef.attributes) + ":" + primitiveDef.mode;
|
|
1248
|
-
}
|
|
1249
|
-
if (primitiveDef.targets !== void 0) {
|
|
1250
|
-
for (let i = 0, il = primitiveDef.targets.length; i < il; i++) {
|
|
1251
|
-
geometryKey += ":" + createAttributesKey(primitiveDef.targets[i]);
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
return geometryKey;
|
|
1255
|
-
}
|
|
1256
|
-
function createAttributesKey(attributes) {
|
|
1257
|
-
let attributesKey = "";
|
|
1258
|
-
const keys = Object.keys(attributes).sort();
|
|
1259
|
-
for (let i = 0, il = keys.length; i < il; i++) {
|
|
1260
|
-
attributesKey += keys[i] + ":" + attributes[keys[i]] + ";";
|
|
1261
|
-
}
|
|
1262
|
-
return attributesKey;
|
|
1263
|
-
}
|
|
1264
|
-
function getNormalizedComponentScale(constructor) {
|
|
1265
|
-
switch (constructor) {
|
|
1266
|
-
case Int8Array:
|
|
1267
|
-
return 1 / 127;
|
|
1268
|
-
case Uint8Array:
|
|
1269
|
-
return 1 / 255;
|
|
1270
|
-
case Int16Array:
|
|
1271
|
-
return 1 / 32767;
|
|
1272
|
-
case Uint16Array:
|
|
1273
|
-
return 1 / 65535;
|
|
1274
|
-
default:
|
|
1275
|
-
throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.");
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
function getImageURIMimeType(uri) {
|
|
1279
|
-
if (uri.search(/\.jpe?g($|\?)/i) > 0 || uri.search(/^data\:image\/jpeg/) === 0)
|
|
1280
|
-
return "image/jpeg";
|
|
1281
|
-
if (uri.search(/\.webp($|\?)/i) > 0 || uri.search(/^data\:image\/webp/) === 0)
|
|
1282
|
-
return "image/webp";
|
|
1283
|
-
return "image/png";
|
|
1284
|
-
}
|
|
1285
|
-
const _identityMatrix = /* @__PURE__ */ new Matrix4();
|
|
1286
|
-
class GLTFParser {
|
|
1287
|
-
constructor(json = {}, options = {}) {
|
|
1288
|
-
this.json = json;
|
|
1289
|
-
this.extensions = {};
|
|
1290
|
-
this.plugins = {};
|
|
1291
|
-
this.options = options;
|
|
1292
|
-
this.cache = new GLTFRegistry();
|
|
1293
|
-
this.associations = /* @__PURE__ */ new Map();
|
|
1294
|
-
this.primitiveCache = {};
|
|
1295
|
-
this.nodeCache = {};
|
|
1296
|
-
this.meshCache = { refs: {}, uses: {} };
|
|
1297
|
-
this.cameraCache = { refs: {}, uses: {} };
|
|
1298
|
-
this.lightCache = { refs: {}, uses: {} };
|
|
1299
|
-
this.sourceCache = {};
|
|
1300
|
-
this.textureCache = {};
|
|
1301
|
-
this.nodeNamesUsed = {};
|
|
1302
|
-
let isSafari = false;
|
|
1303
|
-
let isFirefox = false;
|
|
1304
|
-
let firefoxVersion = -1;
|
|
1305
|
-
if (typeof navigator !== "undefined" && typeof navigator.userAgent !== "undefined") {
|
|
1306
|
-
isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent) === true;
|
|
1307
|
-
isFirefox = navigator.userAgent.indexOf("Firefox") > -1;
|
|
1308
|
-
firefoxVersion = isFirefox ? navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1] : -1;
|
|
1309
|
-
}
|
|
1310
|
-
if (typeof createImageBitmap === "undefined" || isSafari || isFirefox && firefoxVersion < 98) {
|
|
1311
|
-
this.textureLoader = new TextureLoader(this.options.manager);
|
|
1312
|
-
} else {
|
|
1313
|
-
this.textureLoader = new ImageBitmapLoader(this.options.manager);
|
|
1314
|
-
}
|
|
1315
|
-
this.textureLoader.setCrossOrigin(this.options.crossOrigin);
|
|
1316
|
-
this.textureLoader.setRequestHeader(this.options.requestHeader);
|
|
1317
|
-
this.fileLoader = new FileLoader(this.options.manager);
|
|
1318
|
-
this.fileLoader.setResponseType("arraybuffer");
|
|
1319
|
-
if (this.options.crossOrigin === "use-credentials") {
|
|
1320
|
-
this.fileLoader.setWithCredentials(true);
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
setExtensions(extensions) {
|
|
1324
|
-
this.extensions = extensions;
|
|
1325
|
-
}
|
|
1326
|
-
setPlugins(plugins) {
|
|
1327
|
-
this.plugins = plugins;
|
|
1328
|
-
}
|
|
1329
|
-
parse(onLoad, onError) {
|
|
1330
|
-
const parser = this;
|
|
1331
|
-
const json = this.json;
|
|
1332
|
-
const extensions = this.extensions;
|
|
1333
|
-
this.cache.removeAll();
|
|
1334
|
-
this.nodeCache = {};
|
|
1335
|
-
this._invokeAll(function(ext) {
|
|
1336
|
-
return ext._markDefs && ext._markDefs();
|
|
1337
|
-
});
|
|
1338
|
-
Promise.all(
|
|
1339
|
-
this._invokeAll(function(ext) {
|
|
1340
|
-
return ext.beforeRoot && ext.beforeRoot();
|
|
1341
|
-
})
|
|
1342
|
-
).then(function() {
|
|
1343
|
-
return Promise.all([
|
|
1344
|
-
parser.getDependencies("scene"),
|
|
1345
|
-
parser.getDependencies("animation"),
|
|
1346
|
-
parser.getDependencies("camera")
|
|
1347
|
-
]);
|
|
1348
|
-
}).then(function(dependencies) {
|
|
1349
|
-
const result = {
|
|
1350
|
-
scene: dependencies[0][json.scene || 0],
|
|
1351
|
-
scenes: dependencies[0],
|
|
1352
|
-
animations: dependencies[1],
|
|
1353
|
-
cameras: dependencies[2],
|
|
1354
|
-
asset: json.asset,
|
|
1355
|
-
parser,
|
|
1356
|
-
userData: {}
|
|
1357
|
-
};
|
|
1358
|
-
addUnknownExtensionsToUserData(extensions, result, json);
|
|
1359
|
-
assignExtrasToUserData(result, json);
|
|
1360
|
-
Promise.all(
|
|
1361
|
-
parser._invokeAll(function(ext) {
|
|
1362
|
-
return ext.afterRoot && ext.afterRoot(result);
|
|
1363
|
-
})
|
|
1364
|
-
).then(function() {
|
|
1365
|
-
onLoad(result);
|
|
1366
|
-
});
|
|
1367
|
-
}).catch(onError);
|
|
1368
|
-
}
|
|
1369
|
-
/**
|
|
1370
|
-
* Marks the special nodes/meshes in json for efficient parse.
|
|
1371
|
-
*/
|
|
1372
|
-
_markDefs() {
|
|
1373
|
-
const nodeDefs = this.json.nodes || [];
|
|
1374
|
-
const skinDefs = this.json.skins || [];
|
|
1375
|
-
const meshDefs = this.json.meshes || [];
|
|
1376
|
-
for (let skinIndex = 0, skinLength = skinDefs.length; skinIndex < skinLength; skinIndex++) {
|
|
1377
|
-
const joints = skinDefs[skinIndex].joints;
|
|
1378
|
-
for (let i = 0, il = joints.length; i < il; i++) {
|
|
1379
|
-
nodeDefs[joints[i]].isBone = true;
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
for (let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {
|
|
1383
|
-
const nodeDef = nodeDefs[nodeIndex];
|
|
1384
|
-
if (nodeDef.mesh !== void 0) {
|
|
1385
|
-
this._addNodeRef(this.meshCache, nodeDef.mesh);
|
|
1386
|
-
if (nodeDef.skin !== void 0) {
|
|
1387
|
-
meshDefs[nodeDef.mesh].isSkinnedMesh = true;
|
|
1388
|
-
}
|
|
1389
|
-
}
|
|
1390
|
-
if (nodeDef.camera !== void 0) {
|
|
1391
|
-
this._addNodeRef(this.cameraCache, nodeDef.camera);
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
/**
|
|
1396
|
-
* Counts references to shared node / Object3D resources. These resources
|
|
1397
|
-
* can be reused, or "instantiated", at multiple nodes in the scene
|
|
1398
|
-
* hierarchy. Mesh, Camera, and Light instances are instantiated and must
|
|
1399
|
-
* be marked. Non-scenegraph resources (like Materials, Geometries, and
|
|
1400
|
-
* Textures) can be reused directly and are not marked here.
|
|
1401
|
-
*
|
|
1402
|
-
* Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
|
|
1403
|
-
*/
|
|
1404
|
-
_addNodeRef(cache, index) {
|
|
1405
|
-
if (index === void 0)
|
|
1406
|
-
return;
|
|
1407
|
-
if (cache.refs[index] === void 0) {
|
|
1408
|
-
cache.refs[index] = cache.uses[index] = 0;
|
|
1409
|
-
}
|
|
1410
|
-
cache.refs[index]++;
|
|
1411
|
-
}
|
|
1412
|
-
/** Returns a reference to a shared resource, cloning it if necessary. */
|
|
1413
|
-
_getNodeRef(cache, index, object) {
|
|
1414
|
-
if (cache.refs[index] <= 1)
|
|
1415
|
-
return object;
|
|
1416
|
-
const ref = object.clone();
|
|
1417
|
-
const updateMappings = (original, clone) => {
|
|
1418
|
-
const mappings = this.associations.get(original);
|
|
1419
|
-
if (mappings != null) {
|
|
1420
|
-
this.associations.set(clone, mappings);
|
|
1421
|
-
}
|
|
1422
|
-
for (const [i, child] of original.children.entries()) {
|
|
1423
|
-
updateMappings(child, clone.children[i]);
|
|
1424
|
-
}
|
|
1425
|
-
};
|
|
1426
|
-
updateMappings(object, ref);
|
|
1427
|
-
ref.name += "_instance_" + cache.uses[index]++;
|
|
1428
|
-
return ref;
|
|
1429
|
-
}
|
|
1430
|
-
_invokeOne(func) {
|
|
1431
|
-
const extensions = Object.values(this.plugins);
|
|
1432
|
-
extensions.push(this);
|
|
1433
|
-
for (let i = 0; i < extensions.length; i++) {
|
|
1434
|
-
const result = func(extensions[i]);
|
|
1435
|
-
if (result)
|
|
1436
|
-
return result;
|
|
1437
|
-
}
|
|
1438
|
-
return null;
|
|
1439
|
-
}
|
|
1440
|
-
_invokeAll(func) {
|
|
1441
|
-
const extensions = Object.values(this.plugins);
|
|
1442
|
-
extensions.unshift(this);
|
|
1443
|
-
const pending = [];
|
|
1444
|
-
for (let i = 0; i < extensions.length; i++) {
|
|
1445
|
-
const result = func(extensions[i]);
|
|
1446
|
-
if (result)
|
|
1447
|
-
pending.push(result);
|
|
1448
|
-
}
|
|
1449
|
-
return pending;
|
|
1450
|
-
}
|
|
1451
|
-
/**
|
|
1452
|
-
* Requests the specified dependency asynchronously, with caching.
|
|
1453
|
-
* @param {string} type
|
|
1454
|
-
* @param {number} index
|
|
1455
|
-
* @return {Promise<Object3D|Material|THREE.Texture|AnimationClip|ArrayBuffer|Object>}
|
|
1456
|
-
*/
|
|
1457
|
-
getDependency(type, index) {
|
|
1458
|
-
const cacheKey = type + ":" + index;
|
|
1459
|
-
let dependency = this.cache.get(cacheKey);
|
|
1460
|
-
if (!dependency) {
|
|
1461
|
-
switch (type) {
|
|
1462
|
-
case "scene":
|
|
1463
|
-
dependency = this.loadScene(index);
|
|
1464
|
-
break;
|
|
1465
|
-
case "node":
|
|
1466
|
-
dependency = this._invokeOne(function(ext) {
|
|
1467
|
-
return ext.loadNode && ext.loadNode(index);
|
|
1468
|
-
});
|
|
1469
|
-
break;
|
|
1470
|
-
case "mesh":
|
|
1471
|
-
dependency = this._invokeOne(function(ext) {
|
|
1472
|
-
return ext.loadMesh && ext.loadMesh(index);
|
|
1473
|
-
});
|
|
1474
|
-
break;
|
|
1475
|
-
case "accessor":
|
|
1476
|
-
dependency = this.loadAccessor(index);
|
|
1477
|
-
break;
|
|
1478
|
-
case "bufferView":
|
|
1479
|
-
dependency = this._invokeOne(function(ext) {
|
|
1480
|
-
return ext.loadBufferView && ext.loadBufferView(index);
|
|
1481
|
-
});
|
|
1482
|
-
break;
|
|
1483
|
-
case "buffer":
|
|
1484
|
-
dependency = this.loadBuffer(index);
|
|
1485
|
-
break;
|
|
1486
|
-
case "material":
|
|
1487
|
-
dependency = this._invokeOne(function(ext) {
|
|
1488
|
-
return ext.loadMaterial && ext.loadMaterial(index);
|
|
1489
|
-
});
|
|
1490
|
-
break;
|
|
1491
|
-
case "texture":
|
|
1492
|
-
dependency = this._invokeOne(function(ext) {
|
|
1493
|
-
return ext.loadTexture && ext.loadTexture(index);
|
|
1494
|
-
});
|
|
1495
|
-
break;
|
|
1496
|
-
case "skin":
|
|
1497
|
-
dependency = this.loadSkin(index);
|
|
1498
|
-
break;
|
|
1499
|
-
case "animation":
|
|
1500
|
-
dependency = this._invokeOne(function(ext) {
|
|
1501
|
-
return ext.loadAnimation && ext.loadAnimation(index);
|
|
1502
|
-
});
|
|
1503
|
-
break;
|
|
1504
|
-
case "camera":
|
|
1505
|
-
dependency = this.loadCamera(index);
|
|
1506
|
-
break;
|
|
1507
|
-
default:
|
|
1508
|
-
dependency = this._invokeOne(function(ext) {
|
|
1509
|
-
return ext != this && ext.getDependency && ext.getDependency(type, index);
|
|
1510
|
-
});
|
|
1511
|
-
if (!dependency) {
|
|
1512
|
-
throw new Error("Unknown type: " + type);
|
|
1513
|
-
}
|
|
1514
|
-
break;
|
|
1515
|
-
}
|
|
1516
|
-
this.cache.add(cacheKey, dependency);
|
|
1517
|
-
}
|
|
1518
|
-
return dependency;
|
|
1519
|
-
}
|
|
1520
|
-
/**
|
|
1521
|
-
* Requests all dependencies of the specified type asynchronously, with caching.
|
|
1522
|
-
* @param {string} type
|
|
1523
|
-
* @return {Promise<Array<Object>>}
|
|
1524
|
-
*/
|
|
1525
|
-
getDependencies(type) {
|
|
1526
|
-
let dependencies = this.cache.get(type);
|
|
1527
|
-
if (!dependencies) {
|
|
1528
|
-
const parser = this;
|
|
1529
|
-
const defs = this.json[type + (type === "mesh" ? "es" : "s")] || [];
|
|
1530
|
-
dependencies = Promise.all(
|
|
1531
|
-
defs.map(function(def, index) {
|
|
1532
|
-
return parser.getDependency(type, index);
|
|
1533
|
-
})
|
|
1534
|
-
);
|
|
1535
|
-
this.cache.add(type, dependencies);
|
|
1536
|
-
}
|
|
1537
|
-
return dependencies;
|
|
1538
|
-
}
|
|
1539
|
-
/**
|
|
1540
|
-
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
|
|
1541
|
-
* @param {number} bufferIndex
|
|
1542
|
-
* @return {Promise<ArrayBuffer>}
|
|
1543
|
-
*/
|
|
1544
|
-
loadBuffer(bufferIndex) {
|
|
1545
|
-
const bufferDef = this.json.buffers[bufferIndex];
|
|
1546
|
-
const loader = this.fileLoader;
|
|
1547
|
-
if (bufferDef.type && bufferDef.type !== "arraybuffer") {
|
|
1548
|
-
throw new Error("THREE.GLTFLoader: " + bufferDef.type + " buffer type is not supported.");
|
|
1549
|
-
}
|
|
1550
|
-
if (bufferDef.uri === void 0 && bufferIndex === 0) {
|
|
1551
|
-
return Promise.resolve(this.extensions[EXTENSIONS.KHR_BINARY_GLTF].body);
|
|
1552
|
-
}
|
|
1553
|
-
const options = this.options;
|
|
1554
|
-
return new Promise(function(resolve, reject) {
|
|
1555
|
-
loader.load(LoaderUtils.resolveURL(bufferDef.uri, options.path), resolve, void 0, function() {
|
|
1556
|
-
reject(new Error('THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".'));
|
|
1557
|
-
});
|
|
1558
|
-
});
|
|
1559
|
-
}
|
|
1560
|
-
/**
|
|
1561
|
-
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
|
|
1562
|
-
* @param {number} bufferViewIndex
|
|
1563
|
-
* @return {Promise<ArrayBuffer>}
|
|
1564
|
-
*/
|
|
1565
|
-
loadBufferView(bufferViewIndex) {
|
|
1566
|
-
const bufferViewDef = this.json.bufferViews[bufferViewIndex];
|
|
1567
|
-
return this.getDependency("buffer", bufferViewDef.buffer).then(function(buffer) {
|
|
1568
|
-
const byteLength = bufferViewDef.byteLength || 0;
|
|
1569
|
-
const byteOffset = bufferViewDef.byteOffset || 0;
|
|
1570
|
-
return buffer.slice(byteOffset, byteOffset + byteLength);
|
|
1571
|
-
});
|
|
1572
|
-
}
|
|
1573
|
-
/**
|
|
1574
|
-
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
|
|
1575
|
-
* @param {number} accessorIndex
|
|
1576
|
-
* @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
|
|
1577
|
-
*/
|
|
1578
|
-
loadAccessor(accessorIndex) {
|
|
1579
|
-
const parser = this;
|
|
1580
|
-
const json = this.json;
|
|
1581
|
-
const accessorDef = this.json.accessors[accessorIndex];
|
|
1582
|
-
if (accessorDef.bufferView === void 0 && accessorDef.sparse === void 0) {
|
|
1583
|
-
const itemSize = WEBGL_TYPE_SIZES[accessorDef.type];
|
|
1584
|
-
const TypedArray = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
|
|
1585
|
-
const normalized = accessorDef.normalized === true;
|
|
1586
|
-
const array = new TypedArray(accessorDef.count * itemSize);
|
|
1587
|
-
return Promise.resolve(new BufferAttribute(array, itemSize, normalized));
|
|
1588
|
-
}
|
|
1589
|
-
const pendingBufferViews = [];
|
|
1590
|
-
if (accessorDef.bufferView !== void 0) {
|
|
1591
|
-
pendingBufferViews.push(this.getDependency("bufferView", accessorDef.bufferView));
|
|
1592
|
-
} else {
|
|
1593
|
-
pendingBufferViews.push(null);
|
|
1594
|
-
}
|
|
1595
|
-
if (accessorDef.sparse !== void 0) {
|
|
1596
|
-
pendingBufferViews.push(this.getDependency("bufferView", accessorDef.sparse.indices.bufferView));
|
|
1597
|
-
pendingBufferViews.push(this.getDependency("bufferView", accessorDef.sparse.values.bufferView));
|
|
1598
|
-
}
|
|
1599
|
-
return Promise.all(pendingBufferViews).then(function(bufferViews) {
|
|
1600
|
-
const bufferView = bufferViews[0];
|
|
1601
|
-
const itemSize = WEBGL_TYPE_SIZES[accessorDef.type];
|
|
1602
|
-
const TypedArray = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
|
|
1603
|
-
const elementBytes = TypedArray.BYTES_PER_ELEMENT;
|
|
1604
|
-
const itemBytes = elementBytes * itemSize;
|
|
1605
|
-
const byteOffset = accessorDef.byteOffset || 0;
|
|
1606
|
-
const byteStride = accessorDef.bufferView !== void 0 ? json.bufferViews[accessorDef.bufferView].byteStride : void 0;
|
|
1607
|
-
const normalized = accessorDef.normalized === true;
|
|
1608
|
-
let array, bufferAttribute;
|
|
1609
|
-
if (byteStride && byteStride !== itemBytes) {
|
|
1610
|
-
const ibSlice = Math.floor(byteOffset / byteStride);
|
|
1611
|
-
const ibCacheKey = "InterleavedBuffer:" + accessorDef.bufferView + ":" + accessorDef.componentType + ":" + ibSlice + ":" + accessorDef.count;
|
|
1612
|
-
let ib = parser.cache.get(ibCacheKey);
|
|
1613
|
-
if (!ib) {
|
|
1614
|
-
array = new TypedArray(bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes);
|
|
1615
|
-
ib = new InterleavedBuffer(array, byteStride / elementBytes);
|
|
1616
|
-
parser.cache.add(ibCacheKey, ib);
|
|
1617
|
-
}
|
|
1618
|
-
bufferAttribute = new InterleavedBufferAttribute(
|
|
1619
|
-
ib,
|
|
1620
|
-
itemSize,
|
|
1621
|
-
byteOffset % byteStride / elementBytes,
|
|
1622
|
-
normalized
|
|
1623
|
-
);
|
|
1624
|
-
} else {
|
|
1625
|
-
if (bufferView === null) {
|
|
1626
|
-
array = new TypedArray(accessorDef.count * itemSize);
|
|
1627
|
-
} else {
|
|
1628
|
-
array = new TypedArray(bufferView, byteOffset, accessorDef.count * itemSize);
|
|
1629
|
-
}
|
|
1630
|
-
bufferAttribute = new BufferAttribute(array, itemSize, normalized);
|
|
1631
|
-
}
|
|
1632
|
-
if (accessorDef.sparse !== void 0) {
|
|
1633
|
-
const itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR;
|
|
1634
|
-
const TypedArrayIndices = WEBGL_COMPONENT_TYPES[accessorDef.sparse.indices.componentType];
|
|
1635
|
-
const byteOffsetIndices = accessorDef.sparse.indices.byteOffset || 0;
|
|
1636
|
-
const byteOffsetValues = accessorDef.sparse.values.byteOffset || 0;
|
|
1637
|
-
const sparseIndices = new TypedArrayIndices(
|
|
1638
|
-
bufferViews[1],
|
|
1639
|
-
byteOffsetIndices,
|
|
1640
|
-
accessorDef.sparse.count * itemSizeIndices
|
|
1641
|
-
);
|
|
1642
|
-
const sparseValues = new TypedArray(bufferViews[2], byteOffsetValues, accessorDef.sparse.count * itemSize);
|
|
1643
|
-
if (bufferView !== null) {
|
|
1644
|
-
bufferAttribute = new BufferAttribute(
|
|
1645
|
-
bufferAttribute.array.slice(),
|
|
1646
|
-
bufferAttribute.itemSize,
|
|
1647
|
-
bufferAttribute.normalized
|
|
1648
|
-
);
|
|
1649
|
-
}
|
|
1650
|
-
for (let i = 0, il = sparseIndices.length; i < il; i++) {
|
|
1651
|
-
const index = sparseIndices[i];
|
|
1652
|
-
bufferAttribute.setX(index, sparseValues[i * itemSize]);
|
|
1653
|
-
if (itemSize >= 2)
|
|
1654
|
-
bufferAttribute.setY(index, sparseValues[i * itemSize + 1]);
|
|
1655
|
-
if (itemSize >= 3)
|
|
1656
|
-
bufferAttribute.setZ(index, sparseValues[i * itemSize + 2]);
|
|
1657
|
-
if (itemSize >= 4)
|
|
1658
|
-
bufferAttribute.setW(index, sparseValues[i * itemSize + 3]);
|
|
1659
|
-
if (itemSize >= 5)
|
|
1660
|
-
throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.");
|
|
1661
|
-
}
|
|
1662
|
-
}
|
|
1663
|
-
return bufferAttribute;
|
|
1664
|
-
});
|
|
1665
|
-
}
|
|
1666
|
-
/**
|
|
1667
|
-
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
|
|
1668
|
-
* @param {number} textureIndex
|
|
1669
|
-
* @return {Promise<THREE.Texture|null>}
|
|
1670
|
-
*/
|
|
1671
|
-
loadTexture(textureIndex) {
|
|
1672
|
-
const json = this.json;
|
|
1673
|
-
const options = this.options;
|
|
1674
|
-
const textureDef = json.textures[textureIndex];
|
|
1675
|
-
const sourceIndex = textureDef.source;
|
|
1676
|
-
const sourceDef = json.images[sourceIndex];
|
|
1677
|
-
let loader = this.textureLoader;
|
|
1678
|
-
if (sourceDef.uri) {
|
|
1679
|
-
const handler = options.manager.getHandler(sourceDef.uri);
|
|
1680
|
-
if (handler !== null)
|
|
1681
|
-
loader = handler;
|
|
1682
|
-
}
|
|
1683
|
-
return this.loadTextureImage(textureIndex, sourceIndex, loader);
|
|
1684
|
-
}
|
|
1685
|
-
loadTextureImage(textureIndex, sourceIndex, loader) {
|
|
1686
|
-
const parser = this;
|
|
1687
|
-
const json = this.json;
|
|
1688
|
-
const textureDef = json.textures[textureIndex];
|
|
1689
|
-
const sourceDef = json.images[sourceIndex];
|
|
1690
|
-
const cacheKey = (sourceDef.uri || sourceDef.bufferView) + ":" + textureDef.sampler;
|
|
1691
|
-
if (this.textureCache[cacheKey]) {
|
|
1692
|
-
return this.textureCache[cacheKey];
|
|
1693
|
-
}
|
|
1694
|
-
const promise = this.loadImageSource(sourceIndex, loader).then(function(texture) {
|
|
1695
|
-
texture.flipY = false;
|
|
1696
|
-
texture.name = textureDef.name || sourceDef.name || "";
|
|
1697
|
-
if (texture.name === "" && typeof sourceDef.uri === "string" && sourceDef.uri.startsWith("data:image/") === false) {
|
|
1698
|
-
texture.name = sourceDef.uri;
|
|
1699
|
-
}
|
|
1700
|
-
const samplers = json.samplers || {};
|
|
1701
|
-
const sampler = samplers[textureDef.sampler] || {};
|
|
1702
|
-
texture.magFilter = WEBGL_FILTERS[sampler.magFilter] || LinearFilter;
|
|
1703
|
-
texture.minFilter = WEBGL_FILTERS[sampler.minFilter] || LinearMipmapLinearFilter;
|
|
1704
|
-
texture.wrapS = WEBGL_WRAPPINGS[sampler.wrapS] || RepeatWrapping;
|
|
1705
|
-
texture.wrapT = WEBGL_WRAPPINGS[sampler.wrapT] || RepeatWrapping;
|
|
1706
|
-
parser.associations.set(texture, { textures: textureIndex });
|
|
1707
|
-
return texture;
|
|
1708
|
-
}).catch(function() {
|
|
1709
|
-
return null;
|
|
1710
|
-
});
|
|
1711
|
-
this.textureCache[cacheKey] = promise;
|
|
1712
|
-
return promise;
|
|
1713
|
-
}
|
|
1714
|
-
loadImageSource(sourceIndex, loader) {
|
|
1715
|
-
const parser = this;
|
|
1716
|
-
const json = this.json;
|
|
1717
|
-
const options = this.options;
|
|
1718
|
-
if (this.sourceCache[sourceIndex] !== void 0) {
|
|
1719
|
-
return this.sourceCache[sourceIndex].then((texture) => texture.clone());
|
|
1720
|
-
}
|
|
1721
|
-
const sourceDef = json.images[sourceIndex];
|
|
1722
|
-
const URL = self.URL || self.webkitURL;
|
|
1723
|
-
let sourceURI = sourceDef.uri || "";
|
|
1724
|
-
let isObjectURL = false;
|
|
1725
|
-
if (sourceDef.bufferView !== void 0) {
|
|
1726
|
-
sourceURI = parser.getDependency("bufferView", sourceDef.bufferView).then(function(bufferView) {
|
|
1727
|
-
isObjectURL = true;
|
|
1728
|
-
const blob = new Blob([bufferView], { type: sourceDef.mimeType });
|
|
1729
|
-
sourceURI = URL.createObjectURL(blob);
|
|
1730
|
-
return sourceURI;
|
|
1731
|
-
});
|
|
1732
|
-
} else if (sourceDef.uri === void 0) {
|
|
1733
|
-
throw new Error("THREE.GLTFLoader: Image " + sourceIndex + " is missing URI and bufferView");
|
|
1734
|
-
}
|
|
1735
|
-
const promise = Promise.resolve(sourceURI).then(function(sourceURI2) {
|
|
1736
|
-
return new Promise(function(resolve, reject) {
|
|
1737
|
-
let onLoad = resolve;
|
|
1738
|
-
if (loader.isImageBitmapLoader === true) {
|
|
1739
|
-
onLoad = function(imageBitmap) {
|
|
1740
|
-
const texture = new Texture(imageBitmap);
|
|
1741
|
-
texture.needsUpdate = true;
|
|
1742
|
-
resolve(texture);
|
|
1743
|
-
};
|
|
1744
|
-
}
|
|
1745
|
-
loader.load(LoaderUtils.resolveURL(sourceURI2, options.path), onLoad, void 0, reject);
|
|
1746
|
-
});
|
|
1747
|
-
}).then(function(texture) {
|
|
1748
|
-
if (isObjectURL === true) {
|
|
1749
|
-
URL.revokeObjectURL(sourceURI);
|
|
1750
|
-
}
|
|
1751
|
-
texture.userData.mimeType = sourceDef.mimeType || getImageURIMimeType(sourceDef.uri);
|
|
1752
|
-
return texture;
|
|
1753
|
-
}).catch(function(error) {
|
|
1754
|
-
console.error("THREE.GLTFLoader: Couldn't load texture", sourceURI);
|
|
1755
|
-
throw error;
|
|
1756
|
-
});
|
|
1757
|
-
this.sourceCache[sourceIndex] = promise;
|
|
1758
|
-
return promise;
|
|
1759
|
-
}
|
|
1760
|
-
/**
|
|
1761
|
-
* Asynchronously assigns a texture to the given material parameters.
|
|
1762
|
-
* @param {Object} materialParams
|
|
1763
|
-
* @param {string} mapName
|
|
1764
|
-
* @param {Object} mapDef
|
|
1765
|
-
* @return {Promise<Texture>}
|
|
1766
|
-
*/
|
|
1767
|
-
assignTexture(materialParams, mapName, mapDef, encoding) {
|
|
1768
|
-
const parser = this;
|
|
1769
|
-
return this.getDependency("texture", mapDef.index).then(function(texture) {
|
|
1770
|
-
if (!texture)
|
|
1771
|
-
return null;
|
|
1772
|
-
if (mapDef.texCoord !== void 0 && mapDef.texCoord > 0) {
|
|
1773
|
-
texture = texture.clone();
|
|
1774
|
-
texture.channel = mapDef.texCoord;
|
|
1775
|
-
}
|
|
1776
|
-
if (parser.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM]) {
|
|
1777
|
-
const transform = mapDef.extensions !== void 0 ? mapDef.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM] : void 0;
|
|
1778
|
-
if (transform) {
|
|
1779
|
-
const gltfReference = parser.associations.get(texture);
|
|
1780
|
-
texture = parser.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM].extendTexture(texture, transform);
|
|
1781
|
-
parser.associations.set(texture, gltfReference);
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
if (encoding !== void 0) {
|
|
1785
|
-
if ("colorSpace" in texture)
|
|
1786
|
-
texture.colorSpace = encoding === 3001 ? "srgb" : "srgb-linear";
|
|
1787
|
-
else
|
|
1788
|
-
texture.encoding = encoding;
|
|
1789
|
-
}
|
|
1790
|
-
materialParams[mapName] = texture;
|
|
1791
|
-
return texture;
|
|
1792
|
-
});
|
|
1793
|
-
}
|
|
1794
|
-
/**
|
|
1795
|
-
* Assigns final material to a Mesh, Line, or Points instance. The instance
|
|
1796
|
-
* already has a material (generated from the glTF material options alone)
|
|
1797
|
-
* but reuse of the same glTF material may require multiple threejs materials
|
|
1798
|
-
* to accommodate different primitive types, defines, etc. New materials will
|
|
1799
|
-
* be created if necessary, and reused from a cache.
|
|
1800
|
-
* @param {Object3D} mesh Mesh, Line, or Points instance.
|
|
1801
|
-
*/
|
|
1802
|
-
assignFinalMaterial(mesh) {
|
|
1803
|
-
const geometry = mesh.geometry;
|
|
1804
|
-
let material = mesh.material;
|
|
1805
|
-
const useDerivativeTangents = geometry.attributes.tangent === void 0;
|
|
1806
|
-
const useVertexColors = geometry.attributes.color !== void 0;
|
|
1807
|
-
const useFlatShading = geometry.attributes.normal === void 0;
|
|
1808
|
-
if (mesh.isPoints) {
|
|
1809
|
-
const cacheKey = "PointsMaterial:" + material.uuid;
|
|
1810
|
-
let pointsMaterial = this.cache.get(cacheKey);
|
|
1811
|
-
if (!pointsMaterial) {
|
|
1812
|
-
pointsMaterial = new PointsMaterial();
|
|
1813
|
-
Material.prototype.copy.call(pointsMaterial, material);
|
|
1814
|
-
pointsMaterial.color.copy(material.color);
|
|
1815
|
-
pointsMaterial.map = material.map;
|
|
1816
|
-
pointsMaterial.sizeAttenuation = false;
|
|
1817
|
-
this.cache.add(cacheKey, pointsMaterial);
|
|
1818
|
-
}
|
|
1819
|
-
material = pointsMaterial;
|
|
1820
|
-
} else if (mesh.isLine) {
|
|
1821
|
-
const cacheKey = "LineBasicMaterial:" + material.uuid;
|
|
1822
|
-
let lineMaterial = this.cache.get(cacheKey);
|
|
1823
|
-
if (!lineMaterial) {
|
|
1824
|
-
lineMaterial = new LineBasicMaterial();
|
|
1825
|
-
Material.prototype.copy.call(lineMaterial, material);
|
|
1826
|
-
lineMaterial.color.copy(material.color);
|
|
1827
|
-
lineMaterial.map = material.map;
|
|
1828
|
-
this.cache.add(cacheKey, lineMaterial);
|
|
1829
|
-
}
|
|
1830
|
-
material = lineMaterial;
|
|
1831
|
-
}
|
|
1832
|
-
if (useDerivativeTangents || useVertexColors || useFlatShading) {
|
|
1833
|
-
let cacheKey = "ClonedMaterial:" + material.uuid + ":";
|
|
1834
|
-
if (useDerivativeTangents)
|
|
1835
|
-
cacheKey += "derivative-tangents:";
|
|
1836
|
-
if (useVertexColors)
|
|
1837
|
-
cacheKey += "vertex-colors:";
|
|
1838
|
-
if (useFlatShading)
|
|
1839
|
-
cacheKey += "flat-shading:";
|
|
1840
|
-
let cachedMaterial = this.cache.get(cacheKey);
|
|
1841
|
-
if (!cachedMaterial) {
|
|
1842
|
-
cachedMaterial = material.clone();
|
|
1843
|
-
if (useVertexColors)
|
|
1844
|
-
cachedMaterial.vertexColors = true;
|
|
1845
|
-
if (useFlatShading)
|
|
1846
|
-
cachedMaterial.flatShading = true;
|
|
1847
|
-
if (useDerivativeTangents) {
|
|
1848
|
-
if (cachedMaterial.normalScale)
|
|
1849
|
-
cachedMaterial.normalScale.y *= -1;
|
|
1850
|
-
if (cachedMaterial.clearcoatNormalScale)
|
|
1851
|
-
cachedMaterial.clearcoatNormalScale.y *= -1;
|
|
1852
|
-
}
|
|
1853
|
-
this.cache.add(cacheKey, cachedMaterial);
|
|
1854
|
-
this.associations.set(cachedMaterial, this.associations.get(material));
|
|
1855
|
-
}
|
|
1856
|
-
material = cachedMaterial;
|
|
1857
|
-
}
|
|
1858
|
-
mesh.material = material;
|
|
1859
|
-
}
|
|
1860
|
-
getMaterialType() {
|
|
1861
|
-
return MeshStandardMaterial;
|
|
1862
|
-
}
|
|
1863
|
-
/**
|
|
1864
|
-
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
|
|
1865
|
-
* @param {number} materialIndex
|
|
1866
|
-
* @return {Promise<Material>}
|
|
1867
|
-
*/
|
|
1868
|
-
loadMaterial(materialIndex) {
|
|
1869
|
-
const parser = this;
|
|
1870
|
-
const json = this.json;
|
|
1871
|
-
const extensions = this.extensions;
|
|
1872
|
-
const materialDef = json.materials[materialIndex];
|
|
1873
|
-
let materialType;
|
|
1874
|
-
const materialParams = {};
|
|
1875
|
-
const materialExtensions = materialDef.extensions || {};
|
|
1876
|
-
const pending = [];
|
|
1877
|
-
if (materialExtensions[EXTENSIONS.KHR_MATERIALS_UNLIT]) {
|
|
1878
|
-
const kmuExtension = extensions[EXTENSIONS.KHR_MATERIALS_UNLIT];
|
|
1879
|
-
materialType = kmuExtension.getMaterialType();
|
|
1880
|
-
pending.push(kmuExtension.extendParams(materialParams, materialDef, parser));
|
|
1881
|
-
} else {
|
|
1882
|
-
const metallicRoughness = materialDef.pbrMetallicRoughness || {};
|
|
1883
|
-
materialParams.color = new Color(1, 1, 1);
|
|
1884
|
-
materialParams.opacity = 1;
|
|
1885
|
-
if (Array.isArray(metallicRoughness.baseColorFactor)) {
|
|
1886
|
-
const array = metallicRoughness.baseColorFactor;
|
|
1887
|
-
materialParams.color.fromArray(array);
|
|
1888
|
-
materialParams.opacity = array[3];
|
|
1889
|
-
}
|
|
1890
|
-
if (metallicRoughness.baseColorTexture !== void 0) {
|
|
1891
|
-
pending.push(parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture, 3001));
|
|
1892
|
-
}
|
|
1893
|
-
materialParams.metalness = metallicRoughness.metallicFactor !== void 0 ? metallicRoughness.metallicFactor : 1;
|
|
1894
|
-
materialParams.roughness = metallicRoughness.roughnessFactor !== void 0 ? metallicRoughness.roughnessFactor : 1;
|
|
1895
|
-
if (metallicRoughness.metallicRoughnessTexture !== void 0) {
|
|
1896
|
-
pending.push(parser.assignTexture(materialParams, "metalnessMap", metallicRoughness.metallicRoughnessTexture));
|
|
1897
|
-
pending.push(parser.assignTexture(materialParams, "roughnessMap", metallicRoughness.metallicRoughnessTexture));
|
|
1898
|
-
}
|
|
1899
|
-
materialType = this._invokeOne(function(ext) {
|
|
1900
|
-
return ext.getMaterialType && ext.getMaterialType(materialIndex);
|
|
1901
|
-
});
|
|
1902
|
-
pending.push(
|
|
1903
|
-
Promise.all(
|
|
1904
|
-
this._invokeAll(function(ext) {
|
|
1905
|
-
return ext.extendMaterialParams && ext.extendMaterialParams(materialIndex, materialParams);
|
|
1906
|
-
})
|
|
1907
|
-
)
|
|
1908
|
-
);
|
|
1909
|
-
}
|
|
1910
|
-
if (materialDef.doubleSided === true) {
|
|
1911
|
-
materialParams.side = DoubleSide;
|
|
1912
|
-
}
|
|
1913
|
-
const alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE;
|
|
1914
|
-
if (alphaMode === ALPHA_MODES.BLEND) {
|
|
1915
|
-
materialParams.transparent = true;
|
|
1916
|
-
materialParams.depthWrite = false;
|
|
1917
|
-
} else {
|
|
1918
|
-
materialParams.transparent = false;
|
|
1919
|
-
if (alphaMode === ALPHA_MODES.MASK) {
|
|
1920
|
-
materialParams.alphaTest = materialDef.alphaCutoff !== void 0 ? materialDef.alphaCutoff : 0.5;
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
if (materialDef.normalTexture !== void 0 && materialType !== MeshBasicMaterial) {
|
|
1924
|
-
pending.push(parser.assignTexture(materialParams, "normalMap", materialDef.normalTexture));
|
|
1925
|
-
materialParams.normalScale = new Vector2(1, 1);
|
|
1926
|
-
if (materialDef.normalTexture.scale !== void 0) {
|
|
1927
|
-
const scale = materialDef.normalTexture.scale;
|
|
1928
|
-
materialParams.normalScale.set(scale, scale);
|
|
1929
|
-
}
|
|
1930
|
-
}
|
|
1931
|
-
if (materialDef.occlusionTexture !== void 0 && materialType !== MeshBasicMaterial) {
|
|
1932
|
-
pending.push(parser.assignTexture(materialParams, "aoMap", materialDef.occlusionTexture));
|
|
1933
|
-
if (materialDef.occlusionTexture.strength !== void 0) {
|
|
1934
|
-
materialParams.aoMapIntensity = materialDef.occlusionTexture.strength;
|
|
1935
|
-
}
|
|
1936
|
-
}
|
|
1937
|
-
if (materialDef.emissiveFactor !== void 0 && materialType !== MeshBasicMaterial) {
|
|
1938
|
-
materialParams.emissive = new Color().fromArray(materialDef.emissiveFactor);
|
|
1939
|
-
}
|
|
1940
|
-
if (materialDef.emissiveTexture !== void 0 && materialType !== MeshBasicMaterial) {
|
|
1941
|
-
pending.push(parser.assignTexture(materialParams, "emissiveMap", materialDef.emissiveTexture, 3001));
|
|
1942
|
-
}
|
|
1943
|
-
return Promise.all(pending).then(function() {
|
|
1944
|
-
const material = new materialType(materialParams);
|
|
1945
|
-
if (materialDef.name)
|
|
1946
|
-
material.name = materialDef.name;
|
|
1947
|
-
assignExtrasToUserData(material, materialDef);
|
|
1948
|
-
parser.associations.set(material, { materials: materialIndex });
|
|
1949
|
-
if (materialDef.extensions)
|
|
1950
|
-
addUnknownExtensionsToUserData(extensions, material, materialDef);
|
|
1951
|
-
return material;
|
|
1952
|
-
});
|
|
1953
|
-
}
|
|
1954
|
-
/** When Object3D instances are targeted by animation, they need unique names. */
|
|
1955
|
-
createUniqueName(originalName) {
|
|
1956
|
-
const sanitizedName = PropertyBinding.sanitizeNodeName(originalName || "");
|
|
1957
|
-
if (sanitizedName in this.nodeNamesUsed) {
|
|
1958
|
-
return sanitizedName + "_" + ++this.nodeNamesUsed[sanitizedName];
|
|
1959
|
-
} else {
|
|
1960
|
-
this.nodeNamesUsed[sanitizedName] = 0;
|
|
1961
|
-
return sanitizedName;
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1964
|
-
/**
|
|
1965
|
-
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
|
|
1966
|
-
*
|
|
1967
|
-
* Creates BufferGeometries from primitives.
|
|
1968
|
-
*
|
|
1969
|
-
* @param {Array<GLTF.Primitive>} primitives
|
|
1970
|
-
* @return {Promise<Array<BufferGeometry>>}
|
|
1971
|
-
*/
|
|
1972
|
-
loadGeometries(primitives) {
|
|
1973
|
-
const parser = this;
|
|
1974
|
-
const extensions = this.extensions;
|
|
1975
|
-
const cache = this.primitiveCache;
|
|
1976
|
-
function createDracoPrimitive(primitive) {
|
|
1977
|
-
return extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(primitive, parser).then(function(geometry) {
|
|
1978
|
-
return addPrimitiveAttributes(geometry, primitive, parser);
|
|
1979
|
-
});
|
|
1980
|
-
}
|
|
1981
|
-
const pending = [];
|
|
1982
|
-
for (let i = 0, il = primitives.length; i < il; i++) {
|
|
1983
|
-
const primitive = primitives[i];
|
|
1984
|
-
const cacheKey = createPrimitiveKey(primitive);
|
|
1985
|
-
const cached = cache[cacheKey];
|
|
1986
|
-
if (cached) {
|
|
1987
|
-
pending.push(cached.promise);
|
|
1988
|
-
} else {
|
|
1989
|
-
let geometryPromise;
|
|
1990
|
-
if (primitive.extensions && primitive.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION]) {
|
|
1991
|
-
geometryPromise = createDracoPrimitive(primitive);
|
|
1992
|
-
} else {
|
|
1993
|
-
geometryPromise = addPrimitiveAttributes(new BufferGeometry(), primitive, parser);
|
|
1994
|
-
}
|
|
1995
|
-
cache[cacheKey] = { primitive, promise: geometryPromise };
|
|
1996
|
-
pending.push(geometryPromise);
|
|
1997
|
-
}
|
|
1998
|
-
}
|
|
1999
|
-
return Promise.all(pending);
|
|
2000
|
-
}
|
|
2001
|
-
/**
|
|
2002
|
-
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
|
|
2003
|
-
* @param {number} meshIndex
|
|
2004
|
-
* @return {Promise<Group|Mesh|SkinnedMesh>}
|
|
2005
|
-
*/
|
|
2006
|
-
loadMesh(meshIndex) {
|
|
2007
|
-
const parser = this;
|
|
2008
|
-
const json = this.json;
|
|
2009
|
-
const extensions = this.extensions;
|
|
2010
|
-
const meshDef = json.meshes[meshIndex];
|
|
2011
|
-
const primitives = meshDef.primitives;
|
|
2012
|
-
const pending = [];
|
|
2013
|
-
for (let i = 0, il = primitives.length; i < il; i++) {
|
|
2014
|
-
const material = primitives[i].material === void 0 ? createDefaultMaterial(this.cache) : this.getDependency("material", primitives[i].material);
|
|
2015
|
-
pending.push(material);
|
|
2016
|
-
}
|
|
2017
|
-
pending.push(parser.loadGeometries(primitives));
|
|
2018
|
-
return Promise.all(pending).then(function(results) {
|
|
2019
|
-
const materials = results.slice(0, results.length - 1);
|
|
2020
|
-
const geometries = results[results.length - 1];
|
|
2021
|
-
const meshes = [];
|
|
2022
|
-
for (let i = 0, il = geometries.length; i < il; i++) {
|
|
2023
|
-
const geometry = geometries[i];
|
|
2024
|
-
const primitive = primitives[i];
|
|
2025
|
-
let mesh;
|
|
2026
|
-
const material = materials[i];
|
|
2027
|
-
if (primitive.mode === WEBGL_CONSTANTS.TRIANGLES || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN || primitive.mode === void 0) {
|
|
2028
|
-
mesh = meshDef.isSkinnedMesh === true ? new SkinnedMesh(geometry, material) : new Mesh(geometry, material);
|
|
2029
|
-
if (mesh.isSkinnedMesh === true) {
|
|
2030
|
-
mesh.normalizeSkinWeights();
|
|
2031
|
-
}
|
|
2032
|
-
if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP) {
|
|
2033
|
-
mesh.geometry = toTrianglesDrawMode(mesh.geometry, TriangleStripDrawMode);
|
|
2034
|
-
} else if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN) {
|
|
2035
|
-
mesh.geometry = toTrianglesDrawMode(mesh.geometry, TriangleFanDrawMode);
|
|
2036
|
-
}
|
|
2037
|
-
} else if (primitive.mode === WEBGL_CONSTANTS.LINES) {
|
|
2038
|
-
mesh = new LineSegments(geometry, material);
|
|
2039
|
-
} else if (primitive.mode === WEBGL_CONSTANTS.LINE_STRIP) {
|
|
2040
|
-
mesh = new Line(geometry, material);
|
|
2041
|
-
} else if (primitive.mode === WEBGL_CONSTANTS.LINE_LOOP) {
|
|
2042
|
-
mesh = new LineLoop(geometry, material);
|
|
2043
|
-
} else if (primitive.mode === WEBGL_CONSTANTS.POINTS) {
|
|
2044
|
-
mesh = new Points(geometry, material);
|
|
2045
|
-
} else {
|
|
2046
|
-
throw new Error("THREE.GLTFLoader: Primitive mode unsupported: " + primitive.mode);
|
|
2047
|
-
}
|
|
2048
|
-
if (Object.keys(mesh.geometry.morphAttributes).length > 0) {
|
|
2049
|
-
updateMorphTargets(mesh, meshDef);
|
|
2050
|
-
}
|
|
2051
|
-
mesh.name = parser.createUniqueName(meshDef.name || "mesh_" + meshIndex);
|
|
2052
|
-
assignExtrasToUserData(mesh, meshDef);
|
|
2053
|
-
if (primitive.extensions)
|
|
2054
|
-
addUnknownExtensionsToUserData(extensions, mesh, primitive);
|
|
2055
|
-
parser.assignFinalMaterial(mesh);
|
|
2056
|
-
meshes.push(mesh);
|
|
2057
|
-
}
|
|
2058
|
-
for (let i = 0, il = meshes.length; i < il; i++) {
|
|
2059
|
-
parser.associations.set(meshes[i], {
|
|
2060
|
-
meshes: meshIndex,
|
|
2061
|
-
primitives: i
|
|
2062
|
-
});
|
|
2063
|
-
}
|
|
2064
|
-
if (meshes.length === 1) {
|
|
2065
|
-
if (meshDef.extensions)
|
|
2066
|
-
addUnknownExtensionsToUserData(extensions, meshes[0], meshDef);
|
|
2067
|
-
return meshes[0];
|
|
2068
|
-
}
|
|
2069
|
-
const group = new Group();
|
|
2070
|
-
if (meshDef.extensions)
|
|
2071
|
-
addUnknownExtensionsToUserData(extensions, group, meshDef);
|
|
2072
|
-
parser.associations.set(group, { meshes: meshIndex });
|
|
2073
|
-
for (let i = 0, il = meshes.length; i < il; i++) {
|
|
2074
|
-
group.add(meshes[i]);
|
|
2075
|
-
}
|
|
2076
|
-
return group;
|
|
2077
|
-
});
|
|
2078
|
-
}
|
|
2079
|
-
/**
|
|
2080
|
-
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
|
|
2081
|
-
* @param {number} cameraIndex
|
|
2082
|
-
* @return {Promise<THREE.Camera>}
|
|
2083
|
-
*/
|
|
2084
|
-
loadCamera(cameraIndex) {
|
|
2085
|
-
let camera;
|
|
2086
|
-
const cameraDef = this.json.cameras[cameraIndex];
|
|
2087
|
-
const params = cameraDef[cameraDef.type];
|
|
2088
|
-
if (!params) {
|
|
2089
|
-
console.warn("THREE.GLTFLoader: Missing camera parameters.");
|
|
2090
|
-
return;
|
|
2091
|
-
}
|
|
2092
|
-
if (cameraDef.type === "perspective") {
|
|
2093
|
-
camera = new PerspectiveCamera(
|
|
2094
|
-
MathUtils.radToDeg(params.yfov),
|
|
2095
|
-
params.aspectRatio || 1,
|
|
2096
|
-
params.znear || 1,
|
|
2097
|
-
params.zfar || 2e6
|
|
2098
|
-
);
|
|
2099
|
-
} else if (cameraDef.type === "orthographic") {
|
|
2100
|
-
camera = new OrthographicCamera(-params.xmag, params.xmag, params.ymag, -params.ymag, params.znear, params.zfar);
|
|
2101
|
-
}
|
|
2102
|
-
if (cameraDef.name)
|
|
2103
|
-
camera.name = this.createUniqueName(cameraDef.name);
|
|
2104
|
-
assignExtrasToUserData(camera, cameraDef);
|
|
2105
|
-
return Promise.resolve(camera);
|
|
2106
|
-
}
|
|
2107
|
-
/**
|
|
2108
|
-
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
|
|
2109
|
-
* @param {number} skinIndex
|
|
2110
|
-
* @return {Promise<Skeleton>}
|
|
2111
|
-
*/
|
|
2112
|
-
loadSkin(skinIndex) {
|
|
2113
|
-
const skinDef = this.json.skins[skinIndex];
|
|
2114
|
-
const pending = [];
|
|
2115
|
-
for (let i = 0, il = skinDef.joints.length; i < il; i++) {
|
|
2116
|
-
pending.push(this._loadNodeShallow(skinDef.joints[i]));
|
|
2117
|
-
}
|
|
2118
|
-
if (skinDef.inverseBindMatrices !== void 0) {
|
|
2119
|
-
pending.push(this.getDependency("accessor", skinDef.inverseBindMatrices));
|
|
2120
|
-
} else {
|
|
2121
|
-
pending.push(null);
|
|
2122
|
-
}
|
|
2123
|
-
return Promise.all(pending).then(function(results) {
|
|
2124
|
-
const inverseBindMatrices = results.pop();
|
|
2125
|
-
const jointNodes = results;
|
|
2126
|
-
const bones = [];
|
|
2127
|
-
const boneInverses = [];
|
|
2128
|
-
for (let i = 0, il = jointNodes.length; i < il; i++) {
|
|
2129
|
-
const jointNode = jointNodes[i];
|
|
2130
|
-
if (jointNode) {
|
|
2131
|
-
bones.push(jointNode);
|
|
2132
|
-
const mat = new Matrix4();
|
|
2133
|
-
if (inverseBindMatrices !== null) {
|
|
2134
|
-
mat.fromArray(inverseBindMatrices.array, i * 16);
|
|
2135
|
-
}
|
|
2136
|
-
boneInverses.push(mat);
|
|
2137
|
-
} else {
|
|
2138
|
-
console.warn('THREE.GLTFLoader: Joint "%s" could not be found.', skinDef.joints[i]);
|
|
2139
|
-
}
|
|
2140
|
-
}
|
|
2141
|
-
return new Skeleton(bones, boneInverses);
|
|
2142
|
-
});
|
|
2143
|
-
}
|
|
2144
|
-
/**
|
|
2145
|
-
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
|
|
2146
|
-
* @param {number} animationIndex
|
|
2147
|
-
* @return {Promise<AnimationClip>}
|
|
2148
|
-
*/
|
|
2149
|
-
loadAnimation(animationIndex) {
|
|
2150
|
-
const json = this.json;
|
|
2151
|
-
const animationDef = json.animations[animationIndex];
|
|
2152
|
-
const animationName = animationDef.name ? animationDef.name : "animation_" + animationIndex;
|
|
2153
|
-
const pendingNodes = [];
|
|
2154
|
-
const pendingInputAccessors = [];
|
|
2155
|
-
const pendingOutputAccessors = [];
|
|
2156
|
-
const pendingSamplers = [];
|
|
2157
|
-
const pendingTargets = [];
|
|
2158
|
-
for (let i = 0, il = animationDef.channels.length; i < il; i++) {
|
|
2159
|
-
const channel = animationDef.channels[i];
|
|
2160
|
-
const sampler = animationDef.samplers[channel.sampler];
|
|
2161
|
-
const target = channel.target;
|
|
2162
|
-
const name = target.node;
|
|
2163
|
-
const input = animationDef.parameters !== void 0 ? animationDef.parameters[sampler.input] : sampler.input;
|
|
2164
|
-
const output = animationDef.parameters !== void 0 ? animationDef.parameters[sampler.output] : sampler.output;
|
|
2165
|
-
if (target.node === void 0)
|
|
2166
|
-
continue;
|
|
2167
|
-
pendingNodes.push(this.getDependency("node", name));
|
|
2168
|
-
pendingInputAccessors.push(this.getDependency("accessor", input));
|
|
2169
|
-
pendingOutputAccessors.push(this.getDependency("accessor", output));
|
|
2170
|
-
pendingSamplers.push(sampler);
|
|
2171
|
-
pendingTargets.push(target);
|
|
2172
|
-
}
|
|
2173
|
-
return Promise.all([
|
|
2174
|
-
Promise.all(pendingNodes),
|
|
2175
|
-
Promise.all(pendingInputAccessors),
|
|
2176
|
-
Promise.all(pendingOutputAccessors),
|
|
2177
|
-
Promise.all(pendingSamplers),
|
|
2178
|
-
Promise.all(pendingTargets)
|
|
2179
|
-
]).then(function(dependencies) {
|
|
2180
|
-
const nodes = dependencies[0];
|
|
2181
|
-
const inputAccessors = dependencies[1];
|
|
2182
|
-
const outputAccessors = dependencies[2];
|
|
2183
|
-
const samplers = dependencies[3];
|
|
2184
|
-
const targets = dependencies[4];
|
|
2185
|
-
const tracks = [];
|
|
2186
|
-
for (let i = 0, il = nodes.length; i < il; i++) {
|
|
2187
|
-
const node = nodes[i];
|
|
2188
|
-
const inputAccessor = inputAccessors[i];
|
|
2189
|
-
const outputAccessor = outputAccessors[i];
|
|
2190
|
-
const sampler = samplers[i];
|
|
2191
|
-
const target = targets[i];
|
|
2192
|
-
if (node === void 0)
|
|
2193
|
-
continue;
|
|
2194
|
-
node.updateMatrix();
|
|
2195
|
-
let TypedKeyframeTrack;
|
|
2196
|
-
switch (PATH_PROPERTIES[target.path]) {
|
|
2197
|
-
case PATH_PROPERTIES.weights:
|
|
2198
|
-
TypedKeyframeTrack = NumberKeyframeTrack;
|
|
2199
|
-
break;
|
|
2200
|
-
case PATH_PROPERTIES.rotation:
|
|
2201
|
-
TypedKeyframeTrack = QuaternionKeyframeTrack;
|
|
2202
|
-
break;
|
|
2203
|
-
case PATH_PROPERTIES.position:
|
|
2204
|
-
case PATH_PROPERTIES.scale:
|
|
2205
|
-
default:
|
|
2206
|
-
TypedKeyframeTrack = VectorKeyframeTrack;
|
|
2207
|
-
break;
|
|
2208
|
-
}
|
|
2209
|
-
const targetName = node.name ? node.name : node.uuid;
|
|
2210
|
-
const interpolation = sampler.interpolation !== void 0 ? INTERPOLATION[sampler.interpolation] : InterpolateLinear;
|
|
2211
|
-
const targetNames = [];
|
|
2212
|
-
if (PATH_PROPERTIES[target.path] === PATH_PROPERTIES.weights) {
|
|
2213
|
-
node.traverse(function(object) {
|
|
2214
|
-
if (object.morphTargetInfluences) {
|
|
2215
|
-
targetNames.push(object.name ? object.name : object.uuid);
|
|
2216
|
-
}
|
|
2217
|
-
});
|
|
2218
|
-
} else {
|
|
2219
|
-
targetNames.push(targetName);
|
|
2220
|
-
}
|
|
2221
|
-
let outputArray = outputAccessor.array;
|
|
2222
|
-
if (outputAccessor.normalized) {
|
|
2223
|
-
const scale = getNormalizedComponentScale(outputArray.constructor);
|
|
2224
|
-
const scaled = new Float32Array(outputArray.length);
|
|
2225
|
-
for (let j = 0, jl = outputArray.length; j < jl; j++) {
|
|
2226
|
-
scaled[j] = outputArray[j] * scale;
|
|
2227
|
-
}
|
|
2228
|
-
outputArray = scaled;
|
|
2229
|
-
}
|
|
2230
|
-
for (let j = 0, jl = targetNames.length; j < jl; j++) {
|
|
2231
|
-
const track = new TypedKeyframeTrack(
|
|
2232
|
-
targetNames[j] + "." + PATH_PROPERTIES[target.path],
|
|
2233
|
-
inputAccessor.array,
|
|
2234
|
-
outputArray,
|
|
2235
|
-
interpolation
|
|
2236
|
-
);
|
|
2237
|
-
if (sampler.interpolation === "CUBICSPLINE") {
|
|
2238
|
-
track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline(result) {
|
|
2239
|
-
const interpolantType = this instanceof QuaternionKeyframeTrack ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
|
|
2240
|
-
return new interpolantType(this.times, this.values, this.getValueSize() / 3, result);
|
|
2241
|
-
};
|
|
2242
|
-
track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
|
|
2243
|
-
}
|
|
2244
|
-
tracks.push(track);
|
|
2245
|
-
}
|
|
2246
|
-
}
|
|
2247
|
-
return new AnimationClip(animationName, void 0, tracks);
|
|
2248
|
-
});
|
|
2249
|
-
}
|
|
2250
|
-
createNodeMesh(nodeIndex) {
|
|
2251
|
-
const json = this.json;
|
|
2252
|
-
const parser = this;
|
|
2253
|
-
const nodeDef = json.nodes[nodeIndex];
|
|
2254
|
-
if (nodeDef.mesh === void 0)
|
|
2255
|
-
return null;
|
|
2256
|
-
return parser.getDependency("mesh", nodeDef.mesh).then(function(mesh) {
|
|
2257
|
-
const node = parser._getNodeRef(parser.meshCache, nodeDef.mesh, mesh);
|
|
2258
|
-
if (nodeDef.weights !== void 0) {
|
|
2259
|
-
node.traverse(function(o) {
|
|
2260
|
-
if (!o.isMesh)
|
|
2261
|
-
return;
|
|
2262
|
-
for (let i = 0, il = nodeDef.weights.length; i < il; i++) {
|
|
2263
|
-
o.morphTargetInfluences[i] = nodeDef.weights[i];
|
|
2264
|
-
}
|
|
2265
|
-
});
|
|
2266
|
-
}
|
|
2267
|
-
return node;
|
|
2268
|
-
});
|
|
2269
|
-
}
|
|
2270
|
-
/**
|
|
2271
|
-
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
|
|
2272
|
-
* @param {number} nodeIndex
|
|
2273
|
-
* @return {Promise<Object3D>}
|
|
2274
|
-
*/
|
|
2275
|
-
loadNode(nodeIndex) {
|
|
2276
|
-
const json = this.json;
|
|
2277
|
-
const parser = this;
|
|
2278
|
-
const nodeDef = json.nodes[nodeIndex];
|
|
2279
|
-
const nodePending = parser._loadNodeShallow(nodeIndex);
|
|
2280
|
-
const childPending = [];
|
|
2281
|
-
const childrenDef = nodeDef.children || [];
|
|
2282
|
-
for (let i = 0, il = childrenDef.length; i < il; i++) {
|
|
2283
|
-
childPending.push(parser.getDependency("node", childrenDef[i]));
|
|
2284
|
-
}
|
|
2285
|
-
const skeletonPending = nodeDef.skin === void 0 ? Promise.resolve(null) : parser.getDependency("skin", nodeDef.skin);
|
|
2286
|
-
return Promise.all([nodePending, Promise.all(childPending), skeletonPending]).then(function(results) {
|
|
2287
|
-
const node = results[0];
|
|
2288
|
-
const children = results[1];
|
|
2289
|
-
const skeleton = results[2];
|
|
2290
|
-
if (skeleton !== null) {
|
|
2291
|
-
node.traverse(function(mesh) {
|
|
2292
|
-
if (!mesh.isSkinnedMesh)
|
|
2293
|
-
return;
|
|
2294
|
-
mesh.bind(skeleton, _identityMatrix);
|
|
2295
|
-
});
|
|
2296
|
-
}
|
|
2297
|
-
for (let i = 0, il = children.length; i < il; i++) {
|
|
2298
|
-
node.add(children[i]);
|
|
2299
|
-
}
|
|
2300
|
-
return node;
|
|
2301
|
-
});
|
|
2302
|
-
}
|
|
2303
|
-
// ._loadNodeShallow() parses a single node.
|
|
2304
|
-
// skin and child nodes are created and added in .loadNode() (no '_' prefix).
|
|
2305
|
-
_loadNodeShallow(nodeIndex) {
|
|
2306
|
-
const json = this.json;
|
|
2307
|
-
const extensions = this.extensions;
|
|
2308
|
-
const parser = this;
|
|
2309
|
-
if (this.nodeCache[nodeIndex] !== void 0) {
|
|
2310
|
-
return this.nodeCache[nodeIndex];
|
|
2311
|
-
}
|
|
2312
|
-
const nodeDef = json.nodes[nodeIndex];
|
|
2313
|
-
const nodeName = nodeDef.name ? parser.createUniqueName(nodeDef.name) : "";
|
|
2314
|
-
const pending = [];
|
|
2315
|
-
const meshPromise = parser._invokeOne(function(ext) {
|
|
2316
|
-
return ext.createNodeMesh && ext.createNodeMesh(nodeIndex);
|
|
2317
|
-
});
|
|
2318
|
-
if (meshPromise) {
|
|
2319
|
-
pending.push(meshPromise);
|
|
2320
|
-
}
|
|
2321
|
-
if (nodeDef.camera !== void 0) {
|
|
2322
|
-
pending.push(
|
|
2323
|
-
parser.getDependency("camera", nodeDef.camera).then(function(camera) {
|
|
2324
|
-
return parser._getNodeRef(parser.cameraCache, nodeDef.camera, camera);
|
|
2325
|
-
})
|
|
2326
|
-
);
|
|
2327
|
-
}
|
|
2328
|
-
parser._invokeAll(function(ext) {
|
|
2329
|
-
return ext.createNodeAttachment && ext.createNodeAttachment(nodeIndex);
|
|
2330
|
-
}).forEach(function(promise) {
|
|
2331
|
-
pending.push(promise);
|
|
2332
|
-
});
|
|
2333
|
-
this.nodeCache[nodeIndex] = Promise.all(pending).then(function(objects) {
|
|
2334
|
-
let node;
|
|
2335
|
-
if (nodeDef.isBone === true) {
|
|
2336
|
-
node = new Bone();
|
|
2337
|
-
} else if (objects.length > 1) {
|
|
2338
|
-
node = new Group();
|
|
2339
|
-
} else if (objects.length === 1) {
|
|
2340
|
-
node = objects[0];
|
|
2341
|
-
} else {
|
|
2342
|
-
node = new Object3D();
|
|
2343
|
-
}
|
|
2344
|
-
if (node !== objects[0]) {
|
|
2345
|
-
for (let i = 0, il = objects.length; i < il; i++) {
|
|
2346
|
-
node.add(objects[i]);
|
|
2347
|
-
}
|
|
2348
|
-
}
|
|
2349
|
-
if (nodeDef.name) {
|
|
2350
|
-
node.userData.name = nodeDef.name;
|
|
2351
|
-
node.name = nodeName;
|
|
2352
|
-
}
|
|
2353
|
-
assignExtrasToUserData(node, nodeDef);
|
|
2354
|
-
if (nodeDef.extensions)
|
|
2355
|
-
addUnknownExtensionsToUserData(extensions, node, nodeDef);
|
|
2356
|
-
if (nodeDef.matrix !== void 0) {
|
|
2357
|
-
const matrix = new Matrix4();
|
|
2358
|
-
matrix.fromArray(nodeDef.matrix);
|
|
2359
|
-
node.applyMatrix4(matrix);
|
|
2360
|
-
} else {
|
|
2361
|
-
if (nodeDef.translation !== void 0) {
|
|
2362
|
-
node.position.fromArray(nodeDef.translation);
|
|
2363
|
-
}
|
|
2364
|
-
if (nodeDef.rotation !== void 0) {
|
|
2365
|
-
node.quaternion.fromArray(nodeDef.rotation);
|
|
2366
|
-
}
|
|
2367
|
-
if (nodeDef.scale !== void 0) {
|
|
2368
|
-
node.scale.fromArray(nodeDef.scale);
|
|
2369
|
-
}
|
|
2370
|
-
}
|
|
2371
|
-
if (!parser.associations.has(node)) {
|
|
2372
|
-
parser.associations.set(node, {});
|
|
2373
|
-
}
|
|
2374
|
-
parser.associations.get(node).nodes = nodeIndex;
|
|
2375
|
-
return node;
|
|
2376
|
-
});
|
|
2377
|
-
return this.nodeCache[nodeIndex];
|
|
2378
|
-
}
|
|
2379
|
-
/**
|
|
2380
|
-
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
|
|
2381
|
-
* @param {number} sceneIndex
|
|
2382
|
-
* @return {Promise<Group>}
|
|
2383
|
-
*/
|
|
2384
|
-
loadScene(sceneIndex) {
|
|
2385
|
-
const extensions = this.extensions;
|
|
2386
|
-
const sceneDef = this.json.scenes[sceneIndex];
|
|
2387
|
-
const parser = this;
|
|
2388
|
-
const scene = new Group();
|
|
2389
|
-
if (sceneDef.name)
|
|
2390
|
-
scene.name = parser.createUniqueName(sceneDef.name);
|
|
2391
|
-
assignExtrasToUserData(scene, sceneDef);
|
|
2392
|
-
if (sceneDef.extensions)
|
|
2393
|
-
addUnknownExtensionsToUserData(extensions, scene, sceneDef);
|
|
2394
|
-
const nodeIds = sceneDef.nodes || [];
|
|
2395
|
-
const pending = [];
|
|
2396
|
-
for (let i = 0, il = nodeIds.length; i < il; i++) {
|
|
2397
|
-
pending.push(parser.getDependency("node", nodeIds[i]));
|
|
2398
|
-
}
|
|
2399
|
-
return Promise.all(pending).then(function(nodes) {
|
|
2400
|
-
for (let i = 0, il = nodes.length; i < il; i++) {
|
|
2401
|
-
scene.add(nodes[i]);
|
|
2402
|
-
}
|
|
2403
|
-
const reduceAssociations = (node) => {
|
|
2404
|
-
const reducedAssociations = /* @__PURE__ */ new Map();
|
|
2405
|
-
for (const [key, value] of parser.associations) {
|
|
2406
|
-
if (key instanceof Material || key instanceof Texture) {
|
|
2407
|
-
reducedAssociations.set(key, value);
|
|
2408
|
-
}
|
|
2409
|
-
}
|
|
2410
|
-
node.traverse((node2) => {
|
|
2411
|
-
const mappings = parser.associations.get(node2);
|
|
2412
|
-
if (mappings != null) {
|
|
2413
|
-
reducedAssociations.set(node2, mappings);
|
|
2414
|
-
}
|
|
2415
|
-
});
|
|
2416
|
-
return reducedAssociations;
|
|
2417
|
-
};
|
|
2418
|
-
parser.associations = reduceAssociations(scene);
|
|
2419
|
-
return scene;
|
|
2420
|
-
});
|
|
2421
|
-
}
|
|
2422
|
-
}
|
|
2423
|
-
function computeBounds(geometry, primitiveDef, parser) {
|
|
2424
|
-
const attributes = primitiveDef.attributes;
|
|
2425
|
-
const box = new Box3();
|
|
2426
|
-
if (attributes.POSITION !== void 0) {
|
|
2427
|
-
const accessor = parser.json.accessors[attributes.POSITION];
|
|
2428
|
-
const min = accessor.min;
|
|
2429
|
-
const max = accessor.max;
|
|
2430
|
-
if (min !== void 0 && max !== void 0) {
|
|
2431
|
-
box.set(new Vector3(min[0], min[1], min[2]), new Vector3(max[0], max[1], max[2]));
|
|
2432
|
-
if (accessor.normalized) {
|
|
2433
|
-
const boxScale = getNormalizedComponentScale(WEBGL_COMPONENT_TYPES[accessor.componentType]);
|
|
2434
|
-
box.min.multiplyScalar(boxScale);
|
|
2435
|
-
box.max.multiplyScalar(boxScale);
|
|
2436
|
-
}
|
|
2437
|
-
} else {
|
|
2438
|
-
console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
|
|
2439
|
-
return;
|
|
2440
|
-
}
|
|
2441
|
-
} else {
|
|
2442
|
-
return;
|
|
2443
|
-
}
|
|
2444
|
-
const targets = primitiveDef.targets;
|
|
2445
|
-
if (targets !== void 0) {
|
|
2446
|
-
const maxDisplacement = new Vector3();
|
|
2447
|
-
const vector = new Vector3();
|
|
2448
|
-
for (let i = 0, il = targets.length; i < il; i++) {
|
|
2449
|
-
const target = targets[i];
|
|
2450
|
-
if (target.POSITION !== void 0) {
|
|
2451
|
-
const accessor = parser.json.accessors[target.POSITION];
|
|
2452
|
-
const min = accessor.min;
|
|
2453
|
-
const max = accessor.max;
|
|
2454
|
-
if (min !== void 0 && max !== void 0) {
|
|
2455
|
-
vector.setX(Math.max(Math.abs(min[0]), Math.abs(max[0])));
|
|
2456
|
-
vector.setY(Math.max(Math.abs(min[1]), Math.abs(max[1])));
|
|
2457
|
-
vector.setZ(Math.max(Math.abs(min[2]), Math.abs(max[2])));
|
|
2458
|
-
if (accessor.normalized) {
|
|
2459
|
-
const boxScale = getNormalizedComponentScale(WEBGL_COMPONENT_TYPES[accessor.componentType]);
|
|
2460
|
-
vector.multiplyScalar(boxScale);
|
|
2461
|
-
}
|
|
2462
|
-
maxDisplacement.max(vector);
|
|
2463
|
-
} else {
|
|
2464
|
-
console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
|
|
2465
|
-
}
|
|
2466
|
-
}
|
|
2467
|
-
}
|
|
2468
|
-
box.expandByVector(maxDisplacement);
|
|
2469
|
-
}
|
|
2470
|
-
geometry.boundingBox = box;
|
|
2471
|
-
const sphere = new Sphere();
|
|
2472
|
-
box.getCenter(sphere.center);
|
|
2473
|
-
sphere.radius = box.min.distanceTo(box.max) / 2;
|
|
2474
|
-
geometry.boundingSphere = sphere;
|
|
2475
|
-
}
|
|
2476
|
-
function addPrimitiveAttributes(geometry, primitiveDef, parser) {
|
|
2477
|
-
const attributes = primitiveDef.attributes;
|
|
2478
|
-
const pending = [];
|
|
2479
|
-
function assignAttributeAccessor(accessorIndex, attributeName) {
|
|
2480
|
-
return parser.getDependency("accessor", accessorIndex).then(function(accessor) {
|
|
2481
|
-
geometry.setAttribute(attributeName, accessor);
|
|
2482
|
-
});
|
|
2483
|
-
}
|
|
2484
|
-
for (const gltfAttributeName in attributes) {
|
|
2485
|
-
const threeAttributeName = ATTRIBUTES[gltfAttributeName] || gltfAttributeName.toLowerCase();
|
|
2486
|
-
if (threeAttributeName in geometry.attributes)
|
|
2487
|
-
continue;
|
|
2488
|
-
pending.push(assignAttributeAccessor(attributes[gltfAttributeName], threeAttributeName));
|
|
2489
|
-
}
|
|
2490
|
-
if (primitiveDef.indices !== void 0 && !geometry.index) {
|
|
2491
|
-
const accessor = parser.getDependency("accessor", primitiveDef.indices).then(function(accessor2) {
|
|
2492
|
-
geometry.setIndex(accessor2);
|
|
2493
|
-
});
|
|
2494
|
-
pending.push(accessor);
|
|
2495
|
-
}
|
|
2496
|
-
assignExtrasToUserData(geometry, primitiveDef);
|
|
2497
|
-
computeBounds(geometry, primitiveDef, parser);
|
|
2498
|
-
return Promise.all(pending).then(function() {
|
|
2499
|
-
return primitiveDef.targets !== void 0 ? addMorphTargets(geometry, primitiveDef.targets, parser) : geometry;
|
|
2500
|
-
});
|
|
2501
|
-
}
|
|
2502
|
-
export {
|
|
2503
|
-
GLTFLoader
|
|
2504
|
-
};
|