Search in sources :

Example 1 with IndexedMesh

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);
}
Also used : GImpactMeshShape(com.bulletphysics.extras.gimpact.GImpactMeshShape) TriangleIndexVertexArray(com.bulletphysics.collision.shapes.TriangleIndexVertexArray) IndexedMesh(com.bulletphysics.collision.shapes.IndexedMesh)

Example 2 with IndexedMesh

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);
}
Also used : BvhTriangleMeshShape(com.bulletphysics.collision.shapes.BvhTriangleMeshShape) TriangleIndexVertexArray(com.bulletphysics.collision.shapes.TriangleIndexVertexArray) IndexedMesh(com.bulletphysics.collision.shapes.IndexedMesh)

Example 3 with IndexedMesh

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;
}
Also used : IndexBuffer(com.jme3.scene.mesh.IndexBuffer) FloatBuffer(java.nio.FloatBuffer) IndexedMesh(com.bulletphysics.collision.shapes.IndexedMesh)

Example 4 with IndexedMesh

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;
}
Also used : IndexBuffer(com.jme3.scene.mesh.IndexBuffer) IndexedMesh(com.bulletphysics.collision.shapes.IndexedMesh) Mesh(com.jme3.scene.Mesh) FloatBuffer(java.nio.FloatBuffer)

Aggregations

IndexedMesh (com.bulletphysics.collision.shapes.IndexedMesh)4 TriangleIndexVertexArray (com.bulletphysics.collision.shapes.TriangleIndexVertexArray)2 IndexBuffer (com.jme3.scene.mesh.IndexBuffer)2 FloatBuffer (java.nio.FloatBuffer)2 BvhTriangleMeshShape (com.bulletphysics.collision.shapes.BvhTriangleMeshShape)1 GImpactMeshShape (com.bulletphysics.extras.gimpact.GImpactMeshShape)1 Mesh (com.jme3.scene.Mesh)1