@expofp/renderer 0.0.0-experimental.2d6c681
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/README.md +145 -0
- package/dist/Renderer.d.ts +102 -0
- package/dist/Renderer.js +96 -0
- package/dist/controls/CameraControls.d.ts +108 -0
- package/dist/controls/CameraControls.js +203 -0
- package/dist/controls/Controls.d.ts +53 -0
- package/dist/controls/Controls.js +54 -0
- package/dist/controls/camera-api.d.ts +226 -0
- package/dist/controls/camera-api.js +179 -0
- package/dist/controls/gestures.d.ts +71 -0
- package/dist/controls/gestures.js +98 -0
- package/dist/controls/handlers/DoubleTapZoom.d.ts +23 -0
- package/dist/controls/handlers/DoubleTapZoom.js +82 -0
- package/dist/controls/handlers/Inertia.d.ts +60 -0
- package/dist/controls/handlers/Inertia.js +222 -0
- package/dist/controls/handlers/Pan.d.ts +23 -0
- package/dist/controls/handlers/Pan.js +212 -0
- package/dist/controls/handlers/Pitch.d.ts +19 -0
- package/dist/controls/handlers/Pitch.js +200 -0
- package/dist/controls/handlers/Roll.d.ts +30 -0
- package/dist/controls/handlers/Roll.js +196 -0
- package/dist/controls/handlers/Zoom.d.ts +28 -0
- package/dist/controls/handlers/Zoom.js +34 -0
- package/dist/controls/hooks.d.ts +136 -0
- package/dist/controls/hooks.js +200 -0
- package/dist/controls/index.d.ts +9 -0
- package/dist/controls/index.js +7 -0
- package/dist/controls/zoom-to.d.ts +89 -0
- package/dist/controls/zoom-to.js +91 -0
- package/dist/core/InstanceUniforms.d.ts +108 -0
- package/dist/core/InstanceUniforms.js +298 -0
- package/dist/core/SquareDataTexture.d.ts +277 -0
- package/dist/core/SquareDataTexture.js +476 -0
- package/dist/core/batch/BatchedMesh.d.ts +74 -0
- package/dist/core/batch/BatchedMesh.js +155 -0
- package/dist/core/instanced/FrustumCulling.d.ts +141 -0
- package/dist/core/instanced/FrustumCulling.js +246 -0
- package/dist/core/instanced/InstancedMesh.d.ts +302 -0
- package/dist/core/instanced/InstancedMesh.js +497 -0
- package/dist/core/instanced/Instances.d.ts +119 -0
- package/dist/core/instanced/Instances.js +230 -0
- package/dist/core/instanced/Raycasting.d.ts +118 -0
- package/dist/core/instanced/Raycasting.js +134 -0
- package/dist/core/instanced/instanced-material.d.ts +77 -0
- package/dist/core/instanced/instanced-material.js +228 -0
- package/dist/core/lines/BatchedLines.d.ts +137 -0
- package/dist/core/lines/BatchedLines.js +215 -0
- package/dist/core/lines/FrustumCullingLines.d.ts +44 -0
- package/dist/core/lines/FrustumCullingLines.js +85 -0
- package/dist/core/lines/RaycastingLines.d.ts +45 -0
- package/dist/core/lines/RaycastingLines.js +91 -0
- package/dist/core/lines/lines-material.d.ts +47 -0
- package/dist/core/lines/lines-material.js +124 -0
- package/dist/core/shader-source.d.ts +70 -0
- package/dist/core/shader-source.js +110 -0
- package/dist/core/sprites/BatchedSprites.d.ts +115 -0
- package/dist/core/sprites/BatchedSprites.js +173 -0
- package/dist/core/sprites/RaycastingSprites.d.ts +41 -0
- package/dist/core/sprites/RaycastingSprites.js +71 -0
- package/dist/core/sprites/sprite-material.d.ts +59 -0
- package/dist/core/sprites/sprite-material.js +192 -0
- package/dist/core/text/BatchedText.d.ts +233 -0
- package/dist/core/text/BatchedText.js +473 -0
- package/dist/core/text/MemberTexture.d.ts +90 -0
- package/dist/core/text/MemberTexture.js +289 -0
- package/dist/core/text/Text.d.ts +88 -0
- package/dist/core/text/Text.js +230 -0
- package/dist/core/text/batched-text-material.d.ts +56 -0
- package/dist/core/text/batched-text-material.js +123 -0
- package/dist/core/text/glyph-packing.d.ts +17 -0
- package/dist/core/text/glyph-packing.js +61 -0
- package/dist/core/typed-array.d.ts +16 -0
- package/dist/core/typed-array.js +20 -0
- package/dist/debug/components/DebugPanelProvider.d.ts +20 -0
- package/dist/debug/components/DebugPanelProvider.js +50 -0
- package/dist/debug/components/DebugTools.d.ts +22 -0
- package/dist/debug/components/DebugTools.js +28 -0
- package/dist/debug/components/Gui.d.ts +22 -0
- package/dist/debug/components/Gui.js +42 -0
- package/dist/debug/components/MemoryInfo.d.ts +22 -0
- package/dist/debug/components/MemoryInfo.js +42 -0
- package/dist/debug/components/Panel.d.ts +31 -0
- package/dist/debug/components/Panel.js +104 -0
- package/dist/debug/components/Stats.d.ts +9 -0
- package/dist/debug/components/Stats.js +24 -0
- package/dist/debug/debug-chunk.d.ts +26 -0
- package/dist/debug/debug-chunk.js +32 -0
- package/dist/debug/debug-context.d.ts +41 -0
- package/dist/debug/debug-context.js +59 -0
- package/dist/debug/index.d.ts +41 -0
- package/dist/debug/index.js +43 -0
- package/dist/events/LayoutDriver.d.ts +36 -0
- package/dist/events/LayoutDriver.js +192 -0
- package/dist/events/PointerMissed.d.ts +23 -0
- package/dist/events/PointerMissed.js +58 -0
- package/dist/events/def-culling.d.ts +46 -0
- package/dist/events/def-culling.js +69 -0
- package/dist/events/layout-targets.d.ts +151 -0
- package/dist/events/layout-targets.js +397 -0
- package/dist/events/placement/box.d.ts +59 -0
- package/dist/events/placement/box.js +96 -0
- package/dist/events/placement/grid.d.ts +161 -0
- package/dist/events/placement/grid.js +235 -0
- package/dist/events/placement/index.d.ts +2 -0
- package/dist/events/placement/index.js +1 -0
- package/dist/events/placement/pass.d.ts +70 -0
- package/dist/events/placement/pass.js +617 -0
- package/dist/events/pointer.d.ts +194 -0
- package/dist/events/pointer.js +356 -0
- package/dist/external/ExternalCanvas.d.ts +56 -0
- package/dist/external/ExternalCanvas.js +177 -0
- package/dist/external/external-camera.d.ts +18 -0
- package/dist/external/external-camera.js +103 -0
- package/dist/external/external-events.d.ts +14 -0
- package/dist/external/external-events.js +33 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +14 -0
- package/dist/objects/Background.d.ts +31 -0
- package/dist/objects/Background.js +37 -0
- package/dist/objects/containers/SlotContainer.d.ts +312 -0
- package/dist/objects/containers/SlotContainer.js +311 -0
- package/dist/objects/containers/hooks.d.ts +61 -0
- package/dist/objects/containers/hooks.js +196 -0
- package/dist/objects/containers/index.d.ts +6 -0
- package/dist/objects/containers/index.js +4 -0
- package/dist/objects/containers/keys.d.ts +10 -0
- package/dist/objects/containers/keys.js +18 -0
- package/dist/objects/containers/mesh-writes.d.ts +106 -0
- package/dist/objects/containers/mesh-writes.js +97 -0
- package/dist/objects/containers/props.d.ts +33 -0
- package/dist/objects/containers/props.js +1 -0
- package/dist/objects/images/ImageInstance.d.ts +29 -0
- package/dist/objects/images/ImageInstance.js +152 -0
- package/dist/objects/images/Images.d.ts +49 -0
- package/dist/objects/images/Images.js +394 -0
- package/dist/objects/images/atlas-packer.d.ts +129 -0
- package/dist/objects/images/atlas-packer.js +287 -0
- package/dist/objects/images/image-container.d.ts +74 -0
- package/dist/objects/images/image-container.js +100 -0
- package/dist/objects/images/index.d.ts +2 -0
- package/dist/objects/images/index.js +1 -0
- package/dist/objects/images/pack-sources.d.ts +190 -0
- package/dist/objects/images/pack-sources.js +272 -0
- package/dist/objects/images/texture-budget.d.ts +120 -0
- package/dist/objects/images/texture-budget.js +215 -0
- package/dist/objects/images/worker/atlas-worker.d.ts +56 -0
- package/dist/objects/images/worker/atlas-worker.js +123 -0
- package/dist/objects/images/worker/client.d.ts +62 -0
- package/dist/objects/images/worker/client.js +249 -0
- package/dist/objects/images/worker/index.d.ts +10 -0
- package/dist/objects/images/worker/index.js +1 -0
- package/dist/objects/layer/Layer.d.ts +28 -0
- package/dist/objects/layer/Layer.js +134 -0
- package/dist/objects/layer/index.d.ts +2 -0
- package/dist/objects/layer/index.js +1 -0
- package/dist/objects/layer/layer-context.d.ts +74 -0
- package/dist/objects/layer/layer-context.js +82 -0
- package/dist/objects/layer/mount-scheduler.d.ts +131 -0
- package/dist/objects/layer/mount-scheduler.js +289 -0
- package/dist/objects/layer/visibility-gui.d.ts +19 -0
- package/dist/objects/layer/visibility-gui.js +93 -0
- package/dist/objects/lighting/Lighting.d.ts +92 -0
- package/dist/objects/lighting/Lighting.js +384 -0
- package/dist/objects/lighting/OcclusionPasses.d.ts +23 -0
- package/dist/objects/lighting/OcclusionPasses.js +271 -0
- package/dist/objects/lighting/index.d.ts +11 -0
- package/dist/objects/lighting/index.js +10 -0
- package/dist/objects/lighting/lighting-gui.d.ts +24 -0
- package/dist/objects/lighting/lighting-gui.js +114 -0
- package/dist/objects/lighting/occluder.d.ts +34 -0
- package/dist/objects/lighting/occluder.js +62 -0
- package/dist/objects/lighting/occlusion-targets.d.ts +143 -0
- package/dist/objects/lighting/occlusion-targets.js +276 -0
- package/dist/objects/lines/LineInstance.d.ts +21 -0
- package/dist/objects/lines/LineInstance.js +73 -0
- package/dist/objects/lines/Lines.d.ts +17 -0
- package/dist/objects/lines/Lines.js +31 -0
- package/dist/objects/lines/index.d.ts +2 -0
- package/dist/objects/lines/index.js +1 -0
- package/dist/objects/lines/line-container.d.ts +35 -0
- package/dist/objects/lines/line-container.js +40 -0
- package/dist/objects/materials/ColorMaterial.d.ts +92 -0
- package/dist/objects/materials/ColorMaterial.js +124 -0
- package/dist/objects/materials/LineMaterial.d.ts +44 -0
- package/dist/objects/materials/LineMaterial.js +74 -0
- package/dist/objects/materials/ModelMaterial.d.ts +53 -0
- package/dist/objects/materials/ModelMaterial.js +111 -0
- package/dist/objects/materials/TextureMaterial.d.ts +33 -0
- package/dist/objects/materials/TextureMaterial.js +48 -0
- package/dist/objects/materials/effects/ao/ambient-occlusion-pass.d.ts +77 -0
- package/dist/objects/materials/effects/ao/ambient-occlusion-pass.js +296 -0
- package/dist/objects/materials/effects/ao/ambient-occlusion-patch.d.ts +29 -0
- package/dist/objects/materials/effects/ao/ambient-occlusion-patch.js +115 -0
- package/dist/objects/materials/effects/ao/blur-pass.d.ts +61 -0
- package/dist/objects/materials/effects/ao/blur-pass.js +101 -0
- package/dist/objects/materials/effects/ao/index.d.ts +129 -0
- package/dist/objects/materials/effects/ao/index.js +72 -0
- package/dist/objects/materials/effects/color-dim.d.ts +115 -0
- package/dist/objects/materials/effects/color-dim.js +206 -0
- package/dist/objects/materials/effects/contact-shadow.d.ts +100 -0
- package/dist/objects/materials/effects/contact-shadow.js +167 -0
- package/dist/objects/materials/effects/effects-context.d.ts +53 -0
- package/dist/objects/materials/effects/effects-context.js +24 -0
- package/dist/objects/materials/shared.d.ts +24 -0
- package/dist/objects/materials/shared.js +72 -0
- package/dist/objects/models/ModelInstance.d.ts +22 -0
- package/dist/objects/models/ModelInstance.js +33 -0
- package/dist/objects/models/Models.d.ts +22 -0
- package/dist/objects/models/Models.js +186 -0
- package/dist/objects/models/gltf-cache.d.ts +17 -0
- package/dist/objects/models/gltf-cache.js +50 -0
- package/dist/objects/models/index.d.ts +2 -0
- package/dist/objects/models/index.js +1 -0
- package/dist/objects/models/model-asset.d.ts +48 -0
- package/dist/objects/models/model-asset.js +77 -0
- package/dist/objects/models/model-container.d.ts +123 -0
- package/dist/objects/models/model-container.js +207 -0
- package/dist/objects/shapes/ShapeInstance.d.ts +26 -0
- package/dist/objects/shapes/ShapeInstance.js +39 -0
- package/dist/objects/shapes/Shapes.d.ts +21 -0
- package/dist/objects/shapes/Shapes.js +131 -0
- package/dist/objects/shapes/index.d.ts +2 -0
- package/dist/objects/shapes/index.js +1 -0
- package/dist/objects/shapes/shape-container.d.ts +141 -0
- package/dist/objects/shapes/shape-container.js +242 -0
- package/dist/objects/shapes/shape-geometry.d.ts +27 -0
- package/dist/objects/shapes/shape-geometry.js +94 -0
- package/dist/objects/text/TextInstance.d.ts +22 -0
- package/dist/objects/text/TextInstance.js +95 -0
- package/dist/objects/text/Texts.d.ts +30 -0
- package/dist/objects/text/Texts.js +43 -0
- package/dist/objects/text/index.d.ts +2 -0
- package/dist/objects/text/index.js +1 -0
- package/dist/objects/text/text-container.d.ts +121 -0
- package/dist/objects/text/text-container.js +229 -0
- package/dist/objects/text/text-layout.d.ts +92 -0
- package/dist/objects/text/text-layout.js +180 -0
- package/dist/space/Camera.d.ts +103 -0
- package/dist/space/Camera.js +321 -0
- package/dist/space/Scene.d.ts +47 -0
- package/dist/space/Scene.js +127 -0
- package/dist/space/Space.d.ts +325 -0
- package/dist/space/Space.js +359 -0
- package/dist/space/VisibleRect.d.ts +45 -0
- package/dist/space/VisibleRect.js +129 -0
- package/dist/space/camera-handle.d.ts +67 -0
- package/dist/space/camera-handle.js +63 -0
- package/dist/space/camera-kind.d.ts +26 -0
- package/dist/space/camera-kind.js +30 -0
- package/dist/space/canvas-size.d.ts +24 -0
- package/dist/space/canvas-size.js +20 -0
- package/dist/space/clipping.d.ts +69 -0
- package/dist/space/clipping.js +130 -0
- package/dist/space/layout-measure.d.ts +67 -0
- package/dist/space/layout-measure.js +175 -0
- package/dist/space/viewport.d.ts +112 -0
- package/dist/space/viewport.js +67 -0
- package/dist/types/defs.d.ts +234 -0
- package/dist/types/defs.js +1 -0
- package/dist/types/events.d.ts +198 -0
- package/dist/types/events.js +1 -0
- package/dist/types/guards.d.ts +21 -0
- package/dist/types/guards.js +52 -0
- package/dist/update/index.d.ts +3 -0
- package/dist/update/index.js +2 -0
- package/dist/update/slot-writers.d.ts +30 -0
- package/dist/update/slot-writers.js +76 -0
- package/dist/update/store.d.ts +41 -0
- package/dist/update/store.js +104 -0
- package/dist/utils/arrays.d.ts +13 -0
- package/dist/utils/arrays.js +20 -0
- package/dist/utils/colors.d.ts +19 -0
- package/dist/utils/colors.js +27 -0
- package/dist/utils/hot-state.d.ts +41 -0
- package/dist/utils/hot-state.js +37 -0
- package/dist/utils/logging.d.ts +29 -0
- package/dist/utils/logging.js +55 -0
- package/dist/utils/math.d.ts +52 -0
- package/dist/utils/math.js +76 -0
- package/package.json +79 -0
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
import { ColorManagement, DataTexture, FloatType, IntType, NoColorSpace, RedFormat, RedIntegerFormat, RGBAFormat, RGBAIntegerFormat, RGFormat, RGIntegerFormat, Source, UnsignedIntType, WebGLUtils, } from 'three';
|
|
2
|
+
import { createLogger } from '../utils/logging';
|
|
3
|
+
import { resizeTypedArray } from './typed-array';
|
|
4
|
+
const logger = createLogger('square-data-texture');
|
|
5
|
+
/**
|
|
6
|
+
* Calculates the square texture size based on the capacity and pixels per instance, so the texture
|
|
7
|
+
* is large enough to store every instance in a square layout.
|
|
8
|
+
* @param capacity - The maximum number of instances allowed in the texture.
|
|
9
|
+
* @param pixelsPerInstance - The number of pixels required for each instance.
|
|
10
|
+
* @returns The size of the square texture needed to store all the instances.
|
|
11
|
+
*/
|
|
12
|
+
export function getSquareTextureSize(capacity, pixelsPerInstance) {
|
|
13
|
+
return Math.max(pixelsPerInstance, Math.ceil(Math.sqrt(capacity / pixelsPerInstance)) * pixelsPerInstance);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Generates texture information (size, format, type) for a square texture.
|
|
17
|
+
* @param arrayType - The constructor for the TypedArray.
|
|
18
|
+
* @param channels - The number of channels in the texture.
|
|
19
|
+
* @param pixelsPerInstance - The number of pixels required for each instance.
|
|
20
|
+
* @param capacity - The maximum number of instances allowed in the texture.
|
|
21
|
+
* @returns An object containing the texture's array, size, format, and data type.
|
|
22
|
+
*/
|
|
23
|
+
export function getSquareTextureInfo(arrayType, channels, pixelsPerInstance, capacity) {
|
|
24
|
+
if (channels === 3) {
|
|
25
|
+
logger.warn('"channels" cannot be 3. Set to 4. More info: https://github.com/mrdoob/three.js/pull/23228');
|
|
26
|
+
channels = 4;
|
|
27
|
+
}
|
|
28
|
+
const size = getSquareTextureSize(capacity, pixelsPerInstance);
|
|
29
|
+
const array = new arrayType(size * size * channels);
|
|
30
|
+
const isFloat = arrayType.name.includes('Float');
|
|
31
|
+
const isUnsignedInt = arrayType.name.includes('Uint');
|
|
32
|
+
const type = isFloat ? FloatType : isUnsignedInt ? UnsignedIntType : IntType;
|
|
33
|
+
let format;
|
|
34
|
+
switch (channels) {
|
|
35
|
+
case 1:
|
|
36
|
+
format = isFloat ? RedFormat : RedIntegerFormat;
|
|
37
|
+
break;
|
|
38
|
+
case 2:
|
|
39
|
+
format = isFloat ? RGFormat : RGIntegerFormat;
|
|
40
|
+
break;
|
|
41
|
+
default:
|
|
42
|
+
format = isFloat ? RGBAFormat : RGBAIntegerFormat;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
return { array, size, type, format };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A `DataTexture` laid out as a square grid of per-instance records, with partial row uploads and
|
|
49
|
+
* per-instance uniforms addressed by instance id.
|
|
50
|
+
*
|
|
51
|
+
* Vendored from three.ez, which ships two near-identical copies of this file — one per package —
|
|
52
|
+
* and we would otherwise bundle both:
|
|
53
|
+
* - {@link https://github.com/agargaro/batched-mesh-extensions/blob/master/src/core/SquareDataTexture.ts | batched-mesh-extensions}
|
|
54
|
+
* - {@link https://github.com/agargaro/instanced-mesh/blob/master/src/core/utils/SquareDataTexture.ts | instanced-mesh}
|
|
55
|
+
*
|
|
56
|
+
* This is the batched-mesh-extensions version, the later of the two: its `update` hands whole-texture
|
|
57
|
+
* uploads back to three instead of hand-binding a texture unit, which drops `bindToProgram`,
|
|
58
|
+
* `getSlot`, `updateFull` and `updatePartial` along with the `?? maxTextures - 1` slot guess the
|
|
59
|
+
* instanced-mesh copy still carries.
|
|
60
|
+
*
|
|
61
|
+
* Three deliberate departures from both originals:
|
|
62
|
+
*
|
|
63
|
+
* 1. **No `flat` on the varyings.** With flat shading a fragment takes its value from the
|
|
64
|
+
* primitive's *provoking* vertex, and WebGL's default last-vertex convention is the expensive one
|
|
65
|
+
* for drivers — which is why upstream wants `WEBGL_provoking_vertex` enabled. Every value here is
|
|
66
|
+
* per-instance and therefore identical across a primitive's vertices, so interpolating instead of
|
|
67
|
+
* flat-shading yields the same result and needs no extension.
|
|
68
|
+
* 2. **The index varying is always `float`**, so `getUniformsGLSL` no longer takes an index type.
|
|
69
|
+
* It follows from the first: GLSL ES 3.00 requires integer varyings to be `flat`, so an index
|
|
70
|
+
* that is not float could not have the qualifier removed. **Callers must therefore hand it a float
|
|
71
|
+
* index** — `BatchedMeshImpl` does, from three's own `getIndirectIndex( gl_DrawID )`, and
|
|
72
|
+
* `InstancedMeshImpl` does, from the float index texture that replaced upstream's `uint` attribute.
|
|
73
|
+
* 3. **`clone` and `copy` produce an independent texture.** See each method.
|
|
74
|
+
*/
|
|
75
|
+
export class SquareDataTexture extends DataTexture {
|
|
76
|
+
/**
|
|
77
|
+
* Whether to enable partial texture updates by row. If `false`, the entire texture is updated.
|
|
78
|
+
* @default true
|
|
79
|
+
*/
|
|
80
|
+
partialUpdate = true;
|
|
81
|
+
/**
|
|
82
|
+
* The maximum number of update calls per frame. Past it, the whole texture is re-uploaded instead.
|
|
83
|
+
* @default Infinity
|
|
84
|
+
*/
|
|
85
|
+
maxUpdateCalls = Infinity;
|
|
86
|
+
/** Format/type conversion helper, built on first upload. */
|
|
87
|
+
_utils = null;
|
|
88
|
+
/** Whether any row has been marked since the last upload. */
|
|
89
|
+
_needsUpdate = false;
|
|
90
|
+
/** Width at the last upload, used to notice a resize; `null` until the first one. */
|
|
91
|
+
_lastWidth = null;
|
|
92
|
+
/** The typed array backing the texture. */
|
|
93
|
+
_data;
|
|
94
|
+
/** Elements per pixel. */
|
|
95
|
+
_channels;
|
|
96
|
+
/** Pixels each instance occupies. */
|
|
97
|
+
_pixelsPerInstance;
|
|
98
|
+
/** Elements each instance occupies. */
|
|
99
|
+
_stride;
|
|
100
|
+
/** Rows marked dirty for the next partial upload. */
|
|
101
|
+
_rowToUpdate;
|
|
102
|
+
/** Reused pool of dirty-row ranges, refilled each upload so a frame allocates nothing. */
|
|
103
|
+
_rowRanges = [];
|
|
104
|
+
/** Uniform layout, shared with whoever built the schema. */
|
|
105
|
+
_uniformMap;
|
|
106
|
+
/** Whether uniforms are fetched in the fragment shader rather than passed as varyings. */
|
|
107
|
+
_fetchUniformsInFragmentShader;
|
|
108
|
+
/**
|
|
109
|
+
* The backing typed array. An instanced mesh reads and writes its matrix and color data through
|
|
110
|
+
* it directly, the way three's own `InstancedMesh` writes its instance attributes — a per-instance
|
|
111
|
+
* accessor would be pure overhead on that hot path. Pair a write with {@link enqueueUpdate} so the
|
|
112
|
+
* row is re-uploaded.
|
|
113
|
+
* @returns The array.
|
|
114
|
+
*/
|
|
115
|
+
get data() {
|
|
116
|
+
return this._data;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @param arrayType - The constructor for the TypedArray.
|
|
120
|
+
* @param channels - The number of channels in the texture.
|
|
121
|
+
* @param pixelsPerInstance - The number of pixels required for each instance.
|
|
122
|
+
* @param capacity - The total number of instances.
|
|
123
|
+
* @param uniformMap - Optional map for handling uniform values.
|
|
124
|
+
* @param fetchInFragmentShader - Optional flag that determines if uniform values should be fetched
|
|
125
|
+
* in the fragment shader instead of the vertex shader.
|
|
126
|
+
*/
|
|
127
|
+
constructor(arrayType, channels, pixelsPerInstance, capacity, uniformMap, fetchInFragmentShader) {
|
|
128
|
+
if (channels === 3)
|
|
129
|
+
channels = 4;
|
|
130
|
+
const { array, format, size, type } = getSquareTextureInfo(arrayType, channels, pixelsPerInstance, capacity);
|
|
131
|
+
super(array, size, size, format, type);
|
|
132
|
+
this._data = array;
|
|
133
|
+
this._channels = channels;
|
|
134
|
+
this._pixelsPerInstance = pixelsPerInstance;
|
|
135
|
+
this._stride = pixelsPerInstance * channels;
|
|
136
|
+
this._rowToUpdate = new Array(size);
|
|
137
|
+
this._uniformMap = uniformMap;
|
|
138
|
+
this._fetchUniformsInFragmentShader = fetchInFragmentShader;
|
|
139
|
+
this.needsUpdate = true; // necessary to init texture
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Resizes the texture to accommodate a new number of instances.
|
|
143
|
+
* @param count - The new total number of instances.
|
|
144
|
+
*/
|
|
145
|
+
resize(count) {
|
|
146
|
+
const size = getSquareTextureSize(count, this._pixelsPerInstance);
|
|
147
|
+
if (size === this.image.width)
|
|
148
|
+
return;
|
|
149
|
+
this._rowToUpdate.length = size;
|
|
150
|
+
const data = resizeTypedArray(this._data, size * size * this._channels);
|
|
151
|
+
this.dispose();
|
|
152
|
+
this.image = { data, height: size, width: size };
|
|
153
|
+
this._data = data;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Marks a row of the texture for update during the next render cycle, so only rows that changed
|
|
157
|
+
* are re-uploaded.
|
|
158
|
+
* @param index - The index of the instance to update.
|
|
159
|
+
*/
|
|
160
|
+
enqueueUpdate(index) {
|
|
161
|
+
this._needsUpdate = true;
|
|
162
|
+
if (!this.partialUpdate)
|
|
163
|
+
return;
|
|
164
|
+
const elementsPerRow = this.image.width / this._pixelsPerInstance;
|
|
165
|
+
const rowIndex = Math.floor(index / elementsPerRow);
|
|
166
|
+
this._rowToUpdate[rowIndex] = true;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Uploads whatever changed since the last frame, a row range at a time.
|
|
170
|
+
*
|
|
171
|
+
* Defers to three's own full upload whenever it is going to happen anyway — before the texture
|
|
172
|
+
* exists, after a resize, or when the version moved — and whenever the dirty rows are so scattered
|
|
173
|
+
* that `maxUpdateCalls` would be exceeded.
|
|
174
|
+
* @param renderer - The renderer to upload through.
|
|
175
|
+
*/
|
|
176
|
+
update(renderer) {
|
|
177
|
+
const textureProperties = renderer.properties.get(this);
|
|
178
|
+
const versionChanged = this.version > 0 && textureProperties.__version !== this.version;
|
|
179
|
+
const sizeChanged = this._lastWidth !== null && this._lastWidth !== this.image.width;
|
|
180
|
+
if (!this._needsUpdate || !textureProperties.__webglTexture || versionChanged || sizeChanged) {
|
|
181
|
+
this._lastWidth = this.image.width;
|
|
182
|
+
this._needsUpdate = false;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
this._needsUpdate = false;
|
|
186
|
+
if (!this.partialUpdate) {
|
|
187
|
+
this.needsUpdate = true; // three.js will update the whole texture
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const rangeCount = this.collectDirtyRanges();
|
|
191
|
+
if (rangeCount === 0)
|
|
192
|
+
return;
|
|
193
|
+
if (rangeCount > this.maxUpdateCalls) {
|
|
194
|
+
this.needsUpdate = true; // three.js will update the whole texture
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
this.updateRows(textureProperties.__webglTexture, renderer, rangeCount);
|
|
198
|
+
}
|
|
199
|
+
this._rowToUpdate.fill(false);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Sets a uniform value at the specified instance ID in the texture.
|
|
203
|
+
* @param id - The instance ID to set the uniform for.
|
|
204
|
+
* @param name - The name of the uniform.
|
|
205
|
+
* @param value - The value to set for the uniform.
|
|
206
|
+
*/
|
|
207
|
+
setUniformAt(id, name, value) {
|
|
208
|
+
const { offset, size } = this._uniformMap.get(name);
|
|
209
|
+
const stride = this._stride;
|
|
210
|
+
if (size === 1) {
|
|
211
|
+
this._data[id * stride + offset] = value;
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
value.toArray(this._data, id * stride + offset);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Retrieves a uniform value at the specified instance ID from the texture.
|
|
219
|
+
* @param id - The instance ID to retrieve the uniform from.
|
|
220
|
+
* @param name - The name of the uniform.
|
|
221
|
+
* @param target - Optional target object to store the uniform value.
|
|
222
|
+
* @returns The uniform value for the specified instance.
|
|
223
|
+
*/
|
|
224
|
+
getUniformAt(id, name, target) {
|
|
225
|
+
const { offset, size } = this._uniformMap.get(name);
|
|
226
|
+
const stride = this._stride;
|
|
227
|
+
if (size === 1)
|
|
228
|
+
return this._data[id * stride + offset];
|
|
229
|
+
return target.fromArray(this._data, id * stride + offset);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Generates the GLSL for reading this texture's uniforms.
|
|
233
|
+
*
|
|
234
|
+
* The index varying is `float` and has no index-type parameter, because these varyings carry no
|
|
235
|
+
* `flat` qualifier — see the class docs. `indexName` must name a float in the shader.
|
|
236
|
+
* @param textureName - The name of the texture in the GLSL shader.
|
|
237
|
+
* @param indexName - The name of the index in the GLSL shader.
|
|
238
|
+
* @returns What each stage declares and what it runs first; see {@link UniformsStageGLSL}.
|
|
239
|
+
*/
|
|
240
|
+
getUniformsGLSL(textureName, indexName) {
|
|
241
|
+
return {
|
|
242
|
+
vertex: this.getUniformsVertexGLSL(textureName, indexName),
|
|
243
|
+
fragment: this.getUniformsFragmentGLSL(textureName, indexName),
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Copies another texture's pixels and layout, leaving nothing shared between the two.
|
|
248
|
+
*
|
|
249
|
+
* Both originals assign `_rowToUpdate` by reference and inherit `Texture.copy`'s by-reference
|
|
250
|
+
* `source`, so a copy and its original wrote through into each other's pixels and marked each
|
|
251
|
+
* other's rows dirty. Only `_uniformMap` stays shared, which is safe: it is the layout descriptor
|
|
252
|
+
* built once from the schema and never mutated.
|
|
253
|
+
* @param source - The texture to copy.
|
|
254
|
+
* @returns `this`.
|
|
255
|
+
*/
|
|
256
|
+
copy(source) {
|
|
257
|
+
super.copy(source);
|
|
258
|
+
this.partialUpdate = source.partialUpdate;
|
|
259
|
+
this.maxUpdateCalls = source.maxUpdateCalls;
|
|
260
|
+
this._channels = source._channels;
|
|
261
|
+
this._pixelsPerInstance = source._pixelsPerInstance;
|
|
262
|
+
this._stride = source._stride;
|
|
263
|
+
this._rowToUpdate = [...source._rowToUpdate];
|
|
264
|
+
this._uniformMap = source._uniformMap;
|
|
265
|
+
this._fetchUniformsInFragmentShader = source._fetchUniformsInFragmentShader;
|
|
266
|
+
const data = source._data.slice();
|
|
267
|
+
const { width, height } = source.image;
|
|
268
|
+
this.source = new Source({ data, width, height });
|
|
269
|
+
this._data = data;
|
|
270
|
+
this.needsUpdate = true;
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Duplicates the texture.
|
|
275
|
+
*
|
|
276
|
+
* Neither original overrides this, so three's `Texture.clone` ran `new this.constructor()` with no
|
|
277
|
+
* arguments — and this constructor derives its size, format and typed array from those arguments,
|
|
278
|
+
* so the inherited clone always threw, taking every `copy` of an owning mesh down with it.
|
|
279
|
+
* @returns The independent copy.
|
|
280
|
+
*/
|
|
281
|
+
clone() {
|
|
282
|
+
// Reconstructed from the layout rather than the arguments, which are not retained. Capacity is
|
|
283
|
+
// recoverable because `getSquareTextureSize` rounds the edge up to a multiple of
|
|
284
|
+
// `pixelsPerInstance`, making `size² / pixelsPerInstance` the capacity that reproduces this size.
|
|
285
|
+
const size = this.image.width;
|
|
286
|
+
const Constructor = this.constructor;
|
|
287
|
+
const clone = new Constructor(this._data.constructor, this._channels, this._pixelsPerInstance, (size * size) / this._pixelsPerInstance, this._uniformMap, this._fetchUniformsInFragmentShader);
|
|
288
|
+
return clone.copy(this);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Groups the dirty rows into contiguous ranges, so neighbors upload in one call. Fills the reused
|
|
292
|
+
* {@link _rowRanges} pool — growing it only when a frame has more ranges than ever before — rather
|
|
293
|
+
* than allocating a fresh array and range objects every frame.
|
|
294
|
+
* @returns How many ranges were written to the pool.
|
|
295
|
+
*/
|
|
296
|
+
collectDirtyRanges() {
|
|
297
|
+
const rowsToUpdate = this._rowToUpdate;
|
|
298
|
+
const ranges = this._rowRanges;
|
|
299
|
+
let rangeCount = 0;
|
|
300
|
+
for (let i = 0, l = rowsToUpdate.length; i < l; i++) {
|
|
301
|
+
if (!rowsToUpdate[i])
|
|
302
|
+
continue;
|
|
303
|
+
const row = i;
|
|
304
|
+
while (i < l && rowsToUpdate[i])
|
|
305
|
+
i++;
|
|
306
|
+
const range = (ranges[rangeCount] ??= { row: 0, count: 0 });
|
|
307
|
+
range.row = row;
|
|
308
|
+
range.count = i - row;
|
|
309
|
+
rangeCount++;
|
|
310
|
+
}
|
|
311
|
+
return rangeCount;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Uploads the given row ranges with `texSubImage2D`.
|
|
315
|
+
* @param webglTexture - The uploaded texture to write into.
|
|
316
|
+
* @param renderer - The renderer to upload through.
|
|
317
|
+
* @param rangeCount - How many of the pooled {@link _rowRanges} to upload.
|
|
318
|
+
*/
|
|
319
|
+
updateRows(webglTexture, renderer, rangeCount) {
|
|
320
|
+
const state = renderer.state;
|
|
321
|
+
const gl = renderer.getContext();
|
|
322
|
+
this._utils ??= new WebGLUtils(gl, renderer.extensions);
|
|
323
|
+
const glFormat = this._utils.convert(this.format);
|
|
324
|
+
const glType = this._utils.convert(this.type);
|
|
325
|
+
const { data, width } = this.image;
|
|
326
|
+
const channels = this._channels;
|
|
327
|
+
state.bindTexture(gl.TEXTURE_2D, webglTexture);
|
|
328
|
+
const workingPrimaries = ColorManagement.getPrimaries(ColorManagement.workingColorSpace);
|
|
329
|
+
const texturePrimaries = this.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries(this.colorSpace);
|
|
330
|
+
const unpackConversion = this.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries
|
|
331
|
+
? gl.NONE
|
|
332
|
+
: gl.BROWSER_DEFAULT_WEBGL;
|
|
333
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this.flipY);
|
|
334
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha);
|
|
335
|
+
gl.pixelStorei(gl.UNPACK_ALIGNMENT, this.unpackAlignment);
|
|
336
|
+
gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion);
|
|
337
|
+
for (let i = 0; i < rangeCount; i++) {
|
|
338
|
+
const { row, count } = this._rowRanges[i];
|
|
339
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, row, width, count, glFormat, glType, data, row * width * channels);
|
|
340
|
+
}
|
|
341
|
+
this.onUpdate?.(this);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* The vertex stage's share: either the whole fetch plus the varyings it feeds, or — when uniforms
|
|
345
|
+
* are read in the fragment shader — just the index handed across.
|
|
346
|
+
* @param textureName - The sampler name.
|
|
347
|
+
* @param indexName - The per-instance index available in the vertex shader; must be a float.
|
|
348
|
+
* @returns What the stage declares and what it runs first.
|
|
349
|
+
*/
|
|
350
|
+
getUniformsVertexGLSL(textureName, indexName) {
|
|
351
|
+
if (this._fetchUniformsInFragmentShader) {
|
|
352
|
+
return {
|
|
353
|
+
declarations: `varying float ${VARYING_PREFIX}${indexName};`,
|
|
354
|
+
body: `${VARYING_PREFIX}${indexName} = ${indexName};`,
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
const texelsFetch = this.texelsFetchGLSL(textureName, indexName);
|
|
358
|
+
const getFromTexels = this.getFromTexelsGLSL();
|
|
359
|
+
const { assignVarying, declareVarying } = this.getVarying();
|
|
360
|
+
return {
|
|
361
|
+
declarations: `
|
|
362
|
+
uniform highp sampler2D ${textureName};
|
|
363
|
+
${declareVarying}`,
|
|
364
|
+
body: `
|
|
365
|
+
${texelsFetch}
|
|
366
|
+
${getFromTexels}
|
|
367
|
+
${assignVarying}`,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* The fragment stage's share: either the varyings the vertex shader filled, or the fetch itself.
|
|
372
|
+
* @param textureName - The sampler name.
|
|
373
|
+
* @param indexName - The per-instance index carried across as a varying.
|
|
374
|
+
* @returns What the stage declares and what it runs first.
|
|
375
|
+
*/
|
|
376
|
+
getUniformsFragmentGLSL(textureName, indexName) {
|
|
377
|
+
if (!this._fetchUniformsInFragmentShader) {
|
|
378
|
+
const { declareVarying, getVarying } = this.getVarying();
|
|
379
|
+
return { declarations: declareVarying, body: getVarying };
|
|
380
|
+
}
|
|
381
|
+
const texelsFetch = this.texelsFetchGLSL(textureName, `${VARYING_PREFIX}${indexName}`);
|
|
382
|
+
const getFromTexels = this.getFromTexelsGLSL();
|
|
383
|
+
return {
|
|
384
|
+
declarations: `
|
|
385
|
+
uniform highp sampler2D ${textureName};
|
|
386
|
+
varying float ${VARYING_PREFIX}${indexName};`,
|
|
387
|
+
body: `
|
|
388
|
+
${texelsFetch}
|
|
389
|
+
${getFromTexels}`,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* GLSL fetching every texel one instance occupies.
|
|
394
|
+
* @param textureName - The sampler name.
|
|
395
|
+
* @param indexName - The instance index expression.
|
|
396
|
+
* @returns The GLSL statements.
|
|
397
|
+
*/
|
|
398
|
+
texelsFetchGLSL(textureName, indexName) {
|
|
399
|
+
const pixelsPerInstance = this._pixelsPerInstance;
|
|
400
|
+
let texelsFetch = `
|
|
401
|
+
int size = textureSize(${textureName}, 0).x;
|
|
402
|
+
int j = int(${indexName}) * ${pixelsPerInstance};
|
|
403
|
+
int x = j % size;
|
|
404
|
+
int y = j / size;
|
|
405
|
+
`;
|
|
406
|
+
for (let i = 0; i < pixelsPerInstance; i++) {
|
|
407
|
+
texelsFetch += `vec4 ${TEXEL_PREFIX}${i} = texelFetch(${textureName}, ivec2(x + ${i}, y), 0);\n`;
|
|
408
|
+
}
|
|
409
|
+
return texelsFetch;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* GLSL unpacking each uniform out of the fetched texels.
|
|
413
|
+
* @returns The GLSL declarations.
|
|
414
|
+
*/
|
|
415
|
+
getFromTexelsGLSL() {
|
|
416
|
+
const uniforms = this._uniformMap;
|
|
417
|
+
let fromTexels = '';
|
|
418
|
+
for (const [name, { type, offset, size }] of uniforms) {
|
|
419
|
+
const tId = Math.floor(offset / this._channels);
|
|
420
|
+
const id = (offset = 0) => `${TEXEL_PREFIX}${tId + offset}`;
|
|
421
|
+
if (type === 'mat3') {
|
|
422
|
+
fromTexels += `mat3 ${name} = mat3(${id()}.rgb, vec3(${id()}.a, ${id(1)}.rg), vec3(${id(1)}.ba, ${id(2)}.r));`;
|
|
423
|
+
}
|
|
424
|
+
else if (type === 'mat4') {
|
|
425
|
+
fromTexels += `mat4 ${name} = mat4(${id()}, ${id(1)}, ${id(2)}, ${id(3)});`;
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
const components = this.getUniformComponents(offset, size);
|
|
429
|
+
fromTexels += `${type} ${name} = ${id()}.${components};`;
|
|
430
|
+
}
|
|
431
|
+
fromTexels += '\n';
|
|
432
|
+
}
|
|
433
|
+
return fromTexels;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* The varying declarations carrying each uniform from vertex to fragment stage.
|
|
437
|
+
*
|
|
438
|
+
* No `flat` qualifier, unlike both originals — see the class docs.
|
|
439
|
+
* @returns The declaration, assignment and read snippets.
|
|
440
|
+
*/
|
|
441
|
+
getVarying() {
|
|
442
|
+
const uniforms = this._uniformMap;
|
|
443
|
+
let declareVarying = '';
|
|
444
|
+
let assignVarying = '';
|
|
445
|
+
let getVarying = '';
|
|
446
|
+
for (const [name, { type }] of uniforms) {
|
|
447
|
+
declareVarying += `varying ${type} ${VARYING_PREFIX}${name};\n`;
|
|
448
|
+
assignVarying += `${VARYING_PREFIX}${name} = ${name};\n`;
|
|
449
|
+
getVarying += `${type} ${name} = ${VARYING_PREFIX}${name};\n`;
|
|
450
|
+
}
|
|
451
|
+
return { declareVarying, assignVarying, getVarying };
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* The swizzle selecting a uniform's components out of its texel.
|
|
455
|
+
* @param offset - The uniform's element offset within an instance.
|
|
456
|
+
* @param size - How many elements it spans.
|
|
457
|
+
* @returns The component swizzle, such as `rgb`.
|
|
458
|
+
*/
|
|
459
|
+
getUniformComponents(offset, size) {
|
|
460
|
+
const startIndex = offset % this._channels;
|
|
461
|
+
let components = '';
|
|
462
|
+
for (let i = 0; i < size; i++) {
|
|
463
|
+
components += COMPONENTS_ARRAY[startIndex + i];
|
|
464
|
+
}
|
|
465
|
+
return components;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Prefix for the varyings carrying uniforms across shader stages. Namespaced so a generated name
|
|
470
|
+
* cannot collide with anything three or a patched material declares.
|
|
471
|
+
*/
|
|
472
|
+
const VARYING_PREFIX = 'efp_f';
|
|
473
|
+
/** Prefix for the locals holding an instance's fetched texels. */
|
|
474
|
+
const TEXEL_PREFIX = 'efp_texel';
|
|
475
|
+
/** The channel letters a uniform's components are swizzled out of. */
|
|
476
|
+
const COMPONENTS_ARRAY = ['r', 'g', 'b', 'a'];
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { BatchedMesh as BatchedMeshBase, type BufferGeometry, type Camera, type Group, type Intersection, type Material, type Matrix4, type Raycaster, type Scene, type WebGLRenderer } from 'three';
|
|
2
|
+
import { type UniformSchemaShader } from '../InstanceUniforms';
|
|
3
|
+
import { type UniformValue, type UniformValueObj } from '../SquareDataTexture';
|
|
4
|
+
/**
|
|
5
|
+
* Three's `BatchedMesh` with per-instance uniforms, backed by a {@link SquareDataTexture}.
|
|
6
|
+
*
|
|
7
|
+
* Ported from three.ez's batched-mesh-extensions, which supplies this as prototype patches over
|
|
8
|
+
* `BatchedMesh` rather than a subclass:
|
|
9
|
+
* {@link https://github.com/agargaro/batched-mesh-extensions/blob/master/src/core/feature/Uniforms.ts | Uniforms}
|
|
10
|
+
* and
|
|
11
|
+
* {@link https://github.com/agargaro/batched-mesh-extensions/blob/master/src/patch/PatchBatchedMeshMaterial.ts | PatchBatchedMeshMaterial}.
|
|
12
|
+
* Only the uniform feature is taken: BVH, raycasting, LOD and per-object frustum culling are left
|
|
13
|
+
* behind, since the 2D layers draw every instance and pick through their own tables.
|
|
14
|
+
*
|
|
15
|
+
* Two departures from upstream:
|
|
16
|
+
*
|
|
17
|
+
* - **Uniforms are added, not initialized once** — see {@link addUniforms} and
|
|
18
|
+
* {@link InstanceUniforms}.
|
|
19
|
+
* - **Bounds invalidate themselves.** Every mutation that can move the mesh's extents nulls the
|
|
20
|
+
* cached bounds, so callers cannot forget; three's frustum test recomputes a null one on demand.
|
|
21
|
+
*/
|
|
22
|
+
export declare class BatchedMeshImpl extends BatchedMeshBase {
|
|
23
|
+
/** Per-instance uniform store, shared with {@link InstancedMeshImpl}. */
|
|
24
|
+
private readonly uniforms;
|
|
25
|
+
/** The material whose `onBeforeCompile` is already wrapped, so it is wrapped exactly once. */
|
|
26
|
+
private patchedMaterial;
|
|
27
|
+
/**
|
|
28
|
+
* Declares per-instance uniforms, merging with any already declared and rebuilding the backing
|
|
29
|
+
* texture (existing values carried across). See {@link InstanceUniforms.add}.
|
|
30
|
+
* @param schema - The uniforms to add.
|
|
31
|
+
*/
|
|
32
|
+
addUniforms(schema: UniformSchemaShader): void;
|
|
33
|
+
/**
|
|
34
|
+
* Reads one instance's uniform.
|
|
35
|
+
* @param id - The instance to read.
|
|
36
|
+
* @param name - The uniform's name.
|
|
37
|
+
* @param target - Receives the result; unused for a `float`, which is returned directly.
|
|
38
|
+
* @returns The value.
|
|
39
|
+
*/
|
|
40
|
+
getUniformAt(id: number, name: string, target?: UniformValueObj): UniformValue;
|
|
41
|
+
/**
|
|
42
|
+
* Writes one instance's uniform and marks its row for upload.
|
|
43
|
+
* @param id - The instance to write.
|
|
44
|
+
* @param name - The uniform's name.
|
|
45
|
+
* @param value - The value to write.
|
|
46
|
+
*/
|
|
47
|
+
setUniformAt(id: number, name: string, value: UniformValue): void;
|
|
48
|
+
raycast(raycaster: Raycaster, intersects: Intersection[]): void;
|
|
49
|
+
onBeforeRender(renderer: WebGLRenderer, scene: Scene, camera: Camera, geometry: BufferGeometry, material: Material, group: Group): void;
|
|
50
|
+
addInstance(geometryId: number): number;
|
|
51
|
+
deleteInstance(instanceId: number): this;
|
|
52
|
+
setMatrixAt(instanceId: number, matrix: Matrix4): this;
|
|
53
|
+
setInstanceCount(maxInstanceCount: number): void;
|
|
54
|
+
dispose(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Nulls the cached bounds so the next frustum test recomputes them. Kept here rather than at the
|
|
57
|
+
* call sites: every mutation that moves an instance goes through one of the overrides above.
|
|
58
|
+
*/
|
|
59
|
+
private invalidateBounds;
|
|
60
|
+
/**
|
|
61
|
+
* Wraps the current material's `onBeforeCompile` so compiled programs can read the uniform
|
|
62
|
+
* texture, once per material.
|
|
63
|
+
*
|
|
64
|
+
* Deferred to render time rather than done when uniforms are declared, because the material is
|
|
65
|
+
* usually attached after the mesh is constructed — R3F mounts it as a child element.
|
|
66
|
+
*/
|
|
67
|
+
private patchMaterial;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Registers the class as an R3F element, by value so the generated key cannot collide with the
|
|
71
|
+
* `BatchedMesh` three already puts in the catalog when the canvas mounts.
|
|
72
|
+
*/
|
|
73
|
+
export declare const BatchedMesh: import("react").ExoticComponent<import("@react-three/fiber/dist/declarations/src/core/utils").Mutable<import("@react-three/fiber/dist/declarations/src/core/utils").Overwrite<Partial<import("@react-three/fiber/dist/declarations/src/core/utils").Overwrite<BatchedMeshImpl, import("@react-three/fiber").MathProps<BatchedMeshImpl> & import("@react-three/fiber").ReactProps<BatchedMeshImpl> & Partial<import("@react-three/fiber").EventHandlers>>>, Omit<import("@react-three/fiber").InstanceProps<BatchedMeshImpl, typeof BatchedMeshImpl>, "object">>>>;
|
|
74
|
+
//# sourceMappingURL=BatchedMesh.d.ts.map
|