/**
         * Use this for initialization.
         */
        private void Start()
        {
            // Variable initialization
            this.state = State.Undefined;

            // Check references
            if ((this.mainText == null) || (this.infoText == null) || (this.mainMenu == null) || (this.cachedMappingButton == null) ||
                (this.remapButton == null) && (this.liveMappingButton == null) || (this.saveMeshButton == null))
            {
                Debug.Log("SpatialInfo: Script references not set properly.");
                this.enabled = false;
            }

#if UNITY_EDITOR
            this.enabled = false;
#else
            // Attach this GameObject as a listener for input click events
            if (HoloToolkit.Unity.InputModule.InputManager.IsInitialized)
            {
                HoloToolkit.Unity.InputModule.InputManager.Instance.AddGlobalListener(this.gameObject);
            }

            // Request reference to the SpatialUnderstanding instance
            this.spatialUnderstanding = SpatialUnderstanding.Instance;
            if (this.spatialUnderstanding == null)
            {
                Destroy(this.gameObject);
            }
            else
            {
                // Attach this Component as a listener for SpatialUnderstanding state changes
                this.spatialUnderstanding.ScanStateChanged += this.OnScanStateChanged;
            }
#endif
        }
Exemple #2
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);
    }
Exemple #3
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
    }
    private void Start()
    {
        spatialUnderstanding = SpatialUnderstanding.Instance;
#if UNITY_WSA
        if (gameObject.GetComponent <WorldAnchor>() == null)
        {
            gameObject.AddComponent <WorldAnchor>();
        }
#endif
    }
Exemple #5
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;
    }
Exemple #6
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();
    }
    private void Update()
    {
        // Updates
        SpatialUnderstanding g = null;

        if (!SpatialUnderstanding.IsInitialized)
        {
            g = SpatialUnderstanding.Instance;
        }

        if (SpatialUnderstanding.Instance != null)
        {
            Update_DebugDisplay();
            if (!_triggered && SpatialUnderstanding.Instance.ScanState == SpatialUnderstanding.ScanStates.Done)
            {
                _triggered = true;
                ready      = false;
            }
        }
    }
Exemple #8
0
 private void Start()
 {
     m_spatialMappingManager = SpatialMappingManager.Instance;
     m_spatialUnderstanding  = SpatialUnderstanding.Instance;
 }
        /**
         * Perform necessary calculations for the 3D asset of this artwork.
         */
        private void Perform3DAssetCalculations()
        {
            bool found = false;

#if ENABLE_WINMD_SUPPORT
            // Check if a world anchor of this artwork exists
            UnityEngine.VR.WSA.Persistence.WorldAnchorStore store = this.anchorManager.AnchorStore;
            if (store != null)
            {
                string[] ids = store.GetAllIds();

                // Try to find the world anchor of the 3D asset
                this.logger.Log("Find 3D assets's world anchor:");
                for (int index = 0; (index < ids.Length) && !found; index++)
                {
                    string anchorID = ids[index];

                    // The anchor ID should have a specific format
                    if ((anchorID.Length > ASSET_ANCHOR_PREFIX.Length) && anchorID.Substring(0, ASSET_ANCHOR_PREFIX.Length).Equals(ASSET_ANCHOR_PREFIX))
                    {
                        try {
                            int id = int.Parse(anchorID.Substring(ASSET_ANCHOR_PREFIX.Length));
                            if (id == this.artwork.artworkID)
                            {
                                this.logger.Log(" -> found: " + anchorID);
                                this._3DButton.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
                                this._3DButton.GetComponent <Button>().interactable = true;
                                found = true;
                            }
                        } catch (System.Exception ex) {
                            this.logger.Log("EXCEPTION: " + ex.Message);
                        }
                    }
                }
            }
#endif
            // Try to query SpatialUnderstanding if a world anchor was not found
            if (!found)
            {
                SpatialUnderstanding suInstance     = SpatialUnderstanding.Instance;
                ShapeDetection       shapeDetection = ShapeDetection.Instance;
                PlacementSolver      solver         = PlacementSolver.Instance;
                HoloToolkit.Unity.InputModule.InputManager inputManager = HoloToolkit.Unity.InputModule.InputManager.Instance;
                if ((suInstance != null) && (solver != null) && (shapeDetection != null) && (inputManager != null) && (suInstance.ScanState == SpatialUnderstanding.ScanStates.Done) && suInstance.AllowSpatialUnderstanding)
                {
                    switch (this.artwork.artworkID)
                    {
                    case 2:
                        inputManager.PushInputDisable();
                        this._3DButton.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
                        shapeDetection.FindTable(this.middlePoint, this.HandleArtwork2);
                        break;

                    case 3:
                        inputManager.PushInputDisable();
                        this._3DButton.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
                        solver.Query_OnFloor_NearPoint(this.middlePoint, false, this.HandleArtwork3);
                        break;
                    }
                }
            }
        }
Exemple #10
0
        static IEnumerator DoMapping()
        {
            if (SpatialInfoReady)
            {
                WorldErrors.Print("Spatial Info Already There");
                yield break;
            }

            //turn off rendering if we're not scanning, store old mode
            UnityEngine.XR.WSA.SpatialMappingRenderer             smRend   = FindObjectOfType <UnityEngine.XR.WSA.SpatialMappingRenderer>();
            UnityEngine.XR.WSA.SpatialMappingRenderer.RenderState oldState = UnityEngine.XR.WSA.SpatialMappingRenderer.RenderState.Occlusion;
            if (smRend != null)
            {
                oldState           = smRend.renderState;
                smRend.renderState = UnityEngine.XR.WSA.SpatialMappingRenderer.RenderState.None;
            }
            running = true;

            //is there an instance present?
            SpatialUnderstanding puInst = SpatialUnderstanding.Instance;

            if (puInst == null || !puInst.AllowSpatialUnderstanding)
            {
                Debug.LogError("No Spatial Understanding Instance, or not supported in build.");
                WorldErrors.Print("No Instance");
                yield break;
            }

            //can it scan?
            while (!SpatialUnderstanding.IsInitialized)
            {
                WorldErrors.Print("Not initialized");
                yield return(null);
            }

            puInst.UnderstandingCustomMesh.DrawProcessedMesh = true;

            bool requestedFinish = false;

            WorldErrors.Print("" + puInst.AutoBeginScanning + ", " + puInst.ScanState);
            if (!puInst.AutoBeginScanning && (puInst.ScanState == SpatialUnderstanding.ScanStates.ReadyToScan || puInst.ScanState == SpatialUnderstanding.ScanStates.None || puInst.ScanState == SpatialUnderstanding.ScanStates.Done))
            {
                WorldErrors.Print("Request Begin Scan");
                puInst.RequestBeginScanning();
            }

            //yield until scan automatically finishes, or it is stopped, or time runs out
            while (puInst.ScanState != SpatialUnderstanding.ScanStates.Done)
            {
                timer += Time.deltaTime;
                if (!requestedFinish && timer > targetTime)
                {
                    puInst.RequestFinishScan();
                    requestedFinish = true;
                    puInst.UnderstandingCustomMesh.DrawProcessedMesh = false;
                }
                yield return(null);
            }

            //signal we're ready to share data
            SpatialInfoReady = true;
            if (ready != null)
            {
                ready();
            }

            //reset rendering again if we have a mapping renderer
            if (smRend != null)
            {
                smRend.renderState = oldState;
            }

            running = false;
        }
 private void Start()
 {
     spatialUnderstanding = SpatialUnderstanding.Instance;
     if (gameObject.GetComponent<WorldAnchor>() == null)
     {
         gameObject.AddComponent<WorldAnchor>();
     }
 }
Exemple #12
0
        /**
         * This method is called when the user has clicked on this GameObject.
         *
         * @param eventData     input click event data
         */
        public void OnInputClicked(InputClickedEventData eventData)
        {
            if ((this.size == PaladinSizes.Small) && (!this.interpolating))
            {
#if UNITY_EDITOR
                GameObject        paladin = Instantiate(this.gameObject);
                PaladinController ctrl    = paladin.GetComponent <PaladinController>();
                ctrl.ResetSword();
                ctrl.Grow(this.transform.parent, this.gameObject);
                this.gameObject.SetActive(false);
#else
                this.anchorManager = WorldAnchorManager.Instance;
                bool found = false;

                // Check if we have already instantiated a world anchor
                if (this.assetAnchor != null)
                {
                    GameObject        paladin = Instantiate(this.gameObject, this.assetAnchor.transform);
                    PaladinController ctrl    = paladin.GetComponent <PaladinController>();
                    ctrl.ResetSword();
                    ctrl.Grow(this.assetAnchor.transform, this.gameObject);
                    this.gameObject.SetActive(false);
                    found = true;
                }
                else if (this.anchorManager != null)
                {
                    // Check if a world anchor for this asset exists
                    UnityEngine.VR.WSA.Persistence.WorldAnchorStore store = this.anchorManager.AnchorStore;
                    if (store != null)
                    {
                        string[] ids = store.GetAllIds();
                        for (int index = 0; (index < ids.Length) && !found; index++)
                        {
                            if (ids[index].Equals(ANCHOR_ID))
                            {
                                this.assetAnchor = Instantiate(this.worldAnchorParent);
                                this.anchorManager.AttachAnchor(this.assetAnchor, ANCHOR_ID);
                                GameObject        paladin = Instantiate(this.gameObject, this.assetAnchor.transform);
                                PaladinController ctrl    = paladin.GetComponent <PaladinController>();
                                ctrl.ResetSword();
                                ctrl.Grow(this.assetAnchor.transform, this.gameObject);
                                this.gameObject.SetActive(false);
                                found = true;
                            }
                        }
                    }
                }

                // Try to query SpatialUnderstanding if a world anchor was not found
                if (!found && (this.anchorManager != null))
                {
                    SpatialUnderstanding suInstance = SpatialUnderstanding.Instance;
                    PlacementSolver      solver     = PlacementSolver.Instance;
                    if ((suInstance != null) && (solver != null) && InputManager.IsInitialized && (suInstance.ScanState == SpatialUnderstanding.ScanStates.Done) && suInstance.AllowSpatialUnderstanding)
                    {
                        InputManager.Instance.PushInputDisable();
                        solver.Query_OnFloor_NearPoint(this.transform.parent.position, false, this.HandlePlacementQuery);
                    }
                }
#endif
            }
            else if ((this.size == PaladinSizes.Big) && (!this.interpolating))
            {
                this.Die();
            }
        }