-
Notifications
You must be signed in to change notification settings - Fork 323
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
Enable a gltf_gltf2_hook #919
Conversation
I think you could simplify and generalize it by just adding this to def __gather_gltf(exporter, export_settings):
active_scene_idx, scenes, animations = gltf2_blender_gather.gather_gltf2(export_settings)
+ plan = {'active_scene_idx': active_scene_idx, 'scenes': scenes, 'animations': animations }
+ export_user_extensions('gather_gltf_hook', export_settings, plan)
+ active_scene_idx, scenes, animations = plan['active_scene_idx'], plan['scenes'], plan['animations']
+
if export_settings['gltf_draco_mesh_compression']:
gltf2_io_draco_compression_extension.compress_scene_primitives(scenes, export_settings)
exporter.add_draco_extension() ie. we just give extensions a chance to modify those three variables. You'd also have to take my suggestion from here about making |
The code you have posted would work perfectly without modifying the Edit: it doesnt work, as we expect the So if we allow not to pass a |
gltf2_object = args[0] | ||
try: | ||
object_extensions = getattr(gltf2_object, "extensions") | ||
except AttributeError: | ||
pass | ||
else: | ||
if object_extensions is None: | ||
setattr(gltf2_object, "extensions", {}) |
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.
Easier to do
if args and hasattr(args[0], 'extensions'):
if args[0].extensions is None:
args[0].extensions = {}
Like I said before, I think this check should just go away though.
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.
Then you need to do it in all the extensions... By default, the extensions is None, and you dont know which extension is going to be called first
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.
Ive modify it as you said
Any news on this? |
fe76f0e
to
083e131
Compare
try: | ||
hook(*args, export_settings) | ||
except Exception: | ||
pass |
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.
Should the exception get logged to the console? Might be hard to debug without that.
@emackey It would be possible, but not nice. The problem is that the exporter creates a glTF.Scene, which contains glTF.Nodes. Each node may contain a mesh, which may contain a material. There is no other way to specify a material in the glTF.Scene. So with this patch you would be able to add a dummy node, with a dummy mesh, with a material, but there is no way to add directly a material. This is a general problem created by how the exporter works. The exporter creates an intermediate representation which is not 1:1 a glTF representation (for example, there is no textures root store). |
3b53958
to
8ee2eac
Compare
So ... any problem remaining on this, or is that ready to merge? |
I don't really have any problems, but I'm not familiar with this code so I'm not really good to ask (my comments were just ways to make stuff shorter). |
Is there any other review? |
Seems fine. Thanks @jjcasmar. |
This patch allows the user to create a gltf2_hook that returns a new list of scenes and animations. The purpose of this is to allow a second pass that can do more things than what currently the exporter does.
As an example, the exporter checks if an object in bpy.data.objects is exported, and in that case, it checks if it has animations. If it has animations, it exports the animation.
If you want to use glTF2 as an animation library, its not possible, because the animations wont be exported. EXT_property_animation (although not ratified yet), can't be implemented neither as you cant export material animations.
With a second pass, we allow this use cases and more.
@scurest @emackey @julienduroure