{"version":3,"file":"index.cjs","sources":["../../src/core/InstancedEntity.ts","../../src/core/InstancedMeshBVH.ts","../../src/core/utils/GLInstancedBufferAttribute.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.ts","../../src/shaders/chunks/instanced_color_pars_vertex.glsl.ts","../../src/shaders/chunks/instanced_vertex.glsl.ts","../../src/shaders/chunks/instanced_color_vertex.glsl.ts","../../src/shaders/chunks/instanced_skinning_pars_vertex.glsl.ts","../../src/shaders/ShaderChunk.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: 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    const quaternion = this.quaternion = new Quaternion();\r\n\r\n    if (useEuler) {\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   * 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    owner.bvh?.move(id);\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    owner.bvh?.move(id);\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\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: Uint32Array = 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 = new Map();\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    // 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 { 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: boolean = false;\r\n  protected _lastWidth: number = null;\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    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  /**\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   */\r\n  public update(renderer: WebGLRenderer): void {\r\n    const textureProperties: any = renderer.properties.get(this);\r\n    const versionChanged = this.version > 0 && textureProperties.__version !== this.version;\r\n    const sizeChanged = this._lastWidth !== null && this._lastWidth !== this.image.width;\r\n    if (!this._needsUpdate || !textureProperties.__webglTexture || versionChanged || sizeChanged) {\r\n      this._lastWidth = this.image.width;\r\n      this._needsUpdate = false;\r\n      return;\r\n    }\r\n\r\n    this._needsUpdate = false;\r\n\r\n    if (!this.partialUpdate) {\r\n      this.needsUpdate = true; // three.js will update the whole texture\r\n      return;\r\n    }\r\n\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.needsUpdate = true; // three.js will update the whole texture\r\n    } else {\r\n      this.updateRows(textureProperties, renderer, rowsInfo);\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[]): void {\r\n    const state = renderer.state;\r\n    const gl = renderer.getContext() as WebGL2RenderingContext;\r\n    // @ts-expect-error Expected 2 arguments, but got 3.\r\n    if (!this._utils) 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    state.bindTexture(gl.TEXTURE_2D, textureProperties.__webglTexture);\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    if (this.onUpdate) this.onUpdate();\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, SkinnedMesh, 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 { 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\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\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   * @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   * 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 */ _count = 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  protected readonly _allowsEuler: boolean;\r\n  protected readonly _tempInstance: InstancedEntity;\r\n  protected _useOpacity = false;\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 _propertiesGetBase: (obj: unknown) => unknown = null;\r\n  protected _propertiesGetMap = new WeakMap<Material, (obj: unknown) => unknown>();\r\n  protected _properties = new WeakMap<Material, unknown>();\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 instances rendered in the last frame.\r\n   */\r\n  public get count(): number { return this._count; }\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  /**\r\n   * Create an `InstancedMesh2` instance from an existing `Mesh`.\r\n   * @param mesh The mesh 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\n  public static createFrom<TData = {}>(mesh: Mesh, params: InstancedMesh2Params = {}): InstancedMesh2<TData> {\r\n    const instancedMesh = new InstancedMesh2<TData>(mesh.geometry, mesh.material, params);\r\n\r\n    if ((mesh as SkinnedMesh).isSkinnedMesh) {\r\n      instancedMesh.initSkeleton((mesh as SkinnedMesh).skeleton);\r\n    }\r\n\r\n    // TODO add morph\r\n\r\n    return instancedMesh;\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.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    // if multimaterial we compute frustum culling only on first material\r\n    if (!this.instanceIndex || (group && !this.isFirstGroup(group.materialIndex))) return;\r\n\r\n    if (this.autoUpdate) {\r\n      this.performFrustumCulling(shadowCamera, camera);\r\n    }\r\n\r\n    this.matricesTexture.update(renderer);\r\n    this.colorsTexture?.update(renderer);\r\n    this.uniformsTexture?.update(renderer);\r\n    this.boneTexture?.update(renderer);\r\n    // TODO convert also morph texture to squared texture to use partial update\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    if (!this.instanceIndex) {\r\n      this._renderer = renderer;\r\n      return;\r\n    }\r\n\r\n    // if multimaterial we compute frustum culling only on first material\r\n    if (group && !this.isFirstGroup(group.materialIndex)) return;\r\n\r\n    if (this.autoUpdate) {\r\n      this.performFrustumCulling(camera);\r\n    }\r\n\r\n    this.matricesTexture.update(renderer);\r\n    this.colorsTexture?.update(renderer);\r\n    this.uniformsTexture?.update(renderer);\r\n    this.boneTexture?.update(renderer);\r\n    // TODO convert also morph texture to squared texture to use partial update\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 isFirstGroup(materialIndex: number): boolean {\r\n    const materials = this.material as Material[];\r\n\r\n    for (let i = 0; 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 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 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 `ezInstancedMesh2_${this.id}_${!!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.instancing = false;\r\n\r\n    if (!shader.defines) shader.defines = {};\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      if (this._useOpacity) {\r\n        shader.defines['USE_COLOR_ALPHA'] = '';\r\n      } else {\r\n        shader.defines['USE_COLOR'] = '';\r\n      }\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    material.customProgramCacheKey = this._customProgramCacheKey;\r\n    material.onBeforeCompile = this._onBeforeCompile;\r\n\r\n    const propertiesBase = renderer.properties;\r\n\r\n    if (!this._properties.has(material)) {\r\n      const materialProperties = {};\r\n      this._properties.set(material, materialProperties);\r\n\r\n      const propertiesGetBase = this._propertiesGetBase = propertiesBase.get;\r\n\r\n      this._propertiesGetMap.set(material, (object) => {\r\n        if (object === material) return materialProperties;\r\n        return propertiesGetBase(object);\r\n      });\r\n    }\r\n\r\n    propertiesBase.get = this._propertiesGetMap.get(material);\r\n  }\r\n\r\n  protected unpatchMaterial(renderer: WebGLRenderer, material: Material): void {\r\n    this._currentMaterial = null;\r\n    renderer.properties.get = this._propertiesGetBase;\r\n    material.onBeforeCompile = this._onBeforeCompileBase;\r\n    material.customProgramCacheKey = this._customProgramCacheKeyBase;\r\n    this._onBeforeCompileBase = null;\r\n    this._customProgramCacheKeyBase = 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    this.bvh?.move(id);\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    if (this.boundingBox === null) 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    if (this.boundingSphere === null) 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._instancesCount = source._instancesCount;\r\n    this._instancesArrayCount = source._instancesArrayCount;\r\n    this._count = source._capacity;\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","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\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): typeof radixSort<InstancedRenderItem> {\r\n  const options: RadixSortOptions<InstancedRenderItem> = {\r\n    get: (el) => el.depthSort,\r\n    aux: new Array(target._capacity),\r\n    reversed: null\r\n  };\r\n\r\n  return function sortFunction(list: InstancedRenderItem[]): void {\r\n    options.reversed = !!(target.material as Material)?.transparent;\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 */ 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  if (!this._parentLOD && this._instancesArrayCount === 0) {\r\n    this._count = 0;\r\n    return;\r\n  }\r\n\r\n  const LODinfo = this.LODinfo;\r\n  const isShadowRendering = camera !== cameraLOD;\r\n  let LODrenderList: LODRenderList;\r\n\r\n  if (LODinfo) {\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  }\r\n\r\n  if (LODrenderList?.levels.length > 0) this.frustumCullingLOD(LODrenderList, camera, cameraLOD);\r\n  else if (!this._parentLOD) this.frustumCulling(camera);\r\n\r\n  this.instanceIndex.update(this._renderer, this._count);\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    // 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  const isShadowRendering = camera !== cameraLOD;\r\n  const sortObjects = !isShadowRendering && this._sortObjects; // sort is disabled when render shadows\r\n\r\n  for (let i = 0; i < levels.length; i++) {\r\n    count[i] = 0;\r\n\r\n    if (levels[i].object.instanceIndex) {\r\n      levels[i].object.instanceIndex._needsUpdate = true; // TODO improve\r\n    }\r\n  }\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)) continue;\r\n\r\n        const distance = _sphere.center.distanceToSquared(_cameraLODPos);\r\n        _renderList.push(distance, i);\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 A callback function 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  // 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  onCreation(instance, id);\r\n  instance.updateMatrix();\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  this.bvh?.clear();\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 and hysteresis.\r\n     * @param distance The distance for the first LOD.\r\n     * @param hysteresis The hysteresis value for the first LOD.\r\n     * @returns The current `InstancedMesh2` instance.\r\n     */\r\n    setFirstLODDistance(distance?: number, hysteresis?: 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    /** @internal */ addLevel(renderList: LODRenderList, geometry: BufferGeometry, material: Material | Material[], distance: number, hysteresis: number): InstancedMesh2;\r\n    /** @internal */ patchLevel(obj: InstancedMesh2): void;\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 = 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.render) {\r\n    this.LODinfo.render = {\r\n      levels: [{ distance, hysteresis, object: this }],\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. Use \"setFirstLODDistance\" before use \"addLOD\".');\r\n  }\r\n\r\n  this.setFirstLODDistance(0, hysteresis);\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); // TODO handle render order?\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.patchLevel = function (obj: InstancedMesh2): void {\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  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","export default /* glsl */`\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`;\r\n","export default /* glsl */`\r\n#ifdef USE_INSTANCING_COLOR_INDIRECT\r\n  uniform highp sampler2D colorsTexture;\r\n\r\n  #ifdef USE_COLOR_ALPHA\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  #else\r\n    vec3 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 ).rgb;\r\n    }\r\n  #endif\r\n#endif\r\n`;\r\n","export default /* glsl */`\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`;\r\n","export default /* glsl */`\r\n#ifdef USE_INSTANCING_COLOR_INDIRECT\r\n  #ifdef USE_VERTEX_COLOR\r\n    vColor = color;\r\n  #else\r\n    #ifdef USE_COLOR_ALPHA\r\n      vColor = vec4( 1.0 );\r\n    #else\r\n      vColor = vec3( 1.0 );\r\n    #endif\r\n  #endif\r\n#endif\r\n`;\r\n","export default /* glsl */`\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`;\r\n","import { ShaderChunk } from 'three';\r\nimport instanced_pars_vertex from './chunks/instanced_pars_vertex.glsl.js';\r\nimport instanced_color_pars_vertex from './chunks/instanced_color_pars_vertex.glsl.js';\r\nimport instanced_vertex from './chunks/instanced_vertex.glsl.js';\r\nimport instanced_color_vertex from './chunks/instanced_color_vertex.glsl.js';\r\nimport instanced_skinning_pars_vertex from './chunks/instanced_skinning_pars_vertex.glsl.js';\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"],"names":["InstancedEntity","owner","id","useEuler","Vector3","quaternion","Quaternion","rotation","Euler","value","position","scale","te","offset","x","y","z","w","x2","y2","z2","xx","xy","xz","yy","yz","zz","wx","wy","wz","sx","sy","sz","_a","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","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","textureProperties","versionChanged","sizeChanged","rowsInfo","rowsToUpdate","result","l","row","info","state","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","material","params","LOD","allowsEuler","createEntities","AttachedBindMode","InstancedBufferAttribute","shader","_defaultCapacity","mesh","instancedMesh","scene","shadowCamera","depthMaterial","group","_b","_c","materialIndex","materials","instanceIndex","propertiesBase","materialProperties","propertiesGetBase","object","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","_d","force","DetachedBindMode","Matrix4","Color","oldCapacity","minCapacity","indexArray","obj","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","LODinfo","isShadowRendering","LODrenderList","sortObjects","perObjectFrustumCulled","customSort","onFrustumEnter","bSphere","geometryCentered","indexes","levelIndex","levelDistance","onUpdate","end","instances","onCreation","freeIds","maxId","freeIdsUsed","freeidsEnd","hysteresis","renderList","objectsList","objIndex","e","ShaderMaterial","_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","instanced_color_pars_vertex","instanced_vertex","instanced_color_vertex","instanced_skinning_pars_vertex","ShaderChunk","patchShader"],"mappings":"2KAWO,MAAMA,EAAgB,CA8E3B,YAAYC,EAAuBC,EAAYC,EAAmB,CA1ElE,KAAgB,iBAAmB,GAY5B,KAAA,SAAW,IAAIC,UAItB,KAAO,MAAQ,IAAIA,EAAAA,QAAQ,EAAG,EAAG,CAAC,EA2DhC,KAAK,GAAKF,EACV,KAAK,MAAQD,EACb,MAAMI,EAAa,KAAK,WAAa,IAAIC,EAAAA,WAEzC,GAAIH,EAAU,CACZ,MAAMI,EAAW,KAAK,SAAW,IAAIC,EAAAA,MAErCD,EAAS,UAAU,IAAMF,EAAW,aAAaE,EAAU,EAAK,CAAC,EACjEF,EAAW,UAAU,IAAME,EAAS,kBAAkBF,EAAY,OAAW,EAAK,CAAC,CAAA,CACrF,CAtDF,IAAW,SAAmB,CAAE,OAAO,KAAK,MAAM,gBAAgB,KAAK,EAAE,CAAA,CACzE,IAAW,QAAQI,EAAgB,CAAE,KAAK,MAAM,gBAAgB,KAAK,GAAIA,CAAK,CAAA,CAK9E,IAAW,QAAkB,CAAE,OAAO,KAAK,MAAM,YAAY,KAAK,EAAE,CAAA,CACpE,IAAW,OAAOA,EAAgB,CAAE,KAAK,MAAM,YAAY,KAAK,GAAIA,CAAK,CAAA,CAKzE,IAAW,OAAe,CAAE,OAAO,KAAK,MAAM,WAAW,KAAK,EAAE,CAAA,CAChE,IAAW,MAAMA,EAA4B,CAAE,KAAK,MAAM,WAAW,KAAK,GAAIA,CAAK,CAAA,CAKnF,IAAW,SAAkB,CAAE,OAAO,KAAK,MAAM,aAAa,KAAK,EAAE,CAAA,CACrE,IAAW,QAAQA,EAAe,CAAE,KAAK,MAAM,aAAa,KAAK,GAAIA,CAAK,CAAA,CAK1E,IAAW,OAAc,CAAE,OAAO,KAAK,MAAM,WAAW,KAAK,EAAE,CAAA,CAC/D,IAAW,MAAMA,EAAa,CAAE,KAAK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