Search code examples
android-studioopengl-es-2.0bytebuffergltffloatbuffer

How to load .glb (gltf) binary data model to AndroidStudio (OpenGLES20)


I try loading a model from a .glb file (Blender)

doing the following:

        private FloatBuffer bufferXYZ;
        ByteBuffer glb_bb;
    ...
        byte[] bytes = new byte[vertexXYZ_BufferLen];
        glb_bb.get(bytes, 0, bytes.length);
        ByteBuffer buffer = ByteBuffer.allocateDirect(bytes.length).order(ByteOrder.nativeOrder());
        buffer.position(0);
        buffer.put(bytes);
        bufferXYZ = buffer.asFloatBuffer();
        buffer.rewind(); 
        bufferXYZ = ((ByteBuffer) buffer.rewind()).asFloatBuffer();

but I can’t get the correct coordinates in bufferXYZ

and something similar to the coordinates can only be obtained by sorting ByteOrder.BIG_ENDIAN (the documentation says LITTLE_ENDIAN)

how to correctly load a BIN section into a Floatbuffer for OpenGLES20


Solution

  • Thanks understood. it was necessary to shift the starting point of reading even after the word BIN.