For both options, the Android Augmented Reality SDK provides means to control the loading process. Read below about how to:
Inside the online web content creator of CraftAR, you can add 3D models to the AR scene. Once an object is recognized, the SDK starts downloading all the contents that you set online. Once downloaded, all contents in the scene are loaded automatically by the SDK, including 3D models. This process has three steps and we provide feedback of their process through the SDK.
These are the three steps taken to load 3D models in the SDK, once the object (item in the service database) has been recognized:
The SDK provides an interface to track a model’s load progress and status. A handler can be set to the 3D model contents that will receive these updates:
1 2 3 4 5 |
public void setDownloadPercentHandler(CraftARContentDownloadProgressHandler handler){ mProgressHandler = handler; } |
With this interface, you can get updates for the following events:
1 2 3 4 5 6 7 8 |
public interface CraftARContentDownloadProgressHandler{ public void onDownloadProgress(CraftARTrackingContent3dmodel content,double percent); public void onDownloadFinished(CraftARTrackingContent3dmodel content); public void onContentLoaded(CraftARTrackingContent3dmodel content); public void onContentLoadFailed(CraftARTrackingContent3dmodel content); } |
In order to add the handler to your 3D model content, you need to traverse the contents in your item. This example shows how to do this:
1 2 3 4 5 6 7 8 9 |
for(CraftARTrackingContent content:item.getContents()){ switch(content.getContentType()){ case CraftARTrackingContent.ContentType.CONTENT_TYPE_3DMODEL: ((CraftARTrackingContent3dmodel)content).setDownloadPercentHandler(myDownloadProgressHandler); break; } } |
To add 3D model contents on top of the reference image programmatically is as easy as creating the 3D model with the name of the model stored in the resources of the application.
The following lines show how the content is created for a 3D model called “pizza.obj”:
1 2 3 4 5 |
String modelUrl = (getAppDataDirectory() + "/pizza.obj"); CraftARTrackingContent3dmodel modelContent = new CraftARTrackingContent3dmodel(modelUrl); myARItem.addContent(modelContent) |
In this case, the model has been added to the project inside the res/raw directory. The Android SDK takes care into copying resources in this folder to the external storage, if available.
Note: Eclipse is very restrictive about file names in the res folder. If you find issues adding your models there, you can compress them into a file named resources.zip. The SDK will uncompress that file when the application is ran for the first time.