Skip to content

Instantly share code, notes, and snippets.

@yamahigashi
Created October 24, 2012 11:35
Show Gist options
  • Save yamahigashi/3945588 to your computer and use it in GitHub Desktop.
Save yamahigashi/3945588 to your computer and use it in GitHub Desktop.
オブジェクトに最寄りの頂点を返す #softimage
def get_closest_point(geo, obj, near_by=1):
'''return geo's vertex, that located closest obj position'''
g = geo.ActivePrimitive.Geometry
os_pos = get_local_positon_on_another(obj, geo)
cs = g.GetClosestLocations([os_pos.X, os_pos.Y, os_pos.Z])
pindex = g.GetPolygonIndexArray(cs)[0]
closest_polygon = g.Polygons(pindex)
t = []
polygons = closest_polygon.NeighborPolygons(near_by)
for poly in polygons:
for p in poly.Points:
x = abs(os_pos.X - p.position.X)
y = abs(os_pos.Y - p.position.Y)
z = abs(os_pos.Z - p.position.Z)
sum = x + y + z
t.append((abs(sum), p))
return min(t)[1]
def get_local_positon_on_another(obj, ano):
''' return another object's local position of obj. '''
ano_trs = ano.Kinematics.Global.Transform
tmp = obj.Kinematics.Global.Transform
po_pos = XSIMath.CreateVector3(tmp.PosX, tmp.PosY, tmp.PosZ)
return XSIMath.MapWorldPositionToObjectSpace(ano_trs, po_pos)
def get_point_global_position(point):
''' return point(vertex)'s global positon. '''
geo = point.Parent.Parent.Parent
geo_trs = geo.Kinematics.Global.Transform
return XSIMath.MapObjectPositionToWorldSpace(geo_trs, point.position)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment