package java3d; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.ShortBuffer; public abstract class IndexedGeometryArray extends GeometryArray { protected int indexCount; protected ShortBuffer indexBuffer = null; // コンストラクタ public IndexedGeometryArray(int vertexCount, int vertexFormat, int indexCount) { super(vertexCount, vertexFormat); this.indexCount = indexCount; ByteBuffer vbb = ByteBuffer.allocateDirect(indexCount * 2); vbb.order(ByteOrder.nativeOrder()); indexBuffer = vbb.asShortBuffer(); } /** オブジェクトのインデックス数を取得する */ public int getIndexCount() { return indexCount; } public int getCoordinateIndex(int index) { return indexBuffer.get(index); } public void setCoordinateIndex(int index, int coordinateIndex) { indexBuffer.put(index, (short)coordinateIndex); } public void setCoordinateIndices(int index, int[] coordinateIndicies) { indexBuffer.position(index); for (int i = 0; i < coordinateIndicies.length; i++) { indexBuffer.put((short)coordinateIndicies[i]); } indexBuffer.position(0); } public ShortBuffer getIndexBuffer() { return indexBuffer; } }