// invoked by AnchorUpdated-event
    private void PlaneAnchorUpdated(ARPlaneAnchor arPlaneAnchor)
    {
        string surfId = arPlaneAnchor.identifier;

        // update plane anchor
        if (planeAnchorDict.ContainsKey(surfId))
        {
            ARPlaneAnchorGameObject arpag = planeAnchorDict[surfId];
            arpag.planeAnchor = arPlaneAnchor;

            if (arpag.gameObject)
            {
                UnityARUtility.UpdatePlaneWithAnchorTransform(arpag.gameObject, arPlaneAnchor);
            }

            planeAnchorDict[surfId] = arpag;
            trackedPlanesTimestamp  = GetLastFrameTimestamp();
        }

        // update overlay surface
        MultiARInterop.MultiARData arData = arManager.GetARData();
        if (arData.dictOverlaySurfaces.ContainsKey(surfId))
        {
            UpdateOverlaySurface(arData.dictOverlaySurfaces[surfId], arPlaneAnchor);
        }
    }
        public static Tuple <Vector3, Quaternion> GetRandomPoint(ARPlaneAnchorGameObject planeAnchorGameObject)
        {
            var position = planeAnchorGameObject.gameObject.transform.position + planeAnchorGameObject.planeAnchor.planeGeometry.vertices.Sample();
            var rotation = planeAnchorGameObject.gameObject.transform.rotation;

            return(Tuple.Create(position, rotation));
        }
Esempio n. 3
0
    public void OnARKitAnchorAdded(ARPlaneAnchor planeAnchor)
    {
        if (false != this.tracked || false != this.planeAnchorDictionary.ContainsKey(planeAnchor.identifier))
        {
            return;
        }
        this.tracked = true;
        Vector3 originPosition = UnityARMatrixOps.GetPosition(planeAnchor.transform);

        Renderer[] renderers = this.icon.GetComponentsInChildren <Renderer>();
        foreach (Renderer child in renderers)
        {
            child.gameObject.transform.localScale = Vector3.one * IconBehaviour.SCALE_RATE_IOS;
        }
        this.icon.name = planeAnchor.identifier;
        this.icon.transform.position = new Vector3(originPosition.x, originPosition.y, originPosition.z);
        this.icon.transform.rotation = UnityARMatrixOps.GetRotation(planeAnchor.transform);
        ARPlaneAnchorGameObject planeAnchorObject = new ARPlaneAnchorGameObject();

        planeAnchorObject.planeAnchor = planeAnchor;
        planeAnchorObject.gameObject  = this.icon;
        this.planeAnchorDictionary.Add(planeAnchor.identifier, planeAnchorObject);
        Notifier notifier = Notifier.GetInstance();

        notifier.Notify(NotifyMessage.OnTrackingFound);
        this.stateMachine.Change("tracking");
        this.stateMachine.Play();
        return;
    }
    // invoked by AnchorRemoved-event
    private void PlaneAnchorRemoved(ARPlaneAnchor arPlaneAnchor)
    {
        string surfId = arPlaneAnchor.identifier;

        Debug.Log("Plane removed: " + surfId);

        // remove plane anchor
        if (planeAnchorDict.ContainsKey(surfId))
        {
            ARPlaneAnchorGameObject arpag = planeAnchorDict[surfId];

            if (arpag != null && arpag.gameObject)
            {
                GameObject.Destroy(arpag.gameObject);
            }

            planeAnchorDict.Remove(surfId);
            trackedPlanesTimestamp = GetLastFrameTimestamp();
        }

        // remove overlay surface
        MultiARInterop.MultiARData arData = arManager.GetARData();
        if (arData.dictOverlaySurfaces.ContainsKey(surfId))
        {
            OverlaySurfaceUpdater overlaySurface = arData.dictOverlaySurfaces[surfId];
            arData.dictOverlaySurfaces.Remove(surfId);

            Destroy(overlaySurface.gameObject);
        }
    }
Esempio n. 5
0
 public void RemoveAnchor(ARPlaneAnchor arPlaneAnchor)
 {
     if (planes.ContainsKey(arPlaneAnchor.identifier))
     {
         ARPlaneAnchorGameObject arpag = planes[arPlaneAnchor.identifier];
         GameObject.Destroy(arpag.gameObject);
         planes.Remove(arPlaneAnchor.identifier);
     }
 }
