+ // cout << "before list allocs" << endl;
+
+ // cout << "before vl, size = " << size << endl;
+ // cout << "before nl" << endl;
+ // cout << "before tl" << endl;
+ // cout << "before cl" << endl;
+
+ sgVec2 tmp2;
+ sgVec3 tmp3;
+ sgVec4 tmp4;
+ int i;
+
+ // vertices
+ int size = node_index.size();
+ if ( size < 1 ) {
+ SG_LOG( SG_TERRAIN, SG_ALERT, "Woh! node list size < 1" );
+ exit(-1);
+ }
+ ssgVertexArray *vl = new ssgVertexArray( size );
+ Point3D node;
+ for ( i = 0; i < size; ++i ) {
+ node = nodes[ node_index[i] ];
+ sgSetVec3( tmp3, node[0], node[1], node[2] );
+ 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 ) {
+ 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;
+ ssgTexCoordArray *tl = new ssgTexCoordArray( size );
+ if ( size == 1 ) {
+ texcoord = texcoords[ tex_index[0] ];
+ sgSetVec2( tmp2, texcoord[0], texcoord[1] );
+ sgSetVec2( tmp2, texcoord[0], texcoord[1] );
+ if ( tex_width > 0 ) {
+ tmp2[0] *= (1000.0 / tex_width);
+ }
+ if ( tex_height > 0 ) {
+ tmp2[1] *= (1000.0 / tex_height);
+ }
+ tl -> add( tmp2 );
+ } else if ( size > 1 ) {
+ for ( i = 0; i < size; ++i ) {
+ texcoord = texcoords[ tex_index[i] ];
+ sgSetVec2( tmp2, texcoord[0], texcoord[1] );
+ if ( tex_width > 0 ) {
+ tmp2[0] *= (1000.0 / tex_width);
+ }
+ if ( tex_height > 0 ) {
+ tmp2[1] *= (1000.0 / tex_height);
+ }
+ tl -> add( tmp2 );
+ }
+ }
+
+ // cout << "before leaf create" << endl;
+ ssgLeaf *leaf = new ssgVtxTable ( ty, vl, nl, tl, cl );
+ // cout << "after leaf create" << endl;
+
+ // lookup the state record
+ // cout << "looking up material = " << endl;
+ // cout << material << endl;
+ // cout << "'" << endl;
+