-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Allow intercepting GLTFDocument on scene import #63457
Allow intercepting GLTFDocument on scene import #63457
Conversation
Is it possible to avoid the use of class name. I think the similar system of an array .gd files may work. An array of gdscript is not so good now that I think about it, because gdextentions may extend godot. Will need to ponder more. |
I don't think #63072 was an improvement. Testing showed it was a dead end. |
I have made a gltf extensions sandbox which was using the older approach. https://github.com/V-Sekai/godot-gltf-sandbox I can port it to the newer approach. |
|
dfdd371
to
d0c7a6d
Compare
@fire Did some bigger changes, which I think makes the code a bit clearer:
These changes could be split off from adding GLTFDocumentExtension, if you want it to be two PRs (or two commits in one PR)? |
d0c7a6d
to
91d98c0
Compare
I haven't checked precisely but if EditorSceneFormatImporterGLTFBase is a base class, can you make it GDREGISTER_VIRTUAL_CLASS? |
91d98c0
to
2869b5a
Compare
Done. Should I also add |
a78c988
to
4306457
Compare
Did you see the style check failures? |
4306457
to
a90c4b4
Compare
I think so. We can also do the thing where we wait for people to complain. Since if it was essential the compiler and tests would have failed. |
Hmm on second thought, I think since |
I realized there's an alternative away to do the array. Let me know how well it works. It's a bit complicated... D: ADD_PROPERTY(PropertyInfo(Variant::INT, "modification_count", PROPERTY_HINT_RANGE, "0, 100, 1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_ARRAY, "Modifications,modifications/"), "set_modification_count", "get_modification_count"); Becomes: ADD_PROPERTY(PropertyInfo(Variant::INT, "extension_count", PROPERTY_HINT_RANGE, "0, 100, 1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_ARRAY, "Extensions,import_scene/extensions/"set_extension_count", "get_extension_count"); |
Can revise for a future pr. |
Because
For glTF extensions I agree, having those global would make a lot more sense. But the "extras" object is likely only relevant for specific assets only.
Do you mean How should the user get access to |
The file can be a runtime glb loaded from a in-memory buffer. So there is no file! |
I have updated the approach with reduz's feedback. I also updated the MRP for testing above.
This allows for both global import behavior changes, or to check file path beforehand. Sample code:
A simple |
90e371a
to
ad8a738
Compare
Does not seem possible to make a method ( So I added an argument to retrieve the original file path (e.g. .blend path) to Means that for now you can't really do any post-processing logic after the scene import is done (besides using import scripts like before). |
Does this mean we have to make a plug per type of gltf and we'll can only make one of this per extension? |
@fire You have to create one editor plugin (in the addons folder) that looks basically like this:
but you can of course register multiple importer plugins in one editor plugin. The MRP zip has a simple example of how it is done. Each importer plugin you add can change its logic freely based on scene file path (so it can add none, one, or multiple GLTFDocumentExtensions). |
I am not sure what is blocking this. There's a rebase problem though. |
ad8a738
to
3700356
Compare
From my perspective it should be ready. Fixed the conflict that came with 805ffdf , works now. |
- Create EditorSceneImporterGLTFBase, which is how all scene importers that use glTF as backing format can share behavior. - Allow user to intercept creation of GLTFDocument with virtual method _initialize_gltf, for example to conditionally add GLTFDocumentExtensions - De-duplicate file extension check by moving it into the ResourceImporterScene class.
3700356
to
3cd52ad
Compare
@fire Is anything still needed to get this merged? I updated the example project so the addon is a single .gd file now - see PR description for the code. It's a bit simpler than before, might be good for putting into a distant-future wiki page or something. |
Sorry, we was focusing on getting #62499 to be part of Godot 4 beta, and it is in a limboed reviewing state by @reduz , I think both touch the same areas, and I want both. The maintainers have been working hard, https://github.com/godotengine/godot/pulse/monthly and I've been trying to get the two reviews required.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style wise it seems fine to me, and the refactoring seems good. Still need an OK from @reduz.
@aaronfranke Please see if this is usable |
The design of this seems quite limited, because it requires you to create a class that extends the importer in order to add extensions. This means that you are limited to using one importer at a time that adds all of the extensions. This will not work well if you have multiple third-party extensions, you would need to build a master class importer that includes the document extensions. It would make more sense to me to allow independently registering document extensions: # Create a plugin in project settings, then replace plugin.gd with this:
@tool
extends EditorPlugin
func _enter_tree():
# Extensions can be provided anywhere without having to know about each other or
# a master scene importer, so multiple extensions will not conflict with each other.
GLTFDocument.register_gltf_document_extension(MyDocumentExtension.new())
func _exit_tree():
remove_scene_format_importer_plugin(MyDocumentExtension)
class MyDocumentExtension extends GLTFDocumentExtension:
func _import_node(state, gltf_node, json, node):
prints("parent:", node.get_parent().name)
prints("scene_name:", state.scene_name)
prints("json:", json)
return 0 # Create a plugin in project settings, then replace plugin.gd with this:
@tool
extends EditorPlugin
func _enter_tree():
# Extensions can be provided anywhere without having to know about each other or
# a master scene importer, so multiple extensions will not conflict with each other.
GLTFDocument.register_gltf_document_extension(OtherDocumentExtension.new())
func _exit_tree():
remove_scene_format_importer_plugin(OtherDocumentExtension)
class OtherDocumentExtension extends GLTFDocumentExtension:
func _import_node(state, gltf_node, json, node):
prints("parent:", node.get_parent().name)
prints("scene_name:", state.scene_name)
prints("json:", json)
return 0 |
@aaronfranke But then the use case for handling cases file-by-file is lost, since GLTFDocumentExtension does not have a file path association (iirc GLTFState only has the "generated" GLTF path, not the original file's). This is very important for handling the "extras" section (e.g. .blend file Custom Properties), which unlike "extensions" usually differs between the different assets. |
@RedMser That's a good point, although that's not my use case. I think maybe we should have both systems in place, a way to register GLTFDocumentExtensions for GLTF importers to use, and a way to specify custom importers per-file. In that case, I don't really know what to think of with your PR, because I simply don't need it, the use case I have is to specify an extension that is used for importing all GLTF files. EDIT: After discussing with fire, I made a PR that will fit with our use cases: #66026 |
#66026 fixes I and @aaronfranke' use cases. |
Superseded by #66026. |
Let us know if you're able to solve your usecases as an mod to #66026. I am still interested. |
@fire Thanks, I checked the PR and it seems to be a good alternative. Some things I have noticed:
I will close my proposal since this seems to be a good alternative. |
Base path is used for the engine importer to find .bin and .png/.jpg. Like in the blender importer the gltf base path is in the .godot/importer/ folder for a res://example.gltf. Path is “res://example.gltf”. Path doesn’t exist for buffers. I’ll poke @aaronfranke about unregistering gltf document extensions. |
Closes godotengine/godot-proposals#4968
_initialize_gltf
to all glTF-based importers (gltf/glb, fbx, blend), which can intercept the step between creation and usage ofGLTFDocument
andGLTFState
.add_scene_format_importer_plugin
to register aEditorSceneFormatImporter
. It can inherit from e.g. theGLTF
importer and merely override that specific virtual method to conditionally modify the document/state.GLTFDocumentExtension
and let those run for all imported scene assets that go through the glTF pipeline (filtering by path is possible). Among other things, this allows for direct access to the "extensions" and "extras" dictionaries of the glTF nodes.extends
inside ofplugin.gd
to try out .fbx and .blend (don't forget to reload the plugin!).godot-props-test.py
script can be installed and enabled as a Blender add-on to try out the user extension functionality, which will cause a glTF extension to be printed on import.Example code: