Get Started         Best Practices         Developer Guide         FAQ        

Tutorial: Customize AR Contents in CraftAR

Last Updated: Jul 23, 2019
This section applies only to the Augmented Reality SDK v4 +. For earlier versions of the Augmented Reality SDK, check out the section below

The CraftAR Augmented Reality SDK allows you to show AR Contents of different types. All AR Contents have a default behavior. In order to customize AR Contents, you need to use the default contents and override their behavior. In this article, we describe how to extend default AR Contents for Android and for iOS.

In case you’re not familiar with AR Contents, we suggest you to read the article Overview of AR Contents in CraftAR.

Android

Create your own class extending from an existing CraftARTrackingContent type (video, image, image button, or 3D model). In this example, we extend from CraftARTrackingContentImage.

public class MyImageContent extends CraftARContentImage{

    public MyImageContent(String imageUri) {
        super(imageUri);
    }

    public MyImageContent( JSONObject object) throws CraftARSDKException {
        super(object);
    }
}

Create a class extending from CraftARTrackingContentFactory. The role of this class is to indicate the SDK which type of content has to be created for a given response from the CraftAR Service. By changing the factory, you can override the assignation of the content class. In the following example, we’re overriding any object with ContentType equal to CONTENT_TYPE_IMAGE with the class that we just created (MyImageContent).

public class MyCraftARContentFactory extends CraftARContentFactory {

    @Override
    protected CraftARContent contentFromJSONObject(JSONObject object) throws CraftARSDKException {

        boolean type = true;
        int type1 = CraftARContent.contentTypeFromJSON(object);
        Object content = null;
        switch(type1) {
            case CraftARContent.ContentType.CONTENT_TYPE_IMAGE:
                content = new MyImageContent(object);
                break;
            default:
                content = super.contentFromJSONObject(object);
        }
        return (CraftARContent)content;
    }
}

Finally, set your content factory:

CraftARContentFactory.setFactory(new MyCraftARContentFactory());

Now the SDK will create contents of the type MyImageContent instead of creating them for the type CraftARImage. You can do the same for any kind of content.

iOS

Create your own class extending from an existing CraftARTrackingContent type (video, image, image button, or 3D model). In this example we extend from CraftARTrackingContentImage.

@interface MyImage : CraftARTrackingContentImage

// Your code here

@end

Indicate the SDK which type of content has to be created for a given response from the CraftAR Service:


[[CraftARContentFactoryAR factory] setContentClass:
          [MyImageContent class] fortype:SCENE_DESC_TYPE_IMAGE];

[[CraftARContentFactoryAR factory] setContentClass:
          [MyImageButton class] fortype:SCENE_DESC_TYPE_IMAGE_BUTTON];

[[CraftARContentFactoryAR factory] setContentClass:
          [MyVideoContent class] fortype:SCENE_DESC_TYPE_VIDEO];

[[CraftARContentFactoryAR factory] setContentClass:
          [My3DModelContent class] fortype:SCENE_DESC_TYPE_3DMODEL];


 
This section applies only to the Augmented Reality SDK v3 or earlier. For the Augmented Reality SDK v4 or newer, check out the section above

The CraftAR Augmented Reality SDK allows you to show AR Contents of different types. All AR Contents have a default behavior. In order to customize AR Contents, you need to use the default contents and override their behavior. In this article, we describe how to extend default AR Contents for Android and for iOS.

In case you’re not familiar with AR Contents, we suggest you to read the article Overview of AR Contents in CraftAR.

Android

Create your own class extending from an existing CraftARTrackingContent type (video, image, image button, or 3D model). In this example, we extend from CraftARTrackingContentImage.

public class MyImageContent extends CraftARTrackingContentImage {

    public MyImageContent(String imageUri){
            	super(imageUri);
    }
    public MyImageContent(JSONObject object) throws CraftARSDKException {
        super(object);
    }
}

Create a class extending from CraftARTrackingContentFactory. The role of this class is to indicate the SDK which type of content has to be created for a given response from the CraftAR Service. By changing the factory, you can override the assignation of the content class. In the following example, we’re overriding any object with ContentType equal to CONTENT_TYPE_IMAGE with the class that we just created (MyImageContent).

public class MyCraftARTrackingContentFactory extends CraftARTrackingContentFactory {
    @Override
    public CraftARTrackingContent contentFromJSONObject(JSONObject object) throws CraftARSDKException {

        int type=-1;
        type = CraftARTrackingContent.contentTypeFromJSON(object);

        CraftARTrackingContent content = null;

        switch (type) {
            case CraftARTrackingContent.ContentType.CONTENT_TYPE_IMAGE:
                content = new MyImageContent(object);
                break;
            default:
                content = super.contentFromJSONObject(object);
            }

        return content;
    }
}

Finally, set your content factory in the CraftARItemAR class.

CraftARItemAR.setContentFactory(new MyCraftARTrackingContentFactory());

Now the SDK will create contents of the type MyImageContent instead of creating them for the type CraftARImage. You can do the same for any kind of content.

iOS

Create your own class extending from an existing CraftARTrackingContent type (video, image, image button, or 3D model). In this example we extend from CraftARTrackingContentImage.

@interface MyImage : CraftARTrackingContentImage

// Your code here

@end

Indicate the SDK which type of content has to be created for a given response from the CraftAR Service:

[CraftARItemAR setContentClass:[MyImageButton class] forType:@"image_button"];

[CraftARItemAR setContentClass:[MyVideoContent class] forType:@"video"];

[CraftARItemAR setContentClass:[MyImageContent class] forType:@"image"];

[CraftARItemAR setContentClass:[My3DModelContent class] forType:@"3dmodel"];

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