The forum on this site is closed for new comments and posts. Continue the conversation in our Snap AR Discord server.

Blending Animation Layers

  • Hi Tom,

    You can use the AnimationMixer component's startWithCallback function to trigger 2 different animations in sequence.

    Here's an example of a script you can add to your project that will play a single "action" animation followed by a looping "idle" animation. Give it a shot and let me know if you have any specific questions about this approach.

    //@input Component.AnimationMixer animationMixer
    //@input string actionAnimName
    //@input string idleAnimName
    //@input int actionLoopCount = 1

    if(script.animationMixer){
     if(script.actionAnimName){
      script.animationMixer.setWeight(script.actionAnimName, 1);
      script.animationMixer.setWeight(script.idleAnimName, 0);
      script.animationMixer.startWithCallback(script.actionAnimName, 0, script.actionLoopCount, onActionAnimComplete);
     }
    }

    function onActionAnimComplete(){
     if(script.animationMixer){
      if(script.idleAnimName){
          script.animationMixer.setWeight(script.actionAnimName, 0);
          script.animationMixer.setWeight(script.idleAnimName, 1);
          script.animationMixer.start(script.idleAnimName, 0, -1);
      }
     }
    }

    Let me know if you have any specific questions about how to set this up.


    Best,
    Peter

    Comment actions Permalink
  • Hello,

    Thanks Peter for this example! Do you (or anyone) know if it's possible to use startWithCallback and pass it a callback function that takes arguments? I notice that you pass just the function name onActionAnimComplete, without parentheses, but I wonder if there's a way, using anonymous functions, etc. to essentially call onActionAnimComplete and pass it the mixer and layer names each time.

    My use case is that I want to apply this to multiple objects at once, and chain multiple anim layers for each, without stuffing my script full of specific methods for each individual callback that's supposed to happen.

    Honestly I think the best solution is to stop trying to have these all take place in one master script file and just give each animated object a script component so it can handle its own animations. But I'm still curious if what I was trying would have been possible!

    Comment actions Permalink
  • Hey Naomi!

    Here's a version of the script that uses a wrapper function as the callback, which allows you to supply additional parameters to the anim callback:

    //@input Component.AnimationMixer mixer

    var layerName = "BaseLayer"

    script.mixer.startWithCallback("BaseLayer", 0, 1, function(){
    onAnimDoneCallback(layerName, script.mixer);
    });

    function onAnimDoneCallback(layer, mixer){
    print("Done playing layer " + layer + " on " + mixer.getSceneObject().name);
    }

    Let me know if this works for you!

    Best,

    Peter

    Comment actions Permalink
  • Ahhh, a wrapper function that just calls the main function! I see now how I was getting tripped up before and your solution appears to provide the missing piece to the workarounds I was trying.

    However, I have since refactored the code so each animated object is called upon to handle its own animations. I must say it's much cleaner than what I had before, for a number of reasons!

    Thank you so much for helping! Ack I simply love learning new things <3

    Cheers,
    Naomi

    Comment actions Permalink

We're here to help! We just need a little bit of information...

What system are you using?

Have you downloaded the latest version of Lens Studio?

Please download the latest version of Lens Studio. If you still run into this issue, please come back and report it!

Is this issue causing Lens Studio to crash?

What system do you run Lens Studio on?

Version

Graphics

Follow the next steps to help us solve your issue:

  • Copy and paste this text into your TerminalCommand Window
    open ~/Library/Preferences/Snap/Lens\ Studio/ %LOCALAPPDATA%\Snap\Lens Studio Copy Text
  • Press ReturnEnter to run the command. The Lens Studio folder will automatically open
  • Prepare to upload your files: zip the "Log" Folder by right-clicking and choosing "compress."
    Locate the Log.txt file right above it.

    Attach a screenshot of the issue:

Name:

Email:

What is this most relevant to?

Please enter a brief description of your issue:

Thanks for submitting this issue.

Unfortunately, it's likely due to the operating system or hardware you're using – since they don't meet the system requirements for Lens Studio.

Still, we hear you loud and clear, and are logging the issue in case there's ever a workaround we can provide!

Minimum Requirements

Operating System: Windows 10 (64 bit); MacOS 10.11+

Hardware: Minimum of Intel Core i3 2.5Ghz or AMD Phenom II 2.6Ghz with 4 GB RAM; Intel HD Graphics 4000 / Nvidia GeForce 710 / AMD Radeon HD 6450 or better; screen resolution of 1280x768 or higher

We'll try to resolve this issue as soon as possible. Thanks for letting us know about it!

Keep an eye out for a followup email from us. We may have a couple more questions for you, or we might already have a solution to offer.

Happy creating!