fix how it work loading issue

This commit is contained in:
2026-06-10 14:12:36 +05:30
parent 10d73b6d31
commit 1e6653de96
8 changed files with 345 additions and 83 deletions

View File

@@ -32,6 +32,7 @@ import React, { useLayoutEffect } from 'react'
import { useGLTF } from '@react-three/drei'
const GLB = '/models/3d_scene_final.glb'
const DRACO_PATH = '/draco/' // self-hosted decoder (public/draco/)
// Tyre meshes in the exact order the rig expects: [FR, FL, RL, RR]. Order is
// load-bearing — animateWheels() flips spin direction by index parity.
@@ -61,7 +62,10 @@ const BG_TREE_MAT_RX = /background_tree_atlas/i
const matName = (o) => (Array.isArray(o.material) ? o.material[0]?.name : o.material?.name) || ''
export function Model({ truckRef, wheelRefs, tier = 'desktop', /* dashboardRefs (unused) */ ...props }) {
const { scene } = useGLTF(GLB)
// String arg = self-hosted Draco decoder path: the GLB is Draco-compressed
// geometry + WebP textures (31 MB → 3.7 MB). Self-hosting (vs the gstatic CDN)
// keeps this static-export site free of an external runtime dependency.
const { scene } = useGLTF(GLB, DRACO_PATH)
// useLayoutEffect: wire refs + prune before first paint so TruckAnimation /
// CameraRig (which run in useFrame) see a fully-configured graph on frame 1.
@@ -125,4 +129,4 @@ export function Model({ truckRef, wheelRefs, tier = 'desktop', /* dashboardRefs
return <primitive object={scene} {...props} dispose={null} />
}
useGLTF.preload(GLB)
useGLTF.preload(GLB, DRACO_PATH)