Jump to content

How to rotate PluginObject?


Recommended Posts

Replace the MOve code by this. If it is a param obj it will use SetEntityMatrix.



#Modified April 2017
#Modified June    2020
#Modified Nov.  2020, PatW
class Params(metaclass = Marionette.OrderedClass):
    this = Marionette.Node( 'Rotate' )
    this.SetDescription('This node will rotate a 2D or 3D object around "pCent" if provided. If not provided the object will be rotated about its center')
    #Input Ports
    input = Marionette.PortIn( vs.Handle(0), 'hObj')    
    input.SetDescription('The object to rotate')        
    rVec = Marionette.PortIn( (0,0,0) , 'vAng')
    rVec.SetDescription('It could be a 3D vector / Point3 in the Input category. The components x, y, z of the vector are the rotation angles around X, Y and Z-axis. Angles are in radians')
    center = Marionette.PortIn( (None), 'pCent')    
    center.SetDescription('The point to rotate about, optional')
    #OIP Controls
    #Output Ports
    output = Marionette.PortOut('hObj')
    output.SetDescription('The rotated object')

def RunNode(self):  
    r = self.Params.rVec.value           
    center = self.Params.center.value           
    obj = self.Params.input.value    
    path = vs.GetCustomObjectPath(obj)
    offset = (0,0,0)

    if center == None:
        center = vs.HCenter(obj)
        center = (center[0], center[1], 0)
    if path != vs.Handle(0):  
        (ok, offset, rotationXAngle, rotationYAngle, rotationZAngle) = vs.GetEntityMatrix(obj)                  
        obj = path    

    planar = Marionette.Is2DObject(obj)    
    cx = center[0] - offset[0]
    cy = center[1] - offset[1]
    cz = center[2] - offset[2]   
    if planar:        
        vs.HRotate(obj, (cx, cy), r[2])        
        if vs.GetTypeN(obj) == 86:
            bool, offset, rotationXAngle, rotationYAngle, rotationZAngle = vs.GetEntityMatrix(obj)
            vs.SetEntityMatrix(obj, offset, r[0], r[1], r[2])            
            vs.Set3DRot(obj, r[0], r[1], r[2], cx, cy, cz)  
    self.Params.output.value = obj



Edited by PatW
  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...