Пример #1
0
        public static GameObject UpdatePlaneWithAnchorTransform(GameObject plane, ARPlaneMesh arPlane)
        {
            plane.transform.position = UnityARMatrixOps.GetPosition(arPlane.transform);
            plane.transform.rotation = UnityARMatrixOps.GetRotation(arPlane.transform);

            PlacenotePlaneMeshRender ppmr = plane.GetComponent <PlacenotePlaneMeshRender> ();

            if (ppmr != null)
            {
                ppmr.UpdateMesh(arPlane);
            }


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

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

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

            return(plane);
        }
Пример #2
0
        public static Vector3 GetPlaneCenter(PlacenotePlaneMeshRender plane)
        {
            Mesh    m          = plane.GetComponent <MeshFilter> ().mesh;
            Vector3 meshCenter = Vector3.zero;

            //		Mesh m = planes [i].GetComponent<MeshFilter> ().mesh;
            for (int k = 0; k < Mathf.Min(10, m.vertexCount); k++)
            {
                meshCenter += m.vertices [k]; // planes [i].transform.TransformPoint (m.vertices [k]);
            }
            meshCenter /= Mathf.Min(10, m.vertexCount);
            return(plane.transform.TransformPoint(meshCenter));
        }
Пример #3
0
        public static PlaneType DeterminePlaneType(PlacenotePlaneMeshRender plane)
        {
            Vector3[] tri = new Vector3[] {
                plane.GetComponent <MeshFilter>().mesh.vertices[plane.GetComponent <MeshFilter>().mesh.triangles[0]],
                plane.GetComponent <MeshFilter>().mesh.vertices[plane.GetComponent <MeshFilter>().mesh.triangles[1]],
                plane.GetComponent <MeshFilter>().mesh.vertices[plane.GetComponent <MeshFilter>().mesh.triangles[2]]
            };

            if (tri[0].y == tri[1].y && tri[1].y == tri[2].y)
            {
                return(PlaneType.Horizontal);
            }
            else
            {
                return(PlaneType.Vertical);
            }
            // return PlaneType.Horizontal;
        }
        public static GameObject UpdatePlaneWithAnchorTransform(GameObject plane, ARPlaneAnchor arPlaneAnchor)
        {
            //do coordinate conversion from ARKit to Unity
            Vector3    position = UnityARMatrixOps.GetPosition(arPlaneAnchor.transform);
            Quaternion rotation = UnityARMatrixOps.GetRotation(arPlaneAnchor.transform);

            //Transform to placenote frame of reference (planes are detected in ARKit frame of reference)
            Matrix4x4 worldTransform     = Matrix4x4.TRS(position, rotation, Vector3.one);
            Matrix4x4?placenoteTransform = LibPlacenote.Instance.ProcessPose(worldTransform);

            if (placenoteTransform == null)               //no map related transforms are appropriate
            {
                placenoteTransform = worldTransform;
            }

            plane.transform.position = PNUtility.MatrixOps.GetPosition(placenoteTransform.Value);
            plane.transform.rotation = PNUtility.MatrixOps.GetRotation(placenoteTransform.Value);

            PlacenotePlaneMeshRender ppmr = plane.GetComponent <PlacenotePlaneMeshRender> ();

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


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

            if (mf != null)
            {
                if (ppmr == 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);
        }
Пример #5
0
        void GetPlaneWithHighestPointScore()
        {
            GameObject nearest = OnionLocationHelper.instance.GetNearestPlane(this.transform, 1.5f);

            if (nearest)
            {
                PlacenotePlaneMeshRender pi = nearest.GetComponent <PlacenotePlaneMeshRender> ();
                if (pi)
                {
                    SetTarget(Utils2.GetPlaneCenter(pi));
                }
                else
                {
                    // it was a fake!
                    SetTarget(nearest.transform.position);
                }
            }
            else
            {
                Debug.LogError("no nearest!");
            }
        }
Пример #6
0
        public static GameObject CreatePlaneInScene(ARPlaneMesh arPlane)
        {
            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 = arPlane.id;

            PlacenotePlaneMeshRender ppmr = plane.GetComponent <PlacenotePlaneMeshRender> ();

            if (ppmr != null)
            {
                ppmr.InitializeMesh(arPlane);
            }

            return(UpdatePlaneWithAnchorTransform(plane, arPlane));
        }