def getAnimationsFromScene(cls):
        """
        Loop over all transforms and that contain an export animation tag.
        Read the value of this tag and add it into a dictionary.

        :return: Exported animation from current scene
        :rtype: dict
        """
        # data variable
        data = {}

        # loop transforms
        for node in cmds.ls(transforms=True):
            # get plug
            plug = attributes.getPlug(node, ZIVA_ANIMATION)

            # validate plug
            if cmds.objExists(plug):
                # get character
                character = cmds.getAttr(plug)

                # add character to dictionary
                if character not in data.keys():
                    data[character] = []

                # add animation to dictionary
                data[character].append(cls(node, character))

        return data
 def startFrame(self):
     """
     :param int/float value:
     :return: Animation start frame
     :rtype: int/float
     """
     plug = attributes.getPlug(self.root, ZIVA_ANIMATION_START)
     return cmds.getAttr(plug)
 def transitionFrames(self):
     """
     :param int/float value:
     :return: Animation transition frames
     :rtype: int/float
     """
     plug = attributes.getPlug(self.root, ZIVA_ANIMATION_TRANSITION)
     return cmds.getAttr(plug)
 def endFrame(self):
     """
     :param int/float value:
     :return: Animation end frame
     :rtype: int/float
     """
     plug = attributes.getPlug(self.root, ZIVA_ANIMATION_END)
     return cmds.getAttr(plug)
    def _createSolverAnimation(self, animation):
        """
        Create solver animation. It handles the first frame jump and the
        substeps on the solver.

        :param AnimationExport animation:
        """
        # set animation start frame
        plug = attributes.getPlug(self.solver, "startFrame")
        cmds.setAttr(plug, animation.startFrame)

        # get solver mover plugs
        plugs = [
            attributes.getPlug(self.solver, attr)
            for attr in ZIVA_SOLVER_ATTRIBUTES
        ]

        # create first frame jump
        for frame in [animation.startFrame, animation.startFrame + 1]:
            # set time
            cmds.currentTime(frame)

            # position solver
            matrix = transforms.getWorldMatrixAtTime(animation.solver)
            cmds.xform(self.solver, ws=True, matrix=matrix)

            # set keyframes
            cmds.setKeyframe(plugs,
                             inTangentType="linear",
                             outTangentType="linear")

        # create sub step frame jump
        plug = attributes.getPlug(self.solver, "substeps")

        # set keyframes
        tangents = {"inTangentType": "linear", "outTangentType": "linear"}
        cmds.setKeyframe(plug, time=animation.startFrame + 2, **tangents)
        cmds.setKeyframe(plug,
                         time=animation.startFrame + 1,
                         value=1,
                         **tangents)
        cmds.setKeyframe(plug, time=animation.startFrame, value=1, **tangents)
def reverseFiberDirection(fiber):
    """
    Reverse the direction of the zFiber nodes end points.

    :param str fiber:
    :raise TypeError: When parsed node is not of type zFiber
    """
    if cmds.nodeType(fiber) != "zFiber":
        print TypeError("Parsed node is not of type zFiber!")

    plug = attributes.getPlug(fiber, "endPoints")
    weights = CopyWeights(plug, plug)
    weights.copy(reverse=True)
    def solver(self):
        """
        The solver parent group is used to drive the ziva solver with the
        snapping of the character created in the pre roll animation.

        :return: Solver parent
        :rtype: str/None
        """
        # the reason for looping through it's children rather than relying on
        # a link is that when exporting an alembic this link attribute
        # connection is not respected.
        for child in cmds.listRelatives(self.root, children=True):
            if cmds.objExists(attributes.getPlug(child, ZIVA_SOLVER_PARENT)):
                return child
    def _removeSolverAnimation(self):
        """
        Loop al keyframed attributes on the solver and delete any animation
        curves connected to it.
        """
        # remove animation curves from solver
        for attr in ZIVA_SOLVER_ATTRIBUTES + ["substeps"]:
            plug = attributes.getPlug(self.solver, attr)
            anim = cmds.listConnections(plug,
                                        type="animCurve",
                                        source=True,
                                        destination=False,
                                        skipConversionNodes=True)

            if anim:
                cmds.delete(anim)
    def removeAnimation(self):
        """
        Loop all meshes in the importer node and see if a blendshape node is
        connected. If this is the case remove the blendshape node.
        """
        # disable ziva solvers
        with contexts.DisableZivaSolvers():
            # set start frame of existing solver frame
            plug = attributes.getPlug(self.solver, "startFrame")
            frame = cmds.getAttr(plug)
            cmds.currentTime(frame)

            # remove animation
            self._removeAnimation()
            self._removeSolverAnimation()

        cmds.refresh()
        cmds.currentTime(frame)
    def _transferAnimation(self, animation):
        """
        Create a driving connection between matches of the animation and
        muscle rig. Meshes will be checked to see if they

        :param AnimationExport animation:
        """
        # get meshes
        sources = cmds.listRelatives(animation.root, allDescendents=True)
        targets = cmds.listRelatives(self.animation, allDescendents=True)

        # get meshes mappers
        mapper = {path.getName(t): t for t in targets}

        # loop source meshes
        for source in sources:
            # get target mesh
            name = path.getName(source)
            target = mapper.get(name)

            if not target:
                s = "DEBUG: transferAnimation | Unable to find target for {}!"
                print s.format(source)
                continue

            # get connections
            connections = cmds.listConnections(source,
                                               type="AlembicNode",
                                               plugs=True,
                                               connections=True,
                                               skipConversionNodes=True,
                                               source=True,
                                               destination=False) or []

            # do connections
            targetAttributes = [t.split(".", 1)[-1] for t in connections[::2]]
            sourcePlugs = connections[1::2]

            for sourcePlug, attr in zip(sourcePlugs, targetAttributes):
                targetPlug = attributes.getPlug(target, attr)
                cmds.connectAttr(sourcePlug, targetPlug, force=True)
Esempio n. 11
0
    def updateSelection(self):
        # filter selection
        sel = cmds.ls(sl=True)
        sel = selection.filterByZivaTypes(sel)
        node = sel[0] if sel else None

        # update
        self.plug.clear()

        # validate node
        if not node:
            self.plugUpdate.emit(None)
            return

        # get paintable plugs
        attrs = attributes.getZivaPaintableAttributes(node)
        plugs = [attributes.getPlug(node, a) for a in attrs]

        # add attributes
        self.plug.addItems(plugs)

        # emit plug
        plug = plugs[0] if plugs else None
        self.plugUpdate.emit(plug)
Esempio n. 12
0
 def transitionFrames(self, value):
     plug = attributes.getPlug(self.root, ZIVA_ANIMATION_TRANSITION)
     cmds.setAttr(plug, value)
Esempio n. 13
0
 def endFrame(self, value):
     plug = attributes.getPlug(self.root, ZIVA_ANIMATION_END)
     cmds.setAttr(plug, value)
Esempio n. 14
0
 def startFrame(self, value):
     plug = attributes.getPlug(self.root, ZIVA_ANIMATION_START)
     cmds.setAttr(plug, value)
Esempio n. 15
0
 def targetPlug(self):
     return attributes.getPlug(self.target, "weightList[0].weights")
Esempio n. 16
0
 def sourcePlug(self):
     return attributes.getPlug(self.source, "weightList[0].weights")