How to create Procedural Meshes at Runtime?

I am quite confused on how the new render system and dots handles procedural mesh generation, since the RenderMeshArray is per entity chunk,
and every single mesh will be unique and runtime generated based on some paremeters and external inputs. Those parameters are dynamic at runtime, and will be updated quite often.

Are there any docs, samples, examples of generating Many™ meshes procedurally and runtime? Do I really need to mantain game objects , or use Graphics.DrawMesh manually?

You can register meshes directly with EntitiesGraphicsSystem and assign the index that gives you to MaterialMeshInfo. The resulting MaterialMeshInfo will ignore the RenderMeshArray and use this custom mesh instead, and then you can animate that mesh.

However, since you seem to be doing this a lot and frequently, having a bunch of meshes to individually modify could be very expensive. Depending on your requirements, maybe this will interest you? Latios-Framework-Documentation/Kinemation Animation and Rendering/Dynamic Meshes.md at main · Dreaming381/Latios-Framework-Documentation · GitHub

2 Likes

Do you have an updated simple example? I checked out your project on github and tried to use your framework. I was very hopeful it would work for me. I was trying to use your Dynamic Meshes example, but it didn’t work with the latest version of your framework (7.4) and Entities Graphics 1.0.11. Ideally I would like to see an example outside your framework that shows how to register meshes directly with the EntitiesGraphicsSystem. I have attempted to copy the mesh and materials from the Shared RenderMeshArray into a new RenderMeshArray, but saw the same massive performance hit when changing the vertices of the mesh.

I’ll update the guide to not use obsolete baker APIs. But the example code is working for me right now. I’m willing to investigate the issue you encountered if you provide more info.

I wrote my framework partly to bypass performance problems like this. You will need to find an answer from someone else.

You can spawn entities with an empty mesh and than in a system register a new mesh and collider.
For me works something like this:

                    var newMesh = new Mesh();
                    newMesh.vertices = vert.ToArray();
                    newMesh.triangles = tris.ToArray();
                    newMesh.colors = colors.ToArray();
                    newMesh.normals = normals.ToArray();
                    rb.Value.Center = new float3(7f, 7f, 7f);//ref RenderBounds rb
                    rb.Value.Extents = new float3(7f, 7f, 7f);
                    newMesh.RecalculateBounds();
                    var newId = hybridRenderer.RegisterMesh(newMesh);
                    mmi.MeshID = newId;//ref MaterialMeshInfo mmi


                    //Physics collider
                    Collider = Unity.Physics.MeshCollider.Create(vertCol, trisCol);
                    ecb.SetComponent(e, new PhysicsCollider { Value = Collider });