{"version":3,"file":"index.cjs","sources":["../../src/core/InstancedEntity.ts","../../src/core/InstancedMeshBVH.ts","../../src/core/utils/GLInstancedBufferAttribute.ts","../../src/core/utils/PropertiesOverride.ts","../../src/core/utils/SquareDataTexture.ts","../../src/core/InstancedMesh2.ts","../../src/core/feature/Capacity.ts","../../src/utils/SortingUtils.ts","../../src/core/utils/InstancedRenderList.ts","../../src/core/feature/FrustumCulling.ts","../../src/core/feature/Instances.ts","../../src/core/feature/LOD.ts","../../src/core/feature/Morph.ts","../../src/core/feature/Raycasting.ts","../../src/core/feature/Skeleton.ts","../../src/core/feature/Uniforms.ts","../../src/shaders/chunks/instanced_pars_vertex.glsl","../../src/shaders/chunks/instanced_color_pars_vertex.glsl","../../src/shaders/chunks/instanced_vertex.glsl","../../src/shaders/chunks/instanced_color_vertex.glsl","../../src/shaders/chunks/instanced_skinning_pars_vertex.glsl","../../src/shaders/ShaderChunk.ts","../../src/utils/CreateFrom.ts"],"sourcesContent":["import { Color, ColorRepresentation, Euler, Matrix4, Mesh, Object3D, Quaternion, Vector3 } from 'three';\r\nimport { InstancedMesh2 } from './InstancedMesh2.js';\r\nimport { UniformValue, UniformValueObj } from './utils/SquareDataTexture.js';\r\n\r\n// TODO add other object3D methods\r\n// TODO implement parent\r\n\r\n/**\r\n * Represents an instance in an `InstancedMesh2`.\r\n * This class stores transformation data (position, rotation, scale) and provides methods to manipulate them.\r\n */\r\nexport class InstancedEntity {\r\n  /**\r\n   * Indicates if this is an `InstancedEntity`.\r\n   */\r\n  public readonly isInstanceEntity = true;\r\n  /**\r\n   * The unique identifier for this instance (relative to the `InstancedMesh2` it references).\r\n   */\r\n  public readonly id: number;\r\n  /**\r\n   * `InstancedMesh2` to which this instance refers.\r\n   */\r\n  public readonly owner: InstancedMesh2;\r\n  /**\r\n   * The local position.\r\n   */\r\n  public position = new Vector3();\r\n  /**\r\n   * The local scale.\r\n   */\r\n  public scale = new Vector3(1, 1, 1);\r\n  /**\r\n   * The local rotation as `Quaternion`.\r\n   */\r\n  public quaternion = new Quaternion();\r\n  /**\r\n   * The local rotation as `Euler`.\r\n   * This works only if `allowsEuler` is set to `true` in the `InstancedMesh2` constructor parameters.\r\n   */\r\n  public rotation: Euler;\r\n\r\n  /**\r\n   * The visibility state set and got from `owner.availabilityArray`.\r\n   */\r\n  public get visible(): boolean { return this.owner.getVisibilityAt(this.id); }\r\n  public set visible(value: boolean) { this.owner.setVisibilityAt(this.id, value); }\r\n\r\n  /**\r\n   * The availability set and got from `owner.availabilityArray`.\r\n   */\r\n  public get active(): boolean { return this.owner.getActiveAt(this.id); }\r\n  public set active(value: boolean) { this.owner.setActiveAt(this.id, value); }\r\n\r\n  /**\r\n   * Color set and got from `owner.colorsTexture`.\r\n   */\r\n  public get color(): Color { return this.owner.getColorAt(this.id); }\r\n  public set color(value: ColorRepresentation) { this.owner.setColorAt(this.id, value); }\r\n\r\n  /**\r\n   * Opacity set and got from `owner.colorsTexture`.\r\n   */\r\n  public get opacity(): number { return this.owner.getOpacityAt(this.id); }\r\n  public set opacity(value: number) { this.owner.setOpacityAt(this.id, value); }\r\n\r\n  /**\r\n   * Morph target influences set and got from `owner.morphTexture`.\r\n   */\r\n  public get morph(): Mesh { return this.owner.getMorphAt(this.id); }\r\n  public set morph(value: Mesh) { this.owner.setMorphAt(this.id, value); }\r\n\r\n  /**\r\n   * The local transform matrix got from `owner.matricesTexture`.\r\n   */\r\n  public get matrix(): Matrix4 { return this.owner.getMatrixAt(this.id); }\r\n\r\n  /**\r\n   * The world transform matrix got by multiplying the matrix got from `owner.matricesTexture` and `this.owner.matrixWorld`.\r\n   */\r\n  public get matrixWorld(): Matrix4 { return this.matrix.premultiply(this.owner.matrixWorld); }\r\n\r\n  /**\r\n   * This object is instantiated automatically by setting `createEntities` to `true` in the `InstancedMesh2` constructor parameters.\r\n   * Dont instantiate this manually.\r\n   * @param owner The `InstancedMesh2` that owns this instance.\r\n   * @param id The unique identifier for this instance within the `InstancedMesh2`.\r\n   * @param useEuler Whether to use Euler rotations in addition to quaternion rotations.\r\n   */\r\n  constructor(owner: InstancedMesh2, id: number, useEuler: boolean) {\r\n    this.id = id;\r\n    this.owner = owner;\r\n\r\n    if (useEuler) {\r\n      const quaternion = this.quaternion;\r\n      const rotation = this.rotation = new Euler();\r\n\r\n      rotation._onChange(() => quaternion.setFromEuler(rotation, false));\r\n      quaternion._onChange(() => rotation.setFromQuaternion(quaternion, undefined, false));\r\n    }\r\n  }\r\n\r\n  /**\r\n   * @internal\r\n   */\r\n  public setMatrixIdentity(): void {\r\n    const owner = this.owner;\r\n    const te = owner.matricesTexture._data;\r\n    const id = this.id;\r\n    const offset = id * 16;\r\n\r\n    te[offset + 0] = 1;\r\n    te[offset + 1] = 0;\r\n    te[offset + 2] = 0;\r\n    te[offset + 3] = 0;\r\n\r\n    te[offset + 4] = 0;\r\n    te[offset + 5] = 1;\r\n    te[offset + 6] = 0;\r\n    te[offset + 7] = 0;\r\n\r\n    te[offset + 8] = 0;\r\n    te[offset + 9] = 0;\r\n    te[offset + 10] = 1;\r\n    te[offset + 11] = 0;\r\n\r\n    te[offset + 12] = 0;\r\n    te[offset + 13] = 0;\r\n    te[offset + 14] = 0;\r\n    te[offset + 15] = 1;\r\n\r\n    owner.matricesTexture.enqueueUpdate(id);\r\n  }\r\n\r\n  /**\r\n   * Updates the transformation matrix with its current position, quaternion, and scale.\r\n   * The updated matrix is stored in the `owner.matricesTexture`.\r\n   */\r\n  public updateMatrix(): void {\r\n    const owner = this.owner;\r\n    const position = this.position;\r\n    const quaternion = this.quaternion as any;\r\n    const scale = this.scale;\r\n    const te = owner.matricesTexture._data;\r\n    const id = this.id;\r\n    const offset = id * 16;\r\n\r\n    const x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;\r\n    const x2 = x + x, y2 = y + y, z2 = z + z;\r\n    const xx = x * x2, xy = x * y2, xz = x * z2;\r\n    const yy = y * y2, yz = y * z2, zz = z * z2;\r\n    const wx = w * x2, wy = w * y2, wz = w * z2;\r\n\r\n    const sx = scale.x, sy = scale.y, sz = scale.z;\r\n\r\n    te[offset + 0] = (1 - (yy + zz)) * sx;\r\n    te[offset + 1] = (xy + wz) * sx;\r\n    te[offset + 2] = (xz - wy) * sx;\r\n    te[offset + 3] = 0;\r\n\r\n    te[offset + 4] = (xy - wz) * sy;\r\n    te[offset + 5] = (1 - (xx + zz)) * sy;\r\n    te[offset + 6] = (yz + wx) * sy;\r\n    te[offset + 7] = 0;\r\n\r\n    te[offset + 8] = (xz + wy) * sz;\r\n    te[offset + 9] = (yz - wx) * sz;\r\n    te[offset + 10] = (1 - (xx + yy)) * sz;\r\n    te[offset + 11] = 0;\r\n\r\n    te[offset + 12] = position.x;\r\n    te[offset + 13] = position.y;\r\n    te[offset + 14] = position.z;\r\n    te[offset + 15] = 1;\r\n\r\n    owner.matricesTexture.enqueueUpdate(id);\r\n\r\n    if (owner.bvh && owner.autoUpdateBVH) {\r\n      owner.bvh.move(id);\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Updates only the position component of the transformation matrix.\r\n   * This is useful if only position changes, avoiding recalculating the full matrix.\r\n   * The updated matrix is stored in the `owner.matricesTexture`.\r\n   */\r\n  public updateMatrixPosition(): void {\r\n    const owner = this.owner;\r\n    const position = this.position;\r\n    const te = owner.matricesTexture._data;\r\n    const id = this.id;\r\n    const offset = id * 16;\r\n\r\n    te[offset + 12] = position.x;\r\n    te[offset + 13] = position.y;\r\n    te[offset + 14] = position.z;\r\n\r\n    owner.matricesTexture.enqueueUpdate(id);\r\n\r\n    if (owner.bvh && owner.autoUpdateBVH) {\r\n      owner.bvh.move(id);\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Retrieves the uniform value associated with the given name.\r\n   * @param name The name of the uniform to retrieve.\r\n   * @param target Optional target object where the uniform value will be written.\r\n   * @returns The retrieved uniform value.\r\n   */\r\n  public getUniform(name: string, target?: UniformValueObj): UniformValue {\r\n    return this.owner.getUniformAt(this.id, name, target);\r\n  }\r\n\r\n  /**\r\n   * Updates the bones of the skeleton to the instance.\r\n   * @param updateBonesMatrices Whether to update the matrices of the bones. Default is `true`.\r\n   * @param excludeBonesSet An optional set of bone names to exclude from updates, skipping their local matrix updates.\r\n  */\r\n  public updateBones(updateBonesMatrices = true, excludeBonesSet?: Set<string>): void {\r\n    this.owner.setBonesAt(this.id, updateBonesMatrices, excludeBonesSet);\r\n  }\r\n\r\n  /**\r\n   * Sets the uniform value for the given name\r\n   * @param name The name of the uniform to set.\r\n   * @param value The new value for the uniform.\r\n   */\r\n  public setUniform(name: string, value: UniformValue): void {\r\n    this.owner.setUniformAt(this.id, name, value);\r\n  }\r\n\r\n  /**\r\n   * Copies the transformation properties (`position`, `scale`, `quaternion`) of this instance to the specified `Object3D`.\r\n   * @param target The `Object3D` where the transformation properties will be copied.\r\n   */\r\n  public copyTo(target: Object3D): void {\r\n    target.position.copy(this.position);\r\n    target.scale.copy(this.scale);\r\n    target.quaternion.copy(this.quaternion);\r\n    if (this.rotation) target.rotation.copy(this.rotation); // TODO check if this is necessary.. it's probably already synched\r\n  }\r\n\r\n  /**\r\n   * Applies the matrix transform to the object and updates the object's position, rotation and scale.\r\n   * @param m The matrix to apply.\r\n   * @returns The instance of the object.\r\n   */\r\n  public applyMatrix4(m: Matrix4): this {\r\n    this.matrix.premultiply(m).decompose(this.position, this.quaternion, this.scale);\r\n    return this;\r\n  }\r\n\r\n  /**\r\n   * Applies the rotation represented by the quaternion to the object.\r\n   * @param q The quaternion representing the rotation to apply.\r\n   * @returns The instance of the object.\r\n   */\r\n  public applyQuaternion(q: Quaternion): this {\r\n    this.quaternion.premultiply(q);\r\n    return this;\r\n  }\r\n\r\n  /**\r\n   * Rotate an object along an axis in object space. The axis is assumed to be normalized.\r\n   * @param axis A normalized vector in object space.\r\n   * @param angle The angle in radians.\r\n   * @returns The instance of the object.\r\n   */\r\n  public rotateOnAxis(axis: Vector3, angle: number): this {\r\n    _quat.setFromAxisAngle(axis, angle);\r\n    this.quaternion.multiply(_quat);\r\n    return this;\r\n  }\r\n\r\n  /**\r\n   * Rotate an object along an axis in world space. The axis is assumed to be normalized. Method Assumes no rotated parent.\r\n   * @param axis A normalized vector in world space.\r\n   * @param angle The angle in radians.\r\n   * @returns The instance of the object.\r\n   */\r\n  public rotateOnWorldAxis(axis: Vector3, angle: number): this {\r\n    _quat.setFromAxisAngle(axis, angle);\r\n    this.quaternion.premultiply(_quat);\r\n    return this;\r\n  }\r\n\r\n  /**\r\n   * Rotates the object around x axis in local space.\r\n   * @param angle The angle to rotate in radians.\r\n   * @returns The instance of the object.\r\n   */\r\n  public rotateX(angle: number): this {\r\n    return this.rotateOnAxis(_xAxis, angle);\r\n  }\r\n\r\n  /**\r\n   * Rotates the object around y axis in local space.\r\n   * @param angle The angle to rotate in radians.\r\n   * @returns The instance of the object.\r\n   */\r\n  public rotateY(angle: number): this {\r\n    return this.rotateOnAxis(_yAxis, angle);\r\n  }\r\n\r\n  /**\r\n   * Rotates the object around z axis in local space.\r\n   * @param angle The angle to rotate in radians.\r\n   * @returns The instance of the object.\r\n   */\r\n  public rotateZ(angle: number): this {\r\n    return this.rotateOnAxis(_zAxis, angle);\r\n  }\r\n\r\n  /**\r\n   * Translate an object by distance along an axis in object space. The axis is assumed to be normalized.\r\n   * @param axis A normalized vector in object space.\r\n   * @param distance The distance to translate.\r\n   * @returns The instance of the object.\r\n   */\r\n  public translateOnAxis(axis: Vector3, distance: number): this {\r\n    _vec3.copy(axis).applyQuaternion(this.quaternion);\r\n    this.position.add(_vec3.multiplyScalar(distance));\r\n    return this;\r\n  }\r\n\r\n  /**\r\n   * Translates object along x axis in object space by distance units.\r\n   * @param distance The distance to translate.\r\n   * @returns The instance of the object.\r\n   */\r\n  public translateX(distance: number): this {\r\n    return this.translateOnAxis(_xAxis, distance);\r\n  }\r\n\r\n  /**\r\n   * Translates object along y axis in object space by distance units.\r\n   * @param distance The distance to translate.\r\n   * @returns The instance of the object.\r\n   */\r\n  public translateY(distance: number): this {\r\n    return this.translateOnAxis(_yAxis, distance);\r\n  }\r\n\r\n  /**\r\n   * Translates object along z axis in object space by distance units.\r\n   * @param distance The distance to translate.\r\n   * @returns The instance of the object.\r\n   */\r\n  public translateZ(distance: number): this {\r\n    return this.translateOnAxis(_zAxis, distance);\r\n  }\r\n\r\n  /**\r\n   * Removes this entity from its owner instance.\r\n   * @returns The instance of the object.\r\n   */\r\n  public remove(): this {\r\n    this.owner.removeInstances(this.id);\r\n    return this;\r\n  }\r\n}\r\n\r\nconst _quat = new Quaternion();\r\nconst _vec3 = new Vector3();\r\nconst _xAxis = new Vector3(1, 0, 0);\r\nconst _yAxis = new Vector3(0, 1, 0);\r\nconst _zAxis = new Vector3(0, 0, 1);\r\n","import { box3ToArray, BVH, BVHNode, HybridBuilder, onFrustumIntersectionCallback, onFrustumIntersectionLODCallback, onIntersectionCallback, onIntersectionRayCallback, vec3ToArray, WebGLCoordinateSystem } from 'bvh.js';\r\nimport { Box3, Matrix4, Raycaster, Sphere, Vector3 } from 'three';\r\nimport { LODLevel } from './feature/LOD.js';\r\nimport { InstancedMesh2 } from './InstancedMesh2.js';\r\n\r\n// TODO getBoxFromSphere updated if change geometry (and create accessor)\r\n// TODO accurateCulling in bvh.js?\r\n// TODO use params in constructor\r\n// TODO: intersectBox optional intersectCallback\r\n\r\n/**\r\n * Parameters for configuring the BVH (Bounding Volume Hierarchy).\r\n */\r\nexport interface BVHParams {\r\n  /**\r\n   * Margin applied to accommodate animated or moving objects.\r\n   * Improves BVH update performance but slows down frustum culling and raycasting.\r\n   * For static objects, set to 0 to optimize culling and raycasting efficiency.\r\n   * @default 0\r\n   */\r\n  margin?: number;\r\n  /**\r\n   * Uses the geometry bounding sphere to compute instance bounding boxes.\r\n   * Otherwise it's calculated by applying the object's matrix to all 8 bounding box points.\r\n   * This is faster but less precise. Useful for moving objects.\r\n   * Only works if the geometry's bounding sphere is centered at the origin.\r\n   * @default false\r\n   */\r\n  getBBoxFromBSphere?: boolean;\r\n  /**\r\n   * Enables accurate frustum culling by checking intersections without applying margin to the bounding box.\r\n   * @default true\r\n   */\r\n  accurateCulling?: boolean;\r\n}\r\n\r\ninterface SphereTarget {\r\n  centerX: number;\r\n  centerY: number;\r\n  centerZ: number;\r\n  maxScale: number;\r\n}\r\n\r\n/**\r\n * Class to manage BVH (Bounding Volume Hierarchy) for `InstancedMesh2`.\r\n * Provides methods for managing bounding volumes, frustum culling, raycasting, and bounding box computation.\r\n */\r\nexport class InstancedMeshBVH {\r\n  /**\r\n   * The target `InstancedMesh2` object that the BVH is managing.\r\n   */\r\n  public target: InstancedMesh2;\r\n  /**\r\n   * The geometry bounding box of the target.\r\n   */\r\n  public geoBoundingBox: Box3;\r\n  /**\r\n   * The BVH instance used to organize bounding volumes.\r\n   */\r\n  public bvh: BVH<{}, number>;\r\n  /**\r\n   * A map that stores the BVH nodes for each instance.\r\n   */\r\n  public nodesMap = new Map<number, BVHNode<{}, number>>();\r\n  /**\r\n   * Enables accurate frustum culling by checking intersections without applying margin to the bounding box.\r\n   */\r\n  public accurateCulling: boolean;\r\n  protected LODsMap = new Map<LODLevel[], Float32Array>();\r\n  protected _margin: number;\r\n  protected _origin: Float32Array;\r\n  protected _dir: Float32Array;\r\n  protected _boxArray: Float32Array;\r\n  protected _cameraPos: Float32Array;\r\n  protected _getBoxFromSphere: boolean;\r\n  protected _geoBoundingSphere: Sphere = null;\r\n  protected _sphereTarget: SphereTarget = null;\r\n\r\n  /**\r\n   * @param target The target `InstancedMesh2`.\r\n   * @param margin The margin applied for bounding box calculations (default is 0).\r\n   * @param getBBoxFromBSphere Flag to determine if instance bounding boxes should be computed from the geometry bounding sphere. Faster but less precise (default is false).\r\n   * @param accurateCulling Flag to enable accurate frustum culling without considering margin (default is true).\r\n   */\r\n  constructor(target: InstancedMesh2, margin = 0, getBBoxFromBSphere = false, accurateCulling = true) {\r\n    this.target = target;\r\n    this.accurateCulling = accurateCulling;\r\n    this._margin = margin;\r\n\r\n    const geometry = target._geometry;\r\n\r\n    if (!geometry.boundingBox) geometry.computeBoundingBox();\r\n    this.geoBoundingBox = geometry.boundingBox;\r\n\r\n    if (getBBoxFromBSphere) {\r\n      if (!geometry.boundingSphere) geometry.computeBoundingSphere();\r\n\r\n      const center = geometry.boundingSphere.center;\r\n      if (center.x === 0 && center.y === 0 && center.z === 0) {\r\n        this._geoBoundingSphere = geometry.boundingSphere;\r\n        this._sphereTarget = { centerX: 0, centerY: 0, centerZ: 0, maxScale: 0 };\r\n      } else {\r\n        console.warn('\"getBoxFromSphere\" is ignored because geometry is not centered.');\r\n        getBBoxFromBSphere = false;\r\n      }\r\n    }\r\n\r\n    this.bvh = new BVH(new HybridBuilder(), WebGLCoordinateSystem);\r\n    this._origin = new Float32Array(3);\r\n    this._dir = new Float32Array(3);\r\n    this._cameraPos = new Float32Array(3);\r\n    this._getBoxFromSphere = getBBoxFromBSphere;\r\n  }\r\n\r\n  /**\r\n   * Builds the BVH from the target mesh's instances using a top-down construction method.\r\n   * This approach is more efficient and accurate compared to incremental methods, which add one instance at a time.\r\n   */\r\n  public create(): void {\r\n    const count = this.target._instancesCount;\r\n    const instancesArrayCount = this.target._instancesArrayCount;\r\n    const boxes: Float32Array[] = new Array(count); // test if single array and recreation inside node creation is faster due to memory location\r\n    const objects = new Uint32Array(count);\r\n    let index = 0;\r\n\r\n    this.clear();\r\n\r\n    for (let i = 0; i < instancesArrayCount; i++) {\r\n      if (!this.target.getActiveAt(i)) continue;\r\n      boxes[index] = this.getBox(i, new Float32Array(6));\r\n      objects[index] = i;\r\n      index++;\r\n    }\r\n\r\n    this.bvh.createFromArray(objects as unknown as number[], boxes, (node) => {\r\n      this.nodesMap.set(node.object, node);\r\n    }, this._margin);\r\n  }\r\n\r\n  /**\r\n   * Inserts an instance into the BVH.\r\n   * @param id The id of the instance to insert.\r\n   */\r\n  public insert(id: number): void {\r\n    const node = this.bvh.insert(id, this.getBox(id, new Float32Array(6)), this._margin);\r\n    this.nodesMap.set(id, node);\r\n  }\r\n\r\n  /**\r\n   * Inserts a range of instances into the BVH.\r\n   * @param ids An array of ids to insert.\r\n   */\r\n  public insertRange(ids: number[]): void {\r\n    const count = ids.length;\r\n    const boxes: Float32Array[] = new Array(count);\r\n\r\n    for (let i = 0; i < count; i++) {\r\n      boxes[i] = this.getBox(ids[i], new Float32Array(6));\r\n    }\r\n\r\n    this.bvh.insertRange(ids, boxes, this._margin, (node) => {\r\n      this.nodesMap.set(node.object, node);\r\n    });\r\n  }\r\n\r\n  /**\r\n   * Moves an instance within the BVH.\r\n   * @param id The id of the instance to move.\r\n   */\r\n  public move(id: number): void {\r\n    const node = this.nodesMap.get(id);\r\n    if (!node) return;\r\n    this.getBox(id, node.box as Float32Array); // this also updates box\r\n    this.bvh.move(node, this._margin);\r\n  }\r\n\r\n  /**\r\n   * Deletes an instance from the BVH.\r\n   * @param id The id of the instance to delete.\r\n   */\r\n  public delete(id: number): void {\r\n    const node = this.nodesMap.get(id);\r\n    if (!node) return;\r\n    this.bvh.delete(node);\r\n    this.nodesMap.delete(id);\r\n  }\r\n\r\n  /**\r\n   * Clears the BVH.\r\n   */\r\n  public clear(): void {\r\n    this.bvh.clear();\r\n    this.nodesMap.clear();\r\n  }\r\n\r\n  /**\r\n   * Performs frustum culling to determine which instances are visible based on the provided projection matrix.\r\n   * @param projScreenMatrix The projection screen matrix for frustum culling.\r\n   * @param onFrustumIntersection Callback function invoked when an instance intersects the frustum.\r\n   */\r\n  public frustumCulling(projScreenMatrix: Matrix4, onFrustumIntersection: onFrustumIntersectionCallback<{}, number>): void {\r\n    if (this._margin > 0 && this.accurateCulling) {\r\n      this.bvh.frustumCulling(projScreenMatrix.elements, (node, frustum, mask) => {\r\n        if (frustum.isIntersectedMargin(node.box, mask, this._margin)) {\r\n          onFrustumIntersection(node);\r\n        }\r\n      });\r\n    } else {\r\n      this.bvh.frustumCulling(projScreenMatrix.elements, onFrustumIntersection);\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Performs frustum culling with Level of Detail (LOD) consideration.\r\n   * @param projScreenMatrix The projection screen matrix for frustum culling.\r\n   * @param cameraPosition The camera's position used for LOD calculations.\r\n   * @param levels An array of LOD levels.\r\n   * @param onFrustumIntersection Callback function invoked when an instance intersects the frustum.\r\n   */\r\n  public frustumCullingLOD(projScreenMatrix: Matrix4, cameraPosition: Vector3, levels: LODLevel[], onFrustumIntersection: onFrustumIntersectionLODCallback<{}, number>): void {\r\n    if (!this.LODsMap.has(levels)) {\r\n      this.LODsMap.set(levels, new Float32Array(levels.length));\r\n    }\r\n\r\n    const levelsArray = this.LODsMap.get(levels);\r\n    for (let i = 0; i < levels.length; i++) {\r\n      levelsArray[i] = levels[i].distance;\r\n    }\r\n\r\n    const camera = this._cameraPos;\r\n    camera[0] = cameraPosition.x;\r\n    camera[1] = cameraPosition.y;\r\n    camera[2] = cameraPosition.z;\r\n\r\n    if (this._margin > 0 && this.accurateCulling) {\r\n      this.bvh.frustumCullingLOD(projScreenMatrix.elements, camera, levelsArray, (node, level, frustum, mask) => {\r\n        if (frustum.isIntersectedMargin(node.box, mask, this._margin)) {\r\n          onFrustumIntersection(node, level);\r\n        }\r\n      });\r\n    } else {\r\n      this.bvh.frustumCullingLOD(projScreenMatrix.elements, camera, levelsArray, onFrustumIntersection);\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Performs raycasting to check if a ray intersects any instances.\r\n   * @param raycaster The raycaster used for raycasting.\r\n   * @param onIntersection Callback function invoked when a ray intersects an instance.\r\n   */\r\n  public raycast(raycaster: Raycaster, onIntersection: onIntersectionRayCallback<number>): void {\r\n    const ray = raycaster.ray;\r\n    const origin = this._origin;\r\n    const dir = this._dir;\r\n\r\n    vec3ToArray(ray.origin, origin);\r\n    vec3ToArray(ray.direction, dir);\r\n\r\n    // TODO should we add margin check? maybe is not worth it\r\n    this.bvh.rayIntersections(dir, origin, onIntersection, raycaster.near, raycaster.far);\r\n  }\r\n\r\n  /**\r\n   * Checks if a given box intersects with any instance bounding box.\r\n   * @param target The target bounding box.\r\n   * @param onIntersection Callback function invoked when an intersection occurs.\r\n   * @returns `True` if there is an intersection, otherwise `false`.\r\n   */\r\n  public intersectBox(target: Box3, onIntersection: onIntersectionCallback<number>): boolean {\r\n    if (!this._boxArray) this._boxArray = new Float32Array(6);\r\n    const array = this._boxArray;\r\n    box3ToArray(target, array);\r\n    return this.bvh.intersectsBox(array, onIntersection);\r\n  }\r\n\r\n  protected getBox(id: number, array: Float32Array): Float32Array {\r\n    if (this._getBoxFromSphere) {\r\n      const matrixArray = this.target.matricesTexture._data as Float32Array;\r\n      const { centerX, centerY, centerZ, maxScale } = this.getSphereFromMatrix_centeredGeometry(id, matrixArray, this._sphereTarget);\r\n      const radius = this._geoBoundingSphere.radius * maxScale;\r\n      array[0] = centerX - radius;\r\n      array[1] = centerX + radius;\r\n      array[2] = centerY - radius;\r\n      array[3] = centerY + radius;\r\n      array[4] = centerZ - radius;\r\n      array[5] = centerZ + radius;\r\n    } else {\r\n      _box3.copy(this.geoBoundingBox).applyMatrix4(this.target.getMatrixAt(id));\r\n      box3ToArray(_box3, array);\r\n    }\r\n\r\n    return array;\r\n  }\r\n\r\n  protected getSphereFromMatrix_centeredGeometry(id: number, array: Float32Array, target: SphereTarget): SphereTarget {\r\n    const offset = id * 16;\r\n\r\n    const m0 = array[offset + 0];\r\n    const m1 = array[offset + 1];\r\n    const m2 = array[offset + 2];\r\n    const m4 = array[offset + 4];\r\n    const m5 = array[offset + 5];\r\n    const m6 = array[offset + 6];\r\n    const m8 = array[offset + 8];\r\n    const m9 = array[offset + 9];\r\n    const m10 = array[offset + 10];\r\n\r\n    const scaleXSq = m0 * m0 + m1 * m1 + m2 * m2;\r\n    const scaleYSq = m4 * m4 + m5 * m5 + m6 * m6;\r\n    const scaleZSq = m8 * m8 + m9 * m9 + m10 * m10;\r\n\r\n    target.maxScale = Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));\r\n\r\n    target.centerX = array[offset + 12];\r\n    target.centerY = array[offset + 13];\r\n    target.centerZ = array[offset + 14];\r\n\r\n    return target;\r\n  }\r\n}\r\n\r\nconst _box3 = new Box3();\r\n","import { GLBufferAttribute, TypedArray, WebGLRenderer } from 'three';\r\n\r\n/**\r\n * A class that extends `GLBufferAttribute` to handle instanced buffer attributes.\r\n * This class was specifically created to allow updating instanced buffer attributes during the `onBeforeRender` callback,\r\n * providing an efficient way to modify the buffer data dynamically before rendering.\r\n */\r\nexport class GLInstancedBufferAttribute extends GLBufferAttribute {\r\n  /**\r\n   * Indicates if this is an `isGLInstancedBufferAttribute`.\r\n   */\r\n  public isGLInstancedBufferAttribute = true;\r\n  /**\r\n   * The number of meshes that share the same attribute data.\r\n   */\r\n  public meshPerAttribute: number;\r\n  /**\r\n   * The data array that holds the attribute values.\r\n   */\r\n  public array: TypedArray;\r\n  protected _cacheArray: TypedArray;\r\n  /** @internal */ _needsUpdate = false;\r\n\r\n  // HACK TO MAKE IT WORK WITHOUT UPDATE CORE\r\n  /** @internal */ isInstancedBufferAttribute = true;\r\n\r\n  /**\r\n   * @param gl The WebGL2RenderingContext used to create the buffer.\r\n   * @param type The type of data in the attribute.\r\n   * @param itemSize The number of elements per attribute.\r\n   * @param elementSize The size of individual elements in the array.\r\n   * @param array The data array that holds the attribute values.\r\n   * @param meshPerAttribute The number of meshes that share the same attribute data.\r\n   */\r\n  constructor(gl: WebGL2RenderingContext, type: GLenum, itemSize: number, elementSize: 1 | 2 | 4, array: TypedArray, meshPerAttribute = 1) {\r\n    const buffer = gl.createBuffer();\r\n    super(buffer, type, itemSize, elementSize, array.length / itemSize);\r\n\r\n    this.meshPerAttribute = meshPerAttribute;\r\n    this.array = array;\r\n    this._cacheArray = array;\r\n\r\n    gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\r\n    gl.bufferData(gl.ARRAY_BUFFER, array, gl.DYNAMIC_DRAW);\r\n  }\r\n\r\n  /**\r\n   * Updates the buffer data.\r\n   * This method is designed to be called during the `onBeforeRender` callback.\r\n   * It ensures that the attribute data is updated just before the rendering process begins.\r\n   * @param renderer The WebGLRenderer used to render the scene.\r\n   * @param count The number of elements to update in the buffer.\r\n   */\r\n  public update(renderer: WebGLRenderer, count: number): void {\r\n    if (!this._needsUpdate || count === 0) return;\r\n\r\n    const gl = renderer.getContext();\r\n    gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);\r\n\r\n    if (this.array === this._cacheArray) {\r\n      gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.array, 0, count);\r\n    } else {\r\n      gl.bufferData(gl.ARRAY_BUFFER, this.array, gl.DYNAMIC_DRAW);\r\n      this._cacheArray = this.array;\r\n    }\r\n\r\n    this._needsUpdate = false;\r\n  }\r\n\r\n  /** @internal */\r\n  public clone(): this {\r\n    // This method is intentionally empty but necessary to avoid exceptions when cloning geometry.\r\n    return this;\r\n  }\r\n}\r\n","import { MeshDistanceMaterial, WebGLRenderer } from 'three';\r\nimport { InstancedMesh2 } from '../InstancedMesh2.js';\r\n\r\n// TODO: Fix if multiple renderers?\r\n\r\n/**\r\n * To prevent three.js from using the same shader between InstancedMesh and InstancedMesh2 if the material is the same\r\n * (especially with `scene.overrideMaterial`), the `WebGLProperties` object is temporarily patched before each render of an InstancedMesh2.\r\n */\r\nlet propertiesGetBase: (obj: unknown) => unknown = null; // this can become const\r\nlet propertiesGet: WeakMap<any, () => unknown> = null;\r\nconst propertiesGetMap: { [x: string]: WeakMap<any, () => unknown> } = {};\r\n\r\nfunction propertiesGetCallback(object: unknown): unknown {\r\n  return propertiesGet.get(object)?.() ?? propertiesGetBase(object);\r\n}\r\n\r\nfunction addProperties(material: unknown): void {\r\n  if (propertiesGet.has(material)) return;\r\n\r\n  const materialProperties: { [x: string]: any } = {};\r\n\r\n  propertiesGet.set(material, () => {\r\n    // Fix pointLight bug. Related: https://github.com/mrdoob/three.js/blob/dev/src/renderers/webgl/WebGLShadowMap.js#L333\r\n    if ((material as MeshDistanceMaterial).isMeshDistanceMaterial) {\r\n      const materialPropertiesBase = propertiesGetBase(material) as { [x: string]: any };\r\n      materialProperties.light = materialPropertiesBase.light;\r\n    }\r\n\r\n    return materialProperties;\r\n  });\r\n}\r\n\r\nexport function patchProperties(obj: InstancedMesh2, renderer: WebGLRenderer, material: unknown): void {\r\n  const properties = renderer.properties;\r\n  propertiesGetBase = properties.get;\r\n\r\n  const key = `${!!obj.colorsTexture}_${obj._useOpacity}_${!!obj.boneTexture}_${!!obj.uniformsTexture}`;\r\n  propertiesGetMap[key] ??= new WeakMap<any, () => unknown>();\r\n  propertiesGet = propertiesGetMap[key];\r\n\r\n  properties.get = propertiesGetCallback;\r\n\r\n  addProperties(material);\r\n}\r\n\r\nexport function unpatchProperties(renderer: WebGLRenderer): void {\r\n  renderer.properties.get = propertiesGetBase;\r\n}\r\n","import { Color, ColorManagement, DataTexture, FloatType, IntType, Matrix3, Matrix4, NoColorSpace, PixelFormat, RedFormat, RedIntegerFormat, RGBAFormat, RGBAIntegerFormat, RGFormat, RGIntegerFormat, TextureDataType, TypedArray, UnsignedIntType, Vector2, Vector3, Vector4, WebGLRenderer, WebGLUtils } from 'three';\r\n\r\n/**\r\n * Represents the number of elements per pixel.\r\n */\r\nexport type ChannelSize = 1 | 2 | 3 | 4;\r\n/**\r\n * A constructor signature for creating TypedArray.\r\n */\r\nexport type TypedArrayConstructor = new (count: number) => TypedArray;\r\n/**\r\n * Represents the texture information including its data, size, format, and data type.\r\n */\r\nexport type TextureInfo = { array: TypedArray; size: number; format: PixelFormat; type: TextureDataType };\r\n/**\r\n * Represents information for updating rows in the texture, including the row index and number of rows.\r\n */\r\nexport type UpdateRowInfo = { row: number; count: number };\r\n/**\r\n * Defines the possible types of uniforms that can be used in shaders.\r\n */\r\nexport type UniformType = 'float' | 'vec2' | 'vec3' | 'vec4' | 'mat3' | 'mat4';\r\n/**\r\n * Represents a value that can be used as a uniform.\r\n */\r\nexport type UniformValueObj = Vector2 | Vector3 | Vector4 | Matrix3 | Matrix4 | Color;\r\n/**\r\n * Defines a uniform value as either a number or a compatible Three.js object.\r\n */\r\nexport type UniformValue = number | UniformValueObj;\r\n/**\r\n * Represents the schema for a uniform, defining its offset, size, and type.\r\n */\r\nexport type UniformMapType = { offset: number; size: number; type: UniformType };\r\n/**\r\n * Represents a map of uniform names to their schema definitions.\r\n */\r\nexport type UniformMap = Map<string, UniformMapType>;\r\n\r\n/**\r\n * Calculates the square texture size based on the capacity and pixels per instance.\r\n * This ensures the texture is large enough to store all instances in a square layout.\r\n * @param capacity The maximum number of instances allowed in the texture.\r\n * @param pixelsPerInstance The number of pixels required for each instance.\r\n * @returns The size of the square texture needed to store all the instances.\r\n */\r\nexport function getSquareTextureSize(capacity: number, pixelsPerInstance: number): number {\r\n  return Math.max(pixelsPerInstance, Math.ceil(Math.sqrt(capacity / pixelsPerInstance)) * pixelsPerInstance);\r\n}\r\n\r\n/**\r\n * Generates texture information (size, format, type) for a square texture based on the provided parameters.\r\n * @param arrayType The constructor for the TypedArray.\r\n * @param channels The number of channels in the texture.\r\n * @param pixelsPerInstance The number of pixels required for each instance.\r\n * @param capacity The maximum number of instances allowed in the texture.\r\n * @returns An object containing the texture's array, size, format, and data type.\r\n */\r\nexport function getSquareTextureInfo(arrayType: TypedArrayConstructor, channels: ChannelSize, pixelsPerInstance: number, capacity: number): TextureInfo {\r\n  if (channels === 3) {\r\n    console.warn('\"channels\" cannot be 3. Set to 4. More info: https://github.com/mrdoob/three.js/pull/23228');\r\n    channels = 4;\r\n  }\r\n\r\n  const size = getSquareTextureSize(capacity, pixelsPerInstance);\r\n  const array = new arrayType(size * size * channels);\r\n  const isFloat = arrayType.name.includes('Float');\r\n  const isUnsignedInt = arrayType.name.includes('Uint');\r\n  const type: TextureDataType = isFloat ? FloatType : (isUnsignedInt ? UnsignedIntType : IntType);\r\n  let format: PixelFormat;\r\n\r\n  switch (channels) {\r\n    case 1:\r\n      format = isFloat ? RedFormat : RedIntegerFormat;\r\n      break;\r\n    case 2:\r\n      format = isFloat ? RGFormat : RGIntegerFormat;\r\n      break;\r\n    case 4:\r\n      format = isFloat ? RGBAFormat : RGBAIntegerFormat;\r\n      break;\r\n  }\r\n\r\n  return { array, size, type, format };\r\n}\r\n\r\n/**\r\n * A class that extends `DataTexture` to manage a square texture optimized for instances rendering.\r\n * It supports dynamic resizing, partial update based on rows, and allows setting/getting uniforms per instance.\r\n */\r\nexport class SquareDataTexture extends DataTexture {\r\n  /**\r\n   * Whether to enable partial texture updates by row. If `false`, the entire texture will be updated.\r\n   * @default true.\r\n   */\r\n  public partialUpdate = true;\r\n  /**\r\n   * The maximum number of update calls per frame.\r\n   * @default Infinity\r\n   */\r\n  public maxUpdateCalls = Infinity;\r\n  /** @internal */ _data: TypedArray; // TODO make it public or remove it?\r\n  protected _channels: ChannelSize;\r\n  protected _pixelsPerInstance: number;\r\n  protected _stride: number;\r\n  protected _rowToUpdate: boolean[];\r\n  protected _uniformMap: UniformMap;\r\n  protected _fetchUniformsInFragmentShader: boolean;\r\n  protected _utils: WebGLUtils = null; // TODO add it to renderer instead of creating for each texture\r\n  protected _needsUpdate = true;\r\n  protected _lastWidth = -1;\r\n\r\n  /**\r\n   * @param arrayType The constructor for the TypedArray.\r\n   * @param channels The number of channels in the texture.\r\n   * @param pixelsPerInstance The number of pixels required for each instance.\r\n   * @param capacity The total number of instances.\r\n   * @param uniformMap Optional map for handling uniform values.\r\n   * @param fetchInFragmentShader Optional flag that determines if uniform values should be fetched in the fragment shader instead of the vertex shader.\r\n   */\r\n  constructor(arrayType: TypedArrayConstructor, channels: ChannelSize, pixelsPerInstance: number, capacity: number, uniformMap?: UniformMap, fetchInFragmentShader?: boolean) {\r\n    if (channels === 3) channels = 4;\r\n    const { array, format, size, type } = getSquareTextureInfo(arrayType, channels, pixelsPerInstance, capacity);\r\n    super(array, size, size, format, type);\r\n    this._data = array;\r\n    this._channels = channels;\r\n    this._pixelsPerInstance = pixelsPerInstance;\r\n    this._stride = pixelsPerInstance * channels;\r\n    this._rowToUpdate = new Array(size);\r\n    this._uniformMap = uniformMap;\r\n    this._fetchUniformsInFragmentShader = fetchInFragmentShader;\r\n    this.needsUpdate = true; // necessary to init texture\r\n  }\r\n\r\n  /**\r\n   * Resizes the texture to accommodate a new number of instances.\r\n   * @param count The new total number of instances.\r\n   */\r\n  public resize(count: number): void {\r\n    const size = getSquareTextureSize(count, this._pixelsPerInstance);\r\n    if (size === this.image.width) return;\r\n\r\n    const currentData = this._data;\r\n    const channels = this._channels;\r\n    this._rowToUpdate.length = size;\r\n    const arrayType = (currentData as any).constructor;\r\n\r\n    const data = new arrayType(size * size * channels);\r\n    const minLength = Math.min(currentData.length, data.length);\r\n    data.set(new arrayType(currentData.buffer, 0, minLength));\r\n\r\n    this.dispose();\r\n    this.image = { data, height: size, width: size };\r\n    this._data = data;\r\n  }\r\n\r\n  /**\r\n   * Marks a row of the texture for update during the next render cycle.\r\n   * This helps in optimizing texture updates by only modifying the rows that have changed.\r\n   * @param index The index of the instance to update.\r\n   */\r\n  public enqueueUpdate(index: number): void {\r\n    this._needsUpdate = true;\r\n    if (!this.partialUpdate) return;\r\n\r\n    const elementsPerRow = this.image.width / this._pixelsPerInstance;\r\n    const rowIndex = Math.floor(index / elementsPerRow);\r\n    this._rowToUpdate[rowIndex] = true;\r\n  }\r\n\r\n  public bindToProgram(renderer: WebGLRenderer, gl: WebGL2RenderingContext, programUniforms: unknown, materialUniforms: unknown, uniformName: string): void {\r\n    if (!materialUniforms[uniformName]) return;\r\n\r\n    materialUniforms[uniformName].value = this;\r\n\r\n    const slot = this.getSlot(programUniforms, uniformName);\r\n    if (slot === undefined) return;\r\n\r\n    const textureProperties: any = renderer.properties.get(this);\r\n    (renderer.state as any).bindTexture(gl.TEXTURE_2D, textureProperties.__webglTexture, gl.TEXTURE0 + slot); // TODO fix d.ts\r\n  }\r\n\r\n  /**\r\n   * Updates the texture data based on the rows that need updating.\r\n   * This method is optimized to only update the rows that have changed, improving performance.\r\n   * @param renderer The WebGLRenderer used for rendering.\r\n   * @param materialProperties The material properties associated with the texture.\r\n   * @param uniformName The name of the uniform in the shader.\r\n   */\r\n  public update(renderer: WebGLRenderer, materialProperties: any, uniformName: string): void {\r\n    const textureProperties: any = renderer.properties.get(this);\r\n    const versionChanged = textureProperties.__version !== this.version;\r\n\r\n    if (!this._needsUpdate && !versionChanged) return;\r\n\r\n    const sizeChanged = this._lastWidth !== this.image.width;\r\n\r\n    if (!textureProperties.__webglTexture || sizeChanged) {\r\n      renderer.initTexture(this);\r\n    } else {\r\n      const slot = this.getSlot(materialProperties, uniformName) ?? renderer.capabilities.maxTextures - 1;\r\n\r\n      if (this.partialUpdate) {\r\n        this.updatePartial(textureProperties, renderer, slot);\r\n      } else {\r\n        this.updateFull(textureProperties, renderer, slot);\r\n      }\r\n\r\n      textureProperties.__version = this.version;\r\n    }\r\n\r\n    this._lastWidth = this.image.width;\r\n    this._needsUpdate = false;\r\n  }\r\n\r\n  protected getSlot(programUniforms: any, uniformName: string): number | undefined {\r\n    return programUniforms[uniformName]?.cache[0] as number;\r\n  }\r\n\r\n  protected updateFull(textureProperties: any, renderer: WebGLRenderer, slot: number): void {\r\n    this.updateRows(textureProperties, renderer, [{ row: 0, count: this.image.height }], slot);\r\n  }\r\n\r\n  protected updatePartial(textureProperties: any, renderer: WebGLRenderer, slot: number): void {\r\n    const rowsInfo = this.getUpdateRowsInfo();\r\n    if (rowsInfo.length === 0) return;\r\n\r\n    if (rowsInfo.length > this.maxUpdateCalls) {\r\n      this.updateFull(textureProperties, renderer, slot);\r\n    } else {\r\n      this.updateRows(textureProperties, renderer, rowsInfo, slot);\r\n    }\r\n\r\n    this._rowToUpdate.fill(false);\r\n  }\r\n\r\n  // TODO reuse same objects to prevent memory leak\r\n  protected getUpdateRowsInfo(): UpdateRowInfo[] {\r\n    const rowsToUpdate = this._rowToUpdate;\r\n    const result: UpdateRowInfo[] = [];\r\n\r\n    for (let i = 0, l = rowsToUpdate.length; i < l; i++) {\r\n      if (rowsToUpdate[i]) {\r\n        const row = i;\r\n        for (; i < l; i++) {\r\n          if (!rowsToUpdate[i]) break;\r\n        }\r\n        result.push({ row, count: i - row });\r\n      }\r\n    }\r\n\r\n    return result;\r\n  }\r\n\r\n  protected updateRows(textureProperties: any, renderer: WebGLRenderer, info: UpdateRowInfo[], slot: number): void {\r\n    const gl = renderer.getContext() as WebGL2RenderingContext;\r\n    // @ts-expect-error Expected 2 arguments, but got 3.\r\n    this._utils ??= new WebGLUtils(gl, renderer.extensions, renderer.capabilities); // third argument is necessary for older three versions\r\n    const glFormat = this._utils.convert(this.format);\r\n    const glType = this._utils.convert(this.type);\r\n    const { data, width } = this.image;\r\n    const channels = this._channels;\r\n\r\n    renderer.state.activeTexture(gl.TEXTURE0 + slot);\r\n    (renderer.state as any).bindTexture(gl.TEXTURE_2D, textureProperties.__webglTexture, gl.TEXTURE0 + slot); // TODO fix d.ts\r\n\r\n    const workingPrimaries = ColorManagement.getPrimaries(ColorManagement.workingColorSpace);\r\n    const texturePrimaries = this.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries(this.colorSpace);\r\n    const unpackConversion = this.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries ? gl.NONE : gl.BROWSER_DEFAULT_WEBGL;\r\n\r\n    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this.flipY);\r\n    gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha);\r\n    gl.pixelStorei(gl.UNPACK_ALIGNMENT, this.unpackAlignment);\r\n    gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion);\r\n\r\n    for (const { count, row } of info) {\r\n      gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, row, width, count, glFormat, glType, data, row * width * channels);\r\n    }\r\n\r\n    this.onUpdate?.(this);\r\n  }\r\n\r\n  /**\r\n   * Sets a uniform value at the specified instance ID in the texture.\r\n   * @param id The instance ID to set the uniform for.\r\n   * @param name The name of the uniform.\r\n   * @param value The value to set for the uniform.\r\n   */\r\n  public setUniformAt(id: number, name: string, value: UniformValue): void {\r\n    const { offset, size } = this._uniformMap.get(name);\r\n    const stride = this._stride;\r\n\r\n    if (size === 1) {\r\n      this._data[id * stride + offset] = value as number;\r\n    } else {\r\n      (value as UniformValueObj).toArray(this._data, id * stride + offset);\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Retrieves a uniform value at the specified instance ID from the texture.\r\n   * @param id The instance ID to retrieve the uniform from.\r\n   * @param name The name of the uniform.\r\n   * @param target Optional target object to store the uniform value.\r\n   * @returns The uniform value for the specified instance.\r\n   */\r\n  public getUniformAt(id: number, name: string, target?: UniformValueObj): UniformValue {\r\n    const { offset, size } = this._uniformMap.get(name);\r\n    const stride = this._stride;\r\n\r\n    if (size === 1) {\r\n      return this._data[id * stride + offset];\r\n    }\r\n\r\n    return target.fromArray(this._data, id * stride + offset);\r\n  }\r\n\r\n  /**\r\n   * Generates the GLSL code for accessing the uniform data stored in the texture.\r\n   * @param textureName The name of the texture in the GLSL shader.\r\n   * @param indexName The name of the index in the GLSL shader.\r\n   * @param indexType The type of the index in the GLSL shader.\r\n   * @returns An object containing the GLSL code for the vertex and fragment shaders.\r\n   */\r\n  public getUniformsGLSL(textureName: string, indexName: string, indexType: string): { vertex: string; fragment: string } {\r\n    const vertex = this.getUniformsVertexGLSL(textureName, indexName, indexType);\r\n    const fragment = this.getUniformsFragmentGLSL(textureName, indexName, indexType);\r\n    return { vertex, fragment };\r\n  }\r\n\r\n  protected getUniformsVertexGLSL(textureName: string, indexName: string, indexType: string): string {\r\n    if (this._fetchUniformsInFragmentShader) {\r\n      return `\r\n        flat varying ${indexType} ez_v${indexName}; \r\n        void main() {\r\n          ez_v${indexName} = ${indexName};`;\r\n    }\r\n\r\n    const texelsFetch = this.texelsFetchGLSL(textureName, indexName);\r\n    const getFromTexels = this.getFromTexelsGLSL();\r\n    const { assignVarying, declareVarying } = this.getVarying();\r\n\r\n    return `\r\n      uniform highp sampler2D ${textureName};  \r\n      ${declareVarying}\r\n      void main() {\r\n        ${texelsFetch}\r\n        ${getFromTexels}\r\n        ${assignVarying}`;\r\n  }\r\n\r\n  protected getUniformsFragmentGLSL(textureName: string, indexName: string, indexType: string): string {\r\n    if (!this._fetchUniformsInFragmentShader) {\r\n      const { declareVarying, getVarying } = this.getVarying();\r\n\r\n      return `\r\n      ${declareVarying}\r\n      void main() {\r\n        ${getVarying}`;\r\n    }\r\n\r\n    const texelsFetch = this.texelsFetchGLSL(textureName, `ez_v${indexName}`);\r\n    const getFromTexels = this.getFromTexelsGLSL();\r\n\r\n    return `\r\n      uniform highp sampler2D ${textureName};  \r\n      flat varying ${indexType} ez_v${indexName};\r\n      void main() {\r\n        ${texelsFetch}\r\n        ${getFromTexels}`;\r\n  }\r\n\r\n  protected texelsFetchGLSL(textureName: string, indexName: string): string {\r\n    const pixelsPerInstance = this._pixelsPerInstance;\r\n\r\n    let texelsFetch = `\r\n      int size = textureSize(${textureName}, 0).x;\r\n      int j = int(${indexName}) * ${pixelsPerInstance};\r\n      int x = j % size;\r\n      int y = j / size;\r\n    `;\r\n\r\n    for (let i = 0; i < pixelsPerInstance; i++) {\r\n      texelsFetch += `vec4 ez_texel${i} = texelFetch(${textureName}, ivec2(x + ${i}, y), 0);\\n`;\r\n    }\r\n\r\n    return texelsFetch;\r\n  }\r\n\r\n  protected getFromTexelsGLSL(): string {\r\n    const uniforms = this._uniformMap;\r\n    let getFromTexels = '';\r\n\r\n    for (const [name, { type, offset, size }] of uniforms) {\r\n      const tId = Math.floor(offset / this._channels);\r\n\r\n      if (type === 'mat3') {\r\n        getFromTexels += `mat3 ${name} = mat3(ez_texel${tId}.rgb, vec3(ez_texel${tId}.a, ez_texel${tId + 1}.rg), vec3(ez_texel${tId + 1}.ba, ez_texel${tId + 2}.r));\\n`;\r\n      } else if (type === 'mat4') {\r\n        getFromTexels += `mat4 ${name} = mat4(ez_texel${tId}, ez_texel${tId + 1}, ez_texel${tId + 2}, ez_texel${tId + 3});\\n`;\r\n      } else {\r\n        const components = this.getUniformComponents(offset, size);\r\n        getFromTexels += `${type} ${name} = ez_texel${tId}.${components};\\n`;\r\n      }\r\n    }\r\n\r\n    return getFromTexels;\r\n  }\r\n\r\n  protected getVarying(): { declareVarying: string; assignVarying: string; getVarying: string } {\r\n    const uniforms = this._uniformMap;\r\n    let declareVarying = '';\r\n    let assignVarying = '';\r\n    let getVarying = '';\r\n\r\n    for (const [name, { type }] of uniforms) {\r\n      declareVarying += `flat varying ${type} ez_v${name};\\n`;\r\n      assignVarying += `ez_v${name} = ${name};\\n`;\r\n      getVarying += `${type} ${name} = ez_v${name};\\n`;\r\n    }\r\n\r\n    return { declareVarying, assignVarying, getVarying };\r\n  }\r\n\r\n  protected getUniformComponents(offset: number, size: number): string {\r\n    const startIndex = offset % this._channels;\r\n    let components = '';\r\n\r\n    for (let i = 0; i < size; i++) {\r\n      components += componentsArray[startIndex + i];\r\n    }\r\n\r\n    return components;\r\n  }\r\n\r\n  public override copy(source: SquareDataTexture): this {\r\n    super.copy(source);\r\n\r\n    this.partialUpdate = source.partialUpdate;\r\n    this.maxUpdateCalls = source.maxUpdateCalls;\r\n    this._channels = source._channels;\r\n    this._pixelsPerInstance = source._pixelsPerInstance;\r\n    this._stride = source._stride;\r\n    this._rowToUpdate = source._rowToUpdate;\r\n    this._uniformMap = source._uniformMap;\r\n    this._fetchUniformsInFragmentShader = source._fetchUniformsInFragmentShader;\r\n\r\n    return this;\r\n  }\r\n}\r\n\r\nconst componentsArray = ['r', 'g', 'b', 'a'];\r\n","import { AttachedBindMode, BindMode, Box3, BufferAttribute, BufferGeometry, Camera, Color, ColorManagement, ColorRepresentation, DataTexture, DetachedBindMode, InstancedBufferAttribute, Material, Matrix4, Mesh, Object3D, Object3DEventMap, Scene, Skeleton, Sphere, TypedArray, Vector3, WebGLProgramParametersWithUniforms, WebGLRenderer } from 'three';\r\nimport { CustomSortCallback, OnFrustumEnterCallback } from './feature/FrustumCulling.js';\r\nimport { Entity } from './feature/Instances.js';\r\nimport { LODInfo } from './feature/LOD.js';\r\nimport { InstancedEntity } from './InstancedEntity.js';\r\nimport { BVHParams, InstancedMeshBVH } from './InstancedMeshBVH.js';\r\nimport { GLInstancedBufferAttribute } from './utils/GLInstancedBufferAttribute.js';\r\nimport { patchProperties, unpatchProperties } from './utils/PropertiesOverride.js';\r\nimport { SquareDataTexture } from './utils/SquareDataTexture.js';\r\n\r\n// TODO: Add check to not update partial texture if needsuupdate already true\r\n// TODO: if bvh present, can override?\r\n// TODO: Use BVH only for raycasting\r\n// TODO LOD: instancedMeshLOD rendering first nearest levels, look out to transparent\r\n// TODO LOD: shared customDepthMaterial and customDistanceMaterial?\r\n// TODO LOD: BVH and handle raycastOnlyFrustum?;\r\n// TODO: check if check first and last material is right.. we should use the first valid index instead\r\n// TODO: use visible = false instead count = 0 for unused LOD?\r\n// TODO: convert also morph texture to squared texture to use partial update\r\n// TODO: sorting per each LODlevel\r\n\r\n/**\r\n * Parameters for configuring an `InstancedMesh2` instance.\r\n */\r\nexport interface InstancedMesh2Params {\r\n  /**\r\n   * Determines the maximum number of instances that buffers can hold.\r\n   * The buffers will be expanded automatically if necessary.\r\n   * @default 1000\r\n   */\r\n  capacity?: number;\r\n  /**\r\n   * Determines whether to create an array of `InstancedEntity` to easily manipulate instances at the cost of more memory.\r\n   * @default false\r\n   */\r\n  createEntities?: boolean;\r\n  /**\r\n   * Determines whether `InstancedEntity` can use the `rotation` property.\r\n   * If `true` `quaternion` and `rotation` will be synchronized, affecting performance.\r\n   * @default false\r\n   */\r\n  allowsEuler?: boolean;\r\n  /**\r\n   * WebGL renderer instance.\r\n   * If not provided, buffers will be initialized during the first render, resulting in no instances being rendered initially.\r\n   * @default null\r\n   */\r\n  renderer?: WebGLRenderer;\r\n}\r\n\r\ninterface RenderInfo {\r\n  frame: number;\r\n  camera: Camera | null;\r\n  shadowCamera: Camera | null;\r\n}\r\n\r\n/**\r\n * Alternative `InstancedMesh` class to support additional features like frustum culling, fast raycasting, LOD and more.\r\n * @template TData Type for additional instance data.\r\n * @template TGeometry Type extending `BufferGeometry`.\r\n * @template TMaterial Type extending `Material` or an array of `Material`.\r\n * @template TEventMap Type extending `Object3DEventMap`.\r\n */\r\nexport class InstancedMesh2<\r\n  TData = {},\r\n  TGeometry extends BufferGeometry = BufferGeometry,\r\n  TMaterial extends Material | Material[] = Material | Material[],\r\n  TEventMap extends Object3DEventMap = Object3DEventMap\r\n> extends Mesh<TGeometry, TMaterial, TEventMap> {\r\n  /**\r\n   * The number of instances rendered in the last frame.\r\n   */\r\n  public declare count: number;\r\n  /**\r\n   * @defaultValue `InstancedMesh2`\r\n   */\r\n  public override readonly type = 'InstancedMesh2';\r\n  /**\r\n   * Indicates if this is an `InstancedMesh2`.\r\n   */\r\n  public readonly isInstancedMesh2 = true;\r\n  /**\r\n   * An array of `Entity` representing individual instances.\r\n   * This array is only initialized if `createEntities` is set to `true` in the constructor parameters.\r\n   */\r\n  public instances: Entity<TData>[] = null;\r\n  /**\r\n   * Attribute storing indices of the instances to be rendered.\r\n   */\r\n  public instanceIndex: GLInstancedBufferAttribute = null;\r\n  /**\r\n   * Texture storing matrices for instances.\r\n   */\r\n  public matricesTexture: SquareDataTexture;\r\n  /**\r\n   * Texture storing colors for instances.\r\n   */\r\n  public colorsTexture: SquareDataTexture = null;\r\n  /**\r\n   * Texture storing morph target influences for instances.\r\n   */\r\n  public morphTexture: DataTexture = null;\r\n  /**\r\n   * Texture storing bones for instances.\r\n   */\r\n  public boneTexture: SquareDataTexture = null;\r\n  /**\r\n   * Texture storing custom uniforms per instance.\r\n   */\r\n  public uniformsTexture: SquareDataTexture = null;\r\n  /**\r\n   * This bounding box encloses all instances, which can be calculated with `computeBoundingBox` method.\r\n   * Bounding box isn't computed by default. It needs to be explicitly computed, otherwise it's `null`.\r\n   */\r\n  public boundingBox: Box3 = null;\r\n  /**\r\n   * This bounding sphere encloses all instances, which can be calculated with `computeBoundingSphere` method.\r\n   * Bounding sphere is computed during its first render. You may need to recompute it if an instance is transformed.\r\n   */\r\n  public boundingSphere: Sphere = null;\r\n  /**\r\n   * BVH structure for optimized culling and intersection testing.\r\n   * It's possible to create the BVH using the `computeBVH` method. Once created it will be updated automatically.\r\n   */\r\n  public bvh: InstancedMeshBVH = null;\r\n  /**\r\n   * Custom sort function for instances.\r\n   * It's possible to create the radix sort using the `createRadixSort` method.\r\n   * @default null\r\n  */\r\n  public customSort: CustomSortCallback = null;\r\n  /**\r\n   * Flag indicating if raycasting should only consider the last frame frustum culled instances.\r\n   * This is ignored if the bvh has been created.\r\n   * @default false\r\n   */\r\n  public raycastOnlyFrustum = false;\r\n  /**\r\n   * Array storing visibility and availability for instances.\r\n   * [visible0, active0, visible1, active1, ...]\r\n   */\r\n  public readonly availabilityArray: boolean[];\r\n  /**\r\n   * Contains data for managing LOD, allowing different levels of detail for rendering and shadow casting.\r\n   */\r\n  public LODinfo: LODInfo<TData> = null;\r\n  /**\r\n   * Flag indicating whether to automatically perform frustum culling before rendering.\r\n   * @default true\r\n   */\r\n  public autoUpdate = true;\r\n  /**\r\n   * Either `AttachedBindMode` or `DetachedBindMode`. `AttachedBindMode` means the skinned mesh shares the same world space as the skeleton.\r\n   * This is not true when using `DetachedBindMode` which is useful when sharing a skeleton across multiple skinned meshes.\r\n   * @default `AttachedBindMode`\r\n   */\r\n  public bindMode: BindMode = AttachedBindMode;\r\n  /**\r\n   * The base matrix that is used for the bound bone transforms.\r\n   */\r\n  public bindMatrix: Matrix4 = null;\r\n  /**\r\n   * The base matrix that is used for resetting the bound bone transforms.\r\n   */\r\n  public bindMatrixInverse: Matrix4 = null;\r\n  /**\r\n   * Skeleton representing the bone hierarchy of the skinned mesh.\r\n   */\r\n  public skeleton: Skeleton = null;\r\n  /**\r\n   * Flag indicating whether to automatically update the BVH structure (if present).\r\n   * @default true\r\n   */\r\n  public autoUpdateBVH = true;\r\n  /**\r\n   * Callback function called if an instance is inside the frustum.\r\n   */\r\n  public onFrustumEnter: OnFrustumEnterCallback = null;\r\n  /** @internal */ _renderer: WebGLRenderer = null;\r\n  /** @internal */ _instancesCount = 0;\r\n  /** @internal */ _instancesArrayCount = 0;\r\n  /** @internal */ _perObjectFrustumCulled = true;\r\n  /** @internal */ _sortObjects = false;\r\n  /** @internal */ _capacity: number;\r\n  /** @internal */ _indexArrayNeedsUpdate = false;\r\n  /** @internal */ _geometry: TGeometry;\r\n  /** @internal */ _parentLOD: InstancedMesh2;\r\n  /** @internal */ _lastRenderInfo: RenderInfo;\r\n  /** @internal */ _useOpacity = false;\r\n  protected readonly _allowsEuler: boolean;\r\n  protected readonly _tempInstance: InstancedEntity;\r\n  protected _currentMaterial: Material = null;\r\n  protected _customProgramCacheKeyBase: () => string = null;\r\n  protected _onBeforeCompileBase: (parameters: WebGLProgramParametersWithUniforms, renderer: WebGLRenderer) => void = null;\r\n  protected _definesBase: { [key: string]: any } = null;\r\n  protected _freeIds: number[] = [];\r\n  protected _createEntities: boolean;\r\n\r\n  // HACK TO MAKE IT WORK WITHOUT UPDATE CORE\r\n  /** @internal */ isInstancedMesh = true; // must be set to use instancing rendering\r\n  /** @internal */ instanceMatrix = new InstancedBufferAttribute(new Float32Array(0), 16); // must be init to avoid exception\r\n  /** @internal */ instanceColor = null; // must be null to avoid exception\r\n\r\n  /**\r\n   * The capacity of the instance buffers.\r\n   */\r\n  public get capacity(): number { return this._capacity; }\r\n\r\n  /**\r\n   * The number of active instances.\r\n   */\r\n  public get instancesCount(): number { return this._instancesCount; }\r\n\r\n  /**\r\n   * Determines if per-instance frustum culling is enabled.\r\n   * @default true\r\n   */\r\n  public get perObjectFrustumCulled(): boolean { return this._perObjectFrustumCulled; }\r\n  public set perObjectFrustumCulled(value: boolean) {\r\n    this._perObjectFrustumCulled = value;\r\n    this._indexArrayNeedsUpdate = true;\r\n  }\r\n\r\n  /**\r\n   * Determines if objects should be sorted before rendering.\r\n   * @default false\r\n   */\r\n  public get sortObjects(): boolean { return this._sortObjects; }\r\n  public set sortObjects(value: boolean) {\r\n    this._sortObjects = value;\r\n    this._indexArrayNeedsUpdate = true;\r\n  }\r\n\r\n  /**\r\n   * An instance of `BufferGeometry` (or derived classes), defining the object's structure.\r\n   */\r\n  // @ts-expect-error It's defined as a property, but is overridden as an accessor.\r\n  public override get geometry(): TGeometry { return this._geometry; }\r\n  public override set geometry(value: TGeometry) {\r\n    this._geometry = value;\r\n    this.patchGeometry(value);\r\n  }\r\n\r\n  /** @internal */\r\n  // eslint-disable-next-line @typescript-eslint/unified-signatures\r\n  constructor(geometry: TGeometry, material: TMaterial, params?: InstancedMesh2Params, LOD?: InstancedMesh2);\r\n  constructor(geometry: TGeometry, material: TMaterial, params?: InstancedMesh2Params);\r\n  /**\r\n   * @remarks Geometry cannot be shared. If reused, it will be cloned.\r\n   * @param geometry An instance of `BufferGeometry`.\r\n   * @param material A single or an array of `Material`.\r\n   * @param params Optional configuration parameters object. See `InstancedMesh2Params` for details.\r\n   */\r\n  constructor(geometry: TGeometry, material: TMaterial, params: InstancedMesh2Params = {}, LOD?: InstancedMesh2) {\r\n    if (!geometry) throw new Error('\"geometry\" is mandatory.');\r\n    if (!material) throw new Error('\"material\" is mandatory.');\r\n\r\n    const { allowsEuler, renderer, createEntities } = params;\r\n\r\n    super(geometry, null);\r\n\r\n    const capacity = params.capacity > 0 ? params.capacity : _defaultCapacity;\r\n    this._renderer = renderer;\r\n    this._capacity = capacity;\r\n    this._parentLOD = LOD;\r\n    this._geometry = geometry;\r\n    this.material = material;\r\n    this._allowsEuler = allowsEuler ?? false;\r\n    this._tempInstance = new InstancedEntity(this, -1, allowsEuler);\r\n    this.availabilityArray = LOD?.availabilityArray ?? new Array(capacity * 2);\r\n    this._createEntities = createEntities;\r\n\r\n    this.initLastRenderInfo();\r\n    this.initIndexAttribute();\r\n    this.initMatricesTexture();\r\n  }\r\n\r\n  public override onBeforeShadow(renderer: WebGLRenderer, scene: Scene, camera: Camera, shadowCamera: Camera, geometry: BufferGeometry, depthMaterial: Material, group: any): void {\r\n    this.patchMaterial(renderer, depthMaterial);\r\n\r\n    this.updateTextures(renderer, depthMaterial);\r\n\r\n    const frame = renderer.info.render.frame;\r\n    if (this.instanceIndex && this.autoUpdate && !this.frustumCullingAlreadyPerformed(frame, camera, shadowCamera)) {\r\n      this.performFrustumCulling(shadowCamera, camera);\r\n    }\r\n\r\n    if (this.count === 0) return;\r\n\r\n    this.instanceIndex.update(this._renderer, this.count);\r\n    this.bindTextures(renderer, depthMaterial);\r\n  }\r\n\r\n  public override onBeforeRender(renderer: WebGLRenderer, scene: Scene, camera: Camera, geometry: BufferGeometry, material: Material, group: any): void {\r\n    this.patchMaterial(renderer, material);\r\n\r\n    this.updateTextures(renderer, material);\r\n\r\n    if (!this.instanceIndex) {\r\n      this._renderer = renderer;\r\n      return;\r\n    }\r\n\r\n    const frame = renderer.info.render.frame;\r\n    if (this.autoUpdate && !this.frustumCullingAlreadyPerformed(frame, camera, null)) {\r\n      this.performFrustumCulling(camera);\r\n    }\r\n\r\n    if (this.count === 0) return;\r\n\r\n    this.instanceIndex.update(this._renderer, this.count);\r\n    this.bindTextures(renderer, material);\r\n  }\r\n\r\n  public override onAfterShadow(renderer: WebGLRenderer, scene: Scene, camera: Camera, shadowCamera: Camera, geometry: BufferGeometry, depthMaterial: Material, group: any): void {\r\n    this.unpatchMaterial(renderer, depthMaterial);\r\n  }\r\n\r\n  public override onAfterRender(renderer: WebGLRenderer, scene: Scene, camera: Camera, geometry: BufferGeometry, material: Material, group: any): void {\r\n    this.unpatchMaterial(renderer, material);\r\n    if (this.instanceIndex || (group && !this.isLastGroup(group.materialIndex))) return;\r\n    this.initIndexAttribute();\r\n  }\r\n\r\n  protected updateTextures(renderer: WebGLRenderer, material: Material): void {\r\n    const materialProperties = renderer.properties.get(material) as any;\r\n\r\n    this.matricesTexture.update(renderer, materialProperties, 'matricesTexture');\r\n    this.colorsTexture?.update(renderer, materialProperties, 'colorsTexture');\r\n    this.uniformsTexture?.update(renderer, materialProperties, 'uniformsTexture');\r\n    this.boneTexture?.update(renderer, materialProperties, 'boneTexture');\r\n  }\r\n\r\n  protected bindTextures(renderer: WebGLRenderer, material: Material): void {\r\n    const materialProperties = renderer.properties.get(material) as any;\r\n    const materialUniforms = materialProperties.uniforms;\r\n    if (!materialUniforms) return;\r\n\r\n    const currentProgramProperties = materialProperties.currentProgram;\r\n    const currentProgram = currentProgramProperties?.program;\r\n    if (!currentProgram) return;\r\n\r\n    const gl = renderer.getContext() as WebGL2RenderingContext;\r\n    const programUniforms = currentProgramProperties.getUniforms().map;\r\n\r\n    const activeProgram = gl.getParameter(gl.CURRENT_PROGRAM);\r\n    renderer.state.useProgram(currentProgram); // set the program\r\n\r\n    this.matricesTexture.bindToProgram(renderer, gl, programUniforms, materialUniforms, 'matricesTexture');\r\n    this.colorsTexture?.bindToProgram(renderer, gl, programUniforms, materialUniforms, 'colorsTexture');\r\n    this.uniformsTexture?.bindToProgram(renderer, gl, programUniforms, materialUniforms, 'uniformsTexture');\r\n    this.boneTexture?.bindToProgram(renderer, gl, programUniforms, materialUniforms, 'boneTexture');\r\n\r\n    renderer.state.useProgram(activeProgram); // restore the old program to make three.js update uniforms correctly\r\n  }\r\n\r\n  protected isLastGroup(materialIndex: number): boolean {\r\n    const materials = this.material as Material[];\r\n    for (let i = materials.length - 1; i >= materialIndex; i--) {\r\n      if (materials[i].visible) {\r\n        return i === materialIndex;\r\n      }\r\n    }\r\n  }\r\n\r\n  protected initIndexAttribute(): void {\r\n    if (!this._renderer) {\r\n      this.count = 0;\r\n      return;\r\n    }\r\n\r\n    const gl = this._renderer.getContext() as WebGL2RenderingContext;\r\n    const capacity = this._capacity;\r\n    const array = new Uint32Array(capacity);\r\n\r\n    for (let i = 0; i < capacity; i++) {\r\n      array[i] = i;\r\n    }\r\n\r\n    this.instanceIndex = new GLInstancedBufferAttribute(gl, gl.UNSIGNED_INT, 1, 4, array);\r\n    this._geometry.setAttribute('instanceIndex', this.instanceIndex as unknown as BufferAttribute);\r\n  }\r\n\r\n  protected initLastRenderInfo(): void {\r\n    if (!this._parentLOD) {\r\n      this._lastRenderInfo = { frame: -1, camera: null, shadowCamera: null };\r\n    }\r\n  }\r\n\r\n  protected initMatricesTexture(): void {\r\n    if (!this._parentLOD) {\r\n      this.matricesTexture = new SquareDataTexture(Float32Array, 4, 4, this._capacity);\r\n    }\r\n  }\r\n\r\n  protected initColorsTexture(): void {\r\n    if (!this._parentLOD) {\r\n      this.colorsTexture = new SquareDataTexture(Float32Array, 4, 1, this._capacity);\r\n      this.colorsTexture.colorSpace = ColorManagement.workingColorSpace;\r\n      this.colorsTexture._data.fill(1);\r\n      this.materialsNeedsUpdate();\r\n    }\r\n  }\r\n\r\n  protected materialsNeedsUpdate(): void {\r\n    if ((this.material as Material).isMaterial) {\r\n      (this.material as Material).needsUpdate = true;\r\n      return;\r\n    }\r\n\r\n    for (const material of (this.material as Material[])) {\r\n      material.needsUpdate = true;\r\n    }\r\n  }\r\n\r\n  protected patchGeometry(geometry: TGeometry): void {\r\n    const instanceIndex = geometry.getAttribute('instanceIndex') as unknown as GLInstancedBufferAttribute; // TODO fix d.ts\r\n\r\n    if (instanceIndex) {\r\n      if (instanceIndex === this.instanceIndex) return;\r\n\r\n      console.warn('The geometry has been cloned because it was already used.');\r\n      geometry = geometry.clone();\r\n      geometry.deleteAttribute('instanceIndex'); // TODO rename it it ez_instancedIndex\r\n    }\r\n\r\n    if (this.instanceIndex) {\r\n      geometry.setAttribute('instanceIndex', this.instanceIndex as unknown as BufferAttribute); // TODO fix d.ts\r\n    }\r\n  }\r\n\r\n  protected _customProgramCacheKey = (): string => {\r\n    return `ez_${!!this.colorsTexture}_${this._useOpacity}_${!!this.boneTexture}_${!!this.uniformsTexture}_${this._customProgramCacheKeyBase.call(this._currentMaterial)}`;\r\n  };\r\n\r\n  protected _onBeforeCompile = (shader: WebGLProgramParametersWithUniforms, renderer: WebGLRenderer): void => {\r\n    if (this._onBeforeCompileBase) this._onBeforeCompileBase.call(this._currentMaterial, shader, renderer);\r\n\r\n    shader.defines = { ...shader.defines }; // clone to avoid problem with standard material when used for scene.overrideMaterial\r\n    shader.defines['USE_INSTANCING_INDIRECT'] = '';\r\n\r\n    shader.uniforms.matricesTexture = { value: this.matricesTexture };\r\n\r\n    if (this.uniformsTexture) {\r\n      shader.uniforms.uniformsTexture = { value: this.uniformsTexture };\r\n      const { vertex, fragment } = this.uniformsTexture.getUniformsGLSL('uniformsTexture', 'instanceIndex', 'uint');\r\n      shader.vertexShader = shader.vertexShader.replace('void main() {', vertex);\r\n      shader.fragmentShader = shader.fragmentShader.replace('void main() {', fragment);\r\n    }\r\n\r\n    if (this.colorsTexture && shader.fragmentShader.includes('#include <color_pars_fragment>')) {\r\n      shader.defines['USE_INSTANCING_COLOR_INDIRECT'] = '';\r\n      shader.uniforms.colorsTexture = { value: this.colorsTexture };\r\n      shader.vertexShader = shader.vertexShader.replace('<color_vertex>', '<instanced_color_vertex>');\r\n\r\n      if (shader.vertexColors) {\r\n        shader.defines['USE_VERTEX_COLOR'] = '';\r\n      }\r\n\r\n      shader.defines['USE_COLOR_ALPHA'] = '';\r\n    }\r\n\r\n    if (this.boneTexture) {\r\n      shader.defines['USE_SKINNING'] = '';\r\n      shader.defines['USE_INSTANCING_SKINNING'] = '';\r\n      shader.uniforms.bindMatrix = { value: this.bindMatrix };\r\n      shader.uniforms.bindMatrixInverse = { value: this.bindMatrixInverse };\r\n      shader.uniforms.bonesPerInstance = { value: this.skeleton.bones.length };\r\n      shader.uniforms.boneTexture = { value: this.boneTexture };\r\n    }\r\n  };\r\n\r\n  protected patchMaterial(renderer: WebGLRenderer, material: Material): void {\r\n    this._currentMaterial = material;\r\n    this._customProgramCacheKeyBase = material.customProgramCacheKey; // avoid .bind(material); to prevent memory leak\r\n    this._onBeforeCompileBase = material.onBeforeCompile;\r\n    this._definesBase = material.defines;\r\n    material.customProgramCacheKey = this._customProgramCacheKey;\r\n    material.onBeforeCompile = this._onBeforeCompile;\r\n    patchProperties(this, renderer, material);\r\n  }\r\n\r\n  protected unpatchMaterial(renderer: WebGLRenderer, material: Material): void {\r\n    this._currentMaterial = null;\r\n    unpatchProperties(renderer);\r\n    material.defines = this._definesBase;\r\n    material.onBeforeCompile = this._onBeforeCompileBase;\r\n    material.customProgramCacheKey = this._customProgramCacheKeyBase;\r\n    this._onBeforeCompileBase = null;\r\n    this._customProgramCacheKeyBase = null;\r\n    this._definesBase = null;\r\n  }\r\n\r\n  /**\r\n   * Creates and computes the BVH (Bounding Volume Hierarchy) for the instances.\r\n   * It's recommended to create it when all the instance matrices have been assigned.\r\n   * Once created it will be updated automatically.\r\n   * @param config Optional configuration parameters object. See `BVHParams` for details.\r\n   */\r\n  public computeBVH(config: BVHParams = {}): void {\r\n    if (!this.bvh) this.bvh = new InstancedMeshBVH(this, config.margin, config.getBBoxFromBSphere, config.accurateCulling);\r\n    this.bvh.clear();\r\n    this.bvh.create();\r\n  }\r\n\r\n  /**\r\n   * Disposes of the BVH structure.\r\n   */\r\n  public disposeBVH(): void {\r\n    this.bvh = null;\r\n  }\r\n\r\n  /**\r\n   * Sets the local transformation matrix for a specific instance.\r\n   * @param id The index of the instance.\r\n   * @param matrix A `Matrix4` representing the local transformation to apply to the instance.\r\n   */\r\n  public setMatrixAt(id: number, matrix: Matrix4): void {\r\n    matrix.toArray(this.matricesTexture._data, id * 16);\r\n\r\n    if (this.instances) {\r\n      const instance = this.instances[id];\r\n      matrix.decompose(instance.position, instance.quaternion, instance.scale);\r\n    }\r\n\r\n    this.matricesTexture.enqueueUpdate(id);\r\n\r\n    if (this.bvh && this.autoUpdateBVH) {\r\n      this.bvh.move(id);\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Gets the local transformation matrix of a specific instance.\r\n   * @param id The index of the instance.\r\n   * @param matrix Optional `Matrix4` to store the result.\r\n   * @returns The transformation matrix of the instance.\r\n   */\r\n  public getMatrixAt(id: number, matrix = _tempMat4): Matrix4 {\r\n    return matrix.fromArray(this.matricesTexture._data, id * 16);\r\n  }\r\n\r\n  /**\r\n   * Retrieves the position of a specific instance.\r\n   * @param index The index of the instance.\r\n   * @param target Optional `Vector3` to store the result.\r\n   * @returns The position of the instance as a `Vector3`.\r\n   */\r\n  public getPositionAt(index: number, target = _position): Vector3 {\r\n    const offset = index * 16;\r\n    const array = this.matricesTexture._data;\r\n\r\n    target.x = array[offset + 12];\r\n    target.y = array[offset + 13];\r\n    target.z = array[offset + 14];\r\n\r\n    return target;\r\n  }\r\n\r\n  /** @internal */\r\n  public getPositionAndMaxScaleOnAxisAt(index: number, position: Vector3): number {\r\n    const offset = index * 16;\r\n    const array = this.matricesTexture._data;\r\n\r\n    const te0 = array[offset + 0];\r\n    const te1 = array[offset + 1];\r\n    const te2 = array[offset + 2];\r\n    const scaleXSq = te0 * te0 + te1 * te1 + te2 * te2;\r\n\r\n    const te4 = array[offset + 4];\r\n    const te5 = array[offset + 5];\r\n    const te6 = array[offset + 6];\r\n    const scaleYSq = te4 * te4 + te5 * te5 + te6 * te6;\r\n\r\n    const te8 = array[offset + 8];\r\n    const te9 = array[offset + 9];\r\n    const te10 = array[offset + 10];\r\n    const scaleZSq = te8 * te8 + te9 * te9 + te10 * te10;\r\n\r\n    position.x = array[offset + 12];\r\n    position.y = array[offset + 13];\r\n    position.z = array[offset + 14];\r\n\r\n    return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));\r\n  }\r\n\r\n  /** @internal */\r\n  public applyMatrixAtToSphere(index: number, sphere: Sphere, center: Vector3, radius: number): void {\r\n    const offset = index * 16;\r\n    const array = this.matricesTexture._data;\r\n\r\n    const te0 = array[offset + 0];\r\n    const te1 = array[offset + 1];\r\n    const te2 = array[offset + 2];\r\n    const te3 = array[offset + 3];\r\n    const te4 = array[offset + 4];\r\n    const te5 = array[offset + 5];\r\n    const te6 = array[offset + 6];\r\n    const te7 = array[offset + 7];\r\n    const te8 = array[offset + 8];\r\n    const te9 = array[offset + 9];\r\n    const te10 = array[offset + 10];\r\n    const te11 = array[offset + 11];\r\n    const te12 = array[offset + 12];\r\n    const te13 = array[offset + 13];\r\n    const te14 = array[offset + 14];\r\n    const te15 = array[offset + 15];\r\n\r\n    const position = sphere.center;\r\n    const x = center.x;\r\n    const y = center.y;\r\n    const z = center.z;\r\n    const w = 1 / (te3 * x + te7 * y + te11 * z + te15);\r\n\r\n    position.x = (te0 * x + te4 * y + te8 * z + te12) * w;\r\n    position.y = (te1 * x + te5 * y + te9 * z + te13) * w;\r\n    position.z = (te2 * x + te6 * y + te10 * z + te14) * w;\r\n\r\n    const scaleXSq = te0 * te0 + te1 * te1 + te2 * te2;\r\n    const scaleYSq = te4 * te4 + te5 * te5 + te6 * te6;\r\n    const scaleZSq = te8 * te8 + te9 * te9 + te10 * te10;\r\n\r\n    sphere.radius = radius * Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));\r\n  }\r\n\r\n  /**\r\n   * Sets the visibility of a specific instance.\r\n   * @param id The index of the instance.\r\n   * @param visible Whether the instance should be visible.\r\n   */\r\n  public setVisibilityAt(id: number, visible: boolean): void {\r\n    this.availabilityArray[id * 2] = visible;\r\n    this._indexArrayNeedsUpdate = true;\r\n  }\r\n\r\n  /**\r\n   * Gets the visibility of a specific instance.\r\n   * @param id The index of the instance.\r\n   * @returns Whether the instance is visible.\r\n   */\r\n  public getVisibilityAt(id: number): boolean {\r\n    return this.availabilityArray[id * 2];\r\n  }\r\n\r\n  /**\r\n   * Sets the availability of a specific instance.\r\n   * @param id The index of the instance.\r\n   * @param active Whether the instance is active (not deleted).\r\n   */\r\n  public setActiveAt(id: number, active: boolean): void {\r\n    this.availabilityArray[id * 2 + 1] = active;\r\n    this._indexArrayNeedsUpdate = true;\r\n  }\r\n\r\n  /**\r\n   * Gets the availability of a specific instance.\r\n   * @param id The index of the instance.\r\n   * @returns Whether the instance is active (not deleted).\r\n   */\r\n  public getActiveAt(id: number): boolean {\r\n    return this.availabilityArray[id * 2 + 1];\r\n  }\r\n\r\n  /**\r\n   * Indicates if a specific instance is visible and active.\r\n   * @param id The index of the instance.\r\n   * @returns Whether the instance is visible and active.\r\n   */\r\n  public getActiveAndVisibilityAt(id: number): boolean {\r\n    const offset = id * 2;\r\n    const availabilityArray = this.availabilityArray;\r\n    return availabilityArray[offset] && availabilityArray[offset + 1];\r\n  }\r\n\r\n  /**\r\n   * Set if a specific instance is visible and active.\r\n   * @param id The index of the instance.\r\n   * @param value Whether the instance is active and active (not deleted).\r\n   */\r\n  public setActiveAndVisibilityAt(id: number, value: boolean): void {\r\n    const offset = id * 2;\r\n    const availabilityArray = this.availabilityArray;\r\n    availabilityArray[offset] = value;\r\n    availabilityArray[offset + 1] = value;\r\n    this._indexArrayNeedsUpdate = true;\r\n  }\r\n\r\n  /**\r\n   * Sets the color of a specific instance.\r\n   * @param id The index of the instance.\r\n   * @param color The color to assign to the instance.\r\n   */\r\n  public setColorAt(id: number, color: ColorRepresentation): void {\r\n    if (this.colorsTexture === null) {\r\n      this.initColorsTexture();\r\n    }\r\n\r\n    if ((color as Color).isColor) {\r\n      (color as Color).toArray(this.colorsTexture._data, id * 4);\r\n    } else {\r\n      _tempCol.set(color).toArray(this.colorsTexture._data, id * 4);\r\n    }\r\n\r\n    this.colorsTexture.enqueueUpdate(id);\r\n  }\r\n\r\n  /**\r\n   * Gets the color of a specific instance.\r\n   * @param id The index of the instance.\r\n   * @param color Optional `Color` to store the result.\r\n   * @returns The color of the instance.\r\n   */\r\n  public getColorAt(id: number, color = _tempCol): Color {\r\n    return color.fromArray(this.colorsTexture._data, id * 4);\r\n  }\r\n\r\n  /**\r\n   * Sets the opacity of a specific instance.\r\n   * @param id The index of the instance.\r\n   * @param value The opacity value to assign.\r\n   */\r\n  public setOpacityAt(id: number, value: number): void {\r\n    if (!this._useOpacity) {\r\n      if (this.colorsTexture === null) {\r\n        this.initColorsTexture();\r\n      } else {\r\n        this.materialsNeedsUpdate();\r\n      }\r\n      this._useOpacity = true;\r\n    }\r\n\r\n    this.colorsTexture._data[id * 4 + 3] = value;\r\n    this.colorsTexture.enqueueUpdate(id);\r\n  }\r\n\r\n  /**\r\n   * Gets the opacity of a specific instance.\r\n   * @param id The index of the instance.\r\n   * @returns The opacity of the instance.\r\n   */\r\n  public getOpacityAt(id: number): number {\r\n    if (!this._useOpacity) return 1;\r\n    return this.colorsTexture._data[id * 4 + 3];\r\n  }\r\n\r\n  /**\r\n   * Copies `position`, `quaternion`, and `scale` of a specific instance to the specified target `Object3D`.\r\n   * @param id The index of the instance.\r\n   * @param target The `Object3D` where to copy transformation data.\r\n   */\r\n  public copyTo(id: number, target: Object3D): void {\r\n    this.getMatrixAt(id, target.matrix).decompose(target.position, target.quaternion, target.scale);\r\n  }\r\n\r\n  /**\r\n   * Computes the bounding box that encloses all instances, and updates the `boundingBox` attribute.\r\n   */\r\n  public computeBoundingBox(): void {\r\n    const geometry = this._geometry;\r\n    const count = this._instancesArrayCount;\r\n\r\n    this.boundingBox ??= new Box3();\r\n    if (geometry.boundingBox === null) geometry.computeBoundingBox();\r\n\r\n    const geoBoundingBox = geometry.boundingBox;\r\n    const boundingBox = this.boundingBox;\r\n\r\n    boundingBox.makeEmpty();\r\n\r\n    for (let i = 0; i < count; i++) {\r\n      if (!this.getActiveAt(i)) continue;\r\n      _box3.copy(geoBoundingBox).applyMatrix4(this.getMatrixAt(i));\r\n      boundingBox.union(_box3);\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Computes the bounding sphere that encloses all instances, and updates the `boundingSphere` attribute.\r\n   */\r\n  public computeBoundingSphere(): void {\r\n    const geometry = this._geometry;\r\n    const count = this._instancesArrayCount;\r\n\r\n    this.boundingSphere ??= new Sphere();\r\n    if (geometry.boundingSphere === null) geometry.computeBoundingSphere();\r\n\r\n    const geoBoundingSphere = geometry.boundingSphere;\r\n    const boundingSphere = this.boundingSphere;\r\n\r\n    boundingSphere.makeEmpty();\r\n\r\n    for (let i = 0; i < count; i++) {\r\n      if (!this.getActiveAt(i)) continue;\r\n      _sphere.copy(geoBoundingSphere).applyMatrix4(this.getMatrixAt(i));\r\n      boundingSphere.union(_sphere);\r\n    }\r\n  }\r\n\r\n  public override clone(recursive?: boolean): this { // wrong three d.ts\r\n    const params: InstancedMesh2Params = {\r\n      capacity: this._capacity,\r\n      renderer: this._renderer,\r\n      allowsEuler: this._allowsEuler,\r\n      createEntities: this._createEntities\r\n    };\r\n    return new (this as any).constructor(this.geometry, this.material, params).copy(this, recursive);\r\n  }\r\n\r\n  public override copy(source: InstancedMesh2, recursive?: boolean): this {\r\n    super.copy(source, recursive);\r\n\r\n    this.count = source._capacity;\r\n    this._instancesCount = source._instancesCount;\r\n    this._instancesArrayCount = source._instancesArrayCount;\r\n    this._capacity = source._capacity;\r\n\r\n    if (source.boundingBox !== null) this.boundingBox = source.boundingBox.clone();\r\n    if (source.boundingSphere !== null) this.boundingSphere = source.boundingSphere.clone();\r\n\r\n    this.matricesTexture = source.matricesTexture.clone(); // TODO we can avoid cloning it because it already exists\r\n    this.matricesTexture.image.data = (this.matricesTexture.image.data as TypedArray).slice();\r\n\r\n    if (source.colorsTexture !== null) {\r\n      this.colorsTexture = source.colorsTexture.clone();\r\n      this.colorsTexture.image.data = (this.colorsTexture.image.data as TypedArray).slice();\r\n    }\r\n\r\n    if (source.uniformsTexture !== null) {\r\n      this.uniformsTexture = source.uniformsTexture.clone();\r\n      this.uniformsTexture.image.data = (this.uniformsTexture.image.data as TypedArray).slice();\r\n    }\r\n\r\n    if (source.morphTexture !== null) {\r\n      this.morphTexture = source.morphTexture.clone();\r\n      this.morphTexture.image.data = (this.morphTexture.image.data as TypedArray).slice();\r\n    }\r\n\r\n    if (source.boneTexture !== null) {\r\n      this.boneTexture = source.boneTexture.clone();\r\n      this.boneTexture.image.data = (this.boneTexture.image.data as TypedArray).slice(); // TODO check if they fix d.ts\r\n    }\r\n\r\n    // TODO copies and handle LOD?\r\n\r\n    return this;\r\n  }\r\n\r\n  /**\r\n   * Frees the GPU-related resources allocated.\r\n   */\r\n  public dispose(): void {\r\n    this.dispatchEvent<any>({ type: 'dispose' });\r\n\r\n    this.matricesTexture.dispose();\r\n    this.colorsTexture?.dispose();\r\n    this.morphTexture?.dispose();\r\n    this.boneTexture?.dispose();\r\n    this.uniformsTexture?.dispose();\r\n  }\r\n\r\n  public override updateMatrixWorld(force?: boolean): void {\r\n    super.updateMatrixWorld(force);\r\n\r\n    if (!this.bindMatrixInverse) return;\r\n\r\n    if (this.bindMode === AttachedBindMode) {\r\n      this.bindMatrixInverse.copy(this.matrixWorld).invert();\r\n    } else if (this.bindMode === DetachedBindMode) {\r\n      this.bindMatrixInverse.copy(this.bindMatrix).invert();\r\n    } else {\r\n      console.warn('Unrecognized bindMode: ' + this.bindMode);\r\n    }\r\n  }\r\n}\r\n\r\nconst _defaultCapacity = 1000;\r\nconst _box3 = new Box3();\r\nconst _sphere = new Sphere();\r\nconst _tempMat4 = new Matrix4();\r\nconst _tempCol = new Color();\r\nconst _position = new Vector3();\r\n\r\n/** @internal */\r\ndeclare module 'three' {\r\n  interface Material {\r\n    defines: { [key: string]: any };\r\n  }\r\n}\r\n","import { DataTexture, FloatType, RedFormat, TypedArray } from 'three';\r\nimport { InstancedMesh2 } from '../InstancedMesh2.js';\r\n\r\n// TODO: add optimize method to reduce buffer size and remove instances objects\r\n\r\ndeclare module '../InstancedMesh2.js' {\r\n  interface InstancedMesh2 {\r\n    /**\r\n     * Resizes internal buffers to accommodate the specified capacity.\r\n     * This ensures that the buffers are large enough to handle the required number of instances.\r\n     * @param capacity The new capacity of the buffers.\r\n     * @returns The current `InstancedMesh2` instance.\r\n     */\r\n    resizeBuffers(capacity: number): this;\r\n    /** @internal */ setInstancesArrayCount(count: number): void;\r\n  }\r\n}\r\n\r\nInstancedMesh2.prototype.resizeBuffers = function (capacity: number): InstancedMesh2 {\r\n  const oldCapacity = this._capacity;\r\n  this._capacity = capacity;\r\n  const minCapacity = Math.min(capacity, oldCapacity);\r\n\r\n  if (this.instanceIndex) {\r\n    const indexArray = new Uint32Array(capacity);\r\n    indexArray.set(new Uint32Array(this.instanceIndex.array.buffer, 0, minCapacity)); // safely copy TODO method\r\n    this.instanceIndex.array = indexArray;\r\n  }\r\n\r\n  if (this.LODinfo) {\r\n    for (const obj of this.LODinfo.objects) {\r\n      obj._capacity = capacity;\r\n\r\n      if (obj.instanceIndex) {\r\n        const indexArray = new Uint32Array(capacity);\r\n        indexArray.set(new Uint32Array(obj.instanceIndex.array.buffer, 0, minCapacity)); // safely copy TODO method\r\n        obj.instanceIndex.array = indexArray;\r\n      }\r\n    }\r\n  }\r\n\r\n  this.availabilityArray.length = capacity * 2;\r\n\r\n  this.matricesTexture.resize(capacity);\r\n\r\n  if (this.colorsTexture) {\r\n    this.colorsTexture.resize(capacity);\r\n    if (capacity > oldCapacity) {\r\n      this.colorsTexture._data.fill(1, oldCapacity * 4);\r\n    }\r\n  }\r\n\r\n  if (this.morphTexture) { // test it\r\n    const oldArray = this.morphTexture.image.data as TypedArray; // TODO check if they fix d.ts\r\n    const size = oldArray.length / oldCapacity;\r\n    this.morphTexture.dispose();\r\n    this.morphTexture = new DataTexture(new Float32Array(size * capacity), size, capacity, RedFormat, FloatType);\r\n    (this.morphTexture.image.data as TypedArray).set(oldArray); // FIX if reduce\r\n  }\r\n\r\n  this.uniformsTexture?.resize(capacity);\r\n\r\n  return this;\r\n};\r\n\r\nInstancedMesh2.prototype.setInstancesArrayCount = function (count: number): void {\r\n  if (count < this._instancesArrayCount) {\r\n    const bvh = this.bvh;\r\n    if (bvh) {\r\n      for (let i = this._instancesArrayCount - 1; i >= count; i--) {\r\n        if (!this.getActiveAt(i)) continue;\r\n        bvh.delete(i);\r\n      }\r\n    }\r\n\r\n    this._instancesArrayCount = count;\r\n    return;\r\n  }\r\n\r\n  if (count > this._capacity) {\r\n    let newCapacity = this._capacity + (this._capacity >> 1) + 512;\r\n    while (newCapacity < count) {\r\n      newCapacity += (newCapacity >> 1) + 512;\r\n    }\r\n\r\n    this.resizeBuffers(newCapacity);\r\n  }\r\n\r\n  const start = this._instancesArrayCount;\r\n  this._instancesArrayCount = count;\r\n  if (this._createEntities) this.createEntities(start);\r\n};\r\n","import { Material } from 'three';\r\nimport { radixSort, RadixSortOptions } from 'three/addons/utils/SortUtils.js';\r\nimport { InstancedMesh2 } from '../core/InstancedMesh2.js';\r\nimport { InstancedRenderItem } from '../core/utils/InstancedRenderList.js';\r\n\r\ntype radixSortCallback = (list: InstancedRenderItem[]) => void;\r\n\r\n/**\r\n * Creates a radix sort function specifically for sorting `InstancedMesh2` instances.\r\n * The sorting is based on the `depth` property of each `InstancedRenderItem`.\r\n * This function dynamically adjusts for transparent materials by reversing the sort order if necessary.\r\n * @param target The `InstancedMesh2` instance that contains the instances to be sorted.\r\n * @returns A radix sort function.\r\n */\r\n// Reference: https://github.com/mrdoob/three.js/blob/master/examples/webgl_mesh_batch.html#L291\r\nexport function createRadixSort(target: InstancedMesh2): radixSortCallback {\r\n  const options: RadixSortOptions<InstancedRenderItem> = {\r\n    get: (el) => el.depthSort,\r\n    aux: new Array(target._capacity),\r\n    reversed: false\r\n  };\r\n\r\n  return function sortFunction(list: InstancedRenderItem[]): void {\r\n    options.reversed = !!(target.material as Material)?.transparent; // multimaterials are considered opaque\r\n\r\n    if (target._capacity > options.aux.length) {\r\n      options.aux.length = target._capacity;\r\n    }\r\n\r\n    let minZ = Infinity;\r\n    let maxZ = -Infinity;\r\n\r\n    for (const { depth } of list) {\r\n      if (depth > maxZ) maxZ = depth;\r\n      if (depth < minZ) minZ = depth;\r\n    }\r\n\r\n    const depthDelta = maxZ - minZ;\r\n    const factor = (2 ** 32 - 1) / depthDelta;\r\n\r\n    for (const item of list) {\r\n      item.depthSort = (item.depth - minZ) * factor;\r\n    }\r\n\r\n    radixSort(list, options);\r\n  };\r\n}\r\n\r\n/** @internal */\r\nexport function sortOpaque(a: InstancedRenderItem, b: InstancedRenderItem): number {\r\n  return a.depth - b.depth;\r\n}\r\n\r\n/** @internal */\r\nexport function sortTransparent(a: InstancedRenderItem, b: InstancedRenderItem): number {\r\n  return b.depth - a.depth;\r\n}\r\n","export type InstancedRenderItem = { index: number; depth: number; depthSort: number };\r\n\r\n/**\r\n * A class that creates and manages a list of render items, used to determine the rendering order based on depth.\r\n */\r\nexport class InstancedRenderList {\r\n  /**\r\n   * The main array that holds the list of render items for instanced rendering.\r\n   */\r\n  public array: InstancedRenderItem[] = [];\r\n  protected pool: InstancedRenderItem[] = [];\r\n\r\n  /**\r\n   * Adds a new render item to the list.\r\n   * @param depth The depth value used for sorting or determining the rendering order.\r\n   * @param index The unique instance id of the render item.\r\n   */\r\n  public push(depth: number, index: number): void {\r\n    const pool = this.pool;\r\n    const list = this.array;\r\n    const count = list.length;\r\n\r\n    if (count >= pool.length) {\r\n      pool.push({ depth: null, index: null, depthSort: null });\r\n    }\r\n\r\n    const item = pool[count];\r\n    item.depth = depth;\r\n    item.index = index;\r\n\r\n    list.push(item);\r\n  }\r\n\r\n  /**\r\n   * Resets the render list by clearing the array.\r\n   */\r\n  public reset(): void {\r\n    this.array.length = 0;\r\n  }\r\n}\r\n","import { BVHNode } from 'bvh.js';\r\nimport { Camera, Frustum, Material, Matrix4, Sphere, Vector3 } from 'three';\r\nimport { sortOpaque, sortTransparent } from '../../utils/SortingUtils.js';\r\nimport { InstancedMesh2 } from '../InstancedMesh2.js';\r\nimport { InstancedRenderItem, InstancedRenderList } from '../utils/InstancedRenderList.js';\r\nimport { LODRenderList } from './LOD.js';\r\n\r\n// TODO: fix shadowMap LOD sorting objects?\r\n\r\n/**\r\n * A custom sorting callback for render items.\r\n */\r\nexport type CustomSortCallback = (list: InstancedRenderItem[]) => void;\r\n\r\n/**\r\n * Callback invoked when an instance is within the frustum.\r\n * @param index The index of the instance.\r\n * @param camera The camera used for rendering.\r\n * @param cameraLOD The camera used for LOD calculations (provided only if LODs are initialized).\r\n * @param LODindex The LOD level of the instance (provided only if LODs are initialized and `sortObjects` is false).\r\n * @returns True if the instance should be rendered, false otherwise.\r\n */\r\nexport type OnFrustumEnterCallback = (index: number, camera: Camera, cameraLOD?: Camera, LODindex?: number) => boolean;\r\n\r\ndeclare module '../InstancedMesh2.js' {\r\n  interface InstancedMesh2 {\r\n    /**\r\n     * Performs frustum culling and manages LOD visibility.\r\n     * @param camera The main camera used for rendering.\r\n     * @param cameraLOD An optional camera for LOD calculations. Defaults to the main camera.\r\n     */\r\n    performFrustumCulling(camera: Camera, cameraLOD?: Camera): void;\r\n\r\n    /** @internal */ updateLastRenderInfo(frame: number, camera: Camera, shadowCamera: Camera | null): void;\r\n    /** @internal */ frustumCullingAlreadyPerformed(frame: number, camera: Camera, shadowCamera: Camera | null): boolean;\r\n    /** @internal */ frustumCulling(camera: Camera): void;\r\n    /** @internal */ updateIndexArray(): void;\r\n    /** @internal */ updateRenderList(): void;\r\n    /** @internal */ BVHCulling(camera: Camera): void;\r\n    /** @internal */ linearCulling(camera: Camera): void;\r\n\r\n    /** @internal */ frustumCullingLOD(LODrenderList: LODRenderList, camera: Camera, cameraLOD: Camera): void;\r\n    /** @internal */ BVHCullingLOD(LODrenderList: LODRenderList, indexes: Uint32Array[], sortObjects: boolean, camera: Camera, cameraLOD: Camera): void;\r\n    /** @internal */ linearCullingLOD(LODrenderList: LODRenderList, indexes: Uint32Array[], sortObjects: boolean, camera: Camera, cameraLOD: Camera): void;\r\n  }\r\n}\r\n\r\nconst _frustum = new Frustum();\r\nconst _renderList = new InstancedRenderList();\r\nconst _projScreenMatrix = new Matrix4();\r\nconst _invMatrixWorld = new Matrix4();\r\nconst _forward = new Vector3();\r\nconst _cameraPos = new Vector3();\r\nconst _cameraLODPos = new Vector3();\r\nconst _position = new Vector3();\r\nconst _sphere = new Sphere();\r\n\r\nInstancedMesh2.prototype.performFrustumCulling = function (camera: Camera, cameraLOD = camera) {\r\n  const mainMesh = this._parentLOD ?? this;\r\n  const LODinfo = mainMesh.LODinfo;\r\n  let LODrenderList: LODRenderList;\r\n\r\n  if (LODinfo) {\r\n    const isShadowRendering = camera !== cameraLOD;\r\n    LODrenderList = !isShadowRendering ? LODinfo.render : (LODinfo.shadowRender ?? LODinfo.render);\r\n\r\n    for (const object of LODinfo.objects) {\r\n      object.count = 0;\r\n    }\r\n  } else if (mainMesh._perObjectFrustumCulled || mainMesh._sortObjects) {\r\n    mainMesh.count = 0;\r\n  }\r\n\r\n  if (mainMesh._instancesArrayCount === 0) return;\r\n\r\n  if (LODrenderList?.levels.length > 0) mainMesh.frustumCullingLOD(LODrenderList, camera, cameraLOD);\r\n  else mainMesh.frustumCulling(camera);\r\n};\r\n\r\nInstancedMesh2.prototype.updateLastRenderInfo = function (frame, camera, shadowCamera) {\r\n  const lastRenderInfo = this._lastRenderInfo;\r\n  lastRenderInfo.frame = frame;\r\n  lastRenderInfo.camera = camera;\r\n  lastRenderInfo.shadowCamera = shadowCamera;\r\n};\r\n\r\nInstancedMesh2.prototype.frustumCullingAlreadyPerformed = function (frame, camera, shadowCamera) {\r\n  const lastRenderInfo = this._lastRenderInfo;\r\n  if (lastRenderInfo.frame === frame && lastRenderInfo.camera === camera && lastRenderInfo.shadowCamera === shadowCamera) {\r\n    return true;\r\n  }\r\n\r\n  this.updateLastRenderInfo(frame, camera, shadowCamera);\r\n  return false;\r\n};\r\n\r\nInstancedMesh2.prototype.frustumCulling = function (camera: Camera) {\r\n  const sortObjects = this._sortObjects;\r\n  const perObjectFrustumCulled = this._perObjectFrustumCulled;\r\n  const array = this.instanceIndex.array;\r\n\r\n  this.instanceIndex._needsUpdate = true; // TODO improve\r\n\r\n  if (!perObjectFrustumCulled && !sortObjects) {\r\n    this.updateIndexArray();\r\n    return;\r\n  }\r\n\r\n  if (sortObjects) {\r\n    _invMatrixWorld.copy(this.matrixWorld).invert();\r\n    _cameraPos.setFromMatrixPosition(camera.matrixWorld).applyMatrix4(_invMatrixWorld);\r\n    _forward.set(0, 0, -1).transformDirection(camera.matrixWorld).transformDirection(_invMatrixWorld);\r\n  }\r\n\r\n  if (!perObjectFrustumCulled) {\r\n    this.updateRenderList();\r\n  } else {\r\n    _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse).multiply(this.matrixWorld);\r\n\r\n    if (this.bvh) this.BVHCulling(camera);\r\n    else this.linearCulling(camera);\r\n  }\r\n\r\n  if (sortObjects) {\r\n    const customSort = this.customSort;\r\n\r\n    if (customSort === null) {\r\n      _renderList.array.sort(!(this.material as Material)?.transparent ? sortOpaque : sortTransparent);\r\n    } else {\r\n      customSort(_renderList.array);\r\n    }\r\n\r\n    const list = _renderList.array;\r\n    const count = list.length;\r\n    for (let i = 0; i < count; i++) {\r\n      array[i] = list[i].index;\r\n    }\r\n\r\n    this.count = count;\r\n    _renderList.reset();\r\n  }\r\n};\r\n\r\nInstancedMesh2.prototype.updateIndexArray = function () {\r\n  if (!this._indexArrayNeedsUpdate) return;\r\n\r\n  const array = this.instanceIndex.array;\r\n  const instancesArrayCount = this._instancesArrayCount;\r\n  let count = 0;\r\n\r\n  for (let i = 0; i < instancesArrayCount; i++) {\r\n    if (this.getActiveAndVisibilityAt(i)) {\r\n      array[count++] = i;\r\n    }\r\n  }\r\n\r\n  this.count = count;\r\n  this._indexArrayNeedsUpdate = false;\r\n};\r\n\r\nInstancedMesh2.prototype.updateRenderList = function () {\r\n  const instancesArrayCount = this._instancesArrayCount;\r\n\r\n  for (let i = 0; i < instancesArrayCount; i++) {\r\n    if (this.getActiveAndVisibilityAt(i)) {\r\n      const depth = this.getPositionAt(i).sub(_cameraPos).dot(_forward);\r\n      _renderList.push(depth, i);\r\n    }\r\n  }\r\n};\r\n\r\nInstancedMesh2.prototype.BVHCulling = function (camera: Camera) {\r\n  const array = this.instanceIndex.array;\r\n  const instancesArrayCount = this._instancesArrayCount;\r\n  const sortObjects = this._sortObjects;\r\n  const onFrustumEnter = this.onFrustumEnter;\r\n  let count = 0;\r\n\r\n  this.bvh.frustumCulling(_projScreenMatrix, (node: BVHNode<{}, number>) => {\r\n    const index = node.object;\r\n\r\n    // TODO check if (index < instancesArrayCount) is still necessary after last update\r\n\r\n    // we don't check if active because we remove inactive instances from BVH\r\n    if (index < instancesArrayCount && this.getVisibilityAt(index) && (!onFrustumEnter || onFrustumEnter(index, camera))) {\r\n      if (sortObjects) {\r\n        const depth = this.getPositionAt(index).sub(_cameraPos).dot(_forward);\r\n        _renderList.push(depth, index);\r\n      } else {\r\n        array[count++] = index;\r\n      }\r\n    }\r\n  });\r\n\r\n  this.count = count;\r\n};\r\n\r\nInstancedMesh2.prototype.linearCulling = function (camera: Camera) {\r\n  const array = this.instanceIndex.array;\r\n  if (!this.geometry.boundingSphere) this.geometry.computeBoundingSphere();\r\n  const bSphere = this._geometry.boundingSphere;\r\n  const radius = bSphere.radius;\r\n  const center = bSphere.center;\r\n  const instancesArrayCount = this._instancesArrayCount;\r\n  const geometryCentered = center.x === 0 && center.y === 0 && center.z === 0;\r\n  const sortObjects = this._sortObjects;\r\n  const onFrustumEnter = this.onFrustumEnter;\r\n  let count = 0;\r\n\r\n  _frustum.setFromProjectionMatrix(_projScreenMatrix);\r\n\r\n  for (let i = 0; i < instancesArrayCount; i++) {\r\n    if (!this.getActiveAndVisibilityAt(i)) continue;\r\n\r\n    if (geometryCentered) {\r\n      const maxScale = this.getPositionAndMaxScaleOnAxisAt(i, _sphere.center);\r\n      _sphere.radius = radius * maxScale;\r\n    } else {\r\n      this.applyMatrixAtToSphere(i, _sphere, center, radius);\r\n    }\r\n\r\n    if (_frustum.intersectsSphere(_sphere) && (!onFrustumEnter || onFrustumEnter(i, camera))) {\r\n      if (sortObjects) {\r\n        const depth = _position.subVectors(_sphere.center, _cameraPos).dot(_forward);\r\n        _renderList.push(depth, i);\r\n      } else {\r\n        array[count++] = i;\r\n      }\r\n    }\r\n  }\r\n\r\n  this.count = count;\r\n};\r\n\r\nInstancedMesh2.prototype.frustumCullingLOD = function (LODrenderList: LODRenderList, camera: Camera, cameraLOD: Camera) {\r\n  const { count, levels } = LODrenderList;\r\n\r\n  for (let i = 0; i < levels.length; i++) {\r\n    if (!levels[i].object.instanceIndex) return;\r\n\r\n    count[i] = 0;\r\n    levels[i].object.instanceIndex._needsUpdate = true; // TODO improve\r\n  }\r\n\r\n  const isShadowRendering = camera !== cameraLOD;\r\n  const sortObjects = !isShadowRendering && this._sortObjects; // sort is disabled when render shadows\r\n\r\n  _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse).multiply(this.matrixWorld);\r\n  _invMatrixWorld.copy(this.matrixWorld).invert();\r\n  _cameraPos.setFromMatrixPosition(camera.matrixWorld).applyMatrix4(_invMatrixWorld);\r\n  _cameraLODPos.setFromMatrixPosition(cameraLOD.matrixWorld).applyMatrix4(_invMatrixWorld);\r\n\r\n  const indexes = LODrenderList.levels.map((x) => x.object.instanceIndex.array) as Uint32Array[];\r\n\r\n  if (this.bvh) this.BVHCullingLOD(LODrenderList, indexes, sortObjects, camera, cameraLOD);\r\n  else this.linearCullingLOD(LODrenderList, indexes, sortObjects, camera, cameraLOD);\r\n\r\n  if (sortObjects) {\r\n    const customSort = this.customSort;\r\n    const list = _renderList.array;\r\n    let levelIndex = 0;\r\n    let levelDistance = levels[1].distance;\r\n\r\n    if (customSort === null) {\r\n      list.sort(!(levels[0].object.material as Material)?.transparent ? sortOpaque : sortTransparent); // TODO improve multimaterial handling\r\n    } else {\r\n      customSort(list);\r\n    }\r\n\r\n    for (let i = 0, l = list.length; i < l; i++) {\r\n      const item = list[i];\r\n\r\n      if (item.depth > levelDistance) {\r\n        levelIndex++;\r\n        levelDistance = levels[levelIndex + 1]?.distance ?? Infinity; // improve this condition and use for of instead\r\n      }\r\n\r\n      indexes[levelIndex][count[levelIndex]++] = item.index;\r\n    }\r\n\r\n    _renderList.reset();\r\n  }\r\n\r\n  for (let i = 0; i < levels.length; i++) {\r\n    const object = levels[i].object;\r\n    object.count = count[i];\r\n  }\r\n};\r\n\r\nInstancedMesh2.prototype.BVHCullingLOD = function (LODrenderList: LODRenderList, indexes: Uint32Array[], sortObjects: boolean, camera: Camera, cameraLOD: Camera) {\r\n  const { count, levels } = LODrenderList;\r\n  const instancesArrayCount = this._instancesArrayCount;\r\n  const onFrustumEnter = this.onFrustumEnter;\r\n\r\n  if (sortObjects) {\r\n    this.bvh.frustumCulling(_projScreenMatrix, (node: BVHNode<{}, number>) => {\r\n      const index = node.object;\r\n      // we don't check if active because we remove inactive instances from BVH\r\n      if (index < instancesArrayCount && this.getVisibilityAt(index) && (!onFrustumEnter || onFrustumEnter(index, camera, cameraLOD))) {\r\n        const distance = this.getPositionAt(index).distanceToSquared(_cameraLODPos);\r\n        _renderList.push(distance, index);\r\n      }\r\n    });\r\n  } else {\r\n    this.bvh.frustumCullingLOD(_projScreenMatrix, _cameraLODPos, levels, (node: BVHNode<{}, number>, level: number) => {\r\n      const index = node.object;\r\n      if (index < instancesArrayCount && this.getVisibilityAt(index)) {\r\n        if (level === null) {\r\n          const distance = this.getPositionAt(index).distanceToSquared(_cameraLODPos); // distance can be get by BVH, but is not the distance from center\r\n          level = this.getObjectLODIndexForDistance(levels, distance);\r\n        }\r\n\r\n        if (!onFrustumEnter || onFrustumEnter(index, camera, cameraLOD, level)) {\r\n          indexes[level][count[level]++] = index;\r\n        }\r\n      }\r\n    });\r\n  }\r\n};\r\n\r\nInstancedMesh2.prototype.linearCullingLOD = function (LODrenderList: LODRenderList, indexes: Uint32Array[], sortObjects: boolean, camera: Camera, cameraLOD: Camera) {\r\n  const { count, levels } = LODrenderList;\r\n  if (!this.geometry.boundingSphere) this.geometry.computeBoundingSphere();\r\n  const bSphere = this._geometry.boundingSphere;\r\n  const radius = bSphere.radius;\r\n  const center = bSphere.center;\r\n  const instancesArrayCount = this._instancesArrayCount;\r\n  const geometryCentered = center.x === 0 && center.y === 0 && center.z === 0;\r\n  const onFrustumEnter = this.onFrustumEnter;\r\n\r\n  _frustum.setFromProjectionMatrix(_projScreenMatrix);\r\n\r\n  for (let i = 0; i < instancesArrayCount; i++) {\r\n    if (!this.getActiveAndVisibilityAt(i)) continue;\r\n\r\n    if (geometryCentered) {\r\n      const maxScale = this.getPositionAndMaxScaleOnAxisAt(i, _sphere.center);\r\n      _sphere.radius = radius * maxScale;\r\n    } else {\r\n      this.applyMatrixAtToSphere(i, _sphere, center, radius);\r\n    }\r\n\r\n    if (_frustum.intersectsSphere(_sphere)) {\r\n      if (sortObjects) {\r\n        if (!onFrustumEnter || onFrustumEnter(i, camera, cameraLOD)) {\r\n          const distance = _sphere.center.distanceToSquared(_cameraLODPos);\r\n          _renderList.push(distance, i);\r\n        }\r\n      } else {\r\n        const distance = _sphere.center.distanceToSquared(_cameraLODPos);\r\n        const levelIndex = this.getObjectLODIndexForDistance(levels, distance);\r\n\r\n        if (!onFrustumEnter || onFrustumEnter(i, camera, cameraLOD, levelIndex)) {\r\n          indexes[levelIndex][count[levelIndex]++] = i;\r\n        }\r\n      }\r\n    }\r\n  }\r\n};\r\n","import { InstancedEntity } from '../InstancedEntity.js';\r\nimport { InstancedMesh2 } from '../InstancedMesh2.js';\r\n\r\n// TODO: optimize method to fill 'holes'.\r\n\r\n/**\r\n * Represents an extended entity type with custom data.\r\n */\r\nexport type Entity<T> = InstancedEntity & T;\r\n/**\r\n * A callback function used to update or initialize an entity.\r\n */\r\nexport type UpdateEntityCallback<T = InstancedEntity> = (obj: Entity<T>, index: number) => void;\r\n\r\ndeclare module '../InstancedMesh2.js' {\r\n  interface InstancedMesh2<TData = {}> {\r\n    /**\r\n     * Updates instances by applying a callback function to each instance. It calls `updateMatrix` for each instance.\r\n     * @param onUpdate A callback function to update each entity.\r\n     * @returns The current `InstancedMesh2` instance.\r\n     */\r\n    updateInstances(onUpdate: UpdateEntityCallback<Entity<TData>>): this;\r\n    /**\r\n     * Updates instances position by applying a callback function to each instance. It calls `updateMatrixPosition` for each instance.\r\n     * This method updates only the position attributes of the matrix.\r\n     * @param onUpdate A callback function to update each entity.\r\n     * @returns The current `InstancedMesh2` instance.\r\n     */\r\n    updateInstancesPosition(onUpdate: UpdateEntityCallback<Entity<TData>>): this;\r\n    /**\r\n     * Adds new instances and optionally initializes them using a callback function.\r\n     * @param count The number of new instances to add.\r\n     * @param onCreation An optional callback to initialize each new entity.\r\n     * @returns The current `InstancedMesh2` instance.\r\n     */\r\n    addInstances(count: number, onCreation?: UpdateEntityCallback<Entity<TData>>): this;\r\n    /**\r\n     * Removes instances by their ids.\r\n     * @param ids The ids of the instances to remove.\r\n     * @returns The current `InstancedMesh2` instance.\r\n     */\r\n    removeInstances(...ids: number[]): this;\r\n    /**\r\n     * Clears all instances and resets the instance count.\r\n     * @returns The current `InstancedMesh2` instance.\r\n     */\r\n    clearInstances(): this;\r\n    /** @internal */ clearTempInstance(index: number): InstancedEntity;\r\n    /** @internal */ clearTempInstancePosition(index: number): InstancedEntity;\r\n    /** @internal */ clearInstance(instance: InstancedEntity): InstancedEntity;\r\n    /** @internal */ createEntities(start: number): this;\r\n    /** @internal */ addInstance(id: number, onCreation?: UpdateEntityCallback): void;\r\n  }\r\n}\r\n\r\nInstancedMesh2.prototype.clearTempInstance = function (index: number) {\r\n  const instance = this._tempInstance;\r\n  (instance as any).id = index;\r\n  return this.clearInstance(instance);\r\n};\r\n\r\nInstancedMesh2.prototype.clearTempInstancePosition = function (index: number) {\r\n  const instance = this._tempInstance;\r\n  (instance as any).id = index;\r\n  instance.position.set(0, 0, 0);\r\n  return instance;\r\n};\r\n\r\nInstancedMesh2.prototype.clearInstance = function (instance: InstancedEntity) {\r\n  instance.position.set(0, 0, 0);\r\n  instance.scale.set(1, 1, 1);\r\n  instance.quaternion.identity();\r\n  return instance;\r\n};\r\n\r\nInstancedMesh2.prototype.updateInstances = function (this: InstancedMesh2, onUpdate: UpdateEntityCallback) {\r\n  const end = this._instancesArrayCount;\r\n  const instances = this.instances;\r\n\r\n  for (let i = 0; i < end; i++) {\r\n    if (!this.getActiveAt(i)) continue;\r\n    const instance = instances ? instances[i] : this.clearTempInstance(i);\r\n    onUpdate(instance, i);\r\n    instance.updateMatrix();\r\n  }\r\n\r\n  return this;\r\n};\r\n\r\nInstancedMesh2.prototype.updateInstancesPosition = function (this: InstancedMesh2, onUpdate: UpdateEntityCallback) {\r\n  const end = this._instancesArrayCount;\r\n  const instances = this.instances;\r\n\r\n  for (let i = 0; i < end; i++) {\r\n    if (!this.getActiveAt(i)) continue;\r\n    const instance = instances ? instances[i] : this.clearTempInstancePosition(i);\r\n    onUpdate(instance, i);\r\n    instance.updateMatrixPosition();\r\n  }\r\n\r\n  return this;\r\n};\r\n\r\nInstancedMesh2.prototype.createEntities = function (this: InstancedMesh2, start: number) {\r\n  const end = this._instancesArrayCount;\r\n\r\n  if (!this.instances) {\r\n    this.instances = new Array(end);\r\n  } else if (this.instances.length < end) {\r\n    this.instances.length = end;\r\n  } else {\r\n    return this;\r\n  }\r\n\r\n  // we can also revert this for and put 'break' instead of 'continue' but no it's memory consecutive\r\n  const instances = this.instances;\r\n  for (let i = start; i < end; i++) {\r\n    if (instances[i]) continue;\r\n    instances[i] = new InstancedEntity(this, i, this._allowsEuler);\r\n  }\r\n\r\n  return this;\r\n};\r\n\r\nInstancedMesh2.prototype.addInstances = function (count: number, onCreation?: UpdateEntityCallback) {\r\n  if (!onCreation && this.bvh) {\r\n    console.warn('InstancedMesh2: if `computeBVH()` has already been called, it is better to valorize the instances in the `onCreation` callback for better performance.');\r\n  }\r\n\r\n  // refill holes created from removeInstances\r\n  const freeIds = this._freeIds;\r\n  if (freeIds.length > 0) {\r\n    let maxId = -1;\r\n    const freeIdsUsed = Math.min(freeIds.length, count);\r\n    const freeidsEnd = freeIds.length - freeIdsUsed;\r\n\r\n    for (let i = freeIds.length - 1; i >= freeidsEnd; i--) {\r\n      const id = freeIds[i];\r\n      if (id > maxId) maxId = id;\r\n      this.addInstance(id, onCreation);\r\n    }\r\n\r\n    freeIds.length -= freeIdsUsed;\r\n    count -= freeIdsUsed;\r\n    this._instancesArrayCount = Math.max(maxId + 1, this._instancesArrayCount);\r\n  }\r\n\r\n  const start = this._instancesArrayCount;\r\n  const end = start + count;\r\n  this.setInstancesArrayCount(end);\r\n\r\n  for (let i = start; i < end; i++) {\r\n    this.addInstance(i, onCreation);\r\n  }\r\n\r\n  return this;\r\n};\r\n\r\nInstancedMesh2.prototype.addInstance = function (id: number, onCreation?: UpdateEntityCallback) {\r\n  this._instancesCount++;\r\n  this.setActiveAndVisibilityAt(id, true);\r\n  const instance = this.instances ? this.clearInstance(this.instances[id]) : this.clearTempInstance(id);\r\n\r\n  if (onCreation) {\r\n    onCreation(instance, id);\r\n    instance.updateMatrix();\r\n  } else {\r\n    instance.setMatrixIdentity();\r\n  }\r\n\r\n  this.bvh?.insert(id);\r\n};\r\n\r\nInstancedMesh2.prototype.removeInstances = function (...ids: number[]) {\r\n  const freeIds = this._freeIds;\r\n  const bvh = this.bvh;\r\n\r\n  for (const id of ids) {\r\n    if (id < this._instancesArrayCount && this.getActiveAt(id)) {\r\n      this.setActiveAt(id, false);\r\n      freeIds.push(id);\r\n      bvh?.delete(id);\r\n      this._instancesCount--;\r\n    }\r\n  }\r\n\r\n  for (let i = this._instancesArrayCount - 1; i >= 0; i--) {\r\n    if (this.getActiveAt(i)) break;\r\n    this._instancesArrayCount--;\r\n  }\r\n\r\n  return this;\r\n};\r\n\r\nInstancedMesh2.prototype.clearInstances = function () {\r\n  this._instancesCount = 0;\r\n  this._instancesArrayCount = 0;\r\n  this._freeIds.length = 0;\r\n\r\n  this.bvh?.clear();\r\n\r\n  if (this.LODinfo) {\r\n    for (const obj of this.LODinfo.objects) {\r\n      obj.count = 0;\r\n    }\r\n  }\r\n\r\n  return this;\r\n};\r\n","import { BufferGeometry, Material, ShaderMaterial } from 'three';\r\nimport { InstancedMesh2, InstancedMesh2Params } from '../InstancedMesh2.js';\r\n\r\n// TODO check squaured distance in comments and code\r\n\r\n/**\r\n * Represents information about Level of Detail (LOD).\r\n * @template TData Type for additional instance data.\r\n */\r\nexport interface LODInfo<TData = {}> {\r\n  /**\r\n   * Render settings for the LOD.\r\n   */\r\n  render: LODRenderList<TData>;\r\n  /**\r\n   * Shadow rendering settings for the LOD.\r\n   */\r\n  shadowRender: LODRenderList<TData>;\r\n  /**\r\n   * List of `InstancedMesh2` associated to LODs.\r\n   */\r\n  objects: InstancedMesh2<TData>[];\r\n}\r\n\r\n/**\r\n * Represents a list of render levels for LOD.\r\n * @template TData Type for additional instance data.\r\n */\r\nexport interface LODRenderList<TData = {}> {\r\n  /**\r\n   * Array of LOD levels.\r\n   */\r\n  levels: LODLevel<TData>[];\r\n  /**\r\n   * Array of instance counts per LOD level, used internally.\r\n   */\r\n  count: number[];\r\n}\r\n\r\n/**\r\n * Represents a single LOD level.\r\n * @template TData Type for additional instance data.\r\n */\r\nexport interface LODLevel<TData = {}> {\r\n  /**\r\n   * The squared distance at which this LOD level becomes active.\r\n   */\r\n  distance: number;\r\n  /**\r\n   * Hysteresis value to prevent LOD flickering when transitioning.\r\n   */\r\n  hysteresis: number;\r\n  /**\r\n   * The `InstancedMesh2` object associated with this LOD level.\r\n   */\r\n  object: InstancedMesh2<TData>;\r\n}\r\n\r\ndeclare module '../InstancedMesh2.js' {\r\n  interface InstancedMesh2 {\r\n    /**\r\n     * Retrieves the index of the LOD level for a given distance.\r\n     * @param levels The array of LOD levels.\r\n     * @param distance The squared distance from the camera to the object.\r\n     * @returns The index of the LOD level that should be used.\r\n     */\r\n    getObjectLODIndexForDistance(levels: LODLevel[], distance: number): number;\r\n    /**\r\n     * Sets the first LOD (using current geometry) distance.\r\n     * @param distance The distance for the first LOD.\r\n     * @returns The current `InstancedMesh2` instance.\r\n     */\r\n    setFirstLODDistance(distance: number): this;\r\n    /**\r\n     * Adds a new LOD level with the given geometry, material, and distance.\r\n     * @param geometry The geometry for the LOD level.\r\n     * @param material The material for the LOD level.\r\n     * @param distance The distance for this LOD level.\r\n     * @param hysteresis The hysteresis value for this LOD level.\r\n     * @returns The current `InstancedMesh2` instance.\r\n     */\r\n    addLOD(geometry: BufferGeometry, material: Material | Material[], distance?: number, hysteresis?: number): this;\r\n    /**\r\n     * Adds a shadow-specific LOD level with the given geometry and distance.\r\n     * @param geometry The geometry for the shadow LOD.\r\n     * @param distance The distance for this LOD level.\r\n     * @param hysteresis The hysteresis value for this LOD level.\r\n     * @returns The current `InstancedMesh2` instance.\r\n     */\r\n    addShadowLOD(geometry: BufferGeometry, distance?: number, hysteresis?: number): this;\r\n    /**\r\n     * Updates the LOD settings for a specific level.\r\n     * @param levelIndex The index of the LOD to update.\r\n     * @param distance The distance at which this LOD level becomes active.\r\n     * @param hysteresis The hysteresis value to prevent LOD flickering when transitioning.\r\n     * @returns The current `InstancedMesh2` instance.\r\n     */\r\n    updateLOD(levelIndex: number, distance?: number, hysteresis?: number): this;\r\n    /**\r\n     * Updates the shadow LOD settings for a specific level.\r\n     * @param levelIndex The index of the LOD to update.\r\n     * @param distance The distance at which this LOD level becomes active.\r\n     * @param hysteresis The hysteresis value to prevent LOD flickering when transitioning.\r\n     * @returns The current `InstancedMesh2` instance.\r\n     */\r\n    updateShadowLOD(levelIndex: number, distance?: number, hysteresis?: number): this;\r\n    /**\r\n     * Updates the LOD settings for all levels.\r\n     * @param distances The array of distances for each LOD level.\r\n     * @param hysteresis The hysteresis value(s) for each LOD level.\r\n     * @returns The current `InstancedMesh2` instance.\r\n     */\r\n    updateAllLOD(distances?: number[], hysteresis?: number | number[]): this;\r\n    /**\r\n     * Updates the shadow LOD settings for all levels.\r\n     * @param distances The array of distances for each LOD level.\r\n     * @param hysteresis The hysteresis value(s) for each LOD level.\r\n     * @returns The current `InstancedMesh2` instance.\r\n     */\r\n    updateAllShadowLOD(distances?: number[], hysteresis?: number | number[]): this;\r\n    /**\r\n     * Removes a specific LOD level by its index.\r\n     * If the same geometry is reused by other levels, pass removeObject=false.\r\n     * @param levelIndex The index of the LOD level to remove.\r\n     * @param removeObject Also remove the child InstancedMesh2 object. Default true.\r\n     * @returns The current `InstancedMesh2` instance.\r\n     */\r\n    removeLOD(levelIndex: number, removeObject?: boolean): this;\r\n    /** @internal */ addLevel(renderList: LODRenderList, geometry: BufferGeometry, material: Material | Material[], distance: number, hysteresis: number): InstancedMesh2;\r\n    /** @internal */ patchLevel(obj: InstancedMesh2): void;\r\n    /** @internal */ updateLevel(renderList: LODRenderList, levelIndex: number, distance: number, hysteresis: number): this;\r\n    /** @internal */ updateAllLevels(renderList: LODRenderList, distances: number[] | null, hysteresis?: number | number[]): this;\r\n    /** @internal */ disposeLOD(object: InstancedMesh2);\r\n  }\r\n}\r\n\r\nInstancedMesh2.prototype.getObjectLODIndexForDistance = function (levels: LODLevel[], distance: number): number {\r\n  for (let i = levels.length - 1; i > 0; i--) {\r\n    const level = levels[i];\r\n    const levelDistance = level.distance - (level.distance * level.hysteresis);\r\n    if (distance >= levelDistance) return i;\r\n  }\r\n\r\n  return 0;\r\n};\r\n\r\nInstancedMesh2.prototype.setFirstLODDistance = function (distance): InstancedMesh2 {\r\n  if (this._parentLOD) {\r\n    throw new Error('Cannot create LOD for this InstancedMesh2.');\r\n  }\r\n\r\n  if (!this.LODinfo) {\r\n    this.LODinfo = { render: null, shadowRender: null, objects: [this] };\r\n  }\r\n\r\n  if (!this.LODinfo.render) {\r\n    this.LODinfo.render = {\r\n      levels: [{ distance, hysteresis: 0, object: this }], // hysteresis is always 0 at first level\r\n      count: [0]\r\n    };\r\n  }\r\n\r\n  return this;\r\n};\r\n\r\nInstancedMesh2.prototype.addLOD = function (geometry: BufferGeometry, material: Material | Material[], distance = 0, hysteresis = 0): InstancedMesh2 {\r\n  if (this._parentLOD) {\r\n    throw new Error('Cannot create LOD for this InstancedMesh2.');\r\n  }\r\n\r\n  if (!this.LODinfo?.render && distance === 0) {\r\n    throw new Error('Cannot set distance to 0 for the first LOD. Call \"setFirstLODDistance\" method before use \"addLOD\".');\r\n  }\r\n\r\n  this.setFirstLODDistance(0);\r\n\r\n  this.addLevel(this.LODinfo.render, geometry, material, distance, hysteresis);\r\n\r\n  return this;\r\n};\r\n\r\nInstancedMesh2.prototype.addShadowLOD = function (geometry: BufferGeometry, distance = 0, hysteresis = 0): InstancedMesh2 {\r\n  if (this._parentLOD) {\r\n    throw new Error('Cannot create LOD for this InstancedMesh2.');\r\n  }\r\n\r\n  if (!this.LODinfo) {\r\n    this.LODinfo = { render: null, shadowRender: null, objects: [this] };\r\n  }\r\n\r\n  if (!this.LODinfo.shadowRender) {\r\n    this.LODinfo.shadowRender = { levels: [], count: [] };\r\n  }\r\n\r\n  const object = this.addLevel(this.LODinfo.shadowRender, geometry, null, distance, hysteresis);\r\n  object.castShadow = true;\r\n  this.castShadow = true;\r\n\r\n  return this;\r\n};\r\n\r\nInstancedMesh2.prototype.addLevel = function (renderList: LODRenderList, geometry: BufferGeometry, material: Material, distance: number, hysteresis: number): InstancedMesh2 {\r\n  const objectsList = this.LODinfo.objects;\r\n  const levels = renderList.levels;\r\n  let index;\r\n  let object: InstancedMesh2;\r\n  distance = distance ** 2; // to avoid to use Math.sqrt every time\r\n\r\n  const objIndex = objectsList.findIndex((e) => e.geometry === geometry);\r\n  if (objIndex === -1) {\r\n    const params: InstancedMesh2Params = { capacity: this._capacity, renderer: this._renderer };\r\n    object = new InstancedMesh2(geometry, material ?? new ShaderMaterial(), params, this);\r\n    object.frustumCulled = false;\r\n    this.patchLevel(object);\r\n    objectsList.push(object);\r\n    this.add(object);\r\n  } else {\r\n    object = objectsList[objIndex];\r\n    if (material) object.material = material;\r\n  }\r\n\r\n  for (index = 0; index < levels.length; index++) {\r\n    if (distance < levels[index].distance) break;\r\n  }\r\n\r\n  levels.splice(index, 0, { distance, hysteresis, object });\r\n  renderList.count.push(0);\r\n\r\n  return object;\r\n};\r\n\r\nInstancedMesh2.prototype.updateLevel = function (renderList, levelIndex, distance, hysteresis) {\r\n  if (!renderList) throw new Error('Render list is invalid.');\r\n\r\n  const level = renderList.levels[levelIndex];\r\n  if (!level) throw new Error('Cannot update an empty LOD.');\r\n\r\n  if (distance != null && !Number.isNaN(distance)) {\r\n    const d2 = distance ** 2;\r\n    level.distance = d2;\r\n  }\r\n  if (hysteresis != null && !Number.isNaN(hysteresis))\r\n    level.hysteresis = hysteresis;\r\n\r\n  return this;\r\n};\r\n\r\nInstancedMesh2.prototype.updateLOD = function (levelIndex, distance, hysteresis) {\r\n  const list = this?.LODinfo?.render;\r\n  if (levelIndex === 0) throw new Error('Cannot change distance for LOD0. It is the main mesh and must stay at 0.'); // If user try to change first lod\r\n  return this.updateLevel(list, levelIndex, distance, hysteresis);\r\n};\r\n\r\nInstancedMesh2.prototype.updateShadowLOD = function (levelIndex, distance, hysteresis) {\r\n  return this.updateLevel(this.LODinfo?.shadowRender, levelIndex, distance, hysteresis);\r\n};\r\n\r\nInstancedMesh2.prototype.updateAllLevels = function (renderList, distances, hysteresis) {\r\n  if (!renderList?.levels) throw new Error('Invalid LOD list.');\r\n  const levels = renderList.levels;\r\n  const isRender = this.LODinfo?.render === renderList;\r\n\r\n  const start = isRender ? 1 : 0; // for shadowLOD\r\n  if (isRender) levels[0].distance = 0;\r\n\r\n  const hasDistances = distances?.length > 0;\r\n\r\n  let _distances = [];\r\n  if (hasDistances) { // Only when distances provided\r\n    _distances = (isRender && distances[0] === 0) // If user give 0 for first distance, handle this w/o throw error\r\n      ? distances.slice(1, Math.min(levels.length, distances.length))\r\n      : distances.slice(0, Math.min(levels.length - start, distances.length));\r\n\r\n    // Validate\r\n    _distances.every((_d, i) => {\r\n      if (i > 0 && _d <= _distances[i - 1]) throw new Error(`LOD distances must be strictly increasing: d[${i - 1}]=${_distances[i - 1]} < d[${i}]=${_d}`);\r\n      return true;\r\n    });\r\n  }\r\n\r\n  // apply: if no distances, update only hysteresis for all levels\r\n  const total = hasDistances ? _distances.length : (levels.length - start);\r\n\r\n  for (let i = 0; i < total; i++) {\r\n    const _d = hasDistances ? _distances[i] : undefined;\r\n    const _h = Array.isArray(hysteresis) ? hysteresis[i] : hysteresis;\r\n\r\n    this.updateLevel(renderList, start + i, _d, _h);\r\n  }\r\n\r\n  return this;\r\n};\r\n\r\nInstancedMesh2.prototype.updateAllLOD = function (distances, hysteresis) {\r\n  return this.updateAllLevels(this.LODinfo?.render, distances, hysteresis);\r\n};\r\n\r\nInstancedMesh2.prototype.updateAllShadowLOD = function (distances, hysteresis) {\r\n  return this.updateAllLevels(this.LODinfo?.shadowRender, distances, hysteresis);\r\n};\r\n\r\nInstancedMesh2.prototype.disposeLOD = function (object: InstancedMesh2) {\r\n  object.geometry.dispose();\r\n  const mat = object.material;\r\n  if (Array.isArray(mat)) for (const m of mat) m.dispose();\r\n  else mat.dispose();\r\n};\r\n\r\nInstancedMesh2.prototype.removeLOD = function (levelIndex, removeObject = true) {\r\n  const info = this.LODinfo;\r\n  const list = info?.render;\r\n  if (!list?.levels) throw new Error('Invalid LOD list.');\r\n\r\n  const n = list.levels.length;\r\n  if (levelIndex < 0 || levelIndex >= n) throw new Error('Level index OOB');\r\n  if (n > 1 && levelIndex === 0) throw new Error('Cannot remove LOD0 while others exist');\r\n\r\n  // Remove whole list if only LOD0 remains\r\n  const [removed] = list.levels.splice(levelIndex, 1);\r\n  list.count?.splice?.(levelIndex, 1);\r\n  if (list.levels.length <= 1) info.render = null;\r\n\r\n  const obj = removed.object;\r\n\r\n  // Mirror remove on shadow list if that index exists\r\n  const shadow = this.LODinfo?.shadowRender;\r\n  if (shadow?.levels && levelIndex < shadow.levels.length) {\r\n    shadow.levels.splice(levelIndex, 1);\r\n    shadow.count?.splice?.(levelIndex, 1);\r\n    if (shadow.levels.length === 0) this.LODinfo.shadowRender = null;\r\n  }\r\n\r\n  // Remove LOD object\r\n  if (removeObject && obj !== this) {\r\n    try {\r\n      this.remove(obj);\r\n      const idx = info.objects?.indexOf(obj) ?? -1;\r\n      if (idx !== -1) info.objects.splice(idx, 1);\r\n      this.disposeLOD(obj);\r\n    } catch (e) {\r\n      console.error(e);\r\n    }\r\n  }\r\n  return this;\r\n};\r\n\r\nInstancedMesh2.prototype.patchLevel = function (obj: InstancedMesh2): void {\r\n  Object.defineProperty(obj, 'renderOrder', {\r\n    get(this: InstancedMesh2) {\r\n      return this._parentLOD.renderOrder; // TODO reduce overdraw with renderOrder\r\n    }\r\n  });\r\n\r\n  Object.defineProperty(obj, '_lastRenderInfo', {\r\n    get(this: InstancedMesh2) {\r\n      return this._parentLOD._lastRenderInfo;\r\n    }\r\n  });\r\n\r\n  Object.defineProperty(obj, 'matricesTexture', {\r\n    get(this: InstancedMesh2) {\r\n      return this._parentLOD.matricesTexture;\r\n    }\r\n  });\r\n\r\n  Object.defineProperty(obj, 'colorsTexture', {\r\n    get(this: InstancedMesh2) {\r\n      return this._parentLOD.colorsTexture;\r\n    }\r\n  });\r\n\r\n  Object.defineProperty(obj, 'uniformsTexture', {\r\n    get(this: InstancedMesh2) {\r\n      return this._parentLOD.uniformsTexture;\r\n    }\r\n  });\r\n\r\n  Object.defineProperty(obj, 'morphTexture', { // TODO check if it's correct\r\n    get(this: InstancedMesh2) {\r\n      return this._parentLOD.morphTexture;\r\n    }\r\n  });\r\n\r\n  Object.defineProperty(obj, 'boneTexture', {\r\n    get(this: InstancedMesh2) {\r\n      return this._parentLOD.boneTexture;\r\n    }\r\n  });\r\n\r\n  Object.defineProperty(obj, 'skeleton', {\r\n    get(this: InstancedMesh2) {\r\n      return this._parentLOD.skeleton;\r\n    }\r\n  });\r\n\r\n  Object.defineProperty(obj, 'bindMatrixInverse', {\r\n    get(this: InstancedMesh2) {\r\n      return this._parentLOD.bindMatrixInverse;\r\n    }\r\n  });\r\n\r\n  Object.defineProperty(obj, 'bindMatrix', {\r\n    get(this: InstancedMesh2) {\r\n      return this._parentLOD.bindMatrix;\r\n    }\r\n  });\r\n};\r\n","import { DataTexture, FloatType, Mesh, RedFormat } from 'three';\r\nimport { InstancedMesh2 } from '../InstancedMesh2.js';\r\n\r\ndeclare module '../InstancedMesh2.js' {\r\n  interface InstancedMesh2 {\r\n    /**\r\n     * Gets the morph target data for a specific instance.\r\n     * @param id The index of the instance.\r\n     * @param object Optional `Mesh` to store the morph target data.\r\n     * @returns The mesh object with updated morph target influences.\r\n     */\r\n    getMorphAt(id: number, object?: Mesh): Mesh;\r\n    /**\r\n     * Sets the morph target influences for a specific instance.\r\n     * @param id The index of the instance.\r\n     * @param object The `Mesh` containing the morph target influences to apply.\r\n     */\r\n    setMorphAt(id: number, object: Mesh): void;\r\n  }\r\n}\r\n\r\nconst _tempMesh = new Mesh();\r\n\r\nInstancedMesh2.prototype.getMorphAt = function (id: number, object = _tempMesh): Mesh {\r\n  const objectInfluences = object.morphTargetInfluences;\r\n  const array = this.morphTexture.source.data.data;\r\n  const len = objectInfluences.length + 1; // All influences + the baseInfluenceSum\r\n  const dataIndex = id * len + 1; // Skip the baseInfluenceSum at the beginning\r\n\r\n  for (let i = 0; i < objectInfluences.length; i++) {\r\n    objectInfluences[i] = array[dataIndex + i];\r\n  }\r\n\r\n  return object;\r\n};\r\n\r\nInstancedMesh2.prototype.setMorphAt = function (id: number, object: Mesh): void {\r\n  const objectInfluences = object.morphTargetInfluences;\r\n  const len = objectInfluences.length + 1;\r\n\r\n  if (this.morphTexture === null && !this._parentLOD) {\r\n    this.morphTexture = new DataTexture(new Float32Array(len * this._capacity), len, this._capacity, RedFormat, FloatType);\r\n  }\r\n\r\n  const array = this.morphTexture.source.data.data;\r\n  let morphInfluencesSum = 0;\r\n\r\n  for (const objectInfluence of objectInfluences) {\r\n    morphInfluencesSum += objectInfluence;\r\n  }\r\n\r\n  const morphBaseInfluence = this._geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;\r\n  const dataIndex = len * id;\r\n  array[dataIndex] = morphBaseInfluence;\r\n  array.set(objectInfluences, dataIndex + 1);\r\n  this.morphTexture.needsUpdate = true;\r\n};\r\n","import { Intersection, Matrix4, Mesh, Ray, Raycaster, Sphere, Vector3 } from 'three';\r\nimport { InstancedMesh2 } from '../InstancedMesh2.js';\r\n\r\ndeclare module '../InstancedMesh2.js' {\r\n  interface InstancedMesh2 {\r\n    /** @internal */ raycastInstances(raycaster: Raycaster, result: Intersection[]): void;\r\n    /** @internal */ checkObjectIntersection(raycaster: Raycaster, objectIndex: number, result: Intersection[]): void;\r\n  }\r\n}\r\n\r\nconst _intersections: Intersection[] = [];\r\nconst _mesh = new Mesh();\r\nconst _ray = new Ray();\r\nconst _direction = new Vector3();\r\nconst _worldScale = new Vector3();\r\nconst _invMatrixWorld = new Matrix4();\r\nconst _sphere = new Sphere();\r\n\r\nInstancedMesh2.prototype.raycast = function (raycaster, result) {\r\n  if (this._parentLOD || !this.material || this._instancesArrayCount === 0 || !this.instanceIndex) return;\r\n\r\n  _mesh.geometry = this._geometry;\r\n  _mesh.material = this.material;\r\n\r\n  const originalRay = raycaster.ray;\r\n  const originalNear = raycaster.near;\r\n  const originalFar = raycaster.far;\r\n\r\n  _invMatrixWorld.copy(this.matrixWorld).invert();\r\n\r\n  _worldScale.setFromMatrixScale(this.matrixWorld);\r\n  _direction.copy(raycaster.ray.direction).multiply(_worldScale);\r\n  const scaleFactor = _direction.length();\r\n\r\n  raycaster.ray = _ray.copy(raycaster.ray).applyMatrix4(_invMatrixWorld);\r\n  raycaster.near /= scaleFactor;\r\n  raycaster.far /= scaleFactor;\r\n\r\n  this.raycastInstances(raycaster, result);\r\n\r\n  raycaster.ray = originalRay;\r\n  raycaster.near = originalNear;\r\n  raycaster.far = originalFar;\r\n};\r\n\r\nInstancedMesh2.prototype.raycastInstances = function (raycaster, result) {\r\n  if (this.bvh) {\r\n    this.bvh.raycast(raycaster, (instanceId) => this.checkObjectIntersection(raycaster, instanceId, result));\r\n    // TODO test with three-mesh-bvh\r\n  } else {\r\n    if (this.boundingSphere === null) this.computeBoundingSphere();\r\n    _sphere.copy(this.boundingSphere);\r\n    if (!raycaster.ray.intersectsSphere(_sphere)) return;\r\n\r\n    const instancesToCheck = this.instanceIndex.array; // TODO this is unsorted and it's slower to iterate. If raycastFrustum is false, don't use it.\r\n    const raycastFrustum = this.raycastOnlyFrustum && this._perObjectFrustumCulled;\r\n    const checkCount = raycastFrustum ? this.count : this._instancesArrayCount;\r\n\r\n    for (let i = 0; i < checkCount; i++) {\r\n      this.checkObjectIntersection(raycaster, instancesToCheck[i], result);\r\n    }\r\n  }\r\n};\r\n\r\nInstancedMesh2.prototype.checkObjectIntersection = function (raycaster, objectIndex, result) {\r\n  // TODO check objectIndex > this._instancesArrayCount is necessary\r\n  if (objectIndex > this._instancesArrayCount || !this.getActiveAndVisibilityAt(objectIndex)) return;\r\n\r\n  this.getMatrixAt(objectIndex, _mesh.matrixWorld);\r\n\r\n  _mesh.raycast(raycaster, _intersections);\r\n\r\n  for (const intersect of _intersections) {\r\n    intersect.instanceId = objectIndex;\r\n    intersect.object = this;\r\n    result.push(intersect);\r\n  }\r\n\r\n  _intersections.length = 0;\r\n};\r\n","import { Matrix4, Skeleton } from 'three';\r\nimport { InstancedMesh2 } from '../InstancedMesh2.js';\r\nimport { SquareDataTexture } from '../utils/SquareDataTexture.js';\r\n\r\ndeclare module '../InstancedMesh2.js' {\r\n  interface InstancedMesh2 {\r\n    /**\r\n     * Initialize the skeleton of the instances.\r\n     * @param skeleton The skeleton to initialize.\r\n     * @param disableMatrixAutoUpdate Whether to disable the matrix auto update of the bones. Default is `true`.\r\n     */\r\n    initSkeleton(skeleton: Skeleton, disableMatrixAutoUpdate?: boolean): void;\r\n    /**\r\n     * Set the bones of the skeleton to the instance at the specified index.\r\n     * @param id The index of the instance.\r\n     * @param updateBonesMatrices Whether to update the matrices of the bones. Default is `true`.\r\n     * @param excludeBonesSet An optional set of bone names to exclude from updates, skipping their local matrix updates.\r\n    */\r\n    setBonesAt(id: number, updateBonesMatrices?: boolean, excludeBonesSet?: Set<string>): void;\r\n    /** internal */ multiplyBoneMatricesAt(instanceIndex: number, boneIndex: number, m1: Matrix4, m2: Matrix4): void;\r\n  }\r\n}\r\n\r\nInstancedMesh2.prototype.initSkeleton = function (skeleton: Skeleton, disableMatrixAutoUpdate = true) {\r\n  if (skeleton && this.skeleton !== skeleton && !this._parentLOD) { // TODO remove !this._parentLOD\r\n    const bones = skeleton.bones;\r\n    this.skeleton = skeleton;\r\n    this.bindMatrix = new Matrix4();\r\n    this.bindMatrixInverse = new Matrix4();\r\n    this.boneTexture = new SquareDataTexture(Float32Array, 4, 4 * bones.length, this._capacity);\r\n\r\n    if (disableMatrixAutoUpdate) {\r\n      for (const bone of bones) {\r\n        bone.matrixAutoUpdate = false;\r\n        bone.matrixWorldAutoUpdate = false;\r\n      }\r\n    }\r\n\r\n    this.materialsNeedsUpdate(); // TODO this may not work if change already present skeleton\r\n  }\r\n};\r\n\r\nInstancedMesh2.prototype.setBonesAt = function (id: number, updateBonesMatrices = true, excludeBonesSet?: Set<string>) {\r\n  const skeleton = this.skeleton;\r\n  if (!skeleton) {\r\n    throw new Error('\"setBonesAt\" cannot be called before \"initSkeleton\"');\r\n  }\r\n\r\n  const bones = skeleton.bones;\r\n  const boneInverses = skeleton.boneInverses;\r\n\r\n  for (let i = 0, l = bones.length; i < l; i++) {\r\n    const bone = bones[i];\r\n\r\n    if (updateBonesMatrices) {\r\n      if (!excludeBonesSet?.has(bone.name)) {\r\n        bone.updateMatrix();\r\n      }\r\n      bone.matrixWorld.multiplyMatrices(bone.parent.matrixWorld, bone.matrix);\r\n    }\r\n\r\n    this.multiplyBoneMatricesAt(id, i, bone.matrixWorld, boneInverses[i]);\r\n  }\r\n\r\n  this.boneTexture.enqueueUpdate(id);\r\n};\r\n\r\nInstancedMesh2.prototype.multiplyBoneMatricesAt = function (instanceIndex: number, boneIndex: number, m1: Matrix4, m2: Matrix4) {\r\n  const offset = (instanceIndex * this.skeleton.bones.length + boneIndex) * 16;\r\n  const ae = m1.elements;\r\n  const be = m2.elements;\r\n  const te = this.boneTexture._data;\r\n\r\n  const a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];\r\n  const a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];\r\n  const a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];\r\n  const a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];\r\n\r\n  const b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];\r\n  const b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];\r\n  const b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];\r\n  const b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];\r\n\r\n  te[offset + 0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;\r\n  te[offset + 4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;\r\n  te[offset + 8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;\r\n  te[offset + 12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;\r\n\r\n  te[offset + 1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;\r\n  te[offset + 5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;\r\n  te[offset + 9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;\r\n  te[offset + 13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;\r\n\r\n  te[offset + 2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;\r\n  te[offset + 6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;\r\n  te[offset + 10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;\r\n  te[offset + 14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;\r\n\r\n  te[offset + 3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;\r\n  te[offset + 7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;\r\n  te[offset + 11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;\r\n  te[offset + 15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;\r\n};\r\n","import { InstancedMesh2 } from '../InstancedMesh2.js';\r\nimport { ChannelSize, SquareDataTexture, UniformMap, UniformMapType, UniformType, UniformValue, UniformValueObj } from '../utils/SquareDataTexture.js';\r\n\r\ntype UniformSchema = { [x: string]: UniformType };\r\ntype UniformSchemaShader = { vertex?: UniformSchema; fragment?: UniformSchema };\r\n\r\ntype UniformSchemaResult = {\r\n  channels: ChannelSize;\r\n  pixelsPerInstance: number;\r\n  uniformMap: UniformMap;\r\n  fetchInFragmentShader: boolean;\r\n};\r\n\r\ndeclare module '../InstancedMesh2.js' {\r\n  interface InstancedMesh2 {\r\n    /**\r\n     * Retrieves a uniform value for a specific instance.\r\n     * @param id The index of the instance.\r\n     * @param name The name of the uniform.\r\n     * @param target Optional target object to store the uniform value.\r\n     * @returns The uniform value for the specified instance.\r\n     */\r\n    getUniformAt(id: number, name: string, target?: UniformValueObj): UniformValue;\r\n    /**\r\n     * Sets a uniform value for a specific instance.\r\n     * @param id The index of the instance.\r\n     * @param name The name of the uniform.\r\n     * @param value The value to set for the uniform.\r\n     */\r\n    setUniformAt(id: number, name: string, value: UniformValue): void;\r\n    /**\r\n     * Initializes per-instance uniforms using a schema.\r\n     * @param schema The schema defining the uniforms.\r\n     */\r\n    initUniformsPerInstance(schema: UniformSchemaShader): void;\r\n    /** @internal */ getUniformSchemaResult(schema: UniformSchemaShader): UniformSchemaResult;\r\n    /** @internal */ getUniformOffset(size: number, tempOffset: number[]): number;\r\n    /** @internal */ getUniformSize(type: UniformType): number;\r\n  }\r\n}\r\n\r\nInstancedMesh2.prototype.getUniformAt = function (id: number, name: string, target?: UniformValueObj): UniformValue {\r\n  if (!this.uniformsTexture) {\r\n    throw new Error('Before get/set uniform, it\\'s necessary to use \"initUniformsPerInstance\".');\r\n  }\r\n  return this.uniformsTexture.getUniformAt(id, name, target);\r\n};\r\n\r\nInstancedMesh2.prototype.setUniformAt = function (id: number, name: string, value: UniformValue): void {\r\n  if (!this.uniformsTexture) {\r\n    throw new Error('Before get/set uniform, it\\'s necessary to use \"initUniformsPerInstance\".');\r\n  }\r\n  this.uniformsTexture.setUniformAt(id, name, value);\r\n  this.uniformsTexture.enqueueUpdate(id);\r\n};\r\n\r\nInstancedMesh2.prototype.initUniformsPerInstance = function (schema: UniformSchemaShader): void {\r\n  if (!this._parentLOD) {\r\n    const { channels, pixelsPerInstance, uniformMap, fetchInFragmentShader } = this.getUniformSchemaResult(schema);\r\n    this.uniformsTexture = new SquareDataTexture(Float32Array, channels, pixelsPerInstance, this._capacity, uniformMap, fetchInFragmentShader);\r\n    this.materialsNeedsUpdate();\r\n  }\r\n};\r\n\r\nInstancedMesh2.prototype.getUniformSchemaResult = function (schema: UniformSchemaShader): UniformSchemaResult {\r\n  let totalSize = 0;\r\n  const uniformMap = new Map<string, UniformMapType>();\r\n  const uniforms: { type: UniformType; name: string; size: number }[] = [];\r\n  const vertexSchema = schema.vertex ?? {};\r\n  const fragmentSchema = schema.fragment ?? {};\r\n  let fetchInFragmentShader = true;\r\n\r\n  for (const name in vertexSchema) {\r\n    const type = vertexSchema[name];\r\n    const size = this.getUniformSize(type);\r\n    totalSize += size;\r\n    uniforms.push({ name, type, size });\r\n    fetchInFragmentShader = false;\r\n  }\r\n\r\n  for (const name in fragmentSchema) {\r\n    if (!vertexSchema[name]) {\r\n      const type = fragmentSchema[name];\r\n      const size = this.getUniformSize(type);\r\n      totalSize += size;\r\n      uniforms.push({ name, type, size });\r\n    }\r\n  }\r\n\r\n  uniforms.sort((a, b) => b.size - a.size);\r\n\r\n  const tempOffset = [];\r\n  for (const { name, size, type } of uniforms) {\r\n    const offset = this.getUniformOffset(size, tempOffset);\r\n    uniformMap.set(name, { offset, size, type });\r\n  }\r\n\r\n  const pixelsPerInstance = Math.ceil(totalSize / 4);\r\n  const channels = Math.min(totalSize, 4) as ChannelSize;\r\n\r\n  return { channels, pixelsPerInstance, uniformMap, fetchInFragmentShader };\r\n};\r\n\r\nInstancedMesh2.prototype.getUniformOffset = function (size: number, tempOffset: number[]): number {\r\n  if (size < 4) {\r\n    for (let i = 0; i < tempOffset.length; i++) {\r\n      if (tempOffset[i] + size <= 4) {\r\n        const offset = i * 4 + tempOffset[i];\r\n        tempOffset[i] += size;\r\n        return offset;\r\n      }\r\n    }\r\n  }\r\n\r\n  const offset = tempOffset.length * 4;\r\n  for (; size > 0; size -= 4) {\r\n    tempOffset.push(size);\r\n  }\r\n\r\n  return offset;\r\n};\r\n\r\nInstancedMesh2.prototype.getUniformSize = function (type: UniformType): number {\r\n  switch (type) {\r\n    case 'float': return 1;\r\n    case 'vec2': return 2;\r\n    case 'vec3': return 3;\r\n    case 'vec4': return 4;\r\n    case 'mat3': return 9;\r\n    case 'mat4': return 16;\r\n    default:\r\n      throw new Error(`Invalid uniform type: ${type}`);\r\n  }\r\n};\r\n","#ifdef USE_INSTANCING_INDIRECT\r\n  attribute uint instanceIndex;\r\n  uniform highp sampler2D matricesTexture;  \r\n\r\n  mat4 getInstancedMatrix() {\r\n    int size = textureSize( matricesTexture, 0 ).x;\r\n    int j = int( instanceIndex ) * 4;\r\n    int x = j % size;\r\n    int y = j / size;\r\n    vec4 v1 = texelFetch( matricesTexture, ivec2( x, y ), 0 );\r\n    vec4 v2 = texelFetch( matricesTexture, ivec2( x + 1, y ), 0 );\r\n    vec4 v3 = texelFetch( matricesTexture, ivec2( x + 2, y ), 0 );\r\n    vec4 v4 = texelFetch( matricesTexture, ivec2( x + 3, y ), 0 );\r\n    return mat4( v1, v2, v3, v4 );\r\n  }\r\n#endif\r\n","#ifdef USE_INSTANCING_COLOR_INDIRECT\r\n  uniform highp sampler2D colorsTexture;\r\n\r\n  vec4 getColorTexture() {\r\n    int size = textureSize( colorsTexture, 0 ).x;\r\n    int j = int( instanceIndex );\r\n    int x = j % size;\r\n    int y = j / size;\r\n    return texelFetch( colorsTexture, ivec2( x, y ), 0 );\r\n  }\r\n#endif\r\n","#ifdef USE_INSTANCING_INDIRECT\r\n  mat4 instanceMatrix = getInstancedMatrix();\r\n\r\n  #ifdef USE_INSTANCING_COLOR_INDIRECT\r\n    vColor *= getColorTexture();\r\n  #endif\r\n#endif\r\n","#ifdef USE_INSTANCING_COLOR_INDIRECT\r\n  #ifdef USE_VERTEX_COLOR\r\n    vColor = vec4( color );\r\n  #else\r\n    vColor = vec4( 1.0 );\r\n  #endif\r\n#endif\r\n","#ifdef USE_SKINNING\r\n  uniform mat4 bindMatrix;\r\n  uniform mat4 bindMatrixInverse;\r\n  uniform highp sampler2D boneTexture;\r\n\r\n  #ifdef USE_INSTANCING_SKINNING\r\n    uniform int bonesPerInstance;\r\n  #endif\r\n\r\n  mat4 getBoneMatrix( const in float i ) {\r\n    int size = textureSize( boneTexture, 0 ).x;\r\n\r\n    #ifdef USE_INSTANCING_SKINNING\r\n      int j = ( bonesPerInstance * int( instanceIndex ) + int( i ) ) * 4;\r\n    #else\r\n      int j = int( i ) * 4;\r\n    #endif\r\n\r\n    int x = j % size;\r\n    int y = j / size;\r\n    vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );\r\n    vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );\r\n    vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );\r\n    vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );\r\n    return mat4( v1, v2, v3, v4 );\r\n  }\r\n#endif\r\n","import { ShaderChunk } from 'three';\r\nimport instanced_pars_vertex from './chunks/instanced_pars_vertex.glsl';\r\nimport instanced_color_pars_vertex from './chunks/instanced_color_pars_vertex.glsl';\r\nimport instanced_vertex from './chunks/instanced_vertex.glsl';\r\nimport instanced_color_vertex from './chunks/instanced_color_vertex.glsl';\r\nimport instanced_skinning_pars_vertex from './chunks/instanced_skinning_pars_vertex.glsl';\r\n\r\nShaderChunk['instanced_pars_vertex'] = instanced_pars_vertex;\r\nShaderChunk['instanced_color_pars_vertex'] = instanced_color_pars_vertex;\r\nShaderChunk['instanced_vertex'] = instanced_vertex;\r\nShaderChunk['instanced_color_vertex'] = instanced_color_vertex;\r\n\r\n/**\r\n * Patches the given shader string by adding a condition for indirect instancing support.\r\n * @param shader The shader code to modify.\r\n * @returns The modified shader code with the additional instancing condition.\r\n */\r\nexport function patchShader(shader: string): string {\r\n  return shader.replace('#ifdef USE_INSTANCING', '#if defined USE_INSTANCING || defined USE_INSTANCING_INDIRECT');\r\n}\r\n\r\nShaderChunk.project_vertex = patchShader(ShaderChunk.project_vertex);\r\nShaderChunk.worldpos_vertex = patchShader(ShaderChunk.worldpos_vertex);\r\nShaderChunk.defaultnormal_vertex = patchShader(ShaderChunk.defaultnormal_vertex);\r\n\r\nShaderChunk.batching_pars_vertex = ShaderChunk.batching_pars_vertex.concat('\\n#include <instanced_pars_vertex>');\r\nShaderChunk.color_pars_vertex = ShaderChunk.color_pars_vertex.concat('\\n#include <instanced_color_pars_vertex>');\r\nShaderChunk['batching_vertex'] = ShaderChunk['batching_vertex'].concat('\\n#include <instanced_vertex>');\r\n\r\nShaderChunk.skinning_pars_vertex = instanced_skinning_pars_vertex;\r\n\r\n// TODO FIX don't override like this, create a new shaderChunk to make it works also with older three.js version\r\nif (ShaderChunk['morphinstance_vertex']) {\r\n  ShaderChunk['morphinstance_vertex'] = ShaderChunk['morphinstance_vertex'].replaceAll('gl_InstanceID', 'instanceIndex');\r\n}\r\n\r\n// use 'getPatchedShader' function to make these example works\r\n// examples/jsm/modifiers/CurveModifier.js\r\n// examples/jsm/postprocessing/OutlinePass.js\r\n","import { InstancedBufferAttribute, InstancedMesh, Mesh, SkinnedMesh } from 'three';\r\nimport { InstancedMesh2, InstancedMesh2Params } from '../core/InstancedMesh2.js';\r\n\r\n/**\r\n * Create an `InstancedMesh2` instance from an existing `Mesh` or `InstancedMesh`.\r\n * @param mesh The `Mesh` or `InstancedMesh` to create an `InstanceMesh2` from.\r\n * @param params  Optional configuration parameters object. See `InstancedMesh2Params` for details.\r\n * @returns The created `InstancedMesh2` instance.\r\n */\r\nexport function createInstancedMesh2From<TData = {}>(mesh: Mesh, params: InstancedMesh2Params = {}): InstancedMesh2<TData> {\r\n  if ((mesh as SkinnedMesh).isSkinnedMesh) return createFromSkinnedMesh(mesh as SkinnedMesh);\r\n  if ((mesh as InstancedMesh).isInstancedMesh) return createFromInstancedMesh(mesh as InstancedMesh);\r\n  // TODO add morph support\r\n  return new InstancedMesh2<TData>(mesh.geometry, mesh.material, params);\r\n\r\n  function createFromSkinnedMesh<TData = {}>(mesh: SkinnedMesh): InstancedMesh2<TData> {\r\n    const instancedMesh = new InstancedMesh2<TData>(mesh.geometry.clone(), mesh.material, params);\r\n    instancedMesh.initSkeleton(mesh.skeleton);\r\n    return instancedMesh;\r\n  }\r\n\r\n  function createFromInstancedMesh<TData = {}>(mesh: InstancedMesh): InstancedMesh2<TData> {\r\n    params.capacity = Math.max(mesh.count, params.capacity);\r\n\r\n    const geometry = mesh.geometry.clone();\r\n    geometry.deleteAttribute('instanceIndex');\r\n    warnIfInstancedAttribute();\r\n\r\n    const instancedMesh = new InstancedMesh2<TData>(geometry, mesh.material, params);\r\n\r\n    instancedMesh.position.copy(mesh.position);\r\n    instancedMesh.quaternion.copy(mesh.quaternion);\r\n    instancedMesh.scale.copy(mesh.scale);\r\n\r\n    copyInstances();\r\n    copyMatrices();\r\n    copyColors();\r\n    // TODO copy morph target?\r\n\r\n    return instancedMesh;\r\n\r\n    function copyInstances(): void {\r\n      instancedMesh.setInstancesArrayCount(mesh.count);\r\n      instancedMesh._instancesCount = mesh.count;\r\n      instancedMesh.availabilityArray.fill(true, 0, mesh.count * 2);\r\n    }\r\n\r\n    function copyMatrices(): void {\r\n      (instancedMesh.matricesTexture.image.data as Float32Array).set(mesh.instanceMatrix.array);\r\n    }\r\n\r\n    function copyColors(): void {\r\n      if (mesh.instanceColor) {\r\n        (instancedMesh as any).initColorsTexture();\r\n\r\n        const rgbArray = mesh.instanceColor.array;\r\n        const rgbaArray = instancedMesh.colorsTexture.image.data as Float32Array;\r\n\r\n        for (let i = 0, j = 0; i < rgbArray.length; i += 3, j += 4) {\r\n          rgbaArray[j] = rgbArray[i];\r\n          rgbaArray[j + 1] = rgbArray[i + 1];\r\n          rgbaArray[j + 2] = rgbArray[i + 2];\r\n          rgbaArray[j + 3] = 1;\r\n        }\r\n      }\r\n    }\r\n\r\n    function warnIfInstancedAttribute(): void {\r\n      const attributes = geometry.attributes;\r\n      for (const name in attributes) {\r\n        if ((attributes[name] as InstancedBufferAttribute).isInstancedBufferAttribute) {\r\n          console.warn(`InstancedBufferAttribute \"${name}\" is not supported. It will be ignored.`);\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n"],"names":["InstancedEntity","owner","id","useEuler","Vector3","Quaternion","quaternion","rotation","Euler","value","te","offset","position","scale","x","y","z","w","x2","y2","z2","xx","xy","xz","yy","yz","zz","wx","wy","wz","sx","sy","sz","name","target","updateBonesMatrices","excludeBonesSet","m","q","axis","angle","_quat","_xAxis","_yAxis","_zAxis","distance","_vec3","InstancedMeshBVH","margin","getBBoxFromBSphere","accurateCulling","geometry","center","BVH","HybridBuilder","WebGLCoordinateSystem","count","instancesArrayCount","boxes","objects","index","i","node","ids","projScreenMatrix","onFrustumIntersection","frustum","mask","cameraPosition","levels","levelsArray","camera","level","raycaster","onIntersection","ray","origin","dir","vec3ToArray","array","box3ToArray","matrixArray","centerX","centerY","centerZ","maxScale","radius","_box3","m0","m1","m2","m4","m5","m6","m8","m9","m10","scaleXSq","scaleYSq","scaleZSq","Box3","GLInstancedBufferAttribute","GLBufferAttribute","gl","type","itemSize","elementSize","meshPerAttribute","buffer","renderer","propertiesGetBase","propertiesGet","propertiesGetMap","propertiesGetCallback","object","addProperties","material","materialProperties","materialPropertiesBase","patchProperties","obj","properties","key","unpatchProperties","getSquareTextureSize","capacity","pixelsPerInstance","getSquareTextureInfo","arrayType","channels","size","isFloat","isUnsignedInt","FloatType","UnsignedIntType","IntType","format","RedFormat","RedIntegerFormat","RGFormat","RGIntegerFormat","RGBAFormat","RGBAIntegerFormat","SquareDataTexture","DataTexture","uniformMap","fetchInFragmentShader","currentData","data","minLength","elementsPerRow","rowIndex","programUniforms","materialUniforms","uniformName","slot","textureProperties","versionChanged","sizeChanged","rowsInfo","rowsToUpdate","result","l","row","info","WebGLUtils","glFormat","glType","width","workingPrimaries","ColorManagement","texturePrimaries","NoColorSpace","unpackConversion","stride","textureName","indexName","indexType","vertex","fragment","texelsFetch","getFromTexels","assignVarying","declareVarying","getVarying","uniforms","tId","components","startIndex","componentsArray","source","InstancedMesh2","Mesh","params","LOD","allowsEuler","createEntities","AttachedBindMode","InstancedBufferAttribute","shader","_defaultCapacity","scene","shadowCamera","depthMaterial","group","frame","currentProgramProperties","currentProgram","activeProgram","materialIndex","materials","instanceIndex","config","matrix","instance","_tempMat4","_position","te0","te1","te2","te4","te5","te6","te8","te9","te10","sphere","te3","te7","te11","te12","te13","te14","te15","visible","active","availabilityArray","color","_tempCol","geoBoundingBox","boundingBox","Sphere","geoBoundingSphere","boundingSphere","_sphere","recursive","force","DetachedBindMode","Matrix4","Color","oldCapacity","minCapacity","indexArray","oldArray","bvh","newCapacity","start","createRadixSort","options","el","list","minZ","maxZ","depth","depthDelta","factor","item","radixSort","sortOpaque","a","b","sortTransparent","InstancedRenderList","pool","_frustum","Frustum","_renderList","_projScreenMatrix","_invMatrixWorld","_forward","_cameraPos","_cameraLODPos","cameraLOD","mainMesh","LODinfo","LODrenderList","lastRenderInfo","sortObjects","perObjectFrustumCulled","customSort","onFrustumEnter","bSphere","geometryCentered","indexes","levelIndex","levelDistance","onUpdate","end","instances","onCreation","freeIds","maxId","freeIdsUsed","freeidsEnd","hysteresis","renderList","objectsList","objIndex","e","ShaderMaterial","d2","distances","isRender","hasDistances","_distances","_d","total","_h","mat","removeObject","n","removed","shadow","idx","_tempMesh","objectInfluences","len","dataIndex","morphInfluencesSum","objectInfluence","morphBaseInfluence","_intersections","_mesh","_ray","Ray","_direction","_worldScale","originalRay","originalNear","originalFar","scaleFactor","instanceId","instancesToCheck","checkCount","objectIndex","intersect","skeleton","disableMatrixAutoUpdate","bones","bone","boneInverses","boneIndex","ae","be","a11","a12","a13","a14","a21","a22","a23","a24","a31","a32","a33","a34","a41","a42","a43","a44","b11","b12","b13","b14","b21","b22","b23","b24","b31","b32","b33","b34","b41","b42","b43","b44","schema","totalSize","vertexSchema","fragmentSchema","tempOffset","instanced_pars_vertex_default","instanced_color_pars_vertex_default","instanced_vertex_default","instanced_color_vertex_default","instanced_skinning_pars_vertex_default","ShaderChunk","instanced_pars_vertex","instanced_color_pars_vertex","instanced_vertex","instanced_color_vertex","patchShader","instanced_skinning_pars_vertex","createInstancedMesh2From","mesh","createFromSkinnedMesh","createFromInstancedMesh","instancedMesh","warnIfInstancedAttribute","copyInstances","copyMatrices","copyColors","rgbArray","rgbaArray","j","attributes"],"mappings":"2KAWO,MAAMA,EAAgB,CA8E3B,YAAYC,EAAuBC,EAAYC,EAAmB,CAIhE,GA9EF,KAAgB,iBAAmB,GAYnC,KAAO,SAAW,IAAIC,UAItB,KAAO,MAAQ,IAAIA,EAAAA,QAAQ,EAAG,EAAG,CAAC,EAIlC,KAAO,WAAa,IAAIC,aAuDtB,KAAK,GAAKH,EACV,KAAK,MAAQD,EAETE,EAAU,CACZ,MAAMG,EAAa,KAAK,WAClBC,EAAW,KAAK,SAAW,IAAIC,EAAAA,MAErCD,EAAS,UAAU,IAAMD,EAAW,aAAaC,EAAU,EAAK,CAAC,EACjED,EAAW,UAAU,IAAMC,EAAS,kBAAkBD,EAAY,OAAW,EAAK,CAAC,CACrF,CACF,CAvDA,IAAW,SAAmB,CAAE,OAAO,KAAK,MAAM,gBAAgB,KAAK,EAAE,CAAG,CAC5E,IAAW,QAAQG,EAAgB,CAAE,KAAK,MAAM,gBAAgB,KAAK,GAAIA,CAAK,CAAG,CAKjF,IAAW,QAAkB,CAAE,OAAO,KAAK,MAAM,YAAY,KAAK,EAAE,CAAG,CACvE,IAAW,OAAOA,EAAgB,CAAE,KAAK,MAAM,YAAY,KAAK,GAAIA,CAAK,CAAG,CAK5E,IAAW,OAAe,CAAE,OAAO,KAAK,MAAM,WAAW,KAAK,EAAE,CAAG,CACnE,IAAW,MAAMA,EAA4B,CAAE,KAAK,MAAM,WAAW,KAAK,GAAIA,CAAK,CAAG,CAKtF,IAAW,SAAkB,CAAE,OAAO,KAAK,MAAM,aAAa,KAAK,EAAE,CAAG,CACxE,IAAW,QAAQA,EAAe,CAAE,KAAK,MAAM,aAAa,KAAK,GAAIA,CAAK,CAAG,CAK7E,IAAW,OAAc,CAAE,OAAO,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