mbt-3d 0.3.6 → 0.3.7
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 +22 -1
- package/dist/mbt-3d.cjs +1 -1
- package/dist/mbt-3d.cjs.map +1 -1
- package/dist/mbt-3d.js +543 -516
- package/dist/mbt-3d.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -279,6 +279,25 @@ declare interface DirectionalLightConfig extends BaseLightConfig {
|
|
|
279
279
|
castShadow?: boolean;
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Environment (HDRI) configuration for realistic lighting and reflections
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```tsx
|
|
287
|
+
* { files: '/scenes/studio.hdr', intensity: 1, background: false }
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
declare interface EnvironmentConfig {
|
|
291
|
+
/** URL to HDRI file (.hdr or .exr) */
|
|
292
|
+
files: string;
|
|
293
|
+
/** Environment intensity multiplier. Default: 1 */
|
|
294
|
+
intensity?: number;
|
|
295
|
+
/** Use HDRI as scene background. Default: false */
|
|
296
|
+
background?: boolean;
|
|
297
|
+
/** Blur amount for background (0-1). Default: 0 */
|
|
298
|
+
blur?: number;
|
|
299
|
+
}
|
|
300
|
+
|
|
282
301
|
/**
|
|
283
302
|
* Hemisphere light configuration - soft sky/ground lighting (no shadows)
|
|
284
303
|
*
|
|
@@ -647,7 +666,7 @@ export declare function preloadModel(url: string): void;
|
|
|
647
666
|
* </Scene3D>
|
|
648
667
|
* ```
|
|
649
668
|
*/
|
|
650
|
-
export declare function Scene3D({ children, camera, controls, background, shadows, lights, contactShadows, style, className, }: Scene3DProps): JSX_2.Element;
|
|
669
|
+
export declare function Scene3D({ children, camera, controls, background, shadows, lights, environment, contactShadows, style, className, }: Scene3DProps): JSX_2.Element;
|
|
651
670
|
|
|
652
671
|
/**
|
|
653
672
|
* Props for Scene3D component
|
|
@@ -707,6 +726,8 @@ export declare interface Scene3DProps {
|
|
|
707
726
|
shadows?: boolean;
|
|
708
727
|
/** Array of light configurations for multi-light setup */
|
|
709
728
|
lights?: LightConfigUnion[];
|
|
729
|
+
/** Environment (HDRI) configuration for realistic lighting and reflections */
|
|
730
|
+
environment?: EnvironmentConfig;
|
|
710
731
|
/** Contact shadows configuration (ground shadows under models) */
|
|
711
732
|
contactShadows?: boolean | {
|
|
712
733
|
/** Shadow position [x, y, z]. Default: [0, -1, 0] */
|
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 r=require("react"),O=require("@react-three/drei"),ne=require("three"),ae=require("three/examples/jsm/utils/SkeletonUtils.js"),B=require("@react-three/fiber"),le=require("three/examples/jsm/loaders/KTX2Loader.js"),S=require("react/jsx-runtime");function Q(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const a=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,a.get?a:{enumerable:!0,get:()=>e[o]})}}return t.default=e,Object.freeze(t)}const R=Q(ne),ee=Q(ae);function ie({position:e,controlsConfig:t}){const{camera:o}=B.useThree(),a=r.useRef(null);return r.useEffect(()=>{e&&o&&(o.position.set(e[0],e[1],e[2]),o.updateProjectionMatrix(),a.current&&(a.current.target.set(0,0,0),a.current.update()))},[e,o]),S.jsx(O.OrbitControls,{ref:a,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 ce({background:e}){const t=e==null?void 0:e.startsWith("#");return e?t?S.jsx("color",{attach:"background",args:[e]}):S.jsx(ue,{url:e}):null}function ue({url:e}){const t=O.useTexture(e);return r.useMemo(()=>{t.colorSpace=R.SRGBColorSpace},[t]),S.jsx("primitive",{attach:"background",object:t})}function me({config:e}){return S.jsx(O.Environment,{files:e.files,background:e.background??!1,blur:e.blur??0,children:S.jsx("group",{scale:e.intensity??1,children:S.jsx("ambientLight",{intensity:0})})})}function pe({config:e}){switch(e.type){case"spot":{const{position:t=[5,10,5],intensity:o=50,castShadow:a=!0,angle:c=Math.PI/6,penumbra:M=.5,decay:b=2,distance:T=0,color:g="#ffffff"}=e;return S.jsx("spotLight",{position:t,intensity:o,castShadow:a,angle:c,penumbra:M,decay:b,distance:T,color:g})}case"point":{const{position:t=[0,5,0],intensity:o=20,color:a="#ffffff",distance:c=0,decay:M=2,castShadow:b=!1}=e;return S.jsx("pointLight",{position:t,intensity:o,color:a,distance:c,decay:M,castShadow:b})}case"directional":{const{position:t=[10,20,10],intensity:o=40,color:a="#ffffff",castShadow:c=!0}=e;return S.jsx("directionalLight",{position:t,intensity:o,color:a,castShadow:c})}case"hemisphere":{const{skyColor:t="#ffffff",groundColor:o="#444444",intensity:a=.5,position:c=[0,10,0]}=e,M=r.useMemo(()=>new R.Color(t),[t]),b=r.useMemo(()=>new R.Color(o),[o]);return S.jsx("hemisphereLight",{args:[M,b,a],position:c})}case"ambient":{const{intensity:t=.5,color:o="#ffffff"}=e;return S.jsx("ambientLight",{intensity:t,color:o})}default:return null}}function fe({children:e,camera:t={},controls:o={},background:a,shadows:c=!0,lights:M=[{type:"ambient",intensity:.5},{type:"spot",position:[5,10,5],intensity:50,castShadow:!0}],environment:b,contactShadows:T=!0,style:g,className:l}){const s={position:t.position||[0,2,5],fov:t.fov||45},u={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},m=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 S.jsx("div",{style:g,className:l,children:S.jsxs(B.Canvas,{shadows:c,camera:{position:s.position,fov:s.fov},style:{width:"100%",height:"100%"},children:[S.jsx(r.Suspense,{fallback:null,children:S.jsx(ce,{background:a})}),b&&S.jsx(r.Suspense,{fallback:null,children:S.jsx(me,{config:b})}),M.map((h,n)=>S.jsx(pe,{config:h},`${h.type}-${n}`)),S.jsx(r.Suspense,{fallback:null,children:e}),S.jsx(ie,{position:s.position,controlsConfig:u}),m&&S.jsx(O.ContactShadows,{position:m.position,opacity:m.opacity,blur:m.blur})]})})}function K(e,t){const o=r.useRef(new Map),a=r.useRef({}),c=r.useRef({});r.useEffect(()=>{t&&(a.current={...t})},[t]),r.useEffect(()=>{if(!e)return;const g=new Map;e.traverse(l=>{if(l.isMesh){const s=l;s.name&&g.set(s.name,s)}}),o.current=g},[e]),B.useFrame(()=>{const g=o.current;if(g.size===0)return;const l={...a.current,...c.current};for(const[s,u]of Object.entries(l)){const m=g.get(s);m&&m.visible!==u&&(m.visible=u)}});const M=r.useCallback((g,l)=>{c.current[g]=l;const s=o.current.get(g);s&&(s.visible=l)},[]),b=r.useCallback(()=>Array.from(o.current.keys()).sort(),[]),T=r.useCallback(()=>{const g={};return o.current.forEach((l,s)=>{g[s]=l.visible}),g},[]);return{setMeshVisibility:M,getMeshNames:b,getMeshVisibility:T}}function G(e,t){const o=r.useRef(new Map),a=r.useRef(new Map);r.useEffect(()=>{if(!e)return;const l=new Map;e.traverse(s=>{if(s.isMesh){const u=s;(Array.isArray(u.material)?u.material:[u.material]).forEach(h=>{h.name&&!l.has(h.name)&&l.set(h.name,h)})}}),o.current=l,t&&Object.entries(t).forEach(([s,u])=>{const m=l.get(s);if(m&&!Array.isArray(m)){const h=c(u);m.color&&m.color.copy(h),a.current.set(s,h)}})},[e,t]),B.useFrame(()=>{a.current.forEach((l,s)=>{const u=o.current.get(s);if(u&&!Array.isArray(u)){const m=u;m.color&&!m.color.equals(l)&&(m.color.copy(l),m.needsUpdate=!0)}})});const c=l=>typeof l=="string"?new R.Color(l):new R.Color(l[0],l[1],l[2]),M=r.useCallback((l,s)=>{const u=c(s);a.current.set(l,u);const m=o.current.get(l);if(m&&!Array.isArray(m)){const h=m;h.color&&(h.color.copy(u),h.needsUpdate=!0)}},[]),b=r.useCallback(()=>Array.from(o.current.keys()).sort(),[]),T=r.useCallback(l=>{const s=o.current.get(l);if(s&&!Array.isArray(s)){const u=s;if(u.color)return"#"+u.color.getHexString()}return null},[]),g=r.useCallback(()=>{const l={};return o.current.forEach((s,u)=>{if(!Array.isArray(s)){const m=s;m.color&&(l[u]="#"+m.color.getHexString())}}),l},[]);return{setMaterialColor:M,getMaterialNames:b,getMaterialColor:T,getAllMaterialColors:g}}function H(e){const t=e.toLowerCase();if(t.endsWith(".ktx2"))return!0;try{const o=new URL(e,window.location.origin),a=decodeURIComponent(o.hash.replace(/^#/,"")).toLowerCase(),c=decodeURIComponent(o.search).toLowerCase(),M=decodeURIComponent(o.pathname).toLowerCase();return a.endsWith(".ktx2")||c.includes(".ktx2")||M.endsWith(".ktx2")}catch{return t.includes(".ktx2")}}function z(e,t){const{gl:o}=B.useThree(),a=r.useRef(new Map),c=r.useRef(new R.TextureLoader),M=r.useRef(null),b=r.useRef(new Map),T=r.useRef(new Set),g=r.useRef("");r.useEffect(()=>{if(!M.current)try{const n=typeof WebAssembly=="object"&&typeof WebAssembly.validate=="function";console.log("[useMaterialTexture] Browser features:"),console.log(` WebAssembly supported: ${n}`),console.log(` WebGL2: ${o.capabilities.isWebGL2}`);const i=new le.KTX2Loader;i.setTranscoderPath("/basis/"),i.detectSupport(o),M.current=i,console.log("[useMaterialTexture] ✅ KTX2Loader initialized"),console.log("[useMaterialTexture] Transcoder path: /basis/"),fetch("/basis/basis_transcoder.wasm").then(p=>{p.ok?console.log("[useMaterialTexture] ✅ basis_transcoder.wasm is accessible"):console.error("[useMaterialTexture] ❌ basis_transcoder.wasm returned",p.status)}).catch(p=>{console.error("[useMaterialTexture] ❌ Failed to check basis_transcoder.wasm:",p)}),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()=>{M.current&&(M.current.dispose(),M.current=null)}},[o]),r.useEffect(()=>{if(!e)return;const n=new Map;e.traverse(i=>{if(i.isMesh){const p=i;(Array.isArray(p.material)?p.material:[p.material]).forEach(f=>{f.name&&!n.has(f.name)&&n.set(f.name,f)})}}),a.current=n},[e]);const l=r.useCallback(n=>H(n)?M.current?M.current:(console.warn("[useMaterialTexture] KTX2Loader not initialized, falling back to TextureLoader"),c.current):c.current,[]);r.useEffect(()=>{if(!t||!e)return;const n=a.current;if(n.size===0)return;const i=JSON.stringify(t);if(g.current===i){console.log("[useMaterialTexture] Textures unchanged, skipping reload");return}g.current=i;let p=!1;const w=new Map;Object.entries(t).forEach(([d,$])=>{w.set(d,typeof $=="string"?{map:$}:$)}),console.log("[useMaterialTexture] Starting texture load for",w.size,"materials");const f=[];w.forEach((d,$)=>{var A,L;const D=n.get($);if(!D||!D.isMeshStandardMaterial){console.warn(`[useMaterialTexture] Material "${$}" not found or not MeshStandardMaterial`);return}const y=D;console.log(`[useMaterialTexture] 📋 Material "${$}" BEFORE reset:`),console.log(` - map: ${y.map?"EXISTS":"null"} ${y.map?`(uuid: ${y.map.uuid})`:""}`),console.log(` - normalMap: ${y.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${y.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${y.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${y.emissiveMap?"EXISTS":"null"}`),console.log(` - aoMap: ${y.aoMap?"EXISTS":"null"}`),console.log(` - color: ${(A=y.color)==null?void 0:A.getHexString()}`),console.log(` - emissive: ${(L=y.emissive)==null?void 0:L.getHexString()}`),console.log(` - material uuid: ${y.uuid}`),Object.entries(d).forEach(([x,C])=>{if(!C)return;const j=x,k=y[j];k&&(console.log(`[useMaterialTexture] 🗑️ Disposing old ${j} (uuid: ${k.uuid})`),k.dispose(),y[j]=null)}),d.emissiveMap&&(y.emissive=new R.Color(0),y.emissiveIntensity=0),y.needsUpdate=!0,y.color=new R.Color(16777215),console.log(`[useMaterialTexture] ✅ Material "${$}" AFTER reset: only specified maps cleared`),Object.entries(d).forEach(([x,C])=>{if(!C)return;const j=`${$}_${x}_${C}`,k=b.current.get(j);if(k){console.log(`[useMaterialTexture] Using cached texture: ${$}.${x}`),p||s(y,x,k);return}if(T.current.has(j)){console.log(`[useMaterialTexture] Skipping already loading: ${$}.${x}`);return}f.push({materialName:$,textureType:x,url:C,material:y})})}),console.log(`[useMaterialTexture] Queued ${f.length} textures to load`);let E=0;const v=()=>{if(p||E>=f.length){console.log("[useMaterialTexture] ✅ All textures loaded"),console.log("[useMaterialTexture] 📊 FINAL material states:"),n.forEach((A,L)=>{var C,j;const x=A;console.log(` Material "${L}":`),console.log(` - map: ${x.map?"EXISTS":"null"} ${x.map?`(colorSpace: ${x.map.colorSpace})`:""}`),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(` - color: ${(C=x.color)==null?void 0:C.getHexString()}`),console.log(` - emissive: ${(j=x.emissive)==null?void 0:j.getHexString()}`),console.log(` - emissiveIntensity: ${x.emissiveIntensity}`),console.log(` - roughness: ${x.roughness}`),console.log(` - metalness: ${x.metalness}`)});return}const d=f[E++],$=`${d.materialName}_${d.textureType}_${d.url}`;console.log(`[useMaterialTexture] Loading (${E}/${f.length}): ${d.materialName}.${d.textureType} from ${d.url}`),T.current.add($);const D=l(d.url),y=H(d.url)?"KTX2Loader":"TextureLoader";console.log(`[useMaterialTexture] Using ${y} for ${d.url}`),D.load(d.url,A=>{var j,k,P,X,I,F;if(T.current.delete($),p){console.log(`[useMaterialTexture] Disposed, cleaning up texture: ${d.materialName}.${d.textureType}`),A.dispose();return}const L=((j=A.image)==null?void 0:j.width)||((P=(k=A.source)==null?void 0:k.data)==null?void 0:P.width)||"unknown",x=((X=A.image)==null?void 0:X.height)||((F=(I=A.source)==null?void 0:I.data)==null?void 0:F.height)||"unknown";console.log(`[useMaterialTexture] ✅ Loaded: ${d.materialName}.${d.textureType} (${L}x${x})`),A.colorSpace=d.textureType==="map"||d.textureType==="emissiveMap"?R.SRGBColorSpace:R.NoColorSpace,A.wrapS=R.RepeatWrapping,A.wrapT=R.RepeatWrapping,A.flipY=!1,b.current.set($,A),s(d.material,d.textureType,A);const C=H(d.url)?500:150;console.log(`[useMaterialTexture] Waiting111111 ${C}ms before next texture...`),setTimeout(v,0)},A=>{if(A.lengthComputable){const L=Math.round(A.loaded/A.total*100);L%25===0&&console.log(`[useMaterialTexture] Progress ${d.materialName}.${d.textureType}: ${L}%`)}},A=>{T.current.delete($),p||(console.error(`[useMaterialTexture] ❌ Failed to load ${d.materialName}.${d.textureType} from ${d.url}`),console.error("[useMaterialTexture] Error details:",A),console.error("[useMaterialTexture] Loader type:",y),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(v,100)})};return v(),()=>{console.log("[useMaterialTexture] Cleanup: disposed"),p=!0}},[e,t,l]);const s=(n,i,p)=>{var w,f;switch(console.log(`[useMaterialTexture] 🎨 Applying texture: ${n.name}.${i} (texture uuid: ${p.uuid})`),i){case"map":n.map=p;break;case"normalMap":n.normalMap=p;break;case"roughnessMap":n.roughnessMap=p;break;case"metalnessMap":n.metalnessMap=p;break;case"emissiveMap":n.emissiveMap=p,n.emissive=new R.Color(16777215),n.emissiveIntensity=1;break;case"alphaMap":console.log(`[useMaterialTexture] Skipping alphaMap for "${n.name}" to prevent disappearing`);break;case"aoMap":n.aoMap=p;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: ${(w=n.color)==null?void 0:w.getHexString()}`),console.log(` - emissive: ${(f=n.emissive)==null?void 0:f.getHexString()}`),console.log(` - emissiveIntensity: ${n.emissiveIntensity}`),console.log(` - roughness: ${n.roughness}`),console.log(` - metalness: ${n.metalness}`)},u=r.useCallback((n,i)=>{const p=typeof i=="string"?{map:i}:i,w=a.current.get(n);if(!w||!w.isMeshStandardMaterial){console.warn(`Material "${n}" not found or not MeshStandardMaterial`);return}const f=w;Object.entries(p).forEach(([E,v])=>{if(!v)return;const d=`${n}_${E}_${v}`,$=b.current.get(d);if($){s(f,E,$);return}l(v).load(v,y=>{y.colorSpace=E==="map"||E==="emissiveMap"?R.SRGBColorSpace:R.NoColorSpace,y.wrapS=R.RepeatWrapping,y.wrapT=R.RepeatWrapping,b.current.set(d,y),s(f,E,y)},void 0,y=>{console.error(`Failed to load texture ${v}:`,y)})})},[l]),m=r.useCallback(()=>Array.from(a.current.keys()).sort(),[]),h=r.useCallback(n=>{const i=a.current.get(n);if(!i||!i.isMeshStandardMaterial)return;const p=i;p.map=null,p.normalMap=null,p.roughnessMap=null,p.metalnessMap=null,p.emissiveMap=null,p.alphaMap=null,p.aoMap=null,p.needsUpdate=!0},[]);return{setMaterialTextures:u,getMaterialNames:m,clearMaterialTextures:h}}function te({url:e,position:t=[0,0,0],rotation:o=[0,0,0],scale:a=1,meshVisibility:c,materialColors:M,materialTextures:b,onLoad:T,onError:g}){const{scene:l}=O.useGLTF(e),s=r.useRef(T);s.current=T;const u=r.useMemo(()=>{const h=l.clone();console.log("[Model] 🔍 Scene clone created, checking materials...");const n=[],i=new Set,p=[];let w=0;return h.traverse(f=>{if(w++,f.type==="Bone"&&p.push(f.name),f.isMesh){const E=f;n.push(E.name),E.castShadow=!0,E.receiveShadow=!0,(Array.isArray(E.material)?E.material:[E.material]).forEach(d=>{i.add(d.name),console.log(`[Model] 📦 Material found: "${d.name}" (uuid: ${d.uuid})`);const $=d;console.log(` - Has map: ${$.map?"YES":"NO"}`),console.log(` - Has normalMap: ${$.normalMap?"YES":"NO"}`),console.log(` - Has roughnessMap: ${$.roughnessMap?"YES":"NO"}`),console.log(` - Has metalnessMap: ${$.metalnessMap?"YES":"NO"}`)})}}),console.log(`[Model] 📊 Clone summary: ${n.length} meshes, ${i.size} materials`),setTimeout(()=>{var f;(f=s.current)==null||f.call(s,{meshes:n.sort(),materials:Array.from(i).sort(),bones:p.sort(),nodeCount:w})},0),h},[l]);K(u,c),G(u,M),z(u,b);const m=typeof a=="number"?[a,a,a]:a;return S.jsx("group",{position:t,rotation:o,scale:m,children:S.jsx("primitive",{object:u})})}te.preload=e=>{O.useGLTF.preload(e)};function re(e,t,o){const{actions:a,names:c}=O.useAnimations(e,t),M=r.useRef(null),b=r.useRef(o==null?void 0:o.defaultAnimation);r.useEffect(()=>{if(c.length===0)return;const s=b.current;let u=c[0];if(s){const h=c.find(n=>n===s||n.includes(s));h&&(u=h)}const m=a[u];m&&(m.reset().fadeIn(.5).play(),M.current=m)},[a,c]);const T=r.useCallback((s,u)=>{const{loop:m=!1,crossFadeDuration:h=.2,restoreDefault:n=!0}=u||{};let i=a[s];if(!i){const w=Object.keys(a).find(f=>f.toLowerCase().includes(s.toLowerCase())||s.toLowerCase().includes(f.toLowerCase()));w&&(i=a[w])}if(!i){console.warn(`Animation "${s}" not found. Available: ${c.join(", ")}`);return}const p=M.current;if(!(p===i&&i.isRunning())&&(p&&p!==i&&p.fadeOut(h),i.reset(),i.fadeIn(h),i.setLoop(m?R.LoopRepeat:R.LoopOnce,m?1/0:1),i.clampWhenFinished=!m,i.play(),m||i.getMixer().update(0),M.current=i,n&&!m&&b.current)){const w=i.getMixer(),f=E=>{if(E.action===i){w.removeEventListener("finished",f);const v=a[b.current];v&&(i.fadeOut(h),v.reset().fadeIn(h).play(),M.current=v)}};w.addEventListener("finished",f)}},[a,c]),g=r.useCallback(()=>{var s;(s=M.current)==null||s.fadeOut(.2),M.current=null},[]),l=r.useCallback(()=>c,[c]);return{playAnimation:T,stopAnimation:g,getAnimationNames:l,actions:a}}function q(e,t){const o=r.useRef(t||{}),a=r.useRef([]),c=r.useRef([]);r.useEffect(()=>{const g=new Set,l=[];e.traverse(s=>{s instanceof R.Mesh&&s.morphTargetDictionary&&s.morphTargetInfluences&&(l.push(s),Object.keys(s.morphTargetDictionary).forEach(u=>{g.add(u)}))}),a.current=Array.from(g).sort(),c.current=l},[e]),B.useFrame(()=>{const g=o.current;c.current.forEach(l=>{!l.morphTargetDictionary||!l.morphTargetInfluences||Object.entries(g).forEach(([s,u])=>{const m=l.morphTargetDictionary[s];m!==void 0&&(l.morphTargetInfluences[m]=u)})})}),r.useEffect(()=>{t&&(o.current={...t})},[t]);const M=r.useCallback((g,l)=>{o.current[g]=Math.max(0,Math.min(1,l))},[]),b=r.useCallback(()=>a.current,[]),T=r.useCallback(()=>({...o.current}),[]);return{setMorphTarget:M,getMorphTargetNames:b,getMorphTargetValues:T}}const oe=r.createContext(null);function de(){const e=r.useContext(oe);if(!e)throw new Error("BoneAttachment must be used within an AnimatedModel");return e}const V=r.forwardRef(({url:e,position:t=[0,0,0],rotation:o=[0,0,0],scale:a=1,defaultAnimation:c,morphTargets:M,meshVisibility:b,materialColors:T,materialTextures:g,onLoad:l,onError:s,children:u},m)=>{const h=r.useRef(null),n=r.useRef([]),i=r.useRef(l);i.current=l;const{scene:p,animations:w}=O.useGLTF(e),f=r.useMemo(()=>ee.clone(p),[p]),{playAnimation:E,stopAnimation:v,getAnimationNames:d}=re(w,f,{defaultAnimation:c}),{setMorphTarget:$}=q(f,M),{setMeshVisibility:D,getMeshNames:y}=K(f,b),{setMaterialColor:A,getMaterialNames:L,getMaterialColor:x}=G(f,T),{setMaterialTextures:C,clearMaterialTextures:j}=z(f,g);r.useEffect(()=>{if(!f)return;const X=setTimeout(()=>{var J;const I=[],F=[],_=new Set,Y=new Set;let Z=0;f.traverse(W=>{if(Z++,W.type==="Bone"&&I.push(W.name),W.isMesh){const N=W;F.push(N.name),N.castShadow=!0,N.receiveShadow=!0,(Array.isArray(N.material)?N.material:[N.material]).forEach(U=>{_.add(U.name),U.shadowSide=R.DoubleSide}),N.morphTargetDictionary&&Object.keys(N.morphTargetDictionary).forEach(U=>{Y.add(U)})}}),n.current=Array.from(Y).sort(),(J=i.current)==null||J.call(i,{meshes:F.sort(),materials:Array.from(_).sort(),bones:I.sort(),nodeCount:Z,animations:w.map(W=>W.name),morphTargetNames:n.current})},0);return()=>clearTimeout(X)},[f,w]),r.useImperativeHandle(m,()=>({playAnimation:E,stopAnimation:v,getAnimationNames:d,getGroup:()=>h.current,setMorphTarget:$,getMorphTargetNames:()=>n.current,setMeshVisibility:D,getMeshNames:y,setMaterialColor:A,getMaterialNames:L,getMaterialColor:x,setMaterialTextures:C,clearMaterialTextures:j}));const k=r.useMemo(()=>({scene:f,getBone:X=>f.getObjectByName(X)||null}),[f]),P=typeof a=="number"?[a,a,a]:a;return S.jsx(oe.Provider,{value:k,children:S.jsxs("group",{ref:h,position:t,rotation:o,scale:P,children:[S.jsx("primitive",{object:f}),u]})})});V.displayName="AnimatedModel";V.preload=e=>{O.useGLTF.preload(e)};const se=r.forwardRef(({url:e,position:t=[0,0,0],rotation:o=[0,0,0],scale:a=1,morphTargets:c,meshVisibility:M,materialColors:b,materialTextures:T,onMorphTargetsFound:g,onLoad:l,onError:s},u)=>{const{scene:m}=O.useGLTF(e),h=r.useRef(l);h.current=l;const n=r.useRef(g);n.current=g;const i=r.useMemo(()=>m.clone(),[m]),{setMorphTarget:p,getMorphTargetNames:w,getMorphTargetValues:f}=q(i,c),{setMeshVisibility:E,getMeshNames:v}=K(i,M),{setMaterialColor:d,getMaterialNames:$,getMaterialColor:D}=G(i,b),{setMaterialTextures:y,clearMaterialTextures:A}=z(i,T);r.useEffect(()=>{var C;const x=w();x.length>0&&((C=n.current)==null||C.call(n,x))},[i,w]),r.useEffect(()=>{var P;if(!i)return;const x=[],C=new Set,j=[];let k=0;i.traverse(X=>{if(k++,X.type==="Bone"&&j.push(X.name),X.isMesh){const I=X;x.push(I.name),I.castShadow=!0,I.receiveShadow=!0,(Array.isArray(I.material)?I.material:[I.material]).forEach(_=>C.add(_.name))}}),(P=h.current)==null||P.call(h,{meshes:x.sort(),materials:Array.from(C).sort(),bones:j.sort(),nodeCount:k})},[i]),r.useImperativeHandle(u,()=>({setMorphTarget:p,getMorphTargetNames:w,getMorphTargetValues:f,setMeshVisibility:E,getMeshNames:v,setMaterialColor:d,getMaterialNames:$,getMaterialColor:D,setMaterialTextures:y,clearMaterialTextures:A}));const L=typeof a=="number"?[a,a,a]:a;return S.jsx("group",{position:t,rotation:o,scale:L,children:S.jsx("primitive",{object:i})})});se.displayName="MorphableModel";function Me({children:e,bone:t,position:o=[0,0,0],rotation:a=[0,0,0],scale:c=1}){const{getBone:M}=de(),[b,T]=r.useState(null);if(r.useEffect(()=>{const l=M(t);l?T(l):console.warn(`Bone "${t}" not found in model`)},[t,M]),!b)return null;const g=typeof c=="number"?[c,c,c]:c;return B.createPortal(S.jsx("group",{position:o,rotation:a,scale:g,children:e}),b)}function ge(e,t){const{scene:o,animations:a}=O.useGLTF(e),c=r.useMemo(()=>ee.clone(o),[o]);return r.useEffect(()=>{var l;if(!c)return;const M=[],b=[],T=new Set;let g=0;c.traverse(s=>{if(g++,s.type==="Bone"&&M.push(s.name),s.isMesh){const u=s;b.push(u.name),u.castShadow=!0,u.receiveShadow=!0,(Array.isArray(u.material)?u.material:[u.material]).forEach(h=>{T.add(h.name),h.shadowSide=R.DoubleSide})}}),(l=t==null?void 0:t.onLoad)==null||l.call(t,{meshes:b.sort(),materials:Array.from(T).sort(),bones:M.sort(),nodeCount:g})},[c,t]),{scene:c,animations:a}}function he(e){O.useGLTF.preload(e)}exports.AnimatedModel=V;exports.BoneAttachment=Me;exports.Model=te;exports.MorphableModel=se;exports.Scene3D=fe;exports.preloadModel=he;exports.useAnimationController=re;exports.useClonedModel=ge;exports.useMaterialColor=G;exports.useMaterialTexture=z;exports.useMeshVisibility=K;exports.useMorphTargets=q;
|
|
2
2
|
//# sourceMappingURL=mbt-3d.cjs.map
|