Used IndexBuffer instead of the ByteShortIntBufferReader and removed the class

fix-456
Nehon 7 years ago
parent bf18ef3048
commit d606c30a52
  1. 2
      jme3-core/src/main/java/com/jme3/scene/Mesh.java
  2. 24
      jme3-core/src/main/java/com/jme3/scene/mesh/IndexBuffer.java
  3. 7
      jme3-core/src/main/java/com/jme3/scene/mesh/IndexByteBuffer.java
  4. 4
      jme3-core/src/main/java/com/jme3/scene/mesh/IndexIntBuffer.java
  5. 4
      jme3-core/src/main/java/com/jme3/scene/mesh/IndexShortBuffer.java
  6. 18
      jme3-core/src/main/java/com/jme3/scene/mesh/VirtualIndexBuffer.java
  7. 58
      jme3-core/src/main/java/com/jme3/util/BufferUtils.java

@ -1447,7 +1447,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
return false; // no bone animation data
}
BufferUtils.ByteShortIntBufferReader boneIndexBuffer = new BufferUtils.ByteShortIntBufferReader(biBuf.getData());
IndexBuffer boneIndexBuffer = IndexBuffer.wrapIndexBuffer(biBuf.getData());
boneIndexBuffer.rewind();
int numBoneIndices = boneIndexBuffer.remaining();
assert numBoneIndices % 4 == 0 : numBoneIndices;

@ -75,7 +75,29 @@ public abstract class IndexBuffer {
return new IndexShortBuffer(BufferUtils.createShortBuffer(indexCount));
}
}
/**
* @see Buffer#rewind()
*/
public void rewind() {
getBuffer().rewind();
}
/**
* @return
* @see Buffer#remaining()
*/
public int remaining() {
return getBuffer().remaining();
}
/**
* Returns the vertex index for the current position.
*
* @return
*/
public abstract int get();
/**
* Returns the vertex index for the given index in the index buffer.
*

@ -47,7 +47,12 @@ public class IndexByteBuffer extends IndexBuffer {
buf = buffer;
buf.rewind();
}
@Override
public int get() {
return buf.get() & 0x000000FF;
}
@Override
public int get(int i) {
return buf.get(i) & 0x000000FF;

@ -48,6 +48,10 @@ public class IndexIntBuffer extends IndexBuffer {
buf.rewind();
}
@Override
public int get() {
return buf.get();
}
@Override
public int get(int i) {
return buf.get(i);

@ -48,6 +48,10 @@ public class IndexShortBuffer extends IndexBuffer {
buf.rewind();
}
@Override
public int get() {
return buf.get() & 0x0000FFFF;
}
@Override
public int get(int i) {
return buf.get(i) & 0x0000FFFF;

@ -55,6 +55,7 @@ public class VirtualIndexBuffer extends IndexBuffer {
protected int numVerts = 0;
protected int numIndices = 0;
protected Mode meshMode;
protected int position = 0;
public VirtualIndexBuffer(int numVerts, Mode meshMode){
this.numVerts = numVerts;
@ -86,6 +87,23 @@ public class VirtualIndexBuffer extends IndexBuffer {
}
}
@Override
public int get() {
int i = get(position);
position++;
return i;
}
@Override
public void rewind() {
position = 0;
}
@Override
public int remaining() {
return numIndices - position;
}
@Override
public int get(int i) {
if (meshMode == Mode.Triangles || meshMode == Mode.Lines || meshMode == Mode.Points){

@ -1341,62 +1341,4 @@ public final class BufferUtils {
}
}
public static class ByteShortIntBufferReader {
Buffer buffer;
public ByteShortIntBufferReader() {
}
public ByteShortIntBufferReader(Buffer buffer) {
this.buffer = buffer;
}
public int get() {
if (buffer instanceof ByteBuffer) {
return ((ByteBuffer) buffer).get();
} else if (buffer instanceof ShortBuffer) {
return ((ShortBuffer) buffer).get();
} else if (buffer instanceof IntBuffer) {
return ((IntBuffer) buffer).get();
} else {
throw new UnsupportedOperationException("Buffer must be a ByteBuffer, a ShortBuffer or an IntBuffer");
}
}
public int get(int index) {
if (buffer instanceof ByteBuffer) {
return ((ByteBuffer) buffer).get(index);
} else if (buffer instanceof ShortBuffer) {
return ((ShortBuffer) buffer).get(index);
} else if (buffer instanceof IntBuffer) {
return ((IntBuffer) buffer).get(index);
} else {
throw new UnsupportedOperationException("Buffer must be a ByteBuffer, a ShortBuffer or an IntBuffer");
}
}
public int getUnsigned(int index) {
if (buffer instanceof ByteBuffer) {
return ((ByteBuffer) buffer).get(index) & 0xff;
} else if (buffer instanceof ShortBuffer) {
return ((ShortBuffer) buffer).get(index) & 0xffff;
} else if (buffer instanceof IntBuffer) {
return ((IntBuffer) buffer).get(index) & 0xffffff;
} else {
throw new UnsupportedOperationException("Buffer must be a ByteBuffer, a ShortBuffer or an IntBuffer");
}
}
public void setBuffer(Buffer buffer) {
this.buffer = buffer;
}
public void rewind() {
buffer.rewind();
}
public int remaining() {
return buffer.remaining();
}
}
}

Loading…
Cancel
Save