In my previous thread I was asking about get_vertex() to get the pos of a models vertex in world coords...I was helped and figured it out, but now I have the problem that I need to get the scale of the objects as well, looking at the docs I only found global.transform.scaled(), but I either need the scale in the first place or a different method...I'm sure there has got to be a method to return the scale of an object...

short version: How do I return the scale of an object? : Vector3()

Scale is stored in the magnitude of each Vector3 in each of the Vector3s in the Basis, at least that is what I have observed. So, to get the scale, you need to do something like this:

var object_scale = Vector3(
	global_transform.basis.x.length(),
	global_transform.basis.y.length(),
	global_transform.basis.z.length())

Edit: After looking at the documentation, I found the get_scale method in Basis, which should do the same thing. :smile:


I'm not 100% sure if it will work, but if you want to convert a position from local/object space to global space, with the proper rotation, position, and scale adjustments applied, you can use global_transform.xform(position) or global_transform.xform_inv(position). I forget which one does what, but they convert from local/object space to world space, applying all of the changes in position, scale, rotation, etc.

I've used both functions in my Inverse Kinematics scripts, both the old FABRIK and the new one I'm working on, and it works great for converting. It might be something to look into if you have not tried it.

Thanks. "transform.basis.get_scale()" does return the scale... I don't know how I overlooked it...I've been going through things so quickly that it's completely possible I overlooked it...Either that, or, I'm being held back by my own paradigms....from using other software.

In any case, thank you.

EDIT: global_transform.xform(pos)# is less typing and easier to read than the next line...I also don't have to worry about hierarchy pos = global_transform.origin + (mdt.get_vertex(2) * get_parent().transform.basis.get_scale())

I just wanted to point to my posting about 3D transforms and physics: https://godotforums.org/discussion/18480/godot-3d-vector-physics-cheat-sheet#latest

That wouldn't answer your initial Post about scale though. If you can, I'd use scaling only when unavoidable. This mostly relates to (3d) collision shapes where scaling may lead to unexpected results. I first though that this was only true for godot 2.x but I at least read about problems also in Godot 3.x.

And now for something unrelated that nobody asked for: Here's an example tool script that "bakes" the scale of a ConvexPolygonShape (Collision) to Scale 1:

tool
extends CollisionShape

#Small Tool to apply the scale to a ConvexPolygonShape
# this results in a shape with scale 1,1,1 (and scaled point coordinates)
# Purpose is to avoid a scaled collision shape
#
# How to use:
#
#  #1: assign script to collision shape (with ConvexPolygonShape) with scale != (1,1,1)
#  #2: in the inspector check "Apply Scale Now"
#  #3: this should result in no visible changes except that the scale is now 1,1,1
#


export(bool) var applyScaleNow = false setget _apply_scale_now

func _apply_scale_now(newval):
	if newval:
		if shape!=null:
			if shape is ConvexPolygonShape:
				if (scale-Vector3(1,1,1)).length()>0.001: #scale not 1
					var scaledPts = shape.points
					for i in range(scaledPts.size()):
						#print(str(i)+": "+scaledPts[i]+" => "+scaledPts[i].dot(scale))
						scaledPts[i]=Vector3(scaledPts[i].x*scale.x,scaledPts[i].y*scale.y,\
											scaledPts[i].z*scale.z)
					shape.points=scaledPts
					scale=Vector3(1,1,1)
				else:
					print("Scale already 1,1,1")
				#shape.points (PoolVector3Array) passed by value
			else:
				print("For ConvexPolygonShape only")
		else:
			print("Collision shape unassigned...") 

scaling in my case is fine, there will be no collision or translation of the object(objects) I use this on...it's mostly for placing instances or particles(also instances). Thank you all the same :)

3 years later