Transforming many meshes

Hi, I need to load few meshes, that are boxes and then change them size in X axis in world space. From some reasons i can’t use scaling so i have to modify mesh positions. But as you know meshes have them own spaces that are oriented (in my case) randomly in world space. So if change x-coordinates of mesh positions they changing them size in random directions. Do you have some ideas how to solve it?

Only solution that i see is to rotate meshes with axis, and then rotate back only them positions. Maybe you have something easier?

I am not seeing easier :slight_smile: Somebody else might like @JohnK, @jerome

not sure to understand what you’re trying to achieve …

Do you have a playground? Maybe I could help…

Hi Adam1, welcome to the forum.

WHAT IF… you DID use scaling… but then you could “reset” the scaling back-to 1,1,1 (default), and the mesh STAYED scaled? Would THAT work for your project?

See the “bake” commands in lines 27, 34, 41. A bakeCurrentTransformIntoVertices() ALSO resets the rotation AND position to 0,0,0. (see console numbers)

It is sort-of like… scale the mesh… but then remove all evidence that you did the scaling. :slight_smile: It does the same for mesh rotation and position values… resets them back to construction-defaults.

It is truly moving the vertices of the boxes… while maintaining box origin (pivot point) at worldSpace 0,0,0. Let’s rotate the boxes… see where their origin/pivots are located. (I moved center box -y a bit, before bake)

Yep, they are all positioned at world 0,0,0 after the bake, but their vertices positions (sometimes called “positionKind” values) have been “skewed” by our baking.

You CAN move the pivots back to center of mesh, if wanted. (setPivotPoint / setPivotMatrix)

I don’t know if this method of “reset the scaling” would work for your situation, but I thought I should mention it. Party on!

Hi, thank you for response. I already solved this case using my first idea.

First I rotate all meshes using this:

var orientation = BABYLON.Vector3.RotationFromAxis(BABYLON.Axis.X, BABYLON.Axis.Y, BABYLON.Axis.Z);
mesh.rotation = orientation;

Then I calculate angle beatwen local axis before and after rotation. Using rotation matrix and BABYLON.Vector3.TransformCoordinates() I moved positions and normals back.

It’s quite easy and works fast so I am happy with that solution.