Ejemplo n.º 1
0
            /// <summary>
            /// Scan the room and return the scaned room as a RoomMesh (serialized as a byte array)
            /// This method can ONLY be used by HoloLens
            /// </summary>
            /// <returns>Serialized Room Mesh</returns>
            public byte[] LoadMesh()
            {
                SpatialMappingManager mappingManager = GetComponent <SpatialMappingManager>();
                List <MeshFilter>     meshFilters    = mappingManager.GetMeshFilters();
                List <Mesh>           meshes         = new List <Mesh>();

                foreach (var meshFilter in meshFilters)
                {
                    Mesh           mesh  = meshFilter.sharedMesh;
                    Mesh           clone = new Mesh();
                    List <Vector3> verts = new List <Vector3>();
                    verts.AddRange(mesh.vertices);

                    for (int i = 0; i < verts.Count; i++)
                    {
                        verts[i] = meshFilter.transform.TransformPoint(verts[i]);
                    }

                    clone.SetVertices(verts);
                    clone.SetTriangles(mesh.triangles, 0);
                    meshes.Add(clone);
                }

                return(SimpleMeshSerializer.Serialize(meshes));
            }
        /// <summary>
        /// Ensures that the scene has what we need to continue.
        /// </summary>
        /// <returns>True if we can proceed, false otherwise.</returns>
        private bool CheckConfiguration()
        {
            networkTransmitter = GenericNetworkTransmitter.Instance;
            if (networkTransmitter == null)
            {
                Debug.Log("No UNetNetworkTransmitter found in scene");
                return(false);
            }

            networkManager = NetworkManager.singleton;
            if (networkManager == null)
            {
                Debug.Log("No NetworkManager found in scene");
                return(false);
            }

            if (SharedCollection.Instance == null)
            {
                Debug.Log("No SharedCollection found in scene");
                return(false);
            }

#if UNITY_WSA
            objectToAnchor = SharedCollection.Instance.gameObject;

            spatialMapping = SpatialMappingManager.Instance;
            if (spatialMapping == null)
            {
                Debug.Log("Spatial mapping not found in scene. Better anchor locations can be found if a SpatialMappingManager is in the scene");
            }
#endif

            return(true);
        }
    // Use this for initialization
    void Start()
    {
        ttsMgr = GetComponent <TextToSpeechManager>();
        if (ttsMgr == null)
        {
            Debug.LogError("TextToSpeechManager Required");
        }

        anchorManager = WorldAnchorManager.Instance;
        if (anchorManager == null)
        {
            Debug.LogError("This script expects that you have a WorldAnchorManager component in your scene.");
        }

        spatialMappingManager = SpatialMappingManager.Instance;
        if (spatialMappingManager == null)
        {
            Debug.LogError("This script expects that you have a SpatialMappingManager component in your scene.");
        }

        if (anchorManager != null && spatialMappingManager != null)
        {
            anchorManager.AttachAnchor(this.gameObject, SavedAnchorFriendlyName);
            ttsMgr.SpeakText("Anchor Locked");
        }
        else
        {
            ttsMgr.SpeakText("Cannot Lock Anchor");
        }
    }
        /// <summary>
        /// Removes all anchors from the scene and deletes them from the anchor store.
        /// </summary>
        public void RemoveAllAnchors()
        {
            SpatialMappingManager spatialMappingManager = SpatialMappingManager.Instance;

            // This case is unexpected, but just in case.
            if (AnchorStore == null)
            {
                Debug.LogError("remove all anchors called before anchor store is ready.");
            }

            WorldAnchor[] anchors = FindObjectsOfType <WorldAnchor>();

            if (anchors != null)
            {
                foreach (WorldAnchor anchor in anchors)
                {
                    // Don't remove SpatialMapping anchors if exists
                    if (spatialMappingManager == null ||
                        anchor.gameObject.transform.parent.gameObject != spatialMappingManager.gameObject)
                    {
                        anchorOperations.Enqueue(new AnchorAttachmentInfo()
                        {
                            AnchorName         = anchor.name,
                            GameObjectToAnchor = anchor.gameObject,
                            Operation          = AnchorOperation.Delete
                        });
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void Start()
        {
            // Make sure we have all the components in the scene we need.
            anchorManager = WorldAnchorManager.Instance;
            if (anchorManager == null)
            {
                Debug.LogError("This script expects that you have a WorldAnchorManager component in your scene.");
            }

            spatialMappingManager = SpatialMappingManager.Instance;
            if (spatialMappingManager == null)
            {
                Debug.LogError("This script expects that you have a SpatialMappingManager component in your scene.");
            }

            if (anchorManager != null && spatialMappingManager != null)
            {
                anchorManager.AttachAnchor(this.gameObject, SavedAnchorFriendlyName);
            }
            else
            {
                // If we don't have what we need to proceed, we may as well remove ourselves.
                Destroy(this);
            }
        }
    // In order not to affect the user's viewport, we will make the augmented panels/columns
    // invisible when the user starts the test.
    public void StartTest()
    {
        SpatialMappingManager spatialMappingManager = SpatialMappingManager.Instance;

        var anchors = FindObjectsOfType <WorldAnchor>();

        for (var i = 0; i < anchors.Length; i++)
        {
            // Don't remove SpatialMapping anchors if exists
            if (spatialMappingManager != null && anchors[i].gameObject.transform.parent.gameObject == spatialMappingManager.gameObject)
            {
                continue;
            }

            MeshRenderer meshRenderer;
            if ((meshRenderer = anchors[i].gameObject.GetComponent <MeshRenderer>()) != null)
            {
                meshRenderer.enabled = false;
            }
            foreach (Transform child in anchors[i].gameObject.transform)
            {
                if ((meshRenderer = child.gameObject.GetComponent <MeshRenderer>()) != null)
                {
                    meshRenderer.enabled = false;
                }
            }
        }

        stageCounter = 1;
        StartNextStage(stageCounter);
    }
Ejemplo n.º 7
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);
    }
    private void EndTest()
    {
        SpatialMappingManager spatialMappingManager = SpatialMappingManager.Instance;

        var anchors = FindObjectsOfType <WorldAnchor>();

        for (var i = 0; i < anchors.Length; i++)
        {
            // Don't remove SpatialMapping anchors if exists
            if (spatialMappingManager != null && anchors[i].gameObject.transform.parent.gameObject == spatialMappingManager.gameObject)
            {
                continue;
            }

            MeshRenderer meshRenderer;
            if ((meshRenderer = anchors[i].gameObject.GetComponent <MeshRenderer>()) != null)
            {
                meshRenderer.enabled = true;
            }
            foreach (Transform child in anchors[i].gameObject.transform)
            {
                if ((meshRenderer = child.gameObject.GetComponent <MeshRenderer>()) != null)
                {
                    meshRenderer.enabled = true;
                }
            }
        }

        GenerateResults();
    }
    protected virtual void Start()
    {
        // Make sure we have all the components in the scene we need.
        anchorManager = WorldAnchorManager.Instance;
        if (anchorManager == null)
        {
            Debug.LogError("This script expects that you have a WorldAnchorManager component in your scene.");
        }

        spatialMappingManager = SpatialMappingManager.Instance;
        if (spatialMappingManager == null)
        {
            Debug.LogError("This script expects that you have a SpatialMappingManager component in your scene.");
        }

        if (anchorManager != null && spatialMappingManager != null)
        {
            anchorManager.AttachAnchor(gameObject, SavedAnchorFriendlyName);
        }
        else
        {
            // If we don't have what we need to proceed, we may as well remove ourselves.
            Destroy(this);
        }

        if (PlaceParentOnTap)
        {
            if (ParentGameObjectToPlace != null && !gameObject.transform.IsChildOf(ParentGameObjectToPlace.transform))
            {
                Debug.LogError("The specified parent object is not a parent of this object.");
            }

            DetermineParent();
        }
    }
Ejemplo n.º 10
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;
    }
Ejemplo n.º 11
0
        async void HolographicSpace_CameraAdded(HolographicSpace sender, HolographicSpaceCameraAddedEventArgs args)
        {
            if (!appInited)
            {
                await window.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
                {
                    SpatialMappingManager = new SpatialMappingManager();
                    VoiceManager          = new VoiceManager();

                    if (options == null)
                    {
                        options = new ApplicationOptions();
                    }

                    //override some options:
                    options.LimitFps = false;
                    options.Width    = (int)args.Camera.RenderTargetSize.Width;
                    options.Height   = (int)args.Camera.RenderTargetSize.Height;

                    Game = (StereoApplication)Activator.CreateInstance(holoAppType, options);
                    Game.Run();
                    GesturesManager = new GesturesManager(Game, ReferenceFrame);
                    AppStarted?.Invoke(Game);
                    appInited = true;
                });
            }
        }
Ejemplo n.º 12
0
 // Use this for initialization
 void Start()
 {
     spatialMappingManager = SpatialMappingManager.Instance;
     if (spatialMappingManager == null)
     {
         Debug.LogError("This script expects that you have a SpatialMappingManager component in your scene.");
     }
 }
Ejemplo n.º 13
0
 void Awake()
 {
     mappingManager    = GetComponentInChildren <SpatialMappingManager>();
     planesMaker       = GetComponentInChildren <SurfaceMeshesToPlanes>();
     verticesRemover   = GetComponentInChildren <RemoveSurfaceVertices>();
     horizontalObjects = new List <GameObject>();
     verticalObjects   = new List <GameObject>();
     otherObjects      = new List <GameObject>();
 }
Ejemplo n.º 14
0
    void Start()
    {
        m_SpatialMappingManager          = SpatialMappingManager.Instance;
        m_SpatialUnderstandingCustomMesh = SpatialUnderstanding.Instance.UnderstandingCustomMesh;

        m_SpatialMappingDefaultMaterial       = m_SpatialMappingManager.SurfaceMaterials;
        m_SpatialUnderstandingDefaultMaterial = m_SpatialUnderstandingCustomMesh.MeshMaterials;

        CurrentRenderingState = m_CurrentRenderingState;
    }
