Is that an imported Mesh? If so, easy enough, you only need to set your center of axis to the bottom left corner of the mesh and place your mesh at zero origin before exporting. Else, you need to define/redefine your pivot so that it is placed at bottom left of your mesh before rotating. Alternatively, you can parent it to a node that already has this pivot position. Next, rotate the parent.
I see. Well, I suppose the easiest would be to create a parent that will act as a pivot. Or make a pivot and displace the pivot on the mesh. I believe the parent solution might be more versatile to use. Your mesh would still have its pivot at initial if you want to make clones or instances. There’s not much of a difference in fact between one or the other solution. It might be just a matter of your preference.
Edit: Quickly did this very simple PG to illustrate the parent option. It would be about the same using a mesh.
In this scenario, you would still need to know of the width (or length) of your mesh because you need to be able to displace the parent (or pivot). Else if you do not know the width (or if it changes) you will need to rely on bounding boxes to make the calc.
However the boundybox does not give proper values after rotation, hence the x is not calculated properly. it should be calculated based on new width after rotation. any help there
This doesn’t look like my solution (which is a lot easier and also allows you to keep the pivot on the corner by parenting it to the ground and eventually attach other meshes to it).
Here you rely on bounding boxes and you need to account all axis. It looks like for the width you are basing on the groundWidth. But the width you want to account and divide by 2 on rotation is your test mesh (not the ground).
Edit: I also forgot to mention that the solution around the parenting (not relying on bounding boxes from vertices will also avoid any unwanted displacement on the other axis (in your case the Y axis).
I don’t know of your case and why you would choose this solution but if you do so, your imported meshes need to have their vertices and axis aligned (or you will spend your time adjusting these/hacking your own code)
Let me have a look at your PG, but meanwhile for the above, I’ll try to explain:
A parent is a new node (or call it a new ‘local/world origin’) for all meshes attached to it.
When you import a mesh, by default, it zeros at the world origin of the scene and it moves and rotates around it and offsets from it’s local origin (where you place the object axis).
When you attach the mesh to a parent, the local origin of the mesh is unchanged (the pivot/axis from the imported mesh are still at the same position) BUT this local origin now zeros at the parent position and rotation (not the world). Meaning that if you rotate or move the parent on its axis, the ‘child’ will come along with it. It will no longer depend from the world origin but only from the parent.
So, once you have positioned your child relative to the parent, you can use this parent to move and rotate the child around. And you can still offset or rotate your child from its parent. This is why in your case, it can be interesting to use a parent. You can place this parent at a corner of your ground and also parent it to your ground, so that when you rotate or move your ground, the child/parent node axis will always follow and remain placed at the corner of your ground. Next, by attaching your mesh to this parent/corner axis, you can master how your mesh rotates and re-positions relatively to this parent.
Edit: Here is your updated PG using the parenting solution:
Yup, I can see it. But then, what is it supposed to do? It seems like this one has 4 steps/iterations…
Edit: I’m sry, I don’t know if it should rotate vertically or invert on steps 3 and 4. May be you can do a mockup (very simple draw) of all 4 positions? or try to explain
Oh, I just luv it when people solve their own problems
In which case, would you mind to just tick the box solution on your own post to let the others know you have successfully managed to solve your issue? Thanks and have an amazing day
Hi @mawa , again need your help.
check this https://playground.babylonjs.com/#SHMC9A#1 , do you see custom mesh at the the both ends? I want to attach,
for top side, top left point of mesh to parent and then for bottom left point. how can i do this?