# How do I set the global scale of an object in a transform hierachy?

 0 Maybe it will be helpful: ``````function GetParentScale(): Vector3 { var sf: Vector3 = Vector3.one; var parentTransform: Transform = null; if (thisTransform.parent) parentTransform = thisTransform.parent; while (parentTransform) { sf.x *= 1.0f / parentTransform.localScale.x; sf.y *= 1.0f / parentTransform.localScale.y; sf.z *= 1.0f / parentTransform.localScale.z; if (parentTransform.parent) { parentTransform = parentTransform.parent; } else { parentTransform = null; } } return sf; } function SetScale(globalScale: Vector3) { var parentGlobalScale: Vector3 = GetParentScale(); thisTransform.localScale.x = globalScale.x * parentGlobalScale.x; thisTransform.localScale.y = globalScale.y * parentGlobalScale.y; thisTransform.localScale.z = globalScale.z * parentGlobalScale.z; } `````` where thisTransform = gameObject.transform more ▼ answered Apr 18 '11 at 10:30 AM Alex 17 2 ● 1 ● 1 ● 1 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 It was much easier than I was making it out to be. The COLLADA matrices make complete sense if you decompose them and set the localPosition, localScale, and localRotation as follows: ``````Vector3 x = new Vector3((float)matrix[0], (float)matrix[4], (float)matrix[8]); Vector3 y = new Vector3((float)matrix[1], (float)matrix[5], (float)matrix[9]); Vector3 z = new Vector3((float)matrix[2], (float)matrix[6], (float)matrix[10]); float xScale = x.magnitude; float yScale = y.magnitude; float zScale = z.magnitude; newParentTrans.localPosition = new Vector3((float)matrix[3] * conversion, (float)matrix[7] * conversion, (float)matrix[11] * conversion); newParentTrans.localScale = new Vector3(xScale, yScale, zScale); Quaternion rotation = newParentTrans.rotation; rotation.SetLookRotation(z/zScale,y/yScale); newParentTrans.localRotation = rotation; `````` Because well-formed COLLADA files have one top-level element, you can rotate the entire scene by -90 deg around the x axis, if Z_UP is true. more ▼ answered Sep 18 '10 at 03:12 AM ikeo 136 ● 9 ● 11 ● 18 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x1331
x401
x151
x127

asked: Sep 14 '10 at 05:06 PM

Seen: 3574 times

Last Updated: Sep 16 '10 at 02:46 AM