Esempio n. 1
0
        private void trackTest(Touch touch)
        {
            List <ARHitResult> hitResults = ARFrame.HitTest(touch);

            foreach (ARHitResult singleHit in hitResults)
            {
                ARTrackable trackable = singleHit.GetTrackable();
                if ((trackable is ARPlane && ((ARPlane)trackable).IsPoseInPolygon(singleHit.HitPose)) ||
                    (trackable is ARPoint))
                {
                    ARAnchor anchor = singleHit.CreateAnchor();
                    ARDebug.LogInfo("GridARScript:trackTest anchor world position {0}", anchor.GetPose().position);
                    Vector3 screenPos = Camera.main.WorldToScreenPoint(anchor.GetPose().position);
                    ARDebug.LogInfo("GridARScript:trackTest anchor screen position {0}", screenPos);


                    if (m_touchIndex % 2 == 0)
                    {
                        m_touchBeginModel.GetComponent <disToolLogoVisualizer>().setAnchor(anchor);

                        var script = m_grid.GetComponent <GridARScpript>();
                        if (script)
                        {
                            script.setBeginAnchor(anchor);
                        }
                    }
                    else
                    {
                        m_touchEndModel.GetComponent <disToolLogoVisualizer>().setAnchor(anchor);
                    }
                    ++m_touchIndex;
                    break;
                }
            }
        }
Esempio n. 2
0
        private void BuildHWDatabase(string cliBinaryPath, out string error)
        {
            string output;

            error = null;
            var tempDirectoryPath = FileUtil.GetUniqueTempPathInProject();

            Directory.CreateDirectory(tempDirectoryPath);
            var rawDatabasePath = Path.Combine(tempDirectoryPath, "HwDatabase.bin");

            for (int i = 0; i < m_Images.Count; i++)
            {
                var imagePath = AssetDatabase.GetAssetPath(m_Images[i].Texture);
                ShellHelper.RunCommand(cliBinaryPath,
                                       string.Format("add-img --input_image_path {0} --input_database_path {1}",
                                                     imagePath, rawDatabasePath), out output, out error);
            }
            if (!string.IsNullOrEmpty(error))
            {
                ARDebug.LogInfo("RunCommand err" + error);
                return;
            }

            m_RawData = File.ReadAllBytes(rawDatabasePath);
        }
        private void _Connect()
        {
            ARDebug.LogInfo("_connect begin");
            const string ANDROID_CAMERA_PERMISSION_NAME = "android.permission.CAMERA";

            if (AndroidPermissionsRequest.IsPermissionGranted(ANDROID_CAMERA_PERMISSION_NAME))
            {
                _ConnectToService();
                return;
            }
            var permissionsArray = new string[] { ANDROID_CAMERA_PERMISSION_NAME };

            AndroidPermissionsRequest.RequestPermission(permissionsArray).ThenAction((requestResult) =>
            {
                if (requestResult.IsAllGranted)
                {
                    _ConnectToService();
                }
                else
                {
                    ARDebug.LogError("connection failed because a needed permission was rejected.");
                    errorMessage = "This app require camera permission";
                    Log();
                    Invoke("_DoQuit", 0.5f);
                    return;
                }
            });
        }
 public void OnApplicationPause(bool pause)
 {
     if (pause == true)
     {
         ARDebug.LogInfo("OnApplicationPause false, HelloARController _RemoveAnchorGameObject");
     }
 }
Esempio n. 5
0
        private void _CreateWorld(Touch touch)
        {
            List <ARHitResult> hitResults = ARFrame.HitTest(touch);

            ARDebug.LogInfo("_DrawARLogo hitResults count {0}", hitResults.Count);
            foreach (ARHitResult singleHit in hitResults)
            {
                ARTrackable trackable = singleHit.GetTrackable();
                ARDebug.LogInfo("_DrawARLogo GetTrackable {0}", singleHit.GetTrackable());
                if (trackable is ARPlane && ((ARPlane)trackable).IsPoseInPolygon(singleHit.HitPose) ||
                    trackable is ARPoint)
                {
                    ARAnchor anchor = singleHit.CreateAnchor();

                    Vector3 anchorPosition = anchor.GetPose().position;

                    if (world)
                    {
                        world.transform.position = anchorPosition;
                    }
                    else
                    {
                        world = Instantiate(worldPrefab, anchorPosition, Quaternion.identity);
                    }
                    break;
                }
            }
        }
Esempio n. 6
0
        public static bool FindCliBinaryPath(out string path)
        {
            string binaryName;

            if (m_ARAugImageDatabaseType == AREnginesType.HUAWEI_AR_ENGINE)
            {
                binaryName = UtilConstants.HWAugmentedImageCliBinaryName;
            }
            else
            {
                Debug.LogWarning("Wrong AREngine Type" + m_ARAugImageDatabaseType);
                path = string.Empty;
                return(false);
            }

            string[] cliBinaryGuid = AssetDatabase.FindAssets(binaryName);
            if (cliBinaryGuid.Length == 0)
            {
                ARDebug.LogInfo("Could not find required tool for building AugmentedImageDatabase: {0}. " +
                                "Was it removed from the SDK?", binaryName);
                path = string.Empty;
                return(false);
            }

            // Remove the '/Assets' from the project path since it will be added in the path below.
            string projectPath = Application.dataPath.Substring(0, Application.dataPath.Length - 6);

            path = Path.Combine(projectPath, AssetDatabase.GUIDToAssetPath(cliBinaryGuid[0]));
            return(!string.IsNullOrEmpty(path));
        }
Esempio n. 7
0
        public List <ARAugmentedImageDatabaseEntry> GetDirtyQualityEntries()
        {
            var    dirtyEntries = new List <ARAugmentedImageDatabaseEntry>();
            string cliBinaryPath;

            if (!FindCliBinaryPath(out cliBinaryPath))
            {
                return(dirtyEntries);
            }

            string currentCliVersion;
            {
                string error;
#if !UNITY_EDITOR_WIN
                string output;
                ShellHelper.RunCommand("chmod", "+x " + cliBinaryPath, out output, out error);
                if (!string.IsNullOrEmpty(error))
                {
                    Debug.LogWarning(error);
                    return(dirtyEntries);
                }
#endif
                ShellHelper.RunCommand(cliBinaryPath, "version", out currentCliVersion, out error);
                if (!string.IsNullOrEmpty(error))
                {
                    ARDebug.LogInfo(error);
                    return(dirtyEntries);
                }
            }

            bool cliUpdated = m_CliVersion != currentCliVersion;
            // When CLI is updated, mark all entries dirty.
            if (cliUpdated)
            {
                for (int i = 0; i < m_Images.Count; ++i)
                {
                    ARAugmentedImageDatabaseEntry updatedImage = m_Images[i];
                    updatedImage.Quality = string.Empty;
                    m_Images[i]          = updatedImage;
                }

                m_CliVersion = currentCliVersion;
                EditorUtility.SetDirty(this);
            }

            for (int i = 0; i < m_Images.Count; ++i)
            {
                if (!string.IsNullOrEmpty(m_Images[i].Quality))
                {
                    continue;
                }

                dirtyEntries.Add(m_Images[i]);
            }

            return(dirtyEntries);
        }
