Skip to content

Instantly share code, notes, and snippets.

@Meatplowz
Last active November 29, 2019 08:08
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/dc1bd17d34be09c63eff843a8eeb79ea to your computer and use it in GitHub Desktop.
Save Meatplowz/dc1bd17d34be09c63eff843a8eeb79ea to your computer and use it in GitHub Desktop.
def unparent_nodes(fbx_filename):
'''
Unparent Hiearchy Nodes
In an effort to clean your fbx scene
This code is looking for specific nodes in your scene
In my example I have a heirarchy that houses an entire character or weapon
Character
-> Rig_Group
-> Bind_Skeleton (root)
-> Meshes_Group
Weapon
-> Rig_Group
-> Bind_Skeleton (root)
-> Meshes_Group
My intention is to get the Bind Skeleton and Meshes_Group into the scene world depending on animation or skeletal mesh export
You could additionally find parent nodes to unparent based on a given name or attributes and traverse up from there.
'''
# open the fbx scenes and get the scene nodes
fbx_source = FBX( fbx_filename )
if not fbx_source:
return False
# remove namespaces
fbx_source.remove_namespace()
source_nodes = fbx_source.get_scene_nodes( )
# unparent joints from the dummy group
for source_node in source_nodes:
if source_node.GetName() == 'Character' or source_node.GetName() == 'Weapon':
if source_node.GetTypeName() == 'Null':
children = []
for child_index in range(0, source_node.GetChildCount()):
child_node = source_node.GetChild(child_index)
children.append(child_node)
# parent children to scene root
for node in children:
fbx_source.root_node.AddChild(node)
break
# remove the nodes from the scene by name
remove_names = ['Character', 'Weapon']
fbx_source.remove_nodes_by_names( remove_names, remove_tags = False )
save_scene = fbx_source.save_scene_file( filename= output_file )
if save_scene:
return True
else:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment