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 • 2.19 kB
import {Vector3,Quaternion,Matrix4,Box3}from'three';import*as w from'earcut';import P from'proj4';import g from'proj4-list';const b="+proj=longlat +datum=WGS84 +no_defs +type=crs",j="+proj=geocent +datum=WGS84 +units=m +no_defs +type=crs",z=P(j,b);function B(t){let e=[0,0,0];for(let o=0;o<t.length;o++){let n=o+1;n==t.length&&(n=0),e[0]=e[0]+(t[o].y-t[n].y)*(t[o].z+t[n].z),e[1]=e[1]+(t[o].z-t[n].z)*(t[o].x+t[n].x),e[2]=e[2]+(t[o].x-t[n].x)*(t[o].y+t[n].y);}return new Vector3(e[0],e[1],e[2]).normalize()}function M(t,e){const r=[];for(const s of t)r.push(new Vector3(...s));const o=[];for(const s of e)o.push(new Vector3(...s));const n=r.concat(o),i=B(n),m=new Quaternion().setFromUnitVectors(i,new Vector3(0,0,1)),l=new Matrix4().makeRotationFromQuaternion(m);return {projected:r.map(s=>s.clone().applyMatrix4(l)),matrix:l}}function D(t){if(!t||t.length===0)return null;const e=t;let r=e[0];if(r.length===0)return null;const o=M(r,e.slice(1).flat()),n=o.projected.flatMap(a=>[a.x,a.y]),i=[];let m=e[0].length;const l=[];for(let a=1;a<e.length;a++){let h=e[a];if(h.length===0)continue;l.push(m),m+=h.length,h.map(c=>c.length<3?new Vector3(c[0],c[1],0):new Vector3(c[0],c[1],c[2])).forEach(c=>{c.applyMatrix4(o.matrix),i.push(c.x,c.y);});}const f=n.concat(i);return w.default(f,l,2)}function I(t,e){const r=new Box3,o=new Box3;for(const n of t)for(let i=0;i<n.position.length;){const[m,l,f]=[n.position[i++]+e.x,n.position[i++]+e.z,n.position[i++]-e.y],s=[m,-f,l],[a,h,p]=z.forward(s);r.expandByPoint(new Vector3(m,l,f)),o.expandByPoint(new Vector3(a/180*Math.PI,h/180*Math.PI,p));}return {cartesianBox:r,cartographicBox:o}}function k(t){if(!t)return null;let e;try{e=t.split(",").filter(r=>r.includes("EPSG")).map(r=>r.split(":").pop())[0];}catch{}try{e=t.split("/").slice(-1)[0];}catch{}if(!e)throw new Error("Could not parse EPSG code please provide a valid one!");if(!g[`EPSG:${e}`]?.[1])throw new Error(`Did not find "${e}" in epsg list!`);return g[`EPSG:${e}`][1]}export{k as convertEPSGFromCityJSONToProj4,I as getBBoxesFromMeshes,B as getNewellsNormal,M as projectPolygonToPlane,D as triangulate3DPolygon};//# sourceMappingURL=helpers.js.map //# sourceMappingURL=helpers.js.map