{"_id":"5ba1a04d4f89f700039d85cc","project":"5a065a6134873d0010b396ab","version":{"_id":"5ba1a04d4f89f700039d85d0","project":"5a065a6134873d0010b396ab","__v":0,"forked_from":"5b8469fbe0a7ea00039d96b8","createdAt":"2018-04-18T18:19:34.288Z","releaseDate":"2018-04-18T18:19:34.288Z","categories":["5ba1a04d4f89f700039d8594","5ba1a04d4f89f700039d8595","5ba1a04d4f89f700039d8596","5b05923ea5a2f9000357b452","5b05f793c2c86c0003cbe414","5ba1a04d4f89f700039d8597","5ba1a04d4f89f700039d8598","5ba1a04d4f89f700039d8599"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.11.0","version":"1.11.0"},"category":{"_id":"5ba1a04d4f89f700039d8597","project":"5a065a6134873d0010b396ab","version":"5ba1a04d4f89f700039d85d0","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2018-05-24T14:09:29.251Z","from_sync":false,"order":2,"slug":"develop-ar","title":"Augmented Reality"},"user":"579a69d53de0a217007eda56","githubsync":"","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2018-05-24T14:12:47.842Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":5,"body":"AR becomes much more engaging when you can share content with others. Imagine walking around a virtual museum, where other participants curate the pictures on the walls, playing a table-top game on the kitchen table where everyone sees the same pieces, or decorating your new apartment with virtual furniture collaboratively with friends. \n\nThese *shared* and *collaborative* experiences, and much more, are possible when you take AR to the cloud. Viro provides some integrations and building blocks for the AR Cloud, with more coming soon.\n[block:api-header]\n{\n  \"title\": \"Cloud Anchors\"\n}\n[/block]\nViro utilizes Google's Cloud Anchor system to enable sharing anchors with other users. Normally in Viro, each each [ARNode][1] (and its underlying [ARAnchor][2]) serves as a latch connecting a virtual point in the user's virtual coordinate system with a point in the real-world. With cloud support, ARNodes go further: they synchronize points across *multiple* virtual worlds, anchoring them all to the same real-world position.\n\nUsing Viro you can take any ARNode's anchor and [host][3] it in the Google Cloud. Doing so will return a Cloud Anchor Identifier. If you transmit that identifier to other clients, they can use it to [resolve][4] that anchor on their own devices, and same ARNode will become available to them.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Google API Key Required\",\n  \"body\": \"To use cloud anchors, you must have a Google AR API key in the application section of your AndroidManifest. This is of the form:\\n\\n <meta-data android:name=\\\"com.google.android.ar.API_KEY\\\"\\n            android:value=\\\"Your-API-Key\\\" />\"\n}\n[/block]\n## Hosting Cloud Anchors\n\nThe example below shows how to host an ARNode that we've created from a [hit result][5]. In the example, A 3D model of a star is added to the hit result we find, and then the ARNode is hosted. The [CloudAnchorHostListener][6]'s onSuccess callback is invoked when the node is successfully hosted. From here, you can take the Cloud Identifier and send it to other clients.\n\n[1]:https://developer.viromedia.com/virocore/reference/com/viro/core/ARNode.html\n[2]:https://developer.viromedia.com/virocore/reference/com/viro/core/ARAnchor.html\n[3]:https://developer.viromedia.com/virocore/reference/com/viro/core/ARScene.html#hostCloudAnchor(com.viro.core.ARAnchor,%20com.viro.core.ARScene.CloudAnchorHostListener)\n[4]:https://developer.viromedia.com/virocore/reference/com/viro/core/ARScene.html#resolveCloudAnchor(java.lang.String,%20com.viro.core.ARScene.CloudAnchorResolveListener)\n[5]:https://developer.viromedia.com/virocore/reference/com/viro/core/ARHitTestResult.html\n[6]:https://developer.viromedia.com/virocore/reference/com/viro/core/ARScene.CloudAnchorHostListener.html\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"final ViroViewARCore view = ...; //Assume this has been initialized\\nfinal ARScene scene = ...; // Assume this has been initialized\\n\\nPoint point = new Point((int) (view.getWidth() / 2.0), \\n                        (int) (view.getHeight() / 2.0f));\\n\\nview.performARHitTest(point, new ARHitTestListener() {\\n    :::at:::Override\\n    public void onHitTestFinished(ARHitTestResult[] results) {\\n        for (ARHitTestResult result : results) {\\n            ARNode node = result.createAnchoredNode();\\n          \\n            // ARCore may fail to create an anchor\\n            if (node == null) {\\n                continue;\\n            }\\n\\n            // Add a star model to the Node, so the user sees a star where\\n            // the hit test landed\\n            final Object3D star = loadStarModel();\\n            node.addChildNode(star);\\n\\n            scene.hostCloudAnchor(node.getAnchor(), new ARScene.CloudAnchorHostListener() {\\n                @Override\\n                public void onSuccess(ARAnchor anchor, ARNode arNode) {\\n                    String cloundId = anchor.getCloudAnchorId());\\n                    // Send the cloud ID to other clients\\n                }\\n\\n                @Override\\n                public void onFailure(String error) {}\\n            });\\n        }\\n    }\\n});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nTo transmit the Cloud Identifier to other clients, you can use any number of technologies, including [AWS AppSync](https://aws.amazon.com/appsync/) or [Google's Firebase Realtime Database](https://www.google.com/search?q=firebase+realtime+database&rlz=1C5CHFA_enUS740US740&oq=firebase+realtime+database&aqs=chrome.0.0j69i60l3j0l2.2637j0j7&sourceid=chrome&ie=UTF-8). Or, you can roll your own solution.\n\n## Resolving Cloud Anchors\n\nOnce you've transmitted the Cloud Identifier to other clients, the next step is to get those clients to download and synchronize -- or *resolve* -- the ARNode onto their own devices. This is fairly simple, as shown in the code snippet below. In this example, when the ARNode is successfully resolved, we add a 3D object of a star to it. When finished, this client's scene should look just like that of the first client above: both have the same ARNode, to which each has added the same 3D star.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"final ARScene scene = (ARScene) mScene;\\nfor (int i = 0; i < mHostedAnchors.size(); i++) {\\n    String cloudAnchorId = mHostedAnchors.get(i);\\n    scene.resolveCloudAnchor(cloudAnchorId, new ARScene.CloudAnchorResolveListener() {\\n        @Override\\n        public void onSuccess(final ARAnchor anchor, final ARNode arNode) {\\n            // Load a 3D model of a star\\n            final Object3D star = loadStarModel();\\n            arNode.addChildNode(star);\\n        }\\n\\n        @Override\\n        public void onFailure(String error) {\\n        }\\n    });\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"Note that in the examples above, the *content* of the ARNodes was not synchronized: we had to manually add the same 3D star to the ARNode on each client. Viro does not yet support content synchronization.\",\n  \"title\": \"Content Sync\"\n}\n[/block]","excerpt":"","slug":"ar-cloud","type":"basic","title":"AR Cloud"}
AR becomes much more engaging when you can share content with others. Imagine walking around a virtual museum, where other participants curate the pictures on the walls, playing a table-top game on the kitchen table where everyone sees the same pieces, or decorating your new apartment with virtual furniture collaboratively with friends. These *shared* and *collaborative* experiences, and much more, are possible when you take AR to the cloud. Viro provides some integrations and building blocks for the AR Cloud, with more coming soon. [block:api-header] { "title": "Cloud Anchors" } [/block] Viro utilizes Google's Cloud Anchor system to enable sharing anchors with other users. Normally in Viro, each each [ARNode][1] (and its underlying [ARAnchor][2]) serves as a latch connecting a virtual point in the user's virtual coordinate system with a point in the real-world. With cloud support, ARNodes go further: they synchronize points across *multiple* virtual worlds, anchoring them all to the same real-world position. Using Viro you can take any ARNode's anchor and [host][3] it in the Google Cloud. Doing so will return a Cloud Anchor Identifier. If you transmit that identifier to other clients, they can use it to [resolve][4] that anchor on their own devices, and same ARNode will become available to them. [block:callout] { "type": "warning", "title": "Google API Key Required", "body": "To use cloud anchors, you must have a Google AR API key in the application section of your AndroidManifest. This is of the form:\n\n <meta-data android:name=\"com.google.android.ar.API_KEY\"\n android:value=\"Your-API-Key\" />" } [/block] ## Hosting Cloud Anchors The example below shows how to host an ARNode that we've created from a [hit result][5]. In the example, A 3D model of a star is added to the hit result we find, and then the ARNode is hosted. The [CloudAnchorHostListener][6]'s onSuccess callback is invoked when the node is successfully hosted. From here, you can take the Cloud Identifier and send it to other clients. [1]:https://developer.viromedia.com/virocore/reference/com/viro/core/ARNode.html [2]:https://developer.viromedia.com/virocore/reference/com/viro/core/ARAnchor.html [3]:https://developer.viromedia.com/virocore/reference/com/viro/core/ARScene.html#hostCloudAnchor(com.viro.core.ARAnchor,%20com.viro.core.ARScene.CloudAnchorHostListener) [4]:https://developer.viromedia.com/virocore/reference/com/viro/core/ARScene.html#resolveCloudAnchor(java.lang.String,%20com.viro.core.ARScene.CloudAnchorResolveListener) [5]:https://developer.viromedia.com/virocore/reference/com/viro/core/ARHitTestResult.html [6]:https://developer.viromedia.com/virocore/reference/com/viro/core/ARScene.CloudAnchorHostListener.html [block:code] { "codes": [ { "code": "final ViroViewARCore view = ...; //Assume this has been initialized\nfinal ARScene scene = ...; // Assume this has been initialized\n\nPoint point = new Point((int) (view.getWidth() / 2.0), \n (int) (view.getHeight() / 2.0f));\n\nview.performARHitTest(point, new ARHitTestListener() {\n @Override\n public void onHitTestFinished(ARHitTestResult[] results) {\n for (ARHitTestResult result : results) {\n ARNode node = result.createAnchoredNode();\n \n // ARCore may fail to create an anchor\n if (node == null) {\n continue;\n }\n\n // Add a star model to the Node, so the user sees a star where\n // the hit test landed\n final Object3D star = loadStarModel();\n node.addChildNode(star);\n\n scene.hostCloudAnchor(node.getAnchor(), new ARScene.CloudAnchorHostListener() {\n @Override\n public void onSuccess(ARAnchor anchor, ARNode arNode) {\n String cloundId = anchor.getCloudAnchorId());\n // Send the cloud ID to other clients\n }\n\n @Override\n public void onFailure(String error) {}\n });\n }\n }\n});", "language": "java" } ] } [/block] To transmit the Cloud Identifier to other clients, you can use any number of technologies, including [AWS AppSync](https://aws.amazon.com/appsync/) or [Google's Firebase Realtime Database](https://www.google.com/search?q=firebase+realtime+database&rlz=1C5CHFA_enUS740US740&oq=firebase+realtime+database&aqs=chrome.0.0j69i60l3j0l2.2637j0j7&sourceid=chrome&ie=UTF-8). Or, you can roll your own solution. ## Resolving Cloud Anchors Once you've transmitted the Cloud Identifier to other clients, the next step is to get those clients to download and synchronize -- or *resolve* -- the ARNode onto their own devices. This is fairly simple, as shown in the code snippet below. In this example, when the ARNode is successfully resolved, we add a 3D object of a star to it. When finished, this client's scene should look just like that of the first client above: both have the same ARNode, to which each has added the same 3D star. [block:code] { "codes": [ { "code": "final ARScene scene = (ARScene) mScene;\nfor (int i = 0; i < mHostedAnchors.size(); i++) {\n String cloudAnchorId = mHostedAnchors.get(i);\n scene.resolveCloudAnchor(cloudAnchorId, new ARScene.CloudAnchorResolveListener() {\n @Override\n public void onSuccess(final ARAnchor anchor, final ARNode arNode) {\n // Load a 3D model of a star\n final Object3D star = loadStarModel();\n arNode.addChildNode(star);\n }\n\n @Override\n public void onFailure(String error) {\n }\n });\n}", "language": "java" } ] } [/block] [block:callout] { "type": "info", "body": "Note that in the examples above, the *content* of the ARNodes was not synchronized: we had to manually add the same 3D star to the ARNode on each client. Viro does not yet support content synchronization.", "title": "Content Sync" } [/block]