We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Keyframe Animation using JavaScript

Home Forums Programming Keyframe Animation using JavaScript

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #65170
    ps
    Participant

    Hi,
    I am using the v3d.SimplePreloader template to load a cube. Inside runCode() I tried the following code to animate (simple translation) the cube. The animation is not playing. Refer the attached blender file.

    function runCode(app) {
          
      let cubeObject = app.scene.getObjectByName("Cube");
      const mixer = new v3d.AnimationMixer(cubeObject);
    
      const action = v3d.SceneUtils.getAnimationActionByName(app, 'CubeAction');
    
      if (action) {
        
        // Set the action to play only once
        action.setLoop(v3d.LoopOnce);
    
        // Play the animation
        action.play();
      }
    
      function update() {
        requestAnimationFrame(update);
    
        const delta = app.clock.getDelta();
        mixer.update(delta);
        
        // Render the scene
        app.renderer.render(app.scene, app.camera);
      }
    
      // Start the animation update loop
      update();
    }
    • This topic was modified 1 year, 4 months ago by ps.
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.