On 15/07/2014 at 11:33, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R13
Platform: Windows ;
Language(s) : C++ ;
---------
Hello all,
I'm trying to read the animation data from a C4D file using the melange lib, but I'm having all sorts of problems.
My first problem is related to the rotation axis. I have 2 different files, in both files I have a rotation around the Z axis. The problem starts when I create a keyframe. In one of the files, this rotation is applied as a "Rotation.B" whereas in the other file, I get "Rotation.P". Note that in both cases I rotated the model around the Z axis!
Then when I'm importing each of these files into my program, the conversion from HPB into XYZ results in different rotations, however, The Rotation.B is converted into a rotation around Z and the Rotation.P is converted into a rotation around Y for the other, which seems that HPB is directly converted into XYZ.
Another problem I'm having is related to the point of rotation/scale. I'm getting 3 vectors from each keyframe (move, rotate, scale). I then create a transformation matrix with them, but applying this matrix directly will transform my model from within its center, independently of the point of rotation I used in Cinema4D. I'm almost definitely missing something here.
Here is a draft of my current code:
CTrack *track = op->GetFirstCTrack();
while (track)
{
DescID testID = track->GetDescriptionID();
DescLevel lv1 = testID[0];
DescLevel lv2 = testID[1];
CCurve *curve = track->GetCurve();
if (curve)
{
LONG keyCount = curve->GetKeyCount();
CKey *key = NULL;
BaseTime time;
for (LONG i=0; i<keyCount; ++i)
{
key = curve->GetKey(i);
time = key->GetTime();
if (track->GetTrackCategory() == PSEUDO_VALUE)
{
const LONG keyId = time.GetFrame(animProps.fps);
if (animData.keyframes.find(keyId) == animData.keyframes.end())
animData.keyframes[keyId] = MelangeStoreKeyframe(keyId);
MelangeStoreKeyframe &keyframe = animData.keyframes[keyId];
switch (lv1.id)
{
case ID_BASEOBJECT_REL_POSITION:
switch (lv2.id)
{
case VECTOR_X: keyframe.position[0] = key->GetValue(); break;
case VECTOR_Y: keyframe.position[1] = key->GetValue(); break;
case VECTOR_Z: keyframe.position[2] = key->GetValue(); break;
}
break;
case ID_BASEOBJECT_REL_ROTATION:
switch (lv2.id)
{
case VECTOR_X: keyframe.rotation[0] = key->GetValue(); break;
case VECTOR_Y: keyframe.rotation[1] = key->GetValue(); break;
case VECTOR_Z: keyframe.rotation[2] = key->GetValue(); break;
}
break;
case ID_BASEOBJECT_REL_SCALE:
switch (lv2.id)
{
case VECTOR_X: keyframe.scale[0] = key->GetValue(); break;
case VECTOR_Y: keyframe.scale[1] = key->GetValue(); break;
case VECTOR_Z: keyframe.scale[2] = key->GetValue(); break;
}
break;
}
}
}
}
track = track->GetNext();
}
On a final note, I'm not considering the global matrix of the model, which for my understanding, represents the model matrix at the current frame when exported.
PolygonObject *op = (PolygonObject* )GetNode();
Matrix mg = op->GetMg();
I'm not applying this matrix (mg) to the model's vertexes nor the animation transforms (position, scale, rotation).
Also, it would be great is someone pointed me out some examples about this matter, I'm a little bit lost here.
Thanks in advance!