Ejemplo n.º 1
0
            // Apply to IKSolverFullBodyBiped
            public void Apply(IKSolverFullBodyBiped solver, float weight)
            {
                float deltaTime = Time.time - lastTime;

                lastTime = Time.time;

                if (timer >= length)
                {
                    return;
                }

                // Advance the timer
                timer = Mathf.Clamp(timer + deltaTime, 0f, length);

                // Advance the crossFader
                if (crossFadeSpeed > 0f)
                {
                    crossFader = Mathf.Clamp(crossFader + (deltaTime * crossFadeSpeed), 0f, 1f);
                }
                else
                {
                    crossFader = 1f;
                }

                // Pass this on to the hit points
                OnApply(solver, weight);
            }
Ejemplo n.º 2
0
 public void OnModifyOffset(IKSolverFullBodyBiped solver, float weight, float deltaTime)
 {
     if (null == solver)
     {
         m_RemainingTime = 0;
         return;
     }
     if (m_RemainingTime > 0f)
     {
         float   elapseTime      = m_StepTime - m_RemainingTime;
         float   crossFadeWeight = Mathf.Clamp01(elapseTime / m_FadeTime);
         Vector3 deltaDir        = solver.GetRoot().position - m_StartPos;
         foreach (EffectortLink effect in m_Effects)
         {
             effect.OnModifyOffset(solver, m_EffectDir, elapseTime / m_StepTime, weight * crossFadeWeight * m_Weight, deltaDir);
         }
         m_RemainingTime -= deltaTime;
     }
             #if UNITY_EDITOR
     if (m_Test)
     {
         m_Test = false;
         DoEffect(solver, m_EffectDir, m_Weight);
     }
             #endif
 }
Ejemplo n.º 3
0
 public void Apply(IKSolverFullBodyBiped solver, float weight)
 {
     for (int i = 0; i < this.effectorLinks.Length; i++)
     {
         this.effectorLinks[i].Apply(solver, weight, solver.GetRoot().rotation);
     }
 }
Ejemplo n.º 4
0
            // Update this body, apply the offset to the effector
            public void Update(IKSolverFullBodyBiped solver, float weight)
            {
                // If first update, set this body to Transform
                if (firstUpdate)
                {
                    Reset();
                    firstUpdate = false;
                }

                // not using Time.deltaTime or Time.fixedDeltaTime here, because we don't know if animatePhysics is true or not on the character, so we have to keep track of time ourselves.
                float deltaTime = Time.time - lastTime;

                // Acceleration
                direction = Vector3.Lerp(direction, transform.position - lazyPoint, deltaTime * acceleration);

                // Lazy follow
                lazyPoint += direction * deltaTime * speed;

                // Match velocity
                delta      = transform.position - lastPosition;
                lazyPoint += delta * matchVelocity;

                // Gravity
                lazyPoint.y += gravity * deltaTime;

                // Apply position offset to the effector
                foreach (EffectorLink effectorLink in effectorLinks)
                {
                    solver.GetEffector(effectorLink.effector).positionOffset += (lazyPoint - transform.position) * effectorLink.weight * weight;
                }

                lastPosition = transform.position;
                lastTime     = Time.time;
            }
Ejemplo n.º 5
0
            // Update this body, apply the offset to the effector
            public void Update(IKSolverFullBodyBiped solver, float weight, float deltaTime)
            {
                if (transform == null)
                {
                    return;
                }

                // If first update, set this body to Transform
                if (firstUpdate)
                {
                    Reset();
                    firstUpdate = false;
                }

                // Acceleration
                direction = Vector3.Lerp(direction, ((transform.position - lazyPoint) / deltaTime) * 0.01f, deltaTime * acceleration);

                // Lazy follow
                lazyPoint += direction * deltaTime * speed;

                // Match velocity
                delta      = transform.position - lastPosition;
                lazyPoint += delta * matchVelocity;

                // Gravity
                lazyPoint.y += gravity * deltaTime;

                // Apply position offset to the effector
                foreach (EffectorLink effectorLink in effectorLinks)
                {
                    solver.GetEffector(effectorLink.effector).positionOffset += (lazyPoint - transform.position) * effectorLink.weight * weight;
                }

                lastPosition = transform.position;
            }
