Skip to content

Instantly share code, notes, and snippets.

@Meatplowz
Last active January 20, 2022 15:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Meatplowz/5a4358bab9d83f22b9adbbcbf08cd9d0 to your computer and use it in GitHub Desktop.
Save Meatplowz/5a4358bab9d83f22b9adbbcbf08cd9d0 to your computer and use it in GitHub Desktop.
This is used with the FBX_Scene Class in cleaning up an exported skeletal mesh fbx
import FBX_Scene
import FbxCommon
def clean_character_scene(fbx_filename):
"""
Clean up character fbx file
"""
# open the fbx scenes and get the scene nodes
fbx_file = FBX_Class(fbx_filename)
if not fbx_file:
return False
# remove invalid nodes noted by properties assigned in the DCC application
all_nodes = fbx_file.get_scene_nodes()
remove_names = []
for node in all_nodes:
export_property = fbx_file.get_property(node, 'no_export')
if export_property:
property_value = fbx_file.get_property_value(node, 'no_export')
if property_value == True:
node_name = node.GetName()
# need to disconnect before deleting/removing
fbx_file.scene.DisconnectSrcObject(node)
remove_names.append(node_name)
# remove the nodes from the scene by name
fbx_file.remove_nodes_by_names(remove_names)
# remove display layers
# For some reason these change FbxCollection ID and NodeName
layer_nodes = fbx_file.get_class_nodes(fbx.FbxCollectionExclusive.ClassId)
if layer_nodes:
remove_layers(fbx_file, layer_nodes)
# remove FbxContainers
nodes = fbx_file.get_class_nodes(fbx.FbxObject.ClassId)
if nodes:
for node in fbx_objects:
if node.GetClassId().GetName() == 'FbxContainer':
# disconnect the layer from the scene
node.DisconnectAllDstObject()
node.DisconnectAllSrcObject()
fbx_file.scene.RootProperty.DisconnectSrcObject(node)
# remove display layers
display_layers = fbx_file.get_type_nodes( u'DisplayLayer')
if display_layers:
remove_layers(fbx, display_layers)
# save the modified fbx scene
fbx_file.save()
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment