[Huawei Developers] Freemind R:
AR placement apps have enhanced daily life in a myriad of different ways, from AR furniture placement for home furnishing and interior decorating, AR fitting in retail, to AR-based 3D models in education which gives students an opportunity to take an in-depth look at the internal workings of objects.

From integrating HUAWEI Scene Kit, you're only eight steps away from launching an AR placement app of your own. ARView, a set of AR-oriented scenario-based APIs in Scene Kit, uses the plane detection capability of AR Engine, along with the graphics rendering capability in Scene Kit, to create a 3D materials loading and rendering capability for common AR scenes.

ARView Functions

With ARView, you'll be able to:

1. Load and render 3D materials in AR scenes.

2. Set whether to display the lattice plane (consisting of white lattice points) to help select a plane in a real-world view.

3. Tap an object placed on the lattice plane to select it. Once selected, the object will turn red. You can then move, resize, or rotate it as needed.

Development Procedure

Before using ARView, you'll need to integrate the Scene Kit SDK into your Android Studio project. For details, please refer to Integrating the HMS Core SDK.

ARView inherits from GLSurfaceView, and overrides lifecycle-related methods. It can facilitate the creation of an ARView-based app in just eight steps:

1. Create an ARViewActivity that inherits from Activity. Add a Button to load materials.

public class ARViewActivity extends Activity {
private ARView mARView;
private Button mButton;
private boolean isLoadResource = false;
}

2. Add an ARView to the layout.

<com.huawei.hms.scene.sdk.ARView
android:id="@+id/ar_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.huawei.hms.scene.sdk.ARView>

Note: To achieve the desired experience offered by ARView, your app should not support screen orientation changes or split-screen mode; thus, add the following configuration in the AndroidManifest.xml file:

android:screenOrientation="portrait"
android:resizeableActivity="false"

3. Override the onCreate method of ARViewActivity and obtain the ARView.

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ar_view);
mARView = findViewById(R.id.ar_view);
mButton = findViewById(R.id.button);
}

4. Add a Switch button in the onCreate method to set whether or not to display the lattice plane.

Switch mSwitch = findViewById(R.id.show_plane_view);
mSwitch.setChecked(true);
mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mARView.enablePlaneDisplay(isChecked);
}
});

Note: Add the Switch button in the layout before using it.

<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/show_plane_view"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd ="15dp"
android:layout_gravity="end"
android:text="@string/show_plane"
android:theme="@style/AppTheme"
tools:ignore="RelativeOverlap" />

5. Add a button callback method. Tapping the button once will load a material, and tapping it again will clear the material.

public void onBtnClearResourceClicked(View view) {
if (!isLoadResource) {
mARView.loadAsset("ARView/scene.gltf");
isLoadResource = true;
mButton.setText(R.string.btn_text_clear_resource);
} else {
mARView.clearResource();
mARView.loadAsset("");
isLoadResource = false;
mButton.setText(R.string.btn_text_load);
}
}

Note: The onBtnSceneKitDemoClicked method must be registered in the layout attribute onClick of the button, which is tapped to load or clear a material.

6. Override the onPause method of ARViewActivity and call the onPause method of ARView.

@Override
protected void onPause() {
super.onPause();
mARView.onPause();
}

7. Override the onResume method of ARViewActivity and call the onResume method of ARView.

@Override
protected void onResume() {
super.onResume();
mARView.onResume();
}

8. Override the onDestroy method for ARViewActivity and call the destroy method of ARView.

@Override
protected void onDestroy() {
super.onDestroy();
mARView.destroy();
}

9. (Optional) After the material is loaded, use setInitialPose to set its initial status (scale and rotation).

float[] scale = new float[] { 0.1f, 0.1f, 0.1f };
float[] rotation = new float[] { 0.707f, 0.0f, -0.707f, 0.0f };
mARView.setInitialPose(scale, rotation);

Effects

You can develop a basic AR placement app, simply by calling ARView from Scene Kit, as detailed in the eight steps above. If you are interested in this implementation method, you can view the Scene Kit demo on GitHub.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201019090527.17317915702355627678457470557709:50511103012840:2800:1D038991FCDD676F7E7F9F9ACAEA243D26EBA6069315D6F19DE85DDE139C44CA.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201019090527.17317915702355627678457470557709:50511103012840:2800:1D038991FCDD676F7E7F9F9ACAEA243D26EBA6069315D6F19DE85DDE139C44CA.gif[/IMG]

The ARView capability can be used to do far more than just develop AR placement apps; it can also help you implement a range of engaging functions, such as AR games, virtual exhibitions, and AR navigation features.

GitHub to download demos and sample codes