コード例 #1
0
 private void Inject(IAvatarInput input, SpawnedAvatar avatar, ILoggerProvider loggerProvider, IKHelper ikHelper)
 {
     _input    = input;
     _avatar   = avatar;
     _logger   = loggerProvider.CreateLogger <AvatarIK>(_avatar.avatar.descriptor.name);
     _ikHelper = ikHelper;
 }
コード例 #2
0
 private void Inject(ILoggerProvider loggerProvider, IAvatarInput input, SpawnedAvatar spawnedAvatar, TrackingHelper trackingHelper)
 {
     _logger         = loggerProvider.CreateLogger <AvatarTracking>(spawnedAvatar.avatar.descriptor.name);
     _input          = input;
     _spawnedAvatar  = spawnedAvatar;
     _trackingHelper = trackingHelper;
 }
コード例 #3
0
        public void ClearManualFullBodyTrackingData(SpawnedAvatar spawnedAvatar)
        {
            CalibrationData.FullBodyCalibration fullBodyCalibration = _calibrationData.GetAvatarManualCalibration(spawnedAvatar.avatar.fileName);

            fullBodyCalibration.leftFoot  = Pose.identity;
            fullBodyCalibration.rightFoot = Pose.identity;
            fullBodyCalibration.waist     = Pose.identity;
        }
コード例 #4
0
        private void Construct(ILogger <AvatarTracking> logger, IAvatarInput input, SpawnedAvatar spawnedAvatar, TrackingHelper trackingHelper)
        {
            _logger         = logger;
            _input          = input;
            _spawnedAvatar  = spawnedAvatar;
            _trackingHelper = trackingHelper;

            _logger.name = spawnedAvatar.prefab.descriptor.name;
        }
コード例 #5
0
 private void Inject(MainSettingsModelSO mainSettingsModel, ILoggerProvider loggerProvider, IAvatarInput input, SpawnedAvatar spawnedAvatar, VRPlatformHelper vrPlatformHelper, AvatarTailor tailor)
 {
     _mainSettingsModel = mainSettingsModel;
     _logger            = loggerProvider.CreateLogger <AvatarTracking>(spawnedAvatar.avatar.descriptor.name);
     _input             = input;
     _spawnedAvatar     = spawnedAvatar;
     _vrPlatformHelper  = vrPlatformHelper;
     _tailor            = tailor;
 }
コード例 #6
0
        public void ResizeAvatar(SpawnedAvatar spawnedAvatar)
        {
            if (!spawnedAvatar.avatar.descriptor.allowHeightCalibration || !spawnedAvatar.avatar.isIKAvatar)
            {
                return;
            }

            // compute scale
            float            scale;
            AvatarResizeMode resizeMode = _settings.resizeMode;

            switch (resizeMode)
            {
            case AvatarResizeMode.ArmSpan:
                float avatarArmLength = spawnedAvatar.avatar.armSpan;

                if (avatarArmLength > 0)
                {
                    scale = _settings.playerArmSpan / avatarArmLength;
                }
                else
                {
                    scale = 1.0f;
                }

                break;

            case AvatarResizeMode.Height:
                float avatarEyeHeight = spawnedAvatar.avatar.eyeHeight;

                if (avatarEyeHeight > 0)
                {
                    scale = _playerEyeHeight / avatarEyeHeight;
                }
                else
                {
                    scale = 1.0f;
                }

                break;

            default:
                scale = 1.0f;
                break;
            }

            if (scale <= 0)
            {
                _logger.Warning("Calculated scale is <= 0; reverting to 1");
                scale = 1.0f;
            }

            // apply scale
            spawnedAvatar.scale = scale;

            SharedCoroutineStarter.instance.StartCoroutine(FloorMendingWithDelay(spawnedAvatar));
        }
コード例 #7
0
        private IEnumerator FloorMendingWithDelay(SpawnedAvatar spawnedAvatar)
        {
            yield return(new WaitForEndOfFrame()); // wait for CustomFloorPlugin:PlatformManager:Start to hide original platform

            if (!spawnedAvatar)
            {
                yield break;
            }

            float floorOffset = 0f;

            if (_settings.enableFloorAdjust && spawnedAvatar.avatar.isIKAvatar)
            {
                float playerEyeHeight = _playerEyeHeight;
                float avatarEyeHeight = spawnedAvatar.avatar.eyeHeight;

                floorOffset = playerEyeHeight - avatarEyeHeight * spawnedAvatar.scale;

                if (_settings.moveFloorWithRoomAdjust)
                {
                    floorOffset += _roomCenter.y;
                }
            }

            floorOffset = (float)Math.Round(floorOffset, 3);  // round to millimeter

            // apply offset
            spawnedAvatar.verticalPosition = floorOffset;

            // ReSharper disable Unity.PerformanceCriticalCodeInvocation
            GameObject menuPlayersPlace = GameObject.Find("MenuPlayersPlace");
            GameObject originalFloor    = GameObject.Find("Environment/PlayersPlace");
            GameObject customFloor      = GameObject.Find("Platform Loader");

            // ReSharper disable restore Unity.PerformanceCriticalCodeInvocation

            if (menuPlayersPlace)
            {
                _logger.Info($"Moving MenuPlayersPlace floor {Math.Abs(floorOffset)} m {(floorOffset >= 0 ? "up" : "down")}");
                menuPlayersPlace.transform.position = new Vector3(0, floorOffset, 0);
            }

            if (originalFloor)
            {
                _logger.Info($"Moving PlayersPlace {Math.Abs(floorOffset)} m {(floorOffset >= 0 ? "up" : "down")}");
                originalFloor.transform.position = new Vector3(0, floorOffset, 0);
            }

            if (customFloor)
            {
                _logger.Info($"Moving Custom Platforms floor {Math.Abs(floorOffset)} m {(floorOffset >= 0 ? "up" : "down")}");

                _initialPlatformPosition       = _initialPlatformPosition ?? customFloor.transform.position;
                customFloor.transform.position = (Vector3.up * floorOffset) + _initialPlatformPosition ?? Vector3.zero;
            }
        }
コード例 #8
0
        public void SwitchToAvatarAsync(string fileName)
        {
            Object.Destroy(currentlySpawnedAvatar);
            currentlySpawnedAvatar = null;
            _currentAvatarSettings = null;

            if (string.IsNullOrEmpty(fileName))
            {
                _switchingToPath = null;
                SwitchToAvatar(null);
                return;
            }

            string fullPath = Path.Combine(kCustomAvatarsPath, fileName);

            _switchingToPath = fullPath;

            SharedCoroutineStarter.instance.StartCoroutine(_avatarLoader.FromFileCoroutine(fullPath, SwitchToAvatar));
        }
コード例 #9
0
        public Vector3 ApplyTrackedPointFloorOffset(SpawnedAvatar spawnedAvatar, Vector3 position)
        {
            if (!_settings.enableFloorAdjust)
            {
                return(position);
            }

            float scaledEyeHeight = spawnedAvatar.avatar.eyeHeight * spawnedAvatar.scale;
            float yOffset         = spawnedAvatar.verticalPosition;

            if (_settings.moveFloorWithRoomAdjust)
            {
                yOffset -= _mainSettingsModel.roomCenter.value.y;
            }

            float yOffsetScale = scaledEyeHeight / (scaledEyeHeight + yOffset);

            return(new Vector3(position.x, position.y * yOffsetScale + yOffset, position.z));
        }
コード例 #10
0
        private void SwitchToAvatar(LoadedAvatar avatar)
        {
            if (currentlySpawnedAvatar && currentlySpawnedAvatar.avatar == avatar)
            {
                return;
            }
            if (avatar?.fullPath != _switchingToPath)
            {
                return;
            }

            if (avatar == null)
            {
                _logger.Info("No avatar selected");
                avatarChanged?.Invoke(null);
                _settings.previousAvatarPath = null;
                return;
            }

            var avatarInfo = new AvatarInfo(avatar);

            _settings.previousAvatarPath = avatarInfo.fileName;

            // cache avatar info since loading asset bundles is expensive
            if (_avatarInfos.ContainsKey(avatarInfo.fileName))
            {
                _avatarInfos[avatarInfo.fileName] = avatarInfo;
            }
            else
            {
                _avatarInfos.Add(avatarInfo.fileName, avatarInfo);
            }

            currentlySpawnedAvatar = _spawner.SpawnAvatar(avatar, _container.Instantiate <VRPlayerInput>(new object[] { avatar }));
            _currentAvatarSettings = _settings.GetAvatarSettings(avatar.fileName);

            ResizeCurrentAvatar();
            UpdateFirstPersonVisibility();
            UpdateLocomotionEnabled();

            avatarChanged?.Invoke(currentlySpawnedAvatar);
        }
