Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® FBX® / FBX SDK / Strange vertex cache behavior
  RSS 2.0 ATOM  

Strange vertex cache behavior
Rate this thread
 
51783
 
Permlink of this thread  
avatar
  • Location: Midvale, UT
  • Total Posts: 144
  • Joined: 25 March 2010 10:49 AM

Howdy,

Something seems strange with importing and exporting a vertex cache. It seems that I can only get it to work when there is another animated object in the file. If I try to export a vertex cache as the only element in the exported file, it won’t import.

For example, if I comment out everything except the Triangle object in the ExportScene03 example like this:

bool CreateScene(KFbxSdkManagerpSdkManagerKFbxScenepScenecharpSampleFileName)
{
    
//KFbxNode* lCube = CreateCubeWithTexture(pSdkManager, "Cube");
    //KFbxNode* lPyramid = CreatePyramidWithMaterials(pSdkManager, "Pyramid");
    
KFbxNodelTriangle CreateTriangle(pSdkManager"Triangle");
    
//KFbxNode* lMyKFbxMeshCube = CreateCubeWithMaterialAndMyKFbxMesh(pSdkManager, "CubeMyKFbxMesh");
    //MyFbxObject* lMyFbxObject = MyFbxObject::Create(pSdkManager, "MyFbxObject 1");

    //MapShapeOnPyramid(pSdkManager, lPyramid);
    
MapVertexCacheOnTriangle(pSdkManagerlTrianglepSampleFileName);

    
//SetCubeDefaultPosition(lCube);
    //SetPyramidDefaultPosition(lPyramid);
    
SetTriangleDefaultPosition(lTriangle);
    
//SetMyKFbxMeshCubeDefaultPosition(lMyKFbxMeshCube);

    //Animate(lCube);
    //Animate(lPyramid);
    //Animate(lMyKFbxMeshCube);
    
switch(gCacheType)
 
{
 
case 0:
 default:
 
AnimateVertexCacheOnTriangleDoubleVertex(lTriangleKTime::GetFrameRate(pScene->GetGlobalTimeSettings().GetTimeMode()));
 break;
 case 
1:
 
AnimateVertexCacheOnTriangleInt32(lTriangleKTime::GetFrameRate(pScene->GetGlobalTimeSettings().GetTimeMode()));
 break;
    
}

    
// Build the node tree.
    
KFbxNodelRootNode pScene->GetRootNode();
    
//lRootNode->AddChild(lCube);
    //lRootNode->AddChild(lPyramid);
    //lRootNode->AddChild(lMyKFbxMeshCube);
    
lRootNode->AddChild(lTriangle);
    
//lRootNode->ConnectSrcObject(lMyFbxObject);

    // Identify current take when file is loaded.
    
pScene->SetCurrentTake("Show all faces");

    
//Create a simple animated fcurve
    /*KFbxProperty lMyProperty = lMyFbxObject->FindProperty("MyAnimatedPropertyName");
    if( lMyProperty.IsValid() )
    {
        lMyProperty.Set(0.0);   //Default value
        lMyProperty.ModifyFlag(KFbxProperty::eANIMATABLE, true);
        lMyProperty.CreateKFCurveNode();
        KFCurve* lMyFCurve = lMyProperty.GetKFCurve();
        if( lMyFCurve )
        {
            lMyFCurve->KeyAppendFast(KTIME_ZERO, -100);
            lMyFCurve->KeyAppendFast(KTime(100), 0);
            lMyFCurve->KeyAppendFast(KTime(200), 100);
        }
    }*/

    
return true;
}

... then when I try to import it, the mesh is imported without the vertex cache, and the animation take length is 0.

Here is my code to get the take length:

int GetTakeLength(int ind)
{
 int numFrames 
0;
 
 
KTime::ETimeMode tMode pScene->GetGlobalTimeSettings().GetTimeMode();
 
 
float frameRate GetFrameRate(tMode);
 
 
KTime gPeriodcurrentTime;
 
gPeriod.SetTime(0,0,0,1,0,tMode);
 
 
KFbxTakeInfo *lCurrentTakeInfo pScene->GetTakeInfo(*gTakeNameArray[ind]);
 
 if(
lCurrentTakeInfo)
 
{
 pScene
->SetCurrentTake(gTakeNameArray[ind]->Buffer());
 
 
KTime gStart lCurrentTakeInfo->mLocalTimeSpan.GetStart();
 
KTime gStop lCurrentTakeInfo->mLocalTimeSpan.GetStop();
 
 
KTime timeDiff gStop gStart;
 
double diff timeDiff.GetSecondDouble();
 
 
numFrames = (int)(diff frameRate);
 
}
 
 
return numFrames;
}

If I uncomment just one other object from the ExportScene03 example, for example, uncomment the cube, then the file imports correctly with the cube’s animation and the triangle’s vertex cache.

The ViewScene example also has trouble correctly importing the vertex cache alone, but with the cube added to the scene, then it will import the file correctly.

It’s odd though that Maya PLE will correctly import the triangle with its vertex cache alone.

What do I need to do to get this working correctly?

Adios,
Cactus Dan



Replies: 2
/userdata/avatar/vx3501hqr_small.jpg

Hello, the vertex cache animation is not a take, all its animation info is recorded in the cache file.
So for a fbx file that only contains an object with animation cache, for sure you will get 0 if you try to get the animation length from take. The correct way to get the animation length in this case is to parse the cache file and get the animation start and stop time there.

For the ViewScene, I cannot reproduce the issue you describe and here is my test result with FBX SDK 2010.2:
1. Do not change any code of ExportScene03, import the exported fbx file ExportScene03_MC.fbx to ViewScene, and check the triangle, it will keep scaling down until it totally disappears and then do this animation again.
2. Change code of ExportScene03 as you stated to only keep the triangle, import the exported file to ViewScene, and check the triangle, it will still scaling down a while, but only scale down 1/3 and then bounce back to original size immediately.

This is caused by TakeSelectionCallback, in case 1, there exists a take, it will get start/stop of the animation from the take, in case 2, there is no take (although there is a vertex cache), so it will use the default time stored in global settings, so only play the animation for 1 second.

This is a problem and I will log a suggestion to make ViewScene check the cache animation length properly. Thanks for your report.
But in you case, if you get the animation length from the cache file in your own plug-in, then there should be no this problem.

I also did the above test in 2011.3.1 and the newest code, the same result.

Author: Jiayang Xu

Replied: 14 February 2011 06:03 PM  
/userdata/avatar/vx3501hqr_small.jpg

Please give a try to KFbxCache::GetAnimationRange to get the animation length of the vertex cache.

Author: Jiayang Xu

Replied: 14 February 2011 06:46 PM