Ejemplo n.º 6
0
 public void Apply(IKSolverFullBodyBiped solver, float weight, Quaternion rotation)
 {
     for (int i = 0; i < this.effectorLinks.Length; i++)
     {
         this.effectorLinks[i].Apply(solver, weight, rotation);
     }
 }
Ejemplo n.º 7
0
        private void Start()
        {
            this.ik = base.GetComponent <FullBodyBipedIK>();
            IKSolverFullBodyBiped expr_17 = this.ik.solver;

            expr_17.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Combine(expr_17.OnPostUpdate, new IKSolver.UpdateDelegate(this.RotateShoulders));
        }
Ejemplo n.º 8
0
        public static void InitIKTarget(OCIChar _ociChar, bool _addInfo)
        {
            IKSolverFullBodyBiped solver     = (IKSolverFullBodyBiped)_ociChar.finalIK.solver;
            BipedReferences       references = (BipedReferences)_ociChar.finalIK.references;

            _ociChar.ikCtrl = _ociChar.preparation.IKCtrl;
            AddObjectAssist.AddIKTarget(_ociChar, _ociChar.ikCtrl, 0, solver.get_bodyEffector(), false, (Transform)references.pelvis);
            AddObjectAssist.AddIKTarget(_ociChar, _ociChar.ikCtrl, 1, solver.get_leftShoulderEffector(), false, (Transform)references.leftUpperArm);
            AddObjectAssist.AddIKTarget(_ociChar, _ociChar.ikCtrl, 2, solver.get_leftArmChain(), false, (Transform)references.leftForearm);
            AddObjectAssist.AddIKTarget(_ociChar, _ociChar.ikCtrl, 3, solver.get_leftHandEffector(), true, (Transform)references.leftHand);
            AddObjectAssist.AddIKTarget(_ociChar, _ociChar.ikCtrl, 4, solver.get_rightShoulderEffector(), false, (Transform)references.rightUpperArm);
            AddObjectAssist.AddIKTarget(_ociChar, _ociChar.ikCtrl, 5, solver.get_rightArmChain(), false, (Transform)references.rightForearm);
            AddObjectAssist.AddIKTarget(_ociChar, _ociChar.ikCtrl, 6, solver.get_rightHandEffector(), true, (Transform)references.rightHand);
            AddObjectAssist.AddIKTarget(_ociChar, _ociChar.ikCtrl, 7, solver.get_leftThighEffector(), false, (Transform)references.leftThigh);
            AddObjectAssist.AddIKTarget(_ociChar, _ociChar.ikCtrl, 8, solver.get_leftLegChain(), false, (Transform)references.leftCalf);
            AddObjectAssist.AddIKTarget(_ociChar, _ociChar.ikCtrl, 9, solver.get_leftFootEffector(), true, (Transform)references.leftFoot);
            AddObjectAssist.AddIKTarget(_ociChar, _ociChar.ikCtrl, 10, solver.get_rightThighEffector(), false, (Transform)references.rightThigh);
            AddObjectAssist.AddIKTarget(_ociChar, _ociChar.ikCtrl, 11, solver.get_rightLegChain(), false, (Transform)references.rightCalf);
            AddObjectAssist.AddIKTarget(_ociChar, _ociChar.ikCtrl, 12, solver.get_rightFootEffector(), true, (Transform)references.rightFoot);
            if (!_addInfo)
            {
                return;
            }
            _ociChar.ikCtrl.InitTarget();
        }
Ejemplo n.º 9
0
        protected override void Start()
        {
            base.Start();
            IKSolverFullBodyBiped expr_11 = this.ik.solver;

            expr_11.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Combine(expr_11.OnPostUpdate, new IKSolver.UpdateDelegate(this.AfterFBBIK));
        }
Ejemplo n.º 10
0
        public IKTargetPair(MotionIK.IKTargetPair.IKTarget target, IKSolverFullBodyBiped solver)
        {
            switch (target)
            {
            case MotionIK.IKTargetPair.IKTarget.LeftHand:
                this.effector = solver.get_leftHandEffector();
                this.bend     = (IKConstraintBend)solver.get_leftArmChain().bendConstraint;
                break;

            case MotionIK.IKTargetPair.IKTarget.RightHand:
                this.effector = solver.get_rightHandEffector();
                this.bend     = (IKConstraintBend)solver.get_rightArmChain().bendConstraint;
                break;

            case MotionIK.IKTargetPair.IKTarget.LeftFoot:
                this.effector = solver.get_leftFootEffector();
                this.bend     = (IKConstraintBend)solver.get_leftLegChain().bendConstraint;
                break;

            case MotionIK.IKTargetPair.IKTarget.RightFoot:
                this.effector = solver.get_rightFootEffector();
                this.bend     = (IKConstraintBend)solver.get_rightLegChain().bendConstraint;
                break;
            }
        }
Ejemplo n.º 11
0
            public void Update(IKSolverFullBodyBiped solver, float w, float deltaTime)
            {
                if (this.transform == null || this.relativeTo == null)
                {
                    return;
                }
                Vector3 a = this.relativeTo.InverseTransformDirection(this.transform.position - this.relativeTo.position);

                if (this.firstUpdate)
                {
                    this.lastRelativePos = a;
                    this.firstUpdate     = false;
                }
                Vector3 vector = (a - this.lastRelativePos) / deltaTime;

                this.smoothDelta = ((this.speed > 0f) ? Vector3.Lerp(this.smoothDelta, vector, deltaTime * this.speed) : vector);
                Vector3 v  = this.relativeTo.TransformDirection(this.smoothDelta);
                Vector3 a2 = V3Tools.ExtractVertical(v, solver.GetRoot().up, this.verticalWeight) + V3Tools.ExtractHorizontal(v, solver.GetRoot().up, this.horizontalWeight);

                for (int i = 0; i < this.effectorLinks.Length; i++)
                {
                    solver.GetEffector(this.effectorLinks[i].effector).positionOffset += a2 * w * this.effectorLinks[i].weight;
                }
                this.lastRelativePos = a;
            }
Ejemplo n.º 12
0
 // Set effector position and rotation to match it's bone
 public void SetToBone(IKSolverFullBodyBiped solver)
 {
     // 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.
     solver.GetEffector(effector).position = solver.GetEffector(effector).bone.position;
     solver.GetEffector(effector).rotation = solver.GetEffector(effector).bone.rotation;
 }
Ejemplo n.º 13
0
 // Apply offset to FBBIK effectors
 public void Apply(IKSolverFullBodyBiped solver, Quaternion rotation, float masterWeight)
 {
     foreach (EffectorLink e in effectorLinks)
     {
         solver.GetEffector(e.effector).positionOffset += rotation * (offset * masterWeight * e.weight);
     }
 }
Ejemplo n.º 14
0
 // Apply positionOffsets of all the EffectorLinks
 public void Apply(IKSolverFullBodyBiped solver, float weight)
 {
     for (int i = 0; i < effectorLinks.Length; i++)
     {
         effectorLinks[i].Apply(solver, weight);
     }
 }
Ejemplo n.º 15
0
                public void Update(IKSolverFullBodyBiped solver, float weight, float deltaTime, float velocity)
                {
                    //Update inertia
                    Vector3 delta = m_FollowTarget.position - m_LazyPoint;

                    Vector3 currentSpeed = delta / deltaTime;
                    Vector3 vecChgange   = currentSpeed - m_LastVelocity;
                    float   dTime        = vecChgange.magnitude / m_InertiaAcc;

                    dTime           = Mathf.Min(dTime, deltaTime);
                    m_LastVelocity += vecChgange.normalized * m_InertiaAcc * dTime;

                    //
                    m_LazyPoint += m_LastVelocity * deltaTime;

                    delta = m_FollowTarget.position - m_LazyPoint;

                    // Match velocity
                    m_LazyPoint += delta * m_MachVelocity;

                    delta = m_LazyPoint - m_FollowTarget.position;

                    foreach (EffectorLink effectorLink in m_EffectorLink)
                    {
                        solver.GetEffector(effectorLink.m_Effector).positionOffset += delta * effectorLink.m_Weight * weight * m_VelocityFacter.Evaluate(velocity);
                    }
                }
Ejemplo n.º 16
0
 public void OnModifyOffset(IKSolverFullBodyBiped solver, float weight, float deltaTime)
 {
     foreach (HitPart part in m_HitParts)
     {
         part.OnModifyOffset(solver, weight * weightScale, deltaTime);
     }
 }
Ejemplo n.º 17
0
 private void OnDestroy()
 {
     if (this.ik != null)
     {
         IKSolverFullBodyBiped expr_1C = this.ik.solver;
         expr_1C.OnPreRead = (IKSolver.UpdateDelegate)Delegate.Remove(expr_1C.OnPreRead, new IKSolver.UpdateDelegate(this.OnPreRead));
     }
 }
Ejemplo n.º 18
0
            public float m_SubForward;                //Addition forward state. 1: forward -1:backward

            // Reset to Transform
            public void Reset(IKSolverFullBodyBiped solver)
            {
                m_LastPosition = solver.GetRoot().position;
                foreach (EffectorLink effectorLink in m_EffectorLinks)
                {
                    effectorLink.Reset();
                }
            }
        public void Initiate(BehaviourBase behaviour, SubBehaviourCOM centerOfMass, IKSolverFullBodyBiped solver)
        {
            this.behaviour    = behaviour;
            this.centerOfMass = centerOfMass;
            this.solver       = solver;

            behaviour.OnPostRead += OnPostRead;
        }
Ejemplo n.º 20
0
 private void OnDestroy()
 {
     if (this.ik != null)
     {
         IKSolverFullBodyBiped expr_1C = this.ik.solver;
         expr_1C.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(expr_1C.OnPostUpdate, new IKSolver.UpdateDelegate(this.RotateShoulders));
     }
 }
Ejemplo n.º 21
0
 // Token: 0x06004EBA RID: 20154 RVA: 0x001A7149 File Offset: 0x001A5549
 private void OnDestroy()
 {
     if (this.ik != null)
     {
         IKSolverFullBodyBiped solver = this.ik.solver;
         solver.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(solver.OnPostUpdate, new IKSolver.UpdateDelegate(this.OnPostFBBIK));
     }
 }
Ejemplo n.º 22
0
            public Transform target;               // The target

            // Update IK position, rotation and weight
            public void Update(IKSolverFullBodyBiped solver, float weight)
            {
                solver.GetEffector(effector).position = target.position;
                solver.GetEffector(effector).rotation = target.rotation;

                solver.GetEffector(effector).positionWeight = positionWeight * weight;
                solver.GetEffector(effector).rotationWeight = rotationWeight * weight;
            }
Ejemplo n.º 23
0
 public void Apply(IKSolverFullBodyBiped solver, Quaternion rotation, float masterWeight)
 {
     Recoil.RecoilOffset.EffectorLink[] array = this.effectorLinks;
     for (int i = 0; i < array.Length; i++)
     {
         Recoil.RecoilOffset.EffectorLink effectorLink = array[i];
         solver.GetEffector(effectorLink.effector).positionOffset += rotation * (this.offset * masterWeight * effectorLink.weight);
     }
 }
