1 // obj.cxx -- routines to handle "sorta" WaveFront .obj format files.
3 // Written by Curtis Olson, started October 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #ifdef SG_MATH_EXCEPTION_CLASH
35 #include <simgear/compiler.h>
36 #include <simgear/io/sg_binobj.hxx>
40 #include <vector> // STL
41 #include <ctype.h> // isdigit()
43 #include <simgear/constants.h>
44 #include <simgear/debug/logstream.hxx>
45 #include <simgear/math/point3d.hxx>
46 #include <simgear/math/polar3d.hxx>
47 #include <simgear/math/sg_geodesy.hxx>
48 #include <simgear/math/sg_random.h>
49 #include <simgear/misc/sgstream.hxx>
50 #include <simgear/misc/stopwatch.hxx>
51 #include <simgear/misc/texcoord.hxx>
53 #include <Main/globals.hxx>
54 #include <Main/fg_props.hxx>
55 #include <Scenery/tileentry.hxx>
64 typedef vector < int > int_list;
65 typedef int_list::iterator int_list_iterator;
66 typedef int_list::const_iterator int_point_list_iterator;
69 static double normals[FG_MAX_NODES][3];
70 static double tex_coords[FG_MAX_NODES*3][3];
73 #define FG_TEX_CONSTANT 69.0
75 // Calculate texture coordinates for a given point.
76 static Point3D local_calc_tex_coords(const Point3D& node, const Point3D& ref) {
79 // double tmplon, tmplat;
81 // cout << "-> " << node[0] << " " << node[1] << " " << node[2] << endl;
82 // cout << "-> " << ref.x() << " " << ref.y() << " " << ref.z() << endl;
84 cp = Point3D( node[0] + ref.x(),
88 pp = sgCartToPolar3d(cp);
90 // tmplon = pp.lon() * SGD_RADIANS_TO_DEGREES;
91 // tmplat = pp.lat() * SGD_RADIANS_TO_DEGREES;
92 // cout << tmplon << " " << tmplat << endl;
94 pp.setx( fmod(SGD_RADIANS_TO_DEGREES * FG_TEX_CONSTANT * pp.x(), 11.0) );
95 pp.sety( fmod(SGD_RADIANS_TO_DEGREES * FG_TEX_CONSTANT * pp.y(), 11.0) );
98 pp.setx( pp.x() + 11.0 );
101 if ( pp.y() < 0.0 ) {
102 pp.sety( pp.y() + 11.0 );
105 // cout << pp << endl;
111 // Generate a generic ocean tile on the fly
112 ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
115 ssgSimpleState *state = NULL;
117 ssgBranch *tile = new ssgBranch () ;
119 SG_LOG( SG_TERRAIN, SG_ALERT, "fgGenTile(): NO MEMORY" );
123 tile -> setName ( (char *)path.c_str() ) ;
125 double tex_width = 1000.0;
126 // double tex_height;
128 // find Ocean material in the properties list
129 newmat = material_lib.find( "Ocean" );
130 if ( newmat != NULL ) {
131 // set the texture width and height values for this
133 tex_width = newmat->get_xsize();
134 // tex_height = newmat->get_ysize();
137 state = newmat->get_state();
139 SG_LOG( SG_TERRAIN, SG_ALERT,
140 "Ack! unknown usemtl name = " << "Ocean"
144 // Calculate center point
145 SGBucket b = t->tile_bucket;
146 double clon = b.get_center_lon();
147 double clat = b.get_center_lat();
148 double height = b.get_height();
149 double width = b.get_width();
151 Point3D center = sgGeodToCart(Point3D(clon*SGD_DEGREES_TO_RADIANS,clat*SGD_DEGREES_TO_RADIANS,0.0));
153 // cout << "center = " << center << endl;;
155 // Caculate corner vertices
157 geod[0] = Point3D( clon - width/2.0, clat - height/2.0, 0.0 );
158 geod[1] = Point3D( clon + width/2.0, clat - height/2.0, 0.0 );
159 geod[2] = Point3D( clon + width/2.0, clat + height/2.0, 0.0 );
160 geod[3] = Point3D( clon - width/2.0, clat + height/2.0, 0.0 );
164 for ( i = 0; i < 4; ++i ) {
165 rad[i] = Point3D( geod[i].x() * SGD_DEGREES_TO_RADIANS,
166 geod[i].y() * SGD_DEGREES_TO_RADIANS,
170 Point3D cart[4], rel[4];
172 for ( i = 0; i < 4; ++i ) {
173 cart[i] = sgGeodToCart(rad[i]);
174 rel[i] = cart[i] - center;
175 t->nodes.push_back( rel[i] );
176 // cout << "corner " << i << " = " << cart[i] << endl;
181 // Calculate bounding radius
182 t->bounding_radius = center.distance3D( cart[0] );
183 // cout << "bounding radius = " << t->bounding_radius << endl;
187 for ( i = 0; i < 4; ++i ) {
188 double length = cart[i].distance3D( Point3D(0.0) );
189 normals[i] = cart[i] / length;
190 // cout << "normal = " << normals[i] << endl;
193 // Calculate texture coordinates
194 point_list geod_nodes;
198 for ( i = 0; i < 4; ++i ) {
199 geod_nodes.push_back( geod[i] );
200 rectangle.push_back( i );
202 point_list texs = calc_tex_coords( b, geod_nodes, rectangle,
203 1000.0 / tex_width );
205 // Allocate ssg structure
206 ssgVertexArray *vl = new ssgVertexArray( 4 );
207 ssgNormalArray *nl = new ssgNormalArray( 4 );
208 ssgTexCoordArray *tl = new ssgTexCoordArray( 4 );
209 ssgColourArray *cl = new ssgColourArray( 1 );
212 sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
215 // sgVec3 *vtlist = new sgVec3 [ 4 ];
216 // t->vec3_ptrs.push_back( vtlist );
217 // sgVec3 *vnlist = new sgVec3 [ 4 ];
218 // t->vec3_ptrs.push_back( vnlist );
219 // sgVec2 *tclist = new sgVec2 [ 4 ];
220 // t->vec2_ptrs.push_back( tclist );
224 for ( i = 0; i < 4; ++i ) {
226 rel[i].x(), rel[i].y(), rel[i].z() );
230 normals[i].x(), normals[i].y(), normals[i].z() );
233 sgSetVec2( tmp2, texs[i].x(), texs[i].y());
238 new ssgVtxTable ( GL_TRIANGLE_FAN, vl, nl, tl, cl );
240 leaf->setState( state );
242 tile->addKid( leaf );
248 static void random_pt_inside_tri( float *res,
249 float *n1, float *n2, float *n3 )
253 double a = sg_random();
254 double b = sg_random();
259 double c = 1 - a - b;
261 sgScaleVec3( p1, n1, a );
262 sgScaleVec3( p2, n2, b );
263 sgScaleVec3( p3, n3, c );
265 sgAddVec3( res, p1, p2 );
266 sgAddVec3( res, p3 );
270 static void gen_random_surface_points( ssgLeaf *leaf, ssgVertexArray *lights,
272 int num = leaf->getNumTriangles();
274 short int n1, n2, n3;
278 // generate a repeatable random seed
279 p1 = leaf->getVertex( 0 );
280 unsigned int seed = (unsigned int)p1[0];
283 for ( int i = 0; i < num; ++i ) {
284 leaf->getTriangle( i, &n1, &n2, &n3 );
285 p1 = leaf->getVertex(n1);
286 p2 = leaf->getVertex(n2);
287 p3 = leaf->getVertex(n3);
288 double area = sgTriArea( p1, p2, p3 );
289 double num = area / factor;
291 // generate a light point for each unit of area
292 while ( num > 1.0 ) {
293 random_pt_inside_tri( result, p1, p2, p3 );
294 lights->add( result );
297 // for partial units of area, use a zombie door method to
298 // create the proper random chance of a light being created
301 if ( sg_random() <= num ) {
302 // a zombie made it through our door
303 random_pt_inside_tri( result, p1, p2, p3 );
304 lights->add( result );
312 // Load an Ascii obj file
313 ssgBranch *fgAsciiObjLoad( const string& path, FGTileEntry *t,
314 ssgVertexArray *lights, const bool is_base)
316 FGNewMat *newmat = NULL;
320 // sgVec3 approx_normal;
321 // double normal[3], scale = 0.0;
322 // double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin;
323 // GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 };
324 // GLint display_list = 0;
326 bool in_faces = false;
327 int vncount, vtcount;
328 int n1 = 0, n2 = 0, n3 = 0;
330 // int last1 = 0, last2 = 0;
335 double scenery_version = 0.0;
336 double tex_width = 1000.0, tex_height = 1000.0;
337 bool shared_done = false;
338 int_list fan_vertices;
339 int_list fan_tex_coords;
341 ssgSimpleState *state = NULL;
342 sgVec3 *vtlist, *vnlist;
345 ssgBranch *tile = new ssgBranch () ;
347 tile -> setName ( (char *)path.c_str() ) ;
349 // Attempt to open "path.gz" or "path"
350 sg_gzifstream in( path );
351 if ( ! in.is_open() ) {
352 SG_LOG( SG_TERRAIN, SG_DEBUG, "Cannot open file: " << path );
353 SG_LOG( SG_TERRAIN, SG_DEBUG, "default to ocean tile: " << path );
360 shading = fgGetBool("/sim/rendering/shading");
368 t->bounding_radius = 0.0;
372 // StopWatch stopwatch;
373 // stopwatch.start();
375 // ignore initial comments and blank lines. (priming the pump)
376 // in >> skipcomment;
383 while ( in.get(c) && c != '\0' ) {
386 while ( ! in.eof() ) {
391 if ( in.get( c ) && c == '#' ) {
392 // process a comment line
394 // getline( in, line );
395 // cout << "comment = " << line << endl;
399 if ( token == "Version" ) {
400 // read scenery versions number
401 in >> scenery_version;
402 // cout << "scenery_version = " << scenery_version << endl;
403 if ( scenery_version > 0.4 ) {
404 SG_LOG( SG_TERRAIN, SG_ALERT,
405 "\nYou are attempting to load a tile format that\n"
406 << "is newer than this version of flightgear can\n"
407 << "handle. You should upgrade your copy of\n"
408 << "FlightGear to the newest version. For\n"
409 << "details, please see:\n"
410 << "\n http://www.flightgear.org\n" );
413 } else if ( token == "gbs" ) {
414 // reference point (center offset)
416 in >> t->center >> t->bounding_radius;
420 in >> junk1 >> junk2;
423 // cout << "center = " << center
424 // << " radius = " << t->bounding_radius << endl;
425 } else if ( token == "bs" ) {
426 // reference point (center offset)
430 in >> junk1 >> junk2;
431 } else if ( token == "usemtl" ) {
432 // material property specification
434 // if first usemtl with shared_done = false, then set
435 // shared_done true and build the ssg shared lists
436 if ( ! shared_done ) {
438 if ( (int)nodes.size() != vncount ) {
439 SG_LOG( SG_TERRAIN, SG_ALERT,
440 "Tile has mismatched nodes = " << nodes.size()
441 << " and normals = " << vncount << " : "
447 vtlist = new sgVec3 [ nodes.size() ];
448 t->vec3_ptrs.push_back( vtlist );
449 vnlist = new sgVec3 [ vncount ];
450 t->vec3_ptrs.push_back( vnlist );
451 tclist = new sgVec2 [ vtcount ];
452 t->vec2_ptrs.push_back( tclist );
454 for ( i = 0; i < (int)nodes.size(); ++i ) {
455 sgSetVec3( vtlist[i],
456 nodes[i][0], nodes[i][1], nodes[i][2] );
458 for ( i = 0; i < vncount; ++i ) {
459 sgSetVec3( vnlist[i],
464 for ( i = 0; i < vtcount; ++i ) {
465 sgSetVec2( tclist[i],
471 // display_list = xglGenLists(1);
472 // xglNewList(display_list, GL_COMPILE);
473 // printf("xglGenLists(); xglNewList();\n");
476 // scan the material line
479 // find this material in the properties list
481 newmat = material_lib.find( material );
482 if ( newmat == NULL ) {
483 // see if this is an on the fly texture
485 int pos = file.rfind( "/" );
486 file = file.substr( 0, pos );
487 cout << "current file = " << file << endl;
490 cout << "current file = " << file << endl;
491 if ( ! material_lib.add_item( file ) ) {
492 SG_LOG( SG_TERRAIN, SG_ALERT,
493 "Ack! unknown usemtl name = " << material
496 // locate our newly created material
497 newmat = material_lib.find( material );
498 if ( newmat == NULL ) {
499 SG_LOG( SG_TERRAIN, SG_ALERT,
500 "Ack! bad on the fly materia create = "
501 << material << " in " << path );
506 if ( newmat != NULL ) {
507 // set the texture width and height values for this
509 tex_width = newmat->get_xsize();
510 tex_height = newmat->get_ysize();
511 state = newmat->get_state();
512 coverage = newmat->get_light_coverage();
513 // cout << "(w) = " << tex_width << " (h) = "
514 // << tex_width << endl;
519 // unknown comment, just gobble the input until the
529 // cout << "token = " << token << endl;
531 if ( token == "vn" ) {
533 if ( vncount < FG_MAX_NODES ) {
534 in >> normals[vncount][0]
535 >> normals[vncount][1]
536 >> normals[vncount][2];
539 SG_LOG( SG_TERRAIN, SG_ALERT,
540 "Read too many vertex normals in " << path
541 << " ... dying :-(" );
544 } else if ( token == "vt" ) {
545 // vertex texture coordinate
546 if ( vtcount < FG_MAX_NODES*3 ) {
547 in >> tex_coords[vtcount][0]
548 >> tex_coords[vtcount][1];
551 SG_LOG( SG_TERRAIN, SG_ALERT,
552 "Read too many vertex texture coords in " << path
557 } else if ( token == "v" ) {
559 if ( t->ncount < FG_MAX_NODES ) {
560 /* in >> nodes[t->ncount][0]
561 >> nodes[t->ncount][1]
562 >> nodes[t->ncount][2]; */
564 nodes.push_back(node);
569 SG_LOG( SG_TERRAIN, SG_ALERT,
570 "Read too many nodes in " << path
571 << " ... dying :-(");
574 } else if ( (token == "tf") || (token == "ts") || (token == "f") ) {
575 // triangle fan, strip, or individual face
576 // SG_LOG( SG_TERRAIN, SG_INFO, "new fan or strip");
578 fan_vertices.clear();
579 fan_tex_coords.clear();
582 // xglBegin(GL_TRIANGLE_FAN);
585 fan_vertices.push_back( n1 );
586 // xglNormal3dv(normals[n1]);
587 if ( in.get( c ) && c == '/' ) {
589 fan_tex_coords.push_back( tex );
590 if ( scenery_version >= 0.4 ) {
591 if ( tex_width > 0 ) {
592 tclist[tex][0] *= (1000.0 / tex_width);
594 if ( tex_height > 0 ) {
595 tclist[tex][1] *= (1000.0 / tex_height);
598 pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
599 pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
602 pp = local_calc_tex_coords(nodes[n1], center);
604 // xglTexCoord2f(pp.x(), pp.y());
605 // xglVertex3dv(nodes[n1].get_n());
608 fan_vertices.push_back( n2 );
609 // xglNormal3dv(normals[n2]);
610 if ( in.get( c ) && c == '/' ) {
612 fan_tex_coords.push_back( tex );
613 if ( scenery_version >= 0.4 ) {
614 if ( tex_width > 0 ) {
615 tclist[tex][0] *= (1000.0 / tex_width);
617 if ( tex_height > 0 ) {
618 tclist[tex][1] *= (1000.0 / tex_height);
621 pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
622 pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
625 pp = local_calc_tex_coords(nodes[n2], center);
627 // xglTexCoord2f(pp.x(), pp.y());
628 // xglVertex3dv(nodes[n2].get_n());
630 // read all subsequent numbers until next thing isn't a number
637 if ( ! isdigit(c) || in.eof() ) {
642 fan_vertices.push_back( n3 );
643 // cout << " triangle = "
644 // << n1 << "," << n2 << "," << n3
646 // xglNormal3dv(normals[n3]);
647 if ( in.get( c ) && c == '/' ) {
649 fan_tex_coords.push_back( tex );
650 if ( scenery_version >= 0.4 ) {
651 if ( tex_width > 0 ) {
652 tclist[tex][0] *= (1000.0 / tex_width);
654 if ( tex_height > 0 ) {
655 tclist[tex][1] *= (1000.0 / tex_height);
658 pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
659 pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
662 pp = local_calc_tex_coords(nodes[n3], center);
664 // xglTexCoord2f(pp.x(), pp.y());
665 // xglVertex3dv(nodes[n3].get_n());
667 if ( (token == "tf") || (token == "f") ) {
680 // build the ssg entity
681 int size = (int)fan_vertices.size();
682 ssgVertexArray *vl = new ssgVertexArray( size );
683 ssgNormalArray *nl = new ssgNormalArray( size );
684 ssgTexCoordArray *tl = new ssgTexCoordArray( size );
685 ssgColourArray *cl = new ssgColourArray( 1 );
688 sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
693 for ( i = 0; i < size; ++i ) {
694 sgCopyVec3( tmp3, vtlist[ fan_vertices[i] ] );
697 sgCopyVec3( tmp3, vnlist[ fan_vertices[i] ] );
700 sgCopyVec2( tmp2, tclist[ fan_tex_coords[i] ] );
704 ssgLeaf *leaf = NULL;
705 if ( token == "tf" ) {
708 new ssgVtxTable ( GL_TRIANGLE_FAN, vl, nl, tl, cl );
709 } else if ( token == "ts" ) {
712 new ssgVtxTable ( GL_TRIANGLE_STRIP, vl, nl, tl, cl );
713 } else if ( token == "f" ) {
716 new ssgVtxTable ( GL_TRIANGLES, vl, nl, tl, cl );
718 // leaf->makeDList();
719 leaf->setState( state );
721 tile->addKid( leaf );
724 if ( coverage > 0.0 ) {
725 if ( coverage < 10000.0 ) {
726 SG_LOG(SG_INPUT, SG_ALERT, "Light coverage is "
727 << coverage << ", pushing up to 10000");
730 gen_random_surface_points(leaf, lights, coverage);
734 SG_LOG( SG_TERRAIN, SG_WARN, "Unknown token in "
735 << path << " = " << token );
738 // eat white space before start of while loop so if we are
739 // done with useful input it is noticed before hand.
749 // SG_LOG( SG_TERRAIN, SG_DEBUG,
750 // "Loaded " << path << " in "
751 // << stopwatch.elapsedSeconds() << " seconds" );
757 ssgLeaf *gen_leaf( const string& path,
758 const GLenum ty, const string& material,
759 const point_list& nodes, const point_list& normals,
760 const point_list& texcoords,
761 const int_list node_index,
762 const int_list& tex_index,
763 const bool calc_lights, ssgVertexArray *lights )
765 double tex_width = 1000.0, tex_height = 1000.0;
766 ssgSimpleState *state = NULL;
769 FGNewMat *newmat = material_lib.find( material );
770 if ( newmat == NULL ) {
771 // see if this is an on the fly texture
773 int pos = file.rfind( "/" );
774 file = file.substr( 0, pos );
775 cout << "current file = " << file << endl;
778 cout << "current file = " << file << endl;
779 if ( ! material_lib.add_item( file ) ) {
780 SG_LOG( SG_TERRAIN, SG_ALERT,
781 "Ack! unknown usemtl name = " << material
784 // locate our newly created material
785 newmat = material_lib.find( material );
786 if ( newmat == NULL ) {
787 SG_LOG( SG_TERRAIN, SG_ALERT,
788 "Ack! bad on the fly material create = "
789 << material << " in " << path );
794 if ( newmat != NULL ) {
795 // set the texture width and height values for this
797 tex_width = newmat->get_xsize();
798 tex_height = newmat->get_ysize();
799 state = newmat->get_state();
800 coverage = newmat->get_light_coverage();
801 // cout << "(w) = " << tex_width << " (h) = "
802 // << tex_width << endl;
807 // cout << "before list allocs" << endl;
809 // cout << "before vl, size = " << size << endl;
810 // cout << "before nl" << endl;
811 // cout << "before tl" << endl;
812 // cout << "before cl" << endl;
820 int size = node_index.size();
822 SG_LOG( SG_TERRAIN, SG_ALERT, "Woh! node list size < 1" );
825 ssgVertexArray *vl = new ssgVertexArray( size );
827 for ( i = 0; i < size; ++i ) {
828 node = nodes[ node_index[i] ];
829 sgSetVec3( tmp3, node[0], node[1], node[2] );
834 ssgColourArray *cl = new ssgColourArray( 1 );
835 sgSetVec4( tmp4, 1.0, 1.0, 1.0, 1.0 );
840 ssgNormalArray *nl = new ssgNormalArray( size );
841 if ( normals.size() == 1 ) {
842 normal = normals[ 0 ];
843 sgSetVec3( tmp3, normal[0], normal[1], normal[2] );
845 } else if ( normals.size() > 1 ) {
846 for ( i = 0; i < size; ++i ) {
847 normal = normals[ node_index[i] ];
848 sgSetVec3( tmp3, normal[0], normal[1], normal[2] );
853 // texture coordinates
854 size = tex_index.size();
856 ssgTexCoordArray *tl = new ssgTexCoordArray( size );
858 texcoord = texcoords[ tex_index[0] ];
859 sgSetVec2( tmp2, texcoord[0], texcoord[1] );
860 sgSetVec2( tmp2, texcoord[0], texcoord[1] );
861 if ( tex_width > 0 ) {
862 tmp2[0] *= (1000.0 / tex_width);
864 if ( tex_height > 0 ) {
865 tmp2[1] *= (1000.0 / tex_height);
868 } else if ( size > 1 ) {
869 for ( i = 0; i < size; ++i ) {
870 texcoord = texcoords[ tex_index[i] ];
871 sgSetVec2( tmp2, texcoord[0], texcoord[1] );
872 if ( tex_width > 0 ) {
873 tmp2[0] *= (1000.0 / tex_width);
875 if ( tex_height > 0 ) {
876 tmp2[1] *= (1000.0 / tex_height);
882 // cout << "before leaf create" << endl;
883 ssgLeaf *leaf = new ssgVtxTable ( ty, vl, nl, tl, cl );
884 // cout << "after leaf create" << endl;
886 // lookup the state record
887 // cout << "looking up material = " << endl;
888 // cout << material << endl;
889 // cout << "'" << endl;
891 leaf->setState( state );
894 if ( coverage > 0.0 ) {
895 if ( coverage < 10000.0 ) {
896 SG_LOG(SG_INPUT, SG_ALERT, "Light coverage is "
897 << coverage << ", pushing up to 10000");
900 gen_random_surface_points(leaf, lights, coverage);
908 // Load an Binary obj file
909 ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t,
910 ssgVertexArray *lights, const bool is_base)
915 bool result = obj.read_bin( path );
921 // cout << "fans size = " << obj.get_fans_v().size()
922 // << " fan_mats size = " << obj.get_fan_materials().size() << endl;
924 ssgBranch *object = new ssgBranch();
925 object->setName( (char *)path.c_str() );
927 if ( is_base && t != NULL ) {
928 // reference point (center offset/bounding sphere)
929 t->center = obj.get_gbs_center();
930 t->bounding_radius = obj.get_gbs_radius();
933 point_list nodes = obj.get_wgs84_nodes();
934 point_list colors = obj.get_colors();
935 point_list normals = obj.get_normals();
936 point_list texcoords = obj.get_texcoords();
939 int_list vertex_index;
943 string_list pt_materials = obj.get_pt_materials();
944 group_list pts_v = obj.get_pts_v();
945 for ( i = 0; i < (int)pts_v.size(); ++i ) {
946 cout << "pts_v.size() = " << pts_v.size() << endl;
947 material = pt_materials[i];
948 vertex_index = pts_v[i];
950 ssgLeaf *leaf = gen_leaf( path, GL_POINTS, material,
951 nodes, normals, texcoords,
952 vertex_index, tex_index,
955 object->addKid( leaf );
958 // generate triangles
959 string_list tri_materials = obj.get_tri_materials();
960 group_list tris_v = obj.get_tris_v();
961 group_list tris_tc = obj.get_tris_tc();
962 for ( i = 0; i < (int)tris_v.size(); ++i ) {
963 material = tri_materials[i];
964 vertex_index = tris_v[i];
965 tex_index = tris_tc[i];
966 ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLES, material,
967 nodes, normals, texcoords,
968 vertex_index, tex_index,
971 object->addKid( leaf );
975 string_list strip_materials = obj.get_strip_materials();
976 group_list strips_v = obj.get_strips_v();
977 group_list strips_tc = obj.get_strips_tc();
978 for ( i = 0; i < (int)strips_v.size(); ++i ) {
979 material = strip_materials[i];
980 vertex_index = strips_v[i];
981 tex_index = strips_tc[i];
982 ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material,
983 nodes, normals, texcoords,
984 vertex_index, tex_index,
987 object->addKid( leaf );
991 string_list fan_materials = obj.get_fan_materials();
992 group_list fans_v = obj.get_fans_v();
993 group_list fans_tc = obj.get_fans_tc();
994 for ( i = 0; i < (int)fans_v.size(); ++i ) {
995 material = fan_materials[i];
996 vertex_index = fans_v[i];
997 tex_index = fans_tc[i];
998 ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_FAN, material,
999 nodes, normals, texcoords,
1000 vertex_index, tex_index,
1003 object->addKid( leaf );