/// <summary> /// Given a screen coordinate, find a plane that most closely fits depth values in that area. /// /// This assumes you are using this in an AR context. /// </summary> /// <returns><c>true</c>, if plane was found, <c>false</c> otherwise.</returns> /// <param name="cam">The Unity camera.</param> /// <param name="pos">The point in screen space to perform detection on.</param> /// <param name="planeCenter">Filled in with the center of the plane in Unity world space.</param> /// <param name="plane">Filled in with a model of the plane in Unity world space.</param> public bool FindPlane(Camera cam, Vector2 pos, out Vector3 planeCenter, out Plane plane) { Matrix4x4 colorCameraTUnityWorld = m_colorCameraTUnityCamera * cam.transform.worldToLocalMatrix; Vector2 normalizedPos = cam.ScreenToViewportPoint(pos); // If the camera has a TangoARScreen attached, it is not displaying the entire color camera image. Correct // the normalized coordinates by taking the clipping into account. TangoARScreen arScreen = cam.gameObject.GetComponent <TangoARScreen>(); if (arScreen != null) { normalizedPos = arScreen.ViewportPointToCameraImagePoint(normalizedPos); } int returnValue = TangoSupport.FitPlaneModelNearClick( m_points, m_pointsCount, m_depthTimestamp, m_colorCameraIntrinsics, ref colorCameraTUnityWorld, normalizedPos, out planeCenter, out plane); if (returnValue == Common.ErrorType.TANGO_SUCCESS) { return(true); } else { return(false); } }
public void ToggleArMode(bool active) { if (active) { sceneAdapter.HideGeometry(); #if USE_TANGO tangoApplication.m_enableVideoOverlay = true; tangoApplication.m_videoOverlayUseTextureMethod = true; TangoARScreen tangoArScreen = Camera.main.gameObject.GetComponent <TangoARScreen>(); if (tangoArScreen == null) { tangoArScreen = Camera.main.gameObject.AddComponent <TangoARScreen>(); } tangoArScreen.enabled = true; #endif } else { #if USE_TANGO Camera.main.gameObject.GetComponent <TangoARScreen>().enabled = false; GameObject.Destroy(Camera.main.GetComponent <TangoARScreen>()); tangoApplication.m_enableVideoOverlay = false; #endif Camera.main.ResetProjectionMatrix(); sceneAdapter.ShowGeometry(); } hasUpdatedProjectionMatrix = true; }
/// <summary> /// Estimates the depth of a point on a screen, based on nearest neighbors. /// </summary> /// <returns> /// <c>true</c> if a successful depth estimate was obtained. /// </returns> /// <param name="cam">The Unity camera.</param> /// <param name="pos">The point in pixel coordinates to perform depth estimation.</param> /// <param name="colorCameraPoint"> /// The point (x, y, z), where (x, y) is the back-projection of the UV /// coordinates to the color camera space and z is the z coordinate of /// the point in the point cloud nearest to the user selection after /// projection onto the image plane. If there is not a point cloud point /// close to the user selection after projection onto the image plane, /// then the point will be set to (0.0, 0.0, 0.0) and isValidPoint will /// be set to false. /// </param> public bool EstimateDepthOnScreen(Camera cam, Vector2 pos, out Vector3 colorCameraPoint) { // Set up parameters Matrix4x4 colorCameraTUnityWorld = m_colorCameraTUnityCamera * cam.transform.worldToLocalMatrix; Vector2 normalizedPos = cam.ScreenToViewportPoint(pos); // If the camera has a TangoARScreen attached, it is not displaying the entire color camera image. Correct // the normalized coordinates by taking the clipping into account. TangoARScreen arScreen = cam.gameObject.GetComponent <TangoARScreen>(); if (arScreen != null) { normalizedPos = arScreen.ViewportPointToCameraImagePoint(normalizedPos); } bool isValidPoint; int returnType = TangoSupport.ScreenCoordinateToWorldNearestNeighbor( m_points, m_pointsCount, m_depthTimestamp, m_colorCameraIntrinsics, ref colorCameraTUnityWorld, normalizedPos, out colorCameraPoint, out isValidPoint); if (returnType != Common.ErrorType.TANGO_SUCCESS) { Debug.LogErrorFormat("TangoSupport.ScreenCoordinateToWorldNearestNeighbor failed with error code {0}.", returnType); } return((returnType == Common.ErrorType.TANGO_SUCCESS) && isValidPoint); }
IEnumerator LoadScene() { if (!GameManager.Instance.resetGame) { //等待服务器数据到位 yield return(StartCoroutine(GetGameUserData())); } else { //reset game!! } GamePlayer.Me.Create(); GamePlayer.Me.instance.SetPlayer(playerBody.transform); //加载基础场景 //生成tango管理器 ResourcesManager.Instance.LoadGameObject("Prefabs/Tango/Tango Seivice"); //临时代码,这部分以后要变成class create的模式,现在为了便于调试,这个上面起作用的类是tangoserviece #if !UNITY_EDITOR while (PermissionTango == false) { yield return(null); } #endif GameObject cloudObj = ResourcesManager.Instance.LoadGameObject("Prefabs/Tango/Tango Point Cloud"); //临时代码,这部分以后要变成class create的模式,现在为了便于调试 //生成tango镜头 TangoARPoseController tarPoseCon = Camera.main.gameObject.AddComponent <TangoARPoseController>(); tarPoseCon.m_useAreaDescriptionPose = true; tarPoseCon.m_syncToARScreen = true; TangoService.Instance.m_poseController = tarPoseCon; TangoManager.Instance.m_pointCloud = cloudObj.GetComponent <TangoPointCloud> (); TangoManager.Instance.m_pointCloud.m_useAreaDescriptionPose = true; //texture Method TangoService.Instance.m_tangoApplication.m_videoOverlayUseTextureMethod = true; TangoService.Instance.m_tangoApplication.m_videoOverlayUseYUVTextureIdMethod = false; TangoService.Instance.m_tangoApplication.m_videoOverlayUseByteBufferMethod = false; #if UNITY_EDITOR TangoService.Instance.m_tangoApplication.m_doSlowEmulation = true; //TangoService.Instance.m_tangoApplication.m_emulationEnvironment = TangoService.Instance.m_tangoApplication.m_emulationVideoOverlaySimpleLighting = true; #endif //AreaDescriptions TangoService.Instance.m_tangoApplication.m_enableAreaDescriptions = true; //mode 2 TangoService.Instance.m_tangoApplication.m_enableDriftCorrection = false; TangoService.Instance.m_tangoApplication.m_areaDescriptionLearningMode = false; TangoARScreen arScreen = Camera.main.gameObject.GetComponent <TangoARScreen> (); arScreen.m_occlusionShader = Shader.Find("Tango/PointCloud (Occlusion)"); ARCameraPostProcess postProcess = Camera.main.gameObject.AddComponent <ARCameraPostProcess> (); postProcess.m_postProcessMaterial = ResourcesManager.Instance.LoadAsset <Material> ("Common\\TangoGizmos\\Materials\\ar_post_process"); postProcess.enabled = false; TangoEnvironmentalLighting tel = Camera.main.gameObject.AddComponent <TangoEnvironmentalLighting> (); tel.m_enableEnvironmentalLighting = true; //OnSceneLoaded(); UIManager.Instance.Open(UIID.CatHandbook); //更新下载状态 CatSceneManager.Instance.UpdateLoadingState(100, 100); }
/// <summary> /// Start is called on the frame when a script is enabled. /// </summary> public void Start() { m_tangoApplication = FindObjectOfType <TangoApplication>(); if (m_tangoApplication == null) { Debug.LogError("An instance of TangoApplication was not found in the scene."); } m_tangoARScreen = GetComponent <TangoARScreen>(); m_characterController = GetComponent <CharacterController>(); }
/// <summary> /// Start is called on the frame when a script is enabled. /// </summary> public void Start() { m_tangoARScreen = GetComponent <TangoARScreen>(); TangoApplication tangoApplication = FindObjectOfType <TangoApplication>(); if (tangoApplication != null) { tangoApplication.Register(this); } else { Debug.Log("No Tango Manager found in scene."); } }
/// <summary> /// Given a screen coordinate, finds a plane that most closely fits the /// depth values in that area. /// /// This function is slow, as it looks at every single point in the point /// cloud. Avoid calling this more than once a frame. This also assumes the /// Unity camera intrinsics match the device's color camera. /// </summary> /// <returns><c>true</c>, if a plane was found; <c>false</c> otherwise.</returns> /// <param name="cam">The Unity camera.</param> /// <param name="pos">The point in screen space to perform detection on.</param> /// <param name="planeCenter">Filled in with the center of the plane in Unity world space.</param> /// <param name="plane">Filled in with a model of the plane in Unity world space.</param> public bool FindPlane(Camera cam, Vector2 pos, out Vector3 planeCenter, out Plane plane) { if (m_pointsCount == 0) { // No points to check, maybe not connected to the service yet planeCenter = Vector3.zero; plane = new Plane(); return(false); } Vector2 normalizedPos = cam.ScreenToViewportPoint(pos); // If the camera has a TangoARScreen attached, it is not displaying the entire color camera image. Correct // the normalized coordinates by taking the clipping into account. TangoARScreen arScreen = cam.gameObject.GetComponent <TangoARScreen>(); if (arScreen != null) { normalizedPos = arScreen.ViewportPointToCameraImagePoint(normalizedPos); } DVector4 planeModel = new DVector4(); bool returnValue = TangoSupport.FitPlaneModelNearClick( m_mostRecentPointCloud, arScreen.m_screenUpdateTime, normalizedPos, out planeCenter, out planeModel); planeCenter = m_mostRecentUnityWorldTDepthCamera.MultiplyPoint3x4(planeCenter); Vector3 normal = new Vector3((float)planeModel.x, (float)planeModel.y, (float)planeModel.z); normal = m_mostRecentUnityWorldTDepthCamera.MultiplyVector(normal); Vector3.Normalize(normal); float distance = (float)planeModel.w / normal.magnitude; plane = new Plane(normal, distance); return(returnValue); }
/// <summary> /// Start is called on the frame when a script is enabled. /// </summary> public void Start() { m_tangoARScreen = GetComponent <TangoARScreen>(); m_tangoApplicaiton = FindObjectOfType <TangoApplication>(); if (m_tangoApplicaiton != null) { m_tangoApplicaiton.Register(this); // If already connected to a service, then do initialization now. if (m_tangoApplicaiton.IsServiceConnected) { OnTangoServiceConnected(); } } else { Debug.Log("No Tango Manager found in scene."); } }
/// <summary> /// Given a screen coordinate, finds a plane that most closely fits the /// depth values in that area. /// /// This function is slow, as it looks at every single point in the point /// cloud. Avoid calling this more than once a frame. This also assumes the /// Unity camera intrinsics match the device's color camera. /// </summary> /// <returns><c>true</c>, if a plane was found; <c>false</c> otherwise.</returns> /// <param name="cam">The Unity camera.</param> /// <param name="pos">The point in screen space to perform detection on.</param> /// <param name="planeCenter">Filled in with the center of the plane in Unity world space.</param> /// <param name="plane">Filled in with a model of the plane in Unity world space.</param> public bool FindPlane(Camera cam, Vector2 pos, out Vector3 planeCenter, out Plane plane) { if (m_pointsCount == 0) { // No points to check, maybe not connected to the service yet planeCenter = Vector3.zero; plane = new Plane(); return(false); } Matrix4x4 colorCameraTUnityWorld = m_colorCameraTUnityCamera * cam.transform.worldToLocalMatrix; Vector2 normalizedPos = cam.ScreenToViewportPoint(pos); // If the camera has a TangoARScreen attached, it is not displaying the entire color camera image. Correct // the normalized coordinates by taking the clipping into account. TangoARScreen arScreen = cam.gameObject.GetComponent <TangoARScreen>(); if (arScreen != null) { normalizedPos = arScreen.ViewportPointToCameraImagePoint(normalizedPos); } TangoCameraIntrinsics alignedIntrinsics = new TangoCameraIntrinsics(); VideoOverlayProvider.GetDeviceOrientationAlignedIntrinsics(TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR, alignedIntrinsics); int returnValue = TangoSupport.FitPlaneModelNearClick( m_points, m_pointsCount, m_depthTimestamp, alignedIntrinsics, ref colorCameraTUnityWorld, normalizedPos, out planeCenter, out plane); if (returnValue == Common.ErrorType.TANGO_SUCCESS) { return(true); } else { return(false); } }
/// <summary> /// Estimates the depth of a point on a screen, based on nearest neighbors. /// </summary> /// <returns> /// <c>true</c> if a successful depth estimate was obtained. /// </returns> /// <param name="cam">The Unity camera.</param> /// <param name="pos">The point in pixel coordinates to perform depth estimation.</param> /// <param name="colorCameraPoint"> /// The point (x, y, z), where (x, y) is the back-projection of the UV /// coordinates to the color camera space and z is the z coordinate of /// the point in the point cloud nearest to the user selection after /// projection onto the image plane. If there is not a point cloud point /// close to the user selection after projection onto the image plane, /// then the point will be set to (0.0, 0.0, 0.0) and isValidPoint will /// be set to false. /// </param> public bool EstimateDepthOnScreen(Camera cam, Vector2 pos, out Vector3 colorCameraPoint) { // Set up parameters Matrix4x4 colorCameraTUnityWorld = TangoSupport.COLOR_CAMERA_T_UNITY_CAMERA * cam.transform.worldToLocalMatrix; Vector2 normalizedPos = cam.ScreenToViewportPoint(pos); // If the camera has a TangoARScreen attached, it is not displaying the entire color camera image. Correct // the normalized coordinates by taking the clipping into account. TangoARScreen arScreen = cam.gameObject.GetComponent <TangoARScreen>(); if (arScreen != null) { normalizedPos = arScreen.ViewportPointToCameraImagePoint(normalizedPos); } bool returnValue = TangoSupport.ScreenCoordinateToWorldNearestNeighbor( m_mostRecentPointCloud, arScreen.m_screenUpdateTime, normalizedPos, out colorCameraPoint); return(returnValue); }
/// <summary> /// Start is called on the frame when a script is enabled. /// </summary> public void Start() { m_tangoApplication = FindObjectOfType <TangoApplication>(); m_tangoARScreen = GetComponent <TangoARScreen>(); if (m_tangoApplication != null) { if (AndroidHelper.IsTangoCorePresent()) { // Request Tango permissions m_tangoApplication.RegisterPermissionsCallback(_OnTangoApplicationPermissionsEvent); m_tangoApplication.RequestNecessaryPermissionsAndConnect(); } else { // If no Tango Core is present let's tell the user to install it! StartCoroutine(_InformUserNoTangoCore()); } } else { Debug.Log("No Tango Manager found in scene."); } }
/// <summary> /// Start is called on the frame when a script is enabled. /// </summary> public void Start() { m_tangoApplication = FindObjectOfType<TangoApplication>(); m_tangoARScreen = GetComponent<TangoARScreen>(); if (m_tangoApplication != null) { if (AndroidHelper.IsTangoCorePresent()) { // Request Tango permissions m_tangoApplication.Register(this); m_tangoApplication.RequestPermissions(); } else { // If no Tango Core is present let's tell the user to install it! StartCoroutine(_InformUserNoTangoCore()); } } else { Debug.Log("No Tango Manager found in scene."); } }
public void ToggleArMode(bool active) { arMode = active; ui.setupSecondaryMenu(); #if USE_ARKIT GameObject root = GameObject.Find("Scene"); GameObject arPlanes = GameObject.Find("ARPlanes"); GameObject arKit = GameObject.Find("ARKit"); TouchInput input = inputAdapter.GetComponent <TouchInput>(); GameObject arConfigWidget = GameObject.Find("GUI/Canvas/ARConfigWidget"); GameObject rootScene = SceneLoader.scnRoot; if (m_anchorPrefab == null) { m_anchorPrefab = Resources.Load("VPET/Prefabs/AnchorModifier", typeof(GameObject)) as GameObject; } if (input) { input.enabled = !active; } #endif if (active) { #if USE_TANGO sceneAdapter.HideGeometry(); tangoApplication.m_enableVideoOverlay = true; tangoApplication.m_videoOverlayUseTextureMethod = true; TangoARScreen tangoArScreen = Camera.main.gameObject.GetComponent <TangoARScreen>(); if (tangoArScreen == null) { tangoArScreen = Camera.main.gameObject.AddComponent <TangoARScreen>(); } tangoArScreen.enabled = true; #elif USE_ARKIT //avoids object updates while placing, scaling, rotating scene in AR setup lockScene = true; // reset camera cameraAdapter.globalCameraReset(); //resetCameraOffset(); Camera.main.transform.position = Vector3.zero; Camera.main.transform.rotation = Quaternion.identity; //Camera.main.fieldOfView = 60; //Camera.main.nearClipPlane = 0.1f; //Camera.main.farClipPlane = 100000; // enable video background ARScreen arkitScreen = Camera.main.gameObject.GetComponent <ARScreen>(); if (arkitScreen == null) { arkitScreen = Camera.main.gameObject.AddComponent <ARScreen>(); } if (arKit) { ARKitController arController = arKit.GetComponent <ARKitController>(); if (arController) { arController.setARMode(true); } } // enable plane alignment if (root) { ARPlaneAlignment hitTest = root.GetComponent <ARPlaneAlignment>(); if (hitTest == null) { hitTest = root.AddComponent <ARPlaneAlignment>(); hitTest.m_HitTransform = root.transform; } } // enable plane visualisation if (arPlanes) { ARPlane arPlaneComponent = arPlanes.GetComponent <ARPlane>(); if (arPlaneComponent == null) { arPlaneComponent = arPlanes.AddComponent <ARPlane>(); } } // create anchor modifier if (m_anchorModifier == null) { m_anchorModifier = GameObject.Instantiate(m_anchorPrefab); m_anchorModifier.transform.position = Vector3.zero; m_anchorModifier.layer = LayerMask.NameToLayer("RenderInFront"); foreach (Transform child in m_anchorModifier.transform) { child.gameObject.layer = 8; } m_anchorModifier.transform.localScale = Vector3.zero; m_anchorModifier.name = "ARModifier"; if (root) { m_anchorModifier.transform.SetParent(root.transform, false); } } ui.hideConfigWidget(); //hide scene while placing AR anchor //rootScene.SetActive(false); arConfigWidget.SetActive(true); SetSceneScale(VPETSettings.Instance.sceneScale); //arConfigWidget.transform.Find("scale_value").GetComponent<Text>().text; //initalize ar lock buttons ui.changeARLockRotationButtonImage(lockARRotation); ui.changeARLockScaleButtonImage(lockARScale); #endif } else { #if USE_TANGO Camera.main.gameObject.GetComponent <TangoARScreen>().enabled = false; GameObject.Destroy(Camera.main.GetComponent <TangoARScreen>()); tangoApplication.m_enableVideoOverlay = false; #elif USE_ARKIT if (arKit) { ARKitController arController = arKit.GetComponent <ARKitController>(); if (arController) { arController.setARMode(false); } } // destroy video background GameObject.Destroy(Camera.main.GetComponent <ARScreen>()); if (root) { GameObject.Destroy(root.GetComponent <ARPlaneAlignment>()); } // destroy plane visualisation if (arPlanes) { GameObject.Destroy(arPlanes.GetComponent <ARPlane>()); } // disable anchor visualisation if (m_anchorModifier) { m_anchorModifier.SetActive(false); GameObject.Destroy(m_anchorModifier); m_anchorModifier = null; } #endif // reset cameras to defaults Camera.main.ResetProjectionMatrix(); SetSceneScale(1f); repositionCamera(); UpdateProjectionMatrixSecondaryCameras(); sceneAdapter.ShowGeometry(); } hasUpdatedProjectionMatrix = true; }
/// <summary> /// Start is called on the frame when a script is enabled. /// </summary> public void Start() { m_tangoARScreen = GetComponent<TangoARScreen>(); TangoApplication tangoApplication = FindObjectOfType<TangoApplication>(); if (tangoApplication != null) { tangoApplication.Register(this); } else { Debug.Log("No Tango Manager found in scene."); } }
/// <summary> /// Start is called on the frame when a script is enabled. /// </summary> public void Start() { m_tangoARScreen = GetComponent<TangoARScreen>(); m_tangoApplicaiton = FindObjectOfType<TangoApplication>(); if (m_tangoApplicaiton != null) { m_tangoApplicaiton.Register(this); // If already connected to a service, then do initialization now. if (m_tangoApplicaiton.IsServiceConnected) { OnTangoServiceConnected(); } } else { Debug.Log("No Tango Manager found in scene."); } }
/// <summary> /// Minji Kim 2017.09.25 /// Find Edge Wrapper /// call FindEdgesNearPoint /// TangoSupport_findEdgesNearPoint /// </summary> /// <param name="cam"></param> /// <param name="pos"></param> /// <returns></returns> public bool FindEdges(TangoUnityImageData imageBuffer, Camera cam, Vector2 pos, out TangoSupport.TangoSupportEdge[] edges, out int num_edges) //out Vector3[] end_points, out Vector3 nearest_on_edge) { if (m_pointsCount == 0) { // No points to check, maybe not connected to the service yet edges = new TangoSupport.TangoSupportEdge[1]; num_edges = 0; return(false); } Vector2 normalizedPos = cam.ScreenToViewportPoint(pos); // If the camera has a TangoARScreen attached, it is not displaying the entire color camera image. Correct // the normalized coordinates by taking the clipping into account. TangoARScreen arScreen = cam.gameObject.GetComponent <TangoARScreen>(); if (arScreen != null) { normalizedPos = arScreen.ViewportPointToCameraImagePoint(normalizedPos); } // if the image data has not been updated, update it manually if (imageBuffer.data == null) { GetTangoUnityImageData(ref imageBuffer); } bool returnValue = TangoSupport.FindEdgesNearPoint( imageBuffer, m_mostRecentPointCloud, arScreen.m_screenUpdateTime, normalizedPos, out edges, out num_edges ); Vector3[] start = new Vector3[num_edges]; Vector3[] end = new Vector3[num_edges]; Vector3[] near = new Vector3[num_edges]; TangoSupport.TangoSupportEdge[] n_edges = new TangoSupport.TangoSupportEdge[num_edges]; for (int j = 0; j < num_edges; j++) { start[j] = new Vector3(edges[j].end_points_x1, edges[j].end_points_y1, edges[j].end_points_z1); end[j] = new Vector3(edges[j].end_points_x2, edges[j].end_points_y2, edges[j].end_points_z2); near[j] = new Vector3(edges[j].closest_point_on_edge_x, edges[j].closest_point_on_edge_y, edges[j].closest_point_on_edge_z); start[j] = m_mostRecentUnityWorldTDepthCamera.MultiplyVector(start[j]); end[j] = m_mostRecentUnityWorldTDepthCamera.MultiplyVector(end[j]); near[j] = m_mostRecentUnityWorldTDepthCamera.MultiplyVector(near[j]); Vector3.Normalize(start[j]); Vector3.Normalize(end[j]); Vector3.Normalize(near[j]); n_edges[j].end_points_x1 = start[j][0]; n_edges[j].end_points_y1 = start[j][1]; n_edges[j].end_points_z1 = start[j][2]; n_edges[j].end_points_x2 = end[j][0]; n_edges[j].end_points_y2 = end[j][1]; n_edges[j].end_points_z2 = end[j][2]; n_edges[j].closest_point_on_edge_x = near[j][0]; n_edges[j].closest_point_on_edge_y = near[j][1]; n_edges[j].closest_point_on_edge_z = near[j][2]; } edges = n_edges; return(returnValue); }