New Ardor3D Animation Features - Part 3

Parts 1 and 2 on the new Ardor3D Animation Features covered nearly everything you need to know, so we'll wrap it up by discussing a few loose ends.

First, let's talk about weights.  When you put together states and layers, you'll likely use a weight based blending to bring together multiple sources.  For state transitions, the weighting is mostly out of your hands as it is time-based, but for other types of weighting (such as the blending between two layers or a lerp node in a state's blend tree) you'll often find yourself wanting to directly modify it on the fly based on the current state of your game/application.  Again, you run into a problem here...  How to reach into an animation system and access that BlendTreeSource object or LayerBlender when it might be created and maintained outside of your control (e.g. such as by our JSON based "scripting" system.)

To address this, we've taken the actual weight value away from these types of objects and moved it to a map in the AnimationManager.  The blend object itself instead maintains a key used to pull the weight from the manager.  In this way, you merely have to know the key you are altering and have a link to the manager it lies under, letting your aritist/animator/tool tweak things to their heart's content.


Shifting gears, so far our animations have been all about moving skeleton joints around, but the animation system was actually built to handle any generic sample-based data set.  To take advantage of that, a new type of channel called a TriggerChannel was added to give you a String-based, trigger-callback system that can be plugged into existing animations or added as standalone clips.

Here's how a trigger channel works.  The channel is made up of multiple (nullable) String "samples" that change over time.  For example, it might have no sample at time index 0.  Then at 2 it might have a sample called "left_step" and at 4 a sample called "right_step" and at 5, null again.  As the animation this channel belongs to plays, the current sample String is collected.  The applier logic has access to this current string and can then act on it.

Our default applier logic acts on the string by executing callbacks associated with the given String.  The callback is only called on unique samples, so while in the current sample, it will only be called once.  Your callback logic can then be whatever you like... play a sound, a particle effect, trigger a different animation, etc.  In the case of the above left_step, right_step, it might be programmed to play footstep sounds on the appropriate time sequences.  If this was a channel in our walk state, then walking would also trigger the footstep sounds.

TriggerChannels are created/setup only in Java code currently, but they will soon be added to the JSON-based input system as well.

Here's an excerpt from AnimationDemoExample showing how you might put this together. The method shown makes a channel that has a "punch_fire" sample set at the mid point of the given source clip. The trigger callback adds (in the update queue) particles to the scene:

private void addFireballTrigger(final SimpleAnimationApplier applier, final 
AnimationClip punchClip) {
    final float max = punchClip.getMaxTimeIndex();
    final TriggerChannel triggerChannel = new TriggerChannel("punch_fire", new 
float[] { 0, max / 2, max / 2 + 0.25f }, new String[] { null, "fist_fire", null });
    punchClip.addChannel(triggerChannel);
    applier.addTriggerCallback("fist_fire", new TriggerCallback() {
        public void doTrigger() {
            GameTaskQueueManager.getManager(_canvas.getCanvasRenderer()
.getRenderContext()).update(
                new Callable() {
                    @Override
                    public Void call() throws Exception {
                        addParticles();
                        return null;
                    }
                });
            }
        });
    }

Here's a video of Ardor3D's AnimationDemoExample in action:



Finally, let's cap this series of posts off with a webstart of the AnimationDemoExample in Ardor3D. Note that I left it loading from the original Collada files, so it takes a few seconds to start. Also, it's been a while since I've packaged things for webstart, so bear with me if it doesn't work for some reason.

You'll need Java 6.0. (Mac users may need to save the jnlp to disk, then right click and open with Java Web Start.) Drag the scene with the left mouse to rotate the camera. WASD to move.

12 comments:

Paul said...

This is really smart and robust. Congrats, ArdorLabs! :)

Michael Nischt said...

Webstart doesn't work for me on Ubuntu Linux with java version "1.6.0_0"
OpenJDK Runtime Environment (IcedTea6 1.6.1) (6b16-1.6.1-3ubuntu3)
OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)

netx: Unexpected net.sourceforge.jnlp.ParseException: Only one application descriptor element allowed per JNLPFile. at net.sourceforge.jnlp.Parser.getLauncher(Parser.java:565)


using SUN's java resolution chooser dialog shows but nothing happens after clicking 'ok'.

java version "1.6.0_18"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) 64-Bit Server VM (build 16.0-b13, mixed mode)

Konethan said...

Nice bit on the Webstart. It's one thing to watch but it's completely different to do! Congrats, ArdorLabs!

Josh Slack said...

@Michael: I just tried using my old P4 machine running Ubuntu 8.04 and sun's 1.6.0_01 without issue.

I'm not sure the issue with openjdk, but I just today modified the jnlp to not have two descriptor types, so perhaps that will help.

Your issue with sun's jvm is likely that it could not create an accelerated pixel format... See the javaws logs. I recall having to install nvidia's display driver on this box to get things working. Sorry I can't be of more use in debugging!

TheAlchemist said...

Wow, very impressive! Works out of the box on this old Mac with Snow Leopard!

fibric said...

looks really great but if i replay this video again and again i start thinking about how it would looks like if the animation would be processed by an physics engine instead of hard coded animation scene

Alex said...
This comment has been removed by the author.
Alex said...

please provide us netbeans users a better way to gain ur source code better than maven and to allow us a easy startup with it... even with the lack of documentation i can deal but i need a better way to get ardor to work on netbeans or than having to download eclipse..... please build distrutive binaries if u have to but help us with the issues...we need ardor easy quick to access if not i dont see beginneers gearing their butt to deal with building ardor in netbeans with the headache we face....not everyone likes n use eclipse....even if its great,most of us like netbeans ya we oldies but it works...so please help or else am left to either go to c++ or panda3d nd i wana wana make a gmae in java,usig ardor,jme well its a disgrace for real,am sorry for babblig but what am saying is give us a better way,the source,so we can build ardor3d n get it to work on netbeans

Josh Slack said...

@Alex: Thanks for the comment. We don't have as much information about netbeans usage mostly because we (the devs) use eclipse. Not really an intentional slight to netbeans. We also have continuous integration and maven setup so you can pull in the most recent snapshot build and use that (basically your nightly build.) Unfortunately you have to know some maven.

Our new website will have better places for community documentation which should help get that sort of stuff out into everyones hands.

Alex said...

I truely appreciate the quick reply,well yes,i dont know much maven to begin with but i got it setup pretty easily on my ubuntu box,and am pooling the nightly build off the svn repo,so thats good.thou maven tries to build it in offline mode,i tried telling it to build it with the dependencies and it seemed ok,but i am ot sure till it pools all the dependencies it needs,hope am doing it right,ya definately awesome,mayb i will retink my use of eclipse but who knows,first thou,they need some seriouse interface rework...lol.. and thanks for the quick reply,truely appreciate it.
if i get everytin running smoothly i will make a series of tutorials in setting up and using ardor3d for game dev,dts after i gt the hang of it myself,...

Awesome work dudes

Alex said...

i need to get myself a way to turn equations into code...mybrain starts to implode wen i see all those crazy symbols even if i can get what they say

Malachi de Ælfweald said...

Looks great Josh!