| 1234567 |
- import draco3d from 'draco3d'
- const e=await draco3d.createEncoderModule({}),d=await draco3d.createDecoderModule({})
- const builder=new e.MeshBuilder(),mesh=new e.Mesh(),encoder=new e.Encoder(),out=new e.DracoInt8Array()
- builder.AddFloatAttributeToMesh(mesh,e.POSITION,4,3,new Float32Array([0,0,0,1,0,0,0,1,0,100,100,100]));builder.AddFacesToMesh(mesh,1,new Uint32Array([0,1,2]));encoder.SetAttributeQuantization(e.POSITION,20)
- const size=encoder.EncodeMeshToDracoBuffer(mesh,out),buf=Int8Array.from({length:size},(_,i)=>out.GetValue(i))
- const dec=new d.Decoder(),dm=new d.Mesh(),db=new d.DecoderBuffer();db.Init(buf,size);const status=dec.DecodeBufferToMesh(db,dm)
- console.log({ok:status.ok(),points:dm.num_points(),faces:dm.num_faces()})
|