@mml-io/3d-web-client-core 0.22.0 → 0.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/build/camera/CameraManager.d.ts +6 -4
  2. package/build/character/Character.d.ts +25 -9
  3. package/build/character/CharacterManager.d.ts +45 -16
  4. package/build/character/CharacterModel.d.ts +12 -8
  5. package/build/character/CharacterState.d.ts +0 -10
  6. package/build/character/CharacterTooltip.d.ts +1 -0
  7. package/build/character/LocalController.d.ts +15 -14
  8. package/build/character/LowPolyModel.d.ts +1 -0
  9. package/build/character/RemoteController.d.ts +5 -5
  10. package/build/character/Spawning.d.ts +8 -0
  11. package/build/character/instancing/CharacterColourSamplingUtils.d.ts +14 -0
  12. package/build/character/instancing/CharacterInstances.d.ts +92 -0
  13. package/build/character/instancing/CharacterInstancingAnimationUtils.d.ts +7 -0
  14. package/build/character/instancing/CharacterInstancingUtils.d.ts +3 -0
  15. package/build/character/instancing/vendor/core/InstancedEntity.d.ts +191 -0
  16. package/build/character/instancing/vendor/core/InstancedMesh2.d.ts +361 -0
  17. package/build/character/instancing/vendor/core/InstancedMeshBVH.d.ts +145 -0
  18. package/build/character/instancing/vendor/core/feature/Capacity.d.ts +13 -0
  19. package/build/character/instancing/vendor/core/feature/FrustumCulling.d.ts +37 -0
  20. package/build/character/instancing/vendor/core/feature/Instances.d.ts +49 -0
  21. package/build/character/instancing/vendor/core/feature/LOD.d.ts +89 -0
  22. package/build/character/instancing/vendor/core/feature/Morph.d.ts +18 -0
  23. package/build/character/instancing/vendor/core/feature/Raycasting.d.ts +7 -0
  24. package/build/character/instancing/vendor/core/feature/Skeleton.d.ts +19 -0
  25. package/build/character/instancing/vendor/core/feature/Uniforms.d.ts +42 -0
  26. package/build/character/instancing/vendor/core/utils/GLInstancedBufferAttribute.d.ts +42 -0
  27. package/build/character/instancing/vendor/core/utils/InstancedRenderList.d.ts +25 -0
  28. package/build/character/instancing/vendor/core/utils/SquareDataTexture.d.ts +156 -0
  29. package/build/character/instancing/vendor/index.d.ts +25 -0
  30. package/build/character/instancing/vendor/shaders/ShaderChunk.d.ts +1 -0
  31. package/build/character/instancing/vendor/shaders/chunks/instanced_color_pars_vertex.d.ts +1 -0
  32. package/build/character/instancing/vendor/shaders/chunks/instanced_color_vertex.d.ts +1 -0
  33. package/build/character/instancing/vendor/shaders/chunks/instanced_material_color_pars_vertex.d.ts +1 -0
  34. package/build/character/instancing/vendor/shaders/chunks/instanced_material_color_vertex.d.ts +1 -0
  35. package/build/character/instancing/vendor/shaders/chunks/instanced_pars_vertex.d.ts +1 -0
  36. package/build/character/instancing/vendor/shaders/chunks/instanced_skinning_pars_vertex.d.ts +1 -0
  37. package/build/character/instancing/vendor/shaders/chunks/instanced_vertex.d.ts +1 -0
  38. package/build/character/instancing/vendor/utils/CreateFrom.d.ts +9 -0
  39. package/build/character/instancing/vendor/utils/SortingUtils.d.ts +16 -0
  40. package/build/character/loading/CharacterModelLoader.d.ts +11 -0
  41. package/build/character/loading/GLTFLoadingWorker.worker.d.ts +2 -0
  42. package/build/character/loading/GLTFLoadingWorkerBrowserCache.d.ts +8 -0
  43. package/build/character/loading/GLTFLoadingWorkerPool.d.ts +22 -0
  44. package/build/character/loading/GLTFLoadingWorkerTypes.d.ts +18 -0
  45. package/build/character/url-position.d.ts +7 -5
  46. package/build/collisions/CollisionsManager.d.ts +13 -8
  47. package/build/helpers/math-helpers.d.ts +3 -3
  48. package/build/index.d.ts +5 -2
  49. package/build/index.js +10787 -4182
  50. package/build/index.js.map +4 -4
  51. package/build/math/Box.d.ts +16 -0
  52. package/build/math/EulXYZ.d.ts +24 -0
  53. package/build/math/Line.d.ts +19 -0
  54. package/build/math/Matr4.d.ts +77 -0
  55. package/build/math/Quat.d.ts +57 -0
  56. package/build/math/Ray.d.ts +15 -0
  57. package/build/math/Vect3.d.ts +45 -0
  58. package/build/math/index.d.ts +8 -0
  59. package/build/math/radToDeg.d.ts +2 -0
  60. package/build/mml/MMLCompositionScene.d.ts +1 -1
  61. package/build/rendering/PostProcessingManager.d.ts +92 -0
  62. package/build/rendering/composer.d.ts +26 -25
  63. package/build/time/TimeManager.d.ts +2 -1
  64. package/build/tweakpane/TweakPane.d.ts +10 -5
  65. package/build/tweakpane/blades/{bcsFolder.d.ts → effects/bcsFolder.d.ts} +2 -2
  66. package/build/tweakpane/blades/effects/bloomAndGrain.d.ts +12 -0
  67. package/build/tweakpane/blades/{ssaoFolder.d.ts → effects/ssaoFolder.d.ts} +6 -31
  68. package/build/tweakpane/blades/{toneMappingFolder.d.ts → effects/toneMappingFolder.d.ts} +1 -1
  69. package/build/tweakpane/blades/environmentFolder.d.ts +6 -3
  70. package/build/tweakpane/blades/postProcessingFolder.d.ts +31 -0
  71. package/build/tweakpane/blades/rendererFolder.d.ts +1 -1
  72. package/build/tweakpane/blades/rendererStatsFolder.d.ts +0 -2
  73. package/package.json +16 -11
  74. package/build/character/CharacterModelLoader.d.ts +0 -11
  75. package/build/character/CharacterSpeakingIndicator.d.ts +0 -17
  76. package/build/tweakpane/blades/postExtrasFolder.d.ts +0 -12
