From: mfranz Date: Wed, 19 Nov 2008 15:59:54 +0000 (+0000) Subject: add "add-model" command, which adds model properties to the first X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=12cf1c41add24b5f22f8e5199002dbb49817d0f5;p=flightgear.git add "add-model" command, which adds model properties to the first free /models/model[*] slot and lets the model manager load the model. The target address is returned under "property". Simple use in Nasal: fgcommand("add-model", props.Node.new({ "path": "Models/Fauna/cow.ac", "latitude-deg": 16.234, "longitude-deg": 48.321, "elevation-ft": 300, }); An "elevation-m" property can alternatively be used and overrides the "elevation-ft" property. Each of the properties "latitude-deg", "longitude-deg", "elevation-ft", "heading-deg", "pitch-deg", and "roll-deg" can alternatively be used with "-prop" suffix. Their values must then be property path strings pointing to a node that can be changed at runtime to move the model. --- diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 9b0fd0f40..cf5efb8a5 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -1180,6 +1180,33 @@ do_gui_redraw (const SGPropertyNode * arg) } +/** + * Adds model to the scenery. The path to the added branch (/models/model[*]) + * is returned in property "property". + */ +static bool +do_add_model (const SGPropertyNode * arg) +{ + SGPropertyNode * model = fgGetNode("models", true); + for (int i = 0;; i++) { + if (i < 0) + return false; + if (!model->getChild("model", i, false)) { + model = model->getChild("model", i, true); + break; + } + } + copyProperties(arg, model); + if (model->hasValue("elevation-m")) + model->setDoubleValue("elevation-ft", model->getDoubleValue("elevation-m") + * SG_METER_TO_FEET); + model->getNode("load", true); + model->removeChildren("load"); + const_cast(arg)->setStringValue("property", model->getPath()); + return true; +} + + /** * Set mouse cursor coordinates and cursor shape. */ @@ -1520,6 +1547,7 @@ static struct { { "dialog-update", do_dialog_update }, { "dialog-apply", do_dialog_apply }, { "gui-redraw", do_gui_redraw }, + { "add-model", do_add_model }, { "set-cursor", do_set_cursor }, { "play-audio-sample", do_play_audio_sample }, { "presets-commit", do_presets_commit },