use of com.jme3.scene.VertexBuffer in project jmonkeyengine by jMonkeyEngine.
the class TangentBinormalGenerator method processTriangleStrip.
private static List<VertexData> processTriangleStrip(Mesh mesh, int[] index, Vector3f[] v, Vector2f[] t) {
IndexBuffer indexBuffer = mesh.getIndexBuffer();
FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
FloatBuffer textureBuffer = (FloatBuffer) mesh.getBuffer(Type.TexCoord).getData();
List<VertexData> vertices = initVertexData(vertexBuffer.limit() / 3);
index[0] = indexBuffer.get(0);
index[1] = indexBuffer.get(1);
populateFromBuffer(v[0], vertexBuffer, index[0]);
populateFromBuffer(v[1], vertexBuffer, index[1]);
populateFromBuffer(t[0], textureBuffer, index[0]);
populateFromBuffer(t[1], textureBuffer, index[1]);
for (int i = 2; i < indexBuffer.size(); i++) {
index[2] = indexBuffer.get(i);
BufferUtils.populateFromBuffer(v[2], vertexBuffer, index[2]);
BufferUtils.populateFromBuffer(t[2], textureBuffer, index[2]);
boolean isDegenerate = isDegenerateTriangle(v[0], v[1], v[2]);
TriangleData triData = processTriangle(index, v, t);
if (!isDegenerate) {
vertices.get(index[0]).triangles.add(triData);
vertices.get(index[1]).triangles.add(triData);
vertices.get(index[2]).triangles.add(triData);
}
Vector3f vTemp = v[0];
v[0] = v[1];
v[1] = v[2];
v[2] = vTemp;
Vector2f tTemp = t[0];
t[0] = t[1];
t[1] = t[2];
t[2] = tTemp;
index[0] = index[1];
index[1] = index[2];
}
return vertices;
}
use of com.jme3.scene.VertexBuffer in project jmonkeyengine by jMonkeyEngine.
the class TangentBinormalGenerator method genNormalLines.
public static Mesh genNormalLines(Mesh mesh, float scale) {
FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
FloatBuffer normalBuffer = (FloatBuffer) mesh.getBuffer(Type.Normal).getData();
ColorRGBA originColor = ColorRGBA.White;
ColorRGBA normalColor = ColorRGBA.Blue;
Mesh lineMesh = new Mesh();
lineMesh.setMode(Mesh.Mode.Lines);
Vector3f origin = new Vector3f();
Vector3f point = new Vector3f();
FloatBuffer lineVertex = BufferUtils.createFloatBuffer(vertexBuffer.limit() * 2);
FloatBuffer lineColor = BufferUtils.createFloatBuffer(vertexBuffer.limit() / 3 * 4 * 2);
for (int i = 0; i < vertexBuffer.limit() / 3; i++) {
populateFromBuffer(origin, vertexBuffer, i);
populateFromBuffer(point, normalBuffer, i);
int index = i * 2;
setInBuffer(origin, lineVertex, index);
setInBuffer(originColor, lineColor, index);
point.multLocal(scale);
point.addLocal(origin);
setInBuffer(point, lineVertex, index + 1);
setInBuffer(normalColor, lineColor, index + 1);
}
lineMesh.setBuffer(Type.Position, 3, lineVertex);
lineMesh.setBuffer(Type.Color, 4, lineColor);
lineMesh.setStatic();
//lineMesh.setInterleaved();
return lineMesh;
}
use of com.jme3.scene.VertexBuffer in project jmonkeyengine by jMonkeyEngine.
the class MikkTSpaceImpl method getTexCoord.
@Override
public void getTexCoord(float[] texOut, int face, int vert) {
int vertIndex = getIndex(face, vert);
VertexBuffer texCoord = mesh.getBuffer(VertexBuffer.Type.TexCoord);
FloatBuffer tex = (FloatBuffer) texCoord.getData();
tex.position(vertIndex * 2);
texOut[0] = tex.get();
texOut[1] = tex.get();
}
use of com.jme3.scene.VertexBuffer in project jmonkeyengine by jMonkeyEngine.
the class TestVertexBufferSharing method initOpenCL2.
private void initOpenCL2() {
//bind vertex buffer to OpenCL
VertexBuffer vb = geom.getMesh().getBuffer(VertexBuffer.Type.Position);
buffer = clContext.bindVertexBuffer(vb, MemoryAccess.READ_WRITE).register();
ws = new com.jme3.opencl.Kernel.WorkSize(geom.getMesh().getVertexCount());
}
use of com.jme3.scene.VertexBuffer in project jmonkeyengine by jMonkeyEngine.
the class TestLodGeneration method makeLod.
private void makeLod(final LodGenerator.TriangleReductionMethod method, final float value, final int ll) {
exec.execute(new Runnable() {
public void run() {
for (final Geometry geometry : listGeoms) {
LodGenerator lODGenerator = new LodGenerator(geometry);
final VertexBuffer[] lods = lODGenerator.computeLods(method, value);
enqueue(new Callable<Void>() {
public Void call() throws Exception {
geometry.getMesh().setLodLevels(lods);
lodLevel = 0;
if (geometry.getMesh().getNumLodLevels() > ll) {
lodLevel = ll;
}
geometry.setLodLevel(lodLevel);
hudText.setText(computeNbTri() + " tris");
return null;
}
});
}
}
});
}
Aggregations