Multiple Issues with Pivot-Setting Playground

Hi gang.

I’m having problems with a test playground that periodically sets pivots to random corners of a box. (and then does a random-ish 90-degree spin around that new pivot)

https://www.babylonjs-playground.com/#195B2X#10

I am still studying pivot docs, but I can’t find the correct way to prevent box from changing .position.

I think the ‘true’ in the last param of line 48… SHOULD keep the mesh from re-positioning after each pivotMatrix setting, but it is being grumpy for me. It still re-positions the box, sometimes/often.

Help welcome. Thx!


2nd issue: Also, I am experiencing console.logs that won't shut-off. For example, the above playground has two console.logs at lines 39/40. You can watch console and see them execute.

Now remark them out (disable them), or remove them from the code. Click RUN. Are they still active, outputting text to console? They are doing so, for me, in Firefox & IE. Seems broken, but could be Wingnut screw-up… as always. :slight_smile: Thx for info/help.

Update: Issue #2 solved… needed to clearInterval() in scene.onDispose. link “intervals” are SO strange. Ghost-like “forks”… flying around inside the playground walls. “timeouts” are wiser, and can be config’d to act like intervals.

https://www.babylonjs-playground.com/#195B2X#17

New playground, trying two newly-web-found functions… that are “repeating setTimeouts”. BOTH seem to need scene.onDispose clear-out… to make line 39/40 logs… stop displaying (after once activated). Weird.

Timeouts and intervals… just strange. :slight_smile:

“Larry had an in-ter-val, interval, interval”… etc.
“It followed him past RUN one day, RUN one day, RUN one day”… etc.

heh. (parody of “Mary Had a Little Lamb”)


Meantime, primary issue still exists... the 'true' in line 50 appears to be... umm... not working. hmm.

Link to api docs for setPivotMatrix

param:  postMultiplyPivotMatrix: boolean

defines if the pivot matrix must be cancelled in the world matrix. When this 
parameter is set to true (default), the inverse of the pivot matrix is also 
applied at the end to cancel the transformation effect.

Translation to noobian: Mesh position-change is nulled/cancelled. :slight_smile:

1 Like

Hi, @Wingnut, I am not sure aboout my understood of your problem, but if I correct, you are trying to rotate mesh around itself, that means you should use local coordinates.
As I remember, with pivot matrix, default coordinate system is world. If you want to change this, you should do manually recompute to local coordinate system, and apply handmade-recomputed matrix as argument to the methods.

I will try to find additional info about this, because I have some aftersound in my mind about this mathematical transformations, but for now I can’t formalize this to formula.

Thanks for reply, Logunov! You might be right… I need to study that.

Yes, I am rotating the mesh, but not really “around itself”, but “around it’s pivot point”. But, mesh “origin” and mesh pivotPoint… are often deemed identical, so you are “technically” correct. The mesh “origin” is indeed moving when the pivotPoint moves. At least I THINK so.

https://www.babylonjs-playground.com/#195B2X#21

In THAT playground, I disabled the setPivotMatrix() call, and instead used setPivotPoint() in lines 49-53.

SetPivotPoint() allows me to set a “space”… either LOCAL or WORLD… in line 53.

Setting LOCAL or WORLD… doesn’t fix it, but, I’m not sure it is doing the same action… as what YOU describe. I will study… thanks again.

Earlier, I thought that each time I moved the pivot/origin, all future getBoundingInfo().boundingBox.extends*… were returning bad values. This is why I thought about box1.refreshBoundingInfo(). (line 77)

But, after console.log checks, those numbers looked good… always being 1 or -1 (without using the refresh).

The “bake” in line 76 is also related… but using that… screws-up the scene even MORE. :slight_smile: I also experimented with similar lines @ 27-29. No joy.


@Wingnut, let me share a little of my awesome art skill.

So, all I want to say, try to draw point of rotation to figure out where it is, and try manually calculate, what are you doing with it, before apply this though BABYLON, sometimes it helps me understand where problem in the input data, before trying to figure out where is exactly mathematical error in my computations.

As I can see, here is a big chance of wrong rotation pivot. It can be in local coordinates, but out of object volume, so it will provide movement in world space, on the other hand, as closer pivot to the center of meshes, as lower global movement will be (up to zero).

1 Like

To be more clear, I mean: you can rotate around one point and all will be fine, but you using local coordinates, and next point get displacement from previous rotation, and rotate around new point provide new additional displacement in world coordinates.

Yes, but according to…

… setting that param TRUE should compensate-for any worldSpace position-changes that the mesh tries to make. It applies the inverse of any world matrix changes that happened to the mesh… during the setPivotMatrix(). I don’t think it is working.

I think you are correct about ALL you have said, but our “compensator” parameter SHOULD counteract that unwanted transform issue. At least I THINK so. :slight_smile: Thanks for your input.

You MIGHT be implying that it is my spin() function that is messing-with the compensator. It does a worldSpace transform when it spins. hmm. That’s why I was trying a “bake” after the spin. hmm.

Before posting, I took a look on your code and make assumption.
I modify a little your playground: https://www.babylonjs-playground.com/#195B2X#22
Take a look (wait for 10 or more calls of your functions to see previous pivots, I think it will help you figure out what’s going on better).

For clarifying: is commenting line 81 provide expected result?

No. It just disables the “set pivot to a random box corner” operation.

Objective… no mesh position jumps, no matter which corner of the mesh has the pivot point. Only “spin to new position” allowed, no jumps.

Language barrier is so hard >_<
I need one more question: you need to make cube rotate around itself, in other words it will provide rotation around local point and accumulate rotations in some direction, or would you like always cube stay in the center and do new rotation?

1 Like

I agree (language). Also, I’m not very smart, so, there’s a problem with that, too. :slight_smile:

Um, no, the mesh should “crawl around” on the screen… in random directions. The axis that spin() is using… is also random… either x, y, or z. So, mesh should move-around within scene… somewhat. But always SPINNING to the new position, never jumping.

I hope I explained that decently. :slight_smile: I guess it could be called “Slinky-moving”. Butt-end keeps rotating over head-end… to move the Slinky (down a stairs, for example).

1 Like

I figured out what is the problem. It is not in the pivot matrix or rotation errors.
You are tacking bounding info as new data parameter, but bounding info is always static, it do not change it global position, so, when you applying your pivot data from the matrix, your bounding info do not changes, so, you uses old vertex data from mesh, and it’s rolling back to previous state.
https://www.babylonjs-playground.com/#195B2X#24
Take a look in console logs: if mesh data changes, there should be different numbers, but they are always the same. Bounding info returns always same data, so the agruments of matrix are always same, and it do same rotations.

For now I think so, I will take a deeper look right now, maybe I am wrong with it, but I am pretty sure not.

I will do some tests now, to figure out how to fix it.

1 Like

I think boundingInfo NEEDS to stay static. I only use it to get half-sizes OF the box. Since the box doesn’t change size, all extends* should be 1 or -1, for a size 2 box.


I found another fun "bake"...

box1.bakeTransformIntoVertices(box1.getWorldMatrix());

Hmm… bake (make default) any matrix-transform… into/onto a mesh. hmm. Just another magic code-line to confuse Wingnut. heh

Maybe, after the spin… bake the PRE-spin matrix transformation… into the newly-spinned mesh.

Nah, that won’t work. (Wingnut feels-around in the dark) :slight_smile:

        mesh.setPivotMatrix(
            BABYLON.Matrix.Translation(
                rand(xlist), rand(ylist), rand(zlist)
            ),
            true
        );

Still… I think that true is broken, and would make all my dreams come true, if it worked. Maybe.

1 Like

Well, I stuck a little in that, maybe someone else will be better to help you.
I got same result using leading vectors as method, maybe use of animation with loop mode as constant and loop parameter as false, but I can’t figure out what should rotation axis be.
https://www.babylonjs-playground.com/#195B2X#28

1 Like

i dont know if thats true. Even if you werent smart you try really hard, and that is more important than just being smart.

3 Likes

You re dead smart @Wingnut cause you keep learning and sharing :slight_smile:

1 Like