dsh-3d-viewer 0.1.0 → 0.2.0

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.
Files changed (47) hide show
  1. package/README.md +180 -107
  2. package/README.zh.md +180 -107
  3. package/THIRD_PARTY_NOTICES.md +54 -52
  4. package/assets/hdri/LICENSE.md +17 -16
  5. package/dist/client.fbx.js +14 -0
  6. package/dist/client.gltf.js +14 -0
  7. package/dist/client.js +4472 -0
  8. package/dist/client.obj.js +19 -0
  9. package/dist/client.stl.js +14 -0
  10. package/dist/client.tex-exr.js +14 -0
  11. package/dist/client.tex-hdr.js +18 -0
  12. package/dist/client.tex-tga.js +14 -0
  13. package/index.js +167 -7
  14. package/package.json +72 -48
  15. package/assets/preview.png +0 -0
  16. package/build.mjs +0 -49
  17. package/client.js +0 -4462
  18. package/scripts/embed-hdri.mjs +0 -70
  19. package/src/bytes.js +0 -158
  20. package/src/client.js +0 -57
  21. package/src/formats.js +0 -100
  22. package/src/generated/hdri-data.js +0 -8
  23. package/src/loaders/gltf.js +0 -251
  24. package/src/loaders/model-loader.js +0 -232
  25. package/src/loaders/workspace.js +0 -295
  26. package/src/model.js +0 -417
  27. package/src/scene/animation.js +0 -149
  28. package/src/scene/blue-noise.js +0 -48
  29. package/src/scene/camera.js +0 -83
  30. package/src/scene/createSceneView.js +0 -375
  31. package/src/scene/environment.js +0 -187
  32. package/src/scene/ground.js +0 -286
  33. package/src/scene/lighting.js +0 -41
  34. package/src/scene/materials.js +0 -263
  35. package/src/scene/postprocessing.js +0 -155
  36. package/src/scene/render-loop.js +0 -98
  37. package/src/scene/viewer-error.js +0 -16
  38. package/src/ui/AnimationBar.js +0 -95
  39. package/src/ui/ModelViewer.js +0 -278
  40. package/src/ui/ViewerSurface.js +0 -87
  41. package/src/ui/chrome.js +0 -220
  42. package/src/ui/dictionaries.js +0 -99
  43. package/src/ui/icons.js +0 -88
  44. package/src/ui/options.js +0 -23
  45. package/src/ui/primitives.js +0 -88
  46. package/src/ui/styles.js +0 -89
  47. package/src/vendor/FBXLoaderPbr.js +0 -4772
@@ -0,0 +1,19 @@
1
+ /*! dsh-3d-viewer obj loader chunk | bundles Three.js addons (MIT). See THIRD_PARTY_NOTICES.md. */
2
+ window.__ModuleLoader__.load({
3
+ id: "dsh-3d-viewer",
4
+ chunk: "client.obj.js",
5
+ factory(require) {
6
+ var localRequire = (id) => id === 'three' ? globalThis.__DSH3DV_THREE__ : require(id);
7
+ var module = { exports: {} };
8
+ var exports = module.exports;
9
+ (function (require, module, exports) {
10
+ var P=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var re=Object.prototype.hasOwnProperty;var se=(i,e)=>{for(var t in e)P(i,t,{get:e[t],enumerable:!0})},ne=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of te(e))!re.call(i,r)&&r!==t&&P(i,r,{get:()=>e[r],enumerable:!(n=ee(e,r))||n.enumerable});return i};var ie=i=>ne(P({},"__esModule",{value:!0}),i);var Le={};se(Le,{loadObjModel:()=>Z});module.exports=ie(Le);var p=require("three"),U=class extends p.Loader{constructor(e){super(e)}load(e,t,n,r){let s=this,a=this.path===""?p.LoaderUtils.extractUrlBase(e):this.path,o=new p.FileLoader(this.manager);o.setPriority(this.priority),o.setCache(this.cache),o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,function(c){try{t(s.parse(c,a))}catch(l){r?r(l):console.error(l),s.manager.itemError(e)}},n,r)}setMaterialOptions(e){return this.materialOptions=e,this}parse(e,t){let n=e.split(`
11
+ `),r={},s=/\s+/,a={};for(let c=0;c<n.length;c++){let l=n[c];if(l=l.trim(),l.length===0||l.charAt(0)==="#")continue;let h=l.indexOf(" "),d=h>=0?l.substring(0,h):l;d=d.toLowerCase();let f=h>=0?l.substring(h+1):"";if(f=f.trim(),d==="newmtl")r={name:f},a[f]=r;else if(d==="ka"||d==="kd"||d==="ks"||d==="ke"){let m=f.split(s,3);r[d]=[parseFloat(m[0]),parseFloat(m[1]),parseFloat(m[2])]}else r[d]=f}let o=new S(this.resourcePath||t,this.materialOptions);return o.setCrossOrigin(this.crossOrigin),o.setManager(this.manager),o.priority=this.priority,o.cache=this.cache,o.setMaterials(a),o}},S=class{constructor(e="",t={}){this.baseUrl=e,this.options=t,this.materialsInfo={},this.materials={},this.materialsArray=[],this.nameLookup={},this.crossOrigin="anonymous",this.priority="auto",this.cache="default",this.side=this.options.side!==void 0?this.options.side:p.FrontSide,this.wrap=this.options.wrap!==void 0?this.options.wrap:p.RepeatWrapping}setCrossOrigin(e){return this.crossOrigin=e,this}setManager(e){this.manager=e}setMaterials(e){this.materialsInfo=this.convert(e),this.materials={},this.materialsArray=[],this.nameLookup={}}convert(e){if(!this.options)return e;let t={};for(let n in e){let r=e[n],s={};t[n]=s;for(let a in r){let o=!0,c=r[a],l=a.toLowerCase();switch(l){case"kd":case"ka":case"ks":this.options&&this.options.normalizeRGB&&(c=[c[0]/255,c[1]/255,c[2]/255]),this.options&&this.options.ignoreZeroRGBs&&c[0]===0&&c[1]===0&&c[2]===0&&(o=!1);break;default:break}o&&(s[l]=c)}}return t}preload(){for(let e in this.materialsInfo)this.create(e)}getIndex(e){return this.nameLookup[e]}getAsArray(){let e=0;for(let t in this.materialsInfo)this.materialsArray[e]=this.create(t),this.nameLookup[t]=e,e++;return this.materialsArray}create(e){return this.materials[e]===void 0&&this.createMaterial_(e),this.materials[e]}createMaterial_(e){let t=this,n=this.materialsInfo[e],r={name:e,side:this.side};function s(o,c){return typeof c!="string"||c===""?"":/^https?:\/\//i.test(c)?c:o+c}function a(o,c){if(r[o])return;let l=t.getTextureParams(c,r),h=t.loadTexture(s(t.baseUrl,l.url));h.repeat.copy(l.scale),h.offset.copy(l.offset),h.wrapS=t.wrap,h.wrapT=t.wrap,(o==="map"||o==="emissiveMap")&&(h.colorSpace=p.SRGBColorSpace),r[o]=h}for(let o in n){let c=n[o],l;if(c!=="")switch(o.toLowerCase()){case"kd":r.color=p.ColorManagement.colorSpaceToWorking(new p.Color().fromArray(c),p.SRGBColorSpace);break;case"ks":r.specular=p.ColorManagement.colorSpaceToWorking(new p.Color().fromArray(c),p.SRGBColorSpace);break;case"ke":r.emissive=p.ColorManagement.colorSpaceToWorking(new p.Color().fromArray(c),p.SRGBColorSpace);break;case"map_kd":a("map",c);break;case"map_ks":a("specularMap",c);break;case"map_ke":a("emissiveMap",c);break;case"norm":a("normalMap",c);break;case"map_bump":case"bump":a("bumpMap",c);break;case"disp":a("displacementMap",c);break;case"map_d":a("alphaMap",c),r.transparent=!0;break;case"ns":r.shininess=parseFloat(c);break;case"d":l=parseFloat(c),l<1&&(r.opacity=l,r.transparent=!0);break;case"tr":l=parseFloat(c),this.options&&this.options.invertTrProperty&&(l=1-l),l>0&&(r.opacity=1-l,r.transparent=!0);break;default:break}}return this.materials[e]=new p.MeshPhongMaterial(r),this.materials[e]}getTextureParams(e,t){let n={scale:new p.Vector2(1,1),offset:new p.Vector2(0,0)},r=e.split(/\s+/),s;return s=r.indexOf("-bm"),s>=0&&(t.bumpScale=parseFloat(r[s+1]),r.splice(s,2)),s=r.indexOf("-mm"),s>=0&&(t.displacementBias=parseFloat(r[s+1]),t.displacementScale=parseFloat(r[s+2]),r.splice(s,3)),s=r.indexOf("-s"),s>=0&&(n.scale.set(parseFloat(r[s+1]),parseFloat(r[s+2])),r.splice(s,4)),s=r.indexOf("-o"),s>=0&&(n.offset.set(parseFloat(r[s+1]),parseFloat(r[s+2])),r.splice(s,4)),n.url=r.join(" ").trim(),n}loadTexture(e,t,n,r,s){let a=this.manager!==void 0?this.manager:p.DefaultLoadingManager,o=a.getHandler(e);o===null&&(o=new p.TextureLoader(a),o.setPriority(this.priority),o.setCache(this.cache)),o.setCrossOrigin&&o.setCrossOrigin(this.crossOrigin);let c=o.load(e,n,r,s);return t!==void 0&&(c.mapping=t),c}};var u=require("three"),oe=/^[og]\s*(.+)?/,ae=/^mtllib /,le=/^usemtl /,ce=/^usemap /,T=/\s+/,z=new u.Vector3,O=new u.Vector3,H=new u.Vector3,G=new u.Vector3,L=new u.Vector3,M=new u.Color;function de(){let i={objects:[],object:{},vertices:[],normals:[],colors:[],uvs:[],materials:{},materialLibraries:[],startObject:function(e,t){if(this.object&&this.object.fromDeclaration===!1){this.object.name=e,this.object.fromDeclaration=t!==!1;return}let n=this.object&&typeof this.object.currentMaterial=="function"?this.object.currentMaterial():void 0;if(this.object&&typeof this.object._finalize=="function"&&this.object._finalize(!0),this.object={name:e||"",fromDeclaration:t!==!1,geometry:{vertices:[],normals:[],colors:[],uvs:[],hasUVIndices:!1},materials:[],smooth:!0,startMaterial:function(r,s){let a=this._finalize(!1);a&&(a.inherited||a.groupCount<=0)&&this.materials.splice(a.index,1);let o={index:this.materials.length,name:r||"",mtllib:Array.isArray(s)&&s.length>0?s[s.length-1]:"",smooth:a!==void 0?a.smooth:this.smooth,groupStart:a!==void 0?a.groupEnd:0,groupEnd:-1,groupCount:-1,inherited:!1,clone:function(c){let l={index:typeof c=="number"?c:this.index,name:this.name,mtllib:this.mtllib,smooth:this.smooth,groupStart:0,groupEnd:-1,groupCount:-1,inherited:!1};return l.clone=this.clone.bind(l),l}};return this.materials.push(o),o},currentMaterial:function(){if(this.materials.length>0)return this.materials[this.materials.length-1]},_finalize:function(r){let s=this.currentMaterial();if(s&&s.groupEnd===-1&&(s.groupEnd=this.geometry.vertices.length/3,s.groupCount=s.groupEnd-s.groupStart,s.inherited=!1),r&&this.materials.length>1)for(let a=this.materials.length-1;a>=0;a--)this.materials[a].groupCount<=0&&this.materials.splice(a,1);return r&&this.materials.length===0&&this.materials.push({name:"",smooth:this.smooth}),s}},n&&n.name&&typeof n.clone=="function"){let r=n.clone(0);r.inherited=!0,this.object.materials.push(r)}this.objects.push(this.object)},finalize:function(){this.object&&typeof this.object._finalize=="function"&&this.object._finalize(!0)},parseVertexIndex:function(e,t){let n=parseInt(e,10);return(n>=0?n-1:n+t/3)*3},parseNormalIndex:function(e,t){let n=parseInt(e,10);return(n>=0?n-1:n+t/3)*3},parseUVIndex:function(e,t){let n=parseInt(e,10);return(n>=0?n-1:n+t/2)*2},addVertex:function(e,t,n){let r=this.vertices,s=this.object.geometry.vertices;s.push(r[e+0],r[e+1],r[e+2]),s.push(r[t+0],r[t+1],r[t+2]),s.push(r[n+0],r[n+1],r[n+2])},addVertexPoint:function(e){let t=this.vertices;this.object.geometry.vertices.push(t[e+0],t[e+1],t[e+2])},addVertexLine:function(e){let t=this.vertices;this.object.geometry.vertices.push(t[e+0],t[e+1],t[e+2])},addNormal:function(e,t,n){let r=this.normals,s=this.object.geometry.normals;s.push(r[e+0],r[e+1],r[e+2]),s.push(r[t+0],r[t+1],r[t+2]),s.push(r[n+0],r[n+1],r[n+2])},addFaceNormal:function(e,t,n){let r=this.vertices,s=this.object.geometry.normals;z.fromArray(r,e),O.fromArray(r,t),H.fromArray(r,n),L.subVectors(H,O),G.subVectors(z,O),L.cross(G),L.normalize(),s.push(L.x,L.y,L.z),s.push(L.x,L.y,L.z),s.push(L.x,L.y,L.z)},addColor:function(e,t,n){let r=this.colors,s=this.object.geometry.colors;r[e]!==void 0&&s.push(r[e+0],r[e+1],r[e+2]),r[t]!==void 0&&s.push(r[t+0],r[t+1],r[t+2]),r[n]!==void 0&&s.push(r[n+0],r[n+1],r[n+2])},addUV:function(e,t,n){let r=this.uvs,s=this.object.geometry.uvs;s.push(r[e+0],r[e+1]),s.push(r[t+0],r[t+1]),s.push(r[n+0],r[n+1])},addDefaultUV:function(){let e=this.object.geometry.uvs;e.push(0,0),e.push(0,0),e.push(0,0)},addUVLine:function(e){let t=this.uvs;this.object.geometry.uvs.push(t[e+0],t[e+1])},addFace:function(e,t,n,r,s,a,o,c,l){let h=this.vertices.length,d=this.parseVertexIndex(e,h),f=this.parseVertexIndex(t,h),m=this.parseVertexIndex(n,h);if(this.addVertex(d,f,m),this.addColor(d,f,m),o!==void 0&&o!==""){let b=this.normals.length;d=this.parseNormalIndex(o,b),f=this.parseNormalIndex(c,b),m=this.parseNormalIndex(l,b),this.addNormal(d,f,m)}else this.addFaceNormal(d,f,m);if(r!==void 0&&r!==""){let b=this.uvs.length;d=this.parseUVIndex(r,b),f=this.parseUVIndex(s,b),m=this.parseUVIndex(a,b),this.addUV(d,f,m),this.object.geometry.hasUVIndices=!0}else this.addDefaultUV()},addPointGeometry:function(e){this.object.geometry.type="Points";let t=this.vertices.length;for(let n=0,r=e.length;n<r;n++){let s=this.parseVertexIndex(e[n],t);this.addVertexPoint(s),this.addColor(s)}},addLineGeometry:function(e,t){this.object.geometry.type="Line";let n=this.vertices.length,r=this.uvs.length;for(let s=0,a=e.length-1;s<a;s++)this.addVertexLine(this.parseVertexIndex(e[s],n)),this.addVertexLine(this.parseVertexIndex(e[s+1],n));for(let s=0,a=t.length-1;s<a;s++)this.addUVLine(this.parseUVIndex(t[s],r)),this.addUVLine(this.parseUVIndex(t[s+1],r))}};return i.startObject("",!1),i}var C=class extends u.Loader{constructor(e){super(e),this.materials=null}load(e,t,n,r){let s=this,a=new u.FileLoader(this.manager);a.setPriority(this.priority),a.setCache(this.cache),a.setPath(this.path),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(e,function(o){try{t(s.parse(o))}catch(c){r?r(c):console.error(c),s.manager.itemError(e)}},n,r)}setMaterials(e){return this.materials=e,this}parse(e){let t=new de;e.indexOf(`\r
12
+ `)!==-1&&(e=e.replace(/\r\n/g,`
13
+ `)),e.indexOf(`\\
14
+ `)!==-1&&(e=e.replace(/\\\n/g,""));let n=e.split(`
15
+ `),r=[];for(let o=0,c=n.length;o<c;o++){let l=n[o].trimStart();if(l.length===0)continue;let h=l.charAt(0);if(h!=="#")if(h==="v"){let d=l.split(T);switch(d[0]){case"v":t.vertices.push(parseFloat(d[1]),parseFloat(d[2]),parseFloat(d[3])),d.length>=7?(M.setRGB(parseFloat(d[4]),parseFloat(d[5]),parseFloat(d[6]),u.SRGBColorSpace),t.colors.push(M.r,M.g,M.b)):t.colors.push(void 0,void 0,void 0);break;case"vn":t.normals.push(parseFloat(d[1]),parseFloat(d[2]),parseFloat(d[3]));break;case"vt":t.uvs.push(parseFloat(d[1]),parseFloat(d[2]));break}}else if(h==="f"){let f=l.slice(1).trim().split(T),m=[];for(let g=0,x=f.length;g<x;g++){let y=f[g];if(y.length>0){let v=y.split("/");m.push(v)}}let b=m[0];for(let g=1,x=m.length-1;g<x;g++){let y=m[g],v=m[g+1];t.addFace(b[0],y[0],v[0],b[1],y[1],v[1],b[2],y[2],v[2])}}else if(h==="l"){let d=l.substring(1).trim().split(T),f=[],m=[];if(l.indexOf("/")===-1)f=d;else for(let b=0,g=d.length;b<g;b++){let x=d[b].split("/");x[0]!==""&&f.push(x[0]),x[1]!==""&&m.push(x[1])}t.addLineGeometry(f,m)}else if(h==="p"){let f=l.slice(1).trim().split(T);t.addPointGeometry(f)}else if((r=oe.exec(l))!==null){let d=(" "+r[0].slice(1).trim()).slice(1);t.startObject(d)}else if(le.test(l))t.object.startMaterial(l.substring(7).trim(),t.materialLibraries);else if(ae.test(l))t.materialLibraries.push(l.substring(7).trim());else if(ce.test(l))console.warn('THREE.OBJLoader: Rendering identifier "usemap" not supported. Textures must be defined in MTL files.');else if(h==="s"){if(r=l.split(" "),r.length>1){let f=r[1].trim().toLowerCase();t.object.smooth=f!=="0"&&f!=="off"}else t.object.smooth=!0;let d=t.object.currentMaterial();d&&(d.smooth=t.object.smooth)}else{if(l==="\0")continue;console.warn('THREE.OBJLoader: Unexpected line: "'+l+'"')}}t.finalize();let s=new u.Group;if(s.materialLibraries=[].concat(t.materialLibraries),!(t.objects.length===1&&t.objects[0].geometry.vertices.length===0)===!0)for(let o=0,c=t.objects.length;o<c;o++){let l=t.objects[o],h=l.geometry,d=l.materials,f=h.type==="Line",m=h.type==="Points",b=!1;if(h.vertices.length===0)continue;let g=new u.BufferGeometry;g.setAttribute("position",new u.Float32BufferAttribute(h.vertices,3)),h.normals.length>0&&g.setAttribute("normal",new u.Float32BufferAttribute(h.normals,3)),h.colors.length>0&&(b=!0,g.setAttribute("color",new u.Float32BufferAttribute(h.colors,3))),h.hasUVIndices===!0&&g.setAttribute("uv",new u.Float32BufferAttribute(h.uvs,2));let x=[];for(let v=0,E=d.length;v<E;v++){let F=d[v],D=F.name+"_"+F.smooth+"_"+b,w=t.materials[D];if(this.materials!==null){if(w=this.materials.create(F.name),f&&w&&!(w instanceof u.LineBasicMaterial)){let j=new u.LineBasicMaterial;u.Material.prototype.copy.call(j,w),j.color.copy(w.color),w=j}else if(m&&w&&!(w instanceof u.PointsMaterial)){let j=new u.PointsMaterial({size:10,sizeAttenuation:!1});u.Material.prototype.copy.call(j,w),j.color.copy(w.color),j.map=w.map,w=j}}w===void 0&&(f?w=new u.LineBasicMaterial:m?w=new u.PointsMaterial({size:1,sizeAttenuation:!1}):w=new u.MeshPhongMaterial,w.name=F.name,w.flatShading=!F.smooth,w.vertexColors=b,t.materials[D]=w),x.push(w)}let y;if(x.length>1){for(let v=0,E=d.length;v<E;v++){let F=d[v];g.addGroup(F.groupStart,F.groupCount,v)}f?y=new u.LineSegments(g,x):m?y=new u.Points(g,x):y=new u.Mesh(g,x)}else f?y=new u.LineSegments(g,x[0]):m?y=new u.Points(g,x[0]):y=new u.Mesh(g,x[0]);y.name=l.name,s.add(y)}else if(t.vertices.length>0){let o=new u.PointsMaterial({size:1,sizeAttenuation:!1}),c=new u.BufferGeometry;c.setAttribute("position",new u.Float32BufferAttribute(t.vertices,3)),t.colors.length>0&&t.colors[0]!==void 0&&(c.setAttribute("color",new u.Float32BufferAttribute(t.colors,3)),o.vertexColors=!0);let l=new u.Points(c,o);s.add(l)}return s}};var ue=/^(?:data:|blob:|https?:|file:|\/\/)/iu,J=/^(?:[A-Za-z]:[\\/]|\/)/u,he=new Map([["bin","application/octet-stream"],["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"],["webp","image/webp"],["gif","image/gif"],["bmp","image/bmp"],["tga","image/x-tga"],["dds","image/vnd-ms.dds"],["exr","image/x-exr"],["hdr","image/vnd.radiance"]]),$=new TextDecoder("utf-8");function q(i){if(i instanceof ArrayBuffer)return i;if(ArrayBuffer.isView(i))return i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength);if(typeof i=="string")return new TextEncoder().encode(i).buffer;throw new TypeError("The 3D preview was not given binary data")}function I(i){if(typeof i=="string")return i;if(i instanceof ArrayBuffer||ArrayBuffer.isView(i))return $.decode(i);throw new TypeError("The 3D preview was not given model data")}function V(i){let e=String(i).split(/[?#]/u,1)[0];try{return decodeURIComponent(e).replaceAll("\\","/")}catch{return e.replaceAll("\\","/")}}function N(i){return typeof i=="string"&&i!==""&&ue.test(i)===!1}function X(i){let e=V(i),t=e.slice(e.lastIndexOf(".")+1).toLowerCase();return he.get(t)??"application/octet-stream"}function k(i="Model loading was cancelled."){let e=new Error(i);return e.name="AbortError",e}function _(i){typeof console<"u"&&console.warn(i)}var A=require("three");function Y(i){let e=globalThis.__DSH3DV_REQUIRE__;return e===void 0||typeof e.async!="function"?Promise.reject(new Error("The DSH module loader is unavailable for 3D format chunks.")):e.async(i)}var fe=/^(?!data:|blob:|https?:|file:|\/\/).+$/i,pe=5e3,me="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4////fwAJ+wP9KobjigAAAABJRU5ErkJggg==",ge=new A.ImageLoader(new A.LoadingManager),B=new Map;function be(i){let e=String(i).split(/[?#]/,1)[0].toLowerCase();return e.endsWith(".tga")?"tga":e.endsWith(".exr")?"exr":e.endsWith(".hdr")?"hdr":null}function we(i){let e=`./client.tex-${i}.js`,t=B.get(e);return t===void 0&&(t=Y(e),B.set(e,t),t.catch(()=>B.delete(e))),t}async function ye(i,e){let r=(await we(i))[{tga:"decodeTga",exr:"decodeExr",hdr:"decodeHdr"}[i]];if(typeof r!="function")throw new Error(`The ${i.toUpperCase()} decoder chunk is unavailable.`);return r(q(e))}function xe(i,e){let t=e.userData?.dsh3dHdr===!0,n=i.colorSpace;i.image=e.image,i.mipmaps=e.mipmaps,i.mapping=e.mapping,i.channel=e.channel,i.format=e.format,i.internalFormat=e.internalFormat,i.type=e.type,i.colorSpace=t?e.colorSpace:n,i.flipY=e.flipY,i.unpackAlignment=e.unpackAlignment,i.minFilter=e.minFilter,i.magFilter=e.magFilter,i.generateMipmaps=e.generateMipmaps,i.anisotropy=e.anisotropy,i.userData={...e.userData},i.needsUpdate=!0,e.dispose()}async function W(i,e){let t=await i(e);if(t!==void 0&&t.ok===!0)return t;let n=String(e).replaceAll("\\","/");if(!J.test(n))return t;let r=n.slice(n.lastIndexOf("/")+1);return r===""||r===n?t:i(r)}function K(i,e,t){return new Promise((n,r)=>{if(t?.aborted===!0){r(k("Texture loading was cancelled."));return}ge.load(e,s=>{i.image=s,i.needsUpdate=!0,n()},void 0,r)})}var R=class extends A.Loader{constructor(e,t){super(e),this.readFile=t.readFile,this.signal=t.signal,this.onWarn=t.onWarn,this.pending=t.pending,this.blobUrls=t.blobUrls,this.listeners=t.listeners,this.disposed=t.isDisposed}load(e,t,n,r){let s=N(e)?V(e):null,a=s===null?null:be(s),o=a===null?new A.Texture:new A.DataTexture(new Uint8Array([255,255,255,255]),1,1,A.RGBAFormat,A.UnsignedByteType);o.name=e;let c=(async()=>{let l=null;try{if(this.signal?.aborted===!0||this.disposed?.()===!0)throw k("Texture loading was cancelled.");let h=e;if(s!==null){let d=s,f=await W(this.readFile,d);if(f===void 0||f.ok!==!0)throw new Error(f?.error?.message??`Could not read texture ${e}`);if(this.signal?.aborted===!0||this.disposed?.()===!0)throw k("Texture loading was cancelled.");if(a!==null){let m=await ye(a,f.value.data);if(this.signal?.aborted===!0||this.disposed?.()===!0)throw m.dispose(),k("Texture loading was cancelled.");xe(o,m),t?.(o);return}l=URL.createObjectURL(new Blob([f.value.data],{type:X(d)})),this.blobUrls.add(l),h=l}await K(o,h,this.signal),t?.(o)}catch(h){if(l!==null&&this.blobUrls.has(l)&&(URL.revokeObjectURL(l),this.blobUrls.delete(l)),this.signal?.aborted!==!0&&this.disposed?.()!==!0){if(this.onWarn?.(`[dsh-3d-viewer] Could not load texture "${e}": ${String(h)}`),a!==null)o.image={data:new Uint8Array([255,255,255,255]),width:1,height:1},o.needsUpdate=!0;else try{await K(o,me,this.signal)}catch{}t?.(o),r?.(h)}}finally{for(let h of this.listeners)try{h(o)}catch{}}})();return this.pending.add(c),c.then(()=>this.pending.delete(c),()=>this.pending.delete(c)),o}};function Q({readFile:i,signal:e,onWarn:t=_}){let n=new Set,r=new Set,s=new Set,a=!1,o=new A.LoadingManager,c=new R(o,{readFile:i,signal:e,onWarn:t,pending:n,blobUrls:r,listeners:s,isDisposed:()=>a});o.addHandler(fe,c);async function l(f=pe){if(n.size===0||e?.aborted===!0)return;let m,b,g=new Promise(y=>{m=setTimeout(y,f)}),x=new Promise(y=>{b=y,e?.addEventListener("abort",y,{once:!0})});try{await Promise.race([Promise.allSettled([...n]),g,x])}finally{clearTimeout(m),e?.removeEventListener("abort",b)}}function h(f){return s.add(f),()=>s.delete(f)}function d(){if(!a){a=!0;for(let f of r)A.Cache.remove(`image:${f}`),URL.revokeObjectURL(f);r.clear(),s.clear()}}return{manager:o,settle:l,onTextureLoad:h,dispose:d}}function Ae(i){let e=[];for(let t of i.matchAll(/^[^\S\r\n]*mtllib[^\S\r\n]+(.+?)[^\S\r\n]*$/gimu))e.push(t[1].trim());return e}async function ve(i,e){let t=Ae(i);if(t.length===0)return null;let n=r=>e.readWorkspaceFile(e.resourceAddress,r,{signal:e.signal});for(let r of t){if(e.signal?.aborted===!0)throw k();let s;try{s=await W(n,r)}catch(o){if(e.signal?.aborted===!0)throw k();e.onWarn(`[dsh-3d-viewer] Could not read MTL "${r}": ${String(o)}`);continue}if(s===void 0||s.ok!==!0){e.onWarn(`[dsh-3d-viewer] Could not read MTL "${r}": ${s?.error?.message??"unknown error"}`);continue}let a=null;try{let o=I(s.value.data);a=Q({readFile:h=>e.readWorkspaceFile(e.resourceAddress,h,{baseFile:s.value.absolutePath,signal:e.signal}),signal:e.signal,onWarn:e.onWarn});let l=new U(a.manager).parse(o,"");if(l.preload(),await a.settle(),e.signal?.aborted===!0)throw k();return{materials:l,assets:a}}catch(o){a?.dispose(),e.onWarn(`[dsh-3d-viewer] Could not parse MTL "${r}": ${String(o)}`)}}return null}async function Z(i,e={}){let t=I(i),n=e.onWarn??_,r=null,s=null;if(typeof e.readWorkspaceFile=="function"&&typeof e.resourceAddress=="string"){let a=await ve(t,{readWorkspaceFile:e.readWorkspaceFile,resourceAddress:e.resourceAddress,signal:e.signal,onWarn:n});r=a?.materials??null,s=a?.assets??null}try{if(e.signal?.aborted===!0)throw k();let a=new C;return r!==null&&a.setMaterials(r),{object:a.parse(t),assets:s}}catch(a){throw s?.dispose(),a}}
16
+ })(localRequire, module, module.exports);
17
+ return module.exports;
18
+ },
19
+ });
@@ -0,0 +1,14 @@
1
+ /*! dsh-3d-viewer stl loader chunk | bundles Three.js addons (MIT). See THIRD_PARTY_NOTICES.md. */
2
+ window.__ModuleLoader__.load({
3
+ id: "dsh-3d-viewer",
4
+ chunk: "client.stl.js",
5
+ factory(require) {
6
+ var localRequire = (id) => id === 'three' ? globalThis.__DSH3DV_THREE__ : require(id);
7
+ var module = { exports: {} };
8
+ var exports = module.exports;
9
+ (function (require, module, exports) {
10
+ var V=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var Y=(r,t)=>{for(var c in t)V(r,c,{get:t[c],enumerable:!0})},Z=(r,t,c,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of q(t))!W.call(r,i)&&i!==c&&V(r,i,{get:()=>t[i],enumerable:!(p=H(t,i))||p.enumerable});return r};var $=r=>Z(V({},"__esModule",{value:!0}),r);var J={};Y(J,{loadStlModel:()=>G});module.exports=$(J);var v=require("three");var s=require("three"),k=class extends s.Loader{constructor(t){super(t)}load(t,c,p,i){let F=this,n=new s.FileLoader(this.manager);n.setPriority(this.priority),n.setCache(this.cache),n.setPath(this.path),n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(t,function(d){try{c(F.parse(d))}catch(x){i?i(x):console.error(x),F.manager.itemError(t)}},p,i)}parse(t){function c(o){let e=new DataView(o),u=32/8*3+32/8*3*3+16/8,g=e.getUint32(80,!0);if(80+32/8+g*u===e.byteLength)return!0;let h=[115,111,108,105,100];for(let l=0;l<5;l++)if(p(h,e,l))return!1;return!0}function p(o,e,u){for(let g=0,b=o.length;g<b;g++)if(o[g]!==e.getUint8(u+g))return!1;return!0}function i(o){let e=new DataView(o),u=e.getUint32(80,!0),g,b,h,l=!1,U,R,C,M,E;for(let f=0;f<=70;f++)e.getUint32(f,!1)==1129270351&&e.getUint8(f+4)==82&&e.getUint8(f+5)==61&&(l=!0,U=new Float32Array(u*3*3),R=e.getUint8(f+6)/255,C=e.getUint8(f+7)/255,M=e.getUint8(f+8)/255,E=e.getUint8(f+9)/255);let A=84,a=50,y=new s.BufferGeometry,S=new Float32Array(u*3*3),B=new Float32Array(u*3*3),T=new s.Color;for(let f=0;f<u;f++){let L=A+f*a,D=e.getFloat32(L,!0),O=e.getFloat32(L+4,!0),P=e.getFloat32(L+8,!0);if(l){let m=e.getUint16(L+48,!0);(m&32768)===0?(g=(m&31)/31,b=(m>>5&31)/31,h=(m>>10&31)/31):(g=R,b=C,h=M)}for(let m=1;m<=3;m++){let z=L+m*12,w=f*3*3+(m-1)*3;S[w]=e.getFloat32(z,!0),S[w+1]=e.getFloat32(z+4,!0),S[w+2]=e.getFloat32(z+8,!0),B[w]=D,B[w+1]=O,B[w+2]=P,l&&(T.setRGB(g,b,h,s.SRGBColorSpace),U[w]=T.r,U[w+1]=T.g,U[w+2]=T.b)}}return y.setAttribute("position",new s.BufferAttribute(S,3)),y.setAttribute("normal",new s.BufferAttribute(B,3)),l&&(y.setAttribute("color",new s.BufferAttribute(U,3)),y.hasColors=!0,y.alpha=E),y}function F(o){let e=new s.BufferGeometry,u=/solid([\s\S]*?)endsolid/g,g=/facet([\s\S]*?)endfacet/g,b=/solid\s(.+)/,h=0,l=/[\s]+([+-]?(?:\d*)(?:\.\d*)?(?:[eE][+-]?\d+)?)/.source,U=new RegExp("vertex"+l+l+l,"g"),R=new RegExp("normal"+l+l+l,"g"),C=[],M=[],E=[],A=new s.Vector3,a,y=0,S=0,B=0;for(;(a=u.exec(o))!==null;){S=B;let T=a[0],f=(a=b.exec(T))!==null?a[1]:"";for(E.push(f);(a=g.exec(T))!==null;){let O=0,P=0,m=a[0];for(;(a=R.exec(m))!==null;)A.x=parseFloat(a[1]),A.y=parseFloat(a[2]),A.z=parseFloat(a[3]),P++;for(;(a=U.exec(m))!==null;)C.push(parseFloat(a[1]),parseFloat(a[2]),parseFloat(a[3])),M.push(A.x,A.y,A.z),O++,B++;P!==1&&console.error("THREE.STLLoader: Something isn't right with the normal of face number "+h),O!==3&&console.error("THREE.STLLoader: Something isn't right with the vertices of face number "+h),h++}let L=S,D=B-S;e.userData.groupNames=E,e.addGroup(L,D,y),y++}return e.setAttribute("position",new s.Float32BufferAttribute(C,3)),e.setAttribute("normal",new s.Float32BufferAttribute(M,3)),e}function n(o){return typeof o!="string"?new TextDecoder().decode(o):o}function d(o){if(typeof o=="string"){let e=new Uint8Array(o.length);for(let u=0;u<o.length;u++)e[u]=o.charCodeAt(u)&255;return e.buffer||e}else return o}let x=d(t);return c(x)?i(x):F(n(t))}};var ee=new TextDecoder("utf-8");function I(r){if(r instanceof ArrayBuffer)return r;if(ArrayBuffer.isView(r))return r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);if(typeof r=="string")return new TextEncoder().encode(r).buffer;throw new TypeError("The 3D preview was not given binary data")}function j(r="Model loading was cancelled."){let t=new Error(r);return t.name="AbortError",t}var N=require("three");function _(r){let t=new Set,c=new Set,p=new Set,i=new Set,F=new Set;r.traverse(n=>{n.geometry!==void 0&&n.geometry!==null&&t.add(n.geometry),n.isSkinnedMesh===!0&&n.skeleton!==void 0&&n.skeleton!==null&&i.add(n.skeleton);let d=n.material;if(d!=null){for(let x of Array.isArray(d)?d:[d])if(x!=null){c.add(x);for(let o of Object.values(x))if(!(o===null||typeof o!="object")){if(o.isTexture===!0)p.add(o);else if(Array.isArray(o))for(let e of o)e!==null&&typeof e=="object"&&e.isTexture===!0&&p.add(e)}}}});for(let n of p){let d=n.image?.src;typeof d=="string"&&d.startsWith("blob:")&&F.add(d),n.dispose()}if(typeof URL.revokeObjectURL=="function")for(let n of F)try{URL.revokeObjectURL(n)}catch{}for(let n of i)n.dispose();for(let n of c)n.dispose();for(let n of t)n.dispose()}function X(r){let t=new k().parse(I(r));t.getAttribute("normal")===void 0&&t.computeVertexNormals();let c=t.hasColors===!0,p=new v.MeshStandardMaterial({name:"STL",color:c?16777215:13224393,metalness:0,roughness:.8,side:v.DoubleSide,vertexColors:c}),i=new v.Mesh(t,p);return i.name="STL",i.animations=[],i}async function G(r,t={}){if(t.signal?.aborted===!0)throw j();let c=X(r);if(t.signal?.aborted===!0)throw _(c),j();return{object:c,assets:null}}
11
+ })(localRequire, module, module.exports);
12
+ return module.exports;
13
+ },
14
+ });
@@ -0,0 +1,14 @@
1
+ /*! dsh-3d-viewer tex-exr loader chunk | bundles Three.js addons (MIT). See THIRD_PARTY_NOTICES.md. */
2
+ window.__ModuleLoader__.load({
3
+ id: "dsh-3d-viewer",
4
+ chunk: "client.tex-exr.js",
5
+ factory(require) {
6
+ var localRequire = (id) => id === 'three' ? globalThis.__DSH3DV_THREE__ : require(id);
7
+ var module = { exports: {} };
8
+ var exports = module.exports;
9
+ (function (require, module, exports) {
10
+ var pt=Object.defineProperty;var mn=Object.getOwnPropertyDescriptor;var gn=Object.getOwnPropertyNames;var yn=Object.prototype.hasOwnProperty;var wn=(w,p)=>{for(var I in p)pt(w,I,{get:p[I],enumerable:!0})},xn=(w,p,I,b)=>{if(p&&typeof p=="object"||typeof p=="function")for(let T of gn(p))!yn.call(w,T)&&T!==I&&pt(w,T,{get:()=>p[T],enumerable:!(b=mn(p,T))||b.enumerable});return w};var En=w=>xn(pt({},"__esModule",{value:!0}),w);var Dn={};wn(Dn,{decodeExr:()=>Nn});module.exports=En(Dn);var re=require("three");var l=require("three");var J=Uint8Array,Oe=Uint16Array,Sn=Int32Array,Ot=new J([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]),Ht=new J([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]),Cn=new J([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Mt=function(w,p){for(var I=new Oe(31),b=0;b<31;++b)I[b]=p+=1<<w[b-1];for(var T=new Sn(I[30]),b=1;b<30;++b)for(var oe=I[b];oe<I[b+1];++oe)T[oe]=oe-I[b]<<5|b;return{b:I,r:T}},Rt=Mt(Ot,2),bt=Rt.b,In=Rt.r;bt[28]=258,In[258]=28;var zt=Mt(Ht,0),Fn=zt.b,kn=zt.r,gt=new Oe(32768);for(z=0;z<32768;++z)ve=(z&43690)>>1|(z&21845)<<1,ve=(ve&52428)>>2|(ve&13107)<<2,ve=(ve&61680)>>4|(ve&3855)<<4,gt[z]=((ve&65280)>>8|(ve&255)<<8)>>1;var ve,z,Be=(function(w,p,I){for(var b=w.length,T=0,oe=new Oe(p);T<b;++T)w[T]&&++oe[w[T]-1];var fe=new Oe(p);for(T=1;T<p;++T)fe[T]=fe[T-1]+oe[T-1]<<1;var ie;if(I){ie=new Oe(1<<p);var we=15-p;for(T=0;T<b;++T)if(w[T])for(var Ce=T<<4|w[T],ce=p-w[T],U=fe[w[T]-1]++<<ce,k=U|(1<<ce)-1;U<=k;++U)ie[gt[U]>>we]=Ce}else for(ie=new Oe(b),T=0;T<b;++T)w[T]&&(ie[T]=gt[fe[w[T]-1]++]>>15-w[T]);return ie}),ke=new J(288);for(z=0;z<144;++z)ke[z]=8;var z;for(z=144;z<256;++z)ke[z]=9;var z;for(z=256;z<280;++z)ke[z]=7;var z;for(z=280;z<288;++z)ke[z]=8;var z,Nt=new J(32);for(z=0;z<32;++z)Nt[z]=5;var z;var An=Be(ke,9,1);var dn=Be(Nt,5,1),vt=function(w){for(var p=w[0],I=1;I<w.length;++I)w[I]>p&&(p=w[I]);return p},te=function(w,p,I){var b=p/8|0;return(w[b]|w[b+1]<<8)>>(p&7)&I},mt=function(w,p){var I=p/8|0;return(w[I]|w[I+1]<<8|w[I+2]<<16)>>(p&7)},Tn=function(w){return(w+7)/8|0},Un=function(w,p,I){return(p==null||p<0)&&(p=0),(I==null||I>w.length)&&(I=w.length),new J(w.subarray(p,I))};var On=["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"],ne=function(w,p,I){var b=new Error(p||On[w]);if(b.code=w,Error.captureStackTrace&&Error.captureStackTrace(b,ne),!I)throw b;return b},Hn=function(w,p,I,b){var T=w.length,oe=b?b.length:0;if(!T||p.f&&!p.l)return I||new J(0);var fe=!I,ie=fe||p.i!=2,we=p.i;fe&&(I=new J(T*3));var Ce=function(qe){var Ke=I.length;if(qe>Ke){var be=new J(Math.max(Ke*2,qe));be.set(I),I=be}},ce=p.f||0,U=p.p||0,k=p.b||0,me=p.l,Me=p.d,Ie=p.m,Fe=p.n,Le=T*8;do{if(!me){ce=te(w,U,1);var Ze=te(w,U+1,3);if(U+=3,Ze)if(Ze==1)me=An,Me=dn,Ie=9,Fe=5;else if(Ze==2){var Ye=te(w,U,31)+257,st=te(w,U+10,15)+4,at=Ye+te(w,U+5,31)+1;U+=14;for(var xe=new J(at),ue=new J(19),P=0;P<st;++P)ue[Cn[P]]=te(w,U+P*3,7);U+=st*3;for(var Ge=vt(ue),lt=(1<<Ge)-1,V=Be(ue,Ge,1),P=0;P<at;){var Re=V[te(w,U,lt)];U+=Re&15;var Q=Re>>4;if(Q<16)xe[P++]=Q;else{var q=0,Ae=0;for(Q==16?(Ae=3+te(w,U,3),U+=2,q=xe[P-1]):Q==17?(Ae=3+te(w,U,7),U+=3):Q==18&&(Ae=11+te(w,U,127),U+=7);Ae--;)xe[P++]=q}}var Xe=xe.subarray(0,Ye),j=xe.subarray(Ye);Ie=vt(Xe),Fe=vt(j),me=Be(Xe,Ie,1),Me=Be(j,Fe,1)}else ne(1);else{var Q=Tn(U)+4,Pe=w[Q-4]|w[Q-3]<<8,_e=Q+Pe;if(_e>T){we&&ne(0);break}ie&&Ce(k+Pe),I.set(w.subarray(Q,_e),k),p.b=k+=Pe,p.p=U=_e*8,p.f=ce;continue}if(U>Le){we&&ne(0);break}}ie&&Ce(k+131072);for(var We=(1<<Ie)-1,ft=(1<<Fe)-1,K=U;;K=U){var q=me[mt(w,U)&We],se=q>>4;if(U+=q&15,U>Le){we&&ne(0);break}if(q||ne(2),se<256)I[k++]=se;else if(se==256){K=U,me=null;break}else{var ee=se-254;if(se>264){var P=se-257,he=Ot[P];ee=te(w,U,(1<<he)-1)+bt[P],U+=he}var Ee=Me[mt(w,U)&ft],de=Ee>>4;Ee||ne(3),U+=Ee&15;var j=Fn[de];if(de>3){var he=Ht[de];j+=mt(w,U)&(1<<he)-1,U+=he}if(U>Le){we&&ne(0);break}ie&&Ce(k+131072);var D=k+ee;if(k<j){var pe=oe-j,ge=Math.min(j,D);for(pe+k<0&&ne(3);k<ge;++k)I[k]=b[pe+k]}for(;k<D;++k)I[k]=I[k-j]}}p.l=me,p.p=K,p.b=k,p.f=ce,me&&(ce=1,p.m=Ie,p.d=Me,p.n=Fe)}while(!ce);return k!=I.length&&fe?Un(I,0,k):I.subarray(0,k)};var Mn=new J(0);var Rn=function(w,p){return((w[0]&15)!=8||w[0]>>4>7||(w[0]<<8|w[1])%31)&&ne(6,"invalid zlib data"),(w[1]>>5&1)==+!p&&ne(6,"invalid zlib data: "+(w[1]&32?"need":"unexpected")+" dictionary"),(w[1]>>3&4)+2};function He(w,p){return Hn(w.subarray(Rn(w,p&&p.dictionary),-4),{i:2},p&&p.out,p&&p.dictionary)}var bn=typeof TextDecoder<"u"&&new TextDecoder,zn=0;try{bn.decode(Mn,{stream:!0}),zn=1}catch{}var it=class extends l.DataTextureLoader{constructor(p){super(p),this.type=l.HalfFloatType,this.outputFormat=l.RGBAFormat,this.part=0}parse(p){let xe=Math.pow(2.7182818,2.2),ue=null,P=null;function Ge(e,t){let n=0;for(let i=0;i<65536;++i)(i==0||e[i>>3]&1<<(i&7))&&(t[n++]=i);let o=n-1;for(;n<65536;)t[n++]=0;return o}function lt(e){for(let t=0;t<16384;t++)e[t]={},e[t].len=0,e[t].lit=0,e[t].p=null}let V={l:0,c:0,lc:0};function Re(e,t,n,o,i){for(;n<e;)t=t<<8|Ft(o,i),n+=8;n-=e,V.l=t>>n&(1<<e)-1,V.c=t,V.lc=n}let q=new Array(59);function Ae(e){for(let n=0;n<=58;++n)q[n]=0;for(let n=0;n<65537;++n)q[e[n]]+=1;let t=0;for(let n=58;n>0;--n){let o=t+q[n]>>1;q[n]=t,t=o}for(let n=0;n<65537;++n){let o=e[n];o>0&&(e[n]=o|q[o]++<<6)}}function Xe(e,t,n,o,i,a){let r=t,c=0,s=0;for(;o<=i;o++){if(r.value-t.value>n)return!1;Re(6,c,s,e,r);let f=V.l;if(c=V.c,s=V.lc,a[o]=f,f==63){if(r.value-t.value>n)throw new Error("THREE.EXRLoader: Something wrong with hufUnpackEncTable");Re(8,c,s,e,r);let u=V.l+6;if(c=V.c,s=V.lc,o+u>i+1)throw new Error("THREE.EXRLoader: Something wrong with hufUnpackEncTable");for(;u--;)a[o++]=0;o--}else if(f>=59){let u=f-59+2;if(o+u>i+1)throw new Error("THREE.EXRLoader: Something wrong with hufUnpackEncTable");for(;u--;)a[o++]=0;o--}}Ae(a)}function j(e){return e&63}function We(e){return e>>6}function ft(e,t,n,o){for(;t<=n;t++){let i=We(e[t]),a=j(e[t]);if(i>>a)throw new Error("THREE.EXRLoader: Invalid table entry");if(a>14){let r=o[i>>a-14];if(r.len)throw new Error("THREE.EXRLoader: Invalid table entry");if(r.lit++,r.p){let c=r.p;r.p=new Array(r.lit);for(let s=0;s<r.lit-1;++s)r.p[s]=c[s]}else r.p=new Array(1);r.p[r.lit-1]=t}else if(a){let r=0;for(let c=1<<14-a;c>0;c--){let s=o[(i<<14-a)+r];if(s.len||s.p)throw new Error("THREE.EXRLoader: Invalid table entry");s.len=a,s.lit=t,r++}}}return!0}let K={c:0,lc:0};function se(e,t,n,o){e=e<<8|Ft(n,o),t+=8,K.c=e,K.lc=t}let ee={c:0,lc:0};function he(e,t,n,o,i,a,r,c,s){if(e==t){o<8&&(se(n,o,i,a),n=K.c,o=K.lc),o-=8;let f=n>>o;if(f=new Uint8Array([f])[0],c.value+f>s)return!1;let u=r[c.value-1];for(;f-- >0;)r[c.value++]=u}else if(c.value<s)r[c.value++]=e;else return!1;ee.c=n,ee.lc=o}function Ee(e){return e&65535}function de(e){let t=Ee(e);return t>32767?t-65536:t}let D={a:0,b:0};function pe(e,t){let n=de(e),i=de(t),a=n+(i&1)+(i>>1),r=a,c=a-i;D.a=r,D.b=c}function ge(e,t){let n=Ee(e),o=Ee(t),i=n-(o>>1)&65535,a=o+i-32768&65535;D.a=a,D.b=i}function qe(e,t,n,o,i,a,r){let c=r<16384,s=n>i?i:n,f=1,u,v;for(;f<=s;)f<<=1;for(f>>=1,u=f,f>>=1;f>=1;){v=0;let h=v+a*(i-u),g=a*f,x=a*u,m=o*f,y=o*u,F,O,A,M;for(;v<=h;v+=x){let S=v,E=v+o*(n-u);for(;S<=E;S+=y){let C=S+m,N=S+g,R=N+m;c?(pe(e[S+t],e[N+t]),F=D.a,A=D.b,pe(e[C+t],e[R+t]),O=D.a,M=D.b,pe(F,O),e[S+t]=D.a,e[C+t]=D.b,pe(A,M),e[N+t]=D.a,e[R+t]=D.b):(ge(e[S+t],e[N+t]),F=D.a,A=D.b,ge(e[C+t],e[R+t]),O=D.a,M=D.b,ge(F,O),e[S+t]=D.a,e[C+t]=D.b,ge(A,M),e[N+t]=D.a,e[R+t]=D.b)}if(n&f){let C=S+g;c?pe(e[S+t],e[C+t]):ge(e[S+t],e[C+t]),F=D.a,e[C+t]=D.b,e[S+t]=F}}if(i&f){let S=v,E=v+o*(n-u);for(;S<=E;S+=y){let C=S+m;c?pe(e[S+t],e[C+t]):ge(e[S+t],e[C+t]),F=D.a,e[C+t]=D.b,e[S+t]=F}}u=f,f>>=1}return v}function Ke(e,t,n,o,i,a,r,c,s){let f=0,u=0,v=r,h=Math.trunc(o.value+(i+7)/8);for(;o.value<h;)for(se(f,u,n,o),f=K.c,u=K.lc;u>=14;){let x=f>>u-14&16383,m=t[x];if(m.len)u-=m.len,he(m.lit,a,f,u,n,o,c,s,v),f=ee.c,u=ee.lc;else{if(!m.p)throw new Error("THREE.EXRLoader: hufDecode issues");let y;for(y=0;y<m.lit;y++){let F=j(e[m.p[y]]);for(;u<F&&o.value<h;)se(f,u,n,o),f=K.c,u=K.lc;if(u>=F&&We(e[m.p[y]])==(f>>u-F&(1<<F)-1)){u-=F,he(m.p[y],a,f,u,n,o,c,s,v),f=ee.c,u=ee.lc;break}}if(y==m.lit)throw new Error("THREE.EXRLoader: hufDecode issues")}}let g=8-i&7;for(f>>=g,u-=g;u>0;){let x=t[f<<14-u&16383];if(x.len)u-=x.len,he(x.lit,a,f,u,n,o,c,s,v),f=ee.c,u=ee.lc;else throw new Error("THREE.EXRLoader: hufDecode issues")}return!0}function be(e,t,n,o,i,a){let r={value:0},c=n.value,s=X(t,n),f=X(t,n);n.value+=4;let u=X(t,n);if(n.value+=4,s<0||s>=65537||f<0||f>=65537)throw new Error("THREE.EXRLoader: Something wrong with HUF_ENCSIZE");let v=new Array(65537),h=new Array(16384);lt(h);let g=o-(n.value-c);if(Xe(e,n,g,s,f,v),u>8*(o-(n.value-c)))throw new Error("THREE.EXRLoader: Something wrong with hufUncompress");ft(v,s,f,h),Ke(v,h,e,n,u,f,a,i,r)}function Dt(e,t,n){for(let o=0;o<n;++o)t[o]=e[t[o]]}function $e(e){for(let t=1;t<e.length;t++){let n=e[t-1]+e[t]-128;e[t]=n}}function Je(e,t){let n=0,o=Math.floor((e.length+1)/2),i=0,a=e.length-1;for(;!(i>a||(t[i++]=e[n++],i>a));)t[i++]=e[o++]}function ct(e){let t=e.byteLength,n=new Array,o=0,i=new DataView(e);for(;t>0;){let a=i.getInt8(o++);if(a<0){let r=-a;t-=r+1;for(let c=0;c<r;c++)n.push(i.getUint8(o++))}else{let r=a;t-=2;let c=i.getUint8(o++);for(let s=0;s<r+1;s++)n.push(c)}}return n}function Bt(e,t,n,o,i,a){let r=new DataView(a.buffer),c=n[e.idx[0]].width,s=n[e.idx[0]].height,f=3,u=Math.floor(c/8),v=Math.ceil(c/8),h=Math.ceil(s/8),g=c-(v-1)*8,x=s-(h-1)*8,m={value:0},y=new Array(f),F=new Array(f),O=new Array(f),A=new Array(f),M=new Array(f);for(let E=0;E<f;++E)M[E]=t[e.idx[E]],y[E]=E<1?0:y[E-1]+v*h,F[E]=new Float32Array(64),O[E]=new Uint16Array(64),A[E]=new Uint16Array(v*64);for(let E=0;E<h;++E){let C=8;E==h-1&&(C=x);let N=8;for(let d=0;d<v;++d){d==v-1&&(N=g);for(let H=0;H<f;++H)O[H].fill(0),O[H][0]=i[y[H]++],yt(m,o,O[H]),wt(O[H],F[H]),xt(F[H]);f==3&&Lt(F);for(let H=0;H<f;++H)Ct(F[H],A[H],d*64)}let R=0;for(let d=0;d<f;++d){let H=n[e.idx[d]].type;for(let L=8*E;L<8*E+C;++L){R=M[d][L];for(let W=0;W<u;++W){let B=W*64+(L&7)*8;r.setUint16(R+0*H,A[d][B+0],!0),r.setUint16(R+2*H,A[d][B+1],!0),r.setUint16(R+4*H,A[d][B+2],!0),r.setUint16(R+6*H,A[d][B+3],!0),r.setUint16(R+8*H,A[d][B+4],!0),r.setUint16(R+10*H,A[d][B+5],!0),r.setUint16(R+12*H,A[d][B+6],!0),r.setUint16(R+14*H,A[d][B+7],!0),R+=16*H}}if(u!=v)for(let L=8*E;L<8*E+C;++L){let W=M[d][L]+8*u*2*H,B=u*64+(L&7)*8;for(let ae=0;ae<N;++ae)r.setUint16(W+ae*2*H,A[d][B+ae],!0)}}}let S=new Uint16Array(c);r=new DataView(a.buffer);for(let E=0;E<f;++E){n[e.idx[E]].decoded=!0;let C=n[e.idx[E]].type;if(n[E].type==2)for(let N=0;N<s;++N){let R=M[E][N];for(let d=0;d<c;++d)S[d]=r.getUint16(R+d*2*C,!0);for(let d=0;d<c;++d)r.setFloat32(R+d*2*C,l.DataUtils.fromHalfFloat(S[d]),!0)}}}function kt(e,t,n,o,i,a){let r=new DataView(a.buffer),c=n[e],s=c.width,f=c.height,u=Math.ceil(s/8),v=Math.ceil(f/8),h=Math.floor(s/8),g=s-(u-1)*8,x=f-(v-1)*8,m={value:0},y=0,F=new Float32Array(64),O=new Uint16Array(64),A=new Uint16Array(u*64);for(let M=0;M<v;++M){let S=8;M==v-1&&(S=x);for(let E=0;E<u;++E)O.fill(0),O[0]=i[y++],yt(m,o,O),wt(O,F),xt(F),Ct(F,A,E*64);for(let E=8*M;E<8*M+S;++E){let C=t[e][E];for(let N=0;N<h;++N){let R=N*64+(E&7)*8;for(let d=0;d<8;++d)r.setUint16(C+d*2*c.type,A[R+d],!0);C+=16*c.type}if(u!=h){let N=h*64+(E&7)*8;for(let R=0;R<g;++R)r.setUint16(C+R*2*c.type,A[N+R],!0)}}}c.decoded=!0}function yt(e,t,n){let o,i=1;for(;i<64;)o=t[e.value],o==65280?i=64:o>>8==255?i+=o&255:(n[i]=o,i++),e.value++}function wt(e,t){t[0]=l.DataUtils.fromHalfFloat(e[0]),t[1]=l.DataUtils.fromHalfFloat(e[1]),t[2]=l.DataUtils.fromHalfFloat(e[5]),t[3]=l.DataUtils.fromHalfFloat(e[6]),t[4]=l.DataUtils.fromHalfFloat(e[14]),t[5]=l.DataUtils.fromHalfFloat(e[15]),t[6]=l.DataUtils.fromHalfFloat(e[27]),t[7]=l.DataUtils.fromHalfFloat(e[28]),t[8]=l.DataUtils.fromHalfFloat(e[2]),t[9]=l.DataUtils.fromHalfFloat(e[4]),t[10]=l.DataUtils.fromHalfFloat(e[7]),t[11]=l.DataUtils.fromHalfFloat(e[13]),t[12]=l.DataUtils.fromHalfFloat(e[16]),t[13]=l.DataUtils.fromHalfFloat(e[26]),t[14]=l.DataUtils.fromHalfFloat(e[29]),t[15]=l.DataUtils.fromHalfFloat(e[42]),t[16]=l.DataUtils.fromHalfFloat(e[3]),t[17]=l.DataUtils.fromHalfFloat(e[8]),t[18]=l.DataUtils.fromHalfFloat(e[12]),t[19]=l.DataUtils.fromHalfFloat(e[17]),t[20]=l.DataUtils.fromHalfFloat(e[25]),t[21]=l.DataUtils.fromHalfFloat(e[30]),t[22]=l.DataUtils.fromHalfFloat(e[41]),t[23]=l.DataUtils.fromHalfFloat(e[43]),t[24]=l.DataUtils.fromHalfFloat(e[9]),t[25]=l.DataUtils.fromHalfFloat(e[11]),t[26]=l.DataUtils.fromHalfFloat(e[18]),t[27]=l.DataUtils.fromHalfFloat(e[24]),t[28]=l.DataUtils.fromHalfFloat(e[31]),t[29]=l.DataUtils.fromHalfFloat(e[40]),t[30]=l.DataUtils.fromHalfFloat(e[44]),t[31]=l.DataUtils.fromHalfFloat(e[53]),t[32]=l.DataUtils.fromHalfFloat(e[10]),t[33]=l.DataUtils.fromHalfFloat(e[19]),t[34]=l.DataUtils.fromHalfFloat(e[23]),t[35]=l.DataUtils.fromHalfFloat(e[32]),t[36]=l.DataUtils.fromHalfFloat(e[39]),t[37]=l.DataUtils.fromHalfFloat(e[45]),t[38]=l.DataUtils.fromHalfFloat(e[52]),t[39]=l.DataUtils.fromHalfFloat(e[54]),t[40]=l.DataUtils.fromHalfFloat(e[20]),t[41]=l.DataUtils.fromHalfFloat(e[22]),t[42]=l.DataUtils.fromHalfFloat(e[33]),t[43]=l.DataUtils.fromHalfFloat(e[38]),t[44]=l.DataUtils.fromHalfFloat(e[46]),t[45]=l.DataUtils.fromHalfFloat(e[51]),t[46]=l.DataUtils.fromHalfFloat(e[55]),t[47]=l.DataUtils.fromHalfFloat(e[60]),t[48]=l.DataUtils.fromHalfFloat(e[21]),t[49]=l.DataUtils.fromHalfFloat(e[34]),t[50]=l.DataUtils.fromHalfFloat(e[37]),t[51]=l.DataUtils.fromHalfFloat(e[47]),t[52]=l.DataUtils.fromHalfFloat(e[50]),t[53]=l.DataUtils.fromHalfFloat(e[56]),t[54]=l.DataUtils.fromHalfFloat(e[59]),t[55]=l.DataUtils.fromHalfFloat(e[61]),t[56]=l.DataUtils.fromHalfFloat(e[35]),t[57]=l.DataUtils.fromHalfFloat(e[36]),t[58]=l.DataUtils.fromHalfFloat(e[48]),t[59]=l.DataUtils.fromHalfFloat(e[49]),t[60]=l.DataUtils.fromHalfFloat(e[57]),t[61]=l.DataUtils.fromHalfFloat(e[58]),t[62]=l.DataUtils.fromHalfFloat(e[62]),t[63]=l.DataUtils.fromHalfFloat(e[63])}function xt(e){let t=.5*Math.cos(.7853975),n=.5*Math.cos(3.14159/16),o=.5*Math.cos(3.14159/8),i=.5*Math.cos(3*3.14159/16),a=.5*Math.cos(5*3.14159/16),r=.5*Math.cos(3*3.14159/8),c=.5*Math.cos(7*3.14159/16),s=new Array(4),f=new Array(4),u=new Array(4),v=new Array(4);for(let h=0;h<8;++h){let g=h*8;s[0]=o*e[g+2],s[1]=r*e[g+2],s[2]=o*e[g+6],s[3]=r*e[g+6],f[0]=n*e[g+1]+i*e[g+3]+a*e[g+5]+c*e[g+7],f[1]=i*e[g+1]-c*e[g+3]-n*e[g+5]-a*e[g+7],f[2]=a*e[g+1]-n*e[g+3]+c*e[g+5]+i*e[g+7],f[3]=c*e[g+1]-a*e[g+3]+i*e[g+5]-n*e[g+7],u[0]=t*(e[g+0]+e[g+4]),u[3]=t*(e[g+0]-e[g+4]),u[1]=s[0]+s[3],u[2]=s[1]-s[2],v[0]=u[0]+u[1],v[1]=u[3]+u[2],v[2]=u[3]-u[2],v[3]=u[0]-u[1],e[g+0]=v[0]+f[0],e[g+1]=v[1]+f[1],e[g+2]=v[2]+f[2],e[g+3]=v[3]+f[3],e[g+4]=v[3]-f[3],e[g+5]=v[2]-f[2],e[g+6]=v[1]-f[1],e[g+7]=v[0]-f[0]}for(let h=0;h<8;++h)s[0]=o*e[16+h],s[1]=r*e[16+h],s[2]=o*e[48+h],s[3]=r*e[48+h],f[0]=n*e[8+h]+i*e[24+h]+a*e[40+h]+c*e[56+h],f[1]=i*e[8+h]-c*e[24+h]-n*e[40+h]-a*e[56+h],f[2]=a*e[8+h]-n*e[24+h]+c*e[40+h]+i*e[56+h],f[3]=c*e[8+h]-a*e[24+h]+i*e[40+h]-n*e[56+h],u[0]=t*(e[h]+e[32+h]),u[3]=t*(e[h]-e[32+h]),u[1]=s[0]+s[3],u[2]=s[1]-s[2],v[0]=u[0]+u[1],v[1]=u[3]+u[2],v[2]=u[3]-u[2],v[3]=u[0]-u[1],e[0+h]=v[0]+f[0],e[8+h]=v[1]+f[1],e[16+h]=v[2]+f[2],e[24+h]=v[3]+f[3],e[32+h]=v[3]-f[3],e[40+h]=v[2]-f[2],e[48+h]=v[1]-f[1],e[56+h]=v[0]-f[0]}function Lt(e){for(let t=0;t<64;++t){let n=e[0][t],o=e[1][t],i=e[2][t];e[0][t]=n+1.5747*i,e[1][t]=n-.1873*o-.4682*i,e[2][t]=n+1.8556*o}}let ut=new Float32Array(1),Et=new Uint32Array(ut.buffer);function St(e){ut[0]=e;let t=Et[0],n=t>>>16&32768,o=t&2147483647;if(o>=1199570944)return n|(o>2139095040?32256:31744);if(o<947912704)return ut[0]=Math.abs(e)+.5,n|Et[0]-1056964608;let i=o+4095+(o>>>13&1);return n|i-939524096>>>13}function Ct(e,t,n){if(P===null){P=new Uint16Array(65536);for(let o=1;o<65536;++o){if((o&31744)===31744)continue;let i=l.DataUtils.fromHalfFloat(o),a=Math.abs(i),r=a<=1?Math.pow(a,2.2):Math.pow(xe,a-1);P[o]=St(i<0?-r:r)}}for(let o=0;o<64;++o)t[n+o]=P[St(e[o])]}function Qe(e){return new DataView(e.array.buffer,e.offset.value,e.size)}function Zt(e){let t=e.viewer.buffer.slice(e.offset.value,e.offset.value+e.size),n=new Uint8Array(ct(t)),o=new Uint8Array(n.length);return $e(n),Je(n,o),new DataView(o.buffer)}function ht(e){let t=e.array.slice(e.offset.value,e.offset.value+e.size),n=He(t),o=new Uint8Array(n.length);return $e(n),Je(n,o),new DataView(o.buffer)}function Pt(e){let t=e.viewer,n={value:e.offset.value},o=new Uint16Array(e.columns*e.lines*(e.inputChannels.length*e.type)),i=new Uint8Array(8192),a=0,r=new Array(e.inputChannels.length);for(let x=0,m=e.inputChannels.length;x<m;x++)r[x]={},r[x].start=a,r[x].end=r[x].start,r[x].nx=e.columns,r[x].ny=e.lines,r[x].size=e.type,a+=r[x].nx*r[x].ny*r[x].size;let c=ze(t,n),s=ze(t,n);if(s>=8192)throw new Error("THREE.EXRLoader: Something is wrong with PIZ_COMPRESSION BITMAP_SIZE");if(c<=s)for(let x=0;x<s-c+1;x++)i[x+c]=ye(t,n);let f=new Uint16Array(65536),u=Ge(i,f),v=X(t,n);be(e.array,t,n,v,o,a);for(let x=0;x<e.inputChannels.length;++x){let m=r[x];for(let y=0;y<r[x].size;++y)qe(o,m.start+y,m.nx,m.size,m.ny,m.nx*m.size,u)}Dt(f,o,a);let h=0,g=new Uint8Array(o.buffer.byteLength);for(let x=0;x<e.lines;x++)for(let m=0;m<e.inputChannels.length;m++){let y=r[m],F=y.nx*y.size,O=new Uint8Array(o.buffer,y.end*2,F*2);g.set(O,h),h+=F*2,y.end+=F}return new DataView(g.buffer)}function _t(e){let t=e.array.slice(e.offset.value,e.offset.value+e.size),n=He(t),o=e.inputChannels.length*e.lines*e.columns*e.totalBytes,i=new ArrayBuffer(o),a=new DataView(i),r=0,c=0,s=new Array(4);for(let f=0;f<e.lines;f++)for(let u=0;u<e.inputChannels.length;u++){let v=0;switch(e.inputChannels[u].pixelType){case 1:s[0]=r,s[1]=s[0]+e.columns,r=s[1]+e.columns;for(let g=0;g<e.columns;++g){let x=n[s[0]++]<<8|n[s[1]++];v+=x,a.setUint16(c,v,!0),c+=2}break;case 2:s[0]=r,s[1]=s[0]+e.columns,s[2]=s[1]+e.columns,r=s[2]+e.columns;for(let g=0;g<e.columns;++g){let x=n[s[0]++]<<24|n[s[1]++]<<16|n[s[2]++]<<8;v+=x,a.setUint32(c,v,!0),c+=4}break}}return a}function Yt(e){let t=e.array,n=e.offset.value,o=e.columns,i=e.lines,a=e.inputChannels,r=e.totalBytes,c=Y.compression==="B44A_COMPRESSION",s=new Uint8Array(i*o*r),f=new Uint16Array(16),u=0;for(let v=0;v<a.length;v++){let h=a[v],g=h.pixelType*2,x=Math.ceil(o/h.xSampling),m=Math.ceil(i/h.ySampling),y=h.xSampling===1&&h.ySampling===1;if(h.pixelType!==1){for(let A=0;A<m;A++)if(y){let M=A*o*r+u*o;for(let S=0;S<x*g;S++)s[M+S]=t[n++]}else n+=x*g;u+=g;continue}let F=Math.ceil(x/4),O=Math.ceil(m/4);for(let A=0;A<O;A++)for(let M=0;M<F;M++){if(c&&t[n+2]>=52){let S=t[n]<<8|t[n+1],E=S&32768?S&32767:~S&65535;f.fill(E),n+=3}else{let S=t[n]<<8|t[n+1],E=t[n+2]>>2,C=32<<E,N=S+((t[n+2]<<4|t[n+3]>>4)&63)*(1<<E)-C&65535,R=N+((t[n+3]<<2|t[n+4]>>6)&63)*(1<<E)-C&65535,d=R+(t[n+4]&63)*(1<<E)-C&65535,H=S+(t[n+5]>>2&63)*(1<<E)-C&65535,L=N+((t[n+5]<<4|t[n+6]>>4)&63)*(1<<E)-C&65535,W=R+((t[n+6]<<2|t[n+7]>>6)&63)*(1<<E)-C&65535,B=d+(t[n+7]&63)*(1<<E)-C&65535,ae=H+(t[n+8]>>2&63)*(1<<E)-C&65535,Te=L+((t[n+8]<<4|t[n+9]>>4)&63)*(1<<E)-C&65535,Ne=W+((t[n+9]<<2|t[n+10]>>6)&63)*(1<<E)-C&65535,le=B+(t[n+10]&63)*(1<<E)-C&65535,Se=ae+(t[n+11]>>2&63)*(1<<E)-C&65535,nt=Te+((t[n+11]<<4|t[n+12]>>4)&63)*(1<<E)-C&65535,rt=Ne+((t[n+12]<<2|t[n+13]>>6)&63)*(1<<E)-C&65535,ot=le+(t[n+13]&63)*(1<<E)-C&65535,De=[S,H,ae,Se,N,L,Te,nt,R,W,Ne,rt,d,B,le,ot];for(let Ue=0;Ue<16;Ue++)f[Ue]=De[Ue]&32768?De[Ue]&32767:~De[Ue]&65535;n+=14}if(h.pLinear){if(ue===null){ue=new Uint16Array(65536);for(let S=0;S<65536;S++)if((S&31744)===31744||S>32768)ue[S]=0;else{let E=l.DataUtils.fromHalfFloat(S);ue[S]=E<=0?0:l.DataUtils.toHalfFloat(8*Math.log(E))}}for(let S=0;S<16;S++)f[S]=ue[f[S]]}for(let S=0;S<4;S++){let E=A*4+S;if(!(E>=m))for(let C=0;C<4;C++){let N=M*4+C;if(N>=x)continue;let R=f[S*4+C];for(let d=0;d<h.ySampling;d++){let H=E*h.ySampling+d;if(!(H>=i))for(let L=0;L<h.xSampling;L++){let W=N*h.xSampling+L;if(W>=o)continue;let B=H*o*r+u*o+W*2;s[B]=R&255,s[B+1]=R>>8&255}}}}}u+=2}return new DataView(s.buffer)}function It(e){let t=e.viewer,n={value:e.offset.value},o=new Uint8Array(e.columns*e.lines*(e.inputChannels.length*e.type*2)),i={version:Z(t,n),unknownUncompressedSize:Z(t,n),unknownCompressedSize:Z(t,n),acCompressedSize:Z(t,n),dcCompressedSize:Z(t,n),rleCompressedSize:Z(t,n),rleUncompressedSize:Z(t,n),rleRawSize:Z(t,n),totalAcUncompressedCount:Z(t,n),totalDcUncompressedCount:Z(t,n),acCompression:Z(t,n)};if(i.version<2)throw new Error("THREE.EXRLoader: "+Y.compression+" version "+i.version+" is unsupported");let a=new Array,r=ze(t,n)-2;for(;r>0;){let m=Ve(t.buffer,n),y=ye(t,n),F=y>>2&3,O=(y>>4)-1,A=new Int8Array([O])[0],M=ye(t,n);a.push({name:m,index:A,type:M,compression:F}),r-=m.length+3}let c=Y.channels,s=new Array(e.inputChannels.length);for(let m=0;m<e.inputChannels.length;++m){let y=s[m]={},F=c[m];y.name=F.name,y.compression=0,y.decoded=!1,y.type=F.pixelType,y.pLinear=F.pLinear,y.width=e.columns,y.height=e.lines}let f={idx:new Array(3)};for(let m=0;m<e.inputChannels.length;++m){let y=s[m],F=y.name.lastIndexOf("."),O=F>=0?y.name.substring(F+1):y.name;for(let A=0;A<a.length;++A){let M=a[A];O===M.name&&y.type===M.type&&(y.compression=M.compression,M.index>=0&&(f.idx[M.index]=m),y.offset=m)}}let u,v,h;if(i.acCompressedSize>0)switch(i.acCompression){case 0:u=new Uint16Array(i.totalAcUncompressedCount),be(e.array,t,n,i.acCompressedSize,u,i.totalAcUncompressedCount);break;case 1:let m=e.array.slice(n.value,n.value+i.totalAcUncompressedCount),y=He(m);u=new Uint16Array(y.buffer),n.value+=i.totalAcUncompressedCount;break}if(i.dcCompressedSize>0){let m={array:e.array,offset:n,size:i.dcCompressedSize};v=new Uint16Array(ht(m).buffer),n.value+=i.dcCompressedSize}if(i.rleRawSize>0){let m=e.array.slice(n.value,n.value+i.rleCompressedSize),y=He(m);h=ct(y.buffer),n.value+=i.rleCompressedSize}let g=0,x=new Array(s.length);for(let m=0;m<x.length;++m)x[m]=new Array;for(let m=0;m<e.lines;++m)for(let y=0;y<s.length;++y)x[y].push(g),g+=s[y].width*e.type*2;f.idx[0]!==void 0&&s[f.idx[0]]&&Bt(f,x,s,u,v,o);for(let m=0;m<s.length;++m){let y=s[m];if(!y.decoded)switch(y.compression){case 2:let F=0,O=0;for(let A=0;A<e.lines;++A){let M=x[m][F];for(let S=0;S<y.width;++S){for(let E=0;E<2*y.type;++E)o[M++]=h[O+E*y.width*y.height];O++}F++}break;case 1:kt(m,x,s,u,v,o);break;default:throw new Error("THREE.EXRLoader: unsupported channel compression")}}return new DataView(o.buffer)}function Ve(e,t){let n=new Uint8Array(e),o=0;for(;n[t.value+o]!=0;)o+=1;let i=new TextDecoder().decode(n.slice(t.value,t.value+o));return t.value=t.value+o+1,i}function Gt(e,t,n){let o=new TextDecoder().decode(new Uint8Array(e).slice(t.value,t.value+n));return t.value=t.value+n,o}function Xt(e,t){let n=G(e,t),o=X(e,t);return[n,o]}function Wt(e,t){let n=X(e,t),o=X(e,t);return[n,o]}function G(e,t){let n=e.getInt32(t.value,!0);return t.value=t.value+4,n}function X(e,t){let n=e.getUint32(t.value,!0);return t.value=t.value+4,n}function Ft(e,t){let n=e[t.value];return t.value=t.value+1,n}function ye(e,t){let n=e.getUint8(t.value);return t.value=t.value+1,n}let Z=function(e,t){let n=Number(e.getBigInt64(t.value,!0));return t.value+=8,n};function _(e,t){let n=e.getFloat32(t.value,!0);return t.value+=4,n}function qt(e,t){return l.DataUtils.toHalfFloat(_(e,t))}function ze(e,t){let n=e.getUint16(t.value,!0);return t.value+=2,n}function Kt(e,t){return l.DataUtils.fromHalfFloat(ze(e,t))}function $t(e,t,n,o){let i=n.value,a=[];for(;n.value<i+o-1;){let r=Ve(t,n),c=G(e,n),s=ye(e,n);n.value+=3;let f=G(e,n),u=G(e,n);a.push({name:r,pixelType:c,pLinear:s,xSampling:f,ySampling:u})}return n.value+=1,a}function Jt(e,t){let n=_(e,t),o=_(e,t),i=_(e,t),a=_(e,t),r=_(e,t),c=_(e,t),s=_(e,t),f=_(e,t);return{redX:n,redY:o,greenX:i,greenY:a,blueX:r,blueY:c,whiteX:s,whiteY:f}}function Qt(e,t){let n=["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"],o=ye(e,t);return n[o]}function Vt(e,t){let n=G(e,t),o=G(e,t),i=G(e,t),a=G(e,t);return{xMin:n,yMin:o,xMax:i,yMax:a}}function jt(e,t){let n=["INCREASING_Y","DECREASING_Y","RANDOM_Y"],o=ye(e,t);return n[o]}function en(e,t){let n=["ENVMAP_LATLONG","ENVMAP_CUBE"],o=ye(e,t);return n[o]}function tn(e,t){let n=["ONE_LEVEL","MIPMAP_LEVELS","RIPMAP_LEVELS"],o=["ROUND_DOWN","ROUND_UP"],i=X(e,t),a=X(e,t),r=ye(e,t);return{xSize:i,ySize:a,levelMode:n[r&15],roundingMode:o[r>>4]}}function nn(e,t){let n=_(e,t),o=_(e,t);return[n,o]}function rn(e,t){let n=_(e,t),o=_(e,t),i=_(e,t);return[n,o,i]}function on(e,t,n,o,i){if(o==="string"||o==="stringvector"||o==="iccProfile")return Gt(t,n,i);if(o==="chlist")return $t(e,t,n,i);if(o==="chromaticities")return Jt(e,n);if(o==="compression")return Qt(e,n);if(o==="box2i")return Vt(e,n);if(o==="envmap")return en(e,n);if(o==="tiledesc")return tn(e,n);if(o==="lineOrder")return jt(e,n);if(o==="float")return _(e,n);if(o==="v2f")return nn(e,n);if(o==="v3f")return rn(e,n);if(o==="int")return G(e,n);if(o==="rational")return Xt(e,n);if(o==="timecode")return Wt(e,n);if(o==="preview"||o==="deepImageState"||o==="idmanifest")return n.value+=i,"skipped";n.value+=i}function sn(e,t){let n=Math.log2(e);return t=="ROUND_DOWN"?Math.floor(n):Math.ceil(n)}function an(e,t,n){let o=0;switch(e.levelMode){case"ONE_LEVEL":o=1;break;case"MIPMAP_LEVELS":o=sn(Math.max(t,n),e.roundingMode)+1;break;case"RIPMAP_LEVELS":throw new Error("THREE.EXRLoader: RIPMAP_LEVELS tiles currently unsupported.")}return o}function At(e,t,n,o){let i=new Array(e);for(let a=0;a<e;a++){let r=1<<a,c=t/r|0;o=="ROUND_UP"&&c*r<t&&(c+=1);let s=Math.max(c,1);i[a]=(s+n-1)/n|0}return i}function ln(){let e=this,t=e.offset,n={value:0};for(let o=0;o<e.tileCount;o++){let i=G(e.viewer,t),a=G(e.viewer,t);t.value+=8,e.size=X(e.viewer,t);let r=i*e.blockWidth,c=a*e.blockHeight;e.columns=r+e.blockWidth>e.width?e.width-r:e.blockWidth,e.lines=c+e.blockHeight>e.height?e.height-c:e.blockHeight;let s=e.columns*e.totalBytes,u=e.size<e.lines*s?e.uncompress(e):Qe(e);t.value+=e.size;for(let v=0;v<e.lines;v++){let h=v*e.columns*e.totalBytes;for(let g=0;g<e.inputChannels.length;g++){let x=Y.channels[g].name,m=e.channelByteOffsets[x]*e.columns,y=e.decodeChannels[x];if(y===void 0)continue;n.value=h+m;let F=(e.height-(1+c+v))*e.outLineWidth;for(let O=0;O<e.columns;O++){let A=F+(O+r)*e.outputChannels+y;e.byteArray[A]=e.getter(u,n)}}}}}function fn(){let e=this,t=e.offset,n={value:0};for(let o=0;o<e.height/e.blockHeight;o++){let i=G(e.viewer,t)-Y.dataWindow.yMin;e.size=X(e.viewer,t),e.lines=i+e.blockHeight>e.height?e.height-i:e.blockHeight;let a=e.columns*e.totalBytes,c=e.size<e.lines*a?e.uncompress(e):Qe(e);t.value+=e.size;for(let s=0;s<e.lines;s++){let f=i+s,u=s*a,v=(e.height-1-f)*e.outLineWidth;for(let h=0;h<e.inputChannels.length;h++){let g=Y.channels[h].name,x=e.channelByteOffsets[g]*e.columns,m=e.decodeChannels[g];if(m!==void 0){n.value=u+x;for(let y=0;y<e.columns;y++){let F=v+y*e.outputChannels+m;e.byteArray[F]=e.getter(c,n)}}}}}}function cn(){let e=this,t=e.chunkOffsets,n={value:0};for(let o=0;o<t.length;o++){let i={value:t[o]};i.value+=4;let a=G(e.viewer,i)-Y.dataWindow.yMin;e.size=X(e.viewer,i),e.lines=a+e.blockHeight>e.height?e.height-a:e.blockHeight;let r=e.columns*e.totalBytes,c=e.size<e.lines*r,s=e.offset;e.offset=i;let f=c?e.uncompress(e):Qe(e);e.offset=s;for(let u=0;u<e.lines;u++){let v=a+u,h=u*r,g=(e.height-1-v)*e.outLineWidth;for(let x=0;x<e.inputChannels.length;x++){let m=Y.channels[x].name,y=e.channelByteOffsets[m]*e.columns,F=e.decodeChannels[m];if(F!==void 0){n.value=h+y;for(let O=0;O<e.columns;O++){let A=g+O*e.outputChannels+F;e.byteArray[A]=e.getter(f,n)}}}}}}function dt(e,t,n,o){if(n===0)return null;let i=e.slice(t,t+n);switch(o){case"NO_COMPRESSION":return new DataView(i.buffer,i.byteOffset,i.byteLength);case"RLE_COMPRESSION":{let a=new Uint8Array(ct(i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength))),r=new Uint8Array(a.length);return $e(a),Je(a,r),new DataView(r.buffer)}case"ZIPS_COMPRESSION":{let a=He(i),r=new Uint8Array(a.length);return $e(a),Je(a,r),new DataView(r.buffer)}default:throw new Error("THREE.EXRLoader: "+o+" is unsupported for deep data")}}function un(){let e=this,t=e.chunkOffsets,n=e.width,o=e.height,i=e.deepChannels,a=Y.compression,r=e.multiPart,c=e.decodeChannels,s=e.outputChannels,f=e.byteArray instanceof Uint16Array,u=-1;for(let v=0;v<i.length;v++)if(i[v].name==="A"){u=v;break}for(let v=0;v<t.length;v++){let h={value:t[v]};r&&(h.value+=4);let g=G(e.viewer,h)-Y.dataWindow.yMin,x=Z(e.viewer,h),m=Z(e.viewer,h);Z(e.viewer,h);let y=dt(e.array,h.value,x,a);if(h.value+=x,y===null)continue;let F=new Uint32Array(n);for(let C=0;C<n;C++)F[C]=y.getUint32(C*4,!0);let O=F[n-1];if(O===0){h.value+=m;continue}let A=dt(e.array,h.value,m,a),M=[],S=0;for(let C=0;C<i.length;C++)M.push(S),S+=O*i[C].bytesPerSample;let E=(o-1-g)*e.outLineWidth;for(let C=0;C<n;C++){let N=C===0?0:F[C-1],d=F[C]-N;if(d===0)continue;let H=new Float32Array(s),L=0;for(let B=0;B<d;B++){let ae=N+B,Te=1-L;if(Te<=0)break;let Ne=1;if(u>=0){let le=i[u].bytesPerSample,Se=M[u]+ae*le;Ne=le===2?l.DataUtils.fromHalfFloat(A.getUint16(Se,!0)):A.getFloat32(Se,!0)}for(let le=0;le<i.length;le++){let Se=i[le],nt=c[Se.name];if(nt===void 0)continue;let rt=Se.bytesPerSample,ot=M[le]+ae*rt,De=rt===2?l.DataUtils.fromHalfFloat(A.getUint16(ot,!0)):A.getFloat32(ot,!0);H[nt]+=De*Te}L+=Ne*Te}c.A!==void 0&&(H[c.A]=L);let W=E+C*s;for(let B=0;B<s;B++)e.byteArray[W+B]=f?l.DataUtils.toHalfFloat(H[B]):H[B]}}}function Tt(e,t,n){let o={},i=!1;for(;;){let a=Ve(t,n);if(a==="")break;i=!0;let r=Ve(t,n),c=X(e,n),s=on(e,t,n,r,c);s===void 0?console.warn(`THREE.EXRLoader: Skipped unknown header attribute type '${r}'.`):o[a]=s}return i?o:null}function hn(e,t,n){if(e.getUint32(0,!0)!=20000630)throw new Error("THREE.EXRLoader: Provided file doesn't appear to be in OpenEXR format.");let o=e.getUint8(4),i=e.getUint8(5),a={singleTile:!!(i&2),longName:!!(i&4),deepFormat:!!(i&8),multiPart:!!(i&16)};n.value=8;let r=[];if(a.multiPart){for(;;){let c=Tt(e,t,n);if(c===null)break;c.version=o,c.spec=a,r.push(c)}if(r.length===0)throw new Error("THREE.EXRLoader: No valid part headers found.")}else{let c=Tt(e,t,n);c.version=o,c.spec=a,r.push(c)}return r}function pn(e,t,n,o,i,a){let r={size:0,viewer:t,array:n,offset:o,width:e.dataWindow.xMax-e.dataWindow.xMin+1,height:e.dataWindow.yMax-e.dataWindow.yMin+1,inputChannels:e.channels,channelByteOffsets:{},shouldExpand:!1,yCbCr:!1,totalBytes:null,columns:null,lines:null,type:null,uncompress:null,getter:null,format:null,colorSpace:l.LinearSRGBColorSpace};switch(e.compression){case"NO_COMPRESSION":r.blockHeight=1,r.uncompress=Qe;break;case"RLE_COMPRESSION":r.blockHeight=1,r.uncompress=Zt;break;case"ZIPS_COMPRESSION":r.blockHeight=1,r.uncompress=ht;break;case"ZIP_COMPRESSION":r.blockHeight=16,r.uncompress=ht;break;case"PIZ_COMPRESSION":r.blockHeight=32,r.uncompress=Pt;break;case"PXR24_COMPRESSION":r.blockHeight=16,r.uncompress=_t;break;case"B44_COMPRESSION":case"B44A_COMPRESSION":r.blockHeight=32,r.uncompress=Yt;break;case"DWAA_COMPRESSION":r.blockHeight=32,r.uncompress=It;break;case"DWAB_COMPRESSION":r.blockHeight=256,r.uncompress=It;break;default:throw new Error("THREE.EXRLoader: "+e.compression+" is unsupported")}let c={};for(let h of e.channels)switch(h.name){case"BY":case"RY":case"Y":case"R":case"G":case"B":case"A":c[h.name]=!0,r.type=h.pixelType}let s=!1,f=!1;if(c.Y&&c.RY&&c.BY)r.outputChannels=4,r.yCbCr=!0;else if(c.R&&c.G&&c.B)r.outputChannels=4;else if(c.Y)r.outputChannels=1;else throw new Error("THREE.EXRLoader: file contains unsupported data channels.");switch(r.outputChannels){case 4:a==l.RGBAFormat?(s=!c.A,r.format=l.RGBAFormat,r.colorSpace=l.LinearSRGBColorSpace,r.outputChannels=4,r.decodeChannels={R:0,G:1,B:2,A:3}):a==l.RGFormat?(r.format=l.RGFormat,r.colorSpace=l.LinearSRGBColorSpace,r.outputChannels=2,r.decodeChannels={R:0,G:1}):a==l.RedFormat?(r.format=l.RedFormat,r.colorSpace=l.LinearSRGBColorSpace,r.outputChannels=1,r.decodeChannels={R:0}):f=!0;break;case 1:a==l.RGBAFormat?(s=!0,r.format=l.RGBAFormat,r.colorSpace=l.LinearSRGBColorSpace,r.outputChannels=4,r.shouldExpand=!0,r.decodeChannels={Y:0}):a==l.RGFormat?(r.format=l.RGFormat,r.colorSpace=l.LinearSRGBColorSpace,r.outputChannels=2,r.shouldExpand=!0,r.decodeChannels={Y:0}):a==l.RedFormat?(r.format=l.RedFormat,r.colorSpace=l.LinearSRGBColorSpace,r.outputChannels=1,r.decodeChannels={Y:0}):f=!0;break;default:f=!0}if(f)throw new Error("THREE.EXRLoader: invalid output format for specified file.");if(r.yCbCr&&(r.format=l.RGBAFormat,r.outputChannels=4,r.decodeChannels={Y:0,RY:1,BY:2},s=!0),r.type==1)switch(i){case l.FloatType:r.getter=Kt;break;case l.HalfFloatType:r.getter=ze;break}else if(r.type==2)switch(i){case l.FloatType:r.getter=_;break;case l.HalfFloatType:r.getter=qt}else throw new Error("THREE.EXRLoader: unsupported pixelType "+r.type+" for "+e.compression+".");r.columns=r.width;let u=r.width*r.height*r.outputChannels;switch(i){case l.FloatType:r.byteArray=new Float32Array(u),s&&r.byteArray.fill(1,0,u);break;case l.HalfFloatType:r.byteArray=new Uint16Array(u),s&&r.byteArray.fill(15360,0,u);break;default:console.error("THREE.EXRLoader: unsupported type: ",i);break}let v=0;for(let h of e.channels)r.decodeChannels[h.name]!==void 0&&(r.channelByteOffsets[h.name]=v),v+=h.pixelType*2;if(r.totalBytes=v,r.outLineWidth=r.width*r.outputChannels,e.spec.deepFormat){r.deepChannels=[];let h=0;for(let g of e.channels){let x=g.pixelType===0?4:g.pixelType*2;r.deepChannels.push({name:g.name,pixelType:g.pixelType,bytesPerSample:x}),h+=x}r.deepBytesPerSample=h,r.chunkOffsets=e._chunkOffsets,r.multiPart=e.spec.multiPart,r.decode=un.bind(r)}else if(e.spec.singleTile){r.blockHeight=e.tiles.ySize,r.blockWidth=e.tiles.xSize;let h=an(e.tiles,r.width,r.height),g=At(h,r.width,e.tiles.xSize,e.tiles.roundingMode),x=At(h,r.height,e.tiles.ySize,e.tiles.roundingMode);r.tileCount=g[0]*x[0];for(let m=0;m<h;m++)for(let y=0;y<x[m];y++)for(let F=0;F<g[m];F++)Z(t,o);r.decode=ln.bind(r)}else if(e.spec.multiPart)r.blockWidth=r.width,r.chunkOffsets=e._chunkOffsets,r.decode=cn.bind(r);else{r.blockWidth=r.width;let h=Math.ceil(r.height/r.blockHeight);for(let g=0;g<h;g++)Z(t,o);r.decode=fn.bind(r)}return r}let je={value:0},et=new DataView(p),vn=new Uint8Array(p),tt=hn(et,p,je),Ut=Math.max(0,Math.min(this.part,tt.length-1)),Y=tt[Ut];if(Y.spec.multiPart||Y.spec.deepFormat)for(let e=0;e<tt.length;e++){let t=tt[e].chunkCount;if(e===Ut){Y._chunkOffsets=[];for(let n=0;n<t;n++)Y._chunkOffsets.push(Z(et,je))}else for(let n=0;n<t;n++)Z(et,je)}let $=pn(Y,et,vn,je,this.type,this.outputFormat);if($.decode(),$.shouldExpand){let e=$.byteArray;if(this.outputFormat==l.RGBAFormat)for(let t=0;t<e.length;t+=4)e[t+2]=e[t+1]=e[t];else if(this.outputFormat==l.RGFormat)for(let t=0;t<e.length;t+=2)e[t+1]=e[t]}if($.yCbCr){let e=$.byteArray,t=$.width*$.height;if(this.type===l.HalfFloatType)for(let n=0;n<t;n++){let o=n*4,i=l.DataUtils.fromHalfFloat(e[o]),a=l.DataUtils.fromHalfFloat(e[o+1]),r=l.DataUtils.fromHalfFloat(e[o+2]),c=(1+a)*i,s=(1+r)*i,f=(i-c*.2126-s*.0722)/.7152;e[o]=l.DataUtils.toHalfFloat(Math.max(0,c)),e[o+1]=l.DataUtils.toHalfFloat(Math.max(0,f)),e[o+2]=l.DataUtils.toHalfFloat(Math.max(0,s))}else for(let n=0;n<t;n++){let o=n*4,i=e[o],a=e[o+1],r=e[o+2],c=(1+a)*i,s=(1+r)*i;e[o]=Math.max(0,c),e[o+1]=Math.max(0,(i-c*.2126-s*.0722)/.7152),e[o+2]=Math.max(0,s)}}return{header:Y,width:$.width,height:$.height,data:$.byteArray,format:$.format,colorSpace:$.colorSpace,type:this.type,minFilter:l.LinearFilter,magFilter:l.LinearFilter,generateMipmaps:!1,flipY:!1}}setDataType(p){return this.type=p,this}setOutputFormat(p){return this.outputFormat=p,this}setPart(p){return this.part=p,this}};function Nn(w){let p=new it().parse(w),I=new re.DataTexture(p.data,p.width,p.height,p.format??re.RGBAFormat,p.type??re.HalfFloatType);return I.colorSpace=p.colorSpace??re.NoColorSpace,I.flipY=p.flipY??!1,I.generateMipmaps=p.generateMipmaps??!1,I.minFilter=p.minFilter??re.LinearFilter,I.magFilter=p.magFilter??re.LinearFilter,I.unpackAlignment=p.unpackAlignment??1,I.userData.dsh3dHdr=!0,I.needsUpdate=!0,I}
11
+ })(localRequire, module, module.exports);
12
+ return module.exports;
13
+ },
14
+ });
@@ -0,0 +1,18 @@
1
+ /*! dsh-3d-viewer tex-hdr loader chunk | bundles Three.js addons (MIT). See THIRD_PARTY_NOTICES.md. */
2
+ window.__ModuleLoader__.load({
3
+ id: "dsh-3d-viewer",
4
+ chunk: "client.tex-hdr.js",
5
+ factory(require) {
6
+ var localRequire = (id) => id === 'three' ? globalThis.__DSH3DV_THREE__ : require(id);
7
+ var module = { exports: {} };
8
+ var exports = module.exports;
9
+ (function (require, module, exports) {
10
+ var I=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var z=(h,n)=>{for(var p in n)I(h,p,{get:n[p],enumerable:!0})},$=(h,n,p,A)=>{if(n&&typeof n=="object"||typeof n=="function")for(let w of P(n))!Y.call(h,w)&&w!==p&&I(h,w,{get:()=>n[w],enumerable:!(A=C(n,w))||A.enumerable});return h};var W=h=>$(I({},"__esModule",{value:!0}),h);var X={};z(X,{decodeHdr:()=>j});module.exports=W(X);var m=require("three");var c=require("three"),u=class extends c.DataTextureLoader{constructor(n){super(n),this.type=c.HalfFloatType}parse(n){let g=function(e,t){switch(e){case 1:throw new Error("THREE.HDRLoader: Read Error: "+(t||""));case 2:throw new Error("THREE.HDRLoader: Write Error: "+(t||""));case 3:throw new Error("THREE.HDRLoader: Bad File Format: "+(t||""));default:case 4:throw new Error("THREE.HDRLoader: Memory Error: "+(t||""))}},M=function(e,t,a){t=t||1024;let s=e.pos,l=-1,r=0,_="",o=String.fromCharCode.apply(null,new Uint16Array(e.subarray(s,s+128)));for(;0>(l=o.indexOf(`
11
+ `))&&r<t&&s<e.byteLength;)_+=o,r+=o.length,s+=128,o=String.fromCharCode.apply(null,new Uint16Array(e.subarray(s,s+128)));return-1<l?(a!==!1&&(e.pos+=r+l+1),_+o.slice(0,l)):!1},N=function(e){let t=/^#\?(\S+)/,a=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,i=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,s=/^\s*FORMAT=(\S+)\s*$/,l=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,r={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0},_,o;for((e.pos>=e.byteLength||!(_=M(e)))&&g(1,"no header found"),(o=_.match(t))||g(3,"bad initial token"),r.valid|=1,r.programtype=o[1],r.string+=_+`
12
+ `;_=M(e),_!==!1;){if(r.string+=_+`
13
+ `,_.charAt(0)==="#"){r.comments+=_+`
14
+ `;continue}if((o=_.match(a))&&(r.gamma=parseFloat(o[1])),(o=_.match(i))&&(r.exposure=parseFloat(o[1])),(o=_.match(s))&&(r.valid|=2,r.format=o[1]),(o=_.match(l))&&(r.valid|=4,r.height=parseInt(o[1],10),r.width=parseInt(o[2],10)),r.valid&2&&r.valid&4)break}return r.valid&2||g(3,"missing format specifier"),r.valid&4||g(3,"missing image size specifier"),r},k=function(e,t,a){let i=t;if(i<8||i>32767||e[0]!==2||e[1]!==2||e[2]&128)return new Uint8Array(e);i!==(e[2]<<8|e[3])&&g(3,"wrong scanline width");let s=new Uint8Array(4*t*a);s.length||g(4,"unable to allocate buffer space");let l=0,r=0,_=4*i,o=new Uint8Array(4),F=new Uint8Array(_),f=a;for(;f>0&&r<e.byteLength;){r+4>e.byteLength&&g(1),o[0]=e[r++],o[1]=e[r++],o[2]=e[r++],o[3]=e[r++],(o[0]!=2||o[1]!=2||(o[2]<<8|o[3])!=i)&&g(3,"bad rgbe scanline format");let L=0,d;for(;L<_&&r<e.byteLength;){d=e[r++];let E=d>128;if(E&&(d-=128),(d===0||L+d>_)&&g(3,"bad scanline data"),E){let R=e[r++];for(let x=0;x<d;x++)F[L++]=R}else F.set(e.subarray(r,r+d),L),L+=d,r+=d}let v=i;for(let E=0;E<v;E++){let R=0;s[l]=F[E+R],R+=i,s[l+1]=F[E+R],R+=i,s[l+2]=F[E+R],R+=i,s[l+3]=F[E+R],l+=4}f--}return s},U=function(e,t,a,i){let s=e[t+3],l=Math.pow(2,s-128)/255;a[i+0]=e[t+0]*l,a[i+1]=e[t+1]*l,a[i+2]=e[t+2]*l,a[i+3]=1},V=function(e,t,a,i){let s=e[t+3],l=Math.pow(2,s-128)/255;a[i+0]=c.DataUtils.toHalfFloat(Math.min(e[t+0]*l,65504)),a[i+1]=c.DataUtils.toHalfFloat(Math.min(e[t+1]*l,65504)),a[i+2]=c.DataUtils.toHalfFloat(Math.min(e[t+2]*l,65504)),a[i+3]=c.DataUtils.toHalfFloat(1)},S=new Uint8Array(n);S.pos=0;let D=N(S),H=D.width,T=D.height,b=k(S.subarray(S.pos),H,T),B,G,y;switch(this.type){case c.FloatType:y=b.length/4;let e=new Float32Array(y*4);for(let a=0;a<y;a++)U(b,a*4,e,a*4);B=e,G=c.FloatType;break;case c.HalfFloatType:y=b.length/4;let t=new Uint16Array(y*4);for(let a=0;a<y;a++)V(b,a*4,t,a*4);B=t,G=c.HalfFloatType;break;default:throw new Error("THREE.HDRLoader: Unsupported type: "+this.type)}return{width:H,height:T,data:B,header:D.string,gamma:D.gamma,exposure:D.exposure,type:G,colorSpace:c.LinearSRGBColorSpace,minFilter:c.LinearFilter,magFilter:c.LinearFilter,generateMipmaps:!1,flipY:!0}}setDataType(n){return this.type=n,this}};function j(h){let n=new u().parse(h),p=new m.DataTexture(n.data,n.width,n.height,m.RGBAFormat,n.type??m.HalfFloatType);return p.colorSpace=n.colorSpace??m.NoColorSpace,p.flipY=n.flipY??!0,p.generateMipmaps=n.generateMipmaps??!1,p.minFilter=n.minFilter??m.LinearFilter,p.magFilter=n.magFilter??m.LinearFilter,p.unpackAlignment=1,p.userData.dsh3dHdr=!0,p.needsUpdate=!0,p}
15
+ })(localRequire, module, module.exports);
16
+ return module.exports;
17
+ },
18
+ });
@@ -0,0 +1,14 @@
1
+ /*! dsh-3d-viewer tex-tga loader chunk | bundles Three.js addons (MIT). See THIRD_PARTY_NOTICES.md. */
2
+ window.__ModuleLoader__.load({
3
+ id: "dsh-3d-viewer",
4
+ chunk: "client.tex-tga.js",
5
+ factory(require) {
6
+ var localRequire = (id) => id === 'three' ? globalThis.__DSH3DV_THREE__ : require(id);
7
+ var module = { exports: {} };
8
+ var exports = module.exports;
9
+ (function (require, module, exports) {
10
+ var F=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var ee=Object.prototype.hasOwnProperty;var te=(h,_)=>{for(var G in _)F(h,G,{get:_[G],enumerable:!0})},re=(h,_,G,R)=>{if(_&&typeof _=="object"||typeof _=="function")for(let y of D(_))!ee.call(h,y)&&y!==G&&F(h,y,{get:()=>_[y],enumerable:!(R=$(_,y))||R.enumerable});return h};var oe=h=>re(F({},"__esModule",{value:!0}),h);var ie={};te(ie,{decodeTga:()=>ne});module.exports=oe(ie);var d=require("three");var k=require("three"),L=class extends k.DataTextureLoader{constructor(_){super(_)}parse(_){function G(e){switch(e.image_type){case H:case m:if(e.colormap_length>256||e.colormap_size!==24||e.colormap_type!==1)throw new Error("THREE.TGALoader: Invalid type colormap data for indexed type.");break;case Y:case g:case P:case U:if(e.colormap_type)throw new Error("THREE.TGALoader: Invalid type colormap data for colormap type.");break;case j:throw new Error("THREE.TGALoader: No data.");default:throw new Error("THREE.TGALoader: Invalid type "+e.image_type)}if(e.width<=0||e.height<=0)throw new Error("THREE.TGALoader: Invalid image size.");if(e.pixel_size!==8&&e.pixel_size!==16&&e.pixel_size!==24&&e.pixel_size!==32)throw new Error("THREE.TGALoader: Invalid pixel size "+e.pixel_size)}function R(e,u,p,l,E){let s,c,i=p.pixel_size>>3,n=p.width*p.height*i;if(u&&(c=E.subarray(l,l+=p.colormap_length*(p.colormap_size>>3))),e){s=new Uint8Array(n);let r,t,o,T=0,f=new Uint8Array(i);for(;T<n;)if(r=E[l++],t=(r&127)+1,r&128){for(o=0;o<i;++o)f[o]=E[l++];for(o=0;o<t;++o)s.set(f,T+o*i);T+=i*t}else{for(t*=i,o=0;o<t;++o)s[T+o]=E[l++];T+=t}}else s=E.subarray(l,l+=u?p.width*p.height:n);return{pixel_data:s,palettes:c}}function y(e,u,p,l,E,s,c,i,n){let r=n,t=w.colormap_index,o,T=0,f,A,b=w.width;for(A=u;A!==l;A+=p)for(f=E;f!==c;f+=s,T++)o=i[T]-t,e[(f+b*A)*4+3]=255,e[(f+b*A)*4+2]=r[o*3+0],e[(f+b*A)*4+1]=r[o*3+1],e[(f+b*A)*4+0]=r[o*3+2];return e}function M(e,u,p,l,E,s,c,i){let n,r=0,t,o,T=w.width;for(o=u;o!==l;o+=p)for(t=E;t!==c;t+=s,r+=2)n=i[r+0]+(i[r+1]<<8),e[(t+T*o)*4+0]=(n&31744)>>7,e[(t+T*o)*4+1]=(n&992)>>2,e[(t+T*o)*4+2]=(n&31)<<3,e[(t+T*o)*4+3]=n&32768?0:255;return e}function v(e,u,p,l,E,s,c,i){let n=0,r,t,o=w.width;for(t=u;t!==l;t+=p)for(r=E;r!==c;r+=s,n+=3)e[(r+o*t)*4+3]=255,e[(r+o*t)*4+2]=i[n+0],e[(r+o*t)*4+1]=i[n+1],e[(r+o*t)*4+0]=i[n+2];return e}function S(e,u,p,l,E,s,c,i){let n=0,r,t,o=w.width;for(t=u;t!==l;t+=p)for(r=E;r!==c;r+=s,n+=4)e[(r+o*t)*4+2]=i[n+0],e[(r+o*t)*4+1]=i[n+1],e[(r+o*t)*4+0]=i[n+2],e[(r+o*t)*4+3]=i[n+3];return e}function C(e,u,p,l,E,s,c,i){let n,r=0,t,o,T=w.width;for(o=u;o!==l;o+=p)for(t=E;t!==c;t+=s,r++)n=i[r],e[(t+T*o)*4+0]=n,e[(t+T*o)*4+1]=n,e[(t+T*o)*4+2]=n,e[(t+T*o)*4+3]=255;return e}function X(e,u,p,l,E,s,c,i){let n=0,r,t,o=w.width;for(t=u;t!==l;t+=p)for(r=E;r!==c;r+=s,n+=2)e[(r+o*t)*4+0]=i[n+0],e[(r+o*t)*4+1]=i[n+0],e[(r+o*t)*4+2]=i[n+0],e[(r+o*t)*4+3]=i[n+1];return e}function K(e,u,p,l,E){let s,c,i,n,r,t;switch((w.flags&q)>>J){default:case W:s=0,i=1,r=u,c=0,n=1,t=p;break;case Q:s=0,i=1,r=u,c=p-1,n=-1,t=-1;break;case Z:s=u-1,i=-1,r=-1,c=0,n=1,t=p;break;case V:s=u-1,i=-1,r=-1,c=p-1,n=-1,t=-1;break}if(N)switch(w.pixel_size){case 8:C(e,c,n,t,s,i,r,l);break;case 16:X(e,c,n,t,s,i,r,l);break;default:throw new Error("THREE.TGALoader: Format not supported.")}else switch(w.pixel_size){case 8:y(e,c,n,t,s,i,r,l,E);break;case 16:M(e,c,n,t,s,i,r,l);break;case 24:v(e,c,n,t,s,i,r,l);break;case 32:S(e,c,n,t,s,i,r,l);break;default:throw new Error("THREE.TGALoader: Format not supported.")}return e}let j=0,H=1,Y=2,g=3,m=9,P=10,U=11,q=48,J=4,Q=0,V=1,W=2,Z=3;if(_.length<19)throw new Error("THREE.TGALoader: Not enough data to contain header.");let a=0,x=new Uint8Array(_),w={id_length:x[a++],colormap_type:x[a++],image_type:x[a++],colormap_index:x[a++]|x[a++]<<8,colormap_length:x[a++]|x[a++]<<8,colormap_size:x[a++],origin:[x[a++]|x[a++]<<8,x[a++]|x[a++]<<8],width:x[a++]|x[a++]<<8,height:x[a++]|x[a++]<<8,pixel_size:x[a++],flags:x[a++]};if(G(w),w.id_length+a>_.length)throw new Error("THREE.TGALoader: No data.");a+=w.id_length;let I=!1,z=!1,N=!1;switch(w.image_type){case m:I=!0,z=!0;break;case H:z=!0;break;case P:I=!0;break;case Y:break;case U:I=!0,N=!0;break;case g:N=!0;break}let B=new Uint8Array(w.width*w.height*4),O=R(I,z,w,a,x);return K(B,w.width,w.height,O.pixel_data,O.palettes),{data:B,width:w.width,height:w.height,flipY:!0,generateMipmaps:!0,minFilter:k.LinearMipmapLinearFilter}}};function ne(h){let _=new L().parse(h),G=new d.DataTexture(_.data,_.width,_.height,d.RGBAFormat,d.UnsignedByteType);return G.colorSpace=d.NoColorSpace,G.flipY=_.flipY??!0,G.generateMipmaps=_.generateMipmaps??!0,G.minFilter=_.minFilter??d.LinearMipmapLinearFilter,G.magFilter=d.LinearFilter,G.needsUpdate=!0,G}
11
+ })(localRequire, module, module.exports);
12
+ return module.exports;
13
+ },
14
+ });
package/index.js CHANGED
@@ -1,7 +1,167 @@
1
- /**
2
- * Host half of the 3D viewer bundle.
3
- *
4
- * The viewer is entirely browser-side: it extends the right Sidebar's
5
- * document-preview registry, so it registers nothing in the Host tree.
6
- */
7
- export function apply() {}
1
+ /**
2
+ * Host half of the 3D viewer bundle.
3
+ *
4
+ * The viewer itself runs in the browser, but its four HDRI environments are
5
+ * packaged as `.hdr` files instead of base64 inside the client bundle: a web
6
+ * page has no URL for a file inside an installed plugin package. This half
7
+ * registers one read-only route that serves those files from the package the
8
+ * host already loaded, so the browser can fetch them like any other asset.
9
+ *
10
+ * The route is public by design. The HDRIs are CC0 images, the route answers
11
+ * only GET/HEAD, and it maps a fixed whitelist of names to files — it never
12
+ * accepts a caller-chosen path, so there is nothing to traverse and nothing
13
+ * secret to leak. This mirrors how other Host plugins serve their own assets.
14
+ */
15
+ import { readFile } from 'node:fs/promises';
16
+
17
+ /**
18
+ * Route prefix registered with the host web server.
19
+ *
20
+ * No trailing slash: `webServer.match` accepts a prefix only when the request
21
+ * pathname equals it or starts with `${prefix}/`. A registered `/hdri/` would
22
+ * therefore never match `/hdri/nature.hdr`.
23
+ */
24
+ export const HDRI_ROUTE = '/dsh-3d-viewer/hdri';
25
+
26
+ /** Request prefix, with the slash the route matcher expects after the prefix. */
27
+ const HDRI_PREFIX = `${HDRI_ROUTE}/`;
28
+
29
+ /** Environment id to packaged file name. Mirrors `ENVIRONMENT_IDS` client-side. */
30
+ const HDRI_FILES = Object.freeze({
31
+ nature: 'nature.hdr',
32
+ city: 'city.hdr',
33
+ indoor: 'indoor.hdr',
34
+ studio: 'studio.hdr',
35
+ });
36
+
37
+ /** Request name (`<id>.hdr`) to packaged file name. */
38
+ const HDRI_PATHS = new Map(
39
+ Object.entries(HDRI_FILES).map(([id, file]) => [`${id}.hdr`, file]),
40
+ );
41
+
42
+ const HDRI_TYPE = 'image/vnd.radiance';
43
+ // The client appends `?v=<package version>`, so a long immutable lifetime is
44
+ // safe: an upgrade changes the URL instead of reusing a stale cached response.
45
+ const HDRI_CACHE_CONTROL = 'public, max-age=31536000, immutable';
46
+
47
+ /**
48
+ * Packaged HDRIs read once per host process.
49
+ *
50
+ * The files belong to an installed (immutable) package, so caching decoded
51
+ * query results is safe; a rebuilt package restarts the host.
52
+ *
53
+ * @type {Map<string, Promise<Buffer>>}
54
+ */
55
+ const fileCache = new Map();
56
+
57
+ /**
58
+ * Read one packaged HDRI, reusing an earlier read.
59
+ *
60
+ * @param {string} file Packaged file name.
61
+ * @returns {Promise<Buffer>} File contents.
62
+ */
63
+ function readHdriFile(file) {
64
+ const cached = fileCache.get(file);
65
+ if (cached !== undefined) return cached;
66
+
67
+ const task = readFile(new URL(`./assets/hdri/${file}`, import.meta.url));
68
+ task.catch(() => fileCache.delete(file));
69
+ fileCache.set(file, task);
70
+ return task;
71
+ }
72
+
73
+ /**
74
+ * Answer one request with a short plain-text response.
75
+ *
76
+ * @param {import('node:http').ServerResponse} response Response to finish.
77
+ * @param {number} status HTTP status.
78
+ * @param {string} message Body text.
79
+ * @param {Record<string, string | number>} [headers] Extra headers.
80
+ * @param {boolean} [headOnly] Omit the body for a HEAD request.
81
+ */
82
+ function sendText(response, status, message, headers = {}, headOnly = false) {
83
+ response.writeHead(status, {
84
+ 'content-type': 'text/plain; charset=utf-8',
85
+ 'content-length': Buffer.byteLength(message),
86
+ ...headers,
87
+ });
88
+ response.end(headOnly ? undefined : message);
89
+ }
90
+
91
+ /**
92
+ * Create the read-only route that serves the packaged HDRIs.
93
+ *
94
+ * @returns {{
95
+ * kind: 'prefix',
96
+ * path: string,
97
+ * handler: (request: import('node:http').IncomingMessage, response: import('node:http').ServerResponse) => Promise<void>,
98
+ * }} A WebRoute for the host `webServer` service.
99
+ */
100
+ export function createHdriRoute() {
101
+ return {
102
+ kind: 'prefix',
103
+ path: HDRI_ROUTE,
104
+
105
+ async handler(request, response) {
106
+ if (request.method !== 'GET' && request.method !== 'HEAD') {
107
+ sendText(response, 405, 'Method not allowed', { allow: 'GET, HEAD' });
108
+ return;
109
+ }
110
+
111
+ const headOnly = request.method === 'HEAD';
112
+ let pathname;
113
+ try {
114
+ pathname = new URL(request.url ?? '', 'http://localhost').pathname;
115
+ } catch {
116
+ sendText(response, 400, 'Malformed request URL', {}, headOnly);
117
+ return;
118
+ }
119
+
120
+ // Only the exact `<id>.hdr` names in the whitelist resolve. Percent
121
+ // escapes are never decoded, so `..%2fpackage.json` stays a miss.
122
+ const name = pathname.startsWith(HDRI_PREFIX) ? pathname.slice(HDRI_PREFIX.length) : '';
123
+ const file = HDRI_PATHS.get(name);
124
+ if (file === undefined) {
125
+ sendText(response, 404, 'Unknown HDRI', {}, headOnly);
126
+ return;
127
+ }
128
+
129
+ let body;
130
+ try {
131
+ body = await readHdriFile(file);
132
+ } catch (error) {
133
+ console.warn(`[dsh-3d-viewer] Could not read the packaged HDRI "${file}".`, error);
134
+ sendText(response, 500, 'The packaged HDRI could not be read', {}, headOnly);
135
+ return;
136
+ }
137
+
138
+ response.writeHead(200, {
139
+ 'content-type': HDRI_TYPE,
140
+ 'content-length': body.length,
141
+ 'cache-control': HDRI_CACHE_CONTROL,
142
+ });
143
+ if (headOnly) response.end();
144
+ else response.end(body);
145
+ },
146
+ };
147
+ }
148
+
149
+ /**
150
+ * Register the HDRI route once the composition provides a web server.
151
+ *
152
+ * The service is acquired through `ctx.inject`, not `ctx.get`: a Host plugin
153
+ * applies before sibling rows finish loading, so a direct probe can run while
154
+ * `webServer` is still absent. `inject` keeps the callback dormant until the
155
+ * service exists and disposes the route with the plugin. A non-web runtime has
156
+ * no `webServer`, and this half never registers anything there.
157
+ *
158
+ * @param {import('@deepseek-ai/cordis').Context} ctx Owning Host context.
159
+ */
160
+ export function apply(ctx) {
161
+ ctx.inject(['webServer'], (hostCtx) => {
162
+ hostCtx.effect(
163
+ () => hostCtx.webServer.register(createHdriRoute()),
164
+ 'dsh-3d-viewer: HDRI route',
165
+ );
166
+ });
167
+ }
package/package.json CHANGED
@@ -1,48 +1,72 @@
1
- {
2
- "name": "dsh-3d-viewer",
3
- "version": "0.1.0",
4
- "description": "Render FBX, OBJ, glTF, GLB, and STL models from the right Sidebar's workspace file tree in an orbitable 3D view.",
5
- "type": "module",
6
- "icon": "./icon.svg",
7
- "exports": {
8
- ".": "./index.js",
9
- "./client": "./client.js",
10
- "./locale/*.json": "./locale/*.json",
11
- "./icon": "./icon.svg",
12
- "./package.json": "./package.json"
13
- },
14
- "files": [
15
- "client.js",
16
- "index.js",
17
- "cordis.patch.yml",
18
- "locale/*.json",
19
- "README.md",
20
- "README.zh.md",
21
- "LICENSE",
22
- "THIRD_PARTY_NOTICES.md",
23
- "icon.svg",
24
- "src",
25
- "assets",
26
- "scripts",
27
- "build.mjs"
28
- ],
29
- "dsh": {
30
- "bundle": {
31
- "patch": "./cordis.patch.yml"
32
- },
33
- "client": {
34
- "platform": "web",
35
- "immediately": true,
36
- "inject": [
37
- "@deepseek-ai/dsh-client-ui-sidebar-right",
38
- "@deepseek-ai/dsh-client-ui-sidebar-documentpreview"
39
- ]
40
- }
41
- },
42
- "scripts": {
43
- "build": "node build.mjs",
44
- "embed:hdri": "node scripts/embed-hdri.mjs --force",
45
- "test": "node tests/run.mjs"
46
- },
47
- "license": "MIT"
48
- }
1
+ {
2
+ "name": "dsh-3d-viewer",
3
+ "version": "0.2.0",
4
+ "description": "Render FBX, OBJ, glTF, GLB, and STL models plus TGA, EXR, and HDR textures from the right Sidebar's workspace file tree in an orbitable view.",
5
+ "keywords": [
6
+ "dsh",
7
+ "dsh-plugin",
8
+ "deepseek-harness",
9
+ "3d-viewer",
10
+ "texture",
11
+ "tga",
12
+ "exr",
13
+ "hdr"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/ybniaobu/dsh-3d-viewer.git"
18
+ },
19
+ "homepage": "https://github.com/ybniaobu/dsh-3d-viewer#readme",
20
+ "bugs": {
21
+ "url": "https://github.com/ybniaobu/dsh-3d-viewer/issues"
22
+ },
23
+ "type": "module",
24
+ "icon": "./icon.svg",
25
+ "exports": {
26
+ ".": "./index.js",
27
+ "./client": "./dist/client.js",
28
+ "./locale/*.json": "./locale/*.json",
29
+ "./icon": "./icon.svg",
30
+ "./package.json": "./package.json"
31
+ },
32
+ "files": [
33
+ "dist/client.js",
34
+ "dist/client.*.js",
35
+ "index.js",
36
+ "cordis.patch.yml",
37
+ "locale/*.json",
38
+ "README.md",
39
+ "README.zh.md",
40
+ "LICENSE",
41
+ "THIRD_PARTY_NOTICES.md",
42
+ "icon.svg",
43
+ "assets/hdri"
44
+ ],
45
+ "dsh": {
46
+ "bundle": {
47
+ "patch": "./cordis.patch.yml"
48
+ },
49
+ "client": {
50
+ "platform": "web",
51
+ "immediately": true,
52
+ "inject": [
53
+ "@deepseek-ai/dsh-client-ui-sidebar-right",
54
+ "@deepseek-ai/dsh-client-ui-sidebar-documentpreview"
55
+ ]
56
+ }
57
+ },
58
+ "scripts": {
59
+ "build": "node build.mjs",
60
+ "test": "node tests/run.mjs"
61
+ },
62
+ "devDependencies": {
63
+ "esbuild": "^0.28.2",
64
+ "react": "^18.3.1",
65
+ "react-dom": "^18.3.1",
66
+ "three": "^0.187.0"
67
+ },
68
+ "engines": {
69
+ "dsh": ">=0.2.2-rc.1"
70
+ },
71
+ "license": "MIT"
72
+ }
Binary file
package/build.mjs DELETED
@@ -1,49 +0,0 @@
1
- import { spawnSync } from 'node:child_process';
2
- import { mkdir, readFile, writeFile } from 'node:fs/promises';
3
- import { dirname, resolve } from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
- import { embedHdri } from './scripts/embed-hdri.mjs';
6
-
7
- const root = dirname(fileURLToPath(import.meta.url));
8
- const pkg = JSON.parse(await readFile(resolve(root, 'package.json'), 'utf8'));
9
- const esbuildBin = resolve(root, 'node_modules/esbuild/bin/esbuild');
10
- const bundlePath = resolve(root, '.build/client.bundle.cjs');
11
-
12
- await embedHdri();
13
- await mkdir(dirname(bundlePath), { recursive: true });
14
-
15
- const result = spawnSync(process.execPath, [
16
- esbuildBin,
17
- resolve(root, 'src/client.js'),
18
- '--bundle',
19
- '--format=cjs',
20
- '--platform=browser',
21
- '--target=chrome120,edge120',
22
- '--external:react',
23
- '--minify',
24
- '--legal-comments=none',
25
- '--log-level=warning',
26
- `--outfile=${bundlePath}`,
27
- ], {
28
- cwd: root,
29
- stdio: 'inherit',
30
- });
31
-
32
- if (result.error !== undefined) throw result.error;
33
- if (result.status !== 0) process.exit(result.status ?? 1);
34
-
35
- const code = (await readFile(bundlePath, 'utf8')).trimEnd();
36
- const wrapped = `/*! dsh-3d-viewer | bundles Three.js (MIT), FBXLoader, OBJLoader, MTLLoader, GLTFLoader, STLLoader, OrbitControls and HDRLoader (MIT), plus embedded Poly Haven CC0 HDRIs. See THIRD_PARTY_NOTICES.md for third-party licenses. */
37
- window.__ModuleLoader__.load({
38
- id: ${JSON.stringify(pkg.name)},
39
- factory(require) {
40
- var module = { exports: {} };
41
- var exports = module.exports;
42
- ${code}
43
- return module.exports;
44
- },
45
- });
46
- `;
47
-
48
- await writeFile(resolve(root, 'client.js'), wrapped);
49
- console.log(`Built client.js (${Buffer.byteLength(wrapped)} bytes) for ${pkg.name}.`);