Esempio n. 6
0
        private void AddAnchor(ARPlaneAnchor arPlaneAnchor)
        {
            GameObject go = 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);
        }
Esempio n. 7
0
 public void UpdateAnchor(ARPlaneAnchor arPlaneAnchor)
 {
     if (planes.ContainsKey(arPlaneAnchor.identifier))
     {
         ARPlaneAnchorGameObject arpag = planes[arPlaneAnchor.identifier];
         UpdatePlane(arpag.gameObject, arPlaneAnchor);
         arpag.planeAnchor = arPlaneAnchor;
         planes[arPlaneAnchor.identifier] = arpag;
     }
 }
Esempio n. 8
0
 private void UpdateAnchor(ARPlaneAnchor arPlaneAnchor)
 {
     if (planeAnchorMap.ContainsKey(arPlaneAnchor.identifier))
     {
         ARPlaneAnchorGameObject arpag = planeAnchorMap [arPlaneAnchor.identifier];
         UpdatePlaneWithAnchorTransform(arpag.gameObject, arPlaneAnchor);
         arpag.planeAnchor = arPlaneAnchor;
         planeAnchorMap [arPlaneAnchor.identifier] = arpag;
     }
 }
Esempio n. 9
0
    public void RemoveAnchor(ARPlaneAnchor arPlaneAnchor)
    {
        if (planeAnchorMap.ContainsKey(arPlaneAnchor.identifier))
        {
            ARPlaneAnchorGameObject arpag = planeAnchorMap[arPlaneAnchor.identifier];
            GameObject.Destroy(arpag.gameObject);
            planeAnchorMap.Remove(arPlaneAnchor.identifier);

            positionSceneAtLargestAnchor();
        }
    }
Esempio n. 10
0
    public void AddAnchor(ARPlaneAnchor arPlaneAnchor)
    {
        GameObject empty = Instantiate <GameObject>(this.EmptyAnchorPrefab);
        ARPlaneAnchorGameObject arpag = new ARPlaneAnchorGameObject();

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

        positionSceneAtLargestAnchor();
    }
Esempio n. 11
0
    // 新しい平面が検出された場合
    public void AddAnchor(ARPlaneAnchor arPlaneAnchor)
    {
        // Anchorに合わせて新しい平面オブジェクト生成
        GameObject go = CreatePlaneInScene(arPlaneAnchor);
        // 生成した平面オブジェクトを管理用Listに登録
        ARPlaneAnchorGameObject arpag = new ARPlaneAnchorGameObject();

        arpag.planeAnchor = arPlaneAnchor;
        arpag.gameObject  = go;
        planeAnchorMap.Add(arPlaneAnchor.identifier, arpag);
    }
Esempio n. 12
0
    // Update is called once per frame
    void Update()
    {
        // Delay between calls to SetWorldOrigin().
        if (justUpdated > 0)
        {
            justUpdated--;
            return;
        }

        if (unityARAnchorManager == null)
        {
            print("FloorFinder: Anchor manager is null.");
            return;
        }
        // Get the planes found by ARKit.
        List <ARPlaneAnchorGameObject> arpags = unityARAnchorManager.GetCurrentPlaneAnchors();

        // Find the lowest plane
        float lowestPlaneHeight             = 100f;
        ARPlaneAnchorGameObject lowestPlane = null;

        foreach (ARPlaneAnchorGameObject plane in arpags)
        {
            float planeHeight = plane.gameObject.transform.position.y;
            if (planeHeight < lowestPlaneHeight)
            {
                lowestPlaneHeight = planeHeight;
                lowestPlane       = plane;
            }
        }

//		float cameraHeight = Camera.main.transform.position.y;
//		float yDistanceToCamera = cameraHeight - lowestPlaneHeight;
        float distToCurrentFloor = Mathf.Abs(lowestPlaneHeight - 0);

        // and ignore planes that won't make much of a difference with the current state.
        if (lowestPlane != null && distToCurrentFloor > FLOOR_PRECISION_TOLERANCE)
        {
            print("UPDATING NEW FLOOR HEIGHT");
            // Don't update the origin too frequently, becaues it takes a few frames to be applied it seems.
            justUpdated = 5;

            // Use the plane transform, as it's xz-rotated in the correct direction.
//			Transform planeTransform = lowestPlane.gameObject.transform;
//			// Reset plane transform
//			planeTransform.Rotate (new Vector3 (0, -planeTransform.eulerAngles.y, 0));
//			lowestPlane.gameObject.transform.position = new Vector3 (0, lowestPlaneHeight, 0);
//			updateWorldOrigin (lowestPlane.gameObject.transform);
            originTransform.position = new Vector3(0, lowestPlaneHeight, 0);
            updateWorldOrigin(originTransform);
            originTransform.position = new Vector3(0, 0, 0);
        }
    }
