|
2 | 2 |
|
3 | 3 | import { FC } from "react"; |
4 | 4 | import { useComponent } from "../hooks/index.ts"; |
5 | | -import { Asset, Entity, GSplatComponent } from "playcanvas"; |
| 5 | +import { Asset, Entity, GSplatComponent, GSplatInstance, ShaderMaterial } from "playcanvas"; |
6 | 6 | import { PublicProps } from "../utils/types-utils.ts"; |
7 | 7 | import { validatePropsWithDefaults, createComponentDefinition, getStaticNullApplication } from "../utils/validation.ts"; |
8 | 8 | /** |
@@ -60,5 +60,31 @@ componentDefinition.schema = { |
60 | 60 | instance.unified = value; |
61 | 61 | instance.enabled = true; |
62 | 62 | } |
| 63 | + }, |
| 64 | + material: { |
| 65 | + validate: (val: unknown) => val === null || val instanceof ShaderMaterial, |
| 66 | + errorMsg: (val: unknown) => `Invalid value for prop "material": "${val}". Expected a ShaderMaterial or null.`, |
| 67 | + default: null, |
| 68 | + apply: (instance: GSplatComponent, props: Record<string, unknown>, key: string) => { |
| 69 | + const value = props[key] as ShaderMaterial | null; |
| 70 | + if (instance.material === value) { |
| 71 | + return; |
| 72 | + } |
| 73 | + if (value) { |
| 74 | + instance.material = value; |
| 75 | + } |
| 76 | + } |
| 77 | + }, |
| 78 | + instance: { |
| 79 | + validate: (val: unknown) => val === null || val instanceof GSplatInstance, |
| 80 | + errorMsg: (val: unknown) => `Invalid value for prop "instance": "${val}". Expected a GSplatInstance or null.`, |
| 81 | + default: null, |
| 82 | + apply: (instance: GSplatComponent, props: Record<string, unknown>, key: string) => { |
| 83 | + const value = props[key] as GSplatInstance | null; |
| 84 | + if (instance.instance === value) { |
| 85 | + return; |
| 86 | + } |
| 87 | + instance.instance = value; |
| 88 | + } |
63 | 89 | } |
64 | 90 | } |
0 commit comments