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); }
mesh.clearBuffer(Type.BoneIndex); mesh.clearBuffer(Type.BoneWeight);
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); }
clone.clearBuffer(Type.Position); clone.setBuffer(newPos); VertexBuffer oldNorm = getBuffer(Type.Normal); VertexBuffer newNorm = oldNorm.clone(); clone.clearBuffer(Type.Normal); clone.setBuffer(newNorm); VertexBuffer oldTang = getBuffer(Type.Tangent); VertexBuffer newTang = oldTang.clone(); clone.clearBuffer(Type.Tangent); clone.setBuffer(newTang);
mesh.clearBuffer(Type.Tangent); mesh.setBuffer(Type.Tangent, 4, tangents); mesh.clearBuffer(Type.BindPoseNormal); mesh.clearBuffer(Type.BindPosePosition); mesh.clearBuffer(Type.BindPoseTangent); mesh.generateBindPose(true);
Integer count = typesCount.get(buffer.getBufferType()); if (count != null && count < geoms.size()) { geom.getMesh().clearBuffer(buffer.getBufferType()); logger.log(Level.FINE, "removing {0} from {1}", new Object[]{buffer.getBufferType(), geom.getName()});
public static void generateBindPoseTangentsIfNecessary(Mesh mesh){ if (mesh.getBuffer(VertexBuffer.Type.BindPosePosition) != null) { VertexBuffer tangents = mesh.getBuffer(VertexBuffer.Type.Tangent); if (tangents != null) { VertexBuffer bindTangents = new VertexBuffer(VertexBuffer.Type.BindPoseTangent); bindTangents.setupData(VertexBuffer.Usage.CpuOnly, 4, VertexBuffer.Format.Float, BufferUtils.clone(tangents.getData())); if (mesh.getBuffer(VertexBuffer.Type.BindPoseTangent) != null) { mesh.clearBuffer(VertexBuffer.Type.BindPoseTangent); } mesh.setBuffer(bindTangents); tangents.setUsage(VertexBuffer.Usage.Stream); } } } }
terrainBlock.clearBuffer(Type.Index); if (lodIndices instanceof IntBuffer) terrainBlock.setBuffer(Type.Index, 3, (IntBuffer)lodIndices); terrainBlock.clearBuffer(Type.Index); terrainBlock.setBuffer(originalIndices);
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 void convertToList(Mesh mesh){ IndexBuffer inBuf = mesh.getIndicesAsList(); IndexBuffer outBuf = IndexBuffer.createIndexBuffer(mesh.getVertexCount(), inBuf.size()); for (int i = 0; i < inBuf.size(); i++){ outBuf.put(i, inBuf.get(i)); } mesh.clearBuffer(Type.Index); switch (mesh.getMode()){ case LineLoop: case LineStrip: mesh.setMode(Mode.Lines); break; case TriangleStrip: case TriangleFan: mesh.setMode(Mode.Triangles); break; default: break; } if (outBuf instanceof IndexIntBuffer){ mesh.setBuffer(Type.Index, 3, (IntBuffer)outBuf.getBuffer()); }else{ mesh.setBuffer(Type.Index, 3, (ShortBuffer)outBuf.getBuffer()); } }
newIndexBuf instanceof IndexIntBuffer ? Format.UnsignedInt : Format.UnsignedShort, newIndexBuf.getBuffer()); clearBuffer(Type.Index); setBuffer(newIdxBuf); clearBuffer(newVb.getBufferType()); setBuffer(newVb);
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); }
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); }
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); }
/** * Sets the {@link VertexBuffer} on the mesh. * This will update the vertex/triangle counts if needed. * * @param vb The buffer to set * @throws IllegalArgumentException If the buffer type is already set */ public void setBuffer(VertexBuffer vb){ // if (buffers.containsKey(vb.getBufferType().ordinal())) // throw new IllegalArgumentException("Buffer type already set: "+vb.getBufferType()); clearBuffer(vb.getBufferType()); buffers.put(vb.getBufferType().ordinal(), vb); buffersList.add(vb); updateCounts(); }
protected void setHeight(List<LocationHeight> locationHeights, boolean overrideHeight) { for (LocationHeight lh : locationHeights) { if (lh.x < 0 || lh.z < 0 || lh.x >= size || lh.z >= size) continue; int idx = lh.z * size + lh.x; if (overrideHeight) { geomap.getHeightArray()[idx] = lh.h; } else { float h = getMesh().getFloatBuffer(Type.Position).get(idx*3+1); geomap.getHeightArray()[idx] = h+lh.h; } } FloatBuffer newVertexBuffer = geomap.writeVertexArray(null, stepScale, false); getMesh().clearBuffer(Type.Position); getMesh().setBuffer(Type.Position, 3, newVertexBuffer); }
public static void generateBindPoseTangentsIfNecessary(Mesh mesh){ if (mesh.getBuffer(VertexBuffer.Type.BindPosePosition) != null) { VertexBuffer tangents = mesh.getBuffer(VertexBuffer.Type.Tangent); if (tangents != null) { VertexBuffer bindTangents = new VertexBuffer(VertexBuffer.Type.BindPoseTangent); bindTangents.setupData(VertexBuffer.Usage.CpuOnly, 4, VertexBuffer.Format.Float, BufferUtils.clone(tangents.getData())); if (mesh.getBuffer(VertexBuffer.Type.BindPoseTangent) != null) { mesh.clearBuffer(VertexBuffer.Type.BindPoseTangent); } mesh.setBuffer(bindTangents); tangents.setUsage(VertexBuffer.Usage.Stream); } } } }
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 void convertToList(Mesh mesh){ IndexBuffer inBuf = mesh.getIndicesAsList(); IndexBuffer outBuf = IndexBuffer.createIndexBuffer(mesh.getVertexCount(), inBuf.size()); for (int i = 0; i < inBuf.size(); i++){ outBuf.put(i, inBuf.get(i)); } mesh.clearBuffer(Type.Index); switch (mesh.getMode()){ case LineLoop: case LineStrip: mesh.setMode(Mode.Lines); break; case TriangleStrip: case TriangleFan: mesh.setMode(Mode.Triangles); break; default: break; } if (outBuf instanceof IndexIntBuffer){ mesh.setBuffer(Type.Index, 3, (IntBuffer)outBuf.getBuffer()); }else{ mesh.setBuffer(Type.Index, 3, (ShortBuffer)outBuf.getBuffer()); } }
public static void compressIndexBuffer(Mesh mesh){ int vertCount = mesh.getVertexCount(); VertexBuffer vb = mesh.getBuffer(Type.Index); Format targetFmt; if (vb.getFormat() == Format.UnsignedInt && vertCount <= 0xffff){ if (vertCount <= 256) targetFmt = Format.UnsignedByte; else targetFmt = Format.UnsignedShort; }else if (vb.getFormat() == Format.UnsignedShort && vertCount <= 0xff){ targetFmt = Format.UnsignedByte; }else{ return; } IndexBuffer src = mesh.getIndexBuffer(); Buffer newBuf = VertexBuffer.createBuffer(targetFmt, vb.getNumComponents(), src.size()); VertexBuffer newVb = new VertexBuffer(Type.Index); newVb.setupData(vb.getUsage(), vb.getNumComponents(), targetFmt, newBuf); mesh.clearBuffer(Type.Index); mesh.setBuffer(newVb); IndexBuffer dst = mesh.getIndexBuffer(); for (int i = 0; i < src.size(); i++){ dst.put(i, src.get(i)); } }