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

[Proposal] Using Dictionary-Key instead of List-Index #1576

Closed
vpenades opened this issue Mar 6, 2019 · 4 comments
Closed

[Proposal] Using Dictionary-Key instead of List-Index #1576

vpenades opened this issue Mar 6, 2019 · 4 comments

Comments

@vpenades
Copy link
Contributor

vpenades commented Mar 6, 2019

Right now, the current glTF.2 schema defines the root node as the container of all the object of the scene, which are stored in plain arrays. Referencing between elements is done with indices pointing to the appropiate list.

This is a quite simple implementation, but it makes extremely difficult to modify an existing model, specially when dealing with removing elements. With the current implementation, if you want to remove an element, lets say, an accessor it is no longer in use, it needs to be removed from the Accessors list, but then, all the references to all the accessors above the one that's been removed become out of order, so we need to traverse the whole model hunting down all the elements that reference accessors, and fixing the indices, so they point back to the appropiate accessor.

This becomes even more difficult if we also need to handle extensions that also reference elements in the model. Editing (removing) elements in a glTF model without caring about extensions might render the model unusable.

So at this point, I consider glTF.2 as an Append Only format; you can add elements to it, but you cannot remove elements.

And maybe this is just the right approach, because it enforces everybody to write authoring layers on top, and then create the glTF.2 model just at the time of exporting, so an appending only API would be enough.

But, if at some point, editing glTF models (including allow to remove elements) is considered useful, maybe replacing the Lists at model root with Dictionaries, and change the referencing with integer keys could greatly simplify this issue.

@javagl
Copy link
Contributor

javagl commented Mar 6, 2019

This is pretty unlikely to happen. In glTF 1.0, the top-level elements had been dictionaries. In glTF 2.0, this was changed to be arrays. I fully agree that this makes modifications difficult or impossible. But the reasoning behind the changes are summarized in #831

@vpenades
Copy link
Contributor Author

vpenades commented Mar 6, 2019

@javagl Okey, it makes sense them to be arrays.... it quite limits edition, but we will have to live with that.

@vpenades vpenades closed this as completed Mar 6, 2019
@emackey
Copy link
Member

emackey commented Mar 7, 2019

@vpenades It should be possible for a script to renumber things after removing an element from an array, although this gets complicated when extensions are involved. It's been a feature request in VSCode for some time now, but no one has had time to work on it, see AnalyticalGraphicsInc/gltf-vscode#96.

@donmccurdy
Copy link
Contributor

I've written some general-purpose "modify a glTF file" utilities in this project as well: https://github.com/donmccurdy/glTF-Transform, including adding/removing accessors. That project is not polished or production-ready by any stretch, though.

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

No branches or pull requests

4 participants