@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.07 kB
JavaScript
import {EXTMeshFeatures}from'../EXTMeshFeatures/EXTMeshFeatures.js';import {EXTStructuralMetadata}from'../EXTMeshFeatures/EXTStructuralMetadata.js';import {StructuralMetadataPropertyTables}from'../EXTMeshFeatures/StructuralMetadataPropertyTables.js';import {BinaryPropertyTableBuilder}from'../EXTMeshFeatures/BinaryPropertyTableBuilder.js';function g(r,i=""){const a={};for(const o in r){const s=r[o],n=i?`${i}.${o}`:o;if(typeof s=="object"&&s!==null){const f=g(s,n);Object.assign(a,f);}else a[n]=s;}return a}async function N(r,i,a){const o=r.getRoot(),s=a.map(t=>g(t)),n=r.createExtension(EXTMeshFeatures),f=r.getRoot().listBuffers()[0],l=[];for(const t of o.listScenes())t.traverse(e=>{const c=e.getMesh();c&&l.push(...c.listPrimitives());});const m=r.createExtension(EXTStructuralMetadata),p={id:"schema_01",name:"Schema 01",description:"An example schema",version:"1.0.0",enums:{},classes:{tree:{name:"Tree",description:"Jo",properties:{id:{name:"ID",type:"STRING"}}}}},y=new Set;for(const t of s)for(const e of Object.keys(t))p.classes.tree.properties[e]={name:e,type:"STRING"},y.add(e);const u={};for(const t of s)for(const e of y.values())u[e]||(u[e]=[]),u[e].push(String(t[e]??"-"));const A=BinaryPropertyTableBuilder.create(p,"tree","Property Table").addProperty("id",i).addProperties(u).build(),d=StructuralMetadataPropertyTables.create(m,A),S=m.createStructuralMetadata().addPropertyTable(d).setSchema(m.createSchemaFrom(p));o.setExtension("EXT_structural_metadata",S);for(const t of l){const e=t,c=e.getAttribute("TEXCOORD_1"),b=c?.getArray();if(!b)continue;const R=b,E=r.createAccessor().setType("SCALAR").setBuffer(f).setNormalized(false).setArray(new Int16Array(R)),T=0;e.setAttribute(`_FEATURE_ID_${T}`,E);const P=n.createFeatureId().setFeatureCount(d.getCount()).setPropertyTable(d).setAttribute(T),h=n.createMeshFeatures();h.addFeatureId(P),e.setExtension("EXT_mesh_features",h),e.setAttribute("TEXCOORD_1",null),c?.dispose();}}export{N as assignFeatureIds};//# sourceMappingURL=assignFeaturesIds.js.map
//# sourceMappingURL=assignFeaturesIds.js.map