Get Started         Best Practices         Developer Guide         FAQ        

Handle 3D models downloaded from the cloud in CraftAR

Last Updated: Apr 30, 2018
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:
  • the online web content creator and downloaded automatically once the object is recognized; or
  • embedded into your app and loaded programmatically at runtime.
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.
 

Load 3D models from CraftAR Service

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:
  • Model download: Starts as soon as the item contents are parsed.
  • Model load into memory: After the model is downloaded, the library needs to load the geometry and the textures into the memory of the graphics engine.
  • Model rendering: Once the model is loaded, the rendering starts. The model is drawn in its 3D position in the scene attached to your object (while the reference image is tracked).
 

Implementation of the handler on Android

​​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:
 
	public void setDownloadPercentHandler(CraftARContentDownloadProgressHandler handler){
		mProgressHandler = handler;
	}

With this interface, you can get updates for the following events:
 
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:
 
for (CraftARContent content : myARItem.getContents()) {
     if (content instanceof CraftARContent3dmodel) {
         ((CraftARContent3dmodel) content).setDownloadPercentHandler(myDownloadProgressHandler);
    }
}
 

Implementation of the handler on iOS

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:
 
@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:
 
NSArray* contents = [arItem allContents];
[contents enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    if ([obj isKindOfClass:[CraftARTrackingContent3dModel class]]) {
        CraftARTrackingContent3dModel * content = (CraftARTrackingContent3dModel *) obj;
        [content setDelegate: myDelegate];
    }
}];


 

Couldn't find what you were looking for?

support@catchoom.com
https://cdn.desk.com/
false
catchoom
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete