Esempio n. 1
0
    def addBlade(self, name, parentPos, parentDir):

        # Draw from UI
        dist = vec.getDistance2(parentPos, parentDir)

        #        points = [0,0,0,1,0,dist*.5,0,1,dist*.25,0,0,1]
        #        blade = cur.addCurve(parentPos, self.getName(name), points, True, 1, parentPos.Kinematics.Global.Transform, [.75, .75, 0])
        blade = pri.addNull(parentPos, self.getName(name),
                            parentPos.Kinematics.Global.transform, dist * .5)
        pri.setNullDisplay(blade, 0, dist * .5, 9, .25, 0, 0, .5, 1, 0,
                           GUIDE_BLADE_COLOR)
        for s in [
                "primary_icon", "shadow_icon", "shadow_offsetX",
                "shadow_offsetY", "shadow_offsetZ", "shadow_scaleX",
                "shadow_scaleY", "shadow_scaleZ"
        ]:
            blade.ActivePrimitive.Parameters(s).AddExpression(
                blade.ActivePrimitive.Parameters(s).Value)
            blade.ActivePrimitive.Parameters(s).ReadOnly = True

        blade.Kinematics.Local.Parameters("rotorder").Value = 2
        blade.Kinematics.Local.Parameters("roty").Value = 90

        blade.Kinematics.AddConstraint("Position", parentPos, False)
        cns = blade.Kinematics.AddConstraint("Direction", parentDir, False)
        cns.Parameters("dirx").Value = 0
        cns.Parameters("diry").Value = 1
        cns.Parameters("dirz").Value = 0

        if name in self.blades.keys():
            blade.Kinematics.Global.Transform = self.blades[name].transform

        return blade
Esempio n. 2
0
    def addBlade(self, name, parentPos, parentDir):

        # Draw from UI
        dist = vec.getDistance2(parentPos, parentDir)

#        points = [0,0,0,1,0,dist*.5,0,1,dist*.25,0,0,1]
#        blade = cur.addCurve(parentPos, self.getName(name), points, True, 1, parentPos.Kinematics.Global.Transform, [.75, .75, 0])
        blade = pri.addNull(parentPos, self.getName(name), parentPos.Kinematics.Global.transform, dist * .5)
        pri.setNullDisplay(blade, 0, dist*.5, 9, .25, 0, 0, .5, 1, 0, GUIDE_BLADE_COLOR)
        for s in ["primary_icon", "shadow_icon", "shadow_offsetX", "shadow_offsetY", "shadow_offsetZ", "shadow_scaleX", "shadow_scaleY", "shadow_scaleZ"]:
            blade.ActivePrimitive.Parameters(s).AddExpression(blade.ActivePrimitive.Parameters(s).Value)
            blade.ActivePrimitive.Parameters(s).ReadOnly = True

        blade.Kinematics.Local.Parameters("rotorder").Value = 2
        blade.Kinematics.Local.Parameters("roty").Value = 90

        blade.Kinematics.AddConstraint("Position", parentPos, False)
        cns = blade.Kinematics.AddConstraint("Direction", parentDir, False)
        cns.Parameters("dirx").Value = 0
        cns.Parameters("diry").Value = 1
        cns.Parameters("dirz").Value = 0

        if name in self.blades.keys():
            blade.Kinematics.Global.Transform = self.blades[name].transform

        return blade
Esempio n. 3
0
    def drawFromUI(self, parent):

        if not self.pickPositions():
            gear.log("aborded", gear.sev_warning)
            return

        self.parent = parent
        self.setIndex(self.parent.Model)
        self.addObjects()

        # Set the size of the controlers
        if self.root_size is None:
            self.root_size = 1
            if self.type != "control_01":
                for child in self.root.FindChildren():
                    self.root_size = max(self.root_size, vec.getDistance2(self.root, child))
                self.root_size = min(1, max(.1, self.root_size*.15))

        self.root.size = self.root_size
        
        xsi.InspectObj(self.settings)
Esempio n. 4
0
def gear_GetDistance_Execute():

    if not xsi.Selection.Count:
        gear.log("No selection", gear.sev_error)
        return

    objects = [obj for obj in xsi.Selection if obj.IsClassOf(c.siX3DObjectID)]

    if len(objects) < 2:
        gear.log("Not enough object selected", gear.sev_error)
        return

    total = 0
    for i in range(len(objects)-1):
        a = objects[i]
        b = objects[i+1]

        distance = vec.getDistance2(a,b)
        gear.log("Distance : %s (%s to %s)"%(distance, a.Name, b.Name))

        total += distance

    gear.log("Total : %s"%total)
Esempio n. 5
0
def gear_GetDistance_Execute():

    if not xsi.Selection.Count:
        gear.log("No selection", gear.sev_error)
        return

    objects = [obj for obj in xsi.Selection if obj.IsClassOf(c.siX3DObjectID)]

    if len(objects) < 2:
        gear.log("Not enough object selected", gear.sev_error)
        return

    total = 0
    for i in range(len(objects) - 1):
        a = objects[i]
        b = objects[i + 1]

        distance = vec.getDistance2(a, b)
        gear.log("Distance : %s (%s to %s)" % (distance, a.Name, b.Name))

        total += distance

    gear.log("Total : %s" % total)
