def export_camera(self): start, end = self.start.value(), self.end.value() path = Path(self.path.text()) # Validate the selection. sel = ls(selection=True, dagObjects=True, cameras=True) if not ls(selection=True): return error('No cameras in selection.') # Associate the camera shapes with their parents. cams = dict((s, s.getParent()) for s in sel) # Pull-out only the attributes that are checked. shape_atts = [] for cb in self.cameraChannelsLayout.findChildren(QCheckBox): if cb.isChecked(): [shape_atts.extend(str(cb.property(n).toString()).split('|')) \ for n in cb.dynamicPropertyNames() if n == 'shortName'] cam_atts = (cb.objectName() for cb \ in self.translation.findChildren(QCheckBox) if cb.isChecked()) attributes = (shape_atts, cam_atts) # Enable any locked or non-keyable channels. for shape, cam in cams.items(): for i, obj in enumerate((shape, cam)): for att in attributes[i]: obj.attr(att).set('locked', False) obj.attr(att).set('keyable', True) # Initialize the progress bar. lc = len(cams) self.progress_init(lc + lc * len([ x for x in (self.createStandIn.isChecked(), self.oneFile.isChecked() and self.oneFilePerNode.isChecked) if x ])) # Bake the keys to the camera shape. frame_range = self.animation.isChecked() and (start, end) or (start, ) for shape, cam in cams.items(): if self.aborted: return info('Baking keys to %s: %d-%d...' % \ ((shape,) + frame_range)) bakeResults(shape, time=frame_range, simulation=True, attribute=shape_atts) info('%s keys %d-%d baked.' % ((shape, ) + frame_range)) self.progress_step() # Disable the cycle check warning. cycleCheck(evaluation=False) # Create a null stand-in for the camera and bake keys to it. #mel.source('channelBoxCommand.mel') if self.createStandIn.isChecked(): for cam in cams.values(): if self.aborted: return stand_in = Transform(name='standInNull') parentConstraint(cam, stand_in, name='nullParentConstraint') info('Baking keys to the stand-in null...') bakeResults(stand_in, time=frame_range, shape=True, simulation=True, attribute=cam_atts) info('Null keys baked.') # If the camera is a child, parent it to the world. if cam.firstParent2(): cam.setParent(world=True) # Break existing connections between the rotate or translate # attributes. for att in cam_atts: if connectionInfo(cam, isExactDestination=True): disconnectAttr( connectionInfo(cam, getExactDestination=True)) #mel.CBdeleteConnection(getExactDestination=True) # Constrain the camera to the null. parentConstraint(stand_in, cam, name='cameraParentConstraint') # Bake the camera translate/rotate keys. info('Baking keys to the camera...') bakeResults(cam, time=frame_range, disableImplicitControl=True, simulation=True, attribute=cam_atts) info('Transform keys baked.') self.progress_step() # Remove excess elements unless optimize has been disabled. if self.optimize.isChecked(): info('Optimizing scene...') delete([s for s in ls(dagObjects=True) if s not in cams.keys() + \ cams.values() + ls(selection=True, type='animCurve')]) # Save-out the cameras. kwargs = dict(force=True, constructionHistory=False, channels=True, constraints=False, expressions=False, shader=False, type='mayaAscii') ext = str(self.formatExt.text()) if self.oneFile.isChecked(): if self.oneFilePerNode.isChecked(): for cam in cams.values(): if self.aborted: return select(cam) exportSelected(path / cam.name() + ext, **kwargs) self.progress_step() else: select(cams.values()) exportSelected(path / 'camera' + ext, **kwargs) else: error('Not implemented yet. Coming soon...')
def export_camera(self): start, end = self.start.value(), self.end.value() path = Path(self.path.text()) # Validate the selection. sel = ls(selection=True, dagObjects=True, cameras=True) if not ls(selection=True): return error('No cameras in selection.') # Associate the camera shapes with their parents. cams = dict((s, s.getParent()) for s in sel) # Pull-out only the attributes that are checked. shape_atts = [] for cb in self.cameraChannelsLayout.findChildren(QCheckBox): if cb.isChecked(): [shape_atts.extend(str(cb.property(n).toString()).split('|')) \ for n in cb.dynamicPropertyNames() if n == 'shortName'] cam_atts = (cb.objectName() for cb \ in self.translation.findChildren(QCheckBox) if cb.isChecked()) attributes = (shape_atts, cam_atts) # Enable any locked or non-keyable channels. for shape, cam in cams.items(): for i, obj in enumerate((shape, cam)): for att in attributes[i]: obj.attr(att).set('locked', False) obj.attr(att).set('keyable', True) # Initialize the progress bar. lc = len(cams) self.progress_init(lc + lc * len([x for x in (self.createStandIn.isChecked(), self.oneFile.isChecked() and self.oneFilePerNode.isChecked) if x])) # Bake the keys to the camera shape. frame_range = self.animation.isChecked() and (start, end) or (start,) for shape, cam in cams.items(): if self.aborted: return info('Baking keys to %s: %d-%d...' % \ ((shape,) + frame_range)) bakeResults(shape, time=frame_range, simulation=True, attribute=shape_atts) info('%s keys %d-%d baked.' % ((shape,) + frame_range)) self.progress_step() # Disable the cycle check warning. cycleCheck(evaluation=False) # Create a null stand-in for the camera and bake keys to it. #mel.source('channelBoxCommand.mel') if self.createStandIn.isChecked(): for cam in cams.values(): if self.aborted: return stand_in = Transform(name='standInNull') parentConstraint(cam, stand_in, name='nullParentConstraint') info('Baking keys to the stand-in null...') bakeResults(stand_in, time=frame_range, shape=True, simulation=True, attribute=cam_atts) info('Null keys baked.') # If the camera is a child, parent it to the world. if cam.firstParent2(): cam.setParent(world=True) # Break existing connections between the rotate or translate # attributes. for att in cam_atts: if connectionInfo(cam, isExactDestination=True): disconnectAttr(connectionInfo(cam, getExactDestination=True)) #mel.CBdeleteConnection(getExactDestination=True) # Constrain the camera to the null. parentConstraint(stand_in, cam, name='cameraParentConstraint') # Bake the camera translate/rotate keys. info('Baking keys to the camera...') bakeResults(cam, time=frame_range, disableImplicitControl=True, simulation=True, attribute=cam_atts) info('Transform keys baked.') self.progress_step() # Remove excess elements unless optimize has been disabled. if self.optimize.isChecked(): info('Optimizing scene...') delete([s for s in ls(dagObjects=True) if s not in cams.keys() + \ cams.values() + ls(selection=True, type='animCurve')]) # Save-out the cameras. kwargs = dict(force=True, constructionHistory=False, channels=True, constraints=False, expressions=False, shader=False, type='mayaAscii') ext = str(self.formatExt.text()) if self.oneFile.isChecked(): if self.oneFilePerNode.isChecked(): for cam in cams.values(): if self.aborted: return select(cam) exportSelected(path / cam.name() + ext, **kwargs) self.progress_step() else: select(cams.values()) exportSelected(path / 'camera' + ext, **kwargs) else: error('Not implemented yet. Coming soon...')
def __init__(self, *args, **kwargs): """ Flags: - stretchy_spine: ss (bool, default:True) If set, creates a stretchy spine system for the character. - stretchy_neck: sn (bool, default:True) If set, creates a stretchy neck system for the character. - stretchy_tail: st (bool, default:True) If set, creates a stretchy tail system for the character. - stretchy_appendage: sap (bool, default:True) If set, creates a stretchy appendage systems for any appendages on the character. - stretchy_arm: sa (bool, default:True) If set, creates a stretchy arm system for the character. - stretchy_leg: sl (bool, default:True) If set, creates a stretchy leg system for the character. - extra_shoulder_joints: eshj (bool, default:True) If set, creates a stretchy arm system for the character. - extra_forearm_joints: efj (bool, default:True) If set, creates a stretchy arm system for the character. - extra_hip_joints: ehj (bool, default:True) If set, creates a stretchy arm system for the character. - extra_knee_joints: eknj (bool, default:True) If set, creates a stretchy arm system for the character. """ #======================================# # Stretchy Settings #======================================# stretchy_spine = kwargs.pop('ss', kwargs.pop('stretchy_spine', False)) stretchy_neck = kwargs.pop('sn', kwargs.pop('stretchy_neck', False)) stretchy_tail = kwargs.pop('st', kwargs.pop('stretchy_tail', False)) stretchy_appendage = kwargs.pop( 'sap', kwargs.pop('stretchy_appendage', False)) stretchy_arm = kwargs.pop('sa', kwargs.pop('stretchy_arm', False)) stretchy_leg = kwargs.pop('sl', kwargs.pop('stretchy_leg', False)) super(Polyped, self).__init__(Root, *args, **kwargs) self.insert_bind_joints( Shoulder, kwargs.pop('ishj', kwargs.pop('insert_shoulder_joints', 0))) self.insert_bind_joints( Elbow, kwargs.pop('ifj', kwargs.pop('insert_forearm_joints', 3))) self.insert_bind_joints( Hip, kwargs.pop('ihj', kwargs.pop('insert_hip_joints', 0))) self.insert_bind_joints( Knee, kwargs.pop('iknj', kwargs.pop('insert_knee_joints', 0))) # Parent constraint each bind joint to the respective # drive joint. for cls, dj_list in self.drive_joints.items(): for i, dj in enumerate(dj_list): pc = parentConstraint(dj, self.bind_joints[cls][i]) pc.jtype = self.name_helper.jtypes[nt.ParentConstraint] pc.side = dj.side pc.side_sequence = dj.side_sequence pc.__name__ = dj.__name__ pc.name_sequence = dj.name_sequence self.rename_part(pc)
def __init__(self, *args, **kwargs): """ Flags: - stretchy_spine: ss (bool, default:True) If set, creates a stretchy spine system for the character. - stretchy_neck: sn (bool, default:True) If set, creates a stretchy neck system for the character. - stretchy_tail: st (bool, default:True) If set, creates a stretchy tail system for the character. - stretchy_appendage: sap (bool, default:True) If set, creates a stretchy appendage systems for any appendages on the character. - stretchy_arm: sa (bool, default:True) If set, creates a stretchy arm system for the character. - stretchy_leg: sl (bool, default:True) If set, creates a stretchy leg system for the character. - extra_shoulder_joints: eshj (bool, default:True) If set, creates a stretchy arm system for the character. - extra_forearm_joints: efj (bool, default:True) If set, creates a stretchy arm system for the character. - extra_hip_joints: ehj (bool, default:True) If set, creates a stretchy arm system for the character. - extra_knee_joints: eknj (bool, default:True) If set, creates a stretchy arm system for the character. """ #======================================# # Stretchy Settings #======================================# stretchy_spine = kwargs.pop('ss', kwargs.pop('stretchy_spine', False)) stretchy_neck = kwargs.pop('sn', kwargs.pop('stretchy_neck', False)) stretchy_tail = kwargs.pop('st', kwargs.pop('stretchy_tail', False)) stretchy_appendage = kwargs.pop('sap', kwargs.pop('stretchy_appendage', False)) stretchy_arm = kwargs.pop('sa', kwargs.pop('stretchy_arm', False)) stretchy_leg = kwargs.pop('sl', kwargs.pop('stretchy_leg', False)) super(Polyped, self).__init__(Root, *args, **kwargs) self.insert_bind_joints(Shoulder, kwargs.pop('ishj', kwargs.pop('insert_shoulder_joints', 0))) self.insert_bind_joints(Elbow, kwargs.pop('ifj', kwargs.pop('insert_forearm_joints', 3))) self.insert_bind_joints(Hip, kwargs.pop('ihj', kwargs.pop('insert_hip_joints', 0))) self.insert_bind_joints(Knee, kwargs.pop('iknj', kwargs.pop('insert_knee_joints', 0))) # Parent constraint each bind joint to the respective # drive joint. for cls, dj_list in self.drive_joints.items(): for i, dj in enumerate(dj_list): pc = parentConstraint(dj, self.bind_joints[cls][i]) pc.jtype = self.name_helper.jtypes[nt.ParentConstraint] pc.side = dj.side pc.side_sequence = dj.side_sequence pc.__name__ = dj.__name__ pc.name_sequence = dj.name_sequence self.rename_part(pc)