Problems with pivot and rotation

Recommended Posts


My first post on a forum since..... lot of time. But i'm totally lost about a little problem and I need your help !

(first, i'm not a native english speaker, so sorry if I do mistake)

I'm a newbie, it's doing lot of time I would like to try webGL, but I hadn't opportunity to work on a real project.

So, I need to make a box from a template (like this http://www.babylonjs-playground.com/#192VEQ#5 ). Each faces are made with the Meshbuilder. And I need to bend and close the box (for animate it and make it interactive). Ideally the template will be not defined (with less / more faces, different size, but not the problem now), and I search a process who not need tinker with improbable translation for example.

Annd I've real problem to have a good understanding with rotation and pivot. I think my lack of knowledge in 3D and in english don't really help ...

So for the moment I've made that : http://www.babylonjs-playground.com/#192VEQ#6
For example, why the flap (the red mesh) rotate like that, I use the same process than "plaque 4" (blue mesh next to the red). And I don't understand why there are a shift.

I'd just want to do a 90deg rotation from the side.

I know there already lot of stuff about pivot and rotation, but I'm really stuck, and they don't answer to my questions. 

Sorry if it's not really clear . But I hope you can point me on the good solution or/and explain me (I continue to search, so I'll update the post if I found something haha).

and thank you for your help in advance !

Share this post

Link to post
Share on other sites

Hiya ichbinrob, welcome.

     I have to say... this scene is indeed a challenge.  I think you have done a marvelous job so far.  You are experimenting with parenting MUCH, and it is hard work... with geometry like this.

Parenting, as you likely know, causes child to inherit .position, .rotation, and .scaling... FROM the parent.

setPivotMatrix and setPivotPoint... I believe... CAN/DO move mesh origin/center, and this can affect mesh.position (often, unexpectedly). 

I am no pro at that, and setPivotPoint has some extra params at the end... for "move the mesh" or "don't move the mesh", I believe.  The most-recent versions of BJS... made some changes in those things, and I have not learned the changes well.

I'm not sure HOW to figure a plan... for the forum helpers to help.  YOU might be the leading expert in these things, right now.  :)

MAYBE... hmm... goodbye to parenting, hello to custom "grouping manager".   ??  hmm.  #7 playground, all parenting removed... ready for grouping manager... erf.  :)

Actually, lines 354-356 parent almost all mesh, to this._base, and this._container was removed.  Dunno why I did that.  Typing while thinking, I guess.  :)

Perhaps someone has an alternative idea... something to simplify this challenge... without all the parenting/un-parenting.  Let's listen for more comments.

Share this post

Link to post
Share on other sites

So I cleaned up the PG a little http://www.babylonjs-playground.com/#192VEQ#8

Line 39 to 181 are to draw each 13 faces of the box template.

then I need to build the box from the template, with a "realistic" way (I want to animate it to see all the bend process)

It's I try to do with line 183 to 248.

I started to chain rotation and parenting. It  looked quite easy to do, but at the plaque4  (and it's the same problem for plaque5, and all flaps). If I just set pivot, like I do before. The rotation is good, but I've an unwanted translation and i need to compensate with "manual" positioning. And I don't want to do this manual positioning.

So a little code (line 239 - 242)

plaque4.setPivotPoint(new BABYLON.Vector3( - 6/2, 0, 0));
plaque4.position.z -= 3; // it's what I don't want to do
plaque4.position.x += 3; // it's what I don't want to do
plaque4.rotation.y = - Math.PI;

But ! I didn't know the SetPivotPoint could take some parameters (like world / local axes).

and thank you for your answers ! I going to try somethings with this, and I keep you informed :) 

ps It's an example of what it looks like build (but I "cheat" to build it, it's too much specific to this template) : https://www.jill.beer/e/carton/ (long time to load texture, aren't optimize)


Share this post

Link to post
Share on other sites

Yeah, good reply... thx.  You ARE an expert.

We sort-of need... mesh.useBoundingBoxCenterAsOrigin = true;  :)  Or maybe... .lockedOrigin = true;   After that, pivotPoints would be free to fly, without mesh-translation issues.

I said something incorrect, earlier, regarding the "move object" and "don't move object" parameter.

The parameter is called "postMultiplyPivotMatrix" and it is on the setPivotMatrix() func.  (I thought it was on setPivotPoint)


It counter-acts position/origin mesh-moves (unwanted translations) that might happen during the matrix transform.

I think this might be good news for you.  Sorry for the mistake in an earlier post.

And YES, definitely report your progress/discoveries... thx!

Share this post

Link to post
Share on other sites
On 6/7/2018 at 12:29 PM, JohnK said:

as a simple minded man

Don't believe that for a second, forumers.  JohnK is a genius.  A great teacher, a great thinker/inventor, a pivotMaster, and a darned nice guy.  If he's simple at all, he's simply wonderful.  I try to be like him as much as possible.  Nice transformNode demos, guys!  Power bookmarked.

TransformNodes are pretty cool!  I have never seen them used like this (or much at all).  They are a fairly new feature in Babylonia.  They seem to do MUCH of the work for the powerful Babylon.Mesh class, and perhaps lights and cameras, too.  "Transformers - more than meets the eye!"  (robots in disguise)  :)

Good to hear you're rolling, ich!  YAY!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.