-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathneedleEngine.tsx
More file actions
46 lines (39 loc) · 1.38 KB
/
needleEngine.tsx
File metadata and controls
46 lines (39 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// https://nextjs.org/docs/getting-started/react-essentials#the-use-client-directive
'use client'
const isServer = () => typeof window === `undefined`;
import "@needle-tools/engine";
import { type NeedleEngineAttributes } from "@needle-tools/engine";
import { useEffect, useState } from "react";
// Make addEventListener optional
export type NeedleEngineProps = Partial<NeedleEngineAttributes> & React.HTMLAttributes<HTMLElement>;
/** **Needle Engine Component**
* Import with `const NeedleEngine = dynamic(() => import('./needleEngine'), { ssr: false })`
*
* @example
* <NeedleEngine src="./assets/next.glb" loading-style="light" style={{ width: '100%', height: '100%', }}></NeedleEngine>
*
*/
export default function NeedleEngine({ ...props }: NeedleEngineProps): JSX.Element {
const [src, setSrc] = useState(props?.src)
useEffect(() => {
// import the codgegen to register types
if (!isServer()) {
// import("@needle-tools/engine").then(res => {
// res.onStart(ctx => ctx.menu.showNeedleLogo(false))
// })
import("./generated/gen")
.then((m) => {
if (props?.src === undefined)
setSrc(m.needle_exported_files as unknown as string)
})
.catch((e) => {
console.error(e)
});
}
}, [])
return (
<>
{!isServer() && <needle-engine src={src} {...props}></needle-engine>}
</>
);
}