FBX Properties
 
 
 

Managing Properties

The KFbxProperty template class is used to ensure that the data of a KFbxObject is strongly typed. For example, the local translation vector of a KFbxNode is described using a KFbxTypedProperty which is parametrized for fbxDouble3.

When a KFbxObject is created, its static built-in KFbxPropertys are automatically initialized. To create your own KFbxProperty, you must invoke KFbxProperty::Create(), and pass either a reference to a KFbxObject, or to another KFbxProperty.

The following code sample was taken from the Animation example. In this sample, the first parameter of KFbxProperty::Create() is a KFbxScene object. The second parameter is the datatype of the property (a full list of datatypes can be found in the kfbxdatatypes.h header file). The third parameter is the assigned name of the property.

KFbxProperty p = KFbxProperty::Create(pScene, DTDouble3, "Vector3Property");
KFbxSet<fbxDouble3>(p, fbxDouble3(1.1, 2.2, 3.3);

The name with which a KFbxProperty is created can be accessed by calling KFbxProperty::GetName(). This name can be used to search for a property within a hierarchy (see Property Hierarchy).

An instance of KFbxProperty can be destroyed by calling KFbxProperty::Destroy(). A hierarchy of KFbxProperty can be destroyed by invoking KFbxProperty::DestroyRecursively() on the root property.

Property Data

Instances of KFbxProperty contain data which can be set and accessed by respectively calling KFbxProperty::Set() and KFbxProperty::Get(). For example, the KFbxNode geometric transformation data, represented as vectors of fbxDouble3, can be accessed in the following way:

// ... initialize KFbxNode* lNode ...
fbxDouble3 translation = lNode->LclTranslation.Get();
fbxDouble3 rotation = lNode->LclRotation.Get();
fbxDouble3 scaling = lNode->LclScaling.Get();

The data contained within a KFbxTypedProperty can only be set to a value that is valid for the property's data type. Some implicit conversions are supported; you can, for example, provide an int when a double is required.

Flags

Properties also contain a set of KFbxPropertyFlags::eFbxPropertyFlags which can be manipulated using KFbxProperty::GetFlag() and KFbxProperty::ModifyFlag().

Operators

The standard comparison and assignment operators can be used to compare and assign properties to one another (KFbxProperty::operator==(), KFbxProperty::operator!=(), KFbxProperty::operator=()).

User-defined Data

The KFbxProperty class can contain user-defined data, which can be dynamically associated to a KFbxObject at runtime. An example of this can be found in the UserProperties example.

Property Hierarchy

Properties can be organized in a hierarchy. A KFbxProperty can be connected to a KFbxObject, or to another KFbxProperty. The bound KFbxObject of the property can be accessed by invoking KFbxProperty::GetFbxObject(). The ExportScene05 example illustrates the construction of a property hierarchy.

Accessing an FBX Object's Properties

An FBX object can have many properties, which can be searched for using KFbxObject::FindProperty(). An object's properties can also be iterated by invoking methods such as KFbxObject::GetFirstProperty(), and KFbxObject::GetNextProperty().

NoteThe class documentation of KFbxIOSettings provides useful insight into the organization of its property hierarchy.

Navigating a Property Hierarchy

A hierarchy of FBX properties can be traversed by means of the FBX property navigation functions: KFbxProperty::GetParent(), KFbxProperty::GetChild(), KFbxProperty::GetSibling(), KFbxProperty::Find(), to name but a few.

NoteThe Connections topic provides more information on how to navigate between objects and property hierarchies.

Sample Code

The following sample code was taken from the ExportScene05 example. It illustrates how to create your own KFbxProperty values, and bind them to a KFbxObjectMetaData instance (which inherits from KFbxObject).

// ... initialize pScene as a KFbxScene* ...

// Create a KFbxObjectMetaData* object in pScene.
KFbxObjectMetaData* lFamilyMetaData = KFbxObjectMetaData::Create(pScene, "Family");

// Create and assign data to several instances of KFbxProperty, based on their parametrized
// datatypes (DTString, DTFloat, DTDouble). 
//
// The fourth parameter is an optional label string, which can be obtained and modified
// using KFbxProperty::GetLabel() and KFbxProperty::SetLabel(). This label only exists
// in the program's main memory, and will not be exported to a file if/when the property
// is exported.
// 
// These properties will be contained within the pFamilyMetaData object.
//
KFbxProperty::Create(lFamilyMetaData, DTString, "Level", "Level").Set(KString("Family")); // String
KFbxProperty::Create(lFamilyMetaData, DTString, "Type", "Type").Set(KString("Wall"));     // String
KFbxProperty::Create(lFamilyMetaData, DTFloat, "Width", "Width").Set(10.0f);              // float
KFbxProperty::Create(lFamilyMetaData, DTDouble, "Weight", "Weight").Set(25.0);            // double
KFbxProperty::Create(lFamilyMetaData, DTDouble, "Cost", "Cost").Set(1.25);                // double