Hello,
I'd like to modify the texture of objects according to a property (in their own property tree like their altitude or their speed or whatever)
I tried to adapt M1 abrams bombable tank code but I don't want the objects to be in a scenario as I want to create them programmatically (many).
My problem is in fact that the nasal of the objects doesn't execute - cmdarg().getPath() doesn't give anything.
Thanks for your help.
Franck
First I create a "trigger" object placed in the scenery stg file like :
OBJECT_STATIC Models/trigger.xml -157.943 21.326 5.8
(it is a simple square that sits on the ground)
By clicking on it I create a few objects dymamically and I want to have their texture modified according to a parameter value in their own property tree
----------------------------------------
trigger.xml looks like :
<?xml version="1.0" encoding="iso-8859-1"?>
<PropertyList>
<path>square.ac</path>
<animation>
<type>pick</type>
<object-name>trigger</object-name>
<visible>true</visible>
<action>
<button>0</button>
<repeatable>false</repeatable>
<binding>
<command>property-assign</command>
<property>sim/model/start</property>
<value>1</value>
</binding>
</action>
</animation>
<nasal>
<load><![CDATA[
a loop waiting for the click : ("sim/model/start" == 1)
then here are a few places where to create the objects
places = {
{ -157.943, 21.3259, 5.67358 }
{ -157.943, 21.3259, 5.63981 }
{ -157.943, 21.3259, 5.61555 }
{ -157.943, 21.3261, 5.67633 }
{ -157.943, 21.3261, 5.67569 }
};
# Creation of 5 new objects using lng lat and alt in the places table
# These objects appear in the "ai/models" branch of the property tree
ai/model/ship[i]/texture-path=...
ai/model/ship[i]/position/... etc
# as well as the "models" branch (path = AI/Aircraft/Square/Square.xml
elevation-ft-prop = ...)
...
Here I make their altitude vary, and I want to modify their texture along with this property.
(it would be nice to write a text too - like the altitude in ft on top of them)
These objects are very basic squares coded as below
]]></load>
</nasal>
</PropertyList>
----------------------------------------
<?xml version="1.0" encoding="iso-8859-1"?>
<PropertyList >
<path>square.ac</path>
<animation>
<type>material</type>
<object-name>Square</object-name>
<texture-prop>texture-path</texture-prop>
</animation>
<nasal>
<load><![CDATA[
var update_my_color = func (theAlt) {
var objNodeName = cmdarg().getPath();
var node = props.globals.getNode (objNodeName);
if (theAlt > 10)
node.getNode("texture-path", 1).setValue("red.png");
else
node.getNode("texture-path", 1).setValue("blue.png");
}
# every second I modify the color of this object accordingly with its current altitude
settimer (func { update_my_color (objNodeName. getValue (altitude) }, 1);
]]></load>
</nasal>
</PropertyList>
----------------------------------------