gltf-rs / gltf

A crate for loading glTF 2.0
Apache License 2.0
535 stars 124 forks source link

Is there anyway to use gltf in constants? #405

Closed coolcatcoder closed 11 months ago

coolcatcoder commented 11 months ago

Not sure if this is the right place to ask, but is there anyway to read/load/open gltf in a constant function?

alteous commented 11 months ago

I'm struggling to think of a reason why one might want to do such a thing. Could you provide a motivating example?

coolcatcoder commented 11 months ago

I cannot provide a motivating example. However I can provide an example lol. What I would wish to do is create a const array of vertices, and a const array of indices, for use with vulkano. Sure I could manually create these by hand, but it would be easier to grab them from gltf in a const function.

kpreid commented 11 months ago

You could use gltf from inside a build script of your package, which can run whatever kind of non-const calculation it wants, and generate Rust code containing constant arrays (either with simple string formatting, or uneval) which can then be included in your main program with include! or mod.

coolcatcoder commented 11 months ago

Ooh that sounds good, thanks for the info!