/** * <code>setTextureData</code> sets the points that define the texture of the box. It's a one-to-one ratio, where * each plane of the box has it's own copy of the texture. That is, the texture is repeated one time for each six * faces. */ private void setTextureData() { if (_meshData.getTextureCoords(0) == null) { _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(24), 0); final FloatBuffer tex = _meshData.getTextureBuffer(0); for (int i = 0; i < 6; i++) { tex.put(1).put(0); tex.put(0).put(0); tex.put(0).put(1); tex.put(1).put(1); } } }
/** * Set the basic data for this mesh such as texture coordinates, index mode and our vertex buffer. */ private void initialize() { _meshData.setVertexCoords(new FloatBufferData(BufferUtils.createVector2Buffer(4), 2)); final FloatBuffer tbuf = BufferUtils.createVector2Buffer(4); _meshData.setTextureBuffer(tbuf, 0); tbuf.put(0).put(1); tbuf.put(0).put(0); tbuf.put(1).put(0); tbuf.put(1).put(1); _meshData.setIndexMode(IndexMode.TriangleFan); }
/** * <code>setTextureData</code> sets the points that define the texture of the box. It's a one-to-one ratio, where * each plane of the box has it's own copy of the texture. That is, the texture is repeated one time for each six * faces. */ private void setTextureData() { if (_meshData.getTextureCoords(0) == null) { _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(24), 0); final FloatBuffer tex = _meshData.getTextureBuffer(0); for (int i = 0; i < 6; i++) { tex.put(1).put(0); tex.put(0).put(0); tex.put(0).put(1); tex.put(1).put(1); } } }
/** * Set the basic data for this mesh such as texture coordinates, index mode and our vertex buffer. */ private void initialize() { final FloatBufferData vbuf = new FloatBufferData(BufferUtils.createVector2Buffer(4), 2); vbuf.setVboAccessMode(VBOAccessMode.DynamicDraw); _meshData.setVertexCoords(vbuf); final FloatBuffer tbuf = BufferUtils.createVector2Buffer(4); _meshData.setTextureBuffer(tbuf, 0); _meshData.getTextureCoords(0).setVboAccessMode(VBOAccessMode.DynamicDraw); tbuf.put(0).put(1); tbuf.put(0).put(0); tbuf.put(1).put(0); tbuf.put(1).put(1); _meshData.setIndexMode(IndexMode.TriangleFan); }
/** * Sets the correct texture array for the box. */ private void setTextureData() { if (_meshData.getTextureBuffer(0) == null) { _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(24), 0); for (int x = 0; x < 6; x++) { _meshData.getTextureCoords(0).getBuffer().put(_texTopRight.getXf()).put(_texTopRight.getYf()); _meshData.getTextureCoords(0).getBuffer().put(_texTopLeft.getXf()).put(_texTopLeft.getYf()); _meshData.getTextureCoords(0).getBuffer().put(_texBotLeft.getXf()).put(_texBotLeft.getYf()); _meshData.getTextureCoords(0).getBuffer().put(_texBotRight.getXf()).put(_texBotRight.getYf()); } } }
/** * Sets the correct texture array for the box. */ private void setTextureData() { if (_meshData.getTextureBuffer(0) == null) { _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(24), 0); for (int x = 0; x < 6; x++) { _meshData.getTextureCoords(0).getBuffer().put(_texTopRight.getXf()).put(_texTopRight.getYf()); _meshData.getTextureCoords(0).getBuffer().put(_texTopLeft.getXf()).put(_texTopLeft.getYf()); _meshData.getTextureCoords(0).getBuffer().put(_texBotLeft.getXf()).put(_texBotLeft.getYf()); _meshData.getTextureCoords(0).getBuffer().put(_texBotRight.getXf()).put(_texBotRight.getYf()); } } }
/** * Creates an Icosahedron (think of 20-sided dice) with center at the origin. The length of the sides will be as * specified in sideLength. * * @param name * The name of the Icosahedron. * @param sideLength * The length of each side of the Icosahedron. */ public Icosahedron(final String name, final double sideLength) { super(name); _sideLength = sideLength; // allocate vertices _meshData.setVertexBuffer(BufferUtils.createVector3Buffer(NUM_POINTS)); _meshData.setNormalBuffer(BufferUtils.createVector3Buffer(NUM_POINTS)); _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(NUM_POINTS), 0); setVertexData(); setNormalData(); setTextureData(); setIndexData(); }
/** * Check whether buffers have sufficient capacity to hold current string values; if not, increase capacity and set * the limit. * * @param text */ protected void checkBuffers(final String text) { final int chunkSize = 20; final int vertices = 6 * text.length(); final int chunks = 1 + (vertices / chunkSize); final int required = chunks * chunkSize; FloatBuffer vertexBuffer = getMeshData().getVertexBuffer(); FloatBuffer texCrdBuffer = getMeshData().getTextureBuffer(0); if (vertexBuffer == null || vertexBuffer.capacity() < required * 3) { vertexBuffer = BufferUtils.createVector3Buffer(required); texCrdBuffer = BufferUtils.createVector2Buffer(required); getMeshData().setVertexBuffer(vertexBuffer); getMeshData().setTextureBuffer(texCrdBuffer, 0); } vertexBuffer.limit(vertices * 3).rewind(); texCrdBuffer.limit(vertices * 2).rewind(); }
public BMTextBackground(final String name, final BMText text, final Texture texture, final ReadOnlyVector4 textureBorderOffsets) { super(name); _text = text; _texture = texture; _textureBorderOffsets.set(textureBorderOffsets); setRenderStates(texture); // allocate vertex data _meshData.setVertexBuffer(BufferUtils.createVector3Buffer(16)); _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(16), 0); _meshData.setIndices(BufferUtils.createIndexBufferData(28, 15)); // Set initial static data. setTextureData(); setIndexData(); setRenderMaterial("ui/textured/default_color.yaml"); // -- add self as change listener _text.addChangeListener(this); }
/** * Hexagon Constructor instantiates a new Hexagon. This element is center on 0,0,0 with all normals pointing up. The * user must move and rotate for positioning. * * @param name * the name of the scene element. This is required for identification and comparision purposes. * @param sideLength * The length of all the sides of the triangles */ public Hexagon(final String name, final float sideLength) { super(name); _sideLength = sideLength; // allocate vertices _meshData.setVertexBuffer(BufferUtils.createVector3Buffer(NUM_POINTS)); _meshData.setNormalBuffer(BufferUtils.createVector3Buffer(NUM_POINTS)); _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(NUM_POINTS), 0); _meshData.setIndices(BufferUtils.createIndexBufferData(3 * NUM_TRIS, NUM_POINTS - 1)); setVertexData(); setIndexData(); setTextureData(); setNormalData(); }
/** * Creates an octahedron with center at the origin. The lenght sides are given. * * @param name * The name of the octahedron. * @param sideLength * The length of each side of the octahedron. */ public Octahedron(final String name, final double sideLength) { super(name); _sideLength = sideLength; // allocate vertices _meshData.setVertexBuffer(BufferUtils.createVector3Buffer(NUM_POINTS)); _meshData.setNormalBuffer(BufferUtils.createVector3Buffer(NUM_POINTS)); _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(NUM_POINTS), 0); _meshData.setIndices(BufferUtils.createIndexBufferData(3 * NUM_TRIS, NUM_POINTS - 1)); setVertexData(); setNormalData(); setTextureData(); setIndexData(); }
private void allocateVertices() { final int verts = (2 * (_axisSamples + 1) * (_radialSamples + 1) + _radialSamples * 4); _meshData.setVertexBuffer(BufferUtils.createVector3Buffer(_meshData.getVertexBuffer(), verts)); _meshData.setNormalBuffer(BufferUtils.createVector3Buffer(_meshData.getNormalBuffer(), verts)); _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(_meshData.getTextureBuffer(0), verts), 0); final int tris = (4 * _radialSamples * (1 + _axisSamples)); if (_meshData.getIndices() == null || _meshData.getIndices().getBufferLimit() != 3 * tris) { _meshData.setIndices(BufferUtils.createIndexBufferData(3 * tris, verts - 1)); } setGeometryData(); setIndexData(); }
private void allocateVertices() { final int verts = (2 * (_axisSamples + 1) * (_radialSamples + 1) + _radialSamples * 4); _meshData.setVertexBuffer(BufferUtils.createVector3Buffer(_meshData.getVertexBuffer(), verts)); _meshData.setNormalBuffer(BufferUtils.createVector3Buffer(_meshData.getNormalBuffer(), verts)); _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(_meshData.getTextureBuffer(0), verts), 0); final int tris = (4 * _radialSamples * (1 + _axisSamples)); if (_meshData.getIndices() == null || _meshData.getIndices().getBufferLimit() != 3 * tris) { _meshData.setIndices(BufferUtils.createIndexBufferData(3 * tris, verts - 1)); } setGeometryData(); setIndexData(); }
private void allocateVertices() { // allocate vertices final int verts = _axisSamples * (_radialSamples + 1) + (_closed ? 2 : 0); _meshData.setVertexBuffer(BufferUtils.createVector3Buffer(_meshData.getVertexBuffer(), verts)); // allocate normals if requested _meshData.setNormalBuffer(BufferUtils.createVector3Buffer(_meshData.getNormalBuffer(), verts)); // allocate texture coordinates _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(verts), 0); final int count = ((_closed ? 2 : 0) + 2 * (_axisSamples - 1)) * _radialSamples; if (_meshData.getIndices() == null || _meshData.getIndices().getBufferLimit() != 3 * count) { _meshData.setIndices(BufferUtils.createIndexBufferData(3 * count, verts - 1)); } setGeometryData(); setIndexData(); }
private void allocateVertices() { // allocate vertices final int verts = _axisSamples * (_radialSamples + 1) + (_closed ? 2 : 0); _meshData.setVertexBuffer(BufferUtils.createVector3Buffer(_meshData.getVertexBuffer(), verts)); // allocate normals if requested _meshData.setNormalBuffer(BufferUtils.createVector3Buffer(_meshData.getNormalBuffer(), verts)); // allocate texture coordinates _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(verts), 0); final int count = ((_closed ? 2 : 0) + 2 * (_axisSamples - 1)) * _radialSamples; if (_meshData.getIndices() == null || _meshData.getIndices().getBufferLimit() != 3 * count) { _meshData.setIndices(BufferUtils.createIndexBufferData(3 * count, verts - 1)); } setGeometryData(); setIndexData(); }
private void recreateBuffers() { // determine vert quantity - first the sphere caps final int sampleLines = (2 * sphereSamples - 1 + axisSamples); final int verts = (radialSamples + 1) * sampleLines + 2; _meshData.setVertexBuffer(BufferUtils.createVector3Buffer(_meshData.getVertexBuffer(), verts)); // allocate normals _meshData.setNormalBuffer(BufferUtils.createVector3Buffer(_meshData.getNormalBuffer(), verts)); // allocate texture coordinates _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(verts), 0); // determine tri quantity final int tris = 2 * radialSamples * sampleLines; if (_meshData.getIndices() == null || _meshData.getIndices().getBufferLimit() != 3 * tris) { _meshData.setIndices(BufferUtils.createIndexBufferData(3 * tris, verts - 1)); } setGeometryData(); setIndexData(); }
private void recreateBuffers() { // determine vert quantity - first the sphere caps final int sampleLines = (2 * sphereSamples - 1 + axisSamples); final int verts = (radialSamples + 1) * sampleLines + 2; _meshData.setVertexBuffer(BufferUtils.createVector3Buffer(_meshData.getVertexBuffer(), verts)); // allocate normals _meshData.setNormalBuffer(BufferUtils.createVector3Buffer(_meshData.getNormalBuffer(), verts)); // allocate texture coordinates _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(verts), 0); // determine tri quantity final int tris = 2 * radialSamples * sampleLines; if (_meshData.getIndices() == null || _meshData.getIndices().getBufferLimit() != 3 * tris) { _meshData.setIndices(BufferUtils.createIndexBufferData(3 * tris, verts - 1)); } setGeometryData(); setIndexData(); }
private static Mesh createMesh() { final Mesh mesh = new Mesh(); mesh.getMeshData().setVertexCoords(new FloatBufferData(BufferUtils.createVector2Buffer(4), 2)); mesh.getMeshData().setTextureBuffer(BufferUtils.createVector2Buffer(4), 0); mesh.getMeshData().setIndexMode(IndexMode.TriangleFan); mesh.setRenderState(SubTexUtil._tstate); final BlendState blend = new BlendState(); blend.setBlendEnabled(true); blend.setSourceFunction(SourceFunction.SourceAlpha); blend.setDestinationFunction(DestinationFunction.OneMinusSourceAlpha); mesh.setRenderState(blend); mesh.updateWorldRenderStates(false); return mesh; } }
protected Mesh getFullScreenQuad() { if (_fsq != null) { return _fsq; } _fsq = new Mesh("fsq"); _fsq.getMeshData().setVertexBuffer(BufferUtils.createFloatBuffer(-1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1)); _fsq.getMeshData().setTextureBuffer(BufferUtils.createFloatBuffer(0, 0, 1, 0, 1, 1, 0, 1), 0); _fsq.getMeshData().setIndices(BufferUtils.createIndexBufferData(new int[] { 0, 1, 3, 1, 2, 3 }, 3)); _fsq.getSceneHints().setCullHint(CullHint.Never); _fsq.getSceneHints().setLightCombineMode(LightCombineMode.Off); final ZBufferState zState = new ZBufferState(); zState.setEnabled(false); _fsq.setRenderState(zState); _fsq.updateGeometricState(0); return _fsq; }
private static Mesh createMesh() { final Mesh mesh = new Mesh(); mesh.setRenderMaterial("ui/textured/default_color.yaml"); final MeshData meshData = mesh.getMeshData(); meshData.setVertexCoords(new FloatBufferData(BufferUtils.createVector2Buffer(4), 2)); meshData.setTextureBuffer(BufferUtils.createVector2Buffer(4), 0); meshData.setIndexMode(IndexMode.TriangleFan); meshData.getVertexCoords().setVboAccessMode(VBOAccessMode.DynamicDraw); mesh.setRenderState(SubTexUtil._tstate); final BlendState blend = new BlendState(); blend.setBlendEnabled(true); blend.setSourceFunction(SourceFunction.SourceAlpha); blend.setDestinationFunction(DestinationFunction.OneMinusSourceAlpha); mesh.setRenderState(blend); mesh.updateWorldRenderStates(false); return mesh; } }