[Huawei Developers] Freemind R:
More information like this, you can visit HUAWEI Developer Forum

​

1. Preparations

1.1 Introduction

HUAWEI Computer Graphics (CG Kit) is a high-performance rendering framework launched by Huawei that provides atom-level capabilities for rendering, covering materials, models, lighting, and post effects. CG Kit also contains high-performance rendering components, including anti-aliasing and Vulkan-based multi-thread components, while offering such expansions as Smart Cache and Pre-rotation, as well as incorporating cutting-edge research in computer graphics, computer vision, and deep learning.

1.2 Website Walkthrough

Visit the home page of Huawei Developers:

https://developer.huawei.com/consumer/en/

Navigate to CG Kit, as shown in the figure below.

[IMG="https://miro.medium.com/max/700/0*osiAjnHCzAbnRBzR.jpg"]https://miro.medium.com/max/700/0*osiAjnHCzAbnRBzR.jpg[/IMG]

Or alternatively, click on the direct link below:

https://developer.huawei.com/consumer/en/hms/huawei-computer-graphics/

You can find an introduction to CG Kit on this page.

[IMG="https://miro.medium.com/max/604/0*ISHCQLJQt_rfFMYJ.png"]https://miro.medium.com/max/604/0*ISHCQLJQt_rfFMYJ.png[/IMG]

Click on “View documents” to visit the CG Kit development page at:

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/introduction-0000001050197938

Remember to pay special attention to the Examples and Library tab pages:

[IMG="https://miro.medium.com/max/544/0*TggixVgo3KLN63Pt.jpg"]https://miro.medium.com/max/544/0*TggixVgo3KLN63Pt.jpg[/IMG]

The code of a sample Android Studio project is provided, while the necessary .so and header files are packaged in the SDK.

You will need to complete some steps to develop an app on your own:

1. The SDK is a core module and can be downloaded only after you have registered for a HUAWEI Developers account. Therefore, the SDK is not included in the sample code. You will need to download the SDK separately, and import it to the sample project.

2. Due to copyright concerns, the model files are not included in the sample code. You will need to download or create models on your own, and import them to the sample project.

1.3 Getting Started

The following is the list of minimum requirements for integrating with CG Kit:

1. Kirin SoC-powered Huawei mobile phone running Android 10 or later, with Vulkan 1.0 support

2. Android Studio (The most recent release 4.0 is recommended.)

3. NDK 20.1.5948944

4. API level 29 (Android 10)

5. Build Tools 29.0.3

2. Development Workflow

2.1 Creating a Project

Create a project in Android Studio. In this example, directly open the provided sample project.

Android Studio automatically downloads related content based on Gradle, for example, Gradle 5.6.4 specified by the project.

Though the value of minSdkVersion for Gradle can be changed from 27 to 29 for compatibility reasons, for the most recent release of CG Kit, it can only run on versions Android 10 and later.

2.2 Signing

The Gradle file in the sample code is already signed. You can choose to delete the signature for purely development and verification-related purposes. You can also refer to the CG Kit guide to generate signatures and access Huawei applications.

2.3 Integrating the SDK

Download the SDK.

[IMG="https://miro.medium.com/max/248/0*i-FrCSRnRF85C0hQ.jpg"]https://miro.medium.com/max/248/0*i-FrCSRnRF85C0hQ.jpg[/IMG]

Copy the include folder to the following directory:

app\src\main\cpp

Copy the libs directory to the app directory, as shown in the figure below.

[IMG="https://miro.medium.com/max/428/0*MVyZIomCsYsM1t-P.jpg"]https://miro.medium.com/max/428/0*MVyZIomCsYsM1t-P.jpg[/IMG]

[IMG="https://miro.medium.com/max/405/0*1-CGjhXLl4v9oTrp.jpg"]https://miro.medium.com/max/405/0*1-CGjhXLl4v9oTrp.jpg[/IMG]

Click on Refresh Linked C++ Projects under Build.

[IMG="https://miro.medium.com/max/262/0*y6o87NEZfrsTWd51.jpg"]https://miro.medium.com/max/262/0*y6o87NEZfrsTWd51.jpg[/IMG]

Open the MainApplication.cpp file and check the APIs. If they are no longer highlighted in red, it means that the configuration is successful.

[IMG="https://miro.medium.com/max/516/0*IVmGWR-PQvsYSjV-.jpg"]https://miro.medium.com/max/516/0*IVmGWR-PQvsYSjV-.jpg[/IMG]

2.4 Making Skyboxes