Esempio n. 13
0
    public void OnARKitAnchorRemoved(ARPlaneAnchor planeAnchor)
    {
        if (false == this.planeAnchorDictionary.ContainsKey(planeAnchor.identifier))
        {
            return;
        }
        ARPlaneAnchorGameObject planeAnchorObject = this.planeAnchorDictionary [planeAnchor.identifier];

        GameObject.Destroy(planeAnchorObject.gameObject);
        this.planeAnchorDictionary.Remove(planeAnchor.identifier);
        return;
    }
    // invoked by AnchorAdded-event
    private void PlaneAnchorAdded(ARPlaneAnchor arPlaneAnchor)
    {
        Debug.Log("Plane added: " + arPlaneAnchor.identifier);

        GameObject go = null;
//		if(arManager.displayTrackedSurfaces)
//		{
//			go = UnityARUtility.CreatePlaneInScene(arPlaneAnchor);
//			go.AddComponent<DontDestroyOnLoad>();  // these GOs persist across scene loads
//		}

        ARPlaneAnchorGameObject arpag = new ARPlaneAnchorGameObject();

        arpag.planeAnchor = arPlaneAnchor;
        arpag.gameObject  = go;

        planeAnchorDict.Add(arPlaneAnchor.identifier, arpag);
        trackedPlanesTimestamp = GetLastFrameTimestamp();

        // create overlay surfaces as needed
        if (arManager.useOverlaySurface != MultiARManager.SurfaceRenderEnum.None)
        {
            // estimate the material
            Material surfaceMat   = arManager.GetSurfaceMaterial();
            int      surfaceLayer = MultiARInterop.GetSurfaceLayer();

            MultiARInterop.MultiARData arData = arManager.GetARData();

            string surfId = arPlaneAnchor.identifier;
            if (!arData.dictOverlaySurfaces.ContainsKey(surfId))
            {
                GameObject overlaySurfaceObj = new GameObject();
                overlaySurfaceObj.name = "surface-" + surfId;

                overlaySurfaceObj.layer = surfaceLayer;
                overlaySurfaceObj.transform.SetParent(arData.surfaceRendererRoot ? arData.surfaceRendererRoot.transform : null);

//				GameObject overlayCubeObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
//				overlayCubeObj.name = "surface-cube-" + surfId;
//				overlayCubeObj.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
//				overlayCubeObj.transform.SetParent(overlaySurfaceObj.transform);

                OverlaySurfaceUpdater overlaySurface = overlaySurfaceObj.AddComponent <OverlaySurfaceUpdater>();
                overlaySurface.SetSurfaceMaterial(surfaceMat);
                overlaySurface.SetSurfaceCollider(arManager.surfaceCollider, arManager.colliderMaterial);

                arData.dictOverlaySurfaces.Add(surfId, overlaySurface);
            }

            // update the surface mesh
            UpdateOverlaySurface(arData.dictOverlaySurfaces[surfId], arPlaneAnchor);
        }
    }
Esempio n. 15
0
    public void AddAnchor(ARPlaneAnchor arPlaneAnchor)
    {
        Debug.LogWarning("AddAnchor!!!!");

        //Planeが追加されたら呼ばれる。
        ExARKitPlaneMeshRender go = ExUnityARUtility.CreatePlaneInScene(arPlaneAnchor); ////////////生成

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

        arpag.planeAnchor = arPlaneAnchor;
        arpag.gameObject  = go.gameObject;
        planeAnchorMap.Add(arPlaneAnchor.identifier, arpag); ////////////ディクショナリーにAdd
    }
