Board index FlightGear Development

Is there a way to test if an ac or xml file exists?

FlightGear is opensource, so you can be the developer. In the need for help on anything? We are here to help you.
Forum rules
Core development is discussed on the official FlightGear-Devel development mailing list.

Bugs can be reported in the bug tracker.

Is there a way to test if an ac or xml file exists?

Postby japreja » Fri Sep 25, 2015 5:32 am

Is there a way to test if an .ac/.xml file exists prior to loading it from an xml file? For example

Code: Select all
<PropertyList>
<!-- If the following path/file exists -->
  <model>
    <path>Aircraft/SomeAircraft/Models/ModelMayOrMayNotExist.ac</path>
    <offsets>
      <x-m> 0.0 </x-m>
      <y-m> 0.0 </y-m>
      <z-m> 0.0 </z-m>
      <heading-deg>0.0</heading-deg>
    </offsets>
  </model>
<!-- Animate it -->
  <animation>
    .....
  </animation>
<!-- else continue -->
  ....
</PropertyList>


Would this need nasal?

Thanks in advance,
Jorge
japreja
 
Posts: 331
Joined: Thu May 07, 2015 11:05 pm
Location: MT, USA
OS: Windows 10 Pro 64bit

Re: Is there a way to test if an ac or xml file exists?

Postby Hooray » Fri Sep 25, 2015 5:37 am

Nasal can check for directories/files, but the XML stuff is processed separately and doesn't support embedded Nasal or conditionally changing XML constructs.

I guess it would be better to share your exact use-case with you, so that we can provide a solution that should work
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: 11354
Joined: Tue Mar 25, 2008 8:40 am

Re: Is there a way to test if an ac or xml file exists?

Postby japreja » Fri Sep 25, 2015 5:51 am

I just want to setup some files as templates without needing to rewrite some of the xml code each time I create a new .ac part, although I do know which .ac files/objects I will need. I am hoping to just take care of the XML file parts without having to revisit them after I make this or that .ac model file and just skip that section without errors.

Don't know if that makes much sense... Sort of a preemptive coding for files that will exist at some point.
japreja
 
Posts: 331
Joined: Thu May 07, 2015 11:05 pm
Location: MT, USA
OS: Windows 10 Pro 64bit

Re: Is there a way to test if an ac or xml file exists?

Postby Hooray » Fri Sep 25, 2015 7:20 am

The evaluation time of the XML/model loader and Nasal are different, so there is no straightforward way to do this. Unless you are willing to make a feature request, i.e. to support property rules and/or embedded Nasal in model.xml files..

As a workaround, you could associate _each_ model with a condition (property), OSG's PagedLOD will usually defer model loading until it is necessary/visible. Thus, you could create a boilerplate XML snippet with a configurable file name, and then parametrize that using the params directive (when including it).

During initialization, your Nasal module would then check if the 3D model exists or not, and if it does, set the "display" property to "true", so that the OSG model loader (switch node) will actually display/load the filesh
Depending on how well the code is integrated, you may however have to run a fgcommand to re-init the model subsystem.

Either way you are in uncharted waters here, and the approach/idea is kinda flawed - but if you are willing to experiment a little, you could probably get this working without touching any code.

In layman's terms, imagine it like this: there are certain parts of your model that are invisible and that can be toggled on/off using properties. You would use this mechanism to dynamically enable/disable loading of models. And you would accomplish that by having a Nasal function that checks for each required model file, and then sets a true/false property for the switch animation.
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: 11354
Joined: Tue Mar 25, 2008 8:40 am


Return to Development

Who is online

Users browsing this forum: No registered users and 1 guest