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