def on_orientJointsButton_clicked(self): undoInfo(openChunk=True) sel = selected() kwargs = {} if self.zeroScaleOrientCB.isChecked(): kwargs.update({'zeroScaleOrient': True}) if self.aimAxisNoneRadio.isChecked(): val = 'none' else: for i, radio in enumerate( (self.aimAxisXRadio, self.aimAxisYRadio, self.aimAxisZRadio)): if radio.isChecked(): xyz = 'xyz' if self.upAxisNoneRadio.isChecked(): val = xyz[i:] + xyz[:i] else: val = str(radio.text()).lower() for up_radio in (self.upAxisXRadio, self.upAxisYRadio, self.upAxisZRadio): if up_radio.isChecked(): val += str(up_radio.text()).lower() break for c in xyz: if c not in val: val += c break sao = self.worldUpYRadio.isChecked() and 'y' \ or self.worldUpZRadio.isChecked() and 'z' \ or upAxis(query=True, axis=True) sao += self.worldUpReverseCB.isChecked() \ and 'down' or 'up' kwargs.update({'secondaryAxisOrient': sao}) break reverse_aim = self.aimAxisReverseCB.isChecked() \ and Vector([val[1] == c for c in 'xyz']) * 180 or None reverse_up = self.upAxisReverseCB.isChecked() \ and Vector([val[0] == c for c in 'xyz']) * 180 or None for j in self.get_affected_joints(): if j.numChildren(): j.orientJoint(val, **kwargs) else: p = j.getParent() if p: delete(orientConstraint(p, j)) else: self.freeze(j, jointOrient=True) if self.zeroScaleOrientCB.isChecked(): j.zeroScaleOrient() if reverse_aim: self.tweak_joint_orientation(1, rotateAxis=reverse_aim) if reverse_up: self.tweak_joint_orientation(1, rotateAxis=reverse_up) select(sel) undoInfo(closeChunk=True)
def on_orientJointsButton_clicked(self): undoInfo(openChunk=True) sel = selected() kwargs = {} if self.zeroScaleOrientCB.isChecked(): kwargs.update({'zeroScaleOrient': True}) if self.aimAxisNoneRadio.isChecked(): val = 'none' else: for i, radio in enumerate((self.aimAxisXRadio, self.aimAxisYRadio, self.aimAxisZRadio)): if radio.isChecked(): xyz = 'xyz' if self.upAxisNoneRadio.isChecked(): val = xyz[i:] + xyz[:i] else: val = str(radio.text()).lower() for up_radio in (self.upAxisXRadio, self.upAxisYRadio, self.upAxisZRadio): if up_radio.isChecked(): val += str(up_radio.text()).lower() break for c in xyz: if c not in val: val += c break sao = self.worldUpYRadio.isChecked() and 'y' \ or self.worldUpZRadio.isChecked() and 'z' \ or upAxis(query=True, axis=True) sao += self.worldUpReverseCB.isChecked() \ and 'down' or 'up' kwargs.update({'secondaryAxisOrient': sao}) break reverse_aim = self.aimAxisReverseCB.isChecked() \ and Vector([val[1] == c for c in 'xyz']) * 180 or None reverse_up = self.upAxisReverseCB.isChecked() \ and Vector([val[0] == c for c in 'xyz']) * 180 or None for j in self.get_affected_joints(): if j.numChildren(): j.orientJoint(val, **kwargs) else: p = j.getParent() if p: delete(orientConstraint(p, j)) else: self.freeze(j, jointOrient=True) if self.zeroScaleOrientCB.isChecked(): j.zeroScaleOrient() if reverse_aim: self.tweak_joint_orientation(1, rotateAxis=reverse_aim) if reverse_up: self.tweak_joint_orientation(1, rotateAxis=reverse_up) select(sel) undoInfo(closeChunk=True)
def on_bufferButton_clicked(self): undoInfo(openChunk=True) for j in self.get_affected_joints(): buf = group(empty=True, world=True, name='BUF_' + j.nodeName()) p = j.getParent(1) if p: parent(buf, p) dupe = duplicate(j, renameChildren=True, returnRootsOnly=True)[0] snap(dupe, buf, space='object') delete(dupe) parent(j, buf) undoInfo(closeChunk=True)
def __new__(cls, **kwargs): s = super(Custom, cls).__new__(cls, **kwargs) transforms = ls(selection=True, transforms=True) for t in transforms: shapes = t.getShapes() if shapes: s.extend(shapes) elif isinstance(t, nt.Joint): s.append(t) xform(t, translation=(0, 0, 0)) else: # Delete empty transforms. delete(t) s.extend([n for n in ls(selection=True, shapes=True) if n not in s]) return s
def create_shapes(shape_cls=Plus, snaps=[], **kwargs): if not snaps: snaps = ls(selection=True, transforms=True) if snaps: return [shape_cls(snap_to=s) for s in snaps] verts = [v for v in ls(selection=True, flatten=True) if isinstance(v, MeshVertex)] [verts.extend(e.connectedVertices()) for e in ls(selection=True, flatten=True) \ if isinstance(e, MeshEdge)] if verts: verts = uniquify(verts) select(verts, replace=True) transform = cluster()[1] shape = shape_cls(snap_to=transform) delete(transform) return [shape] return [shape_cls()]
def freeze(self, node, **kwargs): sel = selected() kwargs['rotate'] = kwargs.pop('r', kwargs.pop('rotate', True)) kwargs['scale'] = kwargs.pop('s', kwargs.pop('scale', True)) skip_locked = kwargs.pop('skip_locked', True) # Unparent all the joint's children to prevent any locked # attribute errors. children = dict([(c, c.listRelatives(allParents=True)) \ for c in node.getChildren(type=['transform', 'joint'])]) [c.setParent(world=True) for c in children.keys()] # Unlock any locked rotate or scale attributes, save their # values for later and set them to zero for now, so they # aren't affected by the freeze. atts = {} for rs in ('rotate', 'scale'): if not kwargs[rs]: continue for axis in 'xyz': a = node.attr(rs[0] + axis) if a.isLocked(): atts[a] = a.get() a.unlock() if skip_locked: a.set(0) # Perform the freeze. select(node) makeIdentity(apply=True, **kwargs) # Restore and lock any rotate or scale attributes that # were locked before. for a, v in atts.items(): if skip_locked: a.set(v) a.lock() # Restore children to their original parents and delete any # automatically-generated parent buffers. for c, parents in children.items(): p = c.getParent() c.setParent(parents) if p: delete(p) select(sel)
def create_shapes(shape_cls=Plus, snaps=[], **kwargs): if not snaps: snaps = ls(selection=True, transforms=True) if snaps: return [shape_cls(snap_to=s) for s in snaps] verts = [ v for v in ls(selection=True, flatten=True) if isinstance(v, MeshVertex) ] [verts.extend(e.connectedVertices()) for e in ls(selection=True, flatten=True) \ if isinstance(e, MeshEdge)] if verts: verts = uniquify(verts) select(verts, replace=True) transform = cluster()[1] shape = shape_cls(snap_to=transform) delete(transform) return [shape] return [shape_cls()]
def createGizmo(self): ##All this needs to do is create a control square comprised of one transform and a bunch of shape objects parented to it. #First check to see if a gizmo exists that maybe got messed up or something. Delete that and recreate it if general.objExists("WaffleSliceGizmo"): general.delete("WaffleSliceGizmo") general.group(n = "WaffleSliceGizmo", em = True) _deleteArray = [] _shapesArray = [] _c = [] _c.append(modeling.nurbsSquare(n = "gizmoSquare1", nr = [0,0,1] ,c = [0, 0, 0], sl1 = 50, sl2 = 100)) _c.append(modeling.nurbsSquare(n = "gizmoSquare2", nr = [0,1,0] ,c = [0, 0, 0], sl1 = 100, sl2 = 50)) [general.parent(child, "WaffleSliceGizmo", r = True) for child in _c] for child in general.listRelatives("WaffleSliceGizmo", ad = True): if general.objectType(child)=="nurbsCurve": general.parent(child, "WaffleSliceGizmo", r = True, s = True) else: [general.delete(child) for child in general.listRelatives("WaffleSliceGizmo", type = "transform")] #WaffleSliceGizmo is the group that is created. Iterate through it, find a useable transform, get all the shapes, and assign #All the shapes to a transform general.delete("WaffleSliceGizmo", ch = True) general.select("WaffleSliceGizmo")
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 performSlice(self): #Make sure theres a gizmo, otherwise theres no point in doing anything if general.objExists("WaffleSliceGizmo"): #Get the step size and step count from the appropriate sliders step_size = windows.floatSliderGrp("stepSizeSlider", q = True, v = True) step_count = int(windows.floatSliderGrp("stepCountSlider", q = True, v = True)) #Get the axes filter from the radio buttons axes = windows.radioButtonGrp("axesRadioButtonGrp", q = True, sl = True) #Iterate through the selected objects and create an array of sliceable ones sliceArray = [] for child in general.ls(sl = True): if (child!="WaffleSliceGizmo"): #Make sure the selection is either a transform or mesh if (general.objectType(child)=="transform" or general.objectType(child)=="mesh"): sliceArray.append(child) else: #If anything was added to the array, then move forwards with the waffle slice if len(sliceArray)>0: #Create the slicing proxies that will push the proper transforms and rotates into the slice arguments general.group(n = "slice_proxy_x", em = True) general.xform("slice_proxy_x", t=[general.getAttr("WaffleSliceGizmo.translateX"), general.getAttr("WaffleSliceGizmo.translateY"), general.getAttr("WaffleSliceGizmo.translateZ"),] , ro = [general.getAttr("WaffleSliceGizmo.rotateX"), general.getAttr("WaffleSliceGizmo.rotateY"), general.getAttr("WaffleSliceGizmo.rotateZ"),] ,ws = True) general.group(n = "slice_proxy_y", em = True) general.xform("slice_proxy_y", t=[general.getAttr("WaffleSliceGizmo.translateX"), general.getAttr("WaffleSliceGizmo.translateY"), general.getAttr("WaffleSliceGizmo.translateZ"),] , ro = [general.getAttr("WaffleSliceGizmo.rotateX"), general.getAttr("WaffleSliceGizmo.rotateY"), general.getAttr("WaffleSliceGizmo.rotateZ"),] ,ws = True) general.rotate("slice_proxy_y", (90, 0, 0), r = True, os = True) general.parent("slice_proxy_x", "WaffleSliceGizmo") general.parent("slice_proxy_y", "WaffleSliceGizmo") #Iterate through the list of objects for child in sliceArray: #Move the slicers by half of the total distance they're going to need to slice through general.move("slice_proxy_x", [0,0,(-1*((step_size*step_count)/2))] , r = True, ls = True)#, z = True) general.move("slice_proxy_y", [0, (-1*((step_size*step_count)/2)),0], r = True, ls = True)#, y = True) #Get the options for x, y, or both #Do the slices, and for each iteration, bump each proxy forwards by their allotted amount for i in range(step_count): if (axes == 1 or axes == 3): general.move("slice_proxy_x", [0, 0, step_size] , r = True, ls = True)#, z = True) pos = general.xform("slice_proxy_x", ws = True, q = True, t = True) rot = general.xform("slice_proxy_x", ws = True, q = True, ro = True) modeling.polyCut(child, ro = rot , pc = pos) general.delete(child, ch = True) if (axes == 2 or axes == 3): general.move("slice_proxy_y", [0, step_size, 0], r = True, ls = True)#, y = True) pos = general.xform("slice_proxy_y", ws = True, q = True, t = True) rot = general.xform("slice_proxy_y", ws = True, q = True, ro = True) modeling.polyCut(child, ro = rot , pc = pos) general.delete(child, ch = True) else: #Reset the position of the proxies after each object so they dont fly off into the distance general.xform("slice_proxy_x", t=[general.getAttr("WaffleSliceGizmo.translateX"), general.getAttr("WaffleSliceGizmo.translateY"), general.getAttr("WaffleSliceGizmo.translateZ"),] , ws = True) general.xform("slice_proxy_y", t=[general.getAttr("WaffleSliceGizmo.translateX"), general.getAttr("WaffleSliceGizmo.translateY"), general.getAttr("WaffleSliceGizmo.translateZ"),] , ws = True) else: #Clean up the slice proxies general.delete("slice_proxy_x") general.delete("slice_proxy_y") else: print("No slice gizmo")
def deleteGizmo(self): if general.objExists("WaffleSliceGizmo"): general.delete("WaffleSliceGizmo")