Mesh Trimmer script (cuts vertices outside some bounds)?

I need a script to trim (at runtime) all vertices in a mesh beyond some bounds. That would mean trimming the vertices, normals, colors, triangles, bone weights, and blend shapes. Before I write all that myself, does anybody know of such a script off the shelf?

(This is to remove the head of the local player model for use with VR, so if anybody knows of an easier solution for that, I’m all ears!)

If it has to be at runtime and not at model authoring time, perhaps look into the constructive solid geometry (CSG) classes in ProBuilder. You should be able to make a box around the head and use a subtract / remove boolean to chop the head off and seal off the neck hole nicely.

Otherwise just use a boolean in your 3D modeling program and chop it off!

Yeah, it has to be at runtime. But CSG sounds like overkill — I don’t need a nice flat edge, i.e., I don’t need to compute the intersection of any polygons with a plane and add new vertices to make an edge there. I’m content with literally just removing vertices above a line, and tidying up all the related data, which is a much easier problem.

Might be easier to iterate all triangles, summing the positions of their three verts to get the “center” of the triangle, then simply do not keep triangles whose center does not meet your keep criteria, then assign them back into the mesh. Just leave the verts array alone in that case.

Keep in mind if you have multiple submeshes you’d have to do it on a submesh-by-submesh basis.

That would be version one, then if you feel like it, remove all the verts that are no longer used by triangles.

That’s not a terrible version 1. As I’m on Quest and vertices are expensive here (and there tends to be a lot of vertices in the head, since we use the LOD0 model), I’ll probably want to go on to version 2 — but I like your idea of taking it in stages. Thanks for the suggestion!

1 Like