FBX: Enable the Collection exporter feature #105273

Merged
Jesse Yurkovich merged 6 commits from deadpin/blender-addons:fbx-collectionexport into main 2024-04-16 05:13:36 +02:00

This enables FBX to be used as a Collection exporter[0].

To enable this, two changes were made:

  • The export_scene.fbx operator was configured on the File Handler
  • A collection property was added to the export Operator

This collection property is akin to the special filepath and
directory properties in that this is how Blender will communicate with
the addon.

Because FBX already has a use_active_collection property, a small
layout change is included to not draw this property when used as a
Collection exporter as that would introduce confusion. It also makes
sense to only draw use_selection and use_visible while in the file
browser in the same way. Feedback was received about this during
development and indeed these toggles will be skipped during processing
anyhow.

An additional discussion point to consider is if we want this new
collection property drawn when using File->Export to allow the
user to control which exact collection to export as opposed to just the
"Active Collection". This isn't included in the patch currently.

[0] To test, go to Collection Properties -> Exporters -> Add and
select FBX after applying this patch.

This enables FBX to be used as a Collection exporter[0]. To enable this, two changes were made: - The `export_scene.fbx` operator was configured on the File Handler - A `collection` property was added to the export Operator This `collection` property is akin to the special `filepath` and `directory` properties in that this is how Blender will communicate with the addon. Because FBX already has a `use_active_collection` property, a small layout change is included to not draw this property when used as a Collection exporter as that would introduce confusion. It also makes sense to only draw `use_selection` and `use_visible` while in the file browser in the same way. Feedback was received about this during development and indeed these toggles will be skipped during processing anyhow. An additional discussion point to consider is if we want this new `collection` property drawn when using `File`->`Export` to allow the user to control which exact collection to export as opposed to just the "Active Collection". This isn't included in the patch currently. [0] To test, go to `Collection Properties` -> `Exporters` -> `Add` and select FBX after applying this patch.
Jesse Yurkovich added 3 commits 2024-04-09 20:59:03 +02:00
Jesse Yurkovich changed title from FBX: Enable the Collection export feature to FBX: Enable the Collection exporter feature 2024-04-09 21:00:11 +02:00
Jesse Yurkovich requested review from Thomas Barlow 2024-04-09 21:08:55 +02:00
Jesse Yurkovich added 1 commit 2024-04-10 20:25:47 +02:00
Thomas Barlow reviewed 2024-04-15 03:11:26 +02:00
@ -3614,0 +3613,4 @@
source_collection = context.view_layer.active_layer_collection.collection
elif collection:
if collection in bpy.data.collections:
source_collection = bpy.data.collections[collection]
Member

Might want to consider whether performing a Collection export from a Collection linked from another file should be supported because a linked Collection can have the same name as a Collection local to the current file (or presumably another Collection linked from another different file).

Currently, exporting from a linked Collection appears to work, but doesn't seem too useful because the Collection's children, export settings and export file path cannot be changed due to being linked from another file.

I don't know if there is a guarantee that bpy.data.collections[collection] will always return a Collection from the current file in preference to a linked Collection with the same name, but it seems like that might be the case from a quick test using the Python Console. So, exporting from a linked Collection with the same name as a local Collection would export the local Collection instead.

If exporting from a linked Collection should not be supported, bpy.data.collections[(collection, None)] can be used to only get a Collection local to the current file.

Otherwise, to get specific Collections, which could have the same name, linked from different libraries would require bpy.data.collections[(collection, library_filepath)] where library_filepath is the value of my_collection.library.filepath or None (when my_collection.library is None due to the Collection being local to the current file).

I don't know enough about how library linked data-blocks are used and supported by different parts of Blender to say if any changes are needed here.

Might want to consider whether performing a Collection export from a Collection linked from another file should be supported because a linked Collection can have the same name as a Collection local to the current file (or presumably another Collection linked from another different file). Currently, exporting from a linked Collection appears to work, but doesn't seem too useful because the Collection's children, export settings and export file path cannot be changed due to being linked from another file. I don't know if there is a guarantee that `bpy.data.collections[collection]` will always return a Collection from the current file in preference to a linked Collection with the same name, but it seems like that might be the case from a quick test using the Python Console. So, exporting from a linked Collection with the same name as a local Collection would export the local Collection instead. If exporting from a linked Collection should not be supported, `bpy.data.collections[(collection, None)]` can be used to only get a Collection local to the current file. Otherwise, to get specific Collections, which could have the same name, linked from different libraries would require `bpy.data.collections[(collection, library_filepath)]` where `library_filepath` is the value of `my_collection.library.filepath` or `None` (when `my_collection.library is None` due to the Collection being local to the current file). I don't know enough about how library linked data-blocks are used and supported by different parts of Blender to say if any changes are needed here.
Author
Member

Currently, exporting from a linked Collection appears to work, but doesn't seem too useful because the Collection's children, export settings and export file path cannot be changed due to being linked from another file.

Hmm, how did you arrive in this state? If you link in a Collection from foo.blend which has an exporter set you shouldn't see anything in the UI as it's not intended to be exportable in the current file. Are you seeing otherwise?

