Software Archive
Read-only legacy content
17061 Discussions

Unity3D Mirror Mode

Mohammed_A_
Beginner
936 Views

Hi all,

 

I have just start developing my first RealSense application using Unity3D, however, we are facing an issue when trying to disable mirror mode for an AR application.

 

In the SDK Manual, there is PXCMCapture.Device.MirrorMode and PXCMCapture.Device.MirrorMode.MIRROR_MODE_DISABLED

If I try to call capture manager and set the devices Mirror Mode:

cManager.device.SetMirrorMode ( PXCMCapture.Device.MirrorMode.MIRROR_MODE_DISABLED);

 

By adding above statement in SenseToolkitManager.cs, I get an an error with a null reference exception for Capture Manager object...

 

I wonder where and how should the Mirror property be set?

 

Thanks in advance!

0 Kudos
4 Replies
MartyG
Honored Contributor III
936 Views

I don't personally know about how the Mirror Mode works - maybe someone on this forum can help with that.  There are alternatives to creating a mirror in Unity though if the Mirror Mode does not work out.

If you want to create a mirror that shows the user's RL body then you could create a large board by stretching and scaling a Cube object and apply something called a WebCamTexture to the surface of it so that the camera's video feed streams onto the board in place of the texture that you have placed on the board.

http://docs.unity3d.com/ScriptReference/WebCamTexture.html

If you want to put a view from a Unity game camera onto a mirror surface then you can use a RenderTexture.

http://docs.unity3d.com/Manual/class-RenderTexture.html

0 Kudos
Mohammed_A_
Beginner
936 Views
Thanks for the reply. actually, I am trying to disable mirror mode in Unity. We would like to have the standard camera feed as the displayed output. RenderTexture is a good option, the only problem would be having tp flip back text and all ui elements so they would appear correctly (since ui elements are rendered correctly in the mirror mode). Thanks
0 Kudos
MartyG
Honored Contributor III
936 Views

It is possible to flip the camera view horizontally and / or vertically using a script placed inside it.  I found a JavaScript one on the net and tried it with my own mirror to confirm that it works.  

Here's one that flips both horizontally and vertically.

// EXAMPLE WITH CAMERA UPSIDEDOWN
 function OnPreCull () {
     GetComponent.<Camera>().ResetWorldToCameraMatrix ();
     GetComponent.<Camera>().ResetProjectionMatrix ();
     GetComponent.<Camera>().projectionMatrix = GetComponent.<Camera>().projectionMatrix * Matrix4x4.Scale(Vector3 (-1, -1, 1));
 }
  
 function OnPreRender () {
     GL.SetRevertBackfacing (true);
 }
  
 function OnPostRender () {
     GL.SetRevertBackfacing (false);
 }
  
 @script RequireComponent (Camera)

 

And here is the one that only flips horizontally.

// EXAMPLE WITH CAMERA UPSIDEDOWN
 function OnPreCull () {
     GetComponent.<Camera>().ResetWorldToCameraMatrix ();
     GetComponent.<Camera>().ResetProjectionMatrix ();
     GetComponent.<Camera>().projectionMatrix = GetComponent.<Camera>().projectionMatrix * Matrix4x4.Scale(Vector3 (1, -1, 1));
 }
  
 function OnPreRender () {
     GL.SetRevertBackfacing (true);
 }
  
 function OnPostRender () {
     GL.SetRevertBackfacing (false);
 }
  
 @script RequireComponent (Camera)

 

Basically in the "Scale(Vector3 (1, -1, 1))" section, you can flip a particular axis by adding a minus sign in front of the '1' numbers in the bracket - the first being X, the second being Y and the third being Z.

0 Kudos
MartyG
Honored Contributor III
936 Views

Regarding disabling Mirror Mode: if your Mirror Mode script is inside an object, then disabling that object should also disable the visibility of any scripted effects generated by it.

The simple JavaScript script below can disable an object by un-ticking the tick-box at the very top of the Inspector panel that controls whether an object is active or not.

function Start () {
gameObject.active = false;

}

 

Place it inside the object containing your Mirror Mode script.  If you want to make a separate script that makes the Mirror Mode object visible again, just change "false" in the above code to "true" so that it reads:

function Start () {
gameObject.active = true;

}

 

Edit: if you want an easy way of triggering an activation or deactivation script, you can link your script to a SendMessageAction script that is supplied with the RealSense Unity Toolkit.  Then you could use a hand or face gesture to turn the Mirror Mode on and off.

https://software.intel.com/en-us/articles/using-the-unity-toolkit-sendmessage-action-with-intel-realsense-technology

0 Kudos
Reply