Support Custom Asset Loading For GSplat Component
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 528
- Forks
- 60
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Description
Description
I'm trying to use the component with a custom-loaded asset instead of relying on useSplat(url). My use case requires preprocessing .ply files with a @playcanvas/splat-transform based loader , similar to how the superSplat loader works.
Here is my implementation:
const fileSystem = new UrlReadFileSystem(typeof window !== 'undefined' ? window.location.origin : '');
async function load(filename: string, app: pc.Application, fileSystem: UrlReadFileSystem): Promise<Asset> {
const gsplatData = await loadGSplatData(filename, fileSystem);
const resource = new pc.GSplatResource(app.graphicsDevice, gsplatData);
const asset = new Asset(filename, 'gsplat', { url: `/assets/temp-splats/${filename}` });
asset.resource = resource;
asset.loaded = true;
app.assets.add(asset);
return asset;
}
const Scene = () => {
const [cur_asset, setCurAsset] = useState<Asset | null>(null);
const app = CreateApp();
useEffect(() => {
if (!app) return;
load('/assets/temp-splats/scene.ply', app, fileSystem)
.then(setCurAsset)
.catch(console.error);
}, [app]);
return (
<Entity name="splat">
{cur_asset && <GSplat asset={cur_asset} />}
</Entity>
);
};
When trying to pass a custom-constructed Asset to , I get:
Cannot set property id of #<GSplatComponent> which has only a getter
at createComponentDefinition (validation.ts:382)
Root Cause
The root cause is that getPseudoPublicProps (validation.ts) includes getter-only props. When descriptor.get exists and hasSetter is false, it still adds the property with isDefinedWithSetter: false: ->The component schema generation in createComponentDefinition doesn't filter out getter-only properties like GSplatComponent.id when building the prop schema. This path (which would be for custom asset loading) isn't currently supported or tested, so the schema application fails.
In detail the trigger is the assignment step that triggers the error. id is always in the schema, always gets a default, and is always included in safeProps. When applyProps runs, it tries to assign every prop, including id, and that assignment throws because id has no setter.
So:
It’s not the asset loading path that sets id.
It’s the generic “apply all schema props” logic that tries to set id to its default.
The failure would occur even with asset={null} or no props at all, because id is always present in the schema and always applied
I've already prepared a fix PR to support custom asset loaders. I believe the fix should be fairly minor and should allow custom asset loading as long as it abides by the Asset class defined in the documentation.
GSplat asset Property Documentation (PlayCanvas React API):
"asset? number | Asset
'Sets the gsplat asset for this gsplat component. Can also be an asset id. Gets the gsplat asset id for this gsplat component.'
Note: Assuming React support is meant to be flexible, having full loader control is essential IMO and not supporting valid custom Assets is a bit of a bummer. So I'll ensure my fix is up to par and it should only provide extra support without harming functionality.
Conclusion
Just wanted to share to see if anyone had similar type errors or issues I noticed the Element Component bug and from what I can tell it could also be resolved from my fix while not necessarily being a direct application. Even some proper handling in this area should be required as some custom error handling and debug support would be nice - as mentioned by the user of the element component issue. :)
I hope everyone is having a great day!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in validation.ts by reading getPseudoPublicProps and createComponentDefinition, then trace how getter-only properties such as GSplatComponent.id enter the schema and are applied. Use the custom Asset example and the reported GSplat failure to verify that valid custom assets no longer trigger the read-only id assignment while existing component behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100