Example #1
0
    def setNodeDatum(cls, node, value):
        """ Sets the numeric datum value, creating the attribute if not already
            defined. """

        if not cmds.attributeQuery('datum', node=node, exists=True):
            cmds.addAttr(
                node,
                longName='cadence_datum',
                shortName='datum',
                niceName='Datum')

        cmds.setAttr(node + '.datum', value)
Example #2
0
    def build(cls):
        prints = cls.getTargets(2)
        if not prints or len(prints) < 2:
            return False

        prev = prints[0]
        for p in prints[1:]:
            if not cmds.attributeQuery(cls._PREVIOUS_PRINT_ATTR, node=p, exists=True):
                cmds.addAttr(longName=cls._PREVIOUS_PRINT_ATTR, attributeType='message')

            prevs = cls.getPrevious(p)
            if not prevs or prev not in prevs:
                cmds.connectAttr(prev + '.message', p + '.' + cls._PREVIOUS_PRINT_ATTR, force=True)

            prev = p

        return True
Example #3
0
    def setNodeLinks(cls, node, prev, next):
        """ Sets up two attributes, prev and next, that directly link the given
            node to its previous and next nodes. """

        if not cmds.attributeQuery('prevNode', node=node, exists=True):
            cmds.addAttr(
                node,
                longName='cadence_prevNode',
                shortName='prevNode',
                dataType='string',
                niceName='PrevNode')

        if not cmds.attributeQuery('nextNode', node=node, exists=True):
            cmds.addAttr(
                node,
                longName='cadence_nextNode',
                shortName='nextNode',
                dataType='string',
                niceName='NextNode')

        if prev:
            cmds.setAttr(node + '.prevNode', prev, type='string')
        if next:
            cmds.setAttr(node + '.nextNode', next, type='string')
Example #4
0
    def createToken(cls, uid, props, trackSetNode =None):
        """ A token is created, provided with some additional Maya attributes,
            and placed in the scene. Tokens are functtionally similar to
            TrackNodes, but with different shapes and attributes. """

        cylinderHeight = 5.0
        coneHeight     = 10.0

        if not trackSetNode:
            trackSetNode = TrackSceneUtils.getTrackSetNode()

        if not trackSetNode:
            return None

        node = cls.getTrackNode(uid, trackSetNode=trackSetNode)

        if node:
            return node

        # determine whether left or right, and manus or pes, from name
        name = props['name'] if props else None
        if not name:
            print('createToken:  No properties specified')
            return
        # remove '_proxy' or '_token' if present (as in S6_LP3_proxy)
        nameFields = cls.decomposeName(name.split('_')[0])
        isLeft     = nameFields['left']
        isPes      = nameFields['pes']

        # make a cone for the token of an proxy else a cylinder
        if uid.endswith('_proxy'):
            node = cmds.polyCone(
                radius=0.5,
                height=coneHeight,
                subdivisionsX=10,
                subdivisionsY=1,
                subdivisionsZ=1,
                axis=(0, 1, 0),
                createUVs=0,
                constructionHistory=0,
                name='Token_0')[0]
            cmds.move(0, 0.5 * coneHeight, 0)
        else:
            node = cmds.polyCylinder(
                radius=0.5,
                height=cylinderHeight,
                subdivisionsX=10,
                subdivisionsY=1,
                subdivisionsZ=1,
                subdivisionsCaps=0,
                axis=(0, 1, 0),
                createUVs=0,
                constructionHistory=0,
                name='Token_0')[0]
            cmds.move(0, 0.5 * cylinderHeight, 0)

        # Set up the basic cadence attributes
        cmds.addAttr(longName='cadence_dx', shortName='dx', niceName='DX')
        cmds.addAttr(longName='cadence_dy', shortName='dy', niceName='DY')

        cmds.addAttr(
             longName='cadence_uniqueId',
             shortName='track_uid',
             dataType='string',
             niceName='UID')

        cmds.addAttr(
             longName='cadence_name',
             shortName='token_name',
             dataType='string',
             niceName='Name')

        # Disable some transform attributes
        cmds.setAttr(node + '.rotateX',    lock=True)
        cmds.setAttr(node + '.rotateZ',    lock=True)
        cmds.setAttr(node + '.scaleY',     lock=True)
        cmds.setAttr(node + '.translateY', lock=True)

        # Scale the cylinder/cone in x and z to represent 'dy' and 'dx' in
        # centimeters. There is a change of coordinates between Maya (X, Z) and
        # the simulator (X, Y) space. For example, for the right manus:
        #    x = int(100*float(entry['rm_y']))
        #    z = int(100*float(entry['rm_x']))
        # and likewise for dx and dy.

        # the DX and DY attributes affect scaleZ and scaleX in the node
        cmds.connectAttr(node + '.dx', node + '.scaleZ')
        cmds.connectAttr(node + '.dy', node + '.scaleX')

        # add a short annotation based on the name
        annotation = cmds.annotate(node, text=cls.shortName(props['name']))
        cmds.select(annotation)
        aTransform = cmds.pickWalk(direction='up')[0]

        # control it's position by that of the node, so that it stays 15 cm
        # above the pes and 10 cm above the manus
        if isPes:
            cmds.move(0.0, 15.0, 0.0, aTransform)
        else:
            cmds.move(0.0, 10.0, 0.0, aTransform)

        cmds.connectAttr(node + '.translateX', aTransform + '.translateX')
        cmds.connectAttr(node + '.translateZ', aTransform + '.translateZ')

        # and make it non-selectable
        cmds.setAttr(aTransform + '.overrideEnabled', 1)
        cmds.setAttr(aTransform + '.overrideDisplayType', 2)
        cmds.rename(aTransform, "TokenAnnotation_0")

        if isPes:
            if isLeft:
                color = TrackwayShaderConfig.LEFT_PES_TOKEN_COLOR
            else:
                color = TrackwayShaderConfig.RIGHT_PES_TOKEN_COLOR
        else:
            if isLeft:
                color = TrackwayShaderConfig.LEFT_MANUS_TOKEN_COLOR
            else:
                color = TrackwayShaderConfig.RIGHT_MANUS_TOKEN_COLOR
        ShadingUtils.applyShader(color, node)

        cmds.select(node)
        # add the new node to the Cadence track set
        cmds.sets(node, add=trackSetNode)

        # finally, initialize all the properties from the dictionary props
        cls.setTokenProps(node, props)

        return node
Example #5
0
    def createTrackNode(cls, uid, trackSetNode =None, props =None):
        """ A track node consists of a triangular pointer (left = red, right =
            green) which is selectable but only allows rotateY, translateX, and
            translateZ. The node has a child, a transform called inverter, which
            serves to counteract the scaling in x and z that is applied to the
            triangular node.  There are two orthogonal rulers (width and
            length).  Width and length uncertainty is represented by rectangular
            bars at the ends of the rulers.  In Maya one can directly adjust
            track position (translateX and translateZ) and orientation
            (rotationY); other attributes are adjusted only through the UI. """

        if not trackSetNode:
            trackSetNode = TrackSceneUtils.getTrackSetNode()

        if not trackSetNode:
            return None

        node = cls.getTrackNode(uid, trackSetNode=trackSetNode)
        if node:
            return node

        # Set up dimensional constants for the track node
        nodeThickness  = 1.0
        thetaBreadth   = 0.1
        thetaThickness = 0.5
        barBreadth     = 2.0
        barThickness   = 0.5
        rulerBreadth   = 1.0
        rulerThickness = 0.25
        epsilon        = 1.0

        # Create an isoceles triangle pointer, with base aligned with X, and
        # scaled by node.width.  The midpoint of the base is centered on the
        # 'track center' and the altitude extends from that center of the track
        # 'anteriorly' to the perimeter of the track's profile (if present, else
        # estimated).  The node is scaled longitudinally (in z) based on the
        # distance zN (the 'anterior' length of the track, in cm).  The triangle
        # is initially 1 cm on a side.
        sideLength = 1.0
        node = cmds.polyPrism(
            length=nodeThickness,
            sideLength=sideLength,
            numberOfSides=3,
            subdivisionsHeight=1,
            subdivisionsCaps=0,
            axis=(0, 1, 0),
            createUVs=0,
            constructionHistory=0,
            name='Track0')[0]

        # Point the triangle down the +Z axis
        cmds.rotate(0.0, -90.0, 0.0)

        # push it down below ground level so that the two rulers are just
        # submerged, and scale the triangle in Z to match its width (1 cm) so it
        # is ready to be scaled
        cmds.move(0, -(nodeThickness/2.0 + rulerThickness), math.sqrt(3.0)/6.0)

        # move the node's pivot to the 'base' of the triangle so it scales
        # outward from that point
        cmds.move(
            0, 0, 0, node + ".scalePivot", node + ".rotatePivot", absolute=True)
        cmds.scale(2.0/math.sqrt(3.0), 1.0, 100.0)
        cmds.makeIdentity(
            apply=True,
            translate=True,
            rotate=True,
            scale=True,
            normal=False)

        # Set up the cadence attributes
        cmds.addAttr(
             longName='cadence_width',
             shortName=TrackPropEnum.WIDTH.maya,
             niceName='Width')
        cmds.addAttr(
             longName='cadence_widthUncertainty',
             shortName=TrackPropEnum.WIDTH_UNCERTAINTY.maya,
             niceName='Width Uncertainty')
        cmds.addAttr(
             longName='cadence_length',
             shortName=TrackPropEnum.LENGTH.maya,
             niceName='Length')
        cmds.addAttr(
             longName='cadence_lengthUncertainty',
             shortName=TrackPropEnum.LENGTH_UNCERTAINTY.maya,
             niceName='Length Uncertainty')
        cmds.addAttr(
             longName='cadence_lengthRatio',
             shortName=TrackPropEnum.LENGTH_RATIO.maya,
             niceName='Length Ratio')
        cmds.addAttr(
             longName='cadence_rotationUncertainty',
             shortName=TrackPropEnum.ROTATION_UNCERTAINTY.maya,
             niceName='Rotation Uncertainty')
        cmds.addAttr(
             longName='cadence_uniqueId',
             shortName=TrackPropEnum.UID.maya,
             dataType='string',
             niceName='Unique ID')

        # Construct a ruler representing track width, then push it down just
        # below ground level, and ake it non-selectable.  Drive its scale by the
        # node's width attribute.
        widthRuler = cmds.polyCube(
            axis=(0, 1, 0),
            width=100.0,
            height=rulerThickness,
            depth=rulerBreadth,
            subdivisionsX=1,
            subdivisionsY=1,
            createUVs=0,
            constructionHistory=0,
            name='WidthRuler')[0]

        # Push it down to just rest on the triangular node (which is already
        # submerged by the thickness of the ruler and half the node thickness.
        cmds.move(0.0, -rulerThickness/2.0, 0.0)
        cmds.setAttr(widthRuler + '.overrideEnabled', 1)
        cmds.setAttr(widthRuler + '.overrideDisplayType', 2)

        # Construct a ruler representing track length and push it down the same
        # as the width ruler, and make it non-selectable.  Its length will be
        # driven by the node's length attribute.
        lengthRuler = cmds.polyCube(
            axis=(0, 1, 0),
            width=rulerBreadth,
            height=rulerThickness,
            depth=100.0,
            subdivisionsX=1,
            subdivisionsY=1,
            createUVs=0,
            constructionHistory=0,
            name='LengthRuler')[0]
        cmds.move(0.0, -rulerThickness/2.0, 0.0)
        cmds.setAttr(lengthRuler + '.overrideEnabled', 1)
        cmds.setAttr(lengthRuler + '.overrideDisplayType', 2)

        # Now construct 'error bars' to the North, South, West, and East of the
        # node, to visualize uncertainty in width (West and East bars) and
        # length (North and South bars), and push them just below ground level,
        # and make them non-selectable.
        barN = cmds.polyCube(
            axis=(0,1,0),
            width=barBreadth,
            height=barThickness,
            depth=100.0,
            subdivisionsX=1,
            subdivisionsY=1,
            createUVs=0,
            constructionHistory=0,
            name='BarN')[0]
        cmds.move(0, -(barThickness/2 + rulerThickness), 0)
        cmds.setAttr(barN + '.overrideEnabled', 1)
        cmds.setAttr(barN + '.overrideDisplayType', 2)

        barS = cmds.polyCube(
            axis=(0, 1, 0),
            width=barBreadth,
            height=barThickness,
            depth=100.0,
            subdivisionsX=1,
            subdivisionsY=1,
            createUVs=0,
            constructionHistory=0,
            name='BarS')[0]
        cmds.move(0, -(barThickness/2 + rulerThickness), 0)
        cmds.setAttr(barS + '.overrideEnabled', 1)
        cmds.setAttr(barS + '.overrideDisplayType', 2)

        barW = cmds.polyCube(
            axis=(0, 1, 0),
            width=100.0,
            height=barThickness,
            depth=barBreadth,
            subdivisionsX=1,
            subdivisionsY=1,
            createUVs=0,
            constructionHistory=0,
            name='BarW')[0]
        cmds.move(0, -(barThickness/2 + rulerThickness), 0)
        cmds.setAttr(barW + '.overrideEnabled', 1)
        cmds.setAttr(barW + '.overrideDisplayType', 2)

        barE = cmds.polyCube(
            axis=(0, 1, 0),
            width=100.0,
            height=barThickness,
            depth=barBreadth,
            subdivisionsX=1,
            subdivisionsY=1,
            createUVs=0,
            constructionHistory=0,
            name='BarE')[0]
        cmds.move(0, -(barThickness/2 + rulerThickness), 0)
        cmds.setAttr(barE + '.overrideEnabled', 1)
        cmds.setAttr(barE + '.overrideDisplayType', 2)

        # Create two diverging lines that indicate rotation uncertainty (plus
        # and minus), with their pivots placed so they extend from the node
        # center, and each is made non-selectable.  First make the indicator of
        # maximum (counterclockwise) estimated track rotation
        thetaPlus = cmds.polyCube(
            axis=(0, 1, 0),
            width=thetaBreadth,
            height=thetaThickness,
            depth=1.0,
            subdivisionsX=1,
            subdivisionsY=1,
            createUVs=0,
            constructionHistory=0,
            name='ThetaPlus')[0]
        cmds.setAttr(thetaPlus + '.overrideEnabled',     1)
        cmds.setAttr(thetaPlus + '.overrideDisplayType', 2)

        # Next, construct the indicator of the minimum (clockwise) estimate of
        # track rotation
        thetaMinus = cmds.polyCube(
            axis=(0, 1, 0),
            width=thetaBreadth,
            height=thetaThickness,
            depth=1.0,
            subdivisionsX=1,
            subdivisionsY=1,
            createUVs=0,
            constructionHistory=0,
            name='ThetaMinus')[0]
        cmds.setAttr(thetaMinus + '.overrideEnabled',     1)
        cmds.setAttr(thetaMinus + '.overrideDisplayType', 2)

        # The two width 'error bars' will be translated outward from the node
        # center.  First, the width attribute is converted from meters (as it
        # comes from the database) to centimeters; the computation is available
        # in the output of the node 'width'.
        width = cmds.createNode('multiplyDivide', name='width')
        cmds.setAttr(width + '.operation', 1)
        cmds.setAttr(width + '.input1X', 100.0)
        cmds.connectAttr(
            node + '.' + TrackPropEnum.WIDTH.maya, width + '.input2X')

        # Translate barW in x by width/2.0; output is in xW.outputX
        xW = cmds.createNode('multiplyDivide', name = 'xW')
        cmds.setAttr(xW + '.operation', 2)
        cmds.connectAttr(width + '.outputX', xW + '.input1X')
        cmds.setAttr(xW + '.input2X', 2.0)
        cmds.connectAttr(xW + '.outputX', barW + '.translateX')

        # Translate barE in x by -width/2.0; output is in xE.outputX
        xE = cmds.createNode('multiplyDivide', name = 'xE')
        cmds.setAttr(xE + '.operation', 2) # division operation
        cmds.connectAttr(width + '.outputX', xE + '.input1X')
        cmds.setAttr(xE + '.input2X', -2.0)
        cmds.connectAttr(xE + '.outputX', barE + '.translateX')

        # Now regarding length, first convert the node.length attribute from
        # meters to centimeters. This computation is available in the output of
        # the node 'length'
        length = cmds.createNode('multiplyDivide', name='length')
        cmds.setAttr(length + '.operation', 1)
        cmds.setAttr(length + '.input1X', 100.0)
        cmds.connectAttr(
            node + '.' + TrackPropEnum.LENGTH.maya, length + '.input2X')

        # scale thetaPlus and thetaMinus by length (since they are 1 cm,
        # multiply by length in cm)
        cmds.connectAttr(length + '.outputX', thetaPlus  + '.scaleZ')
        cmds.connectAttr(length + '.outputX', thetaMinus + '.scaleZ')

        # Then barN is translated forward in z by zN = lengthRatio*length
        # (centimeters)
        zN = cmds.createNode('multiplyDivide', name='zN')
        cmds.setAttr(zN + '.operation', 1)
        cmds.connectAttr(
            node + '.' + TrackPropEnum.LENGTH_RATIO.maya, zN + '.input1X')
        cmds.connectAttr(length + '.outputX',  zN + '.input2X')
        cmds.connectAttr(zN + '.outputX', barN + '.translateZ')

        # Next, translate barS backward in z by (zN - length); output is in
        # zS.output1D
        zS = cmds.createNode('plusMinusAverage', name='sZ')
        cmds.setAttr(zS + '.operation', 2)
        cmds.connectAttr(zN + '.outputX',     zS + '.input1D[0]')
        cmds.connectAttr(length + '.outputX', zS + '.input1D[1]')
        cmds.connectAttr(zS + '.output1D',    barS + '.translateZ')

        # Next, compute the half length, hl = length/2.0 (centimeters)
        hl = cmds.createNode('multiplyDivide', name='hl')
        cmds.setAttr(hl + '.operation', 2)
        cmds.connectAttr(length + '.outputX', hl + '.input1X')
        cmds.setAttr(hl + '.input2X', 2.0)

        # Translate lengthRuler along z by zL = (zN - hl) (centimeters)
        zL = cmds.createNode('plusMinusAverage', name='zL')
        cmds.setAttr(zL + '.operation', 2)
        cmds.connectAttr(zN + '.outputX',  zL + '.input1D[0]')
        cmds.connectAttr(hl + '.outputX',  zL + '.input1D[1]')
        cmds.connectAttr(zL + '.output1D', lengthRuler + '.translateZ')

        # Scale the four 'error bars' to represent the width and length
        # uncertainties (centimeters)
        cmds.connectAttr(
            node + "." + TrackPropEnum.WIDTH_UNCERTAINTY.maya,
            barW + '.scaleX')
        cmds.connectAttr(
            node + "." + TrackPropEnum.WIDTH_UNCERTAINTY.maya,
            barE + '.scaleX')
        cmds.connectAttr(
            node + "." + TrackPropEnum.LENGTH_UNCERTAINTY.maya,
            barN + '.scaleZ')
        cmds.connectAttr(
            node + "." + TrackPropEnum.LENGTH_UNCERTAINTY.maya,
            barS + '.scaleZ')

        # Create an 'inverter' transform under which all the other parts are
        # hung as children, which counteracts scaling applied to its parent
        # triangular node.
        inverter = cmds.createNode('transform', name='inverter')

        # drive the inverter's .scaleX and .scaleZ as the inverse of the parent
        # node's scale values
        sx = cmds.createNode('multiplyDivide', name='sx')
        cmds.setAttr(sx + '.operation', 2)
        cmds.setAttr(sx + '.input1X', 1.0)
        cmds.connectAttr(node + '.scaleX', sx + '.input2X')
        cmds.connectAttr(sx + '.outputX', inverter + '.scaleX')

        sz = cmds.createNode('multiplyDivide', name='sz')
        cmds.setAttr(sz + '.operation', 2)
        cmds.setAttr(sz + '.input1X', 1.0)
        cmds.connectAttr(node + '.scaleZ', sz + '.input2X')
        cmds.connectAttr(sz + '.outputX', inverter + '.scaleZ')

        # Assemble the parts as children under the scale inverter node
        cmds.parent(lengthRuler, inverter)
        cmds.parent(widthRuler,  inverter)
        cmds.parent(barN,        inverter)
        cmds.parent(barS,        inverter)
        cmds.parent(barW,        inverter)
        cmds.parent(barE,        inverter)
        cmds.parent(thetaPlus,   inverter)
        cmds.parent(thetaMinus,  inverter)
        cmds.parent(inverter,    node)

        # Rotate thetaPlus and thetaMinus about the Y axis to indicate
        # rotational uncertainty
        cmds.connectAttr(
            node + '.' + TrackPropEnum.ROTATION_UNCERTAINTY.maya,
            node + '|' + inverter + '|' + thetaPlus + '.rotateY')

        neg = cmds.createNode('multiplyDivide', name='negative')
        cmds.setAttr(neg + '.operation', 1)
        cmds.setAttr(neg + '.input1X',  -1.0)
        cmds.connectAttr(
            node + '.' + TrackPropEnum.ROTATION_UNCERTAINTY.maya,
            neg + '.input2X')
        cmds.connectAttr(
            neg + '.outputX',
            node + '|' + inverter + '|' + thetaMinus + '.rotateY')

        # Disable some transforms of the node
        cmds.setAttr(node + '.rotateX',    lock=True)
        cmds.setAttr(node + '.rotateZ',    lock=True)
        cmds.setAttr(node + '.scaleY',     lock=True)
        cmds.setAttr(node + '.translateY', lock=True)

        # Now, the width of the triangle will be driven by its width attribute
        # (driving .scaleX)
        cmds.connectAttr(node + '.width',  node + '.scaleX')

        # The quantity zN is used to scale length of the triangle
        cmds.connectAttr(zN + '.outputX',  node + '.scaleZ')

        # Scale the 'length' (in x) of the width ruler
        cmds.connectAttr(
            node + '.width',  node + '|' + inverter + '|WidthRuler.scaleX')

        # Scale the length of the length ruler
        cmds.connectAttr(
            node + '.length', node + '|' + inverter + '|LengthRuler.scaleZ')

        # Translate the track node epsilon below ground level (to reveal the
        # overlaid track siteMap)
        cmds.move(0, -epsilon, 0, node)

        # Initialize all the properties from the dictionary
        if props:
            cls.setTrackProps(node, props)
        else:
            print('in createTrackNode:  properties not provided')
            return node

        # Add the new nodeName to the Cadence track scene set, color it, and
        # we're done
        cmds.sets(node, add=trackSetNode)
        cls.colorTrackNode(node, props)
        return node
Example #6
0
    def buildScene(self):
        """Doc..."""

        groupItems = []
        hinds      = []
        fores      = []

        for c in self._data.getChannelsByKind(ChannelsEnum.POSITION):
            isHind = c.target in [TargetsEnum.LEFT_HIND, TargetsEnum.RIGHT_HIND]
            radius = 20 if isHind else 15
            res    = cmds.polySphere(radius=radius, name=c.target)
            groupItems.append(res[0])
            if isHind:
                hinds.append(res[0])
            else:
                fores.append(res[0])

            if c.target == TargetsEnum.LEFT_HIND:
                self._leftHind = res[0]
            elif c.target == TargetsEnum.RIGHT_HIND:
                self._rightHind = res[0]
            elif c.target == TargetsEnum.RIGHT_FORE:
                self._rightFore = res[0]
            elif c.target == TargetsEnum.LEFT_FORE:
                self._leftFore = res[0]

            for k in c.keys:
                frames = [
                    ['translateX', k.value.x, k.inTangentMaya[0], k.outTangentMaya[0]],
                    ['translateY', k.value.y, k.inTangentMaya[1], k.outTangentMaya[1]],
                    ['translateZ', k.value.z, k.inTangentMaya[2], k.outTangentMaya[2]]
                ]
                for f in frames:
                    cmds.setKeyframe(
                        res[0],
                        attribute=f[0],
                        time=k.time,
                        value=f[1],
                        inTangentType=f[2],
                        outTangentType=f[3]
                    )

                if k.event == 'land':
                    printResult = cmds.polyCylinder(
                        name=c.target + '_print1',
                        radius=radius,
                        height=(1.0 if isHind else 5.0)
                    )
                    cmds.move(k.value.x, k.value.y, k.value.z, printResult[0])
                    groupItems.append(printResult[0])

        cfg = self._data.configs
        name = 'cyc' + str(int(cfg.get(GaitConfigEnum.CYCLES))) + \
               '_ph' + str(int(cfg.get(GaitConfigEnum.PHASE))) + \
               '_gad' + str(int(cfg.get(SkeletonConfigEnum.FORE_OFFSET).z)) + \
               '_step' + str(int(cfg.get(SkeletonConfigEnum.STRIDE_LENGTH)))

        cube        = cmds.polyCube(name='pelvic_reference', width=20, height=20, depth=20)
        self._hips  = cube[0]
        groupItems.append(cube[0])
        cmds.move(0, 100, 0, cube[0])

        backLength = self._data.configs.get(SkeletonConfigEnum.FORE_OFFSET).z - \
                     self._data.configs.get(SkeletonConfigEnum.HIND_OFFSET).z

        cube2 = cmds.polyCube(name='pectoral_comparator', width=15, height=15, depth=15)
        cmds.move(0, 115, backLength, cube2[0])
        cmds.parent(cube2[0], cube[0], absolute=True)

        cmds.expression(
            string="%s.translateZ = 0.5*abs(%s.translateZ - %s.translateZ) + min(%s.translateZ, %s.translateZ)" %
            (cube[0], hinds[0], hinds[1], hinds[0], hinds[1])
        )

        cube = cmds.polyCube(name='pectoral_reference', width=15, height=15, depth=15)
        self._pecs = cube[0]
        groupItems.append(cube[0])
        cmds.move(0, 100, 0, cube[0])
        cmds.expression(
            string="%s.translateZ = 0.5*abs(%s.translateZ - %s.translateZ) + min(%s.translateZ, %s.translateZ)" %
            (cube[0], fores[0], fores[1], fores[0], fores[1])
        )

        self._group = cmds.group(*groupItems, world=True, name=name)

        cfg = self._data.configs
        info = 'Gait Phase: ' + \
                str(cfg.get(GaitConfigEnum.PHASE)) + \
                '\nGleno-Acetabular Distance (GAD): ' + \
                str(cfg.get(SkeletonConfigEnum.FORE_OFFSET).z) + \
                '\nStep Length: ' + \
                str(cfg.get(SkeletonConfigEnum.STRIDE_LENGTH)) + \
                '\nHind Duty Factor: ' + \
                str(cfg.get(GaitConfigEnum.DUTY_FACTOR_HIND)) + \
                '\nFore Duty Factor: ' + \
                str(cfg.get(GaitConfigEnum.DUTY_FACTOR_FORE)) + \
                '\nCycles: ' + \
                str(cfg.get(GaitConfigEnum.CYCLES))

        cmds.select(self._group)
        if not cmds.attributeQuery('notes', node=self._group, exists=True):
            cmds.addAttr(longName='notes', dataType='string')
            cmds.setAttr(self._group + '.notes', info, type='string')

        self.createShaders()
        self.createRenderEnvironment()

        minTime = min(0, int(cmds.playbackOptions(query=True, minTime=True)))

        deltaTime = cfg.get(GeneralConfigEnum.STOP_TIME) - cfg.get(GeneralConfigEnum.START_TIME)
        maxTime = max(
            int(float(cfg.get(GaitConfigEnum.CYCLES))*float(deltaTime)),
            int(cmds.playbackOptions(query=True, maxTime=True))
        )

        cmds.playbackOptions(
            minTime=minTime, animationStartTime=minTime, maxTime= maxTime, animationEndTime=maxTime
        )

        cmds.currentTime(0, update=True)

        cmds.select(self._group)
Example #7
0
    def _handleSetup(self):
        #----Set up dictionary for later use. Numbers are creation order from my modeling (important for NURBS naming)-
        direction = {"Left":2, "Middle":1, "Right":3}
        BLINK_LENGTH =6
        EYE_TARGET_LOW_BOUND = -11.038498
        EYE_TARGET_UPPER_BOUND = 16.118241
        EYE_START_POS = 137

        #----Add attrs for each eyelid
        for dir in direction:
            #------Put in "blink" attributes on the eye target------
            cmds.select("eyeTargets")

            #---Add the attribute "blink" for each eye onto the target
            cmds.addAttr(ln="blink"+dir, at="double", min=0, max=6, dv=0 )
            cmds.setAttr("eyeTargets.blink"+dir, keyable=True)

            #----Key the blinks----
            cmds.select("eyelid"+dir, r=True)
            cmds.select("makeNurbSphere"+str(direction[dir]), addFirst=True)
            #---Make sure the eyelid is in the correct start position----
            cmds.setAttr("makeNurbSphere"+str(direction[dir])+".startSweep", 10)
            cmds.setAttr("makeNurbSphere"+str(direction[dir])+".endSweep", 300)
            #---Set init key
            cmds.setDrivenKeyframe("makeNurbSphere"+str(direction[dir])+".startSweep", cd="eyeTargets.blink"+dir)
            cmds.setDrivenKeyframe("makeNurbSphere"+str(direction[dir])+".endSweep", cd="eyeTargets.blink"+dir)
            #----Clear selection and move driver for next key
            cmds.select(cl=True)
            cmds.setAttr("eyeTargets.blink"+dir, BLINK_LENGTH)
            #~~~move eyelid
            cmds.setAttr("makeNurbSphere"+str(direction[dir])+".startSweep", 0)
            cmds.setAttr("makeNurbSphere"+str(direction[dir])+".endSweep", 360)
            #---Set key
            cmds.setDrivenKeyframe("makeNurbSphere"+str(direction[dir])+".startSweep", cd="eyeTargets.blink"+dir)
            cmds.setDrivenKeyframe("makeNurbSphere"+str(direction[dir])+".endSweep", cd="eyeTargets.blink"+dir)
            #---reset our blink value, so it starts back at 0 once we set up
            cmds.setAttr("eyeTargets.blink"+dir, 0)

            #----Key the eyelid movement----
            #---Set key
            cmds.setAttr("eyeTargets.translateY", EYE_START_POS)
            cmds.setDrivenKeyframe("makeNurbSphere"+str(direction[dir])+".startSweep", cd="eyeTargets.translateY")
            cmds.setDrivenKeyframe("makeNurbSphere"+str(direction[dir])+".endSweep", cd="eyeTargets.translateY")
            #~~~Move eye target down
            cmds.setAttr("eyeTargets.translateY", EYE_START_POS+EYE_TARGET_LOW_BOUND)
            #---adjust eyelid sweep
            cmds.setAttr("makeNurbSphere"+str(direction[dir])+".startSweep", 35)
            cmds.setAttr("makeNurbSphere"+str(direction[dir])+".endSweep", 340)
            #---Set key
            cmds.setDrivenKeyframe("makeNurbSphere"+str(direction[dir])+".startSweep", cd="eyeTargets.translateY")
            cmds.setDrivenKeyframe("makeNurbSphere"+str(direction[dir])+".endSweep", cd="eyeTargets.translateY")
            #------
            #-----
            #~~~~Move Eye target up
            cmds.setAttr("eyeTargets.translateY", EYE_START_POS+EYE_TARGET_UPPER_BOUND)
            #---adjust eyelid sweep
            cmds.setAttr("makeNurbSphere"+str(direction[dir])+".startSweep", -20)
            cmds.setAttr("makeNurbSphere"+str(direction[dir])+".endSweep", 260)
            #---Set key
            cmds.setDrivenKeyframe("makeNurbSphere"+str(direction[dir])+".startSweep", cd="eyeTargets.translateY")
            cmds.setDrivenKeyframe("makeNurbSphere"+str(direction[dir])+".endSweep", cd="eyeTargets.translateY")
            #------Reset target
            cmds.setAttr("eyeTargets.translateY", EYE_START_POS)
