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 / Problem reading vertex animation data from geometry cache written by Maya2012
  RSS 2.0 ATOM  

Problem reading vertex animation data from geometry cache written by Maya2012
Rate this thread
 
64096
 
Permlink of this thread  
avatar
  • mfritzen
  • Posted: 01 February 2012 09:07 PM
  • Total Posts: 10
  • Joined: 16 September 2009 05:08 PM

Hi folks,

I got an really annoying problem when importing vertex animation data, but first I want to describe what I have done so far.

In Maya I have a scene with vertex animations. For exporting this animations I created a Set for my animated object. I also created a new geometry cache for it. After finishing that I exported my scene to fbx checking the option “Geometry Cache Files” with my created set in the “Animation” frame. So far everything works as expected. The fbx file is created as well as a xml and mc file.

No my problem. In my importer I am doing such things as described in the ReadVertexCacheData function of the ViewScene Example....

KFbxVertexCacheDeformerlDeformer     static_cast<KFbxVertexCacheDeformer*>(pMesh->GetDeformer(0KFbxDeformer::eVERTEX_CACHE));
    
KFbxCache*               lCache        lDeformer->GetCache();
    
int                      lChannelIndex = -1;
    
unsigned int             lVertexCount  = (unsigned int)pMesh->GetControlPointsCount();
    
bool                     lReadSucceed  false;
    
double*                  lReadBuf      = new double[3*lVertexCount];

    if (
lCache->GetCacheFileFormat() == KFbxCache::eMC)
    
{
        
if ((lChannelIndex lCache->GetChannelIndex(lDeformer->GetCacheChannel())) > -1)
        
{
            lReadSucceed 
lCache->Read(lChannelIndexpTimelReadBuflVertexCount);
        
}
    }
    
else // ePC2
    
{
        lReadSucceed 
lCache->Read((unsigned int)pTime.GetFrame(true), lReadBuflVertexCount);
    
}

    
if (lReadSucceed)
    
{
        unsigned int lReadBufIndex 
0;

        while (
lReadBufIndex 3*lVertexCount)
        
{
            
// In statements like "pVertexArray[lReadBufIndex/3].SetAt(2, lReadBuf[lReadBufIndex++])", 
            // on Mac platform, "lReadBufIndex++" is evaluated before "lReadBufIndex/3". 
            // So separate them.
            
pVertexArray[lReadBufIndex/3].SetAt(0lReadBuf[lReadBufIndex]); lReadBufIndex++;
            
pVertexArray[lReadBufIndex/3].SetAt(1lReadBuf[lReadBufIndex]); lReadBufIndex++;
            
pVertexArray[lReadBufIndex/3].SetAt(2lReadBuf[lReadBufIndex]); lReadBufIndex++;
        
}
    }

    delete [] lReadBuf
;

But every time the line

lChannelIndex lCache->GetChannelIndex(lDeformer->GetCacheChannel())

return -1 for me. What am I doing wrong? I hope someone can give me a hint…

Best regards,
Marcus



Replies: 1
/userdata/avatar/vx3501hqr_small.jpg

Is that possible for you to attach the Maya file and FBX file that can reproduce this issue, then we can have a further investigation.
Thanks.

Author: Jiayang Xu

Replied: 02 February 2012 10:19 PM  
avatar
  • mfritzen
  • Posted: 04 February 2012 04:21 AM

Sure I can. Thanks for your help so far.

You can download the maya and fbx file from my dropbox:
http://dl.dropbox.com/u/55401338/vertexAnim.zip

Another question. Is there any other way to export vertex animations from maya to fbx where all the data is stored in the fbx file itself?



Replies: 2
/userdata/avatar/vx3501hqr_small.jpg

Hello, I cannot reproduce the issue with ViewScene in 2012.2.
It showed the cached animation properly.
So which version of FBX SDK are you using? And the issue seems in your importer, before reach the cache deformer.
My suggestion is you may check where the cache deformer is created, to see if the creation is all normal.

Author: Jiayang Xu

Replied: 07 February 2012 09:53 PM  
/img/forum/dark/default_avatar.png

Thanks so far. You are right. So I took a deeper look at my code and the one form ViewScene and I investigated that the problem is always in front of the computer ;)
I forgot to call the PreparePointCacheData function. After adding this function to my code I do not get -1 for the channel index anymore.
Again thanks for your help,
Marcus

Author: mfritzen

Replied: 08 February 2012 02:17 AM  
avatar
  • mfritzen
  • Posted: 09 February 2012 07:37 AM

Hi again,

so far I am able to import vertex animations into my application. What is missing are the normals. How do I get the values for these?

I read another post where it is suggested to use the ComputeVertexNormals function of KFbxMesh. But with that I get to another problem. When I use this function I have to check “split per-vertex normals” in the fbx exporter in maya (because I do not have multi index vertices in my application). If I do so, new vertices are generated which lead to an inconsistent amount of vertices in the fbx file and the cache file. E.g. I have a cube with 8 vertices. I animate one of it and create a geometry cache. Now my cache file is referencing 8 vertices. I export the scene using split per-vertex normals which generates new vertices. Now the fbx file contains 24 vertices but my cache file is still referencing 8.

So what is the correct solution for getting the normal values for a specific time? Is there an example where also the normales are included when generating an vertex animation?

Any help is very appreciated.
Marcus



Replies: 2
/userdata/avatar/vx3501hqr_small.jpg

To me it looks like a issue of your application. Because ComputerVertexNormal will give you normals of 8 vertices and the cache file also reference 8 vertices, they are match.
So in your application it need to be able to map the 8 vertices to 24 polygon vertices. And I think FBX already keep this kind of informations as PolygonVertexIndex.

Also there are several other ways to deal this:
1. Split the mesh in Maya first, to make sure the generated cache are also by per polygon vertices, in this example, with 24 vertices. Then export FBX file with “split per-vertex normals” on.
2. In you application, you can set same normal for the vertices that are taken as one vertex in Maya/FBX. In the cube example, in your application there are 24 vertices, but in FBX files, there are only 8 normals, so actually there are 3 vertices in your application should have the same normal, just find them and map the same normal.

All in all, the purpose is to make the number of vertices, normals and cache points match.

Author: Jiayang Xu

Replied: 09 February 2012 07:38 PM  
/img/forum/dark/default_avatar.png

Thanks again.

For everyone who is interested in, here is the way which is working for me (in most cases):

1. create the geometry cache in maya with shared control points. Export the file to fbx.
2. in my application I do not use shared control points. so store the shared indices in a map or whatever when importing the geometry.
3. iterate over the time interval and create the animation curve control points from the values stored in the cache.
4. actually the vertex values are transformed. so compute new normals using the fbx function mesh->ComputeVertexNormals();
5. get the polygon vertex and also create an animation curve control point for these values.

If there are further questions feel free to ask.

Author: mfritzen

Replied: 20 February 2012 07:37 PM