Discussion:
"improper file format" error in opening 3ds file in 3ds Max
Adrian Bedeau
2008-07-17 00:04:25 UTC
Permalink
Hi,

I wrote a program that uses lib3ds to create a cube and write it to a 3ds
file. Each face of the cube is made up of two triangles. I could open the
file fine in some viewers but i got the error "improper file format" when
opening the file in 3ds Max. My code is below. If anyone has an idea of what
I might have done wrong, please help me out.

Thank you,

Adrian
//------------------------------------------------------------------------------------------------------------------------writer.cpp-------------------------------------

#include <lib3ds/file.h>
#include <lib3ds/camera.h>
#include <lib3ds/mesh.h>
#include <lib3ds/node.h>
#include <lib3ds/material.h>
#include <lib3ds/matrix.h>
#include <lib3ds/vector.h>
#include <lib3ds/light.h>

int _tmain(int argc, _TCHAR* argv[])
{
//create file object
Lib3dsFile * file = lib3ds_file_new();
//node
Lib3dsNode* node = lib3ds_node_new_object();
strcpy(node->name, "node0");
node->parent_id = LIB3DS_NO_PARENT;
lib3ds_file_insert_node(file, node);

//mesh
Lib3dsMesh *mesh = lib3ds_mesh_new("mesh0");
lib3ds_mesh_new_face_list(mesh, 12);
//create the face object
Lib3dsFace* face = new Lib3dsFace[12];
mesh->faces = 12;
int n = 0;
for(unsigned int i = 0; i < mesh->faces; i++)
{
face[i].points[0] = n++;
face[i].points[1] = n++;
face[i].points[2] = n++;
}

mesh->faceL = face;


lib3ds_mesh_new_point_list(mesh,36);

Lib3dsVector * vertices = new Lib3dsVector[ 3];
Lib3dsVector v1 = {0.0f, 0.0f, 0.0f};
Lib3dsVector v2 = {1.0f, 0.0f, 0.0f};
Lib3dsVector v3 = {1.0f, 0.0f, 1.0f};
Lib3dsVector v4 = {0.0f, 0.0f, 1.0f};
Lib3dsVector v5 = {0.0f, 1.0f, 0.0f};
Lib3dsVector v6 = {1.0f, 1.0f, 0.0f};
Lib3dsVector v7 = {1.0f, 1.0f, 1.0f};
Lib3dsVector v8 = {0.0f, 1.0f, 1.0f};

int pIndex = 0;
//face1
memcpy(mesh->pointL[pIndex++].pos, &v1, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v2, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v3, sizeof(Lib3dsVector));


memcpy(mesh->pointL[pIndex++].pos, &v1, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v4, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v3, sizeof(Lib3dsVector));

//face2
memcpy(mesh->pointL[pIndex++].pos, &v5, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v6, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v7, sizeof(Lib3dsVector));

memcpy(mesh->pointL[pIndex++].pos, &v5, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v8, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v7, sizeof(Lib3dsVector));


//face3
memcpy(mesh->pointL[pIndex++].pos, &v1, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v4, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v8, sizeof(Lib3dsVector));

memcpy(mesh->pointL[pIndex++].pos, &v1, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v5, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v8, sizeof(Lib3dsVector));

//face4
memcpy(mesh->pointL[pIndex++].pos, &v2, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v7, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v3, sizeof(Lib3dsVector));

memcpy(mesh->pointL[pIndex++].pos, &v2, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v7, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v6, sizeof(Lib3dsVector));

//face5

memcpy(mesh->pointL[pIndex++].pos, &v1, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v5, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v6, sizeof(Lib3dsVector));

memcpy(mesh->pointL[pIndex++].pos, &v1, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v2, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v6, sizeof(Lib3dsVector));

//face 6
memcpy(mesh->pointL[pIndex++].pos, &v4, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v8, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v7, sizeof(Lib3dsVector));

memcpy(mesh->pointL[pIndex++].pos, &v4, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v3, sizeof(Lib3dsVector));
memcpy(mesh->pointL[pIndex++].pos, &v7, sizeof(Lib3dsVector));

lib3ds_file_insert_mesh(file, mesh);

lib3ds_file_save(file, "C:\\temp\\cube.3ds");
return 0;
}
Kyprianidis, Jan Eric
2008-07-17 05:55:41 UTC
Permalink
Hi,

the upcoming lib3ds 2.0 release includes a "cube" example. It's
available from SVN.

Regards,
Jan Eric
Post by Adrian Bedeau
Hi,
I wrote a program that uses lib3ds to create a cube and write it to a
3ds file. Each face of the cube is made up of two triangles. I could
open the file fine in some viewers but i got the error "improper file
format" when opening the file in 3ds Max. My code is below. If anyone
has an idea of what I might have done wrong, please help me out.
Thank you,
Adrian
-------------------------------------------------------------------------
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=/
Adrian Bedeau
2008-07-17 17:50:12 UTC
Permalink
Hi,

Thank you for your reply. I browsed through the repository and found some
code in player.c for rendering a box in openGL. Is this the example you
meant? I was looking for an example that shows how to create a Lib3dsMesh
storing a cube geometry. If I am looking in the wrong place, please point me
to the right place.

Thank you,

Adrian
Post by Kyprianidis, Jan Eric
Hi,
the upcoming lib3ds 2.0 release includes a "cube" example. It's
available from SVN.
Regards,
Jan Eric
Post by Adrian Bedeau
Hi,
I wrote a program that uses lib3ds to create a cube and write it to a
3ds file. Each face of the cube is made up of two triangles. I could
open the file fine in some viewers but i got the error "improper file
format" when opening the file in 3ds Max. My code is below. If anyone
has an idea of what I might have done wrong, please help me out.
Thank you,
Adrian
-------------------------------------------------------------------------
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
Adrian Bedeau
2008-07-17 17:54:57 UTC
Permalink
Hi,

I have just found the file cube.c and it seems to be what i am looking for.
Previously I selected the code->SVN link from the top menu then clicked on
"Search code" on the right and could not find this file. However, just now I
selected code->SVN browse from the top menu and it took me to the latest
revision which includes this file.

Adrian
Post by Adrian Bedeau
Hi,
Thank you for your reply. I browsed through the repository and found some
code in player.c for rendering a box in openGL. Is this the example you
meant? I was looking for an example that shows how to create a Lib3dsMesh
storing a cube geometry. If I am looking in the wrong place, please point me
to the right place.
Thank you,
Adrian
Post by Kyprianidis, Jan Eric
Hi,
the upcoming lib3ds 2.0 release includes a "cube" example. It's
available from SVN.
Regards,
Jan Eric
Post by Adrian Bedeau
Hi,
I wrote a program that uses lib3ds to create a cube and write it to a
3ds file. Each face of the cube is made up of two triangles. I could
open the file fine in some viewers but i got the error "improper file
format" when opening the file in 3ds Max. My code is below. If anyone
has an idea of what I might have done wrong, please help me out.
Thank you,
Adrian
-------------------------------------------------------------------------
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
Loading...