Skip to content

SplatMesh.forEachSplat() returns 0 splats at onLoad when using paged .rad files #317

@Alecapra96

Description

@Alecapra96

When loading a .rad file with paged: true, onLoad fires before any splat data is available. At that point:

splatMesh.numSplats === 0
splatMesh.packedSplats === undefined
splatMesh.isInitialized === true
splatMesh.forEachSplat() iterates 0 splats

This makes it impossible to compute a bounding box (or do any per-splat work) at load time for paged .rad files.

Additionally, SplatMesh.getBoundingBox() throws "Bounding box requires PackedSplats or ExtSplats" in this state, even though isInitialized is true.

Image
  • Reproduction
const splat = new SplatMesh({
  url: 'my-file.rad',
  paged: true,
  onLoad: () => {
    console.log(splat.numSplats);      // 0
    console.log(splat.packedSplats);   // undefined
    console.log(splat.isInitialized);  // true
    splat.forEachSplat(() => {});      // iterates 0 times
    splat.getBoundingBox();            // throws: "Bounding box requires PackedSplats or ExtSplats"
  }
});
  • Expected behavior

Either:

onLoad fires only after the first chunk of splat data is available (so numSplats > 0), or
A separate callback like onFirstChunkLoaded / onSplatsReady is provided for paged files, or
getBoundingBox() and forEachSplat() work correctly once isInitialized === true, regardless of paging mode

  • Workaround

Currently working around this by polling numSplats in onFrame:

const splat = new SplatMesh({
  url: 'my-file.rad',
  paged: true,
  onFrame: ({ mesh }) => {
    if (mesh.numSplats > 0 && !boundingBoxComputed) {
      // compute bounding box here
      boundingBoxComputed = true;
    }
  }
});
  • Environment

@sparkjsdev/spark version: 2.0.0
File format: .rad with paged: true
THREE.js version: r180

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions