Ejemplo n.º 1
0
        private void ShowPatientDetails(ARReferenceImage detectedImage, SCNNode node)
        {
            // Highlight the QR Code?
            var width     = detectedImage.PhysicalSize.Width;
            var length    = detectedImage.PhysicalSize.Height;
            var planeNode = new PlaneNode(0, width, length, new SCNVector3(0, 0, 0), "");

            planeNode.Opacity = 1f;
            float angle = (float)(-Math.PI / 2);

            planeNode.EulerAngles = new SCNVector3(angle, 0, 0);
            //node.AddChildNode(planeNode);

            // Get and Show information panels
            foreach (var informationPanelNode in GetPatientInformationPanels())
            {
                var waitAction     = SCNAction.Wait(0.1 * informationPanelNode.Number);
                var fadeInAction   = SCNAction.FadeIn(1);
                var actionSequence = SCNAction.Sequence(new[] { waitAction, fadeInAction });

                // Not sure I can run actions before adding. May have to add, then run.
                informationPanelNode.RunAction(actionSequence);

                informationPanelNode.EulerAngles = new SCNVector3(angle, 0, 0);

                node.AddChildNode(informationPanelNode);
            }
        }
Ejemplo n.º 2
0
        private SCNNode CreatePlane(ARReferenceImage detectecImage)
        {
            nfloat width  = detectecImage.PhysicalSize.Width;
            nfloat height = detectecImage.PhysicalSize.Height;

            SCNMaterial material = new SCNMaterial();

            material.Diffuse.Contents = UIColor.Blue;
            material.DoubleSided      = false;

            SCNPlane geometry = SCNPlane.Create(width, height);

            geometry.Materials = new[] { material };

            SCNNode planeNode = new SCNNode
            {
                Geometry = geometry,
                Position = new SCNVector3(0, 0, 0)
            };

            float angle = (float)(-Math.PI / 2);

            planeNode.EulerAngles = new SCNVector3(angle, 0, 0);

            return(planeNode);
        }
Ejemplo n.º 3
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            var imageFromDevice              = UIImage.FromBundle("IMG_8230.JPG");
            var imageFromDeviceCG            = imageFromDevice.CGImage;
            var orientation                  = CGImagePropertyOrientation.Up;
            var imageFromDevicePhysicalWidth = new nfloat(0.085);
            var arDeviceImage                = new ARReferenceImage(imageFromDeviceCG, orientation, imageFromDevicePhysicalWidth);

            var imageFromURL   = FromUrl("https://d2gg9evh47fn9z.cloudfront.net/800px_COLOURBOX21927671.jpg");
            var imageFromURLCG = imageFromURL.CGImage;
            //var orientation = CGImagePropertyOrientation.Up;
            var imageFromURLPhysicalWidth = new nfloat(0.145);
            var arURLImage = new ARReferenceImage(imageFromURLCG, orientation, imageFromURLPhysicalWidth);

            var arImageSet = new NSSet <ARReferenceImage>(arURLImage, arDeviceImage);

            var configuration = new ARWorldTrackingConfiguration();

            configuration.DetectionImages = arImageSet;

            //// Run the view's session
            //var options = new ARSessionRunOptions();
            //options = ARSessionRunOptions.RemoveExistingAnchors;
            //SceneView.Session.Run(configuration, options);

            //// Configure ARKit
            //var config = new ARWorldTrackingConfiguration();
            //config.PlaneDetection = ARPlaneDetection.Horizontal;

            // This method is called subsequent to `ViewDidLoad` so we know `scnView` is instantiated
            scnView.Session.Run(configuration, ARSessionRunOptions.RemoveExistingAnchors);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Images that the app will detect
        /// </summary>
        /// <returns></returns>
        private NSSet <ARReferenceImage> GetDetectionImages()
        {
            var i   = UIImage.FromBundle("marker_image").CGImage;
            var r   = new ARReferenceImage(i, ImageIO.CGImagePropertyOrientation.Up, 0.07f);
            var set = new NSSet <ARReferenceImage>(r);

            return(set);
        }
