Пример #1
0
        protected override void InitializeSpace()
        {
            solver   = new IKSolver();
            bones    = new List <BoneRelationship>();
            controls = new List <Control>();
            joints   = new List <IKJoint>();

            dragControl = new DragControl();

            Box ground = new Box(new Vector3(0, 0, 0), 30, 1, 30);

            Space.Add(ground);

            solver.ActiveSet.UseAutomass        = true;
            solver.AutoscaleControlImpulses     = true;
            solver.AutoscaleControlMaximumForce = Fix64.MaxValue;
            solver.TimeStepDuration             = .1m;
            solver.ControlIterationCount        = 100;
            solver.FixerIterationCount          = 10;
            solver.VelocitySubiterationCount    = 3;

            BuildActionFigure(new Vector3(5, 6, -8));
            BuildActionFigure(new Vector3(5, 6, -3));
            BuildActionFigure(new Vector3(5, 6, 3));
            BuildActionFigure(new Vector3(5, 6, 8));

            dragControl.TargetBone = bones[0].Bone;
            controls.Add(dragControl);
            dragControl.LinearMotor.Offset = new Vector3(0, 0, 0.2m);
        }
Пример #2
0
 private void OnDrawGizmos()
 {
     if (_ikHierarchy != null)
     {
         IKSolver.DrawGizmos(_ikHierarchy, _ikTarget);
     }
 }
Пример #3
0
        /// <summary>
        /// This method can be called when the flex move didn't reach the target yet, to continue to converge
        /// <returns>true if the flex move still need to be updated</returns>
        /// </summary>
        public bool update()
        {
            if (mCurrentUpdateStatus == IKSolver.CCDResult.Processing)
            {
                // a threshold tuning variable for reaching target
                const double REACH_TARGET_PRECISION_IN_STUD = 0.1;
                int          lastBone = mBoneList.Count;

                if (mUseTwoTargets)
                {
                    // if we use two targets, do the first pass on the second target
                    // reverse the Y because BlueBrick use an indirect coord sys, and the IKSolver a direct one
                    IKSolver.CalcIK_2D_CCD(ref mBoneList, mSecondaryTarget.X, -mSecondaryTarget.Y,
                                           REACH_TARGET_PRECISION_IN_STUD, lastBone - 1);
                    computeBrickPositionAndOrientation();
                }

                // do the normal pass on the final target
                // reverse the Y because BlueBrick use an indirect coord sys, and the IKSolver a direct one
                mCurrentUpdateStatus = IKSolver.CalcIK_2D_CCD(ref mBoneList, mPrimaryTarget.X, -mPrimaryTarget.Y,
                                                              REACH_TARGET_PRECISION_IN_STUD, lastBone);
                computeBrickPositionAndOrientation();
            }

            // return true if we still need to update
            return(mCurrentUpdateStatus == IKSolver.CCDResult.Processing);
        }
Пример #4
0
 protected PathPlanner(Obstacle[] obstacles, IKSolver solver, int maxTime, bool collisionCheck)
 {
     Obstacles      = obstacles;
     Solver         = solver;
     MaxTime        = maxTime;
     CollisionCheck = collisionCheck;
 }
Пример #5
0
 public static void Postfix(IKSolver __instance)
 {
     if (onPostUpdate != null)
     {
         onPostUpdate(__instance);
     }
 }
Пример #6
0
        public IKSolver GetIKArm()
        {
            ShaderInfo.Material characterMaterial;
            characterMaterial.Emissive  = new Color(0, 0, 0, 255);
            characterMaterial.Diffuse   = new Color(100, 150, 100, 255);
            characterMaterial.Specular  = new Color(255, 255, 255, 255);
            characterMaterial.Shininess = 0.8f;
            LightingInfo characterLighting = new LightingInfo("PlayerNormal", characterMaterial);

            Bone shoulder = new Bone("Shoulder", new Vector2(0), 0, new Vector2(0), new Vector2(-0.5f / 32f, 10.5f / 32f));          //Child connector is placed at location of shoulder

            Bone UpperArmFront = new Bone("UpperArm", new Vector2(0), 0, new Vector2(-0f / 32f, 5.5f / 32f), new Vector2(1.5f / 32f, -7.5f / 32f));

            UpperArmFront.Drawable            = new Drawable("Player", new Vector2(16), 32, 32, 64, 0, 0.11f);
            UpperArmFront.Drawable.ShaderInfo = characterLighting;
            shoulder.AddChild(UpperArmFront);
            Bone LowerArm = new Bone("LowerArm", new Vector2(0), 0, new Vector2(-0.5f / 32f, 7.5f / 32f), new Vector2(2.5f / 32f, -9.5f / 32f));

            LowerArm.Drawable            = new Drawable("Player", new Vector2(16), 32, 32, 0, 32, 0.12f);
            LowerArm.Drawable.ShaderInfo = characterLighting;
            UpperArmFront.AddChild(LowerArm);
            Bone Hand = new Bone("Hand", new Vector2(0), 0, new Vector2(0.5f / 32f, 2.5f / 32f), new Vector2(0.5f / 32f, -2.5f / 32f));

            Hand.Drawable            = new Drawable("Player", new Vector2(16), 32, 32, 32, 32, 0.12f);
            Hand.Drawable.ShaderInfo = characterLighting;
            LowerArm.AddChild(Hand);

            IKSolver armSolver = new IKSolver();

            armSolver.MountId = "PlayerLegs";
            armSolver.Root    = shoulder.Copy();

            return(armSolver);
        }
