Recommended Posts

Hi CLW.  Sorry to hear you are having problems. 

I don't think that pivots3.2 document has been completely updated for 3.2, yet.

There is little/no talk about the new boolean parameter for setPivotMatrix()... postMultiplyPivotMatrix.

https://www.babylonjs-playground.com/#1MKHR9#41

See line 42.  See the added 'false'?  That fixed the "pivot at corner of box" problem, yes?  I hope so.  I added an animation to make sure.  :)

Line 34 is failing, though.

I think there might be issues in the framework code... regarding pivots.

I have not been able to understand the new system, yet.  https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.transformNode.ts#L266

That param is named... postMultiplyPivotMatrix .  Wow.  The name alone... gave me a brain tumor.  :D  I need to study it more.  Bigger dogs than I... need to look it over, too. 

Stay tuned... possibly more comments coming.

Share this post


Link to post
Share on other sites

@WingnutTBH, it looks to me like line 34 is doing what it says on the box, but line 32 is setting a pivot based on absolute coords rather than relative ones, and the rotation isn't occurring around the pivot point.

https://www.babylonjs-playground.com/#1MKHR9#44

The alert boxes show that the pivot and absolute pivot points are at exactly the same place: -1, -1, -1, where the sphere was being put before I commented out line 34.

Share this post


Link to post
Share on other sites

You beat me to it @Wingnut though I approached it in the spirit of the updated version.

From 3.2 setting the pivot does not require the mesh to be re-positioned to maintain its position before the pivot is set. (This was not true prior to 3.2). So when you use

box.setPivotMatrix(BABYLON.Matrix.Translation(1, 1, 1));

the position of the box remains at (0, 0, 0) as in http://www.babylonjs-playground.com/#1MKHR9#43

so as you would do in the situation of not setting a pivot to get the box with its lower left front corner to the origin you need to set its position to (1, 1, 1).

The reason for no mention of the 'false' parameter in v3.2 of the docs is that it the need to move the mesh was not the intended behaviour for setting the pivot and from 3.2 it works as expected. The parameter is mentioned in the docs on setting pivots as a way of keeping the old behaviour for those still using earlier versions. Though it could be added if people think it is necessary. You can see that the old behaviour was to move the mesh when a pivot was set in https://www.babylonjs-playground.com/#1MKHR9#45

Also as Wingnut says there does seem to be something not correct with getAbsolutePosition perhaps the author which I believe was @adam might have time to check it out. As you will see in #42 I formed a work around.

 
 
 

Share this post


Link to post
Share on other sites

Thanks

So to use setPivotMatrix with false set with setPivotPoint I would have to make a new setPivotPoint?

I have set up models in 3Ds max where the pivot point is at 0,0,0 and the model is centred.

When I import them the position is saying its at the top left. This is why after import I am using setPivotPoint with WORLD 0,0,0 to put it back as it was in Max.

This seems ok for the first mesh but when I clone it the clone goes off in some random x,y,z even if I set the pivot to 0,0,0 as the original?

https://www.babylonjs-playground.com/#1MKHR9#46

I don't know what I'm doing.

Share this post


Link to post
Share on other sites
14 hours ago, captainleighwalker said:

I don't know what I'm doing

If you are using the older version by adding false to the function then you probably need to read about the older behaviour http://doc.babylonjs.com/how_to/pivots and http://doc.babylonjs.com/how_to/pivot

There is some description of resetting a pivot in the first.

Share this post


Link to post
Share on other sites

@adam my apologies there is nothing wrong with getAbsolutePivotPoint, as usual I was getting my head in a tiz

On 5/13/2018 at 6:28 PM, captainleighwalker said:

So to use setPivotMatrix with false set with setPivotPoint I would have to make a new setPivotPoint?

Don't do this ^^^^^^^^^ Why not? - read below.

On 5/13/2018 at 4:10 PM, Wingnut said:

There is little/no talk about the new boolean parameter for setPivotMatrix()

Have had a look at the docs for this and have done a re-write which will be available whenever it is next updated.

Having done the re-working my advice is to never add the false parameter (unless updating an old project to work with versions 3.2 and later) it just adds too many complications, including getAbsolutePivotPoint reporting correctly but not the values you might expect. If you need to set a pivot and move a mesh then use mesh.setPivotMatrix(translation) followed by mesh.position or mesh.translate(...) DO NOT use mesh.setPivotMatrix(translation, false).

https://www.babylonjs-playground.com/#1MKHR9#48

Share this post


Link to post
Share on other sites

Thanks @JohnK

 

The models I'm importing from 3Ds Max have negative x,y,z to give the left, bottom, front position of the mesh. All my calcs are based on the centre of the meshes.

Before it worked with setPivotPoint to 0,0,0 WORLD which was nice and easy. How would you do that with 3.2?

It would make things easier if I could position models based on the pivot point.

Share this post


Link to post
Share on other sites
1 hour ago, captainleighwalker said:

Before it worked with setPivotPoint to 0,0,0 WORLD

As far as I know if you were using mesh.setPivotPoint(new BABYLON.Vector3(0, 0, 0), BABYLON.Space.WORLD) then it should still work with v3.2 and after as it is.

http://www.babylonjs-playground.com/#1MKHR9#49

To re-position your mesh with corner at (0, 0, 0)  http://www.babylonjs-playground.com/#1MKHR9#50

It is only if your project was previously using mesh.setPivotMatrix(translation) that you need to change this to mesh.setPivotMatrix(translation, false)

Share this post


Link to post
Share on other sites

hi @JohnK Thanks for your help. The problem I'm having is the imported mesh seems to have y and z flipped also pivot point is actually 0,0,0 when importing and the position is negative,negative,negative so the following moves the mesh to a strange position because pivotAt is 0,0,0:

    //Get current position of pivot as imported
    var pivotAt = box.getPivotPoint();
    //reset center (0, 0, 0) as pivot
    box.setPivotPoint(BABYLON.Vector3.Zero(), BABYLON.Space.WORLD);
    //move mesh 
    box.position = box.position.subtract(pivotAt)

 

At the moment I am using this but its not nice.

var pivot = this.position;

  this.setPivotMatrix(BABYLON.Matrix.Translation(pivot.x, -pivot.z, pivot.y), false);
  this.position = new BABYLON.Vector3(x, y, z);

As you say I need to get rid of the false in setPivotMatrix

Share this post


Link to post
Share on other sites
11 hours ago, captainleighwalker said:

imported mesh seems to have y and z flipped

Babylon.js uses a left handed system of axes  with y up whilst 3DMax uses a right handed system of axes with z up. You can change Babylon.js to a right handed system with

scene.useRightHandedSystem = true;

then carefully position camera if you want to view axes with z up http://www.babylonjs-playground.com/#1MKHR9#51

11 hours ago, captainleighwalker said:

pivot point is actually 0,0,0 when importing and the position is negative,negative,negative

This needs more thinking about as a it seems your mesh is created with a local origin at a corner of the mesh with a pivot at the center. Where as in Babylon.js a mesh the mesh is created with the local origin at the center which acts as the pivot point. Using setPivotMatrix(translation, false) moves both the pivot point and the local origin to a coincident position whereas setPivotMatrix(translation) or setPivotPoint keeps the local origin as the center but places the pivot at the given position.

Since the local origin of your imported mesh is offset from the center when you position the mesh it is this local origin that is placed at the given position.

Say you have the situation where the pivot point (mesh center) is at (0, 0, 0) and the local origin of the mesh is at (x, y, z) and you want the center of the mesh to be at (a, b, c) then without any change to the pivot you will need to use

//once only
var offset = mesh.localOrigin.subtract(mesh.pivotPoint);

//every time you set position
placeMeshAt = new BABYLON.Vector3(a, b, c);
mesh.position = placeMeshAt.subtract(offset);

The following examples are all in  right handed axes

As an example I have simulated a box with the conditions you describe http://www.babylonjs-playground.com/#1MKHR9#54

and then cloned another and re-positioned them with no change of pivot position http://www.babylonjs-playground.com/#1MKHR9#53

and then added a change of pivot point to one of the re-positioned boxes http://www.babylonjs-playground.com/#1MKHR9#55

Share this post


Link to post
Share on other sites

Thanks @JohnK once again for your time.

mesh.localOrigin and mesh.pivotPoint are undefined. Is that something you are setting after the mesh loads?

mesh.localOrigin = mesh.position ?

 

This seems to be working if you think that's ok!?

Also keeps left hand system without having to swap y and z manually. It might have got right hand because I imported to max from Inventor.

    BABYLON.Mesh.prototype.positionModel = function (x, y, z) {
            if (this.localOrigin === undefined)
                this.localOrigin = this.position;
            var offset = this.localOrigin.subtract(this.getPivotPoint());
            var placeMeshAt = new BABYLON.Vector3(x,y,z);
            this.position = placeMeshAt.add(offset);
        }

 

Share this post


Link to post
Share on other sites
3 hours ago, captainleighwalker said:

mesh.localOrigin and mesh.pivotPoint are undefined

just pseudo code to indicate what you should be using.

________________________________________________________________________________________________________________________________________

Remember you only need to find the offset once as it a way of dealing with how your imported mesh is constructed.

var mesh.offset = mesh.getPivotPoint();

and your prototype becomes

BABYLON.Mesh.prototype.positionModel = function (x, y, z) { 
    if (this.offset == undefined) {
        this.offset = BABYLON.Vector3.Zero();
    }
    var placeMeshAt = new BABYLON.Vector3(x,y,z); 
    this.position = placeMeshAt.subtract(this.offset); 
}

Does this PG now do what you want? If the answer is no I will need a more detailed description of the problem which you can give me by  answering the section below.

_______________________________________________________________________________________________________________________________________________

