@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.25 kB
JavaScript
import {MetadataError,BinaryPropertyTables,BinaryBuffers,MetadataUtilities}from'3d-tiles-tools';class i{constructor(t,e,r){this.arrayOffsetType="UINT32";this.stringOffsetType="UINT32";this.propertyTableProperties={};this.createdBufferViewsData=[];if(this.schema=t,this.propertyTableClass=e,this.propertyTableName=r,this.count=void 0,!(t.classes||{})[e])throw new MetadataError(`The schema does not contain class ${e}`)}static create(t,e,r){return new i(t,e,r)}addProperty(t,e){const r=this.getClassProperty(t);if(this.count===void 0)this.count=e.length;else if(this.count!==e.length)throw new MetadataError(`Expected ${this.count} property values, but got ${e.length}`);const a=BinaryPropertyTables.createPropertyTableProperty(r,this.schema,e,this.arrayOffsetType,this.stringOffsetType,this.createdBufferViewsData);return this.propertyTableProperties[t]=a,this}addProperties(t){const e=this.getClassPropertyNames();for(const r of e){const a=t[r];a&&this.addProperty(r,a);}return this}build(){if(this.count===void 0)throw new MetadataError('No properties have been added"');const t=this.getClassPropertyNames();for(const n of t)if(!this.propertyTableProperties[n])throw new MetadataError(`No values have been given for property ${n}`);const e={name:this.propertyTableName,class:this.propertyTableClass,count:this.count,properties:this.propertyTableProperties},r={bufferViewsData:[],buffersData:[]},a=BinaryBuffers.createBinaryBufferStructure(r,this.createdBufferViewsData),o=MetadataUtilities.computeBinaryEnumInfo(this.schema),p={metadataClass:this.getClass(),binaryEnumInfo:o,binaryBufferStructure:a,binaryBufferData:r};return {propertyTable:e,binaryMetadata:p}}getClass(){const e=(this.schema.classes||{})[this.propertyTableClass];if(!e)throw new MetadataError(`The schema does not contain class ${this.propertyTableClass}`);return e}getClassPropertyNames(){const e=this.getClass().properties||{};return Object.keys(e)}getClassProperty(t){const a=(this.getClass().properties||{})[t];if(!a)throw new MetadataError(`The class ${this.propertyTableClass} does not contain property ${t}`);return a}}export{i as BinaryPropertyTableBuilder};//# sourceMappingURL=BinaryPropertyTableBuilder.js.map
//# sourceMappingURL=BinaryPropertyTableBuilder.js.map