我正在尝试准确旋转相同对象的轴,以将其进一步转换为实例。为此,我使用第一个多边形法线并将轴移动到对象的中心。但是,这仅适用于简单对象,并且几乎总是结果是不同的。如果我使用标准的Cinema 4D工具( 轴中心/对齐方式/法线 ),则轴将按其原样旋转。帮助请了解我错了。
import c4d
from c4d import utils, Vector
def Normal(obj):
polygon = obj.GetPolygon(0)
points = obj.GetAllPoints()
nbPolys = obj.GetPolygonCount()
normal = (points[polygon.a] - points[polygon.c]).Cross(points[polygon.b] - points[polygon.d])
normal.Normalize()
return normal
def MoveAxis(obj):
mg = obj.GetMg()
points = obj.GetAllPoints()
p_count = obj.GetPointCount()
if obj.GetUp() is None: n = obj.GetMg().off
else: n = Vector(0)
print obj.GetName(), 'Has Size : ', obj.GetRad()
obj.SetRelRot(utils.VectorToHPB(Normal(obj)))
obj.SetRelPos(obj.GetMp()+n)
new_mg = obj.GetMg()
for point in xrange(p_count):
obj.SetPoint(point,~new_mg*mg*points[point])
obj.Message(c4d.MSG_UPDATE)
def main():
objlist = doc.GetActiveObjects(True)
doc.StartUndo()
for obj in objlist:
doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
MoveAxis(obj)
doc.EndUndo()
c4d.EventAdd()
if __name__=='__main__':
main()