sched.add("render",(w:any)=>{for(const{e,c1:pos,c2:rend}ofw.query(Position,Renderable)){letobj=meshes.get(e.id);if(!obj){obj=makeObjectFromKind(rend.kind);// your factoryscene.add(obj);meshes.set(e.id,obj);}obj.position.set(pos.x,pos.y,pos.z);}});
Despawn visually after flush:
despawn in ECS via cmd().despawn(e)
after the flush boundary, remove from meshes if it’s gone
A simple cleanup pass each frame:
1234
for(const[id,obj]ofmeshes){// if you track alive entities externally, remove when not alive anymore.// (One common approach: record seen IDs during the render query and remove the rest.)}