diff --git a/engine/src/core/com/jme3/scene/mesh/IndexBuffer.java b/engine/src/core/com/jme3/scene/mesh/IndexBuffer.java index 5c41c046b..3d02805f2 100644 --- a/engine/src/core/com/jme3/scene/mesh/IndexBuffer.java +++ b/engine/src/core/com/jme3/scene/mesh/IndexBuffer.java @@ -34,6 +34,9 @@ package com.jme3.scene.mesh; import com.jme3.util.BufferUtils; import java.nio.Buffer; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.ShortBuffer; /** * IndexBuffer is an abstraction for integer index buffers, @@ -44,6 +47,18 @@ import java.nio.Buffer; */ public abstract class IndexBuffer { + public static IndexBuffer wrapIndexBuffer(Buffer buf) { + if (buf instanceof ByteBuffer) { + return new IndexByteBuffer((ByteBuffer) buf); + } else if (buf instanceof ShortBuffer) { + return new IndexShortBuffer((ShortBuffer) buf); + } else if (buf instanceof IntBuffer) { + return new IndexIntBuffer((IntBuffer) buf); + } else { + throw new UnsupportedOperationException("Index buffer type unsupported: "+ buf.getClass()); + } + } + /** * Creates an index buffer that can contain the given amount * of vertices. diff --git a/engine/src/core/com/jme3/scene/mesh/IndexByteBuffer.java b/engine/src/core/com/jme3/scene/mesh/IndexByteBuffer.java index fd3bec410..c35d73b37 100644 --- a/engine/src/core/com/jme3/scene/mesh/IndexByteBuffer.java +++ b/engine/src/core/com/jme3/scene/mesh/IndexByteBuffer.java @@ -45,7 +45,8 @@ public class IndexByteBuffer extends IndexBuffer { private ByteBuffer buf; public IndexByteBuffer(ByteBuffer buffer) { - this.buf = buffer; + buf = buffer; + buf.rewind(); } @Override diff --git a/engine/src/core/com/jme3/scene/mesh/IndexIntBuffer.java b/engine/src/core/com/jme3/scene/mesh/IndexIntBuffer.java index 336930191..f479c9795 100644 --- a/engine/src/core/com/jme3/scene/mesh/IndexIntBuffer.java +++ b/engine/src/core/com/jme3/scene/mesh/IndexIntBuffer.java @@ -45,7 +45,8 @@ public class IndexIntBuffer extends IndexBuffer { private IntBuffer buf; public IndexIntBuffer(IntBuffer buffer) { - this.buf = buffer; + buf = buffer; + buf.rewind(); } @Override diff --git a/engine/src/core/com/jme3/scene/mesh/IndexShortBuffer.java b/engine/src/core/com/jme3/scene/mesh/IndexShortBuffer.java index 5017e6fb4..0b07ac76a 100644 --- a/engine/src/core/com/jme3/scene/mesh/IndexShortBuffer.java +++ b/engine/src/core/com/jme3/scene/mesh/IndexShortBuffer.java @@ -45,7 +45,8 @@ public class IndexShortBuffer extends IndexBuffer { private ShortBuffer buf; public IndexShortBuffer(ShortBuffer buffer) { - this.buf = buffer; + buf = buffer; + buf.rewind(); } @Override