@vctrl/hooks 0.2.1 → 0.3.1
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/README.md +283 -125
- package/_commonjsHelpers-CT5_WOk_.js +1271 -0
- package/_commonjsHelpers-DZAafUiT.cjs +18 -0
- package/index.cjs.js +1 -1
- package/index.es.js +2 -2
- package/{model-context-CjwVhPEC.cjs → model-context-BBYdA-gO.cjs} +1 -1
- package/{model-context-DJcsllu0.js → model-context-Bvjdyghq.js} +3 -3
- package/package.json +2 -1
- package/{three.module-MSVrkZDe.js → three.module-7bSgh1t6.js} +94 -94
- package/use-export-model/index.d.ts +1 -0
- package/use-export-model/types.d.ts +19 -0
- package/use-export-model/use-export-model.d.ts +14 -0
- package/use-export-model/utils/data-uri-to-blob.d.ts +9 -0
- package/use-export-model/utils/export-handlers.d.ts +23 -0
- package/use-export-model/utils/file-helpers.d.ts +17 -0
- package/use-export-model/utils/index.d.ts +3 -0
- package/use-export-model.cjs.js +12 -0
- package/use-export-model.es.js +2461 -0
- package/use-load-model.cjs.js +1 -1
- package/use-load-model.es.js +1 -1
- package/use-optimize-model-DMZVYv9U.cjs +20 -0
- package/{use-optimize-model-D1qG_kQN.js → use-optimize-model-DRrg3MLA.js} +2588 -3852
- package/use-optimize-model.cjs.js +1 -1
- package/use-optimize-model.es.js +1 -1
- package/use-optimize-model-D7TsYCC3.cjs +0 -37
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";const f=require("./three.module-C5-FOeun.cjs");let v,D,_,G;function z(a,e=1/0,t=null){D||(D=new f.PlaneGeometry(2,2,1,1)),_||(_=new f.ShaderMaterial({uniforms:{blitTexture:new f.Uniform(a)},vertexShader:`
|
|
2
|
+
varying vec2 vUv;
|
|
3
|
+
void main(){
|
|
4
|
+
vUv = uv;
|
|
5
|
+
gl_Position = vec4(position.xy * 1.0,0.,.999999);
|
|
6
|
+
}`,fragmentShader:`
|
|
7
|
+
uniform sampler2D blitTexture;
|
|
8
|
+
varying vec2 vUv;
|
|
9
|
+
|
|
10
|
+
void main(){
|
|
11
|
+
gl_FragColor = vec4(vUv.xy, 0, 1);
|
|
12
|
+
|
|
13
|
+
#ifdef IS_SRGB
|
|
14
|
+
gl_FragColor = sRGBTransferOETF( texture2D( blitTexture, vUv) );
|
|
15
|
+
#else
|
|
16
|
+
gl_FragColor = texture2D( blitTexture, vUv);
|
|
17
|
+
#endif
|
|
18
|
+
}`})),_.uniforms.blitTexture.value=a,_.defines.IS_SRGB=a.colorSpace==f.SRGBColorSpace,_.needsUpdate=!0,G||(G=new f.Mesh(D,_),G.frustumCulled=!1);const r=new f.PerspectiveCamera,s=new f.Scene;s.add(G),t===null&&(t=v=new f.WebGLRenderer({antialias:!1}));const i=Math.min(a.image.width,e),n=Math.min(a.image.height,e);t.setSize(i,n),t.clear(),t.render(s,r);const o=document.createElement("canvas"),c=o.getContext("2d");o.width=i,o.height=n,c.drawImage(t.domElement,0,0,i,n);const l=new f.CanvasTexture(o);return l.minFilter=a.minFilter,l.magFilter=a.magFilter,l.wrapS=a.wrapS,l.wrapT=a.wrapT,l.name=a.name,v&&(v.forceContextLoss(),v.dispose(),v=null),l}const Y={POSITION:["byte","byte normalized","unsigned byte","unsigned byte normalized","short","short normalized","unsigned short","unsigned short normalized"],NORMAL:["byte normalized","short normalized"],TANGENT:["byte normalized","short normalized"],TEXCOORD:["byte","byte normalized","unsigned byte","short","short normalized","unsigned short"]};class V{constructor(){this.pluginCallbacks=[],this.register(function(e){return new ce(e)}),this.register(function(e){return new le(e)}),this.register(function(e){return new pe(e)}),this.register(function(e){return new de(e)}),this.register(function(e){return new xe(e)}),this.register(function(e){return new ge(e)}),this.register(function(e){return new ue(e)}),this.register(function(e){return new fe(e)}),this.register(function(e){return new he(e)}),this.register(function(e){return new Te(e)}),this.register(function(e){return new me(e)}),this.register(function(e){return new ye(e)}),this.register(function(e){return new Me(e)}),this.register(function(e){return new we(e)})}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,r,s){const i=new ae,n=[];for(let o=0,c=this.pluginCallbacks.length;o<c;o++)n.push(this.pluginCallbacks[o](i));i.setPlugins(n),i.write(e,t,s).catch(r)}parseAsync(e,t){const r=this;return new Promise(function(s,i){r.parse(e,s,i,t)})}}const m={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,INT:5124,UNSIGNED_INT:5125,FLOAT:5126,ARRAY_BUFFER:34962,ELEMENT_ARRAY_BUFFER:34963,NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987,CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},k="KHR_mesh_quantization",b={};b[f.NearestFilter]=m.NEAREST;b[f.NearestMipmapNearestFilter]=m.NEAREST_MIPMAP_NEAREST;b[f.NearestMipmapLinearFilter]=m.NEAREST_MIPMAP_LINEAR;b[f.LinearFilter]=m.LINEAR;b[f.LinearMipmapNearestFilter]=m.LINEAR_MIPMAP_NEAREST;b[f.LinearMipmapLinearFilter]=m.LINEAR_MIPMAP_LINEAR;b[f.ClampToEdgeWrapping]=m.CLAMP_TO_EDGE;b[f.RepeatWrapping]=m.REPEAT;b[f.MirroredRepeatWrapping]=m.MIRRORED_REPEAT;const K={scale:"scale",position:"translation",quaternion:"rotation",morphTargetInfluences:"weights"},$=new f.Color,q=12,ee=1179937895,te=2,W=8,se=1313821514,ne=5130562;function O(a,e){return a.length===e.length&&a.every(function(t,r){return t===e[r]})}function ie(a){return new TextEncoder().encode(a).buffer}function re(a){return O(a.elements,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function oe(a,e,t){const r={min:new Array(a.itemSize).fill(Number.POSITIVE_INFINITY),max:new Array(a.itemSize).fill(Number.NEGATIVE_INFINITY)};for(let s=e;s<e+t;s++)for(let i=0;i<a.itemSize;i++){let n;a.itemSize>4?n=a.array[s*a.itemSize+i]:(i===0?n=a.getX(s):i===1?n=a.getY(s):i===2?n=a.getZ(s):i===3&&(n=a.getW(s)),a.normalized===!0&&(n=f.MathUtils.normalize(n,a.array))),r.min[i]=Math.min(r.min[i],n),r.max[i]=Math.max(r.max[i],n)}return r}function Q(a){return Math.ceil(a/4)*4}function H(a,e=0){const t=Q(a.byteLength);if(t!==a.byteLength){const r=new Uint8Array(t);if(r.set(new Uint8Array(a)),e!==0)for(let s=a.byteLength;s<t;s++)r[s]=e;return r.buffer}return a}function X(){return typeof document>"u"&&typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):document.createElement("canvas")}function J(a,e){if(a.toBlob!==void 0)return new Promise(r=>a.toBlob(r,e));let t;return e==="image/jpeg"?t=.92:e==="image/webp"&&(t=.8),a.convertToBlob({type:e,quality:t})}class ae{constructor(){this.plugins=[],this.options={},this.pending=[],this.buffers=[],this.byteOffset=0,this.buffers=[],this.nodeMap=new Map,this.skins=[],this.extensionsUsed={},this.extensionsRequired={},this.uids=new Map,this.uid=0,this.json={asset:{version:"2.0",generator:"THREE.GLTFExporter r"+f.REVISION}},this.cache={meshes:new Map,attributes:new Map,attributesNormalized:new Map,materials:new Map,textures:new Map,images:new Map}}setPlugins(e){this.plugins=e}async write(e,t,r={}){this.options=Object.assign({binary:!1,trs:!1,onlyVisible:!0,maxTextureSize:1/0,animations:[],includeCustomExtensions:!1},r),this.options.animations.length>0&&(this.options.trs=!0),this.processInput(e),await Promise.all(this.pending);const s=this,i=s.buffers,n=s.json;r=s.options;const o=s.extensionsUsed,c=s.extensionsRequired,l=new Blob(i,{type:"application/octet-stream"}),p=Object.keys(o),u=Object.keys(c);if(p.length>0&&(n.extensionsUsed=p),u.length>0&&(n.extensionsRequired=u),n.buffers&&n.buffers.length>0&&(n.buffers[0].byteLength=l.size),r.binary===!0){const y=new FileReader;y.readAsArrayBuffer(l),y.onloadend=function(){const h=H(y.result),d=new DataView(new ArrayBuffer(W));d.setUint32(0,h.byteLength,!0),d.setUint32(4,ne,!0);const x=H(ie(JSON.stringify(n)),32),T=new DataView(new ArrayBuffer(W));T.setUint32(0,x.byteLength,!0),T.setUint32(4,se,!0);const w=new ArrayBuffer(q),N=new DataView(w);N.setUint32(0,ee,!0),N.setUint32(4,te,!0);const B=q+T.byteLength+x.byteLength+d.byteLength+h.byteLength;N.setUint32(8,B,!0);const g=new Blob([w,T,x,d,h],{type:"application/octet-stream"}),M=new FileReader;M.readAsArrayBuffer(g),M.onloadend=function(){t(M.result)}}}else if(n.buffers&&n.buffers.length>0){const y=new FileReader;y.readAsDataURL(l),y.onloadend=function(){const h=y.result;n.buffers[0].uri=h,t(n)}}else t(n)}serializeUserData(e,t){if(Object.keys(e.userData).length===0)return;const r=this.options,s=this.extensionsUsed;try{const i=JSON.parse(JSON.stringify(e.userData));if(r.includeCustomExtensions&&i.gltfExtensions){t.extensions===void 0&&(t.extensions={});for(const n in i.gltfExtensions)t.extensions[n]=i.gltfExtensions[n],s[n]=!0;delete i.gltfExtensions}Object.keys(i).length>0&&(t.extras=i)}catch(i){console.warn("THREE.GLTFExporter: userData of '"+e.name+"' won't be serialized because of JSON.stringify error - "+i.message)}}getUID(e,t=!1){if(this.uids.has(e)===!1){const s=new Map;s.set(!0,this.uid++),s.set(!1,this.uid++),this.uids.set(e,s)}return this.uids.get(e).get(t)}isNormalizedNormalAttribute(e){if(this.cache.attributesNormalized.has(e))return!1;const r=new f.Vector3;for(let s=0,i=e.count;s<i;s++)if(Math.abs(r.fromBufferAttribute(e,s).length()-1)>5e-4)return!1;return!0}createNormalizedNormalAttribute(e){const t=this.cache;if(t.attributesNormalized.has(e))return t.attributesNormalized.get(e);const r=e.clone(),s=new f.Vector3;for(let i=0,n=r.count;i<n;i++)s.fromBufferAttribute(r,i),s.x===0&&s.y===0&&s.z===0?s.setX(1):s.normalize(),r.setXYZ(i,s.x,s.y,s.z);return t.attributesNormalized.set(e,r),r}applyTextureTransform(e,t){let r=!1;const s={};(t.offset.x!==0||t.offset.y!==0)&&(s.offset=t.offset.toArray(),r=!0),t.rotation!==0&&(s.rotation=t.rotation,r=!0),(t.repeat.x!==1||t.repeat.y!==1)&&(s.scale=t.repeat.toArray(),r=!0),r&&(e.extensions=e.extensions||{},e.extensions.KHR_texture_transform=s,this.extensionsUsed.KHR_texture_transform=!0)}buildMetalRoughTexture(e,t){if(e===t)return e;function r(h){return h.colorSpace===f.SRGBColorSpace?function(x){return x<.04045?x*.0773993808:Math.pow(x*.9478672986+.0521327014,2.4)}:function(x){return x}}console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures."),e instanceof f.CompressedTexture&&(e=z(e)),t instanceof f.CompressedTexture&&(t=z(t));const s=e?e.image:null,i=t?t.image:null,n=Math.max(s?s.width:0,i?i.width:0),o=Math.max(s?s.height:0,i?i.height:0),c=X();c.width=n,c.height=o;const l=c.getContext("2d",{willReadFrequently:!0});l.fillStyle="#00ffff",l.fillRect(0,0,n,o);const p=l.getImageData(0,0,n,o);if(s){l.drawImage(s,0,0,n,o);const h=r(e),d=l.getImageData(0,0,n,o).data;for(let x=2;x<d.length;x+=4)p.data[x]=h(d[x]/256)*256}if(i){l.drawImage(i,0,0,n,o);const h=r(t),d=l.getImageData(0,0,n,o).data;for(let x=1;x<d.length;x+=4)p.data[x]=h(d[x]/256)*256}l.putImageData(p,0,0);const y=(e||t).clone();return y.source=new f.Source(c),y.colorSpace=f.NoColorSpace,y.channel=(e||t).channel,e&&t&&e.channel!==t.channel&&console.warn("THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match."),y}processBuffer(e){const t=this.json,r=this.buffers;return t.buffers||(t.buffers=[{byteLength:0}]),r.push(e),0}processBufferView(e,t,r,s,i){const n=this.json;n.bufferViews||(n.bufferViews=[]);let o;switch(t){case m.BYTE:case m.UNSIGNED_BYTE:o=1;break;case m.SHORT:case m.UNSIGNED_SHORT:o=2;break;default:o=4}let c=e.itemSize*o;i===m.ARRAY_BUFFER&&(c=Math.ceil(c/4)*4);const l=Q(s*c),p=new DataView(new ArrayBuffer(l));let u=0;for(let d=r;d<r+s;d++){for(let x=0;x<e.itemSize;x++){let T;e.itemSize>4?T=e.array[d*e.itemSize+x]:(x===0?T=e.getX(d):x===1?T=e.getY(d):x===2?T=e.getZ(d):x===3&&(T=e.getW(d)),e.normalized===!0&&(T=f.MathUtils.normalize(T,e.array))),t===m.FLOAT?p.setFloat32(u,T,!0):t===m.INT?p.setInt32(u,T,!0):t===m.UNSIGNED_INT?p.setUint32(u,T,!0):t===m.SHORT?p.setInt16(u,T,!0):t===m.UNSIGNED_SHORT?p.setUint16(u,T,!0):t===m.BYTE?p.setInt8(u,T):t===m.UNSIGNED_BYTE&&p.setUint8(u,T),u+=o}u%c!==0&&(u+=c-u%c)}const y={buffer:this.processBuffer(p.buffer),byteOffset:this.byteOffset,byteLength:l};return i!==void 0&&(y.target=i),i===m.ARRAY_BUFFER&&(y.byteStride=c),this.byteOffset+=l,n.bufferViews.push(y),{id:n.bufferViews.length-1,byteLength:0}}processBufferViewImage(e){const t=this,r=t.json;return r.bufferViews||(r.bufferViews=[]),new Promise(function(s){const i=new FileReader;i.readAsArrayBuffer(e),i.onloadend=function(){const n=H(i.result),o={buffer:t.processBuffer(n),byteOffset:t.byteOffset,byteLength:n.byteLength};t.byteOffset+=n.byteLength,s(r.bufferViews.push(o)-1)}})}processAccessor(e,t,r,s){const i=this.json,n={1:"SCALAR",2:"VEC2",3:"VEC3",4:"VEC4",9:"MAT3",16:"MAT4"};let o;if(e.array.constructor===Float32Array)o=m.FLOAT;else if(e.array.constructor===Int32Array)o=m.INT;else if(e.array.constructor===Uint32Array)o=m.UNSIGNED_INT;else if(e.array.constructor===Int16Array)o=m.SHORT;else if(e.array.constructor===Uint16Array)o=m.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)o=m.BYTE;else if(e.array.constructor===Uint8Array)o=m.UNSIGNED_BYTE;else throw new Error("THREE.GLTFExporter: Unsupported bufferAttribute component type: "+e.array.constructor.name);if(r===void 0&&(r=0),(s===void 0||s===1/0)&&(s=e.count),s===0)return null;const c=oe(e,r,s);let l;t!==void 0&&(l=e===t.index?m.ELEMENT_ARRAY_BUFFER:m.ARRAY_BUFFER);const p=this.processBufferView(e,o,r,s,l),u={bufferView:p.id,byteOffset:p.byteOffset,componentType:o,count:s,max:c.max,min:c.min,type:n[e.itemSize]};return e.normalized===!0&&(u.normalized=!0),i.accessors||(i.accessors=[]),i.accessors.push(u)-1}processImage(e,t,r,s="image/png"){if(e!==null){const i=this,n=i.cache,o=i.json,c=i.options,l=i.pending;n.images.has(e)||n.images.set(e,{});const p=n.images.get(e),u=s+":flipY/"+r.toString();if(p[u]!==void 0)return p[u];o.images||(o.images=[]);const y={mimeType:s},h=X();h.width=Math.min(e.width,c.maxTextureSize),h.height=Math.min(e.height,c.maxTextureSize);const d=h.getContext("2d",{willReadFrequently:!0});if(r===!0&&(d.translate(0,h.height),d.scale(1,-1)),e.data!==void 0){t!==f.RGBAFormat&&console.error("GLTFExporter: Only RGBAFormat is supported.",t),(e.width>c.maxTextureSize||e.height>c.maxTextureSize)&&console.warn("GLTFExporter: Image size is bigger than maxTextureSize",e);const T=new Uint8ClampedArray(e.height*e.width*4);for(let w=0;w<T.length;w+=4)T[w+0]=e.data[w+0],T[w+1]=e.data[w+1],T[w+2]=e.data[w+2],T[w+3]=e.data[w+3];d.putImageData(new ImageData(T,e.width,e.height),0,0)}else if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap||typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas)d.drawImage(e,0,0,h.width,h.height);else throw new Error("THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.");c.binary===!0?l.push(J(h,s).then(T=>i.processBufferViewImage(T)).then(T=>{y.bufferView=T})):h.toDataURL!==void 0?y.uri=h.toDataURL(s):l.push(J(h,s).then(T=>new FileReader().readAsDataURL(T)).then(T=>{y.uri=T}));const x=o.images.push(y)-1;return p[u]=x,x}else throw new Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.")}processSampler(e){const t=this.json;t.samplers||(t.samplers=[]);const r={magFilter:b[e.magFilter],minFilter:b[e.minFilter],wrapS:b[e.wrapS],wrapT:b[e.wrapT]};return t.samplers.push(r)-1}processTexture(e){const r=this.options,s=this.cache,i=this.json;if(s.textures.has(e))return s.textures.get(e);i.textures||(i.textures=[]),e instanceof f.CompressedTexture&&(e=z(e,r.maxTextureSize));let n=e.userData.mimeType;n==="image/webp"&&(n="image/png");const o={sampler:this.processSampler(e),source:this.processImage(e.image,e.format,e.flipY,n)};e.name&&(o.name=e.name),this._invokeAll(function(l){l.writeTexture&&l.writeTexture(e,o)});const c=i.textures.push(o)-1;return s.textures.set(e,c),c}processMaterial(e){const t=this.cache,r=this.json;if(t.materials.has(e))return t.materials.get(e);if(e.isShaderMaterial)return console.warn("GLTFExporter: THREE.ShaderMaterial not supported."),null;r.materials||(r.materials=[]);const s={pbrMetallicRoughness:{}};e.isMeshStandardMaterial!==!0&&e.isMeshBasicMaterial!==!0&&console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");const i=e.color.toArray().concat([e.opacity]);if(O(i,[1,1,1,1])||(s.pbrMetallicRoughness.baseColorFactor=i),e.isMeshStandardMaterial?(s.pbrMetallicRoughness.metallicFactor=e.metalness,s.pbrMetallicRoughness.roughnessFactor=e.roughness):(s.pbrMetallicRoughness.metallicFactor=.5,s.pbrMetallicRoughness.roughnessFactor=.5),e.metalnessMap||e.roughnessMap){const o=this.buildMetalRoughTexture(e.metalnessMap,e.roughnessMap),c={index:this.processTexture(o),channel:o.channel};this.applyTextureTransform(c,o),s.pbrMetallicRoughness.metallicRoughnessTexture=c}if(e.map){const o={index:this.processTexture(e.map),texCoord:e.map.channel};this.applyTextureTransform(o,e.map),s.pbrMetallicRoughness.baseColorTexture=o}if(e.emissive){const o=e.emissive;if(Math.max(o.r,o.g,o.b)>0&&(s.emissiveFactor=e.emissive.toArray()),e.emissiveMap){const l={index:this.processTexture(e.emissiveMap),texCoord:e.emissiveMap.channel};this.applyTextureTransform(l,e.emissiveMap),s.emissiveTexture=l}}if(e.normalMap){const o={index:this.processTexture(e.normalMap),texCoord:e.normalMap.channel};e.normalScale&&e.normalScale.x!==1&&(o.scale=e.normalScale.x),this.applyTextureTransform(o,e.normalMap),s.normalTexture=o}if(e.aoMap){const o={index:this.processTexture(e.aoMap),texCoord:e.aoMap.channel};e.aoMapIntensity!==1&&(o.strength=e.aoMapIntensity),this.applyTextureTransform(o,e.aoMap),s.occlusionTexture=o}e.transparent?s.alphaMode="BLEND":e.alphaTest>0&&(s.alphaMode="MASK",s.alphaCutoff=e.alphaTest),e.side===f.DoubleSide&&(s.doubleSided=!0),e.name!==""&&(s.name=e.name),this.serializeUserData(e,s),this._invokeAll(function(o){o.writeMaterial&&o.writeMaterial(e,s)});const n=r.materials.push(s)-1;return t.materials.set(e,n),n}processMesh(e){const t=this.cache,r=this.json,s=[e.geometry.uuid];if(Array.isArray(e.material))for(let g=0,M=e.material.length;g<M;g++)s.push(e.material[g].uuid);else s.push(e.material.uuid);const i=s.join(":");if(t.meshes.has(i))return t.meshes.get(i);const n=e.geometry;let o;e.isLineSegments?o=m.LINES:e.isLineLoop?o=m.LINE_LOOP:e.isLine?o=m.LINE_STRIP:e.isPoints?o=m.POINTS:o=e.material.wireframe?m.LINES:m.TRIANGLES;const c={},l={},p=[],u=[],y={uv:"TEXCOORD_0",uv1:"TEXCOORD_1",uv2:"TEXCOORD_2",uv3:"TEXCOORD_3",color:"COLOR_0",skinWeight:"WEIGHTS_0",skinIndex:"JOINTS_0"},h=n.getAttribute("normal");h!==void 0&&!this.isNormalizedNormalAttribute(h)&&(console.warn("THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one."),n.setAttribute("normal",this.createNormalizedNormalAttribute(h)));let d=null;for(let g in n.attributes){if(g.slice(0,5)==="morph")continue;const M=n.attributes[g];if(g=y[g]||g.toUpperCase(),/^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/.test(g)||(g="_"+g),t.attributes.has(this.getUID(M))){l[g]=t.attributes.get(this.getUID(M));continue}d=null;const I=M.array;g==="JOINTS_0"&&!(I instanceof Uint16Array)&&!(I instanceof Uint8Array)&&(console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.'),d=new f.BufferAttribute(new Uint16Array(I),M.itemSize,M.normalized));const R=this.processAccessor(d||M,n);R!==null&&(g.startsWith("_")||this.detectMeshQuantization(g,M),l[g]=R,t.attributes.set(this.getUID(M),R))}if(h!==void 0&&n.setAttribute("normal",h),Object.keys(l).length===0)return null;if(e.morphTargetInfluences!==void 0&&e.morphTargetInfluences.length>0){const g=[],M=[],E={};if(e.morphTargetDictionary!==void 0)for(const I in e.morphTargetDictionary)E[e.morphTargetDictionary[I]]=I;for(let I=0;I<e.morphTargetInfluences.length;++I){const R={};let j=!1;for(const C in n.morphAttributes){if(C!=="position"&&C!=="normal"){j||(console.warn("GLTFExporter: Only POSITION and NORMAL morph are supported."),j=!0);continue}const S=n.morphAttributes[C][I],P=C.toUpperCase(),U=n.attributes[C];if(t.attributes.has(this.getUID(S,!0))){R[P]=t.attributes.get(this.getUID(S,!0));continue}const F=S.clone();if(!n.morphTargetsRelative)for(let A=0,Z=S.count;A<Z;A++)for(let L=0;L<S.itemSize;L++)L===0&&F.setX(A,S.getX(A)-U.getX(A)),L===1&&F.setY(A,S.getY(A)-U.getY(A)),L===2&&F.setZ(A,S.getZ(A)-U.getZ(A)),L===3&&F.setW(A,S.getW(A)-U.getW(A));R[P]=this.processAccessor(F,n),t.attributes.set(this.getUID(U,!0),R[P])}u.push(R),g.push(e.morphTargetInfluences[I]),e.morphTargetDictionary!==void 0&&M.push(E[I])}c.weights=g,M.length>0&&(c.extras={},c.extras.targetNames=M)}const x=Array.isArray(e.material);if(x&&n.groups.length===0)return null;let T=!1;if(x&&n.index===null){const g=[];for(let M=0,E=n.attributes.position.count;M<E;M++)g[M]=M;n.setIndex(g),T=!0}const w=x?e.material:[e.material],N=x?n.groups:[{materialIndex:0,start:void 0,count:void 0}];for(let g=0,M=N.length;g<M;g++){const E={mode:o,attributes:l};if(this.serializeUserData(n,E),u.length>0&&(E.targets=u),n.index!==null){let R=this.getUID(n.index);(N[g].start!==void 0||N[g].count!==void 0)&&(R+=":"+N[g].start+":"+N[g].count),t.attributes.has(R)?E.indices=t.attributes.get(R):(E.indices=this.processAccessor(n.index,n,N[g].start,N[g].count),t.attributes.set(R,E.indices)),E.indices===null&&delete E.indices}const I=this.processMaterial(w[N[g].materialIndex]);I!==null&&(E.material=I),p.push(E)}T===!0&&n.setIndex(null),c.primitives=p,r.meshes||(r.meshes=[]),this._invokeAll(function(g){g.writeMesh&&g.writeMesh(e,c)});const B=r.meshes.push(c)-1;return t.meshes.set(i,B),B}detectMeshQuantization(e,t){if(this.extensionsUsed[k])return;let r;switch(t.array.constructor){case Int8Array:r="byte";break;case Uint8Array:r="unsigned byte";break;case Int16Array:r="short";break;case Uint16Array:r="unsigned short";break;default:return}t.normalized&&(r+=" normalized");const s=e.split("_",1)[0];Y[s]&&Y[s].includes(r)&&(this.extensionsUsed[k]=!0,this.extensionsRequired[k]=!0)}processCamera(e){const t=this.json;t.cameras||(t.cameras=[]);const r=e.isOrthographicCamera,s={type:r?"orthographic":"perspective"};return r?s.orthographic={xmag:e.right*2,ymag:e.top*2,zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near}:s.perspective={aspectRatio:e.aspect,yfov:f.MathUtils.degToRad(e.fov),zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near},e.name!==""&&(s.name=e.type),t.cameras.push(s)-1}processAnimation(e,t){const r=this.json,s=this.nodeMap;r.animations||(r.animations=[]),e=V.Utils.mergeMorphTargetTracks(e.clone(),t);const i=e.tracks,n=[],o=[];for(let c=0;c<i.length;++c){const l=i[c],p=f.PropertyBinding.parseTrackName(l.name);let u=f.PropertyBinding.findNode(t,p.nodeName);const y=K[p.propertyName];if(p.objectName==="bones"&&(u.isSkinnedMesh===!0?u=u.skeleton.getBoneByName(p.objectIndex):u=void 0),!u||!y){console.warn('THREE.GLTFExporter: Could not export animation track "%s".',l.name);continue}const h=1;let d=l.values.length/l.times.length;y===K.morphTargetInfluences&&(d/=u.morphTargetInfluences.length);let x;l.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline===!0?(x="CUBICSPLINE",d/=3):l.getInterpolation()===f.InterpolateDiscrete?x="STEP":x="LINEAR",o.push({input:this.processAccessor(new f.BufferAttribute(l.times,h)),output:this.processAccessor(new f.BufferAttribute(l.values,d)),interpolation:x}),n.push({sampler:o.length-1,target:{node:s.get(u),path:y}})}return r.animations.push({name:e.name||"clip_"+r.animations.length,samplers:o,channels:n}),r.animations.length-1}processSkin(e){const t=this.json,r=this.nodeMap,s=t.nodes[r.get(e)],i=e.skeleton;if(i===void 0)return null;const n=e.skeleton.bones[0];if(n===void 0)return null;const o=[],c=new Float32Array(i.bones.length*16),l=new f.Matrix4;for(let u=0;u<i.bones.length;++u)o.push(r.get(i.bones[u])),l.copy(i.boneInverses[u]),l.multiply(e.bindMatrix).toArray(c,u*16);return t.skins===void 0&&(t.skins=[]),t.skins.push({inverseBindMatrices:this.processAccessor(new f.BufferAttribute(c,16)),joints:o,skeleton:r.get(n)}),s.skin=t.skins.length-1}processNode(e){const t=this.json,r=this.options,s=this.nodeMap;t.nodes||(t.nodes=[]);const i={};if(r.trs){const o=e.quaternion.toArray(),c=e.position.toArray(),l=e.scale.toArray();O(o,[0,0,0,1])||(i.rotation=o),O(c,[0,0,0])||(i.translation=c),O(l,[1,1,1])||(i.scale=l)}else e.matrixAutoUpdate&&e.updateMatrix(),re(e.matrix)===!1&&(i.matrix=e.matrix.elements);if(e.name!==""&&(i.name=String(e.name)),this.serializeUserData(e,i),e.isMesh||e.isLine||e.isPoints){const o=this.processMesh(e);o!==null&&(i.mesh=o)}else e.isCamera&&(i.camera=this.processCamera(e));if(e.isSkinnedMesh&&this.skins.push(e),e.children.length>0){const o=[];for(let c=0,l=e.children.length;c<l;c++){const p=e.children[c];if(p.visible||r.onlyVisible===!1){const u=this.processNode(p);u!==null&&o.push(u)}}o.length>0&&(i.children=o)}this._invokeAll(function(o){o.writeNode&&o.writeNode(e,i)});const n=t.nodes.push(i)-1;return s.set(e,n),n}processScene(e){const t=this.json,r=this.options;t.scenes||(t.scenes=[],t.scene=0);const s={};e.name!==""&&(s.name=e.name),t.scenes.push(s);const i=[];for(let n=0,o=e.children.length;n<o;n++){const c=e.children[n];if(c.visible||r.onlyVisible===!1){const l=this.processNode(c);l!==null&&i.push(l)}}i.length>0&&(s.nodes=i),this.serializeUserData(e,s)}processObjects(e){const t=new f.Scene;t.name="AuxScene";for(let r=0;r<e.length;r++)t.children.push(e[r]);this.processScene(t)}processInput(e){const t=this.options;e=e instanceof Array?e:[e],this._invokeAll(function(s){s.beforeParse&&s.beforeParse(e)});const r=[];for(let s=0;s<e.length;s++)e[s]instanceof f.Scene?this.processScene(e[s]):r.push(e[s]);r.length>0&&this.processObjects(r);for(let s=0;s<this.skins.length;++s)this.processSkin(this.skins[s]);for(let s=0;s<t.animations.length;++s)this.processAnimation(t.animations[s],e[0]);this._invokeAll(function(s){s.afterParse&&s.afterParse(e)})}_invokeAll(e){for(let t=0,r=this.plugins.length;t<r;t++)e(this.plugins[t])}}class ce{constructor(e){this.writer=e,this.name="KHR_lights_punctual"}writeNode(e,t){if(!e.isLight)return;if(!e.isDirectionalLight&&!e.isPointLight&&!e.isSpotLight){console.warn("THREE.GLTFExporter: Only directional, point, and spot lights are supported.",e);return}const r=this.writer,s=r.json,i=r.extensionsUsed,n={};e.name&&(n.name=e.name),n.color=e.color.toArray(),n.intensity=e.intensity,e.isDirectionalLight?n.type="directional":e.isPointLight?(n.type="point",e.distance>0&&(n.range=e.distance)):e.isSpotLight&&(n.type="spot",e.distance>0&&(n.range=e.distance),n.spot={},n.spot.innerConeAngle=(1-e.penumbra)*e.angle,n.spot.outerConeAngle=e.angle),e.decay!==void 0&&e.decay!==2&&console.warn("THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."),e.target&&(e.target.parent!==e||e.target.position.x!==0||e.target.position.y!==0||e.target.position.z!==-1)&&console.warn("THREE.GLTFExporter: Light direction may be lost. For best results, make light.target a child of the light with position 0,0,-1."),i[this.name]||(s.extensions=s.extensions||{},s.extensions[this.name]={lights:[]},i[this.name]=!0);const o=s.extensions[this.name].lights;o.push(n),t.extensions=t.extensions||{},t.extensions[this.name]={light:o.length-1}}}class le{constructor(e){this.writer=e,this.name="KHR_materials_unlit"}writeMaterial(e,t){if(!e.isMeshBasicMaterial)return;const s=this.writer.extensionsUsed;t.extensions=t.extensions||{},t.extensions[this.name]={},s[this.name]=!0,t.pbrMetallicRoughness.metallicFactor=0,t.pbrMetallicRoughness.roughnessFactor=.9}}class ue{constructor(e){this.writer=e,this.name="KHR_materials_clearcoat"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.clearcoat===0)return;const r=this.writer,s=r.extensionsUsed,i={};if(i.clearcoatFactor=e.clearcoat,e.clearcoatMap){const n={index:r.processTexture(e.clearcoatMap),texCoord:e.clearcoatMap.channel};r.applyTextureTransform(n,e.clearcoatMap),i.clearcoatTexture=n}if(i.clearcoatRoughnessFactor=e.clearcoatRoughness,e.clearcoatRoughnessMap){const n={index:r.processTexture(e.clearcoatRoughnessMap),texCoord:e.clearcoatRoughnessMap.channel};r.applyTextureTransform(n,e.clearcoatRoughnessMap),i.clearcoatRoughnessTexture=n}if(e.clearcoatNormalMap){const n={index:r.processTexture(e.clearcoatNormalMap),texCoord:e.clearcoatNormalMap.channel};e.clearcoatNormalScale.x!==1&&(n.scale=e.clearcoatNormalScale.x),r.applyTextureTransform(n,e.clearcoatNormalMap),i.clearcoatNormalTexture=n}t.extensions=t.extensions||{},t.extensions[this.name]=i,s[this.name]=!0}}class fe{constructor(e){this.writer=e,this.name="KHR_materials_dispersion"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.dispersion===0)return;const s=this.writer.extensionsUsed,i={};i.dispersion=e.dispersion,t.extensions=t.extensions||{},t.extensions[this.name]=i,s[this.name]=!0}}class he{constructor(e){this.writer=e,this.name="KHR_materials_iridescence"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.iridescence===0)return;const r=this.writer,s=r.extensionsUsed,i={};if(i.iridescenceFactor=e.iridescence,e.iridescenceMap){const n={index:r.processTexture(e.iridescenceMap),texCoord:e.iridescenceMap.channel};r.applyTextureTransform(n,e.iridescenceMap),i.iridescenceTexture=n}if(i.iridescenceIor=e.iridescenceIOR,i.iridescenceThicknessMinimum=e.iridescenceThicknessRange[0],i.iridescenceThicknessMaximum=e.iridescenceThicknessRange[1],e.iridescenceThicknessMap){const n={index:r.processTexture(e.iridescenceThicknessMap),texCoord:e.iridescenceThicknessMap.channel};r.applyTextureTransform(n,e.iridescenceThicknessMap),i.iridescenceThicknessTexture=n}t.extensions=t.extensions||{},t.extensions[this.name]=i,s[this.name]=!0}}class pe{constructor(e){this.writer=e,this.name="KHR_materials_transmission"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;const r=this.writer,s=r.extensionsUsed,i={};if(i.transmissionFactor=e.transmission,e.transmissionMap){const n={index:r.processTexture(e.transmissionMap),texCoord:e.transmissionMap.channel};r.applyTextureTransform(n,e.transmissionMap),i.transmissionTexture=n}t.extensions=t.extensions||{},t.extensions[this.name]=i,s[this.name]=!0}}class de{constructor(e){this.writer=e,this.name="KHR_materials_volume"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;const r=this.writer,s=r.extensionsUsed,i={};if(i.thicknessFactor=e.thickness,e.thicknessMap){const n={index:r.processTexture(e.thicknessMap),texCoord:e.thicknessMap.channel};r.applyTextureTransform(n,e.thicknessMap),i.thicknessTexture=n}i.attenuationDistance=e.attenuationDistance,i.attenuationColor=e.attenuationColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,s[this.name]=!0}}class xe{constructor(e){this.writer=e,this.name="KHR_materials_ior"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.ior===1.5)return;const s=this.writer.extensionsUsed,i={};i.ior=e.ior,t.extensions=t.extensions||{},t.extensions[this.name]=i,s[this.name]=!0}}class ge{constructor(e){this.writer=e,this.name="KHR_materials_specular"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.specularIntensity===1&&e.specularColor.equals($)&&!e.specularIntensityMap&&!e.specularColorMap)return;const r=this.writer,s=r.extensionsUsed,i={};if(e.specularIntensityMap){const n={index:r.processTexture(e.specularIntensityMap),texCoord:e.specularIntensityMap.channel};r.applyTextureTransform(n,e.specularIntensityMap),i.specularTexture=n}if(e.specularColorMap){const n={index:r.processTexture(e.specularColorMap),texCoord:e.specularColorMap.channel};r.applyTextureTransform(n,e.specularColorMap),i.specularColorTexture=n}i.specularFactor=e.specularIntensity,i.specularColorFactor=e.specularColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,s[this.name]=!0}}class Te{constructor(e){this.writer=e,this.name="KHR_materials_sheen"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.sheen==0)return;const r=this.writer,s=r.extensionsUsed,i={};if(e.sheenRoughnessMap){const n={index:r.processTexture(e.sheenRoughnessMap),texCoord:e.sheenRoughnessMap.channel};r.applyTextureTransform(n,e.sheenRoughnessMap),i.sheenRoughnessTexture=n}if(e.sheenColorMap){const n={index:r.processTexture(e.sheenColorMap),texCoord:e.sheenColorMap.channel};r.applyTextureTransform(n,e.sheenColorMap),i.sheenColorTexture=n}i.sheenRoughnessFactor=e.sheenRoughness,i.sheenColorFactor=e.sheenColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,s[this.name]=!0}}class me{constructor(e){this.writer=e,this.name="KHR_materials_anisotropy"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.anisotropy==0)return;const r=this.writer,s=r.extensionsUsed,i={};if(e.anisotropyMap){const n={index:r.processTexture(e.anisotropyMap)};r.applyTextureTransform(n,e.anisotropyMap),i.anisotropyTexture=n}i.anisotropyStrength=e.anisotropy,i.anisotropyRotation=e.anisotropyRotation,t.extensions=t.extensions||{},t.extensions[this.name]=i,s[this.name]=!0}}class ye{constructor(e){this.writer=e,this.name="KHR_materials_emissive_strength"}writeMaterial(e,t){if(!e.isMeshStandardMaterial||e.emissiveIntensity===1)return;const s=this.writer.extensionsUsed,i={};i.emissiveStrength=e.emissiveIntensity,t.extensions=t.extensions||{},t.extensions[this.name]=i,s[this.name]=!0}}class Me{constructor(e){this.writer=e,this.name="EXT_materials_bump"}writeMaterial(e,t){if(!e.isMeshStandardMaterial||e.bumpScale===1&&!e.bumpMap)return;const r=this.writer,s=r.extensionsUsed,i={};if(e.bumpMap){const n={index:r.processTexture(e.bumpMap),texCoord:e.bumpMap.channel};r.applyTextureTransform(n,e.bumpMap),i.bumpTexture=n}i.bumpFactor=e.bumpScale,t.extensions=t.extensions||{},t.extensions[this.name]=i,s[this.name]=!0}}class we{constructor(e){this.writer=e,this.name="EXT_mesh_gpu_instancing"}writeNode(e,t){if(!e.isInstancedMesh)return;const r=this.writer,s=e,i=new Float32Array(s.count*3),n=new Float32Array(s.count*4),o=new Float32Array(s.count*3),c=new f.Matrix4,l=new f.Vector3,p=new f.Quaternion,u=new f.Vector3;for(let h=0;h<s.count;h++)s.getMatrixAt(h,c),c.decompose(l,p,u),l.toArray(i,h*3),p.toArray(n,h*4),u.toArray(o,h*3);const y={TRANSLATION:r.processAccessor(new f.BufferAttribute(i,3)),ROTATION:r.processAccessor(new f.BufferAttribute(n,4)),SCALE:r.processAccessor(new f.BufferAttribute(o,3))};s.instanceColor&&(y._COLOR_0=r.processAccessor(s.instanceColor)),t.extensions=t.extensions||{},t.extensions[this.name]={attributes:y},r.extensionsUsed[this.name]=!0,r.extensionsRequired[this.name]=!0}}V.Utils={insertKeyframe:function(a,e){const r=a.getValueSize(),s=new a.TimeBufferType(a.times.length+1),i=new a.ValueBufferType(a.values.length+r),n=a.createInterpolant(new a.ValueBufferType(r));let o;if(a.times.length===0){s[0]=e;for(let c=0;c<r;c++)i[c]=0;o=0}else if(e<a.times[0]){if(Math.abs(a.times[0]-e)<.001)return 0;s[0]=e,s.set(a.times,1),i.set(n.evaluate(e),0),i.set(a.values,r),o=0}else if(e>a.times[a.times.length-1]){if(Math.abs(a.times[a.times.length-1]-e)<.001)return a.times.length-1;s[s.length-1]=e,s.set(a.times,0),i.set(a.values,0),i.set(n.evaluate(e),a.values.length),o=s.length-1}else for(let c=0;c<a.times.length;c++){if(Math.abs(a.times[c]-e)<.001)return c;if(a.times[c]<e&&a.times[c+1]>e){s.set(a.times.slice(0,c+1),0),s[c+1]=e,s.set(a.times.slice(c+1),c+2),i.set(a.values.slice(0,(c+1)*r),0),i.set(n.evaluate(e),(c+1)*r),i.set(a.values.slice((c+1)*r),(c+2)*r),o=c+1;break}}return a.times=s,a.values=i,o},mergeMorphTargetTracks:function(a,e){const t=[],r={},s=a.tracks;for(let i=0;i<s.length;++i){let n=s[i];const o=f.PropertyBinding.parseTrackName(n.name),c=f.PropertyBinding.findNode(e,o.nodeName);if(o.propertyName!=="morphTargetInfluences"||o.propertyIndex===void 0){t.push(n);continue}if(n.createInterpolant!==n.InterpolantFactoryMethodDiscrete&&n.createInterpolant!==n.InterpolantFactoryMethodLinear){if(n.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline)throw new Error("THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.");console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead."),n=n.clone(),n.setInterpolation(f.InterpolateLinear)}const l=c.morphTargetInfluences.length,p=c.morphTargetDictionary[o.propertyIndex];if(p===void 0)throw new Error("THREE.GLTFExporter: Morph target name not found: "+o.propertyIndex);let u;if(r[c.uuid]===void 0){u=n.clone();const h=new u.ValueBufferType(l*u.times.length);for(let d=0;d<u.times.length;d++)h[d*l+p]=u.values[d];u.name=(o.nodeName||"")+".morphTargetInfluences",u.values=h,r[c.uuid]=u,t.push(u);continue}const y=n.createInterpolant(new n.ValueBufferType(1));u=r[c.uuid];for(let h=0;h<u.times.length;h++)u.values[h*l+p]=y.evaluate(u.times[h]);for(let h=0;h<n.times.length;h++){const d=this.insertKeyframe(u,n.times[h]);u.values[d*l+p]=n.values[h]}}return a.tracks=t,a}};var Ee=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ie(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}exports.GLTFExporter=V;exports.commonjsGlobal=Ee;exports.getDefaultExportFromCjs=Ie;
|
package/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./model-context-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./model-context-BBYdA-gO.cjs"),o=require("./use-optimize-model-DMZVYv9U.cjs");exports.ModelContext=e.ModelContext;exports.ModelFileTypes=e.ModelFileTypes;exports.ModelProvider=e.ModelProvider;exports.useLoadModel=e.useLoadModel;exports.useModelContext=e.useModelContext;exports.useOptimizeModel=o.useOptimizeModel;
|
package/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as s, M as a, b as d, u as l, c as t } from "./model-context-
|
|
2
|
-
import { u as r } from "./use-optimize-model-
|
|
1
|
+
import { a as s, M as a, b as d, u as l, c as t } from "./model-context-Bvjdyghq.js";
|
|
2
|
+
import { u as r } from "./use-optimize-model-DRrg3MLA.js";
|
|
3
3
|
export {
|
|
4
4
|
s as ModelContext,
|
|
5
5
|
a as ModelFileTypes,
|
|
@@ -6,4 +6,4 @@ fflate - fast JavaScript compression/decompression
|
|
|
6
6
|
Licensed under MIT. https://github.com/101arrowz/fflate/blob/master/LICENSE
|
|
7
7
|
version 0.8.2
|
|
8
8
|
*/var v=Uint8Array,nA=Uint16Array,Dt=Int32Array,Qe=new v([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),de=new v([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Ft=new v([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),he=function(n,A){for(var e=new nA(31),a=0;a<31;++a)e[a]=A+=1<<n[a-1];for(var t=new Dt(e[30]),a=1;a<30;++a)for(var i=e[a];i<e[a+1];++i)t[i]=i-e[a]<<5|a;return{b:e,r:t}},pe=he(Qe,2),ue=pe.b,Rt=pe.r;ue[28]=258,Rt[258]=28;var kt=he(de,0),St=kt.b,xA=new nA(32768);for(var M=0;M<32768;++M){var eA=(M&43690)>>1|(M&21845)<<1;eA=(eA&52428)>>2|(eA&13107)<<2,eA=(eA&61680)>>4|(eA&3855)<<4,xA[M]=((eA&65280)>>8|(eA&255)<<8)>>1}var IA=function(n,A,e){for(var a=n.length,t=0,i=new nA(A);t<a;++t)n[t]&&++i[n[t]-1];var s=new nA(A);for(t=1;t<A;++t)s[t]=s[t-1]+i[t-1]<<1;var o;if(e){o=new nA(1<<A);var r=15-A;for(t=0;t<a;++t)if(n[t])for(var c=t<<4|n[t],B=A-n[t],I=s[n[t]-1]++<<B,l=I|(1<<B)-1;I<=l;++I)o[xA[I]>>r]=c}else for(o=new nA(a),t=0;t<a;++t)n[t]&&(o[t]=xA[s[n[t]-1]++]>>15-n[t]);return o},BA=new v(288);for(var M=0;M<144;++M)BA[M]=8;for(var M=144;M<256;++M)BA[M]=9;for(var M=256;M<280;++M)BA[M]=7;for(var M=280;M<288;++M)BA[M]=8;var me=new v(32);for(var M=0;M<32;++M)me[M]=5;var yt=IA(BA,9,1),Gt=IA(me,5,1),FA=function(n){for(var A=n[0],e=1;e<n.length;++e)n[e]>A&&(A=n[e]);return A},K=function(n,A,e){var a=A/8|0;return(n[a]|n[a+1]<<8)>>(A&7)&e},RA=function(n,A){var e=A/8|0;return(n[e]|n[e+1]<<8|n[e+2]<<16)>>(A&7)},xt=function(n){return(n+7)/8|0},UA=function(n,A,e){return(A==null||A<0)&&(A=0),(e==null||e>n.length)&&(e=n.length),new v(n.subarray(A,e))},Lt=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],j=function(n,A,e){var a=new Error(A||Lt[n]);if(a.code=n,Error.captureStackTrace&&Error.captureStackTrace(a,j),!e)throw a;return a},Tt=function(n,A,e,a){var t=n.length,i=a?a.length:0;if(!t||A.f&&!A.l)return e||new v(0);var s=!e,o=s||A.i!=2,r=A.i;s&&(e=new v(t*3));var c=function(OA){var vA=e.length;if(OA>vA){var PA=new v(Math.max(vA*2,OA));PA.set(e),e=PA}},B=A.f||0,I=A.p||0,l=A.b||0,C=A.l,E=A.d,h=A.m,u=A.n,Q=t*8;do{if(!C){B=K(n,I,1);var f=K(n,I+1,3);if(I+=3,f)if(f==1)C=yt,E=Gt,h=9,u=5;else if(f==2){var S=K(n,I,31)+257,x=K(n,I+10,15)+4,U=S+K(n,I+5,31)+1;I+=14;for(var b=new v(U),d=new v(19),w=0;w<x;++w)d[Ft[w]]=K(n,I+w*3,7);I+=x*3;for(var F=FA(d),D=(1<<F)-1,y=IA(d,F,1),w=0;w<U;){var k=y[K(n,I,D)];I+=k&15;var p=k>>4;if(p<16)b[w++]=p;else{var L=0,T=0;for(p==16?(T=3+K(n,I,3),I+=2,L=b[w-1]):p==17?(T=3+K(n,I,7),I+=3):p==18&&(T=11+K(n,I,127),I+=7);T--;)b[w++]=L}}var N=b.subarray(0,S),H=b.subarray(S);h=FA(N),u=FA(H),C=IA(N,h,1),E=IA(H,u,1)}else j(1);else{var p=xt(I)+4,m=n[p-4]|n[p-3]<<8,R=p+m;if(R>t){r&&j(0);break}o&&c(l+m),e.set(n.subarray(p,R),l),A.b=l+=m,A.p=I=R*8,A.f=B;continue}if(I>Q){r&&j(0);break}}o&&c(l+131072);for(var J=(1<<h)-1,$=(1<<u)-1,iA=I;;iA=I){var L=C[RA(n,I)&J],tA=L>>4;if(I+=L&15,I>Q){r&&j(0);break}if(L||j(2),tA<256)e[l++]=tA;else if(tA==256){iA=I,C=null;break}else{var _A=tA-254;if(tA>264){var w=tA-257,rA=Qe[w];_A=K(n,I,(1<<rA)-1)+ue[w],I+=rA}var lA=E[RA(n,I)&$],CA=lA>>4;lA||j(3),I+=lA&15;var H=St[CA];if(CA>3){var rA=de[CA];H+=RA(n,I)&(1<<rA)-1,I+=rA}if(I>Q){r&&j(0);break}o&&c(l+131072);var qA=l+_A;if(l<H){var HA=i-H,De=Math.min(H,qA);for(HA+l<0&&j(3);l<De;++l)e[l]=a[HA+l]}for(;l<qA;++l)e[l]=e[l-H]}}A.l=C,A.p=iA,A.b=l,A.f=B,C&&(B=1,A.m=h,A.d=E,A.n=u)}while(!B);return l!=e.length&&s?UA(e,0,l):e.subarray(0,l)},Mt=new v(0),W=function(n,A){return n[A]|n[A+1]<<8},Y=function(n,A){return(n[A]|n[A+1]<<8|n[A+2]<<16|n[A+3]<<24)>>>0},kA=function(n,A){return Y(n,A)+Y(n,A+4)*4294967296};function Ut(n,A){return Tt(n,{i:2},A&&A.out,A&&A.dictionary)}var LA=typeof TextDecoder<"u"&&new TextDecoder,Nt=0;try{LA.decode(Mt,{stream:!0}),Nt=1}catch{}var _t=function(n){for(var A="",e=0;;){var a=n[e++],t=(a>127)+(a>223)+(a>239);if(e+t>n.length)return{s:A,r:UA(n,e-1)};t?t==3?(a=((a&15)<<18|(n[e++]&63)<<12|(n[e++]&63)<<6|n[e++]&63)-65536,A+=String.fromCharCode(55296|a>>10,56320|a&1023)):t&1?A+=String.fromCharCode((a&31)<<6|n[e++]&63):A+=String.fromCharCode((a&15)<<12|(n[e++]&63)<<6|n[e++]&63):A+=String.fromCharCode(a)}};function TA(n,A){if(A){for(var e="",a=0;a<n.length;a+=16384)e+=String.fromCharCode.apply(null,n.subarray(a,a+16384));return e}else{if(LA)return LA.decode(n);var t=_t(n),i=t.s,e=t.r;return e.length&&j(8),i}}var qt=function(n,A){return A+30+W(n,A+26)+W(n,A+28)},Ht=function(n,A,e){var a=W(n,A+28),t=TA(n.subarray(A+46,A+46+a),!(W(n,A+8)&2048)),i=A+46+a,s=Y(n,A+20),o=e&&s==4294967295?Ot(n,i):[s,Y(n,A+24),Y(n,A+42)],r=o[0],c=o[1],B=o[2];return[W(n,A+10),r,c,t,i+W(n,A+30)+W(n,A+32),B]},Ot=function(n,A){for(;W(n,A)!=1;A+=4+W(n,A+2));return[kA(n,A+12),kA(n,A+4),kA(n,A+20)]};function vt(n,A){for(var e={},a=n.length-22;Y(n,a)!=101010256;--a)(!a||n.length-a>65558)&&j(13);var t=W(n,a+8);if(!t)return{};var i=Y(n,a+16),s=i==4294967295||t==65535;if(s){var o=Y(n,a-12);s=Y(n,o)==101075792,s&&(t=Y(n,o+32),i=Y(n,o+48))}for(var r=0;r<t;++r){var c=Ht(n,i,s),B=c[0],I=c[1],l=c[2],C=c[3],E=c[4],h=c[5],u=qt(n,h);i=E,B?B==8?e[C]=Ut(n.subarray(u,u+I),{out:new v(l)}):j(14,"unknown compression type "+B):e[C]=UA(n,u,u+I)}return e}class Pt{parse(A){const e={},a=A.split(`
|
|
9
|
-
`);let t=null,i=e;const s=[e];for(const o of a)if(o.includes("=")){const r=o.split("="),c=r[0].trim(),B=r[1].trim();if(B.endsWith("{")){const I={};s.push(I),i[c]=I,i=I}else if(B.endsWith("(")){const I=B.slice(0,-1);i[c]=I;const l={};s.push(l),i=l}else i[c]=B}else if(o.endsWith("{")){const r=i[t]||{};s.push(r),i[t]=r,i=r}else if(o.endsWith("}")){if(s.pop(),s.length===0)continue;i=s[s.length-1]}else if(o.endsWith("(")){const r={};s.push(r),t=o.split("(")[0].trim()||t,i[t]=r,i=r}else o.endsWith(")")?(s.pop(),i=s[s.length-1]):t=o.trim();return e}}class jt extends g.Loader{constructor(A){super(A)}load(A,e,a,t){const i=this,s=new g.FileLoader(i.manager);s.setPath(i.path),s.setResponseType("arraybuffer"),s.setRequestHeader(i.requestHeader),s.setWithCredentials(i.withCredentials),s.load(A,function(o){try{e(i.parse(o))}catch(r){t?t(r):console.error(r),i.manager.itemError(A)}},a,t)}parse(A){const e=new Pt;function a(b){const d={};new g.FileLoader().setResponseType("arraybuffer");for(const F in b){if(F.endsWith("png")){const D=new Blob([b[F]],{type:{type:"image/png"}});d[F]=URL.createObjectURL(D)}if(F.endsWith("usd")||F.endsWith("usda")){if(t(b[F]))throw Error("THREE.USDZLoader: Crate files (.usdc or binary .usd) are not supported.");const D=TA(b[F]);d[F]=e.parse(D)}}return d}function t(b){const d=b.slice(0,7),w=new Uint8Array([80,88,82,45,85,83,68,67]);return d.every((F,D)=>F===w[D])}function i(b){if(b.length<1)return;const d=Object.keys(b)[0];let w=!1;if(d.endsWith("usda"))return b[d];if(d.endsWith("usdc"))w=!0;else if(d.endsWith("usd"))if(t(b[d]))w=!0;else return b[d];if(w)throw Error("THREE.USDZLoader: Crate files (.usdc or binary .usd) are not supported.")}const s=vt(new Uint8Array(A)),o=a(s),r=i(s),c=TA(r),B=e.parse(c);function I(b){if(b){if("prepend references"in b){const w=b["prepend references"].split("@"),F=w[1].replace(/^.\//,""),D=w[2].replace(/^<\//,"").replace(/>$/,"");return l(o[F],D)}return l(b)}}function l(b,d){if(b){if(d!==void 0){const w=`def Mesh "${d}"`;if(w in b)return b[w]}for(const w in b){const F=b[w];if(w.startsWith("def Mesh"))return F;if(typeof F=="object"){const D=l(F);if(D)return D}}}}function C(b){if(!b)return;const d=new g.BufferGeometry;let w=null,F=null,D=null,y=-1;if("int[] faceVertexIndices"in b&&(w=JSON.parse(b["int[] faceVertexIndices"])),"int[] faceVertexCounts"in b&&(F=JSON.parse(b["int[] faceVertexCounts"]),w=E(w,F)),"point3f[] points"in b){const k=JSON.parse(b["point3f[] points"].replace(/[()]*/g,""));y=k.length;let L=new g.BufferAttribute(new Float32Array(k),3);w!==null&&(L=h(L,w)),d.setAttribute("position",L)}if("float2[] primvars:st"in b&&(b["texCoord2f[] primvars:st"]=b["float2[] primvars:st"]),"texCoord2f[] primvars:st"in b){D=JSON.parse(b["texCoord2f[] primvars:st"].replace(/[()]*/g,""));let k=new g.BufferAttribute(new Float32Array(D),2);w!==null&&(k=h(k,w)),d.setAttribute("uv",k)}if("int[] primvars:st:indices"in b&&D!==null){const k=new g.BufferAttribute(new Float32Array(D),2);let L=JSON.parse(b["int[] primvars:st:indices"]);L=E(L,F),d.setAttribute("uv",h(k,L))}if("normal3f[] normals"in b){const k=JSON.parse(b["normal3f[] normals"].replace(/[()]*/g,""));let L=new g.BufferAttribute(new Float32Array(k),3);if(k.length===y)w!==null&&(L=h(L,w));else{let T=Array.from(Array(k.length/3).keys());T=E(T,F),L=h(L,T)}d.setAttribute("normal",L)}else d.computeVertexNormals();return d}function E(b,d){const w=[];for(let F=0;F<d.length;F++){const D=d[F],y=F*D;if(D===3){const k=b[y+0],L=b[y+1],T=b[y+2];w.push(k,L,T)}else if(D===4){const k=b[y+0],L=b[y+1],T=b[y+2],N=b[y+3];w.push(k,L,T),w.push(k,T,N)}else console.warn("THREE.USDZLoader: Face vertex count of %s unsupported.",D)}return w}function h(b,d){const w=b.array,F=b.itemSize,D=new w.constructor(d.length*F);let y=0,k=0;for(let L=0,T=d.length;L<T;L++){y=d[L]*F;for(let N=0;N<F;N++)D[k++]=w[y++]}return new g.BufferAttribute(D,F)}function u(b){if(b){if("rel material:binding"in b){const F=b["rel material:binding"].replace(/^<\//,"").replace(/>$/,"").split("/");return Q(B,` "${F[1]}"`)}return Q(b)}}function Q(b,d=""){for(const w in b){const F=b[w];if(w.startsWith("def Material"+d))return F;if(typeof F=="object"){const D=Q(F,d);if(D)return D}}}function f(b,d){d["float inputs:rotation"]&&(b.rotation=parseFloat(d["float inputs:rotation"])),d["float2 inputs:scale"]&&(b.repeat=new g.Vector2().fromArray(JSON.parse("["+d["float2 inputs:scale"].replace(/[()]*/g,"")+"]"))),d["float2 inputs:translation"]&&(b.offset=new g.Vector2().fromArray(JSON.parse("["+d["float2 inputs:translation"].replace(/[()]*/g,"")+"]")))}function p(b){const d=new g.MeshPhysicalMaterial;if(b!==void 0){const w=b["token outputs:surface.connect"],F=/(\w+).output/.exec(w)[1],D=b[`def Shader "${F}"`];if(D!==void 0){if("color3f inputs:diffuseColor.connect"in D){const y=D["color3f inputs:diffuseColor.connect"],k=m(B,/(\w+).output/.exec(y)[1]);d.map=R(k),d.map.colorSpace=g.SRGBColorSpace,'def Shader "Transform2d_diffuse"'in b&&f(d.map,b['def Shader "Transform2d_diffuse"'])}else if("color3f inputs:diffuseColor"in D){const y=D["color3f inputs:diffuseColor"].replace(/[()]*/g,"");d.color.fromArray(JSON.parse("["+y+"]"))}if("color3f inputs:emissiveColor.connect"in D){const y=D["color3f inputs:emissiveColor.connect"],k=m(B,/(\w+).output/.exec(y)[1]);d.emissiveMap=R(k),d.emissiveMap.colorSpace=g.SRGBColorSpace,d.emissive.set(16777215),'def Shader "Transform2d_emissive"'in b&&f(d.emissiveMap,b['def Shader "Transform2d_emissive"'])}else if("color3f inputs:emissiveColor"in D){const y=D["color3f inputs:emissiveColor"].replace(/[()]*/g,"");d.emissive.fromArray(JSON.parse("["+y+"]"))}if("normal3f inputs:normal.connect"in D){const y=D["normal3f inputs:normal.connect"],k=m(B,/(\w+).output/.exec(y)[1]);d.normalMap=R(k),d.normalMap.colorSpace=g.NoColorSpace,'def Shader "Transform2d_normal"'in b&&f(d.normalMap,b['def Shader "Transform2d_normal"'])}if("float inputs:roughness.connect"in D){const y=D["float inputs:roughness.connect"],k=m(B,/(\w+).output/.exec(y)[1]);d.roughness=1,d.roughnessMap=R(k),d.roughnessMap.colorSpace=g.NoColorSpace,'def Shader "Transform2d_roughness"'in b&&f(d.roughnessMap,b['def Shader "Transform2d_roughness"'])}else"float inputs:roughness"in D&&(d.roughness=parseFloat(D["float inputs:roughness"]));if("float inputs:metallic.connect"in D){const y=D["float inputs:metallic.connect"],k=m(B,/(\w+).output/.exec(y)[1]);d.metalness=1,d.metalnessMap=R(k),d.metalnessMap.colorSpace=g.NoColorSpace,'def Shader "Transform2d_metallic"'in b&&f(d.metalnessMap,b['def Shader "Transform2d_metallic"'])}else"float inputs:metallic"in D&&(d.metalness=parseFloat(D["float inputs:metallic"]));if("float inputs:clearcoat.connect"in D){const y=D["float inputs:clearcoat.connect"],k=m(B,/(\w+).output/.exec(y)[1]);d.clearcoat=1,d.clearcoatMap=R(k),d.clearcoatMap.colorSpace=g.NoColorSpace,'def Shader "Transform2d_clearcoat"'in b&&f(d.clearcoatMap,b['def Shader "Transform2d_clearcoat"'])}else"float inputs:clearcoat"in D&&(d.clearcoat=parseFloat(D["float inputs:clearcoat"]));if("float inputs:clearcoatRoughness.connect"in D){const y=D["float inputs:clearcoatRoughness.connect"],k=m(B,/(\w+).output/.exec(y)[1]);d.clearcoatRoughness=1,d.clearcoatRoughnessMap=R(k),d.clearcoatRoughnessMap.colorSpace=g.NoColorSpace,'def Shader "Transform2d_clearcoatRoughness"'in b&&f(d.clearcoatRoughnessMap,b['def Shader "Transform2d_clearcoatRoughness"'])}else"float inputs:clearcoatRoughness"in D&&(d.clearcoatRoughness=parseFloat(D["float inputs:clearcoatRoughness"]));if("float inputs:ior"in D&&(d.ior=parseFloat(D["float inputs:ior"])),"float inputs:occlusion.connect"in D){const y=D["float inputs:occlusion.connect"],k=m(B,/(\w+).output/.exec(y)[1]);d.aoMap=R(k),d.aoMap.colorSpace=g.NoColorSpace,'def Shader "Transform2d_occlusion"'in b&&f(d.aoMap,b['def Shader "Transform2d_occlusion"'])}}}return d}function m(b,d){for(const w in b){const F=b[w];if(w.startsWith(`def Shader "${d}"`))return F;if(typeof F=="object"){const D=m(F,d);if(D)return D}}}function R(b){if("asset inputs:file"in b){const d=b["asset inputs:file"].replace(/@*/g,"").trim(),F=new g.TextureLoader().load(o[d]),D={'"clamp"':g.ClampToEdgeWrapping,'"mirror"':g.MirroredRepeatWrapping,'"repeat"':g.RepeatWrapping};return"token inputs:wrapS"in b&&(F.wrapS=D[b["token inputs:wrapS"]]),"token inputs:wrapT"in b&&(F.wrapT=D[b["token inputs:wrapT"]]),F}return null}function S(b){const d=C(I(b)),w=p(u(b)),F=d?new g.Mesh(d,w):new g.Object3D;if("matrix4d xformOp:transform"in b){const D=JSON.parse("["+b["matrix4d xformOp:transform"].replace(/[()]*/g,"")+"]");F.matrix.fromArray(D),F.matrix.decompose(F.position,F.quaternion,F.scale)}return F}function x(b,d){for(const w in b)if(w.startsWith("def Scope"))x(b[w],d);else if(w.startsWith("def Xform")){const F=S(b[w]);/def Xform "(\w+)"/.test(w)&&(F.name=/def Xform "(\w+)"/.exec(w)[1]),d.add(F),x(b[w],F)}}const U=new g.Group;return x(B,U),U}}function Jt(){const n=new jt;return n.manager.onError=A=>{X.emit("load-error",`Failed to load file ${A}`)},n}function Kt(n){const A=q.useCallback(async(a,t,i)=>{var B,I;const s=new Map(t.map(l=>[l.name,l])),o=(((B=a.buffers)==null?void 0:B.length)||0)+(((I=a.images)==null?void 0:I.length)||0);let r=0;const c=()=>{r++,i(r/o*100)};if(a.buffers)for(let l=0;l<a.buffers.length;l++){const C=a.buffers[l];if(!C.uri||C.uri.startsWith("data:")){c();continue}const E=C.uri.split("/").pop()||"",h=s.get(E);if(h){const u=await h.arrayBuffer(),Q=await jA(u);C.uri=`data:application/octet-stream;base64,${Q}`}c()}if(a.images)for(let l=0;l<a.images.length;l++){const C=a.images[l];if(!C.uri||C.uri.startsWith("data:")){c();continue}const E=C.uri.split("/").pop()||"",h=s.get(E);if(h){const u=await h.arrayBuffer(),Q=await jA(u),f=h.type||"image/png";C.uri=`data:${f};base64,${Q}`}c()}return a},[]);return{loadGltf:q.useCallback((a,t,i)=>{const s=new FileReader;s.onload=async o=>{var I;const r=JSON.parse((I=o.target)==null?void 0:I.result);i(10);const c=await A(r,t,l=>{i(10+l*.8)});MA().parse(JSON.stringify(c),"",l=>{n({type:"set-file",payload:{model:l.scene,type:O.gltf,name:a.name}})}),i(100),n({type:"set-file-loading",payload:!1})},s.readAsText(a)},[n,A])}}function Yt(n){return{loadBinary:q.useCallback((e,a,t)=>{const i=new FileReader;i.onload=async s=>{var o;if((o=s.target)!=null&&o.result){const r=s.target.result;if(a===O.glb)MA().parse(r,"",B=>{n({type:"set-file",payload:{model:B.scene,type:O.glb,name:e.name}})});else if(a===O.usdz){const B=Jt().parse(r);n({type:"set-file",payload:{model:B,type:O.usdz,name:e.name}})}t(),n({type:"set-file-loading",payload:!1})}},i.onerror=s=>{console.error("Error reading file:",s),n({type:"set-file-loading",payload:!1})},i.readAsArrayBuffer(e)},[n])}}function we(n){const A=q.useRef(!1),[e,a]=q.useReducer(Re,Ae),{loadGltf:t}=Kt(a),{loadBinary:i}=Yt(a),s=q.useCallback((l,C)=>l.find(E=>E.name.endsWith("."+C)),[]),o=q.useCallback(l=>{a({type:"set-progress",payload:l}),X.emit("load-progress",l)},[]),r=q.useCallback(()=>{a({type:"reset-state"}),X.emit("load-reset")},[]),c=q.useCallback(l=>{if(l.length===0)return;const C=s(l,O.gltf),E=s(l,O.glb),h=s(l,O.usdz),u=[C,E,h].filter(Boolean);if(u.length>1){X.emit("multiple-models",u);return}const Q=l.filter(p=>p!==C&&p!==E&&p!==h),f=p=>{o(p),p===100&&(A.current=!0)};if(C)t(C,Q,f);else if(E)i(E,O.glb,()=>f(100));else if(h)i(h,O.usdz,()=>f(100));else{X.emit("not-loaded-files",l),a({type:"set-file-loading",payload:!1});return}},[o,s,t,i]),B=q.useCallback(async l=>{const C=[];a({type:"reset-state"}),a({type:"set-file-loading",payload:!0}),o(0),A.current=!1;for(const E of l)if(E instanceof File)C.push(E);else if("kind"in E&&E.kind==="directory"){const h=await ke(E);C.push(...h)}c(C)},[c,o]);q.useEffect(()=>{A.current&&e.file&&(X.emit("load-complete",e.file),A.current=!1,n&&n.load(e.file.model))},[e.file,n]);const I=Wt(n,a,e.file);return{...e,on:X.on,off:X.off,load:B,reset:r,optimize:I}}function Wt(n,A,e){const a=q.useCallback(i=>{console.log("Dispatching new model"),MA().parse(i.buffer,"",o=>{console.log("Loaded new model"),A({type:"set-file",payload:{model:o.scene,type:O.glb,name:(e==null?void 0:e.name)||"optimized.glb"}})},o=>{console.error("Error loading new model:",o)})},[A,e]),t=q.useCallback(async i=>{if(!n||!i){console.warn("Optimizer or optimization function is not available");return}try{await i();const s=await n.getModel();s&&a(s)}catch(s){console.error("Optimization failed:",s)}},[n,a]);return n?{simplifyOptimization:()=>t(n.simplifyOptimization),dedupOptimization:()=>t(n.dedupOptimization),quantizeOptimization:()=>t(n.quantizeOptimization)}:{simplifyOptimization:()=>{console.warn("Optimizer is not available")},dedupOptimization:()=>{console.warn("Optimizer is not available")},quantizeOptimization:()=>{console.warn("Optimizer is not available")}}}const NA=q.createContext({}),Vt=({children:n,optimizer:A})=>{const e=we(A);return Fe.jsx(NA.Provider,{value:e,children:n})},zt=()=>q.useContext(NA);exports.ModelContext=NA;exports.ModelFileTypes=O;exports.ModelProvider=Vt;exports.useLoadModel=we;exports.useModelContext=zt;
|
|
9
|
+
`);let t=null,i=e;const s=[e];for(const o of a)if(o.includes("=")){const r=o.split("="),c=r[0].trim(),B=r[1].trim();if(B.endsWith("{")){const I={};s.push(I),i[c]=I,i=I}else if(B.endsWith("(")){const I=B.slice(0,-1);i[c]=I;const l={};s.push(l),i=l}else i[c]=B}else if(o.endsWith("{")){const r=i[t]||{};s.push(r),i[t]=r,i=r}else if(o.endsWith("}")){if(s.pop(),s.length===0)continue;i=s[s.length-1]}else if(o.endsWith("(")){const r={};s.push(r),t=o.split("(")[0].trim()||t,i[t]=r,i=r}else o.endsWith(")")?(s.pop(),i=s[s.length-1]):t=o.trim();return e}}class jt extends g.Loader{constructor(A){super(A)}load(A,e,a,t){const i=this,s=new g.FileLoader(i.manager);s.setPath(i.path),s.setResponseType("arraybuffer"),s.setRequestHeader(i.requestHeader),s.setWithCredentials(i.withCredentials),s.load(A,function(o){try{e(i.parse(o))}catch(r){t?t(r):console.error(r),i.manager.itemError(A)}},a,t)}parse(A){const e=new Pt;function a(b){const d={};new g.FileLoader().setResponseType("arraybuffer");for(const F in b){if(F.endsWith("png")){const D=new Blob([b[F]],{type:{type:"image/png"}});d[F]=URL.createObjectURL(D)}if(F.endsWith("usd")||F.endsWith("usda")){if(t(b[F]))throw Error("THREE.USDZLoader: Crate files (.usdc or binary .usd) are not supported.");const D=TA(b[F]);d[F]=e.parse(D)}}return d}function t(b){const d=b.slice(0,7),w=new Uint8Array([80,88,82,45,85,83,68,67]);return d.every((F,D)=>F===w[D])}function i(b){if(b.length<1)return;const d=Object.keys(b)[0];let w=!1;if(d.endsWith("usda"))return b[d];if(d.endsWith("usdc"))w=!0;else if(d.endsWith("usd"))if(t(b[d]))w=!0;else return b[d];if(w)throw Error("THREE.USDZLoader: Crate files (.usdc or binary .usd) are not supported.")}const s=vt(new Uint8Array(A)),o=a(s),r=i(s),c=TA(r),B=e.parse(c);function I(b){if(b){if("prepend references"in b){const w=b["prepend references"].split("@"),F=w[1].replace(/^.\//,""),D=w[2].replace(/^<\//,"").replace(/>$/,"");return l(o[F],D)}return l(b)}}function l(b,d){if(b){if(d!==void 0){const w=`def Mesh "${d}"`;if(w in b)return b[w]}for(const w in b){const F=b[w];if(w.startsWith("def Mesh"))return F;if(typeof F=="object"){const D=l(F);if(D)return D}}}}function C(b){if(!b)return;const d=new g.BufferGeometry;let w=null,F=null,D=null,y=-1;if("int[] faceVertexIndices"in b&&(w=JSON.parse(b["int[] faceVertexIndices"])),"int[] faceVertexCounts"in b&&(F=JSON.parse(b["int[] faceVertexCounts"]),w=E(w,F)),"point3f[] points"in b){const k=JSON.parse(b["point3f[] points"].replace(/[()]*/g,""));y=k.length;let L=new g.BufferAttribute(new Float32Array(k),3);w!==null&&(L=h(L,w)),d.setAttribute("position",L)}if("float2[] primvars:st"in b&&(b["texCoord2f[] primvars:st"]=b["float2[] primvars:st"]),"texCoord2f[] primvars:st"in b){D=JSON.parse(b["texCoord2f[] primvars:st"].replace(/[()]*/g,""));let k=new g.BufferAttribute(new Float32Array(D),2);w!==null&&(k=h(k,w)),d.setAttribute("uv",k)}if("int[] primvars:st:indices"in b&&D!==null){const k=new g.BufferAttribute(new Float32Array(D),2);let L=JSON.parse(b["int[] primvars:st:indices"]);L=E(L,F),d.setAttribute("uv",h(k,L))}if("normal3f[] normals"in b){const k=JSON.parse(b["normal3f[] normals"].replace(/[()]*/g,""));let L=new g.BufferAttribute(new Float32Array(k),3);if(k.length===y)w!==null&&(L=h(L,w));else{let T=Array.from(Array(k.length/3).keys());T=E(T,F),L=h(L,T)}d.setAttribute("normal",L)}else d.computeVertexNormals();return d}function E(b,d){const w=[];for(let F=0;F<d.length;F++){const D=d[F],y=F*D;if(D===3){const k=b[y+0],L=b[y+1],T=b[y+2];w.push(k,L,T)}else if(D===4){const k=b[y+0],L=b[y+1],T=b[y+2],N=b[y+3];w.push(k,L,T),w.push(k,T,N)}else console.warn("THREE.USDZLoader: Face vertex count of %s unsupported.",D)}return w}function h(b,d){const w=b.array,F=b.itemSize,D=new w.constructor(d.length*F);let y=0,k=0;for(let L=0,T=d.length;L<T;L++){y=d[L]*F;for(let N=0;N<F;N++)D[k++]=w[y++]}return new g.BufferAttribute(D,F)}function u(b){if(b){if("rel material:binding"in b){const F=b["rel material:binding"].replace(/^<\//,"").replace(/>$/,"").split("/");return Q(B,` "${F[1]}"`)}return Q(b)}}function Q(b,d=""){for(const w in b){const F=b[w];if(w.startsWith("def Material"+d))return F;if(typeof F=="object"){const D=Q(F,d);if(D)return D}}}function f(b,d){d["float inputs:rotation"]&&(b.rotation=parseFloat(d["float inputs:rotation"])),d["float2 inputs:scale"]&&(b.repeat=new g.Vector2().fromArray(JSON.parse("["+d["float2 inputs:scale"].replace(/[()]*/g,"")+"]"))),d["float2 inputs:translation"]&&(b.offset=new g.Vector2().fromArray(JSON.parse("["+d["float2 inputs:translation"].replace(/[()]*/g,"")+"]")))}function p(b){const d=new g.MeshPhysicalMaterial;if(b!==void 0){const w=b["token outputs:surface.connect"],F=/(\w+).output/.exec(w)[1],D=b[`def Shader "${F}"`];if(D!==void 0){if("color3f inputs:diffuseColor.connect"in D){const y=D["color3f inputs:diffuseColor.connect"],k=m(B,/(\w+).output/.exec(y)[1]);d.map=R(k),d.map.colorSpace=g.SRGBColorSpace,'def Shader "Transform2d_diffuse"'in b&&f(d.map,b['def Shader "Transform2d_diffuse"'])}else if("color3f inputs:diffuseColor"in D){const y=D["color3f inputs:diffuseColor"].replace(/[()]*/g,"");d.color.fromArray(JSON.parse("["+y+"]"))}if("color3f inputs:emissiveColor.connect"in D){const y=D["color3f inputs:emissiveColor.connect"],k=m(B,/(\w+).output/.exec(y)[1]);d.emissiveMap=R(k),d.emissiveMap.colorSpace=g.SRGBColorSpace,d.emissive.set(16777215),'def Shader "Transform2d_emissive"'in b&&f(d.emissiveMap,b['def Shader "Transform2d_emissive"'])}else if("color3f inputs:emissiveColor"in D){const y=D["color3f inputs:emissiveColor"].replace(/[()]*/g,"");d.emissive.fromArray(JSON.parse("["+y+"]"))}if("normal3f inputs:normal.connect"in D){const y=D["normal3f inputs:normal.connect"],k=m(B,/(\w+).output/.exec(y)[1]);d.normalMap=R(k),d.normalMap.colorSpace=g.NoColorSpace,'def Shader "Transform2d_normal"'in b&&f(d.normalMap,b['def Shader "Transform2d_normal"'])}if("float inputs:roughness.connect"in D){const y=D["float inputs:roughness.connect"],k=m(B,/(\w+).output/.exec(y)[1]);d.roughness=1,d.roughnessMap=R(k),d.roughnessMap.colorSpace=g.NoColorSpace,'def Shader "Transform2d_roughness"'in b&&f(d.roughnessMap,b['def Shader "Transform2d_roughness"'])}else"float inputs:roughness"in D&&(d.roughness=parseFloat(D["float inputs:roughness"]));if("float inputs:metallic.connect"in D){const y=D["float inputs:metallic.connect"],k=m(B,/(\w+).output/.exec(y)[1]);d.metalness=1,d.metalnessMap=R(k),d.metalnessMap.colorSpace=g.NoColorSpace,'def Shader "Transform2d_metallic"'in b&&f(d.metalnessMap,b['def Shader "Transform2d_metallic"'])}else"float inputs:metallic"in D&&(d.metalness=parseFloat(D["float inputs:metallic"]));if("float inputs:clearcoat.connect"in D){const y=D["float inputs:clearcoat.connect"],k=m(B,/(\w+).output/.exec(y)[1]);d.clearcoat=1,d.clearcoatMap=R(k),d.clearcoatMap.colorSpace=g.NoColorSpace,'def Shader "Transform2d_clearcoat"'in b&&f(d.clearcoatMap,b['def Shader "Transform2d_clearcoat"'])}else"float inputs:clearcoat"in D&&(d.clearcoat=parseFloat(D["float inputs:clearcoat"]));if("float inputs:clearcoatRoughness.connect"in D){const y=D["float inputs:clearcoatRoughness.connect"],k=m(B,/(\w+).output/.exec(y)[1]);d.clearcoatRoughness=1,d.clearcoatRoughnessMap=R(k),d.clearcoatRoughnessMap.colorSpace=g.NoColorSpace,'def Shader "Transform2d_clearcoatRoughness"'in b&&f(d.clearcoatRoughnessMap,b['def Shader "Transform2d_clearcoatRoughness"'])}else"float inputs:clearcoatRoughness"in D&&(d.clearcoatRoughness=parseFloat(D["float inputs:clearcoatRoughness"]));if("float inputs:ior"in D&&(d.ior=parseFloat(D["float inputs:ior"])),"float inputs:occlusion.connect"in D){const y=D["float inputs:occlusion.connect"],k=m(B,/(\w+).output/.exec(y)[1]);d.aoMap=R(k),d.aoMap.colorSpace=g.NoColorSpace,'def Shader "Transform2d_occlusion"'in b&&f(d.aoMap,b['def Shader "Transform2d_occlusion"'])}}}return d}function m(b,d){for(const w in b){const F=b[w];if(w.startsWith(`def Shader "${d}"`))return F;if(typeof F=="object"){const D=m(F,d);if(D)return D}}}function R(b){if("asset inputs:file"in b){const d=b["asset inputs:file"].replace(/@*/g,"").trim(),F=new g.TextureLoader().load(o[d]),D={'"clamp"':g.ClampToEdgeWrapping,'"mirror"':g.MirroredRepeatWrapping,'"repeat"':g.RepeatWrapping};return"token inputs:wrapS"in b&&(F.wrapS=D[b["token inputs:wrapS"]]),"token inputs:wrapT"in b&&(F.wrapT=D[b["token inputs:wrapT"]]),F}return null}function S(b){const d=C(I(b)),w=p(u(b)),F=d?new g.Mesh(d,w):new g.Object3D;if("matrix4d xformOp:transform"in b){const D=JSON.parse("["+b["matrix4d xformOp:transform"].replace(/[()]*/g,"")+"]");F.matrix.fromArray(D),F.matrix.decompose(F.position,F.quaternion,F.scale)}return F}function x(b,d){for(const w in b)if(w.startsWith("def Scope"))x(b[w],d);else if(w.startsWith("def Xform")){const F=S(b[w]);/def Xform "(\w+)"/.test(w)&&(F.name=/def Xform "(\w+)"/.exec(w)[1]),d.add(F),x(b[w],F)}}const U=new g.Group;return x(B,U),U}}function Jt(){const n=new jt;return n.manager.onError=A=>{X.emit("load-error",`Failed to load file ${A}`)},n}function Kt(n){const A=q.useCallback(async(a,t,i)=>{var B,I;const s=new Map(t.map(l=>[l.name,l])),o=(((B=a.buffers)==null?void 0:B.length)||0)+(((I=a.images)==null?void 0:I.length)||0);let r=0;const c=()=>{r++,i(r/o*100)};if(a.buffers)for(let l=0;l<a.buffers.length;l++){const C=a.buffers[l];if(!C.uri||C.uri.startsWith("data:")){c();continue}const E=C.uri.split("/").pop()||"",h=s.get(E);if(h){const u=await h.arrayBuffer(),Q=await jA(u);C.uri=`data:application/octet-stream;base64,${Q}`}c()}if(a.images)for(let l=0;l<a.images.length;l++){const C=a.images[l];if(!C.uri||C.uri.startsWith("data:")){c();continue}const E=C.uri.split("/").pop()||"",h=s.get(E);if(h){const u=await h.arrayBuffer(),Q=await jA(u),f=h.type||"image/png";C.uri=`data:${f};base64,${Q}`}c()}return a},[]);return{loadGltf:q.useCallback((a,t,i)=>{const s=new FileReader;s.onload=async o=>{var I;const r=JSON.parse((I=o.target)==null?void 0:I.result);i(10);const c=await A(r,t,l=>{i(10+l*.8)});MA().parse(JSON.stringify(c),"",l=>{n({type:"set-file",payload:{model:l.scene,type:O.gltf,name:a.name}})}),i(100),n({type:"set-file-loading",payload:!1})},s.readAsText(a)},[n,A])}}function Yt(n){return{loadBinary:q.useCallback((e,a,t)=>{const i=new FileReader;i.onload=async s=>{var o;if((o=s.target)!=null&&o.result){const r=s.target.result;if(a===O.glb)MA().parse(r,"",B=>{n({type:"set-file",payload:{model:B.scene,type:O.glb,name:e.name}})});else if(a===O.usdz){const B=Jt().parse(r);n({type:"set-file",payload:{model:B,type:O.usdz,name:e.name}})}t(),n({type:"set-file-loading",payload:!1})}},i.onerror=s=>{console.error("Error reading file:",s),n({type:"set-file-loading",payload:!1})},i.readAsArrayBuffer(e)},[n])}}function we(n){const A=q.useRef(!1),[e,a]=q.useReducer(Re,Ae),{loadGltf:t}=Kt(a),{loadBinary:i}=Yt(a),s=q.useCallback((l,C)=>l.find(E=>E.name.endsWith("."+C)),[]),o=q.useCallback(l=>{a({type:"set-progress",payload:l}),X.emit("load-progress",l)},[]),r=q.useCallback(()=>{a({type:"reset-state"}),X.emit("load-reset")},[]),c=q.useCallback(l=>{if(l.length===0)return;const C=s(l,O.gltf),E=s(l,O.glb),h=s(l,O.usdz),u=[C,E,h].filter(Boolean);if(u.length>1){X.emit("multiple-models",u);return}const Q=l.filter(p=>p!==C&&p!==E&&p!==h),f=p=>{o(p),p===100&&(A.current=!0)};if(C)t(C,Q,f);else if(E)i(E,O.glb,()=>f(100));else if(h)i(h,O.usdz,()=>f(100));else{X.emit("not-loaded-files",l),a({type:"set-file-loading",payload:!1});return}},[o,s,t,i]),B=q.useCallback(async l=>{const C=[];a({type:"reset-state"}),a({type:"set-file-loading",payload:!0}),o(0),A.current=!1;for(const E of l)if(E instanceof File)C.push(E);else if("kind"in E&&E.kind==="directory"){const h=await ke(E);C.push(...h)}c(C)},[c,o]);q.useEffect(()=>{A.current&&e.file&&(X.emit("load-complete",e.file),A.current=!1,n&&n.load(e.file.model))},[e.file,n]);const I=Wt(n,a,e.file);return{...e,on:X.on,off:X.off,load:B,reset:r,optimize:I}}function Wt(n,A,e){const a=q.useCallback(i=>{MA().parse(i.buffer,"",o=>{A({type:"set-file",payload:{model:o.scene,type:O.glb,name:(e==null?void 0:e.name)||"optimized.glb"}})},o=>{console.error("Error loading new model:",o)})},[A,e]),t=q.useCallback(async i=>{if(!n||!i){console.warn("Optimizer or optimization function is not available");return}try{await i();const s=await n.getModel();s&&a(s)}catch(s){console.error("Optimization failed:",s)}},[n,a]);return n?{simplifyOptimization:()=>t(n.simplifyOptimization),dedupOptimization:()=>t(n.dedupOptimization),quantizeOptimization:()=>t(n.quantizeOptimization)}:{simplifyOptimization:()=>{console.warn("Optimizer is not available")},dedupOptimization:()=>{console.warn("Optimizer is not available")},quantizeOptimization:()=>{console.warn("Optimizer is not available")}}}const NA=q.createContext({}),Vt=({children:n,optimizer:A})=>{const e=we(A);return Fe.jsx(NA.Provider,{value:e,children:n})},zt=()=>q.useContext(NA);exports.ModelContext=NA;exports.ModelFileTypes=O;exports.ModelProvider=Vt;exports.useLoadModel=we;exports.useModelContext=zt;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as Bt } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback as V, useRef as Ct, useReducer as bt, useEffect as lt, createContext as ft, useContext as Et } from "react";
|
|
3
|
-
import { T as Qt,
|
|
3
|
+
import { T as Qt, t as XA, u as Ge, v as TA, w as mA, F as aA, d as rA, x as Y, y as dt, z as ht, A as pt, E as hA, a as $, G as W, H as SA, s as yA, V as CA, J as ut, K as mt, O as se, X as xe, Y as wt, B as z, Z as Dt, L as GA, o as ie, q as xA, _ as kt, $ as NA, a0 as Ft, a1 as Te, D as Rt, i as St, a2 as ne, a3 as yt, M as Le, a4 as Gt, a5 as xt, a6 as Tt, a7 as Lt, a8 as kA, b as Mt, g as Nt, a9 as Ut, aa as _t, ab as qt, ac as Ht, j as Me, ad as le, Q as Ne, k as Ot, l as vt, n as Jt, m as jt, p as Ue, r as _e, I as Kt, ae as Pt, af as Yt, ag as fe, ah as Ee, ai as Qe, aj as de, ak as Wt, al as Vt, am as zt, an as Xt, ao as K, ap as Zt, e as qe, h as bA, aq as $t, ar as Aa, as as ea, at as ta, au as aa, av as sa, aw as ia, ax as na, ay as oa, az as FA, aA as RA, aB as ra, aC as ca, aD as ga, aE as Ia, N as oA, aF as pA, aG as uA, aH as he, W as Ba } from "./three.module-7bSgh1t6.js";
|
|
4
4
|
const BA = {}, eA = {
|
|
5
5
|
emit(n, A) {
|
|
6
6
|
const e = BA[n];
|
|
@@ -3313,11 +3313,11 @@ function Ls(n) {
|
|
|
3313
3313
|
function Ms(n, A, e) {
|
|
3314
3314
|
const a = V(
|
|
3315
3315
|
(s) => {
|
|
3316
|
-
|
|
3316
|
+
oe().parse(
|
|
3317
3317
|
s.buffer,
|
|
3318
3318
|
"",
|
|
3319
3319
|
(o) => {
|
|
3320
|
-
|
|
3320
|
+
A({
|
|
3321
3321
|
type: "set-file",
|
|
3322
3322
|
payload: {
|
|
3323
3323
|
model: o.scene,
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.3.1",
|
|
3
3
|
"name": "@vctrl/hooks",
|
|
4
4
|
"description": "vctrl/hooks is a React hooks package designed to simplify 3D model loading and management within React applications. It's part of the vectreal-core ecosystem and is primarily used in the vctrl/viewer React component and the official website application.",
|
|
5
5
|
"bugs": {
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"url": "https://github.com/vectreal/vectreal-core",
|
|
28
28
|
"type": "https"
|
|
29
29
|
},
|
|
30
|
+
"license": "AGPL-3.0-only",
|
|
30
31
|
"main": "./index.cjs.js",
|
|
31
32
|
"module": "./index.es.js",
|
|
32
33
|
"types": "./index.d.ts",
|
|
@@ -15970,102 +15970,102 @@ typeof __THREE_DEVTOOLS__ < "u" && __THREE_DEVTOOLS__.dispatchEvent(new CustomEv
|
|
|
15970
15970
|
} }));
|
|
15971
15971
|
typeof window < "u" && (window.__THREE__ ? console.warn("WARNING: Multiple instances of Three.js being imported.") : window.__THREE__ = Br);
|
|
15972
15972
|
export {
|
|
15973
|
-
|
|
15974
|
-
|
|
15973
|
+
Mn as $,
|
|
15974
|
+
kf as A,
|
|
15975
15975
|
Rt as B,
|
|
15976
|
-
|
|
15977
|
-
|
|
15978
|
-
|
|
15976
|
+
Nf as C,
|
|
15977
|
+
qd as D,
|
|
15978
|
+
ma as E,
|
|
15979
15979
|
Of as F,
|
|
15980
|
-
|
|
15981
|
-
|
|
15982
|
-
|
|
15983
|
-
|
|
15984
|
-
|
|
15985
|
-
|
|
15986
|
-
|
|
15987
|
-
|
|
15980
|
+
Ff as G,
|
|
15981
|
+
Fe as H,
|
|
15982
|
+
xf as I,
|
|
15983
|
+
Cf as J,
|
|
15984
|
+
js as K,
|
|
15985
|
+
Qd as L,
|
|
15986
|
+
bt as M,
|
|
15987
|
+
rn as N,
|
|
15988
15988
|
nt as O,
|
|
15989
|
-
|
|
15990
|
-
|
|
15991
|
-
|
|
15992
|
-
|
|
15989
|
+
ji as P,
|
|
15990
|
+
Xn as Q,
|
|
15991
|
+
Br as R,
|
|
15992
|
+
an as S,
|
|
15993
15993
|
Sf as T,
|
|
15994
|
-
|
|
15995
|
-
|
|
15996
|
-
|
|
15997
|
-
|
|
15998
|
-
|
|
15999
|
-
|
|
16000
|
-
|
|
16001
|
-
|
|
16002
|
-
|
|
16003
|
-
|
|
16004
|
-
|
|
16005
|
-
|
|
16006
|
-
|
|
16007
|
-
|
|
16008
|
-
|
|
16009
|
-
|
|
16010
|
-
|
|
16011
|
-
|
|
16012
|
-
|
|
16013
|
-
|
|
16014
|
-
|
|
16015
|
-
|
|
16016
|
-
|
|
16017
|
-
|
|
16018
|
-
|
|
16019
|
-
|
|
16020
|
-
|
|
16021
|
-
|
|
16022
|
-
|
|
16023
|
-
|
|
16024
|
-
|
|
16025
|
-
|
|
16026
|
-
|
|
16027
|
-
|
|
16028
|
-
|
|
16029
|
-
|
|
16030
|
-
|
|
16031
|
-
|
|
16032
|
-
|
|
16033
|
-
|
|
16034
|
-
|
|
16035
|
-
|
|
16036
|
-
|
|
16037
|
-
|
|
16038
|
-
|
|
16039
|
-
|
|
16040
|
-
|
|
16041
|
-
|
|
16042
|
-
|
|
16043
|
-
|
|
16044
|
-
|
|
16045
|
-
|
|
16046
|
-
|
|
16047
|
-
|
|
16048
|
-
|
|
16049
|
-
|
|
16050
|
-
|
|
16051
|
-
|
|
16052
|
-
|
|
16053
|
-
|
|
16054
|
-
|
|
16055
|
-
|
|
16056
|
-
|
|
16057
|
-
|
|
16058
|
-
|
|
16059
|
-
|
|
16060
|
-
|
|
16061
|
-
|
|
16062
|
-
|
|
16063
|
-
|
|
16064
|
-
|
|
16065
|
-
|
|
16066
|
-
|
|
16067
|
-
|
|
16068
|
-
|
|
16069
|
-
|
|
16070
|
-
|
|
15994
|
+
Na as U,
|
|
15995
|
+
I as V,
|
|
15996
|
+
Af as W,
|
|
15997
|
+
zf as X,
|
|
15998
|
+
Wf as Y,
|
|
15999
|
+
Rf as Z,
|
|
16000
|
+
xd as _,
|
|
16001
|
+
Nt as a,
|
|
16002
|
+
vd as a0,
|
|
16003
|
+
Md as a1,
|
|
16004
|
+
$t as a2,
|
|
16005
|
+
wf as a3,
|
|
16006
|
+
Pf as a4,
|
|
16007
|
+
La as a5,
|
|
16008
|
+
Lf as a6,
|
|
16009
|
+
Df as a7,
|
|
16010
|
+
Ii as a8,
|
|
16011
|
+
ya as a9,
|
|
16012
|
+
sf as aA,
|
|
16013
|
+
Ca as aB,
|
|
16014
|
+
ho as aC,
|
|
16015
|
+
Or as aD,
|
|
16016
|
+
$i as aE,
|
|
16017
|
+
lf as aF,
|
|
16018
|
+
of as aG,
|
|
16019
|
+
gf as aH,
|
|
16020
|
+
Pa as aa,
|
|
16021
|
+
Bf as ab,
|
|
16022
|
+
md as ac,
|
|
16023
|
+
We as ad,
|
|
16024
|
+
Xd as ae,
|
|
16025
|
+
wa as af,
|
|
16026
|
+
ut as ag,
|
|
16027
|
+
Ki as ah,
|
|
16028
|
+
Yi as ai,
|
|
16029
|
+
er as aj,
|
|
16030
|
+
ln as ak,
|
|
16031
|
+
Kt as al,
|
|
16032
|
+
Qi as am,
|
|
16033
|
+
Uf as an,
|
|
16034
|
+
nf as ao,
|
|
16035
|
+
If as ap,
|
|
16036
|
+
_f as aq,
|
|
16037
|
+
vf as ar,
|
|
16038
|
+
mf as as,
|
|
16039
|
+
df as at,
|
|
16040
|
+
hf as au,
|
|
16041
|
+
ff as av,
|
|
16042
|
+
pf as aw,
|
|
16043
|
+
uf as ax,
|
|
16044
|
+
cf as ay,
|
|
16045
|
+
rf as az,
|
|
16046
|
+
Et as b,
|
|
16047
|
+
bf as c,
|
|
16048
|
+
Ue as d,
|
|
16049
|
+
Da as e,
|
|
16050
|
+
ua as f,
|
|
16051
|
+
Tf as g,
|
|
16052
|
+
af as h,
|
|
16053
|
+
$e as i,
|
|
16054
|
+
Mf as j,
|
|
16055
|
+
Zd as k,
|
|
16056
|
+
jd as l,
|
|
16057
|
+
Jd as m,
|
|
16058
|
+
ef as n,
|
|
16059
|
+
tf as o,
|
|
16060
|
+
Kd as p,
|
|
16061
|
+
Yd as q,
|
|
16062
|
+
$d as r,
|
|
16063
|
+
Ne as s,
|
|
16064
|
+
Ef as t,
|
|
16065
|
+
yf as u,
|
|
16066
|
+
ci as v,
|
|
16067
|
+
Hf as w,
|
|
16068
|
+
on as x,
|
|
16069
|
+
Gf as y,
|
|
16070
|
+
Vf as z
|
|
16071
16071
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as useExportModel } from './use-export-model';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface URIBufferObject {
|
|
2
|
+
uri: string;
|
|
3
|
+
byteLength: number;
|
|
4
|
+
}
|
|
5
|
+
export interface TexturesObject {
|
|
6
|
+
name: string;
|
|
7
|
+
sampler: number;
|
|
8
|
+
source: number;
|
|
9
|
+
}
|
|
10
|
+
export interface ImageDataObject {
|
|
11
|
+
data?: Uint8Array | ArrayBuffer;
|
|
12
|
+
uri?: string;
|
|
13
|
+
mimeType?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ExportResult {
|
|
16
|
+
buffers?: ArrayBuffer[] | URIBufferObject[];
|
|
17
|
+
images?: ImageDataObject[];
|
|
18
|
+
textures?: TexturesObject[];
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ModelFile } from '../use-load-model';
|
|
2
|
+
/**
|
|
3
|
+
* A React hook for exporting a 3D model from a Three.js scene.
|
|
4
|
+
*
|
|
5
|
+
* @param {Function} [onSaved] Called when the export is complete.
|
|
6
|
+
* @param {Function} [onError] Called when an error occurs during exporting.
|
|
7
|
+
* @returns An object with a single property, `handleGltfExport`. `handleGltfExport` is a function
|
|
8
|
+
* that takes a file object and a boolean indicating whether to export in binary format.
|
|
9
|
+
* It exports the scene in the format specified by the boolean parameter.
|
|
10
|
+
*/
|
|
11
|
+
declare const useExportModel: (onSaved?: () => void, onError?: (error: ErrorEvent) => void) => {
|
|
12
|
+
handleGltfExport: (file: ModelFile | null, binary: boolean) => void;
|
|
13
|
+
};
|
|
14
|
+
export default useExportModel;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { default as JSZip } from 'jszip';
|
|
2
|
+
import { ImageDataObject, TexturesObject, URIBufferObject } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Handles processing and adding images to a zip file.
|
|
5
|
+
*
|
|
6
|
+
* @param images The images property of the GLTF model's asset.
|
|
7
|
+
* @param textures The textures property of the GLTF model's asset.
|
|
8
|
+
* @param zip The zip file to add images to.
|
|
9
|
+
*/
|
|
10
|
+
export declare const handleImages: (images: Array<ImageDataObject>, textures: Array<TexturesObject>, zip: JSZip) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Handles processing and adding buffers to a zip file.
|
|
13
|
+
*
|
|
14
|
+
* @param buffers The buffers property of the GLTF model's asset.
|
|
15
|
+
* @param zip The zip file to add buffers to.
|
|
16
|
+
* @param baseFileName The base file name to use for the exported file.
|
|
17
|
+
*
|
|
18
|
+
* Only ArrayBuffers and URIBufferObjects with a uri of type data URL are supported.
|
|
19
|
+
* If the buffer is not an ArrayBuffer, it must have a uri that starts with 'data:'.
|
|
20
|
+
* If the buffer is not an ArrayBuffer and does not have a uri, a warning is logged
|
|
21
|
+
* to the console.
|
|
22
|
+
*/
|
|
23
|
+
export declare const handleBuffers: (buffers: Array<URIBufferObject | ArrayBuffer>, zip: JSZip, baseFileName: string) => void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines the extension of a file based on its URI and MIME type.
|
|
3
|
+
*
|
|
4
|
+
* If the MIME type is not provided, it is inferred from the URI.
|
|
5
|
+
*
|
|
6
|
+
* Returns a default `png` extension if the extension is unknown.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} uri - The URI of the image
|
|
9
|
+
* @param {string} mimeType - The MIME type of the image
|
|
10
|
+
*/
|
|
11
|
+
export declare function getFileExtension(uri: string, mimeType?: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Extracts the base name of a file from its URI.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} filename - The name of the file
|
|
16
|
+
*/
|
|
17
|
+
export declare function getFileBasename(filename: string): string;
|