Last active
August 29, 2015 13:56
-
-
Save yamahigashi/9309426 to your computer and use it in GitHub Desktop.
選択オブジェクトを cog の高さで整列する, calculate object's cog position in global #softimage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calc_cog_global_position(obj): | |
''' calculate objects cog position in global space. returns vector3 ''' | |
#x, y, z, b1, b2, b3 = Application.Selection(0).ActivePrimitive.Geometry.GetBoundingBox() | |
#v = XSIMath.CreateVector3(x, y, z) | |
if obj.ActivePrimitive.Geometry is not None: | |
x = obj.ActivePrimitive.Geometry.Points | |
v = XSIMath.CreateVector3() | |
for p in x: | |
v.Add( v, p.Position) | |
v.Scale(1.0 / x.Count, v) | |
res = XSIMath.MapObjectPositionToWorldSpace(obj.Kinematics.Global.Transform, v) | |
return res | |
else: | |
t = obj.Kinematics.Global.Transform | |
return XSIMath.CreateVector3(t.PosX, t.PosY, t.PosZ) | |
# sort by object height | |
x = sorted([x for x in Application.Selection], | |
key=lambda x: calc_cog_global_position(x).Y, | |
reverse=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment