From: curt Date: Sun, 3 Mar 2002 20:29:31 +0000 (+0000) Subject: Updates to the scenery loading infrastructure to make it more flexible, X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=938d006188e70e891bc04e91610c7b8caaca87b6;p=flightgear.git Updates to the scenery loading infrastructure to make it more flexible, clean up some messiness, and lay more groundwork for runway lighting. --- diff --git a/src/Objects/obj.cxx b/src/Objects/obj.cxx index a33178ae4..3b2b61f93 100644 --- a/src/Objects/obj.cxx +++ b/src/Objects/obj.cxx @@ -108,19 +108,17 @@ static Point3D local_calc_tex_coords(const Point3D& node, const Point3D& ref) { } -// Generate a generic ocean tile on the fly -ssgBranch *fgGenTile( const string& path, FGTileEntry *t) { +// Generate an ocean tile +bool fgGenTile( const string& path, SGBucket b, + Point3D *center, + double *bounding_radius, + ssgBranch* geometry ) +{ FGNewMat *newmat; ssgSimpleState *state = NULL; - ssgBranch *tile = new ssgBranch () ; - if ( !tile ) { - SG_LOG( SG_TERRAIN, SG_ALERT, "fgGenTile(): NO MEMORY" ); - return NULL; - } - - tile -> setName ( (char *)path.c_str() ) ; + geometry -> setName ( (char *)path.c_str() ) ; double tex_width = 1000.0; // double tex_height; @@ -142,14 +140,14 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) { } // Calculate center point - SGBucket b = t->tile_bucket; double clon = b.get_center_lon(); double clat = b.get_center_lat(); double height = b.get_height(); double width = b.get_width(); - Point3D center = sgGeodToCart(Point3D(clon*SGD_DEGREES_TO_RADIANS,clat*SGD_DEGREES_TO_RADIANS,0.0)); - t->center = center; + *center = sgGeodToCart( Point3D(clon*SGD_DEGREES_TO_RADIANS, + clat*SGD_DEGREES_TO_RADIANS, + 0.0) ); // cout << "center = " << center << endl;; // Caculate corner vertices @@ -168,18 +166,14 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) { } Point3D cart[4], rel[4]; - t->nodes.clear(); for ( i = 0; i < 4; ++i ) { cart[i] = sgGeodToCart(rad[i]); - rel[i] = cart[i] - center; - t->nodes.push_back( rel[i] ); + rel[i] = cart[i] - *center; // cout << "corner " << i << " = " << cart[i] << endl; } - t->ncount = 4; - // Calculate bounding radius - t->bounding_radius = center.distance3D( cart[0] ); + *bounding_radius = center->distance3D( cart[0] ); // cout << "bounding radius = " << t->bounding_radius << endl; // Calculate normals @@ -239,9 +233,9 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) { leaf->setState( state ); - tile->addKid( leaf ); + geometry->addKid( leaf ); - return tile; + return true; } @@ -311,7 +305,7 @@ static void gen_random_surface_points( ssgLeaf *leaf, ssgVertexArray *lights, // Load an Ascii obj file ssgBranch *fgAsciiObjLoad( const string& path, FGTileEntry *t, - ssgVertexArray *lights, const bool is_base) + ssgVertexArray *lights, const bool is_base) { FGNewMat *newmat = NULL; string material; @@ -906,28 +900,29 @@ ssgLeaf *gen_leaf( const string& path, // Load an Binary obj file -ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t, - ssgVertexArray *lights, const bool is_base) +bool fgBinObjLoad( const string& path, const bool is_base, + Point3D *center, + double *bounding_radius, + ssgBranch* geometry, + ssgBranch* rwy_lights, + ssgVertexArray *ground_lights ) { - int i; - SGBinObject obj; bool result = obj.read_bin( path ); if ( !result ) { - return NULL; + return false; } // cout << "fans size = " << obj.get_fans_v().size() // << " fan_mats size = " << obj.get_fan_materials().size() << endl; - ssgBranch *object = new ssgBranch(); - object->setName( (char *)path.c_str() ); + geometry->setName( (char *)path.c_str() ); - if ( is_base && t != NULL ) { + if ( is_base ) { // reference point (center offset/bounding sphere) - t->center = obj.get_gbs_center(); - t->bounding_radius = obj.get_gbs_radius(); + *center = obj.get_gbs_center(); + *bounding_radius = obj.get_gbs_radius(); } point_list nodes = obj.get_wgs84_nodes(); @@ -939,6 +934,8 @@ ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t, int_list vertex_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(); @@ -950,9 +947,9 @@ ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t, ssgLeaf *leaf = gen_leaf( path, GL_POINTS, material, nodes, normals, texcoords, vertex_index, tex_index, - false, lights ); + false, ground_lights ); - object->addKid( leaf ); + geometry->addKid( leaf ); } // generate triangles @@ -966,9 +963,9 @@ ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t, ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLES, material, nodes, normals, texcoords, vertex_index, tex_index, - is_base, lights ); + is_base, ground_lights ); - object->addKid( leaf ); + geometry->addKid( leaf ); } // generate strips @@ -982,9 +979,9 @@ ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t, ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material, nodes, normals, texcoords, vertex_index, tex_index, - is_base, lights ); + is_base, ground_lights ); - object->addKid( leaf ); + geometry->addKid( leaf ); } // generate fans @@ -998,10 +995,10 @@ ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t, ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_FAN, material, nodes, normals, texcoords, vertex_index, tex_index, - is_base, lights ); + is_base, ground_lights ); - object->addKid( leaf ); + geometry->addKid( leaf ); } - return object; + return true; } diff --git a/src/Objects/obj.hxx b/src/Objects/obj.hxx index 05a7180d7..68ff0f98f 100644 --- a/src/Objects/obj.hxx +++ b/src/Objects/obj.hxx @@ -57,16 +57,23 @@ SG_USING_STD(string); #define FG_MAX_NODES 4000 -// Load a binary object file -ssgBranch *fgBinObjLoad(const string& path, FGTileEntry *tile, - ssgVertexArray *lights, const bool is_base); +// Load an Binary obj file +bool fgBinObjLoad( const string& path, const bool is_base, + Point3D *center, + double *bounding_radius, + ssgBranch* geometry, + ssgBranch* rwy_lights, + ssgVertexArray *ground_lights ); // Load an ascii object file ssgBranch *fgAsciiObjLoad(const string& path, FGTileEntry *tile, ssgVertexArray *lights, const bool is_base); // Generate an ocean tile -ssgBranch *fgGenTile( const string& path, FGTileEntry *t); +bool fgGenTile( const string& path, SGBucket b, + Point3D *center, + double *bounding_radius, + ssgBranch* geometry ); // Create an ssg leaf diff --git a/src/Scenery/tileentry.cxx b/src/Scenery/tileentry.cxx index e9a719133..adc92e04e 100644 --- a/src/Scenery/tileentry.cxx +++ b/src/Scenery/tileentry.cxx @@ -959,22 +959,42 @@ ssgLeaf* FGTileEntry::gen_lights( ssgVertexArray *lights, int inc, float bright ssgBranch* FGTileEntry::obj_load( const std::string& path, - ssgVertexArray* lights, bool is_base ) + ssgVertexArray* ground_lights, bool is_base ) { - ssgBranch* result = 0; + ssgBranch* geometry = new ssgBranch; + ssgBranch* rwy_lights = new ssgBranch; + + Point3D c; // returned center point + double br; // returned bounding radius // try loading binary format - result = fgBinObjLoad( path, this, lights, is_base ); - if ( result == NULL ) { - // next try the older ascii format - result = fgAsciiObjLoad( path, this, lights, is_base ); - if ( result == NULL ) { + if ( fgBinObjLoad( path, is_base, + &c, &br, geometry, rwy_lights, ground_lights ) ) + { + if ( is_base ) { + center = c; + bounding_radius = br; + } + } else { + // next try the older ascii format, this is some ugly + // weirdness because the ascii loader is *old* and hasn't been + // updated, but hopefully we can can the ascii format soon. + ssgBranch *tmp = fgAsciiObjLoad( path, this, ground_lights, is_base ); + if ( tmp ) { + return tmp; + } else { // default to an ocean tile - result = fgGenTile( path, this ); + if ( fgGenTile( path, tile_bucket, &c, &br, geometry ) ) { + center = c; + bounding_radius = br; + } else { + SG_LOG( SG_TERRAIN, SG_ALERT, + "Warning: failed to generate ocean tile!" ); + } } } - return result; + return geometry; } diff --git a/src/Scenery/tileentry.hxx b/src/Scenery/tileentry.hxx index 45ec4d8f8..0abcebaab 100644 --- a/src/Scenery/tileentry.hxx +++ b/src/Scenery/tileentry.hxx @@ -104,6 +104,8 @@ class FGTileEntry { public: + /* CLO123 FROM HERE TO THE CORRESPONDING MARKER ARE THINGS THAT + CAN BE DELETED AFTER WE DROP THE ASCII SCENERY FORMAT */ typedef vector < sgVec3 * > free_vec3_list; typedef vector < sgVec2 * > free_vec2_list; typedef vector < unsigned short * > free_index_list; @@ -111,6 +113,7 @@ public: // node list point_list nodes; int ncount; + /* CLO123 MARKER */ // global tile culling data Point3D center; @@ -180,7 +183,8 @@ private: volatile int pending_models; ssgBranch* obj_load( const std::string& path, - ssgVertexArray* lights, bool is_base ); + ssgVertexArray* gound_lights, + bool is_base ); ssgLeaf* gen_lights( ssgVertexArray *lights, int inc, float bright );