Skip to content

Commit

Permalink
add read shortbuffer in position
Browse files Browse the repository at this point in the history
  • Loading branch information
WenlinMao committed Aug 23, 2019
1 parent 75f8099 commit d46e708
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,6 @@ private void drawShape(Object3DData obj, int drawMode, int drawSize) {
drawBufferType = GLES20.GL_UNSIGNED_SHORT;
}

// if (drawBufferType == GLES20.GL_UNSIGNED_SHORT){
// drawOrderBuffer = obj.getDrawOrderAsShort();
// }
//
// if (drawBufferType == GLES20.GL_UNSIGNED_BYTE){
// drawOrderBuffer = obj.getDrawOrderAsByte();
// }

if (obj.isDrawUsingArrays()) {
drawOrderBuffer = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,22 @@ private static void traverseNode(NodeModel node, List<Object3DData> ret, int ind
// get accessor, bufferview, and buffer for vertex buffer, normal buffer
// texture coordinate buffer
AccessorModel accessor = attriMap.get(key);
//TODO: ShortBuffer cannot be converted to FloatBuffer, try consider convert
FloatBuffer dataFB = (FloatBuffer)accessor.getCorrBufferData();

// TODO: add read of other types of buffer if needed
Buffer dataB = accessor.getCorrBufferData();
FloatBuffer dataFB = null;
if (dataB instanceof FloatBuffer){
dataFB = (FloatBuffer)dataB;
} else if (dataB instanceof ShortBuffer){
ShortBuffer dataSB = (ShortBuffer)dataB;
short[] shortArr = new short[dataSB.capacity()];
dataSB.get(shortArr);
ByteBuffer bb = ByteBuffer.allocate(shortArr.length * 2);
bb.asShortBuffer().put(shortArr);
dataFB = bb.asFloatBuffer();
}

// FloatBuffer dataFB = accessor.getCorrBufferData();
if (key.equals("POSITION")){
transformVertices(data3D, node, dataFB);
data3D.setVertexArrayBuffer(dataFB);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
package org.andresoviedo.android_3d_model_engine.services.gltf.jgltf_model;

import java.nio.Buffer;

/**
* Interface for a data accessor
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,24 @@ public Buffer getCorrBufferData(){
short[] ver = bytesToShort(byte2);
retBuffer = tempbuf.asShortBuffer();
((ShortBuffer)retBuffer).put(ver);
// tempbuf.asShortBuffer().put(ver);
} else if (type == GLES20.GL_UNSIGNED_INT) {
int[] ver = bytesToInt(byte2);
retBuffer = tempbuf.asIntBuffer();
((IntBuffer)retBuffer).put(ver);
// tempbuf.asIntBuffer().put(ver);
} else if (type == GLES20.GL_UNSIGNED_BYTE){
retBuffer = tempbuf;
((ByteBuffer)retBuffer).put(byte2);
// tempbuf.put(byte2);
} else if (type == GLES20.GL_FLOAT){
float[] ver = byteToFloat(byte2);
retBuffer = tempbuf.asFloatBuffer();
((FloatBuffer)retBuffer).put(ver);
// float[] ver = byteToFloat(byte2);
// tempbuf.asFloatBuffer().put(ver);
}
// tempbuf.position(0);
retBuffer.position(0);

return retBuffer;
Expand Down

0 comments on commit d46e708

Please sign in to comment.