@@ -0,0 +1,191 @@
1
+ import { Color, ColorRepresentation, Euler, Matrix4, Mesh, Object3D, Quaternion, Vector3 } from "three";
2
+ import { InstancedMesh2 } from "./InstancedMesh2";
3
+ import { UniformValue, UniformValueObj } from "./utils/SquareDataTexture";
4
+ /**
5
+ * Represents an instance in an `InstancedMesh2`.
6
+ * This class stores transformation data (position, rotation, scale) and provides methods to manipulate them.
7
+ */
8
+ export declare class InstancedEntity {
9
+ /**
10
+ * Indicates if this is an `InstancedEntity`.
11
+ */
12
+ readonly isInstanceEntity = true;
13
+ /**
14
+ * The unique identifier for this instance (relative to the `InstancedMesh2` it references).
15
+ */
16
+ readonly id: number;
17
+ /**
18
+ * `InstancedMesh2` to which this instance refers.
19
+ */
20
+ readonly owner: InstancedMesh2;
21
+ /**
22
+ * The local position.
23
+ */
24
+ position: Vector3;
25
+ /**
26
+ * The local scale.
27
+ */
28
+ scale: Vector3;
29
+ /**
30
+ * The local rotation as `Quaternion`.
31
+ */
32
+ quaternion: Quaternion;
33
+ /**
34
+ * The local rotation as `Euler`.
35
+ * This works only if `allowsEuler` is set to `true` in the `InstancedMesh2` constructor parameters.
36
+ */
37
+ rotation: Euler;
38
+ /**
39
+ * The visibility state set and got from `owner.availabilityArray`.
40
+ */
41
+ get visible(): boolean;
42
+ set visible(value: boolean);
43
+ /**
44
+ * The availability set and got from `owner.availabilityArray`.
45
+ */
46
+ get active(): boolean;
47
+ set active(value: boolean);
48
+ /**
49
+ * Color set and got from `owner.colorsTexture`.
50
+ */
51
+ get color(): Color;
52
+ set color(value: ColorRepresentation);
53
+ /**
54
+ * Opacity set and got from `owner.colorsTexture`.
55
+ */
56
+ get opacity(): number;
57
+ set opacity(value: number);
58
+ /**
59
+ * Morph target influences set and got from `owner.morphTexture`.
60
+ */
61
+ get morph(): Mesh;
62
+ set morph(value: Mesh);
63
+ /**
64
+ * The local transform matrix got from `owner.matricesTexture`.
65
+ */
66
+ get matrix(): Matrix4;
67
+ /**
68
+ * The world transform matrix got by multiplying the matrix got from `owner.matricesTexture` and `this.owner.matrixWorld`.
69
+ */
70
+ get matrixWorld(): Matrix4;
71
+ /**
72
+ * This object is instantiated automatically by setting `createEntities` to `true` in the `InstancedMesh2` constructor parameters.
73
+ * Dont instantiate this manually.
74
+ * @param owner The `InstancedMesh2` that owns this instance.
75
+ * @param id The unique identifier for this instance within the `InstancedMesh2`.
76
+ * @param useEuler Whether to use Euler rotations in addition to quaternion rotations.
77
+ */
78
+ constructor(owner: InstancedMesh2, id: number, useEuler: boolean);
79
+ /**
80
+ * Set the transformation matrix to identity matrix.
81
+ */
82
+ setMatrixIdentity(): void;
83
+ /**
84
+ * Updates the transformation matrix with its current position, quaternion, and scale.
85
+ * The updated matrix is stored in the `owner.matricesTexture`.
86
+ */
87
+ updateMatrix(): void;
88
+ /**
89
+ * Updates only the position component of the transformation matrix.
90
+ * This is useful if only position changes, avoiding recalculating the full matrix.
91
+ * The updated matrix is stored in the `owner.matricesTexture`.
92
+ */
93
+ updateMatrixPosition(): void;
94
+ /**
95
+ * Retrieves the uniform value associated with the given name.
96
+ * @param name The name of the uniform to retrieve.
97
+ * @param target Optional target object where the uniform value will be written.
98
+ * @returns The retrieved uniform value.
99
+ */
100
+ getUniform(name: string, target?: UniformValueObj): UniformValue;
101
+ /**
102
+ * Updates the bones of the skeleton to the instance.
103
+ * @param updateBonesMatrices Whether to update the matrices of the bones. Default is `true`.
104
+ */
105
+ updateBones(updateBonesMatrices?: boolean): void;
106
+ /**
107
+ * Sets the uniform value for the given name
108
+ * @param name The name of the uniform to set.
109
+ * @param value The new value for the uniform.
110
+ */
111
+ setUniform(name: string, value: UniformValue): void;
112
+ /**
113
+ * Copies the transformation properties (`position`, `scale`, `quaternion`) of this instance to the specified `Object3D`.
114
+ * @param target The `Object3D` where the transformation properties will be copied.
115
+ */
116
+ copyTo(target: Object3D): void;
117
+ /**
118
+ * Applies the matrix transform to the object and updates the object's position, rotation and scale.
119
+ * @param m The matrix to apply.
120
+ * @returns The instance of the object.
121
+ */
122
+ applyMatrix4(m: Matrix4): this;
123
+ /**
124
+ * Applies the rotation represented by the quaternion to the object.
125
+ * @param q The quaternion representing the rotation to apply.
126
+ * @returns The instance of the object.
127
+ */
128
+ applyQuaternion(q: Quaternion): this;
129
+ /**
130
+ * Rotate an object along an axis in object space. The axis is assumed to be normalized.
131
+ * @param axis A normalized vector in object space.
132
+ * @param angle The angle in radians.
133
+ * @returns The instance of the object.
134
+ */
135
+ rotateOnAxis(axis: Vector3, angle: number): this;
136
+ /**
137
+ * Rotate an object along an axis in world space. The axis is assumed to be normalized. Method Assumes no rotated parent.
138
+ * @param axis A normalized vector in world space.
139
+ * @param angle The angle in radians.
140
+ * @returns The instance of the object.
141
+ */
142
+ rotateOnWorldAxis(axis: Vector3, angle: number): this;
143
+ /**
144
+ * Rotates the object around x axis in local space.
145
+ * @param angle The angle to rotate in radians.
146
+ * @returns The instance of the object.
147
+ */
148
+ rotateX(angle: number): this;
149
+ /**
150
+ * Rotates the object around y axis in local space.
151
+ * @param angle The angle to rotate in radians.
152
+ * @returns The instance of the object.
153
+ */
154
+ rotateY(angle: number): this;
155
+ /**
156
+ * Rotates the object around z axis in local space.
157
+ * @param angle The angle to rotate in radians.
158
+ * @returns The instance of the object.
159
+ */
160
+ rotateZ(angle: number): this;
161
+ /**
162
+ * Translate an object by distance along an axis in object space. The axis is assumed to be normalized.
163
+ * @param axis A normalized vector in object space.
164
+ * @param distance The distance to translate.
165
+ * @returns The instance of the object.
166
+ */
167
+ translateOnAxis(axis: Vector3, distance: number): this;
168
+ /**
169
+ * Translates object along x axis in object space by distance units.
170
+ * @param distance The distance to translate.
171
+ * @returns The instance of the object.
172
+ */
173
+ translateX(distance: number): this;
174
+ /**
175
+ * Translates object along y axis in object space by distance units.
176
+ * @param distance The distance to translate.
177
+ * @returns The instance of the object.
178
+ */
179
+ translateY(distance: number): this;
180
+ /**
181
+ * Translates object along z axis in object space by distance units.
182
+ * @param distance The distance to translate.
183
+ * @returns The instance of the object.
184
+ */
185
+ translateZ(distance: number): this;
186
+ /**
187
+ * Removes this entity from its owner instance.
188
+ * @returns The instance of the object.
189
+ */
190
+ remove(): this;
191
+ }
@@ -0,0 +1,361 @@
1
+ import { BindMode, Box3, BufferGeometry, Camera, Color, ColorRepresentation, DataTexture, InstancedBufferAttribute, Material, Matrix4, Mesh, Object3D, Object3DEventMap, Scene, Skeleton, Sphere, Vector3, WebGLProgramParametersWithUniforms, WebGLRenderer } from "three";
2
+ import { ColorPartName } from "../../../CharacterModel";
3
+ import { CustomSortCallback, OnFrustumEnterCallback } from "./feature/FrustumCulling";
4
+ import { Entity } from "./feature/Instances";
5
+ import { LODInfo } from "./feature/LOD";
6
+ import { InstancedEntity } from "./InstancedEntity";
7
+ import { BVHParams, InstancedMeshBVH } from "./InstancedMeshBVH";
8
+ import { GLInstancedBufferAttribute } from "./utils/GLInstancedBufferAttribute";
9
+ import { SquareDataTexture } from "./utils/SquareDataTexture";
10
+ /**
11
+ * Parameters for configuring an `InstancedMesh2` instance.
12
+ */
13
+ export interface InstancedMesh2Params {
14
+ /**
15
+ * Determines the maximum number of instances that buffers can hold.
16
+ * The buffers will be expanded automatically if necessary.
17
+ * @default 1000
18
+ */
19
+ capacity?: number;
20
+ /**
21
+ * Determines whether to create an array of `InstancedEntity` to easily manipulate instances at the cost of more memory.
22
+ * @default false
23
+ */
24
+ createEntities?: boolean;
25
+ /**
26
+ * Determines whether `InstancedEntity` can use the `rotation` property.
27
+ * If `true` `quaternion` and `rotation` will be synchronized, affecting performance.
28
+ * @default false
29
+ */
30
+ allowsEuler?: boolean;
31
+ /**
32
+ * WebGL renderer instance.
33
+ * If not provided, buffers will be initialized during the first render, resulting in no instances being rendered initially.
34
+ * @default null
35
+ */
36
+ renderer?: WebGLRenderer;
37
+ }
38
+ /**
39
+ * Alternative `InstancedMesh` class to support additional features like frustum culling, fast raycasting, LOD and more.
40
+ * @template TData Type for additional instance data.
41
+ * @template TGeometry Type extending `BufferGeometry`.
42
+ * @template TMaterial Type extending `Material` or an array of `Material`.
43
+ * @template TEventMap Type extending `Object3DEventMap`.
44
+ */
45
+ export declare class InstancedMesh2<TData = {}, TGeometry extends BufferGeometry = BufferGeometry, TMaterial extends Material | Material[] = Material | Material[], TEventMap extends Object3DEventMap = Object3DEventMap> extends Mesh<TGeometry, TMaterial, TEventMap> {
46
+ /**
47
+ * The number of instances rendered in the last frame.
48
+ */
49
+ count: number;
50
+ /**
51
+ * @defaultValue `InstancedMesh2`
52
+ */
53
+ readonly type = "InstancedMesh2";
54
+ /**
55
+ * Indicates if this is an `InstancedMesh2`.
56
+ */
57
+ readonly isInstancedMesh2 = true;
58
+ /**
59
+ * An array of `Entity` representing individual instances.
60
+ * This array is only initialized if `createEntities` is set to `true` in the constructor parameters.
61
+ */
62
+ instances: Entity<TData>[] | null;
63
+ /**
64
+ * Attribute storing indices of the instances to be rendered.
65
+ */
66
+ instanceIndex: GLInstancedBufferAttribute | null;
67
+ /**
68
+ * Texture storing matrices for instances.
69
+ */
70
+ matricesTexture: SquareDataTexture;
71
+ /**
72
+ * Texture storing colors for instances.
73
+ */
74
+ colorsTexture: SquareDataTexture | null;
75
+ /**
76
+ * Texture storing multiple colors per instance for per-material coloring.
77
+ * Stores 8 colors per instance (hair, shirt_short, shirt_long, pants_short, pants_long, shoes, skin, lips)
78
+ * Each row stores 2 colors (8 floats), so we need 4 pixels per instance (4 * 2 = 8 colors)
79
+ */
80
+ materialColorsTexture: SquareDataTexture | null;
81
+ /**
82
+ * Texture storing morph target influences for instances.
83
+ */
84
+ morphTexture: DataTexture | null;
85
+ /**
86
+ * Texture storing bones for instances.
87
+ */
88
+ boneTexture: SquareDataTexture | null;
89
+ /**
90
+ * Texture storing custom uniforms per instance.
91
+ */
92
+ uniformsTexture: SquareDataTexture | null;
93
+ /**
94
+ * This bounding box encloses all instances, which can be calculated with `computeBoundingBox` method.
95
+ * Bounding box isn't computed by default. It needs to be explicitly computed, otherwise it's `null`.
96
+ */
97
+ boundingBox: Box3 | null;
98
+ /**
99
+ * This bounding sphere encloses all instances, which can be calculated with `computeBoundingSphere` method.
100
+ * Bounding sphere is computed during its first render. You may need to recompute it if an instance is transformed.
101
+ */
102
+ boundingSphere: Sphere | null;
103
+ /**
104
+ * BVH structure for optimized culling and intersection testing.
105
+ * It's possible to create the BVH using the `computeBVH` method. Once created it will be updated automatically.
106
+ */
107
+ bvh: InstancedMeshBVH | null;
108
+ /**
109
+ * Custom sort function for instances.
110
+ * It's possible to create the radix sort using the `createRadixSort` method.
111
+ * @default null
112
+ */
113
+ customSort: CustomSortCallback | null;
114
+ /**
115
+ * Flag indicating if raycasting should only consider the last frame frustum culled instances.
116
+ * This is ignored if the bvh has been created.
117
+ * @default false
118
+ */
119
+ raycastOnlyFrustum: boolean;
120
+ /**
121
+ * Array storing visibility and availability for instances.
122
+ * [visible0, active0, visible1, active1, ...]
123
+ */
124
+ readonly availabilityArray: boolean[];
125
+ /**
126
+ * Contains data for managing LOD, allowing different levels of detail for rendering and shadow casting.
127
+ */
128
+ LODinfo: LODInfo<TData> | null;
129
+ /**
130
+ * Flag indicating whether to automatically perform frustum culling before rendering.
131
+ * @default true
132
+ */
133
+ autoUpdate: boolean;
134
+ /**
135
+ * Either `AttachedBindMode` or `DetachedBindMode`. `AttachedBindMode` means the skinned mesh shares the same world space as the skeleton.
136
+ * This is not true when using `DetachedBindMode` which is useful when sharing a skeleton across multiple skinned meshes.
137
+ * @default `AttachedBindMode`
138
+ */
139
+ bindMode: BindMode;
140
+ /**
141
+ * The base matrix that is used for the bound bone transforms.
142
+ */
143
+ bindMatrix: Matrix4 | null;
144
+ /**
145
+ * The base matrix that is used for resetting the bound bone transforms.
146
+ */
147
+ bindMatrixInverse: Matrix4 | null;
148
+ /**
149
+ * Skeleton representing the bone hierarchy of the skinned mesh.
150
+ */
151
+ skeleton: Skeleton | null;
152
+ /**
153
+ * Callback function called if an instance is inside the frustum.
154
+ */
155
+ onFrustumEnter: OnFrustumEnterCallback | null;
156
+ /** @internal */ _renderer: WebGLRenderer | null;
157
+ /** @internal */ _instancesCount: number;
158
+ /** @internal */ _instancesArrayCount: number;
159
+ /** @internal */ _perObjectFrustumCulled: boolean;
160
+ /** @internal */ _sortObjects: boolean;
161
+ /** @internal */ _capacity: number;
162
+ /** @internal */ _indexArrayNeedsUpdate: boolean;
163
+ /** @internal */ _geometry: TGeometry;
164
+ /** @internal */ _parentLOD: InstancedMesh2;
165
+ protected readonly _allowsEuler: boolean;
166
+ protected readonly _tempInstance: InstancedEntity;
167
+ protected _useOpacity: boolean;
168
+ protected _currentMaterial: Material | null;
169
+ protected _customProgramCacheKeyBase: (() => string) | null;
170
+ protected _onBeforeCompileBase: ((parameters: WebGLProgramParametersWithUniforms, renderer: WebGLRenderer) => void) | null;
171
+ protected _propertiesGetBase: ((obj: unknown) => unknown) | null;
172
+ protected _propertiesGetMap: WeakMap<Material, (obj: unknown) => unknown>;
173
+ protected _properties: WeakMap<Material, unknown>;
174
+ protected _freeIds: number[];
175
+ protected _createEntities: boolean;
176
+ /** @internal */ isInstancedMesh: boolean;
177
+ /** @internal */ instanceMatrix: InstancedBufferAttribute;
178
+ /** @internal */ instanceColor: null;
179
+ /**
180
+ * The capacity of the instance buffers.
181
+ */
182
+ get capacity(): number;
183
+ /**
184
+ * The number of active instances.
185
+ */
186
+ get instancesCount(): number;
187
+ /**
188
+ * Determines if per-instance frustum culling is enabled.
189
+ * @default true
190
+ */
191
+ get perObjectFrustumCulled(): boolean;
192
+ set perObjectFrustumCulled(value: boolean);
193
+ /**
194
+ * Determines if objects should be sorted before rendering.
195
+ * @default false
196
+ */
197
+ get sortObjects(): boolean;
198
+ set sortObjects(value: boolean);
199
+ /**
200
+ * An instance of `BufferGeometry` (or derived classes), defining the object's structure.
201
+ */
202
+ get geometry(): TGeometry;
203
+ set geometry(value: TGeometry);
204
+ /** @internal */
205
+ constructor(geometry: TGeometry, material: TMaterial, params?: InstancedMesh2Params, LOD?: InstancedMesh2);
206
+ constructor(geometry: TGeometry, material: TMaterial, params?: InstancedMesh2Params);
207
+ onBeforeShadow(renderer: WebGLRenderer, scene: Scene, camera: Camera, shadowCamera: Camera, geometry: BufferGeometry, depthMaterial: Material, group: any): void;
208
+ onBeforeRender(renderer: WebGLRenderer, scene: Scene, camera: Camera, geometry: BufferGeometry, material: Material, group: any): void;
209
+ onAfterShadow(renderer: WebGLRenderer, scene: Scene, camera: Camera, shadowCamera: Camera, geometry: BufferGeometry, depthMaterial: Material, group: any): void;
210
+ onAfterRender(renderer: WebGLRenderer, scene: Scene, camera: Camera, geometry: BufferGeometry, material: Material, group: any): void;
211
+ protected isFirstGroup(materialIndex: number): boolean;
212
+ protected isLastGroup(materialIndex: number): boolean;
213
+ protected initIndexAttribute(): void;
214
+ protected initMatricesTexture(): void;
215
+ protected initColorsTexture(): void;
216
+ protected initMaterialColorsTexture(): void;
217
+ materialsNeedsUpdate(): void;
218
+ protected patchGeometry(geometry: TGeometry): void;
219
+ protected _customProgramCacheKey: () => string;
220
+ protected _onBeforeCompile: (shader: WebGLProgramParametersWithUniforms, renderer: WebGLRenderer) => void;
221
+ protected patchMaterial(renderer: WebGLRenderer, material: Material): void;
222
+ protected unpatchMaterial(renderer: WebGLRenderer, material: Material): void;
223
+ /**
224
+ * Creates and computes the BVH (Bounding Volume Hierarchy) for the instances.
225
+ * It's recommended to create it when all the instance matrices have been assigned.
226
+ * Once created it will be updated automatically.
227
+ * @param config Optional configuration parameters object. See `BVHParams` for details.
228
+ */
229
+ computeBVH(config?: BVHParams): void;
230
+ /**
231
+ * Disposes of the BVH structure.
232
+ */
233
+ disposeBVH(): void;
234
+ /**
235
+ * Sets the local transformation matrix for a specific instance.
236
+ * @param id The index of the instance.
237
+ * @param matrix A `Matrix4` representing the local transformation to apply to the instance.
238
+ */
239
+ setMatrixAt(id: number, matrix: Matrix4): void;
240
+ /**
241
+ * Gets the local transformation matrix of a specific instance.
242
+ * @param id The index of the instance.
243
+ * @param matrix Optional `Matrix4` to store the result.
244
+ * @returns The transformation matrix of the instance.
245
+ */
246
+ getMatrixAt(id: number, matrix?: Matrix4): Matrix4;
247
+ /**
248
+ * Retrieves the position of a specific instance.
249
+ * @param index The index of the instance.
250
+ * @param target Optional `Vector3` to store the result.
251
+ * @returns The position of the instance as a `Vector3`.
252
+ */
253
+ getPositionAt(index: number, target?: Vector3): Vector3;
254
+ /** @internal */
255
+ getPositionAndMaxScaleOnAxisAt(index: number, position: Vector3): number;
256
+ /** @internal */
257
+ applyMatrixAtToSphere(index: number, sphere: Sphere, center: Vector3, radius: number): void;
258
+ /**
259
+ * Sets the visibility of a specific instance.
260
+ * @param id The index of the instance.
261
+ * @param visible Whether the instance should be visible.
262
+ */
263
+ setVisibilityAt(id: number, visible: boolean): void;
264
+ /**
265
+ * Gets the visibility of a specific instance.
266
+ * @param id The index of the instance.
267
+ * @returns Whether the instance is visible.
268
+ */
269
+ getVisibilityAt(id: number): boolean;
270
+ /**
271
+ * Sets the availability of a specific instance.
272
+ * @param id The index of the instance.
273
+ * @param active Whether the instance is active (not deleted).
274
+ */
275
+ setActiveAt(id: number, active: boolean): void;
276
+ /**
277
+ * Gets the availability of a specific instance.
278
+ * @param id The index of the instance.
279
+ * @returns Whether the instance is active (not deleted).
280
+ */
281
+ getActiveAt(id: number): boolean;
282
+ /**
283
+ * Indicates if a specific instance is visible and active.
284
+ * @param id The index of the instance.
285
+ * @returns Whether the instance is visible and active.
286
+ */
287
+ getActiveAndVisibilityAt(id: number): boolean;
288
+ /**
289
+ * Set if a specific instance is visible and active.
290
+ * @param id The index of the instance.
291
+ * @param value Whether the instance is active and active (not deleted).
292
+ */
293
+ setActiveAndVisibilityAt(id: number, value: boolean): void;
294
+ /**
295
+ * Sets the color of a specific instance.
296
+ * @param id The index of the instance.
297
+ * @param color The color to assign to the instance.
298
+ */
299
+ setColorAt(id: number, color: ColorRepresentation): void;
300
+ /**
301
+ * Gets the color of a specific instance.
302
+ * @param id The index of the instance.
303
+ * @param color Optional `Color` to store the result.
304
+ * @returns The color of the instance.
305
+ */
306
+ getColorAt(id: number, color?: Color): Color;
307
+ /**
308
+ * Sets the opacity of a specific instance.
309
+ * @param id The index of the instance.
310
+ * @param value The opacity value to assign.
311
+ */
312
+ setOpacityAt(id: number, value: number): void;
313
+ /**
314
+ * Gets the opacity of a specific instance.
315
+ * @param id The index of the instance.
316
+ * @returns The opacity of the instance.
317
+ */
318
+ getOpacityAt(id: number): number;
319
+ /**
320
+ * Sets material-specific colors for an instance.
321
+ * @param id The index of the instance.
322
+ * @param materialColors Object containing colors for different materials.
323
+ */
324
+ setMaterialColorsAt(id: number, materialColors: Map<ColorPartName, Color>): void;
325
+ /**
326
+ * Gets material-specific colors for an instance.
327
+ * @param id The index of the instance.
328
+ * @returns Object containing colors for different materials.
329
+ */
330
+ getMaterialColorsAt(id: number): {
331
+ hair: Color;
332
+ shirt_short: Color;
333
+ shirt_long: Color;
334
+ pants_short: Color;
335
+ pants_long: Color;
336
+ shoes: Color;
337
+ skin: Color;
338
+ lips: Color;
339
+ } | null;
340
+ /**
341
+ * Copies `position`, `quaternion`, and `scale` of a specific instance to the specified target `Object3D`.
342
+ * @param id The index of the instance.
343
+ * @param target The `Object3D` where to copy transformation data.
344
+ */
345
+ copyTo(id: number, target: Object3D): void;
346
+ /**
347
+ * Computes the bounding box that encloses all instances, and updates the `boundingBox` attribute.
348
+ */
349
+ computeBoundingBox(): void;
350
+ /**
351
+ * Computes the bounding sphere that encloses all instances, and updates the `boundingSphere` attribute.
352
+ */
353
+ computeBoundingSphere(): void;
354
+ clone(recursive?: boolean): this;
355
+ copy(argSource: Object3D, recursive?: boolean): this;
356
+ /**
357
+ * Frees the GPU-related resources allocated.
358
+ */
359
+ dispose(): void;
360
+ updateMatrixWorld(force?: boolean): void;
361
+ }
@@ -0,0 +1,145 @@
1
+ import { Box3, Matrix4, Raycaster, Sphere, Vector3 } from "three";
2
+ import { MeshBVH } from "three-mesh-bvh";
3
+ import { LODLevel } from "./feature/LOD";
4
+ import { InstancedMesh2 } from "./InstancedMesh2";
5
+ export type onFrustumIntersectionCallback<T, U> = (nodeIndex: number) => void;
6
+ export type onFrustumIntersectionLODCallback<T, U> = (nodeIndex: number, level: number) => void;
7
+ export type onIntersectionCallback<T> = (nodeIndex: number) => void;
8
+ export type onIntersectionRayCallback<T> = (nodeIndex: number) => void;
9
+ /**
10
+ * Parameters for configuring the BVH (Bounding Volume Hierarchy).
11
+ */
12
+ export interface BVHParams {
13
+ /**
14
+ * Margin applied to accommodate animated or moving objects.
15
+ * Improves BVH update performance but slows down frustum culling and raycasting.
16
+ * For static objects, set to 0 to optimize culling and raycasting efficiency.
17
+ * @default 0
18
+ */
19
+ margin?: number;
20
+ /**
21
+ * Uses the geometry bounding sphere to compute instance bounding boxes.
22
+ * Otherwise it's calculated by applying the object's matrix to all 8 bounding box points.
23
+ * This is faster but less precise. Useful for moving objects.
24
+ * Only works if the geometry's bounding sphere is centered at the origin.
25
+ * @default false
26
+ */
27
+ getBBoxFromBSphere?: boolean;
28
+ /**
29
+ * Enables accurate frustum culling by checking intersections without applying margin to the bounding box.
30
+ * @default true
31
+ */
32
+ accurateCulling?: boolean;
33
+ }
34
+ interface SphereTarget {
35
+ centerX: number;
36
+ centerY: number;
37
+ centerZ: number;
38
+ maxScale: number;
39
+ }
40
+ /**
41
+ * Class to manage BVH (Bounding Volume Hierarchy) for `InstancedMesh2`.
42
+ * Provides methods for managing bounding volumes, frustum culling, raycasting, and bounding box computation.
43
+ */
44
+ export declare class InstancedMeshBVH {
45
+ /**
46
+ * The target `InstancedMesh2` object that the BVH is managing.
47
+ */
48
+ target: InstancedMesh2;
49
+ /**
50
+ * The geometry bounding box of the target.
51
+ */
52
+ geoBoundingBox: Box3;
53
+ /**
54
+ * The BVH instance used to organize bounding volumes.
55
+ */
56
+ bvh: MeshBVH | null;
57
+ /**
58
+ * A map that stores the BVH nodes for each instance.
59
+ */
60
+ nodesMap: Map<number, any>;
61
+ /**
62
+ * Enables accurate frustum culling by checking intersections without applying margin to the bounding box.
63
+ */
64
+ accurateCulling: boolean;
65
+ protected LODsMap: Map<LODLevel<{}>[], Float32Array<ArrayBufferLike>>;
66
+ protected _margin: number;
67
+ protected _origin: Float32Array;
68
+ protected _dir: Float32Array;
69
+ protected _boxArray: Float32Array | null;
70
+ protected _cameraPos: Float32Array;
71
+ protected _getBoxFromSphere: boolean;
72
+ protected _geoBoundingSphere: Sphere | null;
73
+ protected _sphereTarget: SphereTarget | null;
74
+ /**
75
+ * @param target The target `InstancedMesh2`.
76
+ * @param margin The margin applied for bounding box calculations (default is 0).
77
+ * @param getBBoxFromBSphere Flag to determine if instance bounding boxes should be computed from the geometry bounding sphere. Faster but less precise (default is false).
78
+ * @param accurateCulling Flag to enable accurate frustum culling without considering margin (default is true).
79
+ */
80
+ constructor(target: InstancedMesh2, margin?: number, getBBoxFromBSphere?: boolean, accurateCulling?: boolean);
81
+ /**
82
+ * Builds the BVH from the target mesh's instances using a top-down construction method.
83
+ * This approach is more efficient and accurate compared to incremental methods, which add one instance at a time.
84
+ * Note: Simplified implementation for three-mesh-bvh compatibility
85
+ */
86
+ create(): void;
87
+ /**
88
+ * Inserts an instance into the BVH.
89
+ * @param id The id of the instance to insert.
90
+ */
91
+ insert(id: number): void;
92
+ /**
93
+ * Inserts a range of instances into the BVH.
94
+ * @param ids An array of ids to insert.
95
+ */
96
+ insertRange(ids: number[]): void;
97
+ /**
98
+ * Moves an instance within the BVH.
99
+ * @param id The id of the instance to move.
100
+ */
101
+ move(id: number): void;
102
+ /**
103
+ * Deletes an instance from the BVH.
104
+ * @param id The id of the instance to delete.
105
+ */
106
+ delete(id: number): void;
107
+ /**
108
+ * Clears the BVH.
109
+ */
110
+ clear(): void;
111
+ /**
112
+ * Performs frustum culling to determine which instances are visible based on the provided projection matrix.
113
+ * @param projScreenMatrix The projection screen matrix for frustum culling.
114
+ * @param onFrustumIntersection Callback function invoked when an instance intersects the frustum.
115
+ * Note: Simplified implementation - BVH frustum culling disabled
116
+ */
117
+ frustumCulling(projScreenMatrix: Matrix4, onFrustumIntersection: onFrustumIntersectionCallback<object, number>): void;
118
+ /**
119
+ * Performs frustum culling with Level of Detail (LOD) consideration.
120
+ * @param projScreenMatrix The projection screen matrix for frustum culling.
121
+ * @param cameraPosition The camera's position used for LOD calculations.
122
+ * @param levels An array of LOD levels.
123
+ * @param onFrustumIntersection Callback function invoked when an instance intersects the frustum.
124
+ * Note: Simplified implementation - BVH LOD culling disabled
125
+ */
126
+ frustumCullingLOD(projScreenMatrix: Matrix4, cameraPosition: Vector3, levels: LODLevel[], onFrustumIntersection: onFrustumIntersectionLODCallback<object, number>): void;
127
+ /**
128
+ * Performs raycasting to check if a ray intersects any instances.
129
+ * @param raycaster The raycaster used for raycasting.
130
+ * @param onIntersection Callback function invoked when a ray intersects an instance.
131
+ * Note: Simplified implementation - BVH raycasting disabled
132
+ */
133
+ raycast(raycaster: Raycaster, onIntersection: onIntersectionRayCallback<number>): void;
134
+ /**
135
+ * Checks if a given box intersects with any instance bounding box.
136
+ * @param target The target bounding box.
137
+ * @param onIntersection Callback function invoked when an intersection occurs.
138
+ * @returns `True` if there is an intersection, otherwise `false`.
139
+ * Note: Simplified implementation - BVH box intersection disabled
140
+ */
141
+ intersectBox(target: Box3, onIntersection: onIntersectionCallback<number>): boolean;
142
+ protected getBox(id: number, array: Float32Array): Float32Array;
143
+ protected getSphereFromMatrix_centeredGeometry(id: number, array: Float32Array, target: SphereTarget): SphereTarget;
144
+ }
145
+ export {};