static void CommandPOV(CommandArg[] args)
        {
            if (args[0].Int == 1)
            {
                // POV camera
                if (POV_CAMERA == null)
                {
                    HeadIK headIK = UnityEngine.Object.FindObjectOfType <HeadIK>();

                    GameObject pov = new GameObject("POV_Camera");
                    pov.transform.parent = headIK.head.gameObject.transform;

                    POV_CAMERA = pov.AddComponent <Camera>();
                    POV_CAMERA.nearClipPlane    = 0.15f;
                    POV_CAMERA.depth            = 999;
                    pov.transform.position      = headIK.head.position;
                    pov.transform.rotation      = headIK.head.rotation * Quaternion.Euler(new Vector3(-100f, 13f, 43f));
                    pov.transform.localRotation = pov.transform.localRotation * Quaternion.Euler(new Vector3(20f, 0f, 50f));
                }

                float fov = args.Length == 2 ? args[1].Float : 72f;
                POV_CAMERA.fieldOfView = fov;
                POV_CAMERA.enabled     = true;
            }
            else
            {
                POV_CAMERA.enabled = false;
            }
        }
        public static void SetPlayerView(int value, float fov)
        {
            if (value == 1)
            {
                // POV camera
                if (POV_CAMERA == null)
                {
                    HeadIK headIK = UnityEngine.Object.FindObjectOfType <HeadIK>();

                    GameObject pov = new GameObject("POV_Camera");
                    pov.transform.parent = headIK.head.gameObject.transform;

                    POV_CAMERA = pov.AddComponent <Camera>();
                    POV_CAMERA.nearClipPlane    = 0.15f;
                    POV_CAMERA.depth            = 999;
                    pov.transform.position      = headIK.head.position;
                    pov.transform.rotation      = headIK.head.rotation * Quaternion.Euler(new Vector3(-100f, 13f, 43f));
                    pov.transform.localRotation = pov.transform.localRotation * Quaternion.Euler(new Vector3(20f, 0f, 50f));
                }

                POV_CAMERA.fieldOfView = fov;
                POV_CAMERA.enabled     = true;
            }
            else
            {
                POV_CAMERA.enabled = false;
            }
        }
        public void Awake()
        {
            PlayerHeadIK = PlayerController.Instance.GetComponentInChildren <HeadIK>();
            StartCoroutine(RecordBailedLoop());
            this.transformsToBeRecorded = new List <Transform>();
            this.RecordedFrames         = new List <ReplayRecordedFrame>();

            AddTransformToRecordedList(PlayerController.Instance.transform);

            //Board
            AddTransformToRecordedList(PlayerController.Instance.boardController.boardTransform);
            AddTransformToRecordedList(PlayerController.Instance.boardController.backTruckRigidbody.transform);
            AddTransformToRecordedList(PlayerController.Instance.boardController.frontTruckRigidbody.transform);
            AddTransformToRecordedList(SoundManager.Instance.wheel1);
            AddTransformToRecordedList(SoundManager.Instance.wheel2);
            AddTransformToRecordedList(SoundManager.Instance.wheel3);
            AddTransformToRecordedList(SoundManager.Instance.wheel4);

            //Bones
            AddTransformToRecordedList(PlayerController.Instance.skaterController.skaterTransform);
            AddTransformToRecordedList(PlayerController.Instance.skaterController.skaterRigidbody.transform);

            foreach (object obj in Enum.GetValues(typeof(HumanBodyBones)))
            {
                HumanBodyBones humanBodyBones = (HumanBodyBones)obj;
                if (humanBodyBones < HumanBodyBones.Hips || humanBodyBones >= HumanBodyBones.LastBone)
                {
                    break;
                }
                Transform boneTransform = PlayerController.Instance.animationController.skaterAnim.GetBoneTransform(humanBodyBones);
                if (boneTransform != null)
                {
                    AddTransformToRecordedList(boneTransform);
                }
            }
            var ikcTraverse = Traverse.Create(PlayerController.Instance.ikController);

            AddTransformToRecordedList(ikcTraverse.Field <Transform>("ikAnimBoard").Value);
            AddTransformToRecordedList(ikcTraverse.Field <Transform>("ikLeftFootPosition").Value);
            AddTransformToRecordedList(ikcTraverse.Field <Transform>("ikRightFootPosition").Value);
            AddTransformToRecordedList(ikcTraverse.Field <Transform>("ikAnimLeftFootTarget").Value);
            AddTransformToRecordedList(ikcTraverse.Field <Transform>("ikAnimRightFootTarget").Value);
            AddTransformToRecordedList(ikcTraverse.Field <Transform>("ikLeftFootPositionOffset").Value);
            AddTransformToRecordedList(ikcTraverse.Field <Transform>("ikRightFootPositionOffset").Value);

            transformsToBeRecorded.OrderBy(delegate(Transform t) {
                int i = 0;
                while (t.parent != null)
                {
                    i++;
                    t = t.parent;
                }
                return(i);
            });

            this.startTime = 0f;
            this.endTime   = 0f;
        }
