通过脚本在Spark AR中动态生成值

问题描述 投票:1回答:1

来自此问题Tweening Colors on Spark AR via Script,我现在尝试使开始和结束颜色动态受限。我大概还没有吞噬反应式编程的整个概念,但是我试图制造一个工厂,所以该值是一个函数……但它不起作用,或者仅适用于初始值。使用set函数并重新启动动画不会改变任何事情。我想念什么?谢谢你,最好的问候!

const pink = [.99, .682, .721, 1];
const blue = [.0094, .0092, .501, 1];
const yellow = [0.9372, .7725, 0, 1];

function ColorFactory() {
    this.sourceCol = pink;
    this.targetCol = blue;

    this.set = function (_col1, _col2) {
        this.sourceCol = _col1;
        this.targetCol = _col2;
    }

    this.get = function (id) {
        switch (id) {
            case 'source': return this.sourceCol;
            default: return this.targetCol;
        }
    }
}


var colfac = new ColorFactory();

const timeDriver = Animation.timeDriver(timeDriverParameters);
const rotSampler = Animation.samplers.easeInQuad(0, 35);
const alphaSampler = Animation.samplers.linear(1, 0);
const colSampler = Animation.samplers.linear(colfac.get('source'), colfac.get('target'));
const colorAnimation = Animation.animate(timeDriver, colSampler);

timedriver.start();

//doesnt make change anything, same colors as before:
colfac.set(blue, yellow);
timedriver.reset();
timedriver.start();

所以我如何使颜色动态化?有人吗?

scripting instagram reactive spark-ar-studio
1个回答
1
投票

您唯一的“好”选项是执行以下操作:

const colors = [];
const driver = A.timeDriver({ durationMilliseconds : 1000 });

// On NativeUI monitor selected index event 
ui.selectedIndex.monitor.subscribe(
(val) => {
   const sampler = A.samplers.linear(colors[val.oldValue, colors[val.newValue]);
   const colorAnimation = A.animate(driver, sampler);

   // bind here to shader

})

© www.soinside.com 2019 - 2024. All rights reserved.