Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Matrices and FBX [SOLVED]

 Post Reply Post Reply
Author
Message
eldiren View Drop Down
Member
Member


Joined: 2014 Sep 18
Online Status: Offline
Posts: 41
Post Options Post Options   Quote eldiren Quote  Post ReplyReply Direct Link To This Post Topic: Matrices and FBX [SOLVED]
    Posted: 2017 May 30 at 8:14pm

User Information:

Cinema 4D Version:   R17 
Platform:   Windows  ;   
Language(s):     C++  ;   

---------

I'm working on a plugin using the FBX SDK, but I'm having a terrible time of figuring out the matirx calculations to get my joints rotated right. Obviously the C4D importer works somehow, so I was wondering if anyone had any hints or tips on the way FBX works vs C4D. I've came up with some conclusions based on my research: C4D is left-handed and FBX is right handed. When I'm doing my translation setup I've inverted the z axis and so the positions of the joint are proper. Rotations are a bit of a bastard though. Here's some code I'm using to set up the global matrix for a joint

FbxAMatrix fbxMatrix;
fbxMatrix = fbxNode->EvaluateGlobalTransform(kTime);
Matrix base;
base.v1.x = fbxMatrix.Get(0, 0);
base.v1.y = fbxMatrix.Get(0, 1);
base.v1.z = fbxMatrix.Get(0, 2);
base.v2.x = fbxMatrix.Get(1, 0);
base.v2.y = fbxMatrix.Get(1, 1);
base.v2.z = fbxMatrix.Get(1, 2);
base.v3.x = fbxMatrix.Get(2, 0);
base.v3.y = fbxMatrix.Get(2, 1);
base.v3.z = fbxMatrix.Get(2, 2);
base.off.x = fbxMatrix.Get(3, 0);
base.off.y = fbxMatrix.Get(3, 1);
base.off.z = -fbxMatrix.Get(3, 2);

Considering the handedness I imagine I have to do some interesting to the rotations but I don't know what. Setting the properties use SetAbsRot, SetAbsPos, SetAbsScale isn't working out too well for me either due to those function being local to thier parent. Maybe there's a setglobalpos I'm missing somewhere? The whole base * the inverse of the parent to make things local also failed for me.   
Back to Top
Vision4Next View Drop Down
Member
Member
Avatar

Joined: 2013 Dec 01
Online Status: Offline
Posts: 6
Post Options Post Options   Quote Vision4Next Quote  Post ReplyReply Direct Link To This Post Posted: 2017 May 31 at 12:15am
I only can share some things that I found out so far.

Cinema 4D does HPB rotation and FBX is based on XYZ rotation. There is some confusion about rotation order and the rotation axis. Especially if you are using joint chains or a joint hierarchy. For rotation around the Z axis, Cinema 4D uses the local axis and for rotations around the X/Y axis the axis system of the parent.

So I'm confused as well. It is possible to set the world position and orientation of an object with a Python script. Maybe this is a working approach.
Win7 64bit, Cinema 4D R17/18, VrayForC4D, Surface Spread, Adobe CS6
Back to Top
knickknack View Drop Down
Forum Moderator
Forum Moderator


Joined: 2016 Jul 01
Location: Italy
Online Status: Offline
Posts: 118
Post Options Post Options   Quote knickknack Quote  Post ReplyReply Direct Link To This Post Posted: 2017 May 31 at 2:55am
Hi Eldiren, thanks for writing us.
To swap back and forth RH <-> LH coordinates just swap y/z elements in the transformation matrix without inverting any value.

Basically from you should swap 2nd and 3rd row and then swap 2nd and 3rd column.
a00 a01 a02 a03            a00 a02 a01 a03
a10 a11 a12 a13  ---->  a20 a22 a21 a23
a20 a21 a22 a23           a10 a12 a11 a13
a30 a31 a32 a33           a30 a32 a31 a33

Code-wise this turns to be something like this

 base.v1.x = fbxMatrix.Get(0, 0);
 base.v1.z = fbxMatrix.Get(0, 1);
 base.v1.y = fbxMatrix.Get(0, 2);
 base.v3.x = fbxMatrix.Get(1, 0);
 base.v3.z = fbxMatrix.Get(1, 1);
 base.v3.y = fbxMatrix.Get(1, 2);
 base.v2.x = fbxMatrix.Get(2, 0);
 base.v2.z = fbxMatrix.Get(2, 1);
 base.v2.y = fbxMatrix.Get(2, 2);
 base.off.x = fbxMatrix.Get(3, 0);
 base.off.z = fbxMatrix.Get(3, 1);
 base.off.y = fbxMatrix.Get(3, 2);

Best, Riccardo.
MAXON Computer GmbH
SDK Support Team
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.094 seconds.