1

我必须在 android 中制作 3d obj 文件。我搜索并找到了许多论坛,现在我能够成功加载 obj+mtl 文件。但我遇到了具有许多纹理文件的 obj 和 mtl 文件的问题。在可能的情况下,在 mtl 中,每张脸都有一个纹理 (.png)。如何在 GLES 中加载这种类型的 obj 文件?是否可以在 android opegl Gles 中加载多纹理 obj?我有 min3d、3dmodelviewer 和 arjpct 库,但没有用。如果可以在 GLES 中加载多纹理 obj,请提供帮助

对于 multi_texture 我已经这样做了

 mTextureHandle = setTexture(obj, textureId,GLES20.GL_TEXTURE1);
        ByteArrayInputStream textureIs0 = new ByteArrayInputStream(obj.getTextureData().get(0));
        int textureId0 = GLUtil.loadTexture(textureIs0);
        mTextureHandle = setTexture(obj, textureId0, GLES20.GL_TEXTURE0);
        ByteArrayInputStream textureIs2 = new ByteArrayInputStream(obj.getTextureData().get(2));
        int textureId2 = GLUtil.loadTexture(textureIs2);
        mTextureHandle = setTexture(obj, textureId2, GLES20.GL_TEXTURE2);
        ByteArrayInputStream textureIs3 = new ByteArrayInputStream(obj.getTextureData().get(3));
        int textureId3 = GLUtil.loadTexture(textureIs3);
        mTextureHandle = setTexture(obj, textureId3, GLES20.GL_TEXTURE3);
        ByteArrayInputStream textureIs4 = new ByteArrayInputStream(obj.getTextureData().get(4));
        int textureId4 = GLUtil.loadTexture(textureIs4);
        mTextureHandle = setTexture(obj, textureId2, GLES20.GL_TEXTURE4);
        ByteArrayInputStream textureIs5 = new ByteArrayInputStream(obj.getTextureData().get(5));
        int textureId5 = GLUtil.loadTexture(textureIs5);
        mTextureHandle = setTexture(obj, textureId5, GLES20.GL_TEXTURE5);
        ByteArrayInputStream textureIs6 = new ByteArrayInputStream(obj.getTextureData().get(6));
        int textureId6 = GLUtil.loadTexture(textureIs6);
        mTextureHandle = setTexture(obj, textureId6, GLES20.GL_TEXTURE6);
        ByteArrayInputStream textureIs7 = new ByteArrayInputStream(obj.getTextureData().get(7));
        int textureId7 = GLUtil.loadTexture(textureIs7);
        mTextureHandle = setTexture(obj, textureId7, GLES20.GL_TEXTURE7);
        ByteArrayInputStream textureIs8 = new ByteArrayInputStream(obj.getTextureData().get(8));
        int textureId8 = GLUtil.loadTexture(textureIs8);
        mTextureHandle = setTexture(obj, textureId8, GLES20.GL_TEXTURE8);
        ByteArrayInputStream textureIs9 = new ByteArrayInputStream(obj.getTextureData().get(9));
        int textureId9 = GLUtil.loadTexture(textureIs9);
        mTextureHandle = setTexture(obj, textureId9, GLES20.GL_TEXTURE9);
public static int loadTexture(final InputStream is) {
        Log.v("GLUtil", "Loading texture from stream...");

        final int[] textureHandle = new int[1];

        GLES20.glGenTextures(1, textureHandle, 0);
        GLUtil.checkGlError("glGenTextures");
        if (textureHandle[0] == 0) {
            throw new RuntimeException("Error loading texture.");
        }

        Log.v("GLUtil", "Handler: " + textureHandle[0]);

        final BitmapFactory.Options options = new BitmapFactory.Options();
        // By default, Android applies pre-scaling to bitmaps depending on the resolution of your device and which
        // resource folder you placed the image in. We don’t want Android to scale our bitmap at all, so to be sure,
        // we set inScaled to false.
        options.inScaled = false;

        // Read in the resource
        final Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
        if (bitmap == null) {
            throw new RuntimeException("couldnt load bitmap");
        }

        // Bind to the texture in OpenGL
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
        GLUtil.checkGlError("glBindTexture");
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
        GLUtil.checkGlError("texImage2D");
        bitmap.recycle();
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

        Log.v("GLUtil", "Loaded texture ok");
        return textureHandle[0];
    }
4

0 回答 0