HTEffect 3D Avatar

Updated

Integrate and use HT Portrait 3D special effects in your Android or iOS app.

The HTEffect 3D Avatar extension enables you to quickly and seamlessly integrate 3D portrait special effects capabilities into your app. It encapsulates the Hongtu HTAvatar core API. You call API functions by setting the appropriate extension parameters.

Understand the tech

You use Video SDK methods to pass the appropriate key and value parameters to the extension. The key parameter corresponds exactly to the Hongtu API name, and the value parameter wraps some or all API parameters in JSON format.

Prerequisites

  • Android Studio 4.1 or later.
  • A physical Android device.
  • Implemented the SDK quickstart.

Project setup

  1. Download the Android package.

  2. Copy all .aar files to /app/libs.

  3. Contact support@agora.io to obtain the resource package and save the required model and prop files to /app/src/main/assets.

  4. Add the Gradle dependency:

    implementation fileTree(dir: "libs", include: ["*.jar", "*.aar"])
  5. Import the required Agora classes.

Integrate the extension

Enable the plug-in

private void enableExtension(boolean enabled) {
  agoraEngine.enableExtension("Texeljoy", "HTAvatar", enabled);
}

Initialize the plug-in

private void initExtension() {
  try {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("license", HTKey);
    setExtensionProperty("htARInitOffline", jsonObject.toString());
  } catch (JSONException e) {
    Log.e(TAG, e.toString());
  }
}

Set up a 3D effect

Call setExtensionProperty with keys such as htARRenderEnable and htARSetModel to enable effects and switch models.

Reference

Sample project

Run the sample project from AgoraHTAvatarExtensionDemo.

API reference

Interface description

When you call setExtensionProperty, the following keys and their corresponding functions are supported:

Initialization

KeyDescription
htARInitOfflineInitialization, offline authentication.

Destroy

KeyDescription
htARReleaseBufferRendererResource release function.

Functional interface

KeyDescription
htARRenderEnableTurn on/off the AR special effects function.
htARSetModelSwitch AR model function.
htARMirrorSet whether the image has a mirror function.
htARImageFormatSet image format function.
htARRotationSet image rotation angle function.
htARMaxFacesSet the maximum number of supported faces function.
htARCopyResourceCopy the resource path to the sandbox function.

Value description of method keys

htARInitOffline

value contains the following parameters:

Value parameterDescription
licenseString type, AR offline authentication key.

htARReleaseBufferRenderer

value contains the following parameters:

Value parameterDescription
enableBOOL type, whether to confirm the release of resources.

htARRenderEnable

value contains the following parameters:

Value parameterDescription
enableBOOL type, whether to enable the AR function.

htARSetModel

value contains the following parameters:

Value parameterDescription
nameString type, the name of the model.

htARMirror

value contains the following parameters:

Value parameterDescription
isMirrorBOOL type, whether to set the mirror display of prop special effects. The default is true.

htARImageFormat

value contains the following parameters:

Value parameterDescription
imageFormatInt type, enumeration value of image format. For details, see HTEARImageFormat.

htARRotation

value contains the following parameters:

Value parameterDescription
rotationInt type, enumeration value of image rotation angle. For details, see HTEAROrientation.

htARMaxFaces

value contains the following parameters:

Value parameterDescription
maxFacesInt type, the maximum number of supported faces. The value range is [1, 5].

htARCopyResource

value contains the following parameters:

Value parameterDescription
pathString type, the path that needs to be copied to the sandbox.

Understand the tech

You use Video SDK methods to pass the appropriate key and value parameters to the extension. The key parameter corresponds exactly to the Hongtu API name, and the value parameter wraps some or all API parameters in JSON format.

Prerequisites

  • Xcode 12.0 or later.
  • A physical iOS device.
  • Implemented the SDK quickstart.

Project setup

  1. Download the iOS package.
  2. Copy the .framework library files to your project folder.
  3. Save HTKey.h and HTEffect.bundle to the project folder.
  4. Ensure the dynamic libraries are set to Embed & Sign.

Integrate the extension

Enable the plug-in

