Пример #1
0
    internal void OnLateUpdate()
    {
        if (mediaStream != null && _mediaStreamJustStopped == false && _encodeVideoFrameRequested)
        {
            Assert.IsTrue(isBoundToClient);

            var bypassPrediction = _predictiveCameraRig?.bypassPrediction ?? true;

            var timestamp = bypassPrediction == false && _predictiveCameraRig != null ? _predictiveCameraRig.predictedMotionProvider.timestamp :
                            inputStream.inputRecvTimestamp;
            var leftEyePose     = Pose.identity;
            var rightEyePose    = Pose.identity;
            var leftProjection  = Rect.MinMaxRect(-1, -1, 1, 1);
            var rightProjection = Rect.MinMaxRect(-1, -1, 1, 1);

            if (bypassPrediction)
            {
                leftEyePose = inputStream.GetPose((byte)AXRInputDeviceID.HeadTracker, (byte)AXRHeadTrackerControl.Pose);
            }
            else
            {
                leftEyePose     = _predictiveCameraRig?.predictedMotionProvider.leftEye ?? Pose.identity;
                rightEyePose    = _predictiveCameraRig?.predictedMotionProvider.rightEye ?? Pose.identity;
                leftProjection  = _predictiveCameraRig?.predictedMotionProvider.leftProjection ?? leftProjection;
                rightProjection = _predictiveCameraRig?.predictedMotionProvider.rightProjection ?? rightProjection;
            }

            var encodingProjSize       = _config.GetEncodingProjectionSize();
            var leftEncodingProjection = Rect.MinMaxRect(-encodingProjSize.width / 2 + leftProjection.center.x,
                                                         -encodingProjSize.height / 2 + leftProjection.center.y,
                                                         encodingProjSize.width / 2 + leftProjection.center.x,
                                                         encodingProjSize.height / 2 + leftProjection.center.y);
            var rightEncodingProjection = Rect.MinMaxRect(-encodingProjSize.width / 2 + rightProjection.center.x,
                                                          -encodingProjSize.height / 2 + rightProjection.center.y,
                                                          encodingProjSize.width / 2 + rightProjection.center.x,
                                                          encodingProjSize.height / 2 + rightProjection.center.y);

            var leftRenderProjection = makeSafeRenderProjection(
                Rect.MinMaxRect(Mathf.Max(leftEncodingProjection.xMin, leftProjection.xMin),
                                Mathf.Max(leftEncodingProjection.yMin, leftProjection.yMin),
                                Mathf.Min(leftEncodingProjection.xMax, leftProjection.xMax),
                                Mathf.Min(leftEncodingProjection.yMax, leftProjection.yMax))
                );
            var rightRenderProjection = makeSafeRenderProjection(
                Rect.MinMaxRect(Mathf.Max(rightEncodingProjection.xMin, rightProjection.xMin),
                                Mathf.Max(rightEncodingProjection.yMin, rightProjection.yMin),
                                Mathf.Min(rightEncodingProjection.xMax, rightProjection.xMax),
                                Mathf.Min(rightEncodingProjection.yMax, rightProjection.yMax))
                );

            AXRServerPlugin.GetViewNumber(playerID,
                                          timestamp,
                                          (int)(_predictiveCameraRig?.predictedMotionProvider.predictionTime ?? 0),
                                          leftEyePose.rotation,
                                          leftRenderProjection,
                                          rightRenderProjection,
                                          leftEncodingProjection,
                                          rightEncodingProjection,
                                          out _viewNumber);

            if (bypassPrediction)
            {
                updateCameraTransforms(_config, leftEyePose.position, leftEyePose.rotation);
            }
            else
            {
                updateCameraTransforms(_config, leftEyePose, rightEyePose);
            }

            updateCameraProjection(_config, leftRenderProjection, rightRenderProjection, leftEncodingProjection, rightEncodingProjection);
            updateControllerTransforms(_config, _predictiveCameraRig?.predictedMotionProvider, bypassPrediction);

            mediaStream.GetNextFramebufferTexturesAsRenderTargets(cameras);

            _cameraEventEmitter.UpdatePerFrame(_viewNumber);
        }
        inputStream.UpdateSenders();
    }