FbxCharacter (object)

The FbxCharacter object manages loading character data from an Fbx file.

Check http://softimage.wiki.softimage.com/xsidocs/shape_anim_CreatingShapesintheShapeModelingConstructionModes.html.

If the Fbx file contains animation, and FbxClip object is automatically constructed and ClipPose assigned to drive the pose of the character.

/*
** Example: fbxCharacter.kl
*/

require Fbx, FbxHelpers;

operator entry(){

  FilePath path = FilePath("${FABRIC_SCENE_GRAPH_DIR}/Python/Apps/Resources/Fbx/BendyBox.fbx").expandEnvVars();
  FbxCharacter fbxCharacter(path.string());
  report(fbxCharacter.getDesc('', false));
}

/*
** Output:

Character:{ 
  name: BendyBox 
  skeleton:  Skeleton { 
    name: BendyBox 
    bones:[ 
      Bone { 
        name: Point001
        length: -10.29878
        radius: +0.514939
        parent: -1
        childIndices: [1]
        mirrorBoneID: -1
        flags: 0
        color: {r:+1.0,g:+1.0,b:+0.0,a:+1.0}
        referencePose: {tr:{x:+10.21484,y:+0.0,z:-0.806396},ori:{v:{x:-0.707153,y:+0.0,z:+0.0},w:+0.707153},sc:{x:+1.0,y:+1.0,z:+1.0}}
      } 
      Bone { 
        name: Bone001
        length: +6.880934
        radius: +0.686582
        parent: 0
        childIndices: [2]
        mirrorBoneID: -1
        flags: 8
        color: {r:+1.0,g:+1.0,b:+0.0,a:+1.0}
        referencePose: {tr:{x:-0.084045,y:-0.609497,z:-2.664455e-8},ori:{v:{x:+0.436697e-5,y:+0.426173e-5,z:+0.701782},w:+0.712402},sc:{x:+1.0,y:+1.0,z:+1.0}}
      } 
      Bone { 
        name: Bone002
        length: +5.160701
        radius: +0.644237
        parent: 1
        childIndices: []
        mirrorBoneID: -1
        flags: 8
        color: {r:+1.0,g:+1.0,b:+0.0,a:+1.0}
        referencePose: {tr:{x:+1.864624e-2,y:+6.270508,z:+2.740998e-7},ori:{v:{x:-0.694708e-7,y:-0.694708e-7,z:+0.707153},w:+0.707153},sc:{x:+1.0,y:+1.0,z:+1.0}}
      } 
    ]
  } 
  pose:  Pose { 
    clip:     FbxClip { 
      animationLayerName: 
      Clip:{ 
        Bone002:        KeyframeTrackSet { 
          name: Bone002,
          valueType: Euler,
          flags: 8,
          tracks:[ 
            KeyframeTrack { 
              name: "euler.x",
              color: {r:+1.0,g:+0.0,b:+0.0,a:+1.0},
              defaultValue: +0.0,
              numKeys:3,
            },
            KeyframeTrack { 
              name: "euler.y",
              color: {r:+0.0,g:+1.0,b:+0.0,a:+1.0},
              defaultValue: +0.0,
              numKeys:3,
            },
            KeyframeTrack { 
              name: "euler.z",
              color: {r:+0.0,g:+0.0,b:+1.0,a:+1.0},
              defaultValue: +0.0,
              numKeys:3,
            },
          ],
        },
      }
    }
 
    xfos:[ 
    Point001:{tr:{x:+10.21484,y:+0.0,z:-0.806396},ori:{v:{x:-0.707153,y:+0.0,z:+0.0},w:+0.707153},sc:{x:+1.0,y:+1.0,z:+1.0}}
    Bone001:{tr:{x:-0.084045,y:-0.609497,z:-2.664455e-8},ori:{v:{x:+0.436697e-5,y:+0.426173e-5,z:+0.701782},w:+0.712402},sc:{x:+1.0,y:+1.0,z:+1.0}}
    Bone002:{tr:{x:+1.864624e-2,y:+6.270508,z:+2.740998e-7},ori:{v:{x:-0.694708e-7,y:-0.694708e-7,z:+0.707153},w:+0.707153},sc:{x:+1.0,y:+1.0,z:+1.0}}
    ]
  } 
  num geometries:1 
}

*/

Geometries in the file that are bound to deformers are gathered and a union of all the deformers is generated. This union is used to generate a Skeleton. The skinning binding indices are remapped to index into the union of joints assigned to the skeleton. This grouping of deformers means that only one pose value must be managed per character and the pose uploaded to the GPU during GPU based rendering. All deformed geometries can then be deformed using the same computed pose texture on the GPU.

/*
** Example: fbxDeformingMesh.kl
*/

require Fbx, FbxHelpers;

