def colorTrackNode(cls, node, props): # Save state of selected nodes to restore at end of this function priorSelection = MayaUtils.getSelectedTransforms() # Use red for left, green for right, in accordance with international # maritime convention left = props[TrackPropEnum.LEFT.name] pes = props[TrackPropEnum.PES.name] if left: ShadingUtils.applyShader(TrackwayShaderConfig.RED_COLOR, node) else: ShadingUtils.applyShader(TrackwayShaderConfig.GREEN_COLOR, node) # Next, get a shortcut to the components of the track node root = node + '|inverter' # Make the width and length rulers either light gray (for manus) or # dark gray (for pes) and the 'error bars' white. c = TrackwayShaderConfig.DARK_GRAY_COLOR if pes else \ TrackwayShaderConfig.LIGHT_GRAY_COLOR ShadingUtils.applyShader(c, root + '|WidthRuler') ShadingUtils.applyShader(c, root + '|LengthRuler') ShadingUtils.applyShader( TrackwayShaderConfig.WHITE_COLOR, root + '|BarN') ShadingUtils.applyShader( TrackwayShaderConfig.WHITE_COLOR, root + '|BarS') ShadingUtils.applyShader( TrackwayShaderConfig.WHITE_COLOR, root + '|BarW') ShadingUtils.applyShader( TrackwayShaderConfig.WHITE_COLOR, root + '|BarE') # And finish up with other details ShadingUtils.applyShader( TrackwayShaderConfig.YELLOW_COLOR, root + '|ThetaPlus') ShadingUtils.applyShader( TrackwayShaderConfig.YELLOW_COLOR, root + '|ThetaMinus') MayaUtils.setSelection(priorSelection)
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
def shade(self, transforms): ShadingUtils.applyShader(self._shaderConfig, transforms)