@needle-tools/three 0.169.20-experimental.0 → 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 +54184 -56703
- package/build/three.core.js +59506 -0
- package/build/three.core.min.js +6 -0
- package/build/three.module.js +11645 -73000
- 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 +53912 -51652
- package/build/three.webgpu.min.js +2 -2
- package/build/three.webgpu.nodes.js +53888 -51806
- 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 -37
- 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 +105 -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 +150 -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
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { BufferAttribute } from '../core/BufferAttribute.js';
|
|
2
2
|
import { BufferGeometry } from '../core/BufferGeometry.js';
|
|
3
3
|
import { DataTexture } from '../textures/DataTexture.js';
|
|
4
|
-
import { FloatType, RedIntegerFormat, UnsignedIntType } from '../constants.js';
|
|
4
|
+
import { FloatType, RedIntegerFormat, UnsignedIntType, RGBAFormat } from '../constants.js';
|
|
5
5
|
import { Matrix4 } from '../math/Matrix4.js';
|
|
6
6
|
import { Mesh } from './Mesh.js';
|
|
7
|
-
import { RGBAFormat } from '../constants.js';
|
|
8
7
|
import { ColorManagement } from '../math/ColorManagement.js';
|
|
9
8
|
import { Box3 } from '../math/Box3.js';
|
|
10
9
|
import { Sphere } from '../math/Sphere.js';
|
|
11
10
|
import { Frustum } from '../math/Frustum.js';
|
|
12
11
|
import { Vector3 } from '../math/Vector3.js';
|
|
13
12
|
import { Color } from '../math/Color.js';
|
|
13
|
+
import { FrustumArray } from '../math/FrustumArray.js';
|
|
14
|
+
|
|
15
|
+
function ascIdSort( a, b ) {
|
|
16
|
+
|
|
17
|
+
return a - b;
|
|
18
|
+
|
|
19
|
+
}
|
|
14
20
|
|
|
15
21
|
function sortOpaque( a, b ) {
|
|
16
22
|
|
|
@@ -34,7 +40,7 @@ class MultiDrawRenderList {
|
|
|
34
40
|
|
|
35
41
|
}
|
|
36
42
|
|
|
37
|
-
push(
|
|
43
|
+
push( start, count, z, index ) {
|
|
38
44
|
|
|
39
45
|
const pool = this.pool;
|
|
40
46
|
const list = this.list;
|
|
@@ -55,8 +61,8 @@ class MultiDrawRenderList {
|
|
|
55
61
|
list.push( item );
|
|
56
62
|
this.index ++;
|
|
57
63
|
|
|
58
|
-
item.start =
|
|
59
|
-
item.count =
|
|
64
|
+
item.start = start;
|
|
65
|
+
item.count = count;
|
|
60
66
|
item.z = z;
|
|
61
67
|
item.index = index;
|
|
62
68
|
|
|
@@ -72,11 +78,9 @@ class MultiDrawRenderList {
|
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
const _matrix = /*@__PURE__*/ new Matrix4();
|
|
75
|
-
const _invMatrixWorld = /*@__PURE__*/ new Matrix4();
|
|
76
|
-
const _identityMatrix = /*@__PURE__*/ new Matrix4();
|
|
77
81
|
const _whiteColor = /*@__PURE__*/ new Color( 1, 1, 1 );
|
|
78
|
-
const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
|
|
79
82
|
const _frustum = /*@__PURE__*/ new Frustum();
|
|
83
|
+
const _frustumArray = /*@__PURE__*/ new FrustumArray();
|
|
80
84
|
const _box = /*@__PURE__*/ new Box3();
|
|
81
85
|
const _sphere = /*@__PURE__*/ new Sphere();
|
|
82
86
|
const _vector = /*@__PURE__*/ new Vector3();
|
|
@@ -86,13 +90,6 @@ const _renderList = /*@__PURE__*/ new MultiDrawRenderList();
|
|
|
86
90
|
const _mesh = /*@__PURE__*/ new Mesh();
|
|
87
91
|
const _batchIntersects = [];
|
|
88
92
|
|
|
89
|
-
// @TODO: SkinnedMesh support?
|
|
90
|
-
// @TODO: geometry.groups support?
|
|
91
|
-
// @TODO: geometry.drawRange support?
|
|
92
|
-
// @TODO: geometry.morphAttributes support?
|
|
93
|
-
// @TODO: Support uniform parameter per geometry
|
|
94
|
-
// @TODO: Add an "optimize" function to pack geometry and remove data gaps
|
|
95
|
-
|
|
96
93
|
// copies data from attribute "src" into "target" starting at "targetOffset"
|
|
97
94
|
function copyAttributeData( src, target, targetOffset = 0 ) {
|
|
98
95
|
|
|
@@ -123,47 +120,159 @@ function copyAttributeData( src, target, targetOffset = 0 ) {
|
|
|
123
120
|
|
|
124
121
|
}
|
|
125
122
|
|
|
126
|
-
|
|
123
|
+
// safely copies array contents to a potentially smaller array
|
|
124
|
+
function copyArrayContents( src, target ) {
|
|
127
125
|
|
|
128
|
-
|
|
126
|
+
if ( src.constructor !== target.constructor ) {
|
|
129
127
|
|
|
130
|
-
|
|
128
|
+
// if arrays are of a different type (eg due to index size increasing) then data must be per-element copied
|
|
129
|
+
const len = Math.min( src.length, target.length );
|
|
130
|
+
for ( let i = 0; i < len; i ++ ) {
|
|
131
|
+
|
|
132
|
+
target[ i ] = src[ i ];
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
} else {
|
|
137
|
+
|
|
138
|
+
// if the arrays use the same data layout we can use a fast block copy
|
|
139
|
+
const len = Math.min( src.length, target.length );
|
|
140
|
+
target.set( new src.constructor( src.buffer, 0, len ) );
|
|
131
141
|
|
|
132
142
|
}
|
|
133
143
|
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* A special version of a mesh with multi draw batch rendering support. Use
|
|
148
|
+
* this class if you have to render a large number of objects with the same
|
|
149
|
+
* material but with different geometries or world transformations. The usage of
|
|
150
|
+
* `BatchedMesh` will help you to reduce the number of draw calls and thus improve the overall
|
|
151
|
+
* rendering performance in your application.
|
|
152
|
+
*
|
|
153
|
+
* ```js
|
|
154
|
+
* const box = new THREE.BoxGeometry( 1, 1, 1 );
|
|
155
|
+
* const sphere = new THREE.SphereGeometry( 1, 12, 12 );
|
|
156
|
+
* const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
|
|
157
|
+
*
|
|
158
|
+
* // initialize and add geometries into the batched mesh
|
|
159
|
+
* const batchedMesh = new BatchedMesh( 10, 5000, 10000, material );
|
|
160
|
+
* const boxGeometryId = batchedMesh.addGeometry( box );
|
|
161
|
+
* const sphereGeometryId = batchedMesh.addGeometry( sphere );
|
|
162
|
+
*
|
|
163
|
+
* // create instances of those geometries
|
|
164
|
+
* const boxInstancedId1 = batchedMesh.addInstance( boxGeometryId );
|
|
165
|
+
* const boxInstancedId2 = batchedMesh.addInstance( boxGeometryId );
|
|
166
|
+
*
|
|
167
|
+
* const sphereInstancedId1 = batchedMesh.addInstance( sphereGeometryId );
|
|
168
|
+
* const sphereInstancedId2 = batchedMesh.addInstance( sphereGeometryId );
|
|
169
|
+
*
|
|
170
|
+
* // position the geometries
|
|
171
|
+
* batchedMesh.setMatrixAt( boxInstancedId1, boxMatrix1 );
|
|
172
|
+
* batchedMesh.setMatrixAt( boxInstancedId2, boxMatrix2 );
|
|
173
|
+
*
|
|
174
|
+
* batchedMesh.setMatrixAt( sphereInstancedId1, sphereMatrix1 );
|
|
175
|
+
* batchedMesh.setMatrixAt( sphereInstancedId2, sphereMatrix2 );
|
|
176
|
+
*
|
|
177
|
+
* scene.add( batchedMesh );
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* @augments Mesh
|
|
181
|
+
*/
|
|
182
|
+
class BatchedMesh extends Mesh {
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Constructs a new batched mesh.
|
|
186
|
+
*
|
|
187
|
+
* @param {number} maxInstanceCount - The maximum number of individual instances planned to be added and rendered.
|
|
188
|
+
* @param {number} maxVertexCount - The maximum number of vertices to be used by all unique geometries.
|
|
189
|
+
* @param {number} [maxIndexCount=maxVertexCount*2] - The maximum number of indices to be used by all unique geometries
|
|
190
|
+
* @param {Material|Array<Material>} [material] - The mesh material.
|
|
191
|
+
*/
|
|
134
192
|
constructor( maxInstanceCount, maxVertexCount, maxIndexCount = maxVertexCount * 2, material ) {
|
|
135
193
|
|
|
136
194
|
super( new BufferGeometry(), material );
|
|
137
195
|
|
|
196
|
+
/**
|
|
197
|
+
* This flag can be used for type testing.
|
|
198
|
+
*
|
|
199
|
+
* @type {boolean}
|
|
200
|
+
* @readonly
|
|
201
|
+
* @default true
|
|
202
|
+
*/
|
|
138
203
|
this.isBatchedMesh = true;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* When set ot `true`, the individual objects of a batch are frustum culled.
|
|
207
|
+
*
|
|
208
|
+
* @type {boolean}
|
|
209
|
+
* @default true
|
|
210
|
+
*/
|
|
139
211
|
this.perObjectFrustumCulled = true;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* When set to `true`, the individual objects of a batch are sorted to improve overdraw-related artifacts.
|
|
215
|
+
* If the material is marked as "transparent" objects are rendered back to front and if not then they are
|
|
216
|
+
* rendered front to back.
|
|
217
|
+
*
|
|
218
|
+
* @type {boolean}
|
|
219
|
+
* @default true
|
|
220
|
+
*/
|
|
140
221
|
this.sortObjects = true;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* The bounding box of the batched mesh. Can be computed via {@link BatchedMesh#computeBoundingBox}.
|
|
225
|
+
*
|
|
226
|
+
* @type {?Box3}
|
|
227
|
+
* @default null
|
|
228
|
+
*/
|
|
141
229
|
this.boundingBox = null;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The bounding sphere of the batched mesh. Can be computed via {@link BatchedMesh#computeBoundingSphere}.
|
|
233
|
+
*
|
|
234
|
+
* @type {?Sphere}
|
|
235
|
+
* @default null
|
|
236
|
+
*/
|
|
142
237
|
this.boundingSphere = null;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Takes a sort a function that is run before render. The function takes a list of instances to
|
|
241
|
+
* sort and a camera. The objects in the list include a "z" field to perform a depth-ordered
|
|
242
|
+
* sort with.
|
|
243
|
+
*
|
|
244
|
+
* @type {?Function}
|
|
245
|
+
* @default null
|
|
246
|
+
*/
|
|
143
247
|
this.customSort = null;
|
|
144
248
|
|
|
145
|
-
// stores visible, active, and geometry id per
|
|
146
|
-
this.
|
|
249
|
+
// stores visible, active, and geometry id per instance and reserved buffer ranges for geometries
|
|
250
|
+
this._instanceInfo = [];
|
|
251
|
+
this._geometryInfo = [];
|
|
147
252
|
|
|
148
|
-
// instance ids that have been set as inactive, and are available to be overwritten
|
|
253
|
+
// instance, geometry ids that have been set as inactive, and are available to be overwritten
|
|
149
254
|
this._availableInstanceIds = [];
|
|
255
|
+
this._availableGeometryIds = [];
|
|
150
256
|
|
|
151
|
-
// geometry
|
|
152
|
-
this.
|
|
153
|
-
this.
|
|
154
|
-
this.
|
|
257
|
+
// used to track where the next point is that geometry should be inserted
|
|
258
|
+
this._nextIndexStart = 0;
|
|
259
|
+
this._nextVertexStart = 0;
|
|
260
|
+
this._geometryCount = 0;
|
|
261
|
+
|
|
262
|
+
// flags
|
|
263
|
+
this._visibilityChanged = true;
|
|
264
|
+
this._geometryInitialized = false;
|
|
155
265
|
|
|
266
|
+
// cached user options
|
|
156
267
|
this._maxInstanceCount = maxInstanceCount;
|
|
157
268
|
this._maxVertexCount = maxVertexCount;
|
|
158
269
|
this._maxIndexCount = maxIndexCount;
|
|
159
270
|
|
|
160
|
-
|
|
161
|
-
this._geometryCount = 0;
|
|
271
|
+
// buffers for multi draw
|
|
162
272
|
this._multiDrawCounts = new Int32Array( maxInstanceCount );
|
|
163
273
|
this._multiDrawStarts = new Int32Array( maxInstanceCount );
|
|
164
274
|
this._multiDrawCount = 0;
|
|
165
275
|
this._multiDrawInstances = null;
|
|
166
|
-
this._visibilityChanged = true;
|
|
167
276
|
|
|
168
277
|
// Local matrix per geometry by using data texture
|
|
169
278
|
this._matricesTexture = null;
|
|
@@ -175,6 +284,54 @@ class BatchedMesh extends Mesh {
|
|
|
175
284
|
|
|
176
285
|
}
|
|
177
286
|
|
|
287
|
+
/**
|
|
288
|
+
* The maximum number of individual instances that can be stored in the batch.
|
|
289
|
+
*
|
|
290
|
+
* @type {number}
|
|
291
|
+
* @readonly
|
|
292
|
+
*/
|
|
293
|
+
get maxInstanceCount() {
|
|
294
|
+
|
|
295
|
+
return this._maxInstanceCount;
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* The instance count.
|
|
301
|
+
*
|
|
302
|
+
* @type {number}
|
|
303
|
+
* @readonly
|
|
304
|
+
*/
|
|
305
|
+
get instanceCount() {
|
|
306
|
+
|
|
307
|
+
return this._instanceInfo.length - this._availableInstanceIds.length;
|
|
308
|
+
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* The number of unused vertices.
|
|
313
|
+
*
|
|
314
|
+
* @type {number}
|
|
315
|
+
* @readonly
|
|
316
|
+
*/
|
|
317
|
+
get unusedVertexCount() {
|
|
318
|
+
|
|
319
|
+
return this._maxVertexCount - this._nextVertexStart;
|
|
320
|
+
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* The number of unused indices.
|
|
325
|
+
*
|
|
326
|
+
* @type {number}
|
|
327
|
+
* @readonly
|
|
328
|
+
*/
|
|
329
|
+
get unusedIndexCount() {
|
|
330
|
+
|
|
331
|
+
return this._maxIndexCount - this._nextIndexStart;
|
|
332
|
+
|
|
333
|
+
}
|
|
334
|
+
|
|
178
335
|
_initMatricesTexture() {
|
|
179
336
|
|
|
180
337
|
// layout (1 matrix = 4 pixels)
|
|
@@ -264,7 +421,7 @@ class BatchedMesh extends Mesh {
|
|
|
264
421
|
const batchGeometry = this.geometry;
|
|
265
422
|
if ( Boolean( geometry.getIndex() ) !== Boolean( batchGeometry.getIndex() ) ) {
|
|
266
423
|
|
|
267
|
-
throw new Error( 'BatchedMesh: All geometries must consistently have "index".' );
|
|
424
|
+
throw new Error( 'THREE.BatchedMesh: All geometries must consistently have "index".' );
|
|
268
425
|
|
|
269
426
|
}
|
|
270
427
|
|
|
@@ -272,7 +429,7 @@ class BatchedMesh extends Mesh {
|
|
|
272
429
|
|
|
273
430
|
if ( ! geometry.hasAttribute( attributeName ) ) {
|
|
274
431
|
|
|
275
|
-
throw new Error( `BatchedMesh: Added geometry missing "${ attributeName }". All geometries must have consistent attributes.` );
|
|
432
|
+
throw new Error( `THREE.BatchedMesh: Added geometry missing "${ attributeName }". All geometries must have consistent attributes.` );
|
|
276
433
|
|
|
277
434
|
}
|
|
278
435
|
|
|
@@ -280,7 +437,7 @@ class BatchedMesh extends Mesh {
|
|
|
280
437
|
const dstAttribute = batchGeometry.getAttribute( attributeName );
|
|
281
438
|
if ( srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized ) {
|
|
282
439
|
|
|
283
|
-
throw new Error( 'BatchedMesh: All attributes must have a consistent itemSize and normalized value.' );
|
|
440
|
+
throw new Error( 'THREE.BatchedMesh: All attributes must have a consistent itemSize and normalized value.' );
|
|
284
441
|
|
|
285
442
|
}
|
|
286
443
|
|
|
@@ -288,6 +445,45 @@ class BatchedMesh extends Mesh {
|
|
|
288
445
|
|
|
289
446
|
}
|
|
290
447
|
|
|
448
|
+
/**
|
|
449
|
+
* Validates the instance defined by the given ID.
|
|
450
|
+
*
|
|
451
|
+
* @param {number} instanceId - The instance to validate.
|
|
452
|
+
*/
|
|
453
|
+
validateInstanceId( instanceId ) {
|
|
454
|
+
|
|
455
|
+
const instanceInfo = this._instanceInfo;
|
|
456
|
+
if ( instanceId < 0 || instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
|
|
457
|
+
|
|
458
|
+
throw new Error( `THREE.BatchedMesh: Invalid instanceId ${instanceId}. Instance is either out of range or has been deleted.` );
|
|
459
|
+
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Validates the geometry defined by the given ID.
|
|
466
|
+
*
|
|
467
|
+
* @param {number} geometryId - The geometry to validate.
|
|
468
|
+
*/
|
|
469
|
+
validateGeometryId( geometryId ) {
|
|
470
|
+
|
|
471
|
+
const geometryInfoList = this._geometryInfo;
|
|
472
|
+
if ( geometryId < 0 || geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) {
|
|
473
|
+
|
|
474
|
+
throw new Error( `THREE.BatchedMesh: Invalid geometryId ${geometryId}. Geometry is either out of range or has been deleted.` );
|
|
475
|
+
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Takes a sort a function that is run before render. The function takes a list of instances to
|
|
482
|
+
* sort and a camera. The objects in the list include a "z" field to perform a depth-ordered sort with.
|
|
483
|
+
*
|
|
484
|
+
* @param {Function} func - The custom sort function.
|
|
485
|
+
* @return {BatchedMesh} A reference to this batched mesh.
|
|
486
|
+
*/
|
|
291
487
|
setCustomSort( func ) {
|
|
292
488
|
|
|
293
489
|
this.customSort = func;
|
|
@@ -295,6 +491,11 @@ class BatchedMesh extends Mesh {
|
|
|
295
491
|
|
|
296
492
|
}
|
|
297
493
|
|
|
494
|
+
/**
|
|
495
|
+
* Computes the bounding box, updating {@link BatchedMesh#boundingBox}.
|
|
496
|
+
* Bounding boxes aren't computed by default. They need to be explicitly computed,
|
|
497
|
+
* otherwise they are `null`.
|
|
498
|
+
*/
|
|
298
499
|
computeBoundingBox() {
|
|
299
500
|
|
|
300
501
|
if ( this.boundingBox === null ) {
|
|
@@ -304,14 +505,14 @@ class BatchedMesh extends Mesh {
|
|
|
304
505
|
}
|
|
305
506
|
|
|
306
507
|
const boundingBox = this.boundingBox;
|
|
307
|
-
const
|
|
508
|
+
const instanceInfo = this._instanceInfo;
|
|
308
509
|
|
|
309
510
|
boundingBox.makeEmpty();
|
|
310
|
-
for ( let i = 0, l =
|
|
511
|
+
for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
|
|
311
512
|
|
|
312
|
-
if (
|
|
513
|
+
if ( instanceInfo[ i ].active === false ) continue;
|
|
313
514
|
|
|
314
|
-
const geometryId =
|
|
515
|
+
const geometryId = instanceInfo[ i ].geometryIndex;
|
|
315
516
|
this.getMatrixAt( i, _matrix );
|
|
316
517
|
this.getBoundingBoxAt( geometryId, _box ).applyMatrix4( _matrix );
|
|
317
518
|
boundingBox.union( _box );
|
|
@@ -320,6 +521,11 @@ class BatchedMesh extends Mesh {
|
|
|
320
521
|
|
|
321
522
|
}
|
|
322
523
|
|
|
524
|
+
/**
|
|
525
|
+
* Computes the bounding sphere, updating {@link BatchedMesh#boundingSphere}.
|
|
526
|
+
* Bounding spheres aren't computed by default. They need to be explicitly computed,
|
|
527
|
+
* otherwise they are `null`.
|
|
528
|
+
*/
|
|
323
529
|
computeBoundingSphere() {
|
|
324
530
|
|
|
325
531
|
if ( this.boundingSphere === null ) {
|
|
@@ -329,14 +535,14 @@ class BatchedMesh extends Mesh {
|
|
|
329
535
|
}
|
|
330
536
|
|
|
331
537
|
const boundingSphere = this.boundingSphere;
|
|
332
|
-
const
|
|
538
|
+
const instanceInfo = this._instanceInfo;
|
|
333
539
|
|
|
334
540
|
boundingSphere.makeEmpty();
|
|
335
|
-
for ( let i = 0, l =
|
|
541
|
+
for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
|
|
336
542
|
|
|
337
|
-
if (
|
|
543
|
+
if ( instanceInfo[ i ].active === false ) continue;
|
|
338
544
|
|
|
339
|
-
const geometryId =
|
|
545
|
+
const geometryId = instanceInfo[ i ].geometryIndex;
|
|
340
546
|
this.getMatrixAt( i, _matrix );
|
|
341
547
|
this.getBoundingSphereAt( geometryId, _sphere ).applyMatrix4( _matrix );
|
|
342
548
|
boundingSphere.union( _sphere );
|
|
@@ -345,18 +551,25 @@ class BatchedMesh extends Mesh {
|
|
|
345
551
|
|
|
346
552
|
}
|
|
347
553
|
|
|
554
|
+
/**
|
|
555
|
+
* Adds a new instance to the batch using the geometry of the given ID and returns
|
|
556
|
+
* a new id referring to the new instance to be used by other functions.
|
|
557
|
+
*
|
|
558
|
+
* @param {number} geometryId - The ID of a previously added geometry via {@link BatchedMesh#addGeometry}.
|
|
559
|
+
* @return {number} The instance ID.
|
|
560
|
+
*/
|
|
348
561
|
addInstance( geometryId ) {
|
|
349
562
|
|
|
350
|
-
const atCapacity = this.
|
|
563
|
+
const atCapacity = this._instanceInfo.length >= this.maxInstanceCount;
|
|
351
564
|
|
|
352
565
|
// ensure we're not over geometry
|
|
353
566
|
if ( atCapacity && this._availableInstanceIds.length === 0 ) {
|
|
354
567
|
|
|
355
|
-
throw new Error( 'BatchedMesh: Maximum item count reached.' );
|
|
568
|
+
throw new Error( 'THREE.BatchedMesh: Maximum item count reached.' );
|
|
356
569
|
|
|
357
570
|
}
|
|
358
571
|
|
|
359
|
-
const
|
|
572
|
+
const instanceInfo = {
|
|
360
573
|
visible: true,
|
|
361
574
|
active: true,
|
|
362
575
|
geometryIndex: geometryId,
|
|
@@ -367,19 +580,20 @@ class BatchedMesh extends Mesh {
|
|
|
367
580
|
// Prioritize using previously freed instance ids
|
|
368
581
|
if ( this._availableInstanceIds.length > 0 ) {
|
|
369
582
|
|
|
370
|
-
|
|
371
|
-
|
|
583
|
+
this._availableInstanceIds.sort( ascIdSort );
|
|
584
|
+
|
|
585
|
+
drawId = this._availableInstanceIds.shift();
|
|
586
|
+
this._instanceInfo[ drawId ] = instanceInfo;
|
|
372
587
|
|
|
373
588
|
} else {
|
|
374
589
|
|
|
375
|
-
drawId = this.
|
|
376
|
-
this.
|
|
590
|
+
drawId = this._instanceInfo.length;
|
|
591
|
+
this._instanceInfo.push( instanceInfo );
|
|
377
592
|
|
|
378
593
|
}
|
|
379
594
|
|
|
380
595
|
const matricesTexture = this._matricesTexture;
|
|
381
|
-
|
|
382
|
-
_identityMatrix.toArray( matricesArray, drawId * 16 );
|
|
596
|
+
_matrix.identity().toArray( matricesTexture.image.data, drawId * 16 );
|
|
383
597
|
matricesTexture.needsUpdate = true;
|
|
384
598
|
|
|
385
599
|
const colorsTexture = this._colorsTexture;
|
|
@@ -390,127 +604,118 @@ class BatchedMesh extends Mesh {
|
|
|
390
604
|
|
|
391
605
|
}
|
|
392
606
|
|
|
607
|
+
this._visibilityChanged = true;
|
|
393
608
|
return drawId;
|
|
394
609
|
|
|
395
610
|
}
|
|
396
611
|
|
|
397
|
-
|
|
612
|
+
/**
|
|
613
|
+
* Adds the given geometry to the batch and returns the associated
|
|
614
|
+
* geometry id referring to it to be used in other functions.
|
|
615
|
+
*
|
|
616
|
+
* @param {BufferGeometry} geometry - The geometry to add.
|
|
617
|
+
* @param {number} [reservedVertexCount=-1] - Optional parameter specifying the amount of
|
|
618
|
+
* vertex buffer space to reserve for the added geometry. This is necessary if it is planned
|
|
619
|
+
* to set a new geometry at this index at a later time that is larger than the original geometry.
|
|
620
|
+
* Defaults to the length of the given geometry vertex buffer.
|
|
621
|
+
* @param {number} [reservedIndexCount=-1] - Optional parameter specifying the amount of index
|
|
622
|
+
* buffer space to reserve for the added geometry. This is necessary if it is planned to set a
|
|
623
|
+
* new geometry at this index at a later time that is larger than the original geometry. Defaults to
|
|
624
|
+
* the length of the given geometry index buffer.
|
|
625
|
+
* @return {number} The geometry ID.
|
|
626
|
+
*/
|
|
627
|
+
addGeometry( geometry, reservedVertexCount = - 1, reservedIndexCount = - 1 ) {
|
|
398
628
|
|
|
399
629
|
this._initializeGeometry( geometry );
|
|
400
630
|
|
|
401
631
|
this._validateGeometry( geometry );
|
|
402
632
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
throw new Error( 'BatchedMesh: Maximum item count reached.' );
|
|
407
|
-
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// get the necessary range fo the geometry
|
|
411
|
-
const reservedRange = {
|
|
633
|
+
const geometryInfo = {
|
|
634
|
+
// geometry information
|
|
412
635
|
vertexStart: - 1,
|
|
413
636
|
vertexCount: - 1,
|
|
637
|
+
reservedVertexCount: - 1,
|
|
638
|
+
|
|
414
639
|
indexStart: - 1,
|
|
415
640
|
indexCount: - 1,
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
let lastRange = null;
|
|
419
|
-
const reservedRanges = this._reservedRanges;
|
|
420
|
-
const drawRanges = this._drawRanges;
|
|
421
|
-
const bounds = this._bounds;
|
|
422
|
-
if ( this._geometryCount !== 0 ) {
|
|
423
|
-
|
|
424
|
-
lastRange = reservedRanges[ reservedRanges.length - 1 ];
|
|
425
|
-
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
if ( vertexCount === - 1 ) {
|
|
429
|
-
|
|
430
|
-
reservedRange.vertexCount = geometry.getAttribute( 'position' ).count;
|
|
431
|
-
|
|
432
|
-
} else {
|
|
433
|
-
|
|
434
|
-
reservedRange.vertexCount = vertexCount;
|
|
435
|
-
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
if ( lastRange === null ) {
|
|
641
|
+
reservedIndexCount: - 1,
|
|
439
642
|
|
|
440
|
-
|
|
643
|
+
// draw range information
|
|
644
|
+
start: - 1,
|
|
645
|
+
count: - 1,
|
|
441
646
|
|
|
442
|
-
|
|
647
|
+
// state
|
|
648
|
+
boundingBox: null,
|
|
649
|
+
boundingSphere: null,
|
|
650
|
+
active: true,
|
|
651
|
+
};
|
|
443
652
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
653
|
+
const geometryInfoList = this._geometryInfo;
|
|
654
|
+
geometryInfo.vertexStart = this._nextVertexStart;
|
|
655
|
+
geometryInfo.reservedVertexCount = reservedVertexCount === - 1 ? geometry.getAttribute( 'position' ).count : reservedVertexCount;
|
|
447
656
|
|
|
448
657
|
const index = geometry.getIndex();
|
|
449
658
|
const hasIndex = index !== null;
|
|
450
659
|
if ( hasIndex ) {
|
|
451
660
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
reservedRange.indexCount = index.count;
|
|
661
|
+
geometryInfo.indexStart = this._nextIndexStart;
|
|
662
|
+
geometryInfo.reservedIndexCount = reservedIndexCount === - 1 ? index.count : reservedIndexCount;
|
|
455
663
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
reservedRange.indexCount = indexCount;
|
|
664
|
+
}
|
|
459
665
|
|
|
460
|
-
|
|
666
|
+
if (
|
|
667
|
+
geometryInfo.indexStart !== - 1 &&
|
|
668
|
+
geometryInfo.indexStart + geometryInfo.reservedIndexCount > this._maxIndexCount ||
|
|
669
|
+
geometryInfo.vertexStart + geometryInfo.reservedVertexCount > this._maxVertexCount
|
|
670
|
+
) {
|
|
461
671
|
|
|
462
|
-
|
|
672
|
+
throw new Error( 'THREE.BatchedMesh: Reserved space request exceeds the maximum buffer size.' );
|
|
463
673
|
|
|
464
|
-
|
|
674
|
+
}
|
|
465
675
|
|
|
466
|
-
|
|
676
|
+
// update id
|
|
677
|
+
let geometryId;
|
|
678
|
+
if ( this._availableGeometryIds.length > 0 ) {
|
|
467
679
|
|
|
468
|
-
|
|
680
|
+
this._availableGeometryIds.sort( ascIdSort );
|
|
469
681
|
|
|
470
|
-
|
|
682
|
+
geometryId = this._availableGeometryIds.shift();
|
|
683
|
+
geometryInfoList[ geometryId ] = geometryInfo;
|
|
471
684
|
|
|
472
|
-
}
|
|
473
685
|
|
|
474
|
-
|
|
475
|
-
reservedRange.indexStart !== - 1 &&
|
|
476
|
-
reservedRange.indexStart + reservedRange.indexCount > this._maxIndexCount ||
|
|
477
|
-
reservedRange.vertexStart + reservedRange.vertexCount > this._maxVertexCount
|
|
478
|
-
) {
|
|
686
|
+
} else {
|
|
479
687
|
|
|
480
|
-
|
|
688
|
+
geometryId = this._geometryCount;
|
|
689
|
+
this._geometryCount ++;
|
|
690
|
+
geometryInfoList.push( geometryInfo );
|
|
481
691
|
|
|
482
692
|
}
|
|
483
693
|
|
|
484
|
-
// update id
|
|
485
|
-
const geometryId = this._geometryCount;
|
|
486
|
-
this._geometryCount ++;
|
|
487
|
-
|
|
488
|
-
// add the reserved range and draw range objects
|
|
489
|
-
reservedRanges.push( reservedRange );
|
|
490
|
-
drawRanges.push( {
|
|
491
|
-
start: hasIndex ? reservedRange.indexStart : reservedRange.vertexStart,
|
|
492
|
-
count: - 1
|
|
493
|
-
} );
|
|
494
|
-
bounds.push( {
|
|
495
|
-
boxInitialized: false,
|
|
496
|
-
box: new Box3(),
|
|
497
|
-
|
|
498
|
-
sphereInitialized: false,
|
|
499
|
-
sphere: new Sphere()
|
|
500
|
-
} );
|
|
501
|
-
|
|
502
694
|
// update the geometry
|
|
503
695
|
this.setGeometryAt( geometryId, geometry );
|
|
504
696
|
|
|
697
|
+
// increment the next geometry position
|
|
698
|
+
this._nextIndexStart = geometryInfo.indexStart + geometryInfo.reservedIndexCount;
|
|
699
|
+
this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount;
|
|
700
|
+
|
|
505
701
|
return geometryId;
|
|
506
702
|
|
|
507
703
|
}
|
|
508
704
|
|
|
705
|
+
/**
|
|
706
|
+
* Replaces the geometry at the given ID with the provided geometry. Throws an error if there
|
|
707
|
+
* is not enough space reserved for geometry. Calling this will change all instances that are
|
|
708
|
+
* rendering that geometry.
|
|
709
|
+
*
|
|
710
|
+
* @param {number} geometryId - The ID of the geometry that should be replaced with the given geometry.
|
|
711
|
+
* @param {BufferGeometry} geometry - The new geometry.
|
|
712
|
+
* @return {number} The geometry ID.
|
|
713
|
+
*/
|
|
509
714
|
setGeometryAt( geometryId, geometry ) {
|
|
510
715
|
|
|
511
716
|
if ( geometryId >= this._geometryCount ) {
|
|
512
717
|
|
|
513
|
-
throw new Error( 'BatchedMesh: Maximum geometry count reached.' );
|
|
718
|
+
throw new Error( 'THREE.BatchedMesh: Maximum geometry count reached.' );
|
|
514
719
|
|
|
515
720
|
}
|
|
516
721
|
|
|
@@ -520,20 +725,22 @@ class BatchedMesh extends Mesh {
|
|
|
520
725
|
const hasIndex = batchGeometry.getIndex() !== null;
|
|
521
726
|
const dstIndex = batchGeometry.getIndex();
|
|
522
727
|
const srcIndex = geometry.getIndex();
|
|
523
|
-
const
|
|
728
|
+
const geometryInfo = this._geometryInfo[ geometryId ];
|
|
524
729
|
if (
|
|
525
730
|
hasIndex &&
|
|
526
|
-
srcIndex.count >
|
|
527
|
-
geometry.attributes.position.count >
|
|
731
|
+
srcIndex.count > geometryInfo.reservedIndexCount ||
|
|
732
|
+
geometry.attributes.position.count > geometryInfo.reservedVertexCount
|
|
528
733
|
) {
|
|
529
734
|
|
|
530
|
-
throw new Error( 'BatchedMesh: Reserved space not large enough for provided geometry.' );
|
|
735
|
+
throw new Error( 'THREE.BatchedMesh: Reserved space not large enough for provided geometry.' );
|
|
531
736
|
|
|
532
737
|
}
|
|
533
738
|
|
|
534
|
-
// copy geometry over
|
|
535
|
-
const vertexStart =
|
|
536
|
-
const
|
|
739
|
+
// copy geometry buffer data over
|
|
740
|
+
const vertexStart = geometryInfo.vertexStart;
|
|
741
|
+
const reservedVertexCount = geometryInfo.reservedVertexCount;
|
|
742
|
+
geometryInfo.vertexCount = geometry.getAttribute( 'position' ).count;
|
|
743
|
+
|
|
537
744
|
for ( const attributeName in batchGeometry.attributes ) {
|
|
538
745
|
|
|
539
746
|
// copy attribute data
|
|
@@ -543,7 +750,7 @@ class BatchedMesh extends Mesh {
|
|
|
543
750
|
|
|
544
751
|
// fill the rest in with zeroes
|
|
545
752
|
const itemSize = srcAttribute.itemSize;
|
|
546
|
-
for ( let i = srcAttribute.count, l =
|
|
753
|
+
for ( let i = srcAttribute.count, l = reservedVertexCount; i < l; i ++ ) {
|
|
547
754
|
|
|
548
755
|
const index = vertexStart + i;
|
|
549
756
|
for ( let c = 0; c < itemSize; c ++ ) {
|
|
@@ -555,14 +762,16 @@ class BatchedMesh extends Mesh {
|
|
|
555
762
|
}
|
|
556
763
|
|
|
557
764
|
dstAttribute.needsUpdate = true;
|
|
558
|
-
dstAttribute.addUpdateRange( vertexStart * itemSize,
|
|
765
|
+
dstAttribute.addUpdateRange( vertexStart * itemSize, reservedVertexCount * itemSize );
|
|
559
766
|
|
|
560
767
|
}
|
|
561
768
|
|
|
562
769
|
// copy index
|
|
563
770
|
if ( hasIndex ) {
|
|
564
771
|
|
|
565
|
-
const indexStart =
|
|
772
|
+
const indexStart = geometryInfo.indexStart;
|
|
773
|
+
const reservedIndexCount = geometryInfo.reservedIndexCount;
|
|
774
|
+
geometryInfo.indexCount = geometry.getIndex().count;
|
|
566
775
|
|
|
567
776
|
// copy index data over
|
|
568
777
|
for ( let i = 0; i < srcIndex.count; i ++ ) {
|
|
@@ -572,77 +781,199 @@ class BatchedMesh extends Mesh {
|
|
|
572
781
|
}
|
|
573
782
|
|
|
574
783
|
// fill the rest in with zeroes
|
|
575
|
-
for ( let i = srcIndex.count, l =
|
|
784
|
+
for ( let i = srcIndex.count, l = reservedIndexCount; i < l; i ++ ) {
|
|
576
785
|
|
|
577
786
|
dstIndex.setX( indexStart + i, vertexStart );
|
|
578
787
|
|
|
579
788
|
}
|
|
580
789
|
|
|
581
790
|
dstIndex.needsUpdate = true;
|
|
582
|
-
dstIndex.addUpdateRange( indexStart,
|
|
791
|
+
dstIndex.addUpdateRange( indexStart, geometryInfo.reservedIndexCount );
|
|
583
792
|
|
|
584
793
|
}
|
|
585
794
|
|
|
795
|
+
// update the draw range
|
|
796
|
+
geometryInfo.start = hasIndex ? geometryInfo.indexStart : geometryInfo.vertexStart;
|
|
797
|
+
geometryInfo.count = hasIndex ? geometryInfo.indexCount : geometryInfo.vertexCount;
|
|
798
|
+
|
|
586
799
|
// store the bounding boxes
|
|
587
|
-
|
|
800
|
+
geometryInfo.boundingBox = null;
|
|
588
801
|
if ( geometry.boundingBox !== null ) {
|
|
589
802
|
|
|
590
|
-
|
|
591
|
-
bound.boxInitialized = true;
|
|
803
|
+
geometryInfo.boundingBox = geometry.boundingBox.clone();
|
|
592
804
|
|
|
593
|
-
}
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
geometryInfo.boundingSphere = null;
|
|
808
|
+
if ( geometry.boundingSphere !== null ) {
|
|
594
809
|
|
|
595
|
-
|
|
810
|
+
geometryInfo.boundingSphere = geometry.boundingSphere.clone();
|
|
596
811
|
|
|
597
812
|
}
|
|
598
813
|
|
|
599
|
-
|
|
814
|
+
this._visibilityChanged = true;
|
|
815
|
+
return geometryId;
|
|
600
816
|
|
|
601
|
-
|
|
602
|
-
bound.sphereInitialized = true;
|
|
817
|
+
}
|
|
603
818
|
|
|
604
|
-
|
|
819
|
+
/**
|
|
820
|
+
* Deletes the geometry defined by the given ID from this batch. Any instances referencing
|
|
821
|
+
* this geometry will also be removed as a side effect.
|
|
822
|
+
*
|
|
823
|
+
* @param {number} geometryId - The ID of the geometry to remove from the batch.
|
|
824
|
+
* @return {BatchedMesh} A reference to this batched mesh.
|
|
825
|
+
*/
|
|
826
|
+
deleteGeometry( geometryId ) {
|
|
827
|
+
|
|
828
|
+
const geometryInfoList = this._geometryInfo;
|
|
829
|
+
if ( geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) {
|
|
830
|
+
|
|
831
|
+
return this;
|
|
605
832
|
|
|
606
|
-
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// delete any instances associated with this geometry
|
|
836
|
+
const instanceInfo = this._instanceInfo;
|
|
837
|
+
for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
|
|
838
|
+
|
|
839
|
+
if ( instanceInfo[ i ].active && instanceInfo[ i ].geometryIndex === geometryId ) {
|
|
840
|
+
|
|
841
|
+
this.deleteInstance( i );
|
|
842
|
+
|
|
843
|
+
}
|
|
607
844
|
|
|
608
845
|
}
|
|
609
846
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
const posAttr = geometry.getAttribute( 'position' );
|
|
613
|
-
drawRange.count = hasIndex ? srcIndex.count : posAttr.count;
|
|
847
|
+
geometryInfoList[ geometryId ].active = false;
|
|
848
|
+
this._availableGeometryIds.push( geometryId );
|
|
614
849
|
this._visibilityChanged = true;
|
|
615
850
|
|
|
616
|
-
return
|
|
851
|
+
return this;
|
|
617
852
|
|
|
618
853
|
}
|
|
619
854
|
|
|
620
|
-
|
|
621
|
-
|
|
855
|
+
/**
|
|
856
|
+
* Deletes an existing instance from the batch using the given ID.
|
|
857
|
+
*
|
|
858
|
+
* @param {number} instanceId - The ID of the instance to remove from the batch.
|
|
859
|
+
* @return {BatchedMesh} A reference to this batched mesh.
|
|
860
|
+
*/
|
|
861
|
+
deleteInstance( instanceId ) {
|
|
862
|
+
|
|
863
|
+
this.validateInstanceId( instanceId );
|
|
864
|
+
|
|
865
|
+
this._instanceInfo[ instanceId ].active = false;
|
|
866
|
+
this._availableInstanceIds.push( instanceId );
|
|
867
|
+
this._visibilityChanged = true;
|
|
622
868
|
|
|
623
|
-
|
|
869
|
+
return this;
|
|
624
870
|
|
|
625
871
|
}
|
|
626
|
-
*/
|
|
627
872
|
|
|
628
|
-
|
|
873
|
+
/**
|
|
874
|
+
* Repacks the sub geometries in BatchedMesh to remove any unused space remaining from
|
|
875
|
+
* previously deleted geometry, freeing up space to add new geometry.
|
|
876
|
+
*
|
|
877
|
+
* @return {BatchedMesh} A reference to this batched mesh.
|
|
878
|
+
*/
|
|
879
|
+
optimize() {
|
|
629
880
|
|
|
630
|
-
|
|
631
|
-
|
|
881
|
+
// track the next indices to copy data to
|
|
882
|
+
let nextVertexStart = 0;
|
|
883
|
+
let nextIndexStart = 0;
|
|
632
884
|
|
|
633
|
-
|
|
885
|
+
// Iterate over all geometry ranges in order sorted from earliest in the geometry buffer to latest
|
|
886
|
+
// in the geometry buffer. Because draw range objects can be reused there is no guarantee of their order.
|
|
887
|
+
const geometryInfoList = this._geometryInfo;
|
|
888
|
+
const indices = geometryInfoList
|
|
889
|
+
.map( ( e, i ) => i )
|
|
890
|
+
.sort( ( a, b ) => {
|
|
891
|
+
|
|
892
|
+
return geometryInfoList[ a ].vertexStart - geometryInfoList[ b ].vertexStart;
|
|
893
|
+
|
|
894
|
+
} );
|
|
895
|
+
|
|
896
|
+
const geometry = this.geometry;
|
|
897
|
+
for ( let i = 0, l = geometryInfoList.length; i < l; i ++ ) {
|
|
898
|
+
|
|
899
|
+
// if a geometry range is inactive then don't copy anything
|
|
900
|
+
const index = indices[ i ];
|
|
901
|
+
const geometryInfo = geometryInfoList[ index ];
|
|
902
|
+
if ( geometryInfo.active === false ) {
|
|
903
|
+
|
|
904
|
+
continue;
|
|
905
|
+
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// if a geometry contains an index buffer then shift it, as well
|
|
909
|
+
if ( geometry.index !== null ) {
|
|
910
|
+
|
|
911
|
+
if ( geometryInfo.indexStart !== nextIndexStart ) {
|
|
912
|
+
|
|
913
|
+
const { indexStart, vertexStart, reservedIndexCount } = geometryInfo;
|
|
914
|
+
const index = geometry.index;
|
|
915
|
+
const array = index.array;
|
|
916
|
+
|
|
917
|
+
// shift the index pointers based on how the vertex data will shift
|
|
918
|
+
// adjusting the index must happen first so the original vertex start value is available
|
|
919
|
+
const elementDelta = nextVertexStart - vertexStart;
|
|
920
|
+
for ( let j = indexStart; j < indexStart + reservedIndexCount; j ++ ) {
|
|
921
|
+
|
|
922
|
+
array[ j ] = array[ j ] + elementDelta;
|
|
923
|
+
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
index.array.copyWithin( nextIndexStart, indexStart, indexStart + reservedIndexCount );
|
|
927
|
+
index.addUpdateRange( nextIndexStart, reservedIndexCount );
|
|
928
|
+
index.needsUpdate = true;
|
|
929
|
+
|
|
930
|
+
geometryInfo.indexStart = nextIndexStart;
|
|
931
|
+
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
nextIndexStart += geometryInfo.reservedIndexCount;
|
|
935
|
+
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
// if a geometry needs to be moved then copy attribute data to overwrite unused space
|
|
939
|
+
if ( geometryInfo.vertexStart !== nextVertexStart ) {
|
|
940
|
+
|
|
941
|
+
const { vertexStart, reservedVertexCount } = geometryInfo;
|
|
942
|
+
const attributes = geometry.attributes;
|
|
943
|
+
for ( const key in attributes ) {
|
|
944
|
+
|
|
945
|
+
const attribute = attributes[ key ];
|
|
946
|
+
const { array, itemSize } = attribute;
|
|
947
|
+
array.copyWithin( nextVertexStart * itemSize, vertexStart * itemSize, ( vertexStart + reservedVertexCount ) * itemSize );
|
|
948
|
+
attribute.addUpdateRange( nextVertexStart * itemSize, reservedVertexCount * itemSize );
|
|
949
|
+
attribute.needsUpdate = true;
|
|
950
|
+
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
geometryInfo.vertexStart = nextVertexStart;
|
|
954
|
+
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
nextVertexStart += geometryInfo.reservedVertexCount;
|
|
958
|
+
geometryInfo.start = geometry.index ? geometryInfo.indexStart : geometryInfo.vertexStart;
|
|
634
959
|
|
|
635
960
|
}
|
|
636
961
|
|
|
637
|
-
|
|
638
|
-
this.
|
|
962
|
+
this._nextIndexStart = nextIndexStart;
|
|
963
|
+
this._nextVertexStart = nextVertexStart;
|
|
639
964
|
this._visibilityChanged = true;
|
|
640
965
|
|
|
641
966
|
return this;
|
|
642
967
|
|
|
643
968
|
}
|
|
644
969
|
|
|
645
|
-
|
|
970
|
+
/**
|
|
971
|
+
* Returns the bounding box for the given geometry.
|
|
972
|
+
*
|
|
973
|
+
* @param {number} geometryId - The ID of the geometry to return the bounding box for.
|
|
974
|
+
* @param {Box3} target - The target object that is used to store the method's result.
|
|
975
|
+
* @return {?Box3} The geometry's bounding box. Returns `null` if no geometry has been found for the given ID.
|
|
976
|
+
*/
|
|
646
977
|
getBoundingBoxAt( geometryId, target ) {
|
|
647
978
|
|
|
648
979
|
if ( geometryId >= this._geometryCount ) {
|
|
@@ -652,17 +983,14 @@ class BatchedMesh extends Mesh {
|
|
|
652
983
|
}
|
|
653
984
|
|
|
654
985
|
// compute bounding box
|
|
655
|
-
const bound = this._bounds[ geometryId ];
|
|
656
|
-
const box = bound.box;
|
|
657
986
|
const geometry = this.geometry;
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
box.makeEmpty();
|
|
987
|
+
const geometryInfo = this._geometryInfo[ geometryId ];
|
|
988
|
+
if ( geometryInfo.boundingBox === null ) {
|
|
661
989
|
|
|
990
|
+
const box = new Box3();
|
|
662
991
|
const index = geometry.index;
|
|
663
992
|
const position = geometry.attributes.position;
|
|
664
|
-
|
|
665
|
-
for ( let i = drawRange.start, l = drawRange.start + drawRange.count; i < l; i ++ ) {
|
|
993
|
+
for ( let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count; i < l; i ++ ) {
|
|
666
994
|
|
|
667
995
|
let iv = i;
|
|
668
996
|
if ( index ) {
|
|
@@ -675,16 +1003,22 @@ class BatchedMesh extends Mesh {
|
|
|
675
1003
|
|
|
676
1004
|
}
|
|
677
1005
|
|
|
678
|
-
|
|
1006
|
+
geometryInfo.boundingBox = box;
|
|
679
1007
|
|
|
680
1008
|
}
|
|
681
1009
|
|
|
682
|
-
target.copy(
|
|
1010
|
+
target.copy( geometryInfo.boundingBox );
|
|
683
1011
|
return target;
|
|
684
1012
|
|
|
685
1013
|
}
|
|
686
1014
|
|
|
687
|
-
|
|
1015
|
+
/**
|
|
1016
|
+
* Returns the bounding sphere for the given geometry.
|
|
1017
|
+
*
|
|
1018
|
+
* @param {number} geometryId - The ID of the geometry to return the bounding sphere for.
|
|
1019
|
+
* @param {Sphere} target - The target object that is used to store the method's result.
|
|
1020
|
+
* @return {?Sphere} The geometry's bounding sphere. Returns `null` if no geometry has been found for the given ID.
|
|
1021
|
+
*/
|
|
688
1022
|
getBoundingSphereAt( geometryId, target ) {
|
|
689
1023
|
|
|
690
1024
|
if ( geometryId >= this._geometryCount ) {
|
|
@@ -694,22 +1028,19 @@ class BatchedMesh extends Mesh {
|
|
|
694
1028
|
}
|
|
695
1029
|
|
|
696
1030
|
// compute bounding sphere
|
|
697
|
-
const bound = this._bounds[ geometryId ];
|
|
698
|
-
const sphere = bound.sphere;
|
|
699
1031
|
const geometry = this.geometry;
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
sphere.makeEmpty();
|
|
1032
|
+
const geometryInfo = this._geometryInfo[ geometryId ];
|
|
1033
|
+
if ( geometryInfo.boundingSphere === null ) {
|
|
703
1034
|
|
|
1035
|
+
const sphere = new Sphere();
|
|
704
1036
|
this.getBoundingBoxAt( geometryId, _box );
|
|
705
1037
|
_box.getCenter( sphere.center );
|
|
706
1038
|
|
|
707
1039
|
const index = geometry.index;
|
|
708
1040
|
const position = geometry.attributes.position;
|
|
709
|
-
const drawRange = this._drawRanges[ geometryId ];
|
|
710
1041
|
|
|
711
1042
|
let maxRadiusSq = 0;
|
|
712
|
-
for ( let i =
|
|
1043
|
+
for ( let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count; i < l; i ++ ) {
|
|
713
1044
|
|
|
714
1045
|
let iv = i;
|
|
715
1046
|
if ( index ) {
|
|
@@ -724,29 +1055,29 @@ class BatchedMesh extends Mesh {
|
|
|
724
1055
|
}
|
|
725
1056
|
|
|
726
1057
|
sphere.radius = Math.sqrt( maxRadiusSq );
|
|
727
|
-
|
|
1058
|
+
geometryInfo.boundingSphere = sphere;
|
|
728
1059
|
|
|
729
1060
|
}
|
|
730
1061
|
|
|
731
|
-
target.copy(
|
|
1062
|
+
target.copy( geometryInfo.boundingSphere );
|
|
732
1063
|
return target;
|
|
733
1064
|
|
|
734
1065
|
}
|
|
735
1066
|
|
|
1067
|
+
/**
|
|
1068
|
+
* Sets the given local transformation matrix to the defined instance.
|
|
1069
|
+
* Negatively scaled matrices are not supported.
|
|
1070
|
+
*
|
|
1071
|
+
* @param {number} instanceId - The ID of an instance to set the matrix of.
|
|
1072
|
+
* @param {Matrix4} matrix - A 4x4 matrix representing the local transformation of a single instance.
|
|
1073
|
+
* @return {BatchedMesh} A reference to this batched mesh.
|
|
1074
|
+
*/
|
|
736
1075
|
setMatrixAt( instanceId, matrix ) {
|
|
737
1076
|
|
|
738
|
-
|
|
739
|
-
// optimize() can make geometryId mismatch the index
|
|
1077
|
+
this.validateInstanceId( instanceId );
|
|
740
1078
|
|
|
741
|
-
const drawInfo = this._drawInfo;
|
|
742
1079
|
const matricesTexture = this._matricesTexture;
|
|
743
1080
|
const matricesArray = this._matricesTexture.image.data;
|
|
744
|
-
if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {
|
|
745
|
-
|
|
746
|
-
return this;
|
|
747
|
-
|
|
748
|
-
}
|
|
749
|
-
|
|
750
1081
|
matrix.toArray( matricesArray, instanceId * 16 );
|
|
751
1082
|
matricesTexture.needsUpdate = true;
|
|
752
1083
|
|
|
@@ -754,154 +1085,289 @@ class BatchedMesh extends Mesh {
|
|
|
754
1085
|
|
|
755
1086
|
}
|
|
756
1087
|
|
|
1088
|
+
/**
|
|
1089
|
+
* Returns the local transformation matrix of the defined instance.
|
|
1090
|
+
*
|
|
1091
|
+
* @param {number} instanceId - The ID of an instance to get the matrix of.
|
|
1092
|
+
* @param {Matrix4} matrix - The target object that is used to store the method's result.
|
|
1093
|
+
* @return {Matrix4} The instance's local transformation matrix.
|
|
1094
|
+
*/
|
|
757
1095
|
getMatrixAt( instanceId, matrix ) {
|
|
758
1096
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {
|
|
762
|
-
|
|
763
|
-
return null;
|
|
764
|
-
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
return matrix.fromArray( matricesArray, instanceId * 16 );
|
|
1097
|
+
this.validateInstanceId( instanceId );
|
|
1098
|
+
return matrix.fromArray( this._matricesTexture.image.data, instanceId * 16 );
|
|
768
1099
|
|
|
769
1100
|
}
|
|
770
1101
|
|
|
1102
|
+
/**
|
|
1103
|
+
* Sets the given color to the defined instance.
|
|
1104
|
+
*
|
|
1105
|
+
* @param {number} instanceId - The ID of an instance to set the color of.
|
|
1106
|
+
* @param {Color|Vector4} color - The color to set the instance to. Use a `Vector4` to also define alpha.
|
|
1107
|
+
* @return {BatchedMesh} A reference to this batched mesh.
|
|
1108
|
+
*/
|
|
771
1109
|
setColorAt( instanceId, color ) {
|
|
772
1110
|
|
|
1111
|
+
this.validateInstanceId( instanceId );
|
|
1112
|
+
|
|
773
1113
|
if ( this._colorsTexture === null ) {
|
|
774
1114
|
|
|
775
1115
|
this._initColorsTexture();
|
|
776
1116
|
|
|
777
1117
|
}
|
|
778
1118
|
|
|
779
|
-
|
|
780
|
-
|
|
1119
|
+
color.toArray( this._colorsTexture.image.data, instanceId * 4 );
|
|
1120
|
+
this._colorsTexture.needsUpdate = true;
|
|
781
1121
|
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
1122
|
+
return this;
|
|
1123
|
+
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
/**
|
|
1127
|
+
* Returns the color of the defined instance.
|
|
1128
|
+
*
|
|
1129
|
+
* @param {number} instanceId - The ID of an instance to get the color of.
|
|
1130
|
+
* @param {Color|Vector4} color - The target object that is used to store the method's result.
|
|
1131
|
+
* @return {Color|Vector4} The instance's color. Use a `Vector4` to also retrieve alpha.
|
|
1132
|
+
*/
|
|
1133
|
+
getColorAt( instanceId, color ) {
|
|
1134
|
+
|
|
1135
|
+
this.validateInstanceId( instanceId );
|
|
1136
|
+
return color.fromArray( this._colorsTexture.image.data, instanceId * 4 );
|
|
1137
|
+
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
/**
|
|
1141
|
+
* Sets the visibility of the instance.
|
|
1142
|
+
*
|
|
1143
|
+
* @param {number} instanceId - The id of the instance to set the visibility of.
|
|
1144
|
+
* @param {boolean} visible - Whether the instance is visible or not.
|
|
1145
|
+
* @return {BatchedMesh} A reference to this batched mesh.
|
|
1146
|
+
*/
|
|
1147
|
+
setVisibleAt( instanceId, visible ) {
|
|
1148
|
+
|
|
1149
|
+
this.validateInstanceId( instanceId );
|
|
1150
|
+
|
|
1151
|
+
if ( this._instanceInfo[ instanceId ].visible === visible ) {
|
|
786
1152
|
|
|
787
1153
|
return this;
|
|
788
1154
|
|
|
789
1155
|
}
|
|
790
1156
|
|
|
791
|
-
|
|
792
|
-
|
|
1157
|
+
this._instanceInfo[ instanceId ].visible = visible;
|
|
1158
|
+
this._visibilityChanged = true;
|
|
793
1159
|
|
|
794
1160
|
return this;
|
|
795
1161
|
|
|
796
1162
|
}
|
|
797
1163
|
|
|
798
|
-
|
|
1164
|
+
/**
|
|
1165
|
+
* Returns the visibility state of the defined instance.
|
|
1166
|
+
*
|
|
1167
|
+
* @param {number} instanceId - The ID of an instance to get the visibility state of.
|
|
1168
|
+
* @return {boolean} Whether the instance is visible or not.
|
|
1169
|
+
*/
|
|
1170
|
+
getVisibleAt( instanceId ) {
|
|
799
1171
|
|
|
800
|
-
|
|
801
|
-
const drawInfo = this._drawInfo;
|
|
802
|
-
if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {
|
|
1172
|
+
this.validateInstanceId( instanceId );
|
|
803
1173
|
|
|
804
|
-
|
|
1174
|
+
return this._instanceInfo[ instanceId ].visible;
|
|
805
1175
|
|
|
806
|
-
|
|
1176
|
+
}
|
|
807
1177
|
|
|
808
|
-
|
|
1178
|
+
/**
|
|
1179
|
+
* Sets the geometry ID of the instance at the given index.
|
|
1180
|
+
*
|
|
1181
|
+
* @param {number} instanceId - The ID of the instance to set the geometry ID of.
|
|
1182
|
+
* @param {number} geometryId - The geometry ID to be use by the instance.
|
|
1183
|
+
* @return {BatchedMesh} A reference to this batched mesh.
|
|
1184
|
+
*/
|
|
1185
|
+
setGeometryIdAt( instanceId, geometryId ) {
|
|
809
1186
|
|
|
810
|
-
|
|
1187
|
+
this.validateInstanceId( instanceId );
|
|
1188
|
+
this.validateGeometryId( geometryId );
|
|
811
1189
|
|
|
812
|
-
|
|
1190
|
+
this._instanceInfo[ instanceId ].geometryIndex = geometryId;
|
|
813
1191
|
|
|
814
|
-
|
|
815
|
-
// does not change then return early
|
|
816
|
-
const drawInfo = this._drawInfo;
|
|
817
|
-
if (
|
|
818
|
-
instanceId >= drawInfo.length ||
|
|
819
|
-
drawInfo[ instanceId ].active === false ||
|
|
820
|
-
drawInfo[ instanceId ].visible === value
|
|
821
|
-
) {
|
|
1192
|
+
return this;
|
|
822
1193
|
|
|
823
|
-
|
|
1194
|
+
}
|
|
824
1195
|
|
|
825
|
-
|
|
1196
|
+
/**
|
|
1197
|
+
* Returns the geometry ID of the defined instance.
|
|
1198
|
+
*
|
|
1199
|
+
* @param {number} instanceId - The ID of an instance to get the geometry ID of.
|
|
1200
|
+
* @return {number} The instance's geometry ID.
|
|
1201
|
+
*/
|
|
1202
|
+
getGeometryIdAt( instanceId ) {
|
|
826
1203
|
|
|
827
|
-
|
|
828
|
-
this._visibilityChanged = true;
|
|
1204
|
+
this.validateInstanceId( instanceId );
|
|
829
1205
|
|
|
830
|
-
return this;
|
|
1206
|
+
return this._instanceInfo[ instanceId ].geometryIndex;
|
|
831
1207
|
|
|
832
1208
|
}
|
|
833
1209
|
|
|
834
|
-
|
|
1210
|
+
/**
|
|
1211
|
+
* Get the range representing the subset of triangles related to the attached geometry,
|
|
1212
|
+
* indicating the starting offset and count, or `null` if invalid.
|
|
1213
|
+
*
|
|
1214
|
+
* @param {number} geometryId - The id of the geometry to get the range of.
|
|
1215
|
+
* @param {Object} [target] - The target object that is used to store the method's result.
|
|
1216
|
+
* @return {{
|
|
1217
|
+
* vertexStart:number,vertexCount:number,reservedVertexCount:number,
|
|
1218
|
+
* indexStart:number,indexCount:number,reservedIndexCount:number,
|
|
1219
|
+
* start:number,count:number
|
|
1220
|
+
* }} The result object with range data.
|
|
1221
|
+
*/
|
|
1222
|
+
getGeometryRangeAt( geometryId, target = {} ) {
|
|
835
1223
|
|
|
836
|
-
|
|
837
|
-
const drawInfo = this._drawInfo;
|
|
838
|
-
if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {
|
|
1224
|
+
this.validateGeometryId( geometryId );
|
|
839
1225
|
|
|
840
|
-
|
|
1226
|
+
const geometryInfo = this._geometryInfo[ geometryId ];
|
|
1227
|
+
target.vertexStart = geometryInfo.vertexStart;
|
|
1228
|
+
target.vertexCount = geometryInfo.vertexCount;
|
|
1229
|
+
target.reservedVertexCount = geometryInfo.reservedVertexCount;
|
|
841
1230
|
|
|
842
|
-
|
|
1231
|
+
target.indexStart = geometryInfo.indexStart;
|
|
1232
|
+
target.indexCount = geometryInfo.indexCount;
|
|
1233
|
+
target.reservedIndexCount = geometryInfo.reservedIndexCount;
|
|
843
1234
|
|
|
844
|
-
|
|
1235
|
+
target.start = geometryInfo.start;
|
|
1236
|
+
target.count = geometryInfo.count;
|
|
1237
|
+
|
|
1238
|
+
return target;
|
|
845
1239
|
|
|
846
1240
|
}
|
|
847
1241
|
|
|
848
|
-
|
|
1242
|
+
/**
|
|
1243
|
+
* Resizes the necessary buffers to support the provided number of instances.
|
|
1244
|
+
* If the provided arguments shrink the number of instances but there are not enough
|
|
1245
|
+
* unused Ids at the end of the list then an error is thrown.
|
|
1246
|
+
*
|
|
1247
|
+
* @param {number} maxInstanceCount - The max number of individual instances that can be added and rendered by the batch.
|
|
1248
|
+
*/
|
|
1249
|
+
setInstanceCount( maxInstanceCount ) {
|
|
849
1250
|
|
|
850
|
-
//
|
|
851
|
-
const
|
|
852
|
-
|
|
1251
|
+
// shrink the available instances as much as possible
|
|
1252
|
+
const availableInstanceIds = this._availableInstanceIds;
|
|
1253
|
+
const instanceInfo = this._instanceInfo;
|
|
1254
|
+
availableInstanceIds.sort( ascIdSort );
|
|
1255
|
+
while ( availableInstanceIds[ availableInstanceIds.length - 1 ] === instanceInfo.length - 1 ) {
|
|
853
1256
|
|
|
854
|
-
|
|
1257
|
+
instanceInfo.pop();
|
|
1258
|
+
availableInstanceIds.pop();
|
|
855
1259
|
|
|
856
1260
|
}
|
|
857
1261
|
|
|
858
|
-
//
|
|
859
|
-
if (
|
|
1262
|
+
// throw an error if it can't be shrunk to the desired size
|
|
1263
|
+
if ( maxInstanceCount < instanceInfo.length ) {
|
|
860
1264
|
|
|
861
|
-
|
|
1265
|
+
throw new Error( `BatchedMesh: Instance ids outside the range ${ maxInstanceCount } are being used. Cannot shrink instance count.` );
|
|
862
1266
|
|
|
863
1267
|
}
|
|
864
1268
|
|
|
865
|
-
|
|
1269
|
+
// copy the multi draw counts
|
|
1270
|
+
const multiDrawCounts = new Int32Array( maxInstanceCount );
|
|
1271
|
+
const multiDrawStarts = new Int32Array( maxInstanceCount );
|
|
1272
|
+
copyArrayContents( this._multiDrawCounts, multiDrawCounts );
|
|
1273
|
+
copyArrayContents( this._multiDrawStarts, multiDrawStarts );
|
|
866
1274
|
|
|
867
|
-
|
|
1275
|
+
this._multiDrawCounts = multiDrawCounts;
|
|
1276
|
+
this._multiDrawStarts = multiDrawStarts;
|
|
1277
|
+
this._maxInstanceCount = maxInstanceCount;
|
|
1278
|
+
|
|
1279
|
+
// update texture data for instance sampling
|
|
1280
|
+
const indirectTexture = this._indirectTexture;
|
|
1281
|
+
const matricesTexture = this._matricesTexture;
|
|
1282
|
+
const colorsTexture = this._colorsTexture;
|
|
1283
|
+
|
|
1284
|
+
indirectTexture.dispose();
|
|
1285
|
+
this._initIndirectTexture();
|
|
1286
|
+
copyArrayContents( indirectTexture.image.data, this._indirectTexture.image.data );
|
|
1287
|
+
|
|
1288
|
+
matricesTexture.dispose();
|
|
1289
|
+
this._initMatricesTexture();
|
|
1290
|
+
copyArrayContents( matricesTexture.image.data, this._matricesTexture.image.data );
|
|
1291
|
+
|
|
1292
|
+
if ( colorsTexture ) {
|
|
1293
|
+
|
|
1294
|
+
colorsTexture.dispose();
|
|
1295
|
+
this._initColorsTexture();
|
|
1296
|
+
copyArrayContents( colorsTexture.image.data, this._colorsTexture.image.data );
|
|
1297
|
+
|
|
1298
|
+
}
|
|
868
1299
|
|
|
869
1300
|
}
|
|
870
1301
|
|
|
871
|
-
|
|
1302
|
+
/**
|
|
1303
|
+
* Resizes the available space in the batch's vertex and index buffer attributes to the provided sizes.
|
|
1304
|
+
* If the provided arguments shrink the geometry buffers but there is not enough unused space at the
|
|
1305
|
+
* end of the geometry attributes then an error is thrown.
|
|
1306
|
+
*
|
|
1307
|
+
* @param {number} maxVertexCount - The maximum number of vertices to be used by all unique geometries to resize to.
|
|
1308
|
+
* @param {number} maxIndexCount - The maximum number of indices to be used by all unique geometries to resize to.
|
|
1309
|
+
*/
|
|
1310
|
+
setGeometrySize( maxVertexCount, maxIndexCount ) {
|
|
872
1311
|
|
|
873
|
-
|
|
874
|
-
|
|
1312
|
+
// Check if we can shrink to the requested vertex attribute size
|
|
1313
|
+
const validRanges = [ ...this._geometryInfo ].filter( info => info.active );
|
|
1314
|
+
const requiredVertexLength = Math.max( ...validRanges.map( range => range.vertexStart + range.reservedVertexCount ) );
|
|
1315
|
+
if ( requiredVertexLength > maxVertexCount ) {
|
|
875
1316
|
|
|
876
|
-
|
|
1317
|
+
throw new Error( `BatchedMesh: Geometry vertex values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );
|
|
877
1318
|
|
|
878
1319
|
}
|
|
879
1320
|
|
|
880
|
-
|
|
1321
|
+
// Check if we can shrink to the requested index attribute size
|
|
1322
|
+
if ( this.geometry.index ) {
|
|
881
1323
|
|
|
882
|
-
|
|
1324
|
+
const requiredIndexLength = Math.max( ...validRanges.map( range => range.indexStart + range.reservedIndexCount ) );
|
|
1325
|
+
if ( requiredIndexLength > maxIndexCount ) {
|
|
883
1326
|
|
|
884
|
-
|
|
1327
|
+
throw new Error( `BatchedMesh: Geometry index values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );
|
|
885
1328
|
|
|
886
|
-
|
|
1329
|
+
}
|
|
887
1330
|
|
|
888
|
-
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
//
|
|
1334
|
+
|
|
1335
|
+
// dispose of the previous geometry
|
|
1336
|
+
const oldGeometry = this.geometry;
|
|
1337
|
+
oldGeometry.dispose();
|
|
1338
|
+
|
|
1339
|
+
// recreate the geometry needed based on the previous variant
|
|
1340
|
+
this._maxVertexCount = maxVertexCount;
|
|
1341
|
+
this._maxIndexCount = maxIndexCount;
|
|
1342
|
+
|
|
1343
|
+
if ( this._geometryInitialized ) {
|
|
1344
|
+
|
|
1345
|
+
this._geometryInitialized = false;
|
|
1346
|
+
this.geometry = new BufferGeometry();
|
|
1347
|
+
this._initializeGeometry( oldGeometry );
|
|
889
1348
|
|
|
890
1349
|
}
|
|
891
1350
|
|
|
892
|
-
|
|
1351
|
+
// copy data from the previous geometry
|
|
1352
|
+
const geometry = this.geometry;
|
|
1353
|
+
if ( oldGeometry.index ) {
|
|
893
1354
|
|
|
894
|
-
|
|
895
|
-
target.count = drawRange.count;
|
|
1355
|
+
copyArrayContents( oldGeometry.index.array, geometry.index.array );
|
|
896
1356
|
|
|
897
|
-
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
for ( const key in oldGeometry.attributes ) {
|
|
1360
|
+
|
|
1361
|
+
copyArrayContents( oldGeometry.attributes[ key ].array, geometry.attributes[ key ].array );
|
|
1362
|
+
|
|
1363
|
+
}
|
|
898
1364
|
|
|
899
1365
|
}
|
|
900
1366
|
|
|
901
1367
|
raycast( raycaster, intersects ) {
|
|
902
1368
|
|
|
903
|
-
const
|
|
904
|
-
const
|
|
1369
|
+
const instanceInfo = this._instanceInfo;
|
|
1370
|
+
const geometryInfoList = this._geometryInfo;
|
|
905
1371
|
const matrixWorld = this.matrixWorld;
|
|
906
1372
|
const batchGeometry = this.geometry;
|
|
907
1373
|
|
|
@@ -921,19 +1387,19 @@ class BatchedMesh extends Mesh {
|
|
|
921
1387
|
|
|
922
1388
|
}
|
|
923
1389
|
|
|
924
|
-
for ( let i = 0, l =
|
|
1390
|
+
for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
|
|
925
1391
|
|
|
926
|
-
if ( !
|
|
1392
|
+
if ( ! instanceInfo[ i ].visible || ! instanceInfo[ i ].active ) {
|
|
927
1393
|
|
|
928
1394
|
continue;
|
|
929
1395
|
|
|
930
1396
|
}
|
|
931
1397
|
|
|
932
|
-
const geometryId =
|
|
933
|
-
const
|
|
934
|
-
_mesh.geometry.setDrawRange(
|
|
1398
|
+
const geometryId = instanceInfo[ i ].geometryIndex;
|
|
1399
|
+
const geometryInfo = geometryInfoList[ geometryId ];
|
|
1400
|
+
_mesh.geometry.setDrawRange( geometryInfo.start, geometryInfo.count );
|
|
935
1401
|
|
|
936
|
-
//
|
|
1402
|
+
// get the intersects
|
|
937
1403
|
this.getMatrixAt( i, _mesh.matrixWorld ).premultiply( matrixWorld );
|
|
938
1404
|
this.getBoundingBoxAt( geometryId, _mesh.geometry.boundingBox );
|
|
939
1405
|
this.getBoundingSphereAt( geometryId, _mesh.geometry.boundingSphere );
|
|
@@ -970,27 +1436,32 @@ class BatchedMesh extends Mesh {
|
|
|
970
1436
|
this.boundingBox = source.boundingBox !== null ? source.boundingBox.clone() : null;
|
|
971
1437
|
this.boundingSphere = source.boundingSphere !== null ? source.boundingSphere.clone() : null;
|
|
972
1438
|
|
|
973
|
-
this.
|
|
974
|
-
|
|
1439
|
+
this._geometryInfo = source._geometryInfo.map( info => ( {
|
|
1440
|
+
...info,
|
|
975
1441
|
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
boxInitialized: bound.boxInitialized,
|
|
979
|
-
box: bound.box.clone(),
|
|
980
|
-
|
|
981
|
-
sphereInitialized: bound.sphereInitialized,
|
|
982
|
-
sphere: bound.sphere.clone()
|
|
1442
|
+
boundingBox: info.boundingBox !== null ? info.boundingBox.clone() : null,
|
|
1443
|
+
boundingSphere: info.boundingSphere !== null ? info.boundingSphere.clone() : null,
|
|
983
1444
|
} ) );
|
|
1445
|
+
this._instanceInfo = source._instanceInfo.map( info => ( { ...info } ) );
|
|
1446
|
+
|
|
1447
|
+
this._availableInstanceIds = source._availableInstanceIds.slice();
|
|
1448
|
+
this._availableGeometryIds = source._availableGeometryIds.slice();
|
|
1449
|
+
|
|
1450
|
+
this._nextIndexStart = source._nextIndexStart;
|
|
1451
|
+
this._nextVertexStart = source._nextVertexStart;
|
|
1452
|
+
this._geometryCount = source._geometryCount;
|
|
984
1453
|
|
|
985
1454
|
this._maxInstanceCount = source._maxInstanceCount;
|
|
986
1455
|
this._maxVertexCount = source._maxVertexCount;
|
|
987
1456
|
this._maxIndexCount = source._maxIndexCount;
|
|
988
1457
|
|
|
989
1458
|
this._geometryInitialized = source._geometryInitialized;
|
|
990
|
-
this._geometryCount = source._geometryCount;
|
|
991
1459
|
this._multiDrawCounts = source._multiDrawCounts.slice();
|
|
992
1460
|
this._multiDrawStarts = source._multiDrawStarts.slice();
|
|
993
1461
|
|
|
1462
|
+
this._indirectTexture = source._indirectTexture.clone();
|
|
1463
|
+
this._indirectTexture.image.data = this._indirectTexture.image.data.slice();
|
|
1464
|
+
|
|
994
1465
|
this._matricesTexture = source._matricesTexture.clone();
|
|
995
1466
|
this._matricesTexture.image.data = this._matricesTexture.image.data.slice();
|
|
996
1467
|
|
|
@@ -1005,6 +1476,10 @@ class BatchedMesh extends Mesh {
|
|
|
1005
1476
|
|
|
1006
1477
|
}
|
|
1007
1478
|
|
|
1479
|
+
/**
|
|
1480
|
+
* Frees the GPU-related resources allocated by this instance. Call this
|
|
1481
|
+
* method whenever this instance is no longer used in your app.
|
|
1482
|
+
*/
|
|
1008
1483
|
dispose() {
|
|
1009
1484
|
|
|
1010
1485
|
// Assuming the geometry is not shared with other meshes
|
|
@@ -1023,8 +1498,6 @@ class BatchedMesh extends Mesh {
|
|
|
1023
1498
|
|
|
1024
1499
|
}
|
|
1025
1500
|
|
|
1026
|
-
return this;
|
|
1027
|
-
|
|
1028
1501
|
}
|
|
1029
1502
|
|
|
1030
1503
|
onBeforeRender( renderer, scene, camera, geometry, material/*, _group*/ ) {
|
|
@@ -1040,42 +1513,57 @@ class BatchedMesh extends Mesh {
|
|
|
1040
1513
|
// the indexed version of the multi draw function requires specifying the start
|
|
1041
1514
|
// offset in bytes.
|
|
1042
1515
|
const index = geometry.getIndex();
|
|
1043
|
-
|
|
1516
|
+
let bytesPerElement = index === null ? 1 : index.array.BYTES_PER_ELEMENT;
|
|
1517
|
+
|
|
1518
|
+
|
|
1519
|
+
// the "wireframe" attribute implicitly creates a line attribute in the renderer, which is double
|
|
1520
|
+
// the vertices to draw (3 lines per triangle) so we multiply the draw counts / starts and make
|
|
1521
|
+
// assumptions about the index buffer byte size.
|
|
1522
|
+
let multiDrawMultiplier = 1;
|
|
1523
|
+
if ( material.wireframe ) {
|
|
1044
1524
|
|
|
1045
|
-
|
|
1525
|
+
multiDrawMultiplier = 2;
|
|
1526
|
+
bytesPerElement = geometry.attributes.position.count > 65535 ? 4 : 2;
|
|
1527
|
+
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
const instanceInfo = this._instanceInfo;
|
|
1046
1531
|
const multiDrawStarts = this._multiDrawStarts;
|
|
1047
1532
|
const multiDrawCounts = this._multiDrawCounts;
|
|
1048
|
-
const
|
|
1533
|
+
const geometryInfoList = this._geometryInfo;
|
|
1049
1534
|
const perObjectFrustumCulled = this.perObjectFrustumCulled;
|
|
1050
1535
|
const indirectTexture = this._indirectTexture;
|
|
1051
1536
|
const indirectArray = indirectTexture.image.data;
|
|
1052
1537
|
|
|
1538
|
+
const frustum = camera.isArrayCamera ? _frustumArray : _frustum;
|
|
1053
1539
|
// prepare the frustum in the local frame
|
|
1054
|
-
if ( perObjectFrustumCulled ) {
|
|
1540
|
+
if ( perObjectFrustumCulled && ! camera.isArrayCamera ) {
|
|
1055
1541
|
|
|
1056
|
-
|
|
1542
|
+
_matrix
|
|
1057
1543
|
.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse )
|
|
1058
1544
|
.multiply( this.matrixWorld );
|
|
1545
|
+
|
|
1059
1546
|
_frustum.setFromProjectionMatrix(
|
|
1060
|
-
|
|
1061
|
-
|
|
1547
|
+
_matrix,
|
|
1548
|
+
camera.coordinateSystem,
|
|
1549
|
+
camera.reversedDepth
|
|
1062
1550
|
);
|
|
1063
1551
|
|
|
1064
1552
|
}
|
|
1065
1553
|
|
|
1066
|
-
let
|
|
1554
|
+
let multiDrawCount = 0;
|
|
1067
1555
|
if ( this.sortObjects ) {
|
|
1068
1556
|
|
|
1069
1557
|
// get the camera position in the local frame
|
|
1070
|
-
|
|
1071
|
-
_vector.setFromMatrixPosition( camera.matrixWorld ).applyMatrix4(
|
|
1072
|
-
_forward.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld ).transformDirection(
|
|
1558
|
+
_matrix.copy( this.matrixWorld ).invert();
|
|
1559
|
+
_vector.setFromMatrixPosition( camera.matrixWorld ).applyMatrix4( _matrix );
|
|
1560
|
+
_forward.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld ).transformDirection( _matrix );
|
|
1073
1561
|
|
|
1074
|
-
for ( let i = 0, l =
|
|
1562
|
+
for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
|
|
1075
1563
|
|
|
1076
|
-
if (
|
|
1564
|
+
if ( instanceInfo[ i ].visible && instanceInfo[ i ].active ) {
|
|
1077
1565
|
|
|
1078
|
-
const geometryId =
|
|
1566
|
+
const geometryId = instanceInfo[ i ].geometryIndex;
|
|
1079
1567
|
|
|
1080
1568
|
// get the bounds in world space
|
|
1081
1569
|
this.getMatrixAt( i, _matrix );
|
|
@@ -1085,15 +1573,16 @@ class BatchedMesh extends Mesh {
|
|
|
1085
1573
|
let culled = false;
|
|
1086
1574
|
if ( perObjectFrustumCulled ) {
|
|
1087
1575
|
|
|
1088
|
-
culled = !
|
|
1576
|
+
culled = ! frustum.intersectsSphere( _sphere, camera );
|
|
1089
1577
|
|
|
1090
1578
|
}
|
|
1091
1579
|
|
|
1092
1580
|
if ( ! culled ) {
|
|
1093
1581
|
|
|
1094
1582
|
// get the distance from camera used for sorting
|
|
1583
|
+
const geometryInfo = geometryInfoList[ geometryId ];
|
|
1095
1584
|
const z = _temp.subVectors( _sphere.center, _vector ).dot( _forward );
|
|
1096
|
-
_renderList.push(
|
|
1585
|
+
_renderList.push( geometryInfo.start, geometryInfo.count, z, i );
|
|
1097
1586
|
|
|
1098
1587
|
}
|
|
1099
1588
|
|
|
@@ -1117,10 +1606,10 @@ class BatchedMesh extends Mesh {
|
|
|
1117
1606
|
for ( let i = 0, l = list.length; i < l; i ++ ) {
|
|
1118
1607
|
|
|
1119
1608
|
const item = list[ i ];
|
|
1120
|
-
multiDrawStarts[
|
|
1121
|
-
multiDrawCounts[
|
|
1122
|
-
indirectArray[
|
|
1123
|
-
|
|
1609
|
+
multiDrawStarts[ multiDrawCount ] = item.start * bytesPerElement * multiDrawMultiplier;
|
|
1610
|
+
multiDrawCounts[ multiDrawCount ] = item.count * multiDrawMultiplier;
|
|
1611
|
+
indirectArray[ multiDrawCount ] = item.index;
|
|
1612
|
+
multiDrawCount ++;
|
|
1124
1613
|
|
|
1125
1614
|
}
|
|
1126
1615
|
|
|
@@ -1128,11 +1617,11 @@ class BatchedMesh extends Mesh {
|
|
|
1128
1617
|
|
|
1129
1618
|
} else {
|
|
1130
1619
|
|
|
1131
|
-
for ( let i = 0, l =
|
|
1620
|
+
for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
|
|
1132
1621
|
|
|
1133
|
-
if (
|
|
1622
|
+
if ( instanceInfo[ i ].visible && instanceInfo[ i ].active ) {
|
|
1134
1623
|
|
|
1135
|
-
const geometryId =
|
|
1624
|
+
const geometryId = instanceInfo[ i ].geometryIndex;
|
|
1136
1625
|
|
|
1137
1626
|
// determine whether the batched geometry is within the frustum
|
|
1138
1627
|
let culled = false;
|
|
@@ -1141,17 +1630,17 @@ class BatchedMesh extends Mesh {
|
|
|
1141
1630
|
// get the bounds in world space
|
|
1142
1631
|
this.getMatrixAt( i, _matrix );
|
|
1143
1632
|
this.getBoundingSphereAt( geometryId, _sphere ).applyMatrix4( _matrix );
|
|
1144
|
-
culled = !
|
|
1633
|
+
culled = ! frustum.intersectsSphere( _sphere, camera );
|
|
1145
1634
|
|
|
1146
1635
|
}
|
|
1147
1636
|
|
|
1148
1637
|
if ( ! culled ) {
|
|
1149
1638
|
|
|
1150
|
-
const
|
|
1151
|
-
multiDrawStarts[
|
|
1152
|
-
multiDrawCounts[
|
|
1153
|
-
indirectArray[
|
|
1154
|
-
|
|
1639
|
+
const geometryInfo = geometryInfoList[ geometryId ];
|
|
1640
|
+
multiDrawStarts[ multiDrawCount ] = geometryInfo.start * bytesPerElement * multiDrawMultiplier;
|
|
1641
|
+
multiDrawCounts[ multiDrawCount ] = geometryInfo.count * multiDrawMultiplier;
|
|
1642
|
+
indirectArray[ multiDrawCount ] = i;
|
|
1643
|
+
multiDrawCount ++;
|
|
1155
1644
|
|
|
1156
1645
|
}
|
|
1157
1646
|
|
|
@@ -1162,7 +1651,7 @@ class BatchedMesh extends Mesh {
|
|
|
1162
1651
|
}
|
|
1163
1652
|
|
|
1164
1653
|
indirectTexture.needsUpdate = true;
|
|
1165
|
-
this._multiDrawCount =
|
|
1654
|
+
this._multiDrawCount = multiDrawCount;
|
|
1166
1655
|
this._visibilityChanged = false;
|
|
1167
1656
|
|
|
1168
1657
|
}
|