Search code examples
javascriptspark-ar-studio

How can I access a assets (animation sequence) using scripting in Spark AR studio


I'm trying to change the current frame of an animation sequence using a script in JS and I can't find the equivalent of Scene.root.find.... of assets... I'm trying to create a "Which ____ are you?" and I make the code for the roll an image but I don't know how to access it using scripts?


Solution

  • If I get it right, this will help you.

    
    const Materials = require('Materials');
    const mat = Materials.get('matName');
    // set your number here, or an animation
    mat.diffuse.currentFrame = 1;
    
    

    UPD 8 May 2021: Now you should use async methods:

    
    const M = require("Materials"); 
    const D = require("Diagnostics");
    (async function () {
        const mat = await M.findFirst("material0");
        const diff = await mat.getDiffuse();
        diff.currentFrame = 1;
    })();