Esempio n. 8
0
    public void HandleTouch_Single(GameObject prefab)
    {
        Session.SetHitTestMode(ApiHitTestMode.PolygonPersistence);

        if (Input.touchCount == 0)
        {
            return;
        }

        if (Input.touches[0].phase == TouchPhase.Began)
        {
            if (EventSystem.current.IsPointerOverGameObject(Input.touches[0].fingerId) == false)
            {
                m_bOverGameObj = false;
            }
            else
            {
                m_bOverGameObj = true;
            }
        }

        if (slamController == null || Frame.TrackingState != TrackingState.Tracking)
        {
            return;
        }

        ARDebug.LogInfo("bPlaceModel" + bPlaceModel);
        ARDebug.LogInfo("HandleTouch_Single:IsPointerOverGameObject:" + m_bOverGameObj);

        TrackableHit      hit;
        TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinBounds | TrackableHitFlags.PlaneWithinPolygon;

        if (m_bOverGameObj == false && Session.Raycast(Input.touches[0].position.x, Input.touches[0].position.y, raycastFilter, out hit))
        {
            ARDebug.LogInfo("Raycast:" + Input.touches[0].position.x + "," + Input.touches[0].position.y);

            if (bPlaceModel)
            {
                m_ModelObj = MonoBehaviour.Instantiate(prefab, hit.Pose.position, hit.Pose.rotation);

                // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical
                // world evolves.
                //Anchor anchor = hit.Trackable.CreateAnchor(hit.Pose);
                //m_AnchorObj = anchor.gameObject;
                m_AnchorObj = new GameObject("anchor");

                // Make Andy model a child of the anchor.
                m_ModelObj.transform.parent = m_AnchorObj.transform;
                m_ModelObj.tag   = "ARObj";
                m_ModelObj.layer = 10;

                bPlaceModel = false;
            }

            m_ModelObj.transform.position = hit.Pose.position;
        }
    }
        private void _DrawARLogo(Touch touch)
        {
            List <ARHitResult> hitResults = ARFrame.HitTest(touch);
            ARHitResult        hitResult  = null;
            ARTrackable        trackable  = null;
            Boolean            hasHitFlag = false;

            ARDebug.LogInfo("_DrawARLogo hitResults count {0}", hitResults.Count);
            foreach (ARHitResult singleHit in hitResults)
            {
                trackable = singleHit.GetTrackable();
                ARDebug.LogInfo("_DrawARLogo GetTrackable {0}", singleHit.GetTrackable());
                if ((trackable is ARPlane && ((ARPlane)trackable).IsPoseInPolygon(singleHit.HitPose)) ||
                    (trackable is ARPoint))
                {
                    hitResult  = singleHit;
                    hasHitFlag = true;
                    if (trackable is ARPlane)
                    {
                        break;
                    }
                }
            }

            if (hasHitFlag != true)
            {
                ARDebug.LogInfo("_DrawARLogo can't hit!");
                return;
            }

            if (addedAnchors.Count > 16)
            {
                ARAnchor toRemove = addedAnchors[0];
                toRemove.Detach();
                addedAnchors.RemoveAt(0);
            }

            GameObject prefab;

            trackable = hitResult.GetTrackable();
            if (trackable is ARPlane)
            {
                prefab = arDiscoveryLogoPlanePrefabs;
            }
            else
            {
                prefab = arDiscoveryLogoPointPrefabs;
            }

/*
 *          ARAnchor anchor = hitResult.CreateAnchor();
 *          var logoObject = Instantiate(prefab, anchor.GetPose().position, anchor.GetPose().rotation);
 *          logoObject.GetComponent<ARDiscoveryLogoVisualizer>().Initialize(anchor);
 *          addedAnchors.Add(anchor);
 */
        }
Esempio n. 10
0
        private void renderMesh(Vector3 beginPos, Vector3 endPos)
        {
            var mat = gameObject.GetComponent <MeshRenderer>().material;

            float distance = Vector3.Distance(beginPos, endPos);

            float tilingW = distance / (float)mat.mainTexture.width;

            tilingW *= 100.0f;

            mat.SetTextureScale("_MainTex", new Vector2(tilingW, 1));


            Vector3 cro = Vector3.Cross(endPos - beginPos, new Vector3(0.0f, 1.0f, 0.0f));

            cro.Normalize();
            ARDebug.LogInfo("GridARScript: tilingW:{0},{1},{2},{3}", tilingW, beginPos, endPos, cro);
            cro *= mat.mainTexture.height;

            Vector3[] vertices = new Vector3[4];
            vertices [0] = beginPos;
            vertices [1] = endPos;
            vertices [2] = beginPos + cro;
            vertices [3] = endPos + cro;

            Vector2[] uv = new Vector2[vertices.Length];
            uv [0] = new Vector2(0, 0);
            uv [1] = new Vector2(1, 0);
            uv [2] = new Vector2(0, 1);
            uv [3] = new Vector2(1, 1);

            var mesh = GetComponent <MeshFilter>().mesh;

            if (null != mesh)
            {
                mesh.Clear();
            }

            //mesh.name = "Procedural Grid";

            mesh.vertices = vertices;
            mesh.uv       = uv;

            int[] triangles = new int[6];
            triangles [0] = 0;
            triangles [1] = 2;
            triangles [2] = 1;

            triangles [3] = 2;
            triangles [4] = 3;
            triangles [5] = 1;

            mesh.triangles = triangles;
        }
