use of com.bulletphysics.collision.shapes.IndexedMesh in project jmonkeyengine by jMonkeyEngine.
the class GImpactCollisionShape method createShape.
protected void createShape() {
bulletMesh = new IndexedMesh();
bulletMesh.numVertices = numVertices;
bulletMesh.numTriangles = numTriangles;
bulletMesh.vertexStride = vertexStride;
bulletMesh.triangleIndexStride = triangleIndexStride;
bulletMesh.triangleIndexBase = triangleIndexBase;
bulletMesh.vertexBase = vertexBase;
bulletMesh.triangleIndexBase = triangleIndexBase;
TriangleIndexVertexArray tiv = new TriangleIndexVertexArray(numTriangles, triangleIndexBase, triangleIndexStride, numVertices, vertexBase, vertexStride);
cShape = new GImpactMeshShape(tiv);
cShape.setLocalScaling(Converter.convert(worldScale));
((GImpactMeshShape) cShape).updateBound();
cShape.setLocalScaling(Converter.convert(getScale()));
cShape.setMargin(margin);
}
use of com.bulletphysics.collision.shapes.IndexedMesh in project jmonkeyengine by jMonkeyEngine.
the class MeshCollisionShape method createShape.
protected void createShape() {
bulletMesh = new IndexedMesh();
bulletMesh.numVertices = numVertices;
bulletMesh.numTriangles = numTriangles;
bulletMesh.vertexStride = vertexStride;
bulletMesh.triangleIndexStride = triangleIndexStride;
bulletMesh.triangleIndexBase = triangleIndexBase;
bulletMesh.vertexBase = vertexBase;
bulletMesh.triangleIndexBase = triangleIndexBase;
TriangleIndexVertexArray tiv = new TriangleIndexVertexArray(numTriangles, triangleIndexBase, triangleIndexStride, numVertices, vertexBase, vertexStride);
cShape = new BvhTriangleMeshShape(tiv, true);
cShape.setLocalScaling(Converter.convert(getScale()));
cShape.setMargin(margin);
}
use of com.bulletphysics.collision.shapes.IndexedMesh in project jmonkeyengine by jMonkeyEngine.
the class Converter method convert.
public static synchronized IndexedMesh convert(Mesh mesh) {
IndexedMesh jBulletIndexedMesh = new IndexedMesh();
jBulletIndexedMesh.triangleIndexBase = ByteBuffer.allocate(mesh.getTriangleCount() * 3 * 4);
jBulletIndexedMesh.vertexBase = ByteBuffer.allocate(mesh.getVertexCount() * 3 * 4);
IndexBuffer indices = mesh.getIndicesAsList();
FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
vertices.rewind();
int verticesLength = mesh.getVertexCount() * 3;
jBulletIndexedMesh.numVertices = mesh.getVertexCount();
//3 verts * 4 bytes per.
jBulletIndexedMesh.vertexStride = 12;
for (int i = 0; i < verticesLength; i++) {
float tempFloat = vertices.get();
jBulletIndexedMesh.vertexBase.putFloat(tempFloat);
}
int indicesLength = mesh.getTriangleCount() * 3;
jBulletIndexedMesh.numTriangles = mesh.getTriangleCount();
//3 index entries * 4 bytes each.
jBulletIndexedMesh.triangleIndexStride = 12;
for (int i = 0; i < indicesLength; i++) {
jBulletIndexedMesh.triangleIndexBase.putInt(indices.get(i));
}
vertices.rewind();
vertices.clear();
return jBulletIndexedMesh;
}
use of com.bulletphysics.collision.shapes.IndexedMesh in project jmonkeyengine by jMonkeyEngine.
the class Converter method convert.
public static Mesh convert(IndexedMesh mesh) {
Mesh jmeMesh = new Mesh();
jmeMesh.setBuffer(Type.Index, 3, BufferUtils.createShortBuffer(mesh.numTriangles * 3));
jmeMesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(mesh.numVertices * 3));
IndexBuffer indicess = jmeMesh.getIndexBuffer();
FloatBuffer vertices = jmeMesh.getFloatBuffer(Type.Position);
for (int i = 0; i < mesh.numTriangles * 3; i++) {
indicess.put(i, mesh.triangleIndexBase.getInt(i * 4));
}
for (int i = 0; i < mesh.numVertices * 3; i++) {
vertices.put(i, mesh.vertexBase.getFloat(i * 4));
}
jmeMesh.updateCounts();
jmeMesh.updateBound();
jmeMesh.getFloatBuffer(Type.Position).clear();
return jmeMesh;
}
Aggregations