mbt-3d 0.3.8 → 0.3.9
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/index.d.ts +2 -0
- package/dist/mbt-3d.cjs +1 -1
- package/dist/mbt-3d.cjs.map +1 -1
- package/dist/mbt-3d.js +620 -613
- package/dist/mbt-3d.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -185,6 +185,8 @@ export declare interface AnimatedModelProps extends Omit<ModelProps, 'onLoad'> {
|
|
|
185
185
|
children?: React.ReactNode;
|
|
186
186
|
/** Name of animation to play on load (auto-plays first if not specified) */
|
|
187
187
|
defaultAnimation?: string;
|
|
188
|
+
/** Controlled animation name. When changed, AnimatedModel switches to this animation */
|
|
189
|
+
animation?: string;
|
|
188
190
|
/** Morph target values as key-value pairs { targetName: value } where value is 0-1 */
|
|
189
191
|
morphTargets?: Record<string, number>;
|
|
190
192
|
/** Mesh visibility as key-value pairs { meshName: visible }. Example: { "Hairgirl1": true, "Hairgirl2": false } */
|
package/dist/mbt-3d.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),I=require("@react-three/drei"),ne=require("three"),ae=require("three/examples/jsm/utils/SkeletonUtils.js"),B=require("@react-three/fiber"),ie=require("three/examples/jsm/loaders/KTX2Loader.js"),M=require("react/jsx-runtime");function Q(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const o in t)if(o!=="default"){const a=Object.getOwnPropertyDescriptor(t,o);Object.defineProperty(r,o,a.get?a:{enumerable:!0,get:()=>t[o]})}}return r.default=t,Object.freeze(r)}const R=Q(ne),ee=Q(ae);function le({position:t,controlsConfig:r}){const{camera:o}=B.useThree(),a=e.useRef(null);return e.useEffect(()=>{t&&o&&(o.position.set(t[0],t[1],t[2]),o.updateProjectionMatrix(),a.current&&(a.current.target.set(0,0,0),a.current.update()))},[t,o]),M.jsx(I.OrbitControls,{ref:a,makeDefault:!0,enabled:r.enabled,enablePan:r.enablePan,enableZoom:r.enableZoom,enableRotate:r.enableRotate,minDistance:r.minDistance,maxDistance:r.maxDistance,minPolarAngle:r.minPolarAngle,maxPolarAngle:r.maxPolarAngle,autoRotate:r.autoRotate,autoRotateSpeed:r.autoRotateSpeed})}function ce({background:t}){const r=t==null?void 0:t.startsWith("#");return t?r?M.jsx("color",{attach:"background",args:[t]}):M.jsx(ue,{url:t}):null}function ue({url:t}){const r=I.useTexture(t);return e.useMemo(()=>{r.colorSpace=R.SRGBColorSpace},[r]),M.jsx("primitive",{attach:"background",object:r})}function fe({config:t}){return M.jsx(I.Environment,{files:t.files,background:t.background??!1,blur:t.blur??0,children:M.jsx("group",{scale:t.intensity??1,children:M.jsx("ambientLight",{intensity:0})})})}function me({config:t}){switch(t.type){case"spot":{const{position:r=[5,10,5],intensity:o=50,castShadow:a=!0,angle:c=Math.PI/6,penumbra:g=.5,decay:y=2,distance:T=0,color:h="#ffffff"}=t;return M.jsx("spotLight",{position:r,intensity:o,castShadow:a,angle:c,penumbra:g,decay:y,distance:T,color:h})}case"point":{const{position:r=[0,5,0],intensity:o=20,color:a="#ffffff",distance:c=0,decay:g=2,castShadow:y=!1}=t;return M.jsx("pointLight",{position:r,intensity:o,color:a,distance:c,decay:g,castShadow:y})}case"directional":{const{position:r=[10,20,10],intensity:o=40,color:a="#ffffff",castShadow:c=!0}=t;return M.jsx("directionalLight",{position:r,intensity:o,color:a,castShadow:c})}case"hemisphere":{const{skyColor:r="#ffffff",groundColor:o="#444444",intensity:a=.5,position:c=[0,10,0]}=t,g=e.useMemo(()=>new R.Color(r),[r]),y=e.useMemo(()=>new R.Color(o),[o]);return M.jsx("hemisphereLight",{args:[g,y,a],position:c})}case"ambient":{const{intensity:r=.5,color:o="#ffffff"}=t;return M.jsx("ambientLight",{intensity:r,color:o})}default:return null}}function pe({onChange:t}){const{active:r,progress:o}=I.useProgress();return e.useEffect(()=>{t(r,o)},[r,o,t]),null}function de({children:t,camera:r={},controls:o={},background:a,shadows:c=!0,lights:g=[{type:"ambient",intensity:.5},{type:"spot",position:[5,10,5],intensity:50,castShadow:!0}],environment:y,contactShadows:T=!0,showLoadingOverlay:h=!0,style:n,className:i}){const[u,m]=e.useState(!1),[b,s]=e.useState(0),l=e.useRef(null),f=e.useCallback((E,d)=>{if(E){l.current!==null&&(window.clearTimeout(l.current),l.current=null),m(!0),s(Math.max(0,Math.min(100,Math.round(d))));return}s(100),l.current=window.setTimeout(()=>{m(!1),s(0),l.current=null},200)},[]);e.useEffect(()=>()=>{l.current!==null&&window.clearTimeout(l.current)},[]);const S={position:r.position||[0,2,5],fov:r.fov||45},p={enabled:o.enabled??!0,enablePan:o.enablePan??!0,enableZoom:o.enableZoom??!0,enableRotate:o.enableRotate??!0,minDistance:o.minDistance,maxDistance:o.maxDistance,minPolarAngle:o.minPolarAngle,maxPolarAngle:o.maxPolarAngle,autoRotate:o.autoRotate??!1,autoRotateSpeed:o.autoRotateSpeed??2},A=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 M.jsxs("div",{style:{...n||{},position:(n==null?void 0:n.position)??"relative"},className:i,children:[M.jsxs(B.Canvas,{shadows:c,camera:{position:S.position,fov:S.fov},style:{width:"100%",height:"100%"},children:[M.jsx(e.Suspense,{fallback:null,children:M.jsx(ce,{background:a})}),y&&M.jsx(e.Suspense,{fallback:null,children:M.jsx(fe,{config:y})}),g.map((E,d)=>M.jsx(me,{config:E},`${E.type}-${d}`)),M.jsx(e.Suspense,{fallback:null,children:t}),M.jsx(le,{position:S.position,controlsConfig:p}),A&&M.jsx(I.ContactShadows,{position:A.position,opacity:A.opacity,blur:A.blur}),M.jsx(pe,{onChange:f})]}),h&&u&&M.jsx("div",{style:{position:"absolute",inset:0,background:"rgba(8, 10, 16, 0.46)",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none",zIndex:10},children:M.jsxs("div",{style:{minWidth:220,padding:"16px 18px",borderRadius:14,border:"1px solid rgba(255,255,255,0.2)",background:"linear-gradient(180deg, rgba(18,24,36,0.9), rgba(13,17,27,0.9))",color:"#eef3ff",boxShadow:"0 10px 30px rgba(0,0,0,0.35)",fontFamily:"system-ui, -apple-system, Segoe UI, sans-serif",textAlign:"center"},children:[M.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:10},children:M.jsxs("svg",{width:"34",height:"34",viewBox:"0 0 34 34","aria-hidden":"true",children:[M.jsx("circle",{cx:"17",cy:"17",r:"14",fill:"none",stroke:"rgba(255,255,255,0.2)",strokeWidth:"4"}),M.jsx("path",{d:"M31 17a14 14 0 0 1-14 14",fill:"none",stroke:"#67b4ff",strokeWidth:"4",strokeLinecap:"round",children:M.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 17 17",to:"360 17 17",dur:"0.9s",repeatCount:"indefinite"})})]})}),M.jsxs("div",{style:{fontSize:12,opacity:.82,marginTop:4},children:[b,"%"]})]})})]})}function K(t,r){const o=e.useRef(new Map),a=e.useRef({}),c=e.useRef({});e.useEffect(()=>{r&&(a.current={...r})},[r]),e.useEffect(()=>{if(!t)return;const h=new Map;t.traverse(n=>{if(n.isMesh){const i=n;i.name&&h.set(i.name,i)}}),o.current=h},[t]),B.useFrame(()=>{const h=o.current;if(h.size===0)return;const n={...a.current,...c.current};for(const[i,u]of Object.entries(n)){const m=h.get(i);m&&m.visible!==u&&(m.visible=u)}});const g=e.useCallback((h,n)=>{c.current[h]=n;const i=o.current.get(h);i&&(i.visible=n)},[]),y=e.useCallback(()=>Array.from(o.current.keys()).sort(),[]),T=e.useCallback(()=>{const h={};return o.current.forEach((n,i)=>{h[i]=n.visible}),h},[]);return{setMeshVisibility:g,getMeshNames:y,getMeshVisibility:T}}function G(t,r){const o=e.useRef(new Map),a=e.useRef(new Map);e.useEffect(()=>{if(!t)return;const n=new Map;t.traverse(i=>{if(i.isMesh){const u=i;(Array.isArray(u.material)?u.material:[u.material]).forEach(b=>{b.name&&!n.has(b.name)&&n.set(b.name,b)})}}),o.current=n,r&&Object.entries(r).forEach(([i,u])=>{const m=n.get(i);if(m&&!Array.isArray(m)){const b=c(u);m.color&&m.color.copy(b),a.current.set(i,b)}})},[t,r]),B.useFrame(()=>{a.current.forEach((n,i)=>{const u=o.current.get(i);if(u&&!Array.isArray(u)){const m=u;m.color&&!m.color.equals(n)&&(m.color.copy(n),m.needsUpdate=!0)}})});const c=n=>typeof n=="string"?new R.Color(n):new R.Color(n[0],n[1],n[2]),g=e.useCallback((n,i)=>{const u=c(i);a.current.set(n,u);const m=o.current.get(n);if(m&&!Array.isArray(m)){const b=m;b.color&&(b.color.copy(u),b.needsUpdate=!0)}},[]),y=e.useCallback(()=>Array.from(o.current.keys()).sort(),[]),T=e.useCallback(n=>{const i=o.current.get(n);if(i&&!Array.isArray(i)){const u=i;if(u.color)return"#"+u.color.getHexString()}return null},[]),h=e.useCallback(()=>{const n={};return o.current.forEach((i,u)=>{if(!Array.isArray(i)){const m=i;m.color&&(n[u]="#"+m.color.getHexString())}}),n},[]);return{setMaterialColor:g,getMaterialNames:y,getMaterialColor:T,getAllMaterialColors:h}}function H(t){const r=t.toLowerCase();if(r.endsWith(".ktx2"))return!0;try{const o=new URL(t,window.location.origin),a=decodeURIComponent(o.hash.replace(/^#/,"")).toLowerCase(),c=decodeURIComponent(o.search).toLowerCase(),g=decodeURIComponent(o.pathname).toLowerCase();return a.endsWith(".ktx2")||c.includes(".ktx2")||g.endsWith(".ktx2")}catch{return r.includes(".ktx2")}}function z(t,r){const{gl:o}=B.useThree(),a=e.useRef(new Map),c=e.useRef(new R.TextureLoader),g=e.useRef(null),y=e.useRef(new Map),T=e.useRef(new Set),h=e.useRef("");e.useEffect(()=>{if(!g.current)try{const s=typeof WebAssembly=="object"&&typeof WebAssembly.validate=="function";console.log("[useMaterialTexture] Browser features:"),console.log(` WebAssembly supported: ${s}`),console.log(` WebGL2: ${o.capabilities.isWebGL2}`);const l=new ie.KTX2Loader;l.setTranscoderPath("/basis/"),l.detectSupport(o),g.current=l,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)}),s||(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(s){console.error("[useMaterialTexture] ❌ Failed to initialize KTX2Loader:",s)}return()=>{g.current&&(g.current.dispose(),g.current=null)}},[o]),e.useEffect(()=>{if(!t)return;const s=new Map;t.traverse(l=>{if(l.isMesh){const f=l;(Array.isArray(f.material)?f.material:[f.material]).forEach(p=>{p.name&&!s.has(p.name)&&s.set(p.name,p)})}}),a.current=s},[t]);const n=e.useCallback(s=>H(s)?g.current?g.current:(console.warn("[useMaterialTexture] KTX2Loader not initialized, falling back to TextureLoader"),c.current):c.current,[]);e.useEffect(()=>{if(!r||!t)return;const s=a.current;if(s.size===0)return;const l=JSON.stringify(r);if(h.current===l){console.log("[useMaterialTexture] Textures unchanged, skipping reload");return}h.current=l;let f=!1;const S=new Map;Object.entries(r).forEach(([d,w])=>{S.set(d,typeof w=="string"?{map:w}:w)}),console.log("[useMaterialTexture] Starting texture load for",S.size,"materials");const p=[];S.forEach((d,w)=>{var v,L;const N=s.get(w);if(!N||!N.isMeshStandardMaterial){console.warn(`[useMaterialTexture] Material "${w}" not found or not MeshStandardMaterial`);return}const x=N;console.log(`[useMaterialTexture] 📋 Material "${w}" BEFORE reset:`),console.log(` - map: ${x.map?"EXISTS":"null"} ${x.map?`(uuid: ${x.map.uuid})`:""}`),console.log(` - normalMap: ${x.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${x.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${x.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${x.emissiveMap?"EXISTS":"null"}`),console.log(` - aoMap: ${x.aoMap?"EXISTS":"null"}`),console.log(` - color: ${(v=x.color)==null?void 0:v.getHexString()}`),console.log(` - emissive: ${(L=x.emissive)==null?void 0:L.getHexString()}`),console.log(` - material uuid: ${x.uuid}`),Object.entries(d).forEach(([$,j])=>{if(!j)return;const C=$,k=x[C];k&&(console.log(`[useMaterialTexture] 🗑️ Disposing old ${C} (uuid: ${k.uuid})`),k.dispose(),x[C]=null)}),d.emissiveMap&&(x.emissive=new R.Color(0),x.emissiveIntensity=0),x.needsUpdate=!0,x.color=new R.Color(16777215),console.log(`[useMaterialTexture] ✅ Material "${w}" AFTER reset: only specified maps cleared`),Object.entries(d).forEach(([$,j])=>{if(!j)return;const C=`${w}_${$}_${j}`,k=y.current.get(C);if(k){console.log(`[useMaterialTexture] Using cached texture: ${w}.${$}`),f||i(x,$,k);return}if(T.current.has(C)){console.log(`[useMaterialTexture] Skipping already loading: ${w}.${$}`);return}p.push({materialName:w,textureType:$,url:j,material:x})})}),console.log(`[useMaterialTexture] Queued ${p.length} textures to load`);let A=0;const E=()=>{if(f||A>=p.length){console.log("[useMaterialTexture] ✅ All textures loaded"),console.log("[useMaterialTexture] 📊 FINAL material states:"),s.forEach((v,L)=>{var j,C;const $=v;console.log(` Material "${L}":`),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: ${(j=$.color)==null?void 0:j.getHexString()}`),console.log(` - emissive: ${(C=$.emissive)==null?void 0:C.getHexString()}`),console.log(` - emissiveIntensity: ${$.emissiveIntensity}`),console.log(` - roughness: ${$.roughness}`),console.log(` - metalness: ${$.metalness}`)});return}const d=p[A++],w=`${d.materialName}_${d.textureType}_${d.url}`;console.log(`[useMaterialTexture] Loading (${A}/${p.length}): ${d.materialName}.${d.textureType} from ${d.url}`),T.current.add(w);const N=n(d.url),x=H(d.url)?"KTX2Loader":"TextureLoader";console.log(`[useMaterialTexture] Using ${x} for ${d.url}`),N.load(d.url,v=>{var C,k,D,P,O,W;if(T.current.delete(w),f){console.log(`[useMaterialTexture] Disposed, cleaning up texture: ${d.materialName}.${d.textureType}`),v.dispose();return}const L=((C=v.image)==null?void 0:C.width)||((D=(k=v.source)==null?void 0:k.data)==null?void 0:D.width)||"unknown",$=((P=v.image)==null?void 0:P.height)||((W=(O=v.source)==null?void 0:O.data)==null?void 0:W.height)||"unknown";console.log(`[useMaterialTexture] ✅ Loaded: ${d.materialName}.${d.textureType} (${L}x${$})`),v.colorSpace=d.textureType==="map"||d.textureType==="emissiveMap"?R.SRGBColorSpace:R.NoColorSpace,v.wrapS=R.RepeatWrapping,v.wrapT=R.RepeatWrapping,v.flipY=!1,y.current.set(w,v),i(d.material,d.textureType,v);const j=H(d.url)?500:150;console.log(`[useMaterialTexture] Waiting111111 ${j}ms before next texture...`),setTimeout(E,0)},v=>{if(v.lengthComputable){const L=Math.round(v.loaded/v.total*100);L%25===0&&console.log(`[useMaterialTexture] Progress ${d.materialName}.${d.textureType}: ${L}%`)}},v=>{T.current.delete(w),f||(console.error(`[useMaterialTexture] ❌ Failed to load ${d.materialName}.${d.textureType} from ${d.url}`),console.error("[useMaterialTexture] Error details:",v),console.error("[useMaterialTexture] Loader type:",x),H(d.url)&&(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(E,100)})};return E(),()=>{console.log("[useMaterialTexture] Cleanup: disposed"),f=!0}},[t,r,n]);const i=(s,l,f)=>{var S,p;switch(console.log(`[useMaterialTexture] 🎨 Applying texture: ${s.name}.${l} (texture uuid: ${f.uuid})`),l){case"map":s.map=f;break;case"normalMap":s.normalMap=f;break;case"roughnessMap":s.roughnessMap=f;break;case"metalnessMap":s.metalnessMap=f;break;case"emissiveMap":s.emissiveMap=f,s.emissive=new R.Color(16777215),s.emissiveIntensity=1;break;case"alphaMap":console.log(`[useMaterialTexture] Skipping alphaMap for "${s.name}" to prevent disappearing`);break;case"aoMap":s.aoMap=f;break}s.needsUpdate=!0,console.log(`[useMaterialTexture] ✅ Applied ${l} to ${s.name}, needsUpdate=true`),console.log(`[useMaterialTexture] 📊 Material "${s.name}" FINAL state:`),console.log(` - map: ${s.map?"EXISTS":"null"} ${s.map?`(uuid: ${s.map.uuid}, colorSpace: ${s.map.colorSpace})`:""}`),console.log(` - normalMap: ${s.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${s.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${s.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${s.emissiveMap?"EXISTS":"null"}`),console.log(` - aoMap: ${s.aoMap?"EXISTS":"null"}`),console.log(` - color: ${(S=s.color)==null?void 0:S.getHexString()}`),console.log(` - emissive: ${(p=s.emissive)==null?void 0:p.getHexString()}`),console.log(` - emissiveIntensity: ${s.emissiveIntensity}`),console.log(` - roughness: ${s.roughness}`),console.log(` - metalness: ${s.metalness}`)},u=e.useCallback((s,l)=>{const f=typeof l=="string"?{map:l}:l,S=a.current.get(s);if(!S||!S.isMeshStandardMaterial){console.warn(`Material "${s}" not found or not MeshStandardMaterial`);return}const p=S;Object.entries(f).forEach(([A,E])=>{if(!E)return;const d=`${s}_${A}_${E}`,w=y.current.get(d);if(w){i(p,A,w);return}n(E).load(E,x=>{x.colorSpace=A==="map"||A==="emissiveMap"?R.SRGBColorSpace:R.NoColorSpace,x.wrapS=R.RepeatWrapping,x.wrapT=R.RepeatWrapping,y.current.set(d,x),i(p,A,x)},void 0,x=>{console.error(`Failed to load texture ${E}:`,x)})})},[n]),m=e.useCallback(()=>Array.from(a.current.keys()).sort(),[]),b=e.useCallback(s=>{const l=a.current.get(s);if(!l||!l.isMeshStandardMaterial)return;const f=l;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:u,getMaterialNames:m,clearMaterialTextures:b}}function te({url:t,position:r=[0,0,0],rotation:o=[0,0,0],scale:a=1,meshVisibility:c,materialColors:g,materialTextures:y,onLoad:T,onError:h}){const{scene:n}=I.useGLTF(t),i=e.useRef(T);i.current=T;const u=e.useMemo(()=>{const b=n.clone();console.log("[Model] 🔍 Scene clone created, checking materials...");const s=[],l=new Set,f=[];let S=0;return b.traverse(p=>{if(S++,p.type==="Bone"&&f.push(p.name),p.isMesh){const A=p;s.push(A.name),A.castShadow=!0,A.receiveShadow=!0,(Array.isArray(A.material)?A.material:[A.material]).forEach(d=>{l.add(d.name),console.log(`[Model] 📦 Material found: "${d.name}" (uuid: ${d.uuid})`);const w=d;console.log(` - Has map: ${w.map?"YES":"NO"}`),console.log(` - Has normalMap: ${w.normalMap?"YES":"NO"}`),console.log(` - Has roughnessMap: ${w.roughnessMap?"YES":"NO"}`),console.log(` - Has metalnessMap: ${w.metalnessMap?"YES":"NO"}`)})}}),console.log(`[Model] 📊 Clone summary: ${s.length} meshes, ${l.size} materials`),setTimeout(()=>{var p;(p=i.current)==null||p.call(i,{meshes:s.sort(),materials:Array.from(l).sort(),bones:f.sort(),nodeCount:S})},0),b},[n]);K(u,c),G(u,g),z(u,y);const m=typeof a=="number"?[a,a,a]:a;return M.jsx("group",{position:r,rotation:o,scale:m,children:M.jsx("primitive",{object:u})})}te.preload=t=>{I.useGLTF.preload(t)};function re(t,r,o){const{actions:a,names:c}=I.useAnimations(t,r),g=e.useRef(null),y=e.useRef(o==null?void 0:o.defaultAnimation);e.useEffect(()=>{if(c.length===0)return;const i=y.current;let u=c[0];if(i){const b=c.find(s=>s===i||s.includes(i));b&&(u=b)}const m=a[u];m&&(m.reset().fadeIn(.5).play(),g.current=m)},[a,c]);const T=e.useCallback((i,u)=>{const{loop:m=!1,crossFadeDuration:b=.2,restoreDefault:s=!0}=u||{};let l=a[i];if(!l){const S=Object.keys(a).find(p=>p.toLowerCase().includes(i.toLowerCase())||i.toLowerCase().includes(p.toLowerCase()));S&&(l=a[S])}if(!l){console.warn(`Animation "${i}" not found. Available: ${c.join(", ")}`);return}const f=g.current;if(!(f===l&&l.isRunning())&&(f&&f!==l&&f.fadeOut(b),l.reset(),l.fadeIn(b),l.setLoop(m?R.LoopRepeat:R.LoopOnce,m?1/0:1),l.clampWhenFinished=!m,l.play(),m||l.getMixer().update(0),g.current=l,s&&!m&&y.current)){const S=l.getMixer(),p=A=>{if(A.action===l){S.removeEventListener("finished",p);const E=a[y.current];E&&(l.fadeOut(b),E.reset().fadeIn(b).play(),g.current=E)}};S.addEventListener("finished",p)}},[a,c]),h=e.useCallback(()=>{var i;(i=g.current)==null||i.fadeOut(.2),g.current=null},[]),n=e.useCallback(()=>c,[c]);return{playAnimation:T,stopAnimation:h,getAnimationNames:n,actions:a}}function q(t,r){const o=e.useRef(r||{}),a=e.useRef([]),c=e.useRef([]);e.useEffect(()=>{const h=new Set,n=[];t.traverse(i=>{i instanceof R.Mesh&&i.morphTargetDictionary&&i.morphTargetInfluences&&(n.push(i),Object.keys(i.morphTargetDictionary).forEach(u=>{h.add(u)}))}),a.current=Array.from(h).sort(),c.current=n},[t]),B.useFrame(()=>{const h=o.current;c.current.forEach(n=>{!n.morphTargetDictionary||!n.morphTargetInfluences||Object.entries(h).forEach(([i,u])=>{const m=n.morphTargetDictionary[i];m!==void 0&&(n.morphTargetInfluences[m]=u)})})}),e.useEffect(()=>{r&&(o.current={...r})},[r]);const g=e.useCallback((h,n)=>{o.current[h]=Math.max(0,Math.min(1,n))},[]),y=e.useCallback(()=>a.current,[]),T=e.useCallback(()=>({...o.current}),[]);return{setMorphTarget:g,getMorphTargetNames:y,getMorphTargetValues:T}}const oe=e.createContext(null);function ge(){const t=e.useContext(oe);if(!t)throw new Error("BoneAttachment must be used within an AnimatedModel");return t}const V=e.forwardRef(({url:t,position:r=[0,0,0],rotation:o=[0,0,0],scale:a=1,defaultAnimation:c,morphTargets:g,meshVisibility:y,materialColors:T,materialTextures:h,onLoad:n,onError:i,children:u},m)=>{const b=e.useRef(null),s=e.useRef([]),l=e.useRef(n);l.current=n;const{scene:f,animations:S}=I.useGLTF(t),p=e.useMemo(()=>ee.clone(f),[f]),{playAnimation:A,stopAnimation:E,getAnimationNames:d}=re(S,p,{defaultAnimation:c}),{setMorphTarget:w}=q(p,g),{setMeshVisibility:N,getMeshNames:x}=K(p,y),{setMaterialColor:v,getMaterialNames:L,getMaterialColor:$}=G(p,T),{setMaterialTextures:j,clearMaterialTextures:C}=z(p,h);e.useEffect(()=>{if(!p)return;const P=setTimeout(()=>{var J;const O=[],W=[],_=new Set,Y=new Set;let Z=0;p.traverse(F=>{if(Z++,F.type==="Bone"&&O.push(F.name),F.isMesh){const X=F;W.push(X.name),X.castShadow=!0,X.receiveShadow=!0,(Array.isArray(X.material)?X.material:[X.material]).forEach(U=>{_.add(U.name),U.shadowSide=R.DoubleSide}),X.morphTargetDictionary&&Object.keys(X.morphTargetDictionary).forEach(U=>{Y.add(U)})}}),s.current=Array.from(Y).sort(),(J=l.current)==null||J.call(l,{meshes:W.sort(),materials:Array.from(_).sort(),bones:O.sort(),nodeCount:Z,animations:S.map(F=>F.name),morphTargetNames:s.current})},0);return()=>clearTimeout(P)},[p,S]),e.useImperativeHandle(m,()=>({playAnimation:A,stopAnimation:E,getAnimationNames:d,getGroup:()=>b.current,setMorphTarget:w,getMorphTargetNames:()=>s.current,setMeshVisibility:N,getMeshNames:x,setMaterialColor:v,getMaterialNames:L,getMaterialColor:$,setMaterialTextures:j,clearMaterialTextures:C}));const k=e.useMemo(()=>({scene:p,getBone:P=>p.getObjectByName(P)||null}),[p]),D=typeof a=="number"?[a,a,a]:a;return M.jsx(oe.Provider,{value:k,children:M.jsxs("group",{ref:b,position:r,rotation:o,scale:D,children:[M.jsx("primitive",{object:p}),u]})})});V.displayName="AnimatedModel";V.preload=t=>{I.useGLTF.preload(t)};const se=e.forwardRef(({url:t,position:r=[0,0,0],rotation:o=[0,0,0],scale:a=1,morphTargets:c,meshVisibility:g,materialColors:y,materialTextures:T,onMorphTargetsFound:h,onLoad:n,onError:i},u)=>{const{scene:m}=I.useGLTF(t),b=e.useRef(n);b.current=n;const s=e.useRef(h);s.current=h;const l=e.useMemo(()=>m.clone(),[m]),{setMorphTarget:f,getMorphTargetNames:S,getMorphTargetValues:p}=q(l,c),{setMeshVisibility:A,getMeshNames:E}=K(l,g),{setMaterialColor:d,getMaterialNames:w,getMaterialColor:N}=G(l,y),{setMaterialTextures:x,clearMaterialTextures:v}=z(l,T);e.useEffect(()=>{var j;const $=S();$.length>0&&((j=s.current)==null||j.call(s,$))},[l,S]),e.useEffect(()=>{var D;if(!l)return;const $=[],j=new Set,C=[];let k=0;l.traverse(P=>{if(k++,P.type==="Bone"&&C.push(P.name),P.isMesh){const O=P;$.push(O.name),O.castShadow=!0,O.receiveShadow=!0,(Array.isArray(O.material)?O.material:[O.material]).forEach(_=>j.add(_.name))}}),(D=b.current)==null||D.call(b,{meshes:$.sort(),materials:Array.from(j).sort(),bones:C.sort(),nodeCount:k})},[l]),e.useImperativeHandle(u,()=>({setMorphTarget:f,getMorphTargetNames:S,getMorphTargetValues:p,setMeshVisibility:A,getMeshNames:E,setMaterialColor:d,getMaterialNames:w,getMaterialColor:N,setMaterialTextures:x,clearMaterialTextures:v}));const L=typeof a=="number"?[a,a,a]:a;return M.jsx("group",{position:r,rotation:o,scale:L,children:M.jsx("primitive",{object:l})})});se.displayName="MorphableModel";function he({children:t,bone:r,position:o=[0,0,0],rotation:a=[0,0,0],scale:c=1}){const{getBone:g}=ge(),[y,T]=e.useState(null);if(e.useEffect(()=>{const n=g(r);n?T(n):console.warn(`Bone "${r}" not found in model`)},[r,g]),!y)return null;const h=typeof c=="number"?[c,c,c]:c;return B.createPortal(M.jsx("group",{position:o,rotation:a,scale:h,children:t}),y)}function Me(t,r){const{scene:o,animations:a}=I.useGLTF(t),c=e.useMemo(()=>ee.clone(o),[o]);return e.useEffect(()=>{var n;if(!c)return;const g=[],y=[],T=new Set;let h=0;c.traverse(i=>{if(h++,i.type==="Bone"&&g.push(i.name),i.isMesh){const u=i;y.push(u.name),u.castShadow=!0,u.receiveShadow=!0,(Array.isArray(u.material)?u.material:[u.material]).forEach(b=>{T.add(b.name),b.shadowSide=R.DoubleSide})}}),(n=r==null?void 0:r.onLoad)==null||n.call(r,{meshes:y.sort(),materials:Array.from(T).sort(),bones:g.sort(),nodeCount:h})},[c,r]),{scene:c,animations:a}}function be(t){I.useGLTF.preload(t)}exports.AnimatedModel=V;exports.BoneAttachment=he;exports.Model=te;exports.MorphableModel=se;exports.Scene3D=de;exports.preloadModel=be;exports.useAnimationController=re;exports.useClonedModel=Me;exports.useMaterialColor=G;exports.useMaterialTexture=z;exports.useMeshVisibility=K;exports.useMorphTargets=q;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),O=require("@react-three/drei"),ae=require("three"),le=require("three/examples/jsm/utils/SkeletonUtils.js"),B=require("@react-three/fiber"),ie=require("three/examples/jsm/loaders/KTX2Loader.js"),h=require("react/jsx-runtime");function ee(r){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const e in r)if(e!=="default"){const l=Object.getOwnPropertyDescriptor(r,e);Object.defineProperty(s,e,l.get?l:{enumerable:!0,get:()=>r[e]})}}return s.default=r,Object.freeze(s)}const R=ee(ae),te=ee(le);function ce({position:r,controlsConfig:s}){const{camera:e}=B.useThree(),l=t.useRef(null);return t.useEffect(()=>{r&&e&&(e.position.set(r[0],r[1],r[2]),e.updateProjectionMatrix(),l.current&&(l.current.target.set(0,0,0),l.current.update()))},[r,e]),h.jsx(O.OrbitControls,{ref:l,makeDefault:!0,enabled:s.enabled,enablePan:s.enablePan,enableZoom:s.enableZoom,enableRotate:s.enableRotate,minDistance:s.minDistance,maxDistance:s.maxDistance,minPolarAngle:s.minPolarAngle,maxPolarAngle:s.maxPolarAngle,autoRotate:s.autoRotate,autoRotateSpeed:s.autoRotateSpeed})}function ue({background:r}){const s=r==null?void 0:r.startsWith("#");return r?s?h.jsx("color",{attach:"background",args:[r]}):h.jsx(fe,{url:r}):null}function fe({url:r}){const s=O.useTexture(r);return t.useMemo(()=>{s.colorSpace=R.SRGBColorSpace},[s]),h.jsx("primitive",{attach:"background",object:s})}function me({config:r}){return h.jsx(O.Environment,{files:r.files,background:r.background??!1,blur:r.blur??0,children:h.jsx("group",{scale:r.intensity??1,children:h.jsx("ambientLight",{intensity:0})})})}function pe({config:r}){switch(r.type){case"spot":{const{position:s=[5,10,5],intensity:e=50,castShadow:l=!0,angle:u=Math.PI/6,penumbra:d=.5,decay:y=2,distance:S=0,color:g="#ffffff"}=r;return h.jsx("spotLight",{position:s,intensity:e,castShadow:l,angle:u,penumbra:d,decay:y,distance:S,color:g})}case"point":{const{position:s=[0,5,0],intensity:e=20,color:l="#ffffff",distance:u=0,decay:d=2,castShadow:y=!1}=r;return h.jsx("pointLight",{position:s,intensity:e,color:l,distance:u,decay:d,castShadow:y})}case"directional":{const{position:s=[10,20,10],intensity:e=40,color:l="#ffffff",castShadow:u=!0}=r;return h.jsx("directionalLight",{position:s,intensity:e,color:l,castShadow:u})}case"hemisphere":{const{skyColor:s="#ffffff",groundColor:e="#444444",intensity:l=.5,position:u=[0,10,0]}=r,d=t.useMemo(()=>new R.Color(s),[s]),y=t.useMemo(()=>new R.Color(e),[e]);return h.jsx("hemisphereLight",{args:[d,y,l],position:u})}case"ambient":{const{intensity:s=.5,color:e="#ffffff"}=r;return h.jsx("ambientLight",{intensity:s,color:e})}default:return null}}function de({onChange:r}){const{active:s,progress:e}=O.useProgress();return t.useEffect(()=>{r(s,e)},[s,e,r]),null}function ge({children:r,camera:s={},controls:e={},background:l,shadows:u=!0,lights:d=[{type:"ambient",intensity:.5},{type:"spot",position:[5,10,5],intensity:50,castShadow:!0}],environment:y,contactShadows:S=!0,showLoadingOverlay:g=!0,style:a,className:n}){const[f,m]=t.useState(!1),[x,o]=t.useState(0),i=t.useRef(null),c=t.useCallback((v,p)=>{if(v){i.current!==null&&(window.clearTimeout(i.current),i.current=null),m(!0),o(Math.max(0,Math.min(100,Math.round(p))));return}o(100),i.current=window.setTimeout(()=>{m(!1),o(0),i.current=null},200)},[]);t.useEffect(()=>()=>{i.current!==null&&window.clearTimeout(i.current)},[]);const $={position:s.position||[0,2,5],fov:s.fov||45},M={enabled:e.enabled??!0,enablePan:e.enablePan??!0,enableZoom:e.enableZoom??!0,enableRotate:e.enableRotate??!0,minDistance:e.minDistance,maxDistance:e.maxDistance,minPolarAngle:e.minPolarAngle,maxPolarAngle:e.maxPolarAngle,autoRotate:e.autoRotate??!1,autoRotateSpeed:e.autoRotateSpeed??2},b=typeof S=="object"?{position:S.position||[0,-1,0],opacity:S.opacity??.5,blur:S.blur??2}:S?{position:[0,-1,0],opacity:.5,blur:2}:null;return h.jsxs("div",{style:{...a||{},position:(a==null?void 0:a.position)??"relative"},className:n,children:[h.jsxs(B.Canvas,{shadows:u,camera:{position:$.position,fov:$.fov},style:{width:"100%",height:"100%"},children:[h.jsx(t.Suspense,{fallback:null,children:h.jsx(ue,{background:l})}),y&&h.jsx(t.Suspense,{fallback:null,children:h.jsx(me,{config:y})}),d.map((v,p)=>h.jsx(pe,{config:v},`${v.type}-${p}`)),h.jsx(t.Suspense,{fallback:null,children:r}),h.jsx(ce,{position:$.position,controlsConfig:M}),b&&h.jsx(O.ContactShadows,{position:b.position,opacity:b.opacity,blur:b.blur}),h.jsx(de,{onChange:c})]}),g&&f&&h.jsx("div",{style:{position:"absolute",inset:0,background:"rgba(8, 10, 16, 0.46)",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none",zIndex:10},children:h.jsxs("div",{style:{minWidth:220,padding:"16px 18px",borderRadius:14,border:"1px solid rgba(255,255,255,0.2)",background:"linear-gradient(180deg, rgba(18,24,36,0.9), rgba(13,17,27,0.9))",color:"#eef3ff",boxShadow:"0 10px 30px rgba(0,0,0,0.35)",fontFamily:"system-ui, -apple-system, Segoe UI, sans-serif",textAlign:"center"},children:[h.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:10},children:h.jsxs("svg",{width:"34",height:"34",viewBox:"0 0 34 34","aria-hidden":"true",children:[h.jsx("circle",{cx:"17",cy:"17",r:"14",fill:"none",stroke:"rgba(255,255,255,0.2)",strokeWidth:"4"}),h.jsx("path",{d:"M31 17a14 14 0 0 1-14 14",fill:"none",stroke:"#67b4ff",strokeWidth:"4",strokeLinecap:"round",children:h.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 17 17",to:"360 17 17",dur:"0.9s",repeatCount:"indefinite"})})]})}),h.jsxs("div",{style:{fontSize:12,opacity:.82,marginTop:4},children:[x,"%"]})]})})]})}function K(r,s){const e=t.useRef(new Map),l=t.useRef({}),u=t.useRef({});t.useEffect(()=>{s&&(l.current={...s})},[s]),t.useEffect(()=>{if(!r)return;const g=new Map;r.traverse(a=>{if(a.isMesh){const n=a;n.name&&g.set(n.name,n)}}),e.current=g},[r]),B.useFrame(()=>{const g=e.current;if(g.size===0)return;const a={...l.current,...u.current};for(const[n,f]of Object.entries(a)){const m=g.get(n);m&&m.visible!==f&&(m.visible=f)}});const d=t.useCallback((g,a)=>{u.current[g]=a;const n=e.current.get(g);n&&(n.visible=a)},[]),y=t.useCallback(()=>Array.from(e.current.keys()).sort(),[]),S=t.useCallback(()=>{const g={};return e.current.forEach((a,n)=>{g[n]=a.visible}),g},[]);return{setMeshVisibility:d,getMeshNames:y,getMeshVisibility:S}}function G(r,s){const e=t.useRef(new Map),l=t.useRef(new Map);t.useEffect(()=>{if(!r)return;const a=new Map;r.traverse(n=>{if(n.isMesh){const f=n;(Array.isArray(f.material)?f.material:[f.material]).forEach(x=>{x.name&&!a.has(x.name)&&a.set(x.name,x)})}}),e.current=a,s&&Object.entries(s).forEach(([n,f])=>{const m=a.get(n);if(m&&!Array.isArray(m)){const x=u(f);m.color&&m.color.copy(x),l.current.set(n,x)}})},[r,s]),B.useFrame(()=>{l.current.forEach((a,n)=>{const f=e.current.get(n);if(f&&!Array.isArray(f)){const m=f;m.color&&!m.color.equals(a)&&(m.color.copy(a),m.needsUpdate=!0)}})});const u=a=>typeof a=="string"?new R.Color(a):new R.Color(a[0],a[1],a[2]),d=t.useCallback((a,n)=>{const f=u(n);l.current.set(a,f);const m=e.current.get(a);if(m&&!Array.isArray(m)){const x=m;x.color&&(x.color.copy(f),x.needsUpdate=!0)}},[]),y=t.useCallback(()=>Array.from(e.current.keys()).sort(),[]),S=t.useCallback(a=>{const n=e.current.get(a);if(n&&!Array.isArray(n)){const f=n;if(f.color)return"#"+f.color.getHexString()}return null},[]),g=t.useCallback(()=>{const a={};return e.current.forEach((n,f)=>{if(!Array.isArray(n)){const m=n;m.color&&(a[f]="#"+m.color.getHexString())}}),a},[]);return{setMaterialColor:d,getMaterialNames:y,getMaterialColor:S,getAllMaterialColors:g}}function H(r){const s=r.toLowerCase();if(s.endsWith(".ktx2"))return!0;try{const e=new URL(r,window.location.origin),l=decodeURIComponent(e.hash.replace(/^#/,"")).toLowerCase(),u=decodeURIComponent(e.search).toLowerCase(),d=decodeURIComponent(e.pathname).toLowerCase();return l.endsWith(".ktx2")||u.includes(".ktx2")||d.endsWith(".ktx2")}catch{return s.includes(".ktx2")}}function z(r,s){const{gl:e}=B.useThree(),l=t.useRef(new Map),u=t.useRef(new R.TextureLoader),d=t.useRef(null),y=t.useRef(new Map),S=t.useRef(new Set),g=t.useRef("");t.useEffect(()=>{if(!d.current)try{const o=typeof WebAssembly=="object"&&typeof WebAssembly.validate=="function";console.log("[useMaterialTexture] Browser features:"),console.log(` WebAssembly supported: ${o}`),console.log(` WebGL2: ${e.capabilities.isWebGL2}`);const i=new ie.KTX2Loader;i.setTranscoderPath("/basis/"),i.detectSupport(e),d.current=i,console.log("[useMaterialTexture] ✅ KTX2Loader initialized"),console.log("[useMaterialTexture] Transcoder path: /basis/"),fetch("/basis/basis_transcoder.wasm").then(c=>{c.ok?console.log("[useMaterialTexture] ✅ basis_transcoder.wasm is accessible"):console.error("[useMaterialTexture] ❌ basis_transcoder.wasm returned",c.status)}).catch(c=>{console.error("[useMaterialTexture] ❌ Failed to check basis_transcoder.wasm:",c)}),o||(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(o){console.error("[useMaterialTexture] ❌ Failed to initialize KTX2Loader:",o)}return()=>{d.current&&(d.current.dispose(),d.current=null)}},[e]),t.useEffect(()=>{if(!r)return;const o=new Map;r.traverse(i=>{if(i.isMesh){const c=i;(Array.isArray(c.material)?c.material:[c.material]).forEach(M=>{M.name&&!o.has(M.name)&&o.set(M.name,M)})}}),l.current=o},[r]);const a=t.useCallback(o=>H(o)?d.current?d.current:(console.warn("[useMaterialTexture] KTX2Loader not initialized, falling back to TextureLoader"),u.current):u.current,[]);t.useEffect(()=>{if(!s||!r)return;const o=l.current;if(o.size===0)return;const i=JSON.stringify(s);if(g.current===i){console.log("[useMaterialTexture] Textures unchanged, skipping reload");return}g.current=i;let c=!1;const $=new Map;Object.entries(s).forEach(([p,A])=>{$.set(p,typeof A=="string"?{map:A}:A)}),console.log("[useMaterialTexture] Starting texture load for",$.size,"materials");const M=[];$.forEach((p,A)=>{var E,L;const P=o.get(A);if(!P||!P.isMeshStandardMaterial){console.warn(`[useMaterialTexture] Material "${A}" not found or not MeshStandardMaterial`);return}const T=P;console.log(`[useMaterialTexture] 📋 Material "${A}" BEFORE reset:`),console.log(` - map: ${T.map?"EXISTS":"null"} ${T.map?`(uuid: ${T.map.uuid})`:""}`),console.log(` - normalMap: ${T.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${T.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${T.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${T.emissiveMap?"EXISTS":"null"}`),console.log(` - aoMap: ${T.aoMap?"EXISTS":"null"}`),console.log(` - color: ${(E=T.color)==null?void 0:E.getHexString()}`),console.log(` - emissive: ${(L=T.emissive)==null?void 0:L.getHexString()}`),console.log(` - material uuid: ${T.uuid}`),Object.entries(p).forEach(([w,j])=>{if(!j)return;const C=w,k=T[C];k&&(console.log(`[useMaterialTexture] 🗑️ Disposing old ${C} (uuid: ${k.uuid})`),k.dispose(),T[C]=null)}),p.emissiveMap&&(T.emissive=new R.Color(0),T.emissiveIntensity=0),T.needsUpdate=!0,T.color=new R.Color(16777215),console.log(`[useMaterialTexture] ✅ Material "${A}" AFTER reset: only specified maps cleared`),Object.entries(p).forEach(([w,j])=>{if(!j)return;const C=`${A}_${w}_${j}`,k=y.current.get(C);if(k){console.log(`[useMaterialTexture] Using cached texture: ${A}.${w}`),c||n(T,w,k);return}if(S.current.has(C)){console.log(`[useMaterialTexture] Skipping already loading: ${A}.${w}`);return}M.push({materialName:A,textureType:w,url:j,material:T})})}),console.log(`[useMaterialTexture] Queued ${M.length} textures to load`);let b=0;const v=()=>{if(c||b>=M.length){console.log("[useMaterialTexture] ✅ All textures loaded"),console.log("[useMaterialTexture] 📊 FINAL material states:"),o.forEach((E,L)=>{var j,C;const w=E;console.log(` Material "${L}":`),console.log(` - map: ${w.map?"EXISTS":"null"} ${w.map?`(colorSpace: ${w.map.colorSpace})`:""}`),console.log(` - normalMap: ${w.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${w.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${w.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${w.emissiveMap?"EXISTS":"null"}`),console.log(` - color: ${(j=w.color)==null?void 0:j.getHexString()}`),console.log(` - emissive: ${(C=w.emissive)==null?void 0:C.getHexString()}`),console.log(` - emissiveIntensity: ${w.emissiveIntensity}`),console.log(` - roughness: ${w.roughness}`),console.log(` - metalness: ${w.metalness}`)});return}const p=M[b++],A=`${p.materialName}_${p.textureType}_${p.url}`;console.log(`[useMaterialTexture] Loading (${b}/${M.length}): ${p.materialName}.${p.textureType} from ${p.url}`),S.current.add(A);const P=a(p.url),T=H(p.url)?"KTX2Loader":"TextureLoader";console.log(`[useMaterialTexture] Using ${T} for ${p.url}`),P.load(p.url,E=>{var C,k,X,D,I,W;if(S.current.delete(A),c){console.log(`[useMaterialTexture] Disposed, cleaning up texture: ${p.materialName}.${p.textureType}`),E.dispose();return}const L=((C=E.image)==null?void 0:C.width)||((X=(k=E.source)==null?void 0:k.data)==null?void 0:X.width)||"unknown",w=((D=E.image)==null?void 0:D.height)||((W=(I=E.source)==null?void 0:I.data)==null?void 0:W.height)||"unknown";console.log(`[useMaterialTexture] ✅ Loaded: ${p.materialName}.${p.textureType} (${L}x${w})`),E.colorSpace=p.textureType==="map"||p.textureType==="emissiveMap"?R.SRGBColorSpace:R.NoColorSpace,E.wrapS=R.RepeatWrapping,E.wrapT=R.RepeatWrapping,E.flipY=!1,y.current.set(A,E),n(p.material,p.textureType,E);const j=H(p.url)?500:150;console.log(`[useMaterialTexture] Waiting111111 ${j}ms before next texture...`),setTimeout(v,0)},E=>{if(E.lengthComputable){const L=Math.round(E.loaded/E.total*100);L%25===0&&console.log(`[useMaterialTexture] Progress ${p.materialName}.${p.textureType}: ${L}%`)}},E=>{S.current.delete(A),c||(console.error(`[useMaterialTexture] ❌ Failed to load ${p.materialName}.${p.textureType} from ${p.url}`),console.error("[useMaterialTexture] Error details:",E),console.error("[useMaterialTexture] Loader type:",T),H(p.url)&&(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(v,100)})};return v(),()=>{console.log("[useMaterialTexture] Cleanup: disposed"),c=!0}},[r,s,a]);const n=(o,i,c)=>{var $,M;switch(console.log(`[useMaterialTexture] 🎨 Applying texture: ${o.name}.${i} (texture uuid: ${c.uuid})`),i){case"map":o.map=c;break;case"normalMap":o.normalMap=c;break;case"roughnessMap":o.roughnessMap=c;break;case"metalnessMap":o.metalnessMap=c;break;case"emissiveMap":o.emissiveMap=c,o.emissive=new R.Color(16777215),o.emissiveIntensity=1;break;case"alphaMap":console.log(`[useMaterialTexture] Skipping alphaMap for "${o.name}" to prevent disappearing`);break;case"aoMap":o.aoMap=c;break}o.needsUpdate=!0,console.log(`[useMaterialTexture] ✅ Applied ${i} to ${o.name}, needsUpdate=true`),console.log(`[useMaterialTexture] 📊 Material "${o.name}" FINAL state:`),console.log(` - map: ${o.map?"EXISTS":"null"} ${o.map?`(uuid: ${o.map.uuid}, colorSpace: ${o.map.colorSpace})`:""}`),console.log(` - normalMap: ${o.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${o.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${o.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${o.emissiveMap?"EXISTS":"null"}`),console.log(` - aoMap: ${o.aoMap?"EXISTS":"null"}`),console.log(` - color: ${($=o.color)==null?void 0:$.getHexString()}`),console.log(` - emissive: ${(M=o.emissive)==null?void 0:M.getHexString()}`),console.log(` - emissiveIntensity: ${o.emissiveIntensity}`),console.log(` - roughness: ${o.roughness}`),console.log(` - metalness: ${o.metalness}`)},f=t.useCallback((o,i)=>{const c=typeof i=="string"?{map:i}:i,$=l.current.get(o);if(!$||!$.isMeshStandardMaterial){console.warn(`Material "${o}" not found or not MeshStandardMaterial`);return}const M=$;Object.entries(c).forEach(([b,v])=>{if(!v)return;const p=`${o}_${b}_${v}`,A=y.current.get(p);if(A){n(M,b,A);return}a(v).load(v,T=>{T.colorSpace=b==="map"||b==="emissiveMap"?R.SRGBColorSpace:R.NoColorSpace,T.wrapS=R.RepeatWrapping,T.wrapT=R.RepeatWrapping,y.current.set(p,T),n(M,b,T)},void 0,T=>{console.error(`Failed to load texture ${v}:`,T)})})},[a]),m=t.useCallback(()=>Array.from(l.current.keys()).sort(),[]),x=t.useCallback(o=>{const i=l.current.get(o);if(!i||!i.isMeshStandardMaterial)return;const c=i;c.map=null,c.normalMap=null,c.roughnessMap=null,c.metalnessMap=null,c.emissiveMap=null,c.alphaMap=null,c.aoMap=null,c.needsUpdate=!0},[]);return{setMaterialTextures:f,getMaterialNames:m,clearMaterialTextures:x}}function re({url:r,position:s=[0,0,0],rotation:e=[0,0,0],scale:l=1,meshVisibility:u,materialColors:d,materialTextures:y,onLoad:S,onError:g}){const{scene:a}=O.useGLTF(r),n=t.useRef(S);n.current=S;const f=t.useMemo(()=>{const x=a.clone();console.log("[Model] 🔍 Scene clone created, checking materials...");const o=[],i=new Set,c=[];let $=0;return x.traverse(M=>{if($++,M.type==="Bone"&&c.push(M.name),M.isMesh){const b=M;o.push(b.name),b.castShadow=!0,b.receiveShadow=!0,(Array.isArray(b.material)?b.material:[b.material]).forEach(p=>{i.add(p.name),console.log(`[Model] 📦 Material found: "${p.name}" (uuid: ${p.uuid})`);const A=p;console.log(` - Has map: ${A.map?"YES":"NO"}`),console.log(` - Has normalMap: ${A.normalMap?"YES":"NO"}`),console.log(` - Has roughnessMap: ${A.roughnessMap?"YES":"NO"}`),console.log(` - Has metalnessMap: ${A.metalnessMap?"YES":"NO"}`)})}}),console.log(`[Model] 📊 Clone summary: ${o.length} meshes, ${i.size} materials`),setTimeout(()=>{var M;(M=n.current)==null||M.call(n,{meshes:o.sort(),materials:Array.from(i).sort(),bones:c.sort(),nodeCount:$})},0),x},[a]);K(f,u),G(f,d),z(f,y);const m=typeof l=="number"?[l,l,l]:l;return h.jsx("group",{position:s,rotation:e,scale:m,children:h.jsx("primitive",{object:f})})}re.preload=r=>{O.useGLTF.preload(r)};function se(r,s,e){const{actions:l,names:u}=O.useAnimations(r,s),d=t.useRef(null),y=t.useRef(e==null?void 0:e.defaultAnimation);t.useEffect(()=>{y.current=e==null?void 0:e.defaultAnimation},[e==null?void 0:e.defaultAnimation]),t.useEffect(()=>{if(u.length===0)return;const n=y.current;let f=u[0];if(n){const x=u.find(o=>o===n||o.includes(n));x&&(f=x)}const m=l[f];m&&(m.reset().fadeIn(.5).play(),d.current=m)},[l,u]);const S=t.useCallback((n,f)=>{const{loop:m=!1,crossFadeDuration:x=.2,restoreDefault:o=!0}=f||{};let i=l[n];if(!i){const $=Object.keys(l).find(M=>M.toLowerCase().includes(n.toLowerCase())||n.toLowerCase().includes(M.toLowerCase()));$&&(i=l[$])}if(!i){console.warn(`Animation "${n}" not found. Available: ${u.join(", ")}`);return}const c=d.current;if(!(c===i&&i.isRunning())&&(c&&c!==i&&c.fadeOut(x),i.reset(),i.fadeIn(x),i.setLoop(m?R.LoopRepeat:R.LoopOnce,m?1/0:1),i.clampWhenFinished=!m,i.play(),m||i.getMixer().update(0),d.current=i,o&&!m&&y.current)){const $=i.getMixer(),M=b=>{if(b.action===i){$.removeEventListener("finished",M);const v=l[y.current];v&&(i.fadeOut(x),v.reset().fadeIn(x).play(),d.current=v)}};$.addEventListener("finished",M)}},[l,u]),g=t.useCallback(()=>{var n;(n=d.current)==null||n.fadeOut(.2),d.current=null},[]),a=t.useCallback(()=>u,[u]);return{playAnimation:S,stopAnimation:g,getAnimationNames:a,actions:l}}function q(r,s){const e=t.useRef(s||{}),l=t.useRef([]),u=t.useRef([]);t.useEffect(()=>{const g=new Set,a=[];r.traverse(n=>{n instanceof R.Mesh&&n.morphTargetDictionary&&n.morphTargetInfluences&&(a.push(n),Object.keys(n.morphTargetDictionary).forEach(f=>{g.add(f)}))}),l.current=Array.from(g).sort(),u.current=a},[r]),B.useFrame(()=>{const g=e.current;u.current.forEach(a=>{!a.morphTargetDictionary||!a.morphTargetInfluences||Object.entries(g).forEach(([n,f])=>{const m=a.morphTargetDictionary[n];m!==void 0&&(a.morphTargetInfluences[m]=f)})})}),t.useEffect(()=>{s&&(e.current={...s})},[s]);const d=t.useCallback((g,a)=>{e.current[g]=Math.max(0,Math.min(1,a))},[]),y=t.useCallback(()=>l.current,[]),S=t.useCallback(()=>({...e.current}),[]);return{setMorphTarget:d,getMorphTargetNames:y,getMorphTargetValues:S}}const oe=t.createContext(null);function he(){const r=t.useContext(oe);if(!r)throw new Error("BoneAttachment must be used within an AnimatedModel");return r}const V=t.forwardRef(({url:r,position:s=[0,0,0],rotation:e=[0,0,0],scale:l=1,defaultAnimation:u,animation:d,morphTargets:y,meshVisibility:S,materialColors:g,materialTextures:a,onLoad:n,onError:f,children:m},x)=>{const o=t.useRef(null),i=t.useRef([]),c=t.useRef(n);c.current=n;const{scene:$,animations:M}=O.useGLTF(r),b=t.useMemo(()=>te.clone($),[$]),{playAnimation:v,stopAnimation:p,getAnimationNames:A}=se(M,b,{defaultAnimation:u});t.useEffect(()=>{d&&v(d,{loop:!0,restoreDefault:!1})},[d,v]);const{setMorphTarget:P}=q(b,y),{setMeshVisibility:T,getMeshNames:E}=K(b,S),{setMaterialColor:L,getMaterialNames:w,getMaterialColor:j}=G(b,g),{setMaterialTextures:C,clearMaterialTextures:k}=z(b,a);t.useEffect(()=>{if(!b)return;const I=setTimeout(()=>{var Q;const W=[],_=[],Y=new Set,Z=new Set;let J=0;b.traverse(F=>{if(J++,F.type==="Bone"&&W.push(F.name),F.isMesh){const N=F;_.push(N.name),N.castShadow=!0,N.receiveShadow=!0,(Array.isArray(N.material)?N.material:[N.material]).forEach(U=>{Y.add(U.name),U.shadowSide=R.DoubleSide}),N.morphTargetDictionary&&Object.keys(N.morphTargetDictionary).forEach(U=>{Z.add(U)})}}),i.current=Array.from(Z).sort(),(Q=c.current)==null||Q.call(c,{meshes:_.sort(),materials:Array.from(Y).sort(),bones:W.sort(),nodeCount:J,animations:M.map(F=>F.name),morphTargetNames:i.current})},0);return()=>clearTimeout(I)},[b,M]),t.useImperativeHandle(x,()=>({playAnimation:v,stopAnimation:p,getAnimationNames:A,getGroup:()=>o.current,setMorphTarget:P,getMorphTargetNames:()=>i.current,setMeshVisibility:T,getMeshNames:E,setMaterialColor:L,getMaterialNames:w,getMaterialColor:j,setMaterialTextures:C,clearMaterialTextures:k}));const X=t.useMemo(()=>({scene:b,getBone:I=>b.getObjectByName(I)||null}),[b]),D=typeof l=="number"?[l,l,l]:l;return h.jsx(oe.Provider,{value:X,children:h.jsxs("group",{ref:o,position:s,rotation:e,scale:D,children:[h.jsx("primitive",{object:b}),m]})})});V.displayName="AnimatedModel";V.preload=r=>{O.useGLTF.preload(r)};const ne=t.forwardRef(({url:r,position:s=[0,0,0],rotation:e=[0,0,0],scale:l=1,morphTargets:u,meshVisibility:d,materialColors:y,materialTextures:S,onMorphTargetsFound:g,onLoad:a,onError:n},f)=>{const{scene:m}=O.useGLTF(r),x=t.useRef(a);x.current=a;const o=t.useRef(g);o.current=g;const i=t.useMemo(()=>m.clone(),[m]),{setMorphTarget:c,getMorphTargetNames:$,getMorphTargetValues:M}=q(i,u),{setMeshVisibility:b,getMeshNames:v}=K(i,d),{setMaterialColor:p,getMaterialNames:A,getMaterialColor:P}=G(i,y),{setMaterialTextures:T,clearMaterialTextures:E}=z(i,S);t.useEffect(()=>{var j;const w=$();w.length>0&&((j=o.current)==null||j.call(o,w))},[i,$]),t.useEffect(()=>{var X;if(!i)return;const w=[],j=new Set,C=[];let k=0;i.traverse(D=>{if(k++,D.type==="Bone"&&C.push(D.name),D.isMesh){const I=D;w.push(I.name),I.castShadow=!0,I.receiveShadow=!0,(Array.isArray(I.material)?I.material:[I.material]).forEach(_=>j.add(_.name))}}),(X=x.current)==null||X.call(x,{meshes:w.sort(),materials:Array.from(j).sort(),bones:C.sort(),nodeCount:k})},[i]),t.useImperativeHandle(f,()=>({setMorphTarget:c,getMorphTargetNames:$,getMorphTargetValues:M,setMeshVisibility:b,getMeshNames:v,setMaterialColor:p,getMaterialNames:A,getMaterialColor:P,setMaterialTextures:T,clearMaterialTextures:E}));const L=typeof l=="number"?[l,l,l]:l;return h.jsx("group",{position:s,rotation:e,scale:L,children:h.jsx("primitive",{object:i})})});ne.displayName="MorphableModel";function Me({children:r,bone:s,position:e=[0,0,0],rotation:l=[0,0,0],scale:u=1}){const{getBone:d}=he(),[y,S]=t.useState(null);if(t.useEffect(()=>{const a=d(s);a?S(a):console.warn(`Bone "${s}" not found in model`)},[s,d]),!y)return null;const g=typeof u=="number"?[u,u,u]:u;return B.createPortal(h.jsx("group",{position:e,rotation:l,scale:g,children:r}),y)}function be(r,s){const{scene:e,animations:l}=O.useGLTF(r),u=t.useMemo(()=>te.clone(e),[e]);return t.useEffect(()=>{var a;if(!u)return;const d=[],y=[],S=new Set;let g=0;u.traverse(n=>{if(g++,n.type==="Bone"&&d.push(n.name),n.isMesh){const f=n;y.push(f.name),f.castShadow=!0,f.receiveShadow=!0,(Array.isArray(f.material)?f.material:[f.material]).forEach(x=>{S.add(x.name),x.shadowSide=R.DoubleSide})}}),(a=s==null?void 0:s.onLoad)==null||a.call(s,{meshes:y.sort(),materials:Array.from(S).sort(),bones:d.sort(),nodeCount:g})},[u,s]),{scene:u,animations:l}}function ye(r){O.useGLTF.preload(r)}exports.AnimatedModel=V;exports.BoneAttachment=Me;exports.Model=re;exports.MorphableModel=ne;exports.Scene3D=ge;exports.preloadModel=ye;exports.useAnimationController=se;exports.useClonedModel=be;exports.useMaterialColor=G;exports.useMaterialTexture=z;exports.useMeshVisibility=K;exports.useMorphTargets=q;
|
|
2
2
|
//# sourceMappingURL=mbt-3d.cjs.map
|