Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arbitrary Extension API #395

Merged
merged 5 commits into from
Nov 13, 2023
Merged

Arbitrary Extension API #395

merged 5 commits into from
Nov 13, 2023

Conversation

CorneliusCornbread
Copy link
Contributor

@CorneliusCornbread CorneliusCornbread commented Nov 4, 2023

Fixes #231

You can enable it with the extensions feature flag

You can access the extensions in the following manner:

//materials extension, same for all fields
for value in gltf.materials() {
    if let Some(ext) = value.extensions() {
        for values in ext {
            println!("{},{}", values.0, values.1)
        }
    }
}

//root extensions
gltf.extensions();

//or you can use extension_value() for a single value instead of the whole map
for value in gltf.materials() {
    println!(
        "{}",
        value.extension_value("VRMC_materials_mtoon").unwrap()
    )
}

src/accessor/mod.rs Outdated Show resolved Hide resolved
@alteous
Copy link
Member

alteous commented Nov 7, 2023

Thanks for your PR.

Using RawValue instead of Value would shift deserialisation onto the user but, on the other hand, the user would only pay for the extensions used. I'm curious if you gave this approach a try? I like the proposal as-is nonetheless.

@CorneliusCornbread
Copy link
Contributor Author

CorneliusCornbread commented Nov 7, 2023

Thanks for your PR.

Using RawValue instead of Value would shift deserialisation onto the user but, on the other hand, the user would only pay for the extensions used. I'm curious if you gave this approach a try? I like the proposal as-is nonetheless.

The reason was due to complexity. Raw value requires you to reference it in a data structure as a borrowed value, this causes some problems with some of the attributes on the data structures. I could probably figure it out but I simply went with the regular Value.

Also, the majority of the time, when you are using one extension, you're usually using all the extensions. Also, for actual use, with RawValue, you'd have to store the serialized data yourself. Meaning if you want to pass the gltf to a function with all its extensions, you'd need a structure that can store all the extensions, which would be a huge pain. This makes it so that all the data is in one data structure, making it much easier in use API wise.

If I have some free time this week, I'll make a branch and try implementing this using RawValue

@CorneliusCornbread
Copy link
Contributor Author

CorneliusCornbread commented Nov 11, 2023

Thanks for your PR.

Using RawValue instead of Value would shift deserialisation onto the user but, on the other hand, the user would only pay for the extensions used. I'm curious if you gave this approach a try? I like the proposal as-is nonetheless.

So I looked into it, as far as I can tell I don't believe there's a way we can mix flatten and raw value, it seems flatten will only accept a Map<String, Value> meaning we'd would have to drop support for the existing supported extensions for arbitrary extension support. If you think that would be preferrable I can rewrite it to do that.

Edit: thinking about it we could probably still support the extensions natively, but it would require a pretty decently sized rewrite to the way we're serializing extensions currently.

@alteous
Copy link
Member

alteous commented Nov 13, 2023

So I looked into it, as far as I can tell I don't believe there's a way we can mix flatten and raw value, it seems flatten will only accept a Map<String, Value> meaning we'd would have to drop support for the existing supported extensions for arbitrary extension support. If you think that would be preferrable I can rewrite it to do that.

Thanks for taking a look. If that's the case then it's not worth overhauling everything for it. Let's use the owned Value as you proposed originally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for custom extensions
2 participants