/** * @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; }
/** * @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; }
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); }
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); }
vb = new VertexBuffer(Type.Position); fb = BufferUtils.createFloatBuffer(vertCount * 3); vb.setupData(Usage.Static, 3, Format.Float, fb); mesh.setBuffer(vb); vb = new VertexBuffer(Type.Normal); fb = BufferUtils.createFloatBuffer(vertCount * 3); vb.setupData(Usage.Static, 3, Format.Float, fb); mesh.setBuffer(vb); vb = new VertexBuffer(Type.Color); fb = BufferUtils.createFloatBuffer(vertCount * 4); vb.setupData(Usage.Static, 4, Format.Float, fb); mesh.setBuffer(vb); vb = new VertexBuffer(Type.Tangent); fb = BufferUtils.createFloatBuffer(vertCount * dimensions); vb.setupData(Usage.Static, dimensions, Format.Float, fb); mesh.setBuffer(vb); vb = new VertexBuffer(Type.Binormal); fb = BufferUtils.createFloatBuffer(vertCount * 3); vb.setupData(Usage.Static, 3, Format.Float, fb); mesh.setBuffer(vb); vb.setupData(Usage.Static, dims, Format.Float, fb); mesh.setBuffer(vb);
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); }
transformInstanceData = new VertexBuffer(Type.InstanceData); transformInstanceData.setInstanced(true); transformInstanceData.setupData(Usage.Stream, INSTANCE_SIZE, Format.Float,
@Override public VertexBuffer populate(Integer bufferViewIndex, int componentType, String type, int count, int byteOffset, boolean normalized) throws IOException { if (bufferType == null) { logger.log(Level.WARNING, "could not assign data to any VertexBuffer type for buffer view " + bufferViewIndex); return null; } VertexBuffer vb = new VertexBuffer(bufferType); VertexBuffer.Format format = getVertexBufferFormat(componentType); VertexBuffer.Format originalFormat = format; if (normalized) { //Some float data can be packed into short buffers, "normalized" means they have to be unpacked. //In that case the buffer is a FloatBuffer format = VertexBuffer.Format.Float; } int numComponents = getNumberOfComponents(type); Buffer buff = VertexBuffer.createBuffer(format, numComponents, count); int bufferSize = numComponents * count; if (bufferViewIndex == null) { //no referenced buffer, specs says to pad the buffer with zeros. padBuffer(buff, bufferSize); } else { readBuffer(bufferViewIndex, byteOffset, count, buff, numComponents, originalFormat); } if (bufferType == VertexBuffer.Type.Index) { numComponents = 3; } vb.setupData(VertexBuffer.Usage.Dynamic, numComponents, format, buff); return vb; }
public void updatePositions(float xExt, float yExt, float zExt){ VertexBuffer pvb = getBuffer(Type.Position); FloatBuffer pb; if (pvb == null){ pvb = new VertexBuffer(Type.Position); pb = BufferUtils.createVector3Buffer(8); pvb.setupData(Usage.Dynamic, 3, Format.Float, pb); setBuffer(pvb); }else{ pb = (FloatBuffer) pvb.getData(); pvb.updateData(pb); } pb.rewind(); pb.put( new float[]{ -xExt, -yExt, zExt, xExt, -yExt, zExt, xExt, yExt, zExt, -xExt, yExt, zExt, -xExt, -yExt, -zExt, xExt, -yExt, -zExt, xExt, yExt, -zExt, -xExt, yExt, -zExt, } ); updateBound(); }
/** * Creates a points with bone lengths data. If the data is supplied then the points will show both head and tail of each bone. * @param skeleton * the skeleton that will be shown * @param boneLengths * a map between the bone's index and the bone's length */ public SkeletonPoints(Skeleton skeleton, Map<Integer, Float> boneLengths) { this.skeleton = skeleton; this.setMode(Mode.Points); int pointsCount = skeleton.getBoneCount(); if (boneLengths != null) { this.boneLengths = boneLengths; pointsCount *= 2; } VertexBuffer pb = new VertexBuffer(Type.Position); FloatBuffer fpb = BufferUtils.createFloatBuffer(pointsCount * 3); pb.setupData(Usage.Stream, 3, Format.Float, fpb); this.setBuffer(pb); this.updateCounts(); }
/** * Creates a {@link VertexBuffer} for the mesh or modifies * the existing one per the parameters given. * * @param type The type of the buffer * @param components Number of components * @param format Data format * @param buf The buffer data * * @throws UnsupportedOperationException If the buffer already set is * incompatible with the parameters given. */ public void setBuffer(Type type, int components, Format format, Buffer buf){ VertexBuffer vb = buffers.get(type.ordinal()); if (vb == null){ vb = new VertexBuffer(type); vb.setupData(Usage.Dynamic, components, format, buf); setBuffer(vb); }else{ if (vb.getNumComponents() != components || vb.getFormat() != format){ throw new UnsupportedOperationException("The buffer already set " + "is incompatible with the given parameters"); } vb.updateData(buf); updateCounts(); } }
/** * Creates buffers for points. Each line has POINT_AMOUNT of points. * @param skeleton * the skeleton that will be showed * @param boneLengths * the lengths of the bones */ public SkeletonInterBoneWire(Skeleton skeleton, Map<Integer, Float> boneLengths) { this.skeleton = skeleton; for (Bone bone : skeleton.getRoots()) { this.countConnections(bone); } this.setMode(Mode.Points); this.boneLengths = boneLengths; VertexBuffer pb = new VertexBuffer(Type.Position); FloatBuffer fpb = BufferUtils.createFloatBuffer(POINT_AMOUNT * connectionsAmount * 3); pb.setupData(Usage.Stream, 3, Format.Float, fpb); this.setBuffer(pb); this.updateCounts(); }
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); } } } }
bindPos.setupData(Usage.CpuOnly, pos.getNumComponents(), pos.getFormat(), if (norm != null) { VertexBuffer bindNorm = new VertexBuffer(Type.BindPoseNormal); bindNorm.setupData(Usage.CpuOnly, norm.getNumComponents(), norm.getFormat(), if (tangents != null) { VertexBuffer bindTangents = new VertexBuffer(Type.BindPoseTangent); bindTangents.setupData(Usage.CpuOnly, tangents.getNumComponents(), tangents.getFormat(),
public RenderDeviceJme(NiftyJmeDisplay display) { this.display = display; quadColor = new VertexBuffer(Type.Color); quadColor.setNormalized(true); ByteBuffer bb = BufferUtils.createByteBuffer(4 * 4); quadColor.setupData(Usage.Stream, 4, Format.UnsignedByte, bb); quad.setBuffer(quadColor); quadModTC.setUsage(Usage.Stream); // Load the 3 material types separately to avoid // reloading the shader when the defines change. // Material with a single color (no texture or vertex color) colorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); // Material with a texture and a color (no vertex color) textureColorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); // Material with vertex color, used for gradients (no texture) vertexColorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); vertexColorMaterial.setBoolean("VertexColor", true); // Shared render state for all materials renderState.setDepthTest(false); renderState.setDepthWrite(false); }
uvCoordsBuffer.setupData(Usage.Static, 3, com.jme3.scene.VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(uvCoordinates)); sphere.setBuffer(uvCoordsBuffer);