static ARPlaneAnchor GetPlaneAnchorFromAnchorData(UnityARAnchorData anchor)
        {
            //get the identifier for this anchor from the pointer
            ARPlaneAnchor arPlaneAnchor = new ARPlaneAnchor();

            arPlaneAnchor.identifier = Marshal.PtrToStringAuto(anchor.ptrIdentifier);

            Matrix4x4 matrix = new Matrix4x4();

            matrix.SetColumn(0, anchor.transform.column0);
            matrix.SetColumn(1, anchor.transform.column1);
            matrix.SetColumn(2, anchor.transform.column2);
            matrix.SetColumn(3, anchor.transform.column3);

            arPlaneAnchor.transform = matrix;
            arPlaneAnchor.alignment = anchor.alignment;
            arPlaneAnchor.center    = new Vector3(anchor.center.x, anchor.center.y, anchor.center.z);
            arPlaneAnchor.extent    = new Vector3(anchor.extent.x, anchor.extent.y, anchor.extent.z);
            return(arPlaneAnchor);
        }
Exemple #2
0
        void UpdatePositionIfARScrewUp(ARPlaneAnchor arPlaneAnchor)
        {
            ARPoint point = new ARPoint {
                x = transform.position.x,
                y = transform.position.z
            };

            List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, ARHitTestResultType.ARHitTestResultTypeEstimatedHorizontalPlane);

            if (hitResults.Count > 0)
            {
                foreach (var hitResult in hitResults)
                {
                    //Debug.Log ("Got hit!");
                    transform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                    //transform.rotation = UnityARMatrixOps.GetRotation (hitResult.worldTransform);

                    //Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", transform.position.x, transform.position.y, transform.position.z));
                }
            }
        }
Exemple #3
0
        public static GameObject UpdatePlaneWithAnchorTransform(GameObject plane, ARPlaneAnchor arPlaneAnchor)
        {
            //do coordinate conversion from ARKit to Unity
            plane.transform.position = UnityARMatrixOps.GetPosition(arPlaneAnchor.transform);
            plane.transform.rotation = UnityARMatrixOps.GetRotation(arPlaneAnchor.transform);


            MeshFilter mf = plane.GetComponentInChildren <MeshFilter> ();

            if (mf != null)
            {
                //since our plane mesh is actually 10mx10m in the world, we scale it here by 0.1f
                mf.gameObject.transform.localScale = new Vector3(arPlaneAnchor.extent.x * 0.1f, arPlaneAnchor.extent.y * 0.1f, arPlaneAnchor.extent.z * 0.1f);


                //convert our center position to unity coords
                mf.gameObject.transform.localPosition = new Vector3(arPlaneAnchor.center.x, arPlaneAnchor.center.y, -arPlaneAnchor.center.z);
            }

            return(plane);
        }
Exemple #4
0
        public void AddAnchor(ARPlaneAnchor arPlaneAnchor)
        {
            GameObject go = UnityARUtility.CreatePlaneInScene(arPlaneAnchor);

            go.AddComponent <DontDestroyOnLoad> ();                     //this is so these GOs persist across scene loads
            ARPlaneAnchorGameObject arpag = new ARPlaneAnchorGameObject();

            arpag.planeAnchor = arPlaneAnchor;
            arpag.gameObject  = go;
            planeAnchorMap.Add(arPlaneAnchor.identifier, arpag);

            UnityARSessionNativeInterface.ARAnchorAddedEvent -= AddAnchor;


            //modified
            PlaneAppearDetector detector = generatedPlane;

            detector.planeDetect();
            detector = hitScript;
            detector.planeDetect();
            PlaneDetectorSwitcher switcher = Camera_managerScrpt;
        }
        public void AddAnchor(ARPlaneAnchor arPlaneAnchor)
        {
            if (_floorDetectionStatus == FloorDetectionStatus.Finding)
            {
                if (_debug)
                {
                    debugMessage.text = "Anchor added";
                }
                Debug.Log("New Anchor added");


                // Get point of battle field by using ray from center of display to detected floor and
                Vector3 center         = new Vector3(Screen.width / 2, Screen.height / 2, 0.5f);
                var     screenPosition = Camera.main.ScreenToViewportPoint(center);
                ARPoint point          = new ARPoint
                {
                    x = screenPosition.x,
                    y = screenPosition.y
                };

                List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, ARHitTestResultType.ARHitTestResultTypeExistingPlane);
                if (hitResults.Count > 0)
                {
                    foreach (var hitResult in hitResults)
                    {
                        _basePoint = UnityARMatrixOps.GetPosition(hitResult.worldTransform) + _baseVector;
                    }
                }

                // Change floor detection status to detected
                _floorDetectionStatus = FloorDetectionStatus.Found;
                Debug.Log("Floor detected");
                mainMessage.text = "Detection Complete";

                // Invoke StartGame() with delay
                Invoke("StartGame", 0.5f);
            }
        }
