This article applies only to the Augmented Reality SDK.
The Augmented Reality SDK let's 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.
This article describes how to load a 3D model that is embedded into the app on iOS and on Android. For 3D models downloaded from the cloud at run-time, you can read the separate dedicated article.
In order 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.
Loading the embedded 3D model on AndroidThe following lines show how the content is created for a 3D model called “pizza.obj” using the Android Augmented Reality SDK:
String modelUrl = (getApplicationContext().getExternalFilesDir(null) + "/pizza.obj"); CraftARContent3dmodel modelContent = new CraftARContent3dmodel(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.
Loading the embedded 3D model on iOSThe following lines show how the content is created for a 3D model called “pizza.obj” using the iOS Augmented Reality SDK:
CraftARTrackingContent3dModel* modelContent = [[CraftARTrackingContent3dModel alloc] initWithModelNamed:@"pizza" ofType:@"obj"]; [arItem addContent: modelContent];