Esempio n. 1
0
 private static void Internal_TriggerPositionalLocatorStateChanged(PositionalLocatorState oldState, PositionalLocatorState newState)
 {
     if (OnPositionalLocatorStateChanged != null)
     {
         OnPositionalLocatorStateChanged(oldState, newState);
     }
 }
Esempio n. 2
0
 private static void Internal_TriggerPositionalLocatorStateChanged(PositionalLocatorState oldState, PositionalLocatorState newState)
 {
     if (WorldManager.OnPositionalLocatorStateChanged != null)
     {
         WorldManager.OnPositionalLocatorStateChanged(oldState, newState);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// トラッキングロスト時にイベント通知
 /// </summary>
 /// <param name="oldstate"></param>
 /// <param name="newstate"></param>
 private void OnPositionalLocatorStateChanged(PositionalLocatorState oldstate, PositionalLocatorState newstate)
 {
     if (newstate != PositionalLocatorState.Active)
     {
         // becomimg tracking lost
         if (LostTrackingWorldStateEvent != null)
         {
             LostTrackingWorldStateEvent();
         }
     }
 }
Esempio n. 4
0
 private void WorldManager_OnPositionalLocatorStateChanged(PositionalLocatorState oldState, PositionalLocatorState newState)
 {
     if (newState == PositionalLocatorState.Active)
     {
         // Handle becoming active
     }
     else
     {
         // Handle becoming rotational only
     }
 }
        private void OnPositionalLocatorStateChanged(PositionalLocatorState oldState, PositionalLocatorState newState)
        {
            switch (newState)
            {
            case PositionalLocatorState.Inhibited:
                SetTrackingLost(true);
                break;

            default:
                SetTrackingLost(false);
                break;
            }
        }
Esempio n. 6
0
 private void WorldManager_OnPositionalLocatorStateChanged(PositionalLocatorState oldState, PositionalLocatorState newState)
 {
     Debug.Log("Stage root tracking changed " + oldState.ToString() + " " + newState.ToString());
     // Hide the floor if tracking is lost or if StageRoot can't be located.
     if (floorQuadInstance != null &&
         UnityEngine.XR.WSA.HolographicSettings.IsDisplayOpaque)
     {
         bool located = newState == PositionalLocatorState.Active;
         floorQuadInstance.SetActive((located && renderPlaySpace));
         if (located)
         {
             floorQuadInstance.transform.localPosition = new Vector3(0, Mathf.Min(-1.5f, transform.position.y), 0);
         }
         updatePlayspaceBounds = located;
     }
 }
Esempio n. 7
0
 private void WorldManager_OnPositionalLocatorStateChanged(PositionalLocatorState oldState, PositionalLocatorState newState)
 {
     isPaused = newState != PositionalLocatorState.Active;
 }
Esempio n. 8
0
 private void WorldManager_OnPositionalLocatorStateChanged(PositionalLocatorState oldState, PositionalLocatorState newState)
 {
     Debug.Log("WorldManager_OnPositionalLocatorStateChanged: " + newState.ToString());
     //TODO: Add your real code here to deal with loss tracking appropriately
 }
 private void WorldManager_OnPositionalLocatorStateChanged(PositionalLocatorState oldState, PositionalLocatorState newState)
 {
     TraceHelper.Log("WorldManager_OnPositionalLocatorStateChanged: " + newState.ToString());
 }
Esempio n. 10
0
 private void WorldManager_OnPositionalLocatorStateChanged(PositionalLocatorState oldState, PositionalLocatorState newState)
 {
     CurrentState = newState;
     gameObject.SetActive(newState == PositionalLocatorState.Active);
 }
Esempio n. 11
0
 void Start()
 {
     WorldManager.OnPositionalLocatorStateChanged += WorldManager_OnPositionalLocatorStateChanged;
     CurrentState = WorldManager.state;
 }
Esempio n. 12
0
 void Awake()
 {
     CurrentState = PositionalLocatorState.Unavailable;
 }
    // -- // -- // -- // -- // -- // -- // -- // -- // -- // -- //

    void Start()
    {
        if (!isInterfaceEnabled)
        {
            return;
        }

        // determine if display is opaque or transparent
        isDisplayOpaque = HolographicSettings.IsDisplayOpaque;
        Debug.Log("Display: " + (isDisplayOpaque ? "Opaque" : "Transparent"));

        // modify the main camera in the scene
        Camera currentCamera = MultiARInterop.GetMainCamera();

        if (!currentCamera)
        {
            GameObject currentCameraObj = new GameObject("Main Camera");
            currentCameraObj.tag = "MainCamera";

            currentCamera = currentCameraObj.AddComponent <Camera>();
        }

        // reset camera position & rotation
        //currentCamera.transform.position = Vector3.zero;
        currentCamera.transform.rotation = Quaternion.identity;

        // set camera parameters
        currentCamera.clearFlags      = CameraClearFlags.SolidColor;
        currentCamera.backgroundColor = new Color(0f, 0f, 0f, 0f);
        currentCamera.nearClipPlane   = 0.5f;        // HoloLens recommended
        currentCamera.farClipPlane    = 100f;

        if (isDisplayOpaque)
        {
            currentCamera.clearFlags = CameraClearFlags.Skybox;
        }

        // set the fastest quality setting
        QualitySettings.SetQualityLevel((int)qualityLevel);
        Debug.Log("QualityLevel: " + QualitySettings.names[(int)qualityLevel]);

        // reference to the AR main camera
        mainCamera = currentCamera;

        // don't destroy the light between scenes
        DontDestroyOnLoad(currentCamera.gameObject);

//		// add camera parent
//		if(currentCamera.transform.parent == null)
//		{
//			GameObject cameraParent = new GameObject("CameraParent");
//			currentCamera.transform.SetParent(cameraParent.transform);
//		}

        // modify the directional light
        Light currentLight = MultiARInterop.GetDirectionalLight();

        if (!currentLight)
        {
            GameObject currentLightObj = new GameObject("Directional light");

            currentLight      = currentLightObj.AddComponent <Light>();
            currentLight.type = LightType.Directional;
        }

        // reset light position & rotation
        currentLight.transform.position = Vector3.zero;
        currentLight.transform.rotation = Quaternion.Euler(40f, 40f, 0f);

        // set light parameters
        currentLight.color = new Color32(255, 254, 244, 255);

        // add the ar-light component
        //currentLight.gameObject.AddComponent<MultiARDirectionalLight>();

        // reference to the AR directional light
        //directionalLight = currentLight;

        // don't destroy the light between scenes
        DontDestroyOnLoad(currentLight.gameObject);

        // there is no point cloud in WinMR
        MultiARInterop.MultiARData arData = arManager.GetARData();

        // check for point cloud getter
        if (arManager.pointCloudPrefab != null)
        {
            arData.pointCloudData      = new Vector3[0];
            arData.pointCloudLength    = 0;
            arData.pointCloudTimestamp = 0.0;
        }

        // set tracking state
        cameraTrackingState = WorldManager.state;
        WorldManager.OnPositionalLocatorStateChanged += WorldManager_OnPositionalLocatorStateChanged;

//		// set tracking space type
//		Debug.Log("Before: " + XRDevice.GetTrackingSpaceType());
//		if(XRDevice.GetTrackingSpaceType() != TrackingSpaceType.Stationary)
//		{
//			if(!XRDevice.SetTrackingSpaceType(TrackingSpaceType.Stationary))
//			{
//				Debug.LogError("Cannot set stationary space type!");
//			}
//		}

        // create gesture input
        if (!isDisplayOpaque)
        {
            gestureRecognizer = new GestureRecognizer();
            gestureRecognizer.SetRecognizableGestures(GestureSettings.Tap | GestureSettings.Hold |
                                                      GestureSettings.NavigationX | GestureSettings.NavigationY | GestureSettings.NavigationZ);

            gestureRecognizer.Tapped += GestureRecognizer_Tapped;

//			gestureRecognizer.HoldStarted += GestureRecognizer_HoldStarted;
//			gestureRecognizer.HoldCompleted += GestureRecognizer_HoldCompleted;
//			gestureRecognizer.HoldCanceled += GestureRecognizer_HoldCanceled;

            gestureRecognizer.NavigationStarted   += GestureRecognizer_NavigationStarted;
            gestureRecognizer.NavigationUpdated   += GestureRecognizer_NavigationUpdated;
            gestureRecognizer.NavigationCompleted += GestureRecognizer_NavigationCompleted;
            gestureRecognizer.NavigationCanceled  += GestureRecognizer_NavigationCanceled;

            gestureRecognizer.StartCapturingGestures();
            Debug.Log("Gesture recognizer inited and started.");
        }
        //else
        {
            // init interaction manager
//			InteractionManager.InteractionSourcePressed += InteractionManager_InteractionSourcePressed;
//			InteractionManager.InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated;
//			InteractionManager.InteractionSourceReleased += InteractionManager_InteractionSourceReleased;

            InteractionManager.InteractionSourceDetected += InteractionManager_InteractionSourceDetected;
            InteractionManager.InteractionSourceLost     += InteractionManager_InteractionSourceLost;
            InteractionManager.InteractionSourceUpdated  += InteractionManager_InteractionSourceUpdated;

            Debug.Log("Interaction manager inited.");
        }

        // create surface renderer
        if (arManager.useOverlaySurface != MultiARManager.SurfaceRenderEnum.None)
        {
            GameObject objRenderer = new GameObject();
            objRenderer.name           = "SurfaceRenderer";
            objRenderer.layer          = MultiARInterop.GetSurfaceLayer();
            arData.surfaceRendererRoot = objRenderer;

            surfaceRootTransform = objRenderer.transform;
            DontDestroyOnLoad(objRenderer);

            if (!isDisplayOpaque)
            {
                // hololens
                surfaceRenderer = objRenderer.AddComponent <SpatialMappingRenderer>();
                surfaceRenderer.surfaceParent = objRenderer;

                switch (arManager.useOverlaySurface)
                {
                case MultiARManager.SurfaceRenderEnum.None:
                    surfaceRenderer.renderState = SpatialMappingRenderer.RenderState.None;
                    break;

                case MultiARManager.SurfaceRenderEnum.Visualization:
                    surfaceRenderer.renderState = SpatialMappingRenderer.RenderState.Visualization;
                    break;

                case MultiARManager.SurfaceRenderEnum.Occlusion:
                case MultiARManager.SurfaceRenderEnum.OcclusionWithShadows:
                    surfaceRenderer.renderState = SpatialMappingRenderer.RenderState.Occlusion;
                    break;
                }

                if (arManager.useOverlaySurface != MultiARManager.SurfaceRenderEnum.None)
                {
                    surfaceRenderer.visualMaterial    = arManager.surfaceVisualizationMaterial;
                    surfaceRenderer.occlusionMaterial = arManager.useOverlaySurface == MultiARManager.SurfaceRenderEnum.OcclusionWithShadows ?
                                                        arManager.surfaceOcclusionWithShadowsMaterial : arManager.surfaceOcclusionMaterial;
                }
            }
            else
            {
                // use special surface material on opaque displays
                Material visualMaterial = arManager.GetSurfaceMaterial();
                if (arManager.useOverlaySurface == MultiARManager.SurfaceRenderEnum.Visualization && vrSurfaceMaterial)
                {
                    visualMaterial = vrSurfaceMaterial;
                }

                // mr headsets
                CreateBoundaryPlane(objRenderer.transform, visualMaterial, arManager.surfaceCollider, arManager.colliderMaterial);

                boundaryMgr           = objRenderer.AddComponent <HoloToolkit.Unity.Boundary.BoundaryManager>();
                boundaryMgr.FloorQuad = boundaryPlane;
                boundaryMgr.AwakeBoundaryManager();
            }
        }

        // create surface collider
        if (arManager.surfaceCollider)
        {
            GameObject objCollider = new GameObject();
            objCollider.name  = "SurfaceCollider";
            objCollider.layer = MultiARInterop.GetSurfaceLayer();
            DontDestroyOnLoad(objCollider);

            if (!isDisplayOpaque)
            {
                // hololens
                surfaceCollider = objCollider.AddComponent <SpatialMappingCollider>();
                surfaceCollider.surfaceParent = objCollider;

                surfaceCollider.lodType = SpatialMappingBase.LODType.Low;
                surfaceCollider.layer   = MultiARInterop.GetSurfaceLayer();

                if (arManager.colliderMaterial)
                {
                    surfaceCollider.material = arManager.colliderMaterial;
                }
            }
            else
            {
                // mr headsets
                if (boundaryPlane == null)
                {
                    // there was no boundary rendering
                    CreateBoundaryPlane(objCollider.transform, null, true, arManager.colliderMaterial);

                    boundaryMgr           = objCollider.AddComponent <HoloToolkit.Unity.Boundary.BoundaryManager>();
                    boundaryMgr.FloorQuad = boundaryPlane;
                    boundaryMgr.AwakeBoundaryManager();
                }
            }
        }

//		// if camera is too near to the floor, lower the floor 1.5 meter below the camera
//		if(currentCamera && boundaryMgr)
//		{
//			if(currentCamera.transform.position.y < 0.1f)
//			{
//				boundaryMgr.CurrentFloorHeightOffset = currentCamera.transform.position.y - 1.5f;
//				Debug.Log(string.Format("FloorHeightOffset set below the camera at {0:F2}m.", boundaryMgr.CurrentFloorHeightOffset));
//			}
//		}

        // starts co-routine to check rendered surfaces
        StartCoroutine(CheckSurfacesRoutine());

        Debug.Log("TrackingSpaceType: " + XRDevice.GetTrackingSpaceType());
        Debug.Log("Screen size: " + Screen.width + " x " + Screen.height);

        int surfaceLayer = MultiARInterop.GetSurfaceLayer();          // LayerMask.NameToLayer("SpatialSurface");

        Debug.Log("SpatialSurfaceLayer: " + surfaceLayer);

        // interface is initialized
        isInitialized = true;
    }
 // invoked by WorldManager.OnPositionalLocatorStateChanged-event
 void WorldManager_OnPositionalLocatorStateChanged(PositionalLocatorState oldState, PositionalLocatorState newState)
 {
     cameraTrackingState = newState;
 }