def gear_MatchSR_Execute(): source_object = xsi.Selection(0) target_object = uit.pickSession() if not target_object: return tra.matchGlobalTransform(source_object, target_object, False, True, True)
def gear_createIcon_Execute(iconPreset): reload(gear.xsi.icon) funcDic = {"cube":icon.cube, "pyramid":icon.pyramid, "square":icon.square, "flower":icon.flower, "circle":icon.circle, "cylinder":icon.cylinder, "compas":icon.compas, "foil":icon.foil, "diamond":icon.diamond, "leash":icon.leash, "cubewithpeak":icon.cubewithpeak, "sphere":icon.sphere, "arrow":icon.arrow, "crossarrow":icon.crossarrow, "bendedarrow":icon.bendedarrow, "bendedarrow2":icon.bendedarrow2, "cross":icon.cross, "glasses":icon.glasses, "lookat":icon.lookat, "eyearrow":icon.eyearrow, "anglesurvey":icon.anglesurvey, "eyeball":icon.eyeball, "rectanglecube":icon.rectanglecube, "man":icon.man, "null":icon.null, "boomerang":icon.boomerang} if xsi.Selection.Count: XSIDial = XSIFactory.CreateObject( "XSIDial.XSIDialog") items = ["Only in Place", "Make it Parent", "Make it Child"] out = XSIDial.Combo("Creating Controls on Selected Objects", items) if out == -1: lm("Controls creation cancelled") return for obj in xsi.Selection: crv = funcDic[iconPreset]() source_object = obj tra.matchGlobalTransform( crv, source_object) if out == 1: oParent = obj.Parent #check if 2 objects have the same parent. if oParent.Name != crv.Parent.Name: xsi.ParentObj(oParent, crv) xsi.ParentObj(crv, obj) elif out == 2: xsi.ParentObj(obj, crv) crv.Name = obj.Name + "_" + iconPreset else: crv = funcDic[iconPreset]() xsi.SelectObj(crv) return crv
def gear_MatchT_Execute(): if not xsi.Selection.Count: gear.log("No Selection", gear.sev_error) return source_object = xsi.Selection(0) target_object = uit.pickSession() if not target_object: return tra.matchGlobalTransform(source_object, target_object, True, False, False)
def switchToFk(self): # Match Rotation tra.matchGlobalTransform(self.fk0, self.jnt0, False, True, True) tra.matchGlobalTransform(self.fk1, self.jnt1, False, True, True) # Scale self.scale.Value = (self.length0 + self.length1) / self.rest # Switch to FK self.blend.Value = 0 if self.isleg: x = XSIMath.CreateVector3(0, 0, 1) y = XSIMath.CreateVector3(0, 1, 0) if self.negate: x.NegateInPlace() y.NegateInPlace() x.MulByRotationInPlace( self.ik.Kinematics.Global.Transform.Rotation) y.MulByRotationInPlace( self.ik.Kinematics.Global.Transform.Rotation) t = self.ik.Kinematics.Global.Transform t.SetRotation(tra.getRotationFromAxis(x, y, "xy")) self.fk2.Kinematics.Global.Transform = t else: tra.matchGlobalTransform(self.fk2, self.ik, False, True, True)
def switchToFk(self): # Match Rotation tra.matchGlobalTransform(self.fk0, self.jnt0, False, True, True) tra.matchGlobalTransform(self.fk1, self.jnt1, False, True, True) # Scale self.scale.Value = (self.length0 + self.length1) / self.rest # Switch to FK self.blend.Value = 0 if self.isleg: x = XSIMath.CreateVector3(0,0,1) y = XSIMath.CreateVector3(0,1,0) if self.negate: x.NegateInPlace() y.NegateInPlace() x.MulByRotationInPlace(self.ik.Kinematics.Global.Transform.Rotation) y.MulByRotationInPlace(self.ik.Kinematics.Global.Transform.Rotation) t = self.ik.Kinematics.Global.Transform t.SetRotation(tra.getRotationFromAxis(x, y, "xy")) self.fk2.Kinematics.Global.Transform = t else: tra.matchGlobalTransform(self.fk2, self.ik, False, True, True)
def switchToIk(self): # Get the distance between Root and effector and compare it to bones total length to define if the chain is bend or not vRootEff = XSIMath.CreateVector3() vRootEff.Sub(self.jnt0.kinematics.Global.Transform.Translation, self.ik.kinematics.Global.Transform.Translation) # We get an approximation of the length otherwise it's sometimes tricky to compare distance r = 100000 dRootEffLength = round((vRootEff.Length() * r)) / r dBonesLength = round(((self.length0 + self.length1) * r)) / r # xsi.MatchTransform(self.ik, self.eff, c.siRT, None) # tra.matchGlobalTransform(self.eff, self.ik, True, True, False) tra.matchGlobalTransform(self.ik, self.fk2, True, True, True) self.blend.Value = 1 # tra.matchGlobalTransform(self.fk2, self.ik, False, True, False) # Compute Roll if dRootEffLength < dBonesLength: # Get Vectors to built the plane vFKChain0 = XSIMath.CreateVector3() vIKChain0 = XSIMath.CreateVector3() vRootEff = XSIMath.CreateVector3() vFKChain0.Sub(self.fk0.kinematics.Global.Transform.Translation, self.fk1.kinematics.Global.Transform.Translation) vIKChain0.Sub(self.jnt0.kinematics.Global.Transform.Translation, self.jnt1.kinematics.Global.Transform.Translation) vRootEff.Sub(self.jnt0.kinematics.Global.Transform.Translation, self.ik.kinematics.Global.Transform.Translation) # vFKChain0.NormalizeInPlace() # vIKChain0.NormalizeInPlace() # vRootEff.NormalizeInPlace() # Get Plane's Normal vNormFKPlane = XSIMath.CreateVector3() vNormIKPlane = XSIMath.CreateVector3() vNormFKPlane.Cross(vFKChain0, vRootEff) vNormIKPlane.Cross(vIKChain0, vRootEff) # vNormFKPlane.NormalizeInPlace() # vNormIKPlane.NormalizeInPlace() # Get the Angle between the two planess dAngle = XSIMath.RadiansToDegrees(vNormFKPlane.Angle(vNormIKPlane)) # Check if we have to remove or add the angle vCrossPlane = XSIMath.CreateVector3() vCrossPlane.Cross(vNormFKPlane, vNormIKPlane) # vCrossPlane.NormalizeInPlace() dDirectionDot = vCrossPlane.Dot(vRootEff) # Set the new roll Value a = self.roll.Value + (dDirectionDot / abs(dDirectionDot)) * dAngle # Set the angle in a -180 / 180 range if abs(a) > 180: a = a % ((-a / abs(a)) * 360) # [OLD WAY ]Set the new roll Value -- # Check if the bone is negated or not ## dNegate = self.jnt1.kinematics.Local.posx.Value + self.jnt1.kinematics.Local.nposx.Value #dNegate = 1 # oldAngle = self.roll.Value # if (dDirectionDot * dNegate) < 0: # newAngle = oldAngle - dAngle # else: # newAngle = oldAngle + dAngle # if newAngle > 180: # newAngle -= 360 # elif newAngle < -180: # newAngle += 360 # [END OLD WAY ] ------------------- self.roll.Value = a # Match Scale Value # We remove Soft distances self.softik.Value = 0 if dRootEffLength > dBonesLength: if self.scale.Value > self.maxstretch.Value: self.maxstretch.Value = self.scale.Value self.scale.Value = 1 if self.isleg: z = XSIMath.CreateVector3(1, 0, 0) y = XSIMath.CreateVector3(0, 1, 0) if self.negate: z.NegateInPlace() y.NegateInPlace() z.MulByRotationInPlace( self.fk2.Kinematics.Global.Transform.Rotation) y.MulByRotationInPlace( self.fk2.Kinematics.Global.Transform.Rotation) t = self.fk2.Kinematics.Global.Transform t.SetRotation(tra.getRotationFromAxis(z, y, "zy")) self.ik.Kinematics.Global.Transform = t else: tra.matchGlobalTransform(self.ik, self.fk2, False, True, True)
def switchToIk(self): # Get the distance between Root and effector and compare it to bones total length to define if the chain is bend or not vRootEff = XSIMath.CreateVector3() vRootEff.Sub(self.jnt0.kinematics.Global.Transform.Translation, self.ik.kinematics.Global.Transform.Translation) # We get an approximation of the length otherwise it's sometimes tricky to compare distance r = 100000 dRootEffLength = round((vRootEff.Length()*r)) / r dBonesLength = round(((self.length0 + self.length1)*r)) / r # xsi.MatchTransform(self.ik, self.eff, c.siRT, None) # tra.matchGlobalTransform(self.eff, self.ik, True, True, False) tra.matchGlobalTransform(self.ik, self.fk2, True, True, True) self.blend.Value = 1 # tra.matchGlobalTransform(self.fk2, self.ik, False, True, False) # Compute Roll if dRootEffLength < dBonesLength: # Get Vectors to built the plane vFKChain0 = XSIMath.CreateVector3() vIKChain0 = XSIMath.CreateVector3() vRootEff = XSIMath.CreateVector3() vFKChain0.Sub(self.fk0.kinematics.Global.Transform.Translation, self.fk1.kinematics.Global.Transform.Translation) vIKChain0.Sub(self.jnt0.kinematics.Global.Transform.Translation , self.jnt1.kinematics.Global.Transform.Translation) vRootEff.Sub(self.jnt0.kinematics.Global.Transform.Translation, self.ik.kinematics.Global.Transform.Translation) # vFKChain0.NormalizeInPlace() # vIKChain0.NormalizeInPlace() # vRootEff.NormalizeInPlace() # Get Plane's Normal vNormFKPlane = XSIMath.CreateVector3() vNormIKPlane = XSIMath.CreateVector3() vNormFKPlane.Cross(vFKChain0, vRootEff) vNormIKPlane.Cross(vIKChain0, vRootEff) # vNormFKPlane.NormalizeInPlace() # vNormIKPlane.NormalizeInPlace() # Get the Angle between the two planess dAngle = XSIMath.RadiansToDegrees(vNormFKPlane.Angle(vNormIKPlane)) # Check if we have to remove or add the angle vCrossPlane = XSIMath.CreateVector3() vCrossPlane.Cross(vNormFKPlane, vNormIKPlane) # vCrossPlane.NormalizeInPlace() dDirectionDot = vCrossPlane.Dot(vRootEff) # Set the new roll Value a = self.roll.Value + (dDirectionDot/abs(dDirectionDot)) * dAngle # Set the angle in a -180 / 180 range if abs(a) > 180: a = a%((-a /abs(a))*360) # [OLD WAY ]Set the new roll Value -- # Check if the bone is negated or not ## dNegate = self.jnt1.kinematics.Local.posx.Value + self.jnt1.kinematics.Local.nposx.Value #dNegate = 1 # oldAngle = self.roll.Value # if (dDirectionDot * dNegate) < 0: # newAngle = oldAngle - dAngle # else: # newAngle = oldAngle + dAngle # if newAngle > 180: # newAngle -= 360 # elif newAngle < -180: # newAngle += 360 # [END OLD WAY ] ------------------- self.roll.Value = a # Match Scale Value # We remove Soft distances self.softik.Value = 0 if dRootEffLength > dBonesLength: if self.scale.Value > self.maxstretch.Value: self.maxstretch.Value = self.scale.Value self.scale.Value = 1 if self.isleg: z = XSIMath.CreateVector3(1,0,0) y = XSIMath.CreateVector3(0,1,0) if self.negate: z.NegateInPlace() y.NegateInPlace() z.MulByRotationInPlace(self.fk2.Kinematics.Global.Transform.Rotation) y.MulByRotationInPlace(self.fk2.Kinematics.Global.Transform.Rotation) t = self.fk2.Kinematics.Global.Transform t.SetRotation(tra.getRotationFromAxis(z, y, "zy")) self.ik.Kinematics.Global.Transform = t else: tra.matchGlobalTransform(self.ik, self.fk2, False, True, True)