Discussion:
Problem while exporting a transformation
thomas pleyber
2008-08-20 09:47:03 UTC
Permalink
Hi developers


I successfully load hierarchical 3ds models using the EvalTransformMatrix()
workaround.

Now, when I want to export a mesh, I fill its LCS matrix, but its obviously
not
enough : when I re-load the exported model, the file evaluation computes the
node's matrix accordingly to its pos/rot/scl_track fields, and
EvalTransformMatrix()
ends up providing me a wrong result.

So I tried to fill these "track" fields with the local transformation
components (T,R,S) of
the mesh, but it seems not to be the solution.

My question is : what information should contain the "track" fields of a
node when
exporting a model so that transformations are retained when I reload the
file ?


Thank you for any enlightening explanation


Thomas
Tomas Rapkauskas
2008-08-21 07:13:39 UTC
Permalink
Hi,
Not sure does this will help, but here an example how I apply
rotation for node:

void lib3ds_node_rotate_y(Lib3dsNode *node, float fAngle) {
lib3ds_object_data_rotate_y(&node->data.object, fAngle);
}

void lib3ds_object_data_rotate_y(Lib3dsObjectData *n, float fAngle) {
Lib3dsVector axis;
axis[0] = 0.;
axis[1] = 1.;
axis[2] = 0.;
lib3ds_object_data_rotate(n, fAngle, axis);
}

// fAngle -> radians
void lib3ds_object_data_rotate(Lib3dsObjectData *n, float fAngle,
Lib3dsVector axis)
{
lib3ds_quat_track_free_keys(&n->rot_track);

Lib3dsQuatKey *rot = lib3ds_quat_key_new();
lib3ds_quat_zero(rot->q);
// lib3ds_quat_zero(rot->dd);
// lib3ds_quat_zero(rot->ds);
rot->angle = fAngle;
lib3ds_vector_copy(rot->axis, axis);
lib3ds_quat_track_insert(&n->rot_track, rot);
lib3ds_quat_track_setup(&n->rot_track);

lib3ds_empty_trans(n);
lib3ds_empty_scale(n);
}

void lib3ds_empty_trans(Lib3dsObjectData *n) {
lib3ds_lin3_track_free_keys(&n->pos_track);
n->pos_track.keyL = 0;
Lib3dsLin3Key *key_l = lib3ds_lin3_key_new();
lib3ds_lin3_track_insert(&n->pos_track, key_l);
lib3ds_lin3_track_setup(&n->pos_track);
}

void lib3ds_empty_scale(Lib3dsObjectData *n) {
lib3ds_lin3_track_free_keys(&n->scl_track);
n->scl_track.keyL = 0;
Lib3dsLin3Key *key_l = lib3ds_lin3_key_new();
key_l->value[0] = 1;
key_l->value[1] = 1;
key_l->value[2] = 1;
lib3ds_lin3_track_insert(&n->scl_track, key_l);
lib3ds_lin3_track_setup(&n->scl_track);
}

void lib3ds_quat_zero(Lib3dsQuat q) {
q[0] = 0;
q[1] = 0;
q[2] = 0;
q[3] = 1;
}

Tomas

P.S. (C++ version, but you can modify this to C language)
Post by thomas pleyber
Hi developers
I successfully load hierarchical 3ds models using the
EvalTransformMatrix() workaround.
Now, when I want to export a mesh, I fill its LCS matrix, but its
obviously not
enough : when I re-load the exported model, the file evaluation computes the
node's matrix accordingly to its pos/rot/scl_track fields, and
EvalTransformMatrix()
ends up providing me a wrong result.
So I tried to fill these "track" fields with the local transformation
components (T,R,S) of
the mesh, but it seems not to be the solution.
My question is : what information should contain the "track" fields of a
node when
exporting a model so that transformations are retained when I reload the
file ?
Thank you for any enlightening explanation
Thomas
------------------------------------------------------------------------
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
------------------------------------------------------------------------
_______________________________________________
lib3ds-devel mailing list
https://lists.sourceforge.net/lists/listinfo/lib3ds-devel
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
thomas pleyber
2008-08-21 09:37:33 UTC
Permalink
Thank you for your answer Tomas

Unfortunately, my problem is not how to manipulate these fields, but what i
should put in them when
I want to export a scene, so that I can reload it in any 3ds viewer (3DSMax,
3DExploration and obviously mine).

Basically, does the 3ds file format allows to retain a hierarchy of
transformations ?
or shall I translate the whole scene in the world coordinate system and put
identity transformation for every node and mesh ?


thank you again

Thomas
Tomas Rapkauskas
2008-08-21 10:34:19 UTC
Permalink
Post by thomas pleyber
Basically, does the 3ds file format allows to retain a hierarchy of
transformations ?
Yes, 3ds file format allows to do this.
You can create nodes hierarchy and apply transformations for every node.
Checkout Lib3dsNode - childs, parent, name fields and player sample.

Here is a sample how I export my scene to the 3ds file format:
I create nodes hierarchy and assign mesh structures for nodes.
Lib3dsFile *file = lib3ds_file_new();
Lib3dsNode *node = lib3ds_create_root_node(file);
lib3ds_node_rotate_y(node, (float)LIB3DS_PI);
Lib3dsWord parent_id = node->node_id;
Lib3dsNode *node_child = lib3ds_create_rotated_x_node(file, parent_id,
(float)LIB3DS_PI); // flip y axis
Lib3dsWord child_id = node_child->node_id;
Lib3dsMesh *mesh = lib3ds_mesh_new(sName.c_str());
lib3ds_create_empty_mesh_node(file, mesh, child_id);
(mesh will be rotated by y axis and by x axis)
Post by thomas pleyber
or shall I translate the whole scene in the world coordinate system and
put identity transformation for every node and mesh ?
No you should not do this.

Not sure does it helps, but if you need something please ask.

Tomas


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
thomas pleyber
2008-08-21 12:04:49 UTC
Permalink
Right, and thank you for your quick answer.

Now when you write a Lib3dsFile* object (for example a 5-levels deep
hierarchy of rotated nodes) using "lib3ds_file_save()" and then re-load it,
does your scene look like before ?
If yes, it would mean I could finally succeed :)
On the other hand, I just realized i cannot import in 3DSMax 7 my own
exported files, it says something like "incorrect file format" (other
viewers can read them though)... :/

It seems I have some work in front of me

Thomas
Tomas Rapkauskas
2008-08-21 13:58:26 UTC
Permalink
Post by thomas pleyber
Now when you write a Lib3dsFile* object (for example a 5-levels deep
hierarchy of rotated nodes) using "lib3ds_file_save()" and then re-load
it, does your scene look like before ?
Yes.
Post by thomas pleyber
On the other hand, I just realized i cannot import in 3DSMax 7 my own
exported files, it says something like "incorrect file format" (other
viewers can read them though)... :/
(I can open my exported 3ds files with 3DSMax 7)
You should initialize all Lib3dsObjectData data members.
Currently I do not remember exactly, but I had this problem also and
wrote such functions (look previous email) like
lib3ds_quat_zero/lib3ds_empty_trans/...

Tomas



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
thomas pleyber
2008-08-21 14:35:00 UTC
Permalink
Ok thank you very much for these details. I'm going to follow your advice
concerning the transformation stuff.
For my last problem (the import in 3DSMax), it seems to be linked with empty
nodes ($$$DUMMY or such)
and probably uninitialized fields, as you just mentionned.

Thank you again for your help


Thomas

Loading...