Пример #7
0
    // Drag the selected object in screenspace
    private void Drag(Vector3 cursorPosition)
    {
        Vector3 projectedCursorPosition = new Vector3(cursorPosition.x, cursorPosition.y, _dragDepth);
        Vector3 cursorWorldPosition     = _camera.GetComponent <Camera>().ScreenToWorldPoint(projectedCursorPosition);

        cursorWorldPosition += _dragOffset;

        _ikTarget.position = cursorWorldPosition;
        IKSolver.Evaluate(_ikHierarchy, _ikTarget);
    }
Пример #8
0
 // Start is called before the first frame update
 void Start()
 {
     animator         = this.GetComponent <Animator>();
     camera_transform = Camera.main.transform;
     controller       = this.GetComponent <CharacterController>();
     hunter           = this.GetComponent <Hunter>();
     ik_solver        = this.GetComponent <IKSolver>();
     skin.material    = body_mat;
     //conjure_transition = 1f;
     disappear_transition = 0f;
 }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public InverseKinematicsTestDemo2(DemosGame game)
            : base(game)
        {
            game.Camera.Position = new Vector3(0, 3, 5);
            Box ground = new Box(new Vector3(0, -3, 0), 30, 1, 30);

            Space.Add(ground);
            Space.ForceUpdater.Gravity = new Vector3(0, -9.81m, 0);

            var solver = new IKSolver();

            solver.ActiveSet.UseAutomass = true;
            //solver.AutoscaleControlImpulses = true;
            //solver.AutoscaleControlMaximumForce = Fix64.MaxValue;
            solver.ControlIterationCount     = 20;
            solver.FixerIterationCount       = 0;
            solver.VelocitySubiterationCount = 3;


            List <Bone>   bones;
            List <Entity> boneEntities;
            int           boneCount = 10;

            BuildStick(new Vector3(0, 0.5m, 0), boneCount, out bones, out boneEntities);

            DragControl dragger = new DragControl {
                TargetBone = bones[boneCount - 1], MaximumForce = Fix64.MaxValue
            };

            dragger.LinearMotor.Rigidity       = 16;
            dragger.LinearMotor.LocalOffset    = new Vector3(0, 0.5m, 0);
            dragger.LinearMotor.TargetPosition = new Vector3(10, 0, 0);


            bones[0].Pinned = true;

            var controls = new List <Control>();

            controls.Add(dragger);

            solver.Solve(controls);

            var tipLocation = bones[boneCount - 1].Position + Matrix3x3.CreateFromQuaternion(bones[boneCount - 1].Orientation).Up * 0.5m;

            for (int i = 0; i < bones.Count; ++i)
            {
                boneEntities[i].Position    = bones[i].Position;
                boneEntities[i].Orientation = bones[i].Orientation;
                Space.Add(boneEntities[i]);
            }
        }
 /* This function performs a call to the IKSolvers CCD algorithm, which then solves this chain to the current target. */
 private void solve()
 {
     if (ikSolveMethod == IKSolveMethod.CCD)
     {
         IKSolver.solveChainCCD(ref joints, endEffector, currentTarget, getTolerance(), getMinimumChangePerIterationOfSolving(), getSingularityRadius(), adjustLastJointToNormal, printDebugLogs);
     }
     else if (ikSolveMethod == IKSolveMethod.CCDFrameByFrame)
     {
         StartCoroutine(IKSolver.solveChainCCDFrameByFrame(joints, endEffector, currentTarget, getTolerance(), getMinimumChangePerIterationOfSolving(), getSingularityRadius(), adjustLastJointToNormal, printDebugLogs));
         deactivateSolving = true;
         //Important here is that the coroutine has to update the error after it is done. Not implemented here yet!
     }
     error = Vector3.Distance(endEffector.position, currentTarget.position);
 }
