PDA

View Full Version : 3DS file



vivek vyas
08-10-2009, 05:44 AM
Really i am unable to solve this one
I made an exact code for load all vertex from any file
but there is some assignment problem
here is the code(i changed something)


int nvert
float **vertex;
void Load3Ds(const char *Filename,float **vert,int x)
{
Lib3dsFile *testfile;
Lib3dsIo *testio;

printf("Testing 3-Dimention of 3ds \nhow to load 3ds file for reading all vertes data\n");

testfile = lib3ds_file_open(Filename);
x = testfile->meshes[0]->nvertices;

printf("Number of vertices %i\n",x);

vert = new float*[2];

for(int i=0;i<=x;i++)
{
vert[i] = new float[x];
lib3ds_quat_copy(vert[i],testfile->meshes[0]->vertices[i]);
}
printf("x,y,z\n");

fprintf(stdout,"size of block by vert is %i\n",sizeof(**vert));

}

and when i called


fprintf(stdout,"Test of 3ds file complete vertex scaning\n");
Load3Ds("test.3ds",vertex, nvert);
if(!vertex)fprintf(stdout,"vertex can't initialised\n");
else if(!x)
{
fprintf(stdout,"count of vertex can't initialised\n");
exit(0);
}
else
{
/*if all false show on console*/
...
}

at the point of


Load3Ds("test.3ds",vertex, x);
if(!vertex)fprintf(stdout,"vertex can't initialised\n");
else if(!nvert)
{
fprintf(stdout,"count of vertex can't initialised\n");
exit(0);
}

i found vertex and x are not assigned
in my other OpenGL programs which use Load3ds function
they give up
and message come out


Segmentation fault 3232 ./3dtes


if i use int prototype to define Load3ds
and assign to nvert
nvert works
but vertex not assigned
and vice versa(prototype float assigned vertex but nvert??)
(these things sometimes caught by glibc for look like as a bug with long list of /lib/i915_drm(drm,intel was there exact i don't know)
when i put value of nvert manually after knowing value of testfile->meshes[0]->nvertices)

but
the problem is not come when i put
these line at last of Load3ds definition


nvert = x;
vertex = vert;
}//<-Function definition ends

but using these assignment
is not good idea
please anyone can help me on this perticular
cause i tried so much but these problem not solved very well
any Suggestion in defining function please reply
:( i hope anyone who read this can understand my problem :(
please reply to this
in this situation i am really helpless :sorrow:

please give at least link resource if possible
cause i found there no docs of lib3DS just three examples
in the source package

scratt
08-10-2009, 06:58 AM
There is a working 3DS loader in the Oolong engine, among other places on the internet. Just grab one of those and save yourself a lot of time. :)

Stuart McDonald
08-10-2009, 07:00 AM
Just skimmed this, but you do

vert = new float*[2];
for(int i=0;i<=x;i++)
{
vert[i] = new float[x];
So you allocate an array of pointers to floats with a size of TWO and then assigned values to that array from 0 to X. So do you expect X to always be 2?

Also, you pass X by value into Load3DS and assign a value to it without reading it. So why pass it in? Do you understand what "pass by value" means? i.e. you pass in a COPY of X and assign to the COPY which is lost when the function returns (the original X is unchanged).

Finally, this isn't an advanced question. It seems more like a basic need to learn to program question.

vivek vyas
08-10-2009, 10:27 AM
thanks you bring out my old memories (as i forget & at definition)
i redefined that function with float prototype(returns the vert) and with & of count of vertex
now i can load a 3DS file
only with vertex{x,y,z} part of file
now i am heading to Material cameras and blablaz.
and
thanks dude. :D
i hope 3DS loader helps