use of com.jme3.scene.VertexBuffer in project jmonkeyengine by jMonkeyEngine.
the class SkeletonWire method updateGeometry.
/**
* The method updates the geometry according to the poitions of the bones.
*/
public void updateGeometry() {
VertexBuffer vb = this.getBuffer(Type.Position);
FloatBuffer posBuf = this.getFloatBuffer(Type.Position);
posBuf.clear();
for (int i = 0; i < skeleton.getBoneCount(); ++i) {
Bone bone = skeleton.getBone(i);
Vector3f head = bone.getModelSpacePosition();
posBuf.put(head.getX()).put(head.getY()).put(head.getZ());
if (boneLengths != null) {
Vector3f tail = head.add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i))));
posBuf.put(tail.getX()).put(tail.getY()).put(tail.getZ());
}
}
posBuf.flip();
vb.updateData(posBuf);
this.updateBound();
}
use of com.jme3.scene.VertexBuffer in project jmonkeyengine by jMonkeyEngine.
the class WireBox method updatePositions.
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();
}
use of com.jme3.scene.VertexBuffer in project jmonkeyengine by jMonkeyEngine.
the class Line method updatePoints.
/**
* Update the start and end points of the line.
*/
public void updatePoints(Vector3f start, Vector3f end) {
VertexBuffer posBuf = getBuffer(Type.Position);
FloatBuffer fb = (FloatBuffer) posBuf.getData();
fb.rewind();
fb.put(start.x).put(start.y).put(start.z);
fb.put(end.x).put(end.y).put(end.z);
posBuf.updateData(fb);
updateBound();
}
use of com.jme3.scene.VertexBuffer in project jmonkeyengine by jMonkeyEngine.
the class LodGenerator method gatherIndexData.
private void gatherIndexData(Mesh mesh, List<Vertex> vertexLookup) {
VertexBuffer indexBuffer = mesh.getBuffer(VertexBuffer.Type.Index);
indexCount = indexBuffer.getNumElements() * 3;
Buffer b = indexBuffer.getDataReadOnly();
b.rewind();
while (b.remaining() != 0) {
Triangle tri = new Triangle();
tri.isRemoved = false;
triangleList.add(tri);
for (int i = 0; i < 3; i++) {
if (b instanceof IntBuffer) {
tri.vertexId[i] = ((IntBuffer) b).get();
} else {
//bit shift to avoid negative values due to conversion form short to int.
//we need an unsigned int here.
tri.vertexId[i] = ((ShortBuffer) b).get() & 0xffff;
}
// assert (tri.vertexId[i] < vertexLookup.size());
tri.vertex[i] = vertexLookup.get(tri.vertexId[i]);
//debug only;
tri.vertex[i].index = tri.vertexId[i];
}
if (tri.isMalformed()) {
if (!tri.isRemoved) {
logger.log(Level.FINE, "malformed triangle found with ID:{0}\n{1} It will be excluded from Lod level calculations.", new Object[] { triangleList.indexOf(tri), tri.toString() });
tri.isRemoved = true;
indexCount -= 3;
}
} else {
tri.computeNormal();
addTriangleToEdges(tri);
}
}
b.rewind();
}
use of com.jme3.scene.VertexBuffer in project chordatlas by twak.
the class TexGen method setTexture.
protected void setTexture(Geometry g, Material mat, int[] texSize, BufferedImage srcPano, File writeTo) {
if (!autoProject)
return;
if (cancel != null)
cancel.cancel();
cancel = new Cancellable();
new Thread() {
public void run() {
VertexBuffer vb = g.getMesh().getBuffer(VertexBuffer.Type.TexCoord);
VertexBuffer ib = g.getMesh().getBuffer(VertexBuffer.Type.Index);
VertexBuffer pb = g.getMesh().getBuffer(VertexBuffer.Type.Position);
float[][] pts = new float[3][3], uvs = new float[3][2];
BufferedImage target = new BufferedImage(texSize[0], texSize[1], BufferedImage.TYPE_3BYTE_BGR);
// if (false) {
for (int i = 0; i < ib.getNumElements(); i++) {
assert ib.getNumComponents() == 3;
for (int c = 0; c < ib.getNumComponents(); c++) {
int ind = ((Number) ib.getElementComponent(i, c)).intValue();
for (int x = 0; x < 3; x++) pts[c][x] = ((Number) pb.getElementComponent(ind, x)).floatValue();
for (int u = 0; u < 2; u++) uvs[c][u] = ((Number) vb.getElementComponent(ind, u)).floatValue() * texSize[u];
}
cast(pts, uvs, srcPano, target, cancel, texSize);
if (cancel.cancelled)
return;
}
try {
System.out.println("writing " + writeTo);
ImageIO.write(target, "png", writeTo);
} catch (IOException e) {
e.printStackTrace();
}
if (mat != null)
tweed.enqueue(new Callable<Spatial>() {
public Spatial call() throws Exception {
System.out.println("calculations complete");
TextureKey key = new TextureKey("Desktop/foo.png", false);
tweed.getAssetManager().deleteFromCache(key);
Texture texture = tweed.getAssetManager().loadTexture(key);
mat.setTexture("DiffuseMap", texture);
return null;
}
});
}
}.start();
}
Aggregations