Engine API Reference - v2.16.1
    Preparing search index...

    Class GSplatComponent

    The GSplatComponent enables an Entity to render 3D Gaussian Splats. Splats are always loaded from Assets rather than being created programmatically. The asset type is gsplat which supports multiple file formats including .ply, .sog, .meta.json (SOG format), and .lod-meta.json (streaming LOD format).

    You should never need to use the GSplatComponent constructor directly. To add an GSplatComponent to an Entity, use Entity#addComponent:

    const entity = pc.Entity();
    entity.addComponent('gsplat', {
    asset: asset
    });

    Once the GSplatComponent is added to the entity, you can access it via the Entity#gsplat property:

    entity.gsplat.customAabb = new pc.BoundingBox(new pc.Vec3(), new pc.Vec3(10, 10, 10));

    console.log(entity.gsplat.customAabb);

    The GSplatComponent#unified property enables unified rendering mode, which provides advanced features for Gaussian Splats:

    • Global Sorting: Multiple splat components are sorted together in a single unified sort, eliminating visibility artifacts and popping effects when splat components overlap.
    • LOD Streaming: Dynamically loads and renders appropriate levels of detail based on camera distance, enabling efficient rendering of massive splat scenes.
    // Enable unified rendering for advanced features
    entity.gsplat.unified = true;

    Relevant Engine API examples:

    Hierarchy (View Summary)

    Index

    Properties

    entity: Entity

    The Entity that this Component is attached to.

    The ComponentSystem used to create this Component.

    Accessors

    • get highQualitySH(): boolean

      Gets whether the high quality (true) or the fast approximate (false) spherical-harmonic calculation is used when rendering SOG data.

      Returns boolean

    • set highQualitySH(value: boolean): void

      Sets whether to use the high quality or the approximate (but fast) spherical-harmonic calculation when rendering SOG data.

      The low quality approximation evaluates the scene's spherical harmonic contributions along the camera's Z-axis instead of using each gaussian's view vector. This results in gaussians being accurate at the center of the screen and becoming less accurate as they appear further from the center. This is a good trade-off for performance when rendering large SOG datasets, especially on mobile devices.

      Defaults to false.

      Parameters

      • value: boolean

      Returns void

    • get id(): number

      Gets the unique identifier for this component. This ID is used by the picking system and is also written to the work buffer when app.scene.gsplat.enableIds is enabled, making it available to custom shaders for effects like highlighting or animation.

      Returns number

    • get resource(): GSplatResourceBase | null

      Gets the GSplat resource. Returns the directly set resource if available, otherwise returns the resource from the assigned asset.

      Returns GSplatResourceBase | null

    • set resource(value: GSplatResourceBase | null): void

      Sets a GSplat resource directly (for procedural/container splats). When set, this takes precedence over the asset property.

      Parameters

      • value: GSplatResourceBase | null

      Returns void

    • get splatBudget(): number

      Gets the splat budget limit for this component.

      Returns number

    • set splatBudget(value: number): void

      Sets the target number of splats to render for this component. The system will adjust LOD levels bidirectionally to reach this budget:

      • When over budget: degrades quality for less important geometry
      • When under budget: upgrades quality for more important geometry

      This ensures optimal use of available rendering budget while prioritizing quality for closer/more important geometry.

      Set to 0 to disable the budget (default). When disabled, optimal LOD is determined purely by distance and configured LOD parameters.

      Only applies to octree-based gsplat rendering in unified mode.

      Parameters

      • value: number

      Returns void

    • get workBufferUpdate(): number

      Gets the work buffer update mode.

      Returns number

    • set workBufferUpdate(value: number): void

      Sets the work buffer update mode. Only applicable in unified rendering mode.

      In unified mode, splat data is rendered to a work buffer only when needed (e.g., when transforms change). Can be:

      This is typically useful when using custom shader code via workBufferModifier that depends on external factors like time or animated uniforms.

      Note: WORKBUFFER_UPDATE_ALWAYS has a performance impact as it re-renders all splat data to the work buffer every frame. Where possible, consider using shader customization on the unified gsplat material (app.scene.gsplat.material) which is applied during final rendering without re-rendering the work buffer.

      Parameters

      • value: number

      Returns void

    Methods

    • Fire an event, all additional arguments are passed on to the event listener.

      Parameters

      • name: string

        Name of event to fire.

      • Optionalarg1: any

        First argument that is passed to the event handler.

      • Optionalarg2: any

        Second argument that is passed to the event handler.

      • Optionalarg3: any

        Third argument that is passed to the event handler.

      • Optionalarg4: any

        Fourth argument that is passed to the event handler.

      • Optionalarg5: any

        Fifth argument that is passed to the event handler.

      • Optionalarg6: any

        Sixth argument that is passed to the event handler.

      • Optionalarg7: any

        Seventh argument that is passed to the event handler.

      • Optionalarg8: any

        Eighth argument that is passed to the event handler.

      Returns EventHandler

      Self for chaining.

      obj.fire('test', 'This is the message');
      
    • Gets an instance texture by name. Instance textures are per-component textures defined in the resource's format with storage: GSPLAT_STREAM_INSTANCE. Only available in unified mode.

      Parameters

      • name: string

        The name of the texture.

      Returns Texture | null

      The texture, or null if not found or not in unified mode.

      // Add an instance stream to the resource format
      resource.format.addExtraStreams([
      { name: 'instanceTint', format: pc.PIXELFORMAT_RGBA8, storage: pc.GSPLAT_STREAM_INSTANCE }
      ]);

      // Get the instance texture and fill it with data
      const texture = entity.gsplat.getInstanceTexture('instanceTint');
      if (texture) {
      const data = texture.lock();
      // Fill texture data...
      texture.unlock();
      }
    • Gets a shader parameter value previously set with setParameter.

      Parameters

      • name: string

        The name of the parameter.

      Returns number | number[] | ArrayBufferView<ArrayBufferLike> | undefined

      The parameter value, or undefined if not set.

    • Test if there are any handlers bound to an event name.

      Parameters

      • name: string

        The name of the event to test.

      Returns boolean

      True if the object has handlers bound to the specified event name.

      obj.on('test', () => {}); // bind an event to 'test'
      obj.hasEvent('test'); // returns true
      obj.hasEvent('hello'); // returns false
    • Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.

      Parameters

      • Optionalname: string

        Name of the event to unbind.

      • Optionalcallback: HandleEventCallback

        Function to be unbound.

      • Optionalscope: any

        Scope that was used as the this when the event is fired.

      Returns EventHandler

      Self for chaining.

      const handler = () => {};
      obj.on('test', handler);

      obj.off(); // Removes all events
      obj.off('test'); // Removes all events called 'test'
      obj.off('test', handler); // Removes all handler functions, called 'test'
      obj.off('test', handler, this); // Removes all handler functions, called 'test' with scope this
    • Attach an event handler to an event.

      Parameters

      • name: string

        Name of the event to bind the callback to.

      • callback: HandleEventCallback

        Function that is called when event is fired. Note the callback is limited to 8 arguments.

      • Optionalscope: any = ...

        Object to use as 'this' when the event is fired, defaults to current this.

      Returns EventHandle

      Can be used for removing event in the future.

      obj.on('test', (a, b) => {
      console.log(a + b);
      });
      obj.fire('test', 1, 2); // prints 3 to the console
      const evt = obj.on('test', (a, b) => {
      console.log(a + b);
      });
      // some time later
      evt.off();
    • Attach an event handler to an event. This handler will be removed after being fired once.

      Parameters

      • name: string

        Name of the event to bind the callback to.

      • callback: HandleEventCallback

        Function that is called when event is fired. Note the callback is limited to 8 arguments.

      • Optionalscope: any = ...

        Object to use as 'this' when the event is fired, defaults to current this.

      Returns EventHandle

      Can be used for removing event in the future.

      obj.once('test', (a, b) => {
      console.log(a + b);
      });
      obj.fire('test', 1, 2); // prints 3 to the console
      obj.fire('test', 1, 2); // not going to get handled
    • Sets a shader parameter for this gsplat instance. Parameters set here are applied during unified rendering.

      Parameters

      • name: string

        The name of the parameter (uniform name in shader).

      • data: number | number[] | ArrayBufferView<ArrayBufferLike> | StorageBuffer | Texture

        The value for the parameter.

      Returns void

    • Sets custom shader code for modifying splats when written to the work buffer. Only applicable in unified rendering mode.

      Must provide all three functions:

      • modifySplatCenter: Modify the splat center position
      • modifySplatRotationScale: Modify the splat rotation and scale
      • modifySplatColor: Modify the splat color

      Calling this method automatically triggers a work buffer re-render.

      Parameters

      • value: { glsl?: string; wgsl?: string } | null

        The modifier code for GLSL and/or WGSL.

      Returns void

      entity.gsplat.setWorkBufferModifier({
      glsl: `
      void modifySplatCenter(inout vec3 center) {}
      void modifySplatRotationScale(vec3 originalCenter, vec3 modifiedCenter, inout vec4 rotation, inout vec3 scale) {}
      void modifySplatColor(vec3 center, inout vec4 color) { color.rgb *= vec3(1.0, 0.0, 0.0); }
      `,
      wgsl: `
      fn modifySplatCenter(center: ptr<function, vec3f>) {}
      fn modifySplatRotationScale(originalCenter: vec3f, modifiedCenter: vec3f, rotation: ptr<function, vec4f>, scale: ptr<function, vec3f>) {}
      fn modifySplatColor(center: vec3f, color: ptr<function, vec4f>) { (*color).r = 1.0; (*color).g = 0.0; (*color).b = 0.0; }
      `
      });