operator entry(){
  FilePath path = FilePath("${FABRIC_SCENE_GRAPH_DIR}/Python/Apps/Resources/Fbx/BendyBox.fbx").expandEnvVars();
  FbxCharacter fbxCharacter(path.string());

  ClipPose pose = fbxCharacter.getPose();
  Vec2 timeRange = pose.getClip().getTimeRange();
  report("timeRange:" + timeRange);

  Integer numSamples = 6;
  for(Integer i=0; i<numSamples; i++){
    Scalar time =  Math_linearInterpolate(timeRange.x, timeRange.y, Scalar(i)/Scalar(numSamples));
    
    pose.evaluate(time);

    // Retrieve the deformed geom from the character
    Geometry deformedGeom = fbxCharacter.getDeformedGeometry(0);
    Vec3Attribute positionsAttribute = deformedGeom.getAttributes().positionsAttribute;
    String positionsStr;
    for(Integer j=0; j<6; j++){
      if(j>0)
        positionsStr += ", ";
      positionsStr += positionsAttribute.values[ floor(j * (1.0 / positionsAttribute.values.size())) ];
    }
    report("Deformed Position Values:" + positionsStr);
  }
}

/*
** Output:

timeRange:{x:+0.0,y:+3.333}
Deformed Position Values:{x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}
Deformed Position Values:{x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}
Deformed Position Values:{x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}
Deformed Position Values:{x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}
Deformed Position Values:{x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}
Deformed Position Values:{x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}, {x:-2.55672,y:-3.702378e-7,z:+2.382537}

*/

FbxCharacter FbxCharacter FbxCharacter Character Character FbxCharacter->Character ICharacter ICharacter Character->ICharacter

Members

String name The name of the character.
Geometry[] geometries The array fo geometries that make up the character
Mat44[] bindShapeTransforms  
Mat44[] skinningMatrices  
Skeleton skeleton The Skeleton defining the hierarchy of bones of the character.
IPose pose The pose of the character.
Xfo globalXfo The global transform of the character.
Geometry[] deformedGeometries The cache of deformed geometries that make up the character. When deforming on the CPU, we cache the cloned meshes here.
LocalBoundingVolume localBVol The bounding volume of the deformed character.
String filePath the file path of the fbx file.
FbxHandle handle The opened FbxHandle
ImporterIdentifier[] identifiers All the identifiers extracted from the fbx file.
ImporterIdentifier[] skinMeshIdentifiers The skinned mesh identifiers extracted from the fbx file.
ImporterIdentifier[] deformerIdentifiers The deformer mesh identifiers extracted from the fbx file.
ImporterIdentifier[] boneIdentifiers The final iunion of all identifiers used to generate the skeleton
String[] includedBones An array of joints which must be included in the skeleton
String[] includedSubtrees An array of joints whose subtrees must be included in the skeleton
Color[String] chainColors A dictionary of colors to assign the bone chains. Only the root of a given chain needs to be specified, and all children willl be assigned the color. Colors can be overridden at any point in the hierarchy.
Color[String] suffixColors A dictionary of name suffixes used to generate bone colors. All joints whose names end in a specified suffix will be assigned the mapped color. The suffixColors override the chainColors.

Methods

  FbxCharacter ( in FbxCharacter other )
  FbxCharacter ( in String filePath )
  FbxCharacter ()
FbxCharacter clone ? ()
Index findGeometryIndex ? ( in String name )
Box3 getBoundingBox ! ()
Box3 getBoundingBoxAtIndex ! ( in Index index )
String getFilePath ? ()
FbxHandle getHandle ? ()
Boolean initialized ? ()
  setupFromAnimatedPose ! ( in String filePath, in Scalar scaleFactor )
Character toCharacter ? ()

Methods in detail

FbxCharacter ( in FbxCharacter other )

copy constructor


FbxCharacter ( in String filePath )

Constructor taking a file path to load the fbx file on disk


FbxCharacter ()

Constructor taking a file path to load the fbx file on disk


FbxCharacter FbxCharacter.clone? ()

clone method


Index FbxCharacter.findGeometryIndex? ( in String name )

Returns a geometry with the given name.


Box3 FbxCharacter.getBoundingBox! ()

Get the bouding box


Box3 FbxCharacter.getBoundingBoxAtIndex! ( in Index index )

Get the bouding box at index

The geometry index


String FbxCharacter.getFilePath? ()

Returns the file path of the fbx file.


FbxHandle FbxCharacter.getHandle? ()

returns the fbx handle


Boolean FbxCharacter.initialized? ()

Returns true if the file was successfully opened.


FbxCharacter.setupFromAnimatedPose! ( in String filePath, in Scalar scaleFactor )

sets up the FBXCharacter with a animated pose


Character FbxCharacter.toCharacter? ()

returns this FBXCharacter as a character