Alas, I have made non-backwardsly compatible changes to the scenery file
format. Thus I have had to make the corresponding changes here in the file loader. Things that do not correspond the the .obj format are placed in comments.
This commit is contained in:
parent
b722f8bb63
commit
35e2cf2307
1 changed files with 314 additions and 315 deletions
169
Objects/obj.cxx
169
Objects/obj.cxx
|
@ -141,22 +141,16 @@ int fgObjLoad( const string& path, fgTILE *t) {
|
|||
|
||||
// Attempt to open "path.gz" or "path"
|
||||
fg_gzifstream in( path );
|
||||
if ( ! in )
|
||||
{
|
||||
// Attempt to open "path.obj" or "path.obj.gz"
|
||||
in.open( path + ".obj" );
|
||||
if ( ! in )
|
||||
{
|
||||
if ( ! in ) {
|
||||
FG_LOG( FG_TERRAIN, FG_ALERT, "Cannot open file: " << path );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
shading = current_options.get_shading();
|
||||
|
||||
in_fragment = 0;
|
||||
t->ncount = 1;
|
||||
vncount = 1;
|
||||
t->ncount = 0;
|
||||
vncount = 0;
|
||||
t->bounding_radius = 0.0;
|
||||
nodes = t->nodes;
|
||||
center = t->center;
|
||||
|
@ -165,58 +159,37 @@ int fgObjLoad( const string& path, fgTILE *t) {
|
|||
stopwatch.start();
|
||||
|
||||
// ignore initial comments and blank lines. (priming the pump)
|
||||
in >> skipcomment;
|
||||
|
||||
while ( ! in.eof() )
|
||||
{
|
||||
// in >> skipcomment;
|
||||
string line;
|
||||
|
||||
while ( ! in.eof() ) {
|
||||
string token;
|
||||
char c;
|
||||
|
||||
in >> skipws;
|
||||
|
||||
if ( in.get( c ) && c == '#' ) {
|
||||
// process a comment line
|
||||
|
||||
// getline( in, line );
|
||||
// cout << "comment = " << line << endl;
|
||||
|
||||
in >> token;
|
||||
|
||||
// printf("token = %s\n", token.c_str() );
|
||||
|
||||
if ( token == "gbs" )
|
||||
{
|
||||
if ( token == "gbs" ) {
|
||||
// reference point (center offset)
|
||||
in >> t->center >> t->bounding_radius;
|
||||
center = t->center;
|
||||
}
|
||||
else if ( token == "bs" )
|
||||
{
|
||||
// cout << "center = " << center
|
||||
// << " radius = " << t->bounding_radius << endl;
|
||||
} else if ( token == "bs" ) {
|
||||
// reference point (center offset)
|
||||
in >> fragment.center;
|
||||
in >> fragment.bounding_radius;
|
||||
}
|
||||
else if ( token == "vn" )
|
||||
{
|
||||
// vertex normal
|
||||
if ( vncount < MAX_NODES ) {
|
||||
in >> normals[vncount][0]
|
||||
>> normals[vncount][1]
|
||||
>> normals[vncount][2];
|
||||
vncount++;
|
||||
} else {
|
||||
FG_LOG( FG_TERRAIN, FG_ALERT,
|
||||
"Read too many vertex normals ... dying :-(" );
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
else if ( token[0] == 'v' )
|
||||
{
|
||||
// node (vertex)
|
||||
if ( t->ncount < MAX_NODES ) {
|
||||
in >> t->nodes[t->ncount][0]
|
||||
>> t->nodes[t->ncount][1]
|
||||
>> t->nodes[t->ncount][2];
|
||||
t->ncount++;
|
||||
} else {
|
||||
FG_LOG( FG_TERRAIN, FG_ALERT,
|
||||
"Read too many nodes ... dying :-(");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
else if ( token == "usemtl" )
|
||||
{
|
||||
|
||||
// cout << "center = " << fragment.center
|
||||
// << " radius = " << fragment.bounding_radius << endl;
|
||||
} else if ( token == "usemtl" ) {
|
||||
// material property specification
|
||||
|
||||
// this also signals the start of a new fragment
|
||||
|
@ -267,12 +240,50 @@ int fgObjLoad( const string& path, fgTILE *t) {
|
|||
fragment.matrix[0] = fragment.matrix[5] =
|
||||
fragment.matrix[10] = fragment.matrix[15] = 1.0;
|
||||
*/
|
||||
} else {
|
||||
// unknown comment, just gobble the input untill the
|
||||
// end of line
|
||||
|
||||
in >> skipeol;
|
||||
}
|
||||
} else {
|
||||
in.putback( c );
|
||||
|
||||
in >> token;
|
||||
|
||||
// cout << "token = " << token << endl;
|
||||
|
||||
if ( token == "vn" ) {
|
||||
// vertex normal
|
||||
if ( vncount < MAX_NODES ) {
|
||||
in >> normals[vncount][0]
|
||||
>> normals[vncount][1]
|
||||
>> normals[vncount][2];
|
||||
vncount++;
|
||||
} else {
|
||||
FG_LOG( FG_TERRAIN, FG_ALERT,
|
||||
"Read too many vertex normals ... dying :-(" );
|
||||
exit(-1);
|
||||
}
|
||||
} else if ( token[0] == 'v' ) {
|
||||
// node (vertex)
|
||||
if ( t->ncount < MAX_NODES ) {
|
||||
in >> t->nodes[t->ncount][0]
|
||||
>> t->nodes[t->ncount][1]
|
||||
>> t->nodes[t->ncount][2];
|
||||
t->ncount++;
|
||||
} else {
|
||||
FG_LOG( FG_TERRAIN, FG_ALERT,
|
||||
"Read too many nodes ... dying :-(");
|
||||
exit(-1);
|
||||
}
|
||||
} else if ( token[0] == 't' ) {
|
||||
// start a new triangle strip
|
||||
|
||||
n1 = n2 = n3 = n4 = 0;
|
||||
|
||||
// fgPrintf( FG_TERRAIN, FG_DEBUG, " new tri strip = %s", line);
|
||||
// fgPrintf( FG_TERRAIN, FG_DEBUG,
|
||||
// " new tri strip = %s", line);
|
||||
in >> n1 >> n2 >> n3;
|
||||
fragment.add_face(n1, n2, n3);
|
||||
|
||||
|
@ -291,21 +302,18 @@ int fgObjLoad( const string& path, fgTILE *t) {
|
|||
xglNormal3dv(normal);
|
||||
pp = calc_tex_coords(nodes[n1], center);
|
||||
xglTexCoord2f(pp.lon(), pp.lat());
|
||||
// xglVertex3d(t->nodes[n1][0],t->nodes[n1][1],t->nodes[n1][2]);
|
||||
xglVertex3dv(nodes[n1]);
|
||||
|
||||
MAT3_SCALE_VEC(normal, normals[n2], scale);
|
||||
xglNormal3dv(normal);
|
||||
pp = calc_tex_coords(nodes[n2], center);
|
||||
xglTexCoord2f(pp.lon(), pp.lat());
|
||||
//xglVertex3d(t->nodes[n2][0],t->nodes[n2][1],t->nodes[n2][2]);
|
||||
xglVertex3dv(nodes[n2]);
|
||||
|
||||
MAT3_SCALE_VEC(normal, normals[n3], scale);
|
||||
xglNormal3dv(normal);
|
||||
pp = calc_tex_coords(nodes[n3], center);
|
||||
xglTexCoord2f(pp.lon(), pp.lat());
|
||||
// xglVertex3d(t->nodes[n3][0],t->nodes[n3][1],t->nodes[n3][2]);
|
||||
xglVertex3dv(nodes[n3]);
|
||||
} else {
|
||||
// Shading model is "GL_FLAT" so calculate per face
|
||||
|
@ -322,17 +330,14 @@ int fgObjLoad( const string& path, fgTILE *t) {
|
|||
|
||||
pp = calc_tex_coords(nodes[n1], center);
|
||||
xglTexCoord2f(pp.lon(), pp.lat());
|
||||
// xglVertex3d(t->nodes[n1][0],t->nodes[n1][1],t->nodes[n1][2]);
|
||||
xglVertex3dv(nodes[n1]);
|
||||
|
||||
pp = calc_tex_coords(nodes[n2], center);
|
||||
xglTexCoord2f(pp.lon(), pp.lat());
|
||||
// xglVertex3d(t->nodes[n2][0],t->nodes[n2][1],t->nodes[n2][2]);
|
||||
xglVertex3dv(nodes[n2]);
|
||||
|
||||
pp = calc_tex_coords(nodes[n3], center);
|
||||
xglTexCoord2f(pp.lon(), pp.lat());
|
||||
// xglVertex3d(t->nodes[n3][0],t->nodes[n3][1],t->nodes[n3][2]);
|
||||
xglVertex3dv(nodes[n3]);
|
||||
}
|
||||
// printf("some normals, texcoords, and vertices\n");
|
||||
|
@ -343,13 +348,11 @@ int fgObjLoad( const string& path, fgTILE *t) {
|
|||
|
||||
// There can be three or four values
|
||||
char c;
|
||||
while ( in.get(c) )
|
||||
{
|
||||
if ( c == '\n' )
|
||||
while ( in.get(c) ) {
|
||||
if ( c == '\n' ) {
|
||||
break; // only the one
|
||||
|
||||
if ( isdigit(c) )
|
||||
{
|
||||
}
|
||||
if ( isdigit(c) ){
|
||||
in.putback(c);
|
||||
in >> n4;
|
||||
break;
|
||||
|
@ -371,7 +374,6 @@ int fgObjLoad( const string& path, fgTILE *t) {
|
|||
xglNormal3dv(normal);
|
||||
pp = calc_tex_coords(nodes[n4], center);
|
||||
xglTexCoord2f(pp.lon(), pp.lat());
|
||||
// xglVertex3d(t->nodes[n4][0],t->nodes[n4][1],t->nodes[n4][2]);
|
||||
xglVertex3dv(nodes[n4]);
|
||||
|
||||
odd = 1 - odd;
|
||||
|
@ -396,21 +398,16 @@ int fgObjLoad( const string& path, fgTILE *t) {
|
|||
xglNormal3dv(normals[n1]);
|
||||
pp = calc_tex_coords(nodes[n1], center);
|
||||
xglTexCoord2f(pp.lon(), pp.lat());
|
||||
// xglVertex3d(t->nodes[n1][0], t->nodes[n1][1], t->nodes[n1][2]);
|
||||
xglVertex3dv(nodes[n1]);
|
||||
|
||||
// xglNormal3d(normals[n2][0], normals[n2][1], normals[n2][2]);
|
||||
xglNormal3dv(normals[n2]);
|
||||
pp = calc_tex_coords(nodes[n2], center);
|
||||
xglTexCoord2f(pp.lon(), pp.lat());
|
||||
// xglVertex3d(t->nodes[n2][0], t->nodes[n2][1], t->nodes[n2][2]);
|
||||
xglVertex3dv(nodes[n2]);
|
||||
|
||||
// xglNormal3d(normals[n3][0], normals[n3][1], normals[n3][2]);
|
||||
xglNormal3dv(normals[n3]);
|
||||
pp = calc_tex_coords(nodes[n3], center);
|
||||
xglTexCoord2f(pp.lon(), pp.lat());
|
||||
// xglVertex3d(t->nodes[n3][0], t->nodes[n3][1], t->nodes[n3][2]);
|
||||
xglVertex3dv(nodes[n3]);
|
||||
// printf("some normals, texcoords, and vertices (tris)\n");
|
||||
} else if ( token[0] == 'q' ) {
|
||||
|
@ -423,13 +420,12 @@ int fgObjLoad( const string& path, fgTILE *t) {
|
|||
|
||||
// There can be one or two values
|
||||
char c;
|
||||
while ( in.get(c) )
|
||||
{
|
||||
if ( c == '\n' )
|
||||
while ( in.get(c) ) {
|
||||
if ( c == '\n' ) {
|
||||
break; // only the one
|
||||
}
|
||||
|
||||
if ( isdigit(c) )
|
||||
{
|
||||
if ( isdigit(c) ) {
|
||||
in.putback(c);
|
||||
in >> n2;
|
||||
break;
|
||||
|
@ -461,7 +457,6 @@ int fgObjLoad( const string& path, fgTILE *t) {
|
|||
|
||||
pp = calc_tex_coords(nodes[n1], center);
|
||||
xglTexCoord2f(pp.lon(), pp.lat());
|
||||
// xglVertex3d(t->nodes[n1][0], t->nodes[n1][1], t->nodes[n1][2]);
|
||||
xglVertex3dv(nodes[n1]);
|
||||
// printf("a normal, texcoord, and vertex (4th)\n");
|
||||
|
||||
|
@ -496,7 +491,6 @@ int fgObjLoad( const string& path, fgTILE *t) {
|
|||
|
||||
pp = calc_tex_coords(nodes[n2], center);
|
||||
xglTexCoord2f(pp.lon(), pp.lat());
|
||||
// xglVertex3d(t->nodes[n2][0],t->nodes[n2][1],t->nodes[n2][2]);
|
||||
xglVertex3dv(nodes[n2]);
|
||||
// printf("a normal, texcoord, and vertex (4th)\n");
|
||||
|
||||
|
@ -509,9 +503,10 @@ int fgObjLoad( const string& path, fgTILE *t) {
|
|||
<< path << " = " << token );
|
||||
}
|
||||
|
||||
// eat comments and blank lines before start of while loop so
|
||||
// if we are done with useful input it is noticed before hand.
|
||||
in >> skipcomment;
|
||||
// eat white space before start of while loop so if we are
|
||||
// done with useful input it is noticed before hand.
|
||||
in >> skipws;
|
||||
}
|
||||
}
|
||||
|
||||
if ( in_fragment ) {
|
||||
|
@ -527,8 +522,8 @@ int fgObjLoad( const string& path, fgTILE *t) {
|
|||
t->fragment_list.push_back(fragment);
|
||||
}
|
||||
|
||||
#if 0
|
||||
// Draw normal vectors (for visually verifying normals)
|
||||
/*
|
||||
xglBegin(GL_LINES);
|
||||
xglColor3f(0.0, 0.0, 0.0);
|
||||
for ( i = 0; i < t->ncount; i++ ) {
|
||||
|
@ -540,20 +535,24 @@ int fgObjLoad( const string& path, fgTILE *t) {
|
|||
t->nodes[i][2] + 500*normals[i][2]);
|
||||
}
|
||||
xglEnd();
|
||||
*/
|
||||
#endif
|
||||
|
||||
stopwatch.stop();
|
||||
FG_LOG( FG_TERRAIN, FG_INFO,
|
||||
"Loaded " << path << " in "
|
||||
<< stopwatch.elapsedSeconds() << " seconds" );
|
||||
|
||||
// printf("end of tile\n");
|
||||
|
||||
return(1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.13 1999/03/27 05:36:03 curt
|
||||
// Alas, I have made non-backwardsly compatible changes to the scenery file
|
||||
// format. Thus I have had to make the corresponding changes here in the
|
||||
// file loader.
|
||||
// Things that do not correspond the the .obj format are placed in comments.
|
||||
//
|
||||
// Revision 1.12 1999/03/02 01:03:25 curt
|
||||
// Tweaks for building with native SGI compilers.
|
||||
//
|
||||
|
|
Loading…
Add table
Reference in a new issue