Instancing - Sharing a Mesh

To reduce memory requirements, a single instance of FbxMesh can be bound to multiple instances of FbxNode. Imagine that you need a program where all cubes looked alike, but you needed many thousands of them. You could save memory by creating one FbxMesh object when the program starts up. Then, every time you needed a new cube, you create a new FbxNode object, then point that node to the one mesh. This is called instancing.

In general, you can save memory by having many node objects share one node attribute object (i.e., one object of any subclass of FbxNodeAttribute). The following function illustrates how to bind a FbxMesh to a newly created node.

// Create a cube instance with the given mesh as node attribute, and add it to the scene.
FbxNode* CreateCubeInstance(FbxScene* pScene, const char* pName, FbxMesh* pFirstCube)
{
    // create a FbxNode
    FbxNode* lNode = FbxNode::Create(pScene,pName);

    // set the node attribute
    lNode->SetNodeAttribute(pFirstCube);

    // rescale the cube
    lNode->LclScaling.Set(FbxVector4(0.3, 0.3, 0.3));

        // Add node to the scene
    pScene->GetRootNode()->AddChild(lNode);

    // return the FbxNode
    return lNode;
}

Each node is an instance of the mesh, NURBS, or other scene element. If you export your scene to an FBX file, instancing also reduces the file size. You can also save memory by having multiple nodes share textures, materials, animation curves, etc.