Awesome
Nanite simplification tests
Tests for mesh simplification for Nanite WebGPU. Intended for me.
Main file you want: src/meshPreprocessing/index.ts. There is a separate config file. See logs for raw data.
The context for this repo is discussions with JMS55 and Arseny Kapoulkine. Since this README.md has a stupidly ridiculous conclusion, I'm only going to link my own posts:
There is also a separate discussion in meshoptimizer's repo.
Quick notes
Main problem
After a few rounds of meshlet hierarchy simplification, some meshes end up with disjointed triangles. Not possible to simplify. From meshoptimizer's documentation:
For meshes with inconsistent topology or many seams, such as faceted meshes, it can result in simplifier getting "stuck" and not being able to simplify the mesh fully. Therefore it's critical that identical vertices are "welded" together, that is, the input vertex buffer does not contain duplicates. Additionally, it may be worthwhile to weld the vertices without taking into account vertex attributes that aren't critical and can be rebuilt later.
In some situations, there is no correct answer. Similar problems appeared in Bevy's implementation. We both used many DAG roots as a quick band-aid, but it's far from optimal.
Optimal DAG
There is a definition of an optimal DAG (from "Batched Multi Triangulation" section 3.2):
- the length of a path connecting the root to any leaf is logarithmic in the number of nodes and
- the diameter of a fragment decreases geometrically with the distance of the corresponding node from the root of the DAG.
Conclusion
BTW. I know nothing about mesh simplification algorithms.
ATM I think that it's not possible to get an optimal DAG by only following the standard simplification rules. A similar observation I've buried in Nanite WebGPU's Usage.md. Let's take a model that has flat shading. Each vertex is unique wrt. position and normal. Nothing we can do.
There are some ways to partially solve this, but none that will always work. E.g. you can merge vertices that are close, do more edge collapses, some weird triangle merges (how?). But none seems like a definitive solution.
Actually, I lied. There is one solution that works every time. Randomly removing triangles when the simplifier gets stuck. This also includes triangles whose edge is shared with neighboring meshlets. You increase Nanite's simplification error (one used for error metric) so that the meshlet is not shown to the user if the artifacts would be visible.
This is the same solution used for LODs in my "Frostbitten hair WebGPU". But there I remove randomly entire hair strands (Frostbite does the same).
Not sure if there is an alternative?
I'm also not sure you can always get a balanced DAG. Sometimes METIS creates a group with a single meshlet instead of 4 and you wonder what to do with it. This solves itself on higher levels and it's not a big issue.
Usage (not tested)
This project is 99% copy paste from Nanite WebGPU. I've removed all of the WebGPU stuff. It's all intended as an experiment.
Node.js does not support WebGPU. Deno does.
- Download the
.zip
file from deno/releases.- I use v1.43.5 because I never update things that work.
"<path-to-unzipped-deno>/deno.exe" cache "src/index.deno.ts"
. Download the dependencies."<path-to-unzipped-deno>/deno.exe" task start
.
Personally, I just use the makefile. Update paths there and you should be good to go.
PS. DO NOT LOOK INTO quadric.ts.
References
- Arcane - Jinx 3D model by sketchfab user Craft Tama. Used under CC Attribution license.
- I've merged the textures, adjusted UVs, and removed the weapon.