@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.19 kB
JavaScript
import {Box3,Vector3}from'three';function z(){return h=>{let n=new Box3;const p=[0,0,0],l=[0,0,0],m=new Vector3;for(const g of h.getRoot().listMeshes())for(const s of g.listPrimitives()){const e=s.getAttribute("POSITION");e&&(e.getMin(p),e.getMax(l),m.fromArray(p),n.expandByPoint(m),m.fromArray(l),n.expandByPoint(m));}const i=new Vector3;n.getSize(i);const r=64;for(const g of h.getRoot().listMeshes())for(const s of g.listPrimitives()){const e=new Map,b=s.getAttribute("POSITION");if(!b)continue;const o=b.getArray();if(!o)continue;for(let t=0;t<o.length;t+=3){const c=Math.round((o[t]-n.min.x)/i.x*r);o[t]=c/r*i.x+n.min.x;const a=Math.round((o[t+1]-n.min.y)/i.y*r);o[t+1]=a/r*i.y+n.min.y;const f=Math.round((o[t+2]-n.min.z)/i.z*r),A=`${c}_${a}_${f}`,d=e.get(A)??[];d.push(t/3),e.set(A,d);}const y=new Set(Array.from(e.values()).filter(t=>t.length>1).flatMap(t=>t.slice(1))),u=s.getIndices().getArray(),x=new Array;for(let t=0;t<u.length;t+=3){const c=u[t+0],a=u[t+1],f=u[t+2];y.has(c)&&y.has(a)&&y.has(f)||x.push(c,a,f);}s.getIndices().setArray(new Uint16Array(x));}}}export{z as quantizePositions};//# sourceMappingURL=quantizePositions.js.map
//# sourceMappingURL=quantizePositions.js.map