| 123456789101112131415161718 |
- // Per-content region metadata for public Cesium feature.show masking.
- import assert from 'node:assert/strict'
- import {parseGlb,packGlb} from './instance-repeated-meshes.mjs'
- export function addRegionMetadata(bytes,region){
- const {json,bin}=parseGlb(bytes);assert.ok(Number.isInteger(region)&®ion>=0&®ion<65536)
- const chunks=[bin];let offset=bin.length
- function append(data){const pad=(-offset)&3;if(pad){chunks.push(Buffer.alloc(pad));offset+=pad}const view=json.bufferViews.length;json.bufferViews.push({buffer:0,byteOffset:offset,byteLength:data.length});chunks.push(data);offset+=data.length;return view}
- const value=Buffer.alloc(2);value.writeUInt16LE(region);const view=append(value)
- const schema={id:'city-building-regions',classes:{BuildingRegion:{properties:{region:{type:'SCALAR',componentType:'UINT16'}}}}}
- json.extensions={...(json.extensions||{}),EXT_structural_metadata:{schema,propertyTables:[{class:'BuildingRegion',count:1,properties:{region:{values:view}}}]}}
- for(const mesh of json.meshes)for(const p of mesh.primitives){const count=json.accessors[p.attributes.POSITION].count,index=json.accessors.length
- json.accessors.push({bufferView:append(Buffer.alloc(count*4)),componentType:5125,type:'SCALAR',count,min:[0],max:[0]})
- p.attributes._FEATURE_ID_0=index
- p.extensions={...(p.extensions||{}),EXT_mesh_features:{featureIds:[{featureCount:1,attribute:0,propertyTable:0}]}}
- }
- json.extensionsUsed=[...new Set([...(json.extensionsUsed||[]),'EXT_mesh_features','EXT_structural_metadata'])]
- json.buffers=[{byteLength:offset}];return packGlb(json,Buffer.concat(chunks))
- }
|