Scale a nested game object

Hi everyone. I have an imported fbx mesh that has nested pivots and meshes.
I want to scale this object about a point, but not by using the scale function.
What I want is to move the pivots and the vertices of the mesh so that the result is the same I’d have by scaling in maya/blender and baking the transformation.
Can anyone help? Thanks.

Importer should have a scale setting. That’s effectively a baked scaling.
If you don’t want to use that setting, you either:

  1. use the dedicated modelling program,
  2. make a utility to rescale the mesh, which could be non-trivial, depending on the features of the model itself.

For the most part, it’s only a matter of going through the vertex list, and multiplying it with a couple of matrices, which you build with Matrix4x4.TRS.

For example, rescaling around a certain point X would involve repositioning mesh such that X falls onto the origin. Then applying a scale matrix, then applying the first matrix inversely, to get the mesh back where it was.

You can do this even without matrices, here’s one such example (not the best one, just to illustrate the point)

public Mesh RescaleMesh(Mesh source, Vector3 center, float scale = 1f) {
  var newMesh = new Mesh();
 
  var nv = new List<Vector3>();
  for(int i = 0; i < source.vertices.Length; i++) {
    var pt = source.vertices[i];
    nv.Add( (scale * (pt - center)) + center );
  }

  // you need to also copy and set everything else: triangles, uvs ...
 
  newMesh.SetVertices(nv, 0);

  return newMesh;
}