예제 #1
0
    def symmetrize(self):
        """Inverse the transform of each element of the guide."""

        if self.values["comp_side"] not in ["R", "L"]:
            mgear.log("Can't symmetrize central component", mgear.sev_error)
            return False
        for name, paramDef in self.paramDefs.items():
            if paramDef.valueType == "string":
                self.setParamDefValue(
                    name, mgear.string.convertRLName(self.values[name]))
        for name, t in self.tra.items():
            self.tra[name] = transform.getSymmetricalTransform(t)
        for name, blade in self.blades.items():
            self.blades[name] = vector.Blade(
                transform.getSymmetricalTransform(blade.transform))

        return True
예제 #2
0
파일: guide.py 프로젝트: moChen0607/mgear
    def addBlade(self, name, parentPos, parentDir):
        """
        Add a blade object to the guide.
        This mehod can initialize the object or draw it.
        Blade object is a 3points curve to define a plan in the guide.

        Args:
            name (str): Local name of the element.
            parentPos (dagNode): The parent of the element.
            parentDir (dagNode): The direction constraint of the element.

        Returns:
            dagNode:  The created blade curve.

        """
        if name not in self.blades.keys():
            self.blades[name] = vec.Blade(
                tra.getTransformFromPos(dt.Vector(0, 0, 0)))
            offset = False
        else:
            offset = True

        dist = .6 * self.root.attr("scaleX").get()
        blade = ico.guideBladeIcon(parent=parentPos,
                                   name=self.getName(name),
                                   lenX=dist,
                                   color=13,
                                   m=self.blades[name].transform)
        aim_cns = aop.aimCns(blade,
                             parentDir,
                             axis="xy",
                             wupType=2,
                             wupVector=[0, 1, 0],
                             wupObject=self.root,
                             maintainOffset=offset)
        pm.pointConstraint(parentPos, blade)

        offsetAttr = att.addAttribute(blade, "bladeRollOffset", "float",
                                      aim_cns.attr("offsetX").get())
        pm.connectAttr(offsetAttr, aim_cns.attr("offsetX"))
        att.lockAttribute(blade)

        return blade
예제 #3
0
파일: guide.py 프로젝트: moChen0607/mgear
    def setFromHierarchy(self, root):
        """
        Set the component guide from given hierarchy.

        Args:
            root (dagNode): The root of the hierarchy to parse.

        """
        self.root = root
        self.model = self.root.getParent(generations=-1)

        # ---------------------------------------------------
        # First check and set the settings
        if not self.root.hasAttr("comp_type"):
            mgear.log("%s is not a proper guide." % self.root.longName(),
                      mgear.sev_error)
            self.valid = False
            return

        self.setParamDefValuesFromProperty(self.root)

        # ---------------------------------------------------
        # Then get the objects
        for name in self.save_transform:
            if "#" in name:
                i = 0
                while not self.minmax[name].max > 0 or i < self.minmax[
                        name].max:
                    localName = string.replaceSharpWithPadding(name, i)

                    node = dag.findChild(self.model, self.getName(localName))
                    if not node:
                        break

                    self.tra[localName] = node.getMatrix(worldSpace=True)
                    self.atra.append(node.getMatrix(worldSpace=True))
                    self.pos[localName] = node.getTranslation(space="world")
                    self.apos.append(node.getTranslation(space="world"))

                    i += 1

                if i < self.minmax[name].min:
                    mgear.log(
                        "Minimum of object requiered for " + name +
                        " hasn't been reached!!", mgear.sev_warning)
                    self.valid = False
                    continue

            else:
                node = dag.findChild(self.model, self.getName(name))
                if not node:
                    mgear.log("Object missing : %s" % name, mgear.sev_warning)
                    self.valid = False
                    continue

                self.tra[name] = node.getMatrix(worldSpace=True)
                self.atra.append(node.getMatrix(worldSpace=True))
                self.pos[name] = node.getTranslation(space="world")
                self.apos.append(node.getTranslation(space="world"))

        for name in self.save_blade:

            node = dag.findChild(self.model, self.getName(name))
            if not node:
                mgear.log("Object missing : %s" % name, mgear.sev_warning)
                self.valid = False
                continue

            self.blades[name] = vec.Blade(node.getMatrix(worldSpace=True))

        self.size = self.getSize()