Пример #11
0
    // Todo: Locking joints by clicking on them
    private void Update()
    {
        // TODO Buttons don't work anymore
        bool mouseLeftDown = Input.GetButtonDown("unity_mouse_0");
        bool mouseLeftUp   = Input.GetButtonUp("unity_mouse_0");
        bool mouseLeft     = Input.GetButton("unity_mouse_0");

        Vector3 cursorPosition = Input.mousePosition;

        if (mouseLeftDown)
        {
            GameObject selectedObject = QueryCursor(cursorPosition);
            if (selectedObject)
            {
                MuscleJoint joint = selectedObject.GetComponent <MuscleJoint>();
                if (joint)
                {
                    StartDragging(joint);
                }
                else
                {
                    _camera.Center = selectedObject.transform.position;
                }
            }
        }
        if (mouseLeftUp)
        {
            StopDragging();
        }

        if (mouseLeft)
        {
            if (_isDragging)
            {
                Drag(cursorPosition);
            }
            else
            {
                Look();
            }
        }

        if (_jointHierarchy != null && _ikHierarchy != null)
        {
            IKSolver.Slerp(_ikHierarchy, _jointHierarchy, 10f * _clock.DeltaTime);
        }
    }
Пример #12
0
 private void IKSolverOnPostUpdate(IKSolver solver)
 {
     if (this.enabled == false || this._body.solver != solver)
     {
         return;
     }
     if (this._scheduleNextIKPostUpdate != null)
     {
         Action tempAction = this._scheduleNextIKPostUpdate;
         this._scheduleNextIKPostUpdate = null;
         tempAction();
     }
     this.InitJointCorrection();
     foreach (AdvancedModeModule module in this._modules)
     {
         module.IKSolverOnPostUpdate();
     }
 }
Пример #13
0
    public override void OnInspectorGUI()
    {
        IKSolver solver = (IKSolver)target;

        if (solver.needResetOption)
        {
            GUI.enabled = false;
        }
        DrawDefaultInspector();
        if (solver.needResetOption)
        {
            GUI.enabled = true;
            if (GUILayout.Button("Reset Scene Hierarchy"))
            {
                solver.ResetHierarchy();
            }
        }
    }
Пример #14
0
    private void StartDragging(MuscleJoint joint)
    {
        _isDragging = true;

        if (_ikHierarchy != null)
        {
            DestroyHierarchy(_ikHierarchy);
        }

        _jointHierarchy    = IKSolver.GetHierarchy(joint);
        _ikHierarchy       = IKSolver.CopyHierarchy(_jointHierarchy);
        _ikTarget.position = joint.transform.position;
        _ikTarget.rotation = joint.transform.rotation;

        Vector3 screenSpacePosition = _camera.GetComponent <Camera>().WorldToScreenPoint(joint.transform.position);

        _dragDepth = screenSpacePosition.z;
        Vector3 cursorPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpacePosition.z);

        _dragOffset = joint.transform.position - _camera.GetComponent <Camera>().ScreenToWorldPoint(cursorPosition);
    }
Пример #15
0
 void LateUpdate()
 {
     IKSolver.Solve(false, 1f, 1f, 0f, -1, -1, upperLimb, lowerLimb, endLimb, elbowForward, target.position, Vector3.zero, target.rotation);
 }
Пример #16
0
 public DynamicRRT(Obstacle[] obstacles, IKSolver solver, int maxTime, bool collisionCheck, float d, int period) : base(obstacles, solver, maxTime, collisionCheck)
 {
     this.d      = d;
     this.period = period;
 }
