File tree Expand file tree Collapse file tree 1 file changed +34
-1
lines changed
frontend/src/app/components Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Original file line number Diff line number Diff line change 11'use client' ;
22
3- import React , { Suspense , useMemo } from 'react' ;
3+ import React , { Suspense , useEffect , useMemo } from 'react' ;
44import { Canvas } from '@react-three/fiber' ;
55import { Environment , OrbitControls , useGLTF } from '@react-three/drei' ;
66
77type Viewer3DProps = {
88 modelUrl : string ;
99} ;
1010
11+ declare global {
12+ interface Window {
13+ __lod0VisibleAt ?: number ;
14+ }
15+ }
16+
1117function Model ( { modelUrl } : { modelUrl : string } ) {
1218 // Resolve absolute URL to avoid base path issues
1319 const src = useMemo ( ( ) => {
@@ -19,6 +25,33 @@ function Model({ modelUrl }: { modelUrl: string }) {
1925
2026 // Load GLB (no extra params to avoid signature mismatches)
2127 const gltf = useGLTF ( src ) ;
28+
29+ useEffect ( ( ) => {
30+ if ( typeof window === 'undefined' ) {
31+ return undefined ;
32+ }
33+
34+ if ( ! gltf ?. scene ) {
35+ return undefined ;
36+ }
37+
38+ let cancelled = false ;
39+ const rafId = window . requestAnimationFrame ( ( ) => {
40+ if ( cancelled ) {
41+ return ;
42+ }
43+
44+ const ts = performance . now ( ) ;
45+ window . __lod0VisibleAt = ts ;
46+ window . dispatchEvent ( new CustomEvent ( 'lod0:visible' , { detail : { ts } } ) ) ;
47+ } ) ;
48+
49+ return ( ) => {
50+ cancelled = true ;
51+ window . cancelAnimationFrame ( rafId ) ;
52+ } ;
53+ } , [ gltf ?. scene , src ] ) ;
54+
2255 return < primitive object = { gltf . scene } /> ;
2356}
2457
You can’t perform that action at this time.
0 commit comments