Jul 23, 2019
Catchoom Team
3D model, Android, download, handler, iOS, streaming
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.
Important note: This article is being updated. It may not be consistent with the current version of the SDK. Please, be patient while we review our documentation.
The Augmented Reality SDK lets you render 3D models into the AR scene.
Those models can come from:
For both options, the Augmented Reality SDK provides means to know the status of the loading process.
This article describes the different stages of loading and the handlers that the SDK provides, and how to implement them on iOS and on Android. These handlers let you know the status of the streaming (downloading) and the load of the model into the memory of the device, such that it is ready for rendering. For 3D models embedded into the app, you can read the separate dedicated article.
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 Android Augmented Reality 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 |
public void setDownloadPercentHandler(CraftARContentDownloadProgressHandler handler){ mProgressHandler = handler; } |
With this interface, you can get updates for the following events:
1 2 3 4 5 6 |
public interface CraftARContentDownloadProgressHandler{ public void onDownloadProgress(CraftARContent3dmodel content,double percent); public void onDownloadFinished(CraftARContent3dmodel content); public void onContentLoaded(CraftARContent3dmodel content); public void onContentLoadFailed(CraftARContent3dmodel 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 |
for (CraftARContent content : myARItem.getContents()) { if (content instanceof CraftARContent3dmodel) { ((CraftARContent3dmodel) content).setDownloadPercentHandler(myDownloadProgressHandler); } } |
The iOS Augmented Reality SDK provides a protocol to track a model’s load progress and status. For this, you just need to set the delegate for the content. The protocol sends the following messages to the delegate:
1 2 3 4 5 6 7 8 9 |
@protocol CraftARTrackingContentLoadCallbacks @optional - (void) didProgress: (float) downloadPercent onContentDownload: (CraftARTrackingContent*) content; - (void) didFinishDownloadingContent: (CraftARTrackingContent*) content; - (void) didFinishLoadingContent: (CraftARTrackingContent*) content; - (void) didFailLoadingContent: (CraftARTrackingContent*) content withError: (CraftARSDKError *) error; @end |
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 |
NSArray* contents = [arItem allContents]; [contents enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj isKindOfClass:[CraftARTrackingContent3dModel class]]) { CraftARTrackingContent3dModel * content = (CraftARTrackingContent3dModel *) obj; [content setDelegate: myDelegate]; } }]; |