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 ) );
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 ) );
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 );
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 );
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 ) );
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 ) );
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 );
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 );
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 )
{
vl -> 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 ) {
+ if ( normal_index.size() ) {
+ // object file specifies normal indices (i.e. normal indices
+ // aren't 'implied'
for ( i = 0; i < size; ++i ) {
- normal = normals[ node_index[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 );
+
// texture coordinates
size = tex_index.size();
Point3D texcoord;
string material, tmp_mat;
int_list vertex_index;
+ int_list normal_index;
int_list tex_index;
int i;
// 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];
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 ) {
// 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 );
// 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 );
// 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 );