A KFbxNodeAttribute is paired with a KFbxNode to define a scene element with a specific position, rotation and scale. Calling KFbxNode::GetNodeAttribute() will return NULL if no node attribute was set for that node.
The following code sample (adapted from ExportScene04/main.cxx to fit the diagram above) illustrates how to create a simple spotlight within a scene. Here, KFbxLight* light is the node attribute of KFbxNode* lightNode. For more information on lights, see Lights.
// Create a spotlight.
KFbxNode* CreateLight(KFbxScene* pScene, char* pName)
{
KFbxLight* light = KFbxLight::Create(pScene,pName);
light->LightType.Set(KFbxLight::eSPOT);
light->CastLight.Set(true);
KFbxNode* lightNode = KFbxNode::Create(pScene,pName);
lightNode->SetNodeAttribute(light);
return lightNode;
}The following table presents a set of basic scene elements and their related KFbxNodeAttribute subclasses. These node attributes can be paired with a KFbxNode using KFbxNode::SetNodeAttribute(). Consult the C++ Reference guide for the full class hierarchy.
| Scene Element | KFbxNodeAttribute subclass |
|---|---|
| Camera | KFbxCamera, KFbxCameraStereo |
| Camera Switcher (custom camera definition in Autodesk MotionBuilder) | KFbxCameraSwitcher |
| Line | KFbxLight |
| Mesh | KFbxMesh |
| Nurb | KFbxNurb, KFbxNurbsCurve, KFbxNurbsSurface, KFbxTrimNurbsSurface |
| Patch / Parametric Surface | KFbxPatch |
| Level of Detail Group | KFbxLodGroup |
| Marker | KFbxMarker |
| Skeleton | KFbxSkeleton |
The type (KFbxNodeAttribute::EAttributeType) of a KFbxNodeAttribute can be obtained by calling KFbxNodeAttribute::GetAttributeType(). The EAttributeType is useful for downcasting the node attribute object to its appropriate subclass.
The following code sample (adapted from ImportScene/main.cxx and ImportScene/DisplayLight.cxx) illustrates how to use a switch to display a KFbxLight contained in a KFbxNode.
//
// Adapted from ImportScene/DisplayLight.cxx ...
// Display the various properties of the KFbxLight contained within the KFbxNode.
//
void DisplayLight(KFbxNode* pNode)
{
KFbxLight* lLight = (KFbxLight*) pNode->GetNodeAttribute();
DisplayString("Light Name: ", (char *) pNode->GetName());
// ...
char* lLightTypes[] = { "Point", "Directional", "Spot" };
DisplayString(" Type: ", lLightTypes[lLight->LightType.Get()]);
DisplayBool(" Cast Light: ", lLight->CastLight.Get());
if (!(lLight->FileName.Get().IsEmpty()))
{
DisplayString(" Gobo");
DisplayString(" File Name: \"", lLight->FileName.Get().Buffer(), "\"");
DisplayBool(" Ground Projection: ", lLight->DrawGroundProjection.Get());
DisplayBool(" Volumetric Projection: ", lLight->DrawVolumetricLight.Get());
DisplayBool(" Front Volumetric Projection: ", lLight->DrawFrontFacingVolumetricLight.Get());
}
// ...
}
//
// Adapted from ImportScene/main.cxx ...
// Display the contents of a node. Here, we are only interested in
// looking at the eLight attribute type, which coincides with the
// KFbxLight node attribute.
//
void DisplayContent(KFbxNode* pNode)
{
KFbxNodeAttribute::EAttributeType lAttributeType;
int i;
if(pNode->GetNodeAttribute() == NULL)
{
printf("NULL Node Attribute\n\n");
}
else
{
lAttributeType = (pNode->GetNodeAttribute()->GetAttributeType());
switch (lAttributeType)
{
// ...
case KFbxNodeAttribute::eLIGHT:
DisplayLight(pNode);
break;
// ...
}
}
// ...
for(i = 0; i < pNode->GetChildCount(); i++)
{
DisplayContent(pNode->GetChild(i));
}
}