/// <summary> /// Updates the target game object transform. /// SLAM Reports its transfrom aligned with gravity on (0,-9.8,0) /// At the origin with the initial rotation at Identity /// </summary> public void UpdateTargetGOTransform(bool isScaleEstimated, bool getPoseFromCompositor) { if (getPoseFromCompositor) { // Start frame to get new slam data within the compositor MetaCompositorInterop.BeginFrame(); // Update pose for behaviors with rendering pose from compositor MetaCompositorInterop.GetRenderPoseToWorld(_trans, _quat); } else { int status = CameraSlamToMetaWorld(_trans, _quat); if (status != 0) { return; } } if (TargetGO != null) { TargetGO.transform.rotation = FromDouble(_quat); TargetGO.transform.position = new Vector3( (float)_trans[0], (float)_trans[1], (float)_trans[2] ); } }
/// <summary> /// Update the Camera Matrices for the Compositor /// </summary> private void UpdateCameraMatrices() { //-------------- left eye -------------------- Matrix4x4 viewLeftMatrix = Matrix4x4.identity; MetaCompositorInterop.GetViewMatrix(0, ref viewLeftMatrix); //set the final view matrix for left eye _leftCam.worldToCameraMatrix = viewLeftMatrix; //-------------- right eye -------------------- Matrix4x4 viewRightMatrix = Matrix4x4.identity; MetaCompositorInterop.GetViewMatrix(1, ref viewRightMatrix); //set the final view matrix for right eye _rightCam.worldToCameraMatrix = viewRightMatrix; //-------------- left eye -------------------- Matrix4x4 projLeftMatrix = Matrix4x4.identity; MetaCompositorInterop.GetProjectionMatrix(0, ref projLeftMatrix); //set the final proj matrix for left eye _leftCam.projectionMatrix = projLeftMatrix; //-------------- right eye -------------------- Matrix4x4 projRightMatrix = Matrix4x4.identity; MetaCompositorInterop.GetProjectionMatrix(1, ref projRightMatrix); //set the final proj matrix for right eye _rightCam.projectionMatrix = projRightMatrix; }
/// <summary> /// Initialize this class on Start /// </summary> private void Start() { MetaCompositorInterop.InitCompositor(_enableAsyncLateWarp); // Setup rendertargets for stereo cameras var rt_left = new RenderTexture(2048, 2048, 24, RenderTextureFormat.ARGB32); var rt_right = new RenderTexture(2048, 2048, 24, RenderTextureFormat.ARGB32); rt_left.autoGenerateMips = false; rt_right.autoGenerateMips = false; rt_left.filterMode = rt_right.filterMode = FilterMode.Point; rt_left.Create(); rt_right.Create(); _rightCam.targetTexture = rt_right; _leftCam.targetTexture = rt_left; MetaCompositorInterop.SetEyeRenderTargets( rt_left.GetNativeTexturePtr(), rt_right.GetNativeTexturePtr(), rt_left.GetNativeDepthBufferPtr(), rt_right.GetNativeDepthBufferPtr() ); // register the callback used before camera renders. Unfortunately, Unity sets this for ALL cameras, //so we can't register a callback for a single camera only. Camera.onPreRender += OnPreRenderEvent; //ensure that the right camera renders after the left camera. We need the right camera //to render last since we call EndFrame on the Compositor via the right camera and the left camera to render first _rightCam.depth = _leftCam.depth + 1; // Enable/Disable time warp on start MetaCompositorInterop.EnableTimewarp(_enableTimewarp ? 1 : 0); MetaCompositorInterop.SetTimewarpPrediction(_timeWarpPredictionTime); MetaCompositorInterop.SetAddLatency(_debugAddLatency); // Enable/Disable late warp on start MetaCompositorInterop.EnableLateWarp(_enableLateWarp); MetaCompositorInterop.SetThresholdForLateWarp(_lateWarpThreshold); // Enabling/setting up all the defaults EnableHandOcclusion = _enableDepthOcclusion; TemporalMomentum = _temporalMomentum; FeatherSize = _featherSize; FeatherCutoff = _featherCutoff; FeatherFalloffExponent = _featherFalloffExponent; // Occlusion is disabled during the SLAM init process. Record the initial state of occlusion so it can be restored after SLAM init is dismissed. OcclusionEnabledAtStart = EnableHandOcclusion; // Start the End Of Frame Loop _started = true; CreateTextureAndPassToPlugin(); }
/// <summary> /// End of frame loop /// </summary> /// <returns>IEnumerator Coroutine</returns> private IEnumerator CallPluginAtEndOfFrames() { // Wait for start while (!_started) { yield return(new WaitForEndOfFrame()); } // RenderLoop for compositor while (true) { // Wait until all frame rendering is done yield return(new WaitForEndOfFrame()); // this waits for all cams GL.IssuePluginEvent(MetaCompositorInterop.GetRenderEventFunc(), 1); //calls EndFrame on Compositor. } }
/// <summary> /// Shuts down the compositor /// </summary> private void OnDestroy() { MetaCompositorInterop.ShutdownCompositor(); Camera.onPreRender -= OnPreRenderEvent; }
/// <summary> /// Shuts down the compositor /// </summary> private void OnDestroy() { MetaCompositorInterop.ShutdownCompositor(); }