Jump to content

[Solved} + Rotation flipping when mesh on path


dbawel
 Share

Recommended Posts

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

Link to comment
Share on other sites

@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

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...