stack3js 0.2.0 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/COMMAND.md +147 -0
- package/README.md +171 -4
- package/bin/stack3.mjs +1445 -186
- package/blender/import_stack.py +89 -0
- package/meshing/blocks.py +82 -0
- package/meshing/branches.py +62 -0
- package/meshing/dexel.py +67 -0
- package/meshing/field_data.py +19 -0
- package/meshing/finish_blender.py +203 -0
- package/meshing/finishing.py +155 -0
- package/meshing/geometry.py +71 -0
- package/meshing/guided.py +150 -0
- package/meshing/implicit.py +178 -0
- package/meshing/intersection.py +33 -0
- package/meshing/material.py +115 -0
- package/meshing/mesh.py +103 -0
- package/meshing/network.py +136 -0
- package/meshing/regularization.py +213 -0
- package/meshing/sections.py +165 -0
- package/meshing/signed_distance.py +93 -0
- package/package.json +9 -2
- package/references/hard-surface/README.md +40 -0
- package/references/hard-surface/atlas/concrete-barrier-4view.png +0 -0
- package/references/hard-surface/atlas/preview.pipeline.yaml +14 -0
- package/references/hard-surface/case-studies/benchmark/README.md +22 -0
- package/references/hard-surface/case-studies/benchmark/lod-bevel.pipeline.yaml +258 -0
- package/references/hard-surface/finishing/exports.yaml +10 -0
- package/references/hard-surface/finishing/finish-lod.pipeline.yaml +33 -0
- package/references/hard-surface/finishing/inputs/stack/stack.json +1 -0
- package/references/hard-surface/finishing/inputs/stack/stack.png +0 -0
- package/references/hard-surface/finishing/regularize.pipeline.yaml +46 -0
- package/references/hard-surface/measured-depth/sdf/compare.pipeline.yaml +12 -0
- package/references/hard-surface/measured-depth/sdf/inputs/field.npy +0 -0
- package/references/hard-surface/measured-depth/sdf/inputs/stack/stack.json +1 -0
- package/references/hard-surface/measured-depth/sdf/inputs/stack/stack.png +0 -0
- package/references/hard-surface/measured-depth/sdf/inputs/truth.json +1 -0
- package/references/hard-surface/measured-depth/sdf/sdf.guide.json +3 -0
- package/references/hard-surface/measured-depth/triple-dexel/compare.pipeline.yaml +12 -0
- package/references/hard-surface/measured-depth/triple-dexel/dexel.guide.json +3 -0
- package/references/hard-surface/measured-depth/triple-dexel/inputs/fixture.json +22 -0
- package/references/hard-surface/measured-depth/triple-dexel/inputs/stack/stack.json +22 -0
- package/references/hard-surface/measured-depth/triple-dexel/inputs/stack/stack.png +0 -0
- package/references/hard-surface/measured-depth/triple-dexel/inputs/triple-dexel.npz +0 -0
- package/references/hard-surface/schema/pipeline-fragment.schema.json +5 -0
- package/references/hard-surface/schema/pipeline.schema.json +181 -0
- package/schema/pipeline-fragment.schema.json +5 -0
- package/schema/pipeline.schema.json +181 -0
- package/verification/acceptance.py +85 -0
- package/verification/assembly.py +96 -0
- package/verification/landmarks.py +53 -0
- package/verification/panels.py +147 -0
- package/verification/projections.py +135 -0
- package/verification/verify.py +115 -0
- package/viewer/dist/assets/{GLTFExporter--hziUXc8.js → GLTFExporter-xdVCArY-.js} +1 -1
- package/viewer/dist/assets/compare-Du4RoRQO.js +6 -0
- package/viewer/dist/assets/compare.worker-CgJq-znx.js +21 -0
- package/viewer/dist/assets/presets-jXE0t1fU.js +1 -0
- package/viewer/dist/assets/preview-cache-BKV0EZl9.js +1 -0
- package/viewer/dist/assets/project-DtHHhfo-.js +17 -0
- package/viewer/dist/assets/reconstruct.worker-ONc9GyFO.js +21 -0
- package/viewer/dist/assets/{script-engine-CLj7QMLe.js → script-engine-Bs3azDYZ.js} +1 -1
- package/viewer/dist/assets/style-D6eZHs3D.js +4004 -0
- package/viewer/dist/assets/viewer-DIjS0No7.js +2 -0
- package/viewer/dist/compare.html +4 -4
- package/viewer/dist/index.html +9 -8
- package/viewer/dist/project.html +3 -3
- package/viewer/dist/assets/compare-DJ8rV3Rn.js +0 -6
- package/viewer/dist/assets/compare.worker-DK2lJl0n.js +0 -21
- package/viewer/dist/assets/presets-DwdZVYhs.js +0 -1
- package/viewer/dist/assets/preview-cache-DRF_H5pq.js +0 -58
- package/viewer/dist/assets/project-D8tR6U-_.js +0 -17
- package/viewer/dist/assets/reconstruct.worker-Cf8iZwT3.js +0 -21
- package/viewer/dist/assets/style-CWGgpweN.js +0 -3947
- package/viewer/dist/assets/viewer-CyGodHLY.js +0 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./GLTFExporter-xdVCArY-.js","./style-D6eZHs3D.js","./style-CMUT8CmM.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{T as zt,v as Pe,w as gt,x as Xt,y as se,F as Tt,z as D,E as xt,C as z,H as G,f as oe,J as qt,K as Wt,r as bt,M as he,V as I,U as $t,Q as wt,X as Yt,Y as Et,Z as Jt,_ as Qt,B as Se,$ as Zt,k as yt,i as en,j as tn,h as nn,L as Fe,g as Rt,m as De,n as sn,l as rn,a0 as on,a1 as ve,a2 as an,q as At,D as cn,a3 as te,P as ln,a4 as un,a5 as dn,a6 as fn,a7 as hn,a8 as pn,a9 as mn,aa as gn,G as _e,ab as Tn,b as xn,O as Lt,ac as bn,ad as wn,ae as En,d as yn,o as St,af as Rn,ag as rt,ah as it,ai as ot,aj as at,ak as ct,al as An,am as Ln,p as be,an as Sn,ao as vn,ap as _n,e as Mn,aq as Nn,A as Cn,ar as vt,as as We,W as In,at as On,au as kn,av as Pn,s as Fn,aw as _t,ax as Dn,ay as Hn,az as Gn}from"./style-D6eZHs3D.js";import{C as Un,O as jn,c as Bn,s as Kn,f as lt,a as Vn,_ as zn}from"./preview-cache-BKV0EZl9.js";import{m as Xn,s as Mt,q as Nt,c as Ct,i as qn,b as Wn}from"./presets-jXE0t1fU.js";function $n(o,e){if(!Number.isFinite(e)||e<=0||!Number.isFinite(e*o.size[2]))throw new Error("Spacing must be a positive, finite multiplier.");return e===1?o:{...o,spacing:o.spacing*e,size:[o.size[0],o.size[1],o.size[2]*e],pivot:[o.pivot[0],o.pivot[1],o.pivot[2]*e]}}function ut(o,e){if(e===zt)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),o;if(e===Pe||e===gt){let t=o.getIndex();if(t===null){const r=[],a=o.getAttribute("position");if(a!==void 0){for(let c=0;c<a.count;c++)r.push(c);o.setIndex(r),t=o.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),o}const s=t.count-2,n=[];if(e===Pe)for(let r=1;r<=s;r++)n.push(t.getX(0)),n.push(t.getX(r)),n.push(t.getX(r+1));else for(let r=0;r<s;r++)r%2===0?(n.push(t.getX(r)),n.push(t.getX(r+1)),n.push(t.getX(r+2))):(n.push(t.getX(r+2)),n.push(t.getX(r+1)),n.push(t.getX(r)));n.length/3!==s&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=o.clone();return i.setIndex(n),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),o}class Yn extends Xt{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new ts(t)}),this.register(function(t){return new ns(t)}),this.register(function(t){return new ds(t)}),this.register(function(t){return new fs(t)}),this.register(function(t){return new hs(t)}),this.register(function(t){return new rs(t)}),this.register(function(t){return new is(t)}),this.register(function(t){return new os(t)}),this.register(function(t){return new as(t)}),this.register(function(t){return new es(t)}),this.register(function(t){return new cs(t)}),this.register(function(t){return new ss(t)}),this.register(function(t){return new us(t)}),this.register(function(t){return new ls(t)}),this.register(function(t){return new Qn(t)}),this.register(function(t){return new ps(t)}),this.register(function(t){return new ms(t)})}load(e,t,s,n){const i=this;let r;if(this.resourcePath!=="")r=this.resourcePath;else if(this.path!==""){const l=se.extractUrlBase(e);r=se.resolveURL(l,this.path)}else r=se.extractUrlBase(e);this.manager.itemStart(e);const a=function(l){n?n(l):console.error(l),i.manager.itemError(e),i.manager.itemEnd(e)},c=new Tt(this.manager);c.setPath(this.path),c.setResponseType("arraybuffer"),c.setRequestHeader(this.requestHeader),c.setWithCredentials(this.withCredentials),c.load(e,function(l){try{i.parse(l,r,function(u){t(u),i.manager.itemEnd(e)},a)}catch(u){a(u)}},s,a)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}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,s,n){let i;const r={},a={},c=new TextDecoder;if(typeof e=="string")i=JSON.parse(e);else if(e instanceof ArrayBuffer)if(c.decode(new Uint8Array(e,0,4))===It){try{r[T.KHR_BINARY_GLTF]=new gs(e)}catch(d){n&&n(d);return}i=JSON.parse(r[T.KHR_BINARY_GLTF].content)}else i=JSON.parse(c.decode(e));else i=e;if(i.asset===void 0||i.asset.version[0]<2){n&&n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}const l=new Ms(i,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});l.fileLoader.setRequestHeader(this.requestHeader);for(let u=0;u<this.pluginCallbacks.length;u++){const d=this.pluginCallbacks[u](l);d.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),a[d.name]=d,r[d.name]=!0}if(i.extensionsUsed)for(let u=0;u<i.extensionsUsed.length;++u){const d=i.extensionsUsed[u],f=i.extensionsRequired||[];switch(d){case T.KHR_MATERIALS_UNLIT:r[d]=new Zn;break;case T.KHR_DRACO_MESH_COMPRESSION:r[d]=new Ts(i,this.dracoLoader);break;case T.KHR_TEXTURE_TRANSFORM:r[d]=new xs;break;case T.KHR_MESH_QUANTIZATION:r[d]=new bs;break;default:f.indexOf(d)>=0&&a[d]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+d+'".')}}l.setExtensions(r),l.setPlugins(a),l.parse(s,n)}parseAsync(e,t){const s=this;return new Promise(function(n,i){s.parse(e,t,n,i)})}}function Jn(){let o={};return{get:function(e){return o[e]},add:function(e,t){o[e]=t},remove:function(e){delete o[e]},removeAll:function(){o={}}}}const T={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class Qn{constructor(e){this.parser=e,this.name=T.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,n=t.length;s<n;s++){const i=t[s];i.extensions&&i.extensions[this.name]&&i.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,i.extensions[this.name].light)}}_loadLight(e){const t=this.parser,s="light:"+e;let n=t.cache.get(s);if(n)return n;const i=t.json,c=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e];let l;const u=new z(16777215);c.color!==void 0&&u.setRGB(c.color[0],c.color[1],c.color[2],G);const d=c.range!==void 0?c.range:0;switch(c.type){case"directional":l=new bt(u),l.target.position.set(0,0,-1),l.add(l.target);break;case"point":l=new Wt(u),l.distance=d;break;case"spot":l=new qt(u),l.distance=d,c.spot=c.spot||{},c.spot.innerConeAngle=c.spot.innerConeAngle!==void 0?c.spot.innerConeAngle:0,c.spot.outerConeAngle=c.spot.outerConeAngle!==void 0?c.spot.outerConeAngle:Math.PI/4,l.angle=c.spot.outerConeAngle,l.penumbra=1-c.spot.innerConeAngle/c.spot.outerConeAngle,l.target.position.set(0,0,-1),l.add(l.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+c.type)}return l.position.set(0,0,0),F(l,c),c.intensity!==void 0&&(l.intensity=c.intensity),l.name=t.createUniqueName(c.name||"light_"+e),n=Promise.resolve(l),t.cache.add(s,n),n}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){const t=this,s=this.parser,i=s.json.nodes[e],a=(i.extensions&&i.extensions[this.name]||{}).light;return a===void 0?null:this._loadLight(a).then(function(c){return s._getNodeRef(t.cache,a,c)})}}class Zn{constructor(){this.name=T.KHR_MATERIALS_UNLIT}getMaterialType(){return te}extendParams(e,t,s){const n=[];e.color=new z(1,1,1),e.opacity=1;const i=t.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const r=i.baseColorFactor;e.color.setRGB(r[0],r[1],r[2],G),e.opacity=r[3]}i.baseColorTexture!==void 0&&n.push(s.assignTexture(e,"map",i.baseColorTexture,oe))}return Promise.all(n)}}class es{constructor(e){this.parser=e,this.name=T.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const n=this.parser.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=n.extensions[this.name].emissiveStrength;return i!==void 0&&(t.emissiveIntensity=i),Promise.resolve()}}class ts{constructor(e){this.parser=e,this.name=T.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:D}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],r=n.extensions[this.name];if(r.clearcoatFactor!==void 0&&(t.clearcoat=r.clearcoatFactor),r.clearcoatTexture!==void 0&&i.push(s.assignTexture(t,"clearcoatMap",r.clearcoatTexture)),r.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=r.clearcoatRoughnessFactor),r.clearcoatRoughnessTexture!==void 0&&i.push(s.assignTexture(t,"clearcoatRoughnessMap",r.clearcoatRoughnessTexture)),r.clearcoatNormalTexture!==void 0&&(i.push(s.assignTexture(t,"clearcoatNormalMap",r.clearcoatNormalTexture)),r.clearcoatNormalTexture.scale!==void 0)){const a=r.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new xt(a,a)}return Promise.all(i)}}class ns{constructor(e){this.parser=e,this.name=T.KHR_MATERIALS_DISPERSION}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:D}extendMaterialParams(e,t){const n=this.parser.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=n.extensions[this.name];return t.dispersion=i.dispersion!==void 0?i.dispersion:0,Promise.resolve()}}class ss{constructor(e){this.parser=e,this.name=T.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:D}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],r=n.extensions[this.name];return r.iridescenceFactor!==void 0&&(t.iridescence=r.iridescenceFactor),r.iridescenceTexture!==void 0&&i.push(s.assignTexture(t,"iridescenceMap",r.iridescenceTexture)),r.iridescenceIor!==void 0&&(t.iridescenceIOR=r.iridescenceIor),t.iridescenceThicknessRange===void 0&&(t.iridescenceThicknessRange=[100,400]),r.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessRange[0]=r.iridescenceThicknessMinimum),r.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessRange[1]=r.iridescenceThicknessMaximum),r.iridescenceThicknessTexture!==void 0&&i.push(s.assignTexture(t,"iridescenceThicknessMap",r.iridescenceThicknessTexture)),Promise.all(i)}}class rs{constructor(e){this.parser=e,this.name=T.KHR_MATERIALS_SHEEN}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:D}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[];t.sheenColor=new z(0,0,0),t.sheenRoughness=0,t.sheen=1;const r=n.extensions[this.name];if(r.sheenColorFactor!==void 0){const a=r.sheenColorFactor;t.sheenColor.setRGB(a[0],a[1],a[2],G)}return r.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=r.sheenRoughnessFactor),r.sheenColorTexture!==void 0&&i.push(s.assignTexture(t,"sheenColorMap",r.sheenColorTexture,oe)),r.sheenRoughnessTexture!==void 0&&i.push(s.assignTexture(t,"sheenRoughnessMap",r.sheenRoughnessTexture)),Promise.all(i)}}class is{constructor(e){this.parser=e,this.name=T.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:D}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],r=n.extensions[this.name];return r.transmissionFactor!==void 0&&(t.transmission=r.transmissionFactor),r.transmissionTexture!==void 0&&i.push(s.assignTexture(t,"transmissionMap",r.transmissionTexture)),Promise.all(i)}}class os{constructor(e){this.parser=e,this.name=T.KHR_MATERIALS_VOLUME}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:D}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],r=n.extensions[this.name];t.thickness=r.thicknessFactor!==void 0?r.thicknessFactor:0,r.thicknessTexture!==void 0&&i.push(s.assignTexture(t,"thicknessMap",r.thicknessTexture)),t.attenuationDistance=r.attenuationDistance||1/0;const a=r.attenuationColor||[1,1,1];return t.attenuationColor=new z().setRGB(a[0],a[1],a[2],G),Promise.all(i)}}class as{constructor(e){this.parser=e,this.name=T.KHR_MATERIALS_IOR}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:D}extendMaterialParams(e,t){const n=this.parser.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=n.extensions[this.name];return t.ior=i.ior!==void 0?i.ior:1.5,Promise.resolve()}}class cs{constructor(e){this.parser=e,this.name=T.KHR_MATERIALS_SPECULAR}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:D}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],r=n.extensions[this.name];t.specularIntensity=r.specularFactor!==void 0?r.specularFactor:1,r.specularTexture!==void 0&&i.push(s.assignTexture(t,"specularIntensityMap",r.specularTexture));const a=r.specularColorFactor||[1,1,1];return t.specularColor=new z().setRGB(a[0],a[1],a[2],G),r.specularColorTexture!==void 0&&i.push(s.assignTexture(t,"specularColorMap",r.specularColorTexture,oe)),Promise.all(i)}}class ls{constructor(e){this.parser=e,this.name=T.EXT_MATERIALS_BUMP}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:D}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],r=n.extensions[this.name];return t.bumpScale=r.bumpFactor!==void 0?r.bumpFactor:1,r.bumpTexture!==void 0&&i.push(s.assignTexture(t,"bumpMap",r.bumpTexture)),Promise.all(i)}}class us{constructor(e){this.parser=e,this.name=T.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:D}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],r=n.extensions[this.name];return r.anisotropyStrength!==void 0&&(t.anisotropy=r.anisotropyStrength),r.anisotropyRotation!==void 0&&(t.anisotropyRotation=r.anisotropyRotation),r.anisotropyTexture!==void 0&&i.push(s.assignTexture(t,"anisotropyMap",r.anisotropyTexture)),Promise.all(i)}}class ds{constructor(e){this.parser=e,this.name=T.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,s=t.json,n=s.textures[e];if(!n.extensions||!n.extensions[this.name])return null;const i=n.extensions[this.name],r=t.options.ktx2Loader;if(!r){if(s.extensionsRequired&&s.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,i.source,r)}}class fs{constructor(e){this.parser=e,this.name=T.EXT_TEXTURE_WEBP}loadTexture(e){const t=this.name,s=this.parser,n=s.json,i=n.textures[e];if(!i.extensions||!i.extensions[t])return null;const r=i.extensions[t],a=n.images[r.source];let c=s.textureLoader;if(a.uri){const l=s.options.manager.getHandler(a.uri);l!==null&&(c=l)}return s.loadTextureImage(e,r.source,c)}}class hs{constructor(e){this.parser=e,this.name=T.EXT_TEXTURE_AVIF}loadTexture(e){const t=this.name,s=this.parser,n=s.json,i=n.textures[e];if(!i.extensions||!i.extensions[t])return null;const r=i.extensions[t],a=n.images[r.source];let c=s.textureLoader;if(a.uri){const l=s.options.manager.getHandler(a.uri);l!==null&&(c=l)}return s.loadTextureImage(e,r.source,c)}}class ps{constructor(e){this.name=T.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,s=t.bufferViews[e];if(s.extensions&&s.extensions[this.name]){const n=s.extensions[this.name],i=this.parser.getDependency("buffer",n.buffer),r=this.parser.options.meshoptDecoder;if(!r||!r.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return i.then(function(a){const c=n.byteOffset||0,l=n.byteLength||0,u=n.count,d=n.byteStride,f=new Uint8Array(a,c,l);return r.decodeGltfBufferAsync?r.decodeGltfBufferAsync(u,d,f,n.mode,n.filter).then(function(p){return p.buffer}):r.ready.then(function(){const p=new ArrayBuffer(u*d);return r.decodeGltfBuffer(new Uint8Array(p),u,d,f,n.mode,n.filter),p})})}else return null}}class ms{constructor(e){this.name=T.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,s=t.nodes[e];if(!s.extensions||!s.extensions[this.name]||s.mesh===void 0)return null;const n=t.meshes[s.mesh];for(const l of n.primitives)if(l.mode!==N.TRIANGLES&&l.mode!==N.TRIANGLE_STRIP&&l.mode!==N.TRIANGLE_FAN&&l.mode!==void 0)return null;const r=s.extensions[this.name].attributes,a=[],c={};for(const l in r)a.push(this.parser.getDependency("accessor",r[l]).then(u=>(c[l]=u,c[l])));return a.length<1?null:(a.push(this.parser.createNodeMesh(e)),Promise.all(a).then(l=>{const u=l.pop(),d=u.isGroup?u.children:[u],f=l[0].count,p=[];for(const g of d){const b=new he,m=new I,x=new wt,y=new I(1,1,1),E=new $t(g.geometry,g.material,f);for(let w=0;w<f;w++)c.TRANSLATION&&m.fromBufferAttribute(c.TRANSLATION,w),c.ROTATION&&x.fromBufferAttribute(c.ROTATION,w),c.SCALE&&y.fromBufferAttribute(c.SCALE,w),E.setMatrixAt(w,b.compose(m,x,y));for(const w in c)if(w==="_COLOR_0"){const M=c[w];E.instanceColor=new Yt(M.array,M.itemSize,M.normalized)}else w!=="TRANSLATION"&&w!=="ROTATION"&&w!=="SCALE"&&g.geometry.setAttribute(w,c[w]);Et.prototype.copy.call(E,g),this.parser.assignFinalMaterial(E),p.push(E)}return u.isGroup?(u.clear(),u.add(...p),u):p[0]}))}}const It="glTF",ee=12,dt={JSON:1313821514,BIN:5130562};class gs{constructor(e){this.name=T.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,ee),s=new TextDecoder;if(this.header={magic:s.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==It)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const n=this.header.length-ee,i=new DataView(e,ee);let r=0;for(;r<n;){const a=i.getUint32(r,!0);r+=4;const c=i.getUint32(r,!0);if(r+=4,c===dt.JSON){const l=new Uint8Array(e,ee+r,a);this.content=s.decode(l)}else if(c===dt.BIN){const l=ee+r;this.body=e.slice(l,l+a)}r+=a}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class Ts{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=T.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,n=this.dracoLoader,i=e.extensions[this.name].bufferView,r=e.extensions[this.name].attributes,a={},c={},l={};for(const u in r){const d=He[u]||u.toLowerCase();a[d]=r[u]}for(const u in e.attributes){const d=He[u]||u.toLowerCase();if(r[u]!==void 0){const f=s.accessors[e.attributes[u]],p=Q[f.componentType];l[d]=p.name,c[d]=f.normalized===!0}}return t.getDependency("bufferView",i).then(function(u){return new Promise(function(d,f){n.decodeDracoFile(u,function(p){for(const g in p.attributes){const b=p.attributes[g],m=c[g];m!==void 0&&(b.normalized=m)}d(p)},a,l,G,f)})})}}class xs{constructor(){this.name=T.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return(t.texCoord===void 0||t.texCoord===e.channel)&&t.offset===void 0&&t.rotation===void 0&&t.scale===void 0||(e=e.clone(),t.texCoord!==void 0&&(e.channel=t.texCoord),t.offset!==void 0&&e.offset.fromArray(t.offset),t.rotation!==void 0&&(e.rotation=t.rotation),t.scale!==void 0&&e.repeat.fromArray(t.scale),e.needsUpdate=!0),e}}class bs{constructor(){this.name=T.KHR_MESH_QUANTIZATION}}class Ot extends Ln{constructor(e,t,s,n){super(e,t,s,n)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,n=this.valueSize,i=e*n*3+n;for(let r=0;r!==n;r++)t[r]=s[i+r];return t}interpolate_(e,t,s,n){const i=this.resultBuffer,r=this.sampleValues,a=this.valueSize,c=a*2,l=a*3,u=n-t,d=(s-t)/u,f=d*d,p=f*d,g=e*l,b=g-l,m=-2*p+3*f,x=p-f,y=1-m,E=x-f+d;for(let w=0;w!==a;w++){const M=r[b+w+a],j=r[b+w+c]*u,k=r[g+w+a],Z=r[g+w]*u;i[w]=y*M+E*j+m*k+x*Z}return i}}const ws=new wt;class Es extends Ot{interpolate_(e,t,s,n){const i=super.interpolate_(e,t,s,n);return ws.fromArray(i).normalize().toArray(i),i}}const N={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},Q={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},ft={9728:Rt,9729:Fe,9984:nn,9985:tn,9986:en,9987:yt},ht={33071:rn,33648:sn,10497:De},Me={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},He={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},B={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},ys={CUBICSPLINE:void 0,LINEAR:St,STEP:yn},Ne={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function Rs(o){return o.DefaultMaterial===void 0&&(o.DefaultMaterial=new At({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:An})),o.DefaultMaterial}function V(o,e,t){for(const s in t.extensions)o[s]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[s]=t.extensions[s])}function F(o,e){e.extras!==void 0&&(typeof e.extras=="object"?Object.assign(o.userData,e.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+e.extras))}function As(o,e,t){let s=!1,n=!1,i=!1;for(let l=0,u=e.length;l<u;l++){const d=e[l];if(d.POSITION!==void 0&&(s=!0),d.NORMAL!==void 0&&(n=!0),d.COLOR_0!==void 0&&(i=!0),s&&n&&i)break}if(!s&&!n&&!i)return Promise.resolve(o);const r=[],a=[],c=[];for(let l=0,u=e.length;l<u;l++){const d=e[l];if(s){const f=d.POSITION!==void 0?t.getDependency("accessor",d.POSITION):o.attributes.position;r.push(f)}if(n){const f=d.NORMAL!==void 0?t.getDependency("accessor",d.NORMAL):o.attributes.normal;a.push(f)}if(i){const f=d.COLOR_0!==void 0?t.getDependency("accessor",d.COLOR_0):o.attributes.color;c.push(f)}}return Promise.all([Promise.all(r),Promise.all(a),Promise.all(c)]).then(function(l){const u=l[0],d=l[1],f=l[2];return s&&(o.morphAttributes.position=u),n&&(o.morphAttributes.normal=d),i&&(o.morphAttributes.color=f),o.morphTargetsRelative=!0,o})}function Ls(o,e){if(o.updateMorphTargets(),e.weights!==void 0)for(let t=0,s=e.weights.length;t<s;t++)o.morphTargetInfluences[t]=e.weights[t];if(e.extras&&Array.isArray(e.extras.targetNames)){const t=e.extras.targetNames;if(o.morphTargetInfluences.length===t.length){o.morphTargetDictionary={};for(let s=0,n=t.length;s<n;s++)o.morphTargetDictionary[t[s]]=s}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function Ss(o){let e;const t=o.extensions&&o.extensions[T.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+Ce(t.attributes):e=o.indices+":"+Ce(o.attributes)+":"+o.mode,o.targets!==void 0)for(let s=0,n=o.targets.length;s<n;s++)e+=":"+Ce(o.targets[s]);return e}function Ce(o){let e="";const t=Object.keys(o).sort();for(let s=0,n=t.length;s<n;s++)e+=t[s]+":"+o[t[s]]+";";return e}function Ge(o){switch(o){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}function vs(o){return o.search(/\.jpe?g($|\?)/i)>0||o.search(/^data\:image\/jpeg/)===0?"image/jpeg":o.search(/\.webp($|\?)/i)>0||o.search(/^data\:image\/webp/)===0?"image/webp":o.search(/\.ktx2($|\?)/i)>0||o.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}const _s=new he;class Ms{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new Jn,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let s=!1,n=-1,i=!1,r=-1;if(typeof navigator<"u"){const a=navigator.userAgent;s=/^((?!chrome|android).)*safari/i.test(a)===!0;const c=a.match(/Version\/(\d+)/);n=s&&c?parseInt(c[1],10):-1,i=a.indexOf("Firefox")>-1,r=i?a.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||s&&n<17||i&&r<98?this.textureLoader=new Jt(this.options.manager):this.textureLoader=new Qt(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new Tt(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const s=this,n=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(r){return r._markDefs&&r._markDefs()}),Promise.all(this._invokeAll(function(r){return r.beforeRoot&&r.beforeRoot()})).then(function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])}).then(function(r){const a={scene:r[0][n.scene||0],scenes:r[0],animations:r[1],cameras:r[2],asset:n.asset,parser:s,userData:{}};return V(i,a,n),F(a,n),Promise.all(s._invokeAll(function(c){return c.afterRoot&&c.afterRoot(a)})).then(function(){for(const c of a.scenes)c.updateMatrixWorld();e(a)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],s=this.json.meshes||[];for(let n=0,i=t.length;n<i;n++){const r=t[n].joints;for(let a=0,c=r.length;a<c;a++)e[r[a]].isBone=!0}for(let n=0,i=e.length;n<i;n++){const r=e[n];r.mesh!==void 0&&(this._addNodeRef(this.meshCache,r.mesh),r.skin!==void 0&&(s[r.mesh].isSkinnedMesh=!0)),r.camera!==void 0&&this._addNodeRef(this.cameraCache,r.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,s){if(e.refs[t]<=1)return s;const n=s.clone(),i=(r,a)=>{const c=this.associations.get(r);c!=null&&this.associations.set(a,c);for(const[l,u]of r.children.entries())i(u,a.children[l])};return i(s,n),n.name+="_instance_"+e.uses[t]++,n}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let s=0;s<t.length;s++){const n=e(t[s]);if(n)return n}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const s=[];for(let n=0;n<t.length;n++){const i=e(t[n]);i&&s.push(i)}return s}getDependency(e,t){const s=e+":"+t;let n=this.cache.get(s);if(!n){switch(e){case"scene":n=this.loadScene(t);break;case"node":n=this._invokeOne(function(i){return i.loadNode&&i.loadNode(t)});break;case"mesh":n=this._invokeOne(function(i){return i.loadMesh&&i.loadMesh(t)});break;case"accessor":n=this.loadAccessor(t);break;case"bufferView":n=this._invokeOne(function(i){return i.loadBufferView&&i.loadBufferView(t)});break;case"buffer":n=this.loadBuffer(t);break;case"material":n=this._invokeOne(function(i){return i.loadMaterial&&i.loadMaterial(t)});break;case"texture":n=this._invokeOne(function(i){return i.loadTexture&&i.loadTexture(t)});break;case"skin":n=this.loadSkin(t);break;case"animation":n=this._invokeOne(function(i){return i.loadAnimation&&i.loadAnimation(t)});break;case"camera":n=this.loadCamera(t);break;default:if(n=this._invokeOne(function(i){return i!=this&&i.getDependency&&i.getDependency(e,t)}),!n)throw new Error("Unknown type: "+e);break}this.cache.add(s,n)}return n}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,n=this.json[e+(e==="mesh"?"es":"s")]||[];t=Promise.all(n.map(function(i,r){return s.getDependency(e,r)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],s=this.fileLoader;if(t.type&&t.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[T.KHR_BINARY_GLTF].body);const n=this.options;return new Promise(function(i,r){s.load(se.resolveURL(t.uri,n.path),i,void 0,function(){r(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))})})}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then(function(s){const n=t.byteLength||0,i=t.byteOffset||0;return s.slice(i,i+n)})}loadAccessor(e){const t=this,s=this.json,n=this.json.accessors[e];if(n.bufferView===void 0&&n.sparse===void 0){const r=Me[n.type],a=Q[n.componentType],c=n.normalized===!0,l=new a(n.count*r);return Promise.resolve(new Se(l,r,c))}const i=[];return n.bufferView!==void 0?i.push(this.getDependency("bufferView",n.bufferView)):i.push(null),n.sparse!==void 0&&(i.push(this.getDependency("bufferView",n.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",n.sparse.values.bufferView))),Promise.all(i).then(function(r){const a=r[0],c=Me[n.type],l=Q[n.componentType],u=l.BYTES_PER_ELEMENT,d=u*c,f=n.byteOffset||0,p=n.bufferView!==void 0?s.bufferViews[n.bufferView].byteStride:void 0,g=n.normalized===!0;let b,m;if(p&&p!==d){const x=Math.floor(f/p),y="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+x+":"+n.count;let E=t.cache.get(y);E||(b=new l(a,x*p,n.count*p/u),E=new Zt(b,p/u),t.cache.add(y,E)),m=new Rn(E,c,f%p/u,g)}else a===null?b=new l(n.count*c):b=new l(a,f,n.count*c),m=new Se(b,c,g);if(n.sparse!==void 0){const x=Me.SCALAR,y=Q[n.sparse.indices.componentType],E=n.sparse.indices.byteOffset||0,w=n.sparse.values.byteOffset||0,M=new y(r[1],E,n.sparse.count*x),j=new l(r[2],w,n.sparse.count*c);a!==null&&(m=new Se(m.array.slice(),m.itemSize,m.normalized)),m.normalized=!1;for(let k=0,Z=M.length;k<Z;k++){const W=M[k];if(m.setX(W,j[k*c]),c>=2&&m.setY(W,j[k*c+1]),c>=3&&m.setZ(W,j[k*c+2]),c>=4&&m.setW(W,j[k*c+3]),c>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}m.normalized=g}return m})}loadTexture(e){const t=this.json,s=this.options,i=t.textures[e].source,r=t.images[i];let a=this.textureLoader;if(r.uri){const c=s.manager.getHandler(r.uri);c!==null&&(a=c)}return this.loadTextureImage(e,i,a)}loadTextureImage(e,t,s){const n=this,i=this.json,r=i.textures[e],a=i.images[t],c=(a.uri||a.bufferView)+":"+r.sampler;if(this.textureCache[c])return this.textureCache[c];const l=this.loadImageSource(t,s).then(function(u){u.flipY=!1,u.name=r.name||a.name||"",u.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(u.name=a.uri);const f=(i.samplers||{})[r.sampler]||{};return u.magFilter=ft[f.magFilter]||Fe,u.minFilter=ft[f.minFilter]||yt,u.wrapS=ht[f.wrapS]||De,u.wrapT=ht[f.wrapT]||De,u.generateMipmaps=!u.isCompressedTexture&&u.minFilter!==Rt&&u.minFilter!==Fe,n.associations.set(u,{textures:e}),u}).catch(function(){return null});return this.textureCache[c]=l,l}loadImageSource(e,t){const s=this,n=this.json,i=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(d=>d.clone());const r=n.images[e],a=self.URL||self.webkitURL;let c=r.uri||"",l=!1;if(r.bufferView!==void 0)c=s.getDependency("bufferView",r.bufferView).then(function(d){l=!0;const f=new Blob([d],{type:r.mimeType});return c=a.createObjectURL(f),c});else if(r.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const u=Promise.resolve(c).then(function(d){return new Promise(function(f,p){let g=f;t.isImageBitmapLoader===!0&&(g=function(b){const m=new rt(b);m.needsUpdate=!0,f(m)}),t.load(se.resolveURL(d,i.path),g,void 0,p)})}).then(function(d){return l===!0&&a.revokeObjectURL(c),F(d,r),d.userData.mimeType=r.mimeType||vs(r.uri),d}).catch(function(d){throw console.error("THREE.GLTFLoader: Couldn't load texture",c),d});return this.sourceCache[e]=u,u}assignTexture(e,t,s,n){const i=this;return this.getDependency("texture",s.index).then(function(r){if(!r)return null;if(s.texCoord!==void 0&&s.texCoord>0&&(r=r.clone(),r.channel=s.texCoord),i.extensions[T.KHR_TEXTURE_TRANSFORM]){const a=s.extensions!==void 0?s.extensions[T.KHR_TEXTURE_TRANSFORM]:void 0;if(a){const c=i.associations.get(r);r=i.extensions[T.KHR_TEXTURE_TRANSFORM].extendTexture(r,a),i.associations.set(r,c)}}return n!==void 0&&(r.colorSpace=n),e[t]=r,r})}assignFinalMaterial(e){const t=e.geometry;let s=e.material;const n=t.attributes.tangent===void 0,i=t.attributes.color!==void 0,r=t.attributes.normal===void 0;if(e.isPoints){const a="PointsMaterial:"+s.uuid;let c=this.cache.get(a);c||(c=new on,ve.prototype.copy.call(c,s),c.color.copy(s.color),c.map=s.map,c.sizeAttenuation=!1,this.cache.add(a,c)),s=c}else if(e.isLine){const a="LineBasicMaterial:"+s.uuid;let c=this.cache.get(a);c||(c=new an,ve.prototype.copy.call(c,s),c.color.copy(s.color),c.map=s.map,this.cache.add(a,c)),s=c}if(n||i||r){let a="ClonedMaterial:"+s.uuid+":";n&&(a+="derivative-tangents:"),i&&(a+="vertex-colors:"),r&&(a+="flat-shading:");let c=this.cache.get(a);c||(c=s.clone(),i&&(c.vertexColors=!0),r&&(c.flatShading=!0),n&&(c.normalScale&&(c.normalScale.y*=-1),c.clearcoatNormalScale&&(c.clearcoatNormalScale.y*=-1)),this.cache.add(a,c),this.associations.set(c,this.associations.get(s))),s=c}e.material=s}getMaterialType(){return At}loadMaterial(e){const t=this,s=this.json,n=this.extensions,i=s.materials[e];let r;const a={},c=i.extensions||{},l=[];if(c[T.KHR_MATERIALS_UNLIT]){const d=n[T.KHR_MATERIALS_UNLIT];r=d.getMaterialType(),l.push(d.extendParams(a,i,t))}else{const d=i.pbrMetallicRoughness||{};if(a.color=new z(1,1,1),a.opacity=1,Array.isArray(d.baseColorFactor)){const f=d.baseColorFactor;a.color.setRGB(f[0],f[1],f[2],G),a.opacity=f[3]}d.baseColorTexture!==void 0&&l.push(t.assignTexture(a,"map",d.baseColorTexture,oe)),a.metalness=d.metallicFactor!==void 0?d.metallicFactor:1,a.roughness=d.roughnessFactor!==void 0?d.roughnessFactor:1,d.metallicRoughnessTexture!==void 0&&(l.push(t.assignTexture(a,"metalnessMap",d.metallicRoughnessTexture)),l.push(t.assignTexture(a,"roughnessMap",d.metallicRoughnessTexture))),r=this._invokeOne(function(f){return f.getMaterialType&&f.getMaterialType(e)}),l.push(Promise.all(this._invokeAll(function(f){return f.extendMaterialParams&&f.extendMaterialParams(e,a)})))}i.doubleSided===!0&&(a.side=cn);const u=i.alphaMode||Ne.OPAQUE;if(u===Ne.BLEND?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,u===Ne.MASK&&(a.alphaTest=i.alphaCutoff!==void 0?i.alphaCutoff:.5)),i.normalTexture!==void 0&&r!==te&&(l.push(t.assignTexture(a,"normalMap",i.normalTexture)),a.normalScale=new xt(1,1),i.normalTexture.scale!==void 0)){const d=i.normalTexture.scale;a.normalScale.set(d,d)}if(i.occlusionTexture!==void 0&&r!==te&&(l.push(t.assignTexture(a,"aoMap",i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(a.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&r!==te){const d=i.emissiveFactor;a.emissive=new z().setRGB(d[0],d[1],d[2],G)}return i.emissiveTexture!==void 0&&r!==te&&l.push(t.assignTexture(a,"emissiveMap",i.emissiveTexture,oe)),Promise.all(l).then(function(){const d=new r(a);return i.name&&(d.name=i.name),F(d,i),t.associations.set(d,{materials:e}),i.extensions&&V(n,d,i),d})}createUniqueName(e){const t=ln.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,s=this.extensions,n=this.primitiveCache;function i(a){return s[T.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a,t).then(function(c){return pt(c,a,t)})}const r=[];for(let a=0,c=e.length;a<c;a++){const l=e[a],u=Ss(l),d=n[u];if(d)r.push(d.promise);else{let f;l.extensions&&l.extensions[T.KHR_DRACO_MESH_COMPRESSION]?f=i(l):f=pt(new un,l,t),n[u]={primitive:l,promise:f},r.push(f)}}return Promise.all(r)}loadMesh(e){const t=this,s=this.json,n=this.extensions,i=s.meshes[e],r=i.primitives,a=[];for(let c=0,l=r.length;c<l;c++){const u=r[c].material===void 0?Rs(this.cache):this.getDependency("material",r[c].material);a.push(u)}return a.push(t.loadGeometries(r)),Promise.all(a).then(function(c){const l=c.slice(0,c.length-1),u=c[c.length-1],d=[];for(let p=0,g=u.length;p<g;p++){const b=u[p],m=r[p];let x;const y=l[p];if(m.mode===N.TRIANGLES||m.mode===N.TRIANGLE_STRIP||m.mode===N.TRIANGLE_FAN||m.mode===void 0)x=i.isSkinnedMesh===!0?new dn(b,y):new fn(b,y),x.isSkinnedMesh===!0&&x.normalizeSkinWeights(),m.mode===N.TRIANGLE_STRIP?x.geometry=ut(x.geometry,gt):m.mode===N.TRIANGLE_FAN&&(x.geometry=ut(x.geometry,Pe));else if(m.mode===N.LINES)x=new hn(b,y);else if(m.mode===N.LINE_STRIP)x=new pn(b,y);else if(m.mode===N.LINE_LOOP)x=new mn(b,y);else if(m.mode===N.POINTS)x=new gn(b,y);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+m.mode);Object.keys(x.geometry.morphAttributes).length>0&&Ls(x,i),x.name=t.createUniqueName(i.name||"mesh_"+e),F(x,i),m.extensions&&V(n,x,m),t.assignFinalMaterial(x),d.push(x)}for(let p=0,g=d.length;p<g;p++)t.associations.set(d[p],{meshes:e,primitives:p});if(d.length===1)return i.extensions&&V(n,d[0],i),d[0];const f=new _e;i.extensions&&V(n,f,i),t.associations.set(f,{meshes:e});for(let p=0,g=d.length;p<g;p++)f.add(d[p]);return f})}loadCamera(e){let t;const s=this.json.cameras[e],n=s[s.type];if(!n){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return s.type==="perspective"?t=new Tn(xn.radToDeg(n.yfov),n.aspectRatio||1,n.znear||1,n.zfar||2e6):s.type==="orthographic"&&(t=new Lt(-n.xmag,n.xmag,n.ymag,-n.ymag,n.znear,n.zfar)),s.name&&(t.name=this.createUniqueName(s.name)),F(t,s),Promise.resolve(t)}loadSkin(e){const t=this.json.skins[e],s=[];for(let n=0,i=t.joints.length;n<i;n++)s.push(this._loadNodeShallow(t.joints[n]));return t.inverseBindMatrices!==void 0?s.push(this.getDependency("accessor",t.inverseBindMatrices)):s.push(null),Promise.all(s).then(function(n){const i=n.pop(),r=n,a=[],c=[];for(let l=0,u=r.length;l<u;l++){const d=r[l];if(d){a.push(d);const f=new he;i!==null&&f.fromArray(i.array,l*16),c.push(f)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[l])}return new bn(a,c)})}loadAnimation(e){const t=this.json,s=this,n=t.animations[e],i=n.name?n.name:"animation_"+e,r=[],a=[],c=[],l=[],u=[];for(let d=0,f=n.channels.length;d<f;d++){const p=n.channels[d],g=n.samplers[p.sampler],b=p.target,m=b.node,x=n.parameters!==void 0?n.parameters[g.input]:g.input,y=n.parameters!==void 0?n.parameters[g.output]:g.output;b.node!==void 0&&(r.push(this.getDependency("node",m)),a.push(this.getDependency("accessor",x)),c.push(this.getDependency("accessor",y)),l.push(g),u.push(b))}return Promise.all([Promise.all(r),Promise.all(a),Promise.all(c),Promise.all(l),Promise.all(u)]).then(function(d){const f=d[0],p=d[1],g=d[2],b=d[3],m=d[4],x=[];for(let E=0,w=f.length;E<w;E++){const M=f[E],j=p[E],k=g[E],Z=b[E],W=m[E];if(M===void 0)continue;M.updateMatrix&&M.updateMatrix();const Ae=s._createAnimationTracks(M,j,k,Z,W);if(Ae)for(let Le=0;Le<Ae.length;Le++)x.push(Ae[Le])}const y=new wn(i,void 0,x);return F(y,n),y})}createNodeMesh(e){const t=this.json,s=this,n=t.nodes[e];return n.mesh===void 0?null:s.getDependency("mesh",n.mesh).then(function(i){const r=s._getNodeRef(s.meshCache,n.mesh,i);return n.weights!==void 0&&r.traverse(function(a){if(a.isMesh)for(let c=0,l=n.weights.length;c<l;c++)a.morphTargetInfluences[c]=n.weights[c]}),r})}loadNode(e){const t=this.json,s=this,n=t.nodes[e],i=s._loadNodeShallow(e),r=[],a=n.children||[];for(let l=0,u=a.length;l<u;l++)r.push(s.getDependency("node",a[l]));const c=n.skin===void 0?Promise.resolve(null):s.getDependency("skin",n.skin);return Promise.all([i,Promise.all(r),c]).then(function(l){const u=l[0],d=l[1],f=l[2];f!==null&&u.traverse(function(p){p.isSkinnedMesh&&p.bind(f,_s)});for(let p=0,g=d.length;p<g;p++)u.add(d[p]);return u})}_loadNodeShallow(e){const t=this.json,s=this.extensions,n=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];const i=t.nodes[e],r=i.name?n.createUniqueName(i.name):"",a=[],c=n._invokeOne(function(l){return l.createNodeMesh&&l.createNodeMesh(e)});return c&&a.push(c),i.camera!==void 0&&a.push(n.getDependency("camera",i.camera).then(function(l){return n._getNodeRef(n.cameraCache,i.camera,l)})),n._invokeAll(function(l){return l.createNodeAttachment&&l.createNodeAttachment(e)}).forEach(function(l){a.push(l)}),this.nodeCache[e]=Promise.all(a).then(function(l){let u;if(i.isBone===!0?u=new En:l.length>1?u=new _e:l.length===1?u=l[0]:u=new Et,u!==l[0])for(let d=0,f=l.length;d<f;d++)u.add(l[d]);if(i.name&&(u.userData.name=i.name,u.name=r),F(u,i),i.extensions&&V(s,u,i),i.matrix!==void 0){const d=new he;d.fromArray(i.matrix),u.applyMatrix4(d)}else i.translation!==void 0&&u.position.fromArray(i.translation),i.rotation!==void 0&&u.quaternion.fromArray(i.rotation),i.scale!==void 0&&u.scale.fromArray(i.scale);if(!n.associations.has(u))n.associations.set(u,{});else if(i.mesh!==void 0&&n.meshCache.refs[i.mesh]>1){const d=n.associations.get(u);n.associations.set(u,{...d})}return n.associations.get(u).nodes=e,u}),this.nodeCache[e]}loadScene(e){const t=this.extensions,s=this.json.scenes[e],n=this,i=new _e;s.name&&(i.name=n.createUniqueName(s.name)),F(i,s),s.extensions&&V(t,i,s);const r=s.nodes||[],a=[];for(let c=0,l=r.length;c<l;c++)a.push(n.getDependency("node",r[c]));return Promise.all(a).then(function(c){for(let u=0,d=c.length;u<d;u++)i.add(c[u]);const l=u=>{const d=new Map;for(const[f,p]of n.associations)(f instanceof ve||f instanceof rt)&&d.set(f,p);return u.traverse(f=>{const p=n.associations.get(f);p!=null&&d.set(f,p)}),d};return n.associations=l(i),i})}_createAnimationTracks(e,t,s,n,i){const r=[],a=e.name?e.name:e.uuid,c=[];B[i.path]===B.weights?e.traverse(function(f){f.morphTargetInfluences&&c.push(f.name?f.name:f.uuid)}):c.push(a);let l;switch(B[i.path]){case B.weights:l=ot;break;case B.rotation:l=at;break;case B.translation:case B.scale:l=it;break;default:s.itemSize===1?l=ot:l=it;break}const u=n.interpolation!==void 0?ys[n.interpolation]:St,d=this._getArrayFromAccessor(s);for(let f=0,p=c.length;f<p;f++){const g=new l(c[f]+"."+B[i.path],t.array,d,u);n.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(g),r.push(g)}return r}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const s=Ge(t.constructor),n=new Float32Array(t.length);for(let i=0,r=t.length;i<r;i++)n[i]=t[i]*s;t=n}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(s){const n=this instanceof at?Es:Ot;return new n(this.times,this.values,this.getValueSize()/3,s)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function Ns(o,e,t){const s=e.attributes,n=new be;if(s.POSITION!==void 0){const a=t.json.accessors[s.POSITION],c=a.min,l=a.max;if(c!==void 0&&l!==void 0){if(n.set(new I(c[0],c[1],c[2]),new I(l[0],l[1],l[2])),a.normalized){const u=Ge(Q[a.componentType]);n.min.multiplyScalar(u),n.max.multiplyScalar(u)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;const i=e.targets;if(i!==void 0){const a=new I,c=new I;for(let l=0,u=i.length;l<u;l++){const d=i[l];if(d.POSITION!==void 0){const f=t.json.accessors[d.POSITION],p=f.min,g=f.max;if(p!==void 0&&g!==void 0){if(c.setX(Math.max(Math.abs(p[0]),Math.abs(g[0]))),c.setY(Math.max(Math.abs(p[1]),Math.abs(g[1]))),c.setZ(Math.max(Math.abs(p[2]),Math.abs(g[2]))),f.normalized){const b=Ge(Q[f.componentType]);c.multiplyScalar(b)}a.max(c)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}n.expandByVector(a)}o.boundingBox=n;const r=new Sn;n.getCenter(r.center),r.radius=n.min.distanceTo(n.max)/2,o.boundingSphere=r}function pt(o,e,t){const s=e.attributes,n=[];function i(r,a){return t.getDependency("accessor",r).then(function(c){o.setAttribute(a,c)})}for(const r in s){const a=He[r]||r.toLowerCase();a in o.attributes||n.push(i(s[r],a))}if(e.indices!==void 0&&!o.index){const r=t.getDependency("accessor",e.indices).then(function(a){o.setIndex(a)});n.push(r)}return ct.workingColorSpace!==G&&"COLOR_0"in s&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${ct.workingColorSpace}" not supported.`),F(o,e),Ns(o,e,t),Promise.all(n).then(function(){return e.targets!==void 0?As(o,e.targets,t):o})}async function Cs(o,e=!1,t){const s=new Uint8Array(await o.slice(0,33).arrayBuffer());t===void 0?vn(s):_n(s,t);const n=await createImageBitmap(o,{colorSpaceConversion:e?"none":"default"});try{const i=new OffscreenCanvas(n.width,n.height),r=i.getContext("2d",{willReadFrequently:!0});if(!r)throw new Error("Could not decode the PNG.");r.drawImage(n,0,0);const a=r.getImageData(0,0,i.width,i.height);return{width:i.width,height:i.height,data:new Uint8Array(a.data.buffer)}}finally{n.close()}}function h(o){const e=document.getElementById(o);if(!e)throw new Error("Missing viewer control "+o);return e}const X=h("viewport"),L=h("status"),kt=h("previewLabel"),q=h("export"),Ue=h("pixelArt"),je=h("smoothEdges"),$e=new Un,Pt=h("cpuPreview"),ne=h("gpuPreview"),pe=h("materialLighting"),me=h("supersampling"),K=o=>o.getAttribute("aria-pressed")==="true";let P,$="gpu";X.append($e.canvas);const ae=new Mn,H=new Nn(16,32,4478570,2569798);ae.add(H);const Ft=new bt(16777215,1.5);Ft.position.set(2,3,2);ae.add(new Cn(16777215,.85),Ft);const A=new Lt(-1,1,1,-1,.01,300);A.position.set(2.7,1.8,2.5);const O=new jn(A,X);O.target.y=.4;O.enableDamping=!0;O.minZoom=.15;O.maxZoom=12;let Be=1.1;function we(){const{clientWidth:o,clientHeight:e}=X;if(!o||!e)return;P?.setPixelRatio(Math.min(devicePixelRatio,2)*(K(me)?2:1)),P?.setSize(o,e,!1);const t=o/e;A.left=-Be*Math.max(1,t),A.right=-A.left,A.top=Be*Math.max(1,1/t),A.bottom=-A.top,A.updateProjectionMatrix()}function Ee(o){if(o==="gpu"&&!P)try{P=new In({antialias:!0}),P.setClearColor(1186083),P.domElement.addEventListener("webglcontextlost",e=>{e.preventDefault(),ne.disabled=!0,Ee("cpu")}),P.domElement.addEventListener("webglcontextrestored",()=>{ne.disabled=!1}),X.append(P.domElement)}catch{ne.disabled=!0,h("cacheNotice").textContent="WebGL unavailable. Using CPU.",o="cpu"}$=o,$e.canvas.hidden=$!=="cpu",P&&(P.domElement.hidden=$!=="gpu"),Pt.setAttribute("aria-pressed",String($==="cpu")),ne.setAttribute("aria-pressed",String($==="gpu")),Y=0,de=0,re=performance.now(),we()}Pt.addEventListener("click",()=>Ee("cpu"));ne.addEventListener("click",()=>Ee("gpu"));new ResizeObserver(we).observe(X);let Y=0,re=performance.now(),de=0,mt=re;const Is=h("performance");function Dt(o){requestAnimationFrame(Dt),O.update(Math.min(.1,(o-mt)/1e3)),mt=o;const e=performance.now();if($==="gpu"?P?.render(ae,A):$e.render(v,A,K(me),H.visible,H.position.y,K(pe)),de+=performance.now()-e,Y++,o-re>=500){const t=o-re;Is.value=`${Math.round(Y*1e3/t)} FPS · ${(t/Y).toFixed(1)} ms/frame · ${(de/Y).toFixed(1)} ms render CPU`,Y=0,de=0,re=o}}let v=null,R=null,_=[],C=[],ie,ce=null,le=null;const Ke={};let Ve="atlas",J="stack",ue=null,Ht,ge=!0,S=0;const Gt=["targetMesh","targetStack","meshMethod","textureProjection","contourHub","qualityPreset","layers","resolution","threshold","profile","height","pivot","resetReconstruction"].map(o=>h(o)),ze=h("persistentCache"),Te=h("spacing"),Os=h("squash"),ks=h("previewScale");let Ut=3;function Ye(){if(!v)return;const o=new be().setFromObject(v),e=o.getCenter(new I),t=o.getSize(new I),s=Math.max(t.x,t.y,t.z,.01),n=s*2.65;Be=s*.86,Ut=n,O.target.copy(e),A.position.copy(e).addScaledVector(new I(1.35,.95,1).normalize(),n),A.near=Math.max(1e-4,s/200),A.far=Math.max(300,n*50),we(),Je(),Qe()}function Je(){if(!v)return;const o=new be().setFromObject(v),e=o.getSize(new I);H.scale.setScalar(Math.max(e.x,e.y,e.z,.01)),H.position.y=o.min.y-H.scale.x*.002}function Qe(){const o=new Dn().setFromVector3(A.position.clone().sub(O.target));o.phi=Math.acos(Math.min(.9999,Os.valueAsNumber)),o.radius=Ut,A.zoom=ks.valueAsNumber,A.updateProjectionMatrix(),A.position.copy(O.target).add(new I().setFromSpherical(o)),O.update()}function jt(o,e){v&&(ae.remove(v),We(v)),v=o,ae.add(o),e?Ye():Je(),X.dataset.ready="true"}function Ze(){const o=R?.target==="stack"&&v!==null;Ue.disabled=!o,je.disabled=!o,o&&On(v,Ue.getAttribute("aria-pressed")==="true",je.getAttribute("aria-pressed")==="true")}function ye(){Te.disabled=R?.target!=="stack",R?.target==="stack"&&v&&(v.scale.y=Te.valueAsNumber,Je())}for(const o of[Ue,je])o.addEventListener("click",()=>{o.setAttribute("aria-pressed",String(o.getAttribute("aria-pressed")!=="true")),Ze()});h("showGrid").addEventListener("click",o=>{H.visible=!H.visible,o.currentTarget.setAttribute("aria-pressed",String(H.visible))});for(const o of[pe,me,ze])o.addEventListener("click",()=>{o.setAttribute("aria-pressed",String(!K(o))),o===pe&&R&&v&&_t(v,K(o)),o===me&&we()});function Re(o,e,t){const s=h(o),n=h(o+"Value");s.addEventListener("input",()=>{n.value=e(s.valueAsNumber),t()})}Re("spacing",o=>o.toFixed(2)+"×",ye);Re("squash",o=>o.toFixed(2),Qe);Re("previewScale",o=>o.toFixed(2)+"×",Qe);Re("rotationSpeed",o=>o+"°/s",()=>{const o=h("rotationSpeed").valueAsNumber;O.autoRotate=o>0,O.autoRotateSpeed=o/6});function et(){clearTimeout(Ht)}function Xe(o,e){h(o).replaceChildren(...e.map(s=>{const n=document.createElement("li");return n.textContent=s,n}))}function tt(o,e,t=!1,s){R=o,ie=s,C=s?qn(s,_):[];const n=C.length?Ct(C):Fn(R);R.target==="stack"&&(n.scale.y=Te.valueAsNumber),K(pe)&&_t(n,!0),jt(n,ge),ge=!1,ye(),Ze(),kt.textContent=R.target==="mesh"?"Mesh preview":"Sprite stack preview",q.disabled=t;const i=new be().setFromObject(n).getSize(new I),r=(C.length?[i.x,i.z,i.y]:R.size).map(c=>c.toFixed(2)).join(" × "),a=R.target==="mesh"?`${(R.indices.length/3).toLocaleString()} triangles`:`${R.layers} slices`;L.value=`${r} units · ${C.length?C.length+" parts · ":""}${a} · ${e}`,X.dataset.partCount=String(C.length||1)}function Ie(o,e,t=!1){tt(o.result,t?e+" · Building full resolution…":e,t,o.parts),Xe("mappedViews",o.inspection.views.map(s=>`${s.direction} ${s.width}×${s.height}`)),Xe("warnings",o.inspection.warnings)}function U(o=125){et();const e=++S;q.disabled=!0;let t;if(Ve==="atlas"&&_.length)t={parts:_.map(({atlas:u,layout:d,size:f})=>({atlas:u,layout:d,size:f}))};else if(Ve==="atlas"){if(!ce){L.value="Load a PNG atlas.";return}const u=h("layout").value;try{kn(u)}catch(d){L.value=d.message;return}t={atlas:ce,layout:u}}else{const u=Number(h("viewCount").value),d=vt.slice(0,u),f=d.filter(p=>!Ke[p]);if(f.length){L.value="Add views: "+f.join(", ");return}t={files:Object.fromEntries(d.map(p=>[p,Ke[p]]))}}for(const u of Gt)u.disabled=!1;for(const u of["height","pivot","layout","profile"])h(u).disabled="parts"in t;const s=h("meshMethod").value,n=J==="mesh"&&s==="contour",i=n&&h("contourHub").checked;h("meshOptions").hidden=J!=="mesh",h("resolutionName").textContent=i?"Hub segments":"Texture resolution";const r=h("resolution").valueAsNumber;if(h("resolutionValue").value=i?String(r):st(r),h("hubOption").hidden=!n,n){for(const u of["qualityPreset","layers","profile"])h(u).disabled=!0;h("resolution").disabled=!i}const a=u=>h(u).valueAsNumber,c={textureProjection:J==="mesh"?h("textureProjection").value:void 0,meshMethod:n?s:void 0,contourHub:i||void 0,layers:a("layers"),resolution:a("resolution"),threshold:a("threshold"),height:a("height"),pivot:h("pivot").value,profile:"parts"in t?"silhouette":h("profile").value};L.value="Reconstructing…";const l=J;Ht=setTimeout(async()=>{try{await Ps(e,t,l,c)}catch(u){e===S&&(L.value=u.message)}},o)}async function Ps(o,e,t,s){const n=await Kn(e);if(o!==S)return;const i=K(ze),r=JSON.stringify([n,t,s]),a=await lt(r,i);if(o!==S)return;if(a){Ie(a.value,a.origin);return}let c=s.meshMethod!=="contour"&&(s.layers>45||s.resolution>96)?{...s,layers:Math.min(45,s.layers),resolution:Math.min(96,s.resolution)}:void 0;const l=JSON.stringify([n,t,c]);if(c){const f=await lt(l,i);if(o!==S)return;f&&(Ie(f.value,f.origin,!0),c=void 0)}const u=ue??=new Worker(new URL(""+new URL("reconstruct.worker-ONc9GyFO.js",import.meta.url).href,import.meta.url),{type:"module"}),d=qe;u.onmessage=({data:f})=>{if(!(ue!==u||f.id!==o||o!==S)){if("error"in f){L.value=f.error;return}d===qe&&Vn(f.preview?l:r,f,K(ze)),Ie(f,"Built from source · "+Math.round(f.elapsed)+" ms",f.preview)}},u.onerror=()=>{ue===u&&(u.terminate(),ue=null,o===S&&(L.value="Could not start the reconstruction worker."))},u.postMessage({id:o,sourceKey:n,source:e,target:t,settings:s,preview:c})}let qe=0;h("clearCache").addEventListener("click",async()=>{qe++;const o=h("cacheNotice");try{await Bn(),o.textContent="Cache cleared."}catch{o.textContent="Could not clear the disk cache."}});function nt(o,e=!0){Ve=o,h("atlasFields").hidden=o!=="atlas",h("separateFields").hidden=o!=="files",h("modeAtlas").setAttribute("aria-pressed",String(o==="atlas")),h("modeFiles").setAttribute("aria-pressed",String(o==="files")),e&&U(0)}function xe(o,e,t=[]){ce=o,_=t,Bt(),ge=!0;const s=h("sourceImage");le&&URL.revokeObjectURL(le),le=URL.createObjectURL(o),s.src=le,s.hidden=!1,e&&(h("layout").value=e),nt("atlas")}function Bt(){const o=h("assemblyEditor");o.hidden=!_.length;const e=_.reduce((t,s)=>t+s.mounts.length,0);h("assemblySummary").textContent=`${_.length} atlases · ${e} parts`,h("partMounts").replaceChildren(..._.flatMap((t,s)=>t.mounts.map(n=>Fs(n,s))))}function Fs(o,e){const t=document.createElement("fieldset"),s=document.createElement("legend");s.textContent=o.name;const n=document.createElement("div");for(const[r,a]of["X","Depth","Height","Scale"].entries()){const c=document.createElement("label"),l=document.createElement("input");l.type="number",l.step=".05",l.min=r===3?".05":"-20",l.max="20",l.value=(r===3?o.scale??1:o.position[r]).toFixed(3),c.append(a,l),l.addEventListener("change",()=>{if(!(!Number.isFinite(l.valueAsNumber)||l.validity.rangeUnderflow||l.validity.rangeOverflow)&&(r===3?o.scale=l.valueAsNumber:o.position[r]=l.valueAsNumber,R&&ie&&ie.length===_.length)){const u=!q.disabled;tt(R,"Assembly placement updated",!u,ie)}}),n.append(c)}const i=document.createElement("button");return i.type="button",i.textContent="Remove part",i.disabled=_.reduce((r,a)=>r+a.mounts.length,0)===1,i.addEventListener("click",()=>{const r=_[e];r.mounts=r.mounts.filter(a=>a!==o),r.mounts.length||_.splice(e,1),h("samplePreset").value="",Bt(),U(0)}),t.append(s,n,i),t}const fe=h("partFiles");h("addParts").addEventListener("click",()=>fe.click());fe.addEventListener("change",()=>{const o=Array.from(fe.files??[]);if(fe.value="",!o.length)return;if(o.some(s=>!/\.png$/i.test(s.name))){L.value="Choose four-view PNGs.";return}const e=_.length?_:ce?[{atlas:ce,layout:h("layout").value,name:"Base",mounts:[{name:"Base",position:[0,0,0]}]}]:[];if(e.length+o.length>12){L.value="An assembly supports up to 12 atlases.";return}const t=[...e,...o.map((s,n)=>({atlas:s,name:s.name,layout:"top,left,front,rear",mounts:[{name:s.name,position:[.7*(e.length+n),0,0],scale:e.length+n?.6:1}]}))];h("samplePreset").value="",xe(t[0].atlas,t[0].layout,t)});for(const[o,e]of vt.entries()){const t=document.createElement("div"),s=document.createElement("label");s.htmlFor="view-"+e,s.textContent=e;const n=document.createElement("input");n.id=s.htmlFor,n.type="file",n.accept="image/png,.png",n.addEventListener("change",()=>{n.files?.[0]&&(Ke[e]=n.files[0]),ge=!0,U(0)}),t.append(s,n),t.dataset.direction=e,t.hidden=o>=4,h("viewFiles").append(t)}h("viewCount").addEventListener("change",o=>{const e=o.currentTarget;for(const[t,s]of Array.from(h("viewFiles").children).entries())s.hidden=t>=Number(e.value);U(0)});h("modeAtlas").addEventListener("click",()=>nt("atlas"));h("modeFiles").addEventListener("click",()=>nt("files"));h("atlas").addEventListener("change",o=>{const e=o.currentTarget.files?.[0];e&&(h("samplePreset").value="",h("profile").value="silhouette",xe(e))});h("samplePreset").addEventListener("change",async o=>{const e=++S,t=o.currentTarget.value;if(t){et(),q.disabled=!0,L.value="Loading sample…";try{const s="top,left,front,rear",n=async r=>{const a=await fetch(r);if(!a.ok)throw new Error("Could not load the sample atlas.");return a.blob()},i=Xn[t];if(i){const r=await Promise.all(i.map(async a=>({...a,mounts:structuredClone(a.mounts),atlas:await n(a.url),layout:s})));e===S&&(h("profile").value="silhouette",xe(r[0].atlas,s,r))}else{const r=await n(Mt[t]);e===S&&(h("profile").value=t==="cone"?"round-base":"silhouette",xe(r,s))}}catch(s){e===S&&(L.value=s.message)}}});h("resetCamera").addEventListener("click",Ye);for(const[o,e]of[["targetMesh","mesh"],["targetStack","stack"]])h(o).addEventListener("click",()=>{J!==e&&(J=e,h("targetMesh").setAttribute("aria-pressed",String(e==="mesh")),h("targetStack").setAttribute("aria-pressed",String(e==="stack")),q.textContent=e==="mesh"?"Export GLB":"Export stack",U(0))});for(const[o,e]of[["layers","layerValue"],["resolution","resolutionValue"],["threshold","thresholdValue"]]){const t=h(o);t.addEventListener("input",()=>{!t.validity.valid||!Number.isFinite(t.valueAsNumber)||(h(e).value=o==="resolution"?st(t.valueAsNumber):t.value,o!=="threshold"&&(h("qualityPreset").value=""),U())})}for(const o of["height","pivot","layout","profile","meshMethod","textureProjection","contourHub"])h(o).addEventListener("change",()=>U(0));function st(o){return`${o} px · ${(o/Nt.balanced.resolution).toFixed(2)}×`}function Kt(o){const{layers:e,resolution:t}=Nt[o];h("layers").value=h("layerValue").value=String(e),h("resolution").value=String(t),h("resolutionValue").value=st(t)}h("qualityPreset").addEventListener("change",o=>{const e=o.currentTarget.value;e&&(Kt(e),U(0))});h("resetReconstruction").addEventListener("click",()=>{h("meshMethod").value="marching-cubes",h("textureProjection").value="auto",h("contourHub").checked=!1,h("qualityPreset").value="standard",h("profile").value=h("samplePreset").value==="cone"?"round-base":"silhouette",Kt("standard");for(const[o,e]of[["height","1"],["pivot","ground"],["threshold","238"],["thresholdValue","238"],["spacing","1"],["squash",".75"],["previewScale","1"],["rotationSpeed","0"]])h(o).value=e;for(const[o,e]of[["spacingValue","1.00×"],["squashValue","0.75"],["previewScaleValue","1.00×"],["rotationSpeedValue","0°/s"]])h(o).value=e;O.autoRotate=!1,ye(),Ye(),U(0)});function Oe(o,e,t){const s=URL.createObjectURL(new Blob([new Uint8Array(o)],{type:t})),n=document.createElement("a");n.href=s,n.download=e,n.click(),setTimeout(()=>URL.revokeObjectURL(s),1e3)}q.addEventListener("click",async()=>{if(R)try{if(R.target==="stack"){const o=C.length?Wn(C):R;Oe(Hn($n(o,Te.valueAsNumber)),"stack3-stack.zip","application/zip")}else if(C.length){const o=Ct(C);try{const{GLTFExporter:e}=await zn(async()=>{const{GLTFExporter:s}=await import("./GLTFExporter-xdVCArY-.js");return{GLTFExporter:s}},__vite__mapDeps([0,1,2]),import.meta.url),t=await new e().parseAsync(o,{binary:!0});if(!(t instanceof ArrayBuffer))throw new Error("Could not export assembly as GLB.");Oe(new Uint8Array(t),"stack3-assembly.glb","model/gltf-binary")}finally{We(o)}}else Oe(Gn(R),"stack3.glb","model/gltf-binary")}catch(o){L.value=o.message}});h("openGlb").addEventListener("click",()=>h("glb").click());h("glb").addEventListener("change",async o=>{const e=o.currentTarget,t=e.files?.[0];if(e.value="",!t)return;et();const s=++S;R=null,C=[],ie=void 0,ye(),Ze(),q.disabled=!0;try{const n=await t.arrayBuffer(),i=new DataView(n);if(n.byteLength<20||i.getUint32(0,!0)!==1179937895||i.getUint32(12,!0)>n.byteLength-20)throw new Error("Expected a GLB file.");const r=JSON.parse(new TextDecoder().decode(new Uint8Array(n,20,i.getUint32(12,!0))));if([...r.images??[],...r.buffers??[]].some(c=>c.uri&&!c.uri.startsWith("data:")))throw new Error("Open a GLB with embedded textures and buffers.");const a=await new Yn().parseAsync(n,"");if(s!==S){We(a.scene);return}jt(a.scene,!0),kt.textContent="GLB preview",L.value=t.name+" · Opened",Xe("warnings",[])}catch(n){s===S&&(L.value=n.message)}});async function Ds(o){const e=++S;L.value="Opening stack…";try{const t=new URL(`__stack3/${o}/`,location.href),[s,n]=await Promise.all([fetch(new URL("stack.json",t)),fetch(new URL("stack.png",t))]);if(!s.ok||!n.ok)throw new Error("Could not open this CLI stack bundle.");const i=await s.json(),r=await Cs(await n.blob(),!1,i);if(e!==S)return;tt(Pn(i,r),"Opened stack bundle");for(const a of Gt)a.disabled=!0}catch(t){e===S&&(L.value=t.message)}}const Vt=new URLSearchParams(location.search),ke=Vt.get("stack");Ee("gpu");requestAnimationFrame(Dt);if(ke&&/^[a-f0-9-]{36}$/.test(ke))Ds(ke);else{const o=Vt.get("preset");if(o&&Object.hasOwn(Mt,o)){const e=h("samplePreset");e.value=o,e.dispatchEvent(new Event("change"))}}
|
package/viewer/dist/compare.html
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
6
|
<link rel="icon" href="data:,">
|
|
7
7
|
<title>stack3.js · 4-view comparison</title>
|
|
8
|
-
<script type="module" crossorigin src="./assets/compare-
|
|
9
|
-
<link rel="modulepreload" crossorigin href="./assets/style-
|
|
10
|
-
<link rel="modulepreload" crossorigin href="./assets/presets-
|
|
8
|
+
<script type="module" crossorigin src="./assets/compare-Du4RoRQO.js"></script>
|
|
9
|
+
<link rel="modulepreload" crossorigin href="./assets/style-D6eZHs3D.js">
|
|
10
|
+
<link rel="modulepreload" crossorigin href="./assets/presets-jXE0t1fU.js">
|
|
11
11
|
<link rel="stylesheet" crossorigin href="./assets/style-CMUT8CmM.css">
|
|
12
12
|
<link rel="stylesheet" crossorigin href="./assets/compare-B6DWTZS9.css">
|
|
13
13
|
</head>
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
<div><label for="yaw">Orbit <output id="yaw-value">45°</output></label><input id="yaw" type="range" min="-180" max="180" value="45"></div>
|
|
32
32
|
<div><label for="pitch">Elevation <output id="pitch-value">24°</output></label><input id="pitch" type="range" min="-10" max="90" value="24"></div>
|
|
33
33
|
<div><label for="zoom">Zoom <output id="zoom-value">1×</output></label><input id="zoom" type="range" min="0.75" max="3" step="0.05" value="1"></div>
|
|
34
|
-
<div><label for="layers">Layers <output id="layers-value">
|
|
34
|
+
<div><label for="layers">Layers <output id="layers-value">128</output></label><input id="layers" type="number" min="8" step="1" value="128" disabled></div>
|
|
35
35
|
<div><label for="spacing">Spacing <output id="spacing-value">1.00×</output></label><input id="spacing" type="range" min="0.50" max="2.50" step="0.05" value="1" disabled></div>
|
|
36
36
|
<div><label for="explode">Explode <output id="explode-value">0%</output></label><input id="explode" type="range" min="0" max="100" step="1" value="0" disabled></div>
|
|
37
37
|
<div class="compare-actions">
|
package/viewer/dist/index.html
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
6
|
<link rel="icon" href="data:,">
|
|
7
7
|
<title>stack3.js · Asset Viewer</title>
|
|
8
|
-
<script type="module" crossorigin src="./assets/viewer-
|
|
9
|
-
<link rel="modulepreload" crossorigin href="./assets/style-
|
|
10
|
-
<link rel="modulepreload" crossorigin href="./assets/preview-cache-
|
|
11
|
-
<link rel="modulepreload" crossorigin href="./assets/presets-
|
|
8
|
+
<script type="module" crossorigin src="./assets/viewer-DIjS0No7.js"></script>
|
|
9
|
+
<link rel="modulepreload" crossorigin href="./assets/style-D6eZHs3D.js">
|
|
10
|
+
<link rel="modulepreload" crossorigin href="./assets/preview-cache-BKV0EZl9.js">
|
|
11
|
+
<link rel="modulepreload" crossorigin href="./assets/presets-jXE0t1fU.js">
|
|
12
12
|
<link rel="stylesheet" crossorigin href="./assets/style-CMUT8CmM.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
|
@@ -80,13 +80,14 @@
|
|
|
80
80
|
<select id="qualityPreset">
|
|
81
81
|
<option value="">Custom</option>
|
|
82
82
|
<option value="draft">Draft · 24 layers</option>
|
|
83
|
-
<option value="
|
|
83
|
+
<option value="standard" selected>Standard · 128 layers</option>
|
|
84
|
+
<option value="balanced">Balanced · 48 layers</option>
|
|
84
85
|
<option value="detail">Detail · 90 layers</option>
|
|
85
86
|
</select>
|
|
86
|
-
<label for="layers">Layers <output id="layerValue">
|
|
87
|
-
<input id="layers" type="
|
|
87
|
+
<label for="layers">Layers <output id="layerValue">128</output></label>
|
|
88
|
+
<input id="layers" type="number" min="8" step="1" value="128">
|
|
88
89
|
<label for="resolution"><span id="resolutionName">Texture resolution</span> <output id="resolutionValue">96 px · 1.00×</output></label>
|
|
89
|
-
<input id="resolution" type="
|
|
90
|
+
<input id="resolution" type="number" min="16" step="1" value="96">
|
|
90
91
|
<label for="threshold">Background threshold <output id="thresholdValue">238</output></label>
|
|
91
92
|
<input id="threshold" type="range" min="180" max="255" value="238">
|
|
92
93
|
<label for="profile">Cross-section</label>
|
package/viewer/dist/project.html
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
6
|
<link rel="icon" href="data:,">
|
|
7
7
|
<title>stack3.js · Scene editor</title>
|
|
8
|
-
<script type="module" crossorigin src="./assets/project-
|
|
9
|
-
<link rel="modulepreload" crossorigin href="./assets/style-
|
|
10
|
-
<link rel="modulepreload" crossorigin href="./assets/preview-cache-
|
|
8
|
+
<script type="module" crossorigin src="./assets/project-DtHHhfo-.js"></script>
|
|
9
|
+
<link rel="modulepreload" crossorigin href="./assets/style-D6eZHs3D.js">
|
|
10
|
+
<link rel="modulepreload" crossorigin href="./assets/preview-cache-BKV0EZl9.js">
|
|
11
11
|
<link rel="stylesheet" crossorigin href="./assets/style-CMUT8CmM.css">
|
|
12
12
|
<link rel="stylesheet" crossorigin href="./assets/project-BzR9Ensg.css">
|
|
13
13
|
</head>
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{G as ae,b as P,q as oe,V as y,W as he,O as we,e as fe,C as be,r as $,s as ye,A as Me,M as ne,g as ve,L as re,p as xe,t as Le,u as Ze}from"./style-CWGgpweN.js";import{m as Se,i as We,c as De}from"./presets-DwdZVYhs.js";const A=e=>document.getElementById(e),se=A("comparison-status"),Q=A("atlas"),w=A("part"),X=A("yaw"),V=A("pitch"),z=A("zoom"),K=A("layers"),F=A("spacing"),M=A("explode"),Y=A("clay"),Be=document.querySelector(".compare-results"),le=new URLSearchParams(location.search),E=le.get("session"),O=E&&/^[a-f0-9-]{36}$/.test(E)?"./__stack3_project/"+E:void 0;let L,v=0,N,ge,k,J=[],Ie,U=1;const _=new y;let Ce=[],T=0;const ee="top,left,front,rear",W={layers:80,resolution:144},q=Se.tank,ce="Future Tank · hull material passes",S={source:new URL(""+new URL("hull-4view-BPPqJYUz.png",import.meta.url).href,import.meta.url),clay:new URL(""+new URL("hull-clay-4view-3Cu-4Hvr.png",import.meta.url).href,import.meta.url),depth:new URL(""+new URL("hull-depth-4view-DCOdT5ev.png",import.meta.url).href,import.meta.url),baseColor:new URL(""+new URL("hull-base-color-4view-DrQmdT3h.png",import.meta.url).href,import.meta.url),normal:new URL(""+new URL("hull-normal-4view-CvLaFITy.png",import.meta.url).href,import.meta.url),calibration:new URL("data:application/json;base64,ewogICJzb3VyY2VBdGxhcyI6ICJodWxsLTR2aWV3LnBuZyIsCiAgImdlb21ldHJ5IjogInN0YWNrMyByZWd1bGFyaXplZCB2aXN1YWwgaHVsbCBmcm9tIHRoZSBSR0IgYXRsYXMgc2lsaG91ZXR0ZXMsIHdpdGggdGhlIHR1cm50YWJsZSBhbmQgbGFyZ2UgaGF0Y2ggcmVsaWVmIGd1aWRlZCBieSB2aXNpYmxlIHNvdXJjZSBnZW9tZXRyeSIsCiAgImRpbWVuc2lvbnMiOiBbCiAgICAxODc0LAogICAgNjkyCiAgXSwKICAibGF5b3V0IjogWwogICAgInRvcCIsCiAgICAibGVmdCIsCiAgICAiZnJvbnQiLAogICAgInJlYXIiCiAgXSwKICAicGl4ZWxzUGVyVW5pdCI6IDIwMCwKICAiZ3JvdW5kWSI6IDQ0MCwKICAiY2xheSI6IHsKICAgICJmaWxlIjogImh1bGwtY2xheS00dmlldy5wbmciLAogICAgImJhY2tncm91bmQiOiAidHJhbnNwYXJlbnQiCiAgfSwKICAiZGVwdGgiOiB7CiAgICAiZmlsZSI6ICJodWxsLWRlcHRoLTR2aWV3LnBuZyIsCiAgICAiZW5jb2RpbmciOiAiMTYtYml0IHVuc2lnbmVkIGdyYXlzY2FsZSwgbGluZWFyIGludmVyc2UgY2FtZXJhIGRpc3RhbmNlIiwKICAgICJiYWNrZ3JvdW5kIjogMCwKICAgICJ2YWxpZFJhbmdlIjogWwogICAgICAxLAogICAgICA2NTUzNQogICAgXSwKICAgICJkZWNvZGUiOiAiZGlzdGFuY2UgPSBuZWFyICsgKGZhciAtIG5lYXIpICogKDY1NTM1IC0gdmFsdWUpIC8gNjU1MzQiLAogICAgInVuaXRzIjogInN0YWNrMyBzY2VuZSB1bml0cyIsCiAgICAicGl4ZWxDZW50ZXJPZmZzZXQiOiAwLjUKICB9LAogICJ2aWV3cyI6IHsKICAgICJ0b3AiOiB7CiAgICAgICJyZWN0IjogWwogICAgICAgIDAsCiAgICAgICAgMCwKICAgICAgICAzOTYsCiAgICAgICAgNjkyCiAgICAgIF0sCiAgICAgICJhbmNob3IiOiBbCiAgICAgICAgMTk5LAogICAgICAgIDM0NgogICAgICBdLAogICAgICAib3JpZ2luIjogWwogICAgICAgIDAsCiAgICAgICAgMS4wNCwKICAgICAgICAwCiAgICAgIF0sCiAgICAgICJyaWdodCI6IFsKICAgICAgICAtMSwKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXSwKICAgICAgInVwIjogWwogICAgICAgIDAsCiAgICAgICAgMCwKICAgICAgICAxCiAgICAgIF0sCiAgICAgICJmb3J3YXJkIjogWwogICAgICAgIDAsCiAgICAgICAgLTEsCiAgICAgICAgMAogICAgICBdLAogICAgICAibmVhciI6IDAsCiAgICAgICJmYXIiOiAxLjE0CiAgICB9LAogICAgImxlZnQiOiB7CiAgICAgICJyZWN0IjogWwogICAgICAgIDM5NiwKICAgICAgICAwLAogICAgICAgIDY4OCwKICAgICAgICA2OTIKICAgICAgXSwKICAgICAgImFuY2hvciI6IFsKICAgICAgICA3NDAsCiAgICAgICAgNDQwCiAgICAgIF0sCiAgICAgICJvcmlnaW4iOiBbCiAgICAgICAgLTAuOTQ1LAogICAgICAgIDAsCiAgICAgICAgMAogICAgICBdLAogICAgICAicmlnaHQiOiBbCiAgICAgICAgMCwKICAgICAgICAwLAogICAgICAgIDEKICAgICAgXSwKICAgICAgInVwIjogWwogICAgICAgIDAsCiAgICAgICAgMSwKICAgICAgICAwCiAgICAgIF0sCiAgICAgICJmb3J3YXJkIjogWwogICAgICAgIDEsCiAgICAgICAgMCwKICAgICAgICAwCiAgICAgIF0sCiAgICAgICJuZWFyIjogMCwKICAgICAgImZhciI6IDEuODkKICAgIH0sCiAgICAiZnJvbnQiOiB7CiAgICAgICJyZWN0IjogWwogICAgICAgIDEwODQsCiAgICAgICAgMCwKICAgICAgICAzOTQsCiAgICAgICAgNjkyCiAgICAgIF0sCiAgICAgICJhbmNob3IiOiBbCiAgICAgICAgMTI4MSwKICAgICAgICA0NDAKICAgICAgXSwKICAgICAgIm9yaWdpbiI6IFsKICAgICAgICAwLAogICAgICAgIDAsCiAgICAgICAgLTEuNjgwMDAwMDAwMDAwMDAwMgogICAgICBdLAogICAgICAicmlnaHQiOiBbCiAgICAgICAgLTEsCiAgICAgICAgMCwKICAgICAgICAwCiAgICAgIF0sCiAgICAgICJ1cCI6IFsKICAgICAgICAwLAogICAgICAgIDEsCiAgICAgICAgMAogICAgICBdLAogICAgICAiZm9yd2FyZCI6IFsKICAgICAgICAwLAogICAgICAgIDAsCiAgICAgICAgMQogICAgICBdLAogICAgICAibmVhciI6IDAsCiAgICAgICJmYXIiOiAzLjM2MDAwMDAwMDAwMDAwMDMKICAgIH0sCiAgICAicmVhciI6IHsKICAgICAgInJlY3QiOiBbCiAgICAgICAgMTQ3OCwKICAgICAgICAwLAogICAgICAgIDM5NiwKICAgICAgICA2OTIKICAgICAgXSwKICAgICAgImFuY2hvciI6IFsKICAgICAgICAxNjc1LAogICAgICAgIDQ0MAogICAgICBdLAogICAgICAib3JpZ2luIjogWwogICAgICAgIDAsCiAgICAgICAgMCwKICAgICAgICAxLjY4MDAwMDAwMDAwMDAwMDIKICAgICAgXSwKICAgICAgInJpZ2h0IjogWwogICAgICAgIDEsCiAgICAgICAgMCwKICAgICAgICAwCiAgICAgIF0sCiAgICAgICJ1cCI6IFsKICAgICAgICAwLAogICAgICAgIDEsCiAgICAgICAgMAogICAgICBdLAogICAgICAiZm9yd2FyZCI6IFsKICAgICAgICAwLAogICAgICAgIDAsCiAgICAgICAgLTEKICAgICAgXSwKICAgICAgIm5lYXIiOiAwLAogICAgICAiZmFyIjogMy4zNjAwMDAwMDAwMDAwMDAzCiAgICB9CiAgfSwKICAiYmFzZUNvbG9yIjogewogICAgImZpbGUiOiAiaHVsbC1iYXNlLWNvbG9yLTR2aWV3LnBuZyIsCiAgICAiZW5jb2RpbmciOiAiUkdCQTggc1JHQiIsCiAgICAic291cmNlIjogImdlbmVyYXRlZCBtYXRlcmlhbCBwYXNzIHJlZ2lzdGVyZWQgcGVyIHZpZXcgdG8gdGhlIENsYXkgc2lsaG91ZXR0ZXMiCiAgfSwKICAibm9ybWFsIjogewogICAgImZpbGUiOiAiaHVsbC1ub3JtYWwtNHZpZXcucG5nIiwKICAgICJlbmNvZGluZyI6ICJSR0JBOCBsaW5lYXIgZGF0YSIsCiAgICAic3BhY2UiOiAidmlldyIsCiAgICAiYXhlcyI6IHsKICAgICAgInJlZCI6ICIrWCBpbWFnZSByaWdodCIsCiAgICAgICJncmVlbiI6ICIrWSBpbWFnZSB1cCIsCiAgICAgICJibHVlIjogIitaIHRvd2FyZCB0aGUgY2FtZXJhIgogICAgfSwKICAgICJkZWNvZGUiOiAibm9ybWFsID0gbm9ybWFsaXplKDIgKiBSR0IgLyAyNTUgLSAxKSIsCiAgICAiYmFja2dyb3VuZCI6ICJhbHBoYSAwIgogIH0sCiAgInNpemUiOiBbCiAgICAxLjY5LAogICAgMy4xNiwKICAgIDAuOTQKICBdCn0K",import.meta.url)},Ae=["Armored tank · full (assembled)",...q.map(e=>"Armored tank · "+e.name.toLowerCase()),ce],D=["Voxel surface","Marching Cubes","Finer grid","RGB · nearest","RGB · linear","RGB + ID","RGB + ID + depth"];function Z(e,s=!1){se.value=e,se.dataset.error=String(s)}function Ke(){const e=new he({antialias:!0}),s=Math.min(devicePixelRatio,2),t=new we(-1,1,1,-1,.01,50),a=new fe;a.background=new be("#121923");const n=new $({color:"#b4bac3",roughness:.85}),o=new ye("#fff2e5",2.6);o.position.set(3,6,-4),a.add(o,new Me("#b6c9e4",1.5));let r=0,i=0;return{gray:n,draw(g,l,C){const c=Math.round(l.clientWidth*s),d=Math.round(l.clientHeight*s);if(!c||!d)return;const b=c/d,I=U/Math.min(1,b)/Number(z.value);t.left=-I*b,t.right=I*b,t.top=I,t.bottom=-I;const p=P.degToRad(Number(X.value)),u=P.degToRad(Number(V.value)),m=Math.max(8,U*4);t.far=m+U*3,t.position.set(Math.sin(p)*Math.cos(u)*m,Math.sin(u)*m,-Math.cos(p)*Math.cos(u)*m).add(_),t.lookAt(_),t.updateProjectionMatrix(),(c!==r||d!==i)&&(e.setSize(c,d,!1),r=c,i=d),(l.width!==c||l.height!==d)&&(l.width=c,l.height=d),a.add(g),e.render(a,t),C.drawImage(e.domElement,0,0),a.remove(g)}}}function Ne(e,s){const t=new $({map:e.map,roughness:.82});if(e.dispose(),!s)return t;const a=new Le(s.data,s.width,s.height);return a.minFilter=a.magFilter=re,a.needsUpdate=!0,t.normalMap=a,t.normalMapType=Ze,t.onBeforeCompile=n=>{n.fragmentShader=n.fragmentShader.replace("#include <normal_fragment_maps>",`
|
|
2
|
-
vec3 geometricNormal = normal;
|
|
3
|
-
#include <normal_fragment_maps>
|
|
4
|
-
float coverage = texture2D(normalMap, vNormalMapUv).a;
|
|
5
|
-
normal = normalize(mix(geometricNormal, normal, coverage));
|
|
6
|
-
`)},t}function je(e,s,t){const a=s.getContext("2d",{alpha:!1});if(!a)throw new Error("Could not create a thumbnail surface.");const n=We(e.parts.map(I=>I.asset),e.parts),o=e.parts.flatMap(I=>I.mounts),r=e.parts.flatMap(I=>I.mounts.map(()=>I.normalMap)),i=De(n),g=e.nearest?ve:re,l=[],C=[];for(const[I,{asset:p}]of n.entries()){const u=i.children[I],m=o[I].matrix;if(m&&(u.matrix.fromArray(m),u.matrixAutoUpdate=!1,u.matrixWorldNeedsUpdate=!0),p.target==="stack"){C.push({object:u,asset:p});continue}const h=u,f=h.material,x=e.lit?Ne(f,r[I]):f;x.map&&(x.map.minFilter=x.map.magFilter=g,x.map.needsUpdate=!0);const te=!e.geometryOnly&&p.frontAccents,G=te?xe(te):void 0;G&&(G.material.alphaTest=.4,h.add(G)),l.push({mesh:h,textured:x,accent:G})}const c=i.children.map(I=>(I.matrixAutoUpdate&&I.updateMatrix(),I.matrixAutoUpdate=!1,I.matrix.clone()));let d=1,b=0;return{surface:s,isStack:C.length>0,draw(){const I=M.valueAsNumber/100;if(I!==b){for(const[m,h]of i.children.entries()){const f=Ce[m];h.matrix.copy(c[m]),h.matrix.elements[12]+=f.x*I,h.matrix.elements[13]+=f.y*I,h.matrix.elements[14]+=f.z*I,h.matrixWorldNeedsUpdate=!0}b=I}const p=F.valueAsNumber;if(C.length&&p!==d){for(const{object:m,asset:h}of C)for(const[f,x]of m.children.entries())x.position.y=((f+.5)*h.spacing-h.pivot[2])*p;d=p}const u=e.geometryOnly||Y.getAttribute("aria-pressed")==="true";for(const{mesh:m,textured:h,accent:f}of l)m.material=u?t.gray:h,f&&(f.visible=!u);t.draw(i,s,a)},dispose(){for(const{object:I}of C){const p=I.children;p[0]?.geometry.dispose();for(const u of p){const m=u.material;m.map?.dispose(),m.dispose()}}for(const{mesh:I,textured:p,accent:u}of l){if(I.geometry.dispose(),p.map?.dispose(),p instanceof $&&p.normalMap?.dispose(),p.dispose(),!u)continue;u.geometry.dispose();const m=u.material;m.map?.dispose(),m.dispose()}}}}function Fe(e){const s=r=>e.map(i=>({name:i.name,mounts:i.mounts,asset:typeof r=="number"?i.meshes[r]:i[r],grid:r==="voxel"||r==="marching"?i.coarseGrid:i.fullGrid})),t=s(0),a=e.every(r=>r.fullGrid.every((i,g)=>i===r.coarseGrid[g])),n=[{title:"RGB only",detail:"Visual hull and RGB projection",parts:t},{title:"RGB + ID",detail:"Keeps accent colors on visible source-facing surfaces",parts:s(1)},{title:"RGB + ID + depth",detail:"Rebuilds the surface with smoother depth transitions",parts:s(2)}],o=[{title:"Sprite Stack",detail:"Spacing changes the distance between these horizontal slices.",parts:s("stack")},{title:D[0],detail:"Exposed faces of the occupied cells.",parts:s("voxel"),geometryOnly:!0},{title:D[1],detail:"Interpolated surface from the same occupied cells.",parts:s("marching"),geometryOnly:!0},{title:D[2],detail:a?"Only one occupied grid was available at these settings.":"Marching Cubes rebuilt with the full sampling grid.",parts:t,geometryOnly:!0},{title:D[3],detail:"Projects the atlas onto that mesh, using the closest texel.",parts:t,nearest:!0},{title:D[4],detail:"Blends nearby texels on the same textured mesh.",parts:t},n[1],n[2]];if(e.some(r=>r.mapped)){const r=e.map(l=>({name:l.name,mounts:l.mounts,asset:l.mapped?.mesh??l.meshes[0],grid:l.mapped?.grid??l.fullGrid})),i=r.map((l,C)=>({...l,normalMap:e[C].mapped?.normalMap})),g=r.map((l,C)=>({...l,asset:e[C].mapped?.silhouetteMesh??l.asset}));o.unshift({title:"Clay Silhouette Only",detail:"Uses the same calibrated Clay views, grid, and lighting.",parts:g,geometryOnly:!0},{title:"Clay + Depth Map",detail:"Uses the 16-bit depth pass to carve the registered Clay silhouettes.",parts:r,geometryOnly:!0},{title:"Depth + Base Color",detail:"Projects the generated color pass onto the depth-carved mesh.",parts:r,lit:!0},{title:"Depth + Base Color + Normal",detail:"Uses the view-space normal pass for per-pixel lighting on the same mesh.",parts:i,lit:!0})}return o}function Oe(e,s){const t=document.createElement("figure"),a=document.createElement("canvas");a.className="model",a.setAttribute("role","img"),a.setAttribute("aria-label",e.title),t.append(a);const n=document.createElement("figcaption"),o=document.createElement("small"),r=e.parts.map(({name:l,grid:C})=>(l?l+" ":"")+C.join(" × ")).join(" · "),i=e.parts.reduce((l,{asset:C,mounts:c})=>l+(C.target==="stack"?C.layers:C.indices.length/3)*c.length,0),g=e.parts[0].asset.target==="stack"?" slices":" triangles";o.textContent=r+" cells · "+i.toLocaleString()+g,n.append(o),t.append(n),s.append(t),J.push(je(e,a,Ie)),ue.observe(a)}function Je(e){const s=document.createElement("section");s.className="depth-fit";const t=document.createElement("h2");t.textContent="Depth Fit",s.append(t);const a=c=>c===null?"—":c.toFixed(3),n=document.createElement("strong");n.textContent=a(e.baselineMae)+" → "+a(e.carvedMae)+" units",s.append(n);const o=document.createElement("p"),r=e.baselineMae&&e.carvedMae!==null?100*(e.carvedMae/e.baselineMae-1):null;o.textContent="Mean absolute distance error against the supplied depth map"+(r===null?".":" · "+(r>0?"+":"−")+Math.abs(r).toFixed(1)+"%"),s.append(o);const i=document.createElement("table");i.setAttribute("aria-label","Mean absolute depth error by camera");const g=i.createTHead().insertRow();for(const c of["View","Clay only","+ Depth"]){const d=document.createElement("th");d.scope="col",d.textContent=c,g.append(d)}const l=i.createTBody();for(const c of e.byView){const d=l.insertRow();for(const b of[c.view.toUpperCase(),a(c.baselineMae),a(c.carvedMae)])d.insertCell().textContent=b}s.append(i);const C=document.createElement("p");return C.textContent=e.sharedPixels.toLocaleString()+" shared visible pixels · "+(100*e.sharedPixels/Math.max(1,e.referencePixels)).toFixed(1)+"% of reference",s.append(C),s}function Re(e){for(const n of J)ue.unobserve(n.surface),n.dispose();J=[];const s=Fe(e.parts),t=e.parts.find(n=>n.mapped)?.mapped?.fit,a=document.createDocumentFragment();for(const n of s){const o=document.createElement("section"),r=document.createElement("h2"),i=document.createElement("p");r.textContent=n.title,i.textContent=n.detail,o.append(r),Oe(n,o),o.append(i),a.append(o),t&&n.title==="Clay + Depth Map"&&a.append(Je(t))}Be.replaceChildren(a),R()}function R(){T||(T=requestAnimationFrame(()=>{T=0,A("yaw-value").textContent=X.value+"°",A("pitch-value").textContent=V.value+"°",A("zoom-value").textContent=z.value+"×",A("explode-value").textContent=M.value+"%",J.forEach(e=>e.draw())}))}function me(){return window.clearTimeout(ge),N?.terminate(),N=void 0,++v}function de(e,s,t){const a=new Worker(new URL(""+new URL("compare.worker-DK2lJl0n.js",import.meta.url).href,import.meta.url),{type:"module"});N=a,a.onerror=()=>{a.terminate(),t===v&&(N=void 0,Z("The comparison worker could not start.",!0))},a.onmessage=({data:n})=>{if(a.terminate(),t===v){if(N=void 0,"error"in n){Z(n.error,!0);return}try{Ee(n,s)}catch(o){Z(o instanceof Error?o.message:String(o),!0)}}},a.postMessage(e)}function B(e,s){const t=me();k=void 0,K.disabled=!0,F.disabled=!0,M.disabled=!0,Z("Building comparison from "+s+"…"),A("comparison-warnings").replaceChildren(),e().then(a=>{if(t!==v)return;k={job:a,name:s};const n="parts"in a?a.parts.map(r=>r.settings):[a.settings],o=n[0].layers??W.layers;K.value=String(o),A("layers-value").textContent=n.every(r=>(r.layers??W.layers)===o)?String(o):"Per part",K.disabled=!1,de(a,s,t)}).catch(a=>{t===v&&Z(String(a),!0)})}function Ge(e){return e.flatMap(s=>{const{size:[t,a,n],pivot:o}=s.meshes[0],r=new oe(new y(-t/2,-o[2],-a/2),new y(t/2,n-o[2],a/2));return s.mounts.map(({position:[i,g,l],scale:C=1,matrix:c})=>{const d=c?new ne().fromArray(c):new ne().makeScale(C,C,C).setPosition(i,l,-g);return r.clone().applyMatrix4(d)})})}function Ye(e,s){const t=e.map(i=>i.getSize(new y)),a=t.reduce((i,g,l)=>g.x*g.z>t[i].x*t[i].z?l:i,0),n=e[a].getCenter(new y),o=t[a],r=Math.max(s.x,s.y,s.z)*.12;return e.map((i,g)=>{if(g===a)return new y;const l=i.getCenter(new y).sub(n),C=l.y>o.y*.18;l.y=0;const c=Math.hypot(l.x/o.x,l.z/o.z);return c>.16?l.normalize().multiplyScalar(r):l.set(0,0,0),(C||c<=.16)&&(l.y=r),l})}function Ee(e,s){Ie??=Ke();const t=Ge(e.parts),a=t.reduce((r,i)=>r.union(i),new oe),n=a.getSize(new y);U=n.length()*.53,a.getCenter(_),Ce=Ye(t,n),M.disabled=t.length<2,M.disabled&&(M.value=M.defaultValue),A("comparison-warnings").replaceChildren(...e.warnings.map(r=>{const i=document.createElement("li");return i.textContent=r,i})),Re(e),F.disabled=!1;const o=e.parts.length>1?" "+e.parts.length+" atlases reconstructed separately.":"";Z(s+" · Comparison ready."+o+" Camera settings are shared.")}function pe(){const e=L?.nodes.filter(n=>n.atlasId)??[],s=document.createElement("optgroup");s.label="Built-in atlases",s.append(...Ae.map((n,o)=>new Option(n,"sample:"+o)));const t=document.createElement("optgroup");t.label=L?.name??"Project",t.append(...e.map(n=>new Option(n.name,n.id))),e.length>1&&t.append(new Option("Project · full (assembled)","project:assembly"));const a=e.length?[t,s]:[s];w.replaceChildren(...a)}function Ue(e){const s=new ae,t=new Map(e.map(n=>{const o=new ae;return o.position.set(...n.position),o.rotation.set(...n.rotation.map(P.degToRad)),o.scale.set(...n.scale),o.visible=n.visible,[n.id,o]}));for(const n of e)((n.parentId?t.get(n.parentId):void 0)??s).add(t.get(n.id));s.updateMatrixWorld(!0);const a=new Set;return s.traverseVisible(n=>a.add(n)),e.flatMap(n=>{const o=t.get(n.id);return n.atlasId&&a.has(o)?[{node:n,matrix:o.matrixWorld.toArray()}]:[]})}async function ie(e){const s=O+"/atlas/"+encodeURIComponent(e.id),t=await fetch(s);if(!t.ok)throw new Error("Could not load the project atlas.");return{file:await t.blob(),layout:e.layout}}async function ke(){async function e(i){const g=await fetch(i);if(!g.ok)throw new Error("Could not load the hull material passes.");return g}const[s,t,a,n,o,r]=await Promise.all([e(S.source).then(i=>i.blob()),e(S.clay).then(i=>i.blob()),e(S.depth).then(i=>i.blob()),e(S.baseColor).then(i=>i.blob()),e(S.normal).then(i=>i.blob()),e(S.calibration).then(i=>i.json())]);return{file:s,layout:ee,settings:{...W,size:r.size},maps:{clay:t,depth:a,baseColor:n,normal:o,calibration:r}}}function j(){if(w.value.startsWith("sample:")){const t=Number(w.value.slice(7)),a=Ae[t];if(!a)return;if(a===ce){B(ke,a);return}B(async()=>{async function n(r){const i=await fetch(r);if(!i.ok)throw new Error("Could not load the built-in atlas.");return{file:await i.blob(),layout:ee}}if(t===0)return{parts:await Promise.all(q.map(async({name:i,url:g,size:l,mounts:C})=>({...await n(g),name:i,mounts:C,settings:{...W,size:l,height:l?.[2]}})))};const o=q[t-1].url;return{...await n(o),settings:W}},a);return}if(w.value==="project:assembly"&&L&&O){const t=L;B(async()=>{const a=Ue(t.nodes);if(!a.length)throw new Error("No visible atlas parts in the project.");const n=new Map;return{parts:await Promise.all(a.map(async({node:r,matrix:i})=>{const g=t.atlases.find(l=>l.id===r.atlasId);if(!g)throw new Error("Missing atlas for "+r.name);return n.has(g.id)||n.set(g.id,ie(g)),{...await n.get(g.id),name:r.name,mounts:[{name:r.name,position:[0,0,0],matrix:i}],settings:r.settings}}))}},t.name+" · full (assembled)");return}const e=L?.nodes.find(t=>t.id===w.value),s=L?.atlases.find(t=>t.id===e?.atlasId);!O||!e||!s||B(async()=>({...await ie(s),settings:e.settings}),e.name)}Q.addEventListener("change",()=>{const e=Q.files?.[0];e&&(w.selectedIndex=-1,B(async()=>({file:e,layout:ee,settings:W}),e.name))});w.addEventListener("change",()=>{Q.value="",j()});K.addEventListener("input",()=>{if(!k)return;const{job:e,name:s}=k,t=K.valueAsNumber,a=me();A("layers-value").textContent=String(t),Z("Rebuilding "+s+" at "+t+" layers…");const n="parts"in e?{parts:e.parts.map(o=>({...o,settings:{...o.settings,layers:t}}))}:{...e,settings:{...e.settings,layers:t}};ge=window.setTimeout(()=>de(n,s,a),85)});F.addEventListener("input",()=>{A("spacing-value").textContent=F.valueAsNumber.toFixed(2)+"×",J.find(e=>e.isStack)?.draw()});for(const e of[X,V,z,M])e.addEventListener("input",R);Y.addEventListener("click",()=>{Y.setAttribute("aria-pressed",String(Y.getAttribute("aria-pressed")!=="true")),R()});A("reset").addEventListener("click",()=>{for(const e of[X,V,z])e.value=e.defaultValue;R()});const ue=new ResizeObserver(R);pe();const H=le.get("sample");H!==null&&[...w.options].some(e=>e.value==="sample:"+H)&&(w.value="sample:"+H,j());if(O){const e=A("back");e.href="./project.html?session="+E+"&playground=1",e.textContent="Playground",fetch(O+"/state").then(async s=>{if(!s.ok)throw new Error("Could not read the project.");L=await s.json();const t=w.value;pe(),v?w.value=t:([...w.options].some(a=>a.value==="project:assembly")&&(w.value="project:assembly"),j())}).catch(()=>{v||j()})}else v||j();
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
(function(){"use strict";const At=["top","left","front","rear","right","bottom"];function Gt(n){const t=[137,80,78,71,13,10,26,10];if(n.length<33||t.some((c,l)=>n[l]!==c)||String.fromCharCode(...n.subarray(12,16))!=="IHDR")throw new Error("Expected a PNG image.");const e=new DataView(n.buffer,n.byteOffset,n.byteLength),r=e.getUint32(16),i=e.getUint32(20);if(!r||!i||r>8192||i>8192||r*i>16e6)throw new Error("PNG dimensions exceed the 8192 px or 16 MP input limit.");return{width:r,height:i}}function bt(n){const t=n.split(",").map(e=>e.trim());if(t.some(e=>!At.includes(e)))throw new Error("Use directions top, left, front, rear, right, and bottom.");if(t.length!==4&&t.length!==6||new Set(t).size!==t.length||At.slice(0,t.length).some(e=>!t.includes(e)))throw new Error("A layout needs the four required directions or all six, with no duplicates.");return t}function Kt(n,t){const{width:e,height:r}=n,i=new Uint8Array(n.data),c=e*r;for(let s=3;s<i.length;s+=4)if(i[s]<128)return{width:e,height:r,data:i};const l=new Uint8Array(c),a=new Uint32Array(c);let o=0,f=0;function A(s){if(l[s])return;l[s]=1;const h=s*4;Math.min(i[h],i[h+1],i[h+2])>=t&&(a[f++]=s)}for(let s=0;s<e;s++)A(s),A((r-1)*e+s);for(let s=1;s<r-1;s++)A(s*e),A(s*e+e-1);for(;o<f;){const s=a[o++];i[s*4+3]=0;const h=s%e;h&&A(s-1),h+1<e&&A(s+1),s>=e&&A(s-e),s+e<c&&A(s+e)}return{width:e,height:r,data:i}}function Jt(n,t){const{left:e,top:r,width:i,height:c}=t,l=new Uint8Array(i*c*4);for(let a=0;a<c;a++){const o=((r+a)*n.width+e)*4;l.set(n.data.subarray(o,o+i*4),a*i*4)}return{width:i,height:c,data:l}}function Yt(n,t){const{left:e,top:r,width:i,height:c}=t;let l=e+i,a=-1,o=r+c,f=-1;for(let A=r;A<r+c;A++)for(let s=e;s<e+i;s++)n.data[(A*n.width+s)*4+3]<128||(l=Math.min(l,s),a=Math.max(a,s),o=Math.min(o,A),f=Math.max(f,A));return a<0?null:{left:l,top:o,width:a-l+1,height:f-o+1}}function Pt(n){const t=[];let e=-1;for(let r=0;r<=n.length;r++)n[r]?e<0&&(e=r):e>=0&&(t.push([e,r]),e=-1);return t}function St(n,t,e){const r=new Uint8Array(n.width);for(let i=t;i<e;i++)for(let c=0;c<n.width;c++)n.data[(i*n.width+c)*4+3]>=128&&(r[c]=1);return Pt(r)}function on(n,t){bt(t.join(","));let e=St(n,0,n.height).map(([r,i])=>({left:r,top:0,width:i-r,height:n.height}));if(e.length!==t.length){const r=new Uint8Array(n.height);for(let i=0;i<n.height;i++)for(let c=0;c<n.width;c++)if(n.data[(i*n.width+c)*4+3]>=128){r[i]=1;break}e=Pt(r).flatMap(([i,c])=>St(n,i,c).map(([l,a])=>({left:l,top:i,width:a-l,height:c-i})))}if(e.length!==t.length)throw new Error(`Expected ${t.length} separated views, found ${e.length}. Use clear gutters or individual PNGs.`);return e.map(r=>Yt(n,r))}function sn(n,t,e=238){const r=Kt(n,e);return Object.fromEntries(on(r,t).map((i,c)=>{const l=Jt(r,i),a=l.width+2,o=l.height+2,f=new Uint8Array(a*o*4);for(let A=0;A<l.height;A++)f.set(l.data.subarray(A*l.width*4,(A+1)*l.width*4),((A+1)*a+1)*4);return[t[c],{width:a,height:o,data:f}]}))}function Nt(n,t=238){bt(Object.keys(n).join(","));const e=Object.entries(n);return Object.fromEntries(e.map(([r,i])=>{const c=Kt(i,t),l=Yt(c,{left:0,top:0,width:c.width,height:c.height});if(!l)throw new Error(`The ${r} view has an empty silhouette.`);return[r,Jt(c,l)]}))}function an(n){const{top:t,left:e,front:r,rear:i}=n,c=e.width/e.height*t.width/t.height,l=r.width/r.height,a=[];return Math.abs(c/l-1)>.2&&a.push("Top, left, and front proportions differ by more than 20%. Check alignment."),Math.abs(i.width/i.height/l-1)>.2&&a.push("Front and rear proportions differ by more than 20%."),{views:Object.entries(n).map(([f,A])=>({direction:f,width:A.width,height:A.height})),warnings:a}}var Ut={exports:{}},Tt;function cn(){return Tt||(Tt=1,(function(n){(function(){function t(a,o){var f=a.x-o.x,A=a.y-o.y;return f*f+A*A}function e(a,o,f){var A=o.x,s=o.y,h=f.x-A,C=f.y-s;if(h!==0||C!==0){var u=((a.x-A)*h+(a.y-s)*C)/(h*h+C*C);u>1?(A=f.x,s=f.y):u>0&&(A+=h*u,s+=C*u)}return h=a.x-A,C=a.y-s,h*h+C*C}function r(a,o){for(var f=a[0],A=[f],s,h=1,C=a.length;h<C;h++)s=a[h],t(s,f)>o&&(A.push(s),f=s);return f!==s&&A.push(s),A}function i(a,o,f,A,s){for(var h=A,C,u=o+1;u<f;u++){var p=e(a[u],a[o],a[f]);p>h&&(C=u,h=p)}h>A&&(C-o>1&&i(a,o,C,A,s),s.push(a[C]),f-C>1&&i(a,C,f,A,s))}function c(a,o){var f=a.length-1,A=[a[0]];return i(a,0,f,o,A),A.push(a[f]),A}function l(a,o,f){if(a.length<=2)return a;var A=o!==void 0?o*o:1;return a=f?a:r(a,A),a=c(a,A),a}n.exports=l,n.exports.default=l})()})(Ut)),Ut.exports}cn();function An(n){const{width:t,height:e}=n,r=n.data.slice(),i=new Int32Array(t*e);let c=0,l=0;for(let o=0;o<i.length;o++)r[o*4+3]>=128&&(i[l++]=o);function a(o,f){r[f*4+3]>=128||(r.set(r.subarray(o*4,o*4+3),f*4),r[f*4+3]=255,i[l++]=f)}for(;c<l;){const o=i[c++],f=o%t;f&&a(o,o-1),f+1<t&&a(o,o+1),o>=t&&a(o,o-t),o+t<i.length&&a(o,o+t)}return{width:t,height:e,data:r}}const zt={top:[2,!0],bottom:[2,!1],left:[0,!1],right:[0,!0],front:[1,!0],rear:[1,!1]},fn=[0,1,2];function hn(n,t){const e=n[t],r=n[t+1],i=n[t+2];return n[t+3]<128?0:e>145&&e-i>70&&r-i>20&&e-r>22?1:r>95&&i>105&&Math.min(r,i)-e>46&&i-r>-20?2:0}function ln(n){const t={},e={},r=new Map,i=new Map;for(const[c,l]of Object.entries(n)){let a=function(g,B){!s[B]||h[B]>=0||(h[B]=h[g]+1,u.set(u.subarray(g*4,g*4+3),B*4),C[w++]=B)};const{width:o,height:f,data:A}=l,s=new Uint8Array(o*f),h=new Int32Array(s.length).fill(-1),C=new Int32Array(s.length),u=new Uint8Array(A),p=[0,0,0];for(let g=0;g<s.length;g++){const B=s[g]=hn(A,g*4);B&&p[B]++}const d=s.slice();for(let g=0;g<d.length;g++){const B=d[g];if(!B)continue;const m=g%o,Q=Math.floor(g/o);for(let M=-3;M<=3;M++)for(let U=-3;U<=3;U++){if(U*U+M*M>9||m+U<0||m+U>=o||Q+M<0||Q+M>=f)continue;const I=g+M*o+U,x=I*4;if(s[I]||A[x+3]<128)continue;const E=A[x],b=A[x+1],v=A[x+2];(B===1?E-v>12&&b-v>5&&E>=b-8:Math.min(b,v)-E>12)&&(s[I]=B)}}let w=0;for(let g=0;g<s.length;g++)s[g]||A[g*4+3]<128||(h[g]=0,C[w++]=g);for(let g=0;g<w;g++){const B=C[g],m=B%o;m>0&&a(B,B-1),m+1<o&&a(B,B+1),B>=o&&a(B,B-o),B+o<s.length&&a(B,B+o)}for(const g of[1,2]){const B=p[g]/(o*f)*(c==="front"?1.35:1);B<=(i.get(g)??0)||(i.set(g,B),r.set(g,c))}e[c]=s,t[c]={width:o,height:f,data:u}}return{clean:t,masks:e,owner:r}}function wn(n,t,e){const r={};for(const a of e){const[o,f]=zt[a],A=fn.filter(p=>p!==o),s=t[A[0]],h=t[A[1]],C=new Int16Array(s*h).fill(-1),u=[0,0,0];for(let p=0;p<h;p++)for(let d=0;d<s;d++){u[A[0]]=d,u[A[1]]=p;for(let w=0;w<t[o];w++)if(u[o]=f?t[o]-1-w:w,!!n[(u[2]*t[1]+u[1])*t[0]+u[0]]){C[p*s+d]=u[o]+Number(f);break}}r[a]={axis:o,axes:A,width:s,height:h,values:C}}function i(a,o){return[Math.max(0,Math.min(a.width-1,Math.floor(o[a.axes[0]]))),Math.max(0,Math.min(a.height-1,Math.floor(o[a.axes[1]])))]}function c(a,o){const f=r[a];if(!f)return-1;const[A,s]=i(f,o);return f.values[s*f.width+A]}function l(a,o,f=1.5){const A=c(a,o);return A>=0&&Math.abs(A-o[zt[a][0]])<=f}return{visible:l,firstHit:c}}function gn(n,t,e,r,i,c){const{width:l,height:a,data:o}=n,f=new Uint8Array(t.length),A=new Uint8Array(t.length),s=new Uint8Array(o.length),h=[],C=[],u=[],p=[];for(let w=0;w<t.length;w++){if(t[w]!==1||A[w])continue;const g=[w],B=new Map;let m=l,Q=0,M=a,U=0;A[w]=1;for(const x of g){const E=x%l,b=Math.floor(x/l);m=Math.min(m,E),Q=Math.max(Q,E),M=Math.min(M,b),U=Math.max(U,b);const v=B.get(b)??[E,E];B.set(b,[Math.min(v[0],E),Math.max(v[1],E)]);for(const F of[E>0?x-1:-1,E+1<l?x+1:-1,x-l,x+l])t[F]!==1||A[F]||(A[F]=1,g.push(F))}if(g.length<5||Q-m>l/4||U-M>a/4)continue;const I=new Map;for(const[x,[E,b]]of B){let v=-1;for(let F=E;F<=b;F++){const H=[(F+.5)/l*e[0],0,(1-(x+.5)/a)*e[2]];v=Math.max(v,c("front",H))}v>=0&&I.set(x,v)}if(!(I.size<2)){for(const x of g)I.has(Math.floor(x/l))&&(f[x]=1,s.set(o.subarray(x*4,x*4+4),x*4));for(const[x,E]of I){const[b,v]=B.get(x),F=b/l,H=(v+1)/l,G=x/a,D=(x+1)/a,L=(F-.5)*r[0],Y=(H-.5)*r[0],P=(1-G)*r[2]-i[2],S=(1-D)*r[2]-i[2],T=(.5-(E+.65)/e[1])*r[1],R=h.length/3;h.push(L,P,T,Y,P,T,Y,S,T,L,S,T),C.push(0,0,-1,0,0,-1,0,0,-1,0,0,-1),u.push(R,R+1,R+2,R,R+2,R+3),p.push(F,G,H,G,H,D,F,D)}}}return{mesh:u.length?{target:"mesh",size:r,pivot:i,texture:{width:l,height:a,data:s},positions:Float32Array.from(h),normals:Float32Array.from(C),indices:Uint32Array.from(u),uvs:Float32Array.from(p)}:void 0,marked:f}}const Ot=Int8Array.from(atob("/////////////////////wAIA/////////////////8AAQn/////////////////AQgDCQgB/////////////wECCv////////////////8ACAMBAgr/////////////CQIKAAIJ/////////////wIIAwIKCAoJCP////////8DCwL/////////////////AAsCCAsA/////////////wEJAAIDC/////////////8BCwIBCQsJCAv/////////AwoBCwoD/////////////wAKAQAICggLCv////////8DCQADCwkLCgn/////////CQgKCggL/////////////wQHCP////////////////8EAwAHAwT/////////////AAEJCAQH/////////////wQBCQQHAQcDAf////////8BAgoIBAf/////////////AwQHAwAEAQIK/////////wkCCgkAAggEB/////////8CCgkCCQcCBwMHCQT/////CAQHAwsC/////////////wsEBwsCBAIABP////////8JAAEIBAcCAwv/////////BAcLCQQLCQsCCQIB/////wMKAQMLCgcIBP////////8BCwoBBAsBAAQHCwT/////BAcICQALCQsKCwAD/////wQHCwQLCQkLCv////////8JBQT/////////////////CQUEAAgD/////////////wAFBAEFAP////////////8IBQQIAwUDAQX/////////AQIKCQUE/////////////wMACAECCgQJBf////////8FAgoFBAIEAAL/////////AgoFAwIFAwUEAwQI/////wkFBAIDC/////////////8ACwIACAsECQX/////////AAUEAAEFAgML/////////wIBBQIFCAIICwQIBf////8KAwsKAQMJBQT/////////BAkFAAgBCAoBCAsK/////wUEAAUACwULCgsAA/////8FBAgFCAoKCAv/////////CQcIBQcJ/////////////wkDAAkFAwUHA/////////8ABwgAAQcBBQf/////////AQUDAwUH/////////////wkHCAkFBwoBAv////////8KAQIJBQAFAwAFBwP/////CAACCAIFCAUHCgUC/////wIKBQIFAwMFB/////////8HCQUHCAkDCwL/////////CQUHCQcCCQIAAgcL/////wIDCwABCAEHCAEFB/////8LAgELAQcHAQX/////////CQUICAUHCgEDCgML/////wUHAAUACQcLAAEACgsKAP8LCgALAAMKBQAIAAcFBwD/CwoFBwsF/////////////woGBf////////////////8ACAMFCgb/////////////CQABBQoG/////////////wEIAwEJCAUKBv////////8BBgUCBgH/////////////AQYFAQIGAwAI/////////wkGBQkABgACBv////////8FCQgFCAIFAgYDAgj/////AgMLCgYF/////////////wsACAsCAAoGBf////////8AAQkCAwsFCgb/////////BQoGAQkCCQsCCQgL/////wYDCwYFAwUBA/////////8ACAsACwUABQEFCwb/////AwsGAAMGAAYFAAUJ/////wYFCQYJCwsJCP////////8FCgYEBwj/////////////BAMABAcDBgUK/////////wEJAAUKBggEB/////////8KBgUBCQcBBwMHCQT/////BgECBgUBBAcI/////////wECBQUCBgMABAMEB/////8IBAcJAAUABgUAAgb/////BwMJBwkEAwIJBQkGAgYJ/wMLAgcIBAoGBf////////8FCgYEBwIEAgACBwv/////AAEJBAcIAgMLBQoG/////wkCAQkLAgkECwcLBAUKBv8IBAcDCwUDBQEFCwb/////BQELBQsGAQALBwsEAAQL/wAFCQAGBQADBgsGAwgEB/8GBQkGCQsEBwkHCwn/////CgQJBgQK/////////////wQKBgQJCgAIA/////////8KAAEKBgAGBAD/////////CAMBCAEGCAYEBgEK/////wEECQECBAIGBP////////8DAAgBAgkCBAkCBgT/////AAIEBAIG/////////////wgDAggCBAQCBv////////8KBAkKBgQLAgP/////////AAgCAggLBAkKBAoG/////wMLAgABBgAGBAYBCv////8GBAEGAQoECAECAQsICwH/CQYECQMGCQEDCwYD/////wgLAQgBAAsGAQkBBAYEAf8DCwYDBgAABgT/////////BgQICwYI/////////////wcKBgcICggJCv////////8ABwMACgcACQoGBwr/////CgYHAQoHAQcIAQgA/////woGBwoHAQEHA/////////8BAgYBBggBCAkIBgf/////AgYJAgkBBgcJAAkDBwMJ/wcIAAcABgYAAv////////8HAwIGBwL/////////////AgMLCgYICggJCAYH/////wIABwIHCwAJBwYHCgkKB/8BCAABBwgBCgcGBwoCAwv/CwIBCwEHCgYBBgcB/////wgJBggGBwkBBgsGAwEDBv8ACQELBgf/////////////BwgABwAGAwsACwYA/////wcLBv////////////////8HBgv/////////////////AwAICwcG/////////////wABCQsHBv////////////8IAQkIAwELBwb/////////CgECBgsH/////////////wECCgMACAYLB/////////8CCQACCgkGCwf/////////BgsHAgoDCggDCgkI/////wcCAwYCB/////////////8HAAgHBgAGAgD/////////AgcGAgMHAAEJ/////////wEGAgEIBgEJCAgHBv////8KBwYKAQcBAwf/////////CgcGAQcKAQgHAQAI/////wADBwAHCgAKCQYKB/////8HBgoHCggICgn/////////BggECwgG/////////////wMGCwMABgAEBv////////8IBgsIBAYJAAH/////////CQQGCQYDCQMBCwMG/////wYIBAYLCAIKAf////////8BAgoDAAsABgsABAb/////BAsIBAYLAAIJAgoJ/////woJAwoDAgkEAwsDBgQGA/8IAgMIBAIEBgL/////////AAQCBAYC/////////////wEJAAIDBAIEBgQDCP////8BCQQBBAICBAb/////////CAEDCAYBCAQGBgoB/////woBAAoABgYABP////////8EBgMEAwgGCgMAAwkKCQP/CgkEBgoE/////////////wQJBQcGC/////////////8ACAMECQULBwb/////////BQABBQQABwYL/////////wsHBggDBAMFBAMBBf////8JBQQKAQIHBgv/////////BgsHAQIKAAgDBAkF/////wcGCwUECgQCCgQAAv////8DBAgDBQQDAgUKBQILBwb/BwIDBwYCBQQJ/////////wkFBAAIBgAGAgYIB/////8DBgIDBwYBBQAFBAD/////BgIIBggHAgEIBAgFAQUI/wkFBAoBBgEHBgEDB/////8BBgoBBwYBAAcIBwAJBQT/BAAKBAoFAAMKBgoHAwcK/wcGCgcKCAUECgQICv////8GCQUGCwkLCAn/////////AwYLAAYDAAUGAAkF/////wALCAAFCwABBQUGC/////8GCwMGAwUFAwH/////////AQIKCQULCQsICwUG/////wALAwAGCwAJBgUGCQECCv8LCAULBQYIAAUKBQIAAgX/BgsDBgMFAgoDCgUD/////wUICQUCCAUGAgMIAv////8JBQYJBgAABgL/////////AQUIAQgABQYIAwgCBgII/wEFBgIBBv////////////8BAwYBBgoDCAYFBgkICQb/CgEACgAGCQUABQYA/////wADCAUGCv////////////8KBQb/////////////////CwUKBwUL/////////////wsFCgsHBQgDAP////////8FCwcFCgsBCQD/////////CgcFCgsHCQgBCAMB/////wsBAgsHAQcFAf////////8ACAMBAgcBBwUHAgv/////CQcFCQIHCQACAgsH/////wcFAgcCCwUJAgMCCAkIAv8CBQoCAwUDBwX/////////CAIACAUCCAcFCgIF/////wkAAQUKAwUDBwMKAv////8JCAIJAgEIBwIKAgUHBQL/AQMFAwcF/////////////wAIBwAHAQEHBf////////8JAAMJAwUFAwf/////////CQgHBQkH/////////////wUIBAUKCAoLCP////////8FAAQFCwAFCgsLAwD/////AAEJCAQKCAoLCgQF/////woLBAoEBQsDBAkEAQMBBP8CBQECCAUCCwgEBQj/////AAQLAAsDBAULAgsBBQEL/wACBQAFCQILBQQFCAsIBf8JBAUCCwP/////////////AgUKAwUCAwQFAwgE/////wUKAgUCBAQCAP////////8DCgIDBQoDCAUEBQgAAQn/BQoCBQIEAQkCCQQC/////wgEBQgFAwMFAf////////8ABAUBAAX/////////////CAQFCAUDCQAFAAMF/////wkEBf////////////////8ECwcECQsJCgv/////////AAgDBAkHCQsHCQoL/////wEKCwELBAEEAAcEC/////8DAQQDBAgBCgQHBAsKCwT/BAsHCQsECQILCQEC/////wkHBAkLBwkBCwILAQAIA/8LBwQLBAICBAD/////////CwcECwQCCAMEAwIE/////wIJCgIHCQIDBwcECf////8JCgcJBwQKAgcIBwACAAf/AwcKAwoCBwQKAQoABAAK/wEKAggHBP////////////8ECQEEAQcHAQP/////////BAkBBAEHAAgBCAcB/////wQAAwcEA/////////////8ECAf/////////////////CQoICgsI/////////////wMACQMJCwsJCv////////8AAQoACggICgv/////////AwEKCwMK/////////////wECCwELCQkLCP////////8DAAkDCQsBAgkCCwn/////AAILCAAL/////////////wMCC/////////////////8CAwgCCAoKCAn/////////CQoCAAkC/////////////wIDCAIICgABCAEKCP////8BCgL/////////////////AQMICQEI/////////////wAJAf////////////////8AAwj//////////////////////////////////////w=="),n=>n.charCodeAt(0)),jt=[[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,1],[1,0,1],[1,1,1],[0,1,1]],un=[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]];function dn(n,t,e){const r=Math.min(e[2]*(t[2]-2)*.042,Math.max(e[0],e[1])*1.65),i=[1,t[0],t[0]*t[1]];let c=Float32Array.from(n),l=new Float32Array(c.length);for(let a=0;a<t.length;a++){const o=Math.max(.6,Math.min(5,r/e[a])),f=Math.ceil(o*2.5),A=Array.from({length:f+1},(p,d)=>Math.exp(-d*d/(2*o*o))),s=A[0]+2*A.slice(1).reduce((p,d)=>p+d,0),h=i[a],C=t[a],u=h*C;for(let p=0;p<c.length;p+=u)for(let d=0;d<h;d++)for(let w=0;w<C;w++){const g=p+d+w*h;let B=A[0]*c[g];for(let m=1;m<=f;m++)w>=m&&(B+=A[m]*c[g-m*h]),w+m<C&&(B+=A[m]*c[g+m*h]);l[g]=B/s}[c,l]=[l,c]}return c}function Ft(n,t,e,r,i){const c=t+2,l=e+2,a=r+2,o=c*l,f=o*a,A=new Uint8Array(f);for(let B=0;B<r;B++)for(let m=0;m<e;m++){const Q=(B*e+m)*t;A.set(n.subarray(Q,Q+t),(B+1)*o+(m+1)*c+1)}const s=i?dn(A,[c,l,a],[i[0]/t,i[1]/e,i[2]/r]):new Float32Array(f);for(let B=0;B<a;B++)for(let m=0;m<l;m++)for(let Q=0;Q<c;Q++){const M=B*o+m*c+Q,U=(Q>0?A[M-1]:0)+(Q+1<c?A[M+1]:0)+(m>0?A[M-c]:0)+(m+1<l?A[M+c]:0)+(B>0?A[M-o]:0)+(B+1<a?A[M+o]:0),I=A[M]*.64+U*.06;s[M]=i?s[M]*.92+I*.08:I}const h=[0,1,c+1,c,o,o+1,o+c+1,o+c],C=new Int32Array(f*3).fill(-1),u=[],p=[],d=[];function w(B,m){return(s[B-m]??0)-(s[B+m]??0)}function g(B,m,Q,M,U){const[I,x]=un[U],E=jt[I],b=jt[x],v=M+h[I],F=M+h[x],H=E[0]!==b[0]?0:E[1]!==b[1]?1:2,G=Math.min(v,F)*3+H;if(C[G]>=0)return C[G];const D=u.length/3,L=(.5-s[v])/(s[F]-s[v]);return u.push(B-.5+E[0]+(b[0]-E[0])*L,m-.5+E[1]+(b[1]-E[1])*L,Q-.5+E[2]+(b[2]-E[2])*L),p.push(...[1,c,o].map(Y=>w(v,Y)*(1-L)+w(F,Y)*L)),C[G]=D,D}for(let B=0;B<a-1;B++)for(let m=0;m<l-1;m++)for(let Q=0;Q<c-1;Q++){const M=B*o+m*c+Q;let U=0;for(let I=0;I<8;I++)s[M+h[I]]<.5&&(U|=1<<I);if(!(U===0||U===255))for(let I=U*16;Ot[I]>=0;I++)d.push(g(Q,m,B,M,Ot[I]))}return{positions:u,gradients:p,indices:d}}function Cn(n,t,e,r){const i=[t,e,r],c=[1,t,t*e],l=[],a=[],o=[],f=[[0,0],[1,0],[1,1],[0,1]];for(let A=0;A<r;A++)for(let s=0;s<e;s++)for(let h=0;h<t;h++){const C=(A*e+s)*t+h;if(!n[C])continue;const u=[h,s,A];for(let p=0;p<3;p++){const d=(p+1)%3,w=(p+2)%3;for(const g of[-1,1]){const B=u[p]+g;if(B>=0&&B<i[p]&&n[C+g*c[p]])continue;const m=[0,0,0];m[p]=g;const Q=l.length/3;for(const[E,b]of f){const v=[...u];v[p]+=+(g>0),v[d]+=E,v[w]+=b,l.push(...v),a.push(...m)}const M=Q,U=Q+1,I=Q+2,x=Q+3;g>0?o.push(M,U,I,M,I,x):o.push(M,I,U,M,x,I)}}}return{positions:l,gradients:a,indices:o}}const wt=(n,t,e)=>Math.min(e,Math.max(t,n));function mt(n,t,e,r){switch(n){case"top":return[t,e];case"bottom":return[t,1-e];case"left":return[1-e,1-r];case"right":return[e,1-r];case"front":return[t,1-r];case"rear":return[1-t,1-r]}}function Qt(n,t,e){return(wt(Math.floor(e*n.height),0,n.height-1)*n.width+wt(Math.floor(t*n.width),0,n.width-1))*4}function Rt(n,t,e){if(n.width===t&&n.height===e)return n;const r=new Uint8Array(t*e*4);for(let i=0;i<e;i++)for(let c=0;c<t;c++){const l=Qt(n,(c+.5)/t,(i+.5)/e),a=(i*t+c)*4;for(let o=0;o<4;o++)r[a+o]=n.data[l+o]}return{width:t,height:e,data:r}}function Mt(n,t,e,r){const i=[Math.max(0,r),Math.max(0,-t),Math.max(0,e),Math.max(0,-e),Math.max(0,t),Math.max(0,-r)];return n.right||(i[1]=Math.abs(t)),n.bottom||(i[0]=Math.abs(r)),[...At].filter(c=>n[c]).sort((c,l)=>i[At.indexOf(l)]-i[At.indexOf(c)])}function Bn(n,t){const e=n.top,r=n.front,i=n.left,c=t.layers??48,l=t.resolution??96,a=t.height??1;if(!Number.isInteger(c)||c<8||c>128)throw new Error("Layers must be an integer from 8 to 128.");if(!Number.isInteger(l)||l<16||l>192)throw new Error("Resolution must be an integer from 16 to 192.");if(!Number.isFinite(a)||a<=0)throw new Error("Height must be positive.");if(t.pivot&&t.pivot!=="center"&&t.pivot!=="ground")throw new Error("Pivot must be ground or center.");const o=i.width/i.height*a,[f,A,s]=t.size??[(r.width/r.height*a+o*e.width/e.height)/2,o,a];if(![f,A,s].every(d=>Number.isFinite(d)&&d>0))throw new Error("Part dimensions must be positive.");const h=Math.max(2,Math.round(f/Math.max(f,A)*l)),C=Math.max(2,Math.round(A/Math.max(f,A)*l)),u=[f,A,s],p=[0,0,t.pivot==="center"?s/2:0];return{width:h,depth:C,layers:c,size:u,pivot:p}}function Vt(n,t,e){const{width:r,depth:i,layers:c,size:l,pivot:a}=Bn(n,t);if(r*i*c>3e6)throw new Error("The grid is too large. Reduce layers or XY resolution.");const o={};for(const u of At){const p=n[u];if(!p)continue;const d=u!=="top"&&u!=="bottom";o[u]=Rt(p,u==="left"||u==="right"?i:r,d?c:i)}const f=Object.entries(o),A=(u,p,d,w,g)=>p.data[Qt(p,...mt(u,d,w,g))+3]>=128,s=new Uint8Array(r*i*c);let h=0;const C=t.profile==="round"||t.profile==="round-base";for(let u=0;u<c;u++)for(let p=0;p<i;p++)for(let d=0;d<r;d++){const w=(d+.5)/r,g=(p+.5)/i,B=(u+.5)/c;(n.right?f.every(([Q,M])=>A(Q,M,w,g,B)):A("top",o.top,w,g,B)&&A("left",o.left,w,g,B)&&(A("front",o.front,w,g,B)||A("rear",o.rear,w,g,B)))&&(s[(u*i+p)*r+d]=1,h++)}if(C){const u=r*i;for(let p=0;p<c;p++){if(t.profile==="round-base"&&(p+.5)/c<.03)continue;let d=r,w=-1,g=i,B=-1;const m=p*u;for(let Q=0;Q<i;Q++)for(let M=0;M<r;M++)s[m+Q*r+M]&&(d=Math.min(d,M),w=Math.max(w,M),g=Math.min(g,Q),B=Math.max(B,Q));if(!(w<d))for(let Q=g;Q<=B;Q++)for(let M=d;M<=w;M++){if(((2*M-d-w)/(w-d+1))**2+((2*Q-g-B)/(B-g+1))**2<=1)continue;const U=m+Q*r+M;h-=s[U],s[U]=0}}}if(!h){if(e)return e;throw new Error("The aligned views have no common volume.")}return{width:r,depth:i,layers:c,size:l,pivot:a,volume:s,aligned:o}}function pn(n,t={},e=!1){const r=new Map,i=new Map(r);let c=0,l=0;for(const[o,f]of[[n,r],[t,i]])for(const A of At){const s=o[A];if(!s)continue;const h=Math.min(1,512/Math.max(s.width,s.height)),C=Rt(s,Math.max(1,Math.round(s.width*h)),Math.max(1,Math.round(s.height*h)));f.set(A,{image:e?An(C):C,left:c+1}),c+=C.width+2,l=Math.max(l,C.height+2)}const a=new Uint8Array(c*l*4).fill(255);for(const{image:o,left:f}of[...r.values(),...i.values()])for(let A=-1;A<=o.height;A++)for(let s=-1;s<=o.width;s++){const h=(wt(A,0,o.height-1)*o.width+wt(s,0,o.width-1))*4,C=((A+1)*c+f+s)*4;for(let u=0;u<3;u++)a[C+u]=o.data[h+3]>=128?o.data[h+u]:137}return{tiles:r,accents:i,texture:{width:c,height:l,data:a}}}function Xt(n,t,e="rgb"){const{width:r,depth:i,layers:c,size:l,pivot:a,volume:o}=n,f=Ft(o,r,i,c,e==="depth"?l:void 0);if(!f.indices.length&&e==="depth")return Xt(n,t,"id");const A=new Int16Array(r*i).fill(-1),s=new Int16Array(r*i).fill(c),h=r*i;for(let E=0;E<c;E++)for(let b=0;b<h;b++)o[E*h+b]&&(A[b]=E,s[b]=Math.min(s[b],E));function C(E,b,v,F){const H=wt(Math.floor(b*r),0,r-1),G=wt(Math.floor(v*i),0,i-1),D=E[G*r+H];if(Math.abs(D+.5-F*c)>2)return!1;let L=0;for(const[Y,P]of[[2,0],[-2,0],[0,2],[0,-2]]){const S=H+Y,T=G+P;if(!(S<0||S>=r||T<0||T>=i)){if(Math.abs(E[T*r+S]-D)>(t.bottom?2:1))return!1;L++}}return L>=(t.bottom?2:3)}const u=e==="rgb"?void 0:ln(t),p={};for(const E of u?.owner.values()??[])p[E]=t[E];const d=u?wn(o,[r,i,c],At):void 0,w=u?.owner.get(1)==="front"&&d&&t.front&&u.masks.front?gn(t.front,u.masks.front,[r,i,c],l,a,d.firstHit):void 0,{texture:g,tiles:B,accents:m}=pn(u?.clean??t,p),Q=[],M=[],U=[],I=[],x=new Map;for(let E=0;E<f.indices.length;E+=3){const b=f.indices.slice(E,E+3),v=[0,1,2].map(O=>b.reduce((z,V)=>z+f.gradients[V*3+O],0)),F=[0,1,2].map(O=>b.reduce((z,V)=>z+f.positions[V*3+O],0)),H=[F[0]/(3*r),F[1]/(3*i),F[2]/(3*c)];let G=Mt(t,v[0],v[1],v[2]);const D=v[2]<0&&t.bottom?"bottom":"top",L=v[2]<0?s:A,Y=e==="depth"&&d&&Math.abs(v[2])*c/l[2]>1.55*Math.max(Math.abs(v[0])*r/l[0],Math.abs(v[1])*i/l[1])&&d.visible(D,F.map(O=>O/3),3);if(!Y&&!C(L,H[0],H[1],H[2])){const O=v[0],z=v[1];G=Math.hypot(O,z)>.1?Mt(t,O,z,0):Mt(t,H[0]-.5,H[1]-.5,0),G=[...G.filter(V=>V!=="top"&&V!=="bottom"),D]}const P=O=>{const z=t[O];return z.data[Qt(z,...mt(O,...H))+3]>=128};let S=Y&&P(D)?D:G.find(P)??G[0],T=!1;if(u&&d){const O=F.map(y=>y/3),z=e==="depth"?3:1.5,V=Mt(t,v[0],v[1],v[2]),W=[Math.max(0,v[2]),Math.max(0,-v[0]),Math.max(0,v[1]),Math.max(0,-v[1]),Math.max(0,v[0]),Math.max(0,-v[2])],ht=Math.max(...W);for(const y of V){if(!p[y]||W[At.indexOf(y)]<=ht*.45||!d.visible(y,O,z))continue;const k=p[y],K=Qt(k,...mt(y,...H))/4,j=u.masks[y][K];if(!(u.owner.get(j)!==y||y==="front"&&w?.marked[K])){S=y,T=!0;break}}}const{image:R,left:it}=(T?m:B).get(S);for(const O of b){const z=O*12+At.indexOf(S)+(T?6:0);let V=x.get(z);if(V===void 0){V=Q.length/3,x.set(z,V);const W=O*3,ht=f.positions[W]/r,y=f.positions[W+1]/i,k=f.positions[W+2]/c;Q.push((ht-.5)*l[0],k*l[2]-a[2],(.5-y)*l[1]);const K=f.gradients[W]*r/l[0],j=f.gradients[W+1]*i/l[1],J=f.gradients[W+2]*c/l[2],q=Math.hypot(K,j,J)||1;M.push(K/q,J/q,-j/q);const[$,_]=mt(S,ht,y,k);I.push((it+.5+wt($,0,1)*(R.width-1))/g.width,(1.5+wt(_,0,1)*(R.height-1))/g.height)}U.push(V)}}return{target:"mesh",size:l,pivot:a,texture:g,positions:Float32Array.from(Q),normals:Float32Array.from(M),indices:Uint32Array.from(U),uvs:Float32Array.from(I),...w?.mesh&&{frontAccents:w.mesh}}}function mn(n,t){const{width:e,depth:r,layers:i,size:c,pivot:l,volume:a}=n,o=Math.min(i,Math.max(1,Math.floor(4096/e))),f=e*o,A=r*Math.ceil(i/o),s=new Uint8Array(f*A*4),h=(d,w,g)=>+(d>=0&&d<e&&w>=0&&w<r&&g>=0&&g<i&&a[(g*r+w)*e+d]>0),C=new Int16Array(e*r).fill(-1);for(let d=0;d<i;d++)for(let w=0;w<C.length;w++)a[d*C.length+w]&&(C[w]=d);const u=Array.from({length:27},(d,w)=>Mt(t,w%3-1,Math.floor(w/3)%3-1,Math.floor(w/9)-1)),p=(d,w,g)=>d<0||d>=e||w<0||w>=r||Math.abs(C[w*e+d]-g)<=1;for(let d=0;d<i;d++)for(let w=0;w<r;w++)for(let g=0;g<e;g++){if(!h(g,w,d))continue;const B=h(g-1,w,d)-h(g+1,w,d),m=h(g,w-1,d)-h(g,w+1,d),Q=h(g,w,d-1)-h(g,w,d+1),M=B+1+(m+1)*3+(Q+1)*9,U=((Math.floor(d/o)*r+w)*f+d%o*e+g)*4,I=C[w*e+g],x=d===I&&p(g-2,w,d)&&p(g+2,w,d)&&p(g,w-2,d)&&p(g,w+2,d),E=u[M],b=x||Q<0&&t.bottom?E:u[M-Q*9];let v=0,F=0,H=0,G=0;for(const D of b){if(!x&&D==="top")continue;const L=t[D],Y=Qt(L,...mt(D,(g+.5)/e,(w+.5)/r,(d+.5)/i));if(L.data[Y+3]<128)continue;const P=L.data[Y],S=L.data[Y+1],T=L.data[Y+2];if(v&&Math.max(Math.abs(P-F/v),Math.abs(S-H/v),Math.abs(T-G/v))>66)continue;const R=D==="front"||D==="rear"?.1+Math.abs(m):D==="left"||D==="right"?.1+Math.abs(B):.1+Math.abs(Q);F+=P*R,H+=S*R,G+=T*R,v+=R}v&&(s[U]=Math.round(F/v),s[U+1]=Math.round(H/v),s[U+2]=Math.round(G/v),s[U+3]=255)}return{target:"stack",size:c,pivot:l,width:e,depth:r,layers:i,columns:o,spacing:c[2]/i,texture:{width:f,height:A,data:s}}}function Qn(n,t){return["rgb","id","depth"].map(e=>Xt(t,n,e))}function qt(n,t){const{size:e,pivot:r,width:i,depth:c,layers:l}=n,a=new Float32Array(t.positions.length),o=new Float32Array(a.length);for(let f=0;f<a.length;f+=3){a[f]=(t.positions[f]/i-.5)*e[0],a[f+1]=t.positions[f+2]/l*e[2]-r[2],a[f+2]=(.5-t.positions[f+1]/c)*e[1];const A=t.gradients[f]*i/e[0],s=t.gradients[f+2]*l/e[2],h=-t.gradients[f+1]*c/e[1],C=Math.hypot(A,s,h)||1;o.set([A/C,s/C,h/C],f)}return{target:"mesh",size:e,pivot:r,positions:a,normals:o,indices:Uint32Array.from(t.indices),uvs:new Float32Array(a.length/3*2),texture:{width:1,height:1,data:Uint8Array.of(255,255,255,255)}}}function Mn(n,t={}){const e=Nt(n,t.threshold),r=Vt(e,t),i=Vt(e,{...t,size:r.size,resolution:Math.max(16,Math.min(48,Math.floor((t.resolution??96)/2))),layers:Math.max(8,Math.min(32,Math.floor(r.layers/2)))},r),{volume:c,width:l,depth:a,layers:o}=i,f=qt(i,Cn(c,l,a,o)),A=qt(i,Ft(c,l,a,o)),s=h=>[h.width,h.depth,h.layers];return{voxel:f,marching:A,meshes:Qn(e,r),stack:mn(r,r.aligned),coarseGrid:s(i),fullGrid:s(r)}}var ot=Uint8Array,Bt=Uint16Array,vn=Int32Array,_t=new ot([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]),$t=new ot([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]),yn=new ot([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Wt=function(n,t){for(var e=new Bt(31),r=0;r<31;++r)e[r]=t+=1<<n[r-1];for(var i=new vn(e[30]),r=1;r<30;++r)for(var c=e[r];c<e[r+1];++c)i[c]=c-e[r]<<5|r;return{b:e,r:i}},Zt=Wt(_t,2),tn=Zt.b,xn=Zt.r;tn[28]=258,xn[258]=28;for(var En=Wt($t,0),In=En.b,kt=new Bt(32768),N=0;N<32768;++N){var gt=(N&43690)>>1|(N&21845)<<1;gt=(gt&52428)>>2|(gt&13107)<<2,gt=(gt&61680)>>4|(gt&3855)<<4,kt[N]=((gt&65280)>>8|(gt&255)<<8)>>1}for(var vt=(function(n,t,e){for(var r=n.length,i=0,c=new Bt(t);i<r;++i)n[i]&&++c[n[i]-1];var l=new Bt(t);for(i=1;i<t;++i)l[i]=l[i-1]+c[i-1]<<1;var a;if(e){a=new Bt(1<<t);var o=15-t;for(i=0;i<r;++i)if(n[i])for(var f=i<<4|n[i],A=t-n[i],s=l[n[i]-1]++<<A,h=s|(1<<A)-1;s<=h;++s)a[kt[s]>>o]=f}else for(a=new Bt(r),i=0;i<r;++i)n[i]&&(a[i]=kt[l[n[i]-1]++]>>15-n[i]);return a}),yt=new ot(288),N=0;N<144;++N)yt[N]=8;for(var N=144;N<256;++N)yt[N]=9;for(var N=256;N<280;++N)yt[N]=7;for(var N=280;N<288;++N)yt[N]=8;for(var nn=new ot(32),N=0;N<32;++N)nn[N]=5;var bn=vt(yt,9,1),Un=vt(nn,5,1),Dt=function(n){for(var t=n[0],e=1;e<n.length;++e)n[e]>t&&(t=n[e]);return t},st=function(n,t,e){var r=t/8|0;return(n[r]|n[r+1]<<8)>>(t&7)&e},Lt=function(n,t){var e=t/8|0;return(n[e]|n[e+1]<<8|n[e+2]<<16)>>(t&7)},Fn=function(n){return(n+7)/8|0},kn=function(n,t,e){return(e==null||e>n.length)&&(e=n.length),new ot(n.subarray(t,e))},Dn=["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"],at=function(n,t,e){var r=new Error(t||Dn[n]);if(r.code=n,Error.captureStackTrace&&Error.captureStackTrace(r,at),!e)throw r;return r},Ln=function(n,t,e,r){var i=n.length,c=r?r.length:0;if(!i||t.f&&!t.l)return e||new ot(0);var l=!e,a=l||t.i!=2,o=t.i;l&&(e=new ot(i*3));var f=function(K){var j=e.length;if(K>j){var J=new ot(Math.max(j*2,K));J.set(e),e=J}},A=t.f||0,s=t.p||0,h=t.b||0,C=t.l,u=t.d,p=t.m,d=t.n,w=i*8;do{if(!C){A=st(n,s,1);var g=st(n,s+1,3);if(s+=3,g)if(g==1)C=bn,u=Un,p=9,d=5;else if(g==2){var M=st(n,s,31)+257,U=st(n,s+10,15)+4,I=M+st(n,s+5,31)+1;s+=14;for(var x=new ot(I),E=new ot(19),b=0;b<U;++b)E[yn[b]]=st(n,s+b*3,7);s+=U*3;for(var v=Dt(E),F=(1<<v)-1,H=vt(E,v,1),b=0;b<I;){var G=H[st(n,s,F)];s+=G&15;var B=G>>4;if(B<16)x[b++]=B;else{var D=0,L=0;for(B==16?(L=3+st(n,s,3),s+=2,D=x[b-1]):B==17?(L=3+st(n,s,7),s+=3):B==18&&(L=11+st(n,s,127),s+=7);L--;)x[b++]=D}}var Y=x.subarray(0,M),P=x.subarray(M);p=Dt(Y),d=Dt(P),C=vt(Y,p,1),u=vt(P,d,1)}else at(1);else{var B=Fn(s)+4,m=n[B-4]|n[B-3]<<8,Q=B+m;if(Q>i){o&&at(0);break}a&&f(h+m),e.set(n.subarray(B,Q),h),t.b=h+=m,t.p=s=Q*8,t.f=A;continue}if(s>w){o&&at(0);break}}a&&f(h+131072);for(var S=(1<<p)-1,T=(1<<d)-1,R=s;;R=s){var D=C[Lt(n,s)&S],it=D>>4;if(s+=D&15,s>w){o&&at(0);break}if(D||at(2),it<256)e[h++]=it;else if(it==256){R=s,C=null;break}else{var O=it-254;if(it>264){var b=it-257,z=_t[b];O=st(n,s,(1<<z)-1)+tn[b],s+=z}var V=u[Lt(n,s)&T],W=V>>4;V||at(3),s+=V&15;var P=In[W];if(W>3){var z=$t[W];P+=Lt(n,s)&(1<<z)-1,s+=z}if(s>w){o&&at(0);break}a&&f(h+131072);var ht=h+O;if(h<P){var y=c-P,k=Math.min(P,ht);for(y+h<0&&at(3);h<k;++h)e[h]=r[y+h]}for(;h<ht;++h)e[h]=e[h-P]}}t.l=C,t.p=R,t.b=h,t.f=A,C&&(A=1,t.m=p,t.d=u,t.n=d)}while(!A);return h!=e.length&&l?kn(e,0,h):e.subarray(0,h)},Hn=new ot(0),Gn=function(n,t){return((n[0]&15)!=8||n[0]>>4>7||(n[0]<<8|n[1])%31)&&at(6,"invalid zlib data"),(n[1]>>5&1)==+!t&&at(6,"invalid zlib data: "+(n[1]&32?"need":"unexpected")+" dictionary"),(n[1]>>3&4)+2};function Kn(n,t){return Ln(n.subarray(Gn(n,t&&t.dictionary),-4),{i:2},t&&t.out,t&&t.dictionary)}var Jn=typeof TextDecoder<"u"&&new TextDecoder,Yn=0;try{Jn.decode(Hn,{stream:!0}),Yn=1}catch{}new TextEncoder,Uint32Array.from({length:256},(n,t)=>{let e=t;for(let r=0;r<8;r++)e=e>>>1^(e&1?3988292384:0);return e});function Pn(n){return`function update({ dt, keys, fields, state, rotation }) {
|
|
2
|
-
const tracks = ${JSON.stringify(n)};
|
|
3
|
-
const held = (...codes) => codes.some(code => keys.includes(code));
|
|
4
|
-
const throttle = Number(held('KeyW', 'ArrowUp')) - Number(held('KeyS', 'ArrowDown'));
|
|
5
|
-
const direction = Number(held('KeyA', 'ArrowLeft')) - Number(held('KeyD', 'ArrowRight'));
|
|
6
|
-
const target = throttle * (throttle < 0 ? fields.reverseSpeed : fields.forwardSpeed);
|
|
7
|
-
const oldSpeed = state.speed ?? 0;
|
|
8
|
-
const speed = oldSpeed + (target - oldSpeed) * (1 - Math.exp(-fields.response * dt));
|
|
9
|
-
const distance = (oldSpeed + speed) * .5 * dt;
|
|
10
|
-
const turn = direction * fields.turnRate * dt;
|
|
11
|
-
const radians = Math.PI / 180;
|
|
12
|
-
const previous = state.yaw ?? 0;
|
|
13
|
-
const heading = (rotation[1] + previous + turn * .5) * radians;
|
|
14
|
-
const yaw = (previous + turn) % 360;
|
|
15
|
-
const x = (state.x ?? 0) - Math.sin(heading) * distance;
|
|
16
|
-
const z = (state.z ?? 0) - Math.cos(heading) * distance;
|
|
17
|
-
const travel = tracks.map((track, i) => (state.travel?.[i] ?? 0) + distance + turn * radians * track[1]);
|
|
18
|
-
return { translation: [x, 0, z], rotation: [0, yaw, 0],
|
|
19
|
-
childTrackTravel: Object.fromEntries(tracks.map((track, i) => [track[0], travel[i]])),
|
|
20
|
-
state: { speed, yaw, x, z, travel } };
|
|
21
|
-
}`}Pn([]);const Sn=(n,t,e="number")=>({type:e,minimum:n,maximum:t}),Ct=(...n)=>({...Sn(...n),type:"array"});Ct(-1e4,1e4),Ct(-360,360),Ct(.01,100),Ct(-100,100),Ct(-720,720),Ct(-100,100),Ct(-360,360);function Nn(n){const{width:t,height:e}=Gt(n);if(n[24]!==16||n[25]!==0||n[26]||n[27]||n[28])throw new Error("Depth maps must be non-interlaced 16-bit grayscale PNGs.");const r=new DataView(n.buffer,n.byteOffset,n.byteLength),i=[];let c=0;for(let u=8;u+12<=n.length;){const p=r.getUint32(u),d=r.getUint32(u+4),w=u+12+p;if(w>n.length)throw new Error("Truncated depth PNG.");if(d===1229209940&&(i.push(n.subarray(u+8,u+8+p)),c+=p),d===1229278788)break;u=w}if(!c)throw new Error("Depth PNG is missing image data.");const l=new Uint8Array(c);let a=0;for(const u of i)l.set(u,a),a+=u.length;const o=t*2,f=(o+1)*e,A=Kn(l,{out:new Uint8Array(f+1)});if(A.length!==f)throw new Error("Invalid depth PNG scanline length.");const s=new Uint16Array(t*e);let h=new Uint8Array(o),C=new Uint8Array(o);for(let u=0;u<e;u++){const p=u*(o+1),d=A[p];if(d>4)throw new Error("Invalid depth PNG filter.");for(let w=0;w<o;w++){const g=w>=2?h[w-2]:0,B=C[w],m=w>=2?C[w-2]:0;let Q=0;switch(d){case 1:Q=g;break;case 2:Q=B;break;case 3:Q=g+B>>1;break;case 4:{const M=g+B-m,U=Math.abs(M-g),I=Math.abs(M-B),x=Math.abs(M-m);Q=U<=I&&U<=x?g:I<=x?B:m;break}}h[w]=A[p+1+w]+Q}for(let w=0;w<t;w++)s[u*t+w]=h[w*2]*256+h[w*2+1];[h,C]=[C,h]}return{width:t,height:e,data:s}}function en(n,t,e){return t+(e-t)*(65535-n)/65534}function rn(n,t,e){const[r,i,c,l]=t.rect,a=new Float32Array(n.positions.length),o=n.positions,f=(C,u)=>o[C]*u[0]+o[C+1]*u[1]+o[C+2]*u[2],A=t.origin.reduce((C,u,p)=>C+u*t.forward[p],0);for(let C=0;C<o.length;C+=3)a[C]=t.anchor[0]-r+f(C,t.right)*e,a[C+1]=t.anchor[1]-i-f(C,t.up)*e,a[C+2]=f(C,t.forward)-A;const s=new Float32Array(c*l).fill(1/0),h=n.indices;for(let C=0;C<h.length;C+=3){const u=h[C]*3,p=h[C+1]*3,d=h[C+2]*3,w=a[u],g=a[u+1],B=a[p],m=a[p+1],Q=a[d],M=a[d+1],U=(B-w)*(M-g)-(m-g)*(Q-w);if(Math.abs(U)<1e-8)continue;const I=Math.max(0,Math.ceil(Math.min(w,B,Q)-.5)),x=Math.min(c-1,Math.floor(Math.max(w,B,Q)-.5)),E=Math.max(0,Math.ceil(Math.min(g,m,M)-.5)),b=Math.min(l-1,Math.floor(Math.max(g,m,M)-.5));for(let v=E;v<=b;v++)for(let F=I;F<=x;F++){const H=F+.5,G=v+.5,D=((B-H)*(M-G)-(m-G)*(Q-H))/U,L=((Q-H)*(g-G)-(M-G)*(w-H))/U,Y=1-D-L;if(Math.min(D,L,Y)<-1e-6)continue;const P=D*a[u+2]+L*a[p+2]+Y*a[d+2],S=v*c+F;P>=t.near&&P<=t.far&&P<s[S]&&(s[S]=P)}}return s}function Tn(n,t,e,r){let i=0,c=0,l=0,a=0;const o=Object.entries(r.views).map(([f,A])=>{const s=rn(n,A,r.pixelsPerUnit),h=rn(t,A,r.pixelsPerUnit),[C,u,p,d]=A.rect;let w=0,g=0,B=0,m=0;for(let Q=0;Q<d;Q++)for(let M=0;M<p;M++){const U=e.data[(Q+u)*e.width+M+C];if(!U)continue;w++;const I=Q*p+M;if(!Number.isFinite(s[I])||!Number.isFinite(h[I]))continue;const x=en(U,A.near,A.far);B+=Math.abs(s[I]-x),m+=Math.abs(h[I]-x),g++}return l+=B,a+=m,i+=w,c+=g,{view:f,sharedPixels:g,referencePixels:w,baselineMae:g?B/g:null,carvedMae:g?m/g:null}});return{referencePixels:i,sharedPixels:c,byView:o,baselineMae:c?l/c:null,carvedMae:c?a/c:null}}const zn=["top","left","front","rear"],ut=(n,t,e,r)=>n*r[0]+t*r[1]+e*r[2],Ht=n=>Math.max(0,Math.min(255,Math.round(127.5*(1+n))));function On({calibration:n,depth:t,clay:e,baseColor:r,normal:i},c={}){const{size:l,pixelsPerUnit:a,views:o}=n,[f,A]=n.dimensions;if(![t,e,r,i].every(y=>y.width===f&&y.height===A)||!l.every(y=>Number.isFinite(y)&&y>0)||!Number.isFinite(a)||a<=0)throw new Error("Material passes must match the calibrated atlas dimensions.");const[s,h,C]=l,u=c.resolution??144,p=c.layers??80;if(!Number.isInteger(u)||u<16||u>192||!Number.isInteger(p)||p<8||p>128)throw new Error("Invalid resolution or layer count for registered depth.");const d=Math.max(2,Math.round(s/Math.max(s,h)*u)),w=Math.max(2,Math.round(h/Math.max(s,h)*u));if(d*w*p>3e6)throw new Error("The calibrated grid is too large. Reduce layers or resolution.");const g=Math.max(s/d,h/w,C/p)*.75+1/a,B=[0,0,c.pivot==="center"?C/2:0],m=zn.map(y=>o[y]),Q=m.map(y=>ut(...y.origin,y.forward)),M=m.length,U=[...m,o.left],I=f+o.left.rect[2]+1,x=new Uint8Array(I*A*4),E=new Uint8Array(x.length);for(let y=0;y<x.length;y+=4)x.set([146,149,154,255],y);function b(y,k,K,j){const J=y.anchor[0]+ut(k,K,j,y.right)*a,q=y.anchor[1]-ut(k,K,j,y.up)*a,[$,_,X,nt]=y.rect;return J<$||J>=$+X||q<_||q>=_+nt?-1:Math.floor(q)*f+Math.floor(J)}function v(y,k){return en(t.data[k],y.near,y.far)}function F(y,k){const[K,j,J,q]=y.rect;for(let $=j;$<j+q;$++)for(let _=K;_<K+J;_++){const X=($*f+_)*4;if(r.data[X+3]<128)continue;const nt=($*I+(k?f+_-K:_))*4;if(x.set(r.data.subarray(X,X+4),nt),i.data[X+3]<128)continue;const lt=i.data[X]/127.5-1,Z=i.data[X+1]/127.5-1,et=i.data[X+2]/127.5-1,tt=y.right.map((ct,dt)=>lt*ct+Z*y.up[dt]-et*y.forward[dt]),rt=Math.hypot(...tt)||1;E.set([Ht(tt[0]*(k?-1:1)/rt),Ht(tt[1]/rt),Ht(tt[2]/rt),255],nt)}}for(const y of m)F(y,!1);F(o.left,!0);const H=new Uint8Array(d*w*p),G=new Uint8Array(H.length);for(let y=0;y<p;y++)for(let k=0;k<w;k++)for(let K=0;K<d;K++){const j=((K+.5)/d-.5)*s,J=(y+.5)/p*C,q=(.5-(k+.5)/w)*h;let $=!0,_=!0;for(const[X,nt]of m.entries()){const lt=b(nt,j,J,q);if(lt<0||e.data[lt*4+3]<128){$=!1;break}const Z=ut(j,J,q,nt.forward)-Q[X];(!t.data[lt]||Z+g<v(nt,lt))&&(_=!1)}if($){const X=(y*w+k)*d+K;G[X]=1,_&&(H[X]=1)}}function D(y){const k=Ft(y,d,w,p);if(!k.indices.length)throw new Error("The calibrated views have no common surface.");const K=new Float32Array(k.positions.length),j=new Float32Array(k.positions.length);for(let J=0;J<K.length;J+=3){K.set([(k.positions[J]/d-.5)*s,k.positions[J+2]/p*C,(.5-k.positions[J+1]/w)*h],J);const q=k.gradients[J]*d/s,$=k.gradients[J+2]*p/C,_=-k.gradients[J+1]*w/h,X=Math.hypot(q,$,_)||1;j.set([q/X,$/X,_/X],J)}return{positions:K,normals:j,indices:k.indices}}const L=D(G),Y=D(H),P=Tn(L,Y,t,n),{positions:S,normals:T}=Y,R=new Map,it=[],O=[],z=[],V=[];for(let y=0;y<Y.indices.length;y+=3){const k=Y.indices.slice(y,y+3),K=(Z,et)=>(Z[k[0]*3+et]+Z[k[1]*3+et]+Z[k[2]*3+et])/3,j=K(S,0),J=K(S,1),q=K(S,2),$=K(T,0),_=K(T,1),X=K(T,2);let nt=-1,lt=0;for(const[Z,et]of U.entries()){const tt=Z===M?-1:1,rt=-ut($*tt,_,X,et.forward);if(rt<=.04)continue;const ct=b(et,j*tt,J,q);if(ct<0||!t.data[ct])continue;const dt=v(et,ct),Et=ut(j*tt,J,q,et.forward)-Q[tt===-1?1:Z],ft=Math.abs(Et-dt)/g;if(ft>3.5)continue;const pt=rt/(1+ft*ft);pt>lt&&(nt=Z,lt=pt)}for(const Z of k){const et=Z*(U.length+1)+nt+1;let tt=R.get(et);if(tt===void 0){tt=it.length/3,R.set(et,tt);const rt=Z*3,ct=S[rt],dt=S[rt+1],Et=S[rt+2];it.push(ct,dt-B[2],Et),O.push(T[rt],T[rt+1],T[rt+2]);const ft=U[nt];if(!ft)z.push((I-.5)/I,.5/A);else{const pt=nt===M,jn=ft.anchor[0]+a*ut(pt?-ct:ct,dt,Et,ft.right),Rn=ft.anchor[1]-a*ut(pt?-ct:ct,dt,Et,ft.up);z.push((jn+(pt?f-ft.rect[0]:0))/I,Rn/A)}}V.push(tt)}}const W={target:"mesh",size:l,pivot:B,positions:Float32Array.from(it),normals:Float32Array.from(O),uvs:Float32Array.from(z),indices:Uint32Array.from(V),texture:{width:I,height:A,data:x}},ht={target:"mesh",size:l,pivot:B,positions:L.positions.map((y,k)=>k%3===1?y-B[2]:y),normals:L.normals,indices:Uint32Array.from(L.indices),uvs:new Float32Array(L.positions.length/3*2),texture:{width:1,height:1,data:Uint8Array.of(255,255,255,255)}};return{mesh:W,silhouetteMesh:ht,fit:P,normalMap:{width:I,height:A,data:E},grid:[d,w,p]}}async function It(n,t=!1){Gt(new Uint8Array(await n.slice(0,33).arrayBuffer()));const e=await createImageBitmap(n,{colorSpaceConversion:t?"none":"default"});try{const r=new OffscreenCanvas(e.width,e.height),i=r.getContext("2d",{willReadFrequently:!0});if(!i)throw new Error("Could not decode the PNG.");i.drawImage(e,0,0);const c=i.getImageData(0,0,r.width,r.height);return{width:r.width,height:r.height,data:new Uint8Array(c.data.buffer)}}finally{e.close()}}function xt(n){return[n.positions,n.normals,n.indices,n.uvs,n.texture.data].map(t=>t.buffer)}self.onmessage=async({data:n})=>{try{const t=o=>({...o,name:"",mounts:[{name:"",position:[0,0,0]}]}),e="parts"in n?n.parts:[t(n)],r=[];async function i({file:o,layout:f,settings:A,name:s,mounts:h,maps:C}){const u=sn(await It(o),bt(f),A.threshold),p=Mn(u,A),d=an(Nt(u,A.threshold));r.push(...d.warnings.map(g=>s?s+" · "+g:g));let w;if(C){const[g,B,m,Q]=await Promise.all([It(C.clay),C.depth.arrayBuffer(),It(C.baseColor),It(C.normal,!0)]);w=On({calibration:C.calibration,clay:g,depth:Nn(new Uint8Array(B)),baseColor:m,normal:Q},A)}return{...p,name:s,mounts:h,mapped:w}}const c=[];for(const o of e)c.push(await i(o));const a=c.flatMap(o=>[o.voxel,o.marching,...o.meshes]).flatMap(o=>o.frontAccents?[...xt(o),...xt(o.frontAccents)]:xt(o));for(const o of c)a.push(o.stack.texture.data.buffer),o.mapped&&a.push(...xt(o.mapped.mesh),...xt(o.mapped.silhouetteMesh),o.mapped.normalMap.data.buffer);self.postMessage({parts:c,warnings:r},a)}catch(t){self.postMessage({error:t instanceof Error?t.message:String(t)})}}})();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{G,p as H}from"./style-CWGgpweN.js";function Q(e,n){return n.flatMap((c,i)=>c.mounts.map(w=>({...w,asset:e[i]})))}function S(e){const n=new G;for(const{asset:c,name:i,position:[w,s,f],scale:m=1,mirrorX:p,mirrorY:h}of e){const u=H(c);u.name=i,u.position.set(w,f,-s),u.scale.set(p?-m:m,m,h?-m:m),n.add(u)}return n}function V(e){if(e.length===0||e.some(({asset:r})=>r.target!=="stack"))throw new Error("A stack assembly needs reconstructed stack parts.");const n=e,c=n.map(({asset:r,position:[t,y,T],scale:R=1})=>{const[U,L,v]=r.size.map(l=>l*R),M=T-r.pivot[2]*R;return{min:[t-U/2,y-L/2,M],max:[t+U/2,y+L/2,M+v]}}),i=[0,1,2].map(r=>Math.min(...c.map(({min:t})=>t[r]))),s=[0,1,2].map(r=>Math.max(...c.map(({max:t})=>t[r]))).map((r,t)=>r-i[t]),f=Math.min(192/Math.max(s[0],s[1]),Math.max(...n.map(({asset:r,scale:t=1})=>Math.max(r.width/r.size[0],r.depth/r.size[1])/t))),m=Math.max(1,Math.round(s[0]*f)),p=Math.max(1,Math.round(s[1]*f)),h=Math.min(...n.map(({asset:r,scale:t=1})=>r.spacing*t)),u=Math.max(1,Math.min(128,Math.floor(3e6/(m*p)),Math.ceil(s[2]/h))),g=[s[0]/m,s[1]/p,s[2]/u],d=Math.min(u,Math.floor(4096/m)),B=m*d,A=p*Math.ceil(u/d),C=new Uint8Array(4*B*A);for(const[r,{asset:t,mirrorX:y,mirrorY:T}]of n.entries()){const{min:R,max:U}=c[r],L=R.map((l,o)=>Math.ceil((l-i[o])/g[o]-.5)),v=U.map((l,o)=>Math.ceil((l-i[o])/g[o]-.5)),M=(l,o,k)=>Math.max(0,Math.min(k-1,Math.floor((i[o]+(l+.5)*g[o]-R[o])*k/(U[o]-R[o]))));for(let l=L[2];l<v[2];l++)for(let o=L[1];o<v[1];o++){const k=M(l,2,t.layers),X=M(o,1,t.depth),P=(Math.floor(k/t.columns)*t.depth+(T?t.depth-1-X:X))*t.texture.width,j=(Math.floor(l/d)*p+o)*B;for(let b=L[0];b<v[0];b++){const F=M(b,0,t.width),D=4*(P+k%t.columns*t.width+(y?t.width-1-F:F));if(t.texture.data[D+3]<128)continue;const q=4*(j+l%d*m+b);for(let x=0;x<4;x++)C[q+x]=t.texture.data[D+x]}}}return{target:"stack",width:m,depth:p,layers:u,columns:d,spacing:g[2],size:s,pivot:[0,0,-i[2]],texture:{width:B,height:A,data:C}}}const z={cone:new URL(""+new URL("traffic-cone-4view-DG-TkITx.png",import.meta.url).href,import.meta.url),rover:new URL(""+new URL("fillet-rover-body-4-view-Chk8Mx4R.png",import.meta.url).href,import.meta.url),inspection:new URL(""+new URL("inspection-robot-body-4-view-CLMaHFYm.png",import.meta.url).href,import.meta.url),ant:new URL(""+new URL("ant-mech-body-4view-D9xVPpbc.png",import.meta.url).href,import.meta.url),tank:new URL(""+new URL("tank-hull-4view-B4sMMkP5.png",import.meta.url).href,import.meta.url),sign:new URL(""+new URL("wet-floor-sign-4view-CWJDyeTX.png",import.meta.url).href,import.meta.url),barrier:new URL(""+new URL("plastic-barrier-4view-DQkTBW_i.png",import.meta.url).href,import.meta.url),concrete:new URL(""+new URL("concrete-barrier-4view-7PsO3Ftq.png",import.meta.url).href,import.meta.url)},K={draft:{layers:24,resolution:72},balanced:{layers:48,resolution:96},detail:{layers:90,resolution:144}},W=new URL(""+new URL("fillet-rover-wheel-4-view-B-F8flOC.png",import.meta.url).href,import.meta.url),Y=new URL(""+new URL("inspection-robot-wheel-4-view-27wRsxcs.png",import.meta.url).href,import.meta.url),I=new URL(""+new URL("ant-mech-center-leg-4view-BcphjF_G.png",import.meta.url).href,import.meta.url),_=new URL(""+new URL("ant-mech-angled-leg-4view-BO2qt1_k.png",import.meta.url).href,import.meta.url),E=new URL(""+new URL("tank-turret-4view-Cx0FuNFu.png",import.meta.url).href,import.meta.url),J=new URL(""+new URL("tank-track-4view-DAIiMTy3.png",import.meta.url).href,import.meta.url),a=(e,n,c,i)=>[e/i,n/i,c/i];function O(e,n,c,i,w,s,f,m){const p=c[2];return[{name:"Body",url:e,size:a(...c,p),mounts:[{name:"Body",position:a(0,0,w,p)}]},{name:"Wheel",url:n,size:a(...i,p),mounts:[-1,1].flatMap(h=>[s,f].map((u,g)=>({name:(h<0?"Left ":"Right ")+(g?"rear wheel":"front wheel"),position:a(h*m,u,0,p),mirrorX:h<0})))}]}const Z={rover:O(z.rover,W,[80,188,90],[20,44,44],13,48.5,-56.5,36.5),inspection:O(z.inspection,Y,[92,194,150],[30,74,74],14,45,-63,46.5),ant:[{name:"Body",url:z.ant,size:a(50,114,56,56),mounts:[{name:"Body",position:a(0,0,26,56)}]},{name:"Center leg",url:I,size:a(23,17,41,56),mounts:[-1,1].map(e=>({name:e<0?"Left center leg":"Right center leg",position:a(e*27,0,0,56),mirrorX:e<0}))},{name:"Angled leg",url:_,size:a(23,30,41,56),mounts:[-1,1].flatMap(e=>[-1,1].map(n=>({name:(e<0?"Left ":"Right ")+(n<0?"rear leg":"front leg"),position:a(e*27,n*42,0,56),mirrorX:e<0,mirrorY:n<0})))}],tank:[{name:"Hull",url:z.tank,size:a(86,166,49,49),mounts:[{name:"Hull",position:a(0,0,13,49)}]},{name:"Turret",url:E,size:a(60,120,33,49),mounts:[{name:"Turret",position:a(0,15,60,49)}]},{name:"Track",url:J,size:a(23,163,34,49),mounts:[-1,1].map(e=>({name:e<0?"Left track":"Right track",position:a(e*45,0,0,49),mirrorX:e<0}))}]};export{V as b,S as c,Q as i,Z as m,K as q,z as s};
|