示例#1
0
        private void AnnotateButtonClick()
        {
            // TODO: check if tracking

            byte[] png;
            if (DebugImage != null)
            {
                png = DebugImage.EncodeToPNG();
            }
            else
            {
                png = ArUtils.GetCameraImage(ARInterface.GetInterface());
                if (png == null)
                {
                    return;
                }
            }

            var imageModel = new ImageModel(png);

            imageModel.Save();
            var annotationModel =
                new AnnotationModel(
                    new Pose(Camera.main.transform.position, Camera.main.transform.rotation),
                    Camera.main.aspect,
                    imageModel);

            annotationModel.Save();
            AddAnnotation(annotationModel);
        }
示例#2
0
    void Start()
    {
        Vector3 objectSize = ArUtils.GetObjectSizeByMeshFilter(FollowObject);

        followObjectOffset = new Vector3(0, objectSize.y / 2 + .1f, 0);
        transform.position = FollowObject.transform.position + followObjectOffset;
    }
示例#3
0
 /// <summary>
 /// Inits the model by latlngs.
 /// </summary>
 /// <param name="tasks"></param>
 /// <param name="deviceOfUserHead">If set to <c>true</c> use device orientation otherwise use user heading.</param>
 void InitModelByLatLngs(List <Task> tasks, bool deviceOfUserHead)
 {
     foreach (var task in tasks)
     {
         Vector3 position = _abstractMap.GeoToWorldPosition(task.TaskLocation);
         print(position);
         Object model = ArUtils.LoadModel("Model/" + task.TaskModelName);
         print(model);
         // 地图上显示的物体
         var mapObject = Instantiate(model, position, task.TaskModelRotation) as GameObject;
         mapObject.layer = 0;
         // ar界面显示的物体,两者为模型相同位置不同
         var arObject = CreateArModel(model, position, Quaternion.Euler(new Vector3()));
         ArModelEventController amec = arObject.ArGameObject.AddComponent <ArModelEventController>();
         amec.SetCamera(firstPersonCamera);
         amec.onModelClick = () =>
         {
             print("click model");
             dialogueBox.SetActive(!dialogueBox.activeSelf);
             if (dialogueBox.activeSelf)
             {
                 dialogueBox.GetComponent <DialogueBoxController>().SetTaskDesc(task.TaskDesc);
             }
         };
         //MessageBubblesShow mbs = arObject.ARGameObject.AddComponent<MessageBubblesShow>();
         //ModelIndicator mi = arObject.ArGameObject.AddComponent<ModelIndicator>();
         //mi.SetCameraObject(FirstPersonCamera);
         //mbs.SetTaskDesc(task.TaskDesc);
         //mbs.SetCamera(FirstPersonCamera);
         AdjustArModelByDeviceOrientation(arObject.ArGameObject, deviceOfUserHead);
         _showedArModels.Add(arObject);
     }
 }
示例#4
0
        // Update is called once per frame
        void Update()
        {
            // 返回主页面
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                SceneManager.LoadScene("MainPage");
            }

            Vector3 position = _abstractMap.GeoToWorldPosition(TaskLab.Get().GetTaskList()[0].TaskLocation);

            if (position != Vector3.zero && !_hasLoadModel)
            {
                var locationProvider = LocationProviderFactory.Instance.DefaultLocationProvider;
                TaskLab.Get().SetCurrentLatlng(locationProvider.CurrentLocation.LatitudeLongitude);
                _taskList = TaskLab.Get().GetTaskListIn(200);
                //TaskList = TaskLab.get().GetTaskList();
                text.text = "abstractMap: " + _abstractMap + "\n";
                foreach (var task in _taskList)
                {
                    _model   = ArUtils.LoadModel("Model/" + task.TaskModelName);
                    position = _abstractMap.GeoToWorldPosition(task.TaskLocation);
                    var message = text.text;
                    message  += "name:" + task.TaskModelName + "\n";
                    message  += "location:" + task.TaskLocation + "\n";
                    message  += "position:" + position + "\n";
                    text.text = message;
                    Instantiate(_model, position, task.TaskModelRotation);
                }
                _hasLoadModel = true;
            }
        }