Пример #17
0
    //Has to be lateupdate because we overwrite the transforms
    void LateUpdate() {
        
       if (!animation.isPlaying)         
            return;

        _ikSolver = new IKArm();
	    int arm ; //arm index
	    int keyInd;

        

        float s = TimingControl(Tp);

       

       //map s into the whole spline        		   
        float t = (s * (_animInfo.NextGoal - _animInfo.PrevGoal) + _animInfo.PrevGoal) / _animInfo.AnimLength;

     

       
  //     Debug.Log(s + " " + Tp + " " + t +  " " + Time.deltaTime);
       if (_animInfo.NextGoal == _animInfo.PrevGoal)             
           t = 1f;

       if(t < 0) 
           keyInd = _animInfo.FindKeyNumberAtNormalizedTime(-t); //find an imaginary key before the start of keyframes         
       else if (t > 1) 
           keyInd =  _animInfo.FindKeyNumberAtNormalizedTime(2 - t); //find an imaginary key beyond the keyframes   1 - ( t - 1)       
       else 
           keyInd = _animInfo.FindKeyNumberAtNormalizedTime(t); //including via keys


      // if (this.gameObject == GameObject.Find("AgentPrefab"))
       //    Debug.Log(s + " " + t);
       //if (this.gameObject == GameObject.Find("AgentPrefab"))
        //   Debug.Log(keyInd);

       float lt; //local time between keyframes including via keys
         
       if (keyInd + 1 < _animInfo.Keys.Length) {            
           if(t < 0 )
               lt = (float)(-t *_animInfo.AnimLength - _animInfo.Keys[keyInd].Time) / (_animInfo.Keys[keyInd + 1].Time - _animInfo.Keys[keyInd].Time);            
           else if (t > 1)
               lt = (float)((2 - t) * _animInfo.AnimLength - _animInfo.Keys[keyInd].Time) / (_animInfo.Keys[keyInd + 1].Time - _animInfo.Keys[keyInd].Time);            
           else
               lt = (float)(t * _animInfo.AnimLength - _animInfo.Keys[keyInd].Time) / (_animInfo.Keys[keyInd + 1].Time - _animInfo.Keys[keyInd].Time);            
       }
       else
           lt = 0f;

       

    
        //   if (this.gameObject == GameObject.Find("AgentPrefab"))
       //       Debug.Log("t: " + t + " lt: " + lt + " keyInd: " + keyInd + " frameInd:  " + frameInd + " Curr: " + _animInfo.Curr + " PrevGoal: " + _animInfo.PrevGoal  + " NextGoal: " + _animInfo.NextGoal  + " prevGoalInd " + _animInfo.PrevGoalKeyInd    + " Tp: " + Tp);
        _animInfo.InterpolateWholeBody(keyInd, lt); //linear interpolation
        _animInfo.ProjectWholeBodyBeyondKeyInd(keyInd, lt, t); //linear interpolation
		
        //update both arms
        for (arm = 0; arm < 2; arm++) {
            if (_interpolatorType == InterpolatorType.EndEffector) {//position
                Vector3 target = _animInfo.ComputeInterpolatedTarget(lt, keyInd, arm);

                if (t < 0) { // project target to a position before position at keyInd                
                    Vector3 pivot = _animInfo.ComputeInterpolatedTarget(0f, 0,arm); //TCB interpolation for position
                    target = 2 * pivot - target;
                }
                else if (t > 1) { // project target to a position beyond keyInd
                    Vector3 pivot = _animInfo.ComputeInterpolatedTarget(0, _animInfo.Keys.Length - 1,arm); //TCB interpolation  for position
                    target = 2 * pivot - target;
                    
            //        Debug.Log(Time.time + "  "+ t);
                }


                if (arm == 0)            
                    _targetL = target;
            
                else 
                    _targetR = target;

                              
                        
        #if DEBUGMODE
                    //To see tension
                    if(arm == 0) 
                        _targetLPrev.Add(_targetL);
                    else
                        _targetRPrev.Add(_targetR);
        #endif
                    
                    if(arm == 0)               
                        ((IKArm)_ikSolver).Solve(_arms[arm].Bones, -SwivelAngle, target);         			    
                    else
                        ((IKArm)_ikSolver).Solve(_arms[arm].Bones, SwivelAngle, target);
                
                    
                            
            }

            else if (_interpolatorType == InterpolatorType.ElbowAngle)
            {

             //   _arms[arm].Elbow.transform.localRotation = Quaternion.Slerp(Keys[keyInd].BodyRot[i], Keys[keyInd + 1].BodyRot[i], lt);
                _arms[arm].Elbow.transform.localRotation = _animInfo.ComputeInterpolatedElbowAngle(lt, keyInd, arm);

                //Vector3 targetElbowAngle = _animInfo.ComputeInterpolatedElbowAngle(lt, keyInd, arm);
                //_arms[arm].Elbow.transform.localEulerAngles = targetElbowAngle;



            }
            /*
        else if (_interpolatorType == InterpolatorType.ElbowPos) {
            _arms[arm].Elbow.position = _animInfo.ComputeInterpolatedElbowPos(lt, keyInd,arm); //TCB interpolation for position   

        }
        */


            Flourish(arm, Tp, t);       
            //Flourish(arm, Mathf.Pow(tp, texp));   //Funda
            /*
            
            if (this.gameObject == GameObject.Find("AgentPrefab")) {
                
                if (Math.Abs(lt - 0) < 0.001) { //at keyframes
                    _animInfo.Keys[keyInd].EePosUpdated[arm] = target;
                    _animInfo.Keys[keyInd].TimeUpdated[arm] = Time.time;
                   
                }
                if (t > 1f) {
                    _animInfo.ComputeEeVelUpdated(arm);
                }
                
                    
                
            }
            */    
        }

        
            
        if (this.gameObject != GameObject.Find("AgentControlPrefab")) {
            
            if (Tp == 0) {
                _velArr.Clear();
                _tppArr.Clear();
            }
            //Current velocity curve
            GameObject velCurveCurr = GameObject.Find("VelCurveCurr");
            if (velCurveCurr == null) {
                return;
            }
            velCurveCurr.GetComponent<LineRenderer>().SetVertexCount(_velArr.Count);
            for(int i = 0; i < _velArr.Count; i++) {
                velCurveCurr.GetComponent<LineRenderer>().SetPosition(i, new Vector3(_tppArr[i], _velArr[i], 0));                
            }
            //General velocity curve as in EMOTE
            GameObject velCurveGen = GameObject.Find("VelCurveGeneral");
            velCurveGen.GetComponent<LineRenderer>().SetVertexCount(5);

            velCurveGen.GetComponent<LineRenderer>().SetPosition(0, new Vector3(0, 0, 0));
            velCurveGen.GetComponent<LineRenderer>().SetPosition(1, new Vector3(T0 , -V0, 0));
            velCurveGen.GetComponent<LineRenderer>().SetPosition(2, new Vector3(Ti , _vi, 0));
            velCurveGen.GetComponent<LineRenderer>().SetPosition(3, new Vector3(T1 , -V1, 0));
            velCurveGen.GetComponent<LineRenderer>().SetPosition(4, new Vector3(1 , 0, 0));
            /*velCurveGen.GetComponent<LineRenderer>().SetPosition(1, new Vector3( T0 / _animInfo.AnimSpeed, -V0, 0));
            velCurveGen.GetComponent<LineRenderer>().SetPosition(2, new Vector3( Ti / _animInfo.AnimSpeed, _vi, 0));
            velCurveGen.GetComponent<LineRenderer>().SetPosition(3, new Vector3( T1 / _animInfo.AnimSpeed, -V1, 0));
            velCurveGen.GetComponent<LineRenderer>().SetPosition(4, new Vector3( 1 / _animInfo.AnimSpeed, 0, 0));
            */
        }

	}