Ejemplo n.º 15
0
    private void Start()
    {
        m_spatialMappingManager = SpatialMappingManager.Instance;
        m_spatialUnderstanding  = SpatialUnderstanding.Instance;
#if UNITY_EDITOR
        // An ObjectSurfaceObserver should be attached and will be used in Unity
        // editor mode to generate spatial meshes from a pre-loaded file
        //m_spatialMappingManager.SetSpatialMappingSource(GetComponent<ObjectSurfaceObserver>());
#endif
    }
Ejemplo n.º 16
0
 void Start()
 {
     isEditing          = false;
     originaButtonScale = transform.localScale;
     collider           = GetComponent <BoxCollider>();
     originColliderSize = collider.size;
     spatialMapping     = SpatialMappingManager.Instance;
     picture            = GetComponentInParent <PictureController>();
     relativeOffset     = transform.position - picture.transform.position;
     relativeOffset.z   = -relativeOffset.z;
 }
Ejemplo n.º 17
0
    // Use this for initialization
    void Start()
    {
        SpatialMappingManager instance = SpatialMappingManager.Instance;

        instance.SurfaceMaterial  = MeshingMaterial;
        instance.DrawVisualMeshes = true;
        InputManager.Instance.AddGlobalListener(gameObject);
        _speech.AddRange(GetComponents <AudioSource>());
        Invoke("PlayAudio", 1F);
        //Invoke("FindFloor", 2F);
    }
Ejemplo n.º 18
0
    // Use this for initialization
    void Start()
    {
        spatialMappingManager = SpatialMappingManager.Instance;
        if (spatialMappingManager == null)
        {
            Debug.LogError("This script expects that you have a SpatialMappingManager component in your scene.");
        }

        gestureRecognizer              = new GestureRecognizer();
        gestureRecognizer.TappedEvent += OnTappedEvent;
        gestureRecognizer.StartCapturingGestures();
    }
Ejemplo n.º 19
0
    private void Start()
    {
        m_spatialMappingManager = SpatialMappingManager.Instance;
        m_spatialUnderstanding  = SpatialUnderstanding.Instance;
#if UNITY_EDITOR
        // An ObjectSurfaceObserver should be attached and will be used in Unity
        // editor mode to generate spatial meshes from a pre-loaded file
        m_spatialMappingManager.SetSpatialMappingSource(GetComponent <ObjectSurfaceObserver>());
#endif
        // Register for the MakePlanesComplete event
        SurfaceMeshesToPlanes.Instance.MakePlanesComplete += SurfaceMeshesToPlanes_MakePlanesComplete;
    }
    // Use this for initialization
    private void Start()
    {
        // Get Instance of SpatialMappingManager
        spatialMappingManager = SpatialMappingManager.Instance;

        surfaceMeshesToPlanes = SurfaceMeshesToPlanes.Instance;

        // Start to recognize gestures
        gestureRecognizer = new GestureRecognizer();
        gestureRecognizer.SetRecognizableGestures(GestureSettings.Tap);

        removeVerts = RemoveSurfaceVertices.Instance;
    }
