Esempio n. 1
0
    private void Start()
    {
        // Start scanning with the SpatialUnderstanding module
        m_state = State.Scanning;
        m_spatialMappingManager = SpatialMappingManager.Instance;
        if (!m_spatialMappingManager.IsObserverRunning())
        {
            m_spatialMappingManager.StartObserver();
        }
        if (visualizeSpatialMesh && spatialMeshVisibleMaterial != null)
        {
            m_spatialMappingManager.SetSurfaceMaterial(spatialMeshVisibleMaterial);
            m_spatialMappingManager.DrawVisualMeshes = true;
        }
        m_spatialUnderstanding = SpatialUnderstanding.Instance;
        m_spatialUnderstanding.ScanStateChanged += OnScanStateChanged;
        m_spatialUnderstanding.RequestBeginScanning();

        // Subscribe to tap gesture
        m_gestureRecognizer = new GestureRecognizer();
        m_gestureRecognizer.SetRecognizableGestures(GestureSettings.Tap);
        m_gestureRecognizer.TappedEvent += OnTapEvent;
        m_gestureRecognizer.StartCapturingGestures();

        // Pin the query results memory and get a native pointer
        m_queryResultsPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(m_queryResults);
    }
Esempio n. 2
0
    // Use this for initialization
    public void Start()
    {
        spaceUnderstanding = SpaceUnderstanding.Instance;

        // Start mapping room, hide mesh
        if (SpatialMappingManager.Instance == null)
        {
            Debug.Log("SpatialMappingManager is null");
        }
        else
        {
            spatialMappingManager = SpatialMappingManager.Instance;
        }

        if (ReadText.Instance != null)
        {
            readText = ReadText.Instance;
        }

        holoLensimage = GameObject.Find("HoloLensImage");
#if UNITY_EDITOR
        spatialMappingManager.DrawVisualMeshes = true;
#else
        spatialMappingManager.DrawVisualMeshes = false;

        spatialMappingManager.StartObserver();
#endif
        // Start to recognize gestures
        gestureRecognizer = new GestureRecognizer();
        gestureRecognizer.SetRecognizableGestures(GestureSettings.Tap);
        gestureRecognizer.StartCapturingGestures();

        SpatialUnderstanding.Instance.UnderstandingCustomMesh.DrawProcessedMesh = false;
    }
Esempio n. 3
0
    public void StartStagePlacement()
    {
        if (isLoadingStagePlacement)
        {
            return;
        }

        HideMenu();

#if UNITY_WSA
        isLoadingStagePlacement = true;
        StartCoroutine(ZoneCalibrationManager.Zones[0].ClearAnchorAsync(true, (bool cleared) =>
        {
            if (cleared && isLoadingStagePlacement)
            {
                SpatialMappingManager.gameObject.SetActive(true);
                SpatialMappingManager.StartObserver();
                StartCoroutine(DelayStartStagePlacement());
            }
            else
            {
                isLoadingStagePlacement = false;
            }
        }));
#endif
    }
Esempio n. 4
0
 /// <summary>
 /// Enables the updates to spatial mapping.
 /// </summary>
 private void EnableSpatialMapping()
 {
     if (spatialMappingManager != null)
     {
         spatialMappingManager.StartObserver();
     }
 }
Esempio n. 5
0
 void Start()
 {
     SurfaceMeshesToPlanes.Instance.MakePlanesComplete     += removeVertices;
     RemoveSurfaceVertices.Instance.RemoveVerticesComplete += planesReady;
     InputManager.Instance.PushFallbackInputHandler(gameObject);
     mappingManager.CleanupObserver();
     mappingManager.StartObserver();
 }
 /// <summary>
 /// Called after successfully joining the specified Room Name
 /// Starts the observer (room scanning) functionality of the HoloLens
 /// </summary>
 public override void OnJoinedRoom()
 {
     Debug.Log("OnJoinedRoom called...");
     if (!SpatialMappingManager.IsObserverRunning())
     {
         SpatialMappingManager.StartObserver();
     }
 }
Esempio n. 7
0
    public void StartStagePlacement()
    {
        ShowMenu(MenuManager.MenuType.None);
#if UNITY_WSA
        SpatialMappingManager.gameObject.SetActive(true);
        SpatialMappingManager.StartObserver();
        ZoneCalibrationManager.Zones[0].ClearAnchor(true);
        StartCoroutine(DelayStartStagePlacement());
#endif
    }
Esempio n. 8
0
 public void StartScanning()
 {
     // Start spatial mapping (SpatialUnderstanding requires this, too)
     if (!m_spatialMappingManager.IsObserverRunning())
     {
         m_spatialMappingManager.StartObserver();
     }
     m_spatialMappingManager.DrawVisualMeshes = visualizeSpatialMeshes;
     m_spatialUnderstanding.ScanStateChanged += OnScanStateChanged;
     m_spatialUnderstanding.RequestBeginScanning();
     m_spatialUnderstandingState = SpatialUnderstandingState.Scanning;
     m_spatialMappingManager.SetSurfaceMaterial(renderingMaterial);
 }
Esempio n. 9
0
    // Update is called once per frame
    void Update()
    {
        if (finished)
        {
            return;
        }

        if (spatialUnderstanding.ScanState == SpatialUnderstanding.ScanStates.None)
        {
            mappingManager.StartObserver();
            spatialUnderstanding.RequestBeginScanning();
        }
    }
Esempio n. 10
0
    public void Init(ref RosSharp.RosBridgeClient.RosConnector rosConnector)
    {
        this.rosConnector = rosConnector;
        publisher         = new RosSharp.RosBridgeClient.NonMono.Publisher <RosSharp.RosBridgeClient.Messages.Sensor.PointCloud2>(ref this.rosConnector, "/hololens/" + Config.PointCloud);

        spatialMappingManager = SpatialMappingManager.Instance;
        spatialMappingManager.SurfaceObserver.TimeBetweenUpdates     = Config.UnitySpatialMappingObserverTimeBetweenUpdates;
        spatialMappingManager.SurfaceObserver.TrianglesPerCubicMeter = Config.UnitySpatialMappingObserverTrianglesPerCubicMeter;
        spatialMappingManager.StartObserver(); // TODO: Check if offset is necessary, i.e. float startTime = SpatialMappingManager.Instance.StartTime;
        spatialMappingManager.DrawVisualMeshes = Config.UnitySpatialMappingObserverDrawVisualMeshes;

        CreatePointFieldArray();
    }
Esempio n. 11
0
    private void Start()
    {
        // Start scanning
        m_state = State.Scanning;
        SpatialMappingManager mapper = SpatialMappingManager.Instance;

        if (!mapper.IsObserverRunning())
        {
            mapper.StartObserver();
        }
        mapper.SetSurfaceMaterial(spatialMeshScanningMaterial);

        // Subscribe to tap gesture
        m_gestureRecognizer = new GestureRecognizer();
        m_gestureRecognizer.SetRecognizableGestures(GestureSettings.Tap);
        m_gestureRecognizer.TappedEvent += OnTapEvent;
        m_gestureRecognizer.StartCapturingGestures();
    }
Esempio n. 12
0
    //TODO: if time limited, take an optional callback
    public void StartScanning()
    {
        // Start spatial mapping (SpatialUnderstanding requires this, too)
        if (!m_spatialMappingManager.IsObserverRunning())
        {
            m_spatialMappingManager.StartObserver();
        }

        // If we are only using spatial mapping, visualize the meshes during the scanning
        // phase
        if (useSpatialUnderstanding)
        {
            m_spatialMappingManager.DrawVisualMeshes = visualizeSpatialMeshes;
            m_spatialUnderstanding.ScanStateChanged += OnScanStateChanged;
            m_spatialUnderstanding.RequestBeginScanning();
            m_spatialUnderstandingState = SpatialUnderstandingState.Scanning;
        }
        else
        {
            m_spatialMappingManager.DrawVisualMeshes = true;
        }
        m_spatialMappingManager.SetSurfaceMaterial(renderingMaterial);
    }