コード例 #11
0
        private void Inject(MainSettingsModelSO mainSettingsModel, ILoggerProvider loggerProvider, IAvatarInput input, SpawnedAvatar avatar, VRPlatformHelper vrPlatformHelper, AvatarTailor tailor)
        {
            _mainSettingsModel = mainSettingsModel;
            _logger            = loggerProvider.CreateLogger <AvatarTracking>(avatar.avatar.descriptor.name);
            _input             = input;
            _avatar            = avatar;
            _vrPlatformHelper  = vrPlatformHelper;
            _tailor            = tailor;

            if (_avatar.pelvis)
            {
                _initialPelvisPose = new Pose(_avatar.pelvis.position, _avatar.pelvis.rotation);
            }
            if (_avatar.leftLeg)
            {
                _initialLeftFootPose = new Pose(_avatar.leftLeg.position, _avatar.leftLeg.rotation);
            }
            if (_avatar.rightLeg)
            {
                _initialRightFootPose = new Pose(_avatar.rightLeg.position, _avatar.rightLeg.rotation);
            }
        }
コード例 #12
0
        public void CalibrateFullBodyTrackingManual(SpawnedAvatar spawnedAvatar)
        {
            CalibrationData.FullBodyCalibration fullBodyCalibration = _calibrationData.GetAvatarManualCalibration(spawnedAvatar.avatar.fileName);

            if (_trackedDeviceManager.waist.tracked)
            {
                TrackedDeviceState pelvis = _trackedDeviceManager.waist;

                Vector3    positionOffset = Quaternion.Inverse(spawnedAvatar.pelvis.rotation) * (spawnedAvatar.pelvis.position - ApplyTrackedPointFloorOffset(spawnedAvatar, pelvis.position));
                Quaternion rotationOffset = Quaternion.Inverse(pelvis.rotation) * spawnedAvatar.pelvis.rotation;

                fullBodyCalibration.waist = new Pose(positionOffset, rotationOffset);
                _logger.Info("Set waist pose correction " + fullBodyCalibration.waist);
            }

            if (_trackedDeviceManager.leftFoot.tracked)
            {
                TrackedDeviceState leftFoot = _trackedDeviceManager.leftFoot;

                Vector3    positionOffset = Quaternion.Inverse(spawnedAvatar.leftLeg.rotation) * (spawnedAvatar.leftLeg.position - ApplyTrackedPointFloorOffset(spawnedAvatar, leftFoot.position));
                Quaternion rotationOffset = Quaternion.Inverse(leftFoot.rotation) * spawnedAvatar.leftLeg.rotation;

                fullBodyCalibration.leftFoot = new Pose(positionOffset, rotationOffset);
                _logger.Info("Set left foot pose correction " + fullBodyCalibration.leftFoot);
            }

            if (_trackedDeviceManager.rightFoot.tracked)
            {
                TrackedDeviceState rightFoot = _trackedDeviceManager.rightFoot;

                Vector3    positionOffset = Quaternion.Inverse(spawnedAvatar.rightLeg.rotation) * (spawnedAvatar.rightLeg.position - ApplyTrackedPointFloorOffset(spawnedAvatar, rightFoot.position));
                Quaternion rotationOffset = Quaternion.Inverse(rightFoot.rotation) * spawnedAvatar.rightLeg.rotation;

                fullBodyCalibration.rightFoot = new Pose(positionOffset, rotationOffset);
                _logger.Info("Set right foot pose correction " + fullBodyCalibration.rightFoot);
            }
        }