Esempio n. 11
0
 public void Update()
 {
     if (null == m_body)
     {
         return;
     }
     ARDebug.LogInfo("body tracking state {0}", m_body.GetTrackingState());
     _DonotShowPointAndConnections();
     if (m_body.GetTrackingState() == ARTrackable.TrackingState.STOPPED)
     {
         Destroy(gameObject);
     }
     else if (m_body.GetTrackingState() == ARTrackable.TrackingState.TRACKING)
     {
         _UpdateBody();
     }
 }
        private void BuildGoogleDatabase(string cliBinaryPath, out string error)
        {
            var tempDirectoryPath = FileUtil.GetUniqueTempPathInProject();

            Directory.CreateDirectory(tempDirectoryPath);
            var inputImagesFile = Path.Combine(tempDirectoryPath, "inputImages");

            string[] fileLines = new string[m_Images.Count];
            for (int i = 0; i < m_Images.Count; i++)
            {
                var           imagePath = AssetDatabase.GetAssetPath(m_Images[i].Texture);
                StringBuilder sb        = new StringBuilder();
                sb.Append(m_Images[i].Name).Append('|').Append(imagePath);
                if (m_Images[i].Width > 0)
                {
                    sb.Append('|').Append(m_Images[i].Width);
                }

                fileLines[i] = sb.ToString();
            }

            File.WriteAllLines(inputImagesFile, fileLines);
            var    rawDatabasePath = Path.Combine(tempDirectoryPath, "out_database");
            string output;

#if !UNITY_EDITOR_WIN
            ShellHelper.RunCommand("chmod", "+x " + cliBinaryPath, out output, out error);
            if (!string.IsNullOrEmpty(error))
            {
                Debug.LogWarning(error);
                return;
            }
#endif
            ShellHelper.RunCommand(cliBinaryPath,
                                   string.Format("build-db --input_image_list_path {0} --output_db_path {1}",
                                                 inputImagesFile, rawDatabasePath), out output, out error);
            if (!string.IsNullOrEmpty(error))
            {
                ARDebug.LogInfo("RunCommand err" + error);
                return;
            }

            m_RawData = File.ReadAllBytes(rawDatabasePath + ".imgdb");
        }
Esempio n. 13
0
        private void trackTest()
        {
            if (null == m_beginAnchor)
            {
                m_MeshRenderer.enabled = false;
                return;
            }


            switch (m_beginAnchor.GetTrackingState())
            {
            case ARTrackable.TrackingState.TRACKING:
                m_MeshRenderer.enabled = true;
                break;

            case ARTrackable.TrackingState.PAUSED:
                m_MeshRenderer.enabled = false;
                return;

            case ARTrackable.TrackingState.STOPPED:
            default:
                m_MeshRenderer.enabled = false;
                m_beginAnchor          = null;
                return;
            }

            List <ARHitResult> hitResults = ARFrame.HitTest(m_touchScreenPos.x, m_touchScreenPos.y);

            ARDebug.LogInfo("GridARScript:trackTest hitResults count {0}", hitResults.Count);
            foreach (ARHitResult singleHit in hitResults)
            {
                ARTrackable trackable = singleHit.GetTrackable();
                ARDebug.LogInfo("GridARScript:trackTest GetTrackable {0}", singleHit.GetTrackable());
                if ((trackable is ARPlane && ((ARPlane)trackable).IsPoseInPolygon(singleHit.HitPose)) ||
                    (trackable is ARPoint))
                {
                    ARAnchor anchor = singleHit.CreateAnchor();
                    //ARDebug.LogInfo("GridARScript:trackTest anchor world position {0}", anchor.GetPose().position);

                    renderMesh(m_beginAnchor.GetPose().position, anchor.GetPose().position);
                    break;
                }
            }
        }
Esempio n. 14
0
 public void OnApplicationPause(bool pause)
 {
     if (pause == true)
     {
         ARDebug.LogInfo("OnApplicationPause false, call session pause");
         if (m_SessionManager != null)
         {
             m_SessionManager.Pause();
         }
     }
     else
     {
         ARDebug.LogInfo("OnApplicationPause true, call session resume");
         if (m_SessionManager != null)
         {
             m_SessionManager.Resume(SessionConfig);
         }
     }
 }
