Area :: Header
Interested in making Indie games?

Register for a Meet the Experts webinar with Digital-Tutors today!
Discussion Groups

FBX SDK

Reply
Contributor
The_Neverending_Loop
Posts: 12
Registered: ‎05-22-2012

Back to square one

26 Views, 5 Replies
06-28-2012 02:56 PM
So I took a break from the SDK after a few uncessful attempts and attended the training seminar they had about a week ago. I started trying to fix my issue again by writing new code from scratch, but unfortunately Im still running into my old issues.

Tidbits to consider...
1. Im only concerned with rigid binding, 1 bone per vertex
2. I need the vertex data in its initial positions, so basically I need the mesh data in world space, as well as the bone data in world space. The code in my game is responsible for converting the vertex data into Bone space.


So to make things easier on myself I'm only concerned with getting the vertices to line up correctly.

This is my code for extracting control points


void ExtractVertexData(FbxMesh* pMesh)
{
int lVertexCount = pMesh->GetControlPointsCount();
FbxVector4* lControlPoints = pMesh->GetControlPoints();

for(int i=0; i < lVertexCount; i++)
{
FbxCluster* lCluster = gWorkingModel.getCluster(i);
FbxVector4 lVert = lControlPoints;
FbxVector4& lDstVertex = lControlPoints;



if(lCluster != NULL && true)
{
printf("VertIndx %i is attached to %s\n", i, lCluster->GetLink()->GetName());
FbxAMatrix lMeshGlobal;
lCluster->GetTransformMatrix(lMeshGlobal);
FbxAMatrix lMeshGeometry = GetGeometry(pMesh->GetNode());
lMeshGlobal *= lMeshGeometry;

lDstVertex = lMeshGlobal.MultT(lVert);

FbxAMatrix lBoneBindingMatrix;
lCluster->GetTransformLinkMatrix(lBoneBindingMatrix);

lDstVertex = lBoneBindingMatrix.Inverse().MultT(lDstVertex); // now it is in bone space

FbxNode* lBoneNode = lCluster->GetLink();
lDstVertex = lBoneNode->EvaluateGlobalTransform().MultT(lDstVertex);


printf("\tlMeshGlobal T\n", lMeshGlobal.GetT(), lMeshGlobal.GetT(), lMeshGlobal.GetT());
printf("\tlMeshGlobal S\n", lMeshGlobal.GetS(), lMeshGlobal.GetS(), lMeshGlobal.GetS());

printf("\lBoneBindingMatrix T\n", lBoneBindingMatrix.GetT(), lBoneBindingMatrix.GetT(), lBoneBindingMatrix.GetT());
printf("\lBoneBindingMatrix S\n", lBoneBindingMatrix.GetS(), lBoneBindingMatrix.GetS(), lBoneBindingMatrix.GetS());

printf("\lBoneBindingMatrix Inverse T\n", lBoneBindingMatrix.Inverse().GetT(), lBoneBindingMatrix.Inverse().GetT(), lBoneBindingMatrix.Inverse().GetT());
printf("\lBoneBindingMatrix Inverse S\n", lBoneBindingMatrix.Inverse().GetS(), lBoneBindingMatrix.Inverse().GetS(), lBoneBindingMatrix.Inverse().GetS());
}


gWorkingModel.addVertex( DogModel::fromFBXVector4(lDstVertex));
}
printf("%i Vertices loaded\n", gWorkingModel.getVertexCount());
}


gWorkingModel is a class (DogModel) I created that stores the information I need for my In Game model format and does the saving for me, it also includes some helper functions.

These helper functions are gWorkingModel.getCluster(i), I specify a vertex index and it returns the cluster associated with that vertex. I also have DogModel::fromFBXVector4() which converts the FbxVector4 to the structure I use.

Ok basically you can see in the if statement
if(lCluster != NULL && true)

when I change the true to false, the vertex data shows up in the dimensions I expect the only thing is it is orientated wrong(its on its side when it should be standing up) and its initial position isnt exactly correct, but other than that it has the shape that its suppose to have.

now when I leave that flag as true the max and min size of the model are far to small, but atleast it is orientated correctly, but I believe that the initial position isnt exactly correct either.



Please note that you see some extra matrix transformations that are not exactly necessary but the thing is I tried a few of the iterations and none of them work correctly so I just started testing other things to see if it would work

 FbxAMatrix lMeshGlobal;
