通过脚本在 Spark AR 上补间颜色

Tweening Colors on Spark AR via Script

Reactive 脚本中的转换补丁相当于什么?我想在 RGBA 中补间从 0,0,0,1 到 1,1,1,1 的颜色。我知道如何将单个值设置为 alpha 动画,如下所示:

const timeDriver = Animation.timeDriver(timeDriverParameters);
const alphaSampler = Animation.samplers.linear(1, 0);
const alphaAnimation = Animation.animate(timeDriver, alphaSampler);
mymaterial.opacity = alphaAnimation;

使用视觉补丁,您可以使用变换补丁 link 将 Vector3 用于动画进度。我在响应式脚本的文档中的任何地方都找不到类似的东西。谁能告诉我?

谢谢!

你需要看看ShaderModule。通过名字找到material,然后就可以使用setTexture了。


const R = require('Reactive');
const A = require('Animation');
const S = require('Shaders');
const Materials = require('Materials');


const material = Materials.get('matName');
const driver = A.timeDriver({ durationMilliseconds : 1000});
const sampler = A.samplers.linear(
    [1, 1, 1, 1],
    [0, 0, 0, 1]
);
const colorAnimation = A.animate(
    driver,
    sampler
);


material.setTexture(
    R.pack4(
        colorAnimation.get(0),
        colorAnimation.get(1),
        colorAnimation.get(2),
        colorAnimation.get(3)
    ), 
    {textureSlotName: S.DefaultMaterialTextures.DIFFUSE}
);  

这里我使用了ArrayOfScalarSamplers,但这并不重要。