11import { type JSX , type ParentProps , createMemo , createRenderEffect , mergeProps } from "solid-js"
22import { Object3D } from "three"
3- import { augment } from "./augment.ts"
43import { threeContext , useThree } from "./hooks.ts"
54import { manageSceneGraph , useProps } from "./props.ts"
6- import type { Instance , Props , ThreeInstance } from "./types.ts"
5+ import type { Instance , Props } from "./types.ts"
76import { type InstanceFromConstructor } from "./types.ts"
8- import { isInstance } from "./utils/is-instance.ts"
9- import { withContext } from "./utils/with-context.ts"
7+ import { augment , autodispose , isConstructor , isInstance , withContext } from "./utils.ts"
8+
9+ /**********************************************************************************/
10+ /* */
11+ /* Portal */
12+ /* */
13+ /**********************************************************************************/
1014
1115type PortalProps = ParentProps < {
1216 element ?: InstanceFromConstructor < Object3D > | Instance < Object3D >
@@ -48,10 +52,14 @@ export const Portal = (props: PortalProps) => {
4852 return null
4953}
5054
51- type EntityProps < T > = Omit < Props < T > , "object" | "children" | "ref" | "args" > & {
55+ /**********************************************************************************/
56+ /* */
57+ /* Entity */
58+ /* */
59+ /**********************************************************************************/
60+
61+ type EntityProps < T extends object | ( new ( ...args : any [ ] ) => any ) > = Omit < Props < T > , "from" > & {
5262 from : T
53- children ?: JSX . Element
54- ref ?: T | ( ( value : T ) => void )
5563}
5664/**
5765 * Wraps a `ThreeElement` and allows it to be used as a JSX-component within a `solid-three` scene.
@@ -62,8 +70,13 @@ type EntityProps<T> = Omit<Props<T>, "object" | "children" | "ref" | "args"> & {
6270 * optional children, and a ref that provides access to the object instance.
6371 * @returns The Three.js object wrapped as a JSX element, allowing it to be used within Solid's component system.
6472 */
65- export function Entity < T extends ThreeInstance > ( props : EntityProps < T > ) {
66- const memo = createMemo ( ( ) => augment ( props . from , { props } ) as Instance < T > )
73+ export function Entity < T extends object | ( new ( ...args : any [ ] ) => object ) > ( props : EntityProps < T > ) {
74+ const memo = createMemo ( ( ) => {
75+ return augment (
76+ isConstructor ( props . from ) ? autodispose ( new props . from ( ...( props . args ?? [ ] ) ) ) : props . from ,
77+ { props } ,
78+ ) as Instance < T >
79+ } )
6780 useProps ( memo , props )
6881 return memo as unknown as JSX . Element
6982}
0 commit comments