Esempio n. 16
0
    public void AddAnchor(ARPlaneAnchor arPlaneAnchor)
    {
        GameObject go = CreatePlane(arPlaneAnchor);

        go.AddComponent <DontDestroyOnLoad>();
        go.SetActive(planeVisible);

        ARPlaneAnchorGameObject arpag = new ARPlaneAnchorGameObject();

        arpag.planeAnchor = arPlaneAnchor;
        arpag.gameObject  = go;

        planes.Add(arPlaneAnchor.identifier, arpag);
    }
Esempio n. 17
0
 public void UpdateAnchor(ARPlaneAnchor arPlaneAnchor)
 {
     Debug.LogWarning("updateAnchor!!!!");
     //ancharの更新
     if (planeAnchorMap.ContainsKey(arPlaneAnchor.identifier))
     {
         ARPlaneAnchorGameObject arpag = planeAnchorMap [arPlaneAnchor.identifier];
         //planeをアップデート
         ExUnityARUtility.UpdatePlaneWithAnchorTransform(
             arpag.gameObject.transform.GetComponent <ExARKitPlaneMeshRender>(),
             arPlaneAnchor
             );
         arpag.planeAnchor = arPlaneAnchor;
         planeAnchorMap [arPlaneAnchor.identifier] = arpag;
     }
 }
Esempio n. 18
0
    public void OnARKitAnchorUpdated(ARPlaneAnchor planeAnchor)
    {
        if (false == this.planeAnchorDictionary.ContainsKey(planeAnchor.identifier))
        {
            return;
        }
        ARPlaneAnchorGameObject planeAnchorObject = this.planeAnchorDictionary [planeAnchor.identifier];

        planeAnchorObject.planeAnchor = planeAnchor;
        Vector3 originPosition = UnityARMatrixOps.GetPosition(planeAnchor.transform);

        this.icon.name = planeAnchor.identifier;
        this.icon.transform.position = UnityARMatrixOps.GetPosition(planeAnchor.transform);
        this.icon.transform.rotation = UnityARMatrixOps.GetRotation(planeAnchor.transform);
        return;
    }
Esempio n. 19
0
    // 新しい平面が検出された場合
    public void AddAnchor(ARPlaneAnchor arPlaneAnchor)
    {
        // Anchorに合わせて新しい平面オブジェクト生成
        GameObject go    = CreatePlaneInScene(arPlaneAnchor);
        GameObject field = Instantiate(fieldPrefab, go.transform);

        field.transform.localPosition = Vector3.zero;
        field.name = "ViewFiled";
        RailCreateManager.Instance.ARFiledExist = true;

        Fanctions.Instance.viewF = field;

        // 生成した平面オブジェクトを管理用Listに登録
        ARPlaneAnchorGameObject arpag = new ARPlaneAnchorGameObject();

        arpag.planeAnchor = arPlaneAnchor;
        arpag.gameObject  = go;
        planeAnchorMap.Add(arPlaneAnchor.identifier, arpag);
    }
Esempio n. 20
0
    private void positionSceneAtLargestAnchor()
    {
        ARPlaneAnchorGameObject largestAnchor = this.CurrentUsedAnchor;

        foreach (ARPlaneAnchorGameObject arpag in planeAnchorMap.Values)
        {
            if (largestAnchor == null || arpag.planeAnchor.extent.magnitude > largestAnchor.planeAnchor.extent.magnitude)
            {
                largestAnchor = arpag;
            }
        }

        if (largestAnchor != null && largestAnchor != this.CurrentUsedAnchor)
        {
            this.CurrentUsedAnchor = largestAnchor;
            SceneCreator creator = this.SceneParent.GetComponent <SceneCreator>();
            this.SceneParent.SetParent(largestAnchor.gameObject.transform, false);
            if (!creator.SceneCreated)
            {
                creator.CreateScene();
            }
        }
    }