I don't know if there is a guarantee that bpy.data.collections[collection] will always return a Collection from the current file in preference to a linked Collection with the same name, but it seems like that might be the case from a quick test using the Python Console. So, exporting from a linked Collection with the same name as a local Collection would export the local Collection instead.
If exporting from a linked Collection should not be supported, bpy.data.collections[(collection, None)] can be used to only get a Collection local to the current file.

I'll make the change to use the None argument to make it more explicit.

> Currently, exporting from a linked Collection appears to work, but doesn't seem too useful because the Collection's children, export settings and export file path cannot be changed due to being linked from another file. Hmm, how did you arrive in this state? If you link in a Collection from foo.blend which has an exporter set you shouldn't see anything in the UI as it's not intended to be exportable in the current file. Are you seeing otherwise? > I don't know if there is a guarantee that `bpy.data.collections[collection]` will always return a Collection from the current file in preference to a linked Collection with the same name, but it seems like that might be the case from a quick test using the Python Console. So, exporting from a linked Collection with the same name as a local Collection would export the local Collection instead. > If exporting from a linked Collection should not be supported, `bpy.data.collections[(collection, None)]` can be used to only get a Collection local to the current file. I'll make the change to use the `None` argument to make it more explicit.
Thomas Barlow approved these changes 2024-04-15 03:16:59 +02:00
Dismissed
Thomas Barlow left a comment
Member

Other than a note about library linked Collections where I don't know if changes are needed, looks good to me.

I was initially concerned that exporting as .fbx through File>Export>FBX with the Active Collection option enabled might then result in subsequent Collection exports using the same Active Collection value, however that does not appear to be the case, so all good there.

Other than a note about library linked Collections where I don't know if changes are needed, looks good to me. I was initially concerned that exporting as .fbx through File>Export>FBX with the Active Collection option enabled might then result in subsequent Collection exports using the same Active Collection value, however that does not appear to be the case, so all good there.
Jesse Yurkovich added 1 commit 2024-04-15 22:42:30 +02:00
Member

Hmm, how did you arrive in this state? If you link in a Collection from foo.blend which has an exporter set you shouldn't see anything in the UI as it's not intended to be exportable in the current file. Are you seeing otherwise?

(Replying here because I can't upload images in review comments)

Disable Instance Collections when linking so that the Collection is linked directly instead of as an instance.

image
image

> Hmm, how did you arrive in this state? If you link in a Collection from foo.blend which has an exporter set you shouldn't see anything in the UI as it's not intended to be exportable in the current file. Are you seeing otherwise? (Replying here because I can't upload images in review comments) Disable `Instance Collections` when linking so that the Collection is linked directly instead of as an instance. ![image](/attachments/73e0c86b-1b3b-4b61-a4e3-ba5740e6913d) ![image](/attachments/0e1d68ba-c462-4116-b861-0eaa1b4224f3)
Author
Member

Ok, I see, thanks for that explanation. It's the same when using lib overrides and making the instance local as well. I'll have to follow up on this a bit in general. It's actually mentioned in blender/blender#115690 as part of future design work, but until now I didn't know the set of steps to hit what Brecht was hinting at.

As far as these changes to FBX goes. How are you feeling about them? Are they ok to commit?

Ok, I see, thanks for that explanation. It's the same when using lib overrides and making the instance local as well. I'll have to follow up on this a bit in general. It's actually mentioned in blender/blender#115690 as part of future design work, but until now I didn't know the set of steps to hit what Brecht was hinting at. As far as these changes to FBX goes. How are you feeling about them? Are they ok to commit?
Thomas Barlow requested changes 2024-04-16 01:30:12 +02:00
Dismissed
Thomas Barlow left a comment
Member

One change requested upon having another look through.

Everything else looks good to me.

One change requested upon having another look through. Everything else looks good to me.
@ -560,1 +565,4 @@
# Are we inside the File browser
is_file_browser = context.space_data.type == 'FILE_BROWSER'
export_main(layout, self)
Member

The batch_mode and use_batch_own_dir properties drawn in export_main() should also only be drawn when is_file_browser because the new code in export_fbx_bin.py is only run when batch_mode == 'OFF' (the default value).

Changing the batch_mode to anything else I don't think makes sense for a Collection exporter.

The `batch_mode` and `use_batch_own_dir` properties drawn in `export_main()` should also only be drawn when `is_file_browser` because the new code in `export_fbx_bin.py` is only run when `batch_mode == 'OFF'` (the default value). Changing the `batch_mode` to anything else I don't think makes sense for a Collection exporter.
deadpin marked this conversation as resolved
Jesse Yurkovich added 1 commit 2024-04-16 01:47:00 +02:00
Thomas Barlow approved these changes 2024-04-16 02:13:42 +02:00
Jesse Yurkovich merged commit 4f815e960a into main 2024-04-16 05:13:36 +02:00
Jesse Yurkovich deleted branch fbx-collectionexport 2024-04-16 05:13:37 +02:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#105273
No description provided.