Пример #1
0
    def addCurve(self, name, parent, points=[], close=False, degree=1, position=None):
        
        if name not in self.tra.keys():
            self.tra[name] = tra.getTransformFromPosition(position)

        if name in self.prim.keys():
            crv = self.prim[name].create(parent, self.getName(name), self.tra[name], GUIDE_LOC_COLOR)
        else:
            crv = cur.addCurveFromPos(parent, name, points, close, degree, c.siNonUniformParameterization, self.tra[name], GUIDE_LOC_COLOR)
            
        return crv
Пример #2
0
    def addObjects(self):

        self.inter_shd = 1
        self.shd_count = self.inter_shd * 2 + 3
        self.inter_crv = 1
        self.crv_count = self.inter_crv * 2 + 1

        self.npo = []
        self.ctl = []

        self.crv = []
        self.upv = []
        self.ctr = []
        self.off = []
        self.cns_crv = []
        self.loc = []

        self.percentages = []

        for i, name, blade in zip(range(3), ["root", "mid_loc", "end_loc"], ["blade", "mid_blade", "end_blade"]):

            # Path ----------------------------------------
            crv = self.guide.prim["%s_crv"%i].create(self.root, self.getName("%s_crv"%i), None)
            xsi.SetNeutralPose(crv)

            self.crv.append(crv)
            self.addToGroup(crv, "hidden")

            if i == 0:
                y0 = cur.getGlobalPointPosition(0, crv).Y
                y1 = cur.getGlobalPointPosition(crv.ActivePrimitive.Geometry.Points.Count-1, crv).Y

                self.scale = (y1 - y0) * .5

            # Controlers ----------------------------------
            lookat = XSIMath.CreateVector3()
            lookat.Add(self.guide.pos[name], self.guide.blades[blade].x)
            if blade == "end_blade":
                axisPlane = "zx"
                axisNegate =  True
            else:
                axisPlane = "zx"
                axisNegate = False
            t = tra.getTransformLookingAt(self.guide.pos[name], lookat, self.guide.blades[blade].y, axisPlane, axisNegate)
            t.SetScaling(XSIMath.CreateVector3(self.scale, self.scale, self.scale))

            npo = pri.addNull(self.root, self.getName("%s_npo"%i), t, 1)
            pri.setNullDisplay(npo, 0, 1, 4, 0, 0, 0, .15, 2, 0)
            self.addToGroup(npo, "unselectable")

            ctl = self.addCtl(npo, "%s_ctl"%i, t, self.color_ik, "sphere", w=.2)
            xsi.SetNeutralPose(ctl)
            par.setKeyableParameters(ctl, ["posx", "posy", "posz", "rotx", "roty", "rotz", "rotorder", "sclx"])
            # par.addLocalParamToCollection(self.inv_params, ctl, ["posx", "roty", "rotz"]) # to be defined
            # par.setRotOrder(ctl, "XZY") # to be defined

            self.ctl.append(ctl)


            # Up Vector, Center, Offset -------------------
            v = XSIMath.CreateVector3(self.guide.blades[blade].x.X, self.guide.blades[blade].x.Y, self.guide.blades[blade].x.Z)
            v.ScaleInPlace(-self.size)
            v.AddInPlace(self.guide.pos[name])
            upv = pri.addNullFromPos(crv, self.getName("%s_upv")%i, v, self.size*.025)
            ctr = [pri.addNullFromPos(crv, self.getName("%s_%s_ctr"%(i,j)), self.guide.apos[i], self.size*.025) for j in range(3)]
            off = pri.addNullFromPos(ctr[1], self.getName("%s_off")%i, self.guide.apos[i], self.size*.05)

            self.upv.append(upv)
            self.ctr.append(ctr)
            self.off.append(off)
            self.addToGroup(upv, "hidden")
            self.addToGroup(ctr, "hidden")
            self.addToGroup(off, "hidden")

            # Collecting Percentage to evaluate the curve
            v = XSIMath.MapWorldPositionToObjectSpace(crv.Kinematics.Global.Transform, self.guide.pos[name])
            a = crv.ActivePrimitive.Geometry.GetClosestCurvePosition2(v)
            perc = crv.ActivePrimitive.Geometry.Curves(0).GetPercentageFromU(a[2])
            self.percentages.append(perc)

        # Constrained Curve -------------------------------
        self.cns_crv = []
        self.loc = []
        for i in range(self.crv_count):
            positions = []
            for crv, perc in zip(self.crv, self.percentages):

                if i < self.inter_crv:
                    perc = (i+1.0)/(self.inter_crv+1.0) * perc
                elif i > self.inter_crv:
                    perc = perc + (i-self.inter_crv)/(self.inter_crv+1.0) * perc

                pos = crv.ActivePrimitive.Geometry.Curves(0).EvaluatePositionFromPercentage(perc)[0]
                pos = XSIMath.MapObjectPositionToWorldSpace(crv.Kinematics.Global.Transform, pos)
                positions.append(pos)

            positions.insert(1, vec.linearlyInterpolate(positions[0], positions[1], .1))
            positions.insert(-1, vec.linearlyInterpolate(positions[-2], positions[-1], .9))
            cns_crv = cur.addCurveFromPos(self.root, self.getName("cns%s_crv"%i), positions, False, 3)

            self.cns_crv.append(cns_crv)
            self.addToGroup(cns_crv, "hidden")

            # Shadows
            for j in range(self.shd_count):

                if i < self.inter_crv:
                    name = "%s_low%s"%(j,i)
                elif i == self.inter_crv:
                    name = str(j)
                elif i > self.inter_crv:
                    name = "%s_upp%s"%(j,i-self.inter_crv-1)

                loc = pri.addNullFromPos(cns_crv, self.getName(name+"_loc"), XSIMath.CreateVector3(), self.size*.05)
                self.addShadow(loc, name)

                self.loc.append(loc)
                self.addToGroup(loc, "hidden")
