Jump to content
  • Advertisement
Sign in to follow this  
IgnisDeus

OpenGL Strange problems with my 3D file format

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

First off, thanks for spending the time to read my post. Currently I have coded a Maya plug-in to export to my own 3D file format (in binary). Then it is imported in OpenGL. The format is really quite simple; I have a header struct that looks like this:
 
struct Header
{
float Version;
int VertCount;
int TriCount;
int TextCount;
double ArraySize;
};
It's not yet finished, but for now it supplies what is needed. After that, I have an array of data, 9 float values for normals, then 9 float values for vertices, and repeats for however many triangles I have. The amount of floats contained inside the array is from the ArraySize (1 triangle=3 vertices=18 floats (normals and vertices). So far it works pretty well, and I even have it working with the OpenGL VBO extensions. But I have run into a few problems: 1)Once I export around over 15k triangles, OpenGL bugs out and begins flashing what looks like random coordinates extruding from parts of the original mesh. My computer is a 3.6ghz P4 with 3 gigs of DDR2 Ram and a Geforce 6800 Ultra. I'd expect I can handle more than 15k triangles. 2)Sometimes I will get a sphere in the export. I haven't been able to determine exactly where this comes from, but I know it's from Maya. The sphere is the original sphere template that maya creates, but the normals are distorted completely. I have tried everything, deleting construction history and so forth, with no sucess. The only way to avoid the phantom sphere is by not importing anything foreign (such as a .3ds object) and not creating an actual sphere, sticking to boxes, cones, cylinders etc. But sometimes a regular sphere will work without creating the phantom sphere. As far as the exporting and importing code goes, it's a little complicated due to Maya API, but it looks like this: Get Maya Mesh info. Determine how many vertices/triangles there are. Create dynamic array based on number of vertices + normals. Write to the file the header struct. Fill the dynamic array with the normals and vertices. Write the dynamic array to the file. The code is like this:
fstream myFile (FileName.asChar(), ios::out | ios::binary | ios::trunc); //Open file for writing in binary mode, deleting all the contents first
myFile.seekp (0); //Go to the begining of the file
myFile.write ((char*)&T, sizeof(Header)); //Write the header into the file
myFile.write ((char*)TempArray, sizeof(float)*T.ArraySize); //Write the dynamic array into the file
myFile.close(); //Close it
Then for importing, it's the same thing. Read the header, get how much space will be needed for the array, create the dynamic array, read the data in, throw it into the VBO, render it. It all works perfectly with say for example randomly spaced/rotated cubes, but with some things it will create the phantom sphere. Any help/ideas is greatly appreciated. Thank you again for reading my post!

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!