Ejemplo n.º 21
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();
    }
Ejemplo n.º 22
0
    void Awake()
    {
        // on awake initialize clicker, spatial mapping material and other things
        clickerManager        = GetComponent <ClickerManager>();
        ClickSwitch           = false;
        logPosRot             = mainCamera.GetComponent <LogPosRot>();
        mappingMaterial       = spatialMapping.GetComponent <SpatialMappingManager>();
        objectSurfaceObserver = spatialMapping.GetComponent <ObjectSurfaceObserver>();
        var meshmanager = GetComponent <MeshManager>();

        // App always starts off
        mappingMaterial.DrawVisualMeshes = false;
    }
Ejemplo n.º 23
0
    // Use this for initialization
    void Start()
    {
        spatialUnderstanding = spatialUnderstandingObj.GetComponent <SpatialUnderstanding>();
        customMesh           = spatialUnderstanding.UnderstandingCustomMesh;
        mappingManager       = spatialMappingObj.GetComponent <SpatialMappingManager>();

        recognizer         = new GestureRecognizer();
        recognizer.Tapped += (args) =>
        {
            OnTapped();
        };
        recognizer.StartCapturingGestures();
    }
Ejemplo n.º 24
0
    private void OnPlanesComplete(object source, System.EventArgs args)
    {
        SpatialMappingManager mapper = SpatialMappingManager.Instance;

        if (!visualizeSpatialMeshes)
        {
            mapper.SetSurfaceMaterial(spatialMeshOcclusionMaterial);
        }
        SurfacePlaneDeformationManager.Instance.SetSpatialMeshFilters(mapper.GetMeshFilters());
        if (visualizeSurfacePlanes)
        {
            SetPlanesVisible(true);
        }
    }
Ejemplo n.º 25
0
    void Start()
    {
        currentState  = SystemState.Normal;
        anchorControl = GetComponent <AnchorControl>();
        if (anchorControl == null)
        {
            Debug.LogError("AnchorControl not found");
        }

        spatialMappingManager = SpatialMappingManager.Instance;
        if (spatialMappingManager == null)
        {
            Debug.LogError("This script expects that you have a SpatialMappingManager component in your scene.");
        }
    }
Ejemplo n.º 26
0
    /// <summary>
    /// Removes all anchors from the scene and deletes them from the anchor store.
    /// </summary>
    public void RemoveAllAnchors()
    {
#if !UNITY_WSA || UNITY_EDITOR
        Debug.LogWarning("World Anchor Manager does not work for this build. RemoveAnchor will not be called.");
#else
        SpatialMappingManager spatialMappingManager = SpatialMappingManager.Instance;

        // This case is unexpected, but just in case.
        if (AnchorStore == null)
        {
            Debug.LogWarning("[WorldAnchorManager] RemoveAllAnchors called before anchor store is ready.");
        }

        var anchors = FindObjectsOfType <WorldAnchor>();

        if (anchors == null)
        {
            return;
        }

        for (var i = 0; i < anchors.Length; i++)
        {
            // Don't remove SpatialMapping anchors if exists
            if (spatialMappingManager != null && anchors[i].gameObject.transform.parent.gameObject == spatialMappingManager.gameObject)
            {
                continue;
            }

            // Let's check to see if there are anchors we weren't accounting for.
            // Maybe they were created without using the WorldAnchorManager.
            if (!AnchorGameObjectReferenceList.ContainsKey(anchors[i].name))
            {
                Debug.LogWarning("[WorldAnchorManager] Removing an anchor that was created outside of the WorldAnchorManager.  Please use the WorldAnchorManager to create or delete anchors.");
                if (AnchorDebugText != null)
                {
                    AnchorDebugText.text += string.Format("\nRemoving an anchor that was created outside of the WorldAnchorManager.  Please use the WorldAnchorManager to create or delete anchors.");
                }
            }

            LocalAnchorOperations.Enqueue(new AnchorAttachmentInfo
            {
                AnchorName         = anchors[i].name,
                AnchoredGameObject = anchors[i].gameObject,
                Operation          = AnchorOperation.Delete
            });
        }
#endif
    }
