I would like to rotate an AI object from Nasal. For this purpose, the xml-file of the model gets the tag
- Code: Select all
<animation>
<type>rotate</type>
<property>orientation/rotation-deg</property>
<factor>1.0</factor>
<axis>
<x>1</x>
<y>0</y>
<z>0</z>
</axis>
</animation>
I then can control the rotation just fine from Nasal by
- Code: Select all
setprop("ai/models/aircraft[0]/orientation/rotation-deg",x);
where x is my rotation angle. Now, when I have multiple instances of the AI object,
- Code: Select all
var modelNode = props.globals.getNode("ai/models", 1);
var aircraftNode = modelNode.getChildren("aircraft");
foreach (var e; aircraftNode) {
var e_rot = e.getNode("orientation/rotation-deg");
e_rot.setValue(x);}
is the more convenient way of doing it. But there is a problem, and after some experimentation I think I know what it is: orientation/rotation-deg as declared in the animation tag is only initialized once the object becomes visible. However, unlike setprop, (node).setValue does not simply create the node if there is nothing previously, but returns an error and crashes the Nasal script. So if the Nasal script happens to run while some instances of the AI models are not (yet) visible, the Nasal script exits.
I'm now looking for a clean solution to this - like declaring an extra property in the AI-scenario or the model xml wrapper file - but it doesn't seem to be straightforward (or I may just be too dumb). I can think of a few dirty workarounds (like using setprop a hundred times to initialize all nodes), but I'd rather avoid that.
Any help appreciated!