Ejemplo n.º 5
0
        private SCNNode CreateImagePlaneNode(ARReferenceImage detectedImage)
        {
            nfloat width  = detectedImage.PhysicalSize.Width;
            nfloat length = detectedImage.PhysicalSize.Height;
            ArImageRecognitionPlaneNode imagePlaneNode = new ArImageRecognitionPlaneNode(width, length, new SCNVector3(0, 0, 0), UIColor.Blue);

            return(imagePlaneNode);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Load the resources for the scene
        /// </summary>
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);
            var configuration   = new ARImageTrackingConfiguration();
            var referenceImages = ARReferenceImage.GetReferenceImagesInGroup("RetroGamesGoImages", null);

            configuration.TrackingImages = referenceImages;
            configuration.MaximumNumberOfTrackedImages = 100;
            this.sceneView.Session.Run(configuration);
        }
Ejemplo n.º 7
0
        public override void ViewWillAppear(bool animated)
        {
            var configuration = new ARImageTrackingConfiguration();

            referenceImages = ARReferenceImage.GetReferenceImagesInGroup("Test", null);

            configuration.TrackingImages = referenceImages;

            this.sceneView.Session.Run(configuration);
        }
Ejemplo n.º 8
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            NSSet <ARReferenceImage> images = ARReferenceImage.GetReferenceImagesInGroup("AR Resources", null);

            sceneView.Session.Run(new ARWorldTrackingConfiguration
            {
                AutoFocusEnabled       = true,
                LightEstimationEnabled = true,
                DetectionImages        = images
            }, ARSessionRunOptions.ResetTracking | ARSessionRunOptions.RemoveExistingAnchors);
        }
Ejemplo n.º 9
0
        public override void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            if (anchor is ARImageAnchor imageAnchor)
            {
                ARReferenceImage image  = imageAnchor.ReferenceImage;
                nfloat           width  = image.PhysicalSize.Width;
                nfloat           height = image.PhysicalSize.Height;

                PlaneNode planeNode = new PlaneNode(width, height, new SCNVector3(0, 0, 0), UIColor.Red);
                float     angle     = (float)(-Math.PI / 2);
                planeNode.EulerAngles = new SCNVector3(angle, 0, 0);
                node.AddChildNode(planeNode);
            }
        }
Ejemplo n.º 10
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            var detectionImages = ARReferenceImage.GetReferenceImagesInGroup("AR Resources", null);

            this.sceneView.Session.Run(new ARWorldTrackingConfiguration
            {
                AutoFocusEnabled             = true,
                PlaneDetection               = ARPlaneDetection.Horizontal | ARPlaneDetection.Vertical,
                LightEstimationEnabled       = true,
                WorldAlignment               = ARWorldAlignment.Gravity,
                DetectionImages              = detectionImages,
                MaximumNumberOfTrackedImages = 1
            }, ARSessionRunOptions.ResetTracking | ARSessionRunOptions.RemoveExistingAnchors);
        }
Ejemplo n.º 11
0
        private void RunSession()
        {
            config?.Dispose();
            sceneView?.Delegate?.Dispose();

            config = new ARWorldTrackingConfiguration();
            config.AutoFocusEnabled             = true;
            config.PlaneDetection               = ARPlaneDetection.Horizontal | ARPlaneDetection.Vertical;
            config.LightEstimationEnabled       = true;
            config.WorldAlignment               = ARWorldAlignment.GravityAndHeading;
            config.DetectionImages              = ARReferenceImage.GetReferenceImagesInGroup("AR Resources", null);
            config.MaximumNumberOfTrackedImages = 1;

            sceneView.Session.Run(config, ARSessionRunOptions.ResetTracking | ARSessionRunOptions.RemoveExistingAnchors);
            sceneView.Delegate = new IrScnDelegate();
        }
Ejemplo n.º 12
0
        public override void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            ARImageAnchor imageAnchor = anchor as ARImageAnchor;

            if (imageAnchor == null)
            {
                return;
            }

            ARReferenceImage detectecImage = imageAnchor.ReferenceImage;

            if (detectecImage.Name != "AR_DevsDna_Card")
            {
                return;
            }

            node.AddChildNode(CreatePlane(detectecImage));
        }
Ejemplo n.º 13
0
        public override void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            ARImageAnchor imageAnchor = anchor as ARImageAnchor;

            if (imageAnchor == null)
            {
                return;
            }

            //TODO 6.2 Añadiendo elementos sobre la imagen detectada
            ARReferenceImage detectedImage = imageAnchor.ReferenceImage;

            if (detectedImage.Name != "AR_DevsDNA_Card")
            {
                return;
            }

            node.AddChildNode(model3D ? Create3DNode() : CreateImagePlaneNode(detectedImage));
        }
