Developer Guide

Tutorial: How to fix content to the screen with CraftAR AR SDK

icon Date Developer Guide

icon Date Dec 17, 2020

icon author Catchoom Team

icon folder , , ,

This section applies only to the Augmented Reality SDK v4 +. Are you still using an older version? Previous versions of the SDKs will not receive updates anymore. If you need help transitioning to the newer version, you can get support through our support channel.

In version 3 of the Augmented Reality SDK, we’ve introduced a new feature that allows the user to fix or attach the AR content to the screen instead of the real-world object.

In a regular Augmented Reality experience, the content is attached to the reference object from the real world when your app is augmenting the scene. While tracking the real-world object, the user can move around and interact with the Augmented Reality experience from different viewpoints.

This article shows how to use the off-tracking rendering feature of the Augmented Reality SDK. With this feature, you can indicate that an AR item’s contents are still drawn on the screen even if the reference object is not being tracked.

In order to get familiar with this functionality, we recommend following the example described below (for iOS and for Android), which is also available open-source from our examples project in Github (for iOS and Android). The example consists of a view that renders a regular AR scene and a button to attach AR contents to the screen by freezing them when we press the button. After scanning the reference image, the AR content is loaded. Clicking on the attach icon forces the content to stay fixed on the screen in the last rendered pose.

Fix content on iOS

In order to manage the attachment of a particular AR experience, we need to keep a reference to the corresponding AR item. We add the following attributes to the AR_ProgrammaticallyViewController class to control the state of the contents (attached or not attached):

When the reference image is recognized, we receive all the information of the AR item (together with its contents). This is the right moment to create the reference to that object. In this example, we modify didGetSearchResults in order to do that. The following is a snippet assuming that the contents associated with the AR item are local to the app and consist of an image file named “AR_programmatically_content.png”.

Finally, we add the behavior to our attach button. This button has been added to the storyboard and connected to the following method called attachContents, which is an IBAction of the viewController.

Fix content on Android

In order to manage the attachment of a particular AR experience, we need to keep a reference to the corresponding AR item. We add the following attributes to the ARProgrammaticallyActivity.java class to control the state of the contents (attached or not attached):

When the reference image is recognized, we receive all the information of the AR item (together with its contents). This is the right moment to create the reference to that object. We can modify searchCompleted in order to do that. The following is a snippet assuming that the contents associated with the AR item are local to the app and consist of an image file named “AR_programmatically_content.png”.

Finally, we add the behavior for our Attached button. This button has been added to the layout and the ARProgrammaticallyActivity.java activity has been set as the onClick listener.

Related Posts in Developer Guide