1
0
Fork 0

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.)
This commit is contained in:
curt 2002-03-13 06:03:37 +00:00
parent d31fcd21ef
commit 0a01e563f4
3 changed files with 48 additions and 27 deletions

View file

@ -65,6 +65,7 @@ ssgBranch *gen_taxi_sign( const string path, const string content ) {
point_list normals; normals.clear(); point_list normals; normals.clear();
point_list texcoords; texcoords.clear(); point_list texcoords; texcoords.clear();
int_list vertex_index; vertex_index.clear(); int_list vertex_index; vertex_index.clear();
int_list normal_index; normal_index.clear();
int_list tex_index; tex_index.clear(); int_list tex_index; tex_index.clear();
nodes.push_back( Point3D( -offset + i, 0, 0.25 ) ); 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, 0, 1.25 ) );
nodes.push_back( Point3D( -offset + i + 1, 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 ) ); normals.push_back( Point3D( 0, -1, 0 ) );
texcoords.push_back( Point3D( 0, 0, 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( 2 );
vertex_index.push_back( 3 ); 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( 0 );
tex_index.push_back( 1 ); tex_index.push_back( 1 );
tex_index.push_back( 2 ); 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, ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material,
nodes, normals, texcoords, nodes, normals, texcoords,
vertex_index, tex_index, vertex_index, normal_index, tex_index,
false, NULL ); false, NULL );
object->addKid( leaf ); object->addKid( leaf );
@ -119,6 +122,7 @@ ssgBranch *gen_runway_sign( const string path, const string name ) {
point_list normals; normals.clear(); point_list normals; normals.clear();
point_list texcoords; texcoords.clear(); point_list texcoords; texcoords.clear();
int_list vertex_index; vertex_index.clear(); int_list vertex_index; vertex_index.clear();
int_list normal_index; normal_index.clear();
int_list tex_index; tex_index.clear(); int_list tex_index; tex_index.clear();
nodes.push_back( Point3D( -width, 0, 0.25 ) ); 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, 0, 1.25 ) );
nodes.push_back( Point3D( width + 1, 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 ) ); normals.push_back( Point3D( 0, -1, 0 ) );
texcoords.push_back( Point3D( 0, 0, 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( 2 );
vertex_index.push_back( 3 ); 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( 0 );
tex_index.push_back( 1 ); tex_index.push_back( 1 );
tex_index.push_back( 2 ); 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, ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material,
nodes, normals, texcoords, nodes, normals, texcoords,
vertex_index, tex_index, vertex_index, normal_index, tex_index,
false, NULL ); false, NULL );
object->addKid( leaf ); object->addKid( leaf );

View file

