use of com.bulletphysics.util.IntArrayList in project bdx by GoranM.
the class HullLibrary method calchull.
private int calchull(ObjectArrayList<Vector3f> verts, int verts_count, IntArrayList tris_out, int[] tris_count, int vlimit) {
int rc = calchullgen(verts, verts_count, vlimit);
if (rc == 0)
return 0;
IntArrayList ts = new IntArrayList();
for (int i = 0; i < tris.size(); i++) {
if (tris.getQuick(i) != null) {
for (int j = 0; j < 3; j++) {
ts.add((tris.getQuick(i)).getCoord(j));
}
deAllocateTriangle(tris.getQuick(i));
}
}
tris_count[0] = ts.size() / 3;
MiscUtil.resize(tris_out, ts.size(), 0);
for (int i = 0; i < ts.size(); i++) {
tris_out.set(i, ts.get(i));
}
MiscUtil.resize(tris, 0, NEW_TRI_SUPPLIER);
return 1;
}
use of com.bulletphysics.util.IntArrayList in project jmonkeyengine by jMonkeyEngine.
the class BufferedTriangleCallback method getVertices.
/**
* Processes the given convex shape to retrieve a correctly ordered FloatBuffer to
* construct the shape from with a TriMesh.
*
* @param convexShape the shape to retreieve the vertices from.
* @return the vertices as a FloatBuffer, ordered as Triangles.
*/
private static FloatBuffer getVertices(ConvexShape convexShape) {
// Check there is a hull shape to render
if (convexShape.getUserPointer() == null) {
// create a hull approximation
ShapeHull hull = new ShapeHull(convexShape);
float margin = convexShape.getMargin();
hull.buildHull(margin);
convexShape.setUserPointer(hull);
}
// Assert state - should have a pointer to a hull (shape) that'll be drawn
assert convexShape.getUserPointer() != null : "Should have a shape for the userPointer, instead got null";
ShapeHull hull = (ShapeHull) convexShape.getUserPointer();
// Assert we actually have a shape to render
assert hull.numTriangles() > 0 : "Expecting the Hull shape to have triangles";
int numberOfTriangles = hull.numTriangles();
// The number of bytes needed is: (floats in a vertex) * (vertices in a triangle) * (# of triangles) * (size of float in bytes)
final int numberOfFloats = 3 * 3 * numberOfTriangles;
FloatBuffer vertices = BufferUtils.createFloatBuffer(numberOfFloats);
// Force the limit, set the cap - most number of floats we will use the buffer for
vertices.limit(numberOfFloats);
// Loop variables
final IntArrayList hullIndicies = hull.getIndexPointer();
final List<Vector3f> hullVertices = hull.getVertexPointer();
Vector3f vertexA, vertexB, vertexC;
int index = 0;
for (int i = 0; i < numberOfTriangles; i++) {
// Grab the data for this triangle from the hull
vertexA = hullVertices.get(hullIndicies.get(index++));
vertexB = hullVertices.get(hullIndicies.get(index++));
vertexC = hullVertices.get(hullIndicies.get(index++));
// Put the verticies into the vertex buffer
vertices.put(vertexA.x).put(vertexA.y).put(vertexA.z);
vertices.put(vertexB.x).put(vertexB.y).put(vertexB.z);
vertices.put(vertexC.x).put(vertexC.y).put(vertexC.z);
}
vertices.clear();
return vertices;
}
Aggregations