public PlayerHandBehaviours(PlayerBehaviours abb, PropHandler ph, FBIKChain hc, IKEffector iKEffector) : base(abb, ph) { handChain = hc; hp = ac.humanoidParts; handEffector = iKEffector; //Muscle handMuscle = ph.attachedMuscleGroup.muscles[ph.attachedMuscleGroup.muscles.Length - 1];// 最后一个位置即为 最末尾的 hand 的 muscle }
// private void GetFootContact(IKEffector IK, Transform Bone, Transform ToeTip, Vector3 BoneSpeed, RaycastHit HIT, RaycastHit THIT) { Ray RAY1 = new Ray(new Vector3(IK.position.x, BIK.position.y, IK.position.z), new Vector3(0, -1, 0)); Ray RAY2; if (ToeTip) { RAY2 = new Ray(new Vector3(ToeTip.position.x, BIK.position.y, ToeTip.position.z), new Vector3(0, -1, 0)); } else { RAY2 = RAY1; } // if (Physics.Raycast(RAY1, out HIT, (LegLength * RayReach), FeetMask.value)) { IK.positionWeight = 1f; IK.rotationWeight = 1f; IK.position = Vector3.Lerp(IK.position, new Vector3(Bone.position.x, HIT.point.y + HeelOffset, Bone.position.z), Time.time); IK.rotation = Quaternion.FromToRotation(Vector3.up, HIT.normal) * IK.bone.rotation; Debug.DrawLine(RAY1.origin, BIK.position, Color.cyan); Debug.DrawLine(RAY1.origin, IK.position, Color.green); Debug.DrawLine(IK.position, HIT.point, Color.red); } // if (ToeTip && Physics.Raycast(RAY2, out THIT, (LegLength * RayReach), FeetMask.value) && THIT.point.y > HIT.point.y) { IK.positionWeight = 1f; IK.rotationWeight = 1f; IK.position = Vector3.Lerp(IK.position, new Vector3(Bone.position.x, THIT.point.y + HeelOffset, Bone.position.z), Time.time); IK.rotation = Quaternion.FromToRotation(Vector3.up, THIT.normal) * IK.bone.rotation; Debug.DrawLine(RAY2.origin, BIK.position, Color.cyan); Debug.DrawLine(RAY2.origin, ToeTip.position, Color.green); Debug.DrawLine(ToeTip.position, THIT.point, Color.red); } // if (IK.position.y < THIT.point.y) { IK.position = new Vector3(Bone.position.x, THIT.point.y + HeelOffset, Bone.position.z); } }
// Rotate an effector from the root of the character private void RotateEffector(IKEffector effector, Quaternion rotation, float mlp) { Vector3 d1 = effector.bone.position - transform.position; Vector3 d2 = rotation * d1; Vector3 offset = d2 - d1; effector.positionOffset += offset * mlp; }
void Awake() { newRotation = new Vector3(0, 0, 0); resetCam = new Vector3(0, 0, 0); posweight = 0f; rotweight = 0f; lefthand = ik.solver.leftHandEffector; }
private void RotateEffector(IKEffector effector, Quaternion rotation, float mlp) { Vector3 vector = effector.bone.position - base.transform.position; Vector3 a = rotation * vector; Vector3 a2 = a - vector; effector.positionOffset += a2 * mlp; }
private void RotateEffector(IKEffector effector, Quaternion rotation, float mlp) { Vector3 vector3_1 = Vector3.op_Subtraction(((Transform)effector.bone).get_position(), ((Component)this).get_transform().get_position()); Vector3 vector3_2 = Vector3.op_Subtraction(Quaternion.op_Multiply(rotation, vector3_1), vector3_1); IKEffector ikEffector = effector; ikEffector.positionOffset = (__Null)Vector3.op_Addition((Vector3)ikEffector.positionOffset, Vector3.op_Multiply(vector3_2, mlp)); }
static bool Prefix(MotionIKUI __instance, ChaControl _chara, Motion.IK _ik, FullBodyBipedIK _fullBodyIK, KinematicCtrl _kinematicCtrl, int _charaID) { if (_ik == null || _fullBodyIK == null || _kinematicCtrl == null) { return(false); } var hEditInstance = Singleton <HEditGlobal> .Instance; var nowPartCharaInfo = hEditInstance.nowPartCharaInfo; hEditInstance.nowPartCharaInfo = null; if (_ik.isUse) { _kinematicCtrl.Active(PoseInfo.ModeEN.IK, false); } var effectors = new IKEffector[] { _fullBodyIK.solver.bodyEffector, _fullBodyIK.solver.leftShoulderEffector, _fullBodyIK.solver.leftHandEffector, _fullBodyIK.solver.rightShoulderEffector, _fullBodyIK.solver.rightHandEffector, _fullBodyIK.solver.leftThighEffector, _fullBodyIK.solver.leftFootEffector, _fullBodyIK.solver.rightThighEffector, _fullBodyIK.solver.rightFootEffector }; var chains = new FBIKChain[] { _fullBodyIK.solver.leftArmChain, _fullBodyIK.solver.rightArmChain, _fullBodyIK.solver.leftLegChain, _fullBodyIK.solver.rightLegChain }; for (int i = 0; i < EffectorIndices.Length; i++) { var targetIndex = EffectorIndices[i]; var effector = effectors[i]; var area = _ik.areas[targetIndex]; SetIKUse(__instance, targetIndex, effector, area.isUse, _kinematicCtrl, false); SetIKWeight(__instance, targetIndex, effector, area.isUse, area.weight, false); hEditInstance.SetIKParent(_chara, _kinematicCtrl, area.parentCharaID, area.parentArea, targetIndex); hEditInstance.SetIKPos(_kinematicCtrl.lstIKBone[targetIndex].changeAmount, area.amount); } for (int i = 0; i < ChainIndices.Length; i++) { var targetIndex = ChainIndices[i]; var chain = chains[i]; var area = _ik.areas[targetIndex]; SetIKUse(__instance, targetIndex, chain, area.isUse, _kinematicCtrl, false); SetIKWeight(__instance, targetIndex, chain, area.isUse, area.weight, false); hEditInstance.SetIKParent(_chara, _kinematicCtrl, area.parentCharaID, area.parentArea, targetIndex); hEditInstance.SetIKPos(_kinematicCtrl.lstIKBone[targetIndex].changeAmount, area.amount); } if (!_ik.isUse) { _kinematicCtrl.Active(PoseInfo.ModeEN.None, false); } else if (__instance.CharaInfoData != null && __instance.CharaInfoData.useCharaID != _charaID) { hEditInstance.KinematicCtrlAllVisible(_kinematicCtrl, false); } hEditInstance.nowPartCharaInfo = nowPartCharaInfo; return(false); }
public Footstep(IKEffector effector, Transform thigh, Muscle pelvisMuscle, bool isLeft) { this.effector = effector; this.thigh = thigh; this.pelvisMuscle = pelvisMuscle; this.isLeft = isLeft; Reset(); }
protected void Start() { var ik = GetComponent <FullBodyBipedIK>(); var solver = ik.GetIKSolver() as IKSolverFullBodyBiped; reachingHand = solver.rightHandEffector; reachingHand.positionWeight = 0; relaxedPos = reachPos = reachingHand.bone.position; }
public static EffectorHandle Create(IKEffector effector, IllusionCamera camera) { var handle = GameObject.CreatePrimitive(PrimitiveType.Cube).AddComponent <EffectorHandle>(); handle.transform.localScale *= 0.1f; handle.camera = camera; handle.effector = effector; effector.maintainRelativePositionWeight = 1; return(handle); }
private static OCIChar.IKInfo AddIKTarget( OCIChar _ociChar, IKCtrl _ikCtrl, int _no, IKEffector _effector, bool _usedRot, Transform _bone) { OCIChar.IKInfo ikInfo = AddObjectAssist.AddIKTarget(_ociChar, _ikCtrl, _no, (Transform)_effector.target, _usedRot, _bone, true); _effector.positionWeight = (__Null)1.0; _effector.rotationWeight = !_usedRot ? (__Null)0.0 : (__Null)1.0; _effector.target = (__Null)ikInfo.targetObject; return(ikInfo); }
IEnumerator blendIKEffector(IKEffector ikEffector, float targetWeight, float duration) { float currentWeight = ikEffector.positionWeight; float time = 0; float percentage = 0; while (percentage < 1) { time += Time.deltaTime; percentage = time / duration; ikEffector.positionWeight = Mathf.Lerp(currentWeight, targetWeight, percentage); yield return(null); } ikEffector.positionWeight = targetWeight; ikEffector.target = null; }
// private void Awake() { FBIK = GetComponent <FullBodyBipedIK>(); // Body = FBIK.references.spine[BodySpineID]; BIK = FBIK.solver.bodyEffector; LFIK = FBIK.solver.leftFootEffector; RFIK = FBIK.solver.rightFootEffector; // LeftFoot = FBIK.references.leftFoot; RightFoot = FBIK.references.rightFoot; // LeftFootContact = new RaycastHit(); RightFootContact = new RaycastHit(); LeftToeContact = new RaycastHit(); RightToeContact = new RaycastHit(); LegLength = Vector3.Distance(LeftFoot.position, Body.position); }
internal Limb(LimbName limbpart, GameObject anchorObj, Transform animPos, IKEffector effector, Transform origTarget, BaseData targetBone, FBIKChain chain = null, BaseData parentJointBone = null, IKEffector parentJointEffector = null, Transform parentJointAnimPos = null, bool fix = false) { LimbPart = limbpart; AnchorObj = anchorObj; AnimPos = animPos; Effector = effector; Chain = chain; OrigTarget = origTarget; TargetBone = targetBone; Fixed = fix; ParentJointBone = parentJointBone; ParentJointEffector = parentJointEffector; ParentJointAnimPos = parentJointAnimPos; }
//TODO: Push() and Pull() /*like grab but no target on opponent's body*/ /* * public bool Grab(MovePoint grabber, AttachPoint target) * { * bool reachedTarget = Move(grabber, target.AttachObject.transform); * if (reachedTarget) * { * //DebugLog("Reached target Player " + PlayerNumber); * target.AttachedTo = grabber; * } * return reachedTarget; * } */ public bool Move(BodyPoint bodyPoint, Transform target) { IKEffector effector = _ik.solver.GetEffector(bodyPoint.Effector); if (Vector3.Distance(effector.position, target.position) < MOVE_COMPLETE_PROXIMITY) { return(true); } float step = HAND_MOVE_SPEED * Time.deltaTime; bodyPoint.EffectorTargetPositionWeight = 1.0f; bodyPoint.EffectorTargetPosition = Vector3.Lerp(effector.position, target.position, step); Debug.DrawLine(bodyPoint.EffectorTargetPosition, target.position, Color.white); return(false); }
// Set effector position and rotation to match it's bone public void SetToBone(IKSolverFullBodyBiped solver, Mode mode) { e = solver.GetEffector(effector); // Using world space position and rotation here for the sake of simplicity of the demo // Ideally we should use position and rotation relative to character's root, so we could move around while doing this. switch (mode) { case Mode.Position: e.position = e.bone.position; e.rotation = e.bone.rotation; return; case Mode.PositionOffset: position = e.bone.position; rotation = e.bone.rotation; return; } }
private void HandsOnProp(IKEffector mainHand, IKEffector otherHand) { Vector3 vector = otherHand.bone.position - mainHand.bone.position; Vector3 point = Quaternion.Inverse(mainHand.bone.rotation) * vector; Vector3 b = mainHand.bone.position + vector * 0.5f; Quaternion rhs = Quaternion.Inverse(mainHand.bone.rotation) * otherHand.bone.rotation; Vector3 toDirection = otherHand.bone.position + otherHand.positionOffset - (mainHand.bone.position + mainHand.positionOffset); Vector3 a = mainHand.bone.position + mainHand.positionOffset + vector * 0.5f; mainHand.position = mainHand.bone.position + mainHand.positionOffset + (a - b); mainHand.positionWeight = 1f; Quaternion lhs = Quaternion.FromToRotation(vector, toDirection); mainHand.rotation = lhs * mainHand.bone.rotation; mainHand.rotationWeight = 1f; otherHand.position = mainHand.position + mainHand.rotation * point; otherHand.positionWeight = 1f; otherHand.rotation = mainHand.rotation * rhs; otherHand.rotationWeight = 1f; }
// DOTween.To(()=> myVector, x=> myVector = x, new Vector3(3,4,8), 1); // Use this for initialization void Start() { rgdB = this.GetComponent <Rigidbody>(); rgdB.constraints = RigidbodyConstraints.FreezeRotation; rgdB.useGravity = false; myTransform = transform; mainCameraGO = transform.Find("Camera").gameObject; //targetBone = head.transform.GetChild(0).gameObject; targetBone = GameObject.Find("Target Aim").gameObject; originalHeadRotation = mainCameraGO.transform.localRotation; arrowReference.SetActive(false); bipedIk = transform.GetChild(0).GetComponent <FullBodyBipedIK>(); rightHand = bipedIk.solver.rightHandEffector; leftHand = bipedIk.solver.leftHandEffector; initialHandTargetPosition = rightHand.target.localPosition; //TEST velocityV = new Vector3(); pene = new Vector3(); pene = this.transform.position; //ARROW flecha = Instantiate <GameObject>(arrowReference); // flecha.transform.position = arrowReference.transform.position; flecha.transform.rotation = arrowReference.transform.rotation; // flecha.SetActive(true); flecha.transform.localScale = arrowReference.transform.lossyScale; flecha.transform.SetParent(arrowReference.transform.parent); //ShotTimeLapse returningLeftHandTween = DOTween.To(() => leftHand.positionWeight, x => leftHand.positionWeight = x, 0.0f, 0.5f); returningRightHandTween = DOTween.To(() => rightHand.positionWeight, x => rightHand.positionWeight = x, 0.0f, 0.5f); }
public Leg(IKSolverFullBodyBiped solver, PuppetMaster puppetMaster, FullBodyBipedEffector effectorType) { this.solver = solver; effector = solver.GetEffector(effectorType); chain = solver.GetChain(effectorType); stepFrom = effector.bone.position; stepTo = effector.bone.position; position = effector.bone.position; offset = effectorType == FullBodyBipedEffector.LeftFoot? Vector3.left: Vector3.right; stepTimer = 0f; stepLength = 0f; muscle = puppetMaster.GetMuscle(effector.bone); thighMuscle = puppetMaster.GetMuscle(chain.nodes[0].transform); mass = muscle.rigidbody.mass; inertiaTensor = muscle.rigidbody.inertiaTensor; }
// Apply the limit to the effector public void Apply(IKEffector e, Quaternion rootRotation) { Vector3 offset = Quaternion.Inverse(rootRotation) * e.positionOffset; if (spring <= 0f) { // Hard limits if (x) { offset.x = Mathf.Clamp(offset.x, minX, maxX); } if (y) { offset.y = Mathf.Clamp(offset.y, minY, maxY); } if (z) { offset.z = Mathf.Clamp(offset.z, minZ, maxZ); } } else { // Soft limits if (x) { offset.x = SpringAxis(offset.x, minX, maxX); } if (y) { offset.y = SpringAxis(offset.y, minY, maxY); } if (z) { offset.z = SpringAxis(offset.z, minZ, maxZ); } } // Apply to the effector e.positionOffset = rootRotation * offset; }
private void HandsOnProp(IKEffector mainHand, IKEffector otherHand) { // Get the animated direction from the main hand to the other hand Vector3 toOtherHand = otherHand.bone.position - mainHand.bone.position; // Get the hand direction relative to the main hand's rotation Vector3 otherHandRelativeDirection = Quaternion.Inverse(mainHand.bone.rotation) * toOtherHand; // Get the center point of two hands Vector3 handsCenter = mainHand.bone.position + (toOtherHand * 0.5f); // Get the other hand's rotation relative to the main hand's rotation Quaternion otherHandRelativeRotation = Quaternion.Inverse(mainHand.bone.rotation) * otherHand.bone.rotation; // Get the direction from the main hand to the other hand that icludes effector position offsets Vector3 toOtherHandWithOffset = (otherHand.bone.position + otherHand.positionOffset) - (mainHand.bone.position + mainHand.positionOffset); // Get the center point of two hands that includes effector position offsets Vector3 handsCenterWithOffset = (mainHand.bone.position + mainHand.positionOffset) + (toOtherHand * 0.5f); // Main hand position mainHand.position = (mainHand.bone.position + mainHand.positionOffset) + (handsCenterWithOffset - handsCenter); mainHand.positionWeight = 1f; // Main hand rotation Quaternion rotationOffset = Quaternion.FromToRotation(toOtherHand, toOtherHandWithOffset); mainHand.bone.rotation = rotationOffset * mainHand.bone.rotation; // Other hand position otherHand.position = mainHand.position + mainHand.bone.rotation * otherHandRelativeDirection; otherHand.positionWeight = 1f; // Other hand rotation otherHand.bone.rotation = mainHand.bone.rotation * otherHandRelativeRotation; ik.solver.leftArmMapping.maintainRotationWeight = 1f; ik.solver.rightArmMapping.maintainRotationWeight = 1f; }
public void Apply(IKEffector e, Quaternion rootRotation) { Vector3 point = Quaternion.Inverse(rootRotation) * e.positionOffset; if (this.spring <= 0f) { if (this.x) { point.x = Mathf.Clamp(point.x, this.minX, this.maxX); } if (this.y) { point.y = Mathf.Clamp(point.y, this.minY, this.maxY); } if (this.z) { point.z = Mathf.Clamp(point.z, this.minZ, this.maxZ); } } else { if (this.x) { point.x = this.SpringAxis(point.x, this.minX, this.maxX); } if (this.y) { point.y = this.SpringAxis(point.y, this.minY, this.maxY); } if (this.z) { point.z = this.SpringAxis(point.z, this.minZ, this.maxZ); } } e.positionOffset = rootRotation * point; }
} // 0x00000001804BD990-0x00000001804BDC90 private void RotateEffector(IKEffector effector, Quaternion rotation, float mlp) { } // 0x00000001804BDC90-0x00000001804BDE90
public static bool IsInRange(IKEffector effector, Vector3 toCheck) { return(GetDistance(effector, toCheck) < GRAB_RANGE); }
public static float GetDistance(IKEffector effector, Vector3 toCheck) { return(Vector3.Distance(GetEffectorPosition(effector), toCheck)); }
public static Quaternion GetEffectorRotation(IKEffector effector) { return(effector.bone.rotation); }
public static Vector3 GetEffectorPosition(IKEffector effector) { return(effector.bone.position); }
public EffectorAndActor(IKEffector effector, CharBody actor) { Effector = effector; Actor = actor; }
private static void SetIKUse(MotionIKUI instance, int area, IKEffector effector, bool isOn, KinematicCtrl kinematicCtrl, bool isSave) { SetIKUseEffectorMethod.Invoke(instance, new object[] { area, effector, isOn, kinematicCtrl, isSave }); }
private static void SetIKWeight(MotionIKUI instance, int area, IKEffector effector, bool isOn, float value, bool isSave) { SetIKWeightEffectorMethod.Invoke(instance, new object[] { area, effector, isOn, value, isSave }); }