playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
231 lines (230 loc) • 7.9 kB
TypeScript
/**
* @import { BoundingBox } from '../../core/shape/bounding-box.js'
* @import { GraphicsDevice } from '../../platform/graphics/graphics-device.js'
* @import { GraphNode } from '../graph-node.js'
* @import { GSplatResource } from '../gsplat/gsplat-resource.js'
* @import { GSplatResourceBase } from '../gsplat/gsplat-resource-base.js'
* @import { GSplatOctreeResource } from './gsplat-octree.resource.js'
* @import { ScopeId } from '../../platform/graphics/scope-id.js'
* @import { Texture } from '../../platform/graphics/texture.js'
* @import { Vec2 } from '../../core/math/vec2.js'
*/
/**
* Class representing a placement of a gsplat resource.
*
* @ignore
*/
export class GSplatPlacement {
/**
* Create a new GSplatPlacement.
*
* @param {GSplatResource|null} resource - The resource of the splat.
* @param {GraphNode} node - The node that the gsplat is linked to.
* @param {number} [lodIndex] - The LOD index for this placement.
* @param {Map<string, {scopeId: ScopeId, data: *}>|null} [parameters] - Per-instance shader parameters.
* @param {GSplatPlacement|null} [parentPlacement] - Parent placement for shader config delegation.
* @param {number|null} [id] - Unique identifier for picking. If not provided, inherits from parentPlacement.
*/
constructor(resource: GSplatResource | null, node: GraphNode, lodIndex?: number, parameters?: Map<string, {
scopeId: ScopeId;
data: any;
}> | null, parentPlacement?: GSplatPlacement | null, id?: number | null);
/**
* The resource of the splat..
*
* @type {GSplatResource|GSplatOctreeResource|null}
*/
resource: GSplatResource | GSplatOctreeResource | null;
/**
* The node that the gsplat is linked to.
*
* @type {GraphNode}
*/
node: GraphNode;
/**
* Map of intervals for octree nodes using this placement.
* Key is octree node index, value is Vec2 representing start and end index (inclusive).
*
* @type {Map<number, Vec2>}
*/
intervals: Map<number, Vec2>;
/**
* Unique identifier for this placement. Used by the picking system and available
* for custom shader effects.
*/
id: number;
/**
* Unique allocation identifier for persistent work buffer allocation tracking.
*
* @type {number}
*/
allocId: number;
/**
* The LOD index for this placement.
*/
lodIndex: number;
/**
* Base distance for the first LOD transition (LOD 0 to LOD 1).
*
* @private
*/
private _lodBaseDistance;
/**
* Geometric multiplier between successive LOD distance thresholds.
* Distance for LOD level i is: lodBaseDistance * lodMultiplier^i.
*
* @private
*/
private _lodMultiplier;
/**
* @type {number}
*/
set lodBaseDistance(value: number);
get lodBaseDistance(): number;
/**
* Flag indicating LOD parameters have changed and LOD needs re-evaluation.
*/
lodDirty: boolean;
/**
* @type {number}
*/
set lodMultiplier(value: number);
get lodMultiplier(): number;
/**
* The axis-aligned bounding box for this placement, in local space.
* Null means use resource.aabb as fallback.
*
* @type {BoundingBox|null}
*/
_aabb: BoundingBox | null;
/**
* Per-instance shader parameters. Reference to the component's parameters Map.
*
* @type {Map<string, {scopeId: ScopeId, data: *}>|null}
*/
parameters: Map<string, {
scopeId: ScopeId;
data: any;
}> | null;
/**
* Optional streams for instance-level textures.
*
* @type {GSplatStreams|null}
* @private
*/
private _streams;
/**
* Flag indicating the splat needs to be re-rendered to work buffer.
*/
renderDirty: boolean;
/**
* Work buffer update mode.
*
* @type {number}
*/
workBufferUpdate: number;
/**
* Last seen format version for auto-detecting format changes.
*
* @private
*/
private _lastFormatVersion;
/**
* Custom work buffer modifier code for this placement (object with code and pre-computed hash).
*
* @type {{ code: string, hash: number }|null}
* @private
*/
private _workBufferModifier;
/**
* Parent placement. Used by octree file placements to inherit workBufferModifier and
* parameters from the component's placement.
*
* @type {GSplatPlacement|null}
* @ignore
*/
parentPlacement: GSplatPlacement | null;
/**
* Destroys this placement and releases all resources.
*/
destroy(): void;
/**
* Sets the work buffer modifier for this placement. Triggers work buffer re-render.
* Must provide all three functions: modifySplatCenter, modifySplatRotationScale, modifySplatColor.
*
* @type {{ code: string, hash: number }|null}
*/
set workBufferModifier(value: {
code: string;
hash: number;
} | null);
/**
* Gets the work buffer modifier for this placement.
* Delegates to parent placement if available (for octree file placements).
*
* @type {{ code: string, hash: number }|null}
*/
get workBufferModifier(): {
code: string;
hash: number;
} | null;
/**
* Returns and clears the render dirty flag. Also checks for format version changes
* and handles render mode.
*
* @returns {boolean} True if the splat needed re-rendering.
*/
consumeRenderDirty(): boolean;
/**
* Sets a custom AABB for this placement. Pass null to use resource.aabb as fallback.
*
* @param {BoundingBox|null} aabb - The bounding box to set, or null to clear.
*/
set aabb(aabb: BoundingBox | null);
/**
* Gets the AABB for this placement. Returns custom AABB if set, otherwise resource.aabb.
*
* @returns {BoundingBox} The bounding box.
*/
get aabb(): BoundingBox;
/**
* Computes the LOD distance threshold for a given level using the geometric progression.
*
* @param {number} level - The LOD level index.
* @returns {number} The distance threshold for the given LOD level.
*/
getLodDistance(level: number): number;
/**
* Gets an instance-level texture by name. Creates the streams container on first access
* if the format has instance streams defined.
*
* @param {string} name - The name of the texture to get.
* @param {GraphicsDevice} device - The graphics device (required for lazy initialization).
* @returns {Texture|undefined} The texture, or undefined if not found.
*/
getInstanceTexture(name: string, device: GraphicsDevice): Texture | undefined;
/**
* Gets the instance streams container, or null if not initialized.
* Delegates to parent placement if available (for octree file placements).
*
* @type {GSplatStreams|null}
* @ignore
*/
get streams(): GSplatStreams | null;
/**
* Ensures instance streams container exists if format has instance streams.
*
* @param {GraphicsDevice} device - The graphics device.
* @ignore
*/
ensureInstanceStreams(device: GraphicsDevice): void;
}
import type { GSplatResource } from '../gsplat/gsplat-resource.js';
import type { GSplatOctreeResource } from './gsplat-octree.resource.js';
import type { GraphNode } from '../graph-node.js';
import type { Vec2 } from '../../core/math/vec2.js';
import type { BoundingBox } from '../../core/shape/bounding-box.js';
import type { ScopeId } from '../../platform/graphics/scope-id.js';
import type { GraphicsDevice } from '../../platform/graphics/graphics-device.js';
import type { Texture } from '../../platform/graphics/texture.js';
import { GSplatStreams } from '../gsplat/gsplat-streams.js';