1
0
Fork 0

align tgconstruct and genapt to new sgbinobj api

This commit is contained in:
Peter Sadrozinski 2014-04-12 12:08:59 -04:00 committed by Christian Schmitt
parent 25294ee911
commit c7c8c0be82
2 changed files with 1434 additions and 1500 deletions
src
Airports/GenAirports850
BuildTiles/Main

File diff suppressed because it is too large Load diff

View file

@ -1,252 +1,213 @@
// tgconstruct_output.cxx --Handle writing out the btg and stg files // tgconstruct_output.cxx --Handle writing out the btg and stg files
// //
// Written by Curtis Olson, started May 1999. // Written by Curtis Olson, started May 1999.
// //
// Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt // Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as // modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the // published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version. // License, or (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, but // This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of // WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details. // General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
// //
// $Id: construct.cxx,v 1.4 2004-11-19 22:25:49 curt Exp $ // $Id: construct.cxx,v 1.4 2004-11-19 22:25:49 curt Exp $
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include <config.h> # include <config.h>
#endif #endif
#include <simgear/math/SGGeometry.hxx> #include <simgear/math/SGGeometry.hxx>
#include <simgear/misc/sg_dir.hxx> #include <simgear/misc/sg_dir.hxx>
#include <simgear/io/sg_binobj.hxx> #include <simgear/io/sg_binobj.hxx>
#include <simgear/structure/exception.hxx> #include <simgear/structure/exception.hxx>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <terragear/tg_unique_vec3f.hxx> #include <terragear/tg_unique_vec3f.hxx>
#include <terragear/tg_unique_vec2f.hxx> #include <terragear/tg_unique_vec2f.hxx>
#include "tgconstruct.hxx" #include "tgconstruct.hxx"
using std::string; using std::string;
// collect custom objects and move to scenery area // collect custom objects and move to scenery area
void TGConstruct::AddCustomObjects( void ) { void TGConstruct::AddCustomObjects( void ) {
// Create/open the output .stg file for writing // Create/open the output .stg file for writing
SGPath dest_d(output_base.c_str()); SGPath dest_d(output_base.c_str());
dest_d.append(bucket.gen_base_path().c_str()); dest_d.append(bucket.gen_base_path().c_str());
string dest_dir = dest_d.str_native(); string dest_dir = dest_d.str_native();
SGPath dest_i(dest_d); SGPath dest_i(dest_d);
dest_i.append(bucket.gen_index_str()); dest_i.append(bucket.gen_index_str());
dest_i.concat(".stg"); dest_i.concat(".stg");
string dest_ind = dest_i.str_native(); string dest_ind = dest_i.str_native();
FILE *fp; FILE *fp;
lock->lock(); lock->lock();
if ( (fp = fopen( dest_ind.c_str(), "w" )) == NULL ) { if ( (fp = fopen( dest_ind.c_str(), "w" )) == NULL ) {
SG_LOG( SG_GENERAL, SG_ALERT, "ERROR: opening " << dest_ind << " for writing!" ); SG_LOG( SG_GENERAL, SG_ALERT, "ERROR: opening " << dest_ind << " for writing!" );
exit(-1); exit(-1);
} }
// Start with the default custom object which is the base terrain // Start with the default custom object which is the base terrain
fprintf(fp, "OBJECT_BASE %s.btg\n", bucket.gen_index_str().c_str()); fprintf(fp, "OBJECT_BASE %s.btg\n", bucket.gen_index_str().c_str());
char line[2048]; // big enough? char line[2048]; // big enough?
char token[256]; char token[256];
char name[256]; char name[256];
for ( int i = 0; i < (int)load_dirs.size(); ++i ) { for ( int i = 0; i < (int)load_dirs.size(); ++i ) {
SGPath base(work_base.c_str()); SGPath base(work_base.c_str());
base.append(load_dirs[i]); base.append(load_dirs[i]);
base.append( bucket.gen_base_path() ); base.append( bucket.gen_base_path() );
SGPath index(base); SGPath index(base);
index.append( bucket.gen_index_str() ); index.append( bucket.gen_index_str() );
index.concat(".ind"); index.concat(".ind");
string index_file = index.str_native(); string index_file = index.str_native();
sg_gzifstream in( index_file ); sg_gzifstream in( index_file );
if ( ! in.is_open() ) { if ( ! in.is_open() ) {
//No custom objects //No custom objects
} else { } else {
while ( ! in.eof() ) { while ( ! in.eof() ) {
SG_LOG( SG_GENERAL, SG_DEBUG, "Collecting custom objects from " << index_file ); SG_LOG( SG_GENERAL, SG_DEBUG, "Collecting custom objects from " << index_file );
in.getline(line, 2048); in.getline(line, 2048);
SG_LOG( SG_GENERAL, SG_DEBUG, "line = " << line ); SG_LOG( SG_GENERAL, SG_DEBUG, "line = " << line );
int result = sscanf( line, "%s %s", token, name ); int result = sscanf( line, "%s %s", token, name );
SG_LOG( SG_GENERAL, SG_DEBUG, "scanf scanned " << result << " tokens" ); SG_LOG( SG_GENERAL, SG_DEBUG, "scanf scanned " << result << " tokens" );
if ( result > 0 ) { if ( result > 0 ) {
SG_LOG( SG_GENERAL, SG_DEBUG, "token = " << token << " name = " << name ); SG_LOG( SG_GENERAL, SG_DEBUG, "token = " << token << " name = " << name );
if ( strcmp( token, "OBJECT" ) == 0 ) { if ( strcmp( token, "OBJECT" ) == 0 ) {
SGPath srcbase(base); SGPath srcbase(base);
srcbase.append(name); srcbase.append(name);
srcbase.concat(".gz"); srcbase.concat(".gz");
string basecom = srcbase.str_native(); string basecom = srcbase.str_native();
#ifdef _MSC_VER #ifdef _MSC_VER
string command = "copy " + basecom + " " + dest_dir; string command = "copy " + basecom + " " + dest_dir;
#else #else
string command = "cp " + basecom + " " + dest_dir; string command = "cp " + basecom + " " + dest_dir;
#endif #endif
SG_LOG( SG_GENERAL, SG_DEBUG, "running " << command ); SG_LOG( SG_GENERAL, SG_DEBUG, "running " << command );
if ( system( command.c_str() ) != -1 ) { if ( system( command.c_str() ) != -1 ) {
fprintf(fp, "OBJECT %s\n", name); fprintf(fp, "OBJECT %s\n", name);
} else { } else {
SG_LOG( SG_GENERAL, SG_ALERT, "Could not issue command " << command ); SG_LOG( SG_GENERAL, SG_ALERT, "Could not issue command " << command );
} }
} else { } else {
fprintf(fp, "%s\n", line); fprintf(fp, "%s\n", line);
} }
} }
} }
} }
} }
fclose(fp); fclose(fp);
lock->unlock(); lock->unlock();
} }
void TGConstruct::WriteBtgFile( void ) void TGConstruct::WriteBtgFile( void )
{ {
UniqueSGVec3fSet normals; UniqueSGVec3fSet normals;
UniqueSGVec2fSet texcoords; UniqueSGVec2fSet texcoords;
group_list pts_v; pts_v.clear(); std::vector< SGVec3d > wgs84_nodes;
group_list pts_n; pts_n.clear(); nodes.get_wgs84_nodes( wgs84_nodes );
string_list pt_materials; pt_materials.clear();
SGVec3d gbs_center = SGVec3d::fromGeod( bucket.get_center() );
group_list tris_v; tris_v.clear(); double dist_squared, radius_squared = 0;
group_list tris_n; tris_n.clear(); for (int i = 0; i < (int)wgs84_nodes.size(); ++i)
group_list tris_tc; tris_tc.clear(); {
string_list tri_materials; tri_materials.clear(); dist_squared = distSqr(gbs_center, wgs84_nodes[i]);
if ( dist_squared > radius_squared ) {
group_list strips_v; strips_v.clear(); radius_squared = dist_squared;
group_list strips_n; strips_n.clear(); }
group_list strips_tc; strips_tc.clear(); }
string_list strip_materials; strip_materials.clear(); double gbs_radius = sqrt(radius_squared);
int index; SG_LOG(SG_GENERAL, SG_DEBUG, "gbs center = " << gbs_center);
int_list pt_v, tri_v, strip_v; SG_LOG(SG_GENERAL, SG_DEBUG, "Done with wgs84 node mapping");
int_list pt_n, tri_n, strip_n; SG_LOG(SG_GENERAL, SG_DEBUG, " center = " << gbs_center << " radius = " << gbs_radius );
int_list tri_tc, strip_tc;
string base = output_base;
for (unsigned int area = 0; area < area_defs.size(); area++) { string binname = bucket.gen_index_str();
// only tesselate non holes binname += ".btg";
if ( !area_defs.is_hole_area(area) ) { string txtname = bucket.gen_index_str();
for (unsigned int p = 0; p < polys_clipped.area_size(area); p++ ) { txtname += ".txt";
SG_LOG( SG_CLIPPER, SG_DEBUG, "Ouput nodes for " << area_defs.get_area_name(area) << ":" << p+1 << " of " << polys_clipped.area_size(area) );
SGBinObject obj;
tgPolygon poly = polys_clipped.get_poly(area, p);
string material = poly.GetMaterial(); for (unsigned int area = 0; area < area_defs.size(); area++) {
// only output non holes
for (unsigned int k = 0; k < poly.Triangles(); ++k) { if ( !area_defs.is_hole_area(area) ) {
tri_v.clear(); for (unsigned int p = 0; p < polys_clipped.area_size(area); p++ ) {
tri_n.clear(); SG_LOG( SG_CLIPPER, SG_DEBUG, "Ouput nodes for " << area_defs.get_area_name(area) << ":" << p+1 << " of " << polys_clipped.area_size(area) );
tri_tc.clear();
for (int l = 0; l < 3; ++l) { tgPolygon poly = polys_clipped.get_poly(area, p);
index = poly.GetTriIdx( k, l ); string material = poly.GetMaterial();
tri_v.push_back( index ); SGBinObjectTriangle sgboTri;
// add the node's normal for (unsigned int k = 0; k < poly.Triangles(); ++k) {
index = normals.add( nodes.GetNormal( index ) ); sgboTri.clear();
tri_n.push_back( index ); sgboTri.material = material;
index = texcoords.add( poly.GetTriTexCoord( k, l ) ); for (int l = 0; l < 3; ++l) {
tri_tc.push_back( index ); int index;
}
tris_v.push_back( tri_v ); index = poly.GetTriIdx( k, l );
tris_n.push_back( tri_n ); sgboTri.v_list.push_back( index );
tris_tc.push_back( tri_tc );
// add the node's normal
tri_materials.push_back( material ); index = normals.add( nodes.GetNormal( index ) );
} sgboTri.n_list.push_back( index );
}
} index = texcoords.add( poly.GetTriTexCoord( k, l ) );
} sgboTri.tc_list[0].push_back( index );
}
std::vector< SGVec3d > wgs84_nodes;
nodes.get_wgs84_nodes( wgs84_nodes ); obj.add_triangle( sgboTri );
SGVec3d gbs_center = SGVec3d::fromGeod( bucket.get_center() ); }
double dist_squared, radius_squared = 0; }
for (int i = 0; i < (int)wgs84_nodes.size(); ++i) }
{ }
dist_squared = distSqr(gbs_center, wgs84_nodes[i]);
if ( dist_squared > radius_squared ) { obj.set_gbs_center( gbs_center );
radius_squared = dist_squared; obj.set_gbs_radius( gbs_radius );
} obj.set_wgs84_nodes( wgs84_nodes );
} obj.set_normals( normals.get_list() );
double gbs_radius = sqrt(radius_squared); obj.set_texcoords( texcoords.get_list() );
SG_LOG(SG_GENERAL, SG_DEBUG, "gbs center = " << gbs_center); bool result;
SG_LOG(SG_GENERAL, SG_DEBUG, "Done with wgs84 node mapping");
SG_LOG(SG_GENERAL, SG_DEBUG, " center = " << gbs_center << " radius = " << gbs_radius ); lock->lock();
result = obj.write_bin( base, binname, bucket );
// null structures lock->unlock();
group_list fans_v; fans_v.clear();
group_list fans_n; fans_n.clear(); if ( !result )
group_list fans_tc; fans_tc.clear(); {
string_list fan_materials; fan_materials.clear(); throw sg_exception("error writing file. :-(");
}
string base = output_base; if (debug_all || debug_shapes.size())
string binname = bucket.gen_index_str(); {
binname += ".btg"; lock->lock();
string txtname = bucket.gen_index_str(); result = obj.write_ascii( base, txtname, bucket );
txtname += ".txt"; lock->unlock();
SGBinObject obj; if ( !result )
{
obj.set_gbs_center( gbs_center ); throw sg_exception("error writing file. :-(");
obj.set_gbs_radius( gbs_radius ); }
obj.set_wgs84_nodes( wgs84_nodes ); }
obj.set_normals( normals.get_list() ); }
obj.set_texcoords( texcoords.get_list() );
obj.set_pts_v( pts_v );
obj.set_pts_n( pts_n );
obj.set_pt_materials( pt_materials );
obj.set_tris_v( tris_v );
obj.set_tris_n( tris_n );
obj.set_tris_tc( tris_tc );
obj.set_tri_materials( tri_materials );
obj.set_strips_v( strips_v );
obj.set_strips_n( strips_n );
obj.set_strips_tc( strips_tc );
obj.set_strip_materials( strip_materials );
obj.set_fans_v( fans_v );
obj.set_fans_n( fans_n );
obj.set_fans_tc( fans_tc );
obj.set_fan_materials( fan_materials );
bool result;
lock->lock();
result = obj.write_bin( base, binname, bucket );
lock->unlock();
if ( !result )
{
throw sg_exception("error writing file. :-(");
}
if (debug_all || debug_shapes.size())
{
lock->lock();
result = obj.write_ascii( base, txtname, bucket );
lock->unlock();
if ( !result )
{
throw sg_exception("error writing file. :-(");
}
}
}