FBX IO: Add support for armature data custom properties #104888

Merged
Thomas Barlow merged 4 commits from Mysteryem/blender-addons:fbx_armature_custom_props_pr into main 2023-09-19 01:53:45 +02:00
2 changed files with 19 additions and 4 deletions
Showing only changes of commit 7872b6e51f - Show all commits

View File

@ -552,14 +552,21 @@ def fbx_data_element_custom_properties(props, bid):
def fbx_data_empty_elements(root, empty, scene_data): def fbx_data_empty_elements(root, empty, scene_data):
""" """
Write the Empty data block (you can control its FBX datatype with the 'fbx_type' string custom property). Write the Empty data block (you can control its FBX datatype with the 'fbx_type' string custom property) or Armature
NodeAttribute.
""" """
empty_key = scene_data.data_empties[empty] empty_key = scene_data.data_empties[empty]
null = elem_data_single_int64(root, b"NodeAttribute", get_fbx_uuid_from_key(empty_key)) null = elem_data_single_int64(root, b"NodeAttribute", get_fbx_uuid_from_key(empty_key))
null.add_string(fbx_name_class(empty.name.encode(), b"NodeAttribute")) null.add_string(fbx_name_class(empty.name.encode(), b"NodeAttribute"))
val = empty.bdata.get('fbx_type', None) bdata = empty.bdata
null.add_string(val.encode() if val and isinstance(val, str) else b"Null") is_armature = bdata.type == 'ARMATURE'
if is_armature:
fbx_type = b"Null"
else:
val = bdata.get('fbx_type', None)
fbx_type = val.encode() if val and isinstance(val, str) else b"Null"
null.add_string(fbx_type)
elem_data_single_string(null, b"TypeFlags", b"Null") elem_data_single_string(null, b"TypeFlags", b"Null")
@ -567,7 +574,10 @@ def fbx_data_empty_elements(root, empty, scene_data):
props = elem_properties(null) props = elem_properties(null)
elem_props_template_finalize(tmpl, props) elem_props_template_finalize(tmpl, props)
# No custom properties, already saved with object (Model). # Empty/Armature Object custom properties have already been saved with the Model.
# Only Armature data custom properties need to be saved here with the NodeAttribute.
if is_armature:
fbx_data_element_custom_properties(props, bdata.data)
def fbx_data_light_elements(root, lamp, scene_data): def fbx_data_light_elements(root, lamp, scene_data):

View File

@ -2826,8 +2826,13 @@ class FbxImportHelperNode:
elem_find_first(fbx_tmpl, b'Properties70', fbx_elem_nil)) elem_find_first(fbx_tmpl, b'Properties70', fbx_elem_nil))
if settings.use_custom_props: if settings.use_custom_props:
# Read Armature Object custom props from the Node
blen_read_custom_properties(self.fbx_elem, arm, settings) blen_read_custom_properties(self.fbx_elem, arm, settings)
if self.fbx_data_elem:
# Read Armature Data custom props from the NodeAttribute
blen_read_custom_properties(self.fbx_data_elem, arm_data, settings)
# instance in scene # instance in scene
view_layer.active_layer_collection.collection.objects.link(arm) view_layer.active_layer_collection.collection.objects.link(arm)
arm.select_set(True) arm.select_set(True)