lCluster->GetTransformMatrix(lMeshGlobal);
FbxAMatrix lMeshGeometry = GetGeometry(pMesh->GetNode());
lMeshGlobal *= lMeshGeometry;

lDstVertex = lMeshGlobal.MultT(lVert);

FbxAMatrix lBoneBindingMatrix;
lCluster->GetTransformLinkMatrix(lBoneBindingMatrix);

lDstVertex = lBoneBindingMatrix.Inverse().MultT(lDstVertex); // now it is in bone space

FbxNode* lBoneNode = lCluster->GetLink();
lDstVertex = lBoneNode->EvaluateGlobalTransform().MultT(lDstVertex);


Initially I just wanted world space so I had the transforms up to
 
FbxAMatrix lMeshGlobal;
lCluster->GetTransformMatrix(lMeshGlobal);
FbxAMatrix lMeshGeometry = GetGeometry(pMesh->GetNode());
lMeshGlobal *= lMeshGeometry;

lDstVertex = lMeshGlobal.MultT(lVert);


But the model was far to shrunken so i then proceeded to try changing it to bone space just to see if that gave me what i needed


FbxAMatrix lBoneBindingMatrix;
lCluster->GetTransformLinkMatrix(lBoneBindingMatrix);

lDstVertex = lBoneBindingMatrix.Inverse().MultT(lDstVertex); // now it is in bone space


and the scale problem was fixed by now the mesh was squished together, but the pieces that were squished together looked to be the right size, and in the right orientation.

I then proceeded just for the hell of it (even tho I knew multiplying a matrix by is inverse was just gonna cancle eachother out) trying to multiply it by its bone matrix to see if that worked since it was in bone space.


FbxNode* lBoneNode = lCluster->GetLink();
lDstVertex = lBoneNode->EvaluateGlobalTransform().MultT(lDstVertex);


but it went right back to the scaling issues.


Please help I have been splitting hairs and reading and going to training and still have not made the progress I wanted to, there is something that I have to be missing or somethign that I'm quite not getting because other wise i should of had my results by now.

Attached is a copy of the model Im using for testing purposes.

https://www.dropbox.com/s/teie2uxf3x72ijs/BoxPivot3.FBX
Please use plain text.
Moderator
Steve_Curley
Posts: 18,545
Registered: ‎08-07-2007

Re: Back to square one

06-28-2012 03:26 PM in reply to: The_Neverending_Loop
No file... please see this post for help with attachments.

Max 4.2 through 2015 (SP1), Composite 2014.
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 335.23).

Please use plain text.
Contributor
The_Neverending_Loop
Posts: 12
Registered: ‎05-22-2012

Re: Back to square one

06-28-2012 05:02 PM in reply to: The_Neverending_Loop
Thanks for the heads up. Ive tried attaching the files but they dont seem to be appearing I upload using winzip with extension .zip I Click "Choose File" without adding any extra attachments.
Please use plain text.
Moderator
Steve_Curley
Posts: 18,545
Registered: ‎08-07-2007

Re: Back to square one

06-29-2012 12:43 AM in reply to: The_Neverending_Loop
Don't preview - that will kill any attachments. Click Browse, select and OK your file, click Submit. There is also a size limit - how big is zip you're trying to attach?
If all else fails, there are loads of "upload" sites on the net - upload to one of those and post the link (though this is a last resort if nothing else works).

Max 4.2 through 2015 (SP1), Composite 2014.
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 335.23).

Please use plain text.
Contributor
The_Neverending_Loop
Posts: 12
Registered: ‎05-22-2012

Re: Back to square one

06-29-2012 07:20 AM in reply to: The_Neverending_Loop
Yea i followed the instructions carefully but it wouldnt work, didnt click preview or anythign just submit and the file is only about 13kb.

Anyhow I posted a link on drop box on the OP
https://www.dropbox.com/s/teie2uxf3x72ijs/BoxPivot3.FBX
Please use plain text.
Moderator
Steve_Curley
Posts: 18,545
Registered: ‎08-07-2007

Re: Back to square one

06-29-2012 07:28 AM in reply to: The_Neverending_Loop
testing...

And it works fine - not sure why you can't upload it, I'm afraid.

boxpivot3.fbx.zip


Max 4.2 through 2015 (SP1), Composite 2014.
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 335.23).

Please use plain text.