[self.agoraKit enableExtensionWithVendor:@"Texeljoy"
                               extension:@"HTAvatar"
                                 enabled:self.enable];

Initialize the plug-in

Use setExtensionPropertyWithVendor to call htARCopyResource, htARInitOffline, and optional image format configuration.

Set up a 3D effect

Call setExtensionPropertyWithVendor with keys such as htARRenderEnable and htARSetModel to enable effects and switch models.

Reference

Sample project

Run the sample project from AgoraHTAvatarExtensionDemo.

API reference

Interface description

When you call setExtensionPropertyWithVendor, the following keys and their corresponding functions are supported:

Initialization

KeyDescription
htARInitOfflineInitialization, offline authentication.

Destroy

KeyDescription
htARReleaseBufferRendererResource release function.

Functional interface

KeyDescription
htARRenderEnableTurn on/off the AR special effects function.
htARSetModelSwitch AR model function.
htARMirrorSet whether the image has a mirror function.
htARImageFormatSet image format function.
htARRotationSet image rotation angle function.
htARMaxFacesSet the maximum number of supported faces function.
htARCopyResourceCopy the resource path to the sandbox function.

Value description of method keys

htARInitOffline

value contains the following parameters:

Value parameterDescription
licenseString type, AR offline authentication key.

htARReleaseBufferRenderer

value contains the following parameters:

Value parameterDescription
enableBOOL type, whether to confirm the release of resources.

htARRenderEnable

value contains the following parameters:

Value parameterDescription
enableBOOL type, whether to enable the AR function.

htARSetModel

value contains the following parameters:

Value parameterDescription
nameString type, the name of the model.

htARMirror

value contains the following parameters:

Value parameterDescription
isMirrorBOOL type, whether to set the mirror display of prop special effects. The default is true.

htARImageFormat

value contains the following parameters:

Value parameterDescription
imageFormatInt type, enumeration value of image format. For details, see HTEARImageFormat.

htARRotation

value contains the following parameters:

Value parameterDescription
rotationInt type, enumeration value of image rotation angle. For details, see HTEAROrientation.

htARMaxFaces

value contains the following parameters:

Value parameterDescription
maxFacesInt type, the maximum number of supported faces. The value range is [1, 5].

htARCopyResource

value contains the following parameters:

Value parameterDescription
pathString type, the path that needs to be copied to the sandbox.

Interface description

When calling setExtensionProperty on Android or setExtensionPropertyWithVendor on iOS, use the following keys to call the corresponding HTAvatar functions.

Initialization

KeyDescription
htARInitOfflineInitializes offline authentication.

Destroy

KeyDescription
htARReleaseBufferRendererReleases resources.

Functional interface

KeyDescription
htARRenderEnableTurns AR special effects on or off.
htARSetModelSwitches the AR model.
htARMirrorSets whether the image uses mirroring.
htARImageFormatSets the image format.
htARRotationSets the image rotation angle.
htARMaxFacesSets the maximum number of supported faces.
htARCopyResourceCopies the resource path to the sandbox.

Value description of method keys

htARInitOffline

value contains the following parameter:

Value parameterDescription
licenseString. The AR offline authentication key.

htARReleaseBufferRenderer

value contains the following parameter:

Value parameterDescription
enableBoolean. Whether to confirm resource release.

htARRenderEnable

value contains the following parameter:

Value parameterDescription
enableBoolean. Whether to enable AR.

htARSetModel

value contains the following parameter:

Value parameterDescription
nameString. The model name.

htARMirror

value contains the following parameter:

Value parameterDescription
isMirrorBoolean. Whether to mirror prop effects. The default value is true.

htARImageFormat

value contains the following parameter:

Value parameterDescription
imageFormatInteger. The image format enumeration value. For specific values, see HTEARImageFormat.

htARRotation

value contains the following parameter:

Value parameterDescription
rotationInteger. The image rotation angle enumeration value. For specific values, see HTEAROrientation.

htARMaxFaces

value contains the following parameter:

Value parameterDescription
maxFacesInteger. The maximum number of supported faces. The value range is [1, 5].

htARCopyResource

value contains the following parameter:

Value parameterDescription
pathString. The path to copy to the sandbox.