Esempio n. 15
0
 public void Update()
 {
     sb.Remove(0, sb.Length);
     sb.Append("BodyAction: " + m_body.GetBodyAction() + "\n");
     if (null == m_body)
     {
         return;
     }
     ARDebug.LogInfo("body tracking state {0}", m_body.GetTrackingState());
     _DonotShowPointAndConnections();
     if (m_body.GetTrackingState() == ARTrackable.TrackingState.STOPPED)
     {
         Destroy(gameObject);
     }
     else if (m_body.GetTrackingState() == ARTrackable.TrackingState.TRACKING)
     {
         _UpdateBody();
     }
 }
Esempio n. 16
0
        /// <summary>
        /// The Unity Update method.
        /// </summary>
        public void Update()
        {
            if (Image == null || Image.GetTrackingState() != ARTrackable.TrackingState.TRACKING)
            {
                FrameLowerLeft.SetActive(false);
                FrameLowerRight.SetActive(false);
                FrameUpperLeft.SetActive(false);
                FrameUpperRight.SetActive(false);
                return;
            }

            float halfWidth  = Image.GetExtentX() / 2;
            float halfHeight = Image.GetExtentZ() / 2;

            if (AREnginesSelector.Instance.GetCreatedEngine() == AREnginesType.HUAWEI_AR_ENGINE)
            {
                //arengine GetExtentX&GetExtentZ() isn't changing when camera moving,so using Image.GetCenterPose to move FrameLowerLeft etc.
                Quaternion poseRotation = Image.GetCenterPose().rotation;
                FrameLowerLeft.transform.position  = poseRotation * ((halfWidth * Vector3.left) + (halfHeight * Vector3.back)) + Image.GetCenterPose().position;
                FrameLowerLeft.transform.rotation  = poseRotation;
                FrameLowerRight.transform.position = poseRotation * ((halfWidth * Vector3.right) + (halfHeight * Vector3.back)) + Image.GetCenterPose().position;
                FrameLowerRight.transform.rotation = poseRotation;
                FrameUpperLeft.transform.position  = poseRotation * ((halfWidth * Vector3.left) + (halfHeight * Vector3.forward)) + Image.GetCenterPose().position;
                FrameUpperLeft.transform.rotation  = poseRotation;
                FrameUpperRight.transform.position = poseRotation * ((halfWidth * Vector3.right) + (halfHeight * Vector3.forward)) + Image.GetCenterPose().position;
                FrameUpperRight.transform.rotation = poseRotation;
            }
            else
            {
                //arcore GetExtentX&GetExtentZ() is changing when camera moving,so using halfWidth&halfHeight to move FrameLowerLeft etc.
                FrameLowerLeft.transform.localPosition  = (halfWidth * Vector3.left) + (halfHeight * Vector3.back);
                FrameLowerRight.transform.localPosition = (halfWidth * Vector3.right) + (halfHeight * Vector3.back);
                FrameUpperLeft.transform.localPosition  = (halfWidth * Vector3.left) + (halfHeight * Vector3.forward);
                FrameUpperRight.transform.localPosition = (halfWidth * Vector3.right) + (halfHeight * Vector3.forward);
            }
            ARDebug.LogInfo("image position {0} rotation {1} width {2} height {3}", Image.GetCenterPose().position,
                            Image.GetCenterPose().rotation, halfWidth, halfHeight);

            FrameLowerLeft.SetActive(true);
            FrameLowerRight.SetActive(true);
            FrameUpperLeft.SetActive(true);
            FrameUpperRight.SetActive(true);
        }
        /**
         * \if english
         * Get parameters map.
         * \else
         * 获取当前的面部参数。
         * \endif
         */
        public Dictionary <ARParameterType, float> GetParameters()
        {
            ARDebug.LogInfo("get Parameter Begin", 1);

            float[] var1 = m_ndkSession.TrackableAdapter.GetParameterValueArray(m_trackableHandle);
            int[]   var2 = m_ndkSession.TrackableAdapter.GetParameterTypeArray(m_trackableHandle);

            if (var1.Length != var2.Length)
            {
                throw new ARFatalException("Unexpected array length!");
            }
            else
            {
                Dictionary <ARParameterType, float> var3 = new Dictionary <ARParameterType, float>(60);
                for (int var4 = 0; var4 < var2.Length; ++var4)
                {
                    var3.Add((ARParameterType)var2[var4], var1[var4]);
                }
                return(var3);
            }
        }
