private void setupTable(final Mesh mesh) { _lookupTable = new int[mesh.getMeshData().getVertexCount()]; for (int x = 0; x < _lookupTable.length; x++) { _lookupTable[x] = x; } }
private void setupTable(final Mesh mesh) { _lookupTable = new int[mesh.getMeshData().getVertexCount()]; for (int x = 0; x < _lookupTable.length; x++) { _lookupTable[x] = x; } }
public ProjectedGrid(final String name, final Camera camera, final int sizeX, final int sizeY, final float textureScale, final HeightGenerator heightGenerator, final Timer timer) { super(name); this.sizeX = sizeX; this.sizeY = sizeY; this.textureScale = textureScale; this.heightGenerator = heightGenerator; this.camera = camera; this.timer = timer; buildVertices(sizeX * sizeY); texs = BufferUtils.createVector2Buffer(_meshData.getVertexCount()); _meshData.setTextureBuffer(texs, 0); normBuf = BufferUtils.createVector3Buffer(_meshData.getVertexCount()); _meshData.setNormalBuffer(normBuf); vertBufArray = new float[_meshData.getVertexCount() * 3]; normBufArray = new float[_meshData.getVertexCount() * 3]; texBufArray = new float[_meshData.getVertexCount() * 2]; for (int i = 0; i < 24; i++) { intersections[i] = new Vector3(); } }
public ProjectedGrid(final String name, final Camera camera, final int sizeX, final int sizeY, final float textureScale, final HeightGenerator heightGenerator, final Timer timer) { super(name); this.sizeX = sizeX; this.sizeY = sizeY; this.textureScale = textureScale; this.heightGenerator = heightGenerator; this.camera = camera; this.timer = timer; buildVertices(sizeX * sizeY); texs = BufferUtils.createVector2Buffer(_meshData.getVertexCount()); _meshData.setTextureBuffer(texs, 0); normBuf = BufferUtils.createVector3Buffer(_meshData.getVertexCount()); _meshData.setNormalBuffer(normBuf); vertBufArray = new float[_meshData.getVertexCount() * 3]; normBufArray = new float[_meshData.getVertexCount() * 3]; texBufArray = new float[_meshData.getVertexCount() * 2]; for (int i = 0; i < 24; i++) { intersections[i] = new Vector3(); } }
private void setIndexData() { final IndexBufferData<?> indices = BufferUtils.createIndexBufferData(6 * _meshData.getVertexCount(), _meshData.getVertexCount() - 1); for (int i = _radialSamples; i < _meshData.getVertexCount() + (_radialSamples); i++) { indices.put(i); indices.put(i - _radialSamples); indices.put(i + 1); indices.put(i + 1); indices.put(i - _radialSamples); indices.put(i - _radialSamples + 1); } for (int i = 0, len = indices.getBufferCapacity(); i < len; i++) { int ind = indices.get(i); if (ind < 0) { ind += _meshData.getVertexCount(); indices.put(i, ind); } if (ind >= _meshData.getVertexCount()) { ind -= _meshData.getVertexCount(); indices.put(i, ind); } } indices.getBuffer().rewind(); _meshData.setIndices(indices); }
private void setIndexData() { final IndexBufferData<?> indices = BufferUtils.createIndexBufferData(6 * _meshData.getVertexCount(), _meshData.getVertexCount() - 1); for (int i = _radialSamples; i < _meshData.getVertexCount() + (_radialSamples); i++) { indices.put(i); indices.put(i - _radialSamples); indices.put(i + 1); indices.put(i + 1); indices.put(i - _radialSamples); indices.put(i - _radialSamples + 1); } for (int i = 0, len = indices.getBufferCapacity(); i < len; i++) { int ind = indices.get(i); if (ind < 0) { ind += _meshData.getVertexCount(); indices.put(i, ind); } if (ind >= _meshData.getVertexCount()) { ind -= _meshData.getVertexCount(); indices.put(i, ind); } } indices.getBuffer().rewind(); _meshData.setIndices(indices); }
/** * Sets every color of this geometry's color array to a random color. */ public void setRandomColors() { FloatBuffer colorBuf = _meshData.getColorBuffer(); if (colorBuf == null) { colorBuf = BufferUtils.createColorBuffer(_meshData.getVertexCount()); _meshData.setColorBuffer(colorBuf); } else { colorBuf.rewind(); } for (int x = 0, cLength = colorBuf.limit(); x < cLength; x += 4) { colorBuf.put(MathUtils.nextRandomFloat()); colorBuf.put(MathUtils.nextRandomFloat()); colorBuf.put(MathUtils.nextRandomFloat()); colorBuf.put(1); } colorBuf.flip(); }
/** * Sets every color of this geometry's color array to a random color. */ public void setRandomColors() { FloatBuffer colorBuf = _meshData.getColorBuffer(); if (colorBuf == null) { colorBuf = BufferUtils.createColorBuffer(_meshData.getVertexCount()); _meshData.setColorBuffer(colorBuf); } else { colorBuf.rewind(); } for (int x = 0, cLength = colorBuf.limit(); x < cLength; x += 4) { colorBuf.put(MathUtils.nextRandomFloat()); colorBuf.put(MathUtils.nextRandomFloat()); colorBuf.put(MathUtils.nextRandomFloat()); colorBuf.put(1); } colorBuf.flip(); }
/** * Random vertex. * * @param store * the vector object to store the result in. if null, a new one is created. * * @return a random vertex from the vertices stored in this MeshData. null is returned if there are no vertices. */ public Vector3 randomVertex(final Vector3 store) { if (_vertexCoords == null) { return null; } Vector3 result = store; if (result == null) { result = new Vector3(); } final int i = MathUtils.nextRandomInt(0, getVertexCount() - 1); BufferUtils.populateFromBuffer(result, _vertexCoords.getBuffer(), i); return result; }
@Override public void reorderVertexData(final int[] newVertexOrder) { if (_meshData != null) { reorderVertexData(newVertexOrder, _meshData); } reorderVertexData(newVertexOrder, _bindPoseData); // reorder weight/joint information final float[] weights = new float[_weights.length]; final short[] jointIndices = new short[_jointIndices.length]; for (int i = 0; i < _bindPoseData.getVertexCount(); i++) { for (int j = 0; j < _weightsPerVert; j++) { final int oldIndex = i * _weightsPerVert + j; final int newIndex = newVertexOrder[i] * _weightsPerVert + j; weights[newIndex] = _weights[oldIndex]; jointIndices[newIndex] = _jointIndices[oldIndex]; } } setWeights(weights); setJointIndices(jointIndices); }
@Override public void reorderVertexData(final int[] newVertexOrder) { if (_meshData != null) { reorderVertexData(newVertexOrder, _meshData); } reorderVertexData(newVertexOrder, _bindPoseData); // reorder weight/joint information final float[] weights = new float[_weights.length]; final short[] jointIndices = new short[_jointIndices.length]; for (int i = 0; i < _bindPoseData.getVertexCount(); i++) { for (int j = 0; j < _weightsPerVert; j++) { final int oldIndex = i * _weightsPerVert + j; final int newIndex = newVertexOrder[i] * _weightsPerVert + j; weights[newIndex] = _weights[oldIndex]; jointIndices[newIndex] = _jointIndices[oldIndex]; } } setWeights(weights); setJointIndices(jointIndices); }
/** * <code>setSolidColor</code> sets the color array of this geometry to a single color. For greater efficiency, try * setting the the ColorBuffer to null and using DefaultColor instead. * * @param color * the color to set. */ public void setSolidColor(final ReadOnlyColorRGBA color) { FloatBuffer colorBuf = _meshData.getColorBuffer(); if (colorBuf == null) { colorBuf = BufferUtils.createColorBuffer(_meshData.getVertexCount()); _meshData.setColorBuffer(colorBuf); } colorBuf.rewind(); for (int x = 0, cLength = colorBuf.remaining(); x < cLength; x += 4) { colorBuf.put(color.getRed()); colorBuf.put(color.getGreen()); colorBuf.put(color.getBlue()); colorBuf.put(color.getAlpha()); } colorBuf.flip(); }
/** * <code>setSolidColor</code> sets the color array of this geometry to a single color. For greater efficiency, try * setting the the ColorBuffer to null and using DefaultColor instead. * * @param color * the color to set. */ public void setSolidColor(final ReadOnlyColorRGBA color) { FloatBuffer colorBuf = _meshData.getColorBuffer(); if (colorBuf == null) { colorBuf = BufferUtils.createColorBuffer(_meshData.getVertexCount()); _meshData.setColorBuffer(colorBuf); } colorBuf.rewind(); for (int x = 0, cLength = colorBuf.remaining(); x < cLength; x += 4) { colorBuf.put(color.getRed()); colorBuf.put(color.getGreen()); colorBuf.put(color.getBlue()); colorBuf.put(color.getAlpha()); } colorBuf.flip(); }
/** * Random vertex. * * @param store * the vector object to store the result in. if null, a new one is created. * * @return a random vertex from the vertices stored in this MeshData. null is returned if there are no vertices. */ public Vector3 randomVertex(final Vector3 store) { final FloatBufferData vertexCoords = getVertexCoords(); if (vertexCoords == null) { return null; } Vector3 result = store; if (result == null) { result = new Vector3(); } final int i = MathUtils.nextRandomInt(0, getVertexCount() - 1); BufferUtils.populateFromBuffer(result, vertexCoords.getBuffer(), i); return result; }
private void setGeometryData(final int shellLess) { // generate geometry // center of disk _meshData.getVertexBuffer().put(0).put(0).put(0); for (int x = 0; x < _meshData.getVertexCount(); x++) { _meshData.getNormalBuffer().put(0).put(0).put(1); } _meshData.getTextureCoords(0).getBuffer().put(.5f).put(.5f); final double inverseShellLess = 1.0 / shellLess; final double inverseRadial = 1.0 / _radialSamples; final Vector3 radialFraction = new Vector3(); final Vector2 texCoord = new Vector2(); for (int radialCount = 0; radialCount < _radialSamples; radialCount++) { final double angle = MathUtils.TWO_PI * inverseRadial * radialCount; final double cos = MathUtils.cos(angle); final double sin = MathUtils.sin(angle); final Vector3 radial = new Vector3(cos, sin, 0); for (int shellCount = 1; shellCount < _shellSamples; shellCount++) { final double fraction = inverseShellLess * shellCount; // in (0,R] radialFraction.set(radial).multiplyLocal(fraction); final int i = shellCount + shellLess * radialCount; texCoord.setX(0.5 * (1.0 + radialFraction.getX())); texCoord.setY(0.5 * (1.0 + radialFraction.getY())); BufferUtils.setInBuffer(texCoord, _meshData.getTextureCoords(0).getBuffer(), i); radialFraction.multiplyLocal(_radius); BufferUtils.setInBuffer(radialFraction, _meshData.getVertexBuffer(), i); } } }
totalVertices += md.getVertexCount(); totalIndices += md.getIndices().capacity(); } else { totalIndices += md.getVertexCount();
.getVertexCount(); final int[] indices = new int[size]; for (int j = 0; j < size; j++) {
/** * Generates the connections */ private void setIndexData() { // allocate connectivity final int verts = ((_planes - 1) * (_radialSamples + 1)) + 1; final int tris = (_planes - 2) * _radialSamples * 2 + _radialSamples; _meshData.setIndices(BufferUtils.createIndexBufferData(3 * tris, verts - 1)); // generate connectivity // Generate only for middle planes for (int plane = 1; plane < (_planes - 1); plane++) { final int bottomPlaneStart = (plane - 1) * (_radialSamples + 1); final int topPlaneStart = plane * (_radialSamples + 1); for (int sample = 0; sample < _radialSamples; sample++) { _meshData.getIndices().put(bottomPlaneStart + sample); _meshData.getIndices().put(topPlaneStart + sample); _meshData.getIndices().put(bottomPlaneStart + sample + 1); _meshData.getIndices().put(bottomPlaneStart + sample + 1); _meshData.getIndices().put(topPlaneStart + sample); _meshData.getIndices().put(topPlaneStart + sample + 1); } } // pole triangles final int bottomPlaneStart = (_planes - 2) * (_radialSamples + 1); for (int samples = 0; samples < _radialSamples; samples++) { _meshData.getIndices().put(bottomPlaneStart + samples); _meshData.getIndices().put(_meshData.getVertexCount() - 1); _meshData.getIndices().put(bottomPlaneStart + samples + 1); } }
/** * Generates the connections */ private void setIndexData() { // allocate connectivity final int verts = ((_planes - 1) * (_radialSamples + 1)) + 1; final int tris = (_planes - 2) * _radialSamples * 2 + _radialSamples; _meshData.setIndices(BufferUtils.createIndexBufferData(3 * tris, verts - 1)); // generate connectivity // Generate only for middle planes for (int plane = 1; plane < (_planes - 1); plane++) { final int bottomPlaneStart = (plane - 1) * (_radialSamples + 1); final int topPlaneStart = plane * (_radialSamples + 1); for (int sample = 0; sample < _radialSamples; sample++) { _meshData.getIndices().put(bottomPlaneStart + sample); _meshData.getIndices().put(topPlaneStart + sample); _meshData.getIndices().put(bottomPlaneStart + sample + 1); _meshData.getIndices().put(bottomPlaneStart + sample + 1); _meshData.getIndices().put(topPlaneStart + sample); _meshData.getIndices().put(topPlaneStart + sample + 1); } } // pole triangles final int bottomPlaneStart = (_planes - 2) * (_radialSamples + 1); for (int samples = 0; samples < _radialSamples; samples++) { _meshData.getIndices().put(bottomPlaneStart + samples); _meshData.getIndices().put(_meshData.getVertexCount() - 1); _meshData.getIndices().put(bottomPlaneStart + samples + 1); } }
StatCollector.addStat(StatType.STAT_VERTEX_COUNT, meshData.getVertexCount()); StatCollector.addStat(StatType.STAT_MESH_COUNT, 1);