// Lossless Draco unpacking through the same vendored Google decoder as PlayCanvas. // No reconstruction, simplification or frame change is performed here. const fs = require('node:fs'); const path = require('node:path'); const vendor = path.resolve(__dirname, '../../apps/control-station/public/vendor/playcanvas/draco/1.5.7'); const vm = require('node:vm'); const decoderModule = {exports:{}}; vm.runInNewContext(fs.readFileSync(path.join(vendor,'draco_wasm_wrapper_gltf.js'),'utf8'), {module:decoderModule,exports:decoderModule.exports,require,process,Buffer,console, __dirname:vendor,__filename:path.join(vendor,'draco_wasm_wrapper_gltf.js')}); const factory = decoderModule.exports; async function main() { const input=fs.readFileSync(process.argv[2]); if(input.readUInt32LE(0)!==0x46546c67 || input.readUInt32LE(4)!==2 || input.readUInt32LE(8)!==input.length) throw Error('Invalid GLB'); let document, binary; for(let o=12;on.matrix||n.translation||n.rotation||n.scale))throw Error('Unbaked collider transform'); const module=await factory({wasmBinary:fs.readFileSync(path.join(vendor,'draco_decoder_gltf.wasm'))}); const decoder=new module.Decoder(), chunks=[],views=[],accessors=[],meshes=[];let offset=0; function append(values,type,componentType) { const bytes=Buffer.from(values.buffer,values.byteOffset,values.byteLength); const index=accessors.length; accessors.push({bufferView:views.length,componentType,count:values.length/(type==='VEC3'?3:1),type}); views.push({buffer:0,byteOffset:offset,byteLength:bytes.length});chunks.push(bytes);offset+=bytes.length; return index; } function raw(index) { const a=document.accessors[index],v=document.bufferViews[a.bufferView]; const C=a.componentType===5126?Float32Array:a.componentType===5125?Uint32Array:Uint16Array; const width=a.type==='VEC3'?3:1,out=new C(a.count*width), stride=v.byteStride||C.BYTES_PER_ELEMENT*width; for(let i=0;ii)}],nodes:meshes.map((_,i)=>({mesh:i})),meshes,accessors,bufferViews:views,buffers:[{byteLength:offset}]}; const json=Buffer.from(JSON.stringify(output));const padding=Buffer.alloc((4-json.length%4)%4,32),body=Buffer.concat(chunks); const header=Buffer.alloc(20);header.writeUInt32LE(0x46546c67);header.writeUInt32LE(2,4);header.writeUInt32LE(28+json.length+padding.length+body.length,8);header.writeUInt32LE(json.length+padding.length,12);header.writeUInt32LE(0x4e4f534a,16); const binaryHeader=Buffer.alloc(8);binaryHeader.writeUInt32LE(body.length);binaryHeader.writeUInt32LE(0x004e4942,4); fs.writeFileSync(process.argv[3],Buffer.concat([header,json,padding,binaryHeader,body])); } main().catch(e=>{console.error(e.message);process.exitCode=1;});