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

Import/export GLTF extras to node->meta and back #86183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

demolke
Copy link
Contributor

@demolke demolke commented Dec 15, 2023

This is useful for custom tagging of objects with properties (for example in Blender) and having this available in the editor for scripting.

  • Adds import logic to propagate the parsed GLTF extras all the way to the resulting Node->meta where it creates extras dictionary
  • Adds export logic to save Godot Object meta/extras dictionary into GLTF extras
  • Support nodes, meshes and materials (in GLTF sense of the words)

image

Closes: godotengine/godot-proposals#8271

@AThousandShips
Copy link
Member

Please open a proposal to discuss the need and use cases for this feature

@demolke demolke changed the title Propagate gltf extras during mesh import to node->meta Propagate gltf extras during object import to node->meta Dec 15, 2023
@demolke
Copy link
Contributor Author

demolke commented Dec 15, 2023

Thanks, looks like there is one in godotengine/godot-proposals#8271, so I'll try to reuse that one

@noidexe
Copy link
Contributor

noidexe commented Dec 16, 2023

I tested it with a sample scene and overall it works well but I noticed a few things:

  • materials don't get metadata
  • blender mesh objects with -colonly and -convcolonly lose the metadata (in my workaround I assign it to the resulting StaticBody3D)
  • metadata in mesh datablocks doesn't end in the corresponding ArrayMesh resource. It seems to be added to every MeshInstance3D using the mesh. This could create collisions if a meshinstance and its assigned mesh happen to have a custom property with the same name

@fire
Copy link
Member

fire commented Dec 16, 2023

We also worked on a similar pull request with meta here #39024 #40474

@demolke demolke force-pushed the extras branch 2 times, most recently from acfb4fc to d26cf93 Compare December 17, 2023 03:40
@demolke
Copy link
Contributor Author

demolke commented Dec 17, 2023

@noidexe I've uploaded new version

  • GLTF material extras gets set in Godot Material
  • collision node extras get set on StaticBody3D (does not support collider mesh extra CollisionShape3D)
  • MeshInstance3D gets the node extras and Mesh gets the mesh extra properties

@fire
Copy link
Member

fire commented Dec 17, 2023

Part of my goal is that meta import and export is symmetrical for gltf. Let me know if thats too much or you agree.

@demolke
Copy link
Contributor Author

demolke commented Dec 17, 2023

I was thinking the same thing. I wanted to add a test that creates a scene, serializes it to gltf, deserializes it and checks it has the right meta, but the fact the mesh re-generation is happening in ResourceImporterScene makes testing it hairy.

I also don't understand github too much, so thought I was not including it in this PR, but somehow my in-progress stuff got attached - ignore it for now, I'll try to figure out.

editor/import/resource_importer_scene.cpp Outdated Show resolved Hide resolved
editor/import/resource_importer_scene.cpp Outdated Show resolved Hide resolved
modules/gltf/gltf_document.cpp Outdated Show resolved Hide resolved
modules/gltf/tests/test_gltf_extras.h Outdated Show resolved Hide resolved
editor/import/resource_importer_scene.cpp Outdated Show resolved Hide resolved
modules/gltf/tests/data/extras.gltf Outdated Show resolved Hide resolved
modules/gltf/tests/test_gltf_extras.h Outdated Show resolved Hide resolved
@demolke
Copy link
Contributor Author

demolke commented Dec 17, 2023

I feel bad for having you review this, apologies. I meant to say in my last comment that it needs more work - especially the test change, which I did not want to attach at all.

I guess I should mark it as draft?

@demolke demolke marked this pull request as draft December 17, 2023 18:38
@demolke demolke force-pushed the extras branch 2 times, most recently from 5d47d41 to e59dac2 Compare December 18, 2023 02:22
@demolke demolke marked this pull request as ready for review December 18, 2023 02:23
@demolke
Copy link
Contributor Author

demolke commented Dec 18, 2023

I've added both import and export as discussed in #86183 (comment) and added a test it works as expected.

I haven't found any import/export testing to take inspiration from - it might be my unfamiliarity with Godot, but the test has to instantiate way more of Godot that I would like - the whole import process is extremely intertwined with Editor/Engine (and their subsequent dependencies).

It's also not possible to do this in-memory, so a number of files (.gltf, .bin, .scn) get written and subsequently read from disk during the test run, which I'm not happy about.

Please take a look, cheers

@aaronfranke
Copy link
Member

@demolke Please review the CI failure and resolve all issues until the CI turns green. Only then is it ready for human review.

modules/gltf/gltf_document.cpp Outdated Show resolved Hide resolved
modules/gltf/gltf_document.cpp Show resolved Hide resolved
Copy link
Member

@aaronfranke aaronfranke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akien-mga Does the way the test case hooks into the editor look fine to you? Another option is to have the tests only use GLTFDocument/GLTFState, the same as the runtime import/export pipeline. However it seems like a good idea to allow test cases to test the editor's full import pipeline.

editor/import/3d/resource_importer_scene.cpp Outdated Show resolved Hide resolved
Copy link
Member

@aaronfranke aaronfranke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this! This looks good from the GLTF and import pipeline side of things.

Copy link
Contributor

@lyuma lyuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed on a call with fire. Looks good.

The only thing we need to fix is one case which looks like it may be use-after-free. we should reorganize that function to ensure the memdelete is after we copy meta from p_original_node.

editor/import/3d/resource_importer_scene.cpp Outdated Show resolved Hide resolved
@aaronfranke
Copy link
Member

@demolke: Thanks for taking a look, I've updated it except I did not call it gltf_extras, but just extras.

After thinking about it more, I agree that this is a good idea. If someone uses the .blend importer and that generates extras, the fact that the .blend file importer uses GLTF under the hood is an implementation detail, and the user ideally shouldn't know. So yeah, I like this PR as-is.

@lyuma
Copy link
Contributor

lyuma commented Apr 27, 2024

Hmm, I am worried extras is not something I think most people will understand. (It is a technical term in the gltf spec...)
Is there a better term to indicate it is imported? Or is extras ok

@demolke
Copy link
Contributor Author

demolke commented May 9, 2024

Hmm, I am worried extras is not something I think most people will understand. (It is a technical term in the gltf spec...) Is there a better term to indicate it is imported? Or is extras ok

In absence of other suggestions, I think extras is okay. We can't just call it imported_extras since they also get exported. ported_extras :).

The only other one I can see working is Imported/exported metadata, but it's quite long and since the main usage of this is from code it should be typo proof, so I would stick with extras.

@fire
Copy link
Member

fire commented May 9, 2024

I do like that extras is symmetrical on import and export.

@demolke demolke force-pushed the extras branch 2 times, most recently from 3f1b892 to 7e11089 Compare May 16, 2024 18:34
@demolke demolke force-pushed the extras branch 3 times, most recently from 429a345 to 26d15cb Compare May 22, 2024 17:02
This is useful for custom tagging of objects with properties (for example in Blender) and having this available in the editor for scripting.

- Adds import logic to propagate the parsed GLTF extras all the way to the resulting Node->meta
- Adds export logic to save Godot Object meta into GLTF extras
- Supports `nodes`, `meshes` and `materials` (in GLTF sense of the words)
@aaronfranke aaronfranke modified the milestones: 4.x, 4.4 May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Import custom glTF properties as node metadata
8 participants