You will need to prepare skyboxes on your own, as they are not released with the sample code.

The following website provides the visualized displays for skyboxes:

https://doc.babylonjs.com/resources/playground_textures#cubetextures

Download a cubemap skybox and edit the .cub configuration file as follows:

width=512

height=512

depth=6

mipmap=1

face=6

channel=4

suffix=.png

The width and height must be consistent with those in the PNG image for the level 1 mipmap of the skybox.

Name the images in the following manner.

[IMG="https://miro.medium.com/max/552/0*fN57aFoUyqVp9mjF.jpg"]https://miro.medium.com/max/552/0*fN57aFoUyqVp9mjF.jpg[/IMG]

Store these files in the env directory, then copy them to the cubemap directory for the sample project.

Please note that CG Kit supports only four-channel PNG images. If your PNG images are not four-channel, open the files with Microsoft Paint and save them as .png files, to convert them into four-channel PNG images.

2.5 Preparing a Model

Currently, CG Kit only supports models in .obj format, and can only parse points and planes only from .obj files; .mtl materials are ignored. CG Kit also supports normal parsing, map coordinate parsing, and tangent computing, but only the triangle mode is supported when parsing surfaces. Automatic triangulation is not supported for surfaces with multiple vertices.

Open-source 3D models can be easily accessed online free-of-charge, for instance through the following website:

https://www.turbosquid.com/Search/3D-Models/free/obj

The following model was selected in this guide:

https://www.turbosquid.com/3d-models/medieval-blacksmith-low-poly-3d-model-1591136

The overview is as follows.

[IMG="https://miro.medium.com/max/700/0*-RM15XasBybcUhk3.jpg"]https://miro.medium.com/max/700/0*-RM15XasBybcUhk3.jpg[/IMG]

2.6 Developing an App

Modify the MainApplication.cpp code in the sample project.

2.6.1 Modifying the Model

Modify the model path in the InitScene method.

String modelName = "models/black_smith/black_smith.obj";

Change the path of the map. (Convert the original .jpg file to .png format.)

String texAlbedo = "models/black_smith/texture/black_smith.png";

Comment out the original map.

//String texNormal = "models/Avatar/Normal_01.png";
//String texPbr = "models/Avatar/Pbr_01.png";

Comment out SetTexture and SetSamplerParam corresponding to the two maps.

2.6.2 Modifying the Skybox

Modify the related configuration in the CreateSkybox method to change the cube model used by the skybox to as follows.

String modelName = "models/cube/cube.obj";

The cube is the simplest model. The link is shown below:

https://gist.github.com/MaikKlein/0b6d6bb58772c13593d0a0add6004c1c

Set the environment map in the MainApplication.h file to the following.

String m_envMap = "cubemaps/env/env.cub";

Keep the name the same as that used to create the skybox.

2.7 Verifying Execution

The result is shown below.

[IMG="https://miro.medium.com/max/516/0*F5r87jXED6s-PjpT.jpg"]https://miro.medium.com/max/516/0*F5r87jXED6s-PjpT.jpg[/IMG]

If an error occurs during the execution, you can run the adb logcat command to view the log and locate the error. CG Kit also logs ERROR-level events in Android log files. To view CG Kit log messages, run the following command.

adb logcat | grep CGKit

3. FAQs

3.1 What model formats does CG Kit support?

CG Kit only supports models in .obj format, and can parse vertexes, normals, map coordinates, and surface information. However, automatic triangulation is not supported for surfaces with more than three vertices, and related configurations cannot be parsed from .mtl material files.

3.2 What map formats does CG Kit support?

CG Kit only supports 4-channel PNG images.

3.3 Do I need to sign my app?

Sign your app as required by referring to the Android manual. For purely development and verification-related purposes, you can choose to comment out the signature configuration in the sample code.

3.4 What should I do if “Failed to get hire” is printed?

The “Failed to get hire” message works for dotting only, and can be ignored. Dotting refers to the process during which CG Kit records and reports its runtime status. This does not affect the operation of functional modules, such as the rendering module.

4. Appendix

The compiled APK and Android Studio project are available in Google Drive for reference.

Link:

https://drive.google.com/drive/folders/1V0tC_51dCZDBEy_peD2sWzHBvCQpkwtt?usp=sharing

Please note that the project provided here does not contain the SDK (containing the required .so and header files). You will need to register a HUAWEI Developers account and download the CG Kit SDK on your own. The project already contains the necessary resources, such as the models, maps, and skyboxes. Only the CG Kit SDK needs to be downloaded separately.