public void setBuffer(Type type, int components, ByteBuffer buf) { setBuffer(type, components, Format.UnsignedByte, buf); }
public void setBuffer(Type type, int components, ShortBuffer buf) { setBuffer(type, components, Format.UnsignedShort, buf); }
/** * Set a floating point {@link VertexBuffer} on the mesh. * * @param type The type of {@link VertexBuffer}, * e.g. {@link Type#Position}, {@link Type#Normal}, etc. * * @param components Number of components on the vertex buffer, should * be between 1 and 4. * * @param buf The floating point data to contain */ public void setBuffer(Type type, int components, FloatBuffer buf) { setBuffer(type, components, Format.Float, buf); }
public void setBuffer(Type type, int components, IntBuffer buf) { setBuffer(type, components, Format.UnsignedInt, buf); }
public void setBuffer(Type type, int components, float[] buf){ setBuffer(type, components, BufferUtils.createFloatBuffer(buf)); }
public void setBuffer(Type type, int components, byte[] buf){ setBuffer(type, components, BufferUtils.createByteBuffer(buf)); }
public void setBuffer(Type type, int components, short[] buf){ setBuffer(type, components, BufferUtils.createShortBuffer(buf)); }
public void setBuffer(Type type, int components, int[] buf){ setBuffer(type, components, BufferUtils.createIntBuffer(buf)); }
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); }
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 void activateBuffer(Mesh mesh, int idx, int start, FloatBuffer b) { VertexBuffer.Type t = bufferTypes[start + idx]; VertexBuffer vb = mesh.getBuffer(t); // only set the buffer if it's different if (vb == null || vb.getData() != b) { mesh.setBuffer(t, 3, b); } }
public Mesh createMesh(Vector3f scale, Vector2f tcScale, boolean center){ FloatBuffer pb = writeVertexArray(null, scale, center); FloatBuffer tb = writeTexCoordArray(null, Vector2f.ZERO, tcScale); FloatBuffer nb = writeNormalArray(null, scale); IntBuffer ib = writeIndexArray(null); Mesh m = new Mesh(); m.setBuffer(Type.Position, 3, pb); m.setBuffer(Type.Normal, 3, nb); m.setBuffer(Type.TexCoord, 2, tb); m.setBuffer(Type.Index, 3, ib); m.setStatic(); m.updateBound(); return m; }
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 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); }
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; }
public void updateAll() { updatedPatch.setLod(newLod); updatedPatch.setLodRight(rightLod); updatedPatch.setLodTop(topLod); updatedPatch.setLodLeft(leftLod); updatedPatch.setLodBottom(bottomLod); if (newIndexBuffer != null && isReIndexNeeded()) { updatedPatch.setPreviousLod(previousLod); updatedPatch.getMesh().clearBuffer(Type.Index); if (newIndexBuffer instanceof IntBuffer) updatedPatch.getMesh().setBuffer(Type.Index, 3, (IntBuffer)newIndexBuffer); else if (newIndexBuffer instanceof ShortBuffer) updatedPatch.getMesh().setBuffer(Type.Index, 3, (ShortBuffer)newIndexBuffer); } }
public static Mesh getDebugMesh(CollisionShape shape) { Mesh mesh = null; if (shape.getCShape() instanceof ConvexShape) { mesh = new Mesh(); mesh.setBuffer(Type.Position, 3, getVertices((ConvexShape) shape.getCShape())); mesh.getFloatBuffer(Type.Position).clear(); } else if (shape.getCShape() instanceof ConcaveShape) { mesh = new Mesh(); mesh.setBuffer(Type.Position, 3, getVertices((ConcaveShape) shape.getCShape())); mesh.getFloatBuffer(Type.Position).clear(); } return mesh; }
/** * Create a mesh for visualizing the specified shape. * * @param shape (not null, unaffected) * @return a new mesh (not null) */ public static Mesh getDebugMesh(CollisionShape shape) { Mesh mesh = new Mesh(); DebugMeshCallback callback = new DebugMeshCallback(); long id = shape.getObjectId(); getVertices(id, callback); mesh.setBuffer(Type.Position, 3, callback.getVertices()); mesh.getFloatBuffer(Type.Position).clear(); return mesh; }
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); } }