private static FloatBuffer wrap(float[] data) { FloatBuffer buf = BufferUtils.createFloatBuffer(data.length); buf.put(data); buf.rewind(); return buf; }
private void mergeTargetBuffer(float[] array, float weight, FloatBuffer src, boolean init) { src.rewind(); for (int j = 0; j < src.capacity(); j++) { if (init) { array[j] = 0; } array[j] += weight * src.get(); } }
public void setVector4InArray(float x, float y, float z, float w, int index){ if (location == -1) { return; } if (varType != null && varType != VarType.Vector4Array) { throw new IllegalArgumentException("Expected a " + varType.name() + " value!"); } multiData.position(index * 4); multiData.put(x).put(y).put(z).put(w); multiData.rewind(); updateNeeded = true; setByCurrentMaterial = true; }
/** * <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; }
protected float[] getPoints(Mesh mesh) { FloatBuffer vertices = mesh.getFloatBuffer(Type.Position); vertices.rewind(); int components = mesh.getVertexCount() * 3; float[] pointsArray = new float[components]; for (int i = 0; i < components; i += 3) { pointsArray[i] = vertices.get(); pointsArray[i + 1] = vertices.get(); pointsArray[i + 2] = vertices.get(); } return pointsArray; } }
protected void updateMesh() { FloatBuffer pb = (FloatBuffer)mesh.getBuffer(Type.Position).getData(); pb.rewind(); float scale = 1 / 1000000f; // scaled to ms as pixels for( int i = 0; i < size; i++ ) { float t1 = frames[i * 2] * scale; float t2 = frames[i * 2 + 1] * scale; pb.put(i).put(0).put(0); pb.put(i).put(t1).put(0); pb.put(i).put(t1).put(0); pb.put(i).put(t2).put(0); } mesh.setBuffer(Type.Position, 3, pb); }
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); }
/** * Update the start and end points of the line. */ public void updatePoints(Vector3f start, Vector3f end) { VertexBuffer posBuf = getBuffer(Type.Position); FloatBuffer fb = (FloatBuffer) posBuf.getData(); fb.rewind(); fb.put(start.x).put(start.y).put(start.z); fb.put(end.x).put(end.y).put(end.z); posBuf.updateData(fb); updateBound(); }
/** * Copy the vertex positions from a JME mesh. * * @param mesh the mesh to read (not null) * @return a new array (not null, length a multiple of 3) */ protected float[] getPoints(Mesh mesh) { FloatBuffer vertices = mesh.getFloatBuffer(Type.Position); vertices.rewind(); int components = mesh.getVertexCount() * 3; float[] pointsArray = new float[components]; for (int i = 0; i < components; i += 3) { pointsArray[i] = vertices.get(); pointsArray[i + 1] = vertices.get(); pointsArray[i + 2] = vertices.get(); } return pointsArray; } }
private void writeCpuBuffer(int targetNumBuffers, MorphTarget mt) { if (targetNumBuffers >= 1) { FloatBuffer dest = mt.getBuffer(VertexBuffer.Type.Position); dest.rewind(); dest.put(tmpPosArray, 0, dest.capacity()); } if (targetNumBuffers >= 2) { FloatBuffer dest = mt.getBuffer(VertexBuffer.Type.Normal); dest.rewind(); dest.put(tmpNormArray, 0, dest.capacity()); } if (!approximateTangents && targetNumBuffers == 3) { FloatBuffer dest = mt.getBuffer(VertexBuffer.Type.Tangent); dest.rewind(); dest.put(tmpTanArray, 0, dest.capacity()); } }
@Override public void setTSpaceBasic(float[] tangent, float sign, int face, int vert) { int vertIndex = getIndex(face, vert); VertexBuffer tangentBuffer = mesh.getBuffer(VertexBuffer.Type.Tangent); FloatBuffer tan = (FloatBuffer) tangentBuffer.getData(); tan.position(vertIndex * 4); tan.put(tangent); tan.put(sign); tan.rewind(); tangentBuffer.setUpdateNeeded(); }
/** * <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 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(); }
/** * Create a new FloatBuffer of an appropriate size to hold the specified * number of Vector2f object data only if the given buffer if not already * the right size. * * @param buf * the buffer to first check and rewind * @param vertices * number of vertices that need to be held by the newly created * buffer * @return the requested new FloatBuffer */ public static FloatBuffer createVector2Buffer(FloatBuffer buf, int vertices) { if (buf != null && buf.limit() == 2 * vertices) { buf.rewind(); return buf; } return createFloatBuffer(2 * vertices); }
public void calculateBounds(Geometry3D geometry) { double radius = 0, maxRadius = 0; Vector3 vertex = new Vector3(); FloatBuffer vertices = geometry.getVertices(); vertices.rewind(); while(vertices.hasRemaining()) { vertex.x = vertices.get(); vertex.y = vertices.get(); vertex.z = vertices.get(); radius = vertex.length(); if(radius > maxRadius) maxRadius = radius; } mRadius = maxRadius; }
public static float[] getFloatArrayFromBuffer(FloatBuffer buffer) { float[] array = new float[0]; if (buffer != null) { if (buffer.hasArray()) { array = buffer.array(); } else { buffer.rewind(); array = new float[buffer.capacity()]; buffer.get(array); } } return array; }
protected FloatBuffer readFloatBuffer(byte[] content) throws IOException { int length = readInt(content); if (length == BinaryOutputCapsule.NULL_OBJECT) return null; if (BinaryImporter.canUseFastBuffers()){ ByteBuffer value = BufferUtils.createByteBuffer(length * 4); value.put(content, index, length * 4).rewind(); index += length * 4; return value.asFloatBuffer(); }else{ FloatBuffer value = BufferUtils.createFloatBuffer(length); for (int x = 0; x < length; x++) { value.put(readFloatForBuffer(content)); } value.rewind(); return value; } }
private void setListenerParams(Listener listener) { Vector3f pos = listener.getLocation(); Vector3f vel = listener.getVelocity(); Vector3f dir = listener.getDirection(); Vector3f up = listener.getUp(); al.alListener3f(AL_POSITION, pos.x, pos.y, pos.z); al.alListener3f(AL_VELOCITY, vel.x, vel.y, vel.z); fb.rewind(); fb.put(dir.x).put(dir.y).put(dir.z); fb.put(up.x).put(up.y).put(up.z); fb.flip(); al.alListener(AL_ORIENTATION, fb); al.alListenerf(AL_GAIN, listener.getVolume()); }
private void setColor(Geometry g, ColorRGBA color) { float[] colors = new float[g.getMesh().getVertexCount() * 4]; for (int i = 0; i < g.getMesh().getVertexCount() * 4; i += 4) { colors[i] = color.r; colors[i + 1] = color.g; colors[i + 2] = color.b; colors[i + 3] = color.a; } VertexBuffer colorBuff = g.getMesh().getBuffer(VertexBuffer.Type.Color); if (colorBuff == null) { g.getMesh().setBuffer(VertexBuffer.Type.Color, 4, colors); } else { FloatBuffer cBuff = (FloatBuffer) colorBuff.getData(); cBuff.rewind(); cBuff.put(colors); colorBuff.updateData(cBuff); } }