示例#5
0
        // Update is called once per frame
        void Update()
        {
            if (_userAccount != "" && !_hasQueryUser)
            {
                System.Threading.Tasks.Task
                .Run(() =>
                {
                    print(_userAccount);
//                            CallAndroidMethod.Toast(_userAccount);
                    UserLab.CurrentUser = UserLab.GetUser(_userAccount);
                    _hasGetUser         = true;
                });
                _hasQueryUser = true;
            }

            if (_hasGetUser)
            {
                print(UserLab.CurrentUser.UserName);
                CharacterInfoController cInfoController = characterInfo.GetComponent <CharacterInfoController>();
                cInfoController.UpdateUserMessage(UserLab.CurrentUser);
                _hasGetUser = false;
            }

            // 如果控制状态详细信息面板已经显示,在点击其他地方后让其消失
            if (Input.GetMouseButtonDown(0) && characterDetailInfo.activeSelf && !ArUtils.IsPointerOverUiObject())
            {
                characterDetailInfo.SetActive(false);
            }

            if (Input.GetKey(KeyCode.Escape))
            {
                Application.Quit();
            }
        }
        // Allows you to pan the map around
        void PanMap()
        {
            if (!Input.GetMouseButton(0))
            {
                _isDragging = false;
                return;
            }

            if (!_isDragging &&
                !RectTransformUtility.RectangleContainsScreenPoint(MapView, Input.mousePosition, null))
            {
                return;
            }

            var mousePosScreen = (Vector3)ArUtils.GetRectMousePosition(MapView);

            mousePosScreen.z = _mapCamera.transform.position.y;
            var mousePosition = _mapCamera.ViewportToWorldPoint(mousePosScreen);

            if (!_isDragging)
            {
                _isDragging          = true;
                _originMousePosition = mousePosition;
                return;
            }

            var delta = mousePosition - _originMousePosition;

            _mapCamera.transform.position -= delta;
            _originMousePosition           = mousePosition - delta;

            // inertia effect
            _mapCamera.GetComponent <Rigidbody>().velocity = -delta / Time.deltaTime;
        }
示例#7
0
    // Start is called before the first frame update
    void Start()
    {
        msgText = GameObject.Find("Text").GetComponent <Text>();
        Vector3 objectSize = ArUtils.GetObjectSizeByMeshFilter(FollowObject);

        followObjectOffset = new Vector3(0, objectSize.y / 2 + .1f, 0);
        transform.position = FollowObject.transform.position + followObjectOffset;
    }
示例#8
0
    // Start is called before the first frame update
    void Start()
    {
        Object obj = ArUtils.LoadModel("Model/Array");

        Array = Instantiate(obj, GameObject.Find("Canvas").transform) as GameObject;
        Array.transform.localScale = Vector3.one * .5f;
        arrayText = Array.GetComponentInChildren <Text>();
    }
示例#9
0
        // Update is called once per frame
        void Update()
        {
            Ray ray = cam.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out var hitInfo))
            {
                // 如果点击物体
                if (!ArUtils.IsPointerOverUiObject() && Input.GetMouseButtonDown(0) && hitInfo.transform.name == transform.name)
                {
                    onModelClick?.Invoke();
                }
            }
        }
示例#10
0
        void Start()
        {
//            CallAndroidMethod.StartLoginActivity();

            moreInfo.GetComponent <PointerClickEventTrigger>()
            .onPointerClick
            .AddListener((() =>
            {
                CallAndroidMethod.StartFeedbackActivity();
                print("more information");
            }));

            characterDetailInfo.SetActive(false);
            LongPressEventTrigger characterInfoLongPress = characterInfo.GetComponent <LongPressEventTrigger>();

            characterInfoLongPress.onLongPress.AddListener(() =>
            {
                if (characterDetailInfo.activeSelf == false)
                {
                    characterDetailInfo.SetActive(true);
                    CharacterDetailInfoController infoController =
                        characterDetailInfo.GetComponent <CharacterDetailInfoController>();
                    infoController.UpdateUserDetailMessage(UserLab.CurrentUser);
                }
                else
                {
                    characterDetailInfo.SetActive(false);
                }
            });

            DoubleClickEventTrigger roleDoubleClick = role.GetComponent <DoubleClickEventTrigger>();

            roleDoubleClick.SetCamera(Camera.main);
            roleDoubleClick
            .onDoubleClick
            .AddListener(() =>
            {
                if (!ArUtils.IsPointerOverUiObject())
                {
                    SceneManager.LoadScene("ModelScanScene");
                }
            });
            mapPanel.GetComponent <OnMapButtonDrag>().dragEndEvent.AddListener(CallAndroidMethod.StartMapActivity);
            buttonTask.onClick.AddListener(CallAndroidMethod.StartTaskActivity);
            buttonCourse.onClick.AddListener(CallAndroidMethod.StartCourseActivity);
            buttonPut.onClick.AddListener(() => { SceneManager.LoadScene("ModelPutScene"); });
        }
