Tween Alpha Values
I want to change the value of my material's alpha channel over time. I can't seem to get it to work.
I have attached my code. It's throwing an error on line 34 saying that TWEEN is undefined: var tween = new TWEEN.Tween(tweenStartAlpha)
Any help would be greatly appreciated!
I thought tweening might be the best route, but I'm open to other suggestions on how to change a value over time.
// -----JS CODE-----
// @input Asset.Material tux
// @input vec4 startAlpha = (255, 255, 255, 255)
// @input vec4 goalAlpha = 255, 255, 255, 0)
// @input float time
var tweenStartAlpha = {
r: script.tux.getPass(0).baseColor.r,
g: script.tux.getPass(0).baseColor.g,
b: script.tux.getPass(0).baseColor.b,
a: script.tux.getPass(0).baseColor.startAlpha
};
var tweenGoalAlpha = {
r: script.tux.getPass(0).baseColor.r,
g: script.tux.getPass(0).baseColor.g,
b: script.tux.getPass(0).baseColor.b,
a: script.tux.getPass(0).baseColor.goalAlpha
};
var tween = new TWEEN.Tween(tweenStartAlpha)
.to(tweenGoalAlpha, script.time * 1000.0)
.onUpdate(function() {
updateAlpha(tweenStartAlpha);
})
.start();
// Here's where the values returned by the tween are used
// to drive the alpha of the SceneObject
function updateAlpha(alpha) {
//var material = script.tux.getMaterial
//material.getPass(0).baseColor(new vec4(alpha.r, alpha.g, alpha.b, alpha.a);
script.tux.getPass(0).baseColor = new vec4(alpha.r, alpha.g, alpha.b, alpha.a);
}
// On update, update the Tween engine
function onUpdateEvent() {
TWEEN.update();
}
// Bind an update event
var updateEvent = script.createEvent("UpdateEvent");
updateEvent.bind(onUpdateEvent);
Hi Abigail,
It looks like TWEEN hasn't been initialized yet. Have you added the Tween Manager object and made sure it's at the top of the Objects list?
Also, you can probably do this much more easily using the TweenAlpha script including with Tween Manager. Check out the Tweening Guide to see more info!