Beispiel #4
0
        // Start is called before the first frame update
        void Start()
        {
            if (!premaidRoot)
            {
                // 未指定ならモデルのルートにこのスクリプトがアタッチされているものとする
                premaidRoot = transform;
            }

            if (premaidRoot != null)
            {
                _joints = premaidRoot.GetComponentsInChildren <ModelJoint>();
            }

            // 左腕IKソルバを準備
            leftArmIK               = new ArmIK();
            leftArmIK.isRightSide   = false;
            leftArmIK.shoulderPitch = GetJointById("04");
            leftArmIK.upperArmRoll  = GetJointById("0B");
            leftArmIK.upperArmPitch = GetJointById("0F");
            leftArmIK.lowerArmRoll  = GetJointById("13");
            leftArmIK.handPitch     = GetJointById("17");
            leftArmIK.handTarget    = leftHandTarget;
            leftArmIK.elbowTarget   = leftElbowTarget;
            leftArmIK.Initialize();
            leftElbowTarget = leftArmIK.elbowTarget;  // 自動生成されていたら、controller側に代入
            leftHandTarget  = leftArmIK.handTarget;   // 自動生成されていたら、controller側に代入

            // 右腕IKソルバを準備
            rightArmIK               = new ArmIK();
            rightArmIK.isRightSide   = true;
            rightArmIK.shoulderPitch = GetJointById("02");
            rightArmIK.upperArmRoll  = GetJointById("09");
            rightArmIK.upperArmPitch = GetJointById("0D");
            rightArmIK.lowerArmRoll  = GetJointById("11");
            rightArmIK.handPitch     = GetJointById("15");
            rightArmIK.handTarget    = rightHandTarget;
            rightArmIK.elbowTarget   = rightElbowTarget;
            rightArmIK.Initialize();
            rightElbowTarget = rightArmIK.elbowTarget;    // 自動生成されていたら、controller側に代入
            rightHandTarget  = rightArmIK.handTarget;     // 自動生成されていたら、controller側に代入

            // 頭部IKソルバを準備
            headIK            = new HeadIK();
            headIK.neckYaw    = GetJointById("05");
            headIK.headPitch  = GetJointById("03");
            headIK.headRoll   = GetJointById("07");
            headIK.headTarget = headTarget;
            headIK.Initialize();
            headTarget = headIK.headTarget;         // 自動生成されていたら、controller側に代入

            // 左脚IKソルバを準備
            leftLegIK               = new LegIK();
            leftLegIK.isRightSide   = false;
            leftLegIK.upperLegYaw   = GetJointById("08");
            leftLegIK.upperLegRoll  = GetJointById("0C");
            leftLegIK.upperLegPitch = GetJointById("10");
            leftLegIK.kneePitch     = GetJointById("14");
            leftLegIK.anklePitch    = GetJointById("18");
            leftLegIK.footRoll      = GetJointById("1C");
            leftLegIK.footTarget    = leftFootTarget;
            leftLegIK.Initialize();
            leftFootTarget = leftLegIK.footTarget;

            // 右脚IKソルバを準備
            rightLegIK               = new LegIK();
            rightLegIK.isRightSide   = true;
            rightLegIK.upperLegYaw   = GetJointById("06");
            rightLegIK.upperLegRoll  = GetJointById("0A");
            rightLegIK.upperLegPitch = GetJointById("0E");
            rightLegIK.kneePitch     = GetJointById("12");
            rightLegIK.anklePitch    = GetJointById("16");
            rightLegIK.footRoll      = GetJointById("1A");
            rightLegIK.footTarget    = rightFootTarget;
            rightLegIK.Initialize();
            rightFootTarget = rightLegIK.footTarget;
        }
Beispiel #5
0
		// - Wakeup for solvers.
		// - Require to setup each transforms.
		public bool Prepare()
		{
			_Prefix();

			if( _isPrepared ) {
				return false;
			}

			_isPrepared = true;

			Assert( rootTransform != null );
			if( rootTransform != null ) { // Failsafe.
				internalValues.defaultRootPosition = rootTransform.position;
				internalValues.defaultRootBasis = Matrix3x3.FromColumn( rootTransform.right, rootTransform.up, rootTransform.forward );
				internalValues.defaultRootBasisInv = internalValues.defaultRootBasis.transpose;
				internalValues.defaultRootRotation = rootTransform.rotation;
			}
			
			if( _bones != null ) {
				int boneLength = _bones.Length;
				for( int i = 0; i != boneLength; ++i ) {
					Assert( _bones[i] != null );
					if( _bones[i] != null ) {
						_bones[i].Prepare( this );
					}
				}
				for( int i = 0; i != boneLength; ++i ) {
					if( _bones[i] != null ) {
						_bones[i].PostPrepare();
					}
				}
			}

			boneCaches.Prepare( this );

			if( _effectors != null ) {
				int effectorLength = _effectors.Length;
                for( int i = 0; i != effectorLength; ++i ) {
					Assert( _effectors[i] != null );
					if( _effectors[i] != null ) {
						_effectors[i].Prepare( this );
					}
				}
			}

			if( _limbIK == null || _limbIK.Length != (int)LimbIKLocation.Max ) {
				_limbIK = new LimbIK[(int)LimbIKLocation.Max];
			}

			for( int i = 0; i != (int)LimbIKLocation.Max; ++i ) {
				_limbIK[i] = new LimbIK( this, (LimbIKLocation)i );
			}

			_bodyIK = new BodyIK( this, _limbIK );
			_headIK = new HeadIK( this );

			if( _fingerIK == null || _fingerIK.Length != (int)FingerIKType.Max ) {
				_fingerIK = new FingerIK[(int)FingerIKType.Max];
			}

			for( int i = 0; i != (int)FingerIKType.Max; ++i ) {
				_fingerIK[i] = new FingerIK( this, (FingerIKType)i );
			}

			{
				Bone neckBone = headBones.neck;
				Bone leftShoulder = leftArmBones.shoulder;
				Bone rightShoulder = rightArmBones.shoulder;
				if( leftShoulder != null && leftShoulder.transformIsAlive &&
					rightShoulder != null && rightShoulder.transformIsAlive &&
					neckBone != null && neckBone.transformIsAlive ) {
					if( leftShoulder.transform.parent == neckBone.transform &&
						rightShoulder.transform.parent == neckBone.transform ) {
						_isNeedFixShoulderWorldTransform = true;
					}
				}
			}

			return true;
        }