Esempio n. 13
0
    private void Update()
    {
        if (m_scanningComplete)
        {
            return;
        }
        SpatialUnderstandingDll.Imports.PlayspaceStats stats;
        switch (m_spatialUnderstandingState)
        {
        case State.StartScanning:
            // Start spatial mapping (SpatialUnderstanding requires this, too)
            if (!m_spatialMappingManager.IsObserverRunning())
            {
                m_spatialMappingManager.StartObserver();
            }
            m_spatialMappingManager.DrawVisualMeshes = visualizeSpatialMeshes;
            m_spatialUnderstanding.ScanStateChanged += OnScanStateChanged;
            m_spatialUnderstanding.RequestBeginScanning();
            m_spatialMappingManager.SetSurfaceMaterial(renderingMaterial);
            m_spatialUnderstandingState = State.Scanning;
            break;

        case State.Scanning:
            if (GetStats(out stats))
            {
                Debug.Log("NumFloor=" + stats.NumFloor + ", NumWallX-=" + stats.NumWall_XNeg + ", NumWallX+=" + stats.NumWall_XPos + ", NumWallZ-=" + stats.NumWall_ZNeg + ", NumWallZ+=" + stats.NumWall_ZPos);
            }
            break;

        case State.FinalizeScan:
            //TODO: timeout?
            // Note: this is pretty subtle -- ScanStatsReportStillWorking is *not*
            // automatically updated. It reuses a cached object. GetStats() will
            // fetch the latest object by calling the appropriate query function.
            GetStats(out stats);
            if (!m_spatialUnderstanding.ScanStatsReportStillWorking)
            {
                Debug.Log("Finalizing scan...");
                m_spatialUnderstanding.RequestFinishScan();
                m_spatialUnderstandingState = State.WaitingForScanCompletion;
            }
            break;

        case State.WaitingForMeshImport:
            //TODO: timeout?
            if (m_spatialUnderstanding.UnderstandingCustomMesh.IsImportActive == false)
            {
                List <MeshFilter> meshFilters = m_spatialUnderstanding.UnderstandingCustomMesh.GetMeshFilters();
                Debug.Log("Found " + meshFilters.Count + " meshes (import active=" + m_spatialUnderstanding.UnderstandingCustomMesh.IsImportActive + ")");
                if (!visualizeSpatialMeshes)
                {
                    DisableSpatialMappingMeshes();
                }
                ApplyVisualizationSettings();
                //SurfacePlaneDeformationManager.Instance.SetSpatialMeshFilters(meshFilters);
                if (buildNavMesh)
                {
                    m_navMeshBuilder.AddSourceMeshes(meshFilters, m_spatialUnderstanding.transform);
                }
                m_spatialUnderstandingState = State.WaitingForPlacementSolverInit;
            }
            break;

        case State.WaitingForPlacementSolverInit:
            //TODO: error checking and timeout?
            bool navMeshFinished = !buildNavMesh || (buildNavMesh && m_navMeshBuilder.isFinished);
            if (!m_solverInitCalled)
            {
                m_solverInitCalled = true;
                StartCoroutine(InitSolverCoroutine());
                if (buildNavMesh)
                {
                    m_navMeshBuilder.BuildAsync();
                }
            }
            else if (m_solverInitialized && navMeshFinished)
            {
                ApplyStaticBatching();
                m_scanningComplete          = true;
                m_spatialUnderstandingState = State.Finished;
                if (OnScanComplete != null)
                {
                    OnScanComplete();
                }
            }
            break;

        default:
            break;
        }
    }
Esempio n. 14
0
        /// <summary>
        /// Finds a good position to set the anchor.
        /// 1. If we have an anchor stored in the player prefs/ anchor store, use that
        /// 2. If we don't have spatial mapping, just use where the object happens to be
        /// 3. if we do have spatial mapping, anchor at a vertex dense portion of spatial mapping
        /// </summary>
        private void FindAnchorPosition()
        {
            // 1. recover a stored anchor if we can
            if (PlayerPrefs.HasKey(SavedAnchorKey) && AttachToCachedAnchor(PlayerPrefs.GetString(SavedAnchorKey)))
            {
                exportingAnchorName = PlayerPrefs.GetString(SavedAnchorKey);
                Debug.Log("found " + exportingAnchorName + " again");
                ExportAnchor();
            }
            // 2. just use the current object position if we don't have access to spatial mapping
            else if (spatialMapping == null)
            {
                if (UseSpatialMapping)
                {
                    Debug.Log("No spatial mapping...");
                }

                ExportAnchorAtPosition(objectToAnchor.transform.position);
            }
            // 3. seek a vertex dense portion of spatial mapping
            else
            {
                ReadOnlyCollection <SpatialMappingSource.SurfaceObject> surfaces = spatialMapping.GetSurfaceObjects();
                if (surfaces == null || surfaces.Count == 0)
                {
                    // If we aren't getting surfaces we may need to start the observer.
                    if (spatialMapping.IsObserverRunning() == false)
                    {
                        spatialMapping.StartObserver();
                        StartedObserver = true;
                    }

                    // And try again after the observer has a chance to get an update.
                    Invoke("FindAnchorPosition", spatialMapping.GetComponent <SpatialMappingObserver>().TimeBetweenUpdates);
                }
                else
                {
                    float startTime = Time.realtimeSinceStartup;
                    // If we have surfaces, we need to iterate through them to find a dense area
                    // of geometry, which should provide a good spot for an anchor.
                    Mesh       bestMesh   = null;
                    MeshFilter bestFilter = null;
                    int        mostVerts  = 0;

                    for (int index = 0; index < surfaces.Count; index++)
                    {
                        // If the current surface doesn't have a filter or a mesh, skip to the next one
                        // This happens as a surface is being processed.  We need to track both the mesh
                        // and the filter because the mesh has the verts in local space and the filter has the transform to
                        // world space.
                        MeshFilter currentFilter = surfaces[index].Filter;
                        if (currentFilter == null)
                        {
                            continue;
                        }

                        Mesh currentMesh = currentFilter.sharedMesh;
                        if (currentMesh == null)
                        {
                            continue;
                        }

                        // If we have a collider we can use the extents to estimate the volume.
                        MeshCollider currentCollider = surfaces[index].Collider;
                        float        volume          = currentCollider == null ? 1.0f : currentCollider.bounds.extents.magnitude;

                        // get th verts divided by the volume if any
                        int meshVerts = (int)(currentMesh.vertexCount / volume);

                        // and if this is most verts/volume we've seen, record this mesh as the current best.
                        mostVerts = Mathf.Max(meshVerts, mostVerts);
                        if (mostVerts == meshVerts)
                        {
                            bestMesh   = currentMesh;
                            bestFilter = currentFilter;
                        }
                    }

                    // If we have a good area to use, then use it.
                    if (bestMesh != null && mostVerts > 100)
                    {
                        // Get the average of the vertices
                        Vector3[] verts   = bestMesh.vertices;
                        Vector3   avgVert = verts.Average();

                        // transform the average into world space.
                        Vector3 center = bestFilter.transform.TransformPoint(avgVert);

                        Debug.LogFormat("found a good mesh mostVerts = {0} processed {1} meshes in {2} ms", mostVerts, surfaces.Count, 1000 * (Time.realtimeSinceStartup - startTime));
                        // then export the anchor where we've calculated.
                        ExportAnchorAtPosition(center);
                    }
                    else
                    {
                        // If we didn't find a good mesh, try again a little later.
                        Debug.LogFormat("Failed to find a good mesh mostVerts = {0} processed {1} meshes in {2} ms", mostVerts, surfaces.Count, 1000 * (Time.realtimeSinceStartup - startTime));
                        Invoke("FindAnchorPosition", spatialMapping.GetComponent <SpatialMappingObserver>().TimeBetweenUpdates);
                    }
                }
            }
        }
