Exemplo n.º 1
0
 /**
  * Set the data for this info board.
  *
  * @param recognizedArtwork the recognized artwork information
  * @param placement         initial info board placement
  * @param artwork           data artwork for this info board
  * @param middlePoint       middle point of the recognized artwork
  */
 public void SetData(RecognizedArtwork recognizedArtwork, InfoBoardPlacement placement, Artwork artwork, Vector3 middlePoint)
 {
     this.anchorManager     = WorldAnchorManager.Instance;
     this.logger            = DebugLogger.Instance;
     this.infoCanvas        = InfoCanvas.Instance;
     this.arrows            = UIArrows.Instance;
     this.recognizedArtwork = recognizedArtwork;
     this.currentPlacement  = placement;
     this.artwork           = artwork;
     this.middlePoint       = middlePoint;
     StartCoroutine(Initialize());
 }
Exemplo n.º 2
0
        /**
         * Update is called once per frame.
         */
        private void Update()
        {
            // Load world anchors
            if (!this.worldAnchorsLoaded)
            {
                this.LoadWorldAnchors();
            }

            // Start the object recognition if the data library as well as the world anchors are loaded
            if (this.worldAnchorsLoaded && this.dataLoader.DataLoadingFinished && !this.ObjectRecognitionConfigured && this.initializer.ReadyToStartRecognition)
            {
                this.InitializeData();

                // Start cached object recognition
                if (this.CurrentScanState == ScanState.UserMode)
                {
                    this.StartCachedRecognition();
                }

                this.ObjectRecognitionConfigured = true;
            }

            // Instantiate corresponding GameObjects for the newly recognized artworks
            if (this.newData)
            {
                bool validationFinished = true;
                foreach (KeyValuePair <int, Recognition> pair in this.recognitions)
                {
                    int         id   = pair.Key;
                    Recognition info = pair.Value;

                    // Ignore this artwork if its validation process has already finished
                    if (info.ValidationFinished)
                    {
                        continue;
                    }

                    // Check if the recognized artwork was already instantiated
                    if (this.instantiatedArtworks.ContainsKey(id))
                    {
                        GameObject obj = this.instantiatedArtworks[id];

                        // Check if the data was valid
                        int valid = obj.GetComponent <RecognizedArtwork>().IsValid();

                        // Artwork validation is not finished yet
                        if (valid == -1)
                        {
                            validationFinished = false;

                            // Artwork is valid
                        }
                        else if (valid == 1)
                        {
                            this.logger.Log("Artwork " + id + ": valid");
                            info.ValidationFinished = true;
                            if (this.IsIdEligible(id))
                            {
                                this.recognizedArtworks[id] = true;
                            }
#if ENABLE_WINMD_SUPPORT
                            // Remove artwork from further object recognition cycles
                            if ((this.CurrentScanState != ScanState.LiveScan) || (this.liveScanProcessing == ImageProcessingMethod.FEATURE_MATCHING))
                            {
                                this.matchRecognition.removeModel(id);
                                int count = this.matchRecognition.getModels().Count;
                                this.logger.Log("Count: " + count);
                                this.capture.IsActive(count > 0);
                                this.logger.Log("Artwork " + id + " removed from Companion.");
                                if ((this.CurrentScanState == ScanState.Caching) && (count == 0))
                                {
                                    this.infoCanvas.SetInfoText("All artworks scanned. <i>Bloom</i> to quit.", true);
                                }
                                else if (this.CurrentScanState == ScanState.Caching)
                                {
                                    this.infoCanvas.SetInfoText("Artwork #" + id + " scanned. " + count + " artworks left.");
                                }
                            }
#endif
                            // Artwork is not valid
                        }
                        else
                        {
                            this.logger.Log("Artwork " + id + ": not valid");
                            info.ValidationFinished = true;
                            // Destroy the already instantiated artwork
                            Destroy(obj);
                            this.instantiatedArtworks.Remove(id);
                        }

                        // Instantiate a recognized artwork
                    }
                    else
                    {
                        this.logger.Log("Artwork " + id + ": instantiate new artwork");
                        GameObject        artwork       = Instantiate(this.artwork);
                        RecognizedArtwork artworkScript = artwork.GetComponent <RecognizedArtwork>();
                        artworkScript.SetNewData(info);
                        validationFinished = false;
                        this.instantiatedArtworks.Add(id, artwork);
                    }
                }

                // Validation process finished
                if (validationFinished)
                {
#if COMP_DEBUG_IMAGE
                    // Instantiate the photo in the scene
                    GameObject debugPhoto = Instantiate(this.debugPhoto, this.resultImage.WorldSpaceMiddle, Utils.CreateLookAtRotation(this.resultImage.WorldSpaceMiddle, this.resultImage.WorldSpaceCamera, false));
                    this.resultImage.DisplayImage(debugPhoto.GetComponentInChildren <UnityEngine.UI.Image>().gameObject, this.cameraResolution);
#endif
                    this.newData = false;
                    this.recognitions.Clear();
                    this.ProcessingStopped();
                }
            }

            // Perform feature matching model operations
            if (this.ObjectRecognitionConfigured && !this.isPerformingFmModelOperation && (this.fmModelOperations.Count > 0))
            {
                this.isPerformingFmModelOperation = true;
                StartCoroutine(this.DoFeatureModelOperation(this.fmModelOperations.Dequeue()));
            }
        }