@ -753,6 +753,7 @@ ssgLeaf *gen_leaf( const string& path,
const point_list& nodes, const point_list& normals, const point_list& nodes, const point_list& normals,
const point_list& texcoords, const point_list& texcoords,
const int_list node_index, const int_list node_index,
const int_list normal_index,
const int_list& tex_index, const int_list& tex_index,
const bool calc_lights, ssgVertexArray *lights ) const bool calc_lights, ssgVertexArray *lights )
{ {
@ -824,19 +825,19 @@ ssgLeaf *gen_leaf( const string& path,
vl -> add( tmp3 ); vl -> add( tmp3 );
} }
// colors
ssgColourArray *cl = new ssgColourArray( 1 );
sgSetVec4( tmp4, 1.0, 1.0, 1.0, 1.0 );
cl->add( tmp4 );
// normals // normals
Point3D normal; Point3D normal;
ssgNormalArray *nl = new ssgNormalArray( size ); ssgNormalArray *nl = new ssgNormalArray( size );
if ( normals.size() == 1 ) { if ( normal_index.size() ) {
normal = normals[ 0 ]; // 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] ); sgSetVec3( tmp3, normal[0], normal[1], normal[2] );
nl -> add( tmp3 ); nl -> add( tmp3 );
} else if ( normals.size() > 1 ) { }
} else {
// use implied normal indices. normal index = vertex index.
for ( i = 0; i < size; ++i ) { for ( i = 0; i < size; ++i ) {
normal = normals[ node_index[i] ]; normal = normals[ node_index[i] ];
sgSetVec3( tmp3, normal[0], normal[1], normal[2] ); sgSetVec3( tmp3, normal[0], normal[1], normal[2] );
@ -844,6 +845,11 @@ ssgLeaf *gen_leaf( const string& path,
} }
} }
// colors
ssgColourArray *cl = new ssgColourArray( 1 );
sgSetVec4( tmp4, 1.0, 1.0, 1.0, 1.0 );
cl->add( tmp4 );
// texture coordinates // texture coordinates
size = tex_index.size(); size = tex_index.size();
Point3D texcoord; Point3D texcoord;
@ -931,6 +937,7 @@ bool fgBinObjLoad( const string& path, const bool is_base,
string material, tmp_mat; string material, tmp_mat;
int_list vertex_index; int_list vertex_index;
int_list normal_index;
int_list tex_index; int_list tex_index;
int i; int i;
@ -939,6 +946,7 @@ bool fgBinObjLoad( const string& path, const bool is_base,
// generate points // generate points
string_list pt_materials = obj.get_pt_materials(); string_list pt_materials = obj.get_pt_materials();
group_list pts_v = obj.get_pts_v(); 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 ) { for ( i = 0; i < (int)pts_v.size(); ++i ) {
cout << "pts_v.size() = " << pts_v.size() << endl; cout << "pts_v.size() = " << pts_v.size() << endl;
tmp_mat = pt_materials[i]; tmp_mat = pt_materials[i];
@ -952,7 +960,7 @@ bool fgBinObjLoad( const string& path, const bool is_base,
tex_index.clear(); tex_index.clear();
ssgLeaf *leaf = gen_leaf( path, GL_POINTS, material, ssgLeaf *leaf = gen_leaf( path, GL_POINTS, material,
nodes, normals, texcoords, nodes, normals, texcoords,
vertex_index, tex_index, vertex_index, normal_index, tex_index,
false, ground_lights ); false, ground_lights );
if ( is_lighting ) { if ( is_lighting ) {
@ -965,14 +973,16 @@ bool fgBinObjLoad( const string& path, const bool is_base,
// generate triangles // generate triangles
string_list tri_materials = obj.get_tri_materials(); string_list tri_materials = obj.get_tri_materials();
group_list tris_v = obj.get_tris_v(); group_list tris_v = obj.get_tris_v();
group_list tris_n = obj.get_tris_n();
group_list tris_tc = obj.get_tris_tc(); group_list tris_tc = obj.get_tris_tc();
for ( i = 0; i < (int)tris_v.size(); ++i ) { for ( i = 0; i < (int)tris_v.size(); ++i ) {
material = tri_materials[i]; material = tri_materials[i];
vertex_index = tris_v[i]; vertex_index = tris_v[i];
normal_index = tris_n[i];
tex_index = tris_tc[i]; tex_index = tris_tc[i];
ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLES, material, ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLES, material,
nodes, normals, texcoords, nodes, normals, texcoords,
vertex_index, tex_index, vertex_index, normal_index, tex_index,
is_base, ground_lights ); is_base, ground_lights );
geometry->addKid( leaf ); geometry->addKid( leaf );
@ -981,14 +991,16 @@ bool fgBinObjLoad( const string& path, const bool is_base,
// generate strips // generate strips
string_list strip_materials = obj.get_strip_materials(); string_list strip_materials = obj.get_strip_materials();
group_list strips_v = obj.get_strips_v(); group_list strips_v = obj.get_strips_v();
group_list strips_n = obj.get_strips_n();
group_list strips_tc = obj.get_strips_tc(); group_list strips_tc = obj.get_strips_tc();
for ( i = 0; i < (int)strips_v.size(); ++i ) { for ( i = 0; i < (int)strips_v.size(); ++i ) {
material = strip_materials[i]; material = strip_materials[i];
vertex_index = strips_v[i]; vertex_index = strips_v[i];
normal_index = strips_n[i];
tex_index = strips_tc[i]; tex_index = strips_tc[i];
ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material, ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material,
nodes, normals, texcoords, nodes, normals, texcoords,
vertex_index, tex_index, vertex_index, normal_index, tex_index,
is_base, ground_lights ); is_base, ground_lights );
geometry->addKid( leaf ); geometry->addKid( leaf );
@ -997,14 +1009,16 @@ bool fgBinObjLoad( const string& path, const bool is_base,
// generate fans // generate fans
string_list fan_materials = obj.get_fan_materials(); string_list fan_materials = obj.get_fan_materials();
group_list fans_v = obj.get_fans_v(); group_list fans_v = obj.get_fans_v();
group_list fans_n = obj.get_fans_n();
group_list fans_tc = obj.get_fans_tc(); group_list fans_tc = obj.get_fans_tc();
for ( i = 0; i < (int)fans_v.size(); ++i ) { for ( i = 0; i < (int)fans_v.size(); ++i ) {
material = fan_materials[i]; material = fan_materials[i];
vertex_index = fans_v[i]; vertex_index = fans_v[i];
normal_index = fans_n[i];
tex_index = fans_tc[i]; tex_index = fans_tc[i];
ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_FAN, material, ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_FAN, material,
nodes, normals, texcoords, nodes, normals, texcoords,
vertex_index, tex_index, vertex_index, normal_index, tex_index,
is_base, ground_lights ); is_base, ground_lights );
geometry->addKid( leaf ); geometry->addKid( leaf );

View file

@ -82,6 +82,7 @@ ssgLeaf *gen_leaf( const string& path,
const point_list& nodes, const point_list& normals, const point_list& nodes, const point_list& normals,
const point_list& texcoords, const point_list& texcoords,
const int_list node_index, const int_list node_index,
const int_list normal_index,
const int_list& tex_index, const int_list& tex_index,
const bool calc_lights, ssgVertexArray *lights ); const bool calc_lights, ssgVertexArray *lights );