Esempio n. 6
0
    def addOperators(self):

        # Visibilities -------------------------------------
        par.addExpression(self.fk0_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName)
        par.addExpression(self.fk1_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName)
        par.addExpression(self.fk2_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName)

        par.addExpression(self.upv_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName)
        par.addExpression(self.ikcns_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName +" * "+ self.pIkCns.FullName)
        par.addExpression(self.ik_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName)

        # Leash --------------------------------------------
        aop.clsCtrOp(self.upv_ctl, self.mid_ctl, [0])

        # IK Solver-----------------------------------------
        out = [self.bone0, self.bone1, None, self.eff_loc]
        op = aop.sn_ikfk2bone_op(out, self.root, self.ik_ctl, self.upv_ctl, self.fk0_ctl, self.fk1_ctl, self.fk2_ctl, self.length0, self.length1, self.negate)

        par.addExpression(op.Parameters("blend"), self.pBlend.FullName)
        par.addExpression(op.Parameters("roll"), self.pIkRoll.FullName)
        par.addExpression(op.Parameters("scaleA"), self.pScale.FullName)
        par.addExpression(op.Parameters("scaleB"), self.pScale.FullName)
        par.addExpression(op.Parameters("maxstretch"), self.pMaxStretch.FullName)
        par.addExpression(op.Parameters("softness"), self.pSoftness.FullName)
        par.addExpression(op.Parameters("slide"), self.pSlide.FullName)
        par.addExpression(op.Parameters("reverse"), self.pReverse.FullName)

        # I'm not using the output of the solver to get the ctrn because it only has a +/-180 degree
        # With this simple expression I have a much better result
        # Also remove scaling from ctrn
        for s in "xyz":
            par.addExpression(self.ctrn_loc.Kinematics.Local.Parameters("rot"+s), self.bone1.Kinematics.Local.Parameters("rot"+s).FullName + " * .5")
            par.addExpression(self.ctrn_loc.Kinematics.Global.Parameters("scl"+s), self.root.Kinematics.Global.Parameters("scl"+s).FullName)

        # Membrane
        par.addExpression(self.memb_loc.Kinematics.Local.Parameters("posy"), self.pStartPos.FullName+" + ("+self.pEndPos.FullName+" - "+self.pStartPos.FullName+") * ( 1 - ( ctr_dist("+self.root.Kinematics.Global.FullName+","+self.eff_loc.Kinematics.Global.FullName+") / "+self.pRestDist.FullName+"))")

        # Twist references ---------------------------------
        self.pRestDist.Value = vec.getDistance2(self.root, self.eff_loc)
        par.addExpression(self.pDriver, "(ctr_dist(%s, %s) + ctr_dist(%s, %s)) / %s"
                                        %(self.tws0_loc.Kinematics.Global.FullName, self.tws1_loc.Kinematics.Global.FullName,
                                          self.tws1_loc.Kinematics.Global.FullName, self.tws2_loc.Kinematics.Global.FullName,
                                          self.root.Kinematics.Global.Parameters("sclx").FullName))

        self.tws0_loc.Kinematics.AddConstraint("Pose", self.root, True)
        aop.dirCns(self.tws0_loc, self.mid_ctl, None, False, self.n_sign+"xy")
        
        self.tws1_loc.Kinematics.AddConstraint("Position", self.mid_ctl)
        self.tws1_loc.Kinematics.AddConstraint("Scaling", self.mid_ctl)
        self.tws1_rot.Kinematics.AddConstraint("Orientation", self.mid_ctl)
        par.addExpression(self.tws1_rot.Parameters("rotx"), 0)
        par.addExpression(self.tws1_rot.Parameters("roty"), 0)
        par.addExpression(self.tws1_rot.Parameters("rotz"), 0)

        self.tws2_loc.Kinematics.AddConstraint("Position", self.eff_loc)
        self.tws2_loc.Kinematics.AddConstraint("Scaling", self.eff_loc)
        aop.poseCns(self.tws2_rot, self.eff_loc, False, False, True, False)
        par.addExpression(self.tws2_rot.Parameters("rotx"), 0)
        par.addExpression(self.tws2_rot.Parameters("roty"), 0)
        par.addExpression(self.tws2_rot.Parameters("rotz"), 0)
        par.setRotOrder(self.tws2_rot, "YZX")

        self.tws0_rot.SclX = .001
        par.addExpression(self.tws1_rot.SclX, self.pRoundness.FullName + " + .001")
        self.tws2_rot.SclX = .001

        # Divisions ----------------------------------------
        # at 0 or 1 the division will follow exactly the rotation of the controler.. and we wont have this nice tangent + roll
        for i, div_cns in enumerate(self.div_cns):

            if i < (self.settings["div0"]+1):
                perc = i*.5 / (self.settings["div0"]+1.0)
            else:
                perc = .5 + (i-self.settings["div0"]-1.0)*.5 / (self.settings["div1"]+1.0)

            perc = max(.001, min(.999, perc))

            # Roll
            if self.negate:
                op = aop.sn_rollsplinekine_op(div_cns, [self.tws2_rot, self.tws1_rot, self.tws0_rot], 1-perc)
            else:
                op = aop.sn_rollsplinekine_op(div_cns, [self.tws0_rot, self.tws1_rot, self.tws2_rot], perc)

            # Squash n Stretch
            op = aop.sn_squashstretch2_op(div_cns, self.root, self.pDriver.Value, "x")
            par.addExpression(op.Parameters("blend"), self.pVolume.FullName)
            par.addExpression(op.Parameters("driver"), self.pDriver.FullName)
            if self.options["mode"] == 1: # wip
                par.addExpression(op.Parameters("stretch"), self.pStretch[i])
                par.addExpression(op.Parameters("squash"), self.pSquash[i])
            else:
                op.Parameters("stretch").Value = self.st_value[i]
                op.Parameters("squash").Value = self.sq_value[i]