Jump to content

Set a mesh/camera position/rotation smoothly


3Dlove
 Share

Recommended Posts

Hello guys =D

 

I would like to set a camera position by programmation but the camera move directly to the position, OK normal but how to do that smoothly with inertia ? :)

 

I do that when I click on a mesh to move the camera in front of the mesh (I used a FreeCamera).

 

It would be nice if the setTarget method has a second inertia parameter, the same for a setPosition function :)

 

Thanks for your help ;)

Link to comment
Share on other sites

I found something : Animation =D

var animationPlane = new BABYLON.Animation('anim', 'position.z', 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);var keys = [];  keys.push({ frame: 0, value: scene.getMeshByName(name).position.z });keys.push({ frame: 10, value: scene.getMeshByName(name).position.z-3 });keys.push({ frame: 20, value: scene.getMeshByName(name).position.z-6 });keys.push({ frame: 30, value: scene.getMeshByName(name).position.z-9 });animationPlane.setKeys(keys);plane.animations.push(animationPlane);scene.beginAnimation(plane, 0, 30, true);

I'm trying to do it with vectors :)

Link to comment
Share on other sites

Here is the solution with vectors :

var animationPlane = new BABYLON.Animation('anim', 'position', 30, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);var keys = [];  keys.push({ frame: 0, value: scene.getMeshByName(name).position });keys.push({ frame: 30, value: planeFinalVector });animationPlane.setKeys(keys);plane.animations.push(animationPlane);scene.beginAnimation(plane, 0, 30, true);

Is it possible to do the same with a camera instead of a mesh ?

 

How to remove the animation in order to free the memory ? because I use it just once and we do "plane.animations.push" ?

maybe "plane.animations = null" ??

Link to comment
Share on other sites

OK thanks :)

 

For people who don't know it : in order to just play animation once without loop :

set the 4th parameter of beginAnimation to false ! (I took 20 min to find my error^^)

 

 

Is the below code a good way to free memory and play an animation juste one and delete it ?

// Animations Beginningscene.beginAnimation(plane, 0, 30, false);scene.beginAnimation(scene.activeCamera, 0, 30, false);      // Free Memoryplane.animations = [];  scene.activeCamera.animations = []; 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...