Board index FlightGear Development Aircraft

Duration of an animation

Questions and discussion about creating aircraft. Flight dynamics, 3d models, cockpits, systems, animation, textures.

Duration of an animation

Postby S-KIMO » Thu Mar 16, 2023 5:04 pm

Hi all
One thing I'd like someone to explain to me: how do you code the duration of an animation?
Thank you for your help.
S-KIMO
 
Posts: 83
Joined: Mon Dec 07, 2020 3:01 pm

Re: Duration of an animation

Postby wlbragg » Thu Mar 16, 2023 5:43 pm

There are more ways than one. In the c172p we use a filter on the primer to slow down the animation.

Code: Select all
    <!-- Primer -->
    <animation>
        <type>pick</type>
        <object-name>PrimerLever</object-name>
        <visible>true</visible>
        <action>
            <button>0</button>
            <repeatable>false</repeatable>
            <binding>
                <command>nasal</command>
                <script>c172p.pumpPrimer();</script>
            </binding>
            <binding>
                <command>nasal</command>
                <script>c172p.click("primer-in", 1.2)</script>
            </binding>
            <binding>
                <command>nasal</command>
                <script>c172p.click("primer-out", 1.2)</script>
            </binding>
        </action>
        <hovered>
            <binding>
                <command>set-tooltip</command>
                <tooltip-id>primer</tooltip-id>
                <label>Engine primer (%1d)</label>
                <property>controls/engines/engine/primer</property>
            </binding>
        </hovered>
    </animation>
    <animation>
        <type>translate</type>
        <object-name>PrimerLever</object-name>
        <property alias="/params/controls/primer-lever-animation"/>
        <factor>0.04</factor>
        <axis>
            <x>1.0</x>
            <y>0.0</y>
            <z>0.0</z>
        </axis>
    </animation>


Code: Select all
# Toggles the state of the primer
var pumpPrimer = func {
    var push = getprop("/controls/engines/engine/primer-lever") or 0;

    if (push) {
        var pump = getprop("/controls/engines/engine/primer") or 0;
        setprop("/controls/engines/engine/primer", pump + 1);
        setprop("/controls/engines/engine/primer-lever", 0);
    }
    else {
        setprop("/controls/engines/engine/primer-lever", 1);
    }
};


Code: Select all
 <filter>
        <name>Controls Primer Lever</name>
        <type>noise-spike</type>
        <max-rate-of-change>1.1</max-rate-of-change>
        <enable>
            <condition>
                <not>
                    <property>/sim/freeze/replay-state</property>
                </not>
            </condition>
        </enable>
        <input>
            <property>/controls/engines/engine/primer-lever</property>
        </input>
        <output>
            <property>/sim/model/c172p/cockpit/primer-lever-animation</property>
        </output>
    </filter>


There is built in functions for door like animations.

Code: Select all
# doors ============================================================
var leftDoor = aircraft.door.new( "/sim/model/door-positions/leftDoor", 2, 0 );
var rightDoor = aircraft.door.new( "/sim/model/door-positions/rightDoor", 2, 0 );
var leftWindow = aircraft.door.new( "/sim/model/door-positions/leftWindow", 2, 0 );
var rightWindow = aircraft.door.new( "/sim/model/door-positions/rightWindow", 2, 0 );
var baggageDoor = aircraft.door.new( "/sim/model/door-positions/baggageDoor", 2, 0 );
var oilDoor = aircraft.door.new( "/sim/model/door-positions/oilDoor", 1, 0 );
var gloveboxDoor = aircraft.door.new( "/sim/model/door-positions/gloveboxDoor", 1, 0 );


You can use a nasal loop.

I'm sure there are others I'm not thinking of at the moment.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7587
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Duration of an animation

Postby erik » Fri Mar 17, 2023 8:42 am

JSBSim also has the kinematic flight control component:
https://jsbsim.sourceforge.net/JSBSim/c ... nemat.html

