From 0a01e563f43278b3cd4f5449269e06c95781ecb5 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 13 Mar 2002 06:03:37 +0000 Subject: [PATCH] Better support of the newer more flexible object file format. This includes the ability to specify per vertex normals rather than depending the normals list being the same as the vertices list. (Support for previous binary file format scenery is maintained.) --- src/Objects/apt_signs.cxx | 22 +++++++++++------ src/Objects/obj.cxx | 52 +++++++++++++++++++++++++-------------- src/Objects/obj.hxx | 1 + 3 files changed, 48 insertions(+), 27 deletions(-) diff --git a/src/Objects/apt_signs.cxx b/src/Objects/apt_signs.cxx index 6774e729e..ee377b64e 100644 --- a/src/Objects/apt_signs.cxx +++ b/src/Objects/apt_signs.cxx @@ -65,6 +65,7 @@ ssgBranch *gen_taxi_sign( const string path, const string content ) { point_list normals; normals.clear(); point_list texcoords; texcoords.clear(); int_list vertex_index; vertex_index.clear(); + int_list normal_index; normal_index.clear(); int_list tex_index; tex_index.clear(); nodes.push_back( Point3D( -offset + i, 0, 0.25 ) ); @@ -72,9 +73,6 @@ ssgBranch *gen_taxi_sign( const string path, const string content ) { nodes.push_back( Point3D( -offset + i, 0, 1.25 ) ); nodes.push_back( Point3D( -offset + i + 1, 0, 1.25 ) ); - normals.push_back( Point3D( 0, -1, 0 ) ); - normals.push_back( Point3D( 0, -1, 0 ) ); - normals.push_back( Point3D( 0, -1, 0 ) ); normals.push_back( Point3D( 0, -1, 0 ) ); texcoords.push_back( Point3D( 0, 0, 0 ) ); @@ -87,6 +85,11 @@ ssgBranch *gen_taxi_sign( const string path, const string content ) { vertex_index.push_back( 2 ); vertex_index.push_back( 3 ); + normal_index.push_back( 0 ); + normal_index.push_back( 0 ); + normal_index.push_back( 0 ); + normal_index.push_back( 0 ); + tex_index.push_back( 0 ); tex_index.push_back( 1 ); tex_index.push_back( 2 ); @@ -94,7 +97,7 @@ ssgBranch *gen_taxi_sign( const string path, const string content ) { ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material, nodes, normals, texcoords, - vertex_index, tex_index, + vertex_index, normal_index, tex_index, false, NULL ); object->addKid( leaf ); @@ -119,6 +122,7 @@ ssgBranch *gen_runway_sign( const string path, const string name ) { point_list normals; normals.clear(); point_list texcoords; texcoords.clear(); int_list vertex_index; vertex_index.clear(); + int_list normal_index; normal_index.clear(); int_list tex_index; tex_index.clear(); nodes.push_back( Point3D( -width, 0, 0.25 ) ); @@ -126,9 +130,6 @@ ssgBranch *gen_runway_sign( const string path, const string name ) { nodes.push_back( Point3D( -width, 0, 1.25 ) ); nodes.push_back( Point3D( width + 1, 0, 1.25 ) ); - normals.push_back( Point3D( 0, -1, 0 ) ); - normals.push_back( Point3D( 0, -1, 0 ) ); - normals.push_back( Point3D( 0, -1, 0 ) ); normals.push_back( Point3D( 0, -1, 0 ) ); texcoords.push_back( Point3D( 0, 0, 0 ) ); @@ -141,6 +142,11 @@ ssgBranch *gen_runway_sign( const string path, const string name ) { vertex_index.push_back( 2 ); vertex_index.push_back( 3 ); + normal_index.push_back( 0 ); + normal_index.push_back( 0 ); + normal_index.push_back( 0 ); + normal_index.push_back( 0 ); + tex_index.push_back( 0 ); tex_index.push_back( 1 ); tex_index.push_back( 2 ); @@ -148,7 +154,7 @@ ssgBranch *gen_runway_sign( const string path, const string name ) { ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material, nodes, normals, texcoords, - vertex_index, tex_index, + vertex_index, normal_index, tex_index, false, NULL ); object->addKid( leaf ); diff --git a/src/Objects/obj.cxx b/src/Objects/obj.cxx index e56354d5d..f2470c5db 100644 --- a/src/Objects/obj.cxx +++ b/src/Objects/obj.cxx @@ -753,6 +753,7 @@ ssgLeaf *gen_leaf( const string& path, const point_list& nodes, const point_list& normals, const point_list& texcoords, const int_list node_index, + const int_list normal_index, const int_list& tex_index, const bool calc_lights, ssgVertexArray *lights ) { @@ -824,26 +825,31 @@ ssgLeaf *gen_leaf( const string& path, vl -> add( tmp3 ); } + // normals + Point3D normal; + ssgNormalArray *nl = new ssgNormalArray( size ); + if ( normal_index.size() ) { + // object file specifies normal indices (i.e. normal indices + // aren't 'implied' + for ( i = 0; i < size; ++i ) { + normal = normals[ normal_index[i] ]; + sgSetVec3( tmp3, normal[0], normal[1], normal[2] ); + nl -> add( tmp3 ); + } + } else { + // use implied normal indices. normal index = vertex index. + for ( i = 0; i < size; ++i ) { + normal = normals[ node_index[i] ]; + sgSetVec3( tmp3, normal[0], normal[1], normal[2] ); + nl -> add( tmp3 ); + } + } + // colors ssgColourArray *cl = new ssgColourArray( 1 ); sgSetVec4( tmp4, 1.0, 1.0, 1.0, 1.0 ); cl->add( tmp4 ); - // normals - Point3D normal; - ssgNormalArray *nl = new ssgNormalArray( size ); - if ( normals.size() == 1 ) { - normal = normals[ 0 ]; - sgSetVec3( tmp3, normal[0], normal[1], normal[2] ); - nl -> add( tmp3 ); - } else if ( normals.size() > 1 ) { - for ( i = 0; i < size; ++i ) { - normal = normals[ node_index[i] ]; - sgSetVec3( tmp3, normal[0], normal[1], normal[2] ); - nl -> add( tmp3 ); - } - } - // texture coordinates size = tex_index.size(); Point3D texcoord; @@ -931,6 +937,7 @@ bool fgBinObjLoad( const string& path, const bool is_base, string material, tmp_mat; int_list vertex_index; + int_list normal_index; int_list tex_index; int i; @@ -939,6 +946,7 @@ bool fgBinObjLoad( const string& path, const bool is_base, // generate points string_list pt_materials = obj.get_pt_materials(); group_list pts_v = obj.get_pts_v(); + group_list pts_n = obj.get_pts_n(); for ( i = 0; i < (int)pts_v.size(); ++i ) { cout << "pts_v.size() = " << pts_v.size() << endl; tmp_mat = pt_materials[i]; @@ -952,7 +960,7 @@ bool fgBinObjLoad( const string& path, const bool is_base, tex_index.clear(); ssgLeaf *leaf = gen_leaf( path, GL_POINTS, material, nodes, normals, texcoords, - vertex_index, tex_index, + vertex_index, normal_index, tex_index, false, ground_lights ); if ( is_lighting ) { @@ -965,14 +973,16 @@ bool fgBinObjLoad( const string& path, const bool is_base, // generate triangles string_list tri_materials = obj.get_tri_materials(); group_list tris_v = obj.get_tris_v(); + group_list tris_n = obj.get_tris_n(); group_list tris_tc = obj.get_tris_tc(); for ( i = 0; i < (int)tris_v.size(); ++i ) { material = tri_materials[i]; vertex_index = tris_v[i]; + normal_index = tris_n[i]; tex_index = tris_tc[i]; ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLES, material, nodes, normals, texcoords, - vertex_index, tex_index, + vertex_index, normal_index, tex_index, is_base, ground_lights ); geometry->addKid( leaf ); @@ -981,14 +991,16 @@ bool fgBinObjLoad( const string& path, const bool is_base, // generate strips string_list strip_materials = obj.get_strip_materials(); group_list strips_v = obj.get_strips_v(); + group_list strips_n = obj.get_strips_n(); group_list strips_tc = obj.get_strips_tc(); for ( i = 0; i < (int)strips_v.size(); ++i ) { material = strip_materials[i]; vertex_index = strips_v[i]; + normal_index = strips_n[i]; tex_index = strips_tc[i]; ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material, nodes, normals, texcoords, - vertex_index, tex_index, + vertex_index, normal_index, tex_index, is_base, ground_lights ); geometry->addKid( leaf ); @@ -997,14 +1009,16 @@ bool fgBinObjLoad( const string& path, const bool is_base, // generate fans string_list fan_materials = obj.get_fan_materials(); group_list fans_v = obj.get_fans_v(); + group_list fans_n = obj.get_fans_n(); group_list fans_tc = obj.get_fans_tc(); for ( i = 0; i < (int)fans_v.size(); ++i ) { material = fan_materials[i]; vertex_index = fans_v[i]; + normal_index = fans_n[i]; tex_index = fans_tc[i]; ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_FAN, material, nodes, normals, texcoords, - vertex_index, tex_index, + vertex_index, normal_index, tex_index, is_base, ground_lights ); geometry->addKid( leaf ); diff --git a/src/Objects/obj.hxx b/src/Objects/obj.hxx index 68ff0f98f..1a3d8b934 100644 --- a/src/Objects/obj.hxx +++ b/src/Objects/obj.hxx @@ -82,6 +82,7 @@ ssgLeaf *gen_leaf( const string& path, const point_list& nodes, const point_list& normals, const point_list& texcoords, const int_list node_index, + const int_list normal_index, const int_list& tex_index, const bool calc_lights, ssgVertexArray *lights );