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.26 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 E(o){let e=[0,0,0];for(let t=0;t<o.length;t++){let n=t+1;n==o.length&&(n=0),e[0]=e[0]+(o[t].y-o[n].y)*(o[t].z+o[n].z),e[1]=e[1]+(o[t].z-o[n].z)*(o[t].x+o[n].x),e[2]=e[2]+(o[t].x-o[n].x)*(o[t].y+o[n].y);}return new Vector3(e[0],e[1],e[2]).normalize()}function S(o,e){const r=[];for(const l of o)r.push(new Vector3(...l));const t=[];for(const l of e)t.push(new Vector3(...l));const n=r.concat(t),i=E(n),m=new Quaternion().setFromUnitVectors(i,new Vector3(0,0,1)),s=new Matrix4().makeRotationFromQuaternion(m);return {projected:r.map(l=>l.clone().applyMatrix4(s)),matrix:s}}function v(o){if(!o||o.length===0)return null;const e=o;let r=e[0];if(r.length===0)return null;const t=S(r,e.slice(1).flat()),n=t.projected.flatMap(a=>[a.x,a.y]),i=[];let m=e[0].length;const s=[];for(let a=1;a<e.length;a++){let h=e[a];if(h.length===0)continue;s.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(t.matrix),i.push(c.x,c.y);});}const f=n.concat(i);return w.default(f,s,2)}function D(o,e){const r=new Box3,t=new Box3;for(const n of o)for(let i=0;i<n.position.length;){const[m,s,f]=[n.position[i++]+e.x,n.position[i++]+e.z,n.position[i++]-e.y],l=[m,-f,s],[a,h,p]=z.forward(l);r.expandByPoint(new Vector3(m,s,f)),t.expandByPoint(new Vector3(a/180*Math.PI,h/180*Math.PI,p));}return {cartesianBox:r,cartographicBox:t}}function I(o){if(!o)throw new Error("Source coordinate system is undefined, please provice an EPSG code!");let e;try{e=o.split(",").filter(r=>r.includes("EPSG")).map(r=>r.split(":").pop())[0];}catch{}try{e=o.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{I as convertEPSGFromCityJSONToProj4,D as getBBoxesFromMeshes,E as getNewellsNormal,S as projectPolygonToPlane,v as triangulate3DPolygon};//# sourceMappingURL=helpers.js.map //# sourceMappingURL=helpers.js.map