Search in sources :

Example 1 with HullDesc

use of spacegraph.space3d.phys.math.convexhull.HullDesc in project narchy by automenta.

the class ShapeHull method buildHull.

public boolean buildHull(float margin) {
    v3 norm = new v3();
    int numSampleDirections = NUM_UNITSPHERE_POINTS;
    int numPDA = shape.getNumPreferredPenetrationDirections();
    if (numPDA != 0) {
        for (int i = 0; i < numPDA; i++) {
            shape.getPreferredPenetrationDirection(i, norm);
            // return array[index];
            unitSpherePoints.get(numSampleDirections).set(norm);
            numSampleDirections++;
        }
    }
    FasterList<v3> supportPoints = new FasterList<>();
    MiscUtil.resize(supportPoints, NUM_UNITSPHERE_POINTS + ConvexShape.MAX_PREFERRED_PENETRATION_DIRECTIONS * 2, v3.class);
    for (int i = 0; i < numSampleDirections; i++) {
        // return array[index];
        // return array[index];
        shape.localGetSupportingVertex(unitSpherePoints.get(i), supportPoints.get(i));
    }
    HullDesc hd = new HullDesc();
    hd.flags = HullFlags.TRIANGLES;
    hd.vcount = numSampleDirections;
    // #ifdef BT_USE_DOUBLE_PRECISION
    // hd.mVertices = &supportPoints[0];
    // hd.mVertexStride = sizeof(btVector3);
    // #else
    hd.vertices = supportPoints;
    // hd.vertexStride = 3 * 4;
    // #endif
    HullLibrary hl = new HullLibrary();
    HullResult hr = new HullResult();
    if (!hl.createConvexHull(hd, hr)) {
        return false;
    }
    MiscUtil.resize(vertices, hr.numOutputVertices, v3.class);
    for (int i = 0; i < hr.numOutputVertices; i++) {
        // return array[index];
        // return array[index];
        vertices.get(i).set(hr.outputVertices.get(i));
    }
    numIndices = hr.numIndices;
    MiscUtil.resize(indices, numIndices, 0);
    for (int i = 0; i < numIndices; i++) {
        indices.set(i, hr.indices.get(i));
    }
    // free temporary hull result that we just copied
    HullLibrary.releaseResult(hr);
    return true;
}
Also used : HullDesc(spacegraph.space3d.phys.math.convexhull.HullDesc) FasterList(jcog.list.FasterList) HullResult(spacegraph.space3d.phys.math.convexhull.HullResult) spacegraph.util.math.v3(spacegraph.util.math.v3) HullLibrary(spacegraph.space3d.phys.math.convexhull.HullLibrary)

Aggregations

FasterList (jcog.list.FasterList)1 HullDesc (spacegraph.space3d.phys.math.convexhull.HullDesc)1 HullLibrary (spacegraph.space3d.phys.math.convexhull.HullLibrary)1 HullResult (spacegraph.space3d.phys.math.convexhull.HullResult)1 spacegraph.util.math.v3 (spacegraph.util.math.v3)1