Ejemplo n.º 14
0
    public void setARImage(ARReferenceImage img)
    {
        if (quad == null)
        {
            foreach (Transform child in transform)
            {
                if (child == transform)
                {
                    continue;
                }
                quad = child.gameObject;
                break;
            }
        }
        name = "Quad_" + img.imageName;
        quad.transform.localScale = new Vector3(img.physicalSize, img.physicalSize, img.physicalSize);

        quad.GetComponent <Renderer>().material.SetTexture("_MainTex", img.imageTexture);
    }
    static void AddReferenceImageToResourceGroup(ARReferenceImage arri, string parentFolderFullPath, string projectRelativePath, PBXProject project)
    {
        ARResourceContents resourceContents = new ARResourceContents();

        resourceContents.info         = new ARResourceInfo();
        resourceContents.info.author  = "xcode";
        resourceContents.info.version = 1;

        resourceContents.images           = new ARResourceImage[1];
        resourceContents.images [0]       = new ARResourceImage();
        resourceContents.images [0].idiom = "universal";

        resourceContents.properties       = new ARResourceProperties();
        resourceContents.properties.width = arri.physicalSize;

        //add folder for reference image
        string folderToCreate        = arri.imageName + ".arreferenceimage";
        string folderFullPath        = Path.Combine(parentFolderFullPath, folderToCreate);
        string projectRelativeFolder = Path.Combine(projectRelativePath, folderToCreate);

        Directory.CreateDirectory(folderFullPath);
        project.AddFolderReference(folderFullPath, projectRelativeFolder);

        //copy file from texture asset
        string imagePath     = AssetDatabase.GetAssetPath(arri.imageTexture);
        string imageFilename = Path.GetFileName(imagePath);
        var    dstPath       = Path.Combine(folderFullPath, imageFilename);

        File.Copy(imagePath, dstPath, true);
        project.AddFile(dstPath, Path.Combine(projectRelativeFolder, imageFilename));
        resourceContents.images [0].filename = imageFilename;

        //add contents.json file
        string contentsJsonPath = Path.Combine(folderFullPath, "Contents.json");

        File.WriteAllText(contentsJsonPath, JsonUtility.ToJson(resourceContents, true));
        project.AddFile(contentsJsonPath, Path.Combine(projectRelativeFolder, "Contents.json"));
    }
Ejemplo n.º 16
0
        private void RunSession()
        {
            config?.Dispose();
            sceneView?.Delegate?.Dispose();

            sceneView.DebugOptions = ARSCNDebugOptions.ShowFeaturePoints;

            //TODO 6.1 Configurando detección de imágenes
            config = new ARWorldTrackingConfiguration();
            config.AutoFocusEnabled             = true;
            config.PlaneDetection               = ARPlaneDetection.Horizontal | ARPlaneDetection.Vertical;
            config.LightEstimationEnabled       = true;
            config.WorldAlignment               = ARWorldAlignment.GravityAndHeading;
            config.DetectionImages              = ARReferenceImage.GetReferenceImagesInGroup("AR Resources", null);;
            config.MaximumNumberOfTrackedImages = 1;

            sceneView.Session.Run(config, ARSessionRunOptions.ResetTracking | ARSessionRunOptions.RemoveExistingAnchors);

            sceneView.Delegate = new ArImageRecognitionScnViewDelegate(Element.Model3D);

            //Permite añadir reflejos a los objetos de la escena
            sceneView.AutoenablesDefaultLighting = true;
        }
Ejemplo n.º 17
0
 public override ARConfiguration GetARConfiguration()
 => new ARImageTrackingConfiguration
 {
     TrackingImages = ARReferenceImage.GetReferenceImagesInGroup("cards", null),
     MaximumNumberOfTrackedImages = 4,
 };
Ejemplo n.º 18
0
 public void HandleCardRecognized(ARReferenceImage img)
 {
     Card.ImageToId(img);
 }
Ejemplo n.º 19
0
 public static string ImageToId(ARReferenceImage img)
 {
     return(img.name);
 }
Ejemplo n.º 20
0
    public void HandleCardRemoved(ARReferenceImage img)
    {
        string cardID = Card.ImageToId(img);

        outsDeck.Remove(GetCardById(cardID));
    }