Selected polygon rotation [SOLVED]
-
On 23/03/2015 at 09:28, xxxxxxxx wrote:
Is it possible to get the selected polygon rotation and position?
Kinda like if u select a polygon in polygon-mode then u will get a new axis that represents the center position and rotation of the selected polygon. In the coordinates dialog u can see the values i need to get.
For example a sphere object:
I tried disconnecting all polygons and convert poly-groups to objects but then the axis stays on the rotation and position of the parent object
Also found GetModelingAxis() but that's C++ is there any workaround to get this working?
Or is it possible to get the rotation i need in another more mathematically way?Thanks,
Gianni -
On 24/03/2015 at 05:07, xxxxxxxx wrote:
I created a workaround to get the data. Its only a bit slow with a lot of polygons.
After mesh object is triangulated, disconnected without preserving groups and poly-groups to objects i run this script per triangle. It gives me what i was searching for. With some editing it will also work for non exploded poly-groups.
def triangleModelingAxis(object) : object.SetBit(c4d.BIT_ACTIVE); # sets active object doc.SetMode(c4d.Mpolygons) # sets editing mode sel = object.GetPolygonS(); # get selected polygons sel.DeselectAll(); # deselect them sel.Select(0); # select first poly c4d.CallCommand(431000009); # Align Workplane to Selection c4d.CallCommand(5168); # Add Plane c4d.CallCommand(1027593); # Locked Workplane c4d.CallCommand(431000007); # Reset Workplane to Y plane = doc.GetActiveObject(); # Get the plane object absRot = plane.GetAbsRot(); # Get plane rotation absPos = plane.GetAbsPos(); # Get plane position plane.Remove(); # remove te plane from scene sel.DeselectAll(); # deselect all polygons plane.DelBit(c4d.BIT_ACTIVE); # deselect plane object.SetBit(c4d.BIT_ACTIVE); # select object doc.SetMode(c4d.Mobject); # sets editing mode return absRot, absPos # returns data
Greets,
Gianni -
On 24/03/2015 at 06:41, xxxxxxxx wrote:
Hello Gianni,
this might be a faster approach.
The first is with calculating a new matrix for the polygon, the second takes advantage of the euler angles.
Hope this helps?
Best wishes
Martinimport c4d from c4d import utils def main() : #_______________________________ #validate object if not op : return if not op.IsInstanceOf(c4d.Opolygon) : return #_______________________________ #work on triangulated clone obj = op.GetClone() utils.SendModelingCommand(command=c4d.MCOMMAND_TRIANGULATE, list=[obj], doc=doc) #_______________________________ #choose a polygon poly = op.GetPolygon(80) if not poly : return print poly #_______________________________ #points edges in global space matr = op.GetMg() p0 = obj.GetPoint(poly.a)*matr p1 = obj.GetPoint(poly.b)*matr p2 = obj.GetPoint(poly.c)*matr e0 = p1 - p0 e1 = p2 - p1 #_______________________________ #calculate polygon specific matrix zfn = e0.Cross(e1).GetNormalized() xfn = c4d.Vector(0,1,0).Cross(zfn).GetNormalized() yfn = xfn.Cross(zfn).GetNormalized() newmatr = c4d.Matrix() newmatr.v1 = xfn newmatr.v2 = yfn newmatr.v3 = zfn newmatr.off = (p0 + p1 + p2)/3 #_______________________________ #or use euler angle for the rotation position = (p0 + p1 + p2)/3 zfn = e0.Cross(e1).GetNormalized() rotation = c4d.utils.VectorToHPB(zfn) #_______________________________ #test it cube = doc.SearchObject("Cube") ##set the new matrix #cube.SetMg(newmatr) ##or set rotation and position cube.SetAbsPos(position) cube.SetAbsRot(rotation) c4d.EventAdd() if __name__=='__main__': main()
-
On 25/03/2015 at 04:05, xxxxxxxx wrote:
Thanks Martin i'm incorporating your code now and its indeed alot faster
-
On 27/03/2015 at 10:13, xxxxxxxx wrote:
Hi,
I'll assume that the issue is solved, and will set the topic as such. However, I'll leave the topic open to new postings, in case any follow up is required.
Joey Gaspe
SDK Support Engineer