1
\$\begingroup\$

I have a few objects with different scales i want to make a scene where all objects are scaled proportionally to everything else, something like a normalize function for a mesh.

How would I go about doing this? I have thought about traversing all the vertices, finding the min and maximum and dividing all vertices by the maximum?

I have also thought of traversing all vertices and normalizing them one by one, but I'm not sure it would solve it?

Edit: to reword the question, I want a door and a cup to be the same size. obviously a door will be much bigger than a cup, but I want to scale both such that they fit within a unit cube or a unit sphere.

Edit2: I want to achieve exactly this effect from the Nvidia Omniverse demo at around 1:17 he talks about the mesh and then proceeds to say that they normalize it. how do they do it!

\$\endgroup\$
2
  • \$\begingroup\$ Presumably you've considered looking at Mesh.bounds or Renderer.bounds? \$\endgroup\$
    – DMGregory
    Mar 30, 2022 at 16:26
  • \$\begingroup\$ The bounds will be different for the Door and the Cup, how do i scale both bounds such that they are equal size? \$\endgroup\$
    – GabeTheApe
    Mar 31, 2022 at 7:14

1 Answer 1

2
\$\begingroup\$

This is just simple division.

public static void ScaleLongestAxis(MeshFilter filter, float targetSize = 1f) {
   var size = filter.sharedMesh.bounds.size;
   float longest = Mathf.Max(size.x, size.y, size.z);
   float scaleFactor = targetSize/longest;
   filter.transform.localScale = new Vector3(scaleFactor, scaleFactor, scaleFactor);
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .