Пример #1
0
class Component(core.Component):
    """A Component that imports or references in a Maya file."""
    import_operation = 'Import'
    reference_operation = 'Reference'

    files = fields.ArrayField('files',
                              add_label_text='Add File',
                              display_name=False)
    container = fields.ContainerField('file',
                                      parent=files,
                                      container_view=FileView())
    operation = fields.CharField(
        'operation',
        choices=[import_operation, reference_operation],
        default=import_operation,
        help_text='Whether to import or reference the file.',
        parent=container)
    file_path = fields.FilePathField('file_path',
                                     filter='Maya Files (*.ma *.mb)',
                                     help_text='The Maya file path.',
                                     parent=container)
    namespace = fields.CharField(
        'namespace',
        help_text='The import or reference namespace.',
        parent=container)

    @classmethod
    def image_path(cls):
        return ':/fileOpen.png'

    def help_url(self):
        return 'https://github.com/chadmv/cmt/wiki/File-Component'

    def execute(self):
        for container in self.files:
            operation = container['operation'].value()
            file_path = container['file_path'].get_path()
            namespace = container['namespace'].value()

            flag = 'i' if operation == Component.import_operation else 'r'
            kwargs = {
                flag: True,
                'type': {
                    '.ma': 'mayaAscii',
                    '.mb': 'mayaBinary',
                    '.fbx': 'FBX',
                }[os.path.splitext(file_path.lower())[-1]]
            }
            if namespace:
                kwargs['namespace'] = namespace

            cmds.file(file_path, **kwargs)
Пример #2
0
class Component(core.Component):
    sphere_name = fields.CharField('sphere_name')
    radius = fields.FloatField('radius', default=1.0)

    def execute(self):
        cmds.polySphere(name=self.sphere_name.value(),
                        radius=self.radius.value())
Пример #3
0
class Component(core.Component):
    """A Component that generations a skeleton using the cmt.rig.skeleton serializer."""
    start_joint = fields.MayaNodeField('start_joint',
                                       help_text='The ik spline start joint.')
    end_joint = fields.MayaNodeField('end_joint',
                                     help_text='The ik spline end joint.')
    start_control = fields.MayaNodeField(
        'start_control', help_text='The control at the base of the spine.')
    end_control = fields.MayaNodeField(
        'end_control', help_text='The control at the top of the spine.')
    system_name = fields.CharField(
        'system_name',
        default='spine',
        help_text='The name of the system used with all the created nodes.')

    @classmethod
    def image_path(cls):
        return shortcuts.get_icon_path('spine')

    def execute(self):
        start_joint = self.start_joint.value()
        end_joint = self.end_joint.value()
        start_control = self.start_control.value()
        end_control = self.end_control.value()
        name = self.system_name.value()
        splineik.create_spine(start_joint, end_joint, start_control,
                              end_control, name)
Пример #4
0
 def __init__(self,
              start_joint='',
              end_joint='',
              start_control='',
              end_control='',
              name='spine',
              **kwargs):
     super(Component, self).__init__(**kwargs)
     self.start_joint = fields.MayaNodeField(
         name='Start Joint',
         value=start_joint,
         help_text='The ik spline start joint.')
     self.add_field(self.start_joint)
     self.end_joint = fields.MayaNodeField(
         name='End Joint',
         value=end_joint,
         help_text='The ik spline end joint.')
     self.add_field(self.end_joint)
     self.start_control = fields.MayaNodeField(
         name='Start Control',
         value=start_control,
         help_text='The control at the base of the spine.')
     self.add_field(self.start_control)
     self.end_control = fields.MayaNodeField(
         name='End Control',
         value=end_control,
         help_text='The control at the top of the spine.')
     self.add_field(self.end_control)
     self.system_name = fields.CharField(
         name='Name',
         value=name,
         help_text='The name of the system used with all the created nodes.'
     )
     self.add_field(self.system_name)
Пример #5
0
class Component(core.Component):
    """A Component that creates aimConstraints."""
    constraints = fields.ArrayField('constraints',
                                    add_label_text='Add Aim Constraint')
    container = fields.ContainerField('constraint',
                                      parent=constraints,
                                      container_view=AimConstraintView())
    drivers = fields.MayaNodeField('drivers',
                                   multi=True,
                                   help_text='The nodes to aim at.',
                                   parent=container)
    driven = fields.MayaNodeField('driven',
                                  help_text='The node to aim',
                                  parent=container)
    maintain_offset = fields.BooleanField('maintain_offset',
                                          default=True,
                                          parent=container)
    aim_vector = fields.VectorField('aim_vector',
                                    default=(1.0, 0.0, 0.0),
                                    parent=container)
    up_vector = fields.VectorField('up_vector',
                                   default=(0.0, 1.0, 0.0),
                                   parent=container)
    world_up_type = fields.CharField(
        'world_up_type',
        choices=['scene', 'object', 'objectrotation', 'vector', 'none'],
        default='object',
        parent=container)
    world_up_vector = fields.VectorField('world_up_vector',
                                         default=(0.0, 1.0, 0.0),
                                         parent=container)
    world_up_object = fields.MayaNodeField('world_up_object', parent=container)
    skip_x = fields.BooleanField('skip_x', parent=container)
    skip_y = fields.BooleanField('skip_y', parent=container)
    skip_z = fields.BooleanField('skip_z', parent=container)

    @classmethod
    def image_path(cls):
        return ':/aimConstraint.png'

    def execute(self):
        for container in self.constraints:
            drivers = container['drivers'].value()
            driven = container['driven'].value()
            skip = [
                x for x in 'xyz' if container['skip_{0}'.format(x)].value()
            ]
            cmds.aimConstraint(
                drivers,
                driven,
                maintainOffset=container['maintain_offset'].value(),
                aimVector=container['aim_vector'].value(),
                upVector=container['up_vector'].value(),
                worldUpType=container['world_up_type'].value(),
                worldUpVector=container['world_up_vector'].value(),
                worldUpObject=container['world_up_object'].value(),
                skip=skip)
Пример #6
0
class ContainerComponent(core.Component):
    spheres = fields.ArrayField('spheres')
    container = fields.ContainerField('sphere', parent=spheres)
    sphere_name = fields.CharField('sphere_name', parent=container)
    radius = fields.FloatField('radius', default=1.0, parent=container)

    def execute(self):
        for sphere in self.spheres:
            name = sphere['sphere_name'].value()
            radius = sphere['radius'].value()
            cmds.polySphere(name=name, radius=radius)
Пример #7
0
 def __init__(self, spheres=None, **kwargs):
     super(ContainerComponent, self).__init__(**kwargs)
     self.array_field = fields.ArrayField(name='spheres')
     self.add_field(self.array_field)
     if spheres is None:
         spheres = [{'sphere_name': 'sphere1'}]
     for sphere in spheres:
         container = fields.ContainerField(name='sphere')
         self.array_field.add_field(container)
         container.add_field(
             fields.CharField(name='Sphere Name',
                              value=sphere['sphere_name']))
         container.add_field(
             fields.FloatField(name='Radius',
                               value=sphere.get('radius', 1.0)))
Пример #8
0
 def __init__(self,
              file_path='',
              namespace='',
              operation=import_operation,
              **kwargs):
     super(Component, self).__init__(**kwargs)
     self.operation = fields.ChoiceField(
         name='Operation',
         choices=[
             Component.import_operation, Component.reference_operation
         ],
         value=operation,
         help_text='Whether to import or reference the file.')
     self.add_field(self.operation)
     self.file_path = fields.FilePathField(name='File Path',
                                           value=file_path,
                                           filter='Maya Files (*.ma *.mb)',
                                           help_text='The Maya file path.')
     self.add_field(self.file_path)
     self.namespace = fields.CharField(
         name='Namespace',
         value=namespace,
         help_text='The import or reference namespace.')
     self.add_field(self.namespace)
Пример #9
0
class Component(core.Component):
    """A Component that creates swingTwist nodes."""
    twist_axis = {
        0: 'X',
        1: 'Y',
        2: 'Z',
    }

    swingtwists = fields.ArrayField('swing_twists',
                                    add_label_text='Add SwingTwist',
                                    display_name=False)
    container = fields.ContainerField('swing_twist',
                                      parent=swingtwists,
                                      container_view=SwingTwistView())
    driver = fields.MayaNodeField('driver',
                                  help_text='The node to drive the swingtwist',
                                  parent=container)
    driven = fields.MayaNodeField('driven',
                                  help_text='The node to be driven',
                                  parent=container)
    name = fields.CharField(
        'name',
        default='swingTwist#',
        help_text='The name of the created swingTwist node.',
        parent=container)
    twist = fields.FloatField('twist',
                              default=1.0,
                              help_text='The twist amount',
                              min_value=-1.0,
                              max_value=1.0,
                              parent=container)
    swing = fields.FloatField('swing',
                              default=1.0,
                              help_text='The swing amount',
                              min_value=-1.0,
                              max_value=1.0,
                              parent=container)
    twist_axis = fields.CharField('twist_axis',
                                  default='X',
                                  choices=['X', 'Y', 'Z'],
                                  help_text='The twist axis',
                                  parent=container)

    @classmethod
    def image_path(cls):
        return shortcuts.get_icon_path('swingTwist')

    def execute(self):
        cmds.loadPlugin('cmt_py', qt=True)
        for container in self.swingtwists:
            driver = container['driver'].value()
            driven = container['driven'].value()
            if not cmds.objExists(driver) or not cmds.objExists(driven):
                logger.warning('{0} or {1} does not exist.'.format(
                    driver, driven))
                continue
            logger.info('Creating swingtwist on {0} from {1}'.format(
                driven, driver))
            name = container['name'].value()
            twist = container['twist'].value()
            swing = container['swing'].value()
            twist_axis = 'XYZ'.index(container['twist_axis'].value())
            cmds.swingTwist(driver,
                            driven,
                            name=name,
                            twist=twist,
                            swing=swing,
                            twistAxis=twist_axis)
Пример #10
0
 def __init__(self, sphere_name='', **kwargs):
     super(Component, self).__init__(**kwargs)
     self.sphere_name = fields.CharField(name='Sphere Name',
                                         value=sphere_name)
     self.add_field(self.sphere_name)
Пример #11
0
    def __init__(self, swing_twists=None, **kwargs):
        """Constructor
        :param swing_twists: A list of dictionaries describing the swingTwist nodes that need to be
                           created:
            {
                'driven': node,
                'driver': nodes,
                'name': name,
                'twist': 1.0,
                'swing': 0.2,
            }
        """
        super(Component, self).__init__(**kwargs)
        self.swingtwists = fields.ArrayField(name='Swing Twists',
                                             add_label_text='Add SwingTwist')
        self.add_field(self.swingtwists)
        if not swing_twists:
            # Create default entries if none specified
            swing_twists = [{'name': 'swingTwist#'}]
        twist_axes = self.twist_axis.values()
        twist_axes.sort()
        # The fields will be arranged in two row containers
        # [[driver, driven], [name, twist, swing, invertTwist, invertSwing, twistAxis]]
        for swingtwist in swing_twists:
            container = fields.ContainerField(
                name='Swing Twist',
                orientation=fields.ContainerField.vertical,
                stretch=True)
            self.swingtwists.add_field(container)

            row_container = fields.ContainerField(name='', border=False)
            container.add_field(row_container)
            row_container.add_field(
                fields.MayaNodeField(
                    name='Driver',
                    value=swingtwist.get('driver', ''),
                    help_text='The node to drive the swingtwist'))
            row_container.add_field(
                fields.MayaNodeField(name='Driven',
                                     value=swingtwist.get('driven', ''),
                                     help_text='The node to be driven'))

            row_container = fields.ContainerField(name='', border=False)
            container.add_field(row_container)
            row_container.add_field(
                fields.CharField(
                    name='Name',
                    value=swingtwist.get('name', 'swingTwist#'),
                    help_text='The name of the created swingTwist node.'))
            row_container.add_field(
                fields.FloatField(name='Twist',
                                  value=swingtwist.get('twist', 1.0),
                                  help_text='The twist amount',
                                  min_value=-1.0,
                                  max_value=1.0))
            row_container.add_field(
                fields.FloatField(name='Swing',
                                  value=swingtwist.get('swing', 1.0),
                                  help_text='The swing amount',
                                  min_value=-1.0,
                                  max_value=1.0))
            row_container.add_field(
                fields.ChoiceField(name='Twist Axis',
                                   value=Component.twist_axis[swingtwist.get(
                                       'twistAxis', 0)],
                                   choices=twist_axes,
                                   help_text='The twist axis'))