I think I see what the problem is. Mesh Instance caches some information about the mesh … such as info about vertex format. When you change the vertex format of the mesh, the mesh instance data is not updated to match.
What I would suggest to do:
- use render component, instead of model component, to create your cube.
- get mesh instance from render component, get mesh from it … and modify it as you do at the moment. also keep a material that mesh instance uses.
- create new mesh instances and assign them to render component. something like
this.entity.render.meshInstances = [new MeshInstance(mesh, material)];