The following code moves the flaps to five positions in two different time steps (3 seconds for pos 1 to 2 and pos 2 to 3, 4 seconds for pos 3 to 4 and pos 4 to 5).
Code: Select all
  <channel name="Flaps">
   <kinematic name="fcs/flaps-control">
     <input>fcs/flap-cmd-norm</input>
     <traverse>
       <setting>
         <position>0</position>
         <time>0</time>
       </setting>
       <setting>
         <position>8</position>
         <time>3</time>
       </setting>
       <setting>
         <position>15</position>
         <time>3</time>
       </setting>
       <setting>
         <position>25</position>
         <time>4</time>
       </setting>
       <setting>
         <position>42</position>
         <time>4</time>
       </setting>
     </traverse>
     <output>fcs/flap-pos-deg</output>
   </kinematic>


Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2244
Joined: Thu Nov 01, 2007 2:41 pm

Re: Duration of an animation

Postby S-KIMO » Fri Mar 17, 2023 10:49 am

Hello and thank you!
I use Yasim for my AN225 and I don't understand anything about the NASAL! I'll try empiricism!
And I'll try to make a JSBSim version...
S-KIMO
 
Posts: 83
Joined: Mon Dec 07, 2020 3:01 pm

Re: Duration of an animation

Postby erik » Fri Mar 17, 2023 11:20 am

Beware that creating a JSBSim is a whole lot more difficult than creating a YASim model though.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2244
Joined: Thu Nov 01, 2007 2:41 pm

Re: Duration of an animation

Postby Gijs » Fri Mar 17, 2023 7:14 pm

What kind of animation are you aiming for? It really depends on the application which technique is most suited.
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9544
Joined: Tue Jul 03, 2007 3:55 pm
Location: Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: Duration of an animation

Postby Octal450 » Sat Mar 18, 2023 4:38 am

A lag filter will create a FAR more realistic movement kinematics than a kinematic/max rate of change filter/etc.
I typically use a c1 or 10-20 depending on how fast you want it to go.

Kind Regards,
Josh
Skillset: JSBsim Flight Dynamics, Systems, Canvas, Autoflight/Control, Instrumentation, Animations
Aircraft: A320-family, MD-11, MD-80, Contribs in a few others

Octal450's GitHub|Launcher Catalog
|Airbus Dev Discord|Octal450 Hangar Dev Discord
User avatar
Octal450
 
Posts: 5583
Joined: Tue Oct 06, 2015 1:51 pm
Location: Huntsville, AL
Callsign: WTF411
Version: next
OS: Windows 11

Re: Duration of an animation

Postby MariuszXC » Sat Mar 18, 2023 11:39 am

The isue I have with lag filters used like this:
Code: Select all
      <lag_filter name="/model/canopy-norm">
         <input>/model/canopy-input</input>
         <c1>4.0</c1>
      </lag_filter>

is that the property /model/canopy-norm is being continuously updated at model/channel clock frequency.
This is silly CPU-wise.
One can argue that it is just a single floating point value, but there is no logical reason it should be touched at all, once the canopy reached its end stops.
Besides, once one toggles canopy-input 0->1->0 the resulting canopy-norm approaches to zero in smaller and smaller steps, but I never had patience to observe if it ever actually reaches zero. Usually I loose interest looking around values 1.?????e-250 or so..
I wonder what the animation layer has to say to such small changes. Does it update/recalculate model position on every change of property value?
INOP
MariuszXC
 
Posts: 1061
Joined: Tue May 18, 2021 5:38 pm
Location: Europe
Callsign: SP-MRM
Version: 2020.4
OS: Ubuntu 16.04

Re: Duration of an animation

Postby Octal450 » Sun Mar 19, 2023 3:16 am

Any value in JSBsim is updated like that.
Also, I have noticed zero slowdown by doing this. I'm pretty sure things to animate in an async way like that anyways. Every frame it uses the current value - but anyone who actually knows please correct me because it's not my area.

Kind Regards,
Josh
Skillset: JSBsim Flight Dynamics, Systems, Canvas, Autoflight/Control, Instrumentation, Animations
Aircraft: A320-family, MD-11, MD-80, Contribs in a few others

Octal450's GitHub|Launcher Catalog
|Airbus Dev Discord|Octal450 Hangar Dev Discord
User avatar
Octal450
 
