Rotate a Importet Mesh will not Work Correctly

Hello,

I still use BabylonJS 3. We want to use Babylon as a kind of CAD viewer and I’m trying to write a compliant framework for our application. So far that works just fine, but now I’m not hanging on for 3 days and I’ve got a headache from it …

I’m trying to rotate an imported object around its own axis. And so that the position does not change.

Like here:
https://www.babylonjs-playground.com/#5XMZIB

If I want to use the same code for an imported mesh then do the same as here:
https://playground.babylonjs.com/#FCGDUB#1
(Shown in simplified form)

I despair of it and hope that you can help me …: slight_smile:

Yours sincerely
Daniel

Hopefully this is the issue and the solution Euler Angles and Quaternions - Babylon.js Documentation

hay, thanks.

But i’ve tried this before and it haven’t work yet :confused:

On mobile so cannot easily check playgrounds until later today. However playground is using version 4, so you are right and if issue is in playground it cannot be issue I linked to above.

Okay, thanks. :smiley:

Yeah it’s on Both… in my Code and Playground i have the same issues

Hi.

Did you check your mesh pivot position? Maybe it’s not properly centered within the mesh.

Yes i have.

When i show the Center Point like i do in the First example, the Dot is in the Center. After i use Rotation = Vector3(Rad(90))… All is moving out of the Middle :confused: And this is not only with the one mesh, it’s with all meshes even the Babylon meshes

I have Updated the Importet mesh to show how it look like

https://playground.babylonjs.com/#FCGDUB#3

I tried with the babylon box mesh and it works okay.

https://playground.babylonjs.com/#FCGDUB#5

I am not sure, you have to check this out somehow, but some time ago I was working with the mergeMesh function and I noticed that after the merging I cannot rotate the mesh properly. So maybe you have the same problem, maybe merge mesh somehow is breaking rotation functionality.

Try importing single object instead of that and test it out.

But as I said, I am really not sure and maybe I am completely wrong :smiley:

Hey thank you for the Request :smiley:
But unfortunately your Example is the same as mine First example ^^
With an createMesh it works fine. But i have to work with this what i get and this is a full .obj mesh. So i have to repair it with this :confused:

I am beginning to wonder if it your expectation of the final rotation given by the three options that is not fitting with the rotation seen. Here is a slightly simplified version of your PG. I have removed the ground and have applied a rotation around the y axis only.

https://playground.babylonjs.com/#FCGDUB#4

Comment out line 31and you will see the rotation of the rabbit as imported. You should then see that the rabbit was rotated 90deg as expected.

Perhaps have read of Position and Rotation - Babylon.js Documentation and Position and Rotation - Babylon.js Documentation

Thanks you Guy, one of you have postet but has delted it -> this WORKS - https://playground.babylonjs.com/#FCGDUB#6

So much day’s for this little bit… xD

Okay. I think I got it xD

https://playground.babylonjs.com/#FCGDUB#7

Idea is that you have to set pivot position after merging meshes into one. Because i believe that without that, pivot position is taken from the position of the pivot of the some mesh that existed before the merging (i really am not sure if this is the case);

So at the line 69-70 I simply set the pivot point at the center of the “fullObject”. And at the line 84 I’ve set camera.target also at the center of the mesh (otherwise the effect of the rotation looks wrong, delete this line to check it out);

I hope this works for you. :slight_smile:

1 Like

Ye, I’ve deleted it, I thought I found the solution but because camera target was somewhere else, I thought it wasn’t complete enough xD. But yes, that’s it.

1 Like

:smiley: Thank you very much!
I have prepare it a little bit cau’se i don’t use the fullObject by Natural. I use the Meshes and Combine it to full. But it’s all the same… :smiley:

function setPivotPosition(mesh, mergedMesh){
var info = mergedMesh.getBoundingInfo().boundingBox[“centerWorld”];
mesh.setPivotMatrix(BABYLON.Matrix.Translation(-info.x, -info.y, -info.z));
}

Thank you very much now i fell me much better !! :smiley:

2 Likes