ousnius / BodySlide-and-Outfit-Studio

BodySlide and Outfit Studio, a tool to convert, create, and customize outfits and bodies for Bethesda games.
GNU General Public License v3.0
286 stars 63 forks source link

Vertex count reducer #427

Open sts1skj opened 2 years ago

sts1skj commented 2 years ago

I've come across a few shapes in NIF files where every triangle had its own vertices. The number of vertices was three times the number of triangles. Many, many vertices could be safely merged, reducing the vertex count by roughly a factor of three. Though the merge option on the move-vertex tool lets you merge vertices one at a time, it would be nice if this could be automated.

I've seen other shapes that have ridiculously many vertices in some areas, spaced quite closely together. I doubt these extremely detailed meshes really need all those vertices to provide a good shape. Eliminating a lot of those vertices would likely result in a mesh that looks exactly the same in the game.

So maybe a vertex-count reducer could be useful. It could look for trivially merge-able vertices and merge them. It could look for vertices whose position, position diffs, weights, and texture coordinates are so close to being the average of two neighboring vertices that eliminating the vertex gives an insignificant change in the mesh shape and texture mapping, no matter the slider values or pose.

The algorithm would probably need a "simplification distance" parameter. Points would only be eliminated if the new mesh would be within the simplification distance of the point (for all slider values and poses). It'd probably need a "texture simplification distance" parameter too.

I'm assuming, of course, that reducing the vertex count has a benefit in the game: smaller file, less main memory, less graphics memory. I don't know if these things actually matter.

GrafPanzer commented 2 years ago

I think these functions could be useful, since simpler meshes use less resources, and any mesh over about 24k tris doesn't properly dismember in Fallout 4. If you implement these, I'd suggest limiting them to only the unmasked area of a mesh. They would be similar to the Merge By Distance, Decimate Geometry, and Limited Dissolve functions in Blender. It is important to keep all the original UV coordinates intact when performing these functions, as you mention. One problem in Blender is that algorithmic decimation doesn't look as nice as when it's done by hand. Instead of rows of nice triangulated quads, you tend to end up with meshes that look like the have flowers all over them (many faces originating from one vertex). Not sure if there's a way to avoid that.

lensman11 commented 1 year ago

Would there also be an issue with front and back meshes being very close like simulating thin materials ie silks and nylon for stockings and possibly even body suits etc. Regards Colin