Rotating an imported Asset


I’ve imported a mesh using LoadAssetContainer and inserted it into the scene. Now, I couldn’t figure out how I could rotate the mesh. Tried different ways. Couldn’t achieve.

The playground link:


You almost did it.
Here is the PG -
(moved }); from line 16 to line 29 to close the function in proper place).
Now there is no problem to rotate the needed mesh -
Please note the console messages, physics part should be corrected a bit.

1 Like

But, I still don’t get the car to be in the right direction. What property should I rotate to make the car face front, while moving forward?

Well, I don’t know what is the “right direction” but you can change parameter values at line 18 in order to rotate the mesh
parent.rotate(new BABYLON.Vector3(0, 15, 0), BABYLON.Tools.ToRadians(0));

Yes, I tried that. Could you see the trunk of the jeep? That’s the back and the back has tail lights - red color. The car now moves forward with the tail lights at the front (which basically means the car is reversing, when accelerating). Could you help me correcting the right direction?

Also, I tried removing the physicsImpostor on the child meshes and this happens:

parent.rotate(new BABYLON.Vector3(0, 0.5, 0), BABYLON.Tools.ToRadians(180));
Example -

I’m running the same link - #10, but the object doesn’t seem to be in the forward direction.

I tried rotating the parent before the mesh linking loop - this allows you to adjust the direction in the scene

`       let orientation = 180;
        // change orientation to suit the direction of the car
        parent.rotation = new BABYLON.Vector3 (

The other thought I had was if you are making the asset, rotate it into the correct position before export.

It is definitely strange, but for me this example - - works correctly in Chrome and incorrectly in Opera and Firefox.
This - works incorrectly in Chrome and correctly in Opera and Firefox.

The model rotation in 180 degrees different in Chrome and Opera.
Chrome screenshot

Opera screenshot

Seems that first we need to simplify the question (get rid of physics for a while) in order to pinpoint the problem.

Thanks. So, to rotate a mesh, it’s parent has to be rotated first and then children should be added. Good to know.

I think for a start it would be good to have your locals set correctly on XYZ on your model. Why does your model look back in the first place? Then you can also change your inputs so that ‘forward goes forward’ etc… Finally if you set a parent, and want to act on the children, remember you have to work from your parent (or anchor, in case). But I think the first point here is that the vehicle (mesh) should have its axes set correctly from the start.

I believe you need to rotate and position the axes on your original model so that your imported model faces X (or Z) and doesn’t look back.

Honestly, yes the ‘fix’ works but I would rather urge to set the model correctly. Especially, since this is a vehicle not a house. In essence, it will always remain faulty by default and will require the fix. Knowing that physics are (heavily) involved in a vehicle’s behavior… again, make it right from the start and it will remain right (and also comprehensive)… this would be my advise.

1 Like

From a traditional 3D perspective, I could depend on the orientation or pivot of the mesh - ultimately children will inherit the transform of the parent. So if a mesh isn’t reset properly, it can hold values in it’s transform matrix that gets multiplied into the parent transform when linked. So @mawa 's suggestion would be where I’d look first.

Since child nodes have their own local coordinate space, it is relative to the parent rather than the world. So the parent transforms applied to an object will only traditionally propagate to the child after being linked. As @labris mentioned, the behaviour that is going on is odd so it would be good to get the physics out of the equation and see what happens before this is triggered with the raw asset so you can rule out this first part.

Let me just add this very personal note to you @mapkbalaji . You realize you picked a hard piece wanting to create a vehicle. Many have tried, in BJS and others (incl. Cyberpunk;), few have succeeded. Yes, it is BJS, yes we can do a lot of things, sometimes with just copy/pasting a bunch of code, but physics and physics for a vehicle remain. I have been working 15y. with the automotive industry and I think I can say that the physics of car are nothing easy to handle. So, I encourage you to continue of course. I believe we need people trying to push the boundaries, also in vehicle handling. May be, pay a visit to the other PGs, try to nurture and next enhance… You have chosen the long way my friend, I wish you GL…truly.

There is also a good way to get rid of all parent/child code part.
You can upload .babylon model into Sandbox and save as GLB file.
Here is node structure of your original .babylon model:

And here is the structure of GLB file:

As you see, there is already root node which is the main transform node for this model, so you don’t need to set it manually with the code.

Thanks @mawa. I’m just trying to create a simple arcade type game, where an object can be moved around the screen to explore the scene. Something like And yea, I’m a newbie in this world, and I wish to go a long way. Just learning to tackle some of the obstacles I face.

@labris Yea, I see that the glb groups the nodes into a root node. But, I’m having problem importing the glb into my scene. It gives an error:

Unable to import meshes from 'url: importMesh of undefined from undefined version: undefined, exporter version: undefinedimportMesh has failed JSON parse

I tried using assetsManager, Append, ImportMesh but all gives the same error. What am I doing wrong?

Cool. Thanks for sharing. Very nice and clean little arcade game and the car behaves pretty well. You certainly can achieve something like that with BJS. Still, it’s not all that simple. Quite a bit of work has been put into this but if you are motivated and with the help of the existing PGs, I guess you can make it :smiley: Let me/us know when done. I’m sure many people here would like to see more examples of vehicles. Have a great day,