@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.
- package/build/camera/CameraManager.d.ts +6 -4
- package/build/character/Character.d.ts +25 -9
- package/build/character/CharacterManager.d.ts +45 -16
- package/build/character/CharacterModel.d.ts +12 -8
- package/build/character/CharacterState.d.ts +0 -10
- package/build/character/CharacterTooltip.d.ts +1 -0
- package/build/character/LocalController.d.ts +15 -14
- package/build/character/LowPolyModel.d.ts +1 -0
- package/build/character/RemoteController.d.ts +5 -5
- package/build/character/Spawning.d.ts +8 -0
- package/build/character/instancing/CharacterColourSamplingUtils.d.ts +14 -0
- package/build/character/instancing/CharacterInstances.d.ts +92 -0
- package/build/character/instancing/CharacterInstancingAnimationUtils.d.ts +7 -0
- package/build/character/instancing/CharacterInstancingUtils.d.ts +3 -0
- package/build/character/instancing/vendor/core/InstancedEntity.d.ts +191 -0
- package/build/character/instancing/vendor/core/InstancedMesh2.d.ts +361 -0
- package/build/character/instancing/vendor/core/InstancedMeshBVH.d.ts +145 -0
- package/build/character/instancing/vendor/core/feature/Capacity.d.ts +13 -0
- package/build/character/instancing/vendor/core/feature/FrustumCulling.d.ts +37 -0
- package/build/character/instancing/vendor/core/feature/Instances.d.ts +49 -0
- package/build/character/instancing/vendor/core/feature/LOD.d.ts +89 -0
- package/build/character/instancing/vendor/core/feature/Morph.d.ts +18 -0
- package/build/character/instancing/vendor/core/feature/Raycasting.d.ts +7 -0
- package/build/character/instancing/vendor/core/feature/Skeleton.d.ts +19 -0
- package/build/character/instancing/vendor/core/feature/Uniforms.d.ts +42 -0
- package/build/character/instancing/vendor/core/utils/GLInstancedBufferAttribute.d.ts +42 -0
- package/build/character/instancing/vendor/core/utils/InstancedRenderList.d.ts +25 -0
- package/build/character/instancing/vendor/core/utils/SquareDataTexture.d.ts +156 -0
- package/build/character/instancing/vendor/index.d.ts +25 -0
- package/build/character/instancing/vendor/shaders/ShaderChunk.d.ts +1 -0
- package/build/character/instancing/vendor/shaders/chunks/instanced_color_pars_vertex.d.ts +1 -0
- package/build/character/instancing/vendor/shaders/chunks/instanced_color_vertex.d.ts +1 -0
- package/build/character/instancing/vendor/shaders/chunks/instanced_material_color_pars_vertex.d.ts +1 -0
- package/build/character/instancing/vendor/shaders/chunks/instanced_material_color_vertex.d.ts +1 -0
- package/build/character/instancing/vendor/shaders/chunks/instanced_pars_vertex.d.ts +1 -0
- package/build/character/instancing/vendor/shaders/chunks/instanced_skinning_pars_vertex.d.ts +1 -0
- package/build/character/instancing/vendor/shaders/chunks/instanced_vertex.d.ts +1 -0
- package/build/character/instancing/vendor/utils/CreateFrom.d.ts +9 -0
- package/build/character/instancing/vendor/utils/SortingUtils.d.ts +16 -0
- package/build/character/loading/CharacterModelLoader.d.ts +11 -0
- package/build/character/loading/GLTFLoadingWorker.worker.d.ts +2 -0
- package/build/character/loading/GLTFLoadingWorkerBrowserCache.d.ts +8 -0
- package/build/character/loading/GLTFLoadingWorkerPool.d.ts +22 -0
- package/build/character/loading/GLTFLoadingWorkerTypes.d.ts +18 -0
- package/build/character/url-position.d.ts +7 -5
- package/build/collisions/CollisionsManager.d.ts +13 -8
- package/build/helpers/math-helpers.d.ts +3 -3
- package/build/index.d.ts +5 -2
- package/build/index.js +10787 -4182
- package/build/index.js.map +4 -4
- package/build/math/Box.d.ts +16 -0
- package/build/math/EulXYZ.d.ts +24 -0
- package/build/math/Line.d.ts +19 -0
- package/build/math/Matr4.d.ts +77 -0
- package/build/math/Quat.d.ts +57 -0
- package/build/math/Ray.d.ts +15 -0
- package/build/math/Vect3.d.ts +45 -0
- package/build/math/index.d.ts +8 -0
- package/build/math/radToDeg.d.ts +2 -0
- package/build/mml/MMLCompositionScene.d.ts +1 -1
- package/build/rendering/PostProcessingManager.d.ts +92 -0
- package/build/rendering/composer.d.ts +26 -25
- package/build/time/TimeManager.d.ts +2 -1
- package/build/tweakpane/TweakPane.d.ts +10 -5
- package/build/tweakpane/blades/{bcsFolder.d.ts → effects/bcsFolder.d.ts} +2 -2
- package/build/tweakpane/blades/effects/bloomAndGrain.d.ts +12 -0
- package/build/tweakpane/blades/{ssaoFolder.d.ts → effects/ssaoFolder.d.ts} +6 -31
- package/build/tweakpane/blades/{toneMappingFolder.d.ts → effects/toneMappingFolder.d.ts} +1 -1
- package/build/tweakpane/blades/environmentFolder.d.ts +6 -3
- package/build/tweakpane/blades/postProcessingFolder.d.ts +31 -0
- package/build/tweakpane/blades/rendererFolder.d.ts +1 -1
- package/build/tweakpane/blades/rendererStatsFolder.d.ts +0 -2
- package/package.json +16 -11
- package/build/character/CharacterModelLoader.d.ts +0 -11
- package/build/character/CharacterSpeakingIndicator.d.ts +0 -17
- package/build/tweakpane/blades/postExtrasFolder.d.ts +0 -12
@@ -0,0 +1,13 @@
|
|
1
|
+
declare module "../InstancedMesh2" {
|
2
|
+
interface InstancedMesh2 {
|
3
|
+
/**
|
4
|
+
* Resizes internal buffers to accommodate the specified capacity.
|
5
|
+
* This ensures that the buffers are large enough to handle the required number of instances.
|
6
|
+
* @param capacity The new capacity of the buffers.
|
7
|
+
* @returns The current `InstancedMesh2` instance.
|
8
|
+
*/
|
9
|
+
resizeBuffers(capacity: number): this;
|
10
|
+
/** @internal */ setInstancesArrayCount(count: number): void;
|
11
|
+
}
|
12
|
+
}
|
13
|
+
export {};
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { Camera } from "three";
|
2
|
+
import { InstancedRenderItem } from "../utils/InstancedRenderList";
|
3
|
+
import { LODRenderList } from "./LOD";
|
4
|
+
/**
|
5
|
+
* A custom sorting callback for render items.
|
6
|
+
*/
|
7
|
+
export type CustomSortCallback = (list: InstancedRenderItem[]) => void;
|
8
|
+
/**
|
9
|
+
* Callback invoked when an instance is within the frustum.
|
10
|
+
* @param index The index of the instance.
|
11
|
+
* @param camera The camera used for rendering.
|
12
|
+
* @param cameraLOD The camera used for LOD calculations (provided only if LODs are initialized).
|
13
|
+
* @param LODindex The LOD level of the instance (provided only if LODs are initialized and `sortObjects` is false).
|
14
|
+
* @returns True if the instance should be rendered, false otherwise.
|
15
|
+
*/
|
16
|
+
export type OnFrustumEnterCallback = (index: number, camera: Camera, cameraLOD?: Camera, LODindex?: number) => boolean;
|
17
|
+
declare module "../InstancedMesh2" {
|
18
|
+
interface InstancedMesh2 {
|
19
|
+
/**
|
20
|
+
* Performs frustum culling and manages LOD visibility.
|
21
|
+
* @param camera The main camera used for rendering.
|
22
|
+
* @param cameraLOD An optional camera for LOD calculations. Defaults to the main camera.
|
23
|
+
*/
|
24
|
+
performFrustumCulling(camera: Camera, cameraLOD?: Camera): void;
|
25
|
+
/** @internal */ frustumCulling(camera: Camera): void;
|
26
|
+
/** @internal */ updateIndexArray(): void;
|
27
|
+
/** @internal */ updateRenderList(): void;
|
28
|
+
/** @internal */ BVHCulling(camera: Camera): void;
|
29
|
+
/** @internal */ linearCulling(camera: Camera): void;
|
30
|
+
/** @internal */ frustumCullingLOD(LODrenderList: LODRenderList, camera: Camera, cameraLOD: Camera): void;
|
31
|
+
/** @internal */ BVHCullingLOD(LODrenderList: LODRenderList, indexes: Uint32Array[], sortObjects: boolean, camera: Camera, cameraLOD: Camera): void;
|
32
|
+
/** @internal */ linearCullingLOD(LODrenderList: LODRenderList, indexes: Uint32Array[], sortObjects: boolean, camera: Camera, cameraLOD: Camera): void;
|
33
|
+
/** @internal */ getObjectLODIndexForDistance(levels: {
|
34
|
+
distance: number;
|
35
|
+
}[], distance: number): number;
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { InstancedEntity } from "../InstancedEntity";
|
2
|
+
/**
|
3
|
+
* Represents an extended entity type with custom data.
|
4
|
+
*/
|
5
|
+
export type Entity<T> = InstancedEntity & T;
|
6
|
+
/**
|
7
|
+
* A callback function used to update or initialize an entity.
|
8
|
+
*/
|
9
|
+
export type UpdateEntityCallback<T = InstancedEntity> = (obj: Entity<T>, index: number) => void;
|
10
|
+
declare module "../InstancedMesh2" {
|
11
|
+
interface InstancedMesh2<TData = {}> {
|
12
|
+
/**
|
13
|
+
* Updates instances by applying a callback function to each instance. It calls `updateMatrix` for each instance.
|
14
|
+
* @param onUpdate A callback function to update each entity.
|
15
|
+
* @returns The current `InstancedMesh2` instance.
|
16
|
+
*/
|
17
|
+
updateInstances(onUpdate: UpdateEntityCallback<Entity<TData>>): this;
|
18
|
+
/**
|
19
|
+
* Updates instances position by applying a callback function to each instance. It calls `updateMatrixPosition` for each instance.
|
20
|
+
* This method updates only the position attributes of the matrix.
|
21
|
+
* @param onUpdate A callback function to update each entity.
|
22
|
+
* @returns The current `InstancedMesh2` instance.
|
23
|
+
*/
|
24
|
+
updateInstancesPosition(onUpdate: UpdateEntityCallback<Entity<TData>>): this;
|
25
|
+
/**
|
26
|
+
* Adds new instances and optionally initializes them using a callback function.
|
27
|
+
* @param count The number of new instances to add.
|
28
|
+
* @param onCreation An optional callback to initialize each new entity.
|
29
|
+
* @returns The current `InstancedMesh2` instance.
|
30
|
+
*/
|
31
|
+
addInstances(count: number, onCreation?: UpdateEntityCallback<Entity<TData>>): this;
|
32
|
+
/**
|
33
|
+
* Removes instances by their ids.
|
34
|
+
* @param ids The ids of the instances to remove.
|
35
|
+
* @returns The current `InstancedMesh2` instance.
|
36
|
+
*/
|
37
|
+
removeInstances(...ids: number[]): this;
|
38
|
+
/**
|
39
|
+
* Clears all instances and resets the instance count.
|
40
|
+
* @returns The current `InstancedMesh2` instance.
|
41
|
+
*/
|
42
|
+
clearInstances(): this;
|
43
|
+
/** @internal */ clearTempInstance(index: number): InstancedEntity;
|
44
|
+
/** @internal */ clearTempInstancePosition(index: number): InstancedEntity;
|
45
|
+
/** @internal */ clearInstance(instance: InstancedEntity): InstancedEntity;
|
46
|
+
/** @internal */ createEntities(start: number): this;
|
47
|
+
/** @internal */ addInstance(id: number, onCreation?: UpdateEntityCallback): void;
|
48
|
+
}
|
49
|
+
}
|
@@ -0,0 +1,89 @@
|
|
1
|
+
import { BufferGeometry, Material } from "three";
|
2
|
+
import { InstancedMesh2 } from "../InstancedMesh2";
|
3
|
+
/**
|
4
|
+
* Represents information about Level of Detail (LOD).
|
5
|
+
* @template TData Type for additional instance data.
|
6
|
+
*/
|
7
|
+
export interface LODInfo<TData = {}> {
|
8
|
+
/**
|
9
|
+
* Render settings for the LOD.
|
10
|
+
*/
|
11
|
+
render: LODRenderList<TData>;
|
12
|
+
/**
|
13
|
+
* Shadow rendering settings for the LOD.
|
14
|
+
*/
|
15
|
+
shadowRender: LODRenderList<TData>;
|
16
|
+
/**
|
17
|
+
* List of `InstancedMesh2` associated to LODs.
|
18
|
+
*/
|
19
|
+
objects: InstancedMesh2<TData>[];
|
20
|
+
}
|
21
|
+
/**
|
22
|
+
* Represents a list of render levels for LOD.
|
23
|
+
* @template TData Type for additional instance data.
|
24
|
+
*/
|
25
|
+
export interface LODRenderList<TData = {}> {
|
26
|
+
/**
|
27
|
+
* Array of LOD levels.
|
28
|
+
*/
|
29
|
+
levels: LODLevel<TData>[];
|
30
|
+
/**
|
31
|
+
* Array of instance counts per LOD level, used internally.
|
32
|
+
*/
|
33
|
+
count: number[];
|
34
|
+
}
|
35
|
+
/**
|
36
|
+
* Represents a single LOD level.
|
37
|
+
* @template TData Type for additional instance data.
|
38
|
+
*/
|
39
|
+
export interface LODLevel<TData = {}> {
|
40
|
+
/**
|
41
|
+
* The squared distance at which this LOD level becomes active.
|
42
|
+
*/
|
43
|
+
distance: number;
|
44
|
+
/**
|
45
|
+
* Hysteresis value to prevent LOD flickering when transitioning.
|
46
|
+
*/
|
47
|
+
hysteresis: number;
|
48
|
+
/**
|
49
|
+
* The `InstancedMesh2` object associated with this LOD level.
|
50
|
+
*/
|
51
|
+
object: InstancedMesh2<TData>;
|
52
|
+
}
|
53
|
+
declare module "../InstancedMesh2" {
|
54
|
+
interface InstancedMesh2 {
|
55
|
+
/**
|
56
|
+
* Retrieves the index of the LOD level for a given distance.
|
57
|
+
* @param levels The array of LOD levels.
|
58
|
+
* @param distance The squared distance from the camera to the object.
|
59
|
+
* @returns The index of the LOD level that should be used.
|
60
|
+
*/
|
61
|
+
getObjectLODIndexForDistance(levels: LODLevel[], distance: number): number;
|
62
|
+
/**
|
63
|
+
* Sets the first LOD (using current geometry) distance and hysteresis.
|
64
|
+
* @param distance The distance for the first LOD.
|
65
|
+
* @param hysteresis The hysteresis value for the first LOD.
|
66
|
+
* @returns The current `InstancedMesh2` instance.
|
67
|
+
*/
|
68
|
+
setFirstLODDistance(distance?: number, hysteresis?: number): this;
|
69
|
+
/**
|
70
|
+
* Adds a new LOD level with the given geometry, material, and distance.
|
71
|
+
* @param geometry The geometry for the LOD level.
|
72
|
+
* @param material The material for the LOD level.
|
73
|
+
* @param distance The distance for this LOD level.
|
74
|
+
* @param hysteresis The hysteresis value for this LOD level.
|
75
|
+
* @returns The current `InstancedMesh2` instance.
|
76
|
+
*/
|
77
|
+
addLOD(geometry: BufferGeometry, material: Material | Material[], distance?: number, hysteresis?: number): this;
|
78
|
+
/**
|
79
|
+
* Adds a shadow-specific LOD level with the given geometry and distance.
|
80
|
+
* @param geometry The geometry for the shadow LOD.
|
81
|
+
* @param distance The distance for this LOD level.
|
82
|
+
* @param hysteresis The hysteresis value for this LOD level.
|
83
|
+
* @returns The current `InstancedMesh2` instance.
|
84
|
+
*/
|
85
|
+
addShadowLOD(geometry: BufferGeometry, distance?: number, hysteresis?: number): this;
|
86
|
+
/** @internal */ addLevel(renderList: LODRenderList, geometry: BufferGeometry, material: Material | Material[], distance: number, hysteresis: number): InstancedMesh2;
|
87
|
+
/** @internal */ patchLevel(obj: InstancedMesh2): void;
|
88
|
+
}
|
89
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { Mesh } from "three";
|
2
|
+
declare module "../InstancedMesh2" {
|
3
|
+
interface InstancedMesh2 {
|
4
|
+
/**
|
5
|
+
* Gets the morph target data for a specific instance.
|
6
|
+
* @param id The index of the instance.
|
7
|
+
* @param object Optional `Mesh` to store the morph target data.
|
8
|
+
* @returns The mesh object with updated morph target influences.
|
9
|
+
*/
|
10
|
+
getMorphAt(id: number, object?: Mesh): Mesh;
|
11
|
+
/**
|
12
|
+
* Sets the morph target influences for a specific instance.
|
13
|
+
* @param id The index of the instance.
|
14
|
+
* @param object The `Mesh` containing the morph target influences to apply.
|
15
|
+
*/
|
16
|
+
setMorphAt(id: number, object: Mesh): void;
|
17
|
+
}
|
18
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { Intersection, Raycaster } from "three";
|
2
|
+
declare module "../InstancedMesh2" {
|
3
|
+
interface InstancedMesh2 {
|
4
|
+
/** @internal */ raycastInstances(raycaster: Raycaster, result: Intersection[]): void;
|
5
|
+
/** @internal */ checkObjectIntersection(raycaster: Raycaster, objectIndex: number, result: Intersection[]): void;
|
6
|
+
}
|
7
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { Matrix4, Skeleton } from "three";
|
2
|
+
declare module "../InstancedMesh2" {
|
3
|
+
interface InstancedMesh2 {
|
4
|
+
/**
|
5
|
+
* Initialize the skeleton of the instances.
|
6
|
+
* @param skeleton The skeleton to initialize.
|
7
|
+
* @param disableMatrixAutoUpdate Whether to disable the matrix auto update of the bones. Default is `true`.
|
8
|
+
*/
|
9
|
+
initSkeleton(skeleton: Skeleton, disableMatrixAutoUpdate?: boolean): void;
|
10
|
+
/**
|
11
|
+
* Set the bones of the skeleton to the instance at the specified index.
|
12
|
+
* @param id The index of the instance.
|
13
|
+
* @param updateBonesMatrices Whether to update the matrices of the bones. Default is `true`.
|
14
|
+
* @param excludeBonesSet An optional set of bone names to exclude from updates, skipping their local matrix updates.
|
15
|
+
*/
|
16
|
+
setBonesAt(id: number, updateBonesMatrices?: boolean): void;
|
17
|
+
/** internal */ multiplyBoneMatricesAt(instanceIndex: number, boneIndex: number, m1: Matrix4, m2: Matrix4): void;
|
18
|
+
}
|
19
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { ChannelSize, UniformMap, UniformType, UniformValue, UniformValueObj } from "../utils/SquareDataTexture";
|
2
|
+
type UniformSchema = {
|
3
|
+
[x: string]: UniformType;
|
4
|
+
};
|
5
|
+
type UniformSchemaShader = {
|
6
|
+
vertex?: UniformSchema;
|
7
|
+
fragment?: UniformSchema;
|
8
|
+
};
|
9
|
+
type UniformSchemaResult = {
|
10
|
+
channels: ChannelSize;
|
11
|
+
pixelsPerInstance: number;
|
12
|
+
uniformMap: UniformMap;
|
13
|
+
fetchInFragmentShader: boolean;
|
14
|
+
};
|
15
|
+
declare module "../InstancedMesh2" {
|
16
|
+
interface InstancedMesh2 {
|
17
|
+
/**
|
18
|
+
* Retrieves a uniform value for a specific instance.
|
19
|
+
* @param id The index of the instance.
|
20
|
+
* @param name The name of the uniform.
|
21
|
+
* @param target Optional target object to store the uniform value.
|
22
|
+
* @returns The uniform value for the specified instance.
|
23
|
+
*/
|
24
|
+
getUniformAt(id: number, name: string, target?: UniformValueObj): UniformValue;
|
25
|
+
/**
|
26
|
+
* Sets a uniform value for a specific instance.
|
27
|
+
* @param id The index of the instance.
|
28
|
+
* @param name The name of the uniform.
|
29
|
+
* @param value The value to set for the uniform.
|
30
|
+
*/
|
31
|
+
setUniformAt(id: number, name: string, value: UniformValue): void;
|
32
|
+
/**
|
33
|
+
* Initializes per-instance uniforms using a schema.
|
34
|
+
* @param schema The schema defining the uniforms.
|
35
|
+
*/
|
36
|
+
initUniformsPerInstance(schema: UniformSchemaShader): void;
|
37
|
+
/** @internal */ getUniformSchemaResult(schema: UniformSchemaShader): UniformSchemaResult;
|
38
|
+
/** @internal */ getUniformOffset(size: number, tempOffset: number[]): number;
|
39
|
+
/** @internal */ getUniformSize(type: UniformType): number;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
export {};
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { GLBufferAttribute, TypedArray, WebGLRenderer } from "three";
|
2
|
+
/**
|
3
|
+
* A class that extends `GLBufferAttribute` to handle instanced buffer attributes.
|
4
|
+
* This class was specifically created to allow updating instanced buffer attributes during the `onBeforeRender` callback,
|
5
|
+
* providing an efficient way to modify the buffer data dynamically before rendering.
|
6
|
+
*/
|
7
|
+
export declare class GLInstancedBufferAttribute extends GLBufferAttribute {
|
8
|
+
/**
|
9
|
+
* Indicates if this is an `isGLInstancedBufferAttribute`.
|
10
|
+
*/
|
11
|
+
isGLInstancedBufferAttribute: boolean;
|
12
|
+
/**
|
13
|
+
* The number of meshes that share the same attribute data.
|
14
|
+
*/
|
15
|
+
meshPerAttribute: number;
|
16
|
+
/**
|
17
|
+
* The data array that holds the attribute values.
|
18
|
+
*/
|
19
|
+
array: TypedArray;
|
20
|
+
protected _cacheArray: TypedArray;
|
21
|
+
/** @internal */ _needsUpdate: boolean;
|
22
|
+
/** @internal */ isInstancedBufferAttribute: boolean;
|
23
|
+
/**
|
24
|
+
* @param gl The WebGL2RenderingContext used to create the buffer.
|
25
|
+
* @param type The type of data in the attribute.
|
26
|
+
* @param itemSize The number of elements per attribute.
|
27
|
+
* @param elementSize The size of individual elements in the array.
|
28
|
+
* @param array The data array that holds the attribute values.
|
29
|
+
* @param meshPerAttribute The number of meshes that share the same attribute data.
|
30
|
+
*/
|
31
|
+
constructor(gl: WebGL2RenderingContext, type: GLenum, itemSize: number, elementSize: 1 | 2 | 4, array: TypedArray, meshPerAttribute?: number);
|
32
|
+
/**
|
33
|
+
* Updates the buffer data.
|
34
|
+
* This method is designed to be called during the `onBeforeRender` callback.
|
35
|
+
* It ensures that the attribute data is updated just before the rendering process begins.
|
36
|
+
* @param renderer The WebGLRenderer used to render the scene.
|
37
|
+
* @param count The number of elements to update in the buffer.
|
38
|
+
*/
|
39
|
+
update(renderer: WebGLRenderer, count: number): void;
|
40
|
+
/** @internal */
|
41
|
+
clone(): this;
|
42
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
export type InstancedRenderItem = {
|
2
|
+
index: number;
|
3
|
+
depth: number;
|
4
|
+
depthSort: number;
|
5
|
+
};
|
6
|
+
/**
|
7
|
+
* A class that creates and manages a list of render items, used to determine the rendering order based on depth.
|
8
|
+
*/
|
9
|
+
export declare class InstancedRenderList {
|
10
|
+
/**
|
11
|
+
* The main array that holds the list of render items for instanced rendering.
|
12
|
+
*/
|
13
|
+
array: InstancedRenderItem[];
|
14
|
+
protected pool: InstancedRenderItem[];
|
15
|
+
/**
|
16
|
+
* Adds a new render item to the list.
|
17
|
+
* @param depth The depth value used for sorting or determining the rendering order.
|
18
|
+
* @param index The unique instance id of the render item.
|
19
|
+
*/
|
20
|
+
push(depth: number, index: number): void;
|
21
|
+
/**
|
22
|
+
* Resets the render list by clearing the array.
|
23
|
+
*/
|
24
|
+
reset(): void;
|
25
|
+
}
|
@@ -0,0 +1,156 @@
|
|
1
|
+
import { Color, DataTexture, Matrix3, Matrix4, PixelFormat, TextureDataType, TypedArray, Vector2, Vector3, Vector4, WebGLRenderer, WebGLUtils } from "three";
|
2
|
+
/**
|
3
|
+
* Represents the number of elements per pixel.
|
4
|
+
*/
|
5
|
+
export type ChannelSize = 1 | 2 | 3 | 4;
|
6
|
+
/**
|
7
|
+
* A constructor signature for creating TypedArray.
|
8
|
+
*/
|
9
|
+
export type TypedArrayConstructor = new (count: number) => TypedArray;
|
10
|
+
/**
|
11
|
+
* Represents the texture information including its data, size, format, and data type.
|
12
|
+
*/
|
13
|
+
export type TextureInfo = {
|
14
|
+
array: TypedArray;
|
15
|
+
size: number;
|
16
|
+
format: PixelFormat;
|
17
|
+
type: TextureDataType;
|
18
|
+
};
|
19
|
+
/**
|
20
|
+
* Represents information for updating rows in the texture, including the row index and number of rows.
|
21
|
+
*/
|
22
|
+
export type UpdateRowInfo = {
|
23
|
+
row: number;
|
24
|
+
count: number;
|
25
|
+
};
|
26
|
+
/**
|
27
|
+
* Defines the possible types of uniforms that can be used in shaders.
|
28
|
+
*/
|
29
|
+
export type UniformType = "float" | "vec2" | "vec3" | "vec4" | "mat3" | "mat4";
|
30
|
+
/**
|
31
|
+
* Represents a value that can be used as a uniform.
|
32
|
+
*/
|
33
|
+
export type UniformValueObj = Vector2 | Vector3 | Vector4 | Matrix3 | Matrix4 | Color;
|
34
|
+
/**
|
35
|
+
* Defines a uniform value as either a number or a compatible Three.js object.
|
36
|
+
*/
|
37
|
+
export type UniformValue = number | UniformValueObj;
|
38
|
+
/**
|
39
|
+
* Represents the schema for a uniform, defining its offset, size, and type.
|
40
|
+
*/
|
41
|
+
export type UniformMapType = {
|
42
|
+
offset: number;
|
43
|
+
size: number;
|
44
|
+
type: UniformType;
|
45
|
+
};
|
46
|
+
/**
|
47
|
+
* Represents a map of uniform names to their schema definitions.
|
48
|
+
*/
|
49
|
+
export type UniformMap = Map<string, UniformMapType>;
|
50
|
+
/**
|
51
|
+
* Calculates the square texture size based on the capacity and pixels per instance.
|
52
|
+
* This ensures the texture is large enough to store all instances in a square layout.
|
53
|
+
* @param capacity The maximum number of instances allowed in the texture.
|
54
|
+
* @param pixelsPerInstance The number of pixels required for each instance.
|
55
|
+
* @returns The size of the square texture needed to store all the instances.
|
56
|
+
*/
|
57
|
+
export declare function getSquareTextureSize(capacity: number, pixelsPerInstance: number): number;
|
58
|
+
/**
|
59
|
+
* Generates texture information (size, format, type) for a square texture based on the provided parameters.
|
60
|
+
* @param arrayType The constructor for the TypedArray.
|
61
|
+
* @param channels The number of channels in the texture.
|
62
|
+
* @param pixelsPerInstance The number of pixels required for each instance.
|
63
|
+
* @param capacity The maximum number of instances allowed in the texture.
|
64
|
+
* @returns An object containing the texture's array, size, format, and data type.
|
65
|
+
*/
|
66
|
+
export declare function getSquareTextureInfo(arrayType: TypedArrayConstructor, channels: ChannelSize, pixelsPerInstance: number, capacity: number): TextureInfo;
|
67
|
+
/**
|
68
|
+
* A class that extends `DataTexture` to manage a square texture optimized for instances rendering.
|
69
|
+
* It supports dynamic resizing, partial update based on rows, and allows setting/getting uniforms per instance.
|
70
|
+
*/
|
71
|
+
export declare class SquareDataTexture extends DataTexture {
|
72
|
+
/**
|
73
|
+
* Whether to enable partial texture updates by row. If `false`, the entire texture will be updated.
|
74
|
+
* @default true.
|
75
|
+
*/
|
76
|
+
partialUpdate: boolean;
|
77
|
+
/**
|
78
|
+
* The maximum number of update calls per frame.
|
79
|
+
* @default Infinity
|
80
|
+
*/
|
81
|
+
maxUpdateCalls: number;
|
82
|
+
/** @internal */ _data: TypedArray;
|
83
|
+
protected _channels: ChannelSize;
|
84
|
+
protected _pixelsPerInstance: number;
|
85
|
+
protected _stride: number;
|
86
|
+
protected _rowToUpdate: boolean[];
|
87
|
+
protected _uniformMap?: UniformMap;
|
88
|
+
protected _fetchUniformsInFragmentShader?: boolean;
|
89
|
+
protected _utils?: WebGLUtils;
|
90
|
+
protected _lastWidth?: number;
|
91
|
+
/**
|
92
|
+
* @param arrayType The constructor for the TypedArray.
|
93
|
+
* @param channels The number of channels in the texture.
|
94
|
+
* @param pixelsPerInstance The number of pixels required for each instance.
|
95
|
+
* @param capacity The total number of instances.
|
96
|
+
* @param uniformMap Optional map for handling uniform values.
|
97
|
+
* @param fetchInFragmentShader Optional flag that determines if uniform values should be fetched in the fragment shader instead of the vertex shader.
|
98
|
+
*/
|
99
|
+
constructor(arrayType: TypedArrayConstructor, channels: ChannelSize, pixelsPerInstance: number, capacity: number, uniformMap?: UniformMap, fetchInFragmentShader?: boolean);
|
100
|
+
/**
|
101
|
+
* Resizes the texture to accommodate a new number of instances.
|
102
|
+
* @param count The new total number of instances.
|
103
|
+
*/
|
104
|
+
resize(count: number): void;
|
105
|
+
/**
|
106
|
+
* Marks a row of the texture for update during the next render cycle.
|
107
|
+
* This helps in optimizing texture updates by only modifying the rows that have changed.
|
108
|
+
* @param index The index of the instance to update.
|
109
|
+
*/
|
110
|
+
enqueueUpdate(index: number): void;
|
111
|
+
/**
|
112
|
+
* Updates the texture data based on the rows that need updating.
|
113
|
+
* This method is optimized to only update the rows that have changed, improving performance.
|
114
|
+
* @param renderer The WebGLRenderer used for rendering.
|
115
|
+
*/
|
116
|
+
update(renderer: WebGLRenderer): void;
|
117
|
+
protected getUpdateRowsInfo(): UpdateRowInfo[];
|
118
|
+
protected updateRows(textureProperties: any, renderer: WebGLRenderer, info: UpdateRowInfo[]): void;
|
119
|
+
/**
|
120
|
+
* Sets a uniform value at the specified instance ID in the texture.
|
121
|
+
* @param id The instance ID to set the uniform for.
|
122
|
+
* @param name The name of the uniform.
|
123
|
+
* @param value The value to set for the uniform.
|
124
|
+
*/
|
125
|
+
setUniformAt(id: number, name: string, value: UniformValue): void;
|
126
|
+
/**
|
127
|
+
* Retrieves a uniform value at the specified instance ID from the texture.
|
128
|
+
* @param id The instance ID to retrieve the uniform from.
|
129
|
+
* @param name The name of the uniform.
|
130
|
+
* @param target Optional target object to store the uniform value.
|
131
|
+
* @returns The uniform value for the specified instance.
|
132
|
+
*/
|
133
|
+
getUniformAt(id: number, name: string, target?: UniformValueObj): UniformValue;
|
134
|
+
/**
|
135
|
+
* Generates the GLSL code for accessing the uniform data stored in the texture.
|
136
|
+
* @param textureName The name of the texture in the GLSL shader.
|
137
|
+
* @param indexName The name of the index in the GLSL shader.
|
138
|
+
* @param indexType The type of the index in the GLSL shader.
|
139
|
+
* @returns An object containing the GLSL code for the vertex and fragment shaders.
|
140
|
+
*/
|
141
|
+
getUniformsGLSL(textureName: string, indexName: string, indexType: string): {
|
142
|
+
vertex: string;
|
143
|
+
fragment: string;
|
144
|
+
};
|
145
|
+
protected getUniformsVertexGLSL(textureName: string, indexName: string, indexType: string): string;
|
146
|
+
protected getUniformsFragmentGLSL(textureName: string, indexName: string, indexType: string): string;
|
147
|
+
protected texelsFetchGLSL(textureName: string, indexName: string): string;
|
148
|
+
protected getFromTexelsGLSL(): string;
|
149
|
+
protected getVarying(): {
|
150
|
+
declareVarying: string;
|
151
|
+
assignVarying: string;
|
152
|
+
getVarying: string;
|
153
|
+
};
|
154
|
+
protected getUniformComponents(offset: number, size: number): string;
|
155
|
+
copy(source: SquareDataTexture): this;
|
156
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
export * from "./core/InstancedEntity";
|
2
|
+
export * from "./core/InstancedMesh2";
|
3
|
+
export * from "./core/InstancedMeshBVH";
|
4
|
+
import "./core/feature/Capacity";
|
5
|
+
import "./core/feature/FrustumCulling";
|
6
|
+
import "./core/feature/LOD";
|
7
|
+
import "./core/feature/Morph";
|
8
|
+
import "./core/feature/Raycasting";
|
9
|
+
import "./core/feature/Skeleton";
|
10
|
+
import "./core/feature/Uniforms";
|
11
|
+
export type { Entity, UpdateEntityCallback } from "./core/feature/Instances";
|
12
|
+
import "./core/feature/Instances";
|
13
|
+
export * from "./core/utils/GLInstancedBufferAttribute";
|
14
|
+
export * from "./core/utils/InstancedRenderList";
|
15
|
+
export * from "./core/utils/SquareDataTexture";
|
16
|
+
export * from "./shaders/ShaderChunk";
|
17
|
+
export * from "./shaders/chunks/instanced_pars_vertex";
|
18
|
+
export * from "./shaders/chunks/instanced_color_pars_vertex";
|
19
|
+
export * from "./shaders/chunks/instanced_color_vertex";
|
20
|
+
export * from "./shaders/chunks/instanced_material_color_pars_vertex";
|
21
|
+
export * from "./shaders/chunks/instanced_material_color_vertex";
|
22
|
+
export * from "./shaders/chunks/instanced_vertex";
|
23
|
+
export * from "./shaders/chunks/instanced_skinning_pars_vertex";
|
24
|
+
export * from "./utils/SortingUtils";
|
25
|
+
export * from "./utils/CreateFrom";
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function patchShader(shader: string): string;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const instanced_color_pars_vertex = "\n\n#ifdef USE_INSTANCING_COLOR_INDIRECT\n uniform highp sampler2D colorsTexture;\n\n #ifdef USE_COLOR_ALPHA\n vec4 getColorTexture() {\n int size = textureSize( colorsTexture, 0 ).x;\n int j = int( instanceIndex );\n int x = j % size;\n int y = j / size;\n return texelFetch( colorsTexture, ivec2( x, y ), 0 );\n }\n #else\n vec3 getColorTexture() {\n int size = textureSize( colorsTexture, 0 ).x;\n int j = int( instanceIndex );\n int x = j % size;\n int y = j / size;\n return texelFetch( colorsTexture, ivec2( x, y ), 0 ).rgb;\n }\n #endif\n#endif\n";
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const instanced_color_vertex = "\n#ifdef USE_INSTANCING_COLOR_INDIRECT\n #ifdef USE_VERTEX_COLOR\n vColor = color;\n #else\n #ifdef USE_COLOR_ALPHA\n vColor = vec4( 1.0 );\n #else\n vColor = vec3( 1.0 );\n #endif\n #endif\n#endif\n";
|
package/build/character/instancing/vendor/shaders/chunks/instanced_material_color_pars_vertex.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export declare const instanced_material_color_pars_vertex = "\n#ifdef USE_INSTANCING_MATERIAL_COLORS\n uniform highp sampler2D materialColorsTexture;\n\n // material indices for the LUT\n #define MATERIAL_HAIR 0\n #define MATERIAL_SHIRT_SHORT 1\n #define MATERIAL_SHIRT_LONG 2\n #define MATERIAL_PANTS_SHORT 3\n #define MATERIAL_PANTS_LONG 4\n #define MATERIAL_SHOES 5\n #define MATERIAL_SKIN 6\n #define MATERIAL_LIPS 7\n\n vec3 getMaterialColorTexture(int materialIndex) {\n int size = textureSize(materialColorsTexture, 0).x;\n int instanceId = int(instanceIndex);\n int colorIndex = instanceId * 8 + materialIndex;\n int x = colorIndex % size;\n int y = colorIndex / size;\n return texelFetch(materialColorsTexture, ivec2(x, y), 0).rgb;\n }\n#endif\n";
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const instanced_material_color_vertex = "\n#ifdef USE_INSTANCING_MATERIAL_COLORS\n #ifdef USE_VERTEX_COLOR\n vec3 vertexColor = color;\n vec3 instanceColor = vec3(1.0);\n \n if (vertexColor.r == 0.0 && vertexColor.g == 0.0 && vertexColor.b == 0.0) {\n // Hair material (0, 0, 0)\n instanceColor = getMaterialColorTexture(MATERIAL_HAIR);\n } else if (vertexColor.r == 0.0 && vertexColor.g == 0.0 && vertexColor.b == 1.0) {\n // Shirt short material (0, 0, 1)\n instanceColor = getMaterialColorTexture(MATERIAL_SHIRT_SHORT);\n } else if (vertexColor.r == 0.0 && vertexColor.g == 1.0 && vertexColor.b == 0.0) {\n // Shirt long material (0, 1, 0)\n instanceColor = getMaterialColorTexture(MATERIAL_SHIRT_LONG);\n } else if (vertexColor.r == 0.0 && vertexColor.g == 1.0 && vertexColor.b == 1.0) {\n // Pants short material (0, 1, 1)\n instanceColor = getMaterialColorTexture(MATERIAL_PANTS_SHORT);\n } else if (vertexColor.r == 1.0 && vertexColor.g == 0.0 && vertexColor.b == 0.0) {\n // Pants long material (1, 0, 0)\n instanceColor = getMaterialColorTexture(MATERIAL_PANTS_LONG);\n } else if (vertexColor.r == 1.0 && vertexColor.g == 0.0 && vertexColor.b == 1.0) {\n // Shoes material (1, 0, 1)\n instanceColor = getMaterialColorTexture(MATERIAL_SHOES);\n } else if (vertexColor.r == 1.0 && vertexColor.g == 1.0 && vertexColor.b == 0.0) {\n // Skin material (1, 1, 0)\n instanceColor = getMaterialColorTexture(MATERIAL_SKIN);\n } else if (vertexColor.r == 1.0 && vertexColor.g == 1.0 && vertexColor.b == 1.0) {\n // Lips material (1, 1, 1)\n instanceColor = getMaterialColorTexture(MATERIAL_LIPS);\n } else if (vertexColor.r == 0.5 && vertexColor.g == 0.0 && vertexColor.b == 0.0) {\n // Eyes black material (0.5, 0, 0)\n instanceColor = getMaterialColorTexture(MATERIAL_SKIN); // Using skin index for now\n } else if (vertexColor.r == 0.0 && vertexColor.g == 0.5 && vertexColor.b == 0.0) {\n // Eyes white material (0, 0.5, 0)\n instanceColor = getMaterialColorTexture(MATERIAL_SKIN); // Using skin index for now\n }\n \n vColor = instanceColor;\n #else\n vColor = vec3(1.0);\n #endif\n#endif\n";
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const instanced_pars_vertex = "\n#ifdef USE_INSTANCING_INDIRECT\n attribute uint instanceIndex;\n uniform highp sampler2D matricesTexture; \n\n mat4 getInstancedMatrix() {\n int size = textureSize( matricesTexture, 0 ).x;\n int j = int( instanceIndex ) * 4;\n int x = j % size;\n int y = j / size;\n vec4 v1 = texelFetch( matricesTexture, ivec2( x, y ), 0 );\n vec4 v2 = texelFetch( matricesTexture, ivec2( x + 1, y ), 0 );\n vec4 v3 = texelFetch( matricesTexture, ivec2( x + 2, y ), 0 );\n vec4 v4 = texelFetch( matricesTexture, ivec2( x + 3, y ), 0 );\n return mat4( v1, v2, v3, v4 );\n }\n#endif\n";
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const instanced_skinning_pars_vertex = "\n#ifdef USE_SKINNING\n uniform mat4 bindMatrix;\n uniform mat4 bindMatrixInverse;\n uniform highp sampler2D boneTexture;\n\n #ifdef USE_INSTANCING_SKINNING\n uniform int bonesPerInstance;\n #endif\n\n mat4 getBoneMatrix( const in float i ) {\n int size = textureSize( boneTexture, 0 ).x;\n\n #ifdef USE_INSTANCING_SKINNING\n int j = ( bonesPerInstance * int( instanceIndex ) + int( i ) ) * 4;\n #else\n int j = int( i ) * 4;\n #endif\n\n int x = j % size;\n int y = j / size;\n vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );\n vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );\n vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );\n vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );\n return mat4( v1, v2, v3, v4 );\n }\n#endif\n";
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const instanced_vertex = "\n#ifdef USE_INSTANCING_INDIRECT\n mat4 instanceMatrix = getInstancedMatrix();\n\n #ifdef USE_INSTANCING_COLOR_INDIRECT\n vColor *= getColorTexture();\n #endif\n#endif\n";
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { Mesh } from "three";
|
2
|
+
import { InstancedMesh2, InstancedMesh2Params } from "../core/InstancedMesh2";
|
3
|
+
/**
|
4
|
+
* Create an `InstancedMesh2` instance from an existing `Mesh` or `InstancedMesh`.
|
5
|
+
* @param mesh The `Mesh` or `InstancedMesh` to create an `InstanceMesh2` from.
|
6
|
+
* @param params Optional configuration parameters object. See `InstancedMesh2Params` for details.
|
7
|
+
* @returns The created `InstancedMesh2` instance.
|
8
|
+
*/
|
9
|
+
export declare function createInstancedMesh2From<TData = object>(mesh: Mesh, params?: InstancedMesh2Params): InstancedMesh2<TData>;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { InstancedMesh2 } from "../core/InstancedMesh2";
|
2
|
+
import { InstancedRenderItem } from "../core/utils/InstancedRenderList";
|
3
|
+
type radixSortCallback = (list: InstancedRenderItem[]) => void;
|
4
|
+
/**
|
5
|
+
* Creates a radix sort function specifically for sorting `InstancedMesh2` instances.
|
6
|
+
* The sorting is based on the `depth` property of each `InstancedRenderItem`.
|
7
|
+
* This function dynamically adjusts for transparent materials by reversing the sort order if necessary.
|
8
|
+
* @param target The `InstancedMesh2` instance that contains the instances to be sorted.
|
9
|
+
* @returns A radix sort function.
|
10
|
+
*/
|
11
|
+
export declare function createRadixSort(target: InstancedMesh2): radixSortCallback;
|
12
|
+
/** @internal */
|
13
|
+
export declare function sortOpaque(a: InstancedRenderItem, b: InstancedRenderItem): number;
|
14
|
+
/** @internal */
|
15
|
+
export declare function sortTransparent(a: InstancedRenderItem, b: InstancedRenderItem): number;
|
16
|
+
export {};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { AnimationClip, Object3D } from "three";
|
2
|
+
export declare class CharacterModelLoader {
|
3
|
+
private debug;
|
4
|
+
private readonly modelLoader;
|
5
|
+
private workerPool;
|
6
|
+
constructor(debug?: boolean);
|
7
|
+
loadModel(fileUrl: string, maxTextureSize: number, abortController?: AbortController): Promise<Object3D | null>;
|
8
|
+
loadAnimation(fileUrl: string, abortController?: AbortController): Promise<AnimationClip | null>;
|
9
|
+
private processGLTFInWorker;
|
10
|
+
private loadFromBuffer;
|
11
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
export declare class GLTFLoadingWorkerBrowserCache {
|
2
|
+
private readonly cacheName;
|
3
|
+
private cache;
|
4
|
+
init(): Promise<void>;
|
5
|
+
private generateCacheKey;
|
6
|
+
get(fileUrl: string, maxTextureSize: number): Promise<ArrayBuffer | null>;
|
7
|
+
set(fileUrl: string, maxTextureSize: number, data: ArrayBuffer): Promise<void>;
|
8
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/**
|
2
|
+
* GLTFLoadingWorkerPool - gLTF loading and texture processing using Web Workers
|
3
|
+
*
|
4
|
+
* Features:
|
5
|
+
* - Loads gLTF files entirely in workers (off main thread)
|
6
|
+
* - Uses gltf-transform for gLTF manipulation
|
7
|
+
* - Processes and resizes textures in the worker
|
8
|
+
* - Caches processed gLTF files
|
9
|
+
*/
|
10
|
+
export declare class GLTFLoadingWorkerPool {
|
11
|
+
private workers;
|
12
|
+
private activeJobs;
|
13
|
+
private workerIndex;
|
14
|
+
private readonly maxWorkers;
|
15
|
+
constructor();
|
16
|
+
private handleWorkerMessage;
|
17
|
+
private handleWorkerError;
|
18
|
+
private getNextWorker;
|
19
|
+
processGLTF(fileUrl: string, maxTextureSize: number, abortController?: AbortController): Promise<ArrayBuffer>;
|
20
|
+
dispose(): void;
|
21
|
+
}
|
22
|
+
export declare const TextureWorkerPool: typeof GLTFLoadingWorkerPool;
|