Exemple #6
0
        public static GameObject UpdatePlaneWithAnchorTransform(GameObject plane, ARPlaneAnchor arPlaneAnchor)
        {
            //do coordinate conversion from ARKit to Unity
            plane.transform.position = UnityARMatrixOps.GetPosition(arPlaneAnchor.transform);
            plane.transform.rotation = UnityARMatrixOps.GetRotation(arPlaneAnchor.transform);

            ARKitPlaneMeshRender apmr = plane.GetComponent <ARKitPlaneMeshRender> ();

            if (apmr != null)
            {
                apmr.UpdateMesh(arPlaneAnchor);
            }


            MeshFilter mf           = plane.GetComponentInChildren <MeshFilter> ();
            Vector2    textureScale = plane.GetComponentInChildren <MeshRenderer>().material.mainTextureScale;

            int textureScaleX = (int)(arPlaneAnchor.extent.x * 50);
            int textureScaleY = (int)(arPlaneAnchor.extent.z * 50);

            textureScale = new Vector2(textureScaleX, textureScaleY);
            plane.GetComponentInChildren <MeshRenderer>().material.mainTextureScale = textureScale;


            if (mf != null)
            {
                if (apmr == null)
                {
                    //since our plane mesh is actually 10mx10m in the world, we scale it here by 0.1f
                    mf.gameObject.transform.localScale = new Vector3(arPlaneAnchor.extent.x * 0.1f, arPlaneAnchor.extent.y * 0.1f, arPlaneAnchor.extent.z * 0.1f);

                    //convert our center position to unity coords
                    mf.gameObject.transform.localPosition = new Vector3(arPlaneAnchor.center.x, arPlaneAnchor.center.y, -arPlaneAnchor.center.z);
                }
            }

            return(plane);
        }
        static ARPlaneAnchor GetPlaneAnchorFromAnchorData(UnityARAnchorData anchor)
        {
            #if PLATFORM_IOS
            //get the identifier for this anchor from the pointer
            ARPlaneAnchor arPlaneAnchor = new ARPlaneAnchor();
            arPlaneAnchor.identifier = Marshal.PtrToStringAuto(anchor.ptrIdentifier);

            Matrix4x4 matrix = new Matrix4x4();
            matrix.SetColumn(0, anchor.transform.column0);
            matrix.SetColumn(1, anchor.transform.column1);
            matrix.SetColumn(2, anchor.transform.column2);
            matrix.SetColumn(3, anchor.transform.column3);

            arPlaneAnchor.transform = matrix;
            arPlaneAnchor.alignment = anchor.alignment;
            arPlaneAnchor.center    = new Vector3(anchor.center.x, anchor.center.y, anchor.center.z);
            arPlaneAnchor.extent    = new Vector3(anchor.extent.x, anchor.extent.y, anchor.extent.z);
            return(arPlaneAnchor);
            #else
            Debug.Log("Not available on non iOS platforms");
            return(new ARPlaneAnchor());
            #endif
        }
Exemple #8
0
        public static GameObject UpdatePlaneWithAnchorTransform(GameObject plane, ARPlaneAnchor arPlaneAnchor)
        {
            // TANKS CODE
            if (ARKitGameManager.instance.gameMode != ARKitGameManager.GameMode.Calibration)
            {
                return(plane);
            }
            /////

            //do coordinate conversion from ARKit to Unity
            plane.transform.position = UnityARMatrixOps.GetPosition(arPlaneAnchor.transform);
            plane.transform.rotation = UnityARMatrixOps.GetRotation(arPlaneAnchor.transform);

            ARKitPlaneMeshRender apmr = plane.GetComponent <ARKitPlaneMeshRender> ();

            if (apmr != null)
            {
                apmr.UpdateMesh(arPlaneAnchor);
            }


            MeshFilter mf = plane.GetComponentInChildren <MeshFilter> ();

            if (mf != null)
            {
                if (apmr == null)
                {
                    //since our plane mesh is actually 10mx10m in the world, we scale it here by 0.1f
                    mf.gameObject.transform.localScale = new Vector3(arPlaneAnchor.extent.x * 0.1f, arPlaneAnchor.extent.y * 0.1f, arPlaneAnchor.extent.z * 0.1f);

                    //convert our center position to unity coords
                    mf.gameObject.transform.localPosition = new Vector3(arPlaneAnchor.center.x, arPlaneAnchor.center.y, -arPlaneAnchor.center.z);
                }
            }

            return(plane);
        }
        public static GameObject CreatePlaneInScene(ARPlaneAnchor arPlaneAnchor)
        {
            GameObject plane;

            if (planePrefab != null)
            {
                plane = GameObject.Instantiate(planePrefab);
            }
            else
            {
                plane = new GameObject();                  //put in a blank gameObject to get at least a transform to manipulate
            }

            plane.name = arPlaneAnchor.identifier;

            ARKitPlaneMeshRender apmr = plane.GetComponent <ARKitPlaneMeshRender> ();

            if (apmr != null)
            {
                apmr.InitiliazeMesh(arPlaneAnchor);
            }

            return(UpdatePlaneWithAnchorTransform(plane, arPlaneAnchor));
        }
Exemple #10
0
        public void ARAnchorUpdated(ARPlaneAnchor planeAnchor)
        {
            serializableUnityARPlaneAnchor serPlaneAnchor = planeAnchor;

            SendToEditor(ConnectionMessageIds.updatePlaneAnchorMsgeId, serPlaneAnchor);
        }
Exemple #11
0
        public void ARAnchorRemoved(ARPlaneAnchor planeAnchor)
        {
            serializableUnityARPlaneAnchor serializableObject = planeAnchor;

            SendToEditor(ConnectionMessageIds.removePlaneAnchorMsgeId, serializableObject);
        }