Engine API Reference - v2.20.0-beta.0
    Preparing search index...

    Class GSplatContainer

    A container for procedural Gaussian Splat data. This class allows you to create splat data programmatically using either a built-in format or a custom format with your own texture streams and read code.

    A default format is provided via GSplatFormat.createDefaultFormat which uses float textures for easy CPU population.

    // Example 1: Using the default format (easy CPU population)
    const format = pc.GSplatFormat.createDefaultFormat(device);
    const container = new pc.GSplatContainer(device, 100, format);

    // Float format textures are straightforward to fill
    const centerTex = container.getTexture('dataCenter');
    const pixels = centerTex.lock();
    // pixels is Float32Array, fill with [x, y, z, 0, x, y, z, 0, ...]
    centerTex.unlock();

    // Set bounding box
    container.aabb = new pc.BoundingBox();

    // fill centers only if you need CPU sorting or non-unified rendering
    container.centers.set([x0, y0, z0, x1, y1, z1, ...]); // xyz per splat

    // Add to scene
    entity.addComponent('gsplat', { resource: container, unified: true });
    // Example 2: Using a custom format
    const format = new pc.GSplatFormat(device, [
    { name: 'data', format: pc.PIXELFORMAT_RGBA32F }
    ], {
    // Shader code to read splat attributes from the texture
    readGLSL: `
    vec4 d = loadData();
    splatCenter = d.xyz;
    splatColor = vec4(1.0);
    splatScale = vec3(d.w);
    splatRotation = vec4(0, 0, 0, 1);
    `,
    readWGSL: `
    let d = loadData();
    splatCenter = d.xyz;
    splatColor = vec4f(1.0);
    splatScale = vec3f(d.w);
    splatRotation = vec4f(0, 0, 0, 1);
    `
    });

    const container = new pc.GSplatContainer(device, 100, format);
    Index

    Constructors

    Properties

    _centers: Float32Array<ArrayBufferLike> | null

    Accessors

    • get centers(): Float32Array<ArrayBufferLike>

      CPU-side splat center positions (xyz per splat), or null when not built for this resource.

      Returns Float32Array<ArrayBufferLike>

    • set centers(value: Float32Array<ArrayBufferLike>): void

      CPU-side xyz per splat. Allocated lazily on first read; GPU-only unified rendering can omit touching this property to avoid the extra buffer.

      Parameters

      Returns void

    • get format(): GSplatFormat

      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.

      Returns GSplatFormat

    • get hasCenters(): boolean

      True when a centers buffer has been allocated (GSplatResourceBase#centers is non-null). Reads internal storage only so checks do not trigger lazy allocation in GSplatContainer.

      Returns boolean

    • get maxSplats(): number

      Maximum number of splats this container can hold.

      Returns number

    • get numSplats(): number

      Gets the number of splats to render.

      Returns number

    • get textureDimensions(): Vec2

      Gets the texture dimensions (width and height) used by this resource's data textures.

      Returns Vec2

    Methods

    • Protected

      Actually destroys this resource and releases all GPU resources. Derived classes should override this method instead of destroy().

      Returns void

    • Destroys this resource. If the resource is still in use by the sorter, destruction is automatically deferred until it's safe.

      Returns void

    • Gets a texture by name.

      Parameters

      • name: string

        The name of the texture.

      Returns Texture | null

      The texture, or null if not found.

    • Updates the container after modifying texture data and centers. Call this after filling data to signal that the container contents have changed.

      Parameters

      • OptionalnumSplats: number = ...

        Number of splats to render. Defaults to current value. Must be between 0 and maxSplats.

      • OptionalcentersUpdated: boolean = true

        Whether the centers array was modified. Set to false when only numSplats changes but center positions remain the same, to avoid the cost of re-cloning centers in the sorter (can be significant for large containers).

      Returns void