示例#11
0
        /// <summary>
        /// 根据Resouse目录下的图片初始化背包中物品
        /// </summary>
        /// <param name="imagePath">Image path.</param>
        void CreateCell(string imagePath)
        {
            GameObject go = new GameObject(imagePath);

            go.AddComponent <Image>();
            BagItem bagItem = go.AddComponent <BagItem>();

            bagItem.SetImage(imagePath);
            bagItem.SetMyPointerClick(() =>
            {
                if (_putArObjects.Count >= 1)
                {
                    print("只可放置一个模型");
                    return;
                }
                Object model = Resources.Load("Model/" + imagePath.Split('/')[1]);
                print("bagItem click:" + gameObject);
                print("Model/" + imagePath.Split('/')[1]);
                print("Model:" + model);
                var modelInfo = ArController.CreateArModel(model, new Vector3(0, 0, 2), Quaternion.Euler(new Vector3()));
                Vector3 size  = ArUtils.GetObjectSizeByCollider(modelInfo.ArGameObject);
                modelInfo.ArGameObject.transform.position = new Vector3(0, -size.y / 2, 2 * size.z);
                // 脚本初始化都为false 当用户选择某个模型后添加对此模型的控制
                RotateAndUpDown raud           = modelInfo.ArGameObject.AddComponent <RotateAndUpDown>();
                raud.enabled                   = false;
                TransfromAroundAndDistance tad = modelInfo.ArGameObject.AddComponent <TransfromAroundAndDistance>();
                tad.SetCamera(_firstPersonCamera.GetComponent <Camera>());
                tad.enabled = false;
                DoubleClickChangeStatus dccs = modelInfo.ArGameObject.AddComponent <DoubleClickChangeStatus>();
                dccs.SetCamera(_firstPersonCamera.GetComponent <Camera>());
                dccs.enabled = false;

                // 设置模型附加的脚本信息
                modelInfo.RotateAndUpDown            = raud;
                modelInfo.TransfromAroundAndDistance = tad;
                modelInfo.DoubleClickChangeStatus    = dccs;

                modelInfo.ArGameObject.transform.RotateAround(_firstPersonCamera.transform.position, Vector3.up, _firstPersonCamera.transform.rotation.eulerAngles.y);
                // 更改名字作为每个物体不同的标识
                modelInfo.ArGameObject.name = $"{modelInfo.ArGameObject.name.Split('(')[0]}({modelId++})";

                _putArObjects.Add(modelInfo);
                onMyItemClick?.Invoke(modelInfo.ArGameObject, _putArObjects);
            });
            go.transform.SetParent(transform, false);
        }
        // Use this for initialization
        void Start()
        {
            _gameClient = ClientLab.GetGameClient();

            chatPanel.SetActive(false);

            friendBtn.onClick.AddListener(() =>
            {
                // 此处显示好友列表, 并将当前接收的消息传入android界面
                CallAndroidMethod.StartFriendListDialog();
                // chatPanel.SetActive(true);
            });
            squareBtn.onClick.AddListener(() =>
            {
                print(ArUtils.GetObjectSizeByCollider(role));
                Vector3 chatBubblePosition =
                    Camera.main
                    .WorldToScreenPoint(
                        role.transform.position +
                        new Vector3(
                            0,
                            ArUtils.GetObjectSizeByCollider(role).y / 2,
                            0)) +
                    new Vector3(0, 100, 0);
                var chatBubble = Instantiate(chatBubblePrefab, chatBubblePosition, Quaternion.Euler(new Vector3())) as GameObject;
                chatBubble.transform.SetParent(GameObject.Find("Canvas").transform);
                BubbleController bubbleController = chatBubble.GetComponent <BubbleController>();
                bubbleController.SetMessage("hello\nhello\bhello");
                bubbleController.SetTimeDelay(1);
            });
            quietImage.GetComponent <PointerClickEventTrigger>()
            .onPointerClick
            .AddListener(() =>
            {
                chatPanel.SetActive(false);
            });

            submitButton.onClick.AddListener(() =>
            {
                if (chatInput.text != "")
                {
                    _gameClient.ChatToUser(otherName, chatInput.text);
                }
            });
        }
    // Update is called once per frame
    void Update()
    {
        // Send pose update
        _deltaTimePose += Time.unscaledDeltaTime;
        if (_deltaTimePose >= 1.0 / 5)
        {
            if (ARInterface.GetInterface().TryGetPose(ref _pose))
            {
                SendData("pose", _pose);

                _deltaTimePose = 0;
            }
        }

        // Send point cloud update
        _deltaTimePointCloud += Time.unscaledDeltaTime;
        if (_deltaTimePointCloud >= 1.0 / 5)
        {
            if (ARInterface.GetInterface().TryGetPointCloud(ref _pointCloud))
            {
                var data = _pointCloud.points.ToArray();

                SendData("pointcloud", data);

                _deltaTimePointCloud = 0;
            }
        }

        // Send image update
        _deltaTimeImage += Time.unscaledDeltaTime;
        if (_sendImage && _deltaTimeImage >= 1.0)
        {
            var png = ArUtils.GetCameraImage(ARInterface.GetInterface());

            if (png != null)
            {
                SendData("image", png);

                _deltaTimeImage = 0;
            }
        }
    }
