123 const std::string model_path{node->getStringValue(
"path",
"Models/Geometry/glider.ac")};
124 if (model_path.empty()) {
125 SG_LOG(SG_AIRCRAFT, SG_WARN,
"add_model called with empty path");
129 const std::string internal_model{node->getStringValue(
"internal-model",
"external")};
137 if (internal_model ==
"marker") {
138 std::string label{node->getStringValue(
"marker/text",
"MARKER")};
139 float r = node->getFloatValue(
"marker/color[0]", 1.0f);
140 float g = node->getFloatValue(
"marker/color[1]", 1.0f);
141 float b = node->getFloatValue(
"marker/color[2]", 1.0f);
142 osg::Vec4f color(r, g, b, 1.0f);
143 float font_size = node->getFloatValue(
"marker/size", 1.0f);
144 float pin_height = node->getFloatValue(
"marker/height", 1000.0f);
145 float tip_height = node->getFloatValue(
"marker/tip-height", 0.0f);
146 object =
fgCreateMarkerNode(osgText::String(label, osgText::String::ENCODING_UTF8), font_size, pin_height, tip_height, color);
148 else if (internal_model ==
"external") {
150 std::string fullPath = simgear::SGModelLib::findDataFile(model_path);
151 if (fullPath.empty()) {
152 SG_LOG(SG_AIRCRAFT, SG_ALERT,
"add_model: unable to find model with name '" << model_path <<
"'");
155 object = SGModelLib::loadDeferredModel(fullPath,
globals->get_props());
156 }
catch (
const sg_throwable& t) {
157 SG_LOG(SG_AIRCRAFT, SG_ALERT,
"Error loading " << model_path <<
":\n "
158 << t.getFormattedMessage() << t.getOrigin());
163 object =
new osg::Node;
164 SG_LOG(SG_AIRCRAFT, SG_WARN,
"Unsupported internal-model type " << internal_model);
167 const std::string modelName{node->getStringValue(
"name", model_path.c_str())};
168 SG_LOG(SG_AIRCRAFT, SG_INFO,
"Adding model " << modelName);
170 SGModelPlacement *model =
new SGModelPlacement;
171 instance->
model = model;
172 instance->
node = node;
174 model->init(
object );
175 double lon = node->getDoubleValue(
"longitude-deg"),
176 lat = node->getDoubleValue(
"latitude-deg"),
177 elevFt = node->getDoubleValue(
"elevation-ft");
179 model->setPosition(SGGeod::fromDegFt(lon, lat, elevFt));
183 SGPropertyNode * child = node->getChild(
"longitude-deg-prop");
187 child = node->getChild(
"latitude-deg-prop");
191 child = node->getChild(
"elevation-ft-prop");
195 child = node->getChild(
"roll-deg-prop");
199 model->setRollDeg(node->getDoubleValue(
"roll-deg"));
201 child = node->getChild(
"pitch-deg-prop");
205 model->setPitchDeg(node->getDoubleValue(
"pitch-deg"));
207 child = node->getChild(
"heading-deg-prop");
211 model->setHeadingDeg(node->getDoubleValue(
"heading-deg"));
213 if (node->hasChild(
"enable-hot")) {
214 osg::Node::NodeMask mask = model->getSceneGraph()->getNodeMask();
215 if (node->getBoolValue(
"enable-hot")) {
216 mask |= SG_NODEMASK_TERRAIN_BIT;
218 mask &= ~SG_NODEMASK_TERRAIN_BIT;
220 model->getSceneGraph()->setNodeMask(mask);
224 globals->get_scenery()->get_scene_graph()->addChild(model->getSceneGraph());
267 SGModelPlacement* model = instance->model;
268 double roll, pitch, heading;
269 roll = pitch = heading = 0.0;
270 SGGeod pos = model->getPosition();
274 if (instance->lon_deg_node != 0)
275 pos.setLongitudeDeg(testNan(instance->lon_deg_node->getDoubleValue()));
276 if (instance->lat_deg_node != 0)
277 pos.setLatitudeDeg(testNan(instance->lat_deg_node->getDoubleValue()));
278 if (instance->elev_ft_node != 0)
279 pos.setElevationFt(testNan(instance->elev_ft_node->getDoubleValue()));
282 if (instance->roll_deg_node != 0)
283 roll = testNan(instance->roll_deg_node->getDoubleValue());
284 if (instance->pitch_deg_node != 0)
285 pitch = testNan(instance->pitch_deg_node->getDoubleValue());
286 if (instance->heading_deg_node != 0)
287 heading = testNan(instance->heading_deg_node->getDoubleValue());
288 } catch (
const sg_range_exception&) {
289 std::string path = instance->
node->getStringValue(
"path",
"unknown");
290 SG_LOG(SG_AIRCRAFT, SG_INFO,
"Instance of model " << path
291 <<
" has invalid values");
295 model->setPosition(pos);
298 model->setRollDeg(roll);
300 model->setPitchDeg(pitch);
302 model->setHeadingDeg(heading);
304 instance->
model->update();