-
Notifications
You must be signed in to change notification settings - Fork 73
Improved support for modifying glTF models #137
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
base: extension-support
Are you sure you want to change the base?
Conversation
That took me about 20 hours. It's the little things.
|
I like what I am reading! Keep it up. I have modified my use cases that aim at replacing components by simply fixing up my geometry compilation before I create the actual models. This solved a lot of my problems, at least temporary. And nothing is as permanent as a temporary solution, which is fine by me in this case. The only thing that it didn't solve is that my big models must replace some objects with animated counterparts that were manually edited using Blender and can therefore not be created from scratch by me in the code. Therefore I just keep a list of all the objects that are animated, eliminate them from the big model and tell my rendering client to add the animated objects to the view. Not the best solution, but one that works very well without me having to deep dive too much into this topic. I am curious about any progress on this. Bon courage! |
|
The points of "Modifying arbitrary elements" (by setting some property to The point to "replace some objects with animated counterparts" is a natural next step. And I don't see major hurdles for that right now. The The main goal for allowing modifications of the model is to ensure "structural consistency". You can manually create inconsistent/invalid structures and add them to the model. Or you can make structures "invalid" by removing elements. One important aspect of that is the validity and consistency of the buffer structures ( On the implementation side, most of what is required here already exists (and already existed for a long time in JglTF, with the first versions of the For now, I preliminarily and hesitatingly resorted to what could be seen as a "sledgehammer method": There is an internal All this will require many more tests and validations. And I hope that the current approaches (of using that "Graph" for reachability computations, and that (But... somewhat unrelated: There are currently three open draft PRs, #134 , #135 and this one. The lower-level ones (like the material refactoring) are largely "consolidated" - this is necessary for all PRs that build on top of them. At some point, I'll try to "flatten" this into the |
*looks left*
*looks right*
Yeah, I'm still working on this, occasionally.
I'm opening this as a draft for now, just to track the process. It is part of (and built on top of) the general extension support efforts, aiming at JglTF 3.0.0.
This specific branch/PR mainly addresses the goal to simplify reading, modifying, and writing glTF models .
@CloseFile and @LocutusV0nB0rg : You 👍 'ed this issue. You might not be interested in the "Summary". But maybe you want to have a look at the "Example" below, to maybe get an idea where this might be going.
Summary
The reason why it is built on top of the "extension support" PR is that a really convenient layer for reading/modifying/writing models requires a "model-level" understanding and awareness of extensions.
A very short summary of the approach (with some overlap to what I already wrote in #135):
ModelElementinterface that is implemented by all elements of a glTF model (AccessorModel,SceneModel,AnimationModeletc).DefaultMaterialsClearcoatModelforKHR_materials_clearcoat.ModelElementmust provide a mechanism to determine which other model elements are needed/used by this model element.getReferencedModelElementsfunction. For example, the clearcoat implementation returns the clearcoat/roughness/normalTextureModelobjects.removeModelElementsmethod. For the clearcoat implementation, this sets allTextureModelelements tonullwhen they should be removedWith these operations, it is possible to perform certain operations that, at their core, boil down to graph operations.
For example, it is possible to build a "graph" of model elements, starting at the
SceneModel/AnimationModelobjects, and traversing through the reachable (referenced) model elements. Model elements that are not reachable are disconnected from the rest, and can be removed. The removal methods, in turn, indicate whether an element became "invalid" due to the removal, and have to be removed as well. Once all "unused/invalid" elements have been removed, the model can (or rather: has to be) "validated" in terms of its buffer structure.(I'm aware of some caveats of all this. This is still a draft PR, and still requires extensive testing)
This ~"graph stuff" is currently contained in a first shot of a package called
gltf-model-transform, added via 99488f6 . (Of course I won't dare to claim that it is nearly as clean and powerful as glTF-Transform, but ... I needed a name, and that's it for now...)Example
To illustrate what already works in the state of this PR, consider the following example
The goal is to create (or load) an example model, do the
Magic, and then write out a valid (!) glTF model of the result.And
Magiccan currently be two things:Modifying arbitrary elements:
Imagine the model contains a material with a texture. It is then possible to do the following:
(Yeah, the casts are ugly - let's ignore that for now...)
The base color texture is set to
null, so the texture becomes unused. The result will be a glTF model that does no longer have the texture (and does no longer contain theImageModelthat was used by this texture).Removing arbitrary elements:
Imagine the model contains an animation. It is then possible to do this:
The
AccessorModelthat stores the times (key frames) of theAnimationModelis explcitly removed. (Note that the animation model itself is not explicitly modified. This just removes the accessor from the glTF, regardess of where it is used!) This implies the removal of theAnimationModel, which, in turn, implies the removal of otherAccessorModelinstances that have been used by the animation. The result will be a glTF model that does no longer have this animation (and none of the data that was used for that animation).All this is pretty preliminary. There are several TODOs and things that have to be tested more thoroughly. But it looks like this could be one way to simplify reading, modifying, and writing glTF models .