Posts: 5583
Joined: Tue Oct 06, 2015 1:51 pm
Location: Huntsville, AL
Callsign: WTF411
Version: next
OS: Windows 11

Re: Duration of an animation

Postby S-KIMO » Sun Mar 19, 2023 6:49 pm

@ Erik
I saw with the aligned landing gear of the French Vulture (idem B52)
Last edited by S-KIMO on Sun Mar 19, 2023 6:52 pm, edited 1 time in total.
S-KIMO
 
Posts: 83
Joined: Mon Dec 07, 2020 3:01 pm

Re: Duration of an animation

Postby S-KIMO » Sun Mar 19, 2023 6:51 pm

@ Gjis

To open and close the nose door and unfold the access ramp as well as open and close the left door for the crew and its staircase
S-KIMO
 
Posts: 83
Joined: Mon Dec 07, 2020 3:01 pm

Re: Duration of an animation

Postby wlbragg » Sun Mar 19, 2023 7:08 pm

To open and close the nose door and unfold the access ramp as well as open and close the left door for the crew and its staircase


Most of the simple, timed animations in the c172p use the following. You can see in the first example I gave what all uses this method.
Unfortunately the example code I am providing is a bit more complex than you might want as it includes code for MP and also to limit opening the oil door to when you are stationary on the ground, engine off.

Aircraft\c172p\Nasal\door.nas
Code: Select all
var oilDoor = aircraft.door.new( "/sim/model/door-positions/oilDoor", 1, 0 );


Aircraft\c172p\c172p-main.xml
Code: Select all
<multiplay>
            <chat_display>1</chat_display>
            <generic>

~~~~~~
                <float n="18" alias="/sim/model/door-positions/oilDoor/position-norm"/>

~~~~~~~
            </generic>
        </multiplay>


Aircraft\c172p\c172-common.xml
Code: Select all
    <!-- Oil door pick -->
    <animation>
        <type>pick</type>
        <object-name>oildoor</object-name>
        <visible>true</visible>
        <action>
            <button>0</button>
            <repeatable>false</repeatable>
            <binding>
                <condition>
                    <and>
                        <not>
                            <property>/engines/active-engine/running</property>
                        </not>
                        <or>
                            <property>/fdm/jsbsim/gear/unit[1]/WOW</property>
                            <property>/fdm/jsbsim/gear/unit[19]/WOW</property>
                            <property>/fdm/jsbsim/gear/unit[23]/WOW</property>
                            <property>/fdm/jsbsim/hydro/active-norm</property>
                        </or>
                        <or>
                            <not>
                                <property>/sim/current-view/internal</property>
                            </not>
                            <property>/nasal/tutorial/loaded</property>
                        </or>
                    </and>
                </condition>
                <command>nasal</command>
                <script>
                    var engine = getprop("controls/engines/active-engine");
                    if (!engine)
                        fgcommand("dialog-close", props.Node.new({"dialog-name": "c172p-oil-dialog-160"}));
                    else
                        fgcommand("dialog-close", props.Node.new({"dialog-name": "c172p-oil-dialog-180"}));
                    setprop("sim/model/show-dip-stick", 0);
                    c172p.oilDoor.toggle();
                </script>
            </binding>
            <binding>
                <condition>
                    <and>
                        <property>/engines/active-engine/running</property>
                        <property>/engines/active-engine/oil_consumption_allowed</property>
                    </and>
                </condition>
                <command>nasal</command>
                <script>
                    gui.popupTip("You can't check the oil level with the engine running!", 2);
                </script>
            </binding>
            <binding>
                <condition>
                    <and>
                        <not>
                            <or>
                                <property>/fdm/jsbsim/gear/unit[1]/WOW</property>
                                <property>/fdm/jsbsim/gear/unit[19]/WOW</property>
                                <property>/fdm/jsbsim/gear/unit[23]/WOW</property>
                                <property>/fdm/jsbsim/hydro/active-norm</property>
                            </or>
                        </not>
                        <property>/engines/active-engine/oil_consumption_allowed</property>
                    </and>
                </condition>
                <command>nasal</command>
                <script>
                    gui.popupTip("You can't check the oil level while in the air!", 2);
                </script>
            </binding>
        </action>
        <hovered>
            <binding>
                <condition>
                    <and>
                        <not>
                            <property>/engines/active-engine/running</property>
                        </not>
                        <or>
                            <property>/fdm/jsbsim/gear/unit[1]/WOW</property>
                            <property>/fdm/jsbsim/gear/unit[19]/WOW</property>
                            <property>/fdm/jsbsim/gear/unit[23]/WOW</property>
                            <property>/fdm/jsbsim/hydro/active-norm</property>
                        </or>
                        <or>
                            <not>
                                <property>/sim/current-view/internal</property>
                            </not>
                            <property>/nasal/tutorial/loaded</property>
                        </or>
                    </and>
                </condition>
                <command>set-tooltip</command>
                <tooltip-id>oil-door</tooltip-id>
                <label>Oil Door</label>
            </binding>
        </hovered>
    </animation>


