@needle-tools/three 0.160.2 → 0.162.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +86 -86
- package/build/three.cjs +53267 -53092
- package/build/three.module.js +53269 -53094
- package/build/three.module.min.js +1 -1
- package/examples/fonts/LICENSE +13 -13
- package/examples/fonts/README.md +11 -11
- package/examples/fonts/droid/NOTICE +190 -190
- package/examples/fonts/droid/README.txt +18 -18
- package/examples/fonts/ttf/README.md +9 -9
- package/examples/jsm/Addons.js +295 -294
- package/examples/jsm/animation/AnimationClipCreator.js +116 -116
- package/examples/jsm/animation/CCDIKSolver.js +482 -482
- package/examples/jsm/animation/MMDAnimationHelper.js +1207 -1207
- package/examples/jsm/animation/MMDPhysics.js +1406 -1406
- package/examples/jsm/cameras/CinematicCamera.js +208 -208
- package/examples/jsm/capabilities/WebGL.js +108 -108
- package/examples/jsm/capabilities/WebGPU.js +57 -57
- package/examples/jsm/controls/ArcballControls.js +3224 -3224
- package/examples/jsm/controls/DragControls.js +282 -221
- package/examples/jsm/controls/FirstPersonControls.js +325 -325
- package/examples/jsm/controls/FlyControls.js +326 -326
- package/examples/jsm/controls/MapControls.js +28 -28
- package/examples/jsm/controls/OrbitControls.js +1548 -1521
- package/examples/jsm/controls/PointerLockControls.js +162 -162
- package/examples/jsm/controls/TrackballControls.js +828 -828
- package/examples/jsm/controls/TransformControls.js +1573 -1573
- package/examples/jsm/csm/CSM.js +384 -384
- package/examples/jsm/csm/CSMFrustum.js +152 -152
- package/examples/jsm/csm/CSMHelper.js +193 -193
- package/examples/jsm/csm/CSMShader.js +295 -295
- package/examples/jsm/curves/CurveExtras.js +422 -422
- package/examples/jsm/curves/NURBSCurve.js +80 -80
- package/examples/jsm/curves/NURBSSurface.js +52 -52
- package/examples/jsm/curves/NURBSUtils.js +542 -487
- package/examples/jsm/curves/NURBSVolume.js +62 -0
- package/examples/jsm/effects/AnaglyphEffect.js +154 -154
- package/examples/jsm/effects/AsciiEffect.js +263 -263
- package/examples/jsm/effects/OutlineEffect.js +539 -539
- package/examples/jsm/effects/ParallaxBarrierEffect.js +119 -119
- package/examples/jsm/effects/PeppersGhostEffect.js +153 -153
- package/examples/jsm/effects/StereoEffect.js +55 -55
- package/examples/jsm/environments/DebugEnvironment.js +52 -52
- package/examples/jsm/environments/RoomEnvironment.js +148 -148
- package/examples/jsm/exporters/DRACOExporter.js +267 -267
- package/examples/jsm/exporters/EXRExporter.js +579 -579
- package/examples/jsm/exporters/GLTFExporter.js +3321 -3311
- package/examples/jsm/exporters/KTX2Exporter.js +292 -292
- package/examples/jsm/exporters/MMDExporter.js +217 -217
- package/examples/jsm/exporters/OBJExporter.js +284 -284
- package/examples/jsm/exporters/PLYExporter.js +528 -528
- package/examples/jsm/exporters/STLExporter.js +199 -199
- package/examples/jsm/exporters/USDZExporter.js +720 -720
- package/examples/jsm/geometries/BoxLineGeometry.js +69 -69
- package/examples/jsm/geometries/ConvexGeometry.js +53 -53
- package/examples/jsm/geometries/DecalGeometry.js +356 -356
- package/examples/jsm/geometries/InstancedPointsGeometry.js +174 -174
- package/examples/jsm/geometries/ParametricGeometries.js +254 -254
- package/examples/jsm/geometries/ParametricGeometry.js +139 -139
- package/examples/jsm/geometries/RoundedBoxGeometry.js +155 -155
- package/examples/jsm/geometries/SDFGeometryGenerator.js +144 -144
- package/examples/jsm/geometries/TeapotGeometry.js +704 -704
- package/examples/jsm/geometries/TextGeometry.js +57 -57
- package/examples/jsm/helpers/LightProbeHelper.js +130 -130
- package/examples/jsm/helpers/OctreeHelper.js +73 -73
- package/examples/jsm/helpers/PositionalAudioHelper.js +109 -109
- package/examples/jsm/helpers/RectAreaLightHelper.js +85 -85
- package/examples/jsm/helpers/TextureHelper.js +237 -237
- package/examples/jsm/helpers/VertexNormalsHelper.js +96 -96
- package/examples/jsm/helpers/VertexTangentsHelper.js +88 -88
- package/examples/jsm/helpers/ViewHelper.js +333 -333
- package/examples/jsm/interactive/HTMLMesh.js +572 -572
- package/examples/jsm/interactive/InteractiveGroup.js +106 -116
- package/examples/jsm/interactive/SelectionBox.js +227 -227
- package/examples/jsm/interactive/SelectionHelper.js +104 -104
- package/examples/jsm/libs/ammo.wasm.js +822 -822
- package/examples/jsm/libs/basis/README.md +46 -46
- package/examples/jsm/libs/basis/basis_transcoder.js +21 -21
- package/examples/jsm/libs/chevrotain.module.min.js +141 -141
- package/examples/jsm/libs/draco/README.md +32 -32
- package/examples/jsm/libs/draco/draco_decoder.js +34 -34
- package/examples/jsm/libs/draco/draco_encoder.js +33 -33
- package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -117
- package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -33
- package/examples/jsm/libs/draco/gltf/draco_encoder.js +33 -33
- package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -116
- package/examples/jsm/libs/ecsy.module.js +1792 -1792
- package/examples/jsm/libs/fflate.module.js +2474 -2474
- package/examples/jsm/libs/ktx-parse.module.js +1 -1
- package/examples/jsm/libs/lil-gui.module.min.js +8 -8
- package/examples/jsm/libs/lottie_canvas.module.js +14849 -14849
- package/examples/jsm/libs/meshopt_decoder.module.js +178 -178
- package/examples/jsm/libs/mikktspace.module.js +128 -128
- package/examples/jsm/libs/mmdparser.module.js +11530 -11530
- package/examples/jsm/libs/motion-controllers.module.js +397 -397
- package/examples/jsm/libs/opentype.module.js +14506 -14506
- package/examples/jsm/libs/potpack.module.js +124 -124
- package/examples/jsm/libs/rhino3dm/rhino3dm.js +21 -8743
- package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +15 -8748
- package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
- package/examples/jsm/libs/stats.module.js +167 -167
- package/examples/jsm/libs/surfaceNet.js +200 -200
- package/examples/jsm/libs/tween.module.js +876 -858
- package/examples/jsm/libs/utif.module.js +1664 -1664
- package/examples/jsm/libs/zstddec.module.js +1 -1
- package/examples/jsm/lights/IESSpotLight.js +25 -25
- package/examples/jsm/lights/LightProbeGenerator.js +286 -286
- package/examples/jsm/lights/RectAreaLightUniformsLib.js +79 -79
- package/examples/jsm/lines/Line2.js +19 -19
- package/examples/jsm/lines/LineGeometry.js +79 -79
- package/examples/jsm/lines/LineMaterial.js +619 -619
- package/examples/jsm/lines/LineSegments2.js +361 -361
- package/examples/jsm/lines/LineSegmentsGeometry.js +241 -241
- package/examples/jsm/lines/Wireframe.js +56 -56
- package/examples/jsm/lines/WireframeGeometry2.js +24 -24
- package/examples/jsm/loaders/3DMLoader.js +1764 -1772
- package/examples/jsm/loaders/3MFLoader.js +1478 -1478
- package/examples/jsm/loaders/AMFLoader.js +521 -521
- package/examples/jsm/loaders/BVHLoader.js +437 -437
- package/examples/jsm/loaders/ColladaLoader.js +4116 -4116
- package/examples/jsm/loaders/DDSLoader.js +318 -318
- package/examples/jsm/loaders/DRACOLoader.js +613 -613
- package/examples/jsm/loaders/EXRLoader.js +2309 -2309
- package/examples/jsm/loaders/FBXLoader.js +4314 -4314
- package/examples/jsm/loaders/FontLoader.js +183 -183
- package/examples/jsm/loaders/GCodeLoader.js +261 -261
- package/examples/jsm/loaders/GLTFLoader.js +4666 -4666
- package/examples/jsm/loaders/GLTFLoaderAnimationPointer.js +729 -720
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +115 -115
- package/examples/jsm/loaders/IESLoader.js +337 -337
- package/examples/jsm/loaders/KMZLoader.js +130 -130
- package/examples/jsm/loaders/KTX2Loader.js +932 -932
- package/examples/jsm/loaders/KTXLoader.js +176 -176
- package/examples/jsm/loaders/LDrawLoader.js +2470 -2470
- package/examples/jsm/loaders/LUT3dlLoader.js +183 -183
- package/examples/jsm/loaders/LUTCubeLoader.js +167 -167
- package/examples/jsm/loaders/LUTImageLoader.js +163 -163
- package/examples/jsm/loaders/LWOLoader.js +1052 -1052
- package/examples/jsm/loaders/LogLuvLoader.js +606 -606
- package/examples/jsm/loaders/LottieLoader.js +77 -77
- package/examples/jsm/loaders/MD2Loader.js +399 -399
- package/examples/jsm/loaders/MDDLoader.js +102 -102
- package/examples/jsm/loaders/MMDLoader.js +2276 -2276
- package/examples/jsm/loaders/MTLLoader.js +567 -567
- package/examples/jsm/loaders/MaterialXLoader.js +852 -852
- package/examples/jsm/loaders/NRRDLoader.js +686 -686
- package/examples/jsm/loaders/OBJLoader.js +905 -905
- package/examples/jsm/loaders/PCDLoader.js +467 -467
- package/examples/jsm/loaders/PDBLoader.js +232 -232
- package/examples/jsm/loaders/PLYLoader.js +771 -771
- package/examples/jsm/loaders/PVRLoader.js +251 -251
- package/examples/jsm/loaders/RGBELoader.js +450 -450
- package/examples/jsm/loaders/RGBMLoader.js +1065 -1065
- package/examples/jsm/loaders/STLLoader.js +410 -410
- package/examples/jsm/loaders/SVGLoader.js +3173 -3173
- package/examples/jsm/loaders/TDSLoader.js +1124 -1124
- package/examples/jsm/loaders/TGALoader.js +517 -517
- package/examples/jsm/loaders/TIFFLoader.js +36 -36
- package/examples/jsm/loaders/TTFLoader.js +214 -214
- package/examples/jsm/loaders/TiltLoader.js +520 -520
- package/examples/jsm/loaders/USDZLoader.js +822 -822
- package/examples/jsm/loaders/VOXLoader.js +318 -311
- package/examples/jsm/loaders/VRMLLoader.js +3537 -3533
- package/examples/jsm/loaders/VTKLoader.js +1163 -1163
- package/examples/jsm/loaders/XYZLoader.js +106 -106
- package/examples/jsm/loaders/lwo/IFFParser.js +1214 -1214
- package/examples/jsm/loaders/lwo/LWO2Parser.js +414 -414
- package/examples/jsm/loaders/lwo/LWO3Parser.js +373 -373
- package/examples/jsm/materials/MeshGouraudMaterial.js +426 -426
- package/examples/jsm/materials/MeshPostProcessingMaterial.js +144 -144
- package/examples/jsm/math/Capsule.js +82 -82
- package/examples/jsm/math/ColorConverter.js +36 -36
- package/examples/jsm/math/ConvexHull.js +1271 -1271
- package/examples/jsm/math/ImprovedNoise.js +71 -71
- package/examples/jsm/math/Lut.js +204 -204
- package/examples/jsm/math/MeshSurfaceSampler.js +250 -250
- package/examples/jsm/math/OBB.js +423 -423
- package/examples/jsm/math/Octree.js +540 -540
- package/examples/jsm/math/SimplexNoise.js +444 -444
- package/examples/jsm/misc/ConvexObjectBreaker.js +519 -519
- package/examples/jsm/misc/GPUComputationRenderer.js +446 -446
- package/examples/jsm/misc/Gyroscope.js +66 -66
- package/examples/jsm/misc/MD2Character.js +276 -276
- package/examples/jsm/misc/MD2CharacterComplex.js +576 -576
- package/examples/jsm/misc/MorphAnimMesh.js +75 -75
- package/examples/jsm/misc/MorphBlendMesh.js +322 -322
- package/examples/jsm/misc/ProgressiveLightMap.js +324 -323
- package/examples/jsm/misc/RollerCoaster.js +566 -566
- package/examples/jsm/misc/Timer.js +128 -119
- package/examples/jsm/misc/TubePainter.js +202 -202
- package/examples/jsm/misc/Volume.js +473 -473
- package/examples/jsm/misc/VolumeSlice.js +229 -229
- package/examples/jsm/modifiers/CurveModifier.js +344 -344
- package/examples/jsm/modifiers/EdgeSplitModifier.js +279 -279
- package/examples/jsm/modifiers/SimplifyModifier.js +617 -617
- package/examples/jsm/modifiers/TessellateModifier.js +307 -307
- package/examples/jsm/nodes/Nodes.js +195 -189
- package/examples/jsm/nodes/accessors/AccessorsUtils.js +10 -0
- package/examples/jsm/nodes/accessors/BitangentNode.js +89 -89
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +127 -127
- package/examples/jsm/nodes/accessors/BufferNode.js +30 -30
- package/examples/jsm/nodes/accessors/CameraNode.js +119 -120
- package/examples/jsm/nodes/accessors/ClippingNode.js +144 -0
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +61 -61
- package/examples/jsm/nodes/accessors/InstanceNode.js +71 -71
- package/examples/jsm/nodes/accessors/InstancedPointsMaterialNode.js +21 -21
- package/examples/jsm/nodes/accessors/MaterialNode.js +314 -314
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +41 -51
- package/examples/jsm/nodes/accessors/ModelNode.js +33 -33
- package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +39 -39
- package/examples/jsm/nodes/accessors/MorphNode.js +245 -245
- package/examples/jsm/nodes/accessors/NormalNode.js +96 -96
- package/examples/jsm/nodes/accessors/Object3DNode.js +150 -150
- package/examples/jsm/nodes/accessors/PointUVNode.js +26 -26
- package/examples/jsm/nodes/accessors/PositionNode.js +104 -104
- package/examples/jsm/nodes/accessors/ReferenceNode.js +160 -102
- package/examples/jsm/nodes/accessors/ReflectVectorNode.js +35 -35
- package/examples/jsm/nodes/accessors/SceneNode.js +52 -52
- package/examples/jsm/nodes/accessors/SkinningNode.js +124 -103
- package/examples/jsm/nodes/accessors/StorageBufferNode.js +72 -54
- package/examples/jsm/nodes/accessors/TangentNode.js +109 -103
- package/examples/jsm/nodes/accessors/TextureBicubicNode.js +94 -94
- package/examples/jsm/nodes/accessors/TextureNode.js +367 -367
- package/examples/jsm/nodes/accessors/TextureSizeNode.js +35 -35
- package/examples/jsm/nodes/accessors/TextureStoreNode.js +82 -82
- package/examples/jsm/nodes/accessors/UVNode.js +47 -47
- package/examples/jsm/nodes/accessors/UniformsNode.js +140 -0
- package/examples/jsm/nodes/accessors/UserDataNode.js +29 -29
- package/examples/jsm/nodes/accessors/VertexColorNode.js +70 -70
- package/examples/jsm/nodes/code/CodeNode.js +84 -78
- package/examples/jsm/nodes/code/ExpressionNode.js +37 -37
- package/examples/jsm/nodes/code/FunctionCallNode.js +96 -96
- package/examples/jsm/nodes/code/FunctionNode.js +138 -138
- package/examples/jsm/nodes/code/ScriptableNode.js +488 -488
- package/examples/jsm/nodes/code/ScriptableValueNode.js +167 -167
- package/examples/jsm/nodes/core/AssignNode.js +128 -72
- package/examples/jsm/nodes/core/AttributeNode.js +108 -108
- package/examples/jsm/nodes/core/BypassNode.js +45 -45
- package/examples/jsm/nodes/core/CacheNode.js +49 -49
- package/examples/jsm/nodes/core/ConstNode.js +32 -32
- package/examples/jsm/nodes/core/ContextNode.js +61 -61
- package/examples/jsm/nodes/core/IndexNode.js +66 -66
- package/examples/jsm/nodes/core/InputNode.js +83 -83
- package/examples/jsm/nodes/core/LightingModel.js +17 -17
- package/examples/jsm/nodes/core/Node.js +493 -483
- package/examples/jsm/nodes/core/NodeAttribute.js +15 -15
- package/examples/jsm/nodes/core/NodeBuilder.js +1250 -1267
- package/examples/jsm/nodes/core/NodeCache.js +26 -26
- package/examples/jsm/nodes/core/NodeCode.js +15 -15
- package/examples/jsm/nodes/core/NodeFrame.js +143 -135
- package/examples/jsm/nodes/core/NodeFunction.js +22 -22
- package/examples/jsm/nodes/core/NodeFunctionInput.js +17 -17
- package/examples/jsm/nodes/core/NodeKeywords.js +80 -80
- package/examples/jsm/nodes/core/NodeParser.js +11 -11
- package/examples/jsm/nodes/core/NodeUniform.js +40 -40
- package/examples/jsm/nodes/core/NodeUtils.js +210 -210
- package/examples/jsm/nodes/core/NodeVar.js +14 -14
- package/examples/jsm/nodes/core/NodeVarying.js +17 -17
- package/examples/jsm/nodes/core/OutputStructNode.js +62 -62
- package/examples/jsm/nodes/core/ParameterNode.js +33 -33
- package/examples/jsm/nodes/core/PropertyNode.js +72 -72
- package/examples/jsm/nodes/core/StackNode.js +89 -89
- package/examples/jsm/nodes/core/StructTypeNode.js +24 -24
- package/examples/jsm/nodes/core/TempNode.js +58 -58
- package/examples/jsm/nodes/core/UniformGroup.js +13 -13
- package/examples/jsm/nodes/core/UniformGroupNode.js +36 -36
- package/examples/jsm/nodes/core/UniformNode.js +80 -80
- package/examples/jsm/nodes/core/VarNode.js +60 -60
- package/examples/jsm/nodes/core/VaryingNode.js +65 -65
- package/examples/jsm/nodes/core/constants.js +28 -27
- package/examples/jsm/nodes/display/AfterImageNode.js +148 -134
- package/examples/jsm/nodes/display/AnamorphicNode.js +148 -0
- package/examples/jsm/nodes/display/BlendModeNode.js +128 -99
- package/examples/jsm/nodes/display/BumpMapNode.js +99 -99
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +99 -96
- package/examples/jsm/nodes/display/ColorSpaceNode.js +108 -108
- package/examples/jsm/nodes/display/FrontFacingNode.js +27 -27
- package/examples/jsm/nodes/display/GaussianBlurNode.js +190 -177
- package/examples/jsm/nodes/display/NormalMapNode.js +106 -108
- package/examples/jsm/nodes/display/PassNode.js +183 -182
- package/examples/jsm/nodes/display/PosterizeNode.js +32 -32
- package/examples/jsm/nodes/display/ToneMappingNode.js +184 -184
- package/examples/jsm/nodes/display/ViewportDepthNode.js +97 -97
- package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +31 -31
- package/examples/jsm/nodes/display/ViewportNode.js +134 -134
- package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +31 -31
- package/examples/jsm/nodes/display/ViewportTextureNode.js +75 -75
- package/examples/jsm/nodes/fog/FogExp2Node.js +35 -35
- package/examples/jsm/nodes/fog/FogNode.js +38 -38
- package/examples/jsm/nodes/fog/FogRangeNode.js +34 -34
- package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +40 -40
- package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +9 -9
- package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +57 -57
- package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +30 -30
- package/examples/jsm/nodes/functions/BSDF/D_GGX.js +23 -23
- package/examples/jsm/nodes/functions/BSDF/EnvironmentBRDF.js +13 -13
- package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +16 -16
- package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +21 -21
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +28 -28
- package/examples/jsm/nodes/functions/PhongLightingModel.js +67 -67
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +393 -393
- package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +13 -13
- package/examples/jsm/nodes/functions/material/getRoughness.js +18 -18
- package/examples/jsm/nodes/geometry/RangeNode.js +104 -104
- package/examples/jsm/nodes/gpgpu/ComputeNode.js +85 -85
- package/examples/jsm/nodes/lighting/AONode.js +27 -27
- package/examples/jsm/nodes/lighting/AmbientLightNode.js +27 -27
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +241 -238
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +40 -40
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +181 -181
- package/examples/jsm/nodes/lighting/HemisphereLightNode.js +55 -55
- package/examples/jsm/nodes/lighting/IESSpotLightNode.js +39 -39
- package/examples/jsm/nodes/lighting/LightNode.js +57 -57
- package/examples/jsm/nodes/lighting/LightUtils.js +17 -17
- package/examples/jsm/nodes/lighting/LightingContextNode.js +66 -66
- package/examples/jsm/nodes/lighting/LightingNode.js +21 -21
- package/examples/jsm/nodes/lighting/LightsNode.js +188 -188
- package/examples/jsm/nodes/lighting/PointLightNode.js +68 -68
- package/examples/jsm/nodes/lighting/SpotLightNode.js +89 -89
- package/examples/jsm/nodes/loaders/NodeLoader.js +108 -108
- package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +59 -59
- package/examples/jsm/nodes/loaders/NodeObjectLoader.js +70 -70
- package/examples/jsm/nodes/materials/InstancedPointsNodeMaterial.js +162 -162
- package/examples/jsm/nodes/materials/Line2NodeMaterial.js +436 -436
- package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +28 -28
- package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +54 -54
- package/examples/jsm/nodes/materials/Materials.js +16 -16
- package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +28 -28
- package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +34 -34
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +40 -40
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +65 -65
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +155 -155
- package/examples/jsm/nodes/materials/MeshSSSNodeMaterial.js +84 -84
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +80 -80
- package/examples/jsm/nodes/materials/NodeMaterial.js +601 -568
- package/examples/jsm/nodes/materials/PointsNodeMaterial.js +39 -39
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +90 -96
- package/examples/jsm/nodes/materialx/DISCLAIMER.md +199 -199
- package/examples/jsm/nodes/materialx/MaterialXNodes.js +68 -68
- package/examples/jsm/nodes/materialx/lib/mx_hsv.js +130 -130
- package/examples/jsm/nodes/materialx/lib/mx_noise.js +1430 -1430
- package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +29 -29
- package/examples/jsm/nodes/math/CondNode.js +121 -86
- package/examples/jsm/nodes/math/HashNode.js +34 -34
- package/examples/jsm/nodes/math/MathNode.js +391 -382
- package/examples/jsm/nodes/math/MathUtils.js +15 -0
- package/examples/jsm/nodes/math/OperatorNode.js +274 -266
- package/examples/jsm/nodes/math/TriNoise3D.js +71 -71
- package/examples/jsm/nodes/parsers/GLSLNodeFunction.js +152 -152
- package/examples/jsm/nodes/parsers/GLSLNodeParser.js +14 -14
- package/examples/jsm/nodes/procedural/CheckerNode.js +42 -42
- package/examples/jsm/nodes/shadernode/ShaderNode.js +634 -625
- package/examples/jsm/nodes/utils/ArrayElementNode.js +35 -41
- package/examples/jsm/nodes/utils/ConvertNode.js +65 -65
- package/examples/jsm/nodes/utils/DiscardNode.js +27 -27
- package/examples/jsm/nodes/utils/EquirectUVNode.js +33 -33
- package/examples/jsm/nodes/utils/FunctionOverloadingNode.js +95 -95
- package/examples/jsm/nodes/utils/JoinNode.js +61 -61
- package/examples/jsm/nodes/utils/LoopNode.js +200 -198
- package/examples/jsm/nodes/utils/MatcapUVNode.js +30 -30
- package/examples/jsm/nodes/utils/MaxMipLevelNode.js +46 -46
- package/examples/jsm/nodes/utils/OscNode.js +81 -81
- package/examples/jsm/nodes/utils/PackingNode.js +55 -55
- package/examples/jsm/nodes/utils/ReflectorNode.js +227 -0
- package/examples/jsm/nodes/utils/RemapNode.js +42 -42
- package/examples/jsm/nodes/utils/RotateNode.js +68 -43
- package/examples/jsm/nodes/utils/RotateUVNode.js +35 -43
- package/examples/jsm/nodes/utils/SetNode.js +62 -62
- package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +37 -37
- package/examples/jsm/nodes/utils/SplitNode.js +112 -112
- package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +41 -41
- package/examples/jsm/nodes/utils/StorageArrayElementNode.js +91 -0
- package/examples/jsm/nodes/utils/TimerNode.js +94 -94
- package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +62 -62
- package/examples/jsm/objects/GroundedSkybox.js +50 -50
- package/examples/jsm/objects/InstancedPoints.js +21 -21
- package/examples/jsm/objects/Lensflare.js +397 -397
- package/examples/jsm/objects/MarchingCubes.js +1176 -1176
- package/examples/jsm/objects/QuadMesh.js +66 -66
- package/examples/jsm/objects/Reflector.js +264 -264
- package/examples/jsm/objects/ReflectorForSSRPass.js +352 -352
- package/examples/jsm/objects/Refractor.js +327 -327
- package/examples/jsm/objects/ShadowMesh.js +80 -80
- package/examples/jsm/objects/Sky.js +219 -219
- package/examples/jsm/objects/Water.js +333 -333
- package/examples/jsm/objects/Water2.js +361 -361
- package/examples/jsm/offscreen/jank.js +45 -45
- package/examples/jsm/offscreen/offscreen.js +8 -8
- package/examples/jsm/offscreen/scene.js +86 -86
- package/examples/jsm/physics/AmmoPhysics.js +306 -306
- package/examples/jsm/physics/RapierPhysics.js +220 -220
- package/examples/jsm/postprocessing/AfterimagePass.js +104 -104
- package/examples/jsm/postprocessing/BloomPass.js +172 -172
- package/examples/jsm/postprocessing/BokehPass.js +141 -141
- package/examples/jsm/postprocessing/ClearPass.js +46 -46
- package/examples/jsm/postprocessing/CubeTexturePass.js +85 -85
- package/examples/jsm/postprocessing/DotScreenPass.js +65 -65
- package/examples/jsm/postprocessing/EffectComposer.js +231 -231
- package/examples/jsm/postprocessing/FilmPass.js +64 -64
- package/examples/jsm/postprocessing/GTAOPass.js +582 -582
- package/examples/jsm/postprocessing/GlitchPass.js +128 -128
- package/examples/jsm/postprocessing/HalftonePass.js +79 -79
- package/examples/jsm/postprocessing/LUTPass.js +174 -174
- package/examples/jsm/postprocessing/MaskPass.js +104 -104
- package/examples/jsm/postprocessing/OutlinePass.js +654 -654
- package/examples/jsm/postprocessing/OutputPass.js +97 -95
- package/examples/jsm/postprocessing/Pass.js +95 -95
- package/examples/jsm/postprocessing/RenderPass.js +99 -99
- package/examples/jsm/postprocessing/RenderPixelatedPass.js +235 -235
- package/examples/jsm/postprocessing/SAOPass.js +335 -335
- package/examples/jsm/postprocessing/SMAAPass.js +199 -199
- package/examples/jsm/postprocessing/SSAARenderPass.js +228 -228
- package/examples/jsm/postprocessing/SSAOPass.js +420 -420
- package/examples/jsm/postprocessing/SSRPass.js +641 -641
- package/examples/jsm/postprocessing/SavePass.js +79 -79
- package/examples/jsm/postprocessing/ShaderPass.js +77 -77
- package/examples/jsm/postprocessing/TAARenderPass.js +188 -188
- package/examples/jsm/postprocessing/TexturePass.js +67 -67
- package/examples/jsm/postprocessing/UnrealBloomPass.js +415 -415
- package/examples/jsm/renderers/CSS2DRenderer.js +215 -215
- package/examples/jsm/renderers/CSS3DRenderer.js +329 -329
- package/examples/jsm/renderers/Projector.js +918 -918
- package/examples/jsm/renderers/SVGRenderer.js +556 -556
- package/examples/jsm/renderers/common/Animation.js +47 -47
- package/examples/jsm/renderers/common/Attributes.js +75 -75
- package/examples/jsm/renderers/common/Backend.js +195 -193
- package/examples/jsm/renderers/common/Background.js +134 -134
- package/examples/jsm/renderers/common/Binding.js +25 -25
- package/examples/jsm/renderers/common/Bindings.js +173 -173
- package/examples/jsm/renderers/common/Buffer.js +38 -38
- package/examples/jsm/renderers/common/BufferUtils.js +33 -33
- package/examples/jsm/renderers/common/ChainMap.js +89 -89
- package/examples/jsm/renderers/common/ClippingContext.js +165 -0
- package/examples/jsm/renderers/common/Color4.js +37 -37
- package/examples/jsm/renderers/common/ComputePipeline.js +17 -17
- package/examples/jsm/renderers/common/Constants.js +14 -14
- package/examples/jsm/renderers/common/CubeRenderTarget.js +65 -65
- package/examples/jsm/renderers/common/DataMap.js +54 -54
- package/examples/jsm/renderers/common/Geometries.js +215 -215
- package/examples/jsm/renderers/common/Info.js +107 -107
- package/examples/jsm/renderers/common/Pipeline.js +13 -13
- package/examples/jsm/renderers/common/Pipelines.js +322 -322
- package/examples/jsm/renderers/common/PostProcessing.js +25 -25
- package/examples/jsm/renderers/common/ProgrammableStage.js +20 -20
- package/examples/jsm/renderers/common/RenderContext.js +43 -41
- package/examples/jsm/renderers/common/RenderContexts.js +63 -74
- package/examples/jsm/renderers/common/RenderList.js +186 -186
- package/examples/jsm/renderers/common/RenderLists.js +38 -38
- package/examples/jsm/renderers/common/RenderObject.js +221 -178
- package/examples/jsm/renderers/common/RenderObjects.js +93 -91
- package/examples/jsm/renderers/common/RenderPipeline.js +16 -16
- package/examples/jsm/renderers/common/Renderer.js +1304 -1062
- package/examples/jsm/renderers/common/SampledTexture.js +83 -83
- package/examples/jsm/renderers/common/Sampler.js +18 -18
- package/examples/jsm/renderers/common/StorageBuffer.js +17 -17
- package/examples/jsm/renderers/common/StorageBufferAttribute.js +17 -21
- package/examples/jsm/renderers/common/StorageInstancedBufferAttribute.js +17 -0
- package/examples/jsm/renderers/common/StorageTexture.js +20 -20
- package/examples/jsm/renderers/common/Textures.js +344 -354
- package/examples/jsm/renderers/common/Uniform.js +140 -140
- package/examples/jsm/renderers/common/UniformBuffer.js +15 -15
- package/examples/jsm/renderers/common/UniformsGroup.js +301 -299
- package/examples/jsm/renderers/common/nodes/NodeBuilderState.js +44 -44
- package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +49 -49
- package/examples/jsm/renderers/common/nodes/NodeSampler.js +15 -15
- package/examples/jsm/renderers/common/nodes/NodeStorageBuffer.js +23 -0
- package/examples/jsm/renderers/common/nodes/NodeUniform.js +135 -135
- package/examples/jsm/renderers/common/nodes/NodeUniformBuffer.js +23 -0
- package/examples/jsm/renderers/common/nodes/NodeUniformsGroup.js +44 -44
- package/examples/jsm/renderers/common/nodes/Nodes.js +496 -495
- package/examples/jsm/renderers/webgl/WebGLBackend.js +1382 -1290
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +804 -679
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +258 -252
- package/examples/jsm/renderers/webgl/utils/WebGLCapabilities.js +36 -36
- package/examples/jsm/renderers/webgl/utils/WebGLConstants.js +11 -11
- package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +36 -36
- package/examples/jsm/renderers/webgl/utils/WebGLState.js +738 -738
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +694 -647
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +285 -284
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +320 -320
- package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +26 -26
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +794 -794
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +51 -51
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +1322 -1321
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +53 -53
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +1078 -1098
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +104 -104
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeParser.js +14 -14
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +293 -287
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +244 -244
- package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +324 -324
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +591 -570
- package/examples/jsm/renderers/webgpu/utils/WebGPUTexturePassUtils.js +285 -285
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +1040 -1040
- package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +93 -93
- package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +89 -89
- package/examples/jsm/shaders/AfterimageShader.js +58 -58
- package/examples/jsm/shaders/BasicShader.js +29 -29
- package/examples/jsm/shaders/BleachBypassShader.js +62 -62
- package/examples/jsm/shaders/BlendShader.js +49 -49
- package/examples/jsm/shaders/BokehShader.js +145 -145
- package/examples/jsm/shaders/BokehShader2.js +397 -397
- package/examples/jsm/shaders/BrightnessContrastShader.js +56 -56
- package/examples/jsm/shaders/ColorCorrectionShader.js +52 -52
- package/examples/jsm/shaders/ColorifyShader.js +51 -51
- package/examples/jsm/shaders/ConvolutionShader.js +103 -103
- package/examples/jsm/shaders/CopyShader.js +45 -45
- package/examples/jsm/shaders/DOFMipMapShader.js +56 -56
- package/examples/jsm/shaders/DepthLimitedBlurShader.js +171 -171
- package/examples/jsm/shaders/DigitalGlitch.js +101 -101
- package/examples/jsm/shaders/DotScreenShader.js +70 -70
- package/examples/jsm/shaders/ExposureShader.js +44 -44
- package/examples/jsm/shaders/FXAAShader.js +288 -288
- package/examples/jsm/shaders/FilmShader.js +59 -59
- package/examples/jsm/shaders/FocusShader.js +89 -89
- package/examples/jsm/shaders/FreiChenShader.js +96 -96
- package/examples/jsm/shaders/GTAOShader.js +424 -424
- package/examples/jsm/shaders/GammaCorrectionShader.js +43 -43
- package/examples/jsm/shaders/GodRaysShader.js +321 -321
- package/examples/jsm/shaders/HalftoneShader.js +312 -312
- package/examples/jsm/shaders/HorizontalBlurShader.js +59 -59
- package/examples/jsm/shaders/HorizontalTiltShiftShader.js +63 -63
- package/examples/jsm/shaders/HueSaturationShader.js +67 -67
- package/examples/jsm/shaders/KaleidoShader.js +58 -58
- package/examples/jsm/shaders/LuminosityHighPassShader.js +66 -66
- package/examples/jsm/shaders/LuminosityShader.js +48 -48
- package/examples/jsm/shaders/MMDToonShader.js +134 -134
- package/examples/jsm/shaders/MirrorShader.js +56 -56
- package/examples/jsm/shaders/NormalMapShader.js +55 -55
- package/examples/jsm/shaders/OutputShader.js +85 -81
- package/examples/jsm/shaders/PoissonDenoiseShader.js +226 -226
- package/examples/jsm/shaders/RGBShiftShader.js +54 -54
- package/examples/jsm/shaders/SAOShader.js +179 -179
- package/examples/jsm/shaders/SMAAShader.js +466 -466
- package/examples/jsm/shaders/SSAOShader.js +300 -300
- package/examples/jsm/shaders/SSRShader.js +370 -370
- package/examples/jsm/shaders/SepiaShader.js +52 -52
- package/examples/jsm/shaders/SobelOperatorShader.js +92 -92
- package/examples/jsm/shaders/SubsurfaceScatteringShader.js +90 -90
- package/examples/jsm/shaders/TechnicolorShader.js +45 -45
- package/examples/jsm/shaders/ToonShader.js +326 -326
- package/examples/jsm/shaders/TriangleBlurShader.js +74 -74
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +47 -47
- package/examples/jsm/shaders/VelocityShader.js +130 -130
- package/examples/jsm/shaders/VerticalBlurShader.js +59 -59
- package/examples/jsm/shaders/VerticalTiltShiftShader.js +63 -63
- package/examples/jsm/shaders/VignetteShader.js +51 -51
- package/examples/jsm/shaders/VolumeShader.js +289 -289
- package/examples/jsm/shaders/WaterRefractionShader.js +95 -95
- package/examples/jsm/textures/FlakesTexture.js +40 -40
- package/examples/jsm/transpiler/AST.js +270 -270
- package/examples/jsm/transpiler/GLSLDecoder.js +941 -941
- package/examples/jsm/transpiler/ShaderToyDecoder.js +49 -49
- package/examples/jsm/transpiler/TSLEncoder.js +715 -715
- package/examples/jsm/transpiler/Transpiler.js +18 -18
- package/examples/jsm/utils/BufferGeometryUtils.js +1371 -1371
- package/examples/jsm/utils/CameraUtils.js +73 -73
- package/examples/jsm/utils/GPUStatsPanel.js +128 -128
- package/examples/jsm/utils/GeometryCompressionUtils.js +639 -639
- package/examples/jsm/utils/GeometryUtils.js +221 -221
- package/examples/jsm/utils/LDrawUtils.js +202 -202
- package/examples/jsm/utils/PackedPhongMaterial.js +178 -178
- package/examples/jsm/utils/SceneUtils.js +254 -254
- package/examples/jsm/utils/ShadowMapViewer.js +210 -210
- package/examples/jsm/utils/SkeletonUtils.js +424 -413
- package/examples/jsm/utils/SortUtils.js +160 -160
- package/examples/jsm/utils/TextureUtils.js +98 -98
- package/examples/jsm/utils/UVsDebug.js +165 -165
- package/examples/jsm/utils/WorkerPool.js +102 -102
- package/examples/jsm/webxr/ARButton.js +232 -232
- package/examples/jsm/webxr/OculusHandModel.js +109 -109
- package/examples/jsm/webxr/OculusHandPointerModel.js +416 -416
- package/examples/jsm/webxr/Text2D.js +38 -38
- package/examples/jsm/webxr/VRButton.js +233 -225
- package/examples/jsm/webxr/XRButton.js +223 -224
- package/examples/jsm/webxr/XRControllerModelFactory.js +323 -315
- package/examples/jsm/webxr/XREstimatedLight.js +223 -223
- package/examples/jsm/webxr/XRHandMeshModel.js +116 -116
- package/examples/jsm/webxr/XRHandModelFactory.js +105 -105
- package/examples/jsm/webxr/XRHandPrimitiveModel.js +105 -105
- package/examples/jsm/webxr/XRPlanes.js +100 -100
- package/package.json +4 -4
- package/src/Three.Legacy.js +21 -1
- package/src/Three.js +183 -184
- package/src/animation/AnimationAction.js +700 -700
- package/src/animation/AnimationClip.js +473 -473
- package/src/animation/AnimationMixer.js +770 -770
- package/src/animation/AnimationObjectGroup.js +387 -387
- package/src/animation/AnimationUtils.js +356 -356
- package/src/animation/KeyframeTrack.js +462 -462
- package/src/animation/PropertyBinding.js +719 -719
- package/src/animation/PropertyMixer.js +318 -318
- package/src/animation/tracks/BooleanKeyframeTrack.js +19 -19
- package/src/animation/tracks/ColorKeyframeTrack.js +15 -15
- package/src/animation/tracks/NumberKeyframeTrack.js +12 -12
- package/src/animation/tracks/QuaternionKeyframeTrack.js +23 -23
- package/src/animation/tracks/StringKeyframeTrack.js +15 -15
- package/src/animation/tracks/VectorKeyframeTrack.js +12 -12
- package/src/audio/Audio.js +400 -400
- package/src/audio/AudioAnalyser.js +40 -40
- package/src/audio/AudioContext.js +25 -25
- package/src/audio/AudioListener.js +140 -140
- package/src/audio/PositionalAudio.js +146 -146
- package/src/cameras/ArrayCamera.js +17 -17
- package/src/cameras/Camera.js +69 -69
- package/src/cameras/CubeCamera.js +173 -173
- package/src/cameras/OrthographicCamera.js +136 -136
- package/src/cameras/PerspectiveCamera.js +268 -268
- package/src/cameras/StereoCamera.js +100 -100
- package/src/constants.js +217 -216
- package/src/core/BufferAttribute.js +639 -650
- package/src/core/BufferGeometry.js +1073 -1079
- package/src/core/Clock.js +74 -74
- package/src/core/EventDispatcher.js +87 -87
- package/src/core/GLBufferAttribute.js +60 -60
- package/src/core/InstancedBufferAttribute.js +39 -39
- package/src/core/InstancedBufferGeometry.js +40 -40
- package/src/core/InstancedInterleavedBuffer.js +48 -48
- package/src/core/InterleavedBuffer.js +166 -166
- package/src/core/InterleavedBufferAttribute.js +351 -351
- package/src/core/Layers.js +60 -60
- package/src/core/Object3D.js +1019 -1008
- package/src/core/Raycaster.js +124 -110
- package/src/core/RenderTarget.js +154 -131
- package/src/core/Uniform.js +17 -17
- package/src/core/UniformsGroup.js +98 -98
- package/src/extras/DataUtils.js +176 -176
- package/src/extras/Earcut.js +789 -789
- package/src/extras/ImageUtils.js +129 -129
- package/src/extras/PMREMGenerator.js +912 -910
- package/src/extras/ShapeUtils.js +92 -92
- package/src/extras/core/Curve.js +416 -416
- package/src/extras/core/CurvePath.js +255 -255
- package/src/extras/core/Interpolations.js +79 -79
- package/src/extras/core/Path.js +196 -196
- package/src/extras/core/Shape.js +102 -102
- package/src/extras/core/ShapePath.js +291 -291
- package/src/extras/curves/ArcCurve.js +17 -17
- package/src/extras/curves/CatmullRomCurve3.js +255 -255
- package/src/extras/curves/CubicBezierCurve.js +78 -78
- package/src/extras/curves/CubicBezierCurve3.js +79 -79
- package/src/extras/curves/Curves.js +10 -10
- package/src/extras/curves/EllipseCurve.js +156 -156
- package/src/extras/curves/LineCurve.js +92 -92
- package/src/extras/curves/LineCurve3.js +92 -92
- package/src/extras/curves/QuadraticBezierCurve.js +74 -74
- package/src/extras/curves/QuadraticBezierCurve3.js +75 -75
- package/src/extras/curves/SplineCurve.js +97 -97
- package/src/geometries/BoxGeometry.js +180 -180
- package/src/geometries/CapsuleGeometry.js +33 -33
- package/src/geometries/CircleGeometry.js +101 -101
- package/src/geometries/ConeGeometry.js +31 -31
- package/src/geometries/CylinderGeometry.js +286 -286
- package/src/geometries/DodecahedronGeometry.js +66 -66
- package/src/geometries/EdgesGeometry.js +152 -152
- package/src/geometries/ExtrudeGeometry.js +814 -814
- package/src/geometries/Geometries.js +21 -21
- package/src/geometries/IcosahedronGeometry.js +42 -42
- package/src/geometries/LatheGeometry.js +189 -189
- package/src/geometries/OctahedronGeometry.js +37 -37
- package/src/geometries/PlaneGeometry.js +98 -98
- package/src/geometries/PolyhedronGeometry.js +319 -319
- package/src/geometries/RingGeometry.js +128 -128
- package/src/geometries/ShapeGeometry.js +195 -195
- package/src/geometries/SphereGeometry.js +137 -137
- package/src/geometries/TetrahedronGeometry.js +34 -34
- package/src/geometries/TorusGeometry.js +120 -120
- package/src/geometries/TorusKnotGeometry.js +167 -167
- package/src/geometries/TubeGeometry.js +203 -203
- package/src/geometries/WireframeGeometry.js +147 -147
- package/src/helpers/ArrowHelper.js +114 -114
- package/src/helpers/AxesHelper.js +68 -68
- package/src/helpers/Box3Helper.js +55 -55
- package/src/helpers/BoxHelper.js +113 -113
- package/src/helpers/CameraHelper.js +269 -269
- package/src/helpers/DirectionalLightHelper.js +93 -93
- package/src/helpers/GridHelper.js +56 -56
- package/src/helpers/HemisphereLightHelper.js +88 -88
- package/src/helpers/PlaneHelper.js +63 -63
- package/src/helpers/PointLightHelper.js +92 -92
- package/src/helpers/PolarGridHelper.js +96 -96
- package/src/helpers/SkeletonHelper.js +128 -128
- package/src/helpers/SpotLightHelper.js +111 -94
- package/src/lights/AmbientLight.js +17 -17
- package/src/lights/DirectionalLight.js +43 -43
- package/src/lights/DirectionalLightShadow.js +16 -16
- package/src/lights/HemisphereLight.js +34 -34
- package/src/lights/Light.js +58 -58
- package/src/lights/LightProbe.js +47 -47
- package/src/lights/LightShadow.js +147 -147
- package/src/lights/PointLight.js +57 -57
- package/src/lights/PointLightShadow.js +96 -96
- package/src/lights/RectAreaLight.js +56 -56
- package/src/lights/SpotLight.js +71 -71
- package/src/lights/SpotLightShadow.js +50 -50
- package/src/loaders/AnimationLoader.js +66 -66
- package/src/loaders/AudioLoader.js +66 -66
- package/src/loaders/BufferGeometryLoader.js +217 -217
- package/src/loaders/Cache.js +42 -42
- package/src/loaders/CompressedTextureLoader.js +134 -134
- package/src/loaders/CubeTextureLoader.js +58 -58
- package/src/loaders/DataTextureLoader.js +131 -135
- package/src/loaders/FileLoader.js +284 -284
- package/src/loaders/ImageBitmapLoader.js +123 -123
- package/src/loaders/ImageLoader.js +91 -91
- package/src/loaders/Loader.js +72 -72
- package/src/loaders/LoaderUtils.js +75 -75
- package/src/loaders/LoadingManager.js +142 -142
- package/src/loaders/MaterialLoader.js +373 -372
- package/src/loaders/ObjectLoader.js +1149 -1148
- package/src/loaders/TextureLoader.js +41 -41
- package/src/materials/LineBasicMaterial.js +49 -53
- package/src/materials/LineDashedMaterial.js +35 -35
- package/src/materials/Material.js +523 -522
- package/src/materials/Materials.js +39 -39
- package/src/materials/MeshBasicMaterial.js +84 -85
- package/src/materials/MeshDepthMaterial.js +54 -54
- package/src/materials/MeshDistanceMaterial.js +43 -43
- package/src/materials/MeshLambertMaterial.js +119 -120
- package/src/materials/MeshMatcapMaterial.js +81 -85
- package/src/materials/MeshNormalMaterial.js +61 -61
- package/src/materials/MeshPhongMaterial.js +123 -124
- package/src/materials/MeshPhysicalMaterial.js +224 -224
- package/src/materials/MeshStandardMaterial.js +127 -128
- package/src/materials/MeshToonMaterial.js +102 -106
- package/src/materials/PointsMaterial.js +50 -54
- package/src/materials/RawShaderMaterial.js +17 -17
- package/src/materials/ShaderMaterial.js +189 -190
- package/src/materials/ShadowMaterial.js +37 -37
- package/src/materials/SpriteMaterial.js +54 -54
- package/src/math/Box2.js +204 -204
- package/src/math/Box3.js +534 -534
- package/src/math/Color.js +623 -623
- package/src/math/ColorManagement.js +139 -139
- package/src/math/Cylindrical.js +61 -61
- package/src/math/Euler.js +315 -315
- package/src/math/Frustum.js +186 -186
- package/src/math/Interpolant.js +241 -241
- package/src/math/Line3.js +115 -115
- package/src/math/MathUtils.js +363 -363
- package/src/math/Matrix3.js +388 -388
- package/src/math/Matrix4.js +915 -915
- package/src/math/Plane.js +205 -205
- package/src/math/Quaternion.js +686 -685
- package/src/math/Ray.js +493 -493
- package/src/math/Sphere.js +245 -245
- package/src/math/Spherical.js +86 -86
- package/src/math/SphericalHarmonics3.js +243 -243
- package/src/math/Triangle.js +311 -311
- package/src/math/Vector2.js +480 -480
- package/src/math/Vector3.js +724 -724
- package/src/math/Vector4.js +644 -644
- package/src/math/interpolants/CubicInterpolant.js +150 -150
- package/src/math/interpolants/DiscreteInterpolant.js +26 -26
- package/src/math/interpolants/LinearInterpolant.js +38 -38
- package/src/math/interpolants/QuaternionLinearInterpolant.js +39 -39
- package/src/objects/BatchedMesh.js +1019 -1019
- package/src/objects/Bone.js +17 -17
- package/src/objects/Group.js +17 -17
- package/src/objects/InstancedMesh.js +267 -214
- package/src/objects/LOD.js +214 -214
- package/src/objects/Line.js +222 -222
- package/src/objects/LineLoop.js +17 -17
- package/src/objects/LineSegments.js +55 -55
- package/src/objects/Mesh.js +428 -429
- package/src/objects/Points.js +166 -166
- package/src/objects/Skeleton.js +277 -277
- package/src/objects/SkinnedMesh.js +257 -257
- package/src/objects/Sprite.js +181 -181
- package/src/renderers/WebGL1Renderer.js +7 -7
- package/src/renderers/WebGL3DRenderTarget.js +22 -22
- package/src/renderers/WebGLArrayRenderTarget.js +22 -22
- package/src/renderers/WebGLCubeRenderTarget.js +146 -155
- package/src/renderers/WebGLRenderTarget.js +15 -15
- package/src/renderers/WebGLRenderer.js +2615 -2631
- package/src/renderers/shaders/ShaderChunk/alphahash_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/alphahash_pars_fragment.glsl.js +68 -68
- package/src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl.js +16 -16
- package/src/renderers/shaders/ShaderChunk/alphatest_pars_fragment.glsl.js +5 -5
- package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +26 -26
- package/src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl.js +8 -8
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +19 -19
- package/src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js +5 -5
- package/src/renderers/shaders/ShaderChunk/begin_vertex.glsl.js +9 -9
- package/src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl.js +9 -9
- package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +33 -33
- package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +43 -43
- package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_begin.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js +10 -10
- package/src/renderers/shaders/ShaderChunk/clearcoat_pars_fragment.glsl.js +21 -21
- package/src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl.js +78 -78
- package/src/renderers/shaders/ShaderChunk/clipping_planes_pars_fragment.glsl.js +9 -9
- package/src/renderers/shaders/ShaderChunk/clipping_planes_pars_vertex.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/clipping_planes_vertex.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +11 -11
- package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +11 -11
- package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +11 -11
- package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +23 -23
- package/src/renderers/shaders/ShaderChunk/colorspace_fragment.glsl.js +3 -3
- package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +44 -44
- package/src/renderers/shaders/ShaderChunk/common.glsl.js +147 -147
- package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +186 -186
- package/src/renderers/shaders/ShaderChunk/default_fragment.glsl.js +5 -5
- package/src/renderers/shaders/ShaderChunk/default_vertex.glsl.js +5 -5
- package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +63 -63
- package/src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl.js +9 -9
- package/src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/dithering_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/dithering_pars_fragment.glsl.js +20 -20
- package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +9 -9
- package/src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +15 -14
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +62 -62
- package/src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl.js +21 -21
- package/src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl.js +22 -22
- package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +69 -69
- package/src/renderers/shaders/ShaderChunk/envmap_vertex.glsl.js +37 -37
- package/src/renderers/shaders/ShaderChunk/fog_fragment.glsl.js +17 -17
- package/src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl.js +19 -19
- package/src/renderers/shaders/ShaderChunk/fog_pars_vertex.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/fog_vertex.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/gradientmap_pars_fragment.glsl.js +27 -27
- package/src/renderers/shaders/ShaderChunk/iridescence_fragment.glsl.js +120 -120
- package/src/renderers/shaders/ShaderChunk/iridescence_pars_fragment.glsl.js +14 -14
- package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +10 -10
- package/src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl.js +8 -8
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +202 -202
- package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +13 -13
- package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +40 -40
- package/src/renderers/shaders/ShaderChunk/lights_lambert_fragment.glsl.js +5 -5
- package/src/renderers/shaders/ShaderChunk/lights_lambert_pars_fragment.glsl.js +28 -28
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +228 -228
- package/src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl.js +32 -32
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +151 -151
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +562 -562
- package/src/renderers/shaders/ShaderChunk/lights_toon_fragment.glsl.js +4 -4
- package/src/renderers/shaders/ShaderChunk/lights_toon_pars_fragment.glsl.js +26 -26
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +9 -9
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +9 -9
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +16 -16
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +22 -22
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +21 -21
- package/src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl.js +11 -11
- package/src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl.js +27 -27
- package/src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl.js +27 -27
- package/src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl.js +12 -12
- package/src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/morphcolor_vertex.glsl.js +24 -24
- package/src/renderers/shaders/ShaderChunk/morphinstance_vertex.glsl.js +14 -0
- package/src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl.js +27 -27
- package/src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js +47 -38
- package/src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl.js +36 -36
- package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +76 -76
- package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +33 -33
- package/src/renderers/shaders/ShaderChunk/normal_pars_fragment.glsl.js +14 -14
- package/src/renderers/shaders/ShaderChunk/normal_pars_vertex.glsl.js +14 -14
- package/src/renderers/shaders/ShaderChunk/normal_vertex.glsl.js +14 -14
- package/src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js +43 -43
- package/src/renderers/shaders/ShaderChunk/opaque_fragment.glsl.js +11 -11
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +68 -68
- package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +8 -8
- package/src/renderers/shaders/ShaderChunk/project_vertex.glsl.js +19 -19
- package/src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl.js +12 -12
- package/src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +314 -314
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +68 -68
- package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +68 -68
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +66 -66
- package/src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl.js +10 -10
- package/src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl.js +25 -25
- package/src/renderers/shaders/ShaderChunk/skinning_vertex.glsl.js +15 -15
- package/src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl.js +20 -20
- package/src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl.js +14 -14
- package/src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/tonemapping_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +192 -169
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +36 -36
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +201 -201
- package/src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js +119 -119
- package/src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js +145 -145
- package/src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js +122 -122
- package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +21 -21
- package/src/renderers/shaders/ShaderChunk.js +272 -274
- package/src/renderers/shaders/ShaderLib/background.glsl.js +40 -40
- package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +63 -62
- package/src/renderers/shaders/ShaderLib/cube.glsl.js +36 -36
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +97 -95
- package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +78 -76
- package/src/renderers/shaders/ShaderLib/equirect.glsl.js +35 -35
- package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +76 -77
- package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +116 -117
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +125 -126
- package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +112 -113
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +87 -89
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +127 -128
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +225 -226
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +119 -120
- package/src/renderers/shaders/ShaderLib/points.glsl.js +87 -88
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +58 -57
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +81 -81
- package/src/renderers/shaders/ShaderLib/vsm.glsl.js +53 -53
- package/src/renderers/shaders/ShaderLib.js +360 -367
- package/src/renderers/shaders/UniformsLib.js +231 -236
- package/src/renderers/shaders/UniformsUtils.js +104 -104
- package/src/renderers/webgl/WebGLAnimation.js +53 -53
- package/src/renderers/webgl/WebGLAttributes.js +229 -229
- package/src/renderers/webgl/WebGLBackground.js +257 -239
- package/src/renderers/webgl/WebGLBindingStates.js +631 -631
- package/src/renderers/webgl/WebGLBufferRenderer.js +92 -92
- package/src/renderers/webgl/WebGLCapabilities.js +120 -120
- package/src/renderers/webgl/WebGLClipping.js +171 -171
- package/src/renderers/webgl/WebGLCubeMaps.js +99 -99
- package/src/renderers/webgl/WebGLCubeUVMaps.js +132 -132
- package/src/renderers/webgl/WebGLExtensions.js +97 -97
- package/src/renderers/webgl/WebGLGeometries.js +211 -211
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +102 -102
- package/src/renderers/webgl/WebGLInfo.js +71 -71
- package/src/renderers/webgl/WebGLLights.js +590 -590
- package/src/renderers/webgl/WebGLMaterials.js +590 -576
- package/src/renderers/webgl/WebGLMorphtargets.js +307 -300
- package/src/renderers/webgl/WebGLObjects.js +92 -92
- package/src/renderers/webgl/WebGLProgram.js +1120 -1112
- package/src/renderers/webgl/WebGLPrograms.js +664 -663
- package/src/renderers/webgl/WebGLProperties.js +48 -48
- package/src/renderers/webgl/WebGLRenderLists.js +238 -238
- package/src/renderers/webgl/WebGLRenderStates.js +107 -107
- package/src/renderers/webgl/WebGLShader.js +12 -12
- package/src/renderers/webgl/WebGLShaderCache.js +124 -124
- package/src/renderers/webgl/WebGLShadowMap.js +424 -424
- package/src/renderers/webgl/WebGLState.js +1318 -1328
- package/src/renderers/webgl/WebGLTextures.js +2213 -2117
- package/src/renderers/webgl/WebGLUniforms.js +1156 -1156
- package/src/renderers/webgl/WebGLUniformsGroups.js +392 -392
- package/src/renderers/webgl/WebGLUtils.js +283 -283
- package/src/renderers/webxr/WebXRController.js +343 -343
- package/src/renderers/webxr/WebXRDepthSensing.js +105 -0
- package/src/renderers/webxr/WebXRManager.js +824 -840
- package/src/scenes/Fog.js +38 -38
- package/src/scenes/FogExp2.js +35 -35
- package/src/scenes/Scene.js +71 -63
- package/src/textures/CanvasTexture.js +17 -17
- package/src/textures/CompressedArrayTexture.js +18 -18
- package/src/textures/CompressedCubeTexture.js +19 -19
- package/src/textures/CompressedTexture.js +28 -28
- package/src/textures/CubeTexture.js +33 -33
- package/src/textures/Data3DTexture.js +35 -35
- package/src/textures/DataArrayTexture.js +27 -27
- package/src/textures/DataTexture.js +22 -22
- package/src/textures/DepthTexture.js +58 -58
- package/src/textures/FramebufferTexture.js +23 -23
- package/src/textures/Source.js +128 -127
- package/src/textures/Texture.js +310 -338
- package/src/textures/VideoTexture.js +55 -55
- package/src/utils.js +91 -91
- package/examples/jsm/nodes/core/ArrayUniformNode.js +0 -26
- package/src/renderers/WebGLMultipleRenderTargets.js +0 -82
- package/src/renderers/shaders/ShaderChunk/occlusion_fragment.glsl.js +0 -20
- package/src/renderers/shaders/ShaderChunk/occlusion_pars_fragment.glsl.js +0 -97
|
@@ -1,932 +1,932 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Loader for KTX 2.0 GPU Texture containers.
|
|
3
|
-
*
|
|
4
|
-
* KTX 2.0 is a container format for various GPU texture formats. The loader
|
|
5
|
-
* supports Basis Universal GPU textures, which can be quickly transcoded to
|
|
6
|
-
* a wide variety of GPU texture compression formats, as well as some
|
|
7
|
-
* uncompressed DataTexture and Data3DTexture formats.
|
|
8
|
-
*
|
|
9
|
-
* References:
|
|
10
|
-
* - KTX: http://github.khronos.org/KTX-Specification/
|
|
11
|
-
* - DFD: https://www.khronos.org/registry/DataFormat/specs/1.3/dataformat.1.3.html#basicdescriptor
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
CompressedTexture,
|
|
16
|
-
CompressedArrayTexture,
|
|
17
|
-
CompressedCubeTexture,
|
|
18
|
-
Data3DTexture,
|
|
19
|
-
DataTexture,
|
|
20
|
-
DisplayP3ColorSpace,
|
|
21
|
-
FileLoader,
|
|
22
|
-
FloatType,
|
|
23
|
-
HalfFloatType,
|
|
24
|
-
NoColorSpace,
|
|
25
|
-
LinearFilter,
|
|
26
|
-
LinearMipmapLinearFilter,
|
|
27
|
-
LinearDisplayP3ColorSpace,
|
|
28
|
-
LinearSRGBColorSpace,
|
|
29
|
-
Loader,
|
|
30
|
-
RedFormat,
|
|
31
|
-
RGB_ETC1_Format,
|
|
32
|
-
RGB_ETC2_Format,
|
|
33
|
-
RGB_PVRTC_4BPPV1_Format,
|
|
34
|
-
RGB_S3TC_DXT1_Format,
|
|
35
|
-
RGBA_ASTC_4x4_Format,
|
|
36
|
-
RGBA_ASTC_6x6_Format,
|
|
37
|
-
RGBA_BPTC_Format,
|
|
38
|
-
RGBA_ETC2_EAC_Format,
|
|
39
|
-
RGBA_PVRTC_4BPPV1_Format,
|
|
40
|
-
RGBA_S3TC_DXT5_Format,
|
|
41
|
-
RGBAFormat,
|
|
42
|
-
RGFormat,
|
|
43
|
-
SRGBColorSpace,
|
|
44
|
-
UnsignedByteType,
|
|
45
|
-
} from 'three';
|
|
46
|
-
import { WorkerPool } from '../utils/WorkerPool.js';
|
|
47
|
-
import {
|
|
48
|
-
read,
|
|
49
|
-
KHR_DF_FLAG_ALPHA_PREMULTIPLIED,
|
|
50
|
-
KHR_DF_TRANSFER_SRGB,
|
|
51
|
-
KHR_SUPERCOMPRESSION_NONE,
|
|
52
|
-
KHR_SUPERCOMPRESSION_ZSTD,
|
|
53
|
-
VK_FORMAT_UNDEFINED,
|
|
54
|
-
VK_FORMAT_R16_SFLOAT,
|
|
55
|
-
VK_FORMAT_R16G16_SFLOAT,
|
|
56
|
-
VK_FORMAT_R16G16B16A16_SFLOAT,
|
|
57
|
-
VK_FORMAT_R32_SFLOAT,
|
|
58
|
-
VK_FORMAT_R32G32_SFLOAT,
|
|
59
|
-
VK_FORMAT_R32G32B32A32_SFLOAT,
|
|
60
|
-
VK_FORMAT_R8_SRGB,
|
|
61
|
-
VK_FORMAT_R8_UNORM,
|
|
62
|
-
VK_FORMAT_R8G8_SRGB,
|
|
63
|
-
VK_FORMAT_R8G8_UNORM,
|
|
64
|
-
VK_FORMAT_R8G8B8A8_SRGB,
|
|
65
|
-
VK_FORMAT_R8G8B8A8_UNORM,
|
|
66
|
-
VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
|
|
67
|
-
VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
|
|
68
|
-
KHR_DF_PRIMARIES_UNSPECIFIED,
|
|
69
|
-
KHR_DF_PRIMARIES_BT709,
|
|
70
|
-
KHR_DF_PRIMARIES_DISPLAYP3
|
|
71
|
-
} from '../libs/ktx-parse.module.js';
|
|
72
|
-
import { ZSTDDecoder } from '../libs/zstddec.module.js';
|
|
73
|
-
|
|
74
|
-
const _taskCache = new WeakMap();
|
|
75
|
-
|
|
76
|
-
let _activeLoaders = 0;
|
|
77
|
-
|
|
78
|
-
let _zstd;
|
|
79
|
-
|
|
80
|
-
class KTX2Loader extends Loader {
|
|
81
|
-
|
|
82
|
-
constructor( manager ) {
|
|
83
|
-
|
|
84
|
-
super( manager );
|
|
85
|
-
|
|
86
|
-
this.transcoderPath = '';
|
|
87
|
-
this.transcoderBinary = null;
|
|
88
|
-
this.transcoderPending = null;
|
|
89
|
-
|
|
90
|
-
this.workerPool = new WorkerPool();
|
|
91
|
-
this.workerSourceURL = '';
|
|
92
|
-
this.workerConfig = null;
|
|
93
|
-
|
|
94
|
-
if ( typeof MSC_TRANSCODER !== 'undefined' ) {
|
|
95
|
-
|
|
96
|
-
console.warn(
|
|
97
|
-
|
|
98
|
-
'THREE.KTX2Loader: Please update to latest "basis_transcoder".'
|
|
99
|
-
+ ' "msc_basis_transcoder" is no longer supported in three.js r125+.'
|
|
100
|
-
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
setTranscoderPath( path ) {
|
|
108
|
-
|
|
109
|
-
this.transcoderPath = path;
|
|
110
|
-
|
|
111
|
-
return this;
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
setWorkerLimit( num ) {
|
|
116
|
-
|
|
117
|
-
this.workerPool.setWorkerLimit( num );
|
|
118
|
-
|
|
119
|
-
return this;
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async detectSupportAsync( renderer ) {
|
|
124
|
-
|
|
125
|
-
this.workerConfig = {
|
|
126
|
-
astcSupported: await renderer.hasFeatureAsync( 'texture-compression-astc' ),
|
|
127
|
-
etc1Supported: await renderer.hasFeatureAsync( 'texture-compression-etc1' ),
|
|
128
|
-
etc2Supported: await renderer.hasFeatureAsync( 'texture-compression-etc2' ),
|
|
129
|
-
dxtSupported: await renderer.hasFeatureAsync( 'texture-compression-bc' ),
|
|
130
|
-
bptcSupported: await renderer.hasFeatureAsync( 'texture-compression-bptc' ),
|
|
131
|
-
pvrtcSupported: await renderer.hasFeatureAsync( 'texture-compression-pvrtc' )
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
return this;
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
detectSupport( renderer ) {
|
|
139
|
-
|
|
140
|
-
if ( renderer.isWebGPURenderer === true ) {
|
|
141
|
-
|
|
142
|
-
this.workerConfig = {
|
|
143
|
-
astcSupported: renderer.hasFeature( 'texture-compression-astc' ),
|
|
144
|
-
etc1Supported: renderer.hasFeature( 'texture-compression-etc1' ),
|
|
145
|
-
etc2Supported: renderer.hasFeature( 'texture-compression-etc2' ),
|
|
146
|
-
dxtSupported: renderer.hasFeature( 'texture-compression-bc' ),
|
|
147
|
-
bptcSupported: renderer.hasFeature( 'texture-compression-bptc' ),
|
|
148
|
-
pvrtcSupported: renderer.hasFeature( 'texture-compression-pvrtc' )
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
} else {
|
|
152
|
-
|
|
153
|
-
this.workerConfig = {
|
|
154
|
-
astcSupported: renderer.extensions.has( 'WEBGL_compressed_texture_astc' ),
|
|
155
|
-
etc1Supported: renderer.extensions.has( 'WEBGL_compressed_texture_etc1' ),
|
|
156
|
-
etc2Supported: renderer.extensions.has( 'WEBGL_compressed_texture_etc' ),
|
|
157
|
-
dxtSupported: renderer.extensions.has( 'WEBGL_compressed_texture_s3tc' ),
|
|
158
|
-
bptcSupported: renderer.extensions.has( 'EXT_texture_compression_bptc' ),
|
|
159
|
-
pvrtcSupported: renderer.extensions.has( 'WEBGL_compressed_texture_pvrtc' )
|
|
160
|
-
|| renderer.extensions.has( 'WEBKIT_WEBGL_compressed_texture_pvrtc' )
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
if ( renderer.capabilities.isWebGL2 ) {
|
|
164
|
-
|
|
165
|
-
// https://github.com/mrdoob/three.js/pull/22928
|
|
166
|
-
this.workerConfig.etc1Supported = false;
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return this;
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
init() {
|
|
177
|
-
|
|
178
|
-
if ( ! this.transcoderPending ) {
|
|
179
|
-
|
|
180
|
-
// Load transcoder wrapper.
|
|
181
|
-
const jsLoader = new FileLoader( this.manager );
|
|
182
|
-
jsLoader.setPath( this.transcoderPath );
|
|
183
|
-
jsLoader.setWithCredentials( this.withCredentials );
|
|
184
|
-
const jsContent = jsLoader.loadAsync( 'basis_transcoder.js' );
|
|
185
|
-
|
|
186
|
-
// Load transcoder WASM binary.
|
|
187
|
-
const binaryLoader = new FileLoader( this.manager );
|
|
188
|
-
binaryLoader.setPath( this.transcoderPath );
|
|
189
|
-
binaryLoader.setResponseType( 'arraybuffer' );
|
|
190
|
-
binaryLoader.setWithCredentials( this.withCredentials );
|
|
191
|
-
const binaryContent = binaryLoader.loadAsync( 'basis_transcoder.wasm' );
|
|
192
|
-
|
|
193
|
-
this.transcoderPending = Promise.all( [ jsContent, binaryContent ] )
|
|
194
|
-
.then( ( [ jsContent, binaryContent ] ) => {
|
|
195
|
-
|
|
196
|
-
const fn = KTX2Loader.BasisWorker.toString();
|
|
197
|
-
|
|
198
|
-
const body = [
|
|
199
|
-
'/* constants */',
|
|
200
|
-
'let _EngineFormat = ' + JSON.stringify( KTX2Loader.EngineFormat ),
|
|
201
|
-
'let _TranscoderFormat = ' + JSON.stringify( KTX2Loader.TranscoderFormat ),
|
|
202
|
-
'let _BasisFormat = ' + JSON.stringify( KTX2Loader.BasisFormat ),
|
|
203
|
-
'/* basis_transcoder.js */',
|
|
204
|
-
jsContent,
|
|
205
|
-
'/* worker */',
|
|
206
|
-
fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) )
|
|
207
|
-
].join( '\n' );
|
|
208
|
-
|
|
209
|
-
this.workerSourceURL = URL.createObjectURL( new Blob( [ body ] ) );
|
|
210
|
-
this.transcoderBinary = binaryContent;
|
|
211
|
-
|
|
212
|
-
this.workerPool.setWorkerCreator( () => {
|
|
213
|
-
|
|
214
|
-
const worker = new Worker( this.workerSourceURL );
|
|
215
|
-
const transcoderBinary = this.transcoderBinary.slice( 0 );
|
|
216
|
-
|
|
217
|
-
worker.postMessage( { type: 'init', config: this.workerConfig, transcoderBinary }, [ transcoderBinary ] );
|
|
218
|
-
|
|
219
|
-
return worker;
|
|
220
|
-
|
|
221
|
-
} );
|
|
222
|
-
|
|
223
|
-
} );
|
|
224
|
-
|
|
225
|
-
if ( _activeLoaders > 0 ) {
|
|
226
|
-
|
|
227
|
-
// Each instance loads a transcoder and allocates workers, increasing network and memory cost.
|
|
228
|
-
|
|
229
|
-
console.warn(
|
|
230
|
-
|
|
231
|
-
'THREE.KTX2Loader: Multiple active KTX2 loaders may cause performance issues.'
|
|
232
|
-
+ ' Use a single KTX2Loader instance, or call .dispose() on old instances.'
|
|
233
|
-
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
_activeLoaders ++;
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return this.transcoderPending;
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
load( url, onLoad, onProgress, onError ) {
|
|
247
|
-
|
|
248
|
-
if ( this.workerConfig === null ) {
|
|
249
|
-
|
|
250
|
-
throw new Error( 'THREE.KTX2Loader: Missing initialization with `.detectSupport( renderer )`.' );
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const loader = new FileLoader( this.manager );
|
|
255
|
-
|
|
256
|
-
loader.setResponseType( 'arraybuffer' );
|
|
257
|
-
loader.setWithCredentials( this.withCredentials );
|
|
258
|
-
|
|
259
|
-
loader.load( url, ( buffer ) => {
|
|
260
|
-
|
|
261
|
-
// Check for an existing task using this buffer. A transferred buffer cannot be transferred
|
|
262
|
-
// again from this thread.
|
|
263
|
-
if ( _taskCache.has( buffer ) ) {
|
|
264
|
-
|
|
265
|
-
const cachedTask = _taskCache.get( buffer );
|
|
266
|
-
|
|
267
|
-
return cachedTask.promise.then( onLoad ).catch( onError );
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
this._createTexture( buffer )
|
|
272
|
-
.then( ( texture ) => onLoad ? onLoad( texture ) : null )
|
|
273
|
-
.catch( onError );
|
|
274
|
-
|
|
275
|
-
}, onProgress, onError );
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
_createTextureFrom( transcodeResult, container ) {
|
|
280
|
-
|
|
281
|
-
const { faces, width, height, format, type, error, dfdFlags } = transcodeResult;
|
|
282
|
-
|
|
283
|
-
if ( type === 'error' ) return Promise.reject( error );
|
|
284
|
-
|
|
285
|
-
let texture;
|
|
286
|
-
|
|
287
|
-
if ( container.faceCount === 6 ) {
|
|
288
|
-
|
|
289
|
-
texture = new CompressedCubeTexture( faces, format, UnsignedByteType );
|
|
290
|
-
|
|
291
|
-
} else {
|
|
292
|
-
|
|
293
|
-
const mipmaps = faces[ 0 ].mipmaps;
|
|
294
|
-
|
|
295
|
-
texture = container.layerCount > 1
|
|
296
|
-
? new CompressedArrayTexture( mipmaps, width, height, container.layerCount, format, UnsignedByteType )
|
|
297
|
-
: new CompressedTexture( mipmaps, width, height, format, UnsignedByteType );
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
texture.minFilter = faces[ 0 ].mipmaps.length === 1 ? LinearFilter : LinearMipmapLinearFilter;
|
|
302
|
-
texture.magFilter = LinearFilter;
|
|
303
|
-
texture.generateMipmaps = false;
|
|
304
|
-
|
|
305
|
-
texture.needsUpdate = true;
|
|
306
|
-
texture.colorSpace = parseColorSpace( container );
|
|
307
|
-
texture.premultiplyAlpha = !! ( dfdFlags & KHR_DF_FLAG_ALPHA_PREMULTIPLIED );
|
|
308
|
-
|
|
309
|
-
return texture;
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* @param {ArrayBuffer} buffer
|
|
315
|
-
* @param {object?} config
|
|
316
|
-
* @return {Promise<CompressedTexture|CompressedArrayTexture|DataTexture|Data3DTexture>}
|
|
317
|
-
*/
|
|
318
|
-
async _createTexture( buffer, config = {} ) {
|
|
319
|
-
|
|
320
|
-
const container = read( new Uint8Array( buffer ) );
|
|
321
|
-
|
|
322
|
-
if ( container.vkFormat !== VK_FORMAT_UNDEFINED ) {
|
|
323
|
-
|
|
324
|
-
return createRawTexture( container );
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
//
|
|
329
|
-
const taskConfig = config;
|
|
330
|
-
const texturePending = this.init().then( () => {
|
|
331
|
-
|
|
332
|
-
return this.workerPool.postMessage( { type: 'transcode', buffer, taskConfig: taskConfig }, [ buffer ] );
|
|
333
|
-
|
|
334
|
-
} ).then( ( e ) => this._createTextureFrom( e.data, container ) );
|
|
335
|
-
|
|
336
|
-
// Cache the task result.
|
|
337
|
-
_taskCache.set( buffer, { promise: texturePending } );
|
|
338
|
-
|
|
339
|
-
return texturePending;
|
|
340
|
-
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
dispose() {
|
|
344
|
-
|
|
345
|
-
this.workerPool.dispose();
|
|
346
|
-
if ( this.workerSourceURL ) URL.revokeObjectURL( this.workerSourceURL );
|
|
347
|
-
|
|
348
|
-
_activeLoaders --;
|
|
349
|
-
|
|
350
|
-
return this;
|
|
351
|
-
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
/* CONSTANTS */
|
|
358
|
-
|
|
359
|
-
KTX2Loader.BasisFormat = {
|
|
360
|
-
ETC1S: 0,
|
|
361
|
-
UASTC_4x4: 1,
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
KTX2Loader.TranscoderFormat = {
|
|
365
|
-
ETC1: 0,
|
|
366
|
-
ETC2: 1,
|
|
367
|
-
BC1: 2,
|
|
368
|
-
BC3: 3,
|
|
369
|
-
BC4: 4,
|
|
370
|
-
BC5: 5,
|
|
371
|
-
BC7_M6_OPAQUE_ONLY: 6,
|
|
372
|
-
BC7_M5: 7,
|
|
373
|
-
PVRTC1_4_RGB: 8,
|
|
374
|
-
PVRTC1_4_RGBA: 9,
|
|
375
|
-
ASTC_4x4: 10,
|
|
376
|
-
ATC_RGB: 11,
|
|
377
|
-
ATC_RGBA_INTERPOLATED_ALPHA: 12,
|
|
378
|
-
RGBA32: 13,
|
|
379
|
-
RGB565: 14,
|
|
380
|
-
BGR565: 15,
|
|
381
|
-
RGBA4444: 16,
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
KTX2Loader.EngineFormat = {
|
|
385
|
-
RGBAFormat: RGBAFormat,
|
|
386
|
-
RGBA_ASTC_4x4_Format: RGBA_ASTC_4x4_Format,
|
|
387
|
-
RGBA_BPTC_Format: RGBA_BPTC_Format,
|
|
388
|
-
RGBA_ETC2_EAC_Format: RGBA_ETC2_EAC_Format,
|
|
389
|
-
RGBA_PVRTC_4BPPV1_Format: RGBA_PVRTC_4BPPV1_Format,
|
|
390
|
-
RGBA_S3TC_DXT5_Format: RGBA_S3TC_DXT5_Format,
|
|
391
|
-
RGB_ETC1_Format: RGB_ETC1_Format,
|
|
392
|
-
RGB_ETC2_Format: RGB_ETC2_Format,
|
|
393
|
-
RGB_PVRTC_4BPPV1_Format: RGB_PVRTC_4BPPV1_Format,
|
|
394
|
-
RGB_S3TC_DXT1_Format: RGB_S3TC_DXT1_Format,
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
/* WEB WORKER */
|
|
399
|
-
|
|
400
|
-
KTX2Loader.BasisWorker = function () {
|
|
401
|
-
|
|
402
|
-
let config;
|
|
403
|
-
let transcoderPending;
|
|
404
|
-
let BasisModule;
|
|
405
|
-
|
|
406
|
-
const EngineFormat = _EngineFormat; // eslint-disable-line no-undef
|
|
407
|
-
const TranscoderFormat = _TranscoderFormat; // eslint-disable-line no-undef
|
|
408
|
-
const BasisFormat = _BasisFormat; // eslint-disable-line no-undef
|
|
409
|
-
|
|
410
|
-
self.addEventListener( 'message', function ( e ) {
|
|
411
|
-
|
|
412
|
-
const message = e.data;
|
|
413
|
-
|
|
414
|
-
switch ( message.type ) {
|
|
415
|
-
|
|
416
|
-
case 'init':
|
|
417
|
-
config = message.config;
|
|
418
|
-
init( message.transcoderBinary );
|
|
419
|
-
break;
|
|
420
|
-
|
|
421
|
-
case 'transcode':
|
|
422
|
-
transcoderPending.then( () => {
|
|
423
|
-
|
|
424
|
-
try {
|
|
425
|
-
|
|
426
|
-
const { faces, buffers, width, height, hasAlpha, format, dfdFlags } = transcode( message.buffer );
|
|
427
|
-
|
|
428
|
-
self.postMessage( { type: 'transcode', id: message.id, faces, width, height, hasAlpha, format, dfdFlags }, buffers );
|
|
429
|
-
|
|
430
|
-
} catch ( error ) {
|
|
431
|
-
|
|
432
|
-
console.error( error );
|
|
433
|
-
|
|
434
|
-
self.postMessage( { type: 'error', id: message.id, error: error.message } );
|
|
435
|
-
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
} );
|
|
439
|
-
break;
|
|
440
|
-
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
} );
|
|
444
|
-
|
|
445
|
-
function init( wasmBinary ) {
|
|
446
|
-
|
|
447
|
-
transcoderPending = new Promise( ( resolve ) => {
|
|
448
|
-
|
|
449
|
-
BasisModule = { wasmBinary, onRuntimeInitialized: resolve };
|
|
450
|
-
BASIS( BasisModule ); // eslint-disable-line no-undef
|
|
451
|
-
|
|
452
|
-
} ).then( () => {
|
|
453
|
-
|
|
454
|
-
BasisModule.initializeBasis();
|
|
455
|
-
|
|
456
|
-
if ( BasisModule.KTX2File === undefined ) {
|
|
457
|
-
|
|
458
|
-
console.warn( 'THREE.KTX2Loader: Please update Basis Universal transcoder.' );
|
|
459
|
-
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
} );
|
|
463
|
-
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
function transcode( buffer ) {
|
|
467
|
-
|
|
468
|
-
const ktx2File = new BasisModule.KTX2File( new Uint8Array( buffer ) );
|
|
469
|
-
|
|
470
|
-
function cleanup() {
|
|
471
|
-
|
|
472
|
-
ktx2File.close();
|
|
473
|
-
ktx2File.delete();
|
|
474
|
-
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
if ( ! ktx2File.isValid() ) {
|
|
478
|
-
|
|
479
|
-
cleanup();
|
|
480
|
-
throw new Error( 'THREE.KTX2Loader: Invalid or unsupported .ktx2 file' );
|
|
481
|
-
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
const basisFormat = ktx2File.isUASTC() ? BasisFormat.UASTC_4x4 : BasisFormat.ETC1S;
|
|
485
|
-
const width = ktx2File.getWidth();
|
|
486
|
-
const height = ktx2File.getHeight();
|
|
487
|
-
const layerCount = ktx2File.getLayers() || 1;
|
|
488
|
-
const levelCount = ktx2File.getLevels();
|
|
489
|
-
const faceCount = ktx2File.getFaces();
|
|
490
|
-
const hasAlpha = ktx2File.getHasAlpha();
|
|
491
|
-
const dfdFlags = ktx2File.getDFDFlags();
|
|
492
|
-
|
|
493
|
-
const { transcoderFormat, engineFormat } = getTranscoderFormat( basisFormat, width, height, hasAlpha );
|
|
494
|
-
|
|
495
|
-
if ( ! width || ! height || ! levelCount ) {
|
|
496
|
-
|
|
497
|
-
cleanup();
|
|
498
|
-
throw new Error( 'THREE.KTX2Loader: Invalid texture' );
|
|
499
|
-
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
if ( ! ktx2File.startTranscoding() ) {
|
|
503
|
-
|
|
504
|
-
cleanup();
|
|
505
|
-
throw new Error( 'THREE.KTX2Loader: .startTranscoding failed' );
|
|
506
|
-
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
const faces = [];
|
|
510
|
-
const buffers = [];
|
|
511
|
-
|
|
512
|
-
for ( let face = 0; face < faceCount; face ++ ) {
|
|
513
|
-
|
|
514
|
-
const mipmaps = [];
|
|
515
|
-
|
|
516
|
-
for ( let mip = 0; mip < levelCount; mip ++ ) {
|
|
517
|
-
|
|
518
|
-
const layerMips = [];
|
|
519
|
-
|
|
520
|
-
let mipWidth, mipHeight;
|
|
521
|
-
|
|
522
|
-
for ( let layer = 0; layer < layerCount; layer ++ ) {
|
|
523
|
-
|
|
524
|
-
const levelInfo = ktx2File.getImageLevelInfo( mip, layer, face );
|
|
525
|
-
|
|
526
|
-
if ( face === 0 && mip === 0 && layer === 0 && ( levelInfo.origWidth % 4 !== 0 || levelInfo.origHeight % 4 !== 0 ) ) {
|
|
527
|
-
|
|
528
|
-
console.warn( 'THREE.KTX2Loader: ETC1S and UASTC textures should use multiple-of-four dimensions.' );
|
|
529
|
-
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
if ( levelCount > 1 ) {
|
|
533
|
-
|
|
534
|
-
mipWidth = levelInfo.origWidth;
|
|
535
|
-
mipHeight = levelInfo.origHeight;
|
|
536
|
-
|
|
537
|
-
} else {
|
|
538
|
-
|
|
539
|
-
// Handles non-multiple-of-four dimensions in textures without mipmaps. Textures with
|
|
540
|
-
// mipmaps must use multiple-of-four dimensions, for some texture formats and APIs.
|
|
541
|
-
// See mrdoob/three.js#25908.
|
|
542
|
-
mipWidth = levelInfo.width;
|
|
543
|
-
mipHeight = levelInfo.height;
|
|
544
|
-
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
const dst = new Uint8Array( ktx2File.getImageTranscodedSizeInBytes( mip, layer, 0, transcoderFormat ) );
|
|
548
|
-
const status = ktx2File.transcodeImage( dst, mip, layer, face, transcoderFormat, 0, - 1, - 1 );
|
|
549
|
-
|
|
550
|
-
if ( ! status ) {
|
|
551
|
-
|
|
552
|
-
cleanup();
|
|
553
|
-
throw new Error( 'THREE.KTX2Loader: .transcodeImage failed.' );
|
|
554
|
-
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
layerMips.push( dst );
|
|
558
|
-
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
const mipData = concat( layerMips );
|
|
562
|
-
|
|
563
|
-
mipmaps.push( { data: mipData, width: mipWidth, height: mipHeight } );
|
|
564
|
-
buffers.push( mipData.buffer );
|
|
565
|
-
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
faces.push( { mipmaps, width, height, format: engineFormat } );
|
|
569
|
-
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
cleanup();
|
|
573
|
-
|
|
574
|
-
return { faces, buffers, width, height, hasAlpha, format: engineFormat, dfdFlags };
|
|
575
|
-
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
//
|
|
579
|
-
|
|
580
|
-
// Optimal choice of a transcoder target format depends on the Basis format (ETC1S or UASTC),
|
|
581
|
-
// device capabilities, and texture dimensions. The list below ranks the formats separately
|
|
582
|
-
// for ETC1S and UASTC.
|
|
583
|
-
//
|
|
584
|
-
// In some cases, transcoding UASTC to RGBA32 might be preferred for higher quality (at
|
|
585
|
-
// significant memory cost) compared to ETC1/2, BC1/3, and PVRTC. The transcoder currently
|
|
586
|
-
// chooses RGBA32 only as a last resort and does not expose that option to the caller.
|
|
587
|
-
const FORMAT_OPTIONS = [
|
|
588
|
-
{
|
|
589
|
-
if: 'astcSupported',
|
|
590
|
-
basisFormat: [ BasisFormat.UASTC_4x4 ],
|
|
591
|
-
transcoderFormat: [ TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4 ],
|
|
592
|
-
engineFormat: [ EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format ],
|
|
593
|
-
priorityETC1S: Infinity,
|
|
594
|
-
priorityUASTC: 1,
|
|
595
|
-
needsPowerOfTwo: false,
|
|
596
|
-
},
|
|
597
|
-
{
|
|
598
|
-
if: 'bptcSupported',
|
|
599
|
-
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
|
|
600
|
-
transcoderFormat: [ TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5 ],
|
|
601
|
-
engineFormat: [ EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format ],
|
|
602
|
-
priorityETC1S: 3,
|
|
603
|
-
priorityUASTC: 2,
|
|
604
|
-
needsPowerOfTwo: false,
|
|
605
|
-
},
|
|
606
|
-
{
|
|
607
|
-
if: 'dxtSupported',
|
|
608
|
-
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
|
|
609
|
-
transcoderFormat: [ TranscoderFormat.BC1, TranscoderFormat.BC3 ],
|
|
610
|
-
engineFormat: [ EngineFormat.RGB_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format ],
|
|
611
|
-
priorityETC1S: 4,
|
|
612
|
-
priorityUASTC: 5,
|
|
613
|
-
needsPowerOfTwo: false,
|
|
614
|
-
},
|
|
615
|
-
{
|
|
616
|
-
if: 'etc2Supported',
|
|
617
|
-
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
|
|
618
|
-
transcoderFormat: [ TranscoderFormat.ETC1, TranscoderFormat.ETC2 ],
|
|
619
|
-
engineFormat: [ EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format ],
|
|
620
|
-
priorityETC1S: 1,
|
|
621
|
-
priorityUASTC: 3,
|
|
622
|
-
needsPowerOfTwo: false,
|
|
623
|
-
},
|
|
624
|
-
{
|
|
625
|
-
if: 'etc1Supported',
|
|
626
|
-
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
|
|
627
|
-
transcoderFormat: [ TranscoderFormat.ETC1 ],
|
|
628
|
-
engineFormat: [ EngineFormat.RGB_ETC1_Format ],
|
|
629
|
-
priorityETC1S: 2,
|
|
630
|
-
priorityUASTC: 4,
|
|
631
|
-
needsPowerOfTwo: false,
|
|
632
|
-
},
|
|
633
|
-
{
|
|
634
|
-
if: 'pvrtcSupported',
|
|
635
|
-
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
|
|
636
|
-
transcoderFormat: [ TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA ],
|
|
637
|
-
engineFormat: [ EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format ],
|
|
638
|
-
priorityETC1S: 5,
|
|
639
|
-
priorityUASTC: 6,
|
|
640
|
-
needsPowerOfTwo: true,
|
|
641
|
-
},
|
|
642
|
-
];
|
|
643
|
-
|
|
644
|
-
const ETC1S_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) {
|
|
645
|
-
|
|
646
|
-
return a.priorityETC1S - b.priorityETC1S;
|
|
647
|
-
|
|
648
|
-
} );
|
|
649
|
-
const UASTC_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) {
|
|
650
|
-
|
|
651
|
-
return a.priorityUASTC - b.priorityUASTC;
|
|
652
|
-
|
|
653
|
-
} );
|
|
654
|
-
|
|
655
|
-
function getTranscoderFormat( basisFormat, width, height, hasAlpha ) {
|
|
656
|
-
|
|
657
|
-
let transcoderFormat;
|
|
658
|
-
let engineFormat;
|
|
659
|
-
|
|
660
|
-
const options = basisFormat === BasisFormat.ETC1S ? ETC1S_OPTIONS : UASTC_OPTIONS;
|
|
661
|
-
|
|
662
|
-
for ( let i = 0; i < options.length; i ++ ) {
|
|
663
|
-
|
|
664
|
-
const opt = options[ i ];
|
|
665
|
-
|
|
666
|
-
if ( ! config[ opt.if ] ) continue;
|
|
667
|
-
if ( ! opt.basisFormat.includes( basisFormat ) ) continue;
|
|
668
|
-
if ( hasAlpha && opt.transcoderFormat.length < 2 ) continue;
|
|
669
|
-
if ( opt.needsPowerOfTwo && ! ( isPowerOfTwo( width ) && isPowerOfTwo( height ) ) ) continue;
|
|
670
|
-
|
|
671
|
-
transcoderFormat = opt.transcoderFormat[ hasAlpha ? 1 : 0 ];
|
|
672
|
-
engineFormat = opt.engineFormat[ hasAlpha ? 1 : 0 ];
|
|
673
|
-
|
|
674
|
-
return { transcoderFormat, engineFormat };
|
|
675
|
-
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
console.warn( 'THREE.KTX2Loader: No suitable compressed texture format found. Decoding to RGBA32.' );
|
|
679
|
-
|
|
680
|
-
transcoderFormat = TranscoderFormat.RGBA32;
|
|
681
|
-
engineFormat = EngineFormat.RGBAFormat;
|
|
682
|
-
|
|
683
|
-
return { transcoderFormat, engineFormat };
|
|
684
|
-
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
function isPowerOfTwo( value ) {
|
|
688
|
-
|
|
689
|
-
if ( value <= 2 ) return true;
|
|
690
|
-
|
|
691
|
-
return ( value & ( value - 1 ) ) === 0 && value !== 0;
|
|
692
|
-
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
/** Concatenates N byte arrays. */
|
|
696
|
-
function concat( arrays ) {
|
|
697
|
-
|
|
698
|
-
if ( arrays.length === 1 ) return arrays[ 0 ];
|
|
699
|
-
|
|
700
|
-
let totalByteLength = 0;
|
|
701
|
-
|
|
702
|
-
for ( let i = 0; i < arrays.length; i ++ ) {
|
|
703
|
-
|
|
704
|
-
const array = arrays[ i ];
|
|
705
|
-
totalByteLength += array.byteLength;
|
|
706
|
-
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
const result = new Uint8Array( totalByteLength );
|
|
710
|
-
|
|
711
|
-
let byteOffset = 0;
|
|
712
|
-
|
|
713
|
-
for ( let i = 0; i < arrays.length; i ++ ) {
|
|
714
|
-
|
|
715
|
-
const array = arrays[ i ];
|
|
716
|
-
result.set( array, byteOffset );
|
|
717
|
-
|
|
718
|
-
byteOffset += array.byteLength;
|
|
719
|
-
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
return result;
|
|
723
|
-
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
};
|
|
727
|
-
|
|
728
|
-
//
|
|
729
|
-
// Parsing for non-Basis textures. These textures are may have supercompression
|
|
730
|
-
// like Zstd, but they do not require transcoding.
|
|
731
|
-
|
|
732
|
-
const UNCOMPRESSED_FORMATS = new Set( [ RGBAFormat, RGFormat, RedFormat ] );
|
|
733
|
-
|
|
734
|
-
const FORMAT_MAP = {
|
|
735
|
-
|
|
736
|
-
[ VK_FORMAT_R32G32B32A32_SFLOAT ]: RGBAFormat,
|
|
737
|
-
[ VK_FORMAT_R16G16B16A16_SFLOAT ]: RGBAFormat,
|
|
738
|
-
[ VK_FORMAT_R8G8B8A8_UNORM ]: RGBAFormat,
|
|
739
|
-
[ VK_FORMAT_R8G8B8A8_SRGB ]: RGBAFormat,
|
|
740
|
-
|
|
741
|
-
[ VK_FORMAT_R32G32_SFLOAT ]: RGFormat,
|
|
742
|
-
[ VK_FORMAT_R16G16_SFLOAT ]: RGFormat,
|
|
743
|
-
[ VK_FORMAT_R8G8_UNORM ]: RGFormat,
|
|
744
|
-
[ VK_FORMAT_R8G8_SRGB ]: RGFormat,
|
|
745
|
-
|
|
746
|
-
[ VK_FORMAT_R32_SFLOAT ]: RedFormat,
|
|
747
|
-
[ VK_FORMAT_R16_SFLOAT ]: RedFormat,
|
|
748
|
-
[ VK_FORMAT_R8_SRGB ]: RedFormat,
|
|
749
|
-
[ VK_FORMAT_R8_UNORM ]: RedFormat,
|
|
750
|
-
|
|
751
|
-
[ VK_FORMAT_ASTC_6x6_SRGB_BLOCK ]: RGBA_ASTC_6x6_Format,
|
|
752
|
-
[ VK_FORMAT_ASTC_6x6_UNORM_BLOCK ]: RGBA_ASTC_6x6_Format,
|
|
753
|
-
|
|
754
|
-
};
|
|
755
|
-
|
|
756
|
-
const TYPE_MAP = {
|
|
757
|
-
|
|
758
|
-
[ VK_FORMAT_R32G32B32A32_SFLOAT ]: FloatType,
|
|
759
|
-
[ VK_FORMAT_R16G16B16A16_SFLOAT ]: HalfFloatType,
|
|
760
|
-
[ VK_FORMAT_R8G8B8A8_UNORM ]: UnsignedByteType,
|
|
761
|
-
[ VK_FORMAT_R8G8B8A8_SRGB ]: UnsignedByteType,
|
|
762
|
-
|
|
763
|
-
[ VK_FORMAT_R32G32_SFLOAT ]: FloatType,
|
|
764
|
-
[ VK_FORMAT_R16G16_SFLOAT ]: HalfFloatType,
|
|
765
|
-
[ VK_FORMAT_R8G8_UNORM ]: UnsignedByteType,
|
|
766
|
-
[ VK_FORMAT_R8G8_SRGB ]: UnsignedByteType,
|
|
767
|
-
|
|
768
|
-
[ VK_FORMAT_R32_SFLOAT ]: FloatType,
|
|
769
|
-
[ VK_FORMAT_R16_SFLOAT ]: HalfFloatType,
|
|
770
|
-
[ VK_FORMAT_R8_SRGB ]: UnsignedByteType,
|
|
771
|
-
[ VK_FORMAT_R8_UNORM ]: UnsignedByteType,
|
|
772
|
-
|
|
773
|
-
[ VK_FORMAT_ASTC_6x6_SRGB_BLOCK ]: UnsignedByteType,
|
|
774
|
-
[ VK_FORMAT_ASTC_6x6_UNORM_BLOCK ]: UnsignedByteType,
|
|
775
|
-
|
|
776
|
-
};
|
|
777
|
-
|
|
778
|
-
async function createRawTexture( container ) {
|
|
779
|
-
|
|
780
|
-
const { vkFormat } = container;
|
|
781
|
-
|
|
782
|
-
if ( FORMAT_MAP[ vkFormat ] === undefined ) {
|
|
783
|
-
|
|
784
|
-
throw new Error( 'THREE.KTX2Loader: Unsupported vkFormat.' );
|
|
785
|
-
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
//
|
|
789
|
-
|
|
790
|
-
let zstd;
|
|
791
|
-
|
|
792
|
-
if ( container.supercompressionScheme === KHR_SUPERCOMPRESSION_ZSTD ) {
|
|
793
|
-
|
|
794
|
-
if ( ! _zstd ) {
|
|
795
|
-
|
|
796
|
-
_zstd = new Promise( async ( resolve ) => {
|
|
797
|
-
|
|
798
|
-
const zstd = new ZSTDDecoder();
|
|
799
|
-
await zstd.init();
|
|
800
|
-
resolve( zstd );
|
|
801
|
-
|
|
802
|
-
} );
|
|
803
|
-
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
zstd = await _zstd;
|
|
807
|
-
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
//
|
|
811
|
-
|
|
812
|
-
const mipmaps = [];
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
for ( let levelIndex = 0; levelIndex < container.levels.length; levelIndex ++ ) {
|
|
816
|
-
|
|
817
|
-
const levelWidth = Math.max( 1, container.pixelWidth >> levelIndex );
|
|
818
|
-
const levelHeight = Math.max( 1, container.pixelHeight >> levelIndex );
|
|
819
|
-
const levelDepth = container.pixelDepth ? Math.max( 1, container.pixelDepth >> levelIndex ) : 0;
|
|
820
|
-
|
|
821
|
-
const level = container.levels[ levelIndex ];
|
|
822
|
-
|
|
823
|
-
let levelData;
|
|
824
|
-
|
|
825
|
-
if ( container.supercompressionScheme === KHR_SUPERCOMPRESSION_NONE ) {
|
|
826
|
-
|
|
827
|
-
levelData = level.levelData;
|
|
828
|
-
|
|
829
|
-
} else if ( container.supercompressionScheme === KHR_SUPERCOMPRESSION_ZSTD ) {
|
|
830
|
-
|
|
831
|
-
levelData = zstd.decode( level.levelData, level.uncompressedByteLength );
|
|
832
|
-
|
|
833
|
-
} else {
|
|
834
|
-
|
|
835
|
-
throw new Error( 'THREE.KTX2Loader: Unsupported supercompressionScheme.' );
|
|
836
|
-
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
let data;
|
|
840
|
-
|
|
841
|
-
if ( TYPE_MAP[ vkFormat ] === FloatType ) {
|
|
842
|
-
|
|
843
|
-
data = new Float32Array(
|
|
844
|
-
|
|
845
|
-
levelData.buffer,
|
|
846
|
-
levelData.byteOffset,
|
|
847
|
-
levelData.byteLength / Float32Array.BYTES_PER_ELEMENT
|
|
848
|
-
|
|
849
|
-
);
|
|
850
|
-
|
|
851
|
-
} else if ( TYPE_MAP[ vkFormat ] === HalfFloatType ) {
|
|
852
|
-
|
|
853
|
-
data = new Uint16Array(
|
|
854
|
-
|
|
855
|
-
levelData.buffer,
|
|
856
|
-
levelData.byteOffset,
|
|
857
|
-
levelData.byteLength / Uint16Array.BYTES_PER_ELEMENT
|
|
858
|
-
|
|
859
|
-
);
|
|
860
|
-
|
|
861
|
-
} else {
|
|
862
|
-
|
|
863
|
-
data = levelData;
|
|
864
|
-
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
mipmaps.push( {
|
|
868
|
-
|
|
869
|
-
data: data,
|
|
870
|
-
width: levelWidth,
|
|
871
|
-
height: levelHeight,
|
|
872
|
-
depth: levelDepth,
|
|
873
|
-
|
|
874
|
-
} );
|
|
875
|
-
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
let texture;
|
|
879
|
-
|
|
880
|
-
if ( UNCOMPRESSED_FORMATS.has( FORMAT_MAP[ vkFormat ] ) ) {
|
|
881
|
-
|
|
882
|
-
texture = container.pixelDepth === 0
|
|
883
|
-
? new DataTexture( mipmaps[ 0 ].data, container.pixelWidth, container.pixelHeight )
|
|
884
|
-
: new Data3DTexture( mipmaps[ 0 ].data, container.pixelWidth, container.pixelHeight, container.pixelDepth );
|
|
885
|
-
|
|
886
|
-
} else {
|
|
887
|
-
|
|
888
|
-
if ( container.pixelDepth > 0 ) throw new Error( 'THREE.KTX2Loader: Unsupported pixelDepth.' );
|
|
889
|
-
|
|
890
|
-
texture = new CompressedTexture( mipmaps, container.pixelWidth, container.pixelHeight );
|
|
891
|
-
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
texture.mipmaps = mipmaps;
|
|
895
|
-
|
|
896
|
-
texture.type = TYPE_MAP[ vkFormat ];
|
|
897
|
-
texture.format = FORMAT_MAP[ vkFormat ];
|
|
898
|
-
texture.colorSpace = parseColorSpace( container );
|
|
899
|
-
texture.needsUpdate = true;
|
|
900
|
-
|
|
901
|
-
//
|
|
902
|
-
|
|
903
|
-
return Promise.resolve( texture );
|
|
904
|
-
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
function parseColorSpace( container ) {
|
|
908
|
-
|
|
909
|
-
const dfd = container.dataFormatDescriptor[ 0 ];
|
|
910
|
-
|
|
911
|
-
if ( dfd.colorPrimaries === KHR_DF_PRIMARIES_BT709 ) {
|
|
912
|
-
|
|
913
|
-
return dfd.transferFunction === KHR_DF_TRANSFER_SRGB ? SRGBColorSpace : LinearSRGBColorSpace;
|
|
914
|
-
|
|
915
|
-
} else if ( dfd.colorPrimaries === KHR_DF_PRIMARIES_DISPLAYP3 ) {
|
|
916
|
-
|
|
917
|
-
return dfd.transferFunction === KHR_DF_TRANSFER_SRGB ? DisplayP3ColorSpace : LinearDisplayP3ColorSpace;
|
|
918
|
-
|
|
919
|
-
} else if ( dfd.colorPrimaries === KHR_DF_PRIMARIES_UNSPECIFIED ) {
|
|
920
|
-
|
|
921
|
-
return NoColorSpace;
|
|
922
|
-
|
|
923
|
-
} else {
|
|
924
|
-
|
|
925
|
-
console.warn( `THREE.KTX2Loader: Unsupported color primaries, "${ dfd.colorPrimaries }"` );
|
|
926
|
-
return NoColorSpace;
|
|
927
|
-
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
export { KTX2Loader };
|
|
1
|
+
/**
|
|
2
|
+
* Loader for KTX 2.0 GPU Texture containers.
|
|
3
|
+
*
|
|
4
|
+
* KTX 2.0 is a container format for various GPU texture formats. The loader
|
|
5
|
+
* supports Basis Universal GPU textures, which can be quickly transcoded to
|
|
6
|
+
* a wide variety of GPU texture compression formats, as well as some
|
|
7
|
+
* uncompressed DataTexture and Data3DTexture formats.
|
|
8
|
+
*
|
|
9
|
+
* References:
|
|
10
|
+
* - KTX: http://github.khronos.org/KTX-Specification/
|
|
11
|
+
* - DFD: https://www.khronos.org/registry/DataFormat/specs/1.3/dataformat.1.3.html#basicdescriptor
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
CompressedTexture,
|
|
16
|
+
CompressedArrayTexture,
|
|
17
|
+
CompressedCubeTexture,
|
|
18
|
+
Data3DTexture,
|
|
19
|
+
DataTexture,
|
|
20
|
+
DisplayP3ColorSpace,
|
|
21
|
+
FileLoader,
|
|
22
|
+
FloatType,
|
|
23
|
+
HalfFloatType,
|
|
24
|
+
NoColorSpace,
|
|
25
|
+
LinearFilter,
|
|
26
|
+
LinearMipmapLinearFilter,
|
|
27
|
+
LinearDisplayP3ColorSpace,
|
|
28
|
+
LinearSRGBColorSpace,
|
|
29
|
+
Loader,
|
|
30
|
+
RedFormat,
|
|
31
|
+
RGB_ETC1_Format,
|
|
32
|
+
RGB_ETC2_Format,
|
|
33
|
+
RGB_PVRTC_4BPPV1_Format,
|
|
34
|
+
RGB_S3TC_DXT1_Format,
|
|
35
|
+
RGBA_ASTC_4x4_Format,
|
|
36
|
+
RGBA_ASTC_6x6_Format,
|
|
37
|
+
RGBA_BPTC_Format,
|
|
38
|
+
RGBA_ETC2_EAC_Format,
|
|
39
|
+
RGBA_PVRTC_4BPPV1_Format,
|
|
40
|
+
RGBA_S3TC_DXT5_Format,
|
|
41
|
+
RGBAFormat,
|
|
42
|
+
RGFormat,
|
|
43
|
+
SRGBColorSpace,
|
|
44
|
+
UnsignedByteType,
|
|
45
|
+
} from 'three';
|
|
46
|
+
import { WorkerPool } from '../utils/WorkerPool.js';
|
|
47
|
+
import {
|
|
48
|
+
read,
|
|
49
|
+
KHR_DF_FLAG_ALPHA_PREMULTIPLIED,
|
|
50
|
+
KHR_DF_TRANSFER_SRGB,
|
|
51
|
+
KHR_SUPERCOMPRESSION_NONE,
|
|
52
|
+
KHR_SUPERCOMPRESSION_ZSTD,
|
|
53
|
+
VK_FORMAT_UNDEFINED,
|
|
54
|
+
VK_FORMAT_R16_SFLOAT,
|
|
55
|
+
VK_FORMAT_R16G16_SFLOAT,
|
|
56
|
+
VK_FORMAT_R16G16B16A16_SFLOAT,
|
|
57
|
+
VK_FORMAT_R32_SFLOAT,
|
|
58
|
+
VK_FORMAT_R32G32_SFLOAT,
|
|
59
|
+
VK_FORMAT_R32G32B32A32_SFLOAT,
|
|
60
|
+
VK_FORMAT_R8_SRGB,
|
|
61
|
+
VK_FORMAT_R8_UNORM,
|
|
62
|
+
VK_FORMAT_R8G8_SRGB,
|
|
63
|
+
VK_FORMAT_R8G8_UNORM,
|
|
64
|
+
VK_FORMAT_R8G8B8A8_SRGB,
|
|
65
|
+
VK_FORMAT_R8G8B8A8_UNORM,
|
|
66
|
+
VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
|
|
67
|
+
VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
|
|
68
|
+
KHR_DF_PRIMARIES_UNSPECIFIED,
|
|
69
|
+
KHR_DF_PRIMARIES_BT709,
|
|
70
|
+
KHR_DF_PRIMARIES_DISPLAYP3
|
|
71
|
+
} from '../libs/ktx-parse.module.js';
|
|
72
|
+
import { ZSTDDecoder } from '../libs/zstddec.module.js';
|
|
73
|
+
|
|
74
|
+
const _taskCache = new WeakMap();
|
|
75
|
+
|
|
76
|
+
let _activeLoaders = 0;
|
|
77
|
+
|
|
78
|
+
let _zstd;
|
|
79
|
+
|
|
80
|
+
class KTX2Loader extends Loader {
|
|
81
|
+
|
|
82
|
+
constructor( manager ) {
|
|
83
|
+
|
|
84
|
+
super( manager );
|
|
85
|
+
|
|
86
|
+
this.transcoderPath = '';
|
|
87
|
+
this.transcoderBinary = null;
|
|
88
|
+
this.transcoderPending = null;
|
|
89
|
+
|
|
90
|
+
this.workerPool = new WorkerPool();
|
|
91
|
+
this.workerSourceURL = '';
|
|
92
|
+
this.workerConfig = null;
|
|
93
|
+
|
|
94
|
+
if ( typeof MSC_TRANSCODER !== 'undefined' ) {
|
|
95
|
+
|
|
96
|
+
console.warn(
|
|
97
|
+
|
|
98
|
+
'THREE.KTX2Loader: Please update to latest "basis_transcoder".'
|
|
99
|
+
+ ' "msc_basis_transcoder" is no longer supported in three.js r125+.'
|
|
100
|
+
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
setTranscoderPath( path ) {
|
|
108
|
+
|
|
109
|
+
this.transcoderPath = path;
|
|
110
|
+
|
|
111
|
+
return this;
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
setWorkerLimit( num ) {
|
|
116
|
+
|
|
117
|
+
this.workerPool.setWorkerLimit( num );
|
|
118
|
+
|
|
119
|
+
return this;
|
|
120
|
+
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async detectSupportAsync( renderer ) {
|
|
124
|
+
|
|
125
|
+
this.workerConfig = {
|
|
126
|
+
astcSupported: await renderer.hasFeatureAsync( 'texture-compression-astc' ),
|
|
127
|
+
etc1Supported: await renderer.hasFeatureAsync( 'texture-compression-etc1' ),
|
|
128
|
+
etc2Supported: await renderer.hasFeatureAsync( 'texture-compression-etc2' ),
|
|
129
|
+
dxtSupported: await renderer.hasFeatureAsync( 'texture-compression-bc' ),
|
|
130
|
+
bptcSupported: await renderer.hasFeatureAsync( 'texture-compression-bptc' ),
|
|
131
|
+
pvrtcSupported: await renderer.hasFeatureAsync( 'texture-compression-pvrtc' )
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
return this;
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
detectSupport( renderer ) {
|
|
139
|
+
|
|
140
|
+
if ( renderer.isWebGPURenderer === true ) {
|
|
141
|
+
|
|
142
|
+
this.workerConfig = {
|
|
143
|
+
astcSupported: renderer.hasFeature( 'texture-compression-astc' ),
|
|
144
|
+
etc1Supported: renderer.hasFeature( 'texture-compression-etc1' ),
|
|
145
|
+
etc2Supported: renderer.hasFeature( 'texture-compression-etc2' ),
|
|
146
|
+
dxtSupported: renderer.hasFeature( 'texture-compression-bc' ),
|
|
147
|
+
bptcSupported: renderer.hasFeature( 'texture-compression-bptc' ),
|
|
148
|
+
pvrtcSupported: renderer.hasFeature( 'texture-compression-pvrtc' )
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
} else {
|
|
152
|
+
|
|
153
|
+
this.workerConfig = {
|
|
154
|
+
astcSupported: renderer.extensions.has( 'WEBGL_compressed_texture_astc' ),
|
|
155
|
+
etc1Supported: renderer.extensions.has( 'WEBGL_compressed_texture_etc1' ),
|
|
156
|
+
etc2Supported: renderer.extensions.has( 'WEBGL_compressed_texture_etc' ),
|
|
157
|
+
dxtSupported: renderer.extensions.has( 'WEBGL_compressed_texture_s3tc' ),
|
|
158
|
+
bptcSupported: renderer.extensions.has( 'EXT_texture_compression_bptc' ),
|
|
159
|
+
pvrtcSupported: renderer.extensions.has( 'WEBGL_compressed_texture_pvrtc' )
|
|
160
|
+
|| renderer.extensions.has( 'WEBKIT_WEBGL_compressed_texture_pvrtc' )
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
if ( renderer.capabilities.isWebGL2 ) {
|
|
164
|
+
|
|
165
|
+
// https://github.com/mrdoob/three.js/pull/22928
|
|
166
|
+
this.workerConfig.etc1Supported = false;
|
|
167
|
+
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return this;
|
|
173
|
+
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
init() {
|
|
177
|
+
|
|
178
|
+
if ( ! this.transcoderPending ) {
|
|
179
|
+
|
|
180
|
+
// Load transcoder wrapper.
|
|
181
|
+
const jsLoader = new FileLoader( this.manager );
|
|
182
|
+
jsLoader.setPath( this.transcoderPath );
|
|
183
|
+
jsLoader.setWithCredentials( this.withCredentials );
|
|
184
|
+
const jsContent = jsLoader.loadAsync( 'basis_transcoder.js' );
|
|
185
|
+
|
|
186
|
+
// Load transcoder WASM binary.
|
|
187
|
+
const binaryLoader = new FileLoader( this.manager );
|
|
188
|
+
binaryLoader.setPath( this.transcoderPath );
|
|
189
|
+
binaryLoader.setResponseType( 'arraybuffer' );
|
|
190
|
+
binaryLoader.setWithCredentials( this.withCredentials );
|
|
191
|
+
const binaryContent = binaryLoader.loadAsync( 'basis_transcoder.wasm' );
|
|
192
|
+
|
|
193
|
+
this.transcoderPending = Promise.all( [ jsContent, binaryContent ] )
|
|
194
|
+
.then( ( [ jsContent, binaryContent ] ) => {
|
|
195
|
+
|
|
196
|
+
const fn = KTX2Loader.BasisWorker.toString();
|
|
197
|
+
|
|
198
|
+
const body = [
|
|
199
|
+
'/* constants */',
|
|
200
|
+
'let _EngineFormat = ' + JSON.stringify( KTX2Loader.EngineFormat ),
|
|
201
|
+
'let _TranscoderFormat = ' + JSON.stringify( KTX2Loader.TranscoderFormat ),
|
|
202
|
+
'let _BasisFormat = ' + JSON.stringify( KTX2Loader.BasisFormat ),
|
|
203
|
+
'/* basis_transcoder.js */',
|
|
204
|
+
jsContent,
|
|
205
|
+
'/* worker */',
|
|
206
|
+
fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) )
|
|
207
|
+
].join( '\n' );
|
|
208
|
+
|
|
209
|
+
this.workerSourceURL = URL.createObjectURL( new Blob( [ body ] ) );
|
|
210
|
+
this.transcoderBinary = binaryContent;
|
|
211
|
+
|
|
212
|
+
this.workerPool.setWorkerCreator( () => {
|
|
213
|
+
|
|
214
|
+
const worker = new Worker( this.workerSourceURL );
|
|
215
|
+
const transcoderBinary = this.transcoderBinary.slice( 0 );
|
|
216
|
+
|
|
217
|
+
worker.postMessage( { type: 'init', config: this.workerConfig, transcoderBinary }, [ transcoderBinary ] );
|
|
218
|
+
|
|
219
|
+
return worker;
|
|
220
|
+
|
|
221
|
+
} );
|
|
222
|
+
|
|
223
|
+
} );
|
|
224
|
+
|
|
225
|
+
if ( _activeLoaders > 0 ) {
|
|
226
|
+
|
|
227
|
+
// Each instance loads a transcoder and allocates workers, increasing network and memory cost.
|
|
228
|
+
|
|
229
|
+
console.warn(
|
|
230
|
+
|
|
231
|
+
'THREE.KTX2Loader: Multiple active KTX2 loaders may cause performance issues.'
|
|
232
|
+
+ ' Use a single KTX2Loader instance, or call .dispose() on old instances.'
|
|
233
|
+
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
_activeLoaders ++;
|
|
239
|
+
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return this.transcoderPending;
|
|
243
|
+
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
load( url, onLoad, onProgress, onError ) {
|
|
247
|
+
|
|
248
|
+
if ( this.workerConfig === null ) {
|
|
249
|
+
|
|
250
|
+
throw new Error( 'THREE.KTX2Loader: Missing initialization with `.detectSupport( renderer )`.' );
|
|
251
|
+
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const loader = new FileLoader( this.manager );
|
|
255
|
+
|
|
256
|
+
loader.setResponseType( 'arraybuffer' );
|
|
257
|
+
loader.setWithCredentials( this.withCredentials );
|
|
258
|
+
|
|
259
|
+
loader.load( url, ( buffer ) => {
|
|
260
|
+
|
|
261
|
+
// Check for an existing task using this buffer. A transferred buffer cannot be transferred
|
|
262
|
+
// again from this thread.
|
|
263
|
+
if ( _taskCache.has( buffer ) ) {
|
|
264
|
+
|
|
265
|
+
const cachedTask = _taskCache.get( buffer );
|
|
266
|
+
|
|
267
|
+
return cachedTask.promise.then( onLoad ).catch( onError );
|
|
268
|
+
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
this._createTexture( buffer )
|
|
272
|
+
.then( ( texture ) => onLoad ? onLoad( texture ) : null )
|
|
273
|
+
.catch( onError );
|
|
274
|
+
|
|
275
|
+
}, onProgress, onError );
|
|
276
|
+
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
_createTextureFrom( transcodeResult, container ) {
|
|
280
|
+
|
|
281
|
+
const { faces, width, height, format, type, error, dfdFlags } = transcodeResult;
|
|
282
|
+
|
|
283
|
+
if ( type === 'error' ) return Promise.reject( error );
|
|
284
|
+
|
|
285
|
+
let texture;
|
|
286
|
+
|
|
287
|
+
if ( container.faceCount === 6 ) {
|
|
288
|
+
|
|
289
|
+
texture = new CompressedCubeTexture( faces, format, UnsignedByteType );
|
|
290
|
+
|
|
291
|
+
} else {
|
|
292
|
+
|
|
293
|
+
const mipmaps = faces[ 0 ].mipmaps;
|
|
294
|
+
|
|
295
|
+
texture = container.layerCount > 1
|
|
296
|
+
? new CompressedArrayTexture( mipmaps, width, height, container.layerCount, format, UnsignedByteType )
|
|
297
|
+
: new CompressedTexture( mipmaps, width, height, format, UnsignedByteType );
|
|
298
|
+
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
texture.minFilter = faces[ 0 ].mipmaps.length === 1 ? LinearFilter : LinearMipmapLinearFilter;
|
|
302
|
+
texture.magFilter = LinearFilter;
|
|
303
|
+
texture.generateMipmaps = false;
|
|
304
|
+
|
|
305
|
+
texture.needsUpdate = true;
|
|
306
|
+
texture.colorSpace = parseColorSpace( container );
|
|
307
|
+
texture.premultiplyAlpha = !! ( dfdFlags & KHR_DF_FLAG_ALPHA_PREMULTIPLIED );
|
|
308
|
+
|
|
309
|
+
return texture;
|
|
310
|
+
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* @param {ArrayBuffer} buffer
|
|
315
|
+
* @param {object?} config
|
|
316
|
+
* @return {Promise<CompressedTexture|CompressedArrayTexture|DataTexture|Data3DTexture>}
|
|
317
|
+
*/
|
|
318
|
+
async _createTexture( buffer, config = {} ) {
|
|
319
|
+
|
|
320
|
+
const container = read( new Uint8Array( buffer ) );
|
|
321
|
+
|
|
322
|
+
if ( container.vkFormat !== VK_FORMAT_UNDEFINED ) {
|
|
323
|
+
|
|
324
|
+
return createRawTexture( container );
|
|
325
|
+
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
//
|
|
329
|
+
const taskConfig = config;
|
|
330
|
+
const texturePending = this.init().then( () => {
|
|
331
|
+
|
|
332
|
+
return this.workerPool.postMessage( { type: 'transcode', buffer, taskConfig: taskConfig }, [ buffer ] );
|
|
333
|
+
|
|
334
|
+
} ).then( ( e ) => this._createTextureFrom( e.data, container ) );
|
|
335
|
+
|
|
336
|
+
// Cache the task result.
|
|
337
|
+
_taskCache.set( buffer, { promise: texturePending } );
|
|
338
|
+
|
|
339
|
+
return texturePending;
|
|
340
|
+
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
dispose() {
|
|
344
|
+
|
|
345
|
+
this.workerPool.dispose();
|
|
346
|
+
if ( this.workerSourceURL ) URL.revokeObjectURL( this.workerSourceURL );
|
|
347
|
+
|
|
348
|
+
_activeLoaders --;
|
|
349
|
+
|
|
350
|
+
return this;
|
|
351
|
+
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
/* CONSTANTS */
|
|
358
|
+
|
|
359
|
+
KTX2Loader.BasisFormat = {
|
|
360
|
+
ETC1S: 0,
|
|
361
|
+
UASTC_4x4: 1,
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
KTX2Loader.TranscoderFormat = {
|
|
365
|
+
ETC1: 0,
|
|
366
|
+
ETC2: 1,
|
|
367
|
+
BC1: 2,
|
|
368
|
+
BC3: 3,
|
|
369
|
+
BC4: 4,
|
|
370
|
+
BC5: 5,
|
|
371
|
+
BC7_M6_OPAQUE_ONLY: 6,
|
|
372
|
+
BC7_M5: 7,
|
|
373
|
+
PVRTC1_4_RGB: 8,
|
|
374
|
+
PVRTC1_4_RGBA: 9,
|
|
375
|
+
ASTC_4x4: 10,
|
|
376
|
+
ATC_RGB: 11,
|
|
377
|
+
ATC_RGBA_INTERPOLATED_ALPHA: 12,
|
|
378
|
+
RGBA32: 13,
|
|
379
|
+
RGB565: 14,
|
|
380
|
+
BGR565: 15,
|
|
381
|
+
RGBA4444: 16,
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
KTX2Loader.EngineFormat = {
|
|
385
|
+
RGBAFormat: RGBAFormat,
|
|
386
|
+
RGBA_ASTC_4x4_Format: RGBA_ASTC_4x4_Format,
|
|
387
|
+
RGBA_BPTC_Format: RGBA_BPTC_Format,
|
|
388
|
+
RGBA_ETC2_EAC_Format: RGBA_ETC2_EAC_Format,
|
|
389
|
+
RGBA_PVRTC_4BPPV1_Format: RGBA_PVRTC_4BPPV1_Format,
|
|
390
|
+
RGBA_S3TC_DXT5_Format: RGBA_S3TC_DXT5_Format,
|
|
391
|
+
RGB_ETC1_Format: RGB_ETC1_Format,
|
|
392
|
+
RGB_ETC2_Format: RGB_ETC2_Format,
|
|
393
|
+
RGB_PVRTC_4BPPV1_Format: RGB_PVRTC_4BPPV1_Format,
|
|
394
|
+
RGB_S3TC_DXT1_Format: RGB_S3TC_DXT1_Format,
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
/* WEB WORKER */
|
|
399
|
+
|
|
400
|
+
KTX2Loader.BasisWorker = function () {
|
|
401
|
+
|
|
402
|
+
let config;
|
|
403
|
+
let transcoderPending;
|
|
404
|
+
let BasisModule;
|
|
405
|
+
|
|
406
|
+
const EngineFormat = _EngineFormat; // eslint-disable-line no-undef
|
|
407
|
+
const TranscoderFormat = _TranscoderFormat; // eslint-disable-line no-undef
|
|
408
|
+
const BasisFormat = _BasisFormat; // eslint-disable-line no-undef
|
|
409
|
+
|
|
410
|
+
self.addEventListener( 'message', function ( e ) {
|
|
411
|
+
|
|
412
|
+
const message = e.data;
|
|
413
|
+
|
|
414
|
+
switch ( message.type ) {
|
|
415
|
+
|
|
416
|
+
case 'init':
|
|
417
|
+
config = message.config;
|
|
418
|
+
init( message.transcoderBinary );
|
|
419
|
+
break;
|
|
420
|
+
|
|
421
|
+
case 'transcode':
|
|
422
|
+
transcoderPending.then( () => {
|
|
423
|
+
|
|
424
|
+
try {
|
|
425
|
+
|
|
426
|
+
const { faces, buffers, width, height, hasAlpha, format, dfdFlags } = transcode( message.buffer );
|
|
427
|
+
|
|
428
|
+
self.postMessage( { type: 'transcode', id: message.id, faces, width, height, hasAlpha, format, dfdFlags }, buffers );
|
|
429
|
+
|
|
430
|
+
} catch ( error ) {
|
|
431
|
+
|
|
432
|
+
console.error( error );
|
|
433
|
+
|
|
434
|
+
self.postMessage( { type: 'error', id: message.id, error: error.message } );
|
|
435
|
+
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
} );
|
|
439
|
+
break;
|
|
440
|
+
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
} );
|
|
444
|
+
|
|
445
|
+
function init( wasmBinary ) {
|
|
446
|
+
|
|
447
|
+
transcoderPending = new Promise( ( resolve ) => {
|
|
448
|
+
|
|
449
|
+
BasisModule = { wasmBinary, onRuntimeInitialized: resolve };
|
|
450
|
+
BASIS( BasisModule ); // eslint-disable-line no-undef
|
|
451
|
+
|
|
452
|
+
} ).then( () => {
|
|
453
|
+
|
|
454
|
+
BasisModule.initializeBasis();
|
|
455
|
+
|
|
456
|
+
if ( BasisModule.KTX2File === undefined ) {
|
|
457
|
+
|
|
458
|
+
console.warn( 'THREE.KTX2Loader: Please update Basis Universal transcoder.' );
|
|
459
|
+
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
} );
|
|
463
|
+
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function transcode( buffer ) {
|
|
467
|
+
|
|
468
|
+
const ktx2File = new BasisModule.KTX2File( new Uint8Array( buffer ) );
|
|
469
|
+
|
|
470
|
+
function cleanup() {
|
|
471
|
+
|
|
472
|
+
ktx2File.close();
|
|
473
|
+
ktx2File.delete();
|
|
474
|
+
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
if ( ! ktx2File.isValid() ) {
|
|
478
|
+
|
|
479
|
+
cleanup();
|
|
480
|
+
throw new Error( 'THREE.KTX2Loader: Invalid or unsupported .ktx2 file' );
|
|
481
|
+
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
const basisFormat = ktx2File.isUASTC() ? BasisFormat.UASTC_4x4 : BasisFormat.ETC1S;
|
|
485
|
+
const width = ktx2File.getWidth();
|
|
486
|
+
const height = ktx2File.getHeight();
|
|
487
|
+
const layerCount = ktx2File.getLayers() || 1;
|
|
488
|
+
const levelCount = ktx2File.getLevels();
|
|
489
|
+
const faceCount = ktx2File.getFaces();
|
|
490
|
+
const hasAlpha = ktx2File.getHasAlpha();
|
|
491
|
+
const dfdFlags = ktx2File.getDFDFlags();
|
|
492
|
+
|
|
493
|
+
const { transcoderFormat, engineFormat } = getTranscoderFormat( basisFormat, width, height, hasAlpha );
|
|
494
|
+
|
|
495
|
+
if ( ! width || ! height || ! levelCount ) {
|
|
496
|
+
|
|
497
|
+
cleanup();
|
|
498
|
+
throw new Error( 'THREE.KTX2Loader: Invalid texture' );
|
|
499
|
+
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if ( ! ktx2File.startTranscoding() ) {
|
|
503
|
+
|
|
504
|
+
cleanup();
|
|
505
|
+
throw new Error( 'THREE.KTX2Loader: .startTranscoding failed' );
|
|
506
|
+
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
const faces = [];
|
|
510
|
+
const buffers = [];
|
|
511
|
+
|
|
512
|
+
for ( let face = 0; face < faceCount; face ++ ) {
|
|
513
|
+
|
|
514
|
+
const mipmaps = [];
|
|
515
|
+
|
|
516
|
+
for ( let mip = 0; mip < levelCount; mip ++ ) {
|
|
517
|
+
|
|
518
|
+
const layerMips = [];
|
|
519
|
+
|
|
520
|
+
let mipWidth, mipHeight;
|
|
521
|
+
|
|
522
|
+
for ( let layer = 0; layer < layerCount; layer ++ ) {
|
|
523
|
+
|
|
524
|
+
const levelInfo = ktx2File.getImageLevelInfo( mip, layer, face );
|
|
525
|
+
|
|
526
|
+
if ( face === 0 && mip === 0 && layer === 0 && ( levelInfo.origWidth % 4 !== 0 || levelInfo.origHeight % 4 !== 0 ) ) {
|
|
527
|
+
|
|
528
|
+
console.warn( 'THREE.KTX2Loader: ETC1S and UASTC textures should use multiple-of-four dimensions.' );
|
|
529
|
+
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
if ( levelCount > 1 ) {
|
|
533
|
+
|
|
534
|
+
mipWidth = levelInfo.origWidth;
|
|
535
|
+
mipHeight = levelInfo.origHeight;
|
|
536
|
+
|
|
537
|
+
} else {
|
|
538
|
+
|
|
539
|
+
// Handles non-multiple-of-four dimensions in textures without mipmaps. Textures with
|
|
540
|
+
// mipmaps must use multiple-of-four dimensions, for some texture formats and APIs.
|
|
541
|
+
// See mrdoob/three.js#25908.
|
|
542
|
+
mipWidth = levelInfo.width;
|
|
543
|
+
mipHeight = levelInfo.height;
|
|
544
|
+
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
const dst = new Uint8Array( ktx2File.getImageTranscodedSizeInBytes( mip, layer, 0, transcoderFormat ) );
|
|
548
|
+
const status = ktx2File.transcodeImage( dst, mip, layer, face, transcoderFormat, 0, - 1, - 1 );
|
|
549
|
+
|
|
550
|
+
if ( ! status ) {
|
|
551
|
+
|
|
552
|
+
cleanup();
|
|
553
|
+
throw new Error( 'THREE.KTX2Loader: .transcodeImage failed.' );
|
|
554
|
+
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
layerMips.push( dst );
|
|
558
|
+
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
const mipData = concat( layerMips );
|
|
562
|
+
|
|
563
|
+
mipmaps.push( { data: mipData, width: mipWidth, height: mipHeight } );
|
|
564
|
+
buffers.push( mipData.buffer );
|
|
565
|
+
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
faces.push( { mipmaps, width, height, format: engineFormat } );
|
|
569
|
+
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
cleanup();
|
|
573
|
+
|
|
574
|
+
return { faces, buffers, width, height, hasAlpha, format: engineFormat, dfdFlags };
|
|
575
|
+
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
//
|
|
579
|
+
|
|
580
|
+
// Optimal choice of a transcoder target format depends on the Basis format (ETC1S or UASTC),
|
|
581
|
+
// device capabilities, and texture dimensions. The list below ranks the formats separately
|
|
582
|
+
// for ETC1S and UASTC.
|
|
583
|
+
//
|
|
584
|
+
// In some cases, transcoding UASTC to RGBA32 might be preferred for higher quality (at
|
|
585
|
+
// significant memory cost) compared to ETC1/2, BC1/3, and PVRTC. The transcoder currently
|
|
586
|
+
// chooses RGBA32 only as a last resort and does not expose that option to the caller.
|
|
587
|
+
const FORMAT_OPTIONS = [
|
|
588
|
+
{
|
|
589
|
+
if: 'astcSupported',
|
|
590
|
+
basisFormat: [ BasisFormat.UASTC_4x4 ],
|
|
591
|
+
transcoderFormat: [ TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4 ],
|
|
592
|
+
engineFormat: [ EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format ],
|
|
593
|
+
priorityETC1S: Infinity,
|
|
594
|
+
priorityUASTC: 1,
|
|
595
|
+
needsPowerOfTwo: false,
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
if: 'bptcSupported',
|
|
599
|
+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
|
|
600
|
+
transcoderFormat: [ TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5 ],
|
|
601
|
+
engineFormat: [ EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format ],
|
|
602
|
+
priorityETC1S: 3,
|
|
603
|
+
priorityUASTC: 2,
|
|
604
|
+
needsPowerOfTwo: false,
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
if: 'dxtSupported',
|
|
608
|
+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
|
|
609
|
+
transcoderFormat: [ TranscoderFormat.BC1, TranscoderFormat.BC3 ],
|
|
610
|
+
engineFormat: [ EngineFormat.RGB_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format ],
|
|
611
|
+
priorityETC1S: 4,
|
|
612
|
+
priorityUASTC: 5,
|
|
613
|
+
needsPowerOfTwo: false,
|
|
614
|
+
},
|
|
615
|
+
{
|
|
616
|
+
if: 'etc2Supported',
|
|
617
|
+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
|
|
618
|
+
transcoderFormat: [ TranscoderFormat.ETC1, TranscoderFormat.ETC2 ],
|
|
619
|
+
engineFormat: [ EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format ],
|
|
620
|
+
priorityETC1S: 1,
|
|
621
|
+
priorityUASTC: 3,
|
|
622
|
+
needsPowerOfTwo: false,
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
if: 'etc1Supported',
|
|
626
|
+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
|
|
627
|
+
transcoderFormat: [ TranscoderFormat.ETC1 ],
|
|
628
|
+
engineFormat: [ EngineFormat.RGB_ETC1_Format ],
|
|
629
|
+
priorityETC1S: 2,
|
|
630
|
+
priorityUASTC: 4,
|
|
631
|
+
needsPowerOfTwo: false,
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
if: 'pvrtcSupported',
|
|
635
|
+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
|
|
636
|
+
transcoderFormat: [ TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA ],
|
|
637
|
+
engineFormat: [ EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format ],
|
|
638
|
+
priorityETC1S: 5,
|
|
639
|
+
priorityUASTC: 6,
|
|
640
|
+
needsPowerOfTwo: true,
|
|
641
|
+
},
|
|
642
|
+
];
|
|
643
|
+
|
|
644
|
+
const ETC1S_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) {
|
|
645
|
+
|
|
646
|
+
return a.priorityETC1S - b.priorityETC1S;
|
|
647
|
+
|
|
648
|
+
} );
|
|
649
|
+
const UASTC_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) {
|
|
650
|
+
|
|
651
|
+
return a.priorityUASTC - b.priorityUASTC;
|
|
652
|
+
|
|
653
|
+
} );
|
|
654
|
+
|
|
655
|
+
function getTranscoderFormat( basisFormat, width, height, hasAlpha ) {
|
|
656
|
+
|
|
657
|
+
let transcoderFormat;
|
|
658
|
+
let engineFormat;
|
|
659
|
+
|
|
660
|
+
const options = basisFormat === BasisFormat.ETC1S ? ETC1S_OPTIONS : UASTC_OPTIONS;
|
|
661
|
+
|
|
662
|
+
for ( let i = 0; i < options.length; i ++ ) {
|
|
663
|
+
|
|
664
|
+
const opt = options[ i ];
|
|
665
|
+
|
|
666
|
+
if ( ! config[ opt.if ] ) continue;
|
|
667
|
+
if ( ! opt.basisFormat.includes( basisFormat ) ) continue;
|
|
668
|
+
if ( hasAlpha && opt.transcoderFormat.length < 2 ) continue;
|
|
669
|
+
if ( opt.needsPowerOfTwo && ! ( isPowerOfTwo( width ) && isPowerOfTwo( height ) ) ) continue;
|
|
670
|
+
|
|
671
|
+
transcoderFormat = opt.transcoderFormat[ hasAlpha ? 1 : 0 ];
|
|
672
|
+
engineFormat = opt.engineFormat[ hasAlpha ? 1 : 0 ];
|
|
673
|
+
|
|
674
|
+
return { transcoderFormat, engineFormat };
|
|
675
|
+
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
console.warn( 'THREE.KTX2Loader: No suitable compressed texture format found. Decoding to RGBA32.' );
|
|
679
|
+
|
|
680
|
+
transcoderFormat = TranscoderFormat.RGBA32;
|
|
681
|
+
engineFormat = EngineFormat.RGBAFormat;
|
|
682
|
+
|
|
683
|
+
return { transcoderFormat, engineFormat };
|
|
684
|
+
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
function isPowerOfTwo( value ) {
|
|
688
|
+
|
|
689
|
+
if ( value <= 2 ) return true;
|
|
690
|
+
|
|
691
|
+
return ( value & ( value - 1 ) ) === 0 && value !== 0;
|
|
692
|
+
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/** Concatenates N byte arrays. */
|
|
696
|
+
function concat( arrays ) {
|
|
697
|
+
|
|
698
|
+
if ( arrays.length === 1 ) return arrays[ 0 ];
|
|
699
|
+
|
|
700
|
+
let totalByteLength = 0;
|
|
701
|
+
|
|
702
|
+
for ( let i = 0; i < arrays.length; i ++ ) {
|
|
703
|
+
|
|
704
|
+
const array = arrays[ i ];
|
|
705
|
+
totalByteLength += array.byteLength;
|
|
706
|
+
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
const result = new Uint8Array( totalByteLength );
|
|
710
|
+
|
|
711
|
+
let byteOffset = 0;
|
|
712
|
+
|
|
713
|
+
for ( let i = 0; i < arrays.length; i ++ ) {
|
|
714
|
+
|
|
715
|
+
const array = arrays[ i ];
|
|
716
|
+
result.set( array, byteOffset );
|
|
717
|
+
|
|
718
|
+
byteOffset += array.byteLength;
|
|
719
|
+
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
return result;
|
|
723
|
+
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
//
|
|
729
|
+
// Parsing for non-Basis textures. These textures are may have supercompression
|
|
730
|
+
// like Zstd, but they do not require transcoding.
|
|
731
|
+
|
|
732
|
+
const UNCOMPRESSED_FORMATS = new Set( [ RGBAFormat, RGFormat, RedFormat ] );
|
|
733
|
+
|
|
734
|
+
const FORMAT_MAP = {
|
|
735
|
+
|
|
736
|
+
[ VK_FORMAT_R32G32B32A32_SFLOAT ]: RGBAFormat,
|
|
737
|
+
[ VK_FORMAT_R16G16B16A16_SFLOAT ]: RGBAFormat,
|
|
738
|
+
[ VK_FORMAT_R8G8B8A8_UNORM ]: RGBAFormat,
|
|
739
|
+
[ VK_FORMAT_R8G8B8A8_SRGB ]: RGBAFormat,
|
|
740
|
+
|
|
741
|
+
[ VK_FORMAT_R32G32_SFLOAT ]: RGFormat,
|
|
742
|
+
[ VK_FORMAT_R16G16_SFLOAT ]: RGFormat,
|
|
743
|
+
[ VK_FORMAT_R8G8_UNORM ]: RGFormat,
|
|
744
|
+
[ VK_FORMAT_R8G8_SRGB ]: RGFormat,
|
|
745
|
+
|
|
746
|
+
[ VK_FORMAT_R32_SFLOAT ]: RedFormat,
|
|
747
|
+
[ VK_FORMAT_R16_SFLOAT ]: RedFormat,
|
|
748
|
+
[ VK_FORMAT_R8_SRGB ]: RedFormat,
|
|
749
|
+
[ VK_FORMAT_R8_UNORM ]: RedFormat,
|
|
750
|
+
|
|
751
|
+
[ VK_FORMAT_ASTC_6x6_SRGB_BLOCK ]: RGBA_ASTC_6x6_Format,
|
|
752
|
+
[ VK_FORMAT_ASTC_6x6_UNORM_BLOCK ]: RGBA_ASTC_6x6_Format,
|
|
753
|
+
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
const TYPE_MAP = {
|
|
757
|
+
|
|
758
|
+
[ VK_FORMAT_R32G32B32A32_SFLOAT ]: FloatType,
|
|
759
|
+
[ VK_FORMAT_R16G16B16A16_SFLOAT ]: HalfFloatType,
|
|
760
|
+
[ VK_FORMAT_R8G8B8A8_UNORM ]: UnsignedByteType,
|
|
761
|
+
[ VK_FORMAT_R8G8B8A8_SRGB ]: UnsignedByteType,
|
|
762
|
+
|
|
763
|
+
[ VK_FORMAT_R32G32_SFLOAT ]: FloatType,
|
|
764
|
+
[ VK_FORMAT_R16G16_SFLOAT ]: HalfFloatType,
|
|
765
|
+
[ VK_FORMAT_R8G8_UNORM ]: UnsignedByteType,
|
|
766
|
+
[ VK_FORMAT_R8G8_SRGB ]: UnsignedByteType,
|
|
767
|
+
|
|
768
|
+
[ VK_FORMAT_R32_SFLOAT ]: FloatType,
|
|
769
|
+
[ VK_FORMAT_R16_SFLOAT ]: HalfFloatType,
|
|
770
|
+
[ VK_FORMAT_R8_SRGB ]: UnsignedByteType,
|
|
771
|
+
[ VK_FORMAT_R8_UNORM ]: UnsignedByteType,
|
|
772
|
+
|
|
773
|
+
[ VK_FORMAT_ASTC_6x6_SRGB_BLOCK ]: UnsignedByteType,
|
|
774
|
+
[ VK_FORMAT_ASTC_6x6_UNORM_BLOCK ]: UnsignedByteType,
|
|
775
|
+
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
async function createRawTexture( container ) {
|
|
779
|
+
|
|
780
|
+
const { vkFormat } = container;
|
|
781
|
+
|
|
782
|
+
if ( FORMAT_MAP[ vkFormat ] === undefined ) {
|
|
783
|
+
|
|
784
|
+
throw new Error( 'THREE.KTX2Loader: Unsupported vkFormat.' );
|
|
785
|
+
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
//
|
|
789
|
+
|
|
790
|
+
let zstd;
|
|
791
|
+
|
|
792
|
+
if ( container.supercompressionScheme === KHR_SUPERCOMPRESSION_ZSTD ) {
|
|
793
|
+
|
|
794
|
+
if ( ! _zstd ) {
|
|
795
|
+
|
|
796
|
+
_zstd = new Promise( async ( resolve ) => {
|
|
797
|
+
|
|
798
|
+
const zstd = new ZSTDDecoder();
|
|
799
|
+
await zstd.init();
|
|
800
|
+
resolve( zstd );
|
|
801
|
+
|
|
802
|
+
} );
|
|
803
|
+
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
zstd = await _zstd;
|
|
807
|
+
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
//
|
|
811
|
+
|
|
812
|
+
const mipmaps = [];
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
for ( let levelIndex = 0; levelIndex < container.levels.length; levelIndex ++ ) {
|
|
816
|
+
|
|
817
|
+
const levelWidth = Math.max( 1, container.pixelWidth >> levelIndex );
|
|
818
|
+
const levelHeight = Math.max( 1, container.pixelHeight >> levelIndex );
|
|
819
|
+
const levelDepth = container.pixelDepth ? Math.max( 1, container.pixelDepth >> levelIndex ) : 0;
|
|
820
|
+
|
|
821
|
+
const level = container.levels[ levelIndex ];
|
|
822
|
+
|
|
823
|
+
let levelData;
|
|
824
|
+
|
|
825
|
+
if ( container.supercompressionScheme === KHR_SUPERCOMPRESSION_NONE ) {
|
|
826
|
+
|
|
827
|
+
levelData = level.levelData;
|
|
828
|
+
|
|
829
|
+
} else if ( container.supercompressionScheme === KHR_SUPERCOMPRESSION_ZSTD ) {
|
|
830
|
+
|
|
831
|
+
levelData = zstd.decode( level.levelData, level.uncompressedByteLength );
|
|
832
|
+
|
|
833
|
+
} else {
|
|
834
|
+
|
|
835
|
+
throw new Error( 'THREE.KTX2Loader: Unsupported supercompressionScheme.' );
|
|
836
|
+
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
let data;
|
|
840
|
+
|
|
841
|
+
if ( TYPE_MAP[ vkFormat ] === FloatType ) {
|
|
842
|
+
|
|
843
|
+
data = new Float32Array(
|
|
844
|
+
|
|
845
|
+
levelData.buffer,
|
|
846
|
+
levelData.byteOffset,
|
|
847
|
+
levelData.byteLength / Float32Array.BYTES_PER_ELEMENT
|
|
848
|
+
|
|
849
|
+
);
|
|
850
|
+
|
|
851
|
+
} else if ( TYPE_MAP[ vkFormat ] === HalfFloatType ) {
|
|
852
|
+
|
|
853
|
+
data = new Uint16Array(
|
|
854
|
+
|
|
855
|
+
levelData.buffer,
|
|
856
|
+
levelData.byteOffset,
|
|
857
|
+
levelData.byteLength / Uint16Array.BYTES_PER_ELEMENT
|
|
858
|
+
|
|
859
|
+
);
|
|
860
|
+
|
|
861
|
+
} else {
|
|
862
|
+
|
|
863
|
+
data = levelData;
|
|
864
|
+
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
mipmaps.push( {
|
|
868
|
+
|
|
869
|
+
data: data,
|
|
870
|
+
width: levelWidth,
|
|
871
|
+
height: levelHeight,
|
|
872
|
+
depth: levelDepth,
|
|
873
|
+
|
|
874
|
+
} );
|
|
875
|
+
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
let texture;
|
|
879
|
+
|
|
880
|
+
if ( UNCOMPRESSED_FORMATS.has( FORMAT_MAP[ vkFormat ] ) ) {
|
|
881
|
+
|
|
882
|
+
texture = container.pixelDepth === 0
|
|
883
|
+
? new DataTexture( mipmaps[ 0 ].data, container.pixelWidth, container.pixelHeight )
|
|
884
|
+
: new Data3DTexture( mipmaps[ 0 ].data, container.pixelWidth, container.pixelHeight, container.pixelDepth );
|
|
885
|
+
|
|
886
|
+
} else {
|
|
887
|
+
|
|
888
|
+
if ( container.pixelDepth > 0 ) throw new Error( 'THREE.KTX2Loader: Unsupported pixelDepth.' );
|
|
889
|
+
|
|
890
|
+
texture = new CompressedTexture( mipmaps, container.pixelWidth, container.pixelHeight );
|
|
891
|
+
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
texture.mipmaps = mipmaps;
|
|
895
|
+
|
|
896
|
+
texture.type = TYPE_MAP[ vkFormat ];
|
|
897
|
+
texture.format = FORMAT_MAP[ vkFormat ];
|
|
898
|
+
texture.colorSpace = parseColorSpace( container );
|
|
899
|
+
texture.needsUpdate = true;
|
|
900
|
+
|
|
901
|
+
//
|
|
902
|
+
|
|
903
|
+
return Promise.resolve( texture );
|
|
904
|
+
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
function parseColorSpace( container ) {
|
|
908
|
+
|
|
909
|
+
const dfd = container.dataFormatDescriptor[ 0 ];
|
|
910
|
+
|
|
911
|
+
if ( dfd.colorPrimaries === KHR_DF_PRIMARIES_BT709 ) {
|
|
912
|
+
|
|
913
|
+
return dfd.transferFunction === KHR_DF_TRANSFER_SRGB ? SRGBColorSpace : LinearSRGBColorSpace;
|
|
914
|
+
|
|
915
|
+
} else if ( dfd.colorPrimaries === KHR_DF_PRIMARIES_DISPLAYP3 ) {
|
|
916
|
+
|
|
917
|
+
return dfd.transferFunction === KHR_DF_TRANSFER_SRGB ? DisplayP3ColorSpace : LinearDisplayP3ColorSpace;
|
|
918
|
+
|
|
919
|
+
} else if ( dfd.colorPrimaries === KHR_DF_PRIMARIES_UNSPECIFIED ) {
|
|
920
|
+
|
|
921
|
+
return NoColorSpace;
|
|
922
|
+
|
|
923
|
+
} else {
|
|
924
|
+
|
|
925
|
+
console.warn( `THREE.KTX2Loader: Unsupported color primaries, "${ dfd.colorPrimaries }"` );
|
|
926
|
+
return NoColorSpace;
|
|
927
|
+
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
export { KTX2Loader };
|