问题
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