Пример #18
0
    //Has to be lateupdate because we overwrite the transforms
    void LateUpdate()
    {
        if (!animation.isPlaying)
        {
            return;
        }

        _ikSolver = new IKArm();
        int arm;      //arm index
        int keyInd;



        float s = TimingControl(Tp);



        //map s into the whole spline
        float t = (s * (_animInfo.NextGoal - _animInfo.PrevGoal) + _animInfo.PrevGoal) / _animInfo.AnimLength;



        //     Debug.Log(s + " " + Tp + " " + t +  " " + Time.deltaTime);
        if (_animInfo.NextGoal == _animInfo.PrevGoal)
        {
            t = 1f;
        }

        if (t < 0)
        {
            keyInd = _animInfo.FindKeyNumberAtNormalizedTime(-t); //find an imaginary key before the start of keyframes
        }
        else if (t > 1)
        {
            keyInd = _animInfo.FindKeyNumberAtNormalizedTime(2 - t); //find an imaginary key beyond the keyframes   1 - ( t - 1)
        }
        else
        {
            keyInd = _animInfo.FindKeyNumberAtNormalizedTime(t); //including via keys
        }
        // if (this.gameObject == GameObject.Find("AgentPrefab"))
        //    Debug.Log(s + " " + t);
        //if (this.gameObject == GameObject.Find("AgentPrefab"))
        //   Debug.Log(keyInd);

        float lt; //local time between keyframes including via keys

        if (keyInd + 1 < _animInfo.Keys.Length)
        {
            if (t < 0)
            {
                lt = (float)(-t * _animInfo.AnimLength - _animInfo.Keys[keyInd].Time) / (_animInfo.Keys[keyInd + 1].Time - _animInfo.Keys[keyInd].Time);
            }
            else if (t > 1)
            {
                lt = (float)((2 - t) * _animInfo.AnimLength - _animInfo.Keys[keyInd].Time) / (_animInfo.Keys[keyInd + 1].Time - _animInfo.Keys[keyInd].Time);
            }
            else
            {
                lt = (float)(t * _animInfo.AnimLength - _animInfo.Keys[keyInd].Time) / (_animInfo.Keys[keyInd + 1].Time - _animInfo.Keys[keyInd].Time);
            }
        }
        else
        {
            lt = 0f;
        }



        //   if (this.gameObject == GameObject.Find("AgentPrefab"))
        //       Debug.Log("t: " + t + " lt: " + lt + " keyInd: " + keyInd + " frameInd:  " + frameInd + " Curr: " + _animInfo.Curr + " PrevGoal: " + _animInfo.PrevGoal  + " NextGoal: " + _animInfo.NextGoal  + " prevGoalInd " + _animInfo.PrevGoalKeyInd    + " Tp: " + Tp);
        _animInfo.InterpolateWholeBody(keyInd, lt);            //linear interpolation
        _animInfo.ProjectWholeBodyBeyondKeyInd(keyInd, lt, t); //linear interpolation

        //update both arms
        for (arm = 0; arm < 2; arm++)
        {
            if (_interpolatorType == InterpolatorType.EndEffector)  //position
            {
                Vector3 target = _animInfo.ComputeInterpolatedTarget(lt, keyInd, arm);

                if (t < 0)                                                           // project target to a position before position at keyInd
                {
                    Vector3 pivot = _animInfo.ComputeInterpolatedTarget(0f, 0, arm); //TCB interpolation for position
                    target = 2 * pivot - target;
                }
                else if (t > 1)                                                                             // project target to a position beyond keyInd
                {
                    Vector3 pivot = _animInfo.ComputeInterpolatedTarget(0, _animInfo.Keys.Length - 1, arm); //TCB interpolation  for position
                    target = 2 * pivot - target;

                    //        Debug.Log(Time.time + "  "+ t);
                }


                if (arm == 0)
                {
                    _targetL = target;
                }

                else
                {
                    _targetR = target;
                }



        #if DEBUGMODE
                //To see tension
                if (arm == 0)
                {
                    _targetLPrev.Add(_targetL);
                }
                else
                {
                    _targetRPrev.Add(_targetR);
                }
        #endif

                if (arm == 0)
                {
                    ((IKArm)_ikSolver).Solve(_arms[arm].Bones, -SwivelAngle, target);
                }
                else
                {
                    ((IKArm)_ikSolver).Solve(_arms[arm].Bones, SwivelAngle, target);
                }
            }

            else if (_interpolatorType == InterpolatorType.ElbowAngle)
            {
                //   _arms[arm].Elbow.transform.localRotation = Quaternion.Slerp(Keys[keyInd].BodyRot[i], Keys[keyInd + 1].BodyRot[i], lt);
                _arms[arm].Elbow.transform.localRotation = _animInfo.ComputeInterpolatedElbowAngle(lt, keyInd, arm);

                //Vector3 targetElbowAngle = _animInfo.ComputeInterpolatedElbowAngle(lt, keyInd, arm);
                //_arms[arm].Elbow.transform.localEulerAngles = targetElbowAngle;
            }

            /*
             * else if (_interpolatorType == InterpolatorType.ElbowPos) {
             * _arms[arm].Elbow.position = _animInfo.ComputeInterpolatedElbowPos(lt, keyInd,arm); //TCB interpolation for position
             *
             * }
             */


            Flourish(arm, Tp, t);
            //Flourish(arm, Mathf.Pow(tp, texp));   //Funda

            /*
             *
             * if (this.gameObject == GameObject.Find("AgentPrefab")) {
             *
             *  if (Math.Abs(lt - 0) < 0.001) { //at keyframes
             *      _animInfo.Keys[keyInd].EePosUpdated[arm] = target;
             *      _animInfo.Keys[keyInd].TimeUpdated[arm] = Time.time;
             *
             *  }
             *  if (t > 1f) {
             *      _animInfo.ComputeEeVelUpdated(arm);
             *  }
             *
             *
             *
             * }
             */
        }



        if (this.gameObject != GameObject.Find("AgentControlPrefab"))
        {
            if (Tp == 0)
            {
                _velArr.Clear();
                _tppArr.Clear();
            }
            //Current velocity curve
            GameObject velCurveCurr = GameObject.Find("VelCurveCurr");
            if (velCurveCurr == null)
            {
                return;
            }
            velCurveCurr.GetComponent <LineRenderer>().SetVertexCount(_velArr.Count);
            for (int i = 0; i < _velArr.Count; i++)
            {
                velCurveCurr.GetComponent <LineRenderer>().SetPosition(i, new Vector3(_tppArr[i], _velArr[i], 0));
            }
            //General velocity curve as in EMOTE
            GameObject velCurveGen = GameObject.Find("VelCurveGeneral");
            velCurveGen.GetComponent <LineRenderer>().SetVertexCount(5);

            velCurveGen.GetComponent <LineRenderer>().SetPosition(0, new Vector3(0, 0, 0));
            velCurveGen.GetComponent <LineRenderer>().SetPosition(1, new Vector3(T0, -V0, 0));
            velCurveGen.GetComponent <LineRenderer>().SetPosition(2, new Vector3(Ti, _vi, 0));
            velCurveGen.GetComponent <LineRenderer>().SetPosition(3, new Vector3(T1, -V1, 0));
            velCurveGen.GetComponent <LineRenderer>().SetPosition(4, new Vector3(1, 0, 0));

            /*velCurveGen.GetComponent<LineRenderer>().SetPosition(1, new Vector3( T0 / _animInfo.AnimSpeed, -V0, 0));
             * velCurveGen.GetComponent<LineRenderer>().SetPosition(2, new Vector3( Ti / _animInfo.AnimSpeed, _vi, 0));
             * velCurveGen.GetComponent<LineRenderer>().SetPosition(3, new Vector3( T1 / _animInfo.AnimSpeed, -V1, 0));
             * velCurveGen.GetComponent<LineRenderer>().SetPosition(4, new Vector3( 1 / _animInfo.AnimSpeed, 0, 0));
             */
        }
    }
