Problems creating trimeshes

29 views
Skip to first unread message

Aaron Snoswell

unread,
Dec 16, 2007, 7:39:30 PM12/16/07
to ode-users
Hello all,

My apologies in advance if this question has already been answered, I
tried searching and couldn't find anything.

I recently started using ODE as a physics library for my 3D engine.
Everything worked fine and I could create boxes and spheres, and get
them to collide with each other and a plane (created by dCreatePlane).

I then tried to implement a trimesh geom; my goal was to get a cube
(or box) to fall and collide with a trimesh 'terrain'. I followed two
different tutorials, one from http://gpwiki.org/index.php/ODE_Object_tutorial
and one from Al's programming resources
(www.alsprogrammingresource.com), and I still couldn't get it working.

I think there is a problem when I call dGeomTriMeshDataBuildSimple, or
when I actually create the trimesh object by calling
dGeomTriMeshDataCreate.

I am using C, compiling with Dev-C++ and my code is as follows:

//Trimesh
Objects[numObjs].Body = (dBodyID)0;
triMesh = dGeomTriMeshDataCreate();

int indexes[6];
dVector3 triVert[4];

indexes[0] = 2;
indexes[1] = 1;
indexes[2] = 0;
indexes[3] = 3;
indexes[4] = 2;
indexes[5] = 0;

triVert[0][0] = 100.0f;
triVert[0][1] = 0.0f;
triVert[0][2] = 100.0f;
triVert[0][3] = 0.0f;

triVert[1][0] = -100.0f;
triVert[1][1] = 0.0f;
triVert[1][2] = 100.0f;
triVert[0][3] = 0.0f;

triVert[2][0] = -100.0f;
triVert[2][1] = 0.0f;
triVert[2][2] = -100.0f;
triVert[0][3] = 0.0f;

triVert[3][0] = 100.0f;
triVert[3][1] = 0.0f;
triVert[3][2] = -100.0f;
triVert[0][3] = 0.0f;

dGeomTriMeshDataBuildSimple(triMesh, (dReal*)triVert, 4, indexes,
6);
Objects[numObjs].geoms[j] = dCreateTriMesh(Space, triMesh, NULL,
NULL, NULL);
//dGeomSetData(Objects[numObjs].geoms[j], "Plane");
dGeomSetPosition(Objects[numObjs].geoms[j], 0, 10.0, 0);

Every time I run it ODE appears to create the trimesh successfully,
but my box falls straight through it. I have tried inverting the order
of the vertices in case the normals are backwards, but it still
doesn't work. ODE simply doesn't detect a collision between the
trimesh and the box, which makes me question if the trimesh is being
created at all (or incorrectly created?).

I am aware that some releases do not support trimeshes, the release I
am using is the latest windows one from sourceforge.net (ode-
win32-0.9.zip). Is this the wrong version if I want to use trimeshes?

I would appreciate it greatly if someone could email me source code,
or post a link to an example using trimeshes in ODE. My address is
dvobreakdown[at]gmail.com

Thankyou for any help!
-Aaron Snoswell


Also (sorry for double posting): I have heard people mention the
'demo' projects or examples that come with ODE, yet have not been able
to find them in any of the releases, can someone point me in the right
direction on how to find these? Thanks!

Jason Busch

unread,
Dec 16, 2007, 9:51:28 PM12/16/07
to ode-...@googlegroups.com
Hi,

I found a similar issue that was caused primarily by having a small number
of contact points (ie...for a cube) in relation to the triangle spacing in
the trimesh. Secondly, as you are generating this trimesh as a terrain,
make sure you aren't attaching its geometry to to any bodies.

Hope this helps,
Wulfe

> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.503 / Virus Database: 269.17.4/1187 - Release Date:
> 12/16/2007 11:36 AM
>
>

Aaron Snoswell

unread,
Dec 17, 2007, 2:19:53 AM12/17/07
to ode-users
> Hi,
>
> I found a similar issue that was caused primarily by having a small number
> of contact points (ie...for a cube) in relation to the triangle spacing in
> the trimesh. Secondly, as you are generating this trimesh as a terrain,
> make sure you aren't attaching its geometry to to any bodies.
>
> Hope this helps,
> Wulfe

Thanks Wulfe,
Bear with me as I'm still learning about how ODE works,
So you're saying I should try altering the size or position of the
triangles in the trimesh and see if that helps?

I think I'm not attaching the geometery to any body, is the correct
process for doing this as follows?

Objects[numObjs].Body = (dBodyID)0;
//Create trimesh geom here (stored in Objects[numObjs].geoms[j])
dGeomSetBody(Objects[numObjs].geoms[j], Objects[numObjs].Body);

Or should I just not call dGeomSetBody at all? The two tutorials I
followed did it opposite ways...

Thankyou for your help,
once again if anyone has any working source code they could link me to
it would be greatly appreciated!

Jason Busch

unread,
Dec 17, 2007, 3:39:00 AM12/17/07
to ode-...@googlegroups.com
Hi, I'm quite new to ODE as well...but have experienced the pain of terrain
trimesh creation recently.

You could try a few things to see if anything changes:

1. Scale either your terrain, or the object that is supposed to collide
with it (If you notice a change in collision behaviour...#2 will certainly
help.
2. Increase MAX_CONTACTS. (Keep in mind that the higher the number, the
greater the performance hit)
3. Decrease your objects mass and your gravitational constant. (Just out
of curiosity to see if anything changes)
4. Put a breakpoint in your collision callback. If there is any collision
occuring, it will be caught here.


Your DYNAMIC objects will be attached to a body
dBodyID body = dBodyCreate();
//set body mass, position rotation etc...
dGeomID geom = dCreateBox(); //for example
dGeomSetBody(geom , body );

Your STATIC terrain trimesh should be simply something like this:
dTriMeshDataID tdata = dGeomTriMeshDataCreate()
dGeomTriMeshDataBuildSimple ( tdata, ....... )
dGeomID geom = dCreateTriMesh( space, tdata )
dGeomSetData( geom, tdata );

This triangle winding order works for me:
1st = topleft, bottomleft, topright
2nd = bottomleft, topright, bottomright

Hope this helps,
Wulfe


----- Original Message -----
From: "Aaron Snoswell" <dvobre...@gmail.com>
To: "ode-users" <ode-...@googlegroups.com>

Aaron Snoswell

unread,
Dec 17, 2007, 4:08:58 AM12/17/07
to ode-users
Thanks a ton for all your advice!

I will go now and try your suggestions, and post again later tonight.
I have a feeling now it may be something to do with the MAX_CONTACTS
value...

It is a great comfort to know that there are others who have also
struggled with trimesh creation!!! Will post later tonight,

Thankyou once again!

Aaron Snoswell

unread,
Dec 17, 2007, 8:00:13 AM12/17/07
to ode-users
Hmmmmmm, no good.

I tried all of your seggestions to no avail. ODE appears to create the
trimesh correctly, however the object simply does not collide with it.
I tried putting breakpoints in my collision callback but nothing is
colliding... That is why i think I am not correctly creating the
trimesh, however I am doing it exactly the same as the turtorials I
mentioned...

This is driving me mad!!! ODE obviously works with trimeshes, but I
can't get it!!!!

Is there any working source code someone could send to me / upload
that I can try working with? I've searched everywhere... Perhaps
someone has a working build of one of the ODE trimesh demo's? (I can't
get them to complile, some error with drawstuff)

All I need is one working demo and Ill base everything of that!

Thanks for any help again,

beuiot

unread,
Dec 18, 2007, 9:32:27 AM12/18/07
to ode-users
I've had lots of problems with trimeshes too, and I noticed changing
the simulation step can help. Try to make a smaller step.. Are you
using quick or normal worldStep ? I noticed the quick worldstep is
often not accurate enough with trimeshes..

Hope this helps.

Aaron Snoswell

unread,
Dec 19, 2007, 2:29:22 AM12/19/07
to ode-users
Hmmmmm,

no good again, thank for the advice though.

I am using quickworldstep, and i tried worldstep instead with no
changes...
I might try posting some of my source code soon,,, see if anyone can
spot any blatantly obvious mistakes! :p

Thanks all anyway, will post soon

beuiot

unread,
Dec 20, 2007, 9:18:44 AM12/20/07
to ode-users
What method do you use to detect collisions ?

Aaron Snoswell

unread,
Dec 23, 2007, 5:51:03 AM12/23/07
to ode-users
Ok,

sorry for the delay,
Rather than trying to explain the method I use, I decided to just
paste my entire physics handler below so there is no confusion
whatsoever :p





//Physics.c
//Handles integration of the ODE physics engine

#include "physics.h"

float GeomMatrix[12];
dWorldID World;
dSpaceID Space;
dObject Objects[MAX_OBJS];
dJointGroupID contactgroup;
int numObjs = 0;
dGeomID land;

dTriMeshDataID triMesh;
dVector3 triVert[40000];
int indexes[10000];
int k=0;

void wakeAll(void){
int i;
for(i=0; i<numObjs; i++){
dBodyEnable(Objects[i].Body);
}
}

//Add one user defined object
int addDObj(int numGs, int type){
dMatrix3 R;
size_t s = 0; //The user data
int j;

if(type != 2){
Objects[numObjs].Body = dBodyCreate(World);
dBodySetPosition(Objects[numObjs].Body, 0, 30, 0);
dBodySetLinearVel(Objects[numObjs].Body, .01, 0, 0);
//hdBodySetLinearVel(Objects[numObjs].Body, dRandReal() * 50 -
25, dRandReal() * 50 - 25, dRandReal() * 50 - 25);
dBodySetAngularVel(Objects[numObjs].Body, 0.0, 0.0, 0.0);

dRFromAxisAndAngle(R, dRandReal() * 2.0 - 1.0, dRandReal() * 2.0
- 1.0, dRandReal() * 2.0 - 1.0, dRandReal() * 10.0 - 5.0);
dBodySetRotation(Objects[numObjs].Body, R);

//Add user data (nothing)
dBodySetData(Objects[numObjs].Body, (void*)s);
}

//Add mass
switch(type){
case 0:{
//If Box
dMassSetBox(&Objects[numObjs].mass, 0.5, 2, 2, 2);
dBodySetMass(Objects[numObjs].Body, &Objects[numObjs].mass);
}break;
case 1:{
//If Sphere
dMassSetSphere(&Objects[numObjs].mass, 0.5, 2);
dBodySetMass(Objects[numObjs].Body, &Objects[numObjs].mass);
}break;
case 2:{
//Trimesh (does not link to an object, .: no mass
}break;
}

//Initalise object's geoms
for(j=0; j<numGs; j++){
switch(type){
case 0:{
//If Box
Objects[numObjs].geoms[j] = dCreateBox(Space, 2, 2, 2);
dGeomSetData(Objects[numObjs].geoms[j], "Box");
dGeomSetBody(Objects[numObjs].geoms[j],
Objects[numObjs].Body);
}break;
case 1:{
//If Sphere
Objects[numObjs].geoms[j] = dCreateSphere(Space, 2);
dGeomSetData(Objects[numObjs].geoms[j], "Sphere");
dGeomSetBody(Objects[numObjs].geoms[j],
Objects[numObjs].Body);
}break;
case 2:{
//Trimesh
Objects[numObjs].Body = (dBodyID)0;
triMesh = dGeomTriMeshDataCreate();
int i, j = 0;

for(i=0; i<objects[numObjs].vertices_qty; i++){
triVert[i][0] = (dReal)objects[numObjs].vertex[i].x;
triVert[i][1] = (dReal)objects[numObjs].vertex[i].y;
triVert[i][2] = (dReal)objects[numObjs].vertex[i].z;
triVert[i][3] = 0.0f;
}

for(i=0; i<objects[numObjs].polygons_qty; i++){
indexes[k] = objects[numObjs].triangle[j].a;
k++;
indexes[k] = objects[numObjs].triangle[j].b;
k++;
indexes[k] = objects[numObjs].triangle[j].c;
k++;
j++;
}

dGeomTriMeshDataBuildSimple(triMesh, (dReal*)triVert,
objects[numObjs].vertices_qty, indexes, k);
Objects[numObjs].geoms[j] = dCreateTriMesh(Space, triMesh,
NULL, NULL, NULL);
dGeomTriMeshSetData(Objects[numObjs].geoms[j], triMesh);
dGeomSetPosition(Objects[numObjs].geoms[j], 0, 10, 0);
dGeomSetData(Objects[numObjs].geoms[j], "TriMesh");

/*
int indexes[6];
dVector3 triVert[4];

indexes[0] = 2;
indexes[1] = 1;
indexes[2] = 0;
indexes[3] = 3;
indexes[4] = 2;
indexes[5] = 0;

triVert[0][0] = 100.0f;
triVert[0][1] = -5.0f;
triVert[0][2] = 100.0f;
triVert[0][3] = 0.0f;

triVert[1][0] = -100.0f;
triVert[1][1] = -5.0f;
triVert[1][2] = 100.0f;
triVert[0][3] = 0.0f;

triVert[2][0] = -100.0f;
triVert[2][1] = 5.0f;
triVert[2][2] = -100.0f;
triVert[0][3] = 0.0f;

triVert[3][0] = 100.0f;
triVert[3][1] = 5.0f;
triVert[3][2] = -100.0f;
triVert[0][3] = 0.0f;

dGeomTriMeshDataBuildSimple(triMesh, (dReal*)triVert, 4,
indexes, 6);
Objects[numObjs].geoms[j] = dCreateTriMesh(Space, triMesh,
NULL, NULL, NULL);
dGeomSetData(Objects[numObjs].geoms[j], "Plane");
dGeomSetPosition(Objects[numObjs].geoms[j], 0, 10.0, 0);
*/

/*
dVector3 v0, v1, v2;
dGeomTriMeshGetTriangle(Objects[numObjs].geoms[j], 0, &v0,
&v1, &v2);
printf("\n%f\t%f\t%f\n", (float)v0[0], (float)v0[1],
(float)v0[2]);
printf("%f\t%f\t%f\n", (float)v1[0], (float)v1[1],
(float)v1[2]);
printf("%f\t%f\t%f\n", (float)v2[0], (float)v2[1],
(float)v2[2]);
*/

//dGeomSetBody(Objects[numObjs].geoms[j],
Objects[numObjs].Body);
}break;
};
Objects[numObjs].numGeoms += 1;
}
Objects[numObjs].localID = numObjs;
numObjs += 1;
return(numObjs - 1);
}

//Initialise the ODE engine
void initODE(void){
World = dWorldCreate();
Space = dSimpleSpaceCreate(0);
contactgroup = dJointGroupCreate(0);
dCreatePlane(Space, 0, 1, 0, 0);
dWorldSetGravity(World, 0, -9.8, 0);
dWorldSetERP(World, 0.2);
dWorldSetCFM(World, 1e-5);
dWorldSetContactMaxCorrectingVel(World, 0.9);
dWorldSetContactSurfaceLayer(World, .002);
dWorldSetAutoDisableFlag(World, 1);
}

//Clean up the ODE engine
void closeODE(void){
dJointGroupDestroy(contactgroup);
dSpaceDestroy(Space);
dWorldDestroy(World);
}

//Check if two objects are colliding
//Note: Not allowed to modify collision space while it is being
processed with dSpaceCollide
static void nearCallback(void *data, dGeomID o1, dGeomID o2){
int i, numc;
dBodyID b1 = dGeomGetBody(o1);
dBodyID b2 = dGeomGetBody(o2);

dContact contact[MAX_CONTACTS];

for(i = 0; i < MAX_CONTACTS; i++){
contact[i].surface.mode = dContactBounce | dContactSoftCFM;
contact[i].surface.mu = dInfinity;
contact[i].surface.mu2 = 0;
//contact[i].surface.bounce = 2.51;
contact[i].surface.bounce = 0.1;
contact[i].surface.soft_cfm = 0.0001;
}

numc = dCollide(o1, o2, MAX_CONTACTS, &contact[0].geom,
sizeof(dContact));
printf("numc is %d\n", numc);
if(numc){
for(i = 0; i < numc; i++){
dJointID c = dJointCreateContact(World, contactgroup, contact
+ i);
dJointAttach(c, b1, b2);
}
}
}

//Draw each geom object
//void drawgeoms(dgeomsID g, const dReal *pos, const dReal *R, int
show_aabb){
void drawGeom(dGeomID g, const dReal *pos, const dReal *R, int
show_aabb, int locID){
if(!g){
return;
}

if(!pos){
pos = dGeomGetPosition(g);
}

if(!R){
R = dGeomGetRotation(g);
}

int type = dGeomGetClass(g);
printf("%d", type);
system("pause");

if(type == dBoxClass){
drawObj((float *)pos, (float *)R, locID);
}else if(type == dSphereClass){
drawObj((float *)pos, (float *)R, locID);
}else if(type == dTriMeshClass){
drawObj((float *)pos, (float *)R, locID);
}
}

int type;
//Run one frame of the physics loop
void simLoop(void){
dSpaceCollide(Space, 0, &nearCallback);

//Advance the simulation
//float test = 70.0f / 1000.0f;
//dWorldQuickStep(World, 0.05);
dWorldQuickStep(World, 0.009);

dJointGroupEmpty(contactgroup);

//For each object + geoms
int i, j;
for(i=0; i<numObjs; i++){
for(j=0; j<Objects[i].numGeoms; j++){
drawGeom(Objects[i].geoms[j], 0, 0, 0, i);
}
}
}




OK, brief explanation of the functions,,,
(sorry for any random global variables, this code is the same code I
am working on, so it is till being de-bugged...)

wakeall just activates all geoms, a debugging function

addDObj adds one user-defined object, ignore the first variable, it
doesn't do anything, the second variable says what type of object to
add, 0 is a box, 1 is a sphere and 2 is a trimesh

initODE and closeODE just start and close everything,

nearCallback is my collision test function

drawgeoms draws each geometry

and simLoop steps the simulation every frame...

this isn't my latest version of the code, so if there are minor errors
with things like initialising ODE etc, i am probably allready aware of
them, however if anyone could check my trimesh creation code that
would be really appreciated,

thanks!

Aaron Snoswell

unread,
Dec 23, 2007, 7:15:41 AM12/23/07
to ode-users
Hurrah! Finally some progress!

I realised that the ODE include files I was using didn't match up with
the DLL i was using, they were outdated... I _now_ have the latest
version of ODE. When I run the program now it seems to create the
trimesh; I can trimeshes from any file i like (.3ds, or hard-coded
vertex positions), and ODE doesn't complain. My collision handler then
gives me feedback telling me that the trimesh is colliding (whether
properly or not I don't know yet),,, So i am hopefully loading
trimeshes successfully. I can also create more trimeshes and my
framerate drops, so I konw ODE is doing some calculations at least,
however,

I can't see anything anymore...

I think I've determined that the problem is with my matrix operations,
and the actual positioning of the objects on the screen. (I'm using
GLUT under windows btw). Here's the deal; My rendering file contains
the following function, I got it off one of the tutorials
abovementioned:

float Element[16];
ODEtoOGL(const double* p, const double* R){
Element[0] = R[0]; Element[1] = R[4]; Element[2] = R[8];
Element[3] = 0;
Element[4] = R[1]; Element[5] = R[5]; Element[6] = R[9];
Element[7] = 0;
Element[8] = R[2]; Element[9] = R[6]; Element[10] =
R[10];Element[11] = 0;
Element[12] = p[0]; Element[13] = p[1]; Element[14] = p[2];
Element[15] = 1;
}


The tutorial says it converts the ODE transformation matrix to an
openGL matrix, and it works fine with the (older) version of ODE that
came with the tutorial. Later in the same file is my drawObj function,
it draws the geoms to the screen;

//Draw one object to the scene
void drawObj(const float pos[3], const float R[12], int locID){
//Do physics for object
//glLoadIdentity();
glPushMatrix();
ODEtoOGL((double *)pos, (double *)R);
glMultMatrixf(Element);

//.....and so on, draws everything.....

glEnd();
glFlush();
glPopMatrix();
}

When I run the program without calling the two lines
ODEtoOGL((double *)pos, (double *)R);
glMultMatrixf(Element);
The object is displayed (without rotations or anything, as you would
expect). However with those two lines in, the object disappears. This
makes me wonder if there is something wrong with the way I am handling
the matrices... Does the latest version of ODE use a different type of
matrix???

Any advice or suggestions about how to handle matrices with ODE would
be appreciated, perhaps someone could post code showing how they do it
(if anyone else is using openGL)...

Sorry if this post is a bit hard to understand, I'm just excited
because I think I may finally be able to get ODE trimeshes working...
Thankyou for the help so far, I'm almost done ;)

-Aaron

Aaron Snoswell

unread,
Dec 23, 2007, 9:32:49 PM12/23/07
to ode-users
Yay, Success!

I discovered after posting that the problem was with me casting floats
as doubles in the function ODEtoOGL
It was getting values like 16000000000000 for some of the matrices
values, and thus tranlsating the object far out of view,

thankyou for the help, my trimeshes now work!

beuiot

unread,
Dec 24, 2007, 4:09:07 AM12/24/07
to ode-users
great :)

I have one question : how do you get the trimesh data from .3ds
files ? Could you give me the address of the tutorial you are using ?
I'm having lots of problems with trimeshes at the moment, random
behavior (sometimes works, sometimes doesn't, I can't figure out
why :P) so I suspect my trimesh data is somehow wrong. I currently use
the Irrlicht engine to get the trimesh data from .3ds with the help of
the "official" irrlicht tutorial, but this tutorial uses old versions
of irrlicht / ode. It might be outdated, I don't really know..

Thanks

beuiot

unread,
Dec 24, 2007, 5:24:42 AM12/24/07
to ode-users
(By the way, the problem was not casting from float to double, but
casting a float pointer to a double pointer ;) Casting from float to a
double would have worked, but with less precision of course )

Aaron Snoswell

unread,
Dec 24, 2007, 9:38:59 PM12/24/07
to ode-users
Haha, ok,
thanks for pointing that out, beuiot,

I've never quite gotten my head completley around pointers :p
I've used lots of different tutorials to come up with the .3ds codec i
now use, but I will find the main ones for you and post shortly,

Thanks for the help!

Aaron Snoswell

unread,
Dec 24, 2007, 10:29:02 PM12/24/07
to ode-users
Ok, here we go,,,

the .3ds codec I use was originally based off the tutorial by
Spacesimulator.net (http://www.spacesimulator.net/tutorials.html).
I've since customised it a little based on the Apron openGL tutorials
at http://www.morrowland.com/apron/index.php (he has a .3ds loader in
his tutorials). Im not sure what file version of the .3ds model format
my codec supports, but it has successfully loaded every .3ds file I've
ever come across on the net.

I don't know what language you program in (Irrilicht uses C++ right?),
but my .3ds loader is as follows, feel free to use as you please...



//3ds.c
//Handles loading of .3ds files
//A hybrid C adaption of the Spacesimulator.net .3ds tutorial and the
3DS loader by Apron
//OpenGL - Ronny André Reierstad (www.morrowland.com /
ap...@morrowland.com)

#include "3ds.h"

//The input file
FILE *ifp;

//Reads in a chunk ID and it's length in bytes
void readChunk(chunk *pChunk){
fread(&pChunk->chunkId, 2, 1, ifp);
fread(&pChunk->chunkLength, 4, 1, ifp);
}

//Reads in a string of characters
int getString(char *pBuffer){
int index = 0;
fread(pBuffer, 1, 1, ifp);
while(*(pBuffer + index++) != 0){
fread(pBuffer + index, 1, 1, ifp);
}
return strlen(pBuffer) + 1;
}

//Load a given 3ds file, returning how many objects were added to the
scene
void load3DS(const char *ifilename){
int i, loc;

//Temporary counting variables for reading vertices and faces
unsigned char lChar;
unsigned short lQty;
unsigned short lFaceFlags;

//The temporary object pointer
obj_type_ptr p_object;

//A temporary chunk to store where we're up to
chunk current;

//Open the file and see if everything is ok...
if((ifp=fopen(ifilename, "rb"))==NULL) return;

int num_added = 0;

//Temporary object to work around first object material name glitch
int firstblock = 1;
loc = createObject(0, "_3dsObject");
num_added++;
p_object = &objects[loc];

//Loop to scan the whole file
while(ftell(ifp) < filelength(fileno(ifp))){
readChunk(&current);
switch(current.chunkId){
case PRIMARY:{
}break;
case OBJECTINFO:{
}break;
case OBJECT:{
if(firstblock==1){
firstblock=0;
}else{
loc = createObject(0, "_3dsObject");
num_added++;
p_object = &objects[loc];
}
getString(p_object->name);
}break;
case OBJECT_MESH:{
}break;
case OBJECT_VERTICES:{
fread (&lQty, sizeof(unsigned short), 1, ifp);
p_object->vertices_qty = lQty;
for(i=0; i<lQty; i++){
fread(&(p_object->vertex[i].x), sizeof(float), 1, ifp);
fread(&(p_object->vertex[i].y), sizeof(float), 1, ifp);
fread(&(p_object->vertex[i].z), sizeof(float), 1, ifp);
}
}break;
case OBJECT_FACES:{
fread(&lQty, sizeof(unsigned short), 1, ifp);
p_object->polygons_qty = lQty;
for(i=0; i<lQty; i++){
fread(&p_object->triangle[i].a, sizeof (unsigned short), 1,
ifp);
fread(&p_object->triangle[i].b, sizeof (unsigned short), 1,
ifp);
fread(&p_object->triangle[i].c, sizeof (unsigned short), 1,
ifp);
fread(&lFaceFlags, sizeof(unsigned short), 1, ifp);
}
}break;
case OBJECT_UV:{
fread(&lQty, sizeof(unsigned short), 1, ifp);
for(i=0; i<lQty; i++){
fread(&p_object->mapcoord[i].u, sizeof(float), 1, ifp);
fread(&p_object->mapcoord[i].v, sizeof(float), 1, ifp);
}
}break;
case MATERIAL:{
p_object->hasTex = 1;
}break;
case MATERIAL_NAME:{
getString(p_object->texname);
}break;
case MATERIAL_AMBIENT:{
}break;
case MATERIAL_DIFFUSE:{
}break;
case MATERIAL_SPECULAR:{
}break;
case MATERIAL_MAP:{
}break;
case MATERIAL_FILENAME:{
getString(p_object->texfname);
}break;
default:{
fseek(ifp, current.chunkLength-6, SEEK_CUR);
}
}
}

//Calculate every added object's normals
for(i=num_added; i>0; i--){
objCalcNormalsTri(&objects[count-i]);
}

//Load every added object's texture
for(i=num_added; i>0; i--){
if(objects[count-i].hasTex=1){
objects[count-i].matId = texCount;
loadTexture(texturearray, objects[count-i].texfname,
texCount);
}
}

//Close everything up
fclose(ifp);
return;
}


I haven't gotten rid of my engine specific code, sorry, I just copied
and pasted it, but hopefully it will be of use to you!
Hope it helps!


btw: If you want to write your own .3ds loader there are several
overviews of the file format on the net;
http://the-labs.com/Blender/3DS-details.html
http://www.whisqu.se/per/docs/graphics56.htm
All the best and merry christmas!

beuiot

unread,
Dec 25, 2007, 2:03:27 PM12/25/07
to ode-users
thank you very much. I'm going to try this later this week.

Thanks again and merry christmas :)

On Dec 25, 4:29 am, Aaron Snoswell <dvobreakd...@gmail.com> wrote:
> Ok, here we go,,,
>
> the .3ds codec I use was originally based off the tutorial by
> Spacesimulator.net (http://www.spacesimulator.net/tutorials.html).
> I've since customised it a little based on the Apron openGL tutorials
> athttp://www.morrowland.com/apron/index.php(he has a .3ds loader in
> overviews of the file format on the net;http://the-labs.com/Blender/3DS-details.htmlhttp://www.whisqu.se/per/docs/graphics56.htm

beuiot

unread,
Dec 26, 2007, 7:30:43 AM12/26/07
to ode-users
I used your code to load a .3ds file, fed ODE with it, and it worked
perfectly :) I now have to figure out how to get correct data from
Irrlicht. At least now I'm sure my ODE code works !!

Thank you very much ! :)


On Dec 25, 8:03 pm, beuiot <beu...@gmail.com> wrote:
> thank you very much. I'm going to try this later this week.
>
> Thanks again and merry christmas :)
>
> On Dec 25, 4:29 am, Aaron Snoswell <dvobreakd...@gmail.com> wrote:
>
> > Ok, here we go,,,
>
> > the .3ds codec I use was originally based off the tutorial by
> > Spacesimulator.net (http://www.spacesimulator.net/tutorials.html).
> > I've since customised it a little based on the Apron openGL tutorials
> > athttp://www.morrowland.com/apron/index.php(hehas a .3ds loader in
> > overviews of the file format on the net;http://the-labs.com/Blender/3DS-details.htmlhttp://www.whisqu.se/per/...

Aaron Snoswell

unread,
Dec 26, 2007, 11:57:45 PM12/26/07
to ode-users
Glad to be of assistance!

-Hope you can get irrilicht working!

-Aaron

beuiot

unread,
Dec 27, 2007, 6:12:02 AM12/27/07
to ode-users
I found what was wrong.. guess what : converting from double pointer
to float pointer ! I re-wrote in a clean way the method that reads
trimesh data, with proper types, it now works perfectly. Thanks
again :)

Aaron Snoswell

unread,
Dec 27, 2007, 5:40:58 PM12/27/07
to ode-users
Ha!

Same problem I had!

-Glad it works,,,
Reply all
Reply to author
Forward
0 new messages