0

I'm trying to create a simple color animation in Three.js. This is my code:

var geometry = new THREE.BoxGeometry(1, 1, 1);
var material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
var cube = new THREE.Mesh(geometry, material);
game.camera.position.y = 5;
game.camera.lookAt(new THREE.Vector3());
game.scene.add(cube);

var colorAnim = new THREE.ColorKeyframeTrack(
    ".material.color",
    [0, 2, 3, 4, 5],
    [0xff0000, 0xaa00aa, 0x0000ff, 0x00aaaa, 0x00ff00]);
var colorClip = new THREE.AnimationClip(null, 5, [colorAnim]);
var colorMixer = new THREE.AnimationMixer(cube);
var colorAction = colorMixer.clipAction(colorClip);
colorAction.play();

var clock = new THREE.Clock();

var render = function ()
{
    var delta = clock.getDelta();

    requestAnimationFrame(render);

    cube.rotation.x += Math.PI * delta;
    cube.rotation.y += Math.PI * delta;

    colorMixer.update(delta * colorMixer.timeScale);

    game.renderer.render(game.scene, game.camera);
};

render();

But the animation does not work properly, and instead does this:

The thing that it is doing

I am just trying to create a 5-second color animation, what am I doing wrong?

1 Answer 1

1

All of the components must be specified separately, and the range of values is [0, 1], not 0x00-0xFF.

This works:

var colorAnim = new THREE.ColorKeyframeTrack(
        ".material.color",
        [0, 2],
        [1, 0, 0, 0, 0, 1])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.