1 // tileentry.cxx -- routines to handle a scenery tile
3 // Written by Curtis Olson, started May 1998.
5 // Copyright (C) 1998 - 2001 Curtis L. Olson - http://www.flightgear.org/~curt
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #include <simgear/compiler.h>
30 #include <Main/main.hxx>
36 #include <osg/Geometry>
39 #include <osg/MatrixTransform>
40 #include <osg/NodeCallback>
43 #include <simgear/bucket/newbucket.hxx>
44 #include <simgear/debug/logstream.hxx>
45 #include <simgear/math/polar3d.hxx>
46 #include <simgear/math/sg_geodesy.hxx>
47 #include <simgear/math/sg_random.h>
48 #include <simgear/misc/sgstream.hxx>
49 #include <simgear/scene/material/mat.hxx>
50 #include <simgear/scene/material/matlib.hxx>
51 #include <simgear/scene/tgdb/apt_signs.hxx>
52 #include <simgear/scene/tgdb/obj.hxx>
53 #include <simgear/scene/model/placementtrans.hxx>
55 #include <Aircraft/aircraft.hxx>
56 #include <Include/general.hxx>
57 #include <Main/fg_props.hxx>
58 #include <Main/globals.hxx>
59 #include <Main/viewer.hxx>
60 #include <Scenery/scenery.hxx>
61 #include <Time/light.hxx>
63 #include "tileentry.hxx"
64 #include "tilemgr.hxx"
70 FGTileEntry::FGTileEntry ( const SGBucket& b )
71 : center( Point3D( 0.0 ) ),
73 terra_transform( new SGPlacementTransform ),
74 vasi_lights_transform( new SGPlacementTransform ),
75 rwy_lights_transform( new SGPlacementTransform ),
76 taxi_lights_transform( new SGPlacementTransform ),
77 terra_range( new osg::LOD ),
78 vasi_lights_selector( new osg::Switch ),
79 rwy_lights_selector( new osg::Switch ),
80 taxi_lights_selector( new osg::Switch ),
86 // update the contents
87 // if ( vec3_ptrs.size() || vec2_ptrs.size() || index_ptrs.size() ) {
88 // SG_LOG( SG_TERRAIN, SG_ALERT,
89 // "Attempting to overwrite existing or"
90 // << " not properly freed leaf data." );
97 FGTileEntry::~FGTileEntry () {
98 // cout << "nodes = " << nodes.size() << endl;;
102 static void WorldCoordinate( osg::Matrix& obj_pos, Point3D center, double lat,
103 double lon, double elev, double hdg )
105 double lon_rad = lon * SGD_DEGREES_TO_RADIANS;
106 double lat_rad = lat * SGD_DEGREES_TO_RADIANS;
107 double hdg_rad = hdg * SGD_DEGREES_TO_RADIANS;
110 Point3D geod( lon_rad, lat_rad, elev );
112 Point3D world_pos = sgGeodToCart( geod );
113 Point3D offset = world_pos - center;
117 SGfloat sin_lat = (SGfloat)sin( lat_rad );
118 SGfloat cos_lat = (SGfloat)cos( lat_rad );
119 SGfloat cos_lon = (SGfloat)cos( lon_rad );
120 SGfloat sin_lon = (SGfloat)sin( lon_rad );
121 SGfloat sin_hdg = (SGfloat)sin( hdg_rad ) ;
122 SGfloat cos_hdg = (SGfloat)cos( hdg_rad ) ;
124 mat[0][0] = cos_hdg * (SGfloat)sin_lat * (SGfloat)cos_lon - sin_hdg * (SGfloat)sin_lon;
125 mat[0][1] = cos_hdg * (SGfloat)sin_lat * (SGfloat)sin_lon + sin_hdg * (SGfloat)cos_lon;
126 mat[0][2] = -cos_hdg * (SGfloat)cos_lat;
129 mat[1][0] = -sin_hdg * (SGfloat)sin_lat * (SGfloat)cos_lon - cos_hdg * (SGfloat)sin_lon;
130 mat[1][1] = -sin_hdg * (SGfloat)sin_lat * (SGfloat)sin_lon + cos_hdg * (SGfloat)cos_lon;
131 mat[1][2] = sin_hdg * (SGfloat)cos_lat;
134 mat[2][0] = (SGfloat)cos_lat * (SGfloat)cos_lon;
135 mat[2][1] = (SGfloat)cos_lat * (SGfloat)sin_lon;
136 mat[2][2] = (SGfloat)sin_lat;
139 mat[3][0] = offset.x();
140 mat[3][1] = offset.y();
141 mat[3][2] = offset.z();
144 for (unsigned i = 0; i < 4; ++i)
145 for (unsigned j = 0; j < 4; ++j)
146 obj_pos(i, j) = mat[i][j];
150 // recurse an ssg tree and call removeChild() on every node from the
151 // bottom up. Leaves the original branch in existance, but empty so
152 // it can be removed by the calling routine.
153 // static void my_remove_branch( osg::Group * branch ) {
154 // branch->removeChildren(0, branch->getNumChildren());
158 // Free "n" leaf elements of an ssg tree. returns the number of
159 // elements freed. An empty branch node is considered a leaf. This
160 // is intended to spread the load of freeing a complex tile out over
162 static int fgPartialFreeSSGtree( osg::Group *b, int n ) {
165 b->removeChildren(0, b->getNumChildren());
168 // // we still have some delete budget left
169 // // if ( b->getNumChilds() > 100 ) {
170 // // cout << "large family = " << b->getNumChilds() << endl;
172 // // deleting in reverse would help if my plib patch get's
173 // // applied, but for now it will make things slower.
174 // // for ( int i = b->getNumChilds() - 1; i >= 0 ; --i ) {
175 // for ( int i = 0; i < b->getNumChildren(); ++i ) {
176 // ssgEntity *kid = b->getChild(i);
177 // if ( kid->isAKindOf( ssgTypeBranch() ) && kid->getRef() <= 1 ) {
178 // int result = fgPartialFreeSSGtree( (osg::Group *)kid, n );
179 // num_deletes += result;
185 // // remove the kid if (a) it is now empty -or- (b) it's ref
186 // // count is > zero at which point we don't care if it's
187 // // empty, we don't want to touch it's contents.
188 // if ( kid->getNumChildren() == 0 || kid->getRef() > 1 ) {
189 // b->removeChild( kid );
200 // Clean up the memory used by this tile and delete the arrays used by
201 // ssg as well as the whole ssg branch
202 bool FGTileEntry::free_tile() {
203 int delete_size = 100;
204 SG_LOG( SG_TERRAIN, SG_DEBUG,
205 "FREEING TILE = (" << tile_bucket << ")" );
207 SG_LOG( SG_TERRAIN, SG_DEBUG, "(start) free_tracker = " << free_tracker );
209 if ( !(free_tracker & NODES) ) {
210 free_tracker |= NODES;
211 } else if ( !(free_tracker & VEC_PTRS) ) {
212 free_tracker |= VEC_PTRS;
213 } else if ( !(free_tracker & TERRA_NODE) ) {
214 // delete the terrain branch (this should already have been
215 // disconnected from the scene graph)
216 SG_LOG( SG_TERRAIN, SG_DEBUG, "FREEING terra_transform" );
217 if ( fgPartialFreeSSGtree( terra_transform.get(), delete_size ) == 0 ) {
219 free_tracker |= TERRA_NODE;
221 } else if ( !(free_tracker & GROUND_LIGHTS) && gnd_lights_transform.get() ) {
222 // delete the terrain lighting branch (this should already have been
223 // disconnected from the scene graph)
224 SG_LOG( SG_TERRAIN, SG_DEBUG, "FREEING gnd_lights_transform" );
225 if ( fgPartialFreeSSGtree( gnd_lights_transform.get(), delete_size ) == 0 ) {
226 gnd_lights_transform = 0;
227 free_tracker |= GROUND_LIGHTS;
229 } else if ( !(free_tracker & VASI_LIGHTS) && vasi_lights_selector.get() ) {
230 // delete the runway lighting branch (this should already have
231 // been disconnected from the scene graph)
232 SG_LOG( SG_TERRAIN, SG_DEBUG, "FREEING vasi_lights_selector" );
233 if ( fgPartialFreeSSGtree( vasi_lights_selector.get(), delete_size ) == 0 ) {
234 vasi_lights_selector = 0;
235 free_tracker |= VASI_LIGHTS;
237 } else if ( !(free_tracker & RWY_LIGHTS) && rwy_lights_selector.get() ) {
238 // delete the runway lighting branch (this should already have
239 // been disconnected from the scene graph)
240 SG_LOG( SG_TERRAIN, SG_DEBUG, "FREEING rwy_lights_selector" );
241 if ( fgPartialFreeSSGtree( rwy_lights_selector.get(), delete_size ) == 0 ) {
242 rwy_lights_selector = 0;
243 free_tracker |= RWY_LIGHTS;
245 } else if ( !(free_tracker & TAXI_LIGHTS) && taxi_lights_selector.get() ) {
246 // delete the taxi lighting branch (this should already have been
247 // disconnected from the scene graph)
248 SG_LOG( SG_TERRAIN, SG_DEBUG, "FREEING taxi_lights_selector" );
249 if ( fgPartialFreeSSGtree( taxi_lights_selector.get(), delete_size ) == 0 ) {
250 taxi_lights_selector = 0;
251 free_tracker |= TAXI_LIGHTS;
253 } else if ( !(free_tracker & LIGHTMAPS) ) {
254 free_tracker |= LIGHTMAPS;
259 SG_LOG( SG_TERRAIN, SG_DEBUG, "(end) free_tracker = " << free_tracker );
261 // if we fall down to here, we still have work todo, return false
266 // Update the ssg transform node for this tile so it can be
267 // properly drawn relative to our (0,0,0) point
268 void FGTileEntry::prep_ssg_node( const Point3D& p, sgVec3 up, float vis) {
269 if ( !loaded ) return;
271 // visibility can change from frame to frame so we update the
272 // range selector cutoff's each time.
273 terra_range->setRange( 0, 0, vis + bounding_radius );
275 if ( gnd_lights_range.get() ) {
276 gnd_lights_range->setRange( 0, 0, vis * 1.5 + bounding_radius );
279 SGVec3d lt_trans(center.x(), center.y(), center.z());
281 FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
282 if ( gnd_lights_transform.get() ) {
283 // we need to lift the lights above the terrain to avoid
284 // z-buffer fighting. We do this based on our altitude and
285 // the distance this tile is away from scenery center.
287 // we expect 'up' to be a unit vector coming in, but since we
288 // modify the value of lift_vec, we need to create a local
290 SGVec3f lift_vec(up);
293 agl = globals->get_current_view()->getAltitudeASL_ft()*SG_FEET_TO_METER
294 - globals->get_current_view()->getSGLocation()->get_cur_elev_m();
296 // Compute the distance of the scenery center from the view position.
297 double dist = center.distance3D(p);
299 if ( general.get_glDepthBits() > 16 ) {
300 lift_vec *= 10.0 + agl / 100.0 + dist / 10000;
302 lift_vec *= 10.0 + agl / 20.0 + dist / 5000;
305 gnd_lights_transform->setTransform( lt_trans + toVec3d(lift_vec) );
307 // select which set of lights based on sun angle
308 float sun_angle = l->get_sun_angle() * SGD_RADIANS_TO_DEGREES;
309 if ( sun_angle > 95 ) {
310 gnd_lights_brightness->setSingleChildOn(2);
311 } else if ( sun_angle > 92 ) {
312 gnd_lights_brightness->setSingleChildOn(1);
313 } else if ( sun_angle > 89 ) {
314 gnd_lights_brightness->setSingleChildOn(0);
316 gnd_lights_brightness->setAllChildrenOff();
320 if ( rwy_lights_transform.get() ) {
321 // turn runway lights on/off based on sun angle and visibility
322 float sun_angle = l->get_sun_angle() * SGD_RADIANS_TO_DEGREES;
323 if ( sun_angle > 85 ||
324 (fgGetDouble("/environment/visibility-m") < 5000.0) ) {
325 rwy_lights_selector->setAllChildrenOn();
327 rwy_lights_selector->setAllChildrenOff();
331 if ( taxi_lights_transform.get() ) {
332 // turn taxi lights on/off based on sun angle and visibility
333 float sun_angle = l->get_sun_angle() * SGD_RADIANS_TO_DEGREES;
334 if ( sun_angle > 85 ||
335 (fgGetDouble("/environment/visibility-m") < 5000.0) ) {
336 taxi_lights_selector->setAllChildrenOn();
338 taxi_lights_selector->setAllChildrenOff();
345 FGTileEntry::gen_lights( SGMaterialLib *matlib, osg::Vec3Array *lights,
346 int inc, float bright )
348 // generate a repeatable random seed
349 sg_srandom( (unsigned)(*lights)[0][0] );
351 // Allocate ssg structure
352 osg::Vec3Array *vl = new osg::Vec3Array;
353 osg::Vec4Array *cl = new osg::Vec4Array;
355 for ( unsigned i = 0; i < lights->size(); ++i ) {
356 // this loop is slightly less efficient than it otherwise
357 // could be, but we want a red light to always be red, and a
358 // yellow light to always be yellow, etc. so we are trying to
359 // preserve the random sequence.
360 float zombie = sg_random();
361 if ( i % inc == 0 ) {
362 vl->push_back( (*lights)[i] );
364 // factor = sg_random() ^ 2, range = 0 .. 1 concentrated towards 0
365 float factor = sg_random();
369 if ( zombie > 0.5 ) {
370 // 50% chance of yellowish
371 color = osg::Vec4( 0.9, 0.9, 0.3, bright - factor * 0.2 );
372 } else if ( zombie > 0.15 ) {
373 // 35% chance of whitish
374 color = osg::Vec4( 0.9, 0.9, 0.8, bright - factor * 0.2 );
375 } else if ( zombie > 0.05 ) {
376 // 10% chance of orangish
377 color = osg::Vec4( 0.9, 0.6, 0.2, bright - factor * 0.2 );
379 // 5% chance of redish
380 color = osg::Vec4( 0.9, 0.2, 0.2, bright - factor * 0.2 );
382 cl->push_back( color );
387 osg::Geometry* geometry = new osg::Geometry;
388 geometry->setVertexArray(vl);
389 geometry->setColorArray(cl);
390 geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
391 geometry->addPrimitiveSet(new osg::DrawArrays(GL_POINTS, 0, vl->size()));
392 osg::Geode* geode = new osg::Geode;
393 geode->addDrawable(geometry);
396 SGMaterial *mat = matlib->find( "GROUND_LIGHTS" );
397 geode->setStateSet(mat->get_state());
403 bool FGTileEntry::obj_load( const string& path,
404 osg::Group *geometry,
405 osg::Group *vasi_lights,
406 osg::Group *rwy_lights,
407 osg::Group *taxi_lights,
408 osg::Vec3Array *ground_lights, bool is_base )
410 Point3D c; // returned center point
411 double br; // returned bounding radius
413 bool use_random_objects =
414 fgGetBool("/sim/rendering/random-objects", true);
416 // try loading binary format
417 if ( SGBinObjLoad( path, is_base,
418 &c, &br, globals->get_matlib(), use_random_objects,
419 geometry, vasi_lights, rwy_lights, taxi_lights,
424 bounding_radius = br;
428 return (geometry != NULL);
441 // storage class for deferred object processing in FGTileEntry::load()
443 Object(object_type t, const string& token, const SGPath& p, istream& in)
448 in >> lon >> lat >> elev >> hdg;
452 SG_LOG(SG_TERRAIN, SG_INFO, " " << token << " " << name);
454 SG_LOG(SG_TERRAIN, SG_INFO, " " << token << " " << name << " lon=" <<
455 lon << " lat=" << lat << " elev=" << elev << " hdg=" << hdg);
460 double lon, lat, elev, hdg;
465 FGTileEntry::load( const string_list &path_list, bool is_base )
467 bool found_tile_base = false;
470 vector<const Object*> objects;
472 string index_str = tile_bucket.gen_index_str();
473 SG_LOG( SG_TERRAIN, SG_INFO, "Loading tile " << index_str );
475 // scan and parse all files and store information
476 for (unsigned int i = 0; i < path_list.size(); i++) {
477 // If we found a terrain tile in Terrain/, we have to process the
478 // Objects/ dir in the same group, too, before we can stop scanning.
479 // FGGlobals::set_fg_scenery() inserts an empty string to path_list
481 if (path_list[i].empty()) {
488 bool has_base = false;
490 SGPath tile_path = path_list[i];
491 tile_path.append( tile_bucket.gen_base_path() );
493 SGPath basename = tile_path;
494 basename.append( index_str );
496 SG_LOG( SG_TERRAIN, SG_INFO, " Trying " << basename.str() );
499 // Check for master .stg (scene terra gear) file
500 SGPath stg_name = basename;
501 stg_name.concat( ".stg" );
503 sg_gzifstream in( stg_name.str() );
507 while ( ! in.eof() ) {
511 if ( token[0] == '#' ) {
515 // Load only once (first found)
516 if ( token == "OBJECT_BASE" ) {
518 in >> name >> ::skipws;
519 SG_LOG( SG_TERRAIN, SG_INFO, " " << token << " " << name );
521 if (!found_tile_base) {
522 found_tile_base = true;
525 object_base = tile_path;
526 object_base.append(name);
529 SG_LOG(SG_TERRAIN, SG_INFO, " (skipped)");
531 // Load only if base is not in another file
532 } else if ( token == "OBJECT" ) {
533 if (!found_tile_base || has_base)
534 objects.push_back(new Object(OBJECT, token, tile_path, in));
537 in >> name >> ::skipeol;
538 SG_LOG(SG_TERRAIN, SG_INFO, " " << token << " "
539 << name << " (skipped)");
543 } else if ( token == "OBJECT_STATIC" ) {
544 objects.push_back(new Object(OBJECT_STATIC, token, tile_path, in));
546 } else if ( token == "OBJECT_SHARED" ) {
547 objects.push_back(new Object(OBJECT_SHARED, token, tile_path, in));
549 } else if ( token == "OBJECT_SIGN" ) {
550 objects.push_back(new Object(OBJECT_SIGN, token, tile_path, in));
552 } else if ( token == "OBJECT_RUNWAY_SIGN" ) {
553 objects.push_back(new Object(OBJECT_RUNWAY_SIGN, token, tile_path, in));
556 SG_LOG( SG_TERRAIN, SG_DEBUG,
557 "Unknown token '" << token << "' in " << stg_name.str() );
564 // obj_load() will generate ground lighting for us ...
565 osg::ref_ptr<osg::Vec3Array> light_pts = new osg::Vec3Array;
566 osg::Group* new_tile = new osg::Group;
569 if (found_tile_base) {
570 // load tile if found ...
571 osg::ref_ptr<osg::Group> geometry = new osg::Group;
572 if ( obj_load( object_base.str(), geometry.get(),
573 NULL, NULL, NULL, light_pts.get(), true ) ) {
574 new_tile -> addChild( geometry.get() );
578 // ... or generate an ocean tile on the fly
579 SG_LOG(SG_TERRAIN, SG_INFO, " Generating ocean tile");
580 osg::ref_ptr<osg::Group> geometry = new osg::Group;
583 if ( SGGenTile( path_list[0], tile_bucket, &c, &br,
584 globals->get_matlib(), geometry.get() ) ) {
586 bounding_radius = br;
587 new_tile -> addChild( geometry.get() );
589 SG_LOG( SG_TERRAIN, SG_ALERT,
590 "Warning: failed to generate ocean tile!" );
595 // now that we have a valid center, process all the objects
596 for (unsigned int j = 0; j < objects.size(); j++) {
597 const Object *obj = objects[j];
599 if (obj->type == OBJECT) {
600 SGPath custom_path = obj->path;
601 custom_path.append( obj->name );
603 osg::ref_ptr<osg::Group> geometry = new osg::Group;
604 osg::ref_ptr<osg::Group> vasi_lights = new osg::Group;
605 osg::ref_ptr<osg::Group> rwy_lights = new osg::Group;
606 osg::ref_ptr<osg::Group> taxi_lights = new osg::Group;
608 if ( obj_load( custom_path.str(),
609 geometry.get(), vasi_lights.get(), rwy_lights.get(),
610 taxi_lights.get(), NULL, false ) ) {
612 if ( geometry -> getNumChildren() > 0 ) {
613 new_tile -> addChild( geometry.get() );
616 if ( vasi_lights -> getNumChildren() > 0 )
617 vasi_lights_transform -> addChild( vasi_lights.get() );
619 if ( rwy_lights -> getNumChildren() > 0 )
620 rwy_lights_transform -> addChild( rwy_lights.get() );
622 if ( taxi_lights -> getNumChildren() > 0 )
623 taxi_lights_transform -> addChild( taxi_lights.get() );
627 } else if (obj->type == OBJECT_SHARED || obj->type == OBJECT_STATIC) {
628 // object loading is deferred to main render thread,
629 // but lets figure out the paths right now.
631 if ( obj->type == OBJECT_STATIC ) {
632 custom_path = obj->path;
634 custom_path = globals->get_fg_root();
636 custom_path.append( obj->name );
639 WorldCoordinate( obj_pos, center, obj->lat, obj->lon, obj->elev, obj->hdg );
641 osg::MatrixTransform *obj_trans = new osg::MatrixTransform;
642 obj_trans->setMatrix( obj_pos );
644 // wire as much of the scene graph together as we can
645 new_tile->addChild( obj_trans );
648 // push an entry onto the model load queue
650 = new FGDeferredModel( custom_path.str(),
654 obj->type == OBJECT_SHARED );
655 FGTileMgr::model_ready( dm );
658 } else if (obj->type == OBJECT_SIGN || obj->type == OBJECT_RUNWAY_SIGN) {
659 // load the object itself
660 SGPath custom_path = obj->path;
661 custom_path.append( obj->name );
664 WorldCoordinate( obj_pos, center, obj->lat, obj->lon, obj->elev, obj->hdg );
666 osg::MatrixTransform *obj_trans = new osg::MatrixTransform;
667 obj_trans->setMatrix( obj_pos );
669 osg::Node *custom_obj = 0;
670 if (obj->type == OBJECT_SIGN)
671 custom_obj = SGMakeSign(globals->get_matlib(), custom_path.str(), obj->name);
673 custom_obj = SGMakeRunwaySign(globals->get_matlib(), custom_path.str(), obj->name);
675 // wire the pieces together
676 if ( custom_obj != NULL ) {
677 obj_trans -> addChild( custom_obj );
679 new_tile->addChild( obj_trans );
686 if ( new_tile != NULL ) {
687 terra_range->addChild( new_tile );
690 terra_transform->addChild( terra_range.get() );
692 // calculate initial tile offset
693 SGVec3d sgdTrans(center.x(), center.y(), center.z());
694 terra_transform->setTransform( sgdTrans );
696 // Add ground lights to scene graph if any exist
697 gnd_lights_transform = NULL;
698 gnd_lights_range = NULL;
699 if ( light_pts->size() ) {
700 SG_LOG( SG_TERRAIN, SG_DEBUG, "generating lights" );
701 gnd_lights_transform = new SGPlacementTransform;
702 gnd_lights_range = new osg::LOD;
703 gnd_lights_brightness = new osg::Switch;
706 lights = gen_lights( globals->get_matlib(), light_pts.get(), 4, 0.7 );
707 gnd_lights_brightness->addChild( lights );
709 lights = gen_lights( globals->get_matlib(), light_pts.get(), 2, 0.85 );
710 gnd_lights_brightness->addChild( lights );
712 lights = gen_lights( globals->get_matlib(), light_pts.get(), 1, 1.0 );
713 gnd_lights_brightness->addChild( lights );
715 gnd_lights_range->addChild( gnd_lights_brightness.get() );
716 gnd_lights_transform->addChild( gnd_lights_range.get() );
717 gnd_lights_transform->setTransform( sgdTrans );
720 // Update vasi lights transform
721 if ( vasi_lights_transform->getNumChildren() > 0 ) {
722 vasi_lights_transform->setTransform( sgdTrans );
725 // Update runway lights transform
726 if ( rwy_lights_transform->getNumChildren() > 0 ) {
727 rwy_lights_transform->setTransform( sgdTrans );
730 // Update taxi lights transform
731 if ( taxi_lights_transform->getNumChildren() > 0 ) {
732 taxi_lights_transform->setTransform( sgdTrans );
737 FGTileEntry::add_ssg_nodes( osg::Group *terrain_branch,
738 osg::Group *gnd_lights_branch,
739 osg::Group *vasi_lights_branch,
740 osg::Group *rwy_lights_branch,
741 osg::Group *taxi_lights_branch )
743 // bump up the ref count so we can remove this later without
744 // having ssg try to free the memory.
745 terrain_branch->addChild( terra_transform.get() );
746 globals->get_scenery()->register_placement_transform(terra_transform.get());
748 SG_LOG( SG_TERRAIN, SG_DEBUG,
749 "connected a tile into scene graph. terra_transform = "
750 << terra_transform.get() );
751 SG_LOG( SG_TERRAIN, SG_DEBUG, "num parents now = "
752 << terra_transform->getNumParents() );
754 if ( gnd_lights_transform.get() != NULL ) {
755 // bump up the ref count so we can remove this later without
756 // having ssg try to free the memory.
757 gnd_lights_branch->addChild( gnd_lights_transform.get() );
758 globals->get_scenery()->register_placement_transform(gnd_lights_transform.get());
761 if ( vasi_lights_transform.get() != NULL ) {
762 // bump up the ref count so we can remove this later without
763 // having ssg try to free the memory.
764 vasi_lights_selector->addChild( vasi_lights_transform.get() );
765 globals->get_scenery()->register_placement_transform(vasi_lights_transform.get());
766 vasi_lights_branch->addChild( vasi_lights_selector.get() );
769 if ( rwy_lights_transform.get() != NULL ) {
770 // bump up the ref count so we can remove this later without
771 // having ssg try to free the memory.
772 rwy_lights_selector->addChild( rwy_lights_transform.get() );
773 globals->get_scenery()->register_placement_transform(rwy_lights_transform.get());
774 rwy_lights_branch->addChild( rwy_lights_selector.get() );
777 if ( taxi_lights_transform.get() != NULL ) {
778 // bump up the ref count so we can remove this later without
779 // having ssg try to free the memory.
780 taxi_lights_selector->addChild( taxi_lights_transform.get() );
781 globals->get_scenery()->register_placement_transform(taxi_lights_transform.get());
782 taxi_lights_branch->addChild( taxi_lights_selector.get() );
790 FGTileEntry::disconnect_ssg_nodes()
792 SG_LOG( SG_TERRAIN, SG_DEBUG, "disconnecting ssg nodes" );
795 SG_LOG( SG_TERRAIN, SG_DEBUG, "removing a not-fully loaded tile!" );
797 SG_LOG( SG_TERRAIN, SG_DEBUG, "removing a fully loaded tile! terra_transform = " << terra_transform.get() );
800 // Unregister that one at the scenery manager
801 globals->get_scenery()->unregister_placement_transform(terra_transform.get());
803 // find the terrain branch parent
804 int pcount = terra_transform->getNumParents();
806 // find the first parent (should only be one)
807 osg::Group *parent = terra_transform->getParent( 0 ) ;
809 // disconnect the tile (we previously ref()'d it so it
810 // won't get freed now)
811 parent->removeChild( terra_transform.get() );
813 SG_LOG( SG_TERRAIN, SG_ALERT,
814 "parent pointer is NULL! Dying" );
818 SG_LOG( SG_TERRAIN, SG_ALERT,
819 "Parent count is zero for an ssg tile! Dying" );
823 // find the ground lighting branch
824 if ( gnd_lights_transform.get() ) {
825 // Unregister that one at the scenery manager
826 globals->get_scenery()->unregister_placement_transform(gnd_lights_transform.get());
827 pcount = gnd_lights_transform->getNumParents();
829 // find the first parent (should only be one)
830 osg::Group *parent = gnd_lights_transform->getParent( 0 ) ;
832 // disconnect the light branch (we previously ref()'d
833 // it so it won't get freed now)
834 parent->removeChild( gnd_lights_transform.get() );
836 SG_LOG( SG_TERRAIN, SG_ALERT,
837 "parent pointer is NULL! Dying" );
841 SG_LOG( SG_TERRAIN, SG_ALERT,
842 "Parent count is zero for an ssg light tile! Dying" );
847 // find the vasi lighting branch
848 if ( vasi_lights_transform.get() ) {
849 // Unregister that one at the scenery manager
850 globals->get_scenery()->unregister_placement_transform(vasi_lights_transform.get());
851 pcount = vasi_lights_transform->getNumParents();
853 // find the first parent (should only be one)
854 osg::Group *parent = vasi_lights_transform->getParent( 0 ) ;
856 // disconnect the light branch (we previously ref()'d
857 // it so it won't get freed now)
858 parent->removeChild( vasi_lights_transform.get() );
860 SG_LOG( SG_TERRAIN, SG_ALERT,
861 "parent pointer is NULL! Dying" );
865 SG_LOG( SG_TERRAIN, SG_ALERT,
866 "Parent count is zero for an ssg light tile! Dying" );
871 // find the runway lighting branch
872 if ( rwy_lights_transform.get() ) {
873 // Unregister that one at the scenery manager
874 globals->get_scenery()->unregister_placement_transform(rwy_lights_transform.get());
875 pcount = rwy_lights_transform->getNumParents();
877 // find the first parent (should only be one)
878 osg::Group *parent = rwy_lights_transform->getParent( 0 ) ;
880 // disconnect the light branch (we previously ref()'d
881 // it so it won't get freed now)
882 parent->removeChild( rwy_lights_transform.get() );
884 SG_LOG( SG_TERRAIN, SG_ALERT,
885 "parent pointer is NULL! Dying" );
889 SG_LOG( SG_TERRAIN, SG_ALERT,
890 "Parent count is zero for an ssg light tile! Dying" );
895 // find the taxi lighting branch
896 if ( taxi_lights_transform.get() ) {
897 // Unregister that one at the scenery manager
898 globals->get_scenery()->unregister_placement_transform(taxi_lights_transform.get());
899 pcount = taxi_lights_transform->getNumParents();
901 // find the first parent (should only be one)
902 osg::Group *parent = taxi_lights_transform->getParent( 0 ) ;
904 // disconnect the light branch (we previously ref()'d
905 // it so it won't get freed now)
906 parent->removeChild( taxi_lights_transform.get() );
908 SG_LOG( SG_TERRAIN, SG_ALERT,
909 "parent pointer is NULL! Dying" );
913 SG_LOG( SG_TERRAIN, SG_ALERT,
914 "Parent count is zero for an ssg light tile! Dying" );