UNPKG

@csi-foxbyte/cityjson-to-3d-tiles

Version:

A Node.js library that converts CityJSON files into Cesium 3D Tiles—complete with automatic texture atlas packing, Basis compression, three LOD levels, and customizable threading.

2 lines • 1.07 kB
import {Primitive}from'@gltf-transform/core';import I from'sharp';async function T(M,r=8){if(r<=0)throw new Error("Padding must be larger than 0!");for(const u of M.getRoot().listMaterials()){const v=u.listParents().filter(e=>e instanceof Primitive);if(!u)continue;const h=u.getBaseColorTexture();if(!h)continue;const g=h.getImage();if(!g)continue;const x=I(g),{width:i,height:a,channels:s,format:y}=await x.metadata();if(!i||!a||!s||!y)continue;const B=await x.raw().toBuffer(),c=i+2*r,f=a+2*r,A=new Uint8Array(c*f*s);for(let e=0;e<f;e++)for(let o=0;o<c;o++){const t=Math.min(i-1,Math.max(0,o-r)),l=(Math.min(a-1,Math.max(0,e-r))*i+t)*s,w=(e*c+o)*s;for(let m=0;m<s;m++)A[w+m]=B[l+m];}for(const e of v){const o=e.getAttribute("TEXCOORD_0");if(!o)continue;const t=o.getArray();if(t){for(let n=0;n<t.length;n+=2){const l=t[n]*i+r,w=t[n+1]*a+r;t[n]=l/c,t[n+1]=w/f;}o.setArray(t);}}h.setImage(await I(A,{raw:{width:c,height:f,channels:s}}).toFormat(y).toBuffer());}}export{T as padTextures};//# sourceMappingURL=padTextures.js.map //# sourceMappingURL=padTextures.js.map