Rotate a Importet Mesh will not Work Correctly


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:

If I want to use the same code for an imported mesh then do the same as here:
(Shown in simplified form)

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

Yours sincerely

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


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

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

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.

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 -

So much day’s for this little bit… xD

Okay. I think I got it xD

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 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: