Java Code Examples for com.jme3.util.BufferUtils#createVector3Buffer()
The following examples show how to use
com.jme3.util.BufferUtils#createVector3Buffer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StripBox.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected void doUpdateGeometryVertices() { FloatBuffer fpb = BufferUtils.createVector3Buffer(8 * 3); Vector3f[] v = computeVertices(); fpb.put(new float[] { v[0].x, v[0].y, v[0].z, v[1].x, v[1].y, v[1].z, v[2].x, v[2].y, v[2].z, v[3].x, v[3].y, v[3].z, v[4].x, v[4].y, v[4].z, v[5].x, v[5].y, v[5].z, v[6].x, v[6].y, v[6].z, v[7].x, v[7].y, v[7].z, }); setBuffer(Type.Position, 3, fpb); setMode(Mode.TriangleStrip); updateBound(); }
Example 2
Source File: StripBox.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
protected void duUpdateGeometryVertices() { FloatBuffer fpb = BufferUtils.createVector3Buffer(8 * 3); Vector3f[] v = computeVertices(); fpb.put(new float[] { v[0].x, v[0].y, v[0].z, v[1].x, v[1].y, v[1].z, v[2].x, v[2].y, v[2].z, v[3].x, v[3].y, v[3].z, v[4].x, v[4].y, v[4].z, v[5].x, v[5].y, v[5].z, v[6].x, v[6].y, v[6].z, v[7].x, v[7].y, v[7].z, }); setBuffer(Type.Position, 3, fpb); setMode(Mode.TriangleStrip); updateBound(); }
Example 3
Source File: Box.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void doUpdateGeometryVertices() { FloatBuffer fpb = BufferUtils.createVector3Buffer(24); Vector3f[] v = computeVertices(); fpb.put(new float[] { v[0].x, v[0].y, v[0].z, v[1].x, v[1].y, v[1].z, v[2].x, v[2].y, v[2].z, v[3].x, v[3].y, v[3].z, // back v[1].x, v[1].y, v[1].z, v[4].x, v[4].y, v[4].z, v[6].x, v[6].y, v[6].z, v[2].x, v[2].y, v[2].z, // right v[4].x, v[4].y, v[4].z, v[5].x, v[5].y, v[5].z, v[7].x, v[7].y, v[7].z, v[6].x, v[6].y, v[6].z, // front v[5].x, v[5].y, v[5].z, v[0].x, v[0].y, v[0].z, v[3].x, v[3].y, v[3].z, v[7].x, v[7].y, v[7].z, // left v[2].x, v[2].y, v[2].z, v[6].x, v[6].y, v[6].z, v[7].x, v[7].y, v[7].z, v[3].x, v[3].y, v[3].z, // top v[0].x, v[0].y, v[0].z, v[5].x, v[5].y, v[5].z, v[4].x, v[4].y, v[4].z, v[1].x, v[1].y, v[1].z // bottom }); setBuffer(Type.Position, 3, fpb); updateBound(); }
Example 4
Source File: Box.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
protected void duUpdateGeometryVertices() { FloatBuffer fpb = BufferUtils.createVector3Buffer(24); Vector3f[] v = computeVertices(); fpb.put(new float[] { v[0].x, v[0].y, v[0].z, v[1].x, v[1].y, v[1].z, v[2].x, v[2].y, v[2].z, v[3].x, v[3].y, v[3].z, // back v[1].x, v[1].y, v[1].z, v[4].x, v[4].y, v[4].z, v[6].x, v[6].y, v[6].z, v[2].x, v[2].y, v[2].z, // right v[4].x, v[4].y, v[4].z, v[5].x, v[5].y, v[5].z, v[7].x, v[7].y, v[7].z, v[6].x, v[6].y, v[6].z, // front v[5].x, v[5].y, v[5].z, v[0].x, v[0].y, v[0].z, v[3].x, v[3].y, v[3].z, v[7].x, v[7].y, v[7].z, // left v[2].x, v[2].y, v[2].z, v[6].x, v[6].y, v[6].z, v[7].x, v[7].y, v[7].z, v[3].x, v[3].y, v[3].z, // top v[0].x, v[0].y, v[0].z, v[5].x, v[5].y, v[5].z, v[4].x, v[4].y, v[4].z, v[1].x, v[1].y, v[1].z // bottom }); setBuffer(Type.Position, 3, fpb); updateBound(); }
Example 5
Source File: Torus.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void setGeometryData() { // allocate vertices int vertCount = (circleSamples + 1) * (radialSamples + 1); FloatBuffer fpb = BufferUtils.createVector3Buffer(vertCount); setBuffer(Type.Position, 3, fpb); // allocate normals if requested FloatBuffer fnb = BufferUtils.createVector3Buffer(vertCount); setBuffer(Type.Normal, 3, fnb); // allocate texture coordinates FloatBuffer ftb = BufferUtils.createVector2Buffer(vertCount); setBuffer(Type.TexCoord, 2, ftb); // generate geometry float inverseCircleSamples = 1.0f / circleSamples; float inverseRadialSamples = 1.0f / radialSamples; int i = 0; // generate the cylinder itself Vector3f radialAxis = new Vector3f(), torusMiddle = new Vector3f(), tempNormal = new Vector3f(); for (int circleCount = 0; circleCount < circleSamples; circleCount++) { // compute center point on torus circle at specified angle float circleFraction = circleCount * inverseCircleSamples; float theta = FastMath.TWO_PI * circleFraction; float cosTheta = FastMath.cos(theta); float sinTheta = FastMath.sin(theta); radialAxis.set(cosTheta, sinTheta, 0); radialAxis.mult(outerRadius, torusMiddle); // compute slice vertices with duplication at end point int iSave = i; for (int radialCount = 0; radialCount < radialSamples; radialCount++) { float radialFraction = radialCount * inverseRadialSamples; // in [0,1) float phi = FastMath.TWO_PI * radialFraction; float cosPhi = FastMath.cos(phi); float sinPhi = FastMath.sin(phi); tempNormal.set(radialAxis).multLocal(cosPhi); tempNormal.z += sinPhi; fnb.put(tempNormal.x).put(tempNormal.y).put( tempNormal.z); tempNormal.multLocal(innerRadius).addLocal(torusMiddle); fpb.put(tempNormal.x).put(tempNormal.y).put( tempNormal.z); ftb.put(radialFraction).put(circleFraction); i++; } BufferUtils.copyInternalVector3(fpb, iSave, i); BufferUtils.copyInternalVector3(fnb, iSave, i); ftb.put(1.0f).put(circleFraction); i++; } // duplicate the cylinder ends to form a torus for (int iR = 0; iR <= radialSamples; iR++, i++) { BufferUtils.copyInternalVector3(fpb, iR, i); BufferUtils.copyInternalVector3(fnb, iR, i); BufferUtils.copyInternalVector2(ftb, iR, i); ftb.put(i * 2 + 1, 1.0f); } }
Example 6
Source File: BoundingSphereDebug.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * builds the vertices based on the radius */ private void setGeometryData() { setMode(Mode.Lines); FloatBuffer posBuf = BufferUtils.createVector3Buffer((radialSamples + 1) * 3); FloatBuffer colBuf = BufferUtils.createVector3Buffer((radialSamples + 1) * 4); setBuffer(Type.Position, 3, posBuf); setBuffer(Type.Color, 4, colBuf); // generate geometry float fInvRS = 1.0f / radialSamples; // Generate points on the unit circle to be used in computing the mesh // points on a sphere slice. float[] afSin = new float[(radialSamples + 1)]; float[] afCos = new float[(radialSamples + 1)]; for (int iR = 0; iR < radialSamples; iR++) { float fAngle = FastMath.TWO_PI * fInvRS * iR; afCos[iR] = FastMath.cos(fAngle); afSin[iR] = FastMath.sin(fAngle); } afSin[radialSamples] = afSin[0]; afCos[radialSamples] = afCos[0]; for (int iR = 0; iR <= radialSamples; iR++) { posBuf.put(afCos[iR]) .put(afSin[iR]) .put(0); colBuf.put(ColorRGBA.Blue.r) .put(ColorRGBA.Blue.g) .put(ColorRGBA.Blue.b) .put(ColorRGBA.Blue.a); } for (int iR = 0; iR <= radialSamples; iR++) { posBuf.put(afCos[iR]) .put(0) .put(afSin[iR]); colBuf.put(ColorRGBA.Green.r) .put(ColorRGBA.Green.g) .put(ColorRGBA.Green.b) .put(ColorRGBA.Green.a); } for (int iR = 0; iR <= radialSamples; iR++) { posBuf.put(0) .put(afCos[iR]) .put(afSin[iR]); colBuf.put(ColorRGBA.Yellow.r) .put(ColorRGBA.Yellow.g) .put(ColorRGBA.Yellow.b) .put(ColorRGBA.Yellow.a); } updateBound(); setStatic(); }
Example 7
Source File: ParticlePointMesh.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void initParticleData(ParticleEmitter emitter, int numParticles) { setMode(Mode.Points); this.emitter = emitter; // set positions FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles); //if the buffer is already set only update the data VertexBuffer buf = getBuffer(VertexBuffer.Type.Position); if (buf != null) { buf.updateData(pb); } else { VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position); pvb.setupData(Usage.Stream, 3, Format.Float, pb); setBuffer(pvb); } // set colors ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4); buf = getBuffer(VertexBuffer.Type.Color); if (buf != null) { buf.updateData(cb); } else { VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color); cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb); cvb.setNormalized(true); setBuffer(cvb); } // set sizes FloatBuffer sb = BufferUtils.createFloatBuffer(numParticles); buf = getBuffer(VertexBuffer.Type.Size); if (buf != null) { buf.updateData(sb); } else { VertexBuffer svb = new VertexBuffer(VertexBuffer.Type.Size); svb.setupData(Usage.Stream, 1, Format.Float, sb); setBuffer(svb); } // set UV-scale FloatBuffer tb = BufferUtils.createFloatBuffer(numParticles*4); buf = getBuffer(VertexBuffer.Type.TexCoord); if (buf != null) { buf.updateData(tb); } else { VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord); tvb.setupData(Usage.Stream, 4, Format.Float, tb); setBuffer(tvb); } updateCounts(); }
Example 8
Source File: ParticleTriMesh.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void initParticleData(ParticleEmitter emitter, int numParticles) { setMode(Mode.Triangles); this.emitter = emitter; // particlesCopy = new Particle[numParticles]; // set positions FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles * 4); // if the buffer is already set only update the data VertexBuffer buf = getBuffer(VertexBuffer.Type.Position); if (buf != null) { buf.updateData(pb); } else { VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position); pvb.setupData(Usage.Stream, 3, Format.Float, pb); setBuffer(pvb); } // set colors ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4 * 4); buf = getBuffer(VertexBuffer.Type.Color); if (buf != null) { buf.updateData(cb); } else { VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color); cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb); cvb.setNormalized(true); setBuffer(cvb); } // set texcoords FloatBuffer tb = BufferUtils.createVector2Buffer(numParticles * 4); uniqueTexCoords = false; for (int i = 0; i < numParticles; i++){ tb.put(0f).put(1f); tb.put(1f).put(1f); tb.put(0f).put(0f); tb.put(1f).put(0f); } tb.flip(); buf = getBuffer(VertexBuffer.Type.TexCoord); if (buf != null) { buf.updateData(tb); } else { VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord); tvb.setupData(Usage.Static, 2, Format.Float, tb); setBuffer(tvb); } // set indices ShortBuffer ib = BufferUtils.createShortBuffer(numParticles * 6); for (int i = 0; i < numParticles; i++){ int startIdx = (i * 4); // triangle 1 ib.put((short)(startIdx + 1)) .put((short)(startIdx + 0)) .put((short)(startIdx + 2)); // triangle 2 ib.put((short)(startIdx + 1)) .put((short)(startIdx + 2)) .put((short)(startIdx + 3)); } ib.flip(); buf = getBuffer(VertexBuffer.Type.Index); if (buf != null) { buf.updateData(ib); } else { VertexBuffer ivb = new VertexBuffer(VertexBuffer.Type.Index); ivb.setupData(Usage.Static, 3, Format.UnsignedShort, ib); setBuffer(ivb); } updateCounts(); }
Example 9
Source File: Torus.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
private void setGeometryData() { // allocate vertices int vertCount = (circleSamples + 1) * (radialSamples + 1); FloatBuffer fpb = BufferUtils.createVector3Buffer(vertCount); setBuffer(Type.Position, 3, fpb); // allocate normals if requested FloatBuffer fnb = BufferUtils.createVector3Buffer(vertCount); setBuffer(Type.Normal, 3, fnb); // allocate texture coordinates FloatBuffer ftb = BufferUtils.createVector2Buffer(vertCount); setBuffer(Type.TexCoord, 2, ftb); // generate geometry float inverseCircleSamples = 1.0f / circleSamples; float inverseRadialSamples = 1.0f / radialSamples; int i = 0; // generate the cylinder itself Vector3f radialAxis = new Vector3f(), torusMiddle = new Vector3f(), tempNormal = new Vector3f(); for (int circleCount = 0; circleCount < circleSamples; circleCount++) { // compute center point on torus circle at specified angle float circleFraction = circleCount * inverseCircleSamples; float theta = FastMath.TWO_PI * circleFraction; float cosTheta = FastMath.cos(theta); float sinTheta = FastMath.sin(theta); radialAxis.set(cosTheta, sinTheta, 0); radialAxis.mult(outerRadius, torusMiddle); // compute slice vertices with duplication at end point int iSave = i; for (int radialCount = 0; radialCount < radialSamples; radialCount++) { float radialFraction = radialCount * inverseRadialSamples; // in [0,1) float phi = FastMath.TWO_PI * radialFraction; float cosPhi = FastMath.cos(phi); float sinPhi = FastMath.sin(phi); tempNormal.set(radialAxis).multLocal(cosPhi); tempNormal.z += sinPhi; fnb.put(tempNormal.x).put(tempNormal.y).put( tempNormal.z); tempNormal.multLocal(innerRadius).addLocal(torusMiddle); fpb.put(tempNormal.x).put(tempNormal.y).put( tempNormal.z); ftb.put(radialFraction).put(circleFraction); i++; } BufferUtils.copyInternalVector3(fpb, iSave, i); BufferUtils.copyInternalVector3(fnb, iSave, i); ftb.put(1.0f).put(circleFraction); i++; } // duplicate the cylinder ends to form a torus for (int iR = 0; iR <= radialSamples; iR++, i++) { BufferUtils.copyInternalVector3(fpb, iR, i); BufferUtils.copyInternalVector3(fnb, iR, i); BufferUtils.copyInternalVector2(ftb, iR, i); ftb.put(i * 2 + 1, 1.0f); } }
Example 10
Source File: ParticlePointMesh.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void initParticleData(ParticleEmitter emitter, int numParticles) { setMode(Mode.Points); this.emitter = emitter; // set positions FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles); VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position); pvb.setupData(Usage.Stream, 3, Format.Float, pb); //if the buffer is already set only update the data VertexBuffer buf = getBuffer(VertexBuffer.Type.Position); if (buf != null) { buf.updateData(pb); } else { setBuffer(pvb); } // set colors ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4); VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color); cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb); cvb.setNormalized(true); buf = getBuffer(VertexBuffer.Type.Color); if (buf != null) { buf.updateData(cb); } else { setBuffer(cvb); } // set sizes FloatBuffer sb = BufferUtils.createFloatBuffer(numParticles); VertexBuffer svb = new VertexBuffer(VertexBuffer.Type.Size); svb.setupData(Usage.Stream, 1, Format.Float, sb); buf = getBuffer(VertexBuffer.Type.Size); if (buf != null) { buf.updateData(sb); } else { setBuffer(svb); } // set UV-scale FloatBuffer tb = BufferUtils.createFloatBuffer(numParticles*4); VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord); tvb.setupData(Usage.Stream, 4, Format.Float, tb); buf = getBuffer(VertexBuffer.Type.TexCoord); if (buf != null) { buf.updateData(tb); } else { setBuffer(tvb); } }
Example 11
Source File: ParticleTriMesh.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void initParticleData(ParticleEmitter emitter, int numParticles) { setMode(Mode.Triangles); this.emitter = emitter; particlesCopy = new Particle[numParticles]; // set positions FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles * 4); VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position); pvb.setupData(Usage.Stream, 3, Format.Float, pb); //if the buffer is already set only update the data VertexBuffer buf = getBuffer(VertexBuffer.Type.Position); if (buf != null) { buf.updateData(pb); } else { setBuffer(pvb); } // set colors ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4 * 4); VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color); cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb); cvb.setNormalized(true); buf = getBuffer(VertexBuffer.Type.Color); if (buf != null) { buf.updateData(cb); } else { setBuffer(cvb); } // set texcoords VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord); FloatBuffer tb = BufferUtils.createVector2Buffer(numParticles * 4); uniqueTexCoords = false; for (int i = 0; i < numParticles; i++){ tb.put(0f).put(1f); tb.put(1f).put(1f); tb.put(0f).put(0f); tb.put(1f).put(0f); } tb.flip(); tvb.setupData(Usage.Static, 2, Format.Float, tb); buf = getBuffer(VertexBuffer.Type.TexCoord); if (buf != null) { buf.updateData(tb); } else { setBuffer(tvb); } // set indices ShortBuffer ib = BufferUtils.createShortBuffer(numParticles * 6); for (int i = 0; i < numParticles; i++){ int startIdx = (i * 4); // triangle 1 ib.put((short)(startIdx + 1)) .put((short)(startIdx + 0)) .put((short)(startIdx + 2)); // triangle 2 ib.put((short)(startIdx + 1)) .put((short)(startIdx + 2)) .put((short)(startIdx + 3)); } ib.flip(); VertexBuffer ivb = new VertexBuffer(VertexBuffer.Type.Index); ivb.setupData(Usage.Static, 3, Format.UnsignedShort, ib); buf = getBuffer(VertexBuffer.Type.Index); if (buf != null) { buf.updateData(ib); } else { setBuffer(ivb); } }