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 FG_MATH_EXCEPTION_CLASH
35 // #if defined ( __sun__ )
36 // extern "C" void *memmove(void *, const void *, size_t);
37 // extern "C" void *memset(void *, int, size_t);
40 #include <simgear/compiler.h>
41 #include <simgear/io/sg_binobj.hxx>
45 #include <vector> // STL
46 #include <ctype.h> // isdigit()
48 #include <simgear/constants.h>
49 #include <simgear/debug/logstream.hxx>
50 #include <simgear/math/point3d.hxx>
51 #include <simgear/math/polar3d.hxx>
52 #include <simgear/math/sg_geodesy.hxx>
53 #include <simgear/math/sg_random.h>
54 #include <simgear/misc/fgstream.hxx>
55 #include <simgear/misc/stopwatch.hxx>
56 #include <simgear/misc/texcoord.hxx>
58 #include <Main/globals.hxx>
59 #include <Main/fg_props.hxx>
60 #include <Scenery/tileentry.hxx>
69 typedef vector < int > int_list;
70 typedef int_list::iterator int_list_iterator;
71 typedef int_list::const_iterator int_point_list_iterator;
74 static double normals[FG_MAX_NODES][3];
75 static double tex_coords[FG_MAX_NODES*3][3];
78 #define FG_TEX_CONSTANT 69.0
80 // Calculate texture coordinates for a given point.
81 static Point3D local_calc_tex_coords(const Point3D& node, const Point3D& ref) {
84 // double tmplon, tmplat;
86 // cout << "-> " << node[0] << " " << node[1] << " " << node[2] << endl;
87 // cout << "-> " << ref.x() << " " << ref.y() << " " << ref.z() << endl;
89 cp = Point3D( node[0] + ref.x(),
93 pp = sgCartToPolar3d(cp);
95 // tmplon = pp.lon() * RAD_TO_DEG;
96 // tmplat = pp.lat() * RAD_TO_DEG;
97 // cout << tmplon << " " << tmplat << endl;
99 pp.setx( fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.x(), 11.0) );
100 pp.sety( fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.y(), 11.0) );
102 if ( pp.x() < 0.0 ) {
103 pp.setx( pp.x() + 11.0 );
106 if ( pp.y() < 0.0 ) {
107 pp.sety( pp.y() + 11.0 );
110 // cout << pp << endl;
116 // Generate a generic ocean tile on the fly
117 ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
120 ssgSimpleState *state = NULL;
122 ssgBranch *tile = new ssgBranch () ;
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 FG_LOG( FG_TERRAIN, FG_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*DEG_TO_RAD,clat*DEG_TO_RAD,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() * DEG_TO_RAD, geod[i].y() * DEG_TO_RAD,
169 Point3D cart[4], rel[4];
171 for ( i = 0; i < 4; ++i ) {
172 cart[i] = sgGeodToCart(rad[i]);
173 rel[i] = cart[i] - center;
174 t->nodes.push_back( rel[i] );
175 // cout << "corner " << i << " = " << cart[i] << endl;
180 // Calculate bounding radius
181 t->bounding_radius = center.distance3D( cart[0] );
182 // cout << "bounding radius = " << t->bounding_radius << endl;
186 for ( i = 0; i < 4; ++i ) {
187 normals[i] = cart[i];
188 double length = normals[i].distance3D( Point3D(0.0) );
189 normals[i] /= length;
190 // cout << "normal = " << normals[i] << endl;
193 // Calculate texture coordinates
194 point_list geod_nodes;
196 for ( i = 0; i < 4; ++i ) {
197 geod_nodes.push_back( geod[i] );
201 for ( i = 0; i < 4; ++i ) {
202 rectangle.push_back( i );
204 point_list texs = calc_tex_coords( b, geod_nodes, rectangle,
205 1000.0 / tex_width );
207 // Allocate ssg structure
208 ssgVertexArray *vl = new ssgVertexArray( 4 );
209 ssgNormalArray *nl = new ssgNormalArray( 4 );
210 ssgTexCoordArray *tl = new ssgTexCoordArray( 4 );
211 ssgColourArray *cl = new ssgColourArray( 1 );
214 sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
217 // sgVec3 *vtlist = new sgVec3 [ 4 ];
218 // t->vec3_ptrs.push_back( vtlist );
219 // sgVec3 *vnlist = new sgVec3 [ 4 ];
220 // t->vec3_ptrs.push_back( vnlist );
221 // sgVec2 *tclist = new sgVec2 [ 4 ];
222 // t->vec2_ptrs.push_back( tclist );
226 for ( i = 0; i < 4; ++i ) {
228 rel[i].x(), rel[i].y(), rel[i].z() );
232 normals[i].x(), normals[i].y(), normals[i].z() );
235 sgSetVec2( tmp2, texs[i].x(), texs[i].y());
240 new ssgVtxTable ( GL_TRIANGLE_FAN, vl, nl, tl, cl );
242 leaf->setState( state );
244 tile->addKid( leaf );
250 static float fgTriArea( sgVec3 p0, sgVec3 p1, sgVec3 p2 ) {
252 From comp.graph.algorithms FAQ
253 2A(P) = abs(N.(sum_{i=0}^{n-1}(v_i x v_{i+1})))
259 sgMakeNormal( norm, p0, p1, p2 );
266 for( int i=0; i<3; i++ ) {
268 sum[0] += (vv[i][1] * vv[ii][2] - vv[i][2] * vv[ii][1]) ;
269 sum[1] += (vv[i][2] * vv[ii][0] - vv[i][0] * vv[ii][2]) ;
270 sum[2] += (vv[i][0] * vv[ii][1] - vv[i][1] * vv[ii][0]) ;
273 return( sgAbs(sgScalarProductVec3( norm, sum )) * SG_HALF );
277 static void random_pt_inside_tri( float *res,
278 float *n1, float *n2, float *n3 )
282 double a = sg_random();
283 double b = sg_random();
288 double c = 1 - a - b;
290 sgScaleVec3( p1, n1, a );
291 sgScaleVec3( p2, n2, b );
292 sgScaleVec3( p3, n3, c );
294 sgAddVec3( res, p1, p2 );
295 sgAddVec3( res, p3 );
299 static void gen_random_surface_points( ssgLeaf *leaf, ssgVertexArray *lights,
301 int num = leaf->getNumTriangles();
303 short int n1, n2, n3;
307 // generate a repeatable random seed
308 p1 = leaf->getVertex( 0 );
309 unsigned int *seed = (unsigned int *)p1;
312 for ( int i = 0; i < num; ++i ) {
313 leaf->getTriangle( i, &n1, &n2, &n3 );
314 p1 = leaf->getVertex(n1);
315 p2 = leaf->getVertex(n2);
316 p3 = leaf->getVertex(n3);
317 double area = fgTriArea( p1, p2, p3 );
318 double num = area / factor;
320 // generate a light point for each unit of area
321 while ( num > 1.0 ) {
322 random_pt_inside_tri( result, p1, p2, p3 );
323 lights->add( result );
326 // for partial units of area, use a zombie door method to
327 // create the proper random chance of a light being created
330 if ( sg_random() <= num ) {
331 // a zombie made it through our door
332 random_pt_inside_tri( result, p1, p2, p3 );
333 lights->add( result );
341 // Load an Ascii obj file
342 static ssgBranch *fgAsciiObjLoad( const string& path, FGTileEntry *t,
343 ssgVertexArray *lights, const bool is_base)
345 FGNewMat *newmat = NULL;
349 // sgVec3 approx_normal;
350 // double normal[3], scale = 0.0;
351 // double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin;
352 // GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 };
353 // GLint display_list = 0;
355 bool in_faces = false;
356 int vncount, vtcount;
357 int n1 = 0, n2 = 0, n3 = 0;
359 // int last1 = 0, last2 = 0;
364 double scenery_version = 0.0;
365 double tex_width = 1000.0, tex_height = 1000.0;
366 bool shared_done = false;
367 int_list fan_vertices;
368 int_list fan_tex_coords;
370 ssgSimpleState *state = NULL;
371 sgVec3 *vtlist, *vnlist;
374 ssgBranch *tile = new ssgBranch () ;
376 tile -> setName ( (char *)path.c_str() ) ;
378 // Attempt to open "path.gz" or "path"
379 fg_gzifstream in( path );
380 if ( ! in.is_open() ) {
381 FG_LOG( FG_TERRAIN, FG_DEBUG, "Cannot open file: " << path );
382 FG_LOG( FG_TERRAIN, FG_DEBUG, "default to ocean tile: " << path );
387 shading = fgGetBool("/sim/rendering/shading");
395 t->bounding_radius = 0.0;
402 // ignore initial comments and blank lines. (priming the pump)
403 // in >> skipcomment;
410 while ( in.get(c) && c != '\0' ) {
413 while ( ! in.eof() ) {
416 #if defined( macintosh ) || defined( _MSC_VER )
422 if ( in.get( c ) && c == '#' ) {
423 // process a comment line
425 // getline( in, line );
426 // cout << "comment = " << line << endl;
430 if ( token == "Version" ) {
431 // read scenery versions number
432 in >> scenery_version;
433 // cout << "scenery_version = " << scenery_version << endl;
434 if ( scenery_version > 0.4 ) {
435 FG_LOG( FG_TERRAIN, FG_ALERT,
436 "\nYou are attempting to load a tile format that\n"
437 << "is newer than this version of flightgear can\n"
438 << "handle. You should upgrade your copy of\n"
439 << "FlightGear to the newest version. For\n"
440 << "details, please see:\n"
441 << "\n http://www.flightgear.org\n" );
444 } else if ( token == "gbs" ) {
445 // reference point (center offset)
447 in >> t->center >> t->bounding_radius;
451 in >> junk1 >> junk2;
454 // cout << "center = " << center
455 // << " radius = " << t->bounding_radius << endl;
456 } else if ( token == "bs" ) {
457 // reference point (center offset)
461 in >> junk1 >> junk2;
462 } else if ( token == "usemtl" ) {
463 // material property specification
465 // if first usemtl with shared_done = false, then set
466 // shared_done true and build the ssg shared lists
467 if ( ! shared_done ) {
469 if ( (int)nodes.size() != vncount ) {
470 FG_LOG( FG_TERRAIN, FG_ALERT,
471 "Tile has mismatched nodes = " << nodes.size()
472 << " and normals = " << vncount << " : "
478 vtlist = new sgVec3 [ nodes.size() ];
479 t->vec3_ptrs.push_back( vtlist );
480 vnlist = new sgVec3 [ vncount ];
481 t->vec3_ptrs.push_back( vnlist );
482 tclist = new sgVec2 [ vtcount ];
483 t->vec2_ptrs.push_back( tclist );
485 for ( i = 0; i < (int)nodes.size(); ++i ) {
486 sgSetVec3( vtlist[i],
487 nodes[i][0], nodes[i][1], nodes[i][2] );
489 for ( i = 0; i < vncount; ++i ) {
490 sgSetVec3( vnlist[i],
495 for ( i = 0; i < vtcount; ++i ) {
496 sgSetVec2( tclist[i],
502 // display_list = xglGenLists(1);
503 // xglNewList(display_list, GL_COMPILE);
504 // printf("xglGenLists(); xglNewList();\n");
507 // scan the material line
510 // find this material in the properties list
512 newmat = material_lib.find( material );
513 if ( newmat == NULL ) {
514 // see if this is an on the fly texture
516 int pos = file.rfind( "/" );
517 file = file.substr( 0, pos );
518 cout << "current file = " << file << endl;
521 cout << "current file = " << file << endl;
522 if ( ! material_lib.add_item( file ) ) {
523 FG_LOG( FG_TERRAIN, FG_ALERT,
524 "Ack! unknown usemtl name = " << material
527 // locate our newly created material
528 newmat = material_lib.find( material );
529 if ( newmat == NULL ) {
530 FG_LOG( FG_TERRAIN, FG_ALERT,
531 "Ack! bad on the fly materia create = "
532 << material << " in " << path );
537 if ( newmat != NULL ) {
538 // set the texture width and height values for this
540 tex_width = newmat->get_xsize();
541 tex_height = newmat->get_ysize();
542 state = newmat->get_state();
543 coverage = newmat->get_light_coverage();
544 // cout << "(w) = " << tex_width << " (h) = "
545 // << tex_width << endl;
550 // unknown comment, just gobble the input until the
560 // cout << "token = " << token << endl;
562 if ( token == "vn" ) {
564 if ( vncount < FG_MAX_NODES ) {
565 in >> normals[vncount][0]
566 >> normals[vncount][1]
567 >> normals[vncount][2];
570 FG_LOG( FG_TERRAIN, FG_ALERT,
571 "Read too many vertex normals in " << path
572 << " ... dying :-(" );
575 } else if ( token == "vt" ) {
576 // vertex texture coordinate
577 if ( vtcount < FG_MAX_NODES*3 ) {
578 in >> tex_coords[vtcount][0]
579 >> tex_coords[vtcount][1];
582 FG_LOG( FG_TERRAIN, FG_ALERT,
583 "Read too many vertex texture coords in " << path
588 } else if ( token == "v" ) {
590 if ( t->ncount < FG_MAX_NODES ) {
591 /* in >> nodes[t->ncount][0]
592 >> nodes[t->ncount][1]
593 >> nodes[t->ncount][2]; */
595 nodes.push_back(node);
600 FG_LOG( FG_TERRAIN, FG_ALERT,
601 "Read too many nodes in " << path
602 << " ... dying :-(");
605 } else if ( (token == "tf") || (token == "ts") || (token == "f") ) {
606 // triangle fan, strip, or individual face
607 // FG_LOG( FG_TERRAIN, FG_INFO, "new fan or strip");
609 fan_vertices.clear();
610 fan_tex_coords.clear();
613 // xglBegin(GL_TRIANGLE_FAN);
616 fan_vertices.push_back( n1 );
617 // xglNormal3dv(normals[n1]);
618 if ( in.get( c ) && c == '/' ) {
620 fan_tex_coords.push_back( tex );
621 if ( scenery_version >= 0.4 ) {
622 if ( tex_width > 0 ) {
623 tclist[tex][0] *= (1000.0 / tex_width);
625 if ( tex_height > 0 ) {
626 tclist[tex][1] *= (1000.0 / tex_height);
629 pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
630 pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
633 pp = local_calc_tex_coords(nodes[n1], center);
635 // xglTexCoord2f(pp.x(), pp.y());
636 // xglVertex3dv(nodes[n1].get_n());
639 fan_vertices.push_back( n2 );
640 // xglNormal3dv(normals[n2]);
641 if ( in.get( c ) && c == '/' ) {
643 fan_tex_coords.push_back( tex );
644 if ( scenery_version >= 0.4 ) {
645 if ( tex_width > 0 ) {
646 tclist[tex][0] *= (1000.0 / tex_width);
648 if ( tex_height > 0 ) {
649 tclist[tex][1] *= (1000.0 / tex_height);
652 pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
653 pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
656 pp = local_calc_tex_coords(nodes[n2], center);
658 // xglTexCoord2f(pp.x(), pp.y());
659 // xglVertex3dv(nodes[n2].get_n());
661 // read all subsequent numbers until next thing isn't a number
663 #if defined( macintosh ) || defined( _MSC_VER )
672 if ( ! isdigit(c) || in.eof() ) {
677 fan_vertices.push_back( n3 );
678 // cout << " triangle = "
679 // << n1 << "," << n2 << "," << n3
681 // xglNormal3dv(normals[n3]);
682 if ( in.get( c ) && c == '/' ) {
684 fan_tex_coords.push_back( tex );
685 if ( scenery_version >= 0.4 ) {
686 if ( tex_width > 0 ) {
687 tclist[tex][0] *= (1000.0 / tex_width);
689 if ( tex_height > 0 ) {
690 tclist[tex][1] *= (1000.0 / tex_height);
693 pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
694 pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
697 pp = local_calc_tex_coords(nodes[n3], center);
699 // xglTexCoord2f(pp.x(), pp.y());
700 // xglVertex3dv(nodes[n3].get_n());
702 if ( (token == "tf") || (token == "f") ) {
715 // build the ssg entity
716 int size = (int)fan_vertices.size();
717 ssgVertexArray *vl = new ssgVertexArray( size );
718 ssgNormalArray *nl = new ssgNormalArray( size );
719 ssgTexCoordArray *tl = new ssgTexCoordArray( size );
720 ssgColourArray *cl = new ssgColourArray( 1 );
723 sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
728 for ( i = 0; i < size; ++i ) {
729 sgCopyVec3( tmp3, vtlist[ fan_vertices[i] ] );
732 sgCopyVec3( tmp3, vnlist[ fan_vertices[i] ] );
735 sgCopyVec2( tmp2, tclist[ fan_tex_coords[i] ] );
739 ssgLeaf *leaf = NULL;
740 if ( token == "tf" ) {
743 new ssgVtxTable ( GL_TRIANGLE_FAN, vl, nl, tl, cl );
744 } else if ( token == "ts" ) {
747 new ssgVtxTable ( GL_TRIANGLE_STRIP, vl, nl, tl, cl );
748 } else if ( token == "f" ) {
751 new ssgVtxTable ( GL_TRIANGLES, vl, nl, tl, cl );
753 // leaf->makeDList();
754 leaf->setState( state );
756 tile->addKid( leaf );
759 if ( coverage > 0.0 ) {
760 if ( coverage < 10000.0 ) {
761 FG_LOG(FG_INPUT, FG_ALERT, "Light coverage is "
762 << coverage << ", pushing up to 10000");
765 gen_random_surface_points(leaf, lights, coverage);
769 FG_LOG( FG_TERRAIN, FG_WARN, "Unknown token in "
770 << path << " = " << token );
773 // eat white space before start of while loop so if we are
774 // done with useful input it is noticed before hand.
775 #if defined( macintosh ) || defined( _MSC_VER )
788 FG_LOG( FG_TERRAIN, FG_DEBUG,
789 "Loaded " << path << " in "
790 << stopwatch.elapsedSeconds() << " seconds" );
796 static ssgLeaf *gen_leaf( const string& path,
797 const GLenum ty, const string& material,
798 const point_list& nodes, const point_list& normals,
799 const point_list& texcoords,
800 const int_list node_index,
801 const int_list& tex_index,
802 const bool calc_lights, ssgVertexArray *lights )
804 double tex_width = 1000.0, tex_height = 1000.0;
805 ssgSimpleState *state = NULL;
808 FGNewMat *newmat = material_lib.find( material );
809 if ( newmat == NULL ) {
810 // see if this is an on the fly texture
812 int pos = file.rfind( "/" );
813 file = file.substr( 0, pos );
814 cout << "current file = " << file << endl;
817 cout << "current file = " << file << endl;
818 if ( ! material_lib.add_item( file ) ) {
819 FG_LOG( FG_TERRAIN, FG_ALERT,
820 "Ack! unknown usemtl name = " << material
823 // locate our newly created material
824 newmat = material_lib.find( material );
825 if ( newmat == NULL ) {
826 FG_LOG( FG_TERRAIN, FG_ALERT,
827 "Ack! bad on the fly materia create = "
828 << material << " in " << path );
833 if ( newmat != NULL ) {
834 // set the texture width and height values for this
836 tex_width = newmat->get_xsize();
837 tex_height = newmat->get_ysize();
838 state = newmat->get_state();
839 coverage = newmat->get_light_coverage();
840 // cout << "(w) = " << tex_width << " (h) = "
841 // << tex_width << endl;
846 int size = node_index.size();
847 ssgVertexArray *vl = new ssgVertexArray( size );
848 ssgNormalArray *nl = new ssgNormalArray( size );
849 ssgTexCoordArray *tl = new ssgTexCoordArray( size );
850 ssgColourArray *cl = new ssgColourArray( 1 );
853 sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
859 for ( i = 0; i < size; ++i ) {
860 Point3D node = nodes[ node_index[i] ];
861 sgSetVec3( tmp3, node[0], node[1], node[2] );
864 Point3D normal = normals[ node_index[i] ];
865 sgSetVec3( tmp3, normal[0], normal[1], normal[2] );
868 Point3D texcoord = texcoords[ tex_index[i] ];
869 sgSetVec2( tmp2, texcoord[0], texcoord[1] );
870 if ( tex_width > 0 ) {
871 tmp2[0] *= (1000.0 / tex_width);
873 if ( tex_height > 0 ) {
874 tmp2[1] *= (1000.0 / tex_height);
879 // cout << "before leaf create" << endl;
880 ssgLeaf *leaf = new ssgVtxTable ( ty, vl, nl, tl, cl );
881 // cout << "after leaf create" << endl;
883 // lookup the state record
884 // cout << "looking up material = " << endl;
885 // cout << material << endl;
886 // cout << "'" << endl;
888 leaf->setState( state );
891 if ( coverage > 0.0 ) {
892 if ( coverage < 10000.0 ) {
893 FG_LOG(FG_INPUT, FG_ALERT, "Light coverage is "
894 << coverage << ", pushing up to 10000");
897 gen_random_surface_points(leaf, lights, coverage);
905 // Load an Binary obj file
906 static ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t,
907 ssgVertexArray *lights, const bool is_base)
912 bool result = obj.read_bin( path );
918 // cout << "fans size = " << obj.get_fans_v().size()
919 // << " fan_mats size = " << obj.get_fan_materials().size() << endl;
921 ssgBranch *object = new ssgBranch();
922 object->setName( (char *)path.c_str() );
924 if ( is_base && t != NULL ) {
925 // reference point (center offset/bounding sphere)
926 t->center = obj.get_gbs_center();
927 t->bounding_radius = obj.get_gbs_radius();
930 point_list nodes = obj.get_wgs84_nodes();
931 point_list normals = obj.get_normals();
932 point_list texcoords = obj.get_texcoords();
935 int_list vertex_index;
938 // generate triangles
939 string_list tri_materials = obj.get_tri_materials();
940 group_list tris_v = obj.get_tris_v();
941 group_list tris_tc = obj.get_tris_tc();
942 for ( i = 0; i < (int)tris_v.size(); ++i ) {
943 material = tri_materials[i];
944 vertex_index = tris_v[i];
945 tex_index = tris_tc[i];
946 ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLES, material,
947 nodes, normals, texcoords,
948 vertex_index, tex_index,
951 object->addKid( leaf );
955 string_list strip_materials = obj.get_strip_materials();
956 group_list strips_v = obj.get_strips_v();
957 group_list strips_tc = obj.get_strips_tc();
958 for ( i = 0; i < (int)strips_v.size(); ++i ) {
959 material = strip_materials[i];
960 vertex_index = strips_v[i];
961 tex_index = strips_tc[i];
962 ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material,
963 nodes, normals, texcoords,
964 vertex_index, tex_index,
967 object->addKid( leaf );
971 string_list fan_materials = obj.get_fan_materials();
972 group_list fans_v = obj.get_fans_v();
973 group_list fans_tc = obj.get_fans_tc();
974 for ( i = 0; i < (int)fans_v.size(); ++i ) {
975 material = fan_materials[i];
976 vertex_index = fans_v[i];
977 tex_index = fans_tc[i];
978 ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_FAN, material,
979 nodes, normals, texcoords,
980 vertex_index, tex_index,
983 object->addKid( leaf );
991 ssgBranch *fgObjLoad( const string& path, FGTileEntry *t,
992 ssgVertexArray *lights, const bool is_base)
994 ssgBranch *result = NULL;
996 // try loading binary format
997 result = fgBinObjLoad( path, t, lights, is_base );
998 if ( result == NULL ) {
999 // next try the older ascii format
1000 result = fgAsciiObjLoad( path, t, lights, is_base );
1001 if ( result == NULL ) {
1002 // default to an ocean tile
1003 result = fgGenTile( path, t );