Hi,
One solution for your case 1: can be:
FbxArray<FbxObject*> candidate_to_destroy;
for (int t = 0, count = lScene->GetSrcObjectCount<FbxTexture>(); t < count; t++)
{
FbxTexture* tex = lScene->GetSrcObject<FbxTexture>(t);
if (tex->GetDstPropertyCount() == 0)
{
candidate_to_destroy.Add(tex);
// the Texture object is not connected to any property
// Now get all the connected FbxVideo objects
for (int v = 0, vcount = tex->GetSrcObjectCount<FbxVideo>(); v < vcount; v++)
{
FbxVideo* vid = tex->GetSrcObject<FbxVideo>(v);
FbxObject* d1 = NULL;
FbxObject* d2 = NULL;
bool cant_delete = false;
switch (vid->GetDstObjectCount())
{
case 2:
d2 = vid->GetDstObject(1);
case 1:
d1 = vid->GetDstObject(0);
break;
default:
cant_delete = true;
}
if (cant_delete)
continue;
// make sure the only 2 destination connections are to the scene and tex
if ((d1 == tex && (d2 == NULL || d2 == lScene)) || (d1 == lScene && d2 == tex))
{
candidate_to_destroy.Add(vid);
}
}
}
}
for (int i = 0; i < candidate_to_destroy.GetCount(); i++)
{
candidate_to_destroy[i]->Destroy();
}
remark that the same approach can also be applied for FbxSurfaceMaterials (or almost any other type of objects), the general idea when you want to remove objects from the scene is to make sure there are no other connections to it. The Destroy() method takes care of disconnecting and, when possible, automatically delete other connected objects. (for example: when destroying an FbxNode, the FbxMesh connected to it will also be destroyed if it its last reference). An FbxSurfaceMaterial however, because it is most likely shared by several objects is only disconnected.
For case 2: you can simply do:
node->Destroy();
to remove the FbxNode from the scene and then use a similar loop as above to find "orphan" materials (meaning that they don't have multiple connections anymore). Note that FbxObjects often have a DstConnection to the scene as well as connections to other objects.
Hope this helped!