/** * Create a new FloatBuffer of an appropriate size to hold the specified * number of Vector3f object data. * * @param vertices * number of vertices that need to be held by the newly created * buffer * @return the requested new FloatBuffer */ public static FloatBuffer createVector3Buffer(int vertices) { FloatBuffer vBuff = createFloatBuffer(3 * vertices); return vBuff; }
/** * Create a new FloatBuffer of an appropriate size to hold the specified * number of Vector2f object data. * * @param vertices * number of vertices that need to be held by the newly created * buffer * @return the requested new FloatBuffer */ public static FloatBuffer createVector2Buffer(int vertices) { FloatBuffer vBuff = createFloatBuffer(2 * vertices); return vBuff; }
public FloatBuffer getVertices() { FloatBuffer buf = BufferUtils.createFloatBuffer(list.size() * 3); for (int i = 0; i < list.size(); i++) { Vector3f vector3f = list.get(i); buf.put(vector3f.x); buf.put(vector3f.y); buf.put(vector3f.z); } return buf; } }
/** * <code>toFloatBuffer</code> returns a FloatBuffer object that contains * the matrix data. * * @return matrix data as a FloatBuffer. */ public FloatBuffer toFloatBuffer() { FloatBuffer fb = BufferUtils.createFloatBuffer(9); fb.put(m00).put(m01).put(m02); fb.put(m10).put(m11).put(m12); fb.put(m20).put(m21).put(m22); fb.rewind(); return fb; }
public void setBuffer(Type type, int components, float[] buf){ setBuffer(type, components, BufferUtils.createFloatBuffer(buf)); }
/** * Retrieves the vertices from the Triangle buffer. */ public FloatBuffer getVertices() { // There are 3 floats needed for each vertex (x,y,z) final int numberOfFloats = vertices.size() * 3; FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(numberOfFloats); // Force the limit, set the cap - most number of floats we will use the buffer for verticesBuffer.limit(numberOfFloats); // Copy the values from the list to the direct float buffer for (Vector3f v : vertices) { verticesBuffer.put(v.x).put(v.y).put(v.z); } vertices.clear(); return verticesBuffer; } }
/** * @return normals buffer */ public VertexBuffer getNormalsBuffer() { VertexBuffer positionBuffer = new VertexBuffer(Type.Normal); Vector3f[] data = normals.toArray(new Vector3f[normals.size()]); positionBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(data)); return positionBuffer; }
/** * @return positions buffer */ public VertexBuffer getPositionsBuffer() { VertexBuffer positionBuffer = new VertexBuffer(Type.Position); Vector3f[] data = verts.toArray(new Vector3f[verts.size()]); positionBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(data)); return positionBuffer; }
protected final void createMesh() { if( mesh == null ) { mesh = new Mesh(); mesh.setMode(Mesh.Mode.Lines); } mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(size * 4 * 3)); FloatBuffer cb = BufferUtils.createFloatBuffer(size * 4 * 4); for( int i = 0; i < size; i++ ) { // For each index we add 4 colors, one for each line // endpoint for two layers. cb.put(0.5f).put(0.5f).put(0).put(1); cb.put(1).put(1).put(0).put(1); cb.put(0).put(0.5f).put(0.5f).put(1); cb.put(0).put(1).put(1).put(1); } mesh.setBuffer(Type.Color, 4, cb); }
private static void writeColorBuffer(List<VertexData> vertices, ColorRGBA[] cols, Mesh mesh) { FloatBuffer colors = BufferUtils.createFloatBuffer(vertices.size() * 4); colors.rewind(); for (ColorRGBA color : cols) { colors.put(color.r); colors.put(color.g); colors.put(color.b); colors.put(color.a); } mesh.clearBuffer(Type.Color); mesh.setBuffer(Type.Color, 4, colors); }
protected void doUpdateGeometryTextures() { if (getBuffer(Type.TexCoord) == null){ setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(GEOMETRY_TEXTURE_DATA)); } }
protected void doUpdateGeometryNormals() { if (getBuffer(Type.Normal) == null){ setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(GEOMETRY_NORMALS_DATA)); } }
protected void doUpdateGeometryTextures() { if (getBuffer(Type.TexCoord) == null){ setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(GEOMETRY_TEXTURE_DATA)); } }
/** * Generate a new FloatBuffer using the given array of float primitives. * * @param data * array of float primitives to place into a new FloatBuffer */ public static FloatBuffer createFloatBuffer(float... data) { if (data == null) { return null; } FloatBuffer buff = createFloatBuffer(data.length); buff.clear(); buff.put(data); buff.flip(); return buff; }
/** * <code>toFloatBuffer</code> returns a FloatBuffer object that contains the * matrix data. * * @param columnMajor * if true, this buffer should be filled with column major data, * otherwise it will be filled row major. * @return matrix data as a FloatBuffer. The position is set to 0 for * convenience. */ public FloatBuffer toFloatBuffer(boolean columnMajor) { FloatBuffer fb = BufferUtils.createFloatBuffer(16); fillFloatBuffer(fb, columnMajor); fb.rewind(); return fb; }
public MikkTSpaceImpl(Mesh mesh) { this.mesh = mesh; //replacing any existing tangent buffer, if you came here you want them new. mesh.clearBuffer(VertexBuffer.Type.Tangent); FloatBuffer fb = BufferUtils.createFloatBuffer(mesh.getVertexCount() * 4); mesh.setBuffer(VertexBuffer.Type.Tangent, 4, fb); }
@Override public void simpleUpdate(float tpf) { ByteBuffer buf = BufferUtils.createByteBuffer(500000); BufferUtils.destroyDirectBuffer(buf); FloatBuffer buf2 = BufferUtils.createFloatBuffer(500000); BufferUtils.destroyDirectBuffer(buf2); }
public void update(Vector3f[] points){ VertexBuffer vb = getBuffer(Type.Position); if (vb == null){ setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(points)); return; } FloatBuffer b = BufferUtils.createFloatBuffer(points); FloatBuffer a = (FloatBuffer) vb.getData(); b.rewind(); a.rewind(); a.put(b); a.rewind(); vb.updateData(a); updateBound(); }
protected void doUpdateGeometryNormals() { if (getBuffer(Type.Normal) == null){ float[] normals = new float[8 * 3]; Vector3f[] vert = computeVertices(); Vector3f norm = new Vector3f(); for (int i = 0; i < 8; i++) { norm.set(vert[i]).normalizeLocal(); normals[i * 3 + 0] = norm.x; normals[i * 3 + 1] = norm.y; normals[i * 3 + 2] = norm.z; } setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals)); } }
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); }