Tweening Colors on Spark AR via Script

夙愿已清 提交于 2020-01-25 10:14:53

问题


what would be the equivalent of a transition Patch in Reactive script? I would like to tween a color from say 0,0,0,1 to 1,1,1,1 in RGBA. I know ho to animate a single value as alpha, like this:

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

Using visual patches you can use a Transform Patch to link a Vector3 to an animation progress. I cannot find something like this anywhere in the docs for reactive script. anyone can tell me?

Thank you!


回答1:


you need to look at ShaderModule. Find the material by name, and then you can use 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}
);  

Here i've used ArrayOfScalarSamplers, but it's not crucial.



来源:https://stackoverflow.com/questions/59683552/tweening-colors-on-spark-ar-via-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!