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 {Vector3}from'three';import {getIO}from'./io.js';async function y(r){const w=r.getRoot(),D=await getIO();for(const p of w.listScenes()){const s=[];p.traverse(t=>s.push(t));for(const t of s){const E=t.getMesh();if(!E)return;for(const m of E.listPrimitives()){const e=m.getAttribute("POSITION")?.getArray(),o=m.getIndices()?.getArray();if(!(!e||!o))for(let n=0;n<o.length;){const c=o[n++]*3,i=new Vector3(e[c],e[c+1],e[c+2]),g=o[n++]*3,l=new Vector3(e[g],e[g+1],e[g+2]),f=o[n++]*3,h=new Vector3(e[f],e[f+1],e[f+2]),d=i.clone().sub(l).length(),u=i.clone().sub(h).length(),A=l.clone().sub(h).length();if(d>500||A>500||u>500){console.error({lengthAB:d,lengthAC:u,lengthBC:A}),console.log({vertexA:i,vertexB:l,vertexC:h,positionAttribute:e}),t.setName("DEGENERATE!!!");const v=r.getRoot().getDefaultScene();for(const x of s.filter(N=>N!==t))v?.removeChild(x);throw await D.write("degenerate.glb",r),new Error("DEGENERATE DETECTED!")}}}}}}export{y as checkForDegenerates};//# sourceMappingURL=checkForDegenerates.js.map //# sourceMappingURL=checkForDegenerates.js.map