Board index FlightGear Development Nasal

car with random color

Nasal is the scripting language of FlightGear.

car with random color

Postby pommesschranke » Sun Nov 06, 2016 12:24 pm

for the scenery I'd like to make a parked car that has a different color each time it loads.

do I have to use properties or can I embed nasal into an animation block, similar like this:

Code: Select all
<animation> 
<type>material</type>
  <object-name>body</object-name>
  <diffuse>
   <red>
      <nasal>
              <load>
                   rand();
               </load>
           <nasal>
   </red>
  </diffuse>
</animation>   




I also tried this:

Code: Select all
<animation> 
<type>material</type>
  <object-name>body</object-name>
 
  <diffuse>
   <red>
        <random>
         <min>0.5</min>
         <max>1.0</max>
     </random>
    
   </red>
 
  </diffuse>
 
</animation>     


no success so far.
pommesschranke
 
Posts: 1105
Joined: Sat Apr 27, 2013 7:58 pm
Location: EDLM & LJCE
Callsign: d-laser
IRC name: laserman
Version: git
OS: Linux Lubuntu 18.04

Re: car with random color

Postby Thorsten » Sun Nov 06, 2016 2:30 pm

do I have to use properties or can I embed nasal into an animation block, similar like this:


You have to use properties or expressions. A Nasal function returns a value to Nasal space, that's not accessible by animations. Not sure where the <random> tag is from - I've never seen it before.
Thorsten
 
Posts: 11765
Joined: Mon Nov 02, 2009 8:33 am

Re: car with random color

Postby Hooray » Mon Nov 07, 2016 8:50 pm

Note that you should also be able to use property-driven fgcommands to implement something like that, and that, you can also register Nasal callbacks as dedicated fgcommands - which is basically what the pui2canvas code is doing: it registers itselfs as a new fgcommand, and at that point it can be used by all sorts of dialogs without any of them having to be patched.

Thorsten is right though, in that such a Nasal-based fgcommand will get its operands/arguments in the form of a property tree structure - but that can be processed using props.nas internally.

See addcommand() for details

However, in general, if this is about scenery objects, I would consider using an embedded Nasal block and the cmdarg() API to get a handle to the object specific property tree.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12058
Joined: Tue Mar 25, 2008 8:40 am

Re: car with random color

Postby Johan G » Mon Nov 07, 2016 10:00 pm

As this is about a parked car, I assume it will be for a shared model to use for instance on airport parking lots.

Consider different ways to make it as efficient as possible, as there might be quite many such models loading/loaded (in essence not only those you will easily see, but probably also all of those that are within the detailed LoD distance). Consider also that setting a model specific LoD range will require even more resources when rendering a frame.
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Johan G
Moderator
 
Posts: 6089
Joined: Fri Aug 06, 2010 5:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit


Return to Nasal

Who is online

Users browsing this forum: No registered users and 1 guest