public static float readAsFloat(LittleEndien stream, VertexBuffer.Format format) throws IOException { //We may have packed data so depending on the format, we need to read data differently and unpack it // Implementations must use following equations to get corresponding floating-point value f from a normalized integer c and vise-versa: // accessor.componentType int-to-float float-to-int // 5120 (BYTE) f = max(c / 127.0, -1.0) c = round(f * 127.0) // 5121 (UNSIGNED_BYTE) f = c / 255.0 c = round(f * 255.0) // 5122 (SHORT) f = max(c / 32767.0, -1.0) c = round(f * 32767.0) // 5123 (UNSIGNED_SHORT) f = c / 65535.0 c = round(f * 65535.0) byte b; switch (format) { case Byte: b = stream.readByte(); return Math.max((float) b / 127f, -1f); case UnsignedByte: b = stream.readByte(); return (float) b / 255f; case Short: b = stream.readByte(); return Math.max((float) b / 32767f, -1f); case UnsignedShort: b = stream.readByte(); return (float) b / 65535f; default: //we have a regular float return stream.readFloat(); } }
private static void populateByteArray(byte[] array, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); int arrayIndex = 0; while (index < end) { for (int i = 0; i < numComponents; i++) { array[arrayIndex] = stream.readByte(); arrayIndex++; } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }
private static void populateShortArray(short[] array, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); int arrayIndex = 0; while (index < end) { for (int i = 0; i < numComponents; i++) { if (componentSize == 2) { array[arrayIndex] = stream.readShort(); } else { array[arrayIndex] = stream.readByte(); } arrayIndex++; } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }
public static float readAsFloat(LittleEndien stream, VertexBuffer.Format format) throws IOException { //We may have packed data so depending on the format, we need to read data differently and unpack it // Implementations must use following equations to get corresponding floating-point value f from a normalized integer c and vise-versa: // accessor.componentType int-to-float float-to-int // 5120 (BYTE) f = max(c / 127.0, -1.0) c = round(f * 127.0) // 5121 (UNSIGNED_BYTE) f = c / 255.0 c = round(f * 255.0) // 5122 (SHORT) f = max(c / 32767.0, -1.0) c = round(f * 32767.0) // 5123 (UNSIGNED_SHORT) f = c / 65535.0 c = round(f * 65535.0) byte b; switch (format) { case Byte: b = stream.readByte(); return Math.max((float) b / 127f, -1f); case UnsignedByte: b = stream.readByte(); return (float) b / 255f; case Short: b = stream.readByte(); return Math.max((float) b / 32767f, -1f); case UnsignedShort: b = stream.readByte(); return (float) b / 65535f; default: //we have a regular float return stream.readFloat(); } }
private static void populateByteArray(byte[] array, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); int arrayIndex = 0; while (index < end) { for (int i = 0; i < numComponents; i++) { array[arrayIndex] = stream.readByte(); arrayIndex++; } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }
private static void populateShortArray(short[] array, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); int arrayIndex = 0; while (index < end) { for (int i = 0; i < numComponents; i++) { if (componentSize == 2) { array[arrayIndex] = stream.readShort(); } else { array[arrayIndex] = stream.readByte(); } arrayIndex++; } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }