PDA

View Full Version : Models!!



SeeDAreW
03-06-2002, 06:01 AM
Hi everyone!
Can someone tell me how to import models from Pro-E or Divison MockUp in my project?????

nexusone
03-06-2002, 04:20 PM
You would have to know the format of the Models used by Pro-E or Divison MockUp.
Maybe that could be part of your learning opengl is to create you own model loader for these formats.


If the programs will export, OBJ, 3DS, OR milkshape, there are lot's of examples of loading these types of models



Originally posted by SeeDAreW:
Hi everyone!
Can someone tell me how to import models from Pro-E or Divison MockUp in my project?????

Rob The Bloke
03-06-2002, 06:12 PM
Pro-E? Product design type student then eh? Most CAD packages offer some file format to deal with geometry. Chances are that Pro-E will deal with IGES or DXF. It should be do-able to load the file and then display the data, but the file is likely to be purely face/vertex data and you may have to deal with a bit of maths to calculate the normals & texture co-ordinates.

SeeDAreW
03-08-2002, 01:45 AM
Ok, how do I load them?????

Originally posted by nexusone:
You would have to know the format of the Models used by Pro-E or Divison MockUp.
Maybe that could be part of your learning opengl is to create you own model loader for these formats.


If the programs will export, OBJ, 3DS, OR milkshape, there are lot's of examples of loading these types of models

Mazy
03-08-2002, 01:56 AM
Originally posted by SeeDAreW:
Ok, how do I load them?????


OpenGL cant load geometry. You have to write or get a loader for some object format, and convert it all to polygons that you can feed opengl with.

Rob The Bloke
03-08-2002, 06:14 AM
goto www.wotsit.org (http://www.wotsit.org.) . Look for the file format you want. Read the file in using fopen,fscanf etc, store it in dynamic arrays, draw it.



[This message has been edited by Rob The Bloke (edited 03-08-2002).]

nexusone
03-08-2002, 07:39 AM
Depend's on what format you want to load, ether way you will have to copy someone else's code for the routines loading that format.

try http://nehe.gamedev.net he has some model loader examples on his site.


Originally posted by SeeDAreW:
Ok, how do I load them?????

Rob The Bloke
03-11-2002, 09:57 PM
Originally posted by nexusone:
Depend's on what format you want to load, ether way you will have to copy someone else's code for the routines loading that format.

You cannot say that you will HAVE to copy someone else's code to do it. If the format you choose to use is well defined then loading the format is not going to be that big a deal.

*. Firstly, copying code will not make you understand it so you learn nothing.

* Secondly, without the understanding of the code you are using, you can never alter it to add new features.

* Thirdly, there may be bugs in someone elses code which can be almost impossible to solve without the understanding of it.

Pro-E is a CAD program so it's very unlikely to support formats such as OBJ, 3DS or milkshape. It is however pretty much guarenteed to support dxf or iges files. Copying code is very unlikely in this situation because the loading of these files isn't usually documented in tutorials.

A general set of rules applies for loading simple geometry data files, which relates to this process.

1. Open the file (either use fopen (in C) or ifstream (in C++) to do it)

2. Determine how many data elements are contained in the file. If you have to read the through the entire file to do it then fine, it's more preferable than the alternative of not knowing. Usually this involves searching for tokens such as "v" for a vertex in the obj file.

3. Allocate memory for the data that you are going to read, in C use something like :

float *floatArray = (float*)malloc( numberOfDataElements * sizeof(float) );

in C++, use

float *floatArray = new float[ numberOfDataElements ];

4. Read through the file and read in the data into your array.

5. Close the file.


All that's left is then displaying the data which is up to you if you use immediate mode, vertex arrays or display lists.

As a final point, don't use linked lists or any other dynamic storage method for file loading, it makes absolutely no sense and is too slow.

Simon666
10-21-2002, 12:59 AM
Hello, I use the following code to read in 3D models from a STL file, one of the export formats of Pro-Engineer:

void CadSurface::ReadIn( CString FileName )
{
CFile CADFile(FileName,CFile::modeRead|CFile::typeBinary );

char s[80], unused[2];

int NumberOfFacets, n[1];

float normal [3],
vertex1[3],
vertex2[3],
vertex3[3];

Facet1 NewFacet;


CADFile.Read(s,80*sizeof(char));
CADFile.Read(n, 1*sizeof(int ));

NumberOfFacets=n[0];

for (int i=0;i<NumberOfFacets;i++)
{
CADFile.Read(normal ,3*sizeof(float));
CADFile.Read(vertex1,3*sizeof(float));
CADFile.Read(vertex2,3*sizeof(float));
CADFile.Read(vertex3,3*sizeof(float));
CADFile.Read(unused ,2*sizeof(char ));

NewFacet = Facet1(normal,vertex1,vertex2,vertex3);

Facets.Add(NewFacet);
}
}

Basically, I have a class CADSurface which is composed of among others an array (CArrayEx) of facets, this is triangles. Each facet or triangle has as data members the three location vertices as well as the surface normal. If anybody has similar code to read in 3D objects from IGES files, please let me know.