gwihlidal / meshopt-rs

Rust ffi and idiomatic wrapper for zeux/meshoptimizer, a mesh optimization library that makes indexed meshes more GPU-friendly.
Apache License 2.0
163 stars 33 forks source link

Create a minimalistic 100% optimal tool example #6

Closed gwihlidal closed 5 years ago

gwihlidal commented 6 years ago

Currently, the only example is demo, which is a monolithic feature matrix of the entire API. It would be very helpful to create a minimalistic tool example that shows only shows the necessary calls to optimize a mesh for 100% GPU (and optionally, CPU packing/encoding improvements).

Likely this would be a simple docopt\clap command line tool that takes an obj/gltf2, optimizes it, and saves out the optimized version.

Bonus points would be to preserve information from the original mesh (morph targets, materials, etc.) so the output from the tool could be usable in actual game or demo pipelines, instead of only writing out vertices and indices for the result.

gwihlidal commented 6 years ago

For now, the best example in the demo is the opt_complete method - this is the recommend 100% GPU path; packing and encoding can be optionally added.

TimvanScherpenzeel commented 5 years ago

Hi @gwihlidal,

I was looking through the codebase of meshoptimizer and with the latest release 0.10 it ships with a WebAssembly decoder and JavaScript mesh loader. It can load files processed by meshencoder.cpp.

Would it be an idea to replicate this meshencoder as a basic example in Rust? This way we can leverage the WebAssembly / Javascript in meshoptimizer for free and have a useful demo to ship along with this project.

Kind regards,

Tim

gwihlidal commented 5 years ago

Hi Tim,

Sure, if this is something you plan to use I can look into that. I'm preparing a new release of the crate which includes 0.10 support, so I'll check this out while I'm at it.

TimvanScherpenzeel commented 5 years ago

That is great, thank you.

I'm planning to use it in a tool to make a custom mesh format for a WebGL engine I've been working on. I've used Draco compression (with glTF, through Node.js) in the past but have been looking at creating some tooling in Rust for learning purposes and more control. So it would definitely be useful to me 👍

gwihlidal commented 5 years ago

Very cool! Are you looking for a direct port of meshencoder.cpp to rust (i.e. takes an obj file path, writes out a .optmesh), or are you wanting a generic library/function that takes some abstract geometry data (not tied to .obj, such as .gltf/.glb) and returns an .optmesh binary, such that you write the CLI tool that calls this functionality?

TimvanScherpenzeel commented 5 years ago

I think for this crate it makes most sense to directly port meshencoder.cpp to keep it in line with the meshoptimizer package. I think the .obj -> .optmesh works fine for now as it shows the crate working the same as the main library as users can copy over the relevant parts they consider necessary.

That said, outside of this crate, I think it also makes sense to look at, like you stated above, taking in a glTF file and outputting an optimised version with the original data intact. But I can see how that might be quite complex as I don't think the gltf-rs crate currently exports as of yet and I would advise against rolling your own as glTF can get really quite complex. You would also have to be aware of keeping the glTF file spec compliant (which Draco is through a custom extension) and can therefore only really optimise in place then rather than use the custom .optmesh structure similar to how the current demo exports an .obj.

For my own project, seeing as it is specifically written for my engine anyways, I don't have to worry about spec-compliancy or the ability to transform it back to human readable text.

gwihlidal commented 5 years ago

Hi Tim,

I just released v0.1.5 of the crate which includes 0.10.0 support, and also includes a mesh encoder port to rust as an example. I think this change is sufficient to close this issue.

Thanks for the suggestion!

Cheers, Graham

TimvanScherpenzeel commented 5 years ago

Hi Graham,

Thank you for your work over the weekend 👍! It will be of much use to me.

Kind regards,

Tim