Updates to the scenery loading infrastructure to make it more flexible,
clean up some messiness, and lay more groundwork for runway lighting.
This commit is contained in:
parent
9c42c9288a
commit
938d006188
4 changed files with 82 additions and 54 deletions
|
@ -108,19 +108,17 @@ static Point3D local_calc_tex_coords(const Point3D& node, const Point3D& ref) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Generate a generic ocean tile on the fly
|
// 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 )
|
||||||
|
{
|
||||||
FGNewMat *newmat;
|
FGNewMat *newmat;
|
||||||
|
|
||||||
ssgSimpleState *state = NULL;
|
ssgSimpleState *state = NULL;
|
||||||
|
|
||||||
ssgBranch *tile = new ssgBranch () ;
|
geometry -> setName ( (char *)path.c_str() ) ;
|
||||||
if ( !tile ) {
|
|
||||||
SG_LOG( SG_TERRAIN, SG_ALERT, "fgGenTile(): NO MEMORY" );
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
tile -> setName ( (char *)path.c_str() ) ;
|
|
||||||
|
|
||||||
double tex_width = 1000.0;
|
double tex_width = 1000.0;
|
||||||
// double tex_height;
|
// double tex_height;
|
||||||
|
@ -142,14 +140,14 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate center point
|
// Calculate center point
|
||||||
SGBucket b = t->tile_bucket;
|
|
||||||
double clon = b.get_center_lon();
|
double clon = b.get_center_lon();
|
||||||
double clat = b.get_center_lat();
|
double clat = b.get_center_lat();
|
||||||
double height = b.get_height();
|
double height = b.get_height();
|
||||||
double width = b.get_width();
|
double width = b.get_width();
|
||||||
|
|
||||||
Point3D center = sgGeodToCart(Point3D(clon*SGD_DEGREES_TO_RADIANS,clat*SGD_DEGREES_TO_RADIANS,0.0));
|
*center = sgGeodToCart( Point3D(clon*SGD_DEGREES_TO_RADIANS,
|
||||||
t->center = center;
|
clat*SGD_DEGREES_TO_RADIANS,
|
||||||
|
0.0) );
|
||||||
// cout << "center = " << center << endl;;
|
// cout << "center = " << center << endl;;
|
||||||
|
|
||||||
// Caculate corner vertices
|
// Caculate corner vertices
|
||||||
|
@ -168,18 +166,14 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Point3D cart[4], rel[4];
|
Point3D cart[4], rel[4];
|
||||||
t->nodes.clear();
|
|
||||||
for ( i = 0; i < 4; ++i ) {
|
for ( i = 0; i < 4; ++i ) {
|
||||||
cart[i] = sgGeodToCart(rad[i]);
|
cart[i] = sgGeodToCart(rad[i]);
|
||||||
rel[i] = cart[i] - center;
|
rel[i] = cart[i] - *center;
|
||||||
t->nodes.push_back( rel[i] );
|
|
||||||
// cout << "corner " << i << " = " << cart[i] << endl;
|
// cout << "corner " << i << " = " << cart[i] << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
t->ncount = 4;
|
|
||||||
|
|
||||||
// Calculate bounding radius
|
// Calculate bounding radius
|
||||||
t->bounding_radius = center.distance3D( cart[0] );
|
*bounding_radius = center->distance3D( cart[0] );
|
||||||
// cout << "bounding radius = " << t->bounding_radius << endl;
|
// cout << "bounding radius = " << t->bounding_radius << endl;
|
||||||
|
|
||||||
// Calculate normals
|
// Calculate normals
|
||||||
|
@ -239,9 +233,9 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
|
||||||
|
|
||||||
leaf->setState( state );
|
leaf->setState( state );
|
||||||
|
|
||||||
tile->addKid( leaf );
|
geometry->addKid( leaf );
|
||||||
|
|
||||||
return tile;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -906,28 +900,29 @@ ssgLeaf *gen_leaf( const string& path,
|
||||||
|
|
||||||
|
|
||||||
// Load an Binary obj file
|
// Load an Binary obj file
|
||||||
ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t,
|
bool fgBinObjLoad( const string& path, const bool is_base,
|
||||||
ssgVertexArray *lights, const bool is_base)
|
Point3D *center,
|
||||||
|
double *bounding_radius,
|
||||||
|
ssgBranch* geometry,
|
||||||
|
ssgBranch* rwy_lights,
|
||||||
|
ssgVertexArray *ground_lights )
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
SGBinObject obj;
|
SGBinObject obj;
|
||||||
bool result = obj.read_bin( path );
|
bool result = obj.read_bin( path );
|
||||||
|
|
||||||
if ( !result ) {
|
if ( !result ) {
|
||||||
return NULL;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cout << "fans size = " << obj.get_fans_v().size()
|
// cout << "fans size = " << obj.get_fans_v().size()
|
||||||
// << " fan_mats size = " << obj.get_fan_materials().size() << endl;
|
// << " fan_mats size = " << obj.get_fan_materials().size() << endl;
|
||||||
|
|
||||||
ssgBranch *object = new ssgBranch();
|
geometry->setName( (char *)path.c_str() );
|
||||||
object->setName( (char *)path.c_str() );
|
|
||||||
|
|
||||||
if ( is_base && t != NULL ) {
|
if ( is_base ) {
|
||||||
// reference point (center offset/bounding sphere)
|
// reference point (center offset/bounding sphere)
|
||||||
t->center = obj.get_gbs_center();
|
*center = obj.get_gbs_center();
|
||||||
t->bounding_radius = obj.get_gbs_radius();
|
*bounding_radius = obj.get_gbs_radius();
|
||||||
}
|
}
|
||||||
|
|
||||||
point_list nodes = obj.get_wgs84_nodes();
|
point_list nodes = obj.get_wgs84_nodes();
|
||||||
|
@ -939,6 +934,8 @@ ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t,
|
||||||
int_list vertex_index;
|
int_list vertex_index;
|
||||||
int_list tex_index;
|
int_list tex_index;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
|
||||||
// generate points
|
// generate points
|
||||||
string_list pt_materials = obj.get_pt_materials();
|
string_list pt_materials = obj.get_pt_materials();
|
||||||
group_list pts_v = obj.get_pts_v();
|
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,
|
ssgLeaf *leaf = gen_leaf( path, GL_POINTS, material,
|
||||||
nodes, normals, texcoords,
|
nodes, normals, texcoords,
|
||||||
vertex_index, tex_index,
|
vertex_index, tex_index,
|
||||||
false, lights );
|
false, ground_lights );
|
||||||
|
|
||||||
object->addKid( leaf );
|
geometry->addKid( leaf );
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate triangles
|
// generate triangles
|
||||||
|
@ -966,9 +963,9 @@ ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t,
|
||||||
ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLES, material,
|
ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLES, material,
|
||||||
nodes, normals, texcoords,
|
nodes, normals, texcoords,
|
||||||
vertex_index, tex_index,
|
vertex_index, tex_index,
|
||||||
is_base, lights );
|
is_base, ground_lights );
|
||||||
|
|
||||||
object->addKid( leaf );
|
geometry->addKid( leaf );
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate strips
|
// generate strips
|
||||||
|
@ -982,9 +979,9 @@ ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t,
|
||||||
ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material,
|
ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material,
|
||||||
nodes, normals, texcoords,
|
nodes, normals, texcoords,
|
||||||
vertex_index, tex_index,
|
vertex_index, tex_index,
|
||||||
is_base, lights );
|
is_base, ground_lights );
|
||||||
|
|
||||||
object->addKid( leaf );
|
geometry->addKid( leaf );
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate fans
|
// generate fans
|
||||||
|
@ -998,10 +995,10 @@ ssgBranch *fgBinObjLoad( const string& path, FGTileEntry *t,
|
||||||
ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_FAN, material,
|
ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_FAN, material,
|
||||||
nodes, normals, texcoords,
|
nodes, normals, texcoords,
|
||||||
vertex_index, tex_index,
|
vertex_index, tex_index,
|
||||||
is_base, lights );
|
is_base, ground_lights );
|
||||||
|
|
||||||
object->addKid( leaf );
|
geometry->addKid( leaf );
|
||||||
}
|
}
|
||||||
|
|
||||||
return object;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,16 +57,23 @@ SG_USING_STD(string);
|
||||||
#define FG_MAX_NODES 4000
|
#define FG_MAX_NODES 4000
|
||||||
|
|
||||||
|
|
||||||
// Load a binary object file
|
// Load an Binary obj file
|
||||||
ssgBranch *fgBinObjLoad(const string& path, FGTileEntry *tile,
|
bool fgBinObjLoad( const string& path, const bool is_base,
|
||||||
ssgVertexArray *lights, const bool is_base);
|
Point3D *center,
|
||||||
|
double *bounding_radius,
|
||||||
|
ssgBranch* geometry,
|
||||||
|
ssgBranch* rwy_lights,
|
||||||
|
ssgVertexArray *ground_lights );
|
||||||
|
|
||||||
// Load an ascii object file
|
// Load an ascii object file
|
||||||
ssgBranch *fgAsciiObjLoad(const string& path, FGTileEntry *tile,
|
ssgBranch *fgAsciiObjLoad(const string& path, FGTileEntry *tile,
|
||||||
ssgVertexArray *lights, const bool is_base);
|
ssgVertexArray *lights, const bool is_base);
|
||||||
|
|
||||||
// Generate an ocean tile
|
// 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
|
// Create an ssg leaf
|
||||||
|
|
|
@ -959,22 +959,42 @@ ssgLeaf* FGTileEntry::gen_lights( ssgVertexArray *lights, int inc, float bright
|
||||||
|
|
||||||
ssgBranch*
|
ssgBranch*
|
||||||
FGTileEntry::obj_load( const std::string& path,
|
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
|
// try loading binary format
|
||||||
result = fgBinObjLoad( path, this, lights, is_base );
|
if ( fgBinObjLoad( path, is_base,
|
||||||
if ( result == NULL ) {
|
&c, &br, geometry, rwy_lights, ground_lights ) )
|
||||||
// next try the older ascii format
|
{
|
||||||
result = fgAsciiObjLoad( path, this, lights, is_base );
|
if ( is_base ) {
|
||||||
if ( result == NULL ) {
|
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
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,8 @@ class FGTileEntry {
|
||||||
|
|
||||||
public:
|
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 < sgVec3 * > free_vec3_list;
|
||||||
typedef vector < sgVec2 * > free_vec2_list;
|
typedef vector < sgVec2 * > free_vec2_list;
|
||||||
typedef vector < unsigned short * > free_index_list;
|
typedef vector < unsigned short * > free_index_list;
|
||||||
|
@ -111,6 +113,7 @@ public:
|
||||||
// node list
|
// node list
|
||||||
point_list nodes;
|
point_list nodes;
|
||||||
int ncount;
|
int ncount;
|
||||||
|
/* CLO123 MARKER */
|
||||||
|
|
||||||
// global tile culling data
|
// global tile culling data
|
||||||
Point3D center;
|
Point3D center;
|
||||||
|
@ -180,7 +183,8 @@ private:
|
||||||
volatile int pending_models;
|
volatile int pending_models;
|
||||||
|
|
||||||
ssgBranch* obj_load( const std::string& path,
|
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 );
|
ssgLeaf* gen_lights( ssgVertexArray *lights, int inc, float bright );
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue