def validate(self): """ Check the source and target, their plugs and the weights to see if they are compatible with each other. If they are the state will be returned as true, if not the state is false and and error message will be added. :return: Validation state :rtype: tuple """ # validate input if not self.source: return False, "Source doesn't exist!" elif not self.target: return False, "Target doesn't exist!" # get source weights sourceWeights = self.weightsToList(cmds.getAttr(self.source)) if not len(sourceWeights): return False, "Source contains no painted weights!" # validate vertex count sourceMesh = cmds.zQuery(self.source, mesh=True)[0] targetMesh = cmds.zQuery(self.target, mesh=True)[0] sourceCount = cmds.polyEvaluate(sourceMesh, vertex=True) targetCount = cmds.polyEvaluate(targetMesh, vertex=True) if sourceCount != targetCount: return False, "Source and Target vertex count are not the same!" return True, ""
def __init__(self, parent, node): super(ZivaAttachmentNodeItem, self).__init__(parent, node) self.setExpanded(False) source = cmds.zQuery(node, attachmentSource=True)[0] target = cmds.zQuery(node, attachmentTarget=True)[0] ZivaNodeItem(self, source, "source") ZivaNodeItem(self, target, "target") actions.PaintItem(self, node, "weights")
def extendWeightsWithDefaultValues(self, weights, reverse): """ :param list/tuple weights: :param bool reverse: :return: Extended weights :rtype: list """ # get mesh data mesh = cmds.zQuery(self.source, mesh=True)[0] vertices = cmds.polyEvaluate(mesh, vertex=True) # if the weight list is already as long as the amount of vertices # there is no to extend the list if len(weights) == vertices: return weights # create default weights list defaultWeights = [1 if not reverse else 0] * vertices # get set indices plugs = cmds.listAttr(self.source, multi=True) indices = [int(plug.split("[")[-1][:-1]) for plug in plugs] # update default weights with weights list for i, weight in zip(indices, weights): defaultWeights[i] = weight return defaultWeights
def __init__(self, parent, solver): super(TissuesItem, self).__init__(parent, text="tissues") self.setExpanded(True) # variable data = {} # get tissues meshes = cmds.zQuery(solver, mesh=True, type="zTissue") or [] meshes.sort() # filter tissues for m in meshes: p = cmds.listRelatives(m, parent=True) p = p[0] if p else "None" if p not in data.keys(): data[p] = [] data[p].append(m) # add tissues for container, meshes in data.iteritems(): # add parent parent = MeshTissueItem(self, container, meshes) parent.setExpanded(True)
def createLineOfAction(): """ Loop the current selection and see if a zFiber is connected to the object. If this is the case the zLineOfActionUtil function is used to create a curve based on the fiber direction. This curve is then renamed to reflect the name of the selection and the color is changed to red. :return: Created line of actions :rtype: list """ curves = [] selection = cmds.ls(sl=True) or [] for sel in selection: if not cmds.zQuery(sel, type="zFiber"): continue # create curve curveShape, fiber = cmds.zLineOfActionUtil(sel) # color curve cmds.setAttr("{0}.overrideEnabled".format(curveShape), 1) cmds.setAttr("{0}.overrideColor".format(curveShape), 13) # rename curve curve = cmds.listRelatives(curveShape, p=True)[0] curve = cmds.rename(curve, "{}_crv".format(path.getNiceName(sel))) curves.append(curve) return curves
def __init__(self, parent, node): super(MeshItem, self).__init__(parent) # variable self._search = node.lower() # add widgets widget = widgets.Node(self.treeWidget(), node) self.addWidget(widget) self.setIcon(0, QtGui.QIcon(icons.MESH_ICON)) # add types for t in NODE_TYPES: # validate node type w = NODE_TYPES_WRAPPER.get(t) if not w: continue # get nodes try: connections = cmds.zQuery(node, type=t) or [] connections.sort() except: continue # validate connections if not connections: continue # create node type container nodeTypes.ZivaNodeTypeItem(self, t, connections) # add line of actions # get fibers fibers = cmds.zQuery(node, type="zFiber") if not fibers: return # get attached line of actions lineOfActions = cmds.zQuery(fibers, lineOfAction=True) if not lineOfActions: return # add line of actions nodeTypes.ZivaNodeTypeItem(self, "zLineOfAction", lineOfActions)
def findGeometryByProximity(geo, r=0.25): """ Find geometry by proximity of provided geometry using a distance attribute. The solver that is attached the the provided geometry is found, from that solver all other geometry attached the the solver are checked if they are within proximity of the provided geometry. To speed up the checks first a check based on bounding box is done before using the zFindVerticesByProximity function to get the proximity on a vertex level. :param int/float r: :raise RuntimeError: If no solver is attached to the geometry """ # variable geometryInProximity = [geo] # get solver of first selected object solver = cmds.zQuery(geo, type="zSolver") or [] # validate solver if not solver: raise RuntimeError( "Select geometry that is attached to a Ziva solver!") # get attached meshes meshes = cmds.zQuery(solver, mesh=True) meshes.remove(geo) # loop meshes for mesh in meshes: # get overlapping bounding boxes if not intersect.intersectBoundingBox(geo, mesh, r): continue # get vertices by proximity if not cmds.zFindVerticesByProximity(geo, mesh, r=r): continue # add mesh to proximity meshes geometryInProximity.append(mesh) return geometryInProximity
def paint(self): """ Select the associated mesh and initialize the paint tools. """ # select mesh mesh = cmds.zQuery(self.node, mesh=True)[0] cmds.select(mesh) # set tool cmd = 'artSetToolAndSelectAttr("artAttrCtx", "{}")'.format(self.attr) mel.eval(cmd)
def update(self): # clear self.clear() # get node from widget node = self._widget.node # add types for t in NODE_TYPES: # validate node type w = NODE_TYPES_WRAPPER.get(t) if not w: continue # get nodes try: connections = cmds.zQuery(node, type=t) or [] connections.sort() except: continue # validate connections if not connections: continue # create node type container nodeTypes.ZivaNodeTypeItem(self, t, connections) # add line of actions # get fibers fibers = cmds.zQuery(node, type="zFiber") if not fibers: return # get attached line of actions lineOfActions = cmds.zQuery(fibers, lineOfAction=True) if not lineOfActions: return # add line of actions nodeTypes.ZivaNodeTypeItem(self, "zLineOfAction", lineOfActions)
def __init__(self, parent, solver): super(BonesItem, self).__init__(parent, text="bones") self.setExpanded(False) # get bones meshes = cmds.zQuery(solver, mesh=True, type="zBone") or [] meshes.sort() # add bones for m in meshes: item = mesh.MeshItem(self, m) item.setExpanded(True)
def setEnabledTissues(self, state): """ Loop all children of the container and set the zTissue node that is attached to the child nodes to the provided state. This function makes it easier to enable/disable large groups of tissues. :param bool state: """ with contexts.UndoChunk(): state = True if state == 2 else False num = self.childCount() for i in range(num): m = self.child(i) tissue = cmds.zQuery(m.widget.node, type="zTissue")[0] cmds.setAttr("{}.enable".format(tissue), state)
def __init__(self, parent, container, meshes): super(MeshTissueItem, self).__init__(parent, container) # variables states = [] # loop meshes for m in meshes: # add mesh item = mesh.MeshItem(self, m) item.setExpanded(True) # get tissue enabled state tissue = cmds.zQuery(m, type="zTissue")[0] states.append(cmds.getAttr("{}.enable".format(tissue))) # set checked default state self.widget.setChecked(all(states)) self.widget.stateChanged.connect(self.setEnabledTissues)
def createLineOfAction(transforms): """ Loop the provided transforms list see if a zFiber is connected to the object. If this is the case the zLineOfActionUtil function is used to create a curve based on the fiber direction. This curve is then renamed to reflect the name of the selection and the color is changed to red. :return: Created line of actions :rtype: list """ curves = [] for transform in transforms: # get name name = path.getNiceName(transform) name = "{}_crv".format(name) if cmds.objExists(name): continue if not cmds.zQuery(transform, type="zFiber"): continue # create curve curveShape, fiber = cmds.zLineOfActionUtil(transform) # color curve cmds.setAttr("{0}.overrideEnabled".format(curveShape), 1) cmds.setAttr("{0}.overrideColor".format(curveShape), 13) # rename curve curve = cmds.listRelatives(curveShape, p=True)[0] curve = cmds.rename(curve, name) curves.append(curve) return curves