Пример #19
0
 private void Awake()
 {
     Target = target as IKSolver;
 }
Пример #20
0
        private static OCICharFemale Add(
            ChaControl _female,
            OICharInfo _info,
            ObjectCtrlInfo _parent,
            TreeNodeObject _parentNode,
            bool _addInfo,
            int _initialPosition)
        {
            OCICharFemale ociCharFemale = new OCICharFemale();
            ChaFileStatus _status       = new ChaFileStatus();

            _status.Copy(_female.fileStatus);
            _female.ChangeNowCoordinate(false, true);
            _female.Load(true);
            _female.InitializeExpression(1, true);
            ociCharFemale.charInfo         = _female;
            ociCharFemale.charReference    = (ChaReference)_female;
            ociCharFemale.preparation      = (Preparation)_female.objAnim.GetComponent <Preparation>();
            ociCharFemale.finalIK          = _female.fullBodyIK;
            ociCharFemale.charInfo.hideMoz = false;
            for (int index = 0; index < 2; ++index)
            {
                GameObject gameObject = _female.objHair.SafeGet <GameObject>(index);
                if (Object.op_Inequality((Object)gameObject, (Object)null))
                {
                    AddObjectAssist.ArrangeNames(gameObject.get_transform());
                }
            }
            AddObjectAssist.SetupAccessoryDynamicBones((OCIChar)ociCharFemale);
            AddObjectAssist.DisableComponent((OCIChar)ociCharFemale);
            ociCharFemale.objectInfo = (ObjectInfo)_info;
            GuideObject guideObject = Singleton <GuideObjectManager> .Instance.Add(((Component)_female).get_transform(), _info.dicKey);

            guideObject.scaleSelect   = 0.1f;
            guideObject.scaleRot      = 0.05f;
            guideObject.isActiveFunc += new GuideObject.IsActiveFunc(((ObjectCtrlInfo)ociCharFemale).OnSelect);
            guideObject.SetVisibleCenter(true);
            ociCharFemale.guideObject               = guideObject;
            ociCharFemale.optionItemCtrl            = (OptionItemCtrl)((Component)_female).get_gameObject().AddComponent <OptionItemCtrl>();
            ociCharFemale.optionItemCtrl.animator   = _female.animBody;
            ociCharFemale.optionItemCtrl.oiCharInfo = _info;
            _info.changeAmount.onChangeScale       += new Action <Vector3>(ociCharFemale.optionItemCtrl.ChangeScale);
            ociCharFemale.charAnimeCtrl             = ociCharFemale.preparation?.CharAnimeCtrl;
            if (Object.op_Implicit((Object)ociCharFemale.charAnimeCtrl))
            {
                ociCharFemale.charAnimeCtrl.oiCharInfo = _info;
            }
            ociCharFemale.yureCtrl = ociCharFemale.preparation.YureCtrl;
            ociCharFemale.yureCtrl.Init((OCIChar)ociCharFemale);
            if (_info.animeInfo.group == 0 && _info.animeInfo.category == 2 && _info.animeInfo.no == 11)
            {
                int   group               = _info.animeInfo.group;
                int   category            = _info.animeInfo.category;
                int   no                  = _info.animeInfo.no;
                float animeNormalizedTime = _info.animeNormalizedTime;
                ociCharFemale.LoadAnime(0, 1, 0, 0.0f);
                _female.animBody.Update(0.0f);
                _info.animeInfo.group     = group;
                _info.animeInfo.category  = category;
                _info.animeInfo.no        = no;
                _info.animeNormalizedTime = animeNormalizedTime;
            }
            IKSolver ikSolver = ((IK)ociCharFemale.finalIK).GetIKSolver();

            if (!ikSolver.get_initiated())
            {
                ikSolver.Initiate(((Component)ociCharFemale.finalIK).get_transform());
            }
            if (_addInfo)
            {
                Studio.Studio.AddInfo((ObjectInfo)_info, (ObjectCtrlInfo)ociCharFemale);
            }
            else
            {
                Studio.Studio.AddObjectCtrlInfo((ObjectCtrlInfo)ociCharFemale);
            }
            TreeNodeObject _parent1       = !Object.op_Inequality((Object)_parentNode, (Object)null) ? (_parent == null ? (TreeNodeObject)null : _parent.treeNodeObject) : _parentNode;
            TreeNodeObject treeNodeObject = Studio.Studio.AddNode(_info.charFile.parameter.fullname, _parent1);

            treeNodeObject.enableChangeParent      = true;
            treeNodeObject.treeState               = _info.treeState;
            treeNodeObject.onVisible              += new TreeNodeObject.OnVisibleFunc(((ObjectCtrlInfo)ociCharFemale).OnVisible);
            treeNodeObject.enableVisible           = true;
            treeNodeObject.visible                 = _info.visible;
            guideObject.guideSelect.treeNodeObject = treeNodeObject;
            ociCharFemale.treeNodeObject           = treeNodeObject;
            _info.changeAmount.OnChange();
            AddObjectAssist.InitBone((OCIChar)ociCharFemale, _female.objBodyBone.get_transform(), Singleton <Info> .Instance.dicBoneInfo);
            AddObjectAssist.InitIKTarget((OCIChar)ociCharFemale, _addInfo);
            AddObjectAssist.InitLookAt((OCIChar)ociCharFemale);
            AddObjectAssist.InitAccessoryPoint((OCIChar)ociCharFemale);
            ociCharFemale.voiceCtrl.ociChar = (OCIChar)ociCharFemale;
            ociCharFemale.InitKinematic(((Component)_female).get_gameObject(), ociCharFemale.finalIK, _female.neckLookCtrl, (DynamicBone[])null, AddObjectFemale.GetSkirtDynamic(_female.objClothes));
            treeNodeObject.enableAddChild = false;
            Studio.Studio.AddCtrlInfo((ObjectCtrlInfo)ociCharFemale);
            _parent?.OnLoadAttach(!Object.op_Inequality((Object)_parentNode, (Object)null) ? _parent.treeNodeObject : _parentNode, (ObjectCtrlInfo)ociCharFemale);
            if (_initialPosition == 1)
            {
                _info.changeAmount.pos = Singleton <Studio.Studio> .Instance.cameraCtrl.targetPos;
            }
            ociCharFemale.LoadAnime(_info.animeInfo.group, _info.animeInfo.category, _info.animeInfo.no, _info.animeNormalizedTime);
            for (int index = 0; index < 5; ++index)
            {
                ociCharFemale.ActiveIK((OIBoneInfo.BoneGroup)(1 << index), _info.activeIK[index], false);
            }
            ociCharFemale.ActiveKinematicMode(OICharInfo.KinematicMode.IK, _info.enableIK, true);
            // ISSUE: object of a compiler-generated type is created
            foreach (\u003C\u003E__AnonType18 <OIBoneInfo.BoneGroup, int> anonType18 in ((IEnumerable <OIBoneInfo.BoneGroup>)FKCtrl.parts).Select <OIBoneInfo.BoneGroup, \u003C\u003E__AnonType18 <OIBoneInfo.BoneGroup, int> >((Func <OIBoneInfo.BoneGroup, int, \u003C\u003E__AnonType18 <OIBoneInfo.BoneGroup, int> >)((p, i) => new \u003C\u003E__AnonType18 <OIBoneInfo.BoneGroup, int>(p, i))))
            {
                ociCharFemale.ActiveFK(anonType18.p, ociCharFemale.oiCharInfo.activeFK[anonType18.i], false);
            }
            ociCharFemale.ActiveKinematicMode(OICharInfo.KinematicMode.FK, _info.enableFK, true);
            for (int categoryNo = 0; categoryNo < _info.expression.Length; ++categoryNo)
            {
                ociCharFemale.charInfo.EnableExpressionCategory(categoryNo, _info.expression[categoryNo]);
            }
            ociCharFemale.animeSpeed        = ociCharFemale.animeSpeed;
            ociCharFemale.animeOptionParam1 = ociCharFemale.animeOptionParam1;
            ociCharFemale.animeOptionParam2 = ociCharFemale.animeOptionParam2;
            foreach (byte num in _female.fileStatus.siruLv)
            {
                num = (byte)0;
            }
            _status.visibleSonAlways = _info.visibleSon;
            ociCharFemale.SetSonLength(_info.sonLength);
            ociCharFemale.SetVisibleSimple(_info.visibleSimple);
            ociCharFemale.SetSimpleColor(_info.simpleColor);
            AddObjectAssist.UpdateState((OCIChar)ociCharFemale, _status);
            return(ociCharFemale);
        }