Esempio n. 18
0
        private void _DrawARLogo(Touch touch)
        {
            List <ARHitResult> hitResults = ARFrame.HitTest(touch);

            ARDebug.LogInfo("_DrawARLogo hitResults count {0}", hitResults.Count);
            foreach (ARHitResult singleHit in hitResults)
            {
                ARTrackable trackable = singleHit.GetTrackable();
                ARDebug.LogInfo("_DrawARLogo GetTrackable {0}", singleHit.GetTrackable());
                if ((trackable is ARPlane && ((ARPlane)trackable).IsPoseInPolygon(singleHit.HitPose)) ||
                    (trackable is ARPoint))
                {
                    GameObject prefab;
                    if (trackable is ARPlane)
                    {
                        prefab = arDiscoveryLogoPlanePrefabs;
                    }
                    else
                    {
                        prefab = arDiscoveryLogoPointPrefabs;
                    }

                    if (addedAnchors.Count > 16)
                    {
                        ARAnchor toRemove = addedAnchors[0];
                        toRemove.Detach();
                        addedAnchors.RemoveAt(0);
                    }

                    ARAnchor anchor     = singleHit.CreateAnchor();
                    var      logoObject = Instantiate(prefab, anchor.GetPose().position, anchor.GetPose().rotation);
                    logoObject.GetComponent <ARDiscoveryLogoVisualizer>().Initialize(anchor);
                    addedAnchors.Add(anchor);
                    break;
                }
            }
        }
Esempio n. 19
0
        public void BuildIfNeeded(out string error)
        {
            error = "";
            if (!m_IsRawDataDirty)
            {
                return;
            }

            string cliBinaryPath;

            if (!FindCliBinaryPath(out cliBinaryPath))
            {
                return;
            }

            if (m_ARAugImageDatabaseType == AREnginesType.HUAWEI_AR_ENGINE)
            {
                BuildHWDatabase(cliBinaryPath, out error);
            }
            else
            {
                ARDebug.LogWarning("Wrong AREngine Type" + m_ARAugImageDatabaseType);
                return;
            }

            m_IsRawDataDirty = false;
            EditorUtility.SetDirty(this);

            // Force a save to make certain build process will get updated asset.
            AssetDatabase.SaveAssets();

            const int BYTES_IN_KBYTE = 1024;

            // TODO:: Remove this log when all errors/warnings are moved to stderr for CLI tool.
            ARDebug.LogInfo("Built AugmentedImageDatabase '{0}' ({1} Images, {2} KBytes)", name, m_Images.Count,
                            m_RawData.Length / BYTES_IN_KBYTE);
        }
Esempio n. 20
0
        public void HandleTouch_Single()
        {
            if (currPlaceType == EPlaceType.Place_None)
            {
                return;
            }
            Session.SetHitTestMode(ApiHitTestMode.PolygonPersistence);

            if (Input.touchCount == 0)
            {
                return;
            }

            if (Input.touches[0].phase == TouchPhase.Began)
            {
                if (EventSystem.current.IsPointerOverGameObject(Input.touches[0].fingerId) == false)
                {
                    m_bOverGameObj = false;
                }
                else
                {
                    m_bOverGameObj = true;
                    TouchOnSceneObj(EventSystem.current.currentSelectedGameObject);
                }
            }

            if (slamController == null || Frame.TrackingState != TrackingState.Tracking)
            {
                return;
            }

            ARDebug.LogInfo("bPlaceModel" + bPlaceModel);
            ARDebug.LogInfo("HandleTouch_Single:IsPointerOverGameObject:" + m_bOverGameObj);

            TrackableHit      hit;
            TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinBounds | TrackableHitFlags.PlaneWithinPolygon;

            if (m_bOverGameObj == false && Session.Raycast(Input.touches[0].position.x, Input.touches[0].position.y, raycastFilter, out hit))
            {
                //DZ_DebugConsole.Log("Raycast:" + Input.touches[0].position.x + "," + Input.touches[0].position.y);
                ARDebug.LogInfo("Raycast:" + Input.touches[0].position.x + "," + Input.touches[0].position.y);

                if (currPlaceType == EPlaceType.Place_Anc)
                {
                    if (bPlaceModel)
                    {
                        TouchHandleCreatCloudAncObj(hit);
                        bPlaceModel = false;
                    }
                }
                else
                {
                    if (bPlaceModel)
                    {
                        TouchHandleCreateMode(hit.Pose.position, hit.Pose.rotation);
                    }
                    else if (selectedObj_ != null)
                    {
                        selectedObj_.transform.position = hit.Pose.position;
                    }
                }
            }
        }
