[Huawei Developers] XDARoni:
Procedure

HUAWEI Scene Kit uses SceneView to provide you with rendering capabilities that automatically adapt to 3D scenes. To complete the rendering of a complex 3D scene, you only need to call several APIs.

SceneView inherits from surfaceView and overrides methods including surfaceCreated, surfaceChanged, surfaceDestroyed, onTouchEvent, and onDraw. You create a SampleView inheriting from SceneView to quickly access HUAWEI Scene Kit.

1. Create a SampleView that inherits from SceneView.

public class SampleView extends SceneView {
public SampleView(Context context) {
super(context);
}
public SampleView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
}

2. Override the surfaceCreated method of SceneView in SampleView, and call this method to create and initialize SceneView.

public void surfaceCreated(SurfaceHolder holder) {
super.surfaceCreated(holder);
}

3. In the surfaceCreated method, call loadScene to load materials to be rendered.

loadScene("scene.gltf");

4. In the surfaceCreated method, call loadSkyBox to load skybox materials.

loadSkyBox("skyboxTexture.dds");

5. In the surfaceCreated method, call loadSpecularEnvTexture to load specular maps.

loadSpecularEnvTexture("specularEnvTexture.dds");

6. In the surfaceCreated method, call loadDiffuseEnvTexture to load diffuse maps.

loadDiffuseEnvTexture("diffuseEnvTexture.dds");

7. (Optional) To clear the materials from a scene, call the clearScene method.

clearScene();

NOTE:

When the loadScene method is called to load new materials for a scene, its original materials are automatically cleared, with no need to call the clearScene method.

8. (Optional) Determine whether to override the surface-related lifecycle methods as needed.

@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int foramt, int width, int height) {
super.surfaceChanged(surfaceHolder, foramt, width, height);
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
super.surfaceDestroyed(surfaceHolder);
}
@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
return super.onTouchEvent(motionEvent);
}
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
}

NOTE:

If you do not need custom functions, the methods of SceneView are used by default. No overriding is required.

If custom functions are needed, override the SceneView methods.

For example, if you want to display the frame rate for your rendering, override the onDraw method and add the function of displaying the frame rate.

@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
// showCurrentFPS();
}

9. Create an activity and call setContentView in the onCreate method. Pass the SampleView that you have created to the setContentView method.

public class SampleActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
}

Full SampleView Code

public class SampleView extends SceneView {
// Create a SampleView in new mode.
public SampleView(Context context) {
super(context);
}
// Create a SampleView by registering it in the Layout xml file.
public SampleView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
super.surfaceCreated(holder);
// Load the model of a scene by reading files from assets.
loadScene("scene.gltf");
// Load skybox materials by reading files from assets.
loadSkyBox("skyboxTexture.dds");
// Load specular maps by reading files from assets.
loadSpecularEnvTexture("specularEnvTexture.dds");
// Load diffuse maps by reading files from assets.
loadDiffuseEnvTexture("diffuseEnvTexture.dds");
}

@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int format, int width, int height) {
super.surfaceChanged(surfaceHolder, format, width, height);
}

@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
super.surfaceDestroyed(surfaceHolder);
}

@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
return super.onTouchEvent(motionEvent);
}

@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
}