3Dlove Posted April 28, 2015 Share Posted April 28, 2015 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 Quote Link to comment Share on other sites More sharing options...
3Dlove Posted April 28, 2015 Author Share Posted April 28, 2015 I found something : Animation =Dvar 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 Quote Link to comment Share on other sites More sharing options...
3Dlove Posted April 28, 2015 Author Share Posted April 28, 2015 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" ?? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 28, 2015 Share Posted April 28, 2015 You can do the same with a camera.position to remove animations you just have to remove them from mesh.animations (with a splice or by setting mesh.animations = []) Quote Link to comment Share on other sites More sharing options...
3Dlove Posted April 29, 2015 Author Share Posted April 29, 2015 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 = []; Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 29, 2015 Share Posted April 29, 2015 You can use the 6th parameter to provide a callback to free memory. More info here:http://doc.babylonjs.com/page.php?p=22081 3Dlove 1 Quote Link to comment Share on other sites More sharing options...
3Dlove Posted April 30, 2015 Author Share Posted April 30, 2015 OK thanks I used : var animatableCam = scene.beginAnimation(scene.activeCamera, 0, 30, false);animatableCam.onAnimationEnd = function() { // some code // Free Memory scene.activeCamera.animations = []; }; GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.