示例#14
0
    private void AnnotateButtonClick()
    {
        Debug.Log("attempting raycast");
        var          castPosition = FocusDot.transform.position;
        TrackableHit hit;

//		if (ARInterface.GetInterface().TryRaycast(castPosition.x, castPosition.y, ref anchorPoint))
        if (Frame.Raycast(castPosition.x, castPosition.y, TrackableHitFlags.FeaturePoint, out hit))
        {
            Debug.Log("raycast success");
//			var obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
//			obj.transform.localScale = new Vector3(0.03f, 0.03f, 0.03f);
//			obj.transform.position = anchorPoint.position;
//			obj.transform.rotation = anchorPoint.rotation;
//			anchors.Add(anchorPoint.id, obj.transform);

            var png = ArUtils.GetCameraImage(ARInterface.GetInterface());

            if (png != null)
            {
                if (ARInterface.GetInterface().TryGetPose(ref _pose))
                {
                    var anchor     = hit.Trackable.CreateAnchor(hit.Pose);
                    var annotation = new TrackedAnnotation(png, Camera.main.aspect, _pose, anchor);
                    _annotations.Add(annotation);
                    annotation.Show();

                    ObjToAnnotation.Add(annotation._obj, annotation);

                    setCurrentAnnotation(annotation);

//					SocketConnection.Instance.SendData("annotate", annotation.ToJson());
                }
            }
        }
        else
        {
            Debug.Log("raycast unsuccessful");
        }
    }
示例#15
0
    // Start is called before the first frame update
    void Start()
    {
        UnityEngine.Object messageBubblesModel = ArUtils.LoadModel("Model/MessageBubbles");
        var messageBubbles = Instantiate(messageBubblesModel, Vector3.zero, Quaternion.Euler(Vector3.zero)) as GameObject;

        MessageBubbles = messageBubbles;

        MessageBubbles.transform.parent = GameObject.Find("Canvas").transform;
        //MessageBubbles.GetComponent<RectTransform>()
        //.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, ARUtils.GetObjectSize(gameObject).x*100); ;
        print(" ARUtils.GetObjectSize(gameObject).x:" + ArUtils.GetObjectSizeByMeshFilter(gameObject).x);
        words = SplitSentence(taskDesc);
        MessageBubbles.SetActive(false);
        Button[] buttons = MessageBubbles.GetComponentsInChildren <Button>();
        previousSentence = buttons[0];
        nextSentence     = buttons[1];
        showText         = MessageBubbles.GetComponentInChildren <Text>();
        previousSentence.onClick.AddListener(() =>
        {
            if (index <= 0)
            {
                return;
            }
            index--;
            showText.text = words[index];
        });

        nextSentence.onClick.AddListener(() =>
        {
            if (index >= words.Length - 1)
            {
                return;
            }
            index++;
            showText.text = words[index];
        });
    }
