-
Notifications
You must be signed in to change notification settings - Fork 34
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!