【问题标题】:How to change texture.png after 3d.obj was placed in the surface using ARCORE?使用 ARCORE 将 3d.obj 放置在表面后如何更改 texture.png?
【发布时间】:2018-08-13 03:09:28
【问题描述】:

对于一个 3d.obj 文件,我有四种类型的 texture.png。如何在将 3d.obj 放入表面后更改 texture.png,例如 ARCORE 的变色功能?

有人知道吗?

【问题讨论】:

    标签: android colors textures augmented-reality arcore


    【解决方案1】:

    您可以更改对象的纹理。假设您正在查看 hello_ar_java 示例,您可以向ObjectRenderer 添加一个方法:

      public void setTextureOnGLThread(Bitmap textureBitmap) {
        // Bind the texture name already allocated.
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
        // Set the filtering for handling different sizes to render.
        GLES20.glTexParameteri(
                GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR_MIPMAP_LINEAR);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    
        // Copy the bitmap contents into the texture buffer.    
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, textureBitmap, 0);
    
        // Generate the mip map for the different sizes.
        GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
    
        // Unbind the texture.
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
      }
    

    您需要从 GL 线程调用它,例如从 onDrawFrame()

    【讨论】:

    • 感谢您的回答。在将 png 转换为位图后,我在 ObjectRenderer 中调用您的代码获取空值。
    • 我不确定您所说的“将 png 转换为位图”是什么意思?你不需要做任何特别的事情。要将 png 加载到位图中,请调用 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.mypng);假设 mypng.png 在 res/drawable 中。
    • 获得相同的空值..您能否提供示例arcore sdk中纹理更改的完整代码@Clayton Wilkinson
    猜你喜欢
    • 2020-04-26
    • 2019-12-15
    • 1970-01-01
    • 2020-10-12
    • 1970-01-01
    • 1970-01-01
    • 2020-09-25
    • 2023-04-08
    • 2019-01-06
    相关资源
    最近更新 更多