public void setBuffer(Type type, int components, short[] buf){ setBuffer(type, components, BufferUtils.createShortBuffer(buf)); }
/** * @return indexes buffer */ public Buffer getIndexBuffer() { if (indexes.size() <= Short.MAX_VALUE) { short[] indices = new short[indexes.size()]; for (int i = 0; i < indexes.size(); ++i) { indices[i] = indexes.get(i).shortValue(); } return BufferUtils.createShortBuffer(indices); } else { int[] indices = new int[indexes.size()]; for (int i = 0; i < indexes.size(); ++i) { indices[i] = indexes.get(i).intValue(); } return BufferUtils.createIntBuffer(indices); } }
/** * sets the indices for rendering the sphere. */ private void setIndexData() { // allocate connectivity int nbSegments = (radialSamples) * 3; ShortBuffer idxBuf = BufferUtils.createShortBuffer(2 * nbSegments); setBuffer(Type.Index, 2, idxBuf); int idx = 0; int segDone = 0; while (segDone < nbSegments) { idxBuf.put((short) idx); idxBuf.put((short) (idx + 1)); idx++; segDone++; if (segDone == radialSamples || segDone == radialSamples * 2) { idx++; } } }
public static ShortBuffer createShortBuffer(short... data) { if (data == null) { return null; } ShortBuffer buff = createShortBuffer(data.length); buff.clear(); buff.put(data); buff.flip(); return buff; }
protected void doUpdateGeometryIndices() { if (getBuffer(Type.Index) == null){ setBuffer(Type.Index, 3, BufferUtils.createShortBuffer(GEOMETRY_INDICES_DATA)); } }
protected void doUpdateGeometryIndices() { if (getBuffer(Type.Index) == null){ setBuffer(Type.Index, 3, BufferUtils.createShortBuffer(GEOMETRY_INDICES_DATA)); } }
ShortBuffer sib = BufferUtils.createShortBuffer(3 * triCount); setBuffer(Type.Index, 3, sib);
/** * Create a new ShortBuffer of an appropriate size to hold the specified * number of shorts only if the given buffer if not already the right size. * * @param buf * the buffer to first check and rewind * @param size * number of shorts that need to be held by the newly created * buffer * @return the requested new ShortBuffer */ public static ShortBuffer createShortBuffer(ShortBuffer buf, int size) { if (buf != null && buf.limit() == size) { buf.rewind(); return buf; } buf = createShortBuffer(size); return buf; }
+ ", data contains " + strings.length); ShortBuffer tmp = BufferUtils.createShortBuffer(strings.length); for (String s : strings) tmp.put(Short.valueOf(s)); tmp.flip();
protected ShortBuffer readShortBuffer(byte[] content) throws IOException { int length = readInt(content); if (length == BinaryOutputCapsule.NULL_OBJECT) return null; if (BinaryImporter.canUseFastBuffers()){ ByteBuffer value = BufferUtils.createByteBuffer(length * 2); value.put(content, index, length * 2).rewind(); index += length * 2; return value.asShortBuffer(); }else{ ShortBuffer value = BufferUtils.createShortBuffer(length); for (int x = 0; x < length; x++) { value.put(readShortForBuffer(content)); } value.rewind(); return value; } }
public WireSphere(float radius) { updatePositions(radius); ShortBuffer ib = BufferUtils.createShortBuffer(samples * 2 * 2 + zSamples * samples * 2 /*+ 3 * 2*/); setBuffer(Type.Index, 2, ib); // ib.put(new byte[]{ // (byte) 0, (byte) 1, // (byte) 2, (byte) 3, // (byte) 4, (byte) 5, // }); // int curNum = 3 * 2; int curNum = 0; for (int j = 0; j < 2 + zSamples; j++) { for (int i = curNum; i < curNum + samples - 1; i++) { ib.put((short) i).put((short) (i + 1)); } ib.put((short) (curNum + samples - 1)).put((short) curNum); curNum += samples; } setMode(Mode.Lines); updateBound(); updateCounts(); }
/** * Creates an index buffer that can contain the given amount * of vertices. * Returns {@link IndexShortBuffer} * * @param vertexCount The amount of vertices to contain * @param indexCount The amount of indices * to contain. * @return A new index buffer */ public static IndexBuffer createIndexBuffer(int vertexCount, int indexCount){ if (vertexCount > 65535){ return new IndexIntBuffer(BufferUtils.createIntBuffer(indexCount)); }else{ return new IndexShortBuffer(BufferUtils.createShortBuffer(indexCount)); } }
private void startLodFaceList(String submeshindex, String numfaces) { int index = Integer.parseInt(submeshindex); mesh = geoms.get(index).getMesh(); int faceCount = Integer.parseInt(numfaces); VertexBuffer originalIndexBuffer = mesh.getBuffer(Type.Index); vb = new VertexBuffer(VertexBuffer.Type.Index); if (originalIndexBuffer.getFormat() == Format.UnsignedInt) { // LOD buffer should also be integer ib = BufferUtils.createIntBuffer(faceCount * 3); sb = null; vb.setupData(Usage.Static, 3, Format.UnsignedInt, ib); } else { sb = BufferUtils.createShortBuffer(faceCount * 3); ib = null; vb.setupData(Usage.Static, 3, Format.UnsignedShort, sb); } List<VertexBuffer> levels = lodLevels.get(index); if (levels == null) { // Create the LOD levels list levels = new ArrayList<VertexBuffer>(); // Add the first LOD level (always the original index buffer) levels.add(originalIndexBuffer); lodLevels.put(index, levels); } levels.add(vb); }
case Short: case UnsignedShort: return BufferUtils.createShortBuffer(total); case Int: case UnsignedInt:
public static ShortBuffer ensureLargeEnough(ShortBuffer buffer, int required) { if (buffer != null) { buffer.limit(buffer.capacity()); } if (buffer == null || (buffer.remaining() < required)) { int position = (buffer != null ? buffer.position() : 0); ShortBuffer newVerts = createShortBuffer(position + required); if (buffer != null) { buffer.flip(); newVerts.put(buffer); newVerts.position(position); } buffer = newVerts; } return buffer; }
/** * Creates a new ShortBuffer with the same contents as the given * ShortBuffer. The new ShortBuffer is separate from the old one and changes * are not reflected across. If you want to reflect changes, consider using * Buffer.duplicate(). * * @param buf * the ShortBuffer to copy * @return the copy */ public static ShortBuffer clone(ShortBuffer buf) { if (buf == null) { return null; } buf.rewind(); ShortBuffer copy; if (isDirect(buf)) { copy = createShortBuffer(buf.limit()); } else { copy = ShortBuffer.allocate(buf.limit()); } copy.put(buf); return copy; }
public static Mesh convert(IndexedMesh mesh) { Mesh jmeMesh = new Mesh(); jmeMesh.setBuffer(Type.Index, 3, BufferUtils.createShortBuffer(mesh.numTriangles * 3)); jmeMesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(mesh.numVertices * 3)); IndexBuffer indicess = jmeMesh.getIndexBuffer(); FloatBuffer vertices = jmeMesh.getFloatBuffer(Type.Position); for (int i = 0; i < mesh.numTriangles * 3; i++) { indicess.put(i, mesh.triangleIndexBase.getInt(i * 4)); } for (int i = 0; i < mesh.numVertices * 3; i++) { vertices.put(i, mesh.vertexBase.getFloat(i * 4)); } jmeMesh.updateCounts(); jmeMesh.updateBound(); jmeMesh.getFloatBuffer(Type.Position).clear(); return jmeMesh; }
private void startFaces(String count) throws SAXException { int numFaces = parseInt(count); int indicesPerFace = 0; switch (mesh.getMode()) { case Triangles: indicesPerFace = 3; break; case Lines: indicesPerFace = 2; break; case Points: indicesPerFace = 1; break; default: throw new SAXException("Strips or fans not supported!"); } int numIndices = indicesPerFace * numFaces; vb = new VertexBuffer(VertexBuffer.Type.Index); if (!usesBigIndices) { sb = BufferUtils.createShortBuffer(numIndices); ib = null; vb.setupData(Usage.Static, indicesPerFace, Format.UnsignedShort, sb); } else { ib = BufferUtils.createIntBuffer(numIndices); sb = null; vb.setupData(Usage.Static, indicesPerFace, Format.UnsignedInt, ib); } mesh.setBuffer(vb); }
public static void setSkinBuffers(Mesh mesh, short[] jointsArray, float[] weightsArray, int componentSize) { if (componentSize == 1) { mesh.setBuffer(VertexBuffer.Type.BoneIndex, 4, BufferUtils.createByteBuffer(toByteArray(jointsArray))); } else { mesh.setBuffer(VertexBuffer.Type.BoneIndex, 4, BufferUtils.createShortBuffer(jointsArray)); } mesh.setBuffer(VertexBuffer.Type.BoneWeight, 4, BufferUtils.createFloatBuffer(weightsArray)); mesh.getBuffer(VertexBuffer.Type.BoneIndex).setUsage(VertexBuffer.Usage.CpuOnly); mesh.getBuffer(VertexBuffer.Type.BoneWeight).setUsage(VertexBuffer.Usage.CpuOnly); }
public Batch() { // setup mesh vertexPos.setupData(Usage.Stream, 2, VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(BATCH_MAX_VERTICES * 2)); vertexPosBuffer = (FloatBuffer) vertexPos.getData(); mesh.setBuffer(vertexPos); vertexTexCoord.setupData(Usage.Stream, 2, VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(BATCH_MAX_VERTICES * 2)); vertexTexCoordBuffer = (FloatBuffer) vertexTexCoord.getData(); mesh.setBuffer(vertexTexCoord); vertexColor.setupData(Usage.Stream, 4, VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(BATCH_MAX_VERTICES * 4)); vertexColorBuffer = (FloatBuffer) vertexColor.getData(); mesh.setBuffer(vertexColor); indexBuffer.setupData(Usage.Stream, 3, VertexBuffer.Format.UnsignedShort, BufferUtils.createShortBuffer(BATCH_MAX_QUADS * 2 * 3)); indexBufferBuffer = (ShortBuffer) indexBuffer.getData(); mesh.setBuffer(indexBuffer); material = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); material.setBoolean("VertexColor", true); renderState.setDepthTest(false); renderState.setDepthWrite(false); }