Scale object in your editor scene?
Submitted by clemens on Wed, 2020/11/18 - 1:59pm
I want the assets imported from Blender or other sources fit my scene needs
For this we need to find the bound of the mesh and scale accordingly.
func rescale_mesh(object_to_scale):
var m:ArrayMesh = object_to_scale.mesh
var mins:Vector3 = Vector3()
var maxs:Vector3 = Vector3()
var faces = m.get_faces()
var first:bool = true
for face in faces:
if first:
first = false
mins = face
maxs = face
else:
mins.x = min(mins.x, face.x)
mins.y = min(mins.y, face.y)
mins.z = min(mins.z, face.z)
maxs.x = max(maxs.x, face.x)
maxs.y = max(maxs.y, face.y)
maxs.z = max(maxs.z, face.z)
var delta:Vector3 = maxs - mins
var scale = 1/max(delta.x,max(delta.y, delta.z))
object_to_scale.scale = Vector3(scale, scale, scale)