Board index FlightGear Development Scenery

Dynamic objects problem  Topic is solved

Questions and discussion about enhancing and populating the FlightGear world.

Dynamic objects problem

Postby SharjeelHKh » Mon Apr 04, 2011 8:15 am

Hi all;

I m trying to add dynamic objects using the method mentioned in fgdata/data/Docs/README.scenery, Inorder to later on control them using property system at runtime. I followed the following steps:

=====================================================================================================================================
4.2 dynamic objects
--------------------
Any of the model properties can be made changeable at runtime by appending
"-prop" and using a property path name instead of the fixed value:

<local>
<pony>
<longitude-deg>-115.8352869/<longitude-deg>
<latitude-deg>37.24302849</latitude-deg>
<elevation-ft>4534.691321</elevation-ft>
<heading-deg>0</heading-deg>
</pony>
</local>

<models>
<model n="1">
<name>pony</name>
<path>Local/pony.ac</path>
<longitude-deg-prop>/local/pony/longitude-deg</longitude-deg-prop>
<latitude-deg-prop>/local/pony/latitude-deg</latitude-deg-prop>
<elevation-ft-prop>/local/pony/elevation-ft</elevation-ft-prop>
<heading-deg-prop>/local/pony/heading-deg</heading-deg-prop>
<pitch-deg>1.234</pitch-deg> <!-- static, just for fun -->
</model>
</models>

Then one can move the pony around by changing the values in /local/pony/ in
the property system. One can, of course, use other animals, too.
=====================================================================================================================================

But of no use...
I also read somewhere that "Dynamic objects are OFF by default, you will have to set the following property to true to see anything" --prop:/sim/rendering/dynamic-objects=true
I did this also but still cant able to see the object at that location. Location I given is same as if I add any object in .stg file, it did appear there, but dynamic object at the same location doesn't!

Any clue.
SharjeelHKh
 
Posts: 35
Joined: Mon Oct 11, 2010 5:24 am

Re: Dynamic objects problem

Postby RenanMsV » Mon Mar 26, 2018 12:10 am

Opening this topic again, I also need help to put a model in the scenery and then move it at runtime using nasal.

Code: Select all
var lat = player.getNode("/position/latitude-deg").getValue();
var lon = player.getNode("/position/longitude-deg").getValue();
var alt = player.getNode("/position/altitude-ft").getValue() * FT2M;
var coord = geo.Coord.new();
coord.set_latlon(lat,lon,alt);
var modl = geo.put_model(LIGHT_MODEL_PATH, coord);
modl.initNode("elevation-ft-prop", ("/models/model[" ~ size(MP_PLAYERS) ~ "]/elevation-ft"), "STRING");
modl.initNode("latitude-deg-prop", ("/models/model[" ~ size(MP_PLAYERS) ~ "]/latitude-deg"), "STRING");
modl.initNode("longitude-deg-prop", ("/models/model[" ~ size(MP_PLAYERS) ~ "]/longitude-deg"), "STRING");


nothing happens when i change the "models/model[0]/elevation-ft" property.
www.flightgearbrasil.com.br
www.fgbrazukas.wixsite.com/fgbrazukas
RenanMsV
 
Posts: 134
Joined: Thu Oct 27, 2016 3:02 am
Callsign: BR-RVD

Re: Dynamic objects problem  

Postby wlbragg » Mon Mar 26, 2018 2:18 am

If your good at using examples then I suggest you look at some of the files at https://github.com/wlbragg/AirCrane/commits/master

At the top of this file it injects many cargo objects into the scene and later on manipulates many of them.
https://github.com/wlbragg/AirCrane/blob/master/AirCrane/Nasal/cargooperations.nas

This dialog also has good examples of how you can move the objects around. Between the two it should have most everything you need to figure it out.
https://github.com/wlbragg/AirCrane/blob/master/AirCrane/Dialogs/aicargo-dialog.xml

There is this one too, it has some mouse event code used to move objects around. Look at the lines starting at around 471
https://github.com/wlbragg/AirCrane/blob/master/AirCrane/Nasal/aircrane.nas

The Shuttle also has several objects injected into the scene and animated in various way, In fact that is where I got most of the ideas for the code I use in the Aircrane.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7586
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Dynamic objects problem

Postby RenanMsV » Tue Mar 27, 2018 1:11 am

Code: Select all
#################### inject models into the scene (helper) ####################
var place_model = func(position, path, lat, lon, alt, heading = 0, pitch = 0, roll = 0) {
   var m = props.globals.getNode("models", 1);
   for (var i = 0; 1; i += 1)
      if (m.getChild("model", i, 0) == nil)
         break;
   var model = m.getChild("model", i, 1);

   setprop("/models/etf/etf["~position~"]/latitude-deg", lat);
   setprop("/models/etf/etf["~position~"]/longitude-deg", lon);
   setprop("/models/etf/etf["~position~"]/elevation-ft", alt);
   setprop("/models/etf/etf["~position~"]/heading-deg", heading);
   setprop("/models/etf/etf["~position~"]/pitch-deg", pitch);
   setprop("/models/etf/etf["~position~"]/roll-deg", roll);

   var etlmodel = props.globals.getNode("/models/etf/etf["~position~"]", 1);
   var latN = etlmodel.getNode("latitude-deg",1);
   var lonN = etlmodel.getNode("longitude-deg",1);
   var altN = etlmodel.getNode("elevation-ft",1);
   var headN = etlmodel.getNode("heading-deg",1);
   var pitchN = etlmodel.getNode("pitch-deg",1);
   var rollN = etlmodel.getNode("roll-deg",1);

   model.getNode("path", 1).setValue(path);
   model.getNode("latitude-deg-prop", 1).setValue(latN.getPath());
   model.getNode("longitude-deg-prop", 1).setValue(lonN.getPath());
   model.getNode("elevation-ft-prop", 1).setValue(altN.getPath());
   model.getNode("heading-deg-prop", 1).setValue(headN.getPath());
   model.getNode("pitch-deg-prop", 1).setValue(pitchN.getPath());
   model.getNode("roll-deg-prop", 1).setValue(rollN.getPath());
   model.getNode("load", 1).remove();

   return { "model" : model, "etlmodel" : etlmodel };
};


thats working! :D
So I can move the object by changing the returned hash.etlmodel properties.

Code: Select all
TEMP_MODEL = place_model(0,"model.xml",30.055353,32.9585,2000);
TEMP_MODEL.model.etlmodel.getNode("latitude-deg").setDoubleValue(25.5958); # move the object at runtime :D

Thank you SO MUCH! topic seems to be solved :D
www.flightgearbrasil.com.br
www.fgbrazukas.wixsite.com/fgbrazukas
RenanMsV
 
Posts: 134
Joined: Thu Oct 27, 2016 3:02 am
Callsign: BR-RVD


Return to Scenery

Who is online

Users browsing this forum: No registered users and 7 guests