playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
235 lines (234 loc) • 8.72 kB
TypeScript
/**
* Base class for a GSplat resource and defines common properties.
*
* @ignore
*/
export class GSplatResourceBase {
static createMesh(device: any): Mesh;
static get instanceSize(): number;
/**
* @param {GraphicsDevice} device - The graphics device.
* @param {object} gsplatData - Data source with getCenters(), calcAabb(), numSplats, etc.
* @param {object} [options] - Construction options.
* @param {boolean} [options.prepareCenters] - When omitted or true, calls gsplatData.getCenters()
* and stores the result. When false, {@link GSplatResourceBase#centers} stays null until set or
* materialized by a subclass (e.g. lazy allocation in GSplatContainer).
*/
constructor(device: GraphicsDevice, gsplatData: object, options?: {
prepareCenters?: boolean;
});
/**
* @type {GraphicsDevice}
* @ignore
*/
device: GraphicsDevice;
/**
* @type {GSplatData | GSplatCompressedData | GSplatSogData}
* @ignore
*/
gsplatData: GSplatData | GSplatCompressedData | GSplatSogData;
/**
* CPU-side splat center positions (xyz per splat), or null when not built for this resource.
*
* @type {Float32Array|null}
*/
set centers(value: Float32Array<ArrayBufferLike>);
get centers(): Float32Array<ArrayBufferLike>;
/**
* @type {Float32Array|null}
* @protected
*/
protected _centers: Float32Array | null;
/**
* True when a centers buffer has been allocated ({@link GSplatResourceBase#centers} is non-null).
* Reads internal storage only so checks do not trigger lazy allocation in {@link GSplatContainer}.
*
* @type {boolean}
*/
get hasCenters(): boolean;
/**
* Version counter for centers array changes. Remains 0 for static resources.
* Only GSplatContainer increments this via its update() method.
*
* @ignore
*/
centersVersion: number;
/** @type {BoundingBox} */
aabb: BoundingBox;
/**
* @type {Mesh|null}
* @ignore
*/
mesh: Mesh | null;
/**
* @type {number}
* @ignore
*/
id: number;
/**
* Cache for work buffer render materials/shaders. Keyed by configuration hash.
* Stored per-resource because materials depend on resource-specific configuration
* (SH bands, textures, defines). Cleaned up when resource is destroyed.
*
* @type {Map<string, WorkBufferRenderInfo>}
* @ignore
*/
workBufferRenderInfos: Map<string, WorkBufferRenderInfo>;
/**
* Format descriptor for this resource. Assigned by derived classes.
*
* @type {GSplatFormat}
* @protected
*/
protected _format: GSplatFormat;
/**
* Manages textures for this resource based on format streams.
*
* @type {GSplatStreams}
* @ignore
*/
streams: GSplatStreams;
/**
* Non-texture uniform parameters required by this resource's format.
* This is the single source of truth for format-specific uniforms (e.g., dequantization
* parameters) used by both material configuration and processing.
*
* @type {Map<string, any>}
* @ignore
*/
parameters: Map<string, any>;
/** @private */
private _refCount;
/** @private */
private _meshRefCount;
/**
* Destroys this resource. If the resource is still in use by the sorter, destruction is
* automatically deferred until it's safe.
*/
destroy(): void;
/**
* Actually destroys this resource and releases all GPU resources.
* Derived classes should override this method instead of destroy().
*
* @protected
*/
protected _actualDestroy(): void;
/**
* Increments the reference count.
*
* @ignore
*/
incRefCount(): void;
/**
* Decrements the reference count.
*
* @ignore
*/
decRefCount(): void;
/**
* Gets the current reference count. This represents how many times this resource is currently
* being used internally by the engine. For {@link GSplatComponent#asset|assets} assigned to
* {@link GSplatComponent#unified|unified} gsplat components, this tracks active usage during
* rendering and sorting operations.
*
* Resources should not be unloaded while the reference count is non-zero, as they are still
* in use by the rendering pipeline.
*
* @type {number}
* @ignore
*/
get refCount(): number;
/**
* Ensures mesh and instanceIndices exist. Creates them lazily on first call. Must be paired
* with a call to releaseMesh() when done.
*
* @ignore
*/
ensureMesh(): void;
/**
* Releases reference to mesh. When all references are released, cleans up instanceIndices.
* The mesh itself is destroyed by MeshInstance when its internal refCount reaches zero.
*
* @ignore
*/
releaseMesh(): void;
/**
* True when this resource's color-only work buffer updates (spherical harmonics refresh) can
* source geometry from the work buffer itself instead of re-reading the source textures. The
* resource format's read chunk must compile out getCenter/getRotation/getScale when
* GSPLAT_WORKBUFFER_GEOMETRY is defined (see gsplatWorkBufferGeometryPS chunk).
*
* @type {boolean}
* @ignore
*/
get supportsWorkBufferGeometry(): boolean;
/**
* Get or create a QuadRender for rendering to work buffer.
*
* @param {boolean} colorOnly - Whether to render only color (not full MRT).
* @param {{ code: string, hash: number }|null} workBufferModifier - Optional custom modifier (object with code and pre-computed hash).
* @param {number} formatHash - Captured format hash for shader caching.
* @param {string} formatDeclarations - Captured format declarations for shader compilation.
* @param {GSplatFormat} workBufferFormat - The work buffer format descriptor.
* @returns {WorkBufferRenderInfo} The WorkBufferRenderInfo instance.
* @ignore
*/
getWorkBufferRenderInfo(colorOnly: boolean, workBufferModifier: {
code: string;
hash: number;
} | null, formatHash: number, formatDeclarations: string, workBufferFormat: GSplatFormat): WorkBufferRenderInfo;
get numSplats(): any;
/**
* Gets the format descriptor for this resource. The format defines texture streams and
* shader code for reading splat data. Use this to add extra streams.
*
* @type {GSplatFormat}
*/
get format(): GSplatFormat;
/**
* Gets a texture by name.
*
* @param {string} name - The name of the texture.
* @returns {Texture|null} The texture, or null if not found.
*/
getTexture(name: string): Texture | null;
/**
* Gets the texture dimensions (width and height) used by this resource's data textures.
*
* @type {Vec2}
*/
get textureDimensions(): Vec2;
/**
* Configures a material to use this resource's data. Base implementation injects format's
* shader chunks and binds textures from the streams.
*
* @param {ShaderMaterial} material - The material to configure.
* @param {{ code: string, hash: number }|null} workBufferModifier - Optional custom modifier (object with code and pre-computed hash).
* @param {string} formatDeclarations - Captured format declarations for shader compilation.
* @ignore
*/
configureMaterial(material: ShaderMaterial, workBufferModifier: {
code: string;
hash: number;
} | null, formatDeclarations: string): void;
/**
* Configures material defines for this resource. Derived classes should override this.
*
* @param {Map<string, string|number|boolean>} defines - The defines map to configure.
* @ignore
*/
configureMaterialDefines(defines: Map<string, string | number | boolean>): void;
instantiate(): void;
}
import type { GraphicsDevice } from '../../platform/graphics/graphics-device.js';
import type { GSplatData } from './gsplat-data.js';
import type { GSplatCompressedData } from './gsplat-compressed-data.js';
import type { GSplatSogData } from './gsplat-sog-data.js';
import { BoundingBox } from '../../core/shape/bounding-box.js';
import { Mesh } from '../mesh.js';
import { WorkBufferRenderInfo } from '../gsplat-unified/gsplat-work-buffer.js';
import type { GSplatFormat } from './gsplat-format.js';
import { GSplatStreams } from './gsplat-streams.js';
import type { Texture } from '../../platform/graphics/texture.js';
import type { Vec2 } from '../../core/math/vec2.js';
import { ShaderMaterial } from '../materials/shader-material.js';