Пример #3
0
    def addObjects(self):

        self.inter_shd = 1
        self.shd_count = self.inter_shd * 2 + 3
        self.inter_crv = 1
        self.crv_count = self.inter_crv * 2 + 1

        self.npo = []
        self.ctl = []

        self.crv = []
        self.upv = []
        self.ctr = []
        self.off = []
        self.cns_crv = []
        self.loc = []

        self.percentages = []

        for i, name, blade in zip(range(3), ["root", "mid_loc", "end_loc"],
                                  ["blade", "mid_blade", "end_blade"]):

            # Path ----------------------------------------
            crv = self.guide.prim["%s_crv" % i].create(
                self.root, self.getName("%s_crv" % i), None)
            xsi.SetNeutralPose(crv)

            self.crv.append(crv)
            self.addToGroup(crv, "hidden")

            if i == 0:
                y0 = cur.getGlobalPointPosition(0, crv).Y
                y1 = cur.getGlobalPointPosition(
                    crv.ActivePrimitive.Geometry.Points.Count - 1, crv).Y

                self.scale = (y1 - y0) * .5

            # Controlers ----------------------------------
            lookat = XSIMath.CreateVector3()
            lookat.Add(self.guide.pos[name], self.guide.blades[blade].x)
            if blade == "end_blade":
                axisPlane = "zx"
                axisNegate = True
            else:
                axisPlane = "zx"
                axisNegate = False
            t = tra.getTransformLookingAt(self.guide.pos[name], lookat,
                                          self.guide.blades[blade].y,
                                          axisPlane, axisNegate)
            t.SetScaling(
                XSIMath.CreateVector3(self.scale, self.scale, self.scale))

            npo = pri.addNull(self.root, self.getName("%s_npo" % i), t, 1)
            pri.setNullDisplay(npo, 0, 1, 4, 0, 0, 0, .15, 2, 0)
            self.addToGroup(npo, "unselectable")

            ctl = self.addCtl(npo,
                              "%s_ctl" % i,
                              t,
                              self.color_ik,
                              "sphere",
                              w=.2)
            xsi.SetNeutralPose(ctl)
            par.setKeyableParameters(ctl, [
                "posx", "posy", "posz", "rotx", "roty", "rotz", "rotorder",
                "sclx"
            ])
            # par.addLocalParamToCollection(self.inv_params, ctl, ["posx", "roty", "rotz"]) # to be defined
            # par.setRotOrder(ctl, "XZY") # to be defined

            self.ctl.append(ctl)

            # Up Vector, Center, Offset -------------------
            v = XSIMath.CreateVector3(self.guide.blades[blade].x.X,
                                      self.guide.blades[blade].x.Y,
                                      self.guide.blades[blade].x.Z)
            v.ScaleInPlace(-self.size)
            v.AddInPlace(self.guide.pos[name])
            upv = pri.addNullFromPos(crv,
                                     self.getName("%s_upv") % i, v,
                                     self.size * .025)
            ctr = [
                pri.addNullFromPos(crv, self.getName("%s_%s_ctr" % (i, j)),
                                   self.guide.apos[i], self.size * .025)
                for j in range(3)
            ]
            off = pri.addNullFromPos(ctr[1],
                                     self.getName("%s_off") % i,
                                     self.guide.apos[i], self.size * .05)

            self.upv.append(upv)
            self.ctr.append(ctr)
            self.off.append(off)
            self.addToGroup(upv, "hidden")
            self.addToGroup(ctr, "hidden")
            self.addToGroup(off, "hidden")

            # Collecting Percentage to evaluate the curve
            v = XSIMath.MapWorldPositionToObjectSpace(
                crv.Kinematics.Global.Transform, self.guide.pos[name])
            a = crv.ActivePrimitive.Geometry.GetClosestCurvePosition2(v)
            perc = crv.ActivePrimitive.Geometry.Curves(0).GetPercentageFromU(
                a[2])
            self.percentages.append(perc)

        # Constrained Curve -------------------------------
        self.cns_crv = []
        self.loc = []
        for i in range(self.crv_count):
            positions = []
            for crv, perc in zip(self.crv, self.percentages):

                if i < self.inter_crv:
                    perc = (i + 1.0) / (self.inter_crv + 1.0) * perc
                elif i > self.inter_crv:
                    perc = perc + (i - self.inter_crv) / (self.inter_crv +
                                                          1.0) * perc

                pos = crv.ActivePrimitive.Geometry.Curves(
                    0).EvaluatePositionFromPercentage(perc)[0]
                pos = XSIMath.MapObjectPositionToWorldSpace(
                    crv.Kinematics.Global.Transform, pos)
                positions.append(pos)

            positions.insert(
                1, vec.linearlyInterpolate(positions[0], positions[1], .1))
            positions.insert(
                -1, vec.linearlyInterpolate(positions[-2], positions[-1], .9))
            cns_crv = cur.addCurveFromPos(self.root,
                                          self.getName("cns%s_crv" % i),
                                          positions, False, 3)

            self.cns_crv.append(cns_crv)
            self.addToGroup(cns_crv, "hidden")

            # Shadows
            for j in range(self.shd_count):

                if i < self.inter_crv:
                    name = "%s_low%s" % (j, i)
                elif i == self.inter_crv:
                    name = str(j)
                elif i > self.inter_crv:
                    name = "%s_upp%s" % (j, i - self.inter_crv - 1)

                loc = pri.addNullFromPos(cns_crv, self.getName(name + "_loc"),
                                         XSIMath.CreateVector3(),
                                         self.size * .05)
                self.addShadow(loc, name)

                self.loc.append(loc)
                self.addToGroup(loc, "hidden")