dbawel Posted March 3, 2018 Share Posted March 3, 2018 Hello, I'm animating vehicles on paths, and have no flipping until I get to a heart shape. The curve is less than others, yet I'm getting tons of flipping (gimble lock.) I've tried converting the animation to use quaternions, but no such luck. Here's the code I'm using for the animation: Quote function heartFlight(vehicle) { scene.stopAnimation(vehicle.parent) vehicle.rotation.x = 0; vehicle.rotation.z = Math.PI / 4; vehicle.position.y = 0; const Heartpath = [ new BABYLON.Vector3(0, -40, 100), new BABYLON.Vector3(-50, 20, 100), new BABYLON.Vector3(-25, 38, 100), new BABYLON.Vector3(0, 18, 100), new BABYLON.Vector3(25, 38, 100), new BABYLON.Vector3(50, 20, 100), new BABYLON.Vector3(0, -40, 99), ]; const catmullRomH = BABYLON.Curve3.CreateCatmullRomSpline( Heartpath, 40 ); //let catmullRomSplineH = BABYLON.Mesh.CreateLines("catmullRomH", catmullRomH.getPoints(), scene); //catmullRomSplineH.color = new BABYLON.Color3(1,0,0); const path3d = new BABYLON.Path3D(catmullRomH.getPoints()); const tangents = path3d.getTangents(); // array of tangents to the curve const normals = path3d.getNormals(); // array of normals to the curve const binormals = path3d.getBinormals(); // array of binormals to curve const speed = 20 // const speed = 10 const animationPosition = new BABYLON.Animation('animPos', 'position', speed, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE); const animationRotation = new BABYLON.Animation('animRot', 'rotation', speed, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE); const keysPosition = []; const keysRotation = []; for (let p = 0; p < catmullRomH.getPoints().length; p++) { keysPosition.push({ frame: p, value: catmullRomH.getPoints()[p] }); keysRotation.push({ frame: p, value: BABYLON.Vector3.RotationFromAxis(normals[p], binormals[p], tangents[p]) }); } animationPosition.setKeys(keysPosition); animationRotation.setKeys(keysRotation); vehicle.parent.animations = [ animationPosition, animationRotation ]; flying = scene.beginAnimation(vehicle.parent, 0, 300, false); } If anyone can offer a solution to stop the constant flipping, I would be grateful. Every method I know doesn't want to work on this path. Thanks, DB Quote Link to comment Share on other sites More sharing options...
JohnK Posted March 3, 2018 Share Posted March 3, 2018 Do not have time to reason it out at the moment but changing the order from BABYLON.Vector3.RotationFromAxis(normals[p], binormals[p], tangents[p]) to BABYLON.Vector3.RotationFromAxis(tangents[p], normals[p], binormals[p]) seems to give a smooth journey. https://www.babylonjs-playground.com/#72C7CT dbawel 1 Quote Link to comment Share on other sites More sharing options...
dbawel Posted March 3, 2018 Author Share Posted March 3, 2018 @JohnK- You are amazing in my opinion. I had switched the normals and binormals, but foolishly assumed that changing the order of the tangents would not have an extreme effect on the orientation behavior. This is a huge help to me, and I owe you one - and way beyond "one." You are a gentleman and very accomplished scholar. It's certainly a pleasure to have you as an integral part of our small (yet rapidly growing) community. I just hope I can assist you on the same level one day. Please have a great weekend! Cheers, DB JohnK 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.