Example #8
0
    def _handleSetup(self):
        #----Set up dictionary for later use. Numbers are creation order from my modeling (important for NURBS naming)-
        direction = {"Left": 2, "Middle": 1, "Right": 3}
        BLINK_LENGTH = 6
        EYE_TARGET_LOW_BOUND = -11.038498
        EYE_TARGET_UPPER_BOUND = 16.118241
        EYE_START_POS = 137

        #----Add attrs for each eyelid
        for dir in direction:
            #------Put in "blink" attributes on the eye target------
            cmds.select("eyeTargets")

            #---Add the attribute "blink" for each eye onto the target
            cmds.addAttr(ln="blink" + dir, at="double", min=0, max=6, dv=0)
            cmds.setAttr("eyeTargets.blink" + dir, keyable=True)

            #----Key the blinks----
            cmds.select("eyelid" + dir, r=True)
            cmds.select("makeNurbSphere" + str(direction[dir]), addFirst=True)
            #---Make sure the eyelid is in the correct start position----
            cmds.setAttr(
                "makeNurbSphere" + str(direction[dir]) + ".startSweep", 10)
            cmds.setAttr("makeNurbSphere" + str(direction[dir]) + ".endSweep",
                         300)
            #---Set init key
            cmds.setDrivenKeyframe("makeNurbSphere" + str(direction[dir]) +
                                   ".startSweep",
                                   cd="eyeTargets.blink" + dir)
            cmds.setDrivenKeyframe("makeNurbSphere" + str(direction[dir]) +
                                   ".endSweep",
                                   cd="eyeTargets.blink" + dir)
            #----Clear selection and move driver for next key
            cmds.select(cl=True)
            cmds.setAttr("eyeTargets.blink" + dir, BLINK_LENGTH)
            #~~~move eyelid
            cmds.setAttr(
                "makeNurbSphere" + str(direction[dir]) + ".startSweep", 0)
            cmds.setAttr("makeNurbSphere" + str(direction[dir]) + ".endSweep",
                         360)
            #---Set key
            cmds.setDrivenKeyframe("makeNurbSphere" + str(direction[dir]) +
                                   ".startSweep",
                                   cd="eyeTargets.blink" + dir)
            cmds.setDrivenKeyframe("makeNurbSphere" + str(direction[dir]) +
                                   ".endSweep",
                                   cd="eyeTargets.blink" + dir)
            #---reset our blink value, so it starts back at 0 once we set up
            cmds.setAttr("eyeTargets.blink" + dir, 0)

            #----Key the eyelid movement----
            #---Set key
            cmds.setAttr("eyeTargets.translateY", EYE_START_POS)
            cmds.setDrivenKeyframe("makeNurbSphere" + str(direction[dir]) +
                                   ".startSweep",
                                   cd="eyeTargets.translateY")
            cmds.setDrivenKeyframe("makeNurbSphere" + str(direction[dir]) +
                                   ".endSweep",
                                   cd="eyeTargets.translateY")
            #~~~Move eye target down
            cmds.setAttr("eyeTargets.translateY",
                         EYE_START_POS + EYE_TARGET_LOW_BOUND)
            #---adjust eyelid sweep
            cmds.setAttr(
                "makeNurbSphere" + str(direction[dir]) + ".startSweep", 35)
            cmds.setAttr("makeNurbSphere" + str(direction[dir]) + ".endSweep",
                         340)
            #---Set key
            cmds.setDrivenKeyframe("makeNurbSphere" + str(direction[dir]) +
                                   ".startSweep",
                                   cd="eyeTargets.translateY")
            cmds.setDrivenKeyframe("makeNurbSphere" + str(direction[dir]) +
                                   ".endSweep",
                                   cd="eyeTargets.translateY")
            #------
            #-----
            #~~~~Move Eye target up
            cmds.setAttr("eyeTargets.translateY",
                         EYE_START_POS + EYE_TARGET_UPPER_BOUND)
            #---adjust eyelid sweep
            cmds.setAttr(
                "makeNurbSphere" + str(direction[dir]) + ".startSweep", -20)
            cmds.setAttr("makeNurbSphere" + str(direction[dir]) + ".endSweep",
                         260)
            #---Set key
            cmds.setDrivenKeyframe("makeNurbSphere" + str(direction[dir]) +
                                   ".startSweep",
                                   cd="eyeTargets.translateY")
            cmds.setDrivenKeyframe("makeNurbSphere" + str(direction[dir]) +
                                   ".endSweep",
                                   cd="eyeTargets.translateY")
            #------Reset target
            cmds.setAttr("eyeTargets.translateY", EYE_START_POS)