void Update() { if (!Input.GetMouseButtonDown(0)) { return; } if (!m_SessionOrigin.Raycast(Input.mousePosition, s_Hits, TrackableType.PlaneWithinPolygon)) { return; } var hit = s_Hits[0]; var referencePointManager = m_SessionOrigin.GetComponent <ARReferencePointManager>(); var planeManager = m_SessionOrigin.GetComponent <ARPlaneManager>(); var plane = planeManager.TryGetPlane(hit.trackableId); if (plane == null) { return; } referencePointManager.TryAttachReferencePoint(plane, new Pose(hit.pose.position + Vector3.up * .1f, hit.pose.rotation)); }
// Update is called once per frame void Update() { // Detect touch // project raycast // instantiate a virtual cube if (Input.GetMouseButton(0)) { bool collision = origin.GetComponent <ARRaycastManager>().Raycast(Input.mousePosition, raycasthits, UnityEngine.XR.ARSubsystems.TrackableType.PlaneWithinPolygon); if (collision) { if (instantiatedCube == null) { instantiatedCube = Instantiate(cube); foreach (var plane in origin.GetComponent <ARPlaneManager>().trackables) { plane.gameObject.SetActive(false); } origin.GetComponent <ARPlaneManager>().enabled = false; } instantiatedCube.transform.position = raycasthits[0].pose.position; } } }
private void PlaceBuilding() { List <ARRaycastHit> hits = new List <ARRaycastHit>(); if (m_SessionOrigin.GetComponent <ARRaycastManager>().Raycast(touchPosition, hits, UnityEngine.XR.ARSubsystems.TrackableType.PlaneWithinPolygon)) { if (BuildingPlaced != true) { var hitPose = hits[0].pose; // set hit position to know y values plane targetPosition = new Vector3(hitPose.position.x, hitPose.position.y, hitPose.position.z); //set variables for camera position for rotation var cameraForward = Camera.current.transform.forward; var cameraBearing = new Vector3(cameraForward.x, 0, cameraForward.z).normalized; //for position var cameraPos = Camera.current.transform.position; //set position to 5 units from camera with y value being plane CenterPos = cameraPos + cameraBearing * 5; CenterPos.y = hitPose.position.y; //set rotation to look at camera Quaternion targetRotation = Quaternion.LookRotation(cameraBearing); //set building pos Building.transform.position = CenterPos; //set rot to object looking at camera orientated to the right Building.transform.rotation = Quaternion.LookRotation(targetRotation * Vector3.right, Vector3.up); //disable planes and point clouds DisablePlanes(); DisablePoints(); //set building active and ask if placement ok Building.SetActive(true); BuildingPlaced = true; buildUI.SetActive(true); } } }
void OnRayHit(ARRaycastHit hit) { if (!Input.GetMouseButtonDown(0)) { return; } var referencePointManager = m_ARSessionOrigin.GetComponent <ARReferencePointManager>(); var planeManager = m_ARSessionOrigin.GetComponent <ARPlaneManager>(); if (referencePointManager == null || planeManager == null) { return; } var plane = planeManager.GetPlane(hit.trackableId); if (plane == null) { return; } if (m_Attachment != null) { referencePointManager.RemoveReferencePoint(m_Attachment); m_Attachment = null; } var planeNormal = plane.transform.up; var pose = new Pose(hit.pose.position + planeNormal * m_DistanceFromPlane, hit.pose.rotation); m_Attachment = referencePointManager.AttachReferencePoint(plane, pose); }
private void handleDragging() { // perform a new ray cast against where we have touched on the screen if (arOrigin.GetComponent <ARRaycastManager>().Raycast(touchPosition, hits, TrackableType.PlaneWithinPolygon)) { // update our set selected object's position and rotation for the dragging selectedObject.transform.position = hits[0].pose.position; selectedObject.transform.rotation = hits[0].pose.rotation; } }
IEnumerator coTimedelay(object arObj) { ARPlane arPlane = (ARPlane)arObj; yield return(new WaitForSeconds(3.0f)); arPlaneManager.detectionMode = PlaneDetectionMode.None; arPlane.gameObject.SetActive(false); arSessionOrigin.GetComponent <ARPlaneManager>().enabled = false; arSessionOrigin.GetComponent <ARPointCloudManager>().enabled = false; Debug.Log("***************** 바닥 인식 Plane 비활성화"); }
// Use this for initialization void Start() { arOrigin = FindObjectOfType <ARSessionOrigin>(); ARSessionOrigin = arOrigin.GetComponent <ARSessionOrigin>(); inOtherWorld = portalWindow.GetComponent <PortalOther> (); tracked = device.GetComponent <TrackedPoseDriver>(); }
// Start is called before the first frame update void Start() { arOrigin = FindObjectOfType <ARSessionOrigin>(); //aRRaycastManager = arOrigin.GetComponent<ARRaycastManager>(); disablePlacement = arOrigin.GetComponent <PlacementDisable>(); }
private void OnPlaneChanged(ARPlanesChangedEventArgs obj) { if (!onPlaneDetect) { Debug.Log("OnPlaneChanged --------->>"); onPlaneDetect = true; foreach (var plane in obj.added) { var hits = new List <ARRaycastHit>(); Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward); arSessionOrigin.GetComponent <ARRaycastManager>().Raycast(ray, hits, TrackableType.Planes); if (hits.Count > 0) { Pose pose = hits[0].pose; planeObject = Instantiate(planePrefab, new Vector3(pose.position.x, pose.position.y, pose.position.z), Quaternion.identity); planeYPose = planeObject.transform.position.y; Debug.Log("planeObject position--------->>" + planeObject.transform.position); SwitchSurfaceDetection(); scanPanel.SetActive(false); btnObjectList.SetActive(true); break; } } } }
private void UpdatePlacementPose() { var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f)); var hits = new List <ARRaycastHit>(); arOrigin.Raycast(screenCenter, hits, TrackableType.PlaneWithinBounds); placementPoseIsValid = hits.Count > 0; if (placementPoseIsValid) { nav.AddPlane(arMan.TryGetPlane(hits[0].trackableId).GetComponent <NavMeshSurface>()); placementPose = hits[0].pose; placementPose.position.y += 0.1f; var cameraForward = Camera.current.transform.forward; var cameraBearing = new Vector3(cameraForward.x, 0, cameraForward.z).normalized; placementPose.rotation = Quaternion.LookRotation(cameraBearing); if (arOrigin.GetComponent <ARPlaneManager>().TryGetPlane(hits[0].trackableId).boundedPlane.Alignment != PlaneAlignment.Vertical) { canPlaceObject = true; } else { canPlaceObject = false; } } }
void Start() { m_RaycastManager = m_Session_Origin.GetComponent <ARRaycastManager>(); cam = Camera.main; if (!fixedLine) { fixedLine = GetComponent <LineRenderer>(); } currlist = new List <GameObject>(); linelist = new List <GameObject>(); distline = new List <GameObject>(); centralObject = Instantiate(m_PlacedPrefab, cubepl.transform.position, cubepl.transform.rotation); //m_DistanceVisualizer_yellow.GetComponent<LineRenderer>().SetPosition(0, belcam.transform.position); //Vector3 finpos = Vector3.Lerp(cubepl.transform.position, belcam.transform.position, 0.1f); Vector3 finpos = cubepl.transform.position; //m_DistanceVisualizer_yellow.GetComponent<LineRenderer>().SetPosition(1, finpos); //m_DistanceVisualizer_yellow.GetComponent<LineRenderer>().material.color = Color.yellow; //fixedline = GameObject.Instantiate(m_DistanceVisualizer_yellow, centralObject.transform.position, Quaternion.identity, centralObject.transform); //fixedline.GetComponent<CompleteLine>().finalPos = belcam.transform.position; fl = Instantiate(fixedLine); cubepl.transform.LookAt(cam.transform); shad = Instantiate(Shadow); }
private void Pathfinding() { if (aRSessionOrigin) { List <ARRaycastHit> hits = new List <ARRaycastHit>(); aRSessionOrigin.GetComponent <ARRaycastManager>().Raycast(transform.position, hits, UnityEngine.XR.ARSubsystems.TrackableType.All); if (hits.Count > 0) { Debug.Log("Proximity alert!"); Vector3 direction = ChooseDirection(); Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z)); transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, rotationalDamp * Time.deltaTime); } } else { RaycastHit hit; if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, 0.2f)) { if (hit.collider.tag == "Player") { return; } Debug.Log("Proximity alert!"); Vector3 direction = ChooseDirection(); transform.position += direction * speed * Time.deltaTime; } } }
void Start() { arOrigin = FindObjectOfType <ARSessionOrigin>(); arRaycastManager = arOrigin.GetComponent <ARRaycastManager>(); arCamera = Camera.main; }
public void Init() { canMove = true; arOrigin = FindObjectOfType <ARSessionOrigin>(); arRayManager = arOrigin.GetComponent <ARRaycastManager>(); VechileName = "PrototypeTank"; }
private void UpdatePlacementPose() { /* we need to shoot a ray straight out from screen center*/ // find screen center var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f, 0.5f)); // store what we've hit var hits = new List <ARRaycastHit>(); // perform the raycast arOrigin.GetComponent <ARRaycastManager>().Raycast(screenCenter, hits, UnityEngine.XR.ARSubsystems.TrackableType.Planes); /* now, once we have successfully stored a hit, we need to turn on the indicator * so we can see the plane of where we hit, we'll track that with validPlacementPose */ // make sure we've hit something first validPlacementPose = hits.Count > 0; if (validPlacementPose) { // the first thing we successfully register is where we will place the indicator placementPose = hits[0].pose; // orient indicator icon with camera var cameraForward = Camera.current.transform.forward; var cameraBearing = new Vector3(cameraForward.x, 0, cameraForward.z).normalized; placementPose.rotation = Quaternion.LookRotation(cameraBearing); } }
void Start() { mainCam = FindObjectOfType <Camera>(); //You should only have one camera in the scene for this test aRSessionOrigin = FindObjectOfType <ARSessionOrigin>(); // creating a reference to ARSessionOrigin raycastManager = aRSessionOrigin.GetComponent <ARRaycastManager>(); //need this to perform raycasts to any "AR trackable". It should be in the same game object as ARSessionOrigin objectToPaintWithVisualizer = Instantiate(objectToPaintWith, Vector3.zero, Quaternion.identity); //will use this to visualize the brush were are using }
// Start is called before the first frame update void Start() { arOrigin = FindObjectOfType <ARSessionOrigin>(); arPlaneManager = arOrigin.GetComponent <ARPlaneManager>(); arRayCastMgr = arOrigin.GetComponent <ARRaycastManager>(); arCameraManager = arOrigin.camera.GetComponent <ARCameraManager>(); if (arCameraManager != null) { arCameraManager.frameReceived -= FrameChanged; } if (arCameraManager != null & enabled) { arCameraManager.frameReceived += FrameChanged; } }
// Start is called before the first frame update void Start() { if (ar_session.GetComponent <SwitchPrefab>().markerPrefabCombos != null) { allObjects = ar_session.GetComponent <SwitchPrefab>().markerPrefabCombos; } else { Debug.Log("marker prefab combos null"); } if (goldilocks.GetComponent <Collider>() != null) { goldilocksCollider = goldilocks.GetComponent <Collider>(); } else { Debug.Log("goldilocks collider null"); } }
// Start is called before the first frame update void Start() { // set session origion transform to transform of the instantionated object ARSessionOrigin origin = FindObjectOfType <ARSessionOrigin>(); origin.transform.position = transform.position; origin.transform.rotation = transform.rotation; // disable image and object manager ARTrackedImageManager imageManger = origin.GetComponent <ARTrackedImageManager>(); imageManger.enabled = false; ARTrackedObjectManager objectManger = origin.GetComponent <ARTrackedObjectManager>(); objectManger.enabled = false; if (OnSceneRootSet != null) { OnSceneRootSet.Raise(); } }
/*private void UpdatePlacementIndicator() * { * if (placementPoseIsValid && !avatarHasBeenPlaced) { * placementIndicator.SetActive(true); * placementIndicator.transform.SetPositionAndRotation(placementPose.position, placementPose.rotation); * } else { * placementIndicator.SetActive(false); * } * } */ private void UpdatePlacementPose() { var planeManager = arOrigin.GetComponent <ARPlaneManager>(); var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f)); var hits = new List <ARRaycastHit>(); var raycastMgr = arOrigin.GetComponent <ARRaycastManager>(); raycastMgr.Raycast(screenCenter, hits, TrackableType.Planes); Debug.Log("Hits count is " + hits.Count); placementPoseIsValid = hits.Count > 0; if (placementPoseIsValid) { placementPose = hits[0].pose; var cameraForward = Camera.current.transform.forward; var cameraBearing = new Vector3(cameraForward.x, 0, cameraForward.z).normalized; placementPose.rotation = Quaternion.LookRotation(cameraBearing); } }
public void PlaceOnSelectedPlane(Transform contentParent, float contentDimension) { ARSessionOrigin.MakeContentAppearAt(contentParent, tappedPosition, tappedRotation); ARSessionOrigin.transform.localScale = Vector3.one * (contentDimension / tappedMinDimension); arCamera.nearClipPlane = savedCameraNear * (contentDimension / tappedMinDimension); arCamera.farClipPlane = savedCameraFar * (contentDimension / tappedMinDimension); ARPlaneManager arPlaneManager = ARSessionOrigin.GetComponent <ARPlaneManager>(); arPlaneManager.planePrefab = null; //do not generate any more visible planes ARSessionOrigin.trackablesParent.gameObject.SetActive(false); //turn off existing visible planes }
// Start is called before the first frame update void Awake() { Screen.sleepTimeout = SleepTimeout.NeverSleep; //disable screen dimming on Mobile Devices. We might want to change so that it dims while in the menu. Application.targetFrameRate = 60; //Set framerate to 60hz. This improves plane detection in my experience. arOrigin = FindObjectOfType <ARSessionOrigin>(); arRaycast = arOrigin.GetComponent <ARRaycastManager>(); arPlanes = arOrigin.GetComponent <ARPlaneManager>(); arCloud = arOrigin.GetComponent <ARPointCloudManager>(); arCameraManager = Camera.main.GetComponent <ARCameraManager>(); arImageManager = arOrigin.GetComponent <ARTrackedImageManager>(); mapCreator = GetComponentInChildren <MapCreator>(); spawnedCans = new Dictionary <TrackableId, GameObject>(); spawnPoints = new List <Vector3>(); placeButton = GameObject.Find("PlaceScene"); resetButton = GameObject.Find("Reset"); resetButton.SetActive(false); }
void LookForSurface() { var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f)); sessionOrigin.GetComponent <ARRaycastManager>().Raycast(screenCenter, hits, TrackableType.Planes); canPlace = hits.Count > 0; if (canPlace) { pose = hits[0].pose; } }
private void UpdatePlacementPose() { var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f)); var hits = new List <ARRaycastHit>(); arOrigin.GetComponent <ARRaycastManager>().Raycast(screenCenter, hits, UnityEngine.XR.ARSubsystems.TrackableType.Planes); placementPoseIsValid = hits.Count > 0; if (placementPoseIsValid) { placementPose = hits[0].pose; } }
void spawn() { Debug.Log("here"); aRSessionOrigin.GetComponent <GroundPlane>().zz(); height = aRSessionOrigin.GetComponent <GroundPlane>().heightPose; wall.transform.position = new Vector3(0, 0, 15f); Debug.Log("" + height); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { Instantiate(cube, new Vector3((j * cube.transform.localScale.x), (i * 0.5f), 0f), Quaternion.identity).transform.SetParent(wall.transform); } } wall.transform.position = new Vector3(height.x, height.y / 2, 15f); // wall.transform.position -= new Vector3(0,height.y,0); Debug.Log("" + wall.transform.position); Debug.Log("" + wall.transform.localPosition); toJS(); }
private void UpdatePlane() { Vector3 center = Camera.main.ViewportToScreenPoint(new Vector3(0.5f, 0.5f)); List <ARRaycastHit> hits = new List <ARRaycastHit>(); origin.GetComponent <ARRaycastManager>().Raycast(center, hits, UnityEngine.XR.ARSubsystems.TrackableType.PlaneEstimated); canPlace = hits.Count > 0; if (canPlace) { placementPose = hits[0].pose; } }
private void Start() { arOrigin = FindObjectOfType <ARSessionOrigin>(); arRayManager = arOrigin.GetComponent <ARRaycastManager>(); if (deviceCam == null) { #if (UNITY_ANDROID && !UNITY_EDITOR) AndroidJavaClass cameraClass = new AndroidJavaClass("android.hardware.Camera"); deviceCam = cameraClass.CallStatic <AndroidJavaObject>("open"); FlashLight(); #endif } }
// Warps cached_homoMat to outMat void HomographyTransform(ref Mat homoMat) { Corner_AR_Controller Homo_Controller = m_ARSessionManager.GetComponent <Corner_AR_Controller>(); Point[] c2_scrpoints = Homo_Controller.GetScreenpoints(false); MatOfPoint2f initPoints = new MatOfPoint2f(regPointArray); MatOfPoint2f currPoints = new MatOfPoint2f(c2_scrpoints); Mat H = Calib3d.findHomography(initPoints, currPoints); Imgproc.warpPerspective(homoMat, outMat, H, new Size(HOMOGRAPHY_WIDTH, HOMOGRAPHY_HEIGHT)); Core.flip(outMat, outMat, 0); }
// Update is called once per frame void Update() { // Check for the tap on screen if (Input.GetMouseButton(0)) { // Cast a ray from the touch position to the plane bool collision = ar_session_origin.GetComponent <ARRaycastManager>().Raycast(Input.mousePosition, raycast_hits, TrackableType.PlaneWithinPolygon); if (collision && obj == null) { obj = Instantiate(place_object); } obj.transform.position = raycast_hits[0].pose.position; } }
private void UpdatePlacementPose() { var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f)); var screenPoint = new Vector2(screenCenter.x, screenCenter.y); var hits = new List <ARRaycastHit>(); _arOrigin.GetComponent <ARRaycastManager>().Raycast(screenPoint, hits, TrackableType.Planes); _placementPoseIsValid = hits.Count != 0; if (_placementPoseIsValid) { _placementPose = hits[0].pose; var cameraForward = Camera.current.transform.forward; var cameraBearing = new Vector3(cameraForward.x, 0.0f, cameraForward.z).normalized; _placementPose.rotation = Quaternion.LookRotation(cameraBearing); } }