Aircraft\c172p\c172-common.xml
Code: Select all
    <!-- Oil door animation -->
    <animation>
        <type>rotate</type>
        <object-name>oildoor</object-name>
        <property alias="../../params/doors/oil/property"/>
        <interpolation>
            <entry>
                <ind>0.0</ind>
                <dep>0.0</dep>
            </entry>
            <entry>
                <ind>0.5</ind>
                <dep>-45.0</dep>
            </entry>
            <entry>
                <ind>1</ind>
                <dep>-90.0</dep>
            </entry>
        </interpolation>
        <axis>
            <x1-m>-0.80485</x1-m>
            <y1-m> 0.23079</y1-m>
            <z1-m> 0.16388</z1-m>
            <x2-m>-0.88058</x2-m>
            <y2-m> 0.2303</y2-m>
            <z2-m> 0.16328</z2-m>
        </axis>
    </animation>
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7587
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Duration of an animation

Postby MariuszXC » Sun Mar 19, 2023 9:44 pm

Octal450 wrote in Sun Mar 19, 2023 3:16 am:Any value in JSBsim is updated like that...


... but not every value is used to drive an animation.

Josh, let me start with a disclaimer. I am not trying to say what you do is wrong or attack you in any way. I am just curious what the animation layer does when a property used to drive the animation is updated (almost?) continuously with very small deltas. Are new coordinates for affected mesh nodes being updated every frame in this case, even if the actual change in position would still be contained within the same pixel (so not visible to the user)?
INOP
MariuszXC
 
Posts: 1061
Joined: Tue May 18, 2021 5:38 pm
Location: Europe
Callsign: SP-MRM
Version: 2020.4
OS: Ubuntu 16.04

Re: Duration of an animation

Postby Octal450 » Tue Mar 21, 2023 4:38 am

Hi Mariusz,
Do not worry - I did not take it as such :mrgreen:

I believe that the animation is re-rendered with whatever value is present when it do it, regardless of if the value changed or not. Maybe I am wrong, this is just my knowledge, and my knowledge of 3D stuff is limited :)

But even so not, it does not seem to cause any slowdown that I have noticed.

Kind Regards,
Josh
Skillset: JSBsim Flight Dynamics, Systems, Canvas, Autoflight/Control, Instrumentation, Animations
Aircraft: A320-family, MD-11, MD-80, Contribs in a few others

Octal450's GitHub|Launcher Catalog
|Airbus Dev Discord|Octal450 Hangar Dev Discord
User avatar
Octal450
 
Posts: 5583
Joined: Tue Oct 06, 2015 1:51 pm
Location: Huntsville, AL
Callsign: WTF411
Version: next
OS: Windows 11

Re: Duration of an animation

Postby erik » Tue Mar 21, 2023 3:09 pm

Octal450 wrote in Tue Mar 21, 2023 4:38 am:I believe that the animation is re-rendered with whatever value is present when it do it, regardless of if the value changed or not.

That's correct: everything you see gets re-rendered every frame.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2244
Joined: Thu Nov 01, 2007 2:41 pm

Next

Return to Aircraft

Who is online

Users browsing this forum: No registered users and 12 guests