|
1 | 1 | "use client" |
2 | 2 |
|
3 | | -import { FC, ReactElement, useRef, createContext, useContext, useCallback } from "react"; |
| 3 | +import { FC, ReactElement, createContext, useContext } from "react"; |
4 | 4 | import { useComponent } from "../hooks/index.ts"; |
5 | 5 | import { MeshInstance } from "./MeshInstance.tsx"; |
6 | 6 | import { Asset, Entity, MeshInstance as PcMeshInstance, type RenderComponent as PcRenderComponent } from "playcanvas"; |
7 | 7 | import { PublicProps, Serializable } from "../utils/types-utils.ts"; |
8 | 8 | import { getStaticNullApplication, validatePropsPartial, Schema } from "../utils/validation.ts"; |
9 | 9 | import { createComponentDefinition } from "../utils/validation.ts"; |
10 | | -import { useParent } from "../hooks/use-parent.tsx"; |
| 10 | +import { Container } from "../Container.tsx"; |
11 | 11 |
|
12 | 12 | const MeshInstanceContext = createContext<((instance: PcMeshInstance) => void) | null>(null); |
13 | 13 |
|
14 | 14 | export const useMeshInstanceRegistration = () => useContext(MeshInstanceContext); |
15 | 15 |
|
16 | 16 | const RenderComponent: FC<RenderProps> = (props) => { |
17 | | - const { children, ...rest } = props; |
18 | | - |
19 | | - const parent : Entity = useParent(); |
20 | | - const meshInstancesRef = useRef<PcMeshInstance[]>([]); |
21 | | - |
22 | | - useComponent("render", rest, componentDefinition.schema as Schema<RenderProps, PcRenderComponent>); |
23 | | - |
24 | | - const registerMeshInstance = useCallback((instance: PcMeshInstance) => { |
25 | | - if (!meshInstancesRef.current.includes(instance)) { |
26 | | - meshInstancesRef.current.push(instance); |
27 | | - if (parent.render) { |
28 | | - (parent.render as PcRenderComponent).meshInstances = meshInstancesRef.current; |
29 | | - } |
30 | | - } |
31 | | - }, [parent]); |
32 | | - |
33 | | - return ( |
34 | | - <MeshInstanceContext.Provider value={registerMeshInstance}> |
35 | | - {children} |
36 | | - </MeshInstanceContext.Provider> |
37 | | - ); |
| 17 | + useComponent("render", props, componentDefinition.schema as Schema<RenderProps, PcRenderComponent>); |
| 18 | + return null; |
38 | 19 | } |
39 | 20 |
|
40 | 21 | /** |
@@ -63,11 +44,11 @@ export const Render: FC<RenderProps> = (props) => { |
63 | 44 | if(safeProps.type === "asset" && !safeProps.asset) return null; |
64 | 45 |
|
65 | 46 | // Render a container if the asset is a container |
66 | | - // if (safeProps.asset?.type === 'container') { |
67 | | - // return <Container asset={safeProps.asset as Asset} > |
68 | | - // { safeProps.children } |
69 | | - // </Container> |
70 | | - // } |
| 47 | + if (safeProps.asset?.type === 'container') { |
| 48 | + return <Container asset={safeProps.asset as Asset} > |
| 49 | + { safeProps.children } |
| 50 | + </Container> |
| 51 | + } |
71 | 52 |
|
72 | 53 | // console.log('safeProps', safeProps); |
73 | 54 |
|
|
0 commit comments