@needle-tools/three 0.169.20 → 0.183.2-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +5 -6
- package/build/three.cjs +54178 -56709
- package/build/three.core.js +59506 -0
- package/build/three.core.min.js +6 -0
- package/build/three.module.js +11645 -73012
- package/build/three.module.min.js +2 -2
- package/build/three.tsl.js +648 -0
- package/build/three.tsl.min.js +6 -0
- package/build/three.webgpu.js +53905 -51657
- package/build/three.webgpu.min.js +2 -2
- package/build/three.webgpu.nodes.js +53884 -51814
- package/build/three.webgpu.nodes.min.js +2 -2
- package/examples/fonts/MPLUSRounded1c/MPLUSRounded1c-Regular.typeface.json.zip +0 -0
- package/examples/fonts/MPLUSRounded1c/OFL.txt +91 -0
- package/examples/jsm/Addons.js +5 -15
- package/examples/jsm/animation/AnimationClipCreator.js +58 -6
- package/examples/jsm/animation/CCDIKSolver.js +152 -45
- package/examples/jsm/capabilities/WebGL.js +28 -29
- package/examples/jsm/capabilities/WebGPU.js +19 -17
- package/examples/jsm/controls/ArcballControls.js +474 -178
- package/examples/jsm/controls/DragControls.js +100 -58
- package/examples/jsm/controls/FirstPersonControls.js +116 -6
- package/examples/jsm/controls/FlyControls.js +50 -2
- package/examples/jsm/controls/MapControls.js +96 -8
- package/examples/jsm/controls/OrbitControls.js +496 -57
- package/examples/jsm/controls/PointerLockControls.js +115 -22
- package/examples/jsm/controls/TrackballControls.js +166 -14
- package/examples/jsm/controls/TransformControls.js +336 -26
- package/examples/jsm/csm/CSM.js +232 -18
- package/examples/jsm/csm/CSMFrustum.js +61 -4
- package/examples/jsm/csm/CSMHelper.js +50 -0
- package/examples/jsm/csm/CSMShader.js +13 -1
- package/examples/jsm/csm/CSMShadowNode.js +599 -0
- package/examples/jsm/curves/CurveExtras.js +303 -31
- package/examples/jsm/curves/NURBSCurve.js +91 -16
- package/examples/jsm/curves/NURBSSurface.js +52 -6
- package/examples/jsm/curves/NURBSUtils.js +102 -112
- package/examples/jsm/curves/NURBSVolume.js +24 -4
- package/examples/jsm/effects/AnaglyphEffect.js +134 -7
- package/examples/jsm/effects/AsciiEffect.js +69 -22
- package/examples/jsm/effects/OutlineEffect.js +61 -111
- package/examples/jsm/effects/ParallaxBarrierEffect.js +30 -0
- package/examples/jsm/effects/StereoEffect.js +31 -0
- package/examples/jsm/environments/ColorEnvironment.js +59 -0
- package/examples/jsm/environments/DebugEnvironment.js +50 -0
- package/examples/jsm/environments/RoomEnvironment.js +83 -42
- package/examples/jsm/exporters/DRACOExporter.js +56 -14
- package/examples/jsm/exporters/EXRExporter.js +40 -9
- package/examples/jsm/exporters/GLTFExporter.js +502 -169
- package/examples/jsm/exporters/OBJExporter.js +21 -1
- package/examples/jsm/exporters/PLYExporter.js +44 -12
- package/examples/jsm/exporters/STLExporter.js +27 -5
- package/examples/jsm/exporters/USDZExporter.js +781 -291
- package/examples/jsm/geometries/BoxLineGeometry.js +23 -0
- package/examples/jsm/geometries/ConvexGeometry.js +19 -0
- package/examples/jsm/geometries/DecalGeometry.js +91 -30
- package/examples/jsm/geometries/ParametricFunctions.js +100 -0
- package/examples/jsm/geometries/ParametricGeometry.js +38 -5
- package/examples/jsm/geometries/RoundedBoxGeometry.js +68 -7
- package/examples/jsm/geometries/TeapotGeometry.js +23 -38
- package/examples/jsm/geometries/TextGeometry.js +48 -29
- package/examples/jsm/gpgpu/BitonicSort.js +715 -0
- package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
- package/examples/jsm/helpers/LightProbeHelper.js +36 -0
- package/examples/jsm/helpers/LightProbeHelperGPU.js +38 -1
- package/examples/jsm/helpers/OctreeHelper.js +36 -0
- package/examples/jsm/helpers/PositionalAudioHelper.js +60 -0
- package/examples/jsm/helpers/RapierHelper.js +59 -0
- package/examples/jsm/helpers/RectAreaLightHelper.js +36 -3
- package/examples/jsm/helpers/TextureHelper.js +28 -0
- package/examples/jsm/helpers/TextureHelperGPU.js +214 -0
- package/examples/jsm/helpers/VertexNormalsHelper.js +61 -2
- package/examples/jsm/helpers/VertexTangentsHelper.js +47 -2
- package/examples/jsm/helpers/ViewHelper.js +181 -9
- package/examples/jsm/inspector/Inspector.js +487 -0
- package/examples/jsm/inspector/RendererInspector.js +425 -0
- package/examples/jsm/inspector/tabs/Console.js +238 -0
- package/examples/jsm/inspector/tabs/Parameters.js +348 -0
- package/examples/jsm/inspector/tabs/Performance.js +268 -0
- package/examples/jsm/inspector/tabs/Viewer.js +166 -0
- package/examples/jsm/inspector/ui/Graph.js +95 -0
- package/examples/jsm/inspector/ui/Item.js +170 -0
- package/examples/jsm/inspector/ui/List.js +75 -0
- package/examples/jsm/inspector/ui/Profiler.js +1975 -0
- package/examples/jsm/inspector/ui/Style.js +1613 -0
- package/examples/jsm/inspector/ui/Tab.js +233 -0
- package/examples/jsm/inspector/ui/Values.js +439 -0
- package/examples/jsm/inspector/ui/utils.js +56 -0
- package/examples/jsm/interactive/HTMLMesh.js +43 -12
- package/examples/jsm/interactive/InteractiveGroup.js +170 -52
- package/examples/jsm/interactive/SelectionBox.js +106 -9
- package/examples/jsm/interactive/SelectionHelper.js +76 -30
- package/examples/jsm/libs/demuxer_mp4.js +109 -0
- package/examples/jsm/libs/meshopt_decoder.module.js +76 -58
- package/examples/jsm/libs/motion-controllers.module.js +1 -1
- package/examples/jsm/lighting/TiledLighting.js +42 -0
- package/examples/jsm/lights/LightProbeGenerator.js +44 -7
- package/examples/jsm/lights/RectAreaLightTexturesLib.js +50 -14
- package/examples/jsm/lights/RectAreaLightUniformsLib.js +16 -0
- package/examples/jsm/lines/Line2.js +41 -4
- package/examples/jsm/lines/LineGeometry.js +80 -2
- package/examples/jsm/lines/LineMaterial.js +105 -5
- package/examples/jsm/lines/LineSegments2.js +54 -4
- package/examples/jsm/lines/LineSegmentsGeometry.js +65 -8
- package/examples/jsm/lines/Wireframe.js +41 -4
- package/examples/jsm/lines/WireframeGeometry2.js +27 -2
- package/examples/jsm/lines/webgpu/Line2.js +28 -2
- package/examples/jsm/lines/webgpu/LineSegments2.js +59 -24
- package/examples/jsm/lines/webgpu/Wireframe.js +86 -0
- package/examples/jsm/loaders/3DMLoader.js +78 -6
- package/examples/jsm/loaders/3MFLoader.js +148 -7
- package/examples/jsm/loaders/AMFLoader.js +34 -14
- package/examples/jsm/loaders/BVHLoader.js +59 -12
- package/examples/jsm/loaders/ColladaLoader.js +61 -4027
- package/examples/jsm/loaders/DDSLoader.js +68 -1
- package/examples/jsm/loaders/DRACOLoader.js +146 -22
- package/examples/jsm/loaders/EXRLoader.js +255 -34
- package/examples/jsm/loaders/FBXLoader.js +80 -42
- package/examples/jsm/loaders/FontLoader.js +83 -6
- package/examples/jsm/loaders/GCodeLoader.js +71 -14
- package/examples/jsm/loaders/GLTFLoader.js +381 -263
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +52 -3
- package/examples/jsm/loaders/HDRLoader.js +485 -0
- package/examples/jsm/loaders/IESLoader.js +42 -0
- package/examples/jsm/loaders/KMZLoader.js +39 -6
- package/examples/jsm/loaders/KTX2Loader.js +124 -48
- package/examples/jsm/loaders/KTXLoader.js +31 -10
- package/examples/jsm/loaders/LDrawLoader.js +192 -145
- package/examples/jsm/loaders/LUT3dlLoader.js +47 -10
- package/examples/jsm/loaders/LUTCubeLoader.js +46 -9
- package/examples/jsm/loaders/LUTImageLoader.js +79 -38
- package/examples/jsm/loaders/LWOLoader.js +54 -59
- package/examples/jsm/loaders/LottieLoader.js +54 -1
- package/examples/jsm/loaders/MD2Loader.js +37 -1
- package/examples/jsm/loaders/MDDLoader.js +57 -12
- package/examples/jsm/loaders/MTLLoader.js +60 -35
- package/examples/jsm/loaders/MaterialXLoader.js +268 -34
- package/examples/jsm/loaders/NRRDLoader.js +40 -8
- package/examples/jsm/loaders/OBJLoader.js +51 -2
- package/examples/jsm/loaders/PCDLoader.js +173 -21
- package/examples/jsm/loaders/PDBLoader.js +41 -2
- package/examples/jsm/loaders/PLYLoader.js +70 -39
- package/examples/jsm/loaders/PVRLoader.js +25 -6
- package/examples/jsm/loaders/RGBELoader.js +6 -438
- package/examples/jsm/loaders/STLLoader.js +48 -38
- package/examples/jsm/loaders/SVGLoader.js +119 -25
- package/examples/jsm/loaders/TDSLoader.js +92 -74
- package/examples/jsm/loaders/TGALoader.js +23 -2
- package/examples/jsm/loaders/TIFFLoader.js +23 -0
- package/examples/jsm/loaders/TTFLoader.js +50 -3
- package/examples/jsm/loaders/USDLoader.js +279 -0
- package/examples/jsm/loaders/USDZLoader.js +4 -858
- package/examples/jsm/loaders/UltraHDRLoader.js +338 -166
- package/examples/jsm/loaders/VOXLoader.js +688 -87
- package/examples/jsm/loaders/VRMLLoader.js +121 -12
- package/examples/jsm/loaders/VTKLoader.js +77 -25
- package/examples/jsm/loaders/XYZLoader.js +36 -0
- package/examples/jsm/loaders/collada/ColladaComposer.js +2950 -0
- package/examples/jsm/loaders/collada/ColladaParser.js +1962 -0
- package/examples/jsm/loaders/lwo/IFFParser.js +77 -77
- package/examples/jsm/loaders/usd/USDAParser.js +822 -0
- package/examples/jsm/loaders/usd/USDCParser.js +1852 -0
- package/examples/jsm/loaders/usd/USDComposer.js +4041 -0
- package/examples/jsm/materials/LDrawConditionalLineMaterial.js +183 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +154 -0
- package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
- package/examples/jsm/math/Capsule.js +91 -14
- package/examples/jsm/math/ColorConverter.js +22 -0
- package/examples/jsm/math/ColorSpaces.js +74 -2
- package/examples/jsm/math/ConvexHull.js +517 -93
- package/examples/jsm/math/ImprovedNoise.js +32 -15
- package/examples/jsm/math/Lut.js +113 -0
- package/examples/jsm/math/MeshSurfaceSampler.js +78 -13
- package/examples/jsm/math/OBB.js +141 -29
- package/examples/jsm/math/Octree.js +283 -7
- package/examples/jsm/math/SimplexNoise.js +68 -42
- package/examples/jsm/misc/ConvexObjectBreaker.js +45 -25
- package/examples/jsm/misc/GPUComputationRenderer.js +96 -20
- package/examples/jsm/misc/Gyroscope.js +12 -0
- package/examples/jsm/misc/MD2Character.js +117 -2
- package/examples/jsm/misc/MD2CharacterComplex.js +175 -11
- package/examples/jsm/misc/MorphAnimMesh.js +44 -0
- package/examples/jsm/misc/MorphBlendMesh.js +103 -0
- package/examples/jsm/misc/ProgressiveLightMap.js +100 -54
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +322 -0
- package/examples/jsm/misc/RollerCoaster.js +57 -0
- package/examples/jsm/misc/TubePainter.js +437 -40
- package/examples/jsm/misc/Volume.js +123 -76
- package/examples/jsm/misc/VolumeSlice.js +95 -49
- package/examples/jsm/modifiers/CurveModifier.js +66 -38
- package/examples/jsm/modifiers/CurveModifierGPU.js +42 -19
- package/examples/jsm/modifiers/EdgeSplitModifier.js +20 -0
- package/examples/jsm/modifiers/SimplifyModifier.js +24 -10
- package/examples/jsm/modifiers/TessellateModifier.js +35 -2
- package/examples/jsm/objects/GroundedSkybox.js +25 -6
- package/examples/jsm/objects/Lensflare.js +94 -2
- package/examples/jsm/objects/LensflareMesh.js +64 -10
- package/examples/jsm/objects/MarchingCubes.js +90 -5
- package/examples/jsm/objects/Reflector.js +76 -2
- package/examples/jsm/objects/ReflectorForSSRPass.js +41 -0
- package/examples/jsm/objects/Refractor.js +62 -0
- package/examples/jsm/objects/ShadowMesh.js +54 -4
- package/examples/jsm/objects/Sky.js +106 -16
- package/examples/jsm/objects/SkyMesh.js +211 -38
- package/examples/jsm/objects/Water.js +49 -8
- package/examples/jsm/objects/Water2.js +49 -7
- package/examples/jsm/objects/Water2Mesh.js +50 -9
- package/examples/jsm/objects/WaterMesh.js +136 -43
- package/examples/jsm/physics/AmmoPhysics.js +60 -7
- package/examples/jsm/physics/JoltPhysics.js +65 -12
- package/examples/jsm/physics/RapierPhysics.js +217 -21
- package/examples/jsm/postprocessing/AfterimagePass.js +110 -29
- package/examples/jsm/postprocessing/BloomPass.js +128 -26
- package/examples/jsm/postprocessing/BokehPass.js +99 -22
- package/examples/jsm/postprocessing/ClearPass.js +54 -3
- package/examples/jsm/postprocessing/CubeTexturePass.js +82 -21
- package/examples/jsm/postprocessing/DotScreenPass.js +59 -10
- package/examples/jsm/postprocessing/EffectComposer.js +140 -6
- package/examples/jsm/postprocessing/FXAAPass.js +40 -0
- package/examples/jsm/postprocessing/FilmPass.js +54 -5
- package/examples/jsm/postprocessing/GTAOPass.js +202 -57
- package/examples/jsm/postprocessing/GlitchPass.js +86 -34
- package/examples/jsm/postprocessing/HalftonePass.js +65 -10
- package/examples/jsm/postprocessing/LUTPass.js +38 -8
- package/examples/jsm/postprocessing/MaskPass.js +91 -0
- package/examples/jsm/postprocessing/OutlinePass.js +272 -135
- package/examples/jsm/postprocessing/OutputPass.js +65 -14
- package/examples/jsm/postprocessing/Pass.js +100 -4
- package/examples/jsm/postprocessing/RenderPass.js +94 -0
- package/examples/jsm/postprocessing/RenderPixelatedPass.js +124 -45
- package/examples/jsm/postprocessing/RenderTransitionPass.js +120 -21
- package/examples/jsm/postprocessing/SAOPass.js +128 -55
- package/examples/jsm/postprocessing/SMAAPass.js +106 -75
- package/examples/jsm/postprocessing/SSAARenderPass.js +118 -35
- package/examples/jsm/postprocessing/SSAOPass.js +173 -60
- package/examples/jsm/postprocessing/SSRPass.js +268 -53
- package/examples/jsm/postprocessing/SavePass.js +69 -16
- package/examples/jsm/postprocessing/ShaderPass.js +65 -7
- package/examples/jsm/postprocessing/TAARenderPass.js +79 -24
- package/examples/jsm/postprocessing/TexturePass.js +72 -8
- package/examples/jsm/postprocessing/UnrealBloomPass.js +168 -59
- package/examples/jsm/renderers/CSS2DRenderer.js +98 -5
- package/examples/jsm/renderers/CSS3DRenderer.js +111 -7
- package/examples/jsm/renderers/Projector.js +288 -32
- package/examples/jsm/renderers/SVGRenderer.js +323 -61
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +3 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +1 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +5 -1
- package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +12 -5
- package/examples/jsm/shaders/AfterimageShader.js +8 -3
- package/examples/jsm/shaders/BasicShader.js +8 -1
- package/examples/jsm/shaders/BleachBypassShader.js +10 -3
- package/examples/jsm/shaders/BlendShader.js +8 -1
- package/examples/jsm/shaders/BokehShader.js +9 -3
- package/examples/jsm/shaders/BokehShader2.js +11 -4
- package/examples/jsm/shaders/BrightnessContrastShader.js +10 -4
- package/examples/jsm/shaders/ColorCorrectionShader.js +8 -1
- package/examples/jsm/shaders/ColorifyShader.js +8 -1
- package/examples/jsm/shaders/ConvolutionShader.js +9 -38
- package/examples/jsm/shaders/CopyShader.js +8 -1
- package/examples/jsm/shaders/DOFMipMapShader.js +10 -3
- package/examples/jsm/shaders/DepthLimitedBlurShader.js +10 -1
- package/examples/jsm/shaders/DigitalGlitch.js +10 -7
- package/examples/jsm/shaders/DotScreenShader.js +8 -3
- package/examples/jsm/shaders/ExposureShader.js +8 -1
- package/examples/jsm/shaders/FXAAShader.js +233 -221
- package/examples/jsm/shaders/FilmShader.js +13 -0
- package/examples/jsm/shaders/FocusShader.js +8 -3
- package/examples/jsm/shaders/FreiChenShader.js +10 -3
- package/examples/jsm/shaders/GTAOShader.js +55 -45
- package/examples/jsm/shaders/GammaCorrectionShader.js +11 -2
- package/examples/jsm/shaders/HalftoneShader.js +24 -4
- package/examples/jsm/shaders/HorizontalBlurShader.js +12 -3
- package/examples/jsm/shaders/HorizontalTiltShiftShader.js +9 -2
- package/examples/jsm/shaders/HueSaturationShader.js +10 -3
- package/examples/jsm/shaders/KaleidoShader.js +11 -4
- package/examples/jsm/shaders/LuminosityHighPassShader.js +8 -4
- package/examples/jsm/shaders/LuminosityShader.js +8 -2
- package/examples/jsm/shaders/MirrorShader.js +10 -4
- package/examples/jsm/shaders/NormalMapShader.js +7 -2
- package/examples/jsm/shaders/OutputShader.js +19 -1
- package/examples/jsm/shaders/PoissonDenoiseShader.js +30 -17
- package/examples/jsm/shaders/RGBShiftShader.js +8 -1
- package/examples/jsm/shaders/SAOShader.js +27 -5
- package/examples/jsm/shaders/SMAAShader.js +24 -1
- package/examples/jsm/shaders/SSAOShader.js +37 -6
- package/examples/jsm/shaders/SSRShader.js +32 -6
- package/examples/jsm/shaders/SepiaShader.js +8 -3
- package/examples/jsm/shaders/SobelOperatorShader.js +9 -3
- package/examples/jsm/shaders/SubsurfaceScatteringShader.js +13 -8
- package/examples/jsm/shaders/TechnicolorShader.js +10 -4
- package/examples/jsm/shaders/ToonShader.js +29 -6
- package/examples/jsm/shaders/TriangleBlurShader.js +9 -4
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +19 -6
- package/examples/jsm/shaders/VelocityShader.js +8 -1
- package/examples/jsm/shaders/VerticalBlurShader.js +9 -2
- package/examples/jsm/shaders/VerticalTiltShiftShader.js +8 -1
- package/examples/jsm/shaders/VignetteShader.js +8 -3
- package/examples/jsm/shaders/VolumeShader.js +11 -2
- package/examples/jsm/shaders/WaterRefractionShader.js +11 -0
- package/examples/jsm/textures/FlakesTexture.js +14 -0
- package/examples/jsm/transpiler/AST.js +436 -31
- package/examples/jsm/transpiler/GLSLDecoder.js +380 -135
- package/examples/jsm/transpiler/Linker.js +327 -0
- package/examples/jsm/transpiler/ShaderToyDecoder.js +3 -1
- package/examples/jsm/transpiler/TSLEncoder.js +363 -97
- package/examples/jsm/transpiler/Transpiler.js +50 -1
- package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
- package/examples/jsm/transpiler/WGSLEncoder.js +839 -0
- package/examples/jsm/tsl/display/AfterImageNode.js +244 -0
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +549 -0
- package/examples/jsm/tsl/display/AnamorphicNode.js +282 -0
- package/examples/jsm/tsl/display/BilateralBlurNode.js +364 -0
- package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +11 -4
- package/examples/jsm/tsl/display/BloomNode.js +534 -0
- package/examples/jsm/tsl/display/CRT.js +150 -0
- package/examples/jsm/tsl/display/ChromaticAberrationNode.js +207 -0
- package/examples/jsm/tsl/display/DenoiseNode.js +334 -0
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +554 -0
- package/examples/jsm/tsl/display/DotScreenNode.js +104 -0
- package/examples/jsm/tsl/display/FXAANode.js +365 -0
- package/examples/jsm/tsl/display/FilmNode.js +101 -0
- package/examples/jsm/tsl/display/GTAONode.js +571 -0
- package/examples/jsm/tsl/display/GaussianBlurNode.js +389 -0
- package/examples/jsm/tsl/display/GodraysNode.js +624 -0
- package/examples/jsm/tsl/display/LensflareNode.js +279 -0
- package/examples/jsm/tsl/display/Lut3DNode.js +109 -0
- package/examples/jsm/tsl/display/MotionBlur.js +33 -0
- package/examples/jsm/tsl/display/OutlineNode.js +762 -0
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +89 -0
- package/examples/jsm/tsl/display/PixelationPassNode.js +335 -0
- package/examples/jsm/tsl/display/RGBShiftNode.js +96 -0
- package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
- package/examples/jsm/tsl/display/SMAANode.js +768 -0
- package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +120 -49
- package/examples/jsm/tsl/display/SSGINode.js +642 -0
- package/examples/jsm/tsl/display/SSRNode.js +656 -0
- package/examples/jsm/tsl/display/SSSNode.js +490 -0
- package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +9 -2
- package/examples/jsm/tsl/display/Shape.js +29 -0
- package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +61 -19
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +192 -0
- package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +48 -12
- package/examples/jsm/tsl/display/TRAANode.js +726 -0
- package/examples/jsm/tsl/display/TransitionNode.js +141 -0
- package/examples/jsm/tsl/display/boxBlur.js +65 -0
- package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
- package/examples/jsm/tsl/display/hashBlur.js +54 -0
- package/examples/jsm/tsl/display/radialBlur.js +68 -0
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +442 -0
- package/examples/jsm/tsl/math/Bayer.js +73 -0
- package/examples/jsm/tsl/shadows/TileShadowNode.js +456 -0
- package/examples/jsm/tsl/shadows/TileShadowNodeHelper.js +212 -0
- package/examples/jsm/tsl/utils/Raymarching.js +70 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +91 -29
- package/examples/jsm/utils/CameraUtils.js +15 -6
- package/examples/jsm/utils/GeometryCompressionUtils.js +23 -30
- package/examples/jsm/utils/GeometryUtils.js +32 -27
- package/examples/jsm/utils/LDrawUtils.js +14 -5
- package/examples/jsm/utils/SceneOptimizer.js +458 -0
- package/examples/jsm/utils/SceneUtils.js +53 -3
- package/examples/jsm/utils/ShadowMapViewer.js +72 -33
- package/examples/jsm/utils/ShadowMapViewerGPU.js +61 -29
- package/examples/jsm/utils/SkeletonUtils.js +48 -0
- package/examples/jsm/utils/SortUtils.js +17 -5
- package/examples/jsm/utils/UVsDebug.js +12 -4
- package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +16 -0
- package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +20 -2
- package/examples/jsm/utils/WorkerPool.js +67 -2
- package/examples/jsm/webxr/ARButton.js +19 -0
- package/examples/jsm/webxr/OculusHandModel.js +84 -0
- package/examples/jsm/webxr/OculusHandPointerModel.js +148 -22
- package/examples/jsm/webxr/Text2D.js +20 -6
- package/examples/jsm/webxr/VRButton.js +31 -0
- package/examples/jsm/webxr/XRButton.js +23 -0
- package/examples/jsm/webxr/XRControllerModelFactory.js +94 -3
- package/examples/jsm/webxr/XREstimatedLight.js +35 -4
- package/examples/jsm/webxr/XRHandMeshModel.js +37 -0
- package/examples/jsm/webxr/XRHandModelFactory.js +96 -6
- package/examples/jsm/webxr/XRHandPrimitiveModel.js +44 -0
- package/examples/jsm/webxr/XRPlanes.js +18 -0
- package/package.json +29 -34
- package/src/Three.Core.js +198 -0
- package/src/Three.Legacy.js +0 -21
- package/src/Three.TSL.js +641 -0
- package/src/Three.WebGPU.Nodes.js +14 -186
- package/src/Three.WebGPU.js +16 -186
- package/src/Three.js +2 -197
- package/src/animation/AnimationAction.js +263 -31
- package/src/animation/AnimationClip.js +162 -7
- package/src/animation/AnimationMixer.js +99 -15
- package/src/animation/AnimationObjectGroup.js +45 -21
- package/src/animation/AnimationUtils.js +163 -24
- package/src/animation/KeyframeTrack.js +191 -17
- package/src/animation/PropertyBinding.js +91 -16
- package/src/animation/PropertyMixer.js +72 -5
- package/src/animation/tracks/BooleanKeyframeTrack.js +33 -6
- package/src/animation/tracks/ColorKeyframeTrack.js +26 -5
- package/src/animation/tracks/NumberKeyframeTrack.js +26 -2
- package/src/animation/tracks/QuaternionKeyframeTrack.js +30 -1
- package/src/animation/tracks/StringKeyframeTrack.js +33 -2
- package/src/animation/tracks/VectorKeyframeTrack.js +26 -2
- package/src/audio/Audio.js +386 -8
- package/src/audio/AudioAnalyser.js +58 -1
- package/src/audio/AudioContext.js +15 -0
- package/src/audio/AudioListener.js +94 -13
- package/src/audio/PositionalAudio.js +107 -0
- package/src/cameras/ArrayCamera.js +37 -0
- package/src/cameras/Camera.js +61 -0
- package/src/cameras/CubeCamera.js +86 -0
- package/src/cameras/OrthographicCamera.js +110 -1
- package/src/cameras/PerspectiveCamera.js +174 -35
- package/src/cameras/StereoCamera.js +48 -2
- package/src/constants.js +1546 -11
- package/src/core/BufferAttribute.js +417 -3
- package/src/core/BufferGeometry.js +407 -22
- package/src/core/Clock.js +69 -8
- package/src/core/EventDispatcher.js +52 -8
- package/src/core/GLBufferAttribute.js +113 -2
- package/src/core/InstancedBufferAttribute.js +29 -0
- package/src/core/InstancedBufferGeometry.js +20 -0
- package/src/core/InstancedInterleavedBuffer.js +26 -0
- package/src/core/InterleavedBuffer.js +141 -7
- package/src/core/InterleavedBufferAttribute.js +200 -2
- package/src/core/Layers.js +71 -10
- package/src/core/Object3D.js +673 -26
- package/src/core/Raycaster.js +136 -2
- package/src/core/RenderTarget.js +256 -27
- package/src/core/RenderTarget3D.js +48 -0
- package/src/core/Timer.js +184 -0
- package/src/core/Uniform.js +29 -0
- package/src/core/UniformsGroup.js +84 -2
- package/src/extras/Controls.js +89 -1
- package/src/extras/DataUtils.js +50 -9
- package/src/extras/Earcut.js +18 -779
- package/src/extras/ImageUtils.js +22 -14
- package/src/extras/PMREMGenerator.js +316 -67
- package/src/extras/ShapeUtils.js +24 -2
- package/src/extras/TextureUtils.js +101 -15
- package/src/extras/core/Curve.js +156 -55
- package/src/extras/core/CurvePath.js +63 -22
- package/src/extras/core/Interpolations.js +34 -2
- package/src/extras/core/Path.js +134 -1
- package/src/extras/core/Shape.js +66 -3
- package/src/extras/core/ShapePath.js +80 -4
- package/src/extras/curves/ArcCurve.js +22 -0
- package/src/extras/curves/CatmullRomCurve3.js +89 -18
- package/src/extras/curves/CubicBezierCurve.js +67 -0
- package/src/extras/curves/CubicBezierCurve3.js +50 -0
- package/src/extras/curves/EllipseCurve.js +102 -0
- package/src/extras/curves/LineCurve.js +36 -0
- package/src/extras/curves/LineCurve3.js +36 -0
- package/src/extras/curves/QuadraticBezierCurve.js +59 -0
- package/src/extras/curves/QuadraticBezierCurve3.js +43 -0
- package/src/extras/curves/SplineCurve.js +48 -0
- package/src/extras/lib/earcut.js +685 -0
- package/src/geometries/BoxGeometry.js +39 -0
- package/src/geometries/CapsuleGeometry.js +196 -11
- package/src/geometries/CircleGeometry.js +41 -0
- package/src/geometries/ConeGeometry.js +39 -0
- package/src/geometries/CylinderGeometry.js +42 -2
- package/src/geometries/DodecahedronGeometry.js +33 -0
- package/src/geometries/EdgesGeometry.js +30 -2
- package/src/geometries/ExtrudeGeometry.js +148 -52
- package/src/geometries/IcosahedronGeometry.js +33 -0
- package/src/geometries/LatheGeometry.js +44 -3
- package/src/geometries/OctahedronGeometry.js +33 -0
- package/src/geometries/PlaneGeometry.js +35 -0
- package/src/geometries/PolyhedronGeometry.js +30 -1
- package/src/geometries/RingGeometry.js +37 -0
- package/src/geometries/ShapeGeometry.js +38 -0
- package/src/geometries/SphereGeometry.js +38 -0
- package/src/geometries/TetrahedronGeometry.js +33 -0
- package/src/geometries/TorusGeometry.js +44 -3
- package/src/geometries/TorusKnotGeometry.js +39 -0
- package/src/geometries/TubeGeometry.js +50 -0
- package/src/geometries/WireframeGeometry.js +32 -0
- package/src/helpers/ArrowHelper.js +62 -5
- package/src/helpers/AxesHelper.js +28 -0
- package/src/helpers/Box3Helper.js +28 -0
- package/src/helpers/BoxHelper.js +43 -7
- package/src/helpers/CameraHelper.js +103 -27
- package/src/helpers/DirectionalLightHelper.js +55 -0
- package/src/helpers/GridHelper.js +26 -0
- package/src/helpers/HemisphereLightHelper.js +42 -0
- package/src/helpers/PlaneHelper.js +33 -0
- package/src/helpers/PointLightHelper.js +43 -24
- package/src/helpers/PolarGridHelper.js +30 -0
- package/src/helpers/SkeletonHelper.js +73 -7
- package/src/helpers/SpotLightHelper.js +43 -0
- package/src/lights/AmbientLight.js +25 -0
- package/src/lights/DirectionalLight.js +70 -0
- package/src/lights/DirectionalLightShadow.js +15 -0
- package/src/lights/HemisphereLight.js +42 -0
- package/src/lights/Light.js +37 -11
- package/src/lights/LightProbe.js +37 -9
- package/src/lights/LightShadow.js +202 -7
- package/src/lights/PointLight.js +74 -0
- package/src/lights/PointLightShadow.js +15 -80
- package/src/lights/RectAreaLight.js +59 -0
- package/src/lights/SpotLight.js +124 -1
- package/src/lights/SpotLightShadow.js +33 -3
- package/src/lights/webgpu/IESSpotLight.js +22 -0
- package/src/lights/webgpu/ProjectorLight.js +46 -0
- package/src/loaders/AnimationLoader.js +34 -2
- package/src/loaders/AudioLoader.js +34 -2
- package/src/loaders/BufferGeometryLoader.js +38 -13
- package/src/loaders/Cache.js +75 -2
- package/src/loaders/CompressedTextureLoader.js +36 -3
- package/src/loaders/CubeTextureLoader.js +45 -0
- package/src/loaders/DataTextureLoader.js +45 -4
- package/src/loaders/FileLoader.js +85 -5
- package/src/loaders/ImageBitmapLoader.js +113 -11
- package/src/loaders/ImageLoader.js +85 -8
- package/src/loaders/Loader.js +144 -0
- package/src/loaders/LoaderUtils.js +18 -36
- package/src/loaders/LoadingManager.js +187 -0
- package/src/loaders/MaterialLoader.js +62 -3
- package/src/loaders/ObjectLoader.js +131 -31
- package/src/loaders/TextureLoader.js +33 -0
- package/src/loaders/nodes/NodeLoader.js +68 -4
- package/src/loaders/nodes/NodeMaterialLoader.js +45 -0
- package/src/loaders/nodes/NodeObjectLoader.js +61 -0
- package/src/materials/LineBasicMaterial.js +74 -1
- package/src/materials/LineDashedMaterial.js +52 -1
- package/src/materials/Material.js +502 -8
- package/src/materials/MeshBasicMaterial.js +168 -2
- package/src/materials/MeshDepthMaterial.js +94 -0
- package/src/materials/MeshDistanceMaterial.js +76 -0
- package/src/materials/MeshLambertMaterial.js +283 -0
- package/src/materials/MeshMatcapMaterial.js +164 -0
- package/src/materials/MeshNormalMaterial.js +114 -0
- package/src/materials/MeshPhongMaterial.js +298 -0
- package/src/materials/MeshPhysicalMaterial.js +296 -4
- package/src/materials/MeshStandardMaterial.js +300 -2
- package/src/materials/MeshToonMaterial.js +219 -0
- package/src/materials/PointsMaterial.js +89 -0
- package/src/materials/RawShaderMaterial.js +25 -0
- package/src/materials/ShaderMaterial.js +234 -6
- package/src/materials/ShadowMaterial.js +54 -0
- package/src/materials/SpriteMaterial.js +82 -0
- package/src/materials/nodes/Line2NodeMaterial.js +158 -53
- package/src/materials/nodes/LineBasicNodeMaterial.js +17 -2
- package/src/materials/nodes/LineDashedNodeMaterial.js +81 -6
- package/src/materials/nodes/MeshBasicNodeMaterial.js +59 -2
- package/src/materials/nodes/MeshLambertNodeMaterial.js +35 -0
- package/src/materials/nodes/MeshMatcapNodeMaterial.js +23 -3
- package/src/materials/nodes/MeshNormalNodeMaterial.js +27 -4
- package/src/materials/nodes/MeshPhongNodeMaterial.js +64 -1
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +276 -3
- package/src/materials/nodes/MeshSSSNodeMaterial.js +98 -10
- package/src/materials/nodes/MeshStandardNodeMaterial.js +83 -4
- package/src/materials/nodes/MeshToonNodeMaterial.js +28 -0
- package/src/materials/nodes/NodeMaterial.js +789 -74
- package/src/materials/nodes/NodeMaterials.js +0 -1
- package/src/materials/nodes/PointsNodeMaterial.js +180 -11
- package/src/materials/nodes/ShadowNodeMaterial.js +38 -0
- package/src/materials/nodes/SpriteNodeMaterial.js +86 -23
- package/src/materials/nodes/VolumeNodeMaterial.js +57 -84
- package/src/materials/nodes/manager/NodeMaterialObserver.js +329 -12
- package/src/math/Box2.js +177 -0
- package/src/math/Box3.js +271 -0
- package/src/math/Color.js +355 -11
- package/src/math/ColorManagement.js +158 -92
- package/src/math/Cylindrical.js +65 -6
- package/src/math/Euler.js +139 -5
- package/src/math/Frustum.js +108 -9
- package/src/math/FrustumArray.js +258 -0
- package/src/math/Interpolant.js +87 -8
- package/src/math/Line3.js +221 -2
- package/src/math/MathUtils.js +408 -20
- package/src/math/Matrix2.js +70 -0
- package/src/math/Matrix3.js +229 -4
- package/src/math/Matrix4.js +489 -94
- package/src/math/Plane.js +164 -2
- package/src/math/Quaternion.js +322 -90
- package/src/math/Ray.js +162 -0
- package/src/math/Sphere.js +175 -0
- package/src/math/Spherical.js +73 -11
- package/src/math/SphericalHarmonics3.js +112 -14
- package/src/math/Triangle.js +206 -2
- package/src/math/Vector2.js +396 -10
- package/src/math/Vector3.js +550 -15
- package/src/math/Vector4.js +415 -9
- package/src/math/interpolants/BezierInterpolant.js +108 -0
- package/src/math/interpolants/CubicInterpolant.js +10 -1
- package/src/math/interpolants/DiscreteInterpolant.js +10 -2
- package/src/math/interpolants/LinearInterpolant.js +13 -0
- package/src/math/interpolants/QuaternionLinearInterpolant.js +10 -1
- package/src/nodes/Nodes.js +91 -88
- package/src/nodes/TSL.js +32 -38
- package/src/nodes/accessors/AccessorsUtils.js +37 -9
- package/src/nodes/accessors/Arrays.js +68 -0
- package/src/nodes/accessors/BatchNode.js +49 -14
- package/src/nodes/accessors/Bitangent.js +82 -13
- package/src/nodes/accessors/BufferAttributeNode.js +269 -8
- package/src/nodes/accessors/BufferNode.js +91 -2
- package/src/nodes/accessors/BuiltinNode.js +63 -0
- package/src/nodes/accessors/Camera.js +400 -10
- package/src/nodes/accessors/ClippingNode.js +149 -45
- package/src/nodes/accessors/CubeTextureNode.js +137 -7
- package/src/nodes/accessors/InstanceNode.js +245 -40
- package/src/nodes/accessors/InstancedMeshNode.js +50 -0
- package/src/nodes/accessors/Lights.js +88 -0
- package/src/nodes/accessors/MaterialNode.js +355 -13
- package/src/nodes/accessors/MaterialProperties.js +57 -1
- package/src/nodes/accessors/MaterialReferenceNode.js +52 -14
- package/src/nodes/accessors/ModelNode.js +117 -5
- package/src/nodes/accessors/ModelViewProjectionNode.js +10 -39
- package/src/nodes/accessors/MorphNode.js +73 -26
- package/src/nodes/accessors/Normal.js +174 -19
- package/src/nodes/accessors/Object3DNode.js +146 -12
- package/src/nodes/accessors/PointUVNode.js +25 -0
- package/src/nodes/accessors/Position.js +119 -7
- package/src/nodes/accessors/ReferenceBaseNode.js +190 -4
- package/src/nodes/accessors/ReferenceNode.js +223 -8
- package/src/nodes/accessors/ReflectVector.js +29 -3
- package/src/nodes/accessors/RendererReferenceNode.js +45 -2
- package/src/nodes/accessors/SceneProperties.js +53 -0
- package/src/nodes/accessors/SkinningNode.js +180 -43
- package/src/nodes/accessors/StorageBufferNode.js +278 -26
- package/src/nodes/accessors/StorageTextureNode.js +205 -12
- package/src/nodes/accessors/Tangent.js +48 -10
- package/src/nodes/accessors/TangentUtils.js +46 -0
- package/src/nodes/accessors/Texture3DNode.js +104 -11
- package/src/nodes/accessors/TextureBicubic.js +31 -4
- package/src/nodes/accessors/TextureNode.js +564 -52
- package/src/nodes/accessors/TextureSizeNode.js +42 -1
- package/src/nodes/accessors/UV.js +9 -1
- package/src/nodes/accessors/UniformArrayNode.js +226 -34
- package/src/nodes/accessors/UserDataNode.js +46 -2
- package/src/nodes/accessors/VelocityNode.js +93 -3
- package/src/nodes/accessors/VertexColorNode.js +39 -4
- package/src/nodes/code/CodeNode.js +101 -8
- package/src/nodes/code/ExpressionNode.js +29 -2
- package/src/nodes/code/FunctionCallNode.js +98 -10
- package/src/nodes/code/FunctionNode.js +69 -2
- package/src/nodes/core/ArrayNode.js +174 -0
- package/src/nodes/core/AssignNode.js +80 -9
- package/src/nodes/core/AttributeNode.js +47 -4
- package/src/nodes/core/BypassNode.js +47 -3
- package/src/nodes/core/ConstNode.js +32 -0
- package/src/nodes/core/ContextNode.js +220 -14
- package/src/nodes/core/IndexNode.js +72 -7
- package/src/nodes/core/InputNode.js +50 -1
- package/src/nodes/core/InspectorNode.js +128 -0
- package/src/nodes/core/IsolateNode.js +133 -0
- package/src/nodes/core/LightingModel.js +65 -5
- package/src/nodes/core/MRTNode.js +113 -2
- package/src/nodes/core/Node.js +595 -36
- package/src/nodes/core/NodeAttribute.js +38 -0
- package/src/nodes/core/NodeBuilder.js +1840 -121
- package/src/nodes/core/NodeCache.js +41 -2
- package/src/nodes/core/NodeCode.js +31 -0
- package/src/nodes/core/NodeError.js +28 -0
- package/src/nodes/core/NodeFrame.js +153 -24
- package/src/nodes/core/NodeFunction.js +48 -1
- package/src/nodes/core/NodeFunctionInput.js +44 -0
- package/src/nodes/core/NodeParser.js +13 -1
- package/src/nodes/core/NodeUniform.js +53 -1
- package/src/nodes/core/NodeUtils.js +201 -51
- package/src/nodes/core/NodeVar.js +47 -1
- package/src/nodes/core/NodeVarying.js +47 -1
- package/src/nodes/core/OutputStructNode.js +54 -12
- package/src/nodes/core/ParameterNode.js +60 -2
- package/src/nodes/core/PropertyNode.js +286 -7
- package/src/nodes/core/StackNode.js +337 -20
- package/src/nodes/core/StackTrace.js +139 -0
- package/src/nodes/core/StructNode.js +134 -0
- package/src/nodes/core/StructType.js +13 -0
- package/src/nodes/core/StructTypeNode.js +126 -6
- package/src/nodes/core/SubBuildNode.js +89 -0
- package/src/nodes/core/TempNode.js +31 -5
- package/src/nodes/core/UniformGroupNode.js +85 -7
- package/src/nodes/core/UniformNode.js +163 -16
- package/src/nodes/core/VarNode.js +317 -10
- package/src/nodes/core/VaryingNode.js +115 -13
- package/src/nodes/core/constants.js +40 -0
- package/src/nodes/display/BlendModes.js +171 -0
- package/src/nodes/display/BumpMapNode.js +38 -2
- package/src/nodes/display/ColorAdjustment.js +118 -6
- package/src/nodes/display/ColorSpaceFunctions.js +22 -6
- package/src/nodes/display/ColorSpaceNode.js +97 -47
- package/src/nodes/display/FrontFacingNode.js +64 -7
- package/src/nodes/display/NormalMapNode.js +101 -54
- package/src/nodes/display/PassNode.js +690 -33
- package/src/nodes/display/RenderOutputNode.js +94 -4
- package/src/nodes/display/ScreenNode.js +138 -27
- package/src/nodes/display/ToneMappingFunctions.js +62 -10
- package/src/nodes/display/ToneMappingNode.js +88 -8
- package/src/nodes/display/ToonOutlinePassNode.js +84 -4
- package/src/nodes/display/ViewportDepthNode.js +227 -10
- package/src/nodes/display/ViewportDepthTextureNode.js +39 -5
- package/src/nodes/display/ViewportSharedTextureNode.js +35 -1
- package/src/nodes/display/ViewportTextureNode.js +171 -7
- package/src/nodes/fog/Fog.js +97 -0
- package/src/nodes/functions/BSDF/BRDF_GGX.js +2 -6
- package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +52 -0
- package/src/nodes/functions/BSDF/BRDF_Sheen.js +4 -4
- package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
- package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
- package/src/nodes/functions/BSDF/LTC.js +45 -1
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +1 -1
- package/src/nodes/functions/BasicLightingModel.js +28 -6
- package/src/nodes/functions/PhongLightingModel.js +36 -6
- package/src/nodes/functions/PhysicalLightingModel.js +336 -91
- package/src/nodes/functions/ShadowMaskModel.js +30 -3
- package/src/nodes/functions/ToonLightingModel.js +21 -2
- package/src/nodes/functions/VolumetricLightingModel.js +183 -0
- package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
- package/src/nodes/functions/material/getGeometryRoughness.js +10 -4
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
- package/src/nodes/geometry/RangeNode.js +97 -8
- package/src/nodes/gpgpu/AtomicFunctionNode.js +198 -23
- package/src/nodes/gpgpu/BarrierNode.js +52 -3
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +135 -6
- package/src/nodes/gpgpu/ComputeNode.js +212 -16
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +455 -0
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +143 -9
- package/src/nodes/lighting/AONode.js +18 -0
- package/src/nodes/lighting/AmbientLightNode.js +10 -0
- package/src/nodes/lighting/AnalyticLightNode.js +186 -399
- package/src/nodes/lighting/BasicEnvironmentNode.js +19 -0
- package/src/nodes/lighting/BasicLightMapNode.js +17 -0
- package/src/nodes/lighting/DirectionalLightNode.js +12 -11
- package/src/nodes/lighting/EnvironmentNode.js +59 -19
- package/src/nodes/lighting/HemisphereLightNode.js +33 -2
- package/src/nodes/lighting/IESSpotLightNode.js +13 -1
- package/src/nodes/lighting/IrradianceNode.js +17 -0
- package/src/nodes/lighting/LightProbeNode.js +20 -0
- package/src/nodes/lighting/LightUtils.js +11 -3
- package/src/nodes/lighting/LightingContextNode.js +52 -4
- package/src/nodes/lighting/LightingNode.js +15 -6
- package/src/nodes/lighting/LightsNode.js +238 -35
- package/src/nodes/lighting/PointLightNode.js +60 -25
- package/src/nodes/lighting/PointShadowNode.js +325 -0
- package/src/nodes/lighting/ProjectorLightNode.js +91 -0
- package/src/nodes/lighting/RectAreaLightNode.js +50 -14
- package/src/nodes/lighting/ShadowBaseNode.js +81 -0
- package/src/nodes/lighting/ShadowFilterNode.js +264 -0
- package/src/nodes/lighting/ShadowNode.js +867 -0
- package/src/nodes/lighting/SpotLightNode.js +99 -18
- package/src/nodes/materialx/MaterialXNodes.js +131 -2
- package/src/nodes/materialx/lib/mx_noise.js +166 -2
- package/src/nodes/math/BitcastNode.js +156 -0
- package/src/nodes/math/BitcountNode.js +433 -0
- package/src/nodes/math/ConditionalNode.js +110 -21
- package/src/nodes/math/Hash.js +8 -0
- package/src/nodes/math/MathNode.js +820 -97
- package/src/nodes/math/MathUtils.js +47 -1
- package/src/nodes/math/OperatorNode.js +517 -84
- package/src/nodes/math/PackFloatNode.js +98 -0
- package/src/nodes/math/TriNoise3D.js +17 -7
- package/src/nodes/math/UnpackFloatNode.js +96 -0
- package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
- package/src/nodes/parsers/GLSLNodeParser.js +11 -0
- package/src/nodes/pmrem/PMREMNode.js +180 -23
- package/src/nodes/pmrem/PMREMUtils.js +114 -5
- package/src/nodes/procedural/Checker.js +8 -0
- package/src/nodes/shapes/Shapes.js +33 -0
- package/src/nodes/tsl/TSLBase.js +10 -4
- package/src/nodes/tsl/TSLCore.js +732 -160
- package/src/nodes/utils/ArrayElementNode.js +55 -4
- package/src/nodes/utils/ConvertNode.js +31 -0
- package/src/nodes/utils/CubeMapNode.js +79 -2
- package/src/nodes/utils/DebugNode.js +83 -0
- package/src/nodes/utils/Discard.js +18 -2
- package/src/nodes/utils/EquirectUV.js +27 -0
- package/src/nodes/utils/EventNode.js +118 -0
- package/src/nodes/utils/FlipNode.js +38 -0
- package/src/nodes/utils/FunctionOverloadingNode.js +91 -22
- package/src/nodes/utils/JoinNode.js +57 -4
- package/src/nodes/utils/LoopNode.js +193 -55
- package/src/nodes/utils/MatcapUV.js +22 -0
- package/src/nodes/utils/MaxMipLevelNode.js +49 -1
- package/src/nodes/utils/MemberNode.js +120 -0
- package/src/nodes/utils/Oscillators.js +41 -0
- package/src/nodes/utils/Packing.js +30 -1
- package/src/nodes/utils/PostProcessingUtils.js +154 -0
- package/src/nodes/utils/RTTNode.js +165 -9
- package/src/nodes/utils/ReflectorNode.js +407 -21
- package/src/nodes/utils/RemapNode.js +81 -2
- package/src/nodes/utils/RotateNode.js +41 -1
- package/src/nodes/utils/SampleNode.js +91 -0
- package/src/nodes/utils/SetNode.js +44 -1
- package/src/nodes/utils/SplitNode.js +66 -3
- package/src/nodes/utils/SpriteSheetUV.js +35 -0
- package/src/nodes/utils/SpriteUtils.js +16 -0
- package/src/nodes/utils/StorageArrayElementNode.js +56 -3
- package/src/nodes/utils/Timer.js +26 -0
- package/src/nodes/utils/TriplanarTextures.js +65 -0
- package/src/nodes/utils/UVUtils.js +48 -0
- package/src/nodes/utils/ViewportUtils.js +12 -0
- package/src/objects/BatchedMesh.js +798 -309
- package/src/objects/Bone.js +24 -0
- package/src/objects/ClippingGroup.js +68 -0
- package/src/objects/Group.js +24 -0
- package/src/objects/InstancedMesh.js +131 -2
- package/src/objects/LOD.js +99 -5
- package/src/objects/Line.js +90 -7
- package/src/objects/LineLoop.js +20 -0
- package/src/objects/LineSegments.js +20 -1
- package/src/objects/Mesh.js +84 -0
- package/src/objects/Points.js +60 -0
- package/src/objects/Skeleton.js +120 -5
- package/src/objects/SkinnedMesh.js +102 -6
- package/src/objects/Sprite.js +65 -1
- package/src/renderers/WebGL3DRenderTarget.js +26 -0
- package/src/renderers/WebGLArrayRenderTarget.js +26 -0
- package/src/renderers/WebGLCubeRenderTarget.js +41 -5
- package/src/renderers/WebGLRenderTarget.js +19 -0
- package/src/renderers/WebGLRenderer.js +1016 -278
- package/src/renderers/common/Animation.js +123 -14
- package/src/renderers/common/Attributes.js +41 -1
- package/src/renderers/common/Backend.js +623 -44
- package/src/renderers/common/Background.js +99 -16
- package/src/renderers/common/BindGroup.js +37 -2
- package/src/renderers/common/Binding.js +46 -0
- package/src/renderers/common/Bindings.js +211 -20
- package/src/renderers/common/BlendMode.js +143 -0
- package/src/renderers/common/Buffer.js +89 -0
- package/src/renderers/common/BufferUtils.js +25 -0
- package/src/renderers/common/BundleGroup.js +57 -0
- package/src/renderers/common/CanvasTarget.js +341 -0
- package/src/renderers/common/ChainMap.js +73 -10
- package/src/renderers/common/ClippingContext.js +172 -87
- package/src/renderers/common/Color4.js +40 -0
- package/src/renderers/common/ComputePipeline.js +24 -0
- package/src/renderers/common/Constants.js +2 -1
- package/src/renderers/common/CubeRenderTarget.js +77 -7
- package/src/renderers/common/DataMap.js +37 -1
- package/src/renderers/common/Geometries.js +163 -14
- package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
- package/src/renderers/common/Info.js +81 -36
- package/src/renderers/common/InspectorBase.js +146 -0
- package/src/renderers/common/Lighting.js +57 -0
- package/src/renderers/common/Pipeline.js +22 -0
- package/src/renderers/common/Pipelines.js +150 -7
- package/src/renderers/common/PostProcessing.js +22 -84
- package/src/renderers/common/ProgrammableStage.js +60 -2
- package/src/renderers/common/QuadMesh.js +63 -6
- package/src/renderers/common/RenderBundle.js +14 -8
- package/src/renderers/common/RenderBundles.js +40 -10
- package/src/renderers/common/RenderContext.js +219 -4
- package/src/renderers/common/RenderContexts.js +54 -17
- package/src/renderers/common/RenderList.js +233 -24
- package/src/renderers/common/RenderLists.js +46 -6
- package/src/renderers/common/RenderObject.js +548 -46
- package/src/renderers/common/RenderObjectPipeline.js +40 -0
- package/src/renderers/common/RenderObjects.js +133 -15
- package/src/renderers/common/RenderPipeline.js +216 -6
- package/src/renderers/common/Renderer.js +2155 -332
- package/src/renderers/common/RendererUtils.js +200 -0
- package/src/renderers/common/SampledTexture.js +99 -39
- package/src/renderers/common/Sampler.js +148 -1
- package/src/renderers/common/Storage3DTexture.js +100 -0
- package/src/renderers/common/StorageArrayTexture.js +84 -0
- package/src/renderers/common/StorageBuffer.js +38 -2
- package/src/renderers/common/StorageBufferAttribute.js +31 -2
- package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
- package/src/renderers/common/StorageTexture.js +65 -0
- package/src/renderers/common/Textures.js +273 -57
- package/src/renderers/common/TimestampQueryPool.js +163 -0
- package/src/renderers/common/Uniform.js +233 -3
- package/src/renderers/common/UniformBuffer.js +19 -0
- package/src/renderers/common/UniformsGroup.js +235 -26
- package/src/renderers/common/XRManager.js +1677 -0
- package/src/renderers/common/XRRenderTarget.js +91 -0
- package/src/renderers/common/extras/PMREMGenerator.js +371 -108
- package/src/renderers/common/nodes/NodeBuilderState.js +100 -6
- package/src/renderers/common/nodes/NodeLibrary.js +95 -17
- package/src/renderers/common/nodes/NodeManager.js +852 -0
- package/src/renderers/common/nodes/NodeSampledTexture.js +84 -8
- package/src/renderers/common/nodes/NodeSampler.js +41 -1
- package/src/renderers/common/nodes/NodeStorageBuffer.js +48 -3
- package/src/renderers/common/nodes/NodeUniform.js +285 -2
- package/src/renderers/common/nodes/NodeUniformBuffer.js +81 -0
- package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
- package/src/renderers/shaders/DFGLUTData.js +49 -0
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +8 -10
- package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
- package/src/renderers/shaders/ShaderChunk/common.glsl.js +0 -12
- package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +7 -11
- package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +5 -2
- package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +6 -2
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +154 -59
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +20 -4
- package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +230 -181
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk.js +3 -3
- package/src/renderers/shaders/ShaderLib/background.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +14 -2
- package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +1 -2
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
- package/src/renderers/shaders/ShaderLib.js +7 -5
- package/src/renderers/shaders/UniformsLib.js +2 -7
- package/src/renderers/shaders/UniformsUtils.js +21 -2
- package/src/renderers/webgl/WebGLAttributes.js +4 -0
- package/src/renderers/webgl/WebGLBackground.js +30 -5
- package/src/renderers/webgl/WebGLBindingStates.js +99 -27
- package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLCapabilities.js +7 -14
- package/src/renderers/webgl/WebGLEnvironments.js +228 -0
- package/src/renderers/webgl/WebGLExtensions.js +2 -25
- package/src/renderers/webgl/WebGLGeometries.js +10 -35
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLInfo.js +3 -1
- package/src/renderers/webgl/WebGLLights.js +18 -1
- package/src/renderers/webgl/WebGLMaterials.js +12 -0
- package/src/renderers/webgl/WebGLObjects.js +3 -1
- package/src/renderers/webgl/WebGLOutput.js +267 -0
- package/src/renderers/webgl/WebGLProgram.js +87 -148
- package/src/renderers/webgl/WebGLPrograms.js +53 -51
- package/src/renderers/webgl/WebGLRenderLists.js +15 -0
- package/src/renderers/webgl/WebGLShadowMap.js +204 -28
- package/src/renderers/webgl/WebGLState.js +88 -56
- package/src/renderers/webgl/WebGLTextures.js +293 -59
- package/src/renderers/webgl/WebGLUniforms.js +40 -3
- package/src/renderers/webgl/WebGLUniformsGroups.js +5 -3
- package/src/renderers/webgl/WebGLUtils.js +7 -5
- package/src/renderers/webgl-fallback/WebGLBackend.js +1416 -293
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +5 -10
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +785 -92
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +62 -1
- package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
- package/src/renderers/webgl-fallback/utils/WebGLConstants.js +3 -3
- package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +584 -20
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +468 -80
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +396 -0
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +72 -24
- package/src/renderers/webgpu/WebGPUBackend.js +1517 -428
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +31 -4
- package/src/renderers/webgpu/WebGPURenderer.js +55 -4
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +23 -16
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +37 -42
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +1335 -241
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +32 -4
- package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +144 -20
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +460 -116
- package/src/renderers/webgpu/utils/WebGPUConstants.js +17 -4
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +283 -69
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +225 -178
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +583 -191
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +310 -0
- package/src/renderers/webgpu/utils/WebGPUUtils.js +150 -28
- package/src/renderers/webxr/WebXRController.js +87 -2
- package/src/renderers/webxr/WebXRDepthSensing.js +52 -7
- package/src/renderers/webxr/WebXRManager.js +275 -15
- package/src/scenes/Fog.js +60 -0
- package/src/scenes/FogExp2.js +51 -0
- package/src/scenes/Scene.js +88 -0
- package/src/textures/CanvasTexture.js +28 -0
- package/src/textures/CompressedArrayTexture.js +57 -0
- package/src/textures/CompressedCubeTexture.js +29 -0
- package/src/textures/CompressedTexture.js +64 -6
- package/src/textures/CubeDepthTexture.js +76 -0
- package/src/textures/CubeTexture.js +52 -4
- package/src/textures/Data3DTexture.js +79 -2
- package/src/textures/DataArrayTexture.js +93 -0
- package/src/textures/DataTexture.js +65 -0
- package/src/textures/DepthTexture.js +59 -11
- package/src/textures/ExternalTexture.js +56 -0
- package/src/textures/FramebufferTexture.js +62 -0
- package/src/textures/Source.js +106 -4
- package/src/textures/Texture.js +488 -6
- package/src/textures/VideoFrameTexture.js +72 -0
- package/src/textures/VideoTexture.js +78 -6
- package/src/utils.js +322 -3
- package/examples/jsm/animation/MMDAnimationHelper.js +0 -1207
- package/examples/jsm/animation/MMDPhysics.js +0 -1406
- package/examples/jsm/cameras/CinematicCamera.js +0 -208
- package/examples/jsm/effects/PeppersGhostEffect.js +0 -153
- package/examples/jsm/exporters/MMDExporter.js +0 -217
- package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -174
- package/examples/jsm/geometries/ParametricGeometries.js +0 -254
- package/examples/jsm/libs/mmdparser.module.js +0 -11530
- package/examples/jsm/loaders/GLTFLoaderAnimationPointer.js +0 -729
- package/examples/jsm/loaders/MMDLoader.js +0 -2295
- package/examples/jsm/loaders/RGBMLoader.js +0 -1081
- package/examples/jsm/materials/MeshGouraudMaterial.js +0 -432
- package/examples/jsm/materials/MeshPostProcessingMaterial.js +0 -144
- package/examples/jsm/misc/Timer.js +0 -128
- package/examples/jsm/objects/InstancedPoints.js +0 -21
- package/examples/jsm/shaders/GodRaysShader.js +0 -321
- package/examples/jsm/shaders/MMDToonShader.js +0 -134
- package/src/materials/nodes/InstancedPointsNodeMaterial.js +0 -156
- package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -24
- package/src/nodes/accessors/SceneNode.js +0 -55
- package/src/nodes/code/ScriptableNode.js +0 -505
- package/src/nodes/code/ScriptableValueNode.js +0 -170
- package/src/nodes/core/CacheNode.js +0 -50
- package/src/nodes/core/UniformGroup.js +0 -13
- package/src/nodes/display/AfterImageNode.js +0 -158
- package/src/nodes/display/AnaglyphPassNode.js +0 -67
- package/src/nodes/display/AnamorphicNode.js +0 -151
- package/src/nodes/display/BlendMode.js +0 -54
- package/src/nodes/display/BloomNode.js +0 -341
- package/src/nodes/display/DenoiseNode.js +0 -204
- package/src/nodes/display/DepthOfFieldNode.js +0 -124
- package/src/nodes/display/DotScreenNode.js +0 -66
- package/src/nodes/display/FXAANode.js +0 -332
- package/src/nodes/display/FilmNode.js +0 -56
- package/src/nodes/display/GTAONode.js +0 -331
- package/src/nodes/display/GaussianBlurNode.js +0 -213
- package/src/nodes/display/Lut3DNode.js +0 -57
- package/src/nodes/display/MotionBlur.js +0 -25
- package/src/nodes/display/ParallaxBarrierPassNode.js +0 -58
- package/src/nodes/display/PixelationPassNode.js +0 -213
- package/src/nodes/display/PosterizeNode.js +0 -33
- package/src/nodes/display/RGBShiftNode.js +0 -53
- package/src/nodes/display/StereoCompositePassNode.js +0 -110
- package/src/nodes/display/TransitionNode.js +0 -80
- package/src/nodes/fog/FogExp2Node.js +0 -35
- package/src/nodes/fog/FogNode.js +0 -50
- package/src/nodes/fog/FogRangeNode.js +0 -36
- package/src/nodes/functions/BSDF/DFGApprox.js +0 -30
- package/src/nodes/utils/EquirectUVNode.js +0 -36
- package/src/nodes/utils/MatcapUVNode.js +0 -33
- package/src/nodes/utils/OscNode.js +0 -85
- package/src/nodes/utils/SpriteSheetUVNode.js +0 -45
- package/src/nodes/utils/TimerNode.js +0 -97
- package/src/nodes/utils/TriplanarTexturesNode.js +0 -64
- package/src/renderers/common/nodes/Nodes.js +0 -534
- package/src/renderers/webgl/WebGLCubeMaps.js +0 -99
- package/src/renderers/webgl/WebGLCubeUVMaps.js +0 -136
|
@@ -0,0 +1,1852 @@
|
|
|
1
|
+
const textDecoder = new TextDecoder();
|
|
2
|
+
|
|
3
|
+
// Pre-computed half-float exponent lookup table for fast conversion
|
|
4
|
+
// Math.pow(2, exp - 15) for exp = 0..31
|
|
5
|
+
const HALF_EXPONENT_TABLE = new Float32Array( 32 );
|
|
6
|
+
for ( let i = 0; i < 32; i ++ ) {
|
|
7
|
+
|
|
8
|
+
HALF_EXPONENT_TABLE[ i ] = Math.pow( 2, i - 15 );
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Pre-computed constant for denormalized half-floats: 2^-14
|
|
13
|
+
const HALF_DENORM_SCALE = Math.pow( 2, - 14 );
|
|
14
|
+
|
|
15
|
+
// Type enum values from crateDataTypes.h
|
|
16
|
+
const TypeEnum = {
|
|
17
|
+
Invalid: 0,
|
|
18
|
+
Bool: 1,
|
|
19
|
+
UChar: 2,
|
|
20
|
+
Int: 3,
|
|
21
|
+
UInt: 4,
|
|
22
|
+
Int64: 5,
|
|
23
|
+
UInt64: 6,
|
|
24
|
+
Half: 7,
|
|
25
|
+
Float: 8,
|
|
26
|
+
Double: 9,
|
|
27
|
+
String: 10,
|
|
28
|
+
Token: 11,
|
|
29
|
+
AssetPath: 12,
|
|
30
|
+
Matrix2d: 13,
|
|
31
|
+
Matrix3d: 14,
|
|
32
|
+
Matrix4d: 15,
|
|
33
|
+
Quatd: 16,
|
|
34
|
+
Quatf: 17,
|
|
35
|
+
Quath: 18,
|
|
36
|
+
Vec2d: 19,
|
|
37
|
+
Vec2f: 20,
|
|
38
|
+
Vec2h: 21,
|
|
39
|
+
Vec2i: 22,
|
|
40
|
+
Vec3d: 23,
|
|
41
|
+
Vec3f: 24,
|
|
42
|
+
Vec3h: 25,
|
|
43
|
+
Vec3i: 26,
|
|
44
|
+
Vec4d: 27,
|
|
45
|
+
Vec4f: 28,
|
|
46
|
+
Vec4h: 29,
|
|
47
|
+
Vec4i: 30,
|
|
48
|
+
Dictionary: 31,
|
|
49
|
+
TokenListOp: 32,
|
|
50
|
+
StringListOp: 33,
|
|
51
|
+
PathListOp: 34,
|
|
52
|
+
ReferenceListOp: 35,
|
|
53
|
+
IntListOp: 36,
|
|
54
|
+
Int64ListOp: 37,
|
|
55
|
+
UIntListOp: 38,
|
|
56
|
+
UInt64ListOp: 39,
|
|
57
|
+
PathVector: 40,
|
|
58
|
+
TokenVector: 41,
|
|
59
|
+
Specifier: 42,
|
|
60
|
+
Permission: 43,
|
|
61
|
+
Variability: 44,
|
|
62
|
+
VariantSelectionMap: 45,
|
|
63
|
+
TimeSamples: 46,
|
|
64
|
+
Payload: 47,
|
|
65
|
+
DoubleVector: 48,
|
|
66
|
+
LayerOffsetVector: 49,
|
|
67
|
+
StringVector: 50,
|
|
68
|
+
ValueBlock: 51,
|
|
69
|
+
Value: 52,
|
|
70
|
+
UnregisteredValue: 53,
|
|
71
|
+
UnregisteredValueListOp: 54,
|
|
72
|
+
PayloadListOp: 55,
|
|
73
|
+
TimeCode: 56,
|
|
74
|
+
PathExpression: 57,
|
|
75
|
+
Relocates: 58,
|
|
76
|
+
Spline: 59,
|
|
77
|
+
AnimationBlock: 60
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Field set terminator marker
|
|
81
|
+
const FIELD_SET_TERMINATOR = 0xFFFFFFFF;
|
|
82
|
+
|
|
83
|
+
// Float compression type codes
|
|
84
|
+
const FLOAT_COMPRESSION_INT = 0x69; // 'i' - compressed as integers
|
|
85
|
+
const FLOAT_COMPRESSION_LUT = 0x74; // 't' - lookup table
|
|
86
|
+
|
|
87
|
+
// ============================================================================
|
|
88
|
+
// LZ4 Decompression (minimal implementation for USD)
|
|
89
|
+
// Based on LZ4 block format specification
|
|
90
|
+
// ============================================================================
|
|
91
|
+
|
|
92
|
+
function lz4DecompressBlock( input, inputOffset, inputEnd, output, outputOffset, outputEnd ) {
|
|
93
|
+
|
|
94
|
+
while ( inputOffset < inputEnd ) {
|
|
95
|
+
|
|
96
|
+
// Read token
|
|
97
|
+
const token = input[ inputOffset ++ ];
|
|
98
|
+
if ( inputOffset > inputEnd ) break;
|
|
99
|
+
|
|
100
|
+
// Literal length
|
|
101
|
+
let literalLength = token >> 4;
|
|
102
|
+
if ( literalLength === 15 ) {
|
|
103
|
+
|
|
104
|
+
let b;
|
|
105
|
+
do {
|
|
106
|
+
|
|
107
|
+
if ( inputOffset >= inputEnd ) break;
|
|
108
|
+
b = input[ inputOffset ++ ];
|
|
109
|
+
literalLength += b;
|
|
110
|
+
|
|
111
|
+
} while ( b === 255 && inputOffset < inputEnd );
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Copy literals
|
|
116
|
+
if ( literalLength > 0 ) {
|
|
117
|
+
|
|
118
|
+
if ( inputOffset + literalLength > inputEnd ) {
|
|
119
|
+
|
|
120
|
+
literalLength = inputEnd - inputOffset;
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
for ( let i = 0; i < literalLength; i ++ ) {
|
|
125
|
+
|
|
126
|
+
if ( outputOffset >= outputEnd ) break;
|
|
127
|
+
output[ outputOffset ++ ] = input[ inputOffset ++ ];
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Check if we're at the end (last sequence has no match)
|
|
134
|
+
if ( inputOffset >= inputEnd ) break;
|
|
135
|
+
|
|
136
|
+
// Read match offset (little-endian 16-bit)
|
|
137
|
+
if ( inputOffset + 2 > inputEnd ) break;
|
|
138
|
+
const matchOffset = input[ inputOffset ++ ] | ( input[ inputOffset ++ ] << 8 );
|
|
139
|
+
|
|
140
|
+
if ( matchOffset === 0 ) {
|
|
141
|
+
|
|
142
|
+
// Invalid offset
|
|
143
|
+
break;
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Match length
|
|
148
|
+
let matchLength = ( token & 0x0F ) + 4;
|
|
149
|
+
if ( matchLength === 19 ) {
|
|
150
|
+
|
|
151
|
+
let b;
|
|
152
|
+
do {
|
|
153
|
+
|
|
154
|
+
if ( inputOffset >= inputEnd ) break;
|
|
155
|
+
b = input[ inputOffset ++ ];
|
|
156
|
+
matchLength += b;
|
|
157
|
+
|
|
158
|
+
} while ( b === 255 && inputOffset < inputEnd );
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Copy match (byte-by-byte to handle overlapping)
|
|
163
|
+
const matchPos = outputOffset - matchOffset;
|
|
164
|
+
if ( matchPos < 0 ) {
|
|
165
|
+
|
|
166
|
+
// Invalid match position
|
|
167
|
+
break;
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
for ( let i = 0; i < matchLength; i ++ ) {
|
|
172
|
+
|
|
173
|
+
if ( outputOffset >= outputEnd ) break;
|
|
174
|
+
output[ outputOffset ++ ] = output[ matchPos + i ];
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return outputOffset;
|
|
181
|
+
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// USD uses TfFastCompression which wraps LZ4 with chunk headers
|
|
185
|
+
function decompressLZ4( input, uncompressedSize ) {
|
|
186
|
+
|
|
187
|
+
// TfFastCompression format (used by OpenUSD):
|
|
188
|
+
// Single chunk (byte 0 == 0): [0] + LZ4 data
|
|
189
|
+
// Multi chunk (byte 0 > 0): [numChunks] + [compressedSizes...] + [chunkData...]
|
|
190
|
+
|
|
191
|
+
const output = new Uint8Array( uncompressedSize );
|
|
192
|
+
const numChunks = input[ 0 ];
|
|
193
|
+
|
|
194
|
+
if ( numChunks === 0 ) {
|
|
195
|
+
|
|
196
|
+
// Single chunk - all remaining bytes are LZ4 compressed
|
|
197
|
+
lz4DecompressBlock( input, 1, input.length, output, 0, uncompressedSize );
|
|
198
|
+
return output;
|
|
199
|
+
|
|
200
|
+
} else {
|
|
201
|
+
|
|
202
|
+
// Multiple chunks - each chunk decompresses to max 65536 bytes
|
|
203
|
+
const CHUNK_SIZE = 65536;
|
|
204
|
+
|
|
205
|
+
// First, read all chunk sizes
|
|
206
|
+
let headerOffset = 1;
|
|
207
|
+
const compressedSizes = [];
|
|
208
|
+
|
|
209
|
+
for ( let i = 0; i < numChunks; i ++ ) {
|
|
210
|
+
|
|
211
|
+
const size = ( input[ headerOffset ] |
|
|
212
|
+
( input[ headerOffset + 1 ] << 8 ) |
|
|
213
|
+
( input[ headerOffset + 2 ] << 16 ) |
|
|
214
|
+
( input[ headerOffset + 3 ] << 24 ) ) >>> 0;
|
|
215
|
+
compressedSizes.push( size );
|
|
216
|
+
headerOffset += 4;
|
|
217
|
+
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Decompress each chunk
|
|
221
|
+
let inputOffset = headerOffset;
|
|
222
|
+
let outputOffset = 0;
|
|
223
|
+
|
|
224
|
+
for ( let i = 0; i < numChunks; i ++ ) {
|
|
225
|
+
|
|
226
|
+
const chunkCompressedSize = compressedSizes[ i ];
|
|
227
|
+
const chunkOutputSize = Math.min( CHUNK_SIZE, uncompressedSize - outputOffset );
|
|
228
|
+
|
|
229
|
+
lz4DecompressBlock(
|
|
230
|
+
input, inputOffset, inputOffset + chunkCompressedSize,
|
|
231
|
+
output, outputOffset, outputOffset + chunkOutputSize
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
inputOffset += chunkCompressedSize;
|
|
235
|
+
outputOffset += chunkOutputSize;
|
|
236
|
+
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return output;
|
|
240
|
+
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// ============================================================================
|
|
246
|
+
// Integer Decompression (USD-specific delta + variable-width encoding)
|
|
247
|
+
// ============================================================================
|
|
248
|
+
|
|
249
|
+
function decompressIntegers32( compressedData, numInts ) {
|
|
250
|
+
|
|
251
|
+
// First decompress with LZ4
|
|
252
|
+
const encodedSize = numInts * 4 + ( ( numInts * 2 + 7 ) >> 3 ) + 4;
|
|
253
|
+
const encoded = decompressLZ4( new Uint8Array( compressedData ), encodedSize );
|
|
254
|
+
|
|
255
|
+
// Then decode
|
|
256
|
+
return decodeIntegers32( encoded, numInts );
|
|
257
|
+
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function decodeIntegers32( data, numInts ) {
|
|
261
|
+
|
|
262
|
+
const view = new DataView( data.buffer, data.byteOffset, data.byteLength );
|
|
263
|
+
let offset = 0;
|
|
264
|
+
|
|
265
|
+
// Read common value (signed 32-bit)
|
|
266
|
+
const commonValue = view.getInt32( offset, true );
|
|
267
|
+
offset += 4;
|
|
268
|
+
|
|
269
|
+
const numCodesBytes = ( numInts * 2 + 7 ) >> 3;
|
|
270
|
+
const codesStart = offset;
|
|
271
|
+
const vintsStart = offset + numCodesBytes;
|
|
272
|
+
|
|
273
|
+
const result = new Int32Array( numInts );
|
|
274
|
+
let prevVal = 0;
|
|
275
|
+
let codesOffset = codesStart;
|
|
276
|
+
let vintsOffset = vintsStart;
|
|
277
|
+
|
|
278
|
+
for ( let i = 0; i < numInts; ) {
|
|
279
|
+
|
|
280
|
+
const codeByte = data[ codesOffset ++ ];
|
|
281
|
+
|
|
282
|
+
for ( let j = 0; j < 4 && i < numInts; j ++, i ++ ) {
|
|
283
|
+
|
|
284
|
+
const code = ( codeByte >> ( j * 2 ) ) & 3;
|
|
285
|
+
let delta = 0;
|
|
286
|
+
|
|
287
|
+
switch ( code ) {
|
|
288
|
+
|
|
289
|
+
case 0: // Common value
|
|
290
|
+
delta = commonValue;
|
|
291
|
+
break;
|
|
292
|
+
case 1: // 8-bit signed
|
|
293
|
+
delta = view.getInt8( vintsOffset );
|
|
294
|
+
vintsOffset += 1;
|
|
295
|
+
break;
|
|
296
|
+
case 2: // 16-bit signed
|
|
297
|
+
delta = view.getInt16( vintsOffset, true );
|
|
298
|
+
vintsOffset += 2;
|
|
299
|
+
break;
|
|
300
|
+
case 3: // 32-bit signed
|
|
301
|
+
delta = view.getInt32( vintsOffset, true );
|
|
302
|
+
vintsOffset += 4;
|
|
303
|
+
break;
|
|
304
|
+
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
prevVal += delta;
|
|
308
|
+
result[ i ] = prevVal;
|
|
309
|
+
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return result;
|
|
315
|
+
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// ============================================================================
|
|
319
|
+
// Binary Reader Helper
|
|
320
|
+
// ============================================================================
|
|
321
|
+
|
|
322
|
+
class BinaryReader {
|
|
323
|
+
|
|
324
|
+
constructor( buffer ) {
|
|
325
|
+
|
|
326
|
+
this.buffer = buffer;
|
|
327
|
+
this.view = new DataView( buffer );
|
|
328
|
+
this.offset = 0;
|
|
329
|
+
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
seek( offset ) {
|
|
333
|
+
|
|
334
|
+
this.offset = offset;
|
|
335
|
+
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
tell() {
|
|
339
|
+
|
|
340
|
+
return this.offset;
|
|
341
|
+
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
readUint8() {
|
|
345
|
+
|
|
346
|
+
const value = this.view.getUint8( this.offset );
|
|
347
|
+
this.offset += 1;
|
|
348
|
+
return value;
|
|
349
|
+
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
readInt8() {
|
|
353
|
+
|
|
354
|
+
const value = this.view.getInt8( this.offset );
|
|
355
|
+
this.offset += 1;
|
|
356
|
+
return value;
|
|
357
|
+
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
readUint16() {
|
|
361
|
+
|
|
362
|
+
const value = this.view.getUint16( this.offset, true );
|
|
363
|
+
this.offset += 2;
|
|
364
|
+
return value;
|
|
365
|
+
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
readInt16() {
|
|
369
|
+
|
|
370
|
+
const value = this.view.getInt16( this.offset, true );
|
|
371
|
+
this.offset += 2;
|
|
372
|
+
return value;
|
|
373
|
+
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
readUint32() {
|
|
377
|
+
|
|
378
|
+
const value = this.view.getUint32( this.offset, true );
|
|
379
|
+
this.offset += 4;
|
|
380
|
+
return value;
|
|
381
|
+
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
readInt32() {
|
|
385
|
+
|
|
386
|
+
const value = this.view.getInt32( this.offset, true );
|
|
387
|
+
this.offset += 4;
|
|
388
|
+
return value;
|
|
389
|
+
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
readUint64() {
|
|
393
|
+
|
|
394
|
+
const lo = this.view.getUint32( this.offset, true );
|
|
395
|
+
const hi = this.view.getUint32( this.offset + 4, true );
|
|
396
|
+
this.offset += 8;
|
|
397
|
+
// For values that fit in Number, this is safe
|
|
398
|
+
return hi * 0x100000000 + lo;
|
|
399
|
+
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
readInt64() {
|
|
403
|
+
|
|
404
|
+
const lo = this.view.getUint32( this.offset, true );
|
|
405
|
+
const hi = this.view.getInt32( this.offset + 4, true );
|
|
406
|
+
this.offset += 8;
|
|
407
|
+
return hi * 0x100000000 + lo;
|
|
408
|
+
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
readFloat32() {
|
|
412
|
+
|
|
413
|
+
const value = this.view.getFloat32( this.offset, true );
|
|
414
|
+
this.offset += 4;
|
|
415
|
+
return value;
|
|
416
|
+
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
readFloat64() {
|
|
420
|
+
|
|
421
|
+
const value = this.view.getFloat64( this.offset, true );
|
|
422
|
+
this.offset += 8;
|
|
423
|
+
return value;
|
|
424
|
+
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
readBytes( length ) {
|
|
428
|
+
|
|
429
|
+
const bytes = new Uint8Array( this.buffer, this.offset, length );
|
|
430
|
+
this.offset += length;
|
|
431
|
+
return bytes;
|
|
432
|
+
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
readString( length ) {
|
|
436
|
+
|
|
437
|
+
const bytes = this.readBytes( length );
|
|
438
|
+
let end = 0;
|
|
439
|
+
while ( end < length && bytes[ end ] !== 0 ) end ++;
|
|
440
|
+
return textDecoder.decode( bytes.subarray( 0, end ) );
|
|
441
|
+
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// ============================================================================
|
|
447
|
+
// ValueRep - 64-bit packed value representation
|
|
448
|
+
// ============================================================================
|
|
449
|
+
|
|
450
|
+
class ValueRep {
|
|
451
|
+
|
|
452
|
+
constructor( lo, hi ) {
|
|
453
|
+
|
|
454
|
+
this.lo = lo; // Lower 32 bits
|
|
455
|
+
this.hi = hi; // Upper 32 bits
|
|
456
|
+
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
get isArray() {
|
|
460
|
+
|
|
461
|
+
return ( this.hi & 0x80000000 ) !== 0;
|
|
462
|
+
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
get isInlined() {
|
|
466
|
+
|
|
467
|
+
return ( this.hi & 0x40000000 ) !== 0;
|
|
468
|
+
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
get isCompressed() {
|
|
472
|
+
|
|
473
|
+
return ( this.hi & 0x20000000 ) !== 0;
|
|
474
|
+
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
get typeEnum() {
|
|
478
|
+
|
|
479
|
+
return ( this.hi >> 16 ) & 0xFF;
|
|
480
|
+
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
get payload() {
|
|
484
|
+
|
|
485
|
+
// 48-bit payload: lo (32 bits) + hi lower 16 bits
|
|
486
|
+
// Note: JavaScript numbers are IEEE 754 doubles with 53 bits of integer precision,
|
|
487
|
+
// so 48-bit values are represented exactly without loss of precision.
|
|
488
|
+
return this.lo + ( ( this.hi & 0xFFFF ) * 0x100000000 );
|
|
489
|
+
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
getInlinedValue() {
|
|
493
|
+
|
|
494
|
+
// For inlined scalars, the value is in the lower 32 bits
|
|
495
|
+
return this.lo;
|
|
496
|
+
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// ============================================================================
|
|
502
|
+
// USDC Parser
|
|
503
|
+
// ============================================================================
|
|
504
|
+
|
|
505
|
+
class USDCParser {
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Parse USDC file and return raw spec data without building Three.js scene.
|
|
509
|
+
* Used by USDComposer for unified scene composition.
|
|
510
|
+
*/
|
|
511
|
+
parseData( buffer ) {
|
|
512
|
+
|
|
513
|
+
this.buffer = buffer instanceof ArrayBuffer ? buffer : buffer.buffer;
|
|
514
|
+
this.reader = new BinaryReader( this.buffer );
|
|
515
|
+
this.version = { major: 0, minor: 0, patch: 0 };
|
|
516
|
+
|
|
517
|
+
this._conversionBuffer = new ArrayBuffer( 4 );
|
|
518
|
+
this._conversionView = new DataView( this._conversionBuffer );
|
|
519
|
+
|
|
520
|
+
this._readBootstrap();
|
|
521
|
+
this._readTOC();
|
|
522
|
+
this._readTokens();
|
|
523
|
+
this._readStrings();
|
|
524
|
+
this._readFields();
|
|
525
|
+
this._readFieldSets();
|
|
526
|
+
this._readPaths();
|
|
527
|
+
this._readSpecs();
|
|
528
|
+
|
|
529
|
+
// Build specsByPath without building scene
|
|
530
|
+
this.specsByPath = {};
|
|
531
|
+
|
|
532
|
+
for ( const spec of this.specs ) {
|
|
533
|
+
|
|
534
|
+
const path = this.paths[ spec.pathIndex ];
|
|
535
|
+
if ( ! path ) continue;
|
|
536
|
+
|
|
537
|
+
const fields = this._getFieldsForSpec( spec );
|
|
538
|
+
this.specsByPath[ path ] = { specType: spec.specType, fields };
|
|
539
|
+
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
return { specsByPath: this.specsByPath };
|
|
543
|
+
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
_readBootstrap() {
|
|
547
|
+
|
|
548
|
+
const reader = this.reader;
|
|
549
|
+
reader.seek( 0 );
|
|
550
|
+
|
|
551
|
+
// Read magic "PXR-USDC"
|
|
552
|
+
const magic = reader.readString( 8 );
|
|
553
|
+
if ( magic !== 'PXR-USDC' ) {
|
|
554
|
+
|
|
555
|
+
throw new Error( 'Not a valid USDC file' );
|
|
556
|
+
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// Read version
|
|
560
|
+
this.version.major = reader.readUint8();
|
|
561
|
+
this.version.minor = reader.readUint8();
|
|
562
|
+
this.version.patch = reader.readUint8();
|
|
563
|
+
reader.readBytes( 5 ); // Skip remaining version bytes
|
|
564
|
+
|
|
565
|
+
// Read TOC offset
|
|
566
|
+
this.tocOffset = reader.readUint64();
|
|
567
|
+
|
|
568
|
+
// Skip reserved bytes (rest of 128-byte header)
|
|
569
|
+
// Already at offset 24, skip to end of bootstrap (88 bytes total for bootstrap struct)
|
|
570
|
+
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
_readTOC() {
|
|
574
|
+
|
|
575
|
+
const reader = this.reader;
|
|
576
|
+
reader.seek( this.tocOffset );
|
|
577
|
+
|
|
578
|
+
// Read number of sections
|
|
579
|
+
const numSections = reader.readUint64();
|
|
580
|
+
this.sections = {};
|
|
581
|
+
|
|
582
|
+
for ( let i = 0; i < numSections; i ++ ) {
|
|
583
|
+
|
|
584
|
+
const name = reader.readString( 16 );
|
|
585
|
+
const start = reader.readUint64();
|
|
586
|
+
const size = reader.readUint64();
|
|
587
|
+
|
|
588
|
+
this.sections[ name ] = { start, size };
|
|
589
|
+
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
_readTokens() {
|
|
595
|
+
|
|
596
|
+
const section = this.sections[ 'TOKENS' ];
|
|
597
|
+
if ( ! section ) return;
|
|
598
|
+
|
|
599
|
+
const reader = this.reader;
|
|
600
|
+
reader.seek( section.start );
|
|
601
|
+
|
|
602
|
+
const numTokens = reader.readUint64();
|
|
603
|
+
this.tokens = [];
|
|
604
|
+
|
|
605
|
+
if ( this.version.major === 0 && this.version.minor < 4 ) {
|
|
606
|
+
|
|
607
|
+
// Uncompressed tokens (version < 0.4.0)
|
|
608
|
+
const tokensNumBytes = reader.readUint64();
|
|
609
|
+
const tokensData = reader.readBytes( tokensNumBytes );
|
|
610
|
+
|
|
611
|
+
let strStart = 0;
|
|
612
|
+
for ( let i = 0; i < numTokens; i ++ ) {
|
|
613
|
+
|
|
614
|
+
let strEnd = strStart;
|
|
615
|
+
while ( strEnd < tokensData.length && tokensData[ strEnd ] !== 0 ) strEnd ++;
|
|
616
|
+
|
|
617
|
+
this.tokens.push( textDecoder.decode( tokensData.subarray( strStart, strEnd ) ) );
|
|
618
|
+
strStart = strEnd + 1;
|
|
619
|
+
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
} else {
|
|
623
|
+
|
|
624
|
+
// Compressed tokens (version >= 0.4.0)
|
|
625
|
+
const uncompressedSize = reader.readUint64();
|
|
626
|
+
const compressedSize = reader.readUint64();
|
|
627
|
+
const compressedData = reader.readBytes( compressedSize );
|
|
628
|
+
|
|
629
|
+
const tokensData = decompressLZ4( compressedData, uncompressedSize );
|
|
630
|
+
|
|
631
|
+
let strStart = 0;
|
|
632
|
+
for ( let i = 0; i < numTokens; i ++ ) {
|
|
633
|
+
|
|
634
|
+
let strEnd = strStart;
|
|
635
|
+
while ( strEnd < tokensData.length && tokensData[ strEnd ] !== 0 ) strEnd ++;
|
|
636
|
+
|
|
637
|
+
this.tokens.push( textDecoder.decode( tokensData.subarray( strStart, strEnd ) ) );
|
|
638
|
+
strStart = strEnd + 1;
|
|
639
|
+
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
_readStrings() {
|
|
647
|
+
|
|
648
|
+
const section = this.sections[ 'STRINGS' ];
|
|
649
|
+
if ( ! section ) {
|
|
650
|
+
|
|
651
|
+
this.strings = [];
|
|
652
|
+
return;
|
|
653
|
+
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
const reader = this.reader;
|
|
657
|
+
reader.seek( section.start );
|
|
658
|
+
|
|
659
|
+
// Strings section has an 8-byte count prefix, but string indices stored
|
|
660
|
+
// elsewhere in the file are relative to the section start (not the data).
|
|
661
|
+
// So we read the entire section as uint32 values to maintain correct indexing.
|
|
662
|
+
const numStrings = Math.floor( section.size / 4 );
|
|
663
|
+
this.strings = [];
|
|
664
|
+
|
|
665
|
+
for ( let i = 0; i < numStrings; i ++ ) {
|
|
666
|
+
|
|
667
|
+
this.strings.push( reader.readUint32() );
|
|
668
|
+
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
_readFields() {
|
|
674
|
+
|
|
675
|
+
const section = this.sections[ 'FIELDS' ];
|
|
676
|
+
if ( ! section ) return;
|
|
677
|
+
|
|
678
|
+
const reader = this.reader;
|
|
679
|
+
reader.seek( section.start );
|
|
680
|
+
|
|
681
|
+
this.fields = [];
|
|
682
|
+
|
|
683
|
+
if ( this.version.major === 0 && this.version.minor < 4 ) {
|
|
684
|
+
|
|
685
|
+
// Uncompressed fields
|
|
686
|
+
const numFields = Math.floor( section.size / 12 ); // 4 bytes token index + 8 bytes value rep
|
|
687
|
+
|
|
688
|
+
for ( let i = 0; i < numFields; i ++ ) {
|
|
689
|
+
|
|
690
|
+
const tokenIndex = reader.readUint32();
|
|
691
|
+
const repLo = reader.readUint32();
|
|
692
|
+
const repHi = reader.readUint32();
|
|
693
|
+
|
|
694
|
+
this.fields.push( {
|
|
695
|
+
tokenIndex,
|
|
696
|
+
valueRep: new ValueRep( repLo, repHi )
|
|
697
|
+
} );
|
|
698
|
+
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
} else {
|
|
702
|
+
|
|
703
|
+
// Compressed fields (version >= 0.4.0)
|
|
704
|
+
const numFields = reader.readUint64();
|
|
705
|
+
|
|
706
|
+
// Read compressed token indices
|
|
707
|
+
const tokenIndicesCompressedSize = reader.readUint64();
|
|
708
|
+
const tokenIndicesCompressed = reader.readBytes( tokenIndicesCompressedSize );
|
|
709
|
+
const tokenIndices = decompressIntegers32(
|
|
710
|
+
tokenIndicesCompressed.buffer.slice(
|
|
711
|
+
tokenIndicesCompressed.byteOffset,
|
|
712
|
+
tokenIndicesCompressed.byteOffset + tokenIndicesCompressedSize
|
|
713
|
+
),
|
|
714
|
+
numFields
|
|
715
|
+
);
|
|
716
|
+
|
|
717
|
+
// Read compressed value reps (LZ4 only, no integer encoding)
|
|
718
|
+
const repsCompressedSize = reader.readUint64();
|
|
719
|
+
const repsCompressed = reader.readBytes( repsCompressedSize );
|
|
720
|
+
const repsData = decompressLZ4( repsCompressed, numFields * 8 );
|
|
721
|
+
const repsView = new DataView( repsData.buffer, repsData.byteOffset, repsData.byteLength );
|
|
722
|
+
|
|
723
|
+
for ( let i = 0; i < numFields; i ++ ) {
|
|
724
|
+
|
|
725
|
+
const repLo = repsView.getUint32( i * 8, true );
|
|
726
|
+
const repHi = repsView.getUint32( i * 8 + 4, true );
|
|
727
|
+
|
|
728
|
+
this.fields.push( {
|
|
729
|
+
tokenIndex: tokenIndices[ i ],
|
|
730
|
+
valueRep: new ValueRep( repLo, repHi )
|
|
731
|
+
} );
|
|
732
|
+
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
_readFieldSets() {
|
|
740
|
+
|
|
741
|
+
const section = this.sections[ 'FIELDSETS' ];
|
|
742
|
+
if ( ! section ) return;
|
|
743
|
+
|
|
744
|
+
const reader = this.reader;
|
|
745
|
+
reader.seek( section.start );
|
|
746
|
+
|
|
747
|
+
this.fieldSets = [];
|
|
748
|
+
|
|
749
|
+
if ( this.version.major === 0 && this.version.minor < 4 ) {
|
|
750
|
+
|
|
751
|
+
// Uncompressed field sets
|
|
752
|
+
const numFieldSets = Math.floor( section.size / 4 );
|
|
753
|
+
|
|
754
|
+
for ( let i = 0; i < numFieldSets; i ++ ) {
|
|
755
|
+
|
|
756
|
+
this.fieldSets.push( reader.readUint32() );
|
|
757
|
+
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
} else {
|
|
761
|
+
|
|
762
|
+
// Compressed field sets
|
|
763
|
+
const numFieldSets = reader.readUint64();
|
|
764
|
+
const compressedSize = reader.readUint64();
|
|
765
|
+
const compressed = reader.readBytes( compressedSize );
|
|
766
|
+
|
|
767
|
+
const indices = decompressIntegers32(
|
|
768
|
+
compressed.buffer.slice(
|
|
769
|
+
compressed.byteOffset,
|
|
770
|
+
compressed.byteOffset + compressedSize
|
|
771
|
+
),
|
|
772
|
+
numFieldSets
|
|
773
|
+
);
|
|
774
|
+
|
|
775
|
+
for ( let i = 0; i < numFieldSets; i ++ ) {
|
|
776
|
+
|
|
777
|
+
this.fieldSets.push( indices[ i ] );
|
|
778
|
+
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
_readPaths() {
|
|
786
|
+
|
|
787
|
+
const section = this.sections[ 'PATHS' ];
|
|
788
|
+
if ( ! section ) return;
|
|
789
|
+
|
|
790
|
+
const reader = this.reader;
|
|
791
|
+
reader.seek( section.start );
|
|
792
|
+
|
|
793
|
+
const numPaths = reader.readUint64();
|
|
794
|
+
this.paths = new Array( numPaths ).fill( '' );
|
|
795
|
+
|
|
796
|
+
if ( this.version.major === 0 && this.version.minor < 4 ) {
|
|
797
|
+
|
|
798
|
+
// Uncompressed paths - recursive tree structure
|
|
799
|
+
this._readPathsRecursive( '' );
|
|
800
|
+
|
|
801
|
+
} else {
|
|
802
|
+
|
|
803
|
+
// Compressed paths (version >= 0.4.0)
|
|
804
|
+
// Note: numPaths is stored twice - once for array sizing, once in compressed paths section
|
|
805
|
+
reader.readUint64(); // Read duplicate numPaths value (matches numPaths above)
|
|
806
|
+
|
|
807
|
+
const compressedSize1 = reader.readUint64();
|
|
808
|
+
const pathIndicesCompressed = reader.readBytes( compressedSize1 );
|
|
809
|
+
const pathIndices = decompressIntegers32(
|
|
810
|
+
pathIndicesCompressed.buffer.slice(
|
|
811
|
+
pathIndicesCompressed.byteOffset,
|
|
812
|
+
pathIndicesCompressed.byteOffset + compressedSize1
|
|
813
|
+
),
|
|
814
|
+
numPaths
|
|
815
|
+
);
|
|
816
|
+
|
|
817
|
+
const compressedSize2 = reader.readUint64();
|
|
818
|
+
const elementTokenIndicesCompressed = reader.readBytes( compressedSize2 );
|
|
819
|
+
const elementTokenIndices = decompressIntegers32(
|
|
820
|
+
elementTokenIndicesCompressed.buffer.slice(
|
|
821
|
+
elementTokenIndicesCompressed.byteOffset,
|
|
822
|
+
elementTokenIndicesCompressed.byteOffset + compressedSize2
|
|
823
|
+
),
|
|
824
|
+
numPaths
|
|
825
|
+
);
|
|
826
|
+
|
|
827
|
+
const compressedSize3 = reader.readUint64();
|
|
828
|
+
const jumpsCompressed = reader.readBytes( compressedSize3 );
|
|
829
|
+
const jumps = decompressIntegers32(
|
|
830
|
+
jumpsCompressed.buffer.slice(
|
|
831
|
+
jumpsCompressed.byteOffset,
|
|
832
|
+
jumpsCompressed.byteOffset + compressedSize3
|
|
833
|
+
),
|
|
834
|
+
numPaths
|
|
835
|
+
);
|
|
836
|
+
|
|
837
|
+
// Build paths from compressed data
|
|
838
|
+
this._buildPathsFromCompressed( pathIndices, elementTokenIndices, jumps );
|
|
839
|
+
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
_readPathsRecursive( parentPath, depth = 0 ) {
|
|
845
|
+
|
|
846
|
+
const reader = this.reader;
|
|
847
|
+
|
|
848
|
+
// Prevent infinite recursion
|
|
849
|
+
if ( depth > 1000 ) return;
|
|
850
|
+
|
|
851
|
+
// Read path item header
|
|
852
|
+
const index = reader.readUint32();
|
|
853
|
+
const elementTokenIndex = reader.readUint32();
|
|
854
|
+
const bits = reader.readUint8();
|
|
855
|
+
|
|
856
|
+
const hasChild = ( bits & 1 ) !== 0;
|
|
857
|
+
const hasSibling = ( bits & 2 ) !== 0;
|
|
858
|
+
const isPrimProperty = ( bits & 4 ) !== 0;
|
|
859
|
+
|
|
860
|
+
// Build path
|
|
861
|
+
let path;
|
|
862
|
+
if ( parentPath === '' ) {
|
|
863
|
+
|
|
864
|
+
path = '/';
|
|
865
|
+
|
|
866
|
+
} else {
|
|
867
|
+
|
|
868
|
+
const elemToken = this.tokens[ elementTokenIndex ] || '';
|
|
869
|
+
if ( isPrimProperty ) {
|
|
870
|
+
|
|
871
|
+
path = parentPath + '.' + elemToken;
|
|
872
|
+
|
|
873
|
+
} else {
|
|
874
|
+
|
|
875
|
+
path = parentPath === '/' ? '/' + elemToken : parentPath + '/' + elemToken;
|
|
876
|
+
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
this.paths[ index ] = path;
|
|
882
|
+
|
|
883
|
+
// Process children and siblings
|
|
884
|
+
if ( hasChild && hasSibling ) {
|
|
885
|
+
|
|
886
|
+
// Read sibling offset
|
|
887
|
+
const siblingOffset = reader.readUint64();
|
|
888
|
+
|
|
889
|
+
// Read child
|
|
890
|
+
this._readPathsRecursive( path, depth + 1 );
|
|
891
|
+
|
|
892
|
+
// Read sibling
|
|
893
|
+
reader.seek( siblingOffset );
|
|
894
|
+
this._readPathsRecursive( parentPath, depth + 1 );
|
|
895
|
+
|
|
896
|
+
} else if ( hasChild ) {
|
|
897
|
+
|
|
898
|
+
this._readPathsRecursive( path, depth + 1 );
|
|
899
|
+
|
|
900
|
+
} else if ( hasSibling ) {
|
|
901
|
+
|
|
902
|
+
this._readPathsRecursive( parentPath, depth + 1 );
|
|
903
|
+
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
_buildPathsFromCompressed( pathIndices, elementTokenIndices, jumps ) {
|
|
909
|
+
|
|
910
|
+
// Jump encoding from USD:
|
|
911
|
+
// 0 = only sibling (no child), next entry is sibling
|
|
912
|
+
// -1 = only child (no sibling), next entry is child
|
|
913
|
+
// -2 = leaf (no child, no sibling)
|
|
914
|
+
// >0 = has both child and sibling, value is offset to sibling
|
|
915
|
+
|
|
916
|
+
const buildPaths = ( startIndex, parentPath ) => {
|
|
917
|
+
|
|
918
|
+
let curIndex = startIndex;
|
|
919
|
+
|
|
920
|
+
while ( curIndex < pathIndices.length ) {
|
|
921
|
+
|
|
922
|
+
const thisIndex = curIndex ++;
|
|
923
|
+
const pathIndex = pathIndices[ thisIndex ];
|
|
924
|
+
const elementTokenIndex = elementTokenIndices[ thisIndex ];
|
|
925
|
+
const jump = jumps[ thisIndex ];
|
|
926
|
+
|
|
927
|
+
// Build path
|
|
928
|
+
let path;
|
|
929
|
+
if ( parentPath === '' ) {
|
|
930
|
+
|
|
931
|
+
path = '/';
|
|
932
|
+
parentPath = path;
|
|
933
|
+
|
|
934
|
+
} else {
|
|
935
|
+
|
|
936
|
+
const elemToken = this.tokens[ Math.abs( elementTokenIndex ) ] || '';
|
|
937
|
+
const isPrimProperty = elementTokenIndex < 0;
|
|
938
|
+
|
|
939
|
+
if ( isPrimProperty ) {
|
|
940
|
+
|
|
941
|
+
path = parentPath + '.' + elemToken;
|
|
942
|
+
|
|
943
|
+
} else {
|
|
944
|
+
|
|
945
|
+
path = parentPath === '/' ? '/' + elemToken : parentPath + '/' + elemToken;
|
|
946
|
+
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
this.paths[ pathIndex ] = path;
|
|
952
|
+
|
|
953
|
+
// Determine children and siblings
|
|
954
|
+
const hasChild = jump > 0 || jump === - 1;
|
|
955
|
+
const hasSibling = jump >= 0;
|
|
956
|
+
|
|
957
|
+
if ( hasChild ) {
|
|
958
|
+
|
|
959
|
+
if ( hasSibling ) {
|
|
960
|
+
|
|
961
|
+
// Has both child and sibling
|
|
962
|
+
// Recursively process sibling subtree
|
|
963
|
+
const siblingIndex = thisIndex + jump;
|
|
964
|
+
buildPaths( siblingIndex, parentPath );
|
|
965
|
+
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
// Child is next entry, continue with new parent path
|
|
969
|
+
parentPath = path;
|
|
970
|
+
|
|
971
|
+
} else if ( hasSibling ) {
|
|
972
|
+
|
|
973
|
+
// Only sibling, next entry is sibling with same parent
|
|
974
|
+
// Just continue loop with curIndex and same parentPath
|
|
975
|
+
|
|
976
|
+
} else {
|
|
977
|
+
|
|
978
|
+
// Leaf node, exit loop
|
|
979
|
+
break;
|
|
980
|
+
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
};
|
|
986
|
+
|
|
987
|
+
buildPaths( 0, '' );
|
|
988
|
+
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
_readSpecs() {
|
|
992
|
+
|
|
993
|
+
const section = this.sections[ 'SPECS' ];
|
|
994
|
+
if ( ! section ) return;
|
|
995
|
+
|
|
996
|
+
const reader = this.reader;
|
|
997
|
+
reader.seek( section.start );
|
|
998
|
+
|
|
999
|
+
this.specs = [];
|
|
1000
|
+
|
|
1001
|
+
if ( this.version.major === 0 && this.version.minor < 4 ) {
|
|
1002
|
+
|
|
1003
|
+
// Uncompressed specs
|
|
1004
|
+
// Each spec: pathIndex (4), fieldSetIndex (4), specType (4) = 12 bytes
|
|
1005
|
+
// For version 0.0.1 there may be different padding
|
|
1006
|
+
const specSize = ( this.version.minor === 0 && this.version.patch === 1 ) ? 16 : 12;
|
|
1007
|
+
const numSpecs = Math.floor( section.size / specSize );
|
|
1008
|
+
|
|
1009
|
+
for ( let i = 0; i < numSpecs; i ++ ) {
|
|
1010
|
+
|
|
1011
|
+
const pathIndex = reader.readUint32();
|
|
1012
|
+
const fieldSetIndex = reader.readUint32();
|
|
1013
|
+
const specType = reader.readUint32();
|
|
1014
|
+
|
|
1015
|
+
if ( specSize === 16 ) reader.readUint32(); // padding
|
|
1016
|
+
|
|
1017
|
+
this.specs.push( { pathIndex, fieldSetIndex, specType } );
|
|
1018
|
+
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
} else {
|
|
1022
|
+
|
|
1023
|
+
// Compressed specs
|
|
1024
|
+
const numSpecs = reader.readUint64();
|
|
1025
|
+
|
|
1026
|
+
const compressedSize1 = reader.readUint64();
|
|
1027
|
+
const pathIndicesCompressed = reader.readBytes( compressedSize1 );
|
|
1028
|
+
const pathIndices = decompressIntegers32(
|
|
1029
|
+
pathIndicesCompressed.buffer.slice(
|
|
1030
|
+
pathIndicesCompressed.byteOffset,
|
|
1031
|
+
pathIndicesCompressed.byteOffset + compressedSize1
|
|
1032
|
+
),
|
|
1033
|
+
numSpecs
|
|
1034
|
+
);
|
|
1035
|
+
|
|
1036
|
+
const compressedSize2 = reader.readUint64();
|
|
1037
|
+
const fieldSetIndicesCompressed = reader.readBytes( compressedSize2 );
|
|
1038
|
+
const fieldSetIndices = decompressIntegers32(
|
|
1039
|
+
fieldSetIndicesCompressed.buffer.slice(
|
|
1040
|
+
fieldSetIndicesCompressed.byteOffset,
|
|
1041
|
+
fieldSetIndicesCompressed.byteOffset + compressedSize2
|
|
1042
|
+
),
|
|
1043
|
+
numSpecs
|
|
1044
|
+
);
|
|
1045
|
+
|
|
1046
|
+
const compressedSize3 = reader.readUint64();
|
|
1047
|
+
const specTypesCompressed = reader.readBytes( compressedSize3 );
|
|
1048
|
+
const specTypes = decompressIntegers32(
|
|
1049
|
+
specTypesCompressed.buffer.slice(
|
|
1050
|
+
specTypesCompressed.byteOffset,
|
|
1051
|
+
specTypesCompressed.byteOffset + compressedSize3
|
|
1052
|
+
),
|
|
1053
|
+
numSpecs
|
|
1054
|
+
);
|
|
1055
|
+
|
|
1056
|
+
for ( let i = 0; i < numSpecs; i ++ ) {
|
|
1057
|
+
|
|
1058
|
+
this.specs.push( {
|
|
1059
|
+
pathIndex: pathIndices[ i ],
|
|
1060
|
+
fieldSetIndex: fieldSetIndices[ i ],
|
|
1061
|
+
specType: specTypes[ i ]
|
|
1062
|
+
} );
|
|
1063
|
+
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
// ========================================================================
|
|
1071
|
+
// Value Reading
|
|
1072
|
+
// ========================================================================
|
|
1073
|
+
|
|
1074
|
+
_readValue( valueRep ) {
|
|
1075
|
+
|
|
1076
|
+
const type = valueRep.typeEnum;
|
|
1077
|
+
const isArray = valueRep.isArray;
|
|
1078
|
+
const isInlined = valueRep.isInlined;
|
|
1079
|
+
|
|
1080
|
+
// Handle TimeSamples specially - they have their own format
|
|
1081
|
+
if ( type === TypeEnum.TimeSamples ) {
|
|
1082
|
+
|
|
1083
|
+
return this._readTimeSamples( valueRep );
|
|
1084
|
+
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
if ( isInlined ) {
|
|
1088
|
+
|
|
1089
|
+
return this._readInlinedValue( valueRep );
|
|
1090
|
+
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// Seek to payload offset and read value
|
|
1094
|
+
const offset = valueRep.payload;
|
|
1095
|
+
const savedOffset = this.reader.tell();
|
|
1096
|
+
this.reader.seek( offset );
|
|
1097
|
+
|
|
1098
|
+
let value;
|
|
1099
|
+
|
|
1100
|
+
if ( isArray ) {
|
|
1101
|
+
|
|
1102
|
+
value = this._readArrayValue( valueRep );
|
|
1103
|
+
|
|
1104
|
+
} else {
|
|
1105
|
+
|
|
1106
|
+
value = this._readScalarValue( type );
|
|
1107
|
+
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
this.reader.seek( savedOffset );
|
|
1111
|
+
return value;
|
|
1112
|
+
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
_readInlinedValue( valueRep ) {
|
|
1116
|
+
|
|
1117
|
+
const type = valueRep.typeEnum;
|
|
1118
|
+
const payload = valueRep.getInlinedValue();
|
|
1119
|
+
const view = this._conversionView;
|
|
1120
|
+
|
|
1121
|
+
switch ( type ) {
|
|
1122
|
+
|
|
1123
|
+
case TypeEnum.Bool:
|
|
1124
|
+
return payload !== 0;
|
|
1125
|
+
case TypeEnum.UChar:
|
|
1126
|
+
return payload & 0xFF;
|
|
1127
|
+
case TypeEnum.Int:
|
|
1128
|
+
case TypeEnum.UInt:
|
|
1129
|
+
return payload;
|
|
1130
|
+
case TypeEnum.Float: {
|
|
1131
|
+
|
|
1132
|
+
view.setUint32( 0, payload, true );
|
|
1133
|
+
return view.getFloat32( 0, true );
|
|
1134
|
+
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
case TypeEnum.Double: {
|
|
1138
|
+
|
|
1139
|
+
// When a double is inlined, it's stored as float32 bits in the payload
|
|
1140
|
+
view.setUint32( 0, payload, true );
|
|
1141
|
+
return view.getFloat32( 0, true );
|
|
1142
|
+
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
case TypeEnum.Token:
|
|
1146
|
+
return this.tokens[ payload ] || '';
|
|
1147
|
+
case TypeEnum.String:
|
|
1148
|
+
return this.tokens[ this.strings[ payload ] ] || '';
|
|
1149
|
+
case TypeEnum.AssetPath:
|
|
1150
|
+
return this.tokens[ payload ] || '';
|
|
1151
|
+
case TypeEnum.Specifier:
|
|
1152
|
+
return payload; // 0=def, 1=over, 2=class
|
|
1153
|
+
case TypeEnum.Permission:
|
|
1154
|
+
case TypeEnum.Variability:
|
|
1155
|
+
return payload;
|
|
1156
|
+
|
|
1157
|
+
// Vec2h: Two half-floats fit in 4 bytes, stored directly
|
|
1158
|
+
case TypeEnum.Vec2h: {
|
|
1159
|
+
|
|
1160
|
+
view.setUint32( 0, payload, true );
|
|
1161
|
+
return [ this._halfToFloat( view.getUint16( 0, true ) ), this._halfToFloat( view.getUint16( 2, true ) ) ];
|
|
1162
|
+
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
// Inlined vectors that don't fit in 4 bytes are encoded as signed 8-bit integers
|
|
1166
|
+
// Vec2f = 8 bytes (2x float32), Vec3f = 12 bytes, Vec4f = 16 bytes, etc.
|
|
1167
|
+
case TypeEnum.Vec2f:
|
|
1168
|
+
case TypeEnum.Vec2i: {
|
|
1169
|
+
|
|
1170
|
+
view.setUint32( 0, payload, true );
|
|
1171
|
+
return [ view.getInt8( 0 ), view.getInt8( 1 ) ];
|
|
1172
|
+
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
case TypeEnum.Vec3f:
|
|
1176
|
+
case TypeEnum.Vec3i: {
|
|
1177
|
+
|
|
1178
|
+
view.setUint32( 0, payload, true );
|
|
1179
|
+
return [ view.getInt8( 0 ), view.getInt8( 1 ), view.getInt8( 2 ) ];
|
|
1180
|
+
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
case TypeEnum.Vec4f:
|
|
1184
|
+
case TypeEnum.Vec4i: {
|
|
1185
|
+
|
|
1186
|
+
view.setUint32( 0, payload, true );
|
|
1187
|
+
return [ view.getInt8( 0 ), view.getInt8( 1 ), view.getInt8( 2 ), view.getInt8( 3 ) ];
|
|
1188
|
+
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
case TypeEnum.Matrix2d: {
|
|
1192
|
+
|
|
1193
|
+
// Inlined Matrix2d stores diagonal values as 2 signed int8 values
|
|
1194
|
+
view.setUint32( 0, payload, true );
|
|
1195
|
+
const d0 = view.getInt8( 0 ), d1 = view.getInt8( 1 );
|
|
1196
|
+
return [ d0, 0, 0, d1 ];
|
|
1197
|
+
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
case TypeEnum.Matrix3d: {
|
|
1201
|
+
|
|
1202
|
+
// Inlined Matrix3d stores diagonal values as 3 signed int8 values
|
|
1203
|
+
view.setUint32( 0, payload, true );
|
|
1204
|
+
const d0 = view.getInt8( 0 ), d1 = view.getInt8( 1 ), d2 = view.getInt8( 2 );
|
|
1205
|
+
return [ d0, 0, 0, 0, d1, 0, 0, 0, d2 ];
|
|
1206
|
+
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
case TypeEnum.Matrix4d: {
|
|
1210
|
+
|
|
1211
|
+
// Inlined Matrix4d stores diagonal values as 4 signed int8 values
|
|
1212
|
+
view.setUint32( 0, payload, true );
|
|
1213
|
+
const d0 = view.getInt8( 0 ), d1 = view.getInt8( 1 ), d2 = view.getInt8( 2 ), d3 = view.getInt8( 3 );
|
|
1214
|
+
return [ d0, 0, 0, 0, 0, d1, 0, 0, 0, 0, d2, 0, 0, 0, 0, d3 ];
|
|
1215
|
+
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
default:
|
|
1219
|
+
return payload;
|
|
1220
|
+
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
_readTimeSamples( valueRep ) {
|
|
1226
|
+
|
|
1227
|
+
const reader = this.reader;
|
|
1228
|
+
const offset = valueRep.payload;
|
|
1229
|
+
const savedOffset = reader.tell();
|
|
1230
|
+
reader.seek( offset );
|
|
1231
|
+
|
|
1232
|
+
// TimeSamples format uses RELATIVE offsets (from OpenUSD _RecursiveRead):
|
|
1233
|
+
// _RecursiveRead: read int64 relativeOffset at current position, then seek to start + relativeOffset
|
|
1234
|
+
// After reading timesRep, continue reading from current position (after timesRep)
|
|
1235
|
+
// Layout at TimeSamples location:
|
|
1236
|
+
// - int64 timesOffset (relative from start of this int64)
|
|
1237
|
+
// At (start + timesOffset): timesRep ValueRep, then int64 valuesOffset, then numValues + ValueReps
|
|
1238
|
+
|
|
1239
|
+
// Read times relative offset and resolve
|
|
1240
|
+
const timesStart = reader.tell();
|
|
1241
|
+
const timesRelOffset = reader.readInt64();
|
|
1242
|
+
reader.seek( timesStart + timesRelOffset );
|
|
1243
|
+
|
|
1244
|
+
const timesRepLo = reader.readUint32();
|
|
1245
|
+
const timesRepHi = reader.readUint32();
|
|
1246
|
+
const timesRep = new ValueRep( timesRepLo, timesRepHi );
|
|
1247
|
+
|
|
1248
|
+
// Resolve times array
|
|
1249
|
+
const times = this._readValue( timesRep );
|
|
1250
|
+
|
|
1251
|
+
// Continue reading from current position (after timesRep)
|
|
1252
|
+
// The second _RecursiveRead reads from CURRENT position, not from the beginning
|
|
1253
|
+
const afterTimesRep = timesStart + timesRelOffset + 8;
|
|
1254
|
+
reader.seek( afterTimesRep );
|
|
1255
|
+
|
|
1256
|
+
// Read values relative offset
|
|
1257
|
+
const valuesStart = reader.tell();
|
|
1258
|
+
const valuesRelOffset = reader.readInt64();
|
|
1259
|
+
reader.seek( valuesStart + valuesRelOffset );
|
|
1260
|
+
|
|
1261
|
+
// Read number of values
|
|
1262
|
+
const numValues = reader.readUint64();
|
|
1263
|
+
|
|
1264
|
+
// Read all ValueReps
|
|
1265
|
+
const valueReps = [];
|
|
1266
|
+
for ( let i = 0; i < numValues; i ++ ) {
|
|
1267
|
+
|
|
1268
|
+
const repLo = reader.readUint32();
|
|
1269
|
+
const repHi = reader.readUint32();
|
|
1270
|
+
valueReps.push( new ValueRep( repLo, repHi ) );
|
|
1271
|
+
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
// Resolve each value
|
|
1275
|
+
const values = [];
|
|
1276
|
+
for ( let i = 0; i < numValues; i ++ ) {
|
|
1277
|
+
|
|
1278
|
+
values.push( this._readValue( valueReps[ i ] ) );
|
|
1279
|
+
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
reader.seek( savedOffset );
|
|
1283
|
+
|
|
1284
|
+
// Convert times to array if needed
|
|
1285
|
+
const timesArray = times instanceof Float64Array ? Array.from( times ) : ( Array.isArray( times ) ? times : [ times ] );
|
|
1286
|
+
|
|
1287
|
+
return { times: timesArray, values };
|
|
1288
|
+
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
_readScalarValue( type ) {
|
|
1292
|
+
|
|
1293
|
+
const reader = this.reader;
|
|
1294
|
+
|
|
1295
|
+
switch ( type ) {
|
|
1296
|
+
|
|
1297
|
+
case TypeEnum.Invalid:
|
|
1298
|
+
return null;
|
|
1299
|
+
case TypeEnum.Bool:
|
|
1300
|
+
return reader.readUint8() !== 0;
|
|
1301
|
+
case TypeEnum.UChar:
|
|
1302
|
+
return reader.readUint8();
|
|
1303
|
+
case TypeEnum.Int:
|
|
1304
|
+
return reader.readInt32();
|
|
1305
|
+
case TypeEnum.UInt:
|
|
1306
|
+
return reader.readUint32();
|
|
1307
|
+
case TypeEnum.Int64:
|
|
1308
|
+
return reader.readInt64();
|
|
1309
|
+
case TypeEnum.UInt64:
|
|
1310
|
+
return reader.readUint64();
|
|
1311
|
+
case TypeEnum.Half:
|
|
1312
|
+
return this._readHalf();
|
|
1313
|
+
case TypeEnum.Float:
|
|
1314
|
+
return reader.readFloat32();
|
|
1315
|
+
case TypeEnum.Double:
|
|
1316
|
+
return reader.readFloat64();
|
|
1317
|
+
case TypeEnum.String:
|
|
1318
|
+
case TypeEnum.Token: {
|
|
1319
|
+
|
|
1320
|
+
const index = reader.readUint32();
|
|
1321
|
+
return this.tokens[ index ] || '';
|
|
1322
|
+
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
case TypeEnum.AssetPath: {
|
|
1326
|
+
|
|
1327
|
+
const index = reader.readUint32();
|
|
1328
|
+
return this.tokens[ index ] || '';
|
|
1329
|
+
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
case TypeEnum.Vec2f:
|
|
1333
|
+
return [ reader.readFloat32(), reader.readFloat32() ];
|
|
1334
|
+
case TypeEnum.Vec2d:
|
|
1335
|
+
return [ reader.readFloat64(), reader.readFloat64() ];
|
|
1336
|
+
case TypeEnum.Vec2i:
|
|
1337
|
+
return [ reader.readInt32(), reader.readInt32() ];
|
|
1338
|
+
case TypeEnum.Vec3f:
|
|
1339
|
+
return [ reader.readFloat32(), reader.readFloat32(), reader.readFloat32() ];
|
|
1340
|
+
case TypeEnum.Vec3d:
|
|
1341
|
+
return [ reader.readFloat64(), reader.readFloat64(), reader.readFloat64() ];
|
|
1342
|
+
case TypeEnum.Vec3i:
|
|
1343
|
+
return [ reader.readInt32(), reader.readInt32(), reader.readInt32() ];
|
|
1344
|
+
case TypeEnum.Vec4f:
|
|
1345
|
+
return [ reader.readFloat32(), reader.readFloat32(), reader.readFloat32(), reader.readFloat32() ];
|
|
1346
|
+
case TypeEnum.Vec4d:
|
|
1347
|
+
return [ reader.readFloat64(), reader.readFloat64(), reader.readFloat64(), reader.readFloat64() ];
|
|
1348
|
+
case TypeEnum.Quatf:
|
|
1349
|
+
return [ reader.readFloat32(), reader.readFloat32(), reader.readFloat32(), reader.readFloat32() ];
|
|
1350
|
+
case TypeEnum.Quatd:
|
|
1351
|
+
return [ reader.readFloat64(), reader.readFloat64(), reader.readFloat64(), reader.readFloat64() ];
|
|
1352
|
+
case TypeEnum.Matrix4d: {
|
|
1353
|
+
|
|
1354
|
+
const m = [];
|
|
1355
|
+
for ( let i = 0; i < 16; i ++ ) m.push( reader.readFloat64() );
|
|
1356
|
+
return m;
|
|
1357
|
+
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
case TypeEnum.TokenVector: {
|
|
1361
|
+
|
|
1362
|
+
const count = reader.readUint64();
|
|
1363
|
+
const tokens = [];
|
|
1364
|
+
for ( let i = 0; i < count; i ++ ) {
|
|
1365
|
+
|
|
1366
|
+
const index = reader.readUint32();
|
|
1367
|
+
tokens.push( this.tokens[ index ] || '' );
|
|
1368
|
+
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
return tokens;
|
|
1372
|
+
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
case TypeEnum.PathVector: {
|
|
1376
|
+
|
|
1377
|
+
const count = reader.readUint64();
|
|
1378
|
+
const paths = [];
|
|
1379
|
+
for ( let i = 0; i < count; i ++ ) {
|
|
1380
|
+
|
|
1381
|
+
const index = reader.readUint32();
|
|
1382
|
+
paths.push( this.paths[ index ] || '' );
|
|
1383
|
+
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
return paths;
|
|
1387
|
+
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
case TypeEnum.DoubleVector: {
|
|
1391
|
+
|
|
1392
|
+
// DoubleVector is a count-prefixed array of doubles
|
|
1393
|
+
const count = reader.readUint64();
|
|
1394
|
+
const arr = new Float64Array( count );
|
|
1395
|
+
for ( let i = 0; i < count; i ++ ) arr[ i ] = reader.readFloat64();
|
|
1396
|
+
return arr;
|
|
1397
|
+
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
case TypeEnum.Dictionary: {
|
|
1401
|
+
|
|
1402
|
+
// Dictionary format:
|
|
1403
|
+
// u64 elementCount
|
|
1404
|
+
// For each element: u32 keyIndex + i64 valueOffset (relative)
|
|
1405
|
+
const elementCount = reader.readUint64();
|
|
1406
|
+
const dict = {};
|
|
1407
|
+
|
|
1408
|
+
for ( let i = 0; i < elementCount; i ++ ) {
|
|
1409
|
+
|
|
1410
|
+
const keyIdx = reader.readUint32();
|
|
1411
|
+
const key = this.tokens[ keyIdx ];
|
|
1412
|
+
|
|
1413
|
+
// Value offset is relative to current position
|
|
1414
|
+
const currentPos = reader.position;
|
|
1415
|
+
const valueOffset = reader.readInt64();
|
|
1416
|
+
const valuePos = currentPos + valueOffset;
|
|
1417
|
+
|
|
1418
|
+
// Save position, read value, restore position
|
|
1419
|
+
const savedPos = reader.position;
|
|
1420
|
+
reader.position = valuePos;
|
|
1421
|
+
|
|
1422
|
+
// Read the value representation at the offset
|
|
1423
|
+
const valueRepData = reader.readUint64();
|
|
1424
|
+
const valueRep = new ValueRep( valueRepData );
|
|
1425
|
+
|
|
1426
|
+
// Read the value based on the representation
|
|
1427
|
+
let value = null;
|
|
1428
|
+
if ( valueRep.isInlined ) {
|
|
1429
|
+
|
|
1430
|
+
value = this._readInlinedValue( valueRep );
|
|
1431
|
+
|
|
1432
|
+
} else if ( valueRep.isArray ) {
|
|
1433
|
+
|
|
1434
|
+
reader.position = valueRep.payload;
|
|
1435
|
+
value = this._readArrayValue( valueRep );
|
|
1436
|
+
|
|
1437
|
+
} else {
|
|
1438
|
+
|
|
1439
|
+
reader.position = valueRep.payload;
|
|
1440
|
+
value = this._readScalarValue( valueRep.typeEnum );
|
|
1441
|
+
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
reader.position = savedPos;
|
|
1445
|
+
|
|
1446
|
+
if ( key !== undefined && value !== null ) {
|
|
1447
|
+
|
|
1448
|
+
dict[ key ] = value;
|
|
1449
|
+
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
return dict;
|
|
1455
|
+
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
case TypeEnum.TokenListOp:
|
|
1459
|
+
case TypeEnum.StringListOp:
|
|
1460
|
+
case TypeEnum.IntListOp:
|
|
1461
|
+
case TypeEnum.Int64ListOp:
|
|
1462
|
+
case TypeEnum.UIntListOp:
|
|
1463
|
+
case TypeEnum.UInt64ListOp:
|
|
1464
|
+
// These complex types are not needed for geometry loading
|
|
1465
|
+
// Skip them silently
|
|
1466
|
+
return null;
|
|
1467
|
+
|
|
1468
|
+
case TypeEnum.PathListOp: {
|
|
1469
|
+
|
|
1470
|
+
// PathListOp format (from AOUSD Core Spec 16.3.10.25):
|
|
1471
|
+
// Header byte bitmask:
|
|
1472
|
+
// - bit 0 (0x01): Make Explicit (clears list)
|
|
1473
|
+
// - bit 1 (0x02): Add Explicit Items
|
|
1474
|
+
// - bit 2 (0x04): Add Items
|
|
1475
|
+
// - bit 3 (0x08): Delete Items
|
|
1476
|
+
// - bit 4 (0x10): Reorder Items
|
|
1477
|
+
// - bit 5 (0x20): Prepend Items
|
|
1478
|
+
// - bit 6 (0x40): Append Items
|
|
1479
|
+
// Arrays follow in order: Explicit, Add, Prepend, Append, Delete, Reorder
|
|
1480
|
+
// Each array: uint64 count + count * uint32 path indices
|
|
1481
|
+
const flags = reader.readUint8();
|
|
1482
|
+
const hasExplicitItems = ( flags & 0x02 ) !== 0;
|
|
1483
|
+
const hasAddItems = ( flags & 0x04 ) !== 0;
|
|
1484
|
+
const hasDeleteItems = ( flags & 0x08 ) !== 0;
|
|
1485
|
+
const hasReorderItems = ( flags & 0x10 ) !== 0;
|
|
1486
|
+
const hasPrependItems = ( flags & 0x20 ) !== 0;
|
|
1487
|
+
const hasAppendItems = ( flags & 0x40 ) !== 0;
|
|
1488
|
+
|
|
1489
|
+
const readPathList = () => {
|
|
1490
|
+
|
|
1491
|
+
const itemCount = reader.readUint64();
|
|
1492
|
+
const paths = [];
|
|
1493
|
+
for ( let i = 0; i < itemCount; i ++ ) {
|
|
1494
|
+
|
|
1495
|
+
const pathIdx = reader.readUint32();
|
|
1496
|
+
paths.push( this.paths[ pathIdx ] );
|
|
1497
|
+
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
return paths;
|
|
1501
|
+
|
|
1502
|
+
};
|
|
1503
|
+
|
|
1504
|
+
// Read arrays in spec order: Explicit, Add, Prepend, Append, Delete, Reorder
|
|
1505
|
+
let explicitPaths = null;
|
|
1506
|
+
let addPaths = null;
|
|
1507
|
+
let prependPaths = null;
|
|
1508
|
+
let appendPaths = null;
|
|
1509
|
+
|
|
1510
|
+
if ( hasExplicitItems ) explicitPaths = readPathList();
|
|
1511
|
+
if ( hasAddItems ) addPaths = readPathList();
|
|
1512
|
+
if ( hasPrependItems ) prependPaths = readPathList();
|
|
1513
|
+
if ( hasAppendItems ) appendPaths = readPathList();
|
|
1514
|
+
if ( hasDeleteItems ) readPathList(); // Skip delete items
|
|
1515
|
+
if ( hasReorderItems ) readPathList(); // Skip reorder items
|
|
1516
|
+
|
|
1517
|
+
// Return the first non-empty list (connections are typically prepended)
|
|
1518
|
+
if ( prependPaths && prependPaths.length > 0 ) return prependPaths;
|
|
1519
|
+
if ( explicitPaths && explicitPaths.length > 0 ) return explicitPaths;
|
|
1520
|
+
if ( appendPaths && appendPaths.length > 0 ) return appendPaths;
|
|
1521
|
+
if ( addPaths && addPaths.length > 0 ) return addPaths;
|
|
1522
|
+
|
|
1523
|
+
return null;
|
|
1524
|
+
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
case TypeEnum.VariantSelectionMap: {
|
|
1528
|
+
|
|
1529
|
+
const elementCount = reader.readUint64();
|
|
1530
|
+
const map = {};
|
|
1531
|
+
|
|
1532
|
+
for ( let i = 0; i < elementCount; i ++ ) {
|
|
1533
|
+
|
|
1534
|
+
const keyIdx = reader.readUint32();
|
|
1535
|
+
const valueIdx = reader.readUint32();
|
|
1536
|
+
const key = this.tokens[ this.strings[ keyIdx ] ];
|
|
1537
|
+
const value = this.tokens[ this.strings[ valueIdx ] ];
|
|
1538
|
+
if ( key && value ) map[ key ] = value;
|
|
1539
|
+
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
return map;
|
|
1543
|
+
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
default:
|
|
1547
|
+
console.warn( 'USDCParser: Unsupported scalar type', type );
|
|
1548
|
+
return null;
|
|
1549
|
+
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
_readArrayValue( valueRep ) {
|
|
1555
|
+
|
|
1556
|
+
const reader = this.reader;
|
|
1557
|
+
const type = valueRep.typeEnum;
|
|
1558
|
+
const isCompressed = valueRep.isCompressed;
|
|
1559
|
+
|
|
1560
|
+
// Read array size
|
|
1561
|
+
let size;
|
|
1562
|
+
if ( this.version.major === 0 && this.version.minor < 7 ) {
|
|
1563
|
+
|
|
1564
|
+
size = reader.readUint32();
|
|
1565
|
+
|
|
1566
|
+
} else {
|
|
1567
|
+
|
|
1568
|
+
size = reader.readUint64();
|
|
1569
|
+
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
if ( size === 0 ) return [];
|
|
1573
|
+
|
|
1574
|
+
// Handle compressed arrays
|
|
1575
|
+
if ( isCompressed ) {
|
|
1576
|
+
|
|
1577
|
+
return this._readCompressedArray( type, size );
|
|
1578
|
+
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
// Read uncompressed array
|
|
1582
|
+
switch ( type ) {
|
|
1583
|
+
|
|
1584
|
+
case TypeEnum.Int: {
|
|
1585
|
+
|
|
1586
|
+
const arr = new Int32Array( size );
|
|
1587
|
+
for ( let i = 0; i < size; i ++ ) arr[ i ] = reader.readInt32();
|
|
1588
|
+
return arr;
|
|
1589
|
+
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
case TypeEnum.UInt: {
|
|
1593
|
+
|
|
1594
|
+
const arr = new Uint32Array( size );
|
|
1595
|
+
for ( let i = 0; i < size; i ++ ) arr[ i ] = reader.readUint32();
|
|
1596
|
+
return arr;
|
|
1597
|
+
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
case TypeEnum.Float: {
|
|
1601
|
+
|
|
1602
|
+
const arr = new Float32Array( size );
|
|
1603
|
+
for ( let i = 0; i < size; i ++ ) arr[ i ] = reader.readFloat32();
|
|
1604
|
+
return arr;
|
|
1605
|
+
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
case TypeEnum.Double: {
|
|
1609
|
+
|
|
1610
|
+
const arr = new Float64Array( size );
|
|
1611
|
+
for ( let i = 0; i < size; i ++ ) arr[ i ] = reader.readFloat64();
|
|
1612
|
+
return arr;
|
|
1613
|
+
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
case TypeEnum.Vec2f: {
|
|
1617
|
+
|
|
1618
|
+
const arr = new Float32Array( size * 2 );
|
|
1619
|
+
for ( let i = 0; i < size * 2; i ++ ) arr[ i ] = reader.readFloat32();
|
|
1620
|
+
return arr;
|
|
1621
|
+
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
case TypeEnum.Vec3f: {
|
|
1625
|
+
|
|
1626
|
+
const arr = new Float32Array( size * 3 );
|
|
1627
|
+
for ( let i = 0; i < size * 3; i ++ ) arr[ i ] = reader.readFloat32();
|
|
1628
|
+
return arr;
|
|
1629
|
+
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
case TypeEnum.Vec4f: {
|
|
1633
|
+
|
|
1634
|
+
const arr = new Float32Array( size * 4 );
|
|
1635
|
+
for ( let i = 0; i < size * 4; i ++ ) arr[ i ] = reader.readFloat32();
|
|
1636
|
+
return arr;
|
|
1637
|
+
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
case TypeEnum.Vec3h: {
|
|
1641
|
+
|
|
1642
|
+
// Half-precision vec3 array (used for scales in skeletal animation)
|
|
1643
|
+
const arr = new Float32Array( size * 3 );
|
|
1644
|
+
for ( let i = 0; i < size * 3; i ++ ) arr[ i ] = this._readHalf();
|
|
1645
|
+
return arr;
|
|
1646
|
+
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
case TypeEnum.Quatf: {
|
|
1650
|
+
|
|
1651
|
+
const arr = new Float32Array( size * 4 );
|
|
1652
|
+
for ( let i = 0; i < size * 4; i ++ ) arr[ i ] = reader.readFloat32();
|
|
1653
|
+
return arr;
|
|
1654
|
+
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
case TypeEnum.Quath: {
|
|
1658
|
+
|
|
1659
|
+
// Half-precision quaternion array
|
|
1660
|
+
const arr = new Float32Array( size * 4 );
|
|
1661
|
+
for ( let i = 0; i < size * 4; i ++ ) arr[ i ] = this._readHalf();
|
|
1662
|
+
return arr;
|
|
1663
|
+
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
case TypeEnum.Matrix4d: {
|
|
1667
|
+
|
|
1668
|
+
// 4x4 matrix array (16 doubles per matrix, row-major)
|
|
1669
|
+
const arr = new Float64Array( size * 16 );
|
|
1670
|
+
for ( let i = 0; i < size * 16; i ++ ) arr[ i ] = reader.readFloat64();
|
|
1671
|
+
return arr;
|
|
1672
|
+
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
case TypeEnum.Token: {
|
|
1676
|
+
|
|
1677
|
+
const arr = [];
|
|
1678
|
+
for ( let i = 0; i < size; i ++ ) {
|
|
1679
|
+
|
|
1680
|
+
const index = reader.readUint32();
|
|
1681
|
+
arr.push( this.tokens[ index ] || '' );
|
|
1682
|
+
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
return arr;
|
|
1686
|
+
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
case TypeEnum.Half: {
|
|
1690
|
+
|
|
1691
|
+
const arr = new Float32Array( size );
|
|
1692
|
+
for ( let i = 0; i < size; i ++ ) arr[ i ] = this._readHalf();
|
|
1693
|
+
return arr;
|
|
1694
|
+
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
default:
|
|
1698
|
+
console.warn( 'USDCParser: Unsupported array type', type );
|
|
1699
|
+
return [];
|
|
1700
|
+
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
_readCompressedArray( type, size ) {
|
|
1706
|
+
|
|
1707
|
+
const reader = this.reader;
|
|
1708
|
+
|
|
1709
|
+
switch ( type ) {
|
|
1710
|
+
|
|
1711
|
+
case TypeEnum.Int:
|
|
1712
|
+
case TypeEnum.UInt: {
|
|
1713
|
+
|
|
1714
|
+
const compressedSize = reader.readUint64();
|
|
1715
|
+
const compressed = reader.readBytes( compressedSize );
|
|
1716
|
+
return decompressIntegers32(
|
|
1717
|
+
compressed.buffer.slice(
|
|
1718
|
+
compressed.byteOffset,
|
|
1719
|
+
compressed.byteOffset + compressedSize
|
|
1720
|
+
),
|
|
1721
|
+
size
|
|
1722
|
+
);
|
|
1723
|
+
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
case TypeEnum.Float: {
|
|
1727
|
+
|
|
1728
|
+
// Float compression: 'i' = compressed as ints, 't' = lookup table
|
|
1729
|
+
const code = reader.readInt8();
|
|
1730
|
+
|
|
1731
|
+
if ( code === FLOAT_COMPRESSION_INT ) {
|
|
1732
|
+
|
|
1733
|
+
const compressedSize = reader.readUint64();
|
|
1734
|
+
const compressed = reader.readBytes( compressedSize );
|
|
1735
|
+
const ints = decompressIntegers32(
|
|
1736
|
+
compressed.buffer.slice(
|
|
1737
|
+
compressed.byteOffset,
|
|
1738
|
+
compressed.byteOffset + compressedSize
|
|
1739
|
+
),
|
|
1740
|
+
size
|
|
1741
|
+
);
|
|
1742
|
+
const floats = new Float32Array( size );
|
|
1743
|
+
for ( let i = 0; i < size; i ++ ) floats[ i ] = ints[ i ];
|
|
1744
|
+
return floats;
|
|
1745
|
+
|
|
1746
|
+
} else if ( code === FLOAT_COMPRESSION_LUT ) {
|
|
1747
|
+
|
|
1748
|
+
const lutSize = reader.readUint32();
|
|
1749
|
+
const lut = new Float32Array( lutSize );
|
|
1750
|
+
for ( let i = 0; i < lutSize; i ++ ) lut[ i ] = reader.readFloat32();
|
|
1751
|
+
|
|
1752
|
+
const compressedSize = reader.readUint64();
|
|
1753
|
+
const compressed = reader.readBytes( compressedSize );
|
|
1754
|
+
const indices = decompressIntegers32(
|
|
1755
|
+
compressed.buffer.slice(
|
|
1756
|
+
compressed.byteOffset,
|
|
1757
|
+
compressed.byteOffset + compressedSize
|
|
1758
|
+
),
|
|
1759
|
+
size
|
|
1760
|
+
);
|
|
1761
|
+
|
|
1762
|
+
const floats = new Float32Array( size );
|
|
1763
|
+
for ( let i = 0; i < size; i ++ ) floats[ i ] = lut[ indices[ i ] ];
|
|
1764
|
+
return floats;
|
|
1765
|
+
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
console.warn( 'USDCParser: Unknown float compression code', code );
|
|
1769
|
+
return new Float32Array( size );
|
|
1770
|
+
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
default:
|
|
1774
|
+
console.warn( 'USDCParser: Unsupported compressed array type', type );
|
|
1775
|
+
return [];
|
|
1776
|
+
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
_readHalf() {
|
|
1782
|
+
|
|
1783
|
+
return this._halfToFloat( this.reader.readUint16() );
|
|
1784
|
+
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
_halfToFloat( h ) {
|
|
1788
|
+
|
|
1789
|
+
const sign = ( h & 0x8000 ) >> 15;
|
|
1790
|
+
const exp = ( h & 0x7C00 ) >> 10;
|
|
1791
|
+
const frac = h & 0x03FF;
|
|
1792
|
+
|
|
1793
|
+
if ( exp === 0 ) {
|
|
1794
|
+
|
|
1795
|
+
// Zero or denormalized number
|
|
1796
|
+
if ( frac === 0 ) {
|
|
1797
|
+
|
|
1798
|
+
return sign ? - 0 : 0;
|
|
1799
|
+
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
// Denormalized: value = ±2^-14 × (frac/1024)
|
|
1803
|
+
return ( sign ? - 1 : 1 ) * HALF_DENORM_SCALE * ( frac / 1024 );
|
|
1804
|
+
|
|
1805
|
+
} else if ( exp === 31 ) {
|
|
1806
|
+
|
|
1807
|
+
return frac ? NaN : ( sign ? - Infinity : Infinity );
|
|
1808
|
+
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
return ( sign ? - 1 : 1 ) * HALF_EXPONENT_TABLE[ exp ] * ( 1 + frac / 1024 );
|
|
1812
|
+
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
_getFieldsForSpec( spec ) {
|
|
1816
|
+
|
|
1817
|
+
const fields = {};
|
|
1818
|
+
let fieldSetIndex = spec.fieldSetIndex;
|
|
1819
|
+
|
|
1820
|
+
// Field sets are terminated by FIELD_SET_TERMINATOR
|
|
1821
|
+
// Limit iterations to prevent infinite loops from malformed data
|
|
1822
|
+
const maxIterations = 10000;
|
|
1823
|
+
let iterations = 0;
|
|
1824
|
+
|
|
1825
|
+
while ( fieldSetIndex < this.fieldSets.length && iterations < maxIterations ) {
|
|
1826
|
+
|
|
1827
|
+
const fieldIndex = this.fieldSets[ fieldSetIndex ];
|
|
1828
|
+
|
|
1829
|
+
// Terminator
|
|
1830
|
+
if ( fieldIndex === FIELD_SET_TERMINATOR || fieldIndex === - 1 ) break;
|
|
1831
|
+
|
|
1832
|
+
const field = this.fields[ fieldIndex ];
|
|
1833
|
+
if ( field ) {
|
|
1834
|
+
|
|
1835
|
+
const name = this.tokens[ field.tokenIndex ];
|
|
1836
|
+
const value = this._readValue( field.valueRep );
|
|
1837
|
+
fields[ name ] = value;
|
|
1838
|
+
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1841
|
+
fieldSetIndex ++;
|
|
1842
|
+
iterations ++;
|
|
1843
|
+
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
return fields;
|
|
1847
|
+
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
export { USDCParser };
|