示例#16
0
    // Update is called once per frame
    void Update()
    {
        if (transform.position.z < 0 && GetComponent <MeshRenderer>().isVisible == false)
        {
            MessageBubbles.SetActive(false);
        }

        Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;

        if (Physics.Raycast(ray, out hitInfo))
        {
            // 如果点击物体
            if (Input.GetMouseButtonDown(0) && hitInfo.transform.name == transform.name)
            {
                MessageBubbles.SetActive(!MessageBubbles.activeSelf);
                showText.text = words[index];
            }
        }
        if (MessageBubbles.activeSelf)
        {
            float distance = Vector3.Distance(transform.position, cam.transform.position);
            print(distance);
            // 消息框随模型移动缩放
            float   scale       = 20 / distance;
            Vector3 screenPoint = cam.WorldToScreenPoint(transform.position + new Vector3(0, ArUtils.GetObjectSizeByMeshFilter(gameObject).y, 0));
            MessageBubbles.transform.position   = screenPoint;
            MessageBubbles.transform.localScale = Vector3.one * scale;
        }
    }
示例#17
0
    // Update is called once per frame
    void Update()
    {
        var          castPosition = FocusDot.transform.position;
        TrackableHit hit;
        var          success = Frame.Raycast(castPosition.x, castPosition.y, TrackableHitFlags.FeaturePoint, out hit);

        FocusDot.GetComponent <Image>().color = success ? Color.green : Color.red;

        if (Input.GetMouseButtonDown(0))
        {
            var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit rayHit;
            if (Physics.Raycast(ray, out rayHit))
            {
                if (ObjToAnnotation.ContainsKey(rayHit.collider.gameObject))
                {
                    setCurrentAnnotation(ObjToAnnotation[rayHit.collider.gameObject]);
                }
            }
        }

        if (Input.GetMouseButton(0))
        {
            var previewRect = LargePreviewImage.GetComponent <RectTransform>();
            var mapRect     = LargeMap.GetComponent <RectTransform>();

            if (_state == State.Preview)
            {
                if (RectTransformUtility.RectangleContainsScreenPoint(previewRect, Input.mousePosition))
                {
                    var point = ArUtils.GetRectMousePosition(previewRect);
                }
            }
            else if (_state == State.Map)
            {
                if (RectTransformUtility.RectangleContainsScreenPoint(mapRect, Input.mousePosition))
                {
                    var point = ArUtils.GetRectMousePosition(mapRect);
                    Debug.Log(point);
                }
            }
        }

        // Send pose update
//		_deltaTimePose += Time.unscaledDeltaTime;
//		if (_deltaTimePose >= 1.0/10)
//		{
//			if (ARInterface.GetInterface().TryGetPose(ref _pose))
//			{
//				SocketConnection.Instance.SendData("pose", _pose);
//
//				_deltaTimePose = 0;
//			}
//		}

        // Send point cloud update
//		_deltaTimePointCloud += Time.unscaledDeltaTime;
//		if (_deltaTimePointCloud >= 1.0/10)
//		{
//			if (ARInterface.GetInterface().TryGetPointCloud(ref _pointCloud))
//			{
//				var data = _pointCloud.points.ToArray();
//
//				SocketConnection.Instance.SendData("pointcloud", data);
//
//				_deltaTimePointCloud = 0;
//			}
//		}
    }
示例#18
0
        // Update is called once per frame
        void Update()
        {
            // 按下鼠标时,如果焦点不在模型上则返回
            // 如果初始时在模型上,则之后划出模型仍然当作滑动成功
            if (Input.GetMouseButtonDown(0))
            {
                //如果非滑动模型,则返回
                Ray ray = cam.ScreenPointToRay(Input.mousePosition);
                if (ArUtils.IsPointerOverUiObject())
                {
                    return;
                }
                if (Physics.Raycast(ray, out RaycastHit hitInfo))
                {
                    var    hitParent = hitInfo.transform.parent;
                    string hitName   = hitParent == null
                        ? hitInfo.transform.name
                        : hitParent.name;

                    var    goParent = transform.parent;
                    string goName   = goParent == null
                        ? gameObject.transform.name
                        : goParent.name;

                    if (hitName != goName)
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
                print("mouse down");
                _startPos = Input.mousePosition;
                _isClick  = true;
                _hasSlide = false;
            }

            if (Input.GetMouseButtonUp(0))
            {
                print("mouse up");
                _endPos  = Input.mousePosition;
                _isClick = false;
            }

            // 如果还未松手且已经滑动完成,则返回
            if (_isClick || _hasSlide)
            {
                return;
            }

            Vector3 v = _endPos - _startPos;

            // 上下滑动,返回
            if (Mathf.Abs(v.y) > Mathf.Abs(v.x))
            {
                return;
            }
            // 滑动距离不够,返回
            if (Mathf.Abs(v.x) < slideDistance)
            {
                return;
            }
            onSlide?.Invoke(v.x, v.y);
            _hasSlide = true;
        }