Esempio n. 21
0
        public void Update()
        {
            // Exit the app when the 'back' button is pressed.
            if (Input.GetKey(KeyCode.Escape))
            {
                Application.Quit();
            }

            // Check that motion tracking is tracking.
            if (ARFrame.GetTrackingState() != ARTrackable.TrackingState.TRACKING)
            {
                ARDebug.LogInfo("GetTrackingState no tracing return <<");
                return;
            }

            // Get updated augmented images for this frame.
            ARFrame.GetTrackables <ARAugmentedImage>(m_TempAugmentedImages, ARTrackableQueryFilter.UPDATED);
            ARDebug.LogInfo("m_TempAugmentedImages size {0}", m_TempAugmentedImages.Count);

            // Create visualizers and anchors for updated augmented images that are tracking and do not previously
            // have a visualizer. Remove visualizers for stopped images.
            foreach (var image in m_TempAugmentedImages)
            {
                AugmentedImageVisualizer visualizer = null;
                m_Visualizers.TryGetValue(image.GetDataBaseIndex(), out visualizer);

                ARDebug.LogInfo("GetTrackingState {0}", image.GetTrackingState());
                if (image.GetTrackingState() == ARTrackable.TrackingState.TRACKING && visualizer != null)
                {
                    visualizer.Image = image;
                    ARDebug.LogInfo("update position {0} rotation {1}", image.GetCenterPose().position, image.GetCenterPose().rotation);
                }

                if (image.GetTrackingState() == ARTrackable.TrackingState.TRACKING && visualizer == null)
                {
                    // Create an anchor to ensure that ARCore keeps tracking this augmented image.
                    //ARAnchor anchor = image.CreateAnchor(image.GetCenterPose());
                    //visualizer = (AugmentedImageVisualizer)Instantiate(AugmentedImageVisualizerPrefab, anchor.GetPose().position, anchor.GetPose().rotation);
                    visualizer = (AugmentedImageVisualizer)Instantiate(AugmentedImageVisualizerPrefab, image.GetCenterPose().position, image.GetCenterPose().rotation);
                    ARDebug.LogInfo("create position {0} rotation {1}", image.GetCenterPose().position, image.GetCenterPose().rotation);
                    visualizer.Image = image;
                    m_Visualizers.Add(image.GetDataBaseIndex(), visualizer);
                }
                else if (image.GetTrackingState() == ARTrackable.TrackingState.STOPPED && visualizer != null)
                {
                    m_Visualizers.Remove(image.GetDataBaseIndex());
                    GameObject.Destroy(visualizer.gameObject);
                }
            }

            // Show the fit-to-scan overlay if there are no images that are Tracking.
            foreach (var visualizer in m_Visualizers.Values)
            {
                if (visualizer.Image.GetTrackingState() == ARTrackable.TrackingState.TRACKING)
                {
                    FitToScanOverlay.SetActive(false);
                    return;
                }
            }

            //FitToScanOverlay.SetActive(true);
        }
Esempio n. 22
0
 public void setBeginAnchor(ARAnchor ch)
 {
     m_beginAnchor    = ch;
     m_touchScreenPos = Camera.main.WorldToScreenPoint(ch.GetPose().position);
     ARDebug.LogInfo("GridARScript:m_touchScreenPos {0}", m_touchScreenPos);
 }