A FbxNodeAttribute is paired with a FbxNode to define a scene element with a specific position, rotation and scale. Calling FbxNode::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, FbxLight* light is the node attribute of FbxNode* lightNode. For more information on lights, see Lights.
// Create a spotlight. FbxNode* CreateLight(FbxScene* pScene, char* pName) { FbxLight* light = FbxLight::Create(pScene,pName); light->LightType.Set(FbxLight::eSpot); light->CastLight.Set(true); FbxNode* lightNode = FbxNode::Create(pScene,pName); lightNode->SetNodeAttribute(light); return lightNode; }
The following table presents a set of basic scene elements and their related FbxNodeAttribute subclasses. These node attributes can be paired with a FbxNode using FbxNode::SetNodeAttribute(). Consult the C++ Reference guide for the full class hierarchy.
Scene Element | FbxNodeAttribute subclass |
---|---|
Camera | FbxCamera, FbxCameraStereo |
Camera Switcher (custom camera definition in Autodesk MotionBuilder) | FbxCameraSwitcher |
Light | FbxLight |
Mesh | FbxMesh |
Nurb | FbxNurbs, FbxNurbsCurve, FbxNurbsSurface, FbxTrimNurbsSurface |
Patch / Parametric Surface | FbxPatch |
Level of Detail Group | FbxLodGroup |
Marker | FbxMarker |
Skeleton | FbxSkeleton |
The type (FbxNodeAttribute::EAttributeType) of a FbxNodeAttribute can be obtained by calling FbxNodeAttribute::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 FbxLight contained in a FbxNode.
// // Adapted from ImportScene/DisplayLight.cxx ... // Display the various properties of the FbxLight contained within the FbxNode. // void DisplayLight(FbxNode* pNode) { FbxLight* lLight = (FbxLight*) 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 // FbxLight node attribute. // void DisplayContent(FbxNode* pNode) { FbxNodeAttribute::EAttributeType lAttributeType; int i; if(pNode->GetNodeAttribute() == NULL) { printf("NULL Node Attribute\n\n"); } else { lAttributeType = (pNode->GetNodeAttribute()->GetAttributeType()); switch (lAttributeType) { // ... case FbxNodeAttribute::eLight: DisplayLight(pNode); break; // ... } } // ... for(i = 0; i < pNode->GetChildCount(); i++) { DisplayContent(pNode->GetChild(i)); } }