Jump to content

How to rotate PluginObject?


Nico_be

Recommended Posts

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

 

Quote

#Modified April 2017
#Modified June    2020
#Modified Nov.  2020, PatW
@Marionette.NodeDefinition
class Params(metaclass = Marionette.OrderedClass):
#APPEARANCE
    #Name
    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')

#BEHAVIOR
 
def RunNode(self):  
    #inputs
    r = self.Params.rVec.value           
    center = self.Params.center.value           
    obj = self.Params.input.value    
    
    #script
    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])        
    else:                                
        if vs.GetTypeN(obj) == 86:
            bool, offset, rotationXAngle, rotationYAngle, rotationZAngle = vs.GetEntityMatrix(obj)
            vs.SetEntityMatrix(obj, offset, r[0], r[1], r[2])            
        else:
            vs.Set3DRot(obj, r[0], r[1], r[2], cx, cy, cz)  
            
    #outputs
    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.

Guest
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...