#How can I change the mesh of an object using code?
1 messages · Page 1 of 1 (latest)
Before you can change the mesh, you need to understand how 3d models are defined in 3d graphics using vertices, their data (uvs, normals, etc.) and triangle indices. Deforming arbitrary meshes isn't trivial task at all. If the model was created procedurally by using marching cubes or something similar, then modifying the underlying data and generating the mesh again isn't too hard. Modifying meshes at runtime isn't particularly fast either (well, you could potentially move the computation to GPU) which often means that you must use different optimization strategies like chunks to be able to make modifications more locally
The example you showed seems to be 2D which means it can potentially use something other than meshes to begin with (textures, distance fields?) but even the mesh manipulation can be simpler in 2D and much faster. In 2D meshes could be generated procedurally by marching squares (2D version of marching cubes) which would be faster given one less dimension and generally less geometry to work with
Assuming you are going for the same type of manipulation than in the reference, you would have to remove every triangle within the circle, leave everything outside the circle untouched and handle the triangles at the circle edges separately. The last part of that is the hard one but there are surely some algorithms you can find that does that but it is not a trivial issue regardless
At that point I would consider going for other solutions. In 2D, I would assume doing a realtime texture manipulation would be easier and if the texture represented the map as a distance field (and was rendered using special shader, similar to the one that is used by TMPro to render SDF text), you would get a way with relatively low resolution textures. If I had to guess, this would be much closer to what they did in that reference game (the animated destruction and relatively smooth corners there would also suggest that to me)