Hey all
I would feel bad for creating such a vague topic but considering the current state of development, with everything changing, API still being written, I guess it’s fine. I’m looking at the examples provided but they are either too complex or don’t show how to do certain operations. Any help would be greatly appreciated!
My end goal is fortunately simple. I need to create planar meshes and move the vertices along the plane. Probuilder already has a plane primitive, so that was easy! I would like to add my own control points using my own Bézier surface thing, but it requires being able to move vertices. I also need to edit UVs; It’s a simple UV layout but important, the plane needs to be exactly inside the UV space. With four vertices this is trivial (each vertex is in a corner of UV space) but then the mesh has many vertices this can be hard to accomplish from code if the vertices are in no specific order. Maybe if PB has a subdivision operation that tries to find the new vertex UV “smartly” this could be easily achieved, by starting with single quad properly UVed then subdividing it as required.
Ideally I would like to be able to subdivide the mesh in specific directions without messing up UVs, but I’ll leave that for when the basic works.
All right, I managed to get pretty far without having to resort to using probuilder but now I need it. The example provided for creating a new mesh uses a function that generates a new gameobject. I would rather have a way of generating a new mesh with the same gameobject though. I tried to find the relevant functions, first deleting faces or using clear, I tried to find convenient functions for creating meshes that don’t create new game objects but I couldn’t find anything.
I don’t want to simply move vertices, I am adding vertices and faces. Right now my solution is terrible: I save everything I need from the original gameobject, generate the new probuilder gameobject, copy all the values I want to the new gameobject, delete the previous gameobject.
Anyway I can just clear the current mesh and generate a new one without creating new gameobject?
That is great! It might help but I would still need more direct control to implement the whole thing. This operation reorders the vertices in unintuitive ways.
That’s all right though. I wanted to see if this could be achieved quickly as my main method isn’t too convenient (using external 3d editors). If it’s possible but not quicker or easier then it defeats the purpose. I’ve dealt with meshes directly in the past, and it’s always a mess! I don’t want to change sharedmesh because it needs to be unique and using mesh freaks Unity out, and I also don’t want to trust Unity handling automatically destroying the created mesh to prevent memory leaks. It tends to get complex and annoying very fast, is my point. ProBuilder was just one last attempt at editing meshes from code intuitively.
1 Like
I don’t want to change sharedmesh because it needs to be unique and using mesh freaks Unity out, and I also don’t want to trust Unity handling automatically destroying the created mesh to prevent memory leaks.
This is all handled in the background by ProBuilder. Any time you make a mesh editable it creates a copy, and will manage the lifecycle of that mesh for you.