def test_addChild(self): newNode = nodes.createDagNode("test", "transform") newParent = base.MetaBase(newNode) self.meta.addChild(newParent) self.assertEquals(len(self.meta.metaChildren()), 1) self.assertEquals(self.meta.metaChildren()[0].mobject(), newParent.mobject())
def test_iterMetaChildren(self): childOne = base.MetaBase(nodes.createDagNode("child", "transform")) childTwo = base.MetaBase(nodes.createDagNode("child1", "transform")) childThree = base.MetaBase(nodes.createDagNode("child2", "transform")) self.meta.addChild(childOne) childOne.addChild(childTwo) childTwo.addChild(childThree) iterchildren = [i for i in self.meta.iterMetaChildren()] nonChildren = [i for i in self.meta.iterMetaChildren(depthLimit=1)] self.assertEquals(len(nonChildren), 1) self.assertEquals(len(iterchildren), 3) selection = [childOne, childTwo, childThree] # non recursive self.assertTrue(nonChildren[0] in nonChildren) for i in selection: self.assertTrue(i in iterchildren) selection.remove(i)
def test_removeParent(self): newNode = nodes.createDagNode("test", "transform") newParent = base.MetaBase(newNode) self.meta.addParent(newParent) self.assertEquals(len(list(newParent.iterMetaChildren())), 1) self.meta.removeParent(newParent) self.assertEquals(len(list(newParent.iterMetaChildren())), 0) self.meta.addParent(newParent) self.assertEquals(len(list(newParent.iterMetaChildren())), 1) self.meta.removeParent(newParent) self.assertEquals(len(list(newParent.iterMetaChildren())), 0)
def test_removeChild(self): newNode = nodes.createDagNode("test", "transform") newParent = base.MetaBase(newNode) self.meta.addParent(newParent) self.assertEquals(len(newParent.metaChildren()), 1) newParent.removeChild(self.meta) self.assertEquals(len(newParent.metaChildren()), 0) self.meta.addParent(newParent) self.assertEquals(len(newParent.metaChildren()), 1) newParent.removeChild(self.meta.mobject()) self.assertEquals(len(newParent.metaChildren()), 0)
def _createInScene(self, node, name): if node is None: name = "_".join([name or self.__class__.__name__, "meta"]) node = nodes.createDagNode(name, "camera") self._handle = om2.MObjectHandle(node) if node.hasFn(om2.MFn.kDagNode): self._mfn = om2.MFnDagNode(node) else: self._mfn = om2.MFnDependencyNode(node) if node.hasFn(om2.MFn.kTransform): node = list( nodes.iterChildren(self.mobject(), False, om2.MFn.kCamera))[0] self.camMfn = om2.MFnCamera(node)
def createAnnotation(rootObj, endObj, text=None, name=None): newparent = nodes.createDagNode("_".join([name, "ann_hrc"]), "transform") name = name or "annotation" locator = nodes.createDagNode("_".join([name, "loc"]), "locator", newparent) annotationNode = nodes.asMObject( cmds.annotate(nodes.nameFromMObject(locator), tx=text)) annParent = nodes.getParent(annotationNode) nodes.rename(annParent, name) nodes.setParent(annParent, newparent, False) extras = [newparent] constraint = constraints.MatrixConstraint( name="_".join([name, "startMtx"])) extras.extend( constraint.create(endObj, locator, (True, True, True), (True, True, True), (True, True, True))) extras.extend( constraint.create(rootObj, annParent, (True, True, True), (True, True, True), (True, True, True))) return annParent, locator, extras
def create(self, shape=None, position=None, rotation=None, scale=(1, 1, 1), rotationOrder=0, color=None): """This method creates a new set of curve shapes for the control based on the shape type specified. if the self.node already initialized then this node will become the parent. this method has basic functionality for transformation if you need more control use the other helper method on this class. :param shape: The shape type to create should be present in the shape library :type shape: str :param position: The position to set the control at, if not specified the control will be created at 0,0,0 :type position: MVector :param rotation: the rotation for the control, if not specified the control with rotation 0,0,0 :type rotation: MEulerRotation or MQuaterion :param scale: the scale for the control, if not specified the control will be created at 1,1,1 :type scale: sequence :param rotationOrder: the rotation eg. MEulerRotation.kXYZ :type rotationOrder: int :return: The newly created control transform :rtype: mobject """ if not self._name: self._name = "control_new" if not self.dagPath: self.dagPath = nodes.createDagNode(self._name, "transform") if self.dagPath is None: raise ValueError("Not a valid shape name %s" % shape) if position is not None: self.setPosition(position, space=om2.MSpace.kWorld) if rotation is not None: self.setRotation(rotation) if scale != (1, 1, 1) and scale: self.setScale(scale, space=om2.MSpace.kWorld) self.setRotationOrder(rotationOrder) if isinstance(shape, basestring): self.dagPath = om2.MFnDagNode( shapelib.loadFromLib(shape, parent=self.dagPath)).getPath() else: self.dagPath = om2.MFnDagNode( curves.createCurveShape(self.dagPath, shape)).getPath() if color is not None: self.setColour(color, 0) return self.dagPath
def createCamera(name, start, end, focalLength=35.000, horizontalFilmAperture=1.682): # returns the camera transform camObj = nodes.createDagNode(name, "camera") camObj = list(nodes.iterChildren(camObj, False, (om2.MFn.kCamera, ))) # expectation that the camera was created an the transform was returned above # add the meta camera data meta = metacamera.MetaCamera(camObj[0]) meta.focalLength = focalLength meta.horizontalFilmAperture = horizontalFilmAperture meta.shotName = name meta.startFrame = start meta.endFrame = end return meta
def iterGenerateSrtAlongCurve(dagPath, count, name): """Generator function to iterate the curve and attach transform nodes to the curve using a motionPath :param dagPath: the dagpath to the nurbscurve shape node :type dagPath: om2.MDagPath :param count: the number of transforms :type count: int :param name: the name for the transform, the motionpath will have the same name plus "_mp" :type name: str :return: Python Generator first element is the created transform node, the second is the motionpath node :rtype: Generate(tuple(om2.MObject, om2.MObject)) """ curveNode = dagPath.node() for index, param in enumerate(iterCurveParams(dagPath, count)): transform = nodes.createDagNode(name, "transform") motionPath = attachNodeToCurveAtParam(curveNode, transform, param, "_".join([name, "mp"])) yield transform, motionPath
def createAnnotation(rootObj, endObj, text=None, name=None): name = name or "annotation" rootDag = om2.MFnDagNode(rootObj) boundingBox = rootDag.boundingBox center = om2.MVector(boundingBox.center) transform = nodes.createDagNode("_".join([name, "loc"]), "transform", parent=rootObj) nodes.setTranslation(transform, nodes.getTranslation(rootObj, om2.MSpace.kWorld), om2.MSpace.kWorld) annotationNode = nodes.asMObject( cmds.annotate(nodes.nameFromMObject(transform), tx=text)) annParent = nodes.getParent(annotationNode) nodes.rename(annParent, name) plugs.setPlugValue( om2.MFnDagNode(annotationNode).findPlug("position", False), center) nodes.setParent(annParent, endObj, False) return annotationNode, transform
def addSrtBuffer(self, suffix="", parent=None): """Adds a parent transform to the curve transform :param suffix: the suffix that this transform will get, eg name: self.name_suffix :type suffix: str :return: the newly created node :rtype: mobject """ if self.dagPath is None: return ctrlPat = nodes.getParent(self.mobject()) newSrt = nodes.createDagNode("_".join([self.name, suffix]), "transform", ctrlPat) nodes.setMatrix(newSrt, nodes.getWorldMatrix(self.mobject())) if parent is not None: nodes.setParent(newSrt, parent, True) nodes.setParent(self.mobject(), newSrt, True) self.srt = om2.MObjectHandle(newSrt) return newSrt
def test_createDagNode(self): node = nodes.createDagNode("new", "transform") self.assertIsInstance(node, om2.MObject)
def test_addParent(self): newNode = nodes.createDagNode("test", "transform") newParent = base.MetaBase(newNode) self.meta.addParent(newParent) self.assertEquals(list(self.meta.metaParents())[0].mobject(), newParent.mobject())
def testCreate(): return nodes.asMObject( cmds.createNode("transform")), nodes.createDagNode( "test", "transform")
def doIt(self): node = nodes.createDagNode("testNode", "transform") self._testNode = om2.MObjectHandle(node)
def test_name(self): self.assertEquals(self.meta.fullPathName(), "testNode_meta") self.assertEquals(base.MetaBase(nodes.createDagNode("transform1", "transform")).fullPathName(), "|transform1")
def test_deleteNode(self): node = om2.MObjectHandle(nodes.createDagNode("testTransform", "transform")) self.assertTrue(node.isValid() and node.isAlive()) nodes.delete(node.object()) self.assertFalse(node.isValid() and node.isAlive())