Search code examples
javaunity-game-enginemayafbx3d-model

How can I get the names of all nodes or polygons from an fbx file?


I have a 3D character model saved in an FBX format. I want to know the list of names for each model or joint so I can decide if that part of the character is relevant to me or not. I am not using Maya software. I got the 3D model from a third party and I am going to use that model for animation in unity3D but before importing the model in unity3d, I want to know the model label like hair, head etc so is there any way to get the label programmatically from FBX file? Thanks


Solution

  • About FBX format

    "FBX" is a compiled format, created by Autodesk, that can be utilized by a number of 3D Softwares even though FBX is a proprietary file format. Because it is compiled, you will end up with a wide-range of "NULL" format symbols; I.E. -

    €«±µÈ7L—C«‚›ìŸn»yàn´ZÌ'>ï¯Óp>¸z±ú‘uá#OFªƒû·Pð>U>j}jp[7)
    

    Because of this, it is better to either export as a DAE / Collada format or OBJ format if you are not utilizing bone structures.

    About Collada / DAE_FBX / DAE format

    This format is open source and was typically used for video games in the past. The file is an XML based file and should be easy to manipulate in Java / JavaScript. Because of this, the file offers full support for opening the file up in your favorite notepad program / app... or even your favorite programming language.

    Utilizing this format, your geometry will be listed under the child "geometry".

    Potential Solution (Python in Maya)

    If you are using Maya and can inject a bit of code in before exporting the FBX file... Try running this before export (Python):

    import maya.cmds as cmds
    
    # Create the location and fileName
    yourDesktopVar = "C:\\Users\\[Your user]\\Desktop\\"
    saveFileName   = "Joints_Models_Groups.txt"
    documentToSave = open((yourDesktopVar + saveFileName), "w")
    
    # Setup arrays full of relative information
    
    jointNames     = [jn for jn in cmds.ls(type = "joint")]
    meshNames      = [cmds.listRelatives(mn, parent=1)[0] for mn in cmds.ls(type = "mesh")]
    
    # ================================
    # Writing Joints
    # ================================
    
    documentToSave.write("Joints\n\r")
    documentToSave.write("--------------")
    
    for eachJointName in jointNames:
        documentToSave.write(eachJointName + "\n\r")
    
    # Create a blank space
    documentToSave.write("\n\r\n\r)
    
    # ================================
    # Writing Meshes
    # ================================
    documentToSave.write("Meshes\n\r")
    documentToSave.write("--------------")
    
    for eachMeshName in meshNames:
        documentToSave.write(eachMeshName + "\n\r")
    

    Obviously, you'll have to edit this to fit your format, but this will crank out a basic text document that should give you enough information to start with.