Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ignite

Turespace Model Loading...

This topic is 6329 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

Not really sure if this is where to post but... I''m working on a Truespace model loader. I downloaded th *only* file format document on the *.cob (Truespace object file) from Whotsit that i found. I can read in the header values, but after that, when I try to start to read in chunks, the program won''t work. The header is in plain text in the files, but the data is in binary. I''m using:
  
FILE* fp;
if ((fp = fopen(filename, "rb")) == NULL)
  return false;

// read in header....


// read in chunks - get run-time errors

  
I''m new to loading binary files, so I wonder if I''m doing something wrong. Anyways, if someone could point me to a site that has another *.cob format specification (the on I have is for version 2!) or maybe some example source code or tutorials on binary files or Truespace model loading. I appreciate any help given. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Here''s some code I wrote a while ago, but it will only load file which have a single object (a single polygonal data chunk), it the file has materials or groups it''ll crash, but I think it might not be that hard to update it. Anyway hopefully this will help you out. The code also does not deal with the current position and axis matrices.

  
cob_header COB_Header;
cob_local_vertex_list *COB_Vertex_List;
cob_UV_List UV_List;
cob_Faces *Faces;

cob_polygonal_data_chunk_header COB_PolyChunk_Header;
cob_chunk_name COB_Chunk_Name;
cob_local_axis COB_Local_Axis;
cob_current_pos COB_Current_Pos;

FILE *fileptr = fopen(filename,"rb");

fread(&COB_Header,sizeof(COB_Header),1,fileptr);
fread(&COB_PolyChunk_Header,sizeof(COB_PolyChunk_Header),1,fileptr);

fread(&COB_Chunk_Name.dupecount,sizeof(COB_Chunk_Name.dupecount),1,fileptr);
fread(&COB_Chunk_Name.str_len,sizeof(COB_Chunk_Name.str_len),1,fileptr);
fread(&COB_Chunk_Name.name,COB_Chunk_Name.str_len,1,fileptr);

fread(&COB_Local_Axis,sizeof(COB_Local_Axis),1,fileptr);
fread(&COB_Current_Pos,sizeof(COB_Current_Pos),1,fileptr);

fread(&num_verticies,sizeof(long),1,fileptr);

COB_Vertex_List = new cob_local_vertex_list[num_verticies];

for(int i=0; i<num_verticies; i++)
fread(&COB_Vertex_List[i],sizeof(cob_local_vertex_list),1,fileptr);


fread(&num_uv,sizeof(long),1,fileptr);

UV_List.u = new float[num_uv];
UV_List.v = new float[num_uv];

for(i=0; i<num_uv; i++)
{
fread(&UV_List.u[i],sizeof(float),1,fileptr);
fread(&UV_List.v[i],sizeof(float),1,fileptr);
}

fread(&num_faces,sizeof(long),1,fileptr);

Faces = new cob_Faces[num_faces];

for(i=0; i<num_faces; i++)
{
fread(&Faces[i].flags_byte,sizeof(Faces[i].flags_byte),1,fileptr);
fread(&Faces[i].num_verticies,sizeof(Faces[i].num_verticies),1,fileptr);
fread(&Faces[i].mat_index,sizeof(Faces[i].mat_index),1,fileptr);
fread(&Faces[i].vertex_index[0],sizeof(Faces[i].vertex_index[0]),1,fileptr);
fread(&Faces[i].uv_index[0],sizeof(Faces[i].uv_index[0]),1,fileptr);
fread(&Faces[i].vertex_index[1],sizeof(Faces[i].vertex_index[1]),1,fileptr);
fread(&Faces[i].uv_index[1],sizeof(Faces[i].uv_index[1]),1,fileptr);
fread(&Faces[i].vertex_index[2],sizeof(Faces[i].vertex_index[2]),1,fileptr);
fread(&Faces[i].uv_index[2],sizeof(Faces[i].uv_index[2]),1,fileptr);
}



you should also make sure you''ve set up your structures correctly (sorry about the bad naming)...

typedef struct
{
char id[9];
char version[6];
char binary;
char endian[2];
char blanks[13];
char newline;
}cob_header;

typedef struct
{
char type[4];
short major_version;
short minor_version;
long chunk_id;
long parent_id;
long num_bytes;
}cob_polygonal_data_chunk_header;

typedef struct
{
short dupecount;
short str_len;
char *name;
}cob_chunk_name;

typedef struct
{
float center[3];
float dir_x[3];
float dir_y[3];
float dir_z[3];
}cob_local_axis;

typedef struct
{
float MatrixRow1[4];
float MatrixRow2[4];
float MatrixRow3[4];
}cob_current_pos;


typedef struct
{
float Vertex_Coordinates[3];
}cob_local_vertex_list;

typedef struct
{
float *u;
float *v;
}cob_UV_List;


typedef struct
{
BYTE flags_byte;
short num_verticies;
short mat_index;
long vertex_index[3];
long uv_index[3];

}cob_Faces;

typedef struct
{
long num_verticies;
long num_faces;
long num_uv;
point_3d *VertexList;
cob_UV_List UV_List;
cob_Faces *Faces;

}cob_data;



Digital Radiation

Share this post


Link to post
Share on other sites

  • 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!