Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Huawei AR Engine .obj file not rendering properly

I have an android app and I am using Huawei AR Engine Kit.

I have a model file with the .obj extension. When I add this file to my application after reducing its size in the application called blender, my model does not appear properly. I add them as assets in the Android project. I export the model properly because I checked it where necessary and my model is correct.

I want to resize the model and show it in a smaller size.

I shared what the model actually is and the screenshot in the application below.

model screenshot-eiffel

model-in-app

onDrawFrame is as follows

    public void onDrawFrame(float[] cameraView, float[] cameraProjection, float lightIntensity, VirtualObject obj) {
    ShaderUtil.checkGlError(TAG, "onDrawFrame start.");
    mModelMatrixs = obj.getModelAnchorMatrix();
    Matrix.multiplyMM(mModelViewMatrixs, 0, cameraView, 0, mModelMatrixs, 0);
    Matrix.multiplyMM(mModelViewProjectionMatrixs, 0, cameraProjection, 0, mModelViewMatrixs, 0);
    GLES20.glUseProgram(mGlProgram);
    Matrix.multiplyMV(mViewLightDirections, 0, mModelViewMatrixs, 0, LIGHT_DIRECTIONS, 0);
    MatrixUtil.normalizeVec3(mViewLightDirections);

    GLES20.glUniform4f(mLightingParametersUniform,
            mViewLightDirections[0], mViewLightDirections[1], mViewLightDirections[2], lightIntensity);
    float[] objColors = obj.getColor();

    GLES20.glUniform4fv(mColorUniform, 1, objColors, 0);
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]);
    GLES20.glUniform1i(mTextureUniform, 0);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVertexBufferId);

    GLES20.glVertexAttribPointer(
            mPositionAttribute, 3, GLES20.GL_FLOAT, false, 0, 0);

    GLES20.glVertexAttribPointer(
            mNormalAttribute, 3, GLES20.GL_FLOAT, false, 0, mNormalsBaseAddress);

    GLES20.glVertexAttribPointer(
            mTexCoordAttribute, 2, GLES20.GL_FLOAT, false, 0, mTexCoordsBaseAddress);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
    GLES20.glUniformMatrix4fv(
            mModelViewUniform, 1, false, mModelViewMatrixs, 0);
    GLES20.glUniformMatrix4fv(
            mModelViewProjectionUniform, 1, false, mModelViewProjectionMatrixs, 0);
    GLES20.glEnableVertexAttribArray(mPositionAttribute);
    GLES20.glEnableVertexAttribArray(mNormalAttribute);
    GLES20.glEnableVertexAttribArray(mTexCoordAttribute);
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, mIndexBufferId);
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, mIndexCount, GLES20.GL_UNSIGNED_SHORT, 0);
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
    GLES20.glDisableVertexAttribArray(mPositionAttribute);
    GLES20.glDisableVertexAttribArray(mNormalAttribute);
    GLES20.glDisableVertexAttribArray(mTexCoordAttribute);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
    ShaderUtil.checkGlError(TAG, "onDrawFrame end.");
}
like image 385
kubilay Avatar asked Nov 06 '22 03:11

kubilay


1 Answers

In order to resize the model , you can change the SCALE_FACTOR to a desired value,

mModelMatrix[0] = SCALE_FACTOR;
mModelMatrix[5] = SCALE_FACTOR;
mModelMatrix[10] = SCALE_FACTOR;

It’s located in VirtualObject if you are using AR Engine’s demo code. AR Engine

And for the model display part, you need to modify the rendering code in the onDrawFrame method based on GLSurfaceView for each frame, according to the model you are using. If the rendering part is too complex, you can try using Scene Kit’s AR View to do the model rendering, which supports glTF and glb formats.

like image 53
zhangxaochen Avatar answered Nov 14 '22 23:11

zhangxaochen