mbt-3d 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mbt-3d.cjs +1 -1
- package/dist/mbt-3d.cjs.map +1 -1
- package/dist/mbt-3d.js +430 -422
- package/dist/mbt-3d.js.map +1 -1
- package/package.json +1 -1
package/dist/mbt-3d.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),O=require("@react-three/drei"),oe=require("three"),ae=require("three/examples/jsm/utils/SkeletonUtils.js"),B=require("@react-three/fiber"),ne=require("three/examples/jsm/loaders/KTX2Loader.js"),w=require("react/jsx-runtime");function J(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const r in s)if(r!=="default"){const l=Object.getOwnPropertyDescriptor(s,r);Object.defineProperty(t,r,l.get?l:{enumerable:!0,get:()=>s[r]})}}return t.default=s,Object.freeze(t)}const E=J(oe),Q=J(ae);function le({position:s,controlsConfig:t}){const{camera:r}=B.useThree(),l=e.useRef(null);return e.useEffect(()=>{s&&r&&(r.position.set(s[0],s[1],s[2]),r.updateProjectionMatrix(),l.current&&(l.current.target.set(0,0,0),l.current.update()))},[s,r]),w.jsx(O.OrbitControls,{ref:l,makeDefault:!0,enabled:t.enabled,enablePan:t.enablePan,enableZoom:t.enableZoom,enableRotate:t.enableRotate,minDistance:t.minDistance,maxDistance:t.maxDistance,minPolarAngle:t.minPolarAngle,maxPolarAngle:t.maxPolarAngle,autoRotate:t.autoRotate,autoRotateSpeed:t.autoRotateSpeed})}function ie({background:s}){const t=s==null?void 0:s.startsWith("#");return s?t?w.jsx("color",{attach:"background",args:[s]}):w.jsx(ce,{url:s}):null}function ce({url:s}){const t=O.useTexture(s);return e.useMemo(()=>{t.colorSpace=E.SRGBColorSpace},[t]),w.jsx("primitive",{attach:"background",object:t})}function ue({config:s}){switch(s.type){case"spot":{const{position:t=[5,10,5],intensity:r=50,castShadow:l=!0,angle:p=Math.PI/6,penumbra:g=.5,decay:T=2,distance:S=0,color:h="#ffffff"}=s;return w.jsx("spotLight",{position:t,intensity:r,castShadow:l,angle:p,penumbra:g,decay:T,distance:S,color:h})}case"point":{const{position:t=[0,5,0],intensity:r=20,color:l="#ffffff",distance:p=0,decay:g=2,castShadow:T=!1}=s;return w.jsx("pointLight",{position:t,intensity:r,color:l,distance:p,decay:g,castShadow:T})}case"directional":{const{position:t=[10,20,10],intensity:r=40,color:l="#ffffff",castShadow:p=!0}=s;return w.jsx("directionalLight",{position:t,intensity:r,color:l,castShadow:p})}case"hemisphere":{const{skyColor:t="#ffffff",groundColor:r="#444444",intensity:l=.5,position:p=[0,10,0]}=s,g=e.useMemo(()=>new E.Color(t),[t]),T=e.useMemo(()=>new E.Color(r),[r]);return w.jsx("hemisphereLight",{args:[g,T,l],position:p})}case"ambient":{const{intensity:t=.5,color:r="#ffffff"}=s;return w.jsx("ambientLight",{intensity:t,color:r})}default:return null}}function pe({children:s,camera:t={},controls:r={},background:l,shadows:p=!0,lights:g=[{type:"ambient",intensity:.5},{type:"spot",position:[5,10,5],intensity:50,castShadow:!0}],contactShadows:T=!0,style:S,className:h}){const o={position:t.position||[0,2,5],fov:t.fov||45},a={enabled:r.enabled??!0,enablePan:r.enablePan??!0,enableZoom:r.enableZoom??!0,enableRotate:r.enableRotate??!0,minDistance:r.minDistance,maxDistance:r.maxDistance,minPolarAngle:r.minPolarAngle,maxPolarAngle:r.maxPolarAngle,autoRotate:r.autoRotate??!1,autoRotateSpeed:r.autoRotateSpeed??2},c=typeof T=="object"?{position:T.position||[0,-1,0],opacity:T.opacity??.5,blur:T.blur??2}:T?{position:[0,-1,0],opacity:.5,blur:2}:null;return w.jsx("div",{style:S,className:h,children:w.jsxs(B.Canvas,{shadows:p,camera:{position:o.position,fov:o.fov},style:{width:"100%",height:"100%"},children:[w.jsx(e.Suspense,{fallback:null,children:w.jsx(ie,{background:l})}),g.map((m,b)=>w.jsx(ue,{config:m},`${m.type}-${b}`)),w.jsx(e.Suspense,{fallback:null,children:s}),w.jsx(le,{position:o.position,controlsConfig:a}),c&&w.jsx(O.ContactShadows,{position:c.position,opacity:c.opacity,blur:c.blur})]})})}function G(s,t){const r=e.useRef(new Map),l=e.useRef({}),p=e.useRef({});e.useEffect(()=>{t&&(l.current={...t})},[t]),e.useEffect(()=>{if(!s)return;const h=new Map;s.traverse(o=>{if(o.isMesh){const a=o;a.name&&h.set(a.name,a)}}),r.current=h},[s]),B.useFrame(()=>{const h=r.current;if(h.size===0)return;const o={...l.current,...p.current};for(const[a,c]of Object.entries(o)){const m=h.get(a);m&&m.visible!==c&&(m.visible=c)}});const g=e.useCallback((h,o)=>{p.current[h]=o;const a=r.current.get(h);a&&(a.visible=o)},[]),T=e.useCallback(()=>Array.from(r.current.keys()).sort(),[]),S=e.useCallback(()=>{const h={};return r.current.forEach((o,a)=>{h[a]=o.visible}),h},[]);return{setMeshVisibility:g,getMeshNames:T,getMeshVisibility:S}}function K(s,t){const r=e.useRef(new Map),l=e.useRef(new Map);e.useEffect(()=>{if(!s)return;const o=new Map;s.traverse(a=>{if(a.isMesh){const c=a;(Array.isArray(c.material)?c.material:[c.material]).forEach(b=>{b.name&&!o.has(b.name)&&o.set(b.name,b)})}}),r.current=o,t&&Object.entries(t).forEach(([a,c])=>{const m=o.get(a);if(m&&!Array.isArray(m)){const b=p(c);m.color&&m.color.copy(b),l.current.set(a,b)}})},[s,t]),B.useFrame(()=>{l.current.forEach((o,a)=>{const c=r.current.get(a);if(c&&!Array.isArray(c)){const m=c;m.color&&!m.color.equals(o)&&(m.color.copy(o),m.needsUpdate=!0)}})});const p=o=>typeof o=="string"?new E.Color(o):new E.Color(o[0],o[1],o[2]),g=e.useCallback((o,a)=>{const c=p(a);l.current.set(o,c);const m=r.current.get(o);if(m&&!Array.isArray(m)){const b=m;b.color&&(b.color.copy(c),b.needsUpdate=!0)}},[]),T=e.useCallback(()=>Array.from(r.current.keys()).sort(),[]),S=e.useCallback(o=>{const a=r.current.get(o);if(a&&!Array.isArray(a)){const c=a;if(c.color)return"#"+c.color.getHexString()}return null},[]),h=e.useCallback(()=>{const o={};return r.current.forEach((a,c)=>{if(!Array.isArray(a)){const m=a;m.color&&(o[c]="#"+m.color.getHexString())}}),o},[]);return{setMaterialColor:g,getMaterialNames:T,getMaterialColor:S,getAllMaterialColors:h}}function U(s,t){const{gl:r}=B.useThree(),l=e.useRef(new Map),p=e.useRef(new E.TextureLoader),g=e.useRef(null),T=e.useRef(new Map),S=e.useRef(new Set),h=e.useRef("");e.useEffect(()=>{if(!g.current)try{const n=typeof WebAssembly=="object"&&typeof WebAssembly.validate=="function";console.log("[useMaterialTexture] Browser features:"),console.log(` WebAssembly supported: ${n}`),console.log(` WebGL2: ${r.capabilities.isWebGL2}`);const i=new ne.KTX2Loader;i.setTranscoderPath("/basis/"),i.detectSupport(r),g.current=i,console.log("[useMaterialTexture] ✅ KTX2Loader initialized"),console.log("[useMaterialTexture] Transcoder path: /basis/"),fetch("/basis/basis_transcoder.wasm").then(f=>{f.ok?console.log("[useMaterialTexture] ✅ basis_transcoder.wasm is accessible"):console.error("[useMaterialTexture] ❌ basis_transcoder.wasm returned",f.status)}).catch(f=>{console.error("[useMaterialTexture] ❌ Failed to check basis_transcoder.wasm:",f)}),n||(console.warn("[useMaterialTexture] ⚠️ WebAssembly not supported! KTX2 will fallback to CPU decoding (slow)"),console.warn("[useMaterialTexture] ⚠️ Recommend using WebP instead of KTX2 for this browser"))}catch(n){console.error("[useMaterialTexture] ❌ Failed to initialize KTX2Loader:",n)}return()=>{g.current&&(g.current.dispose(),g.current=null)}},[r]),e.useEffect(()=>{if(!s)return;const n=new Map;s.traverse(i=>{if(i.isMesh){const f=i;(Array.isArray(f.material)?f.material:[f.material]).forEach(d=>{d.name&&!n.has(d.name)&&n.set(d.name,d)})}}),l.current=n},[s]);const o=e.useCallback(n=>n.toLowerCase().endsWith(".ktx2")?g.current?g.current:(console.warn("[useMaterialTexture] KTX2Loader not initialized, falling back to TextureLoader"),p.current):p.current,[]);e.useEffect(()=>{if(!t||!s)return;const n=l.current;if(n.size===0)return;const i=JSON.stringify(t);if(h.current===i){console.log("[useMaterialTexture] Textures unchanged, skipping reload");return}h.current=i;let f=!1;const x=new Map;Object.entries(t).forEach(([M,y])=>{x.set(M,typeof y=="string"?{map:y}:y)}),console.log("[useMaterialTexture] Starting texture load for",x.size,"materials");const d=[];x.forEach((M,y)=>{var A,k;const D=n.get(y);if(!D||!D.isMeshStandardMaterial){console.warn(`[useMaterialTexture] Material "${y}" not found or not MeshStandardMaterial`);return}const u=D;console.log(`[useMaterialTexture] 📋 Material "${y}" BEFORE reset:`),console.log(` - map: ${u.map?"EXISTS":"null"} ${u.map?`(uuid: ${u.map.uuid})`:""}`),console.log(` - normalMap: ${u.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${u.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${u.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${u.emissiveMap?"EXISTS":"null"}`),console.log(` - aoMap: ${u.aoMap?"EXISTS":"null"}`),console.log(` - color: ${(A=u.color)==null?void 0:A.getHexString()}`),console.log(` - emissive: ${(k=u.emissive)==null?void 0:k.getHexString()}`),console.log(` - material uuid: ${u.uuid}`),u.map&&(console.log(`[useMaterialTexture] 🗑️ Disposing old map (uuid: ${u.map.uuid})`),u.map.dispose()),u.normalMap&&(console.log("[useMaterialTexture] 🗑️ Disposing old normalMap"),u.normalMap.dispose()),u.roughnessMap&&(console.log("[useMaterialTexture] 🗑️ Disposing old roughnessMap"),u.roughnessMap.dispose()),u.metalnessMap&&(console.log("[useMaterialTexture] 🗑️ Disposing old metalnessMap"),u.metalnessMap.dispose()),u.emissiveMap&&(console.log("[useMaterialTexture] 🗑️ Disposing old emissiveMap"),u.emissiveMap.dispose()),u.aoMap&&(console.log("[useMaterialTexture] 🗑️ Disposing old aoMap"),u.aoMap.dispose()),u.map=null,u.normalMap=null,u.roughnessMap=null,u.metalnessMap=null,u.emissiveMap=null,u.emissive=new E.Color(0),u.emissiveIntensity=0,u.aoMap=null,u.needsUpdate=!0,u.color=new E.Color(16777215),console.log(`[useMaterialTexture] ✅ Material "${y}" AFTER reset: all maps cleared and disposed`),Object.entries(M).forEach(([$,C])=>{if(!C)return;const j=`${y}_${$}_${C}`,X=T.current.get(j);if(X){console.log(`[useMaterialTexture] Using cached texture: ${y}.${$}`),f||a(u,$,X);return}if(S.current.has(j)){console.log(`[useMaterialTexture] Skipping already loading: ${y}.${$}`);return}d.push({materialName:y,textureType:$,url:C,material:u})})}),console.log(`[useMaterialTexture] Queued ${d.length} textures to load`);let v=0;const R=()=>{if(f||v>=d.length){console.log("[useMaterialTexture] ✅ All textures loaded"),console.log("[useMaterialTexture] 📊 FINAL material states:"),n.forEach((A,k)=>{var C,j;const $=A;console.log(` Material "${k}":`),console.log(` - map: ${$.map?"EXISTS":"null"} ${$.map?`(colorSpace: ${$.map.colorSpace})`:""}`),console.log(` - normalMap: ${$.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${$.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${$.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${$.emissiveMap?"EXISTS":"null"}`),console.log(` - color: ${(C=$.color)==null?void 0:C.getHexString()}`),console.log(` - emissive: ${(j=$.emissive)==null?void 0:j.getHexString()}`),console.log(` - emissiveIntensity: ${$.emissiveIntensity}`),console.log(` - roughness: ${$.roughness}`),console.log(` - metalness: ${$.metalness}`)});return}const M=d[v++],y=`${M.materialName}_${M.textureType}_${M.url}`;console.log(`[useMaterialTexture] Loading (${v}/${d.length}): ${M.materialName}.${M.textureType} from ${M.url}`),S.current.add(y);const D=o(M.url),u=M.url.toLowerCase().endsWith(".ktx2")?"KTX2Loader":"TextureLoader";console.log(`[useMaterialTexture] Using ${u} for ${M.url}`),D.load(M.url,A=>{var j,X,P,I,L,W;if(S.current.delete(y),f){console.log(`[useMaterialTexture] Disposed, cleaning up texture: ${M.materialName}.${M.textureType}`),A.dispose();return}const k=((j=A.image)==null?void 0:j.width)||((P=(X=A.source)==null?void 0:X.data)==null?void 0:P.width)||"unknown",$=((I=A.image)==null?void 0:I.height)||((W=(L=A.source)==null?void 0:L.data)==null?void 0:W.height)||"unknown";console.log(`[useMaterialTexture] ✅ Loaded: ${M.materialName}.${M.textureType} (${k}x${$})`),A.colorSpace=M.textureType==="map"||M.textureType==="emissiveMap"?E.SRGBColorSpace:E.NoColorSpace,A.wrapS=E.RepeatWrapping,A.wrapT=E.RepeatWrapping,A.flipY=!1,T.current.set(y,A),a(M.material,M.textureType,A);const C=M.url.endsWith(".ktx2")?500:150;console.log(`[useMaterialTexture] Waiting111111 ${C}ms before next texture...`),setTimeout(R,0)},A=>{if(A.lengthComputable){const k=Math.round(A.loaded/A.total*100);k%25===0&&console.log(`[useMaterialTexture] Progress ${M.materialName}.${M.textureType}: ${k}%`)}},A=>{S.current.delete(y),f||(console.error(`[useMaterialTexture] ❌ Failed to load ${M.materialName}.${M.textureType} from ${M.url}`),console.error("[useMaterialTexture] Error details:",A),console.error("[useMaterialTexture] Loader type:",u),M.url.endsWith(".ktx2")&&(console.error("[useMaterialTexture] KTX2 error - file may not be in Basis Universal format!"),console.error("[useMaterialTexture] Make sure files are created with: gltf-transform etc1s input.png output.ktx2"))),setTimeout(R,100)})};return R(),()=>{console.log("[useMaterialTexture] Cleanup: disposed"),f=!0}},[s,t,o]);const a=(n,i,f)=>{var x,d;switch(console.log(`[useMaterialTexture] 🎨 Applying texture: ${n.name}.${i} (texture uuid: ${f.uuid})`),i){case"map":n.map=f;break;case"normalMap":n.normalMap=f;break;case"roughnessMap":n.roughnessMap=f;break;case"metalnessMap":n.metalnessMap=f;break;case"emissiveMap":n.emissiveMap=f,n.emissive=new E.Color(16777215),n.emissiveIntensity=1;break;case"alphaMap":console.log(`[useMaterialTexture] Skipping alphaMap for "${n.name}" to prevent disappearing`);break;case"aoMap":n.aoMap=f;break}n.needsUpdate=!0,console.log(`[useMaterialTexture] ✅ Applied ${i} to ${n.name}, needsUpdate=true`),console.log(`[useMaterialTexture] 📊 Material "${n.name}" FINAL state:`),console.log(` - map: ${n.map?"EXISTS":"null"} ${n.map?`(uuid: ${n.map.uuid}, colorSpace: ${n.map.colorSpace})`:""}`),console.log(` - normalMap: ${n.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${n.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${n.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${n.emissiveMap?"EXISTS":"null"}`),console.log(` - aoMap: ${n.aoMap?"EXISTS":"null"}`),console.log(` - color: ${(x=n.color)==null?void 0:x.getHexString()}`),console.log(` - emissive: ${(d=n.emissive)==null?void 0:d.getHexString()}`),console.log(` - emissiveIntensity: ${n.emissiveIntensity}`),console.log(` - roughness: ${n.roughness}`),console.log(` - metalness: ${n.metalness}`)},c=e.useCallback((n,i)=>{const f=typeof i=="string"?{map:i}:i,x=l.current.get(n);if(!x||!x.isMeshStandardMaterial){console.warn(`Material "${n}" not found or not MeshStandardMaterial`);return}const d=x;Object.entries(f).forEach(([v,R])=>{if(!R)return;const M=`${n}_${v}_${R}`,y=T.current.get(M);if(y){a(d,v,y);return}o(R).load(R,u=>{u.colorSpace=v==="map"||v==="emissiveMap"?E.SRGBColorSpace:E.NoColorSpace,u.wrapS=E.RepeatWrapping,u.wrapT=E.RepeatWrapping,T.current.set(M,u),a(d,v,u)},void 0,u=>{console.error(`Failed to load texture ${R}:`,u)})})},[o]),m=e.useCallback(()=>Array.from(l.current.keys()).sort(),[]),b=e.useCallback(n=>{const i=l.current.get(n);if(!i||!i.isMeshStandardMaterial)return;const f=i;f.map=null,f.normalMap=null,f.roughnessMap=null,f.metalnessMap=null,f.emissiveMap=null,f.alphaMap=null,f.aoMap=null,f.needsUpdate=!0},[]);return{setMaterialTextures:c,getMaterialNames:m,clearMaterialTextures:b}}function ee({url:s,position:t=[0,0,0],rotation:r=[0,0,0],scale:l=1,meshVisibility:p,materialColors:g,materialTextures:T,onLoad:S,onError:h}){const{scene:o}=O.useGLTF(s),a=e.useRef(S);a.current=S;const c=e.useMemo(()=>{const b=o.clone();console.log("[Model] 🔍 Scene clone created, checking materials...");const n=[],i=new Set,f=[];let x=0;return b.traverse(d=>{if(x++,d.type==="Bone"&&f.push(d.name),d.isMesh){const v=d;n.push(v.name),v.castShadow=!0,v.receiveShadow=!0,(Array.isArray(v.material)?v.material:[v.material]).forEach(M=>{i.add(M.name),console.log(`[Model] 📦 Material found: "${M.name}" (uuid: ${M.uuid})`);const y=M;console.log(` - Has map: ${y.map?"YES":"NO"}`),console.log(` - Has normalMap: ${y.normalMap?"YES":"NO"}`),console.log(` - Has roughnessMap: ${y.roughnessMap?"YES":"NO"}`),console.log(` - Has metalnessMap: ${y.metalnessMap?"YES":"NO"}`)})}}),console.log(`[Model] 📊 Clone summary: ${n.length} meshes, ${i.size} materials`),setTimeout(()=>{var d;(d=a.current)==null||d.call(a,{meshes:n.sort(),materials:Array.from(i).sort(),bones:f.sort(),nodeCount:x})},0),b},[o]);G(c,p),K(c,g),U(c,T);const m=typeof l=="number"?[l,l,l]:l;return w.jsx("group",{position:t,rotation:r,scale:m,children:w.jsx("primitive",{object:c})})}ee.preload=s=>{O.useGLTF.preload(s)};function te(s,t,r){const{actions:l,names:p}=O.useAnimations(s,t),g=e.useRef(null),T=e.useRef(r==null?void 0:r.defaultAnimation);e.useEffect(()=>{if(p.length===0)return;const a=T.current;let c=p[0];if(a){const b=p.find(n=>n===a||n.includes(a));b&&(c=b)}const m=l[c];m&&(m.reset().fadeIn(.5).play(),g.current=m)},[l,p]);const S=e.useCallback((a,c)=>{const{loop:m=!1,crossFadeDuration:b=.2,restoreDefault:n=!0}=c||{};let i=l[a];if(!i){const x=Object.keys(l).find(d=>d.toLowerCase().includes(a.toLowerCase())||a.toLowerCase().includes(d.toLowerCase()));x&&(i=l[x])}if(!i){console.warn(`Animation "${a}" not found. Available: ${p.join(", ")}`);return}const f=g.current;if(!(f===i&&i.isRunning())&&(f&&f!==i&&f.fadeOut(b),i.reset(),i.fadeIn(b),i.setLoop(m?E.LoopRepeat:E.LoopOnce,m?1/0:1),i.clampWhenFinished=!m,i.play(),m||i.getMixer().update(0),g.current=i,n&&!m&&T.current)){const x=i.getMixer(),d=v=>{if(v.action===i){x.removeEventListener("finished",d);const R=l[T.current];R&&(i.fadeOut(b),R.reset().fadeIn(b).play(),g.current=R)}};x.addEventListener("finished",d)}},[l,p]),h=e.useCallback(()=>{var a;(a=g.current)==null||a.fadeOut(.2),g.current=null},[]),o=e.useCallback(()=>p,[p]);return{playAnimation:S,stopAnimation:h,getAnimationNames:o,actions:l}}function z(s,t){const r=e.useRef(t||{}),l=e.useRef([]),p=e.useRef([]);e.useEffect(()=>{const h=new Set,o=[];s.traverse(a=>{a instanceof E.Mesh&&a.morphTargetDictionary&&a.morphTargetInfluences&&(o.push(a),Object.keys(a.morphTargetDictionary).forEach(c=>{h.add(c)}))}),l.current=Array.from(h).sort(),p.current=o},[s]),B.useFrame(()=>{const h=r.current;p.current.forEach(o=>{!o.morphTargetDictionary||!o.morphTargetInfluences||Object.entries(h).forEach(([a,c])=>{const m=o.morphTargetDictionary[a];m!==void 0&&(o.morphTargetInfluences[m]=c)})})}),e.useEffect(()=>{t&&(r.current={...t})},[t]);const g=e.useCallback((h,o)=>{r.current[h]=Math.max(0,Math.min(1,o))},[]),T=e.useCallback(()=>l.current,[]),S=e.useCallback(()=>({...r.current}),[]);return{setMorphTarget:g,getMorphTargetNames:T,getMorphTargetValues:S}}const re=e.createContext(null);function me(){const s=e.useContext(re);if(!s)throw new Error("BoneAttachment must be used within an AnimatedModel");return s}const q=e.forwardRef(({url:s,position:t=[0,0,0],rotation:r=[0,0,0],scale:l=1,defaultAnimation:p,morphTargets:g,meshVisibility:T,materialColors:S,materialTextures:h,onLoad:o,onError:a,children:c},m)=>{const b=e.useRef(null),n=e.useRef([]),i=e.useRef(o);i.current=o;const{scene:f,animations:x}=O.useGLTF(s),d=e.useMemo(()=>Q.clone(f),[f]),{playAnimation:v,stopAnimation:R,getAnimationNames:M}=te(x,d,{defaultAnimation:p}),{setMorphTarget:y}=z(d,g),{setMeshVisibility:D,getMeshNames:u}=G(d,T),{setMaterialColor:A,getMaterialNames:k,getMaterialColor:$}=K(d,S),{setMaterialTextures:C,clearMaterialTextures:j}=U(d,h);e.useEffect(()=>{if(!d)return;const I=setTimeout(()=>{var Z;const L=[],W=[],_=new Set,V=new Set;let Y=0;d.traverse(F=>{if(Y++,F.type==="Bone"&&L.push(F.name),F.isMesh){const N=F;W.push(N.name),N.castShadow=!0,N.receiveShadow=!0,(Array.isArray(N.material)?N.material:[N.material]).forEach(H=>{_.add(H.name),H.shadowSide=E.DoubleSide}),N.morphTargetDictionary&&Object.keys(N.morphTargetDictionary).forEach(H=>{V.add(H)})}}),n.current=Array.from(V).sort(),(Z=i.current)==null||Z.call(i,{meshes:W.sort(),materials:Array.from(_).sort(),bones:L.sort(),nodeCount:Y,animations:x.map(F=>F.name),morphTargetNames:n.current})},0);return()=>clearTimeout(I)},[d,x]),e.useImperativeHandle(m,()=>({playAnimation:v,stopAnimation:R,getAnimationNames:M,getGroup:()=>b.current,setMorphTarget:y,getMorphTargetNames:()=>n.current,setMeshVisibility:D,getMeshNames:u,setMaterialColor:A,getMaterialNames:k,getMaterialColor:$,setMaterialTextures:C,clearMaterialTextures:j}));const X=e.useMemo(()=>({scene:d,getBone:I=>d.getObjectByName(I)||null}),[d]),P=typeof l=="number"?[l,l,l]:l;return w.jsx(re.Provider,{value:X,children:w.jsxs("group",{ref:b,position:t,rotation:r,scale:P,children:[w.jsx("primitive",{object:d}),c]})})});q.displayName="AnimatedModel";q.preload=s=>{O.useGLTF.preload(s)};const se=e.forwardRef(({url:s,position:t=[0,0,0],rotation:r=[0,0,0],scale:l=1,morphTargets:p,meshVisibility:g,materialColors:T,materialTextures:S,onMorphTargetsFound:h,onLoad:o,onError:a},c)=>{const{scene:m}=O.useGLTF(s),b=e.useRef(o);b.current=o;const n=e.useRef(h);n.current=h;const i=e.useMemo(()=>m.clone(),[m]),{setMorphTarget:f,getMorphTargetNames:x,getMorphTargetValues:d}=z(i,p),{setMeshVisibility:v,getMeshNames:R}=G(i,g),{setMaterialColor:M,getMaterialNames:y,getMaterialColor:D}=K(i,T),{setMaterialTextures:u,clearMaterialTextures:A}=U(i,S);e.useEffect(()=>{var C;const $=x();$.length>0&&((C=n.current)==null||C.call(n,$))},[i,x]),e.useEffect(()=>{var P;if(!i)return;const $=[],C=new Set,j=[];let X=0;i.traverse(I=>{if(X++,I.type==="Bone"&&j.push(I.name),I.isMesh){const L=I;$.push(L.name),L.castShadow=!0,L.receiveShadow=!0,(Array.isArray(L.material)?L.material:[L.material]).forEach(_=>C.add(_.name))}}),(P=b.current)==null||P.call(b,{meshes:$.sort(),materials:Array.from(C).sort(),bones:j.sort(),nodeCount:X})},[i]),e.useImperativeHandle(c,()=>({setMorphTarget:f,getMorphTargetNames:x,getMorphTargetValues:d,setMeshVisibility:v,getMeshNames:R,setMaterialColor:M,getMaterialNames:y,getMaterialColor:D,setMaterialTextures:u,clearMaterialTextures:A}));const k=typeof l=="number"?[l,l,l]:l;return w.jsx("group",{position:t,rotation:r,scale:k,children:w.jsx("primitive",{object:i})})});se.displayName="MorphableModel";function fe({children:s,bone:t,position:r=[0,0,0],rotation:l=[0,0,0],scale:p=1}){const{getBone:g}=me(),[T,S]=e.useState(null);if(e.useEffect(()=>{const o=g(t);o?S(o):console.warn(`Bone "${t}" not found in model`)},[t,g]),!T)return null;const h=typeof p=="number"?[p,p,p]:p;return B.createPortal(w.jsx("group",{position:r,rotation:l,scale:h,children:s}),T)}function de(s,t){const{scene:r,animations:l}=O.useGLTF(s),p=e.useMemo(()=>Q.clone(r),[r]);return e.useEffect(()=>{var o;if(!p)return;const g=[],T=[],S=new Set;let h=0;p.traverse(a=>{if(h++,a.type==="Bone"&&g.push(a.name),a.isMesh){const c=a;T.push(c.name),c.castShadow=!0,c.receiveShadow=!0,(Array.isArray(c.material)?c.material:[c.material]).forEach(b=>{S.add(b.name),b.shadowSide=E.DoubleSide})}}),(o=t==null?void 0:t.onLoad)==null||o.call(t,{meshes:T.sort(),materials:Array.from(S).sort(),bones:g.sort(),nodeCount:h})},[p,t]),{scene:p,animations:l}}function Me(s){O.useGLTF.preload(s)}exports.AnimatedModel=q;exports.BoneAttachment=fe;exports.Model=ee;exports.MorphableModel=se;exports.Scene3D=pe;exports.preloadModel=Me;exports.useAnimationController=te;exports.useClonedModel=de;exports.useMaterialColor=K;exports.useMaterialTexture=U;exports.useMeshVisibility=G;exports.useMorphTargets=z;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),O=require("@react-three/drei"),se=require("three"),ne=require("three/examples/jsm/utils/SkeletonUtils.js"),B=require("@react-three/fiber"),ae=require("three/examples/jsm/loaders/KTX2Loader.js"),w=require("react/jsx-runtime");function J(n){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const s in n)if(s!=="default"){const l=Object.getOwnPropertyDescriptor(n,s);Object.defineProperty(t,s,l.get?l:{enumerable:!0,get:()=>n[s]})}}return t.default=n,Object.freeze(t)}const E=J(se),Q=J(ne);function le({position:n,controlsConfig:t}){const{camera:s}=B.useThree(),l=e.useRef(null);return e.useEffect(()=>{n&&s&&(s.position.set(n[0],n[1],n[2]),s.updateProjectionMatrix(),l.current&&(l.current.target.set(0,0,0),l.current.update()))},[n,s]),w.jsx(O.OrbitControls,{ref:l,makeDefault:!0,enabled:t.enabled,enablePan:t.enablePan,enableZoom:t.enableZoom,enableRotate:t.enableRotate,minDistance:t.minDistance,maxDistance:t.maxDistance,minPolarAngle:t.minPolarAngle,maxPolarAngle:t.maxPolarAngle,autoRotate:t.autoRotate,autoRotateSpeed:t.autoRotateSpeed})}function ie({background:n}){const t=n==null?void 0:n.startsWith("#");return n?t?w.jsx("color",{attach:"background",args:[n]}):w.jsx(ce,{url:n}):null}function ce({url:n}){const t=O.useTexture(n);return e.useMemo(()=>{t.colorSpace=E.SRGBColorSpace},[t]),w.jsx("primitive",{attach:"background",object:t})}function ue({config:n}){switch(n.type){case"spot":{const{position:t=[5,10,5],intensity:s=50,castShadow:l=!0,angle:f=Math.PI/6,penumbra:g=.5,decay:T=2,distance:x=0,color:h="#ffffff"}=n;return w.jsx("spotLight",{position:t,intensity:s,castShadow:l,angle:f,penumbra:g,decay:T,distance:x,color:h})}case"point":{const{position:t=[0,5,0],intensity:s=20,color:l="#ffffff",distance:f=0,decay:g=2,castShadow:T=!1}=n;return w.jsx("pointLight",{position:t,intensity:s,color:l,distance:f,decay:g,castShadow:T})}case"directional":{const{position:t=[10,20,10],intensity:s=40,color:l="#ffffff",castShadow:f=!0}=n;return w.jsx("directionalLight",{position:t,intensity:s,color:l,castShadow:f})}case"hemisphere":{const{skyColor:t="#ffffff",groundColor:s="#444444",intensity:l=.5,position:f=[0,10,0]}=n,g=e.useMemo(()=>new E.Color(t),[t]),T=e.useMemo(()=>new E.Color(s),[s]);return w.jsx("hemisphereLight",{args:[g,T,l],position:f})}case"ambient":{const{intensity:t=.5,color:s="#ffffff"}=n;return w.jsx("ambientLight",{intensity:t,color:s})}default:return null}}function pe({children:n,camera:t={},controls:s={},background:l,shadows:f=!0,lights:g=[{type:"ambient",intensity:.5},{type:"spot",position:[5,10,5],intensity:50,castShadow:!0}],contactShadows:T=!0,style:x,className:h}){const r={position:t.position||[0,2,5],fov:t.fov||45},o={enabled:s.enabled??!0,enablePan:s.enablePan??!0,enableZoom:s.enableZoom??!0,enableRotate:s.enableRotate??!0,minDistance:s.minDistance,maxDistance:s.maxDistance,minPolarAngle:s.minPolarAngle,maxPolarAngle:s.maxPolarAngle,autoRotate:s.autoRotate??!1,autoRotateSpeed:s.autoRotateSpeed??2},c=typeof T=="object"?{position:T.position||[0,-1,0],opacity:T.opacity??.5,blur:T.blur??2}:T?{position:[0,-1,0],opacity:.5,blur:2}:null;return w.jsx("div",{style:x,className:h,children:w.jsxs(B.Canvas,{shadows:f,camera:{position:r.position,fov:r.fov},style:{width:"100%",height:"100%"},children:[w.jsx(e.Suspense,{fallback:null,children:w.jsx(ie,{background:l})}),g.map((u,y)=>w.jsx(ue,{config:u},`${u.type}-${y}`)),w.jsx(e.Suspense,{fallback:null,children:n}),w.jsx(le,{position:r.position,controlsConfig:o}),c&&w.jsx(O.ContactShadows,{position:c.position,opacity:c.opacity,blur:c.blur})]})})}function G(n,t){const s=e.useRef(new Map),l=e.useRef({}),f=e.useRef({});e.useEffect(()=>{t&&(l.current={...t})},[t]),e.useEffect(()=>{if(!n)return;const h=new Map;n.traverse(r=>{if(r.isMesh){const o=r;o.name&&h.set(o.name,o)}}),s.current=h},[n]),B.useFrame(()=>{const h=s.current;if(h.size===0)return;const r={...l.current,...f.current};for(const[o,c]of Object.entries(r)){const u=h.get(o);u&&u.visible!==c&&(u.visible=c)}});const g=e.useCallback((h,r)=>{f.current[h]=r;const o=s.current.get(h);o&&(o.visible=r)},[]),T=e.useCallback(()=>Array.from(s.current.keys()).sort(),[]),x=e.useCallback(()=>{const h={};return s.current.forEach((r,o)=>{h[o]=r.visible}),h},[]);return{setMeshVisibility:g,getMeshNames:T,getMeshVisibility:x}}function K(n,t){const s=e.useRef(new Map),l=e.useRef(new Map);e.useEffect(()=>{if(!n)return;const r=new Map;n.traverse(o=>{if(o.isMesh){const c=o;(Array.isArray(c.material)?c.material:[c.material]).forEach(y=>{y.name&&!r.has(y.name)&&r.set(y.name,y)})}}),s.current=r,console.log("[useMaterialColor] 🎨 Discovered materials:",Array.from(r.keys())),r.forEach((o,c)=>{if(!Array.isArray(o)){const u=o;if(u.color){const y=u.color.clone();console.log(`[useMaterialColor] 📋 Original color for "${c}": ${y.getHexString()}`),u.color.set(16777215),u.needsUpdate=!0,console.log(`[useMaterialColor] ✅ Reset "${c}" to white (0xffffff)`),l.current.set(c,u.color.clone())}}}),t&&Object.entries(t).forEach(([o,c])=>{const u=r.get(o);if(u&&!Array.isArray(u)){const y=f(c);u.color&&u.color.copy(y),l.current.set(o,y),console.log(`[useMaterialColor] 🎨 Applied custom color for "${o}": ${y.getHexString()}`)}})},[n,t]),B.useFrame(()=>{l.current.forEach((r,o)=>{const c=s.current.get(o);if(c&&!Array.isArray(c)){const u=c;u.color&&!u.color.equals(r)&&(console.log(`[useMaterialColor] 🔄 Applying color to "${o}": ${u.color.getHexString()} -> ${r.getHexString()}`),u.color.copy(r),u.needsUpdate=!0)}})});const f=r=>typeof r=="string"?new E.Color(r):new E.Color(r[0],r[1],r[2]),g=e.useCallback((r,o)=>{const c=f(o);l.current.set(r,c);const u=s.current.get(r);if(u&&!Array.isArray(u)){const y=u;y.color&&(y.color.copy(c),y.needsUpdate=!0)}},[]),T=e.useCallback(()=>Array.from(s.current.keys()).sort(),[]),x=e.useCallback(r=>{const o=s.current.get(r);if(o&&!Array.isArray(o)){const c=o;if(c.color)return"#"+c.color.getHexString()}return null},[]),h=e.useCallback(()=>{const r={};return s.current.forEach((o,c)=>{if(!Array.isArray(o)){const u=o;u.color&&(r[c]="#"+u.color.getHexString())}}),r},[]);return{setMaterialColor:g,getMaterialNames:T,getMaterialColor:x,getAllMaterialColors:h}}function U(n,t){const{gl:s}=B.useThree(),l=e.useRef(new Map),f=e.useRef(new E.TextureLoader),g=e.useRef(null),T=e.useRef(new Map),x=e.useRef(new Set),h=e.useRef("");e.useEffect(()=>{if(!g.current)try{const a=typeof WebAssembly=="object"&&typeof WebAssembly.validate=="function";console.log("[useMaterialTexture] Browser features:"),console.log(` WebAssembly supported: ${a}`),console.log(` WebGL2: ${s.capabilities.isWebGL2}`);const i=new ae.KTX2Loader;i.setTranscoderPath("/basis/"),i.detectSupport(s),g.current=i,console.log("[useMaterialTexture] ✅ KTX2Loader initialized"),console.log("[useMaterialTexture] Transcoder path: /basis/"),fetch("/basis/basis_transcoder.wasm").then(m=>{m.ok?console.log("[useMaterialTexture] ✅ basis_transcoder.wasm is accessible"):console.error("[useMaterialTexture] ❌ basis_transcoder.wasm returned",m.status)}).catch(m=>{console.error("[useMaterialTexture] ❌ Failed to check basis_transcoder.wasm:",m)}),a||(console.warn("[useMaterialTexture] ⚠️ WebAssembly not supported! KTX2 will fallback to CPU decoding (slow)"),console.warn("[useMaterialTexture] ⚠️ Recommend using WebP instead of KTX2 for this browser"))}catch(a){console.error("[useMaterialTexture] ❌ Failed to initialize KTX2Loader:",a)}return()=>{g.current&&(g.current.dispose(),g.current=null)}},[s]),e.useEffect(()=>{if(!n)return;const a=new Map;n.traverse(i=>{if(i.isMesh){const m=i;(Array.isArray(m.material)?m.material:[m.material]).forEach(d=>{d.name&&!a.has(d.name)&&a.set(d.name,d)})}}),l.current=a},[n]);const r=e.useCallback(a=>a.toLowerCase().endsWith(".ktx2")?g.current?g.current:(console.warn("[useMaterialTexture] KTX2Loader not initialized, falling back to TextureLoader"),f.current):f.current,[]);e.useEffect(()=>{if(!t||!n)return;const a=l.current;if(a.size===0)return;const i=JSON.stringify(t);if(h.current===i){console.log("[useMaterialTexture] Textures unchanged, skipping reload");return}h.current=i;let m=!1;const S=new Map;Object.entries(t).forEach(([M,b])=>{S.set(M,typeof b=="string"?{map:b}:b)}),console.log("[useMaterialTexture] Starting texture load for",S.size,"materials");const d=[];S.forEach((M,b)=>{var A,k;const D=a.get(b);if(!D||!D.isMeshStandardMaterial){console.warn(`[useMaterialTexture] Material "${b}" not found or not MeshStandardMaterial`);return}const p=D;console.log(`[useMaterialTexture] 📋 Material "${b}" BEFORE reset:`),console.log(` - map: ${p.map?"EXISTS":"null"} ${p.map?`(uuid: ${p.map.uuid})`:""}`),console.log(` - normalMap: ${p.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${p.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${p.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${p.emissiveMap?"EXISTS":"null"}`),console.log(` - aoMap: ${p.aoMap?"EXISTS":"null"}`),console.log(` - color: ${(A=p.color)==null?void 0:A.getHexString()}`),console.log(` - emissive: ${(k=p.emissive)==null?void 0:k.getHexString()}`),console.log(` - material uuid: ${p.uuid}`),p.map&&(console.log(`[useMaterialTexture] 🗑️ Disposing old map (uuid: ${p.map.uuid})`),p.map.dispose()),p.normalMap&&(console.log("[useMaterialTexture] 🗑️ Disposing old normalMap"),p.normalMap.dispose()),p.roughnessMap&&(console.log("[useMaterialTexture] 🗑️ Disposing old roughnessMap"),p.roughnessMap.dispose()),p.metalnessMap&&(console.log("[useMaterialTexture] 🗑️ Disposing old metalnessMap"),p.metalnessMap.dispose()),p.emissiveMap&&(console.log("[useMaterialTexture] 🗑️ Disposing old emissiveMap"),p.emissiveMap.dispose()),p.aoMap&&(console.log("[useMaterialTexture] 🗑️ Disposing old aoMap"),p.aoMap.dispose()),p.map=null,p.normalMap=null,p.roughnessMap=null,p.metalnessMap=null,p.emissiveMap=null,p.emissive=new E.Color(0),p.emissiveIntensity=0,p.aoMap=null,p.needsUpdate=!0,console.log(`[useMaterialTexture] ✅ Material "${b}" AFTER reset: all maps cleared and disposed`),Object.entries(M).forEach(([$,C])=>{if(!C)return;const j=`${b}_${$}_${C}`,X=T.current.get(j);if(X){console.log(`[useMaterialTexture] Using cached texture: ${b}.${$}`),m||o(p,$,X);return}if(x.current.has(j)){console.log(`[useMaterialTexture] Skipping already loading: ${b}.${$}`);return}d.push({materialName:b,textureType:$,url:C,material:p})})}),console.log(`[useMaterialTexture] Queued ${d.length} textures to load`);let v=0;const R=()=>{if(m||v>=d.length){console.log("[useMaterialTexture] ✅ All textures loaded"),console.log("[useMaterialTexture] 📊 FINAL material states:"),a.forEach((A,k)=>{var C,j;const $=A;console.log(` Material "${k}":`),console.log(` - map: ${$.map?"EXISTS":"null"} ${$.map?`(colorSpace: ${$.map.colorSpace})`:""}`),console.log(` - normalMap: ${$.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${$.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${$.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${$.emissiveMap?"EXISTS":"null"}`),console.log(` - color: ${(C=$.color)==null?void 0:C.getHexString()}`),console.log(` - emissive: ${(j=$.emissive)==null?void 0:j.getHexString()}`),console.log(` - emissiveIntensity: ${$.emissiveIntensity}`),console.log(` - roughness: ${$.roughness}`),console.log(` - metalness: ${$.metalness}`)});return}const M=d[v++],b=`${M.materialName}_${M.textureType}_${M.url}`;console.log(`[useMaterialTexture] Loading (${v}/${d.length}): ${M.materialName}.${M.textureType} from ${M.url}`),x.current.add(b);const D=r(M.url),p=M.url.toLowerCase().endsWith(".ktx2")?"KTX2Loader":"TextureLoader";console.log(`[useMaterialTexture] Using ${p} for ${M.url}`),D.load(M.url,A=>{var j,X,N,I,L,H;if(x.current.delete(b),m){console.log(`[useMaterialTexture] Disposed, cleaning up texture: ${M.materialName}.${M.textureType}`),A.dispose();return}const k=((j=A.image)==null?void 0:j.width)||((N=(X=A.source)==null?void 0:X.data)==null?void 0:N.width)||"unknown",$=((I=A.image)==null?void 0:I.height)||((H=(L=A.source)==null?void 0:L.data)==null?void 0:H.height)||"unknown";console.log(`[useMaterialTexture] ✅ Loaded: ${M.materialName}.${M.textureType} (${k}x${$})`),A.colorSpace=M.textureType==="map"||M.textureType==="emissiveMap"?E.SRGBColorSpace:E.NoColorSpace,A.wrapS=E.RepeatWrapping,A.wrapT=E.RepeatWrapping,A.flipY=!1,T.current.set(b,A),o(M.material,M.textureType,A);const C=M.url.endsWith(".ktx2")?500:150;console.log(`[useMaterialTexture] Waiting111111 ${C}ms before next texture...`),setTimeout(R,0)},A=>{if(A.lengthComputable){const k=Math.round(A.loaded/A.total*100);k%25===0&&console.log(`[useMaterialTexture] Progress ${M.materialName}.${M.textureType}: ${k}%`)}},A=>{x.current.delete(b),m||(console.error(`[useMaterialTexture] ❌ Failed to load ${M.materialName}.${M.textureType} from ${M.url}`),console.error("[useMaterialTexture] Error details:",A),console.error("[useMaterialTexture] Loader type:",p),M.url.endsWith(".ktx2")&&(console.error("[useMaterialTexture] KTX2 error - file may not be in Basis Universal format!"),console.error("[useMaterialTexture] Make sure files are created with: gltf-transform etc1s input.png output.ktx2"))),setTimeout(R,100)})};return R(),()=>{console.log("[useMaterialTexture] Cleanup: disposed"),m=!0}},[n,t,r]);const o=(a,i,m)=>{var S,d;switch(console.log(`[useMaterialTexture] 🎨 Applying texture: ${a.name}.${i} (texture uuid: ${m.uuid})`),i){case"map":a.map=m;break;case"normalMap":a.normalMap=m;break;case"roughnessMap":a.roughnessMap=m;break;case"metalnessMap":a.metalnessMap=m;break;case"emissiveMap":a.emissiveMap=m,a.emissive=new E.Color(16777215),a.emissiveIntensity=1;break;case"alphaMap":console.log(`[useMaterialTexture] Skipping alphaMap for "${a.name}" to prevent disappearing`);break;case"aoMap":a.aoMap=m;break}a.needsUpdate=!0,console.log(`[useMaterialTexture] ✅ Applied ${i} to ${a.name}, needsUpdate=true`),console.log(`[useMaterialTexture] 📊 Material "${a.name}" FINAL state:`),console.log(` - map: ${a.map?"EXISTS":"null"} ${a.map?`(uuid: ${a.map.uuid}, colorSpace: ${a.map.colorSpace})`:""}`),console.log(` - normalMap: ${a.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${a.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${a.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${a.emissiveMap?"EXISTS":"null"}`),console.log(` - aoMap: ${a.aoMap?"EXISTS":"null"}`),console.log(` - color: ${(S=a.color)==null?void 0:S.getHexString()}`),console.log(` - emissive: ${(d=a.emissive)==null?void 0:d.getHexString()}`),console.log(` - emissiveIntensity: ${a.emissiveIntensity}`),console.log(` - roughness: ${a.roughness}`),console.log(` - metalness: ${a.metalness}`)},c=e.useCallback((a,i)=>{const m=typeof i=="string"?{map:i}:i,S=l.current.get(a);if(!S||!S.isMeshStandardMaterial){console.warn(`Material "${a}" not found or not MeshStandardMaterial`);return}const d=S;Object.entries(m).forEach(([v,R])=>{if(!R)return;const M=`${a}_${v}_${R}`,b=T.current.get(M);if(b){o(d,v,b);return}r(R).load(R,p=>{p.colorSpace=v==="map"||v==="emissiveMap"?E.SRGBColorSpace:E.NoColorSpace,p.wrapS=E.RepeatWrapping,p.wrapT=E.RepeatWrapping,T.current.set(M,p),o(d,v,p)},void 0,p=>{console.error(`Failed to load texture ${R}:`,p)})})},[r]),u=e.useCallback(()=>Array.from(l.current.keys()).sort(),[]),y=e.useCallback(a=>{const i=l.current.get(a);if(!i||!i.isMeshStandardMaterial)return;const m=i;m.map=null,m.normalMap=null,m.roughnessMap=null,m.metalnessMap=null,m.emissiveMap=null,m.alphaMap=null,m.aoMap=null,m.needsUpdate=!0},[]);return{setMaterialTextures:c,getMaterialNames:u,clearMaterialTextures:y}}function ee({url:n,position:t=[0,0,0],rotation:s=[0,0,0],scale:l=1,meshVisibility:f,materialColors:g,materialTextures:T,onLoad:x,onError:h}){const{scene:r}=O.useGLTF(n),o=e.useRef(x);o.current=x;const c=e.useMemo(()=>{const y=r.clone();console.log("[Model] 🔍 Scene clone created, checking materials...");const a=[],i=new Set,m=[];let S=0;return y.traverse(d=>{if(S++,d.type==="Bone"&&m.push(d.name),d.isMesh){const v=d;a.push(v.name),v.castShadow=!0,v.receiveShadow=!0,(Array.isArray(v.material)?v.material:[v.material]).forEach(M=>{i.add(M.name),console.log(`[Model] 📦 Material found: "${M.name}" (uuid: ${M.uuid})`);const b=M;console.log(` - Has map: ${b.map?"YES":"NO"}`),console.log(` - Has normalMap: ${b.normalMap?"YES":"NO"}`),console.log(` - Has roughnessMap: ${b.roughnessMap?"YES":"NO"}`),console.log(` - Has metalnessMap: ${b.metalnessMap?"YES":"NO"}`)})}}),console.log(`[Model] 📊 Clone summary: ${a.length} meshes, ${i.size} materials`),setTimeout(()=>{var d;(d=o.current)==null||d.call(o,{meshes:a.sort(),materials:Array.from(i).sort(),bones:m.sort(),nodeCount:S})},0),y},[r]);G(c,f),K(c,g),U(c,T);const u=typeof l=="number"?[l,l,l]:l;return w.jsx("group",{position:t,rotation:s,scale:u,children:w.jsx("primitive",{object:c})})}ee.preload=n=>{O.useGLTF.preload(n)};function te(n,t,s){const{actions:l,names:f}=O.useAnimations(n,t),g=e.useRef(null),T=e.useRef(s==null?void 0:s.defaultAnimation);e.useEffect(()=>{if(f.length===0)return;const o=T.current;let c=f[0];if(o){const y=f.find(a=>a===o||a.includes(o));y&&(c=y)}const u=l[c];u&&(u.reset().fadeIn(.5).play(),g.current=u)},[l,f]);const x=e.useCallback((o,c)=>{const{loop:u=!1,crossFadeDuration:y=.2,restoreDefault:a=!0}=c||{};let i=l[o];if(!i){const S=Object.keys(l).find(d=>d.toLowerCase().includes(o.toLowerCase())||o.toLowerCase().includes(d.toLowerCase()));S&&(i=l[S])}if(!i){console.warn(`Animation "${o}" not found. Available: ${f.join(", ")}`);return}const m=g.current;if(!(m===i&&i.isRunning())&&(m&&m!==i&&m.fadeOut(y),i.reset(),i.fadeIn(y),i.setLoop(u?E.LoopRepeat:E.LoopOnce,u?1/0:1),i.clampWhenFinished=!u,i.play(),u||i.getMixer().update(0),g.current=i,a&&!u&&T.current)){const S=i.getMixer(),d=v=>{if(v.action===i){S.removeEventListener("finished",d);const R=l[T.current];R&&(i.fadeOut(y),R.reset().fadeIn(y).play(),g.current=R)}};S.addEventListener("finished",d)}},[l,f]),h=e.useCallback(()=>{var o;(o=g.current)==null||o.fadeOut(.2),g.current=null},[]),r=e.useCallback(()=>f,[f]);return{playAnimation:x,stopAnimation:h,getAnimationNames:r,actions:l}}function z(n,t){const s=e.useRef(t||{}),l=e.useRef([]),f=e.useRef([]);e.useEffect(()=>{const h=new Set,r=[];n.traverse(o=>{o instanceof E.Mesh&&o.morphTargetDictionary&&o.morphTargetInfluences&&(r.push(o),Object.keys(o.morphTargetDictionary).forEach(c=>{h.add(c)}))}),l.current=Array.from(h).sort(),f.current=r},[n]),B.useFrame(()=>{const h=s.current;f.current.forEach(r=>{!r.morphTargetDictionary||!r.morphTargetInfluences||Object.entries(h).forEach(([o,c])=>{const u=r.morphTargetDictionary[o];u!==void 0&&(r.morphTargetInfluences[u]=c)})})}),e.useEffect(()=>{t&&(s.current={...t})},[t]);const g=e.useCallback((h,r)=>{s.current[h]=Math.max(0,Math.min(1,r))},[]),T=e.useCallback(()=>l.current,[]),x=e.useCallback(()=>({...s.current}),[]);return{setMorphTarget:g,getMorphTargetNames:T,getMorphTargetValues:x}}const oe=e.createContext(null);function fe(){const n=e.useContext(oe);if(!n)throw new Error("BoneAttachment must be used within an AnimatedModel");return n}const q=e.forwardRef(({url:n,position:t=[0,0,0],rotation:s=[0,0,0],scale:l=1,defaultAnimation:f,morphTargets:g,meshVisibility:T,materialColors:x,materialTextures:h,onLoad:r,onError:o,children:c},u)=>{const y=e.useRef(null),a=e.useRef([]),i=e.useRef(r);i.current=r;const{scene:m,animations:S}=O.useGLTF(n),d=e.useMemo(()=>Q.clone(m),[m]),{playAnimation:v,stopAnimation:R,getAnimationNames:M}=te(S,d,{defaultAnimation:f}),{setMorphTarget:b}=z(d,g),{setMeshVisibility:D,getMeshNames:p}=G(d,T),{setMaterialColor:A,getMaterialNames:k,getMaterialColor:$}=K(d,x),{setMaterialTextures:C,clearMaterialTextures:j}=U(d,h);e.useEffect(()=>{if(!d)return;const I=setTimeout(()=>{var Z;const L=[],H=[],F=new Set,V=new Set;let Y=0;d.traverse(W=>{if(Y++,W.type==="Bone"&&L.push(W.name),W.isMesh){const P=W;H.push(P.name),P.castShadow=!0,P.receiveShadow=!0,(Array.isArray(P.material)?P.material:[P.material]).forEach(_=>{F.add(_.name),_.shadowSide=E.DoubleSide}),P.morphTargetDictionary&&Object.keys(P.morphTargetDictionary).forEach(_=>{V.add(_)})}}),a.current=Array.from(V).sort(),(Z=i.current)==null||Z.call(i,{meshes:H.sort(),materials:Array.from(F).sort(),bones:L.sort(),nodeCount:Y,animations:S.map(W=>W.name),morphTargetNames:a.current})},0);return()=>clearTimeout(I)},[d,S]),e.useImperativeHandle(u,()=>({playAnimation:v,stopAnimation:R,getAnimationNames:M,getGroup:()=>y.current,setMorphTarget:b,getMorphTargetNames:()=>a.current,setMeshVisibility:D,getMeshNames:p,setMaterialColor:A,getMaterialNames:k,getMaterialColor:$,setMaterialTextures:C,clearMaterialTextures:j}));const X=e.useMemo(()=>({scene:d,getBone:I=>d.getObjectByName(I)||null}),[d]),N=typeof l=="number"?[l,l,l]:l;return w.jsx(oe.Provider,{value:X,children:w.jsxs("group",{ref:y,position:t,rotation:s,scale:N,children:[w.jsx("primitive",{object:d}),c]})})});q.displayName="AnimatedModel";q.preload=n=>{O.useGLTF.preload(n)};const re=e.forwardRef(({url:n,position:t=[0,0,0],rotation:s=[0,0,0],scale:l=1,morphTargets:f,meshVisibility:g,materialColors:T,materialTextures:x,onMorphTargetsFound:h,onLoad:r,onError:o},c)=>{const{scene:u}=O.useGLTF(n),y=e.useRef(r);y.current=r;const a=e.useRef(h);a.current=h;const i=e.useMemo(()=>u.clone(),[u]),{setMorphTarget:m,getMorphTargetNames:S,getMorphTargetValues:d}=z(i,f),{setMeshVisibility:v,getMeshNames:R}=G(i,g),{setMaterialColor:M,getMaterialNames:b,getMaterialColor:D}=K(i,T),{setMaterialTextures:p,clearMaterialTextures:A}=U(i,x);e.useEffect(()=>{var C;const $=S();$.length>0&&((C=a.current)==null||C.call(a,$))},[i,S]),e.useEffect(()=>{var N;if(!i)return;const $=[],C=new Set,j=[];let X=0;i.traverse(I=>{if(X++,I.type==="Bone"&&j.push(I.name),I.isMesh){const L=I;$.push(L.name),L.castShadow=!0,L.receiveShadow=!0,(Array.isArray(L.material)?L.material:[L.material]).forEach(F=>C.add(F.name))}}),(N=y.current)==null||N.call(y,{meshes:$.sort(),materials:Array.from(C).sort(),bones:j.sort(),nodeCount:X})},[i]),e.useImperativeHandle(c,()=>({setMorphTarget:m,getMorphTargetNames:S,getMorphTargetValues:d,setMeshVisibility:v,getMeshNames:R,setMaterialColor:M,getMaterialNames:b,getMaterialColor:D,setMaterialTextures:p,clearMaterialTextures:A}));const k=typeof l=="number"?[l,l,l]:l;return w.jsx("group",{position:t,rotation:s,scale:k,children:w.jsx("primitive",{object:i})})});re.displayName="MorphableModel";function me({children:n,bone:t,position:s=[0,0,0],rotation:l=[0,0,0],scale:f=1}){const{getBone:g}=fe(),[T,x]=e.useState(null);if(e.useEffect(()=>{const r=g(t);r?x(r):console.warn(`Bone "${t}" not found in model`)},[t,g]),!T)return null;const h=typeof f=="number"?[f,f,f]:f;return B.createPortal(w.jsx("group",{position:s,rotation:l,scale:h,children:n}),T)}function de(n,t){const{scene:s,animations:l}=O.useGLTF(n),f=e.useMemo(()=>Q.clone(s),[s]);return e.useEffect(()=>{var r;if(!f)return;const g=[],T=[],x=new Set;let h=0;f.traverse(o=>{if(h++,o.type==="Bone"&&g.push(o.name),o.isMesh){const c=o;T.push(c.name),c.castShadow=!0,c.receiveShadow=!0,(Array.isArray(c.material)?c.material:[c.material]).forEach(y=>{x.add(y.name),y.shadowSide=E.DoubleSide})}}),(r=t==null?void 0:t.onLoad)==null||r.call(t,{meshes:T.sort(),materials:Array.from(x).sort(),bones:g.sort(),nodeCount:h})},[f,t]),{scene:f,animations:l}}function Me(n){O.useGLTF.preload(n)}exports.AnimatedModel=q;exports.BoneAttachment=me;exports.Model=ee;exports.MorphableModel=re;exports.Scene3D=pe;exports.preloadModel=Me;exports.useAnimationController=te;exports.useClonedModel=de;exports.useMaterialColor=K;exports.useMaterialTexture=U;exports.useMeshVisibility=G;exports.useMorphTargets=z;
|
|
2
2
|
//# sourceMappingURL=mbt-3d.cjs.map
|