Esempio n. 15
0
    private void Update()
    {
        if (m_scanningComplete)
        {
            return;
        }
        switch (m_spatialUnderstandingState)
        {
        case SpatialUnderstandingState.StartScanning:
            // Start spatial mapping (SpatialUnderstanding requires this, too)
            if (!m_spatialMappingManager.IsObserverRunning())
            {
                m_spatialMappingManager.StartObserver();
            }
            m_spatialMappingManager.DrawVisualMeshes = visualizeSpatialMeshes;
            m_spatialUnderstanding.ScanStateChanged += OnScanStateChanged;
            m_spatialUnderstanding.RequestBeginScanning();
            m_spatialMappingManager.SetSurfaceMaterial(renderingMaterial);
            m_spatialUnderstandingState = SpatialUnderstandingState.Scanning;
            break;

        case SpatialUnderstandingState.FinalizeScan:
            //TODO: timeout?
            if (!m_spatialUnderstanding.ScanStatsReportStillWorking)
            {
                Debug.Log("Finalizing scan...");
                m_spatialUnderstanding.RequestFinishScan();
                m_spatialUnderstandingState = SpatialUnderstandingState.WaitingForScanCompletion;
            }
            break;

        case SpatialUnderstandingState.WaitingForMeshImport:
            //TODO: timeout?
            if (m_spatialUnderstanding.UnderstandingCustomMesh.IsImportActive == false)
            {
                Debug.Log("Found " + m_spatialUnderstanding.UnderstandingCustomMesh.GetMeshFilters().Count + " meshes (import active=" + m_spatialUnderstanding.UnderstandingCustomMesh.IsImportActive + ")");
                if (!visualizeSpatialMeshes)
                {
                    DisableSpatialMappingMeshes();
                }
                ApplyVisualizationSettings();
                //SurfacePlaneDeformationManager.Instance.SetSpatialMeshFilters(m_spatialUnderstanding.UnderstandingCustomMesh.GetMeshFilters());
                m_spatialUnderstandingState = SpatialUnderstandingState.WaitingForPlacementSolverInit;
            }
            break;

        case SpatialUnderstandingState.WaitingForPlacementSolverInit:
            //TODO: error checking and timeout?
            if (!m_placementSolverInitialized)
            {
                m_placementSolverInitialized = (SpatialUnderstandingDllObjectPlacement.Solver_Init() == 1);
                Debug.Log("Placement Solver initialization " + (m_placementSolverInitialized ? "succeeded" : "FAILED"));
                if (m_placementSolverInitialized)
                {
                    if (OnScanComplete != null)
                    {
                        OnScanComplete();
                    }
                    m_scanningComplete          = true;
                    m_spatialUnderstandingState = SpatialUnderstandingState.Finished;
                }
            }
            break;

        default:
            break;
        }
    }