diff --git a/ARCamera_Inspector.jpg b/ARCamera_Inspector.jpg deleted file mode 100644 index 60e8c2e..0000000 Binary files a/ARCamera_Inspector.jpg and /dev/null differ diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Editor.meta b/Assets/GoogleVRWithOpenCVForUnityExample/Editor.meta deleted file mode 100644 index ae1e3ee..0000000 --- a/Assets/GoogleVRWithOpenCVForUnityExample/Editor.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 1f54f35ab56a3384cb9eed848d4717af -folderAsset: yes -timeCreated: 1479748316 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Editor/iOS_BuildPostprocessor.cs b/Assets/GoogleVRWithOpenCVForUnityExample/Editor/iOS_BuildPostprocessor.cs deleted file mode 100644 index 20e6ad9..0000000 --- a/Assets/GoogleVRWithOpenCVForUnityExample/Editor/iOS_BuildPostprocessor.cs +++ /dev/null @@ -1,42 +0,0 @@ -#if UNITY_5 && UNITY_IOS -using UnityEngine; -using UnityEditor; -using UnityEditor.Callbacks; -using UnityEditor.iOS.Xcode; -using System.Collections; -using System.IO; - -namespace GoogleVRWithOpenCVForUnitySample -{ - public class iOS_BuildPostprocessor : MonoBehaviour - { - - [PostProcessBuild] - public static void OnPostprocessBuild (BuildTarget buildTarget, string path) - { - if (buildTarget == BuildTarget.iOS) { - - #if UNITY_5_0 || UNITY_5_1 || UNITY5_2 - string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; - #else - string projPath = PBXProject.GetPBXProjectPath (path); - #endif - - PBXProject proj = new PBXProject (); - proj.ReadFromString (System.IO.File.ReadAllText (projPath)); - - #if UNITY_5_0 || UNITY_5_1 || UNITY5_2 - string target = proj.TargetGuidByName ("Unity-iPhone"); - #else - string target = proj.TargetGuidByName (PBXProject.GetUnityTargetName ()); - #endif - - // Add our framework directory to the framework include path - proj.AddFrameworkToProject(target, "AssetsLibrary.framework", false); - - File.WriteAllText (projPath, proj.WriteToString ()); - } - } - } -} -#endif \ No newline at end of file diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Editor/iOS_BuildPostprocessor.cs.meta b/Assets/GoogleVRWithOpenCVForUnityExample/Editor/iOS_BuildPostprocessor.cs.meta deleted file mode 100644 index 001ceed..0000000 --- a/Assets/GoogleVRWithOpenCVForUnityExample/Editor/iOS_BuildPostprocessor.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 3ed7153eee3fa1d4894d7ce9d265c906 -timeCreated: 1459497071 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scenes.meta b/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRMarkerBasedARExample.meta similarity index 60% rename from Assets/GoogleVRWithOpenCVForUnityExample/Scenes.meta rename to Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRMarkerBasedARExample.meta index 7e14a41..44c15a6 100644 --- a/Assets/GoogleVRWithOpenCVForUnityExample/Scenes.meta +++ b/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRMarkerBasedARExample.meta @@ -1,9 +1,10 @@ fileFormatVersion: 2 -guid: c670e772643d72c48bd0059ed0944b51 +guid: 080136ea16ca7db46b564bf542322fe1 folderAsset: yes -timeCreated: 1479748316 +timeCreated: 1553977793 licenseType: Free DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/GoogleVRMarkerBasedARExample.cs b/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRMarkerBasedARExample/GoogleVRMarkerBasedARExample.cs similarity index 63% rename from Assets/GoogleVRWithOpenCVForUnityExample/Scripts/GoogleVRMarkerBasedARExample.cs rename to Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRMarkerBasedARExample/GoogleVRMarkerBasedARExample.cs index 548fd35..59b2f20 100644 --- a/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/GoogleVRMarkerBasedARExample.cs +++ b/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRMarkerBasedARExample/GoogleVRMarkerBasedARExample.cs @@ -1,27 +1,33 @@ using UnityEngine; +using UnityEngine.SceneManagement; using System.Collections; using System.Collections.Generic; using OpenCVMarkerBasedAR; using MarkerBasedARExample; -using OpenCVForUnity; - -#if UNITY_5_3 || UNITY_5_3_OR_NEWER -using UnityEngine.SceneManagement; -#endif +using OpenCVForUnity.UnityUtils.Helper; +using OpenCVForUnity.CoreModule; +using OpenCVForUnity.Calib3dModule; +using OpenCVForUnity.UnityUtils; +using UnityEngine.XR; +using System; namespace GoogleVRWithOpenCVForUnityExample { /// - /// GoogleVR With OpenCVForUnity example. + /// GoogleVR With OpenCVForUnity Example. /// [RequireComponent (typeof(WebCamTextureToMatHelper))] public class GoogleVRMarkerBasedARExample : MonoBehaviour { + /// + /// The screen Quad. + /// + public Transform ScreenQuad; /// - /// The texture. + /// The Quad camera. /// - Texture2D texture; + public Camera QuadCamera; /// /// The AR camera. @@ -29,9 +35,14 @@ public class GoogleVRMarkerBasedARExample : MonoBehaviour public Camera ARCamera; /// - /// The AR camera. + /// The marker settings. /// - public GvrHead ARGvrHead; + public MarkerSettings[] markerSettings; + + /// + /// The texture. + /// + Texture2D texture; /// /// The cam matrix. @@ -68,63 +79,79 @@ public class GoogleVRMarkerBasedARExample : MonoBehaviour /// Matrix4x4 ARM; - /// - /// The marker settings. - /// - public MarkerSettings[] markerSettings; - /// /// The web cam texture to mat helper. /// WebCamTextureToMatHelper webCamTextureToMatHelper; // Use this for initialization - void Start () + IEnumerator Start () { + yield return StartCoroutine (SwitchToVR ()); + webCamTextureToMatHelper = gameObject.GetComponent (); - webCamTextureToMatHelper.Init (); + #if UNITY_ANDROID && !UNITY_EDITOR + // Avoids the front camera low light issue that occurs in only some Android devices (e.g. Google Pixel, Pixel2). + webCamTextureToMatHelper.avoidAndroidFrontCameraLowLightIssue = true; + #endif + webCamTextureToMatHelper.Initialize (); + } + + // Call via `StartCoroutine(SwitchToVR())` from your code. Or, use + // `yield SwitchToVR()` if calling from inside another coroutine. + IEnumerator SwitchToVR () + { + // Device names are lowercase, as returned by `XRSettings.supportedDevices`. + string desiredDevice = "cardboard"; // Or "daydream". + + // Some VR Devices do not support reloading when already active, see + // https://docs.unity3d.com/ScriptReference/XR.XRSettings.LoadDeviceByName.html + if (String.Compare (XRSettings.loadedDeviceName, desiredDevice, true) != 0) { + XRSettings.LoadDeviceByName (desiredDevice); + + // Must wait one frame after calling `XRSettings.LoadDeviceByName()`. + yield return null; + } + + // Now it's ok to enable VR mode. + XRSettings.enabled = true; } /// - /// Raises the web cam texture to mat helper inited event. + /// Raises the web cam texture to mat helper initialized event. /// - public void OnWebCamTextureToMatHelperInited () + public void OnWebCamTextureToMatHelperInitialized () { - Debug.Log ("OnWebCamTextureToMatHelperInited"); + Debug.Log ("OnWebCamTextureToMatHelperInitialized"); Mat webCamTextureMat = webCamTextureToMatHelper.GetMat (); texture = new Texture2D (webCamTextureMat.cols (), webCamTextureMat.rows (), TextureFormat.RGBA32, false); - gameObject.GetComponent ().material.mainTexture = texture; + ScreenQuad.GetComponent ().material.mainTexture = texture; - gameObject.transform.localScale = new Vector3 (webCamTextureMat.cols (), webCamTextureMat.rows (), 1); - Debug.Log ("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation); - float width = gameObject.transform.localScale.x; - float height = gameObject.transform.localScale.y; + float width = webCamTextureMat.width (); + float height = webCamTextureMat.height (); float imageSizeScale = 1.0f; float widthScale = (float)Screen.width / width; float heightScale = (float)Screen.height / height; if (widthScale < heightScale) { - Camera.main.orthographicSize = height / 2; } else { - Camera.main.orthographicSize = (width * (float)Screen.height / (float)Screen.width) / 2; imageSizeScale = (float)Screen.height / (float)Screen.width; - } - + } //set cameraparam - int max_d = Mathf.Max (webCamTextureMat.cols (), webCamTextureMat.rows ()); + int max_d = (int)Mathf.Max (width, height); double fx = max_d; double fy = max_d; - double cx = webCamTextureMat.cols () / 2.0f; - double cy = webCamTextureMat.rows () / 2.0f; + double cx = width / 2.0f; + double cy = height / 2.0f; camMatrix = new Mat (3, 3, CvType.CV_64FC1); camMatrix.put (0, 0, fx); camMatrix.put (0, 1, 0); @@ -142,19 +169,17 @@ public void OnWebCamTextureToMatHelperInited () //calibration camera - Size imageSize = new Size (webCamTextureMat.cols () * imageSizeScale, webCamTextureMat.rows () * imageSizeScale); + Size imageSize = new Size (width * imageSizeScale, height * imageSizeScale); double apertureWidth = 0; double apertureHeight = 0; double[] fovx = new double[1]; double[] fovy = new double[1]; double[] focalLength = new double[1]; - Point principalPoint = new Point (); + Point principalPoint = new Point (0, 0); double[] aspectratio = new double[1]; - Calib3d.calibrationMatrixValues (camMatrix, imageSize, apertureWidth, apertureHeight, fovx, fovy, focalLength, principalPoint, aspectratio); - Debug.Log ("imageSize " + imageSize.ToString ()); Debug.Log ("apertureWidth " + apertureWidth); Debug.Log ("apertureHeight " + apertureHeight); @@ -173,23 +198,24 @@ public void OnWebCamTextureToMatHelperInited () Debug.Log ("fovYScale " + fovYScale); - //Adjust Unity Camera FOV https://github.com/opencv/opencv/commit/8ed1945ccd52501f5ab22bdec6aa1f91f1e2cfd4 + //resize screen Quad + Matrix4x4 p = ARUtils.CalculateProjectionMatrixFromCameraMatrixValues ((float)fx, (float)fy, (float)cx, (float)cy, width, height, 0.3f, 1000f); + Vector3 cameraSpacePos = UnProjectVector (p, new Vector3 (1.0f, 1.0f, 1.0f)); if (widthScale > heightScale) { - ARCamera.fieldOfView = (float)(fovx [0] * fovXScale); + ScreenQuad.transform.localScale = new Vector3 (cameraSpacePos.x * 2f, cameraSpacePos.x * height / width * 2f, 1); } else { - ARCamera.fieldOfView = (float)(fovy [0] * fovYScale); + ScreenQuad.transform.localScale = new Vector3 (cameraSpacePos.y * width / height * 2f, cameraSpacePos.y * 2f, 1); } + //create markerDetector MarkerDesign[] markerDesigns = new MarkerDesign[markerSettings.Length]; for (int i = 0; i < markerDesigns.Length; i++) { markerDesigns [i] = markerSettings [i].markerDesign; - } - + } markerDetector = new MarkerDetector (camMatrix, distCoeffs, markerDesigns); - invertYM = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, new Vector3 (1, -1, 1)); Debug.Log ("invertYM " + invertYM.ToString ()); @@ -201,41 +227,35 @@ public void OnWebCamTextureToMatHelperInited () if (webCamTextureToMatHelper.GetWebCamDevice ().isFrontFacing) { webCamTextureToMatHelper.flipHorizontal = true; } - - StartCoroutine(resetCameraStatus ()); } - public IEnumerator resetCameraStatus(){ - - GvrViewer.Instance.DistortionCorrectionEnabled = !GvrViewer.Instance.DistortionCorrectionEnabled; - - yield return null; - - GvrViewer.Instance.UpdateState(); - GvrViewer.Instance.DistortionCorrectionEnabled = !GvrViewer.Instance.DistortionCorrectionEnabled; - } - - /// /// Raises the web cam texture to mat helper disposed event. /// public void OnWebCamTextureToMatHelperDisposed () { Debug.Log ("OnWebCamTextureToMatHelperDisposed"); - } - - void Update (){ - if (webCamTextureToMatHelper.IsPlaying () && webCamTextureToMatHelper.DidUpdateThisFrame ()) { - ARGvrHead.trackRotation = true; - - }else{ - ARGvrHead.trackRotation = false; + if (texture != null) { + Texture2D.Destroy (texture); + texture = null; } } - void LateUpdate () + /// + /// Raises the web cam texture to mat helper error occurred event. + /// + /// Error code. + public void OnWebCamTextureToMatHelperErrorOccurred (WebCamTextureToMatHelper.ErrorCode errorCode) { + Debug.Log ("OnWebCamTextureToMatHelperErrorOccurred " + errorCode); + } + + void Update () + { + if (Input.GetKeyDown (KeyCode.Escape)) { + OnBackButton (); + } if (webCamTextureToMatHelper.IsPlaying () && webCamTextureToMatHelper.DidUpdateThisFrame ()) { @@ -243,21 +263,20 @@ void LateUpdate () markerDetector.processFrame (rgbaMat, 1); - foreach (MarkerSettings settings in markerSettings) { - if(!settings.shouldNotSetToInactivePerFrame){ + if (!settings.shouldNotSetToInactivePerFrame) { settings.setAllARGameObjectsDisable (); - }else{ + } else { GameObject ARGameObject = settings.getARGameObject (); if (ARGameObject != null) { - DelayableSetActive obj = ARGameObject.GetComponent(); - if(obj != null){ - obj.SetActive(false, 0.5f); + DelayableSetActive obj = ARGameObject.GetComponent (); + if (obj != null) { + obj.SetActive (false, 0.5f); } } } } - + List findMarkers = markerDetector.getFindMarkers (); for (int i = 0; i < findMarkers.Count; i++) { Marker marker = findMarkers [i]; @@ -271,22 +290,20 @@ void LateUpdate () //Debug.Log ("arM " + arM.ToString ()); GameObject ARGameObject = settings.getARGameObject (); - if (ARGameObject != null) { ARUtils.SetTransformFromMatrix (ARGameObject.transform, ref ARM); - DelayableSetActive obj = ARGameObject.GetComponent(); - if(obj != null){ - obj.SetActive(true); - }else{ + DelayableSetActive obj = ARGameObject.GetComponent (); + if (obj != null) { + obj.SetActive (true); + } else { ARGameObject.SetActive (true); } } } } } - - Utils.matToTexture2D (rgbaMat, texture, webCamTextureToMatHelper.GetBufferColors()); + Utils.fastMatToTexture2D (rgbaMat, texture); } } @@ -298,16 +315,24 @@ void OnDisable () webCamTextureToMatHelper.Dispose (); } + private Vector3 UnProjectVector (Matrix4x4 proj, Vector3 to) + { + Vector3 from = new Vector3 (0, 0, 0); + var axsX = proj.GetRow (0); + var axsY = proj.GetRow (1); + var axsZ = proj.GetRow (2); + from.z = to.z / axsZ.z; + from.y = (to.y - (from.z * axsY.z)) / axsY.y; + from.x = (to.x - (from.z * axsX.z)) / axsX.x; + return from; + } + /// /// Raises the back button event. /// public void OnBackButton () { - #if UNITY_5_3 || UNITY_5_3_OR_NEWER SceneManager.LoadScene ("GoogleVRWithOpenCVForUnityExample"); - #else - Application.LoadLevel ("GoogleVRWithOpenCVForUnityExample"); - #endif } /// @@ -339,23 +364,15 @@ public void OnStopButton () /// public void OnChangeCameraButton () { - webCamTextureToMatHelper.Init (null, webCamTextureToMatHelper.requestWidth, webCamTextureToMatHelper.requestHeight, !webCamTextureToMatHelper.requestIsFrontFacing); + webCamTextureToMatHelper.requestedIsFrontFacing = !webCamTextureToMatHelper.IsFrontFacing (); } - public void ToggleVRMode() { - GvrViewer.Instance.VRModeEnabled = !GvrViewer.Instance.VRModeEnabled; - } - - public void ToggleDistortionCorrection() { - GvrViewer.Instance.DistortionCorrectionEnabled = - !GvrViewer.Instance.DistortionCorrectionEnabled; - } - - #if !UNITY_HAS_GOOGLEVR || UNITY_EDITOR - public void ToggleDirectRender() { - GvrViewer.Controller.directRender = !GvrViewer.Controller.directRender; + /// + /// Raises the recenter button event. + /// + public void OnRecenterButton () + { + InputTracking.Recenter (); } - #endif // !UNITY_HAS_GOOGLEVR || UNITY_EDITOR - } -} +} \ No newline at end of file diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/GoogleVRMarkerBasedARExample.cs.meta b/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRMarkerBasedARExample/GoogleVRMarkerBasedARExample.cs.meta similarity index 100% rename from Assets/GoogleVRWithOpenCVForUnityExample/Scripts/GoogleVRMarkerBasedARExample.cs.meta rename to Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRMarkerBasedARExample/GoogleVRMarkerBasedARExample.cs.meta diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRMarkerBasedARExample/GoogleVRMarkerBasedARExample.unity b/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRMarkerBasedARExample/GoogleVRMarkerBasedARExample.unity new file mode 100644 index 0000000..35ee80c Binary files /dev/null and b/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRMarkerBasedARExample/GoogleVRMarkerBasedARExample.unity differ diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scenes/GoogleVRMarkerBasedARExample.unity.meta b/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRMarkerBasedARExample/GoogleVRMarkerBasedARExample.unity.meta similarity index 100% rename from Assets/GoogleVRWithOpenCVForUnityExample/Scenes/GoogleVRMarkerBasedARExample.unity.meta rename to Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRMarkerBasedARExample/GoogleVRMarkerBasedARExample.unity.meta diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRWithOpenCVForUnityExample.cs b/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRWithOpenCVForUnityExample.cs new file mode 100644 index 0000000..bb5f561 --- /dev/null +++ b/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRWithOpenCVForUnityExample.cs @@ -0,0 +1,125 @@ +using UnityEngine; +using System.Collections; +using UnityEngine.SceneManagement; +using UnityEngine.XR; +using UnityEngine.UI; + +namespace GoogleVRWithOpenCVForUnityExample +{ + public class GoogleVRWithOpenCVForUnityExample : MonoBehaviour + { + + public Text exampleTitle; + public Text versionInfo; + public ScrollRect scrollRect; + static float verticalNormalizedPosition = 1f; + + // Use this for initialization + IEnumerator Start () + { + yield return StartCoroutine (SwitchTo2D ()); + + + exampleTitle.text = "GoogleVRWithOpenCVForUnity Example " + Application.version; + + versionInfo.text = OpenCVForUnity.CoreModule.Core.NATIVE_LIBRARY_NAME + " " + OpenCVForUnity.UnityUtils.Utils.getVersion () + " (" + OpenCVForUnity.CoreModule.Core.VERSION + ")"; + versionInfo.text += " / UnityEditor " + Application.unityVersion; + versionInfo.text += " / "; + + #if UNITY_EDITOR + versionInfo.text += "Editor"; + #elif UNITY_STANDALONE_WIN + versionInfo.text += "Windows"; + #elif UNITY_STANDALONE_OSX + versionInfo.text += "Mac OSX"; + #elif UNITY_STANDALONE_LINUX + versionInfo.text += "Linux"; + #elif UNITY_ANDROID + versionInfo.text += "Android"; + #elif UNITY_IOS + versionInfo.text += "iOS"; + #elif UNITY_WSA + versionInfo.text += "WSA"; + #elif UNITY_WEBGL + versionInfo.text += "WebGL"; + #endif + versionInfo.text += " "; + #if ENABLE_MONO + versionInfo.text += "Mono"; + #elif ENABLE_IL2CPP + versionInfo.text += "IL2CPP"; + #elif ENABLE_DOTNET + versionInfo.text += ".NET"; + #endif + + scrollRect.verticalNormalizedPosition = verticalNormalizedPosition; + } + + // Update is called once per frame + void Update () + { + + } + + public void OnScrollRectValueChanged () + { + verticalNormalizedPosition = scrollRect.verticalNormalizedPosition; + } + + // Call via `StartCoroutine(SwitchTo2D())` from your code. Or, use + // `yield SwitchTo2D()` if calling from inside another coroutine. + IEnumerator SwitchTo2D () + { + // Empty string loads the "None" device. + XRSettings.LoadDeviceByName (""); + + // Must wait one frame after calling `XRSettings.LoadDeviceByName()`. + yield return null; + + // Not needed, since loading the None (`""`) device takes care of this. + // XRSettings.enabled = false; + + // Restore 2D camera settings. + ResetCameras (); + } + + // Resets camera transform and settings on all enabled eye cameras. + void ResetCameras () + { + // Camera looping logic copied from GvrEditorEmulator.cs + for (int i = 0; i < Camera.allCameras.Length; i++) { + Camera cam = Camera.allCameras [i]; + if (cam.enabled && cam.stereoTargetEye != StereoTargetEyeMask.None) { + + // Reset local position. + // Only required if you change the camera's local position while in 2D mode. + cam.transform.localPosition = Vector3.zero; + + // Reset local rotation. + // Only required if you change the camera's local rotation while in 2D mode. + cam.transform.localRotation = Quaternion.identity; + + // No longer needed, see issue github.com/googlevr/gvr-unity-sdk/issues/628. + // cam.ResetAspect(); + + // No need to reset `fieldOfView`, since it's reset automatically. + } + } + } + + public void OnShowLicenseButton () + { + SceneManager.LoadScene ("ShowLicense"); + } + + public void OnShowARMarkerButton () + { + SceneManager.LoadScene ("ShowARMarker"); + } + + public void OnGoogleVRMarkerBasedARExample () + { + SceneManager.LoadScene ("GoogleVRMarkerBasedARExample"); + } + } +} \ No newline at end of file diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/GoogleVRWithOpenCVForUnityExample.cs.meta b/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRWithOpenCVForUnityExample.cs.meta similarity index 100% rename from Assets/GoogleVRWithOpenCVForUnityExample/Scripts/GoogleVRWithOpenCVForUnityExample.cs.meta rename to Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRWithOpenCVForUnityExample.cs.meta diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRWithOpenCVForUnityExample.unity b/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRWithOpenCVForUnityExample.unity new file mode 100644 index 0000000..c2787b2 Binary files /dev/null and b/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRWithOpenCVForUnityExample.unity differ diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scenes/GoogleVRWithOpenCVForUnityExample.unity.meta b/Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRWithOpenCVForUnityExample.unity.meta similarity index 100% rename from Assets/GoogleVRWithOpenCVForUnityExample/Scenes/GoogleVRWithOpenCVForUnityExample.unity.meta rename to Assets/GoogleVRWithOpenCVForUnityExample/GoogleVRWithOpenCVForUnityExample.unity.meta diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scenes/GoogleVRMarkerBasedARExample.unity b/Assets/GoogleVRWithOpenCVForUnityExample/Scenes/GoogleVRMarkerBasedARExample.unity deleted file mode 100644 index 28dee3d..0000000 Binary files a/Assets/GoogleVRWithOpenCVForUnityExample/Scenes/GoogleVRMarkerBasedARExample.unity and /dev/null differ diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scenes/GoogleVRWithOpenCVForUnityExample.unity b/Assets/GoogleVRWithOpenCVForUnityExample/Scenes/GoogleVRWithOpenCVForUnityExample.unity deleted file mode 100644 index d3519e7..0000000 Binary files a/Assets/GoogleVRWithOpenCVForUnityExample/Scenes/GoogleVRWithOpenCVForUnityExample.unity and /dev/null differ diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/GoogleVRWithOpenCVForUnityExample.cs b/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/GoogleVRWithOpenCVForUnityExample.cs deleted file mode 100644 index af50eec..0000000 --- a/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/GoogleVRWithOpenCVForUnityExample.cs +++ /dev/null @@ -1,52 +0,0 @@ -using UnityEngine; -using System.Collections; - -#if UNITY_5_3 || UNITY_5_3_OR_NEWER -using UnityEngine.SceneManagement; -#endif - -namespace GoogleVRWithOpenCVForUnityExample -{ - public class GoogleVRWithOpenCVForUnityExample : MonoBehaviour - { - // Use this for initialization - void Start () - { - - } - - // Update is called once per frame - void Update () - { - - } - - public void OnShowLicenseButton () - { - #if UNITY_5_3 || UNITY_5_3_OR_NEWER - SceneManager.LoadScene ("ShowLicense"); - #else - Application.LoadLevel ("ShowLicense"); - #endif - } - - public void OnShowARMarkerButton () - { - - #if UNITY_5_3 || UNITY_5_3_OR_NEWER - SceneManager.LoadScene ("ShowARMarker"); - #else - Application.LoadLevel ("ShowARMarker"); - #endif - } - - public void OnGoogleVRMarkerBasedARExample () - { - #if UNITY_5_3 || UNITY_5_3_OR_NEWER - SceneManager.LoadScene ("GoogleVRMarkerBasedARExample"); - #else - Application.LoadLevel ("GoogleVRMarkerBasedARExample"); - #endif - } - } -} \ No newline at end of file diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/Utils/ColorChangeGvrResponder.cs b/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/Utils/ColorChangeGvrResponder.cs index 5c44460..b68b6dd 100644 --- a/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/Utils/ColorChangeGvrResponder.cs +++ b/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/Utils/ColorChangeGvrResponder.cs @@ -4,7 +4,7 @@ namespace GoogleVRWithOpenCVForUnityExample { [RequireComponent (typeof(Collider))] - public class ColorChangeGvrResponder : MonoBehaviour, IGvrGazeResponder + public class ColorChangeGvrResponder : MonoBehaviour { void Start () { diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/ShowARMarker.cs b/Assets/GoogleVRWithOpenCVForUnityExample/ShowARMarker.cs similarity index 84% rename from Assets/GoogleVRWithOpenCVForUnityExample/Scripts/ShowARMarker.cs rename to Assets/GoogleVRWithOpenCVForUnityExample/ShowARMarker.cs index be969b9..65c4b7d 100644 --- a/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/ShowARMarker.cs +++ b/Assets/GoogleVRWithOpenCVForUnityExample/ShowARMarker.cs @@ -1,12 +1,8 @@ using UnityEngine; +using UnityEngine.SceneManagement; using System.Collections; using System.Collections.Generic; -#if UNITY_5_3 || UNITY_5_3_OR_NEWER -using UnityEngine.SceneManagement; -#endif -using OpenCVForUnity; - namespace GoogleVRWithOpenCVForUnityExample { /// @@ -14,9 +10,8 @@ namespace GoogleVRWithOpenCVForUnityExample /// public class ShowARMarker : MonoBehaviour { - /// - /// The marker texture. + /// Show ARMarker /// public Texture2D[] markerTexture; @@ -27,8 +22,7 @@ public class ShowARMarker : MonoBehaviour // Use this for initialization void Start () - { - + { float width = gameObject.transform.localScale.x; float height = gameObject.transform.localScale.y; @@ -63,11 +57,7 @@ void OnDisable () /// public void OnBackButton () { - #if UNITY_5_3 || UNITY_5_3_OR_NEWER SceneManager.LoadScene ("GoogleVRWithOpenCVForUnityExample"); - #else - Application.LoadLevel ("GoogleVRWithOpenCVForUnityExample"); - #endif } /// @@ -79,5 +69,4 @@ public void OnChangeMarkerButton () gameObject.GetComponent ().material.mainTexture = markerTexture [index]; } } - -} +} \ No newline at end of file diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/ShowARMarker.cs.meta b/Assets/GoogleVRWithOpenCVForUnityExample/ShowARMarker.cs.meta similarity index 100% rename from Assets/GoogleVRWithOpenCVForUnityExample/Scripts/ShowARMarker.cs.meta rename to Assets/GoogleVRWithOpenCVForUnityExample/ShowARMarker.cs.meta diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scenes/ShowARMarker.unity b/Assets/GoogleVRWithOpenCVForUnityExample/ShowARMarker.unity similarity index 100% rename from Assets/GoogleVRWithOpenCVForUnityExample/Scenes/ShowARMarker.unity rename to Assets/GoogleVRWithOpenCVForUnityExample/ShowARMarker.unity diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scenes/ShowARMarker.unity.meta b/Assets/GoogleVRWithOpenCVForUnityExample/ShowARMarker.unity.meta similarity index 100% rename from Assets/GoogleVRWithOpenCVForUnityExample/Scenes/ShowARMarker.unity.meta rename to Assets/GoogleVRWithOpenCVForUnityExample/ShowARMarker.unity.meta diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/ShowLicense.cs b/Assets/GoogleVRWithOpenCVForUnityExample/ShowLicense.cs similarity index 67% rename from Assets/GoogleVRWithOpenCVForUnityExample/Scripts/ShowLicense.cs rename to Assets/GoogleVRWithOpenCVForUnityExample/ShowLicense.cs index f3f18c7..df37ed4 100644 --- a/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/ShowLicense.cs +++ b/Assets/GoogleVRWithOpenCVForUnityExample/ShowLicense.cs @@ -1,9 +1,6 @@ using UnityEngine; using System.Collections; - -#if UNITY_5_3 || UNITY_5_3_OR_NEWER using UnityEngine.SceneManagement; -#endif namespace GoogleVRWithOpenCVForUnityExample { @@ -25,11 +22,7 @@ void Update () public void OnBackButton () { - #if UNITY_5_3 || UNITY_5_3_OR_NEWER SceneManager.LoadScene ("GoogleVRWithOpenCVForUnityExample"); - #else - Application.LoadLevel ("GoogleVRWithOpenCVForUnityExample"); - #endif } } } diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scripts/ShowLicense.cs.meta b/Assets/GoogleVRWithOpenCVForUnityExample/ShowLicense.cs.meta similarity index 100% rename from Assets/GoogleVRWithOpenCVForUnityExample/Scripts/ShowLicense.cs.meta rename to Assets/GoogleVRWithOpenCVForUnityExample/ShowLicense.cs.meta diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scenes/ShowLicense.unity b/Assets/GoogleVRWithOpenCVForUnityExample/ShowLicense.unity similarity index 100% rename from Assets/GoogleVRWithOpenCVForUnityExample/Scenes/ShowLicense.unity rename to Assets/GoogleVRWithOpenCVForUnityExample/ShowLicense.unity diff --git a/Assets/GoogleVRWithOpenCVForUnityExample/Scenes/ShowLicense.unity.meta b/Assets/GoogleVRWithOpenCVForUnityExample/ShowLicense.unity.meta similarity index 100% rename from Assets/GoogleVRWithOpenCVForUnityExample/Scenes/ShowLicense.unity.meta rename to Assets/GoogleVRWithOpenCVForUnityExample/ShowLicense.unity.meta diff --git a/GoogleVRWithOpenCVForUnityExample.apk b/GoogleVRWithOpenCVForUnityExample.apk deleted file mode 100644 index 4a760a4..0000000 Binary files a/GoogleVRWithOpenCVForUnityExample.apk and /dev/null differ diff --git a/GoogleVRWithOpenCVForUnityExample.unitypackage b/GoogleVRWithOpenCVForUnityExample.unitypackage deleted file mode 100644 index 4bd8cb2..0000000 Binary files a/GoogleVRWithOpenCVForUnityExample.unitypackage and /dev/null differ diff --git a/GvrAdaptor_Inspector.jpg b/GvrAdaptor_Inspector.jpg deleted file mode 100644 index f6ddd84..0000000 Binary files a/GvrAdaptor_Inspector.jpg and /dev/null differ diff --git a/GvrMain_Head_Inspector.jpg b/GvrMain_Head_Inspector.jpg deleted file mode 100644 index a195375..0000000 Binary files a/GvrMain_Head_Inspector.jpg and /dev/null differ diff --git a/GvrMain_Inspector.jpg b/GvrMain_Inspector.jpg deleted file mode 100644 index 7e41e4c..0000000 Binary files a/GvrMain_Inspector.jpg and /dev/null differ diff --git a/MainCamera_Inspector.jpg b/MainCamera_Inspector.jpg deleted file mode 100644 index 47fe0f5..0000000 Binary files a/MainCamera_Inspector.jpg and /dev/null differ diff --git a/PlayerSettingsWindow.jpg b/PlayerSettingsWindow.jpg new file mode 100644 index 0000000..5369348 Binary files /dev/null and b/PlayerSettingsWindow.jpg differ diff --git a/ProjectWindow.jpg b/ProjectWindow.jpg index 962598a..5872304 100644 Binary files a/ProjectWindow.jpg and b/ProjectWindow.jpg differ diff --git a/README.md b/README.md index 355937c..93961e7 100644 --- a/README.md +++ b/README.md @@ -8,35 +8,37 @@ Screen Shot Environment ----- -Windows 8.1 -Unity 5.3.0f4 -OpenCVForUnity2.0.9 -GVR Unity SDK v1.0.3 + +- Anddroid (Pixel, Nexus 7) / iOS (iPhone8, iPhone6) +- Unity >= 2017.4+ +- Scripting backend MONO / IL2CPP +- [OpenCV for Unity](https://assetstore.unity.com/packages/tools/integration/opencv-for-unity-21088?aid=1011l4ehR) 2.3.4+ +- [MarkerBased AR Example](https://assetstore.unity.com/packages/templates/tutorials/markerbased-ar-example-29678?aid=1011l4ehR) 1.2.2+ +- [Google VR SDK for Unity](https://github.com/googlevr/gvr-unity-sdk/releases) v1.190.1 + + +## Demo +- Android [GoogleVRWithOpenCVForUnityExample.apk](https://github.com/EnoxSoftware/GoogleVRWithOpenCVForUnityExample/releases) Setup ----- -* Create New Project. (GoogleVRMarkerBasedARExample) -* Import OpenCVForUnity2.0.9 from AssetStore (if iOS platform, please use "OpenCVForUnity/Extra/ios_exclude_contrib.zip".) -* Import MarkerBased AR Example1.2.0 from AssetStore -* Import GoogleVRForUnity.unitypackage -* Import GoogleVRWithOpenCVForUnityExample.unitypackage -* Change Product Name. (GoogleVRMarkerBasedARExample) -* Change PlayerSettings.bundleIdentifier. (xxx.xxxxxxx.googlevrmarkerbasedarexample) -* Add the “Assets/GoogleVRWithOpenCVForUnityExample/Scenes/*.unity” files to “Scenes In Build” list in “Build Settings” window. -* Set In PlayerSettings, at the bottom under Settings for iOS, click Resolution and Presentation to expand that panel. Set the Default Orientation to Auto Rotation, and then uncheck all of the Allowed Orientations for Auto Rotation except for Landscape Left. +1. Download the latest release unitypackage. [GoogleVRWithOpenCVForUnityExample.unitypackage](https://github.com/EnoxSoftware/GoogleVRWithOpenCVForUnityExample/releases) +1. Create a new Project. (GoogleVRWithOpenCVForUnityExample) +1. Import OpenCVForUnity. + * Setup the OpenCVForUnity. (Tools > OpenCV for Unity > Set Plugin Import Settings) +1. Import MarkerBasedARExample. +1. Import GoogleVRForUnity_xxxxxxx.unitypackage +1. Import GoogleVRWithOpenCVForUnityExample.unitypackage +1. Add the “Assets/GoogleVRWithOpenCVForUnityExample/*.unity” files to “Scenes In Build” list in “Build Settings” window. +1. Set In PlayerSettings, at the bottom under Settings for iOS, click Resolution and Presentation to expand that panel. Set the Default Orientation to Auto Rotation, and then uncheck all of the Allowed Orientations for Auto Rotation except for Landscape Left. +1. Configure build settings and player settings. (See [Android](https://developers.google.com/vr/develop/unity/get-started-android) and [iOS](https://developers.google.com/vr/develop/unity/get-started-ios)) +1. Build and Deploy to Android and iOS. -![ProjectWindow.jpg](ProjectWindow.jpg) -![MainCamera_Inspector.jpg](MainCamera_Inspector.jpg) -![GvrAdaptor_Inspector.jpg](GvrAdaptor_Inspector.jpg) -![GvrMain_Inspector.jpg](GvrMain_Inspector.jpg) -![GvrMain_Head_Inspector.jpg](GvrMain_Head_Inspector.jpg) -![ARCamera_Inspector.jpg](ARCamera_Inspector.jpg) +![ProjectWindow.jpg](ProjectWindow.jpg) +![PlayerSettingsWindow.jpg](PlayerSettingsWindow.jpg) -Android Build ------ -[GoogleVRWithOpenCVForUnityExample.apk](GoogleVRWithOpenCVForUnityExample.apk) ![marker.png](marker.png) diff --git a/ScreenShot.jpg b/ScreenShot.jpg index 1f40093..bc5a296 100644 Binary files a/ScreenShot.jpg and b/ScreenShot.jpg differ