public void LoadFromFile(string filename) { string filepath = filename + ".es3"; groundPlaneAnchorIdentifier = ES3.Load <string>("identifier", filepath); Vector3 position = ES3.Load <Vector3>("groundPlanePosition", filepath); CreateGroundPlane(position); groundPlane.shapes[0].points = ES3.Load <List <Vector3> >("points", filepath); groundPlane.UpdateMeshDisplay(); isClose = true; Status = GroundPlaneManagerStatus.FinishCreateGroundMesh; }
public void NewSession(bool isLoading) { particle.gameObject.SetActive(true); groundPlaneAnchorIdentifier = ""; groundPlane.shapes[0].points.Clear(); groundPlane.UpdateMeshDisplay(); Destroy(groundPlane.gameObject); isClose = false; if (!isLoading) { Status = GroundPlaneManagerStatus.GetingARKitGroundPlane; } }
//private void AddPlanePoint(ARPoint point, ARHitTestResultType resultTypes) { // List<ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); // if (hitResults.Count > 0) { // foreach (var hitResult in hitResults) { // if (hitResult.anchorIdentifier == groundPlaneAnchorIdentifier) { // Vector3 position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); // Quaternion rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform); // if (isClose) { // foreach (GameObject p in groundPlane.pointPrefabList) { // p.SetActive(false); // aimTarget.SetActive(false); // aimTextMesh.gameObject.SetActive(false); // Status = GroundPlaneManagerStatus.FinishCreateGroundMesh; // } // } else { // groundPlane.pointPrefabList.Add(Instantiate(pointPrefab, position, rotation)); // if (groundPlane.pointPrefabList.Count > 1) // groundPlane.pointPrefabList[groundPlane.pointPrefabList.Count - 2].GetComponent<MeshRenderer>().material = pointPrefabWhiteMat; // groundPlane.shapes[0].points.Add(position); // groundPlane.UpdateMeshDisplay(); // } // } // } // } //} private void AddPlanePointHitTest(Vector3 hitpoint) { if (isClose) { foreach (GameObject p in groundPlane.pointPrefabList) { p.SetActive(false); aimTarget.SetActive(false); aimTextMesh.gameObject.SetActive(false); Status = GroundPlaneManagerStatus.FinishCreateGroundMesh; } } else { groundPlane.pointPrefabList.Add(Instantiate(pointPrefab, hitpoint, Quaternion.identity)); if (groundPlane.pointPrefabList.Count > 1) { groundPlane.pointPrefabList[groundPlane.pointPrefabList.Count - 2].GetComponent <MeshRenderer>().material = pointPrefabWhiteMat; } groundPlane.shapes[0].points.Add(hitpoint); groundPlane.UpdateMeshDisplay(); } }
private void Start() { aimTarget.SetActive(false); Status = GroundPlaneManagerStatus.GetingARKitGroundPlane; }
// Update is called once per frame void Update() { if (Status == GroundPlaneManagerStatus.GetingARKitGroundPlane) { if (Input.touchCount > 0) { var touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) { var screenPosition = Camera.main.ScreenToViewportPoint(touch.position); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; if (GetGroundPlane(point, ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent)) { Status = GroundPlaneManagerStatus.CreatingGroundMesh; particle.gameObject.SetActive(false); return; } } } } if (Status == GroundPlaneManagerStatus.CreatingGroundMesh) { //ARPoint aimpoint = new ARPoint { // x = screenCenterPosition.x, // y = screenCenterPosition.y //}; //AimTarget(aimpoint, ARHitTestResultType.ARHitTestResultTypeExistingPlane); Vector3 hitPoint; if (AimTargetHitTest(screenCenterPosition, out hitPoint)) { if (Input.touchCount > 0) { var touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { //AddPlanePoint(aimpoint, ARHitTestResultType.ARHitTestResultTypeExistingPlane); AddPlanePointHitTest(hitPoint); } } } } if (isDisplay) { if (textMesh.Count > 0) { for (int i = 0; i < textMesh.Count; i++) { //Quaternion rotation = textMesh[i].transform.rotation; //rotation.x = Camera.main.transform.rotation.x; textMesh[i].transform.rotation = Camera.main.transform.rotation; } } } }