Ejemplo n.º 24
0
            public void Apply(IKSolverFullBodyBiped solver, float weight, Quaternion rotation)
            {
                solver.GetEffector(this.effector).positionOffset += rotation * this.offset * weight;
                Vector3 a       = solver.GetRoot().position + rotation * this.pin;
                Vector3 vector  = a - solver.GetEffector(this.effector).bone.position;
                Vector3 vector2 = this.pinWeight * Mathf.Abs(weight);

                solver.GetEffector(this.effector).positionOffset = new Vector3(Mathf.Lerp(solver.GetEffector(this.effector).positionOffset.x, vector.x, vector2.x), Mathf.Lerp(solver.GetEffector(this.effector).positionOffset.y, vector.y, vector2.y), Mathf.Lerp(solver.GetEffector(this.effector).positionOffset.z, vector.z, vector2.z));
            }
Ejemplo n.º 25
0
        public bool m_PinWordPos = false;         // Wether pin effect in world position

        public void OnModifyOffset(IKSolverFullBodyBiped solver, Vector3 dir, float timeP, float weight, Vector3 deltaDir)
        {
            if (null == solver)
            {
                return;
            }
            solver.GetEffector(m_Effector).positionOffset
                += (m_ForceDir.Evaluate(timeP) * dir + m_UpDir.Evaluate(timeP) * Vector3.up - (m_PinWordPos?deltaDir:Vector3.zero)) * weight;
        }
Ejemplo n.º 26
0
        public static void InitIKTarget(OCIChar _ociChar, bool _addInfo)
        {
            IKSolverFullBodyBiped solver = _ociChar.finalIK.solver;

            solver.rightShoulderEffector.target.name = "f_t_shoulder_R(work)";
            solver.leftShoulderEffector.target.name  = "f_t_shoulder_L(work)";
            BepInEx.Logging.Logger.LogWarning("IK patch applied for: " + solver.rightShoulderEffector.target.name);
            BepInEx.Logging.Logger.LogWarning("IK patch applied for: " + solver.leftShoulderEffector.target.name);
        }
Ejemplo n.º 27
0
 public static MotionIK.IKTargetPair[] GetPairs(IKSolverFullBodyBiped solver)
 {
     for (int index1 = 0; index1 < MotionIK.IKTargetPair.ret.Length; ++index1)
     {
         int index2 = index1;
         MotionIK.IKTargetPair.ret[index2] = new MotionIK.IKTargetPair((MotionIK.IKTargetPair.IKTarget)index2, solver);
     }
     return(MotionIK.IKTargetPair.ret);
 }
Ejemplo n.º 28
0
            // Apply offset to FBBIK effectors
            public void Apply(IKSolverFullBodyBiped solver, Quaternion rotation, float masterWeight, float length, float timeLeft)
            {
                additiveOffset = Vector3.Lerp(Vector3.zero, additiveOffset, timeLeft / length);
                lastOffset     = (rotation * (offset * masterWeight)) + (rotation * additiveOffset);

                foreach (EffectorLink e in effectorLinks)
                {
                    solver.GetEffector(e.effector).positionOffset += lastOffset * e.weight;
                }
            }
Ejemplo n.º 29
0
 public void OnHit(IKSolverFullBodyBiped solver, Transform trans, Vector3 dir, float weight, float effectTime)
 {
     foreach (HitPart part in m_HitParts)
     {
         if (part.m_PartTrans.Contains(trans))
         {
             part.Hit(solver, dir, weight * weightScale, effectTime);
         }
     }
 }
Ejemplo n.º 30
0
            public void Update(IKSolverFullBodyBiped solver, float deltaTime)
            {
                float velocity = (solver.GetRoot().position - m_LastPos).magnitude / deltaTime;

                m_LastPos = solver.GetRoot().position;
                foreach (InertiaBody body in m_Bodies)
                {
                    body.Update(solver, m_Weight * m_FadeWeight, deltaTime, velocity);
                }
            }