Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Support Custom Asset Loading For GSplat Component

未关闭
#315 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
react, typescript
领域
frontend, web-dev

调研方向

从 validation.ts 开始阅读 getPseudoPublicProps 和 createComponentDefinition,然后跟踪 getter-only 属性(例如 GSplatComponent.id)如何进入 schema 并被应用。使用自定义 Asset 示例和报告的 GSplat 失败来验证有效的自定义 Asset 不再触发对只读 id 的赋值,同时现有的组件行为保持不变。

由索引模型根据 Issue 内容生成。

描述

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!

主要语言
TypeScript
星标
544
派生
60
平均合并
23 分钟
30 天内合并 PR
1

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

playcanvas/react 的其他 Issue

查看 playcanvas/react 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。