diff --git a/jme3-core/src/main/java/com/jme3/scene/Mesh.java b/jme3-core/src/main/java/com/jme3/scene/Mesh.java index bc9781040..87dff6aec 100644 --- a/jme3-core/src/main/java/com/jme3/scene/Mesh.java +++ b/jme3-core/src/main/java/com/jme3/scene/Mesh.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; diff --git a/jme3-core/src/main/java/com/jme3/scene/mesh/IndexBuffer.java b/jme3-core/src/main/java/com/jme3/scene/mesh/IndexBuffer.java index a67bb6704..43846b541 100644 --- a/jme3-core/src/main/java/com/jme3/scene/mesh/IndexBuffer.java +++ b/jme3-core/src/main/java/com/jme3/scene/mesh/IndexBuffer.java @@ -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. * diff --git a/jme3-core/src/main/java/com/jme3/scene/mesh/IndexByteBuffer.java b/jme3-core/src/main/java/com/jme3/scene/mesh/IndexByteBuffer.java index 2c06c25a9..ab7461c2a 100644 --- a/jme3-core/src/main/java/com/jme3/scene/mesh/IndexByteBuffer.java +++ b/jme3-core/src/main/java/com/jme3/scene/mesh/IndexByteBuffer.java @@ -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; diff --git a/jme3-core/src/main/java/com/jme3/scene/mesh/IndexIntBuffer.java b/jme3-core/src/main/java/com/jme3/scene/mesh/IndexIntBuffer.java index 4412be260..ca109ba66 100644 --- a/jme3-core/src/main/java/com/jme3/scene/mesh/IndexIntBuffer.java +++ b/jme3-core/src/main/java/com/jme3/scene/mesh/IndexIntBuffer.java @@ -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); diff --git a/jme3-core/src/main/java/com/jme3/scene/mesh/IndexShortBuffer.java b/jme3-core/src/main/java/com/jme3/scene/mesh/IndexShortBuffer.java index 5f3c25ae9..e87b5533f 100644 --- a/jme3-core/src/main/java/com/jme3/scene/mesh/IndexShortBuffer.java +++ b/jme3-core/src/main/java/com/jme3/scene/mesh/IndexShortBuffer.java @@ -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; diff --git a/jme3-core/src/main/java/com/jme3/scene/mesh/VirtualIndexBuffer.java b/jme3-core/src/main/java/com/jme3/scene/mesh/VirtualIndexBuffer.java index 18fefa90a..64aa438eb 100644 --- a/jme3-core/src/main/java/com/jme3/scene/mesh/VirtualIndexBuffer.java +++ b/jme3-core/src/main/java/com/jme3/scene/mesh/VirtualIndexBuffer.java @@ -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){ diff --git a/jme3-core/src/main/java/com/jme3/util/BufferUtils.java b/jme3-core/src/main/java/com/jme3/util/BufferUtils.java index 72e50c8b0..628b2451d 100644 --- a/jme3-core/src/main/java/com/jme3/util/BufferUtils.java +++ b/jme3-core/src/main/java/com/jme3/util/BufferUtils.java @@ -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(); - } - } }