Please answer each of the following questions yes or no, numbering answers to match question numbers.

For the simulated imported box that has local origin at the bottom left front corner of the box and pivot at center of the box

1. In this PG the box has position (0, 0, 0). Is this what you would expect from your imported mesh?

2. In this PG the box has position (0, 0, 0) and is rotating about a pivot (1, 1, 1) at the center of the box.  Is this what you want to happen when positioning the center of the box?

3. In this PG  the solid box has had its center positioned at (0, 4, 0) and it is rotating about its center. Is this what you want to happen when positioning the center of the box?

4. In this PG  the wireframe box has had its local origin positioned at (4, 0, 0) and is rotating about its center. Is this what you want to happen when positioning the local origin of the box?

5. In this PG the wireframe box has had its local origin positioned at (4, 0, 0) and its pivot moved to the corner. Is this what you want to happen when positioning the local origin of the box and changing the pivot position?

For any question you have said no to using the box as an example please explain what you expect or want to happen with a diagram.

Share this post


Link to post
Share on other sites

I really need to keep left hand system because I have to make a lot of other meshes in code. So the questions wont really apply to this imported mesh.

I have made a simplified model in Inventor, exported to 3ds Max and then to .Babylon https://www.babylonjs-playground.com/#WFLKH#48

I realised it's not quite right on my models to use the absolute pivot position as the offset (x -z y) as this seems to be about 0.2 out of position which messes other code up later. This is why I was using set pivot 0,0,0 in World before 3.2.

As you can see on line 22 23 pivot 0,0,0 in World does not allow rotation around the centre in this situation.

I just want to be able to move the mesh around with the pivot in the middle! 😁

Sorry to be a pain.

Share this post


Link to post
Share on other sites
9 hours ago, JohnK said:

Does this PG now do what you want? If the answer is no I will need a more detailed description of the problem which you can give me by  answering the section below.

Sorry mssed the link out https://www.babylonjs-playground.com/#1MKHR9#58

On 5/16/2018 at 11:33 PM, captainleighwalker said:

The problem I'm having is the imported mesh seems to have y and z flipped also pivot point is actually 0,0,0 when importing and the position is negative,negative,negative so the following moves the mesh to a strange position because pivotAt is 0,0,0:

I was trying to answer this issue. Whether the system is left handed or fight handed the procedures I gave in my previous example still have the same behaviour. To help any further I really do need you to be clear and very specific about what you want to happen using the box as an example  and for this I need answers to the points I asked.

Share this post


Link to post
Share on other sites

Hi guys.

Hey, I got it centered-up.

https://www.babylonjs-playground.com/#WFLKH#50

What was the subject, again?  I forget.  :)

This pivot stuff has got us entangled, eh?

It might take a feature length movie-grade tutorial.

Is Yahoo Serious still around?  He seemed to have a good teaching mannerism... like when he taught us about beer atoms:)

He might do fine for... "BJS Pivots - The Movie"

Share this post


Link to post
Share on other sites

Actually, here's another... even MORE "squared-up with the world".

https://www.babylonjs-playground.com/#WFLKH#51

Look at lines 20 and 21.  Big beefy transformers... sucking that picture frame and its origin pivot... back into submission.  (choke hold)  :D

What's an 'origin'?  Whats a 'pivot point'?  When does a modeling package or exporter... get them confused?  hmm.

Butt yeah, that picture frame model was slid-sideways, a bit.  I chained it to my Cub Cadet... and pulled it on-stage, in front of the camera.  Perhaps shy?  :)

Update:  https://www.babylonjs-playground.com/#WFLKH#52

Even better!  Lines 20-26...   A pre-bake pivot-set, AND a post-bake pivot-set.  Wow!

Move the box, check the poz, move the piv, bake the box, move the piv, check the poz. 

Poz (position) for box... 0,0,0... dead center, squared-up with the world... +z-aiming cam, ground level, no rot.

It's best to do pivot experiments... with squared-up models... in squared-up scenes, eh?  *nod*

Share this post


Link to post
Share on other sites

Yes @Wingnut That's is what I was looking for. Sorry @JohnK not had time to get back to the questions.

I did work that out in my head Wingnut since I last posted. I realised I made the model in Inventor with bottom left corner at 0,0,0 in XY axis.

I centred the model in Max which obviously just applies a transom.

I realised all the verts are still at the original cords.

I think baking transforms makes life more simple then I don't need to worry about y and z after importing.

However since pivot and verts are all at the correct absolute position all I have to do is  box.bakeCurrentTransformIntoVertices(); and everything is normal!!!!

https://www.babylonjs-playground.com/#WFLKH#54

Thanks for your help, I think this case is closed!

Share this post


Link to post
Share on other sites

Sorry John... I butted-in while questions/answers were pending... my apologies on that.

I just got bored and curious about the 'origin' of that model.

See me editing on-the-fly, here, guys?  :D

Ya'll are watching me type and do rethinks.  heh

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.