def _getTransformWithRollByBlade(self, t):
        # t = getTransform(self.guide.root)
        a = self.guide.blades["blade"].y
        x = vector.Blade(t).x
        z = vector.Blade(t).z

        x = vecProjection(a, x)[0]
        z = vecProjection(a, z)[2]
        theta = math.atan2(x, z)
        roll = theta + math.pi

        tm = datatypes.TransformationMatrix(t)
        tm.addRotation([0., roll, 0], 'XYZ', om.MSpace.kObject)

        return datatypes.Matrix(tm)
Exemple #2
0
    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] = vector.Blade(
                transform.getTransformFromPos(datatypes.Vector(0, 0, 0)))
            offset = False
        else:
            offset = True

        blade = icon.guideBladeIcon(parent=parentPos,
                                    name=self.getName(name),
                                    lenX=.5,
                                    color=[0, 0, 1],
                                    m=self.blades[name].transform)
        aim_cns = applyop.aimCns(blade,
                                 parentDir,
                                 axis="xy",
                                 wupType=2,
                                 wupVector=[0, 1, 0],
                                 wupObject=self.root,
                                 maintainOffset=offset)
        pnt_cns = pm.pointConstraint(parentPos, blade)

        aim_cns.isHistoricallyInteresting.set(False)
        pnt_cns.isHistoricallyInteresting.set(False)

        offsetAttr = attribute.addAttribute(blade, "bladeRollOffset", "float",
                                            aim_cns.attr("offsetX").get())
        pm.connectAttr(offsetAttr, aim_cns.attr("offsetX"))
        scaleAttr = attribute.addAttribute(blade,
                                           "bladeScale",
                                           "float",
                                           1,
                                           minValue=0.1,
                                           maxValue=100)
        for axis in "xyz":
            pm.connectAttr(scaleAttr, blade.attr("s{}".format(axis)))
        attribute.lockAttribute(blade,
                                attributes=[
                                    "tx", "ty", "tz", "rx", "ry", "rz", "sx",
                                    "sy", "sz", "v", "ro"
                                ])

        return blade
Exemple #3
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,
                                      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
Exemple #4
0
    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] = vector.Blade(
                transform.getTransformFromPos(datatypes.Vector(0, 0, 0)))
            offset = False
        else:
            offset = True

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

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

        return blade
Exemple #5
0
    def set_from_dict(self, c_dict):

        self.setParamDefValuesFromDict(c_dict["param_values"])
        self.child_components = c_dict["child_components"]

        temp_dict = {}
        for k in c_dict["tra"].keys():
            temp_dict[k] = datatypes.Matrix(c_dict["tra"][k])
        self.tra = temp_dict

        self.atra = [datatypes.Matrix(t) for t in c_dict["atra"]]

        temp_dict = {}
        for k in c_dict["pos"].keys():
            temp_dict[k] = datatypes.Vector(c_dict["pos"][k])
        self.pos = temp_dict

        self.apos = [datatypes.Vector(v) for v in c_dict["apos"]]
        for b in c_dict["blade"].keys():
            self.blades[b] = vector.Blade(datatypes.Matrix(c_dict["blade"][b]))

        self.size = self.getSize()
Exemple #6
0
    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" % (self.getName(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" % (self.getName(name)),
                          mgear.sev_warning)
                self.valid = False
                continue

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

        self.size = self.getSize()