Ejemplo n.º 27
0
    void Start()
    {
        GameObject SpatialMappingObject = GameObject.Find("SpatialMapping");

        onSceneMappingObserver  = SpatialMappingObject.GetComponent <SpatialMappingObserver>();
        onSceneSpatialManager   = SpatialMappingObject.GetComponent <SpatialMappingManager>();
        onSceneGeommetryDivider = SpatialMappingObject.GetComponent <ObjectSurfaceObserver>();

        onSceneMappingObserver.enabled          = false;
        onSceneSpatialManager.autoStartObserver = false;
        onSceneGeommetryDivider.enabled         = false;

        MRCam = GameObject.FindGameObjectWithTag(TAG_MAIN_CAMERA);
        informationObject.transform.position = MRCam.transform.position + MRCam.transform.forward * distanceFromCam;
        informationObject.transform.rotation = Quaternion.LookRotation(informationObject.transform.position - MRCam.transform.position, MRCam.transform.up);
    }
Ejemplo n.º 28
0
        /**
         * Use this for initialization.
         */
        private void Start()
        {
            // Variable initialization (the other variables are set by a 'SetNewData' call)
            this.valid = false;

            // Get reference to other scripts in the scene
            this.anchorManager  = WorldAnchorManager.Instance;
            this.spatialMapping = SpatialMappingManager.Instance;
            this.logger         = DebugLogger.Instance;

            // Deactivate this script if necessary components are missing
            if ((this.infoBoard == null) || (this.scanningArea == null) || (this.artwork == null) || (this.anchorManager == null) || (this.spatialMapping == null) || (this.logger == null))
            {
                Debug.LogError("RecognizedArtwork: Script references not set properly.");
                this.enabled = false;
            }
        }
Ejemplo n.º 29
0
        void InitializeRoom()
        {
            // if the spatial mapping object doesn't exist, create it
            if (spatialMappingObj == null)
            {
                InstantiateSpatialMappingPrefab();
            }

            // move the room mesh over to the spatialmappingobj
            ObjectSurfaceObserver surfaceObserver = spatialMappingObj.GetComponent <ObjectSurfaceObserver>();

            surfaceObserver.roomModel = Resources.Load <GameObject>(Constants.Folders.RoomMeshFolderPath + Constants.Names.RoomMeshName + Constants.Suffixes.RoomMeshSuffix);
            // set the material that the spatialmapping object will use to render it
            SpatialMappingManager mappingManager = spatialMappingObj.GetComponent <SpatialMappingManager>();

            mappingManager.SetSurfaceMaterial(CreateRoomMeshMaterial());
        }
Ejemplo n.º 30
0
    // Use this for initialization
    void Start()
    {
        anchorManager = WorldAnchorManager.Instance;
        anchorName    = gameObject.name;
        if (anchorManager == null)
        {
            Debug.LogError("This script expects that you have a WorldAnchorManager component in your scene.");
        }

        spatialMappingManager = SpatialMappingManager.Instance;
        if (spatialMappingManager == null)
        {
            Debug.LogError("This script expects that you have a SpatialMappingManager component in your scene.");
        }

        if (anchorManager != null && spatialMappingManager != null)
        {
            anchorManager.AttachAnchor(this.gameObject, anchorName);

            // ensures light UI is set at the proper position and rotation relative to parent

            foreach (Transform child in transform)
            {
                if (child.name == "HoloLightContainer(Clone)")
                {
                    var defaultHeight = child.localPosition.y;

                    child.localRotation = Quaternion.Euler(new Vector3(0, child.rotation.y, child.rotation.z));
                    child.localPosition = new Vector3(0, defaultHeight, 0);
                }
            }
            //if (gameObject.transform.GetChild(0)) {
            //    var child = this.gameObject.transform.GetChild(0);
            //    Debug.Log("here is child name: " + child.name);
            //    var defaultHeight = child.localPosition.y;

            //    child.localRotation = Quaternion.Euler(new Vector3(0, child.rotation.y, child.rotation.z));
            //    child.localPosition = new Vector3(0, defaultHeight, 0);
            //};
        }
        else
        {
            // If we don't have what we need to proceed, we may as well remove ourselves.
            Destroy(this);
        }
    }
Ejemplo n.º 31
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();
    }