Search in sources :

Example 1 with SurfaceMeshIntersector

use of maspack.collision.SurfaceMeshIntersector in project artisynth_core by artisynth.

the class CollisionManager method checkForContact.

void checkForContact(CollidableBody c0, CollidableBody c1, CollisionBehavior behav, boolean testMode) {
    if (c0.getCollidableIndex() > c1.getCollidableIndex()) {
        CollidableBody tmp = c0;
        c0 = c1;
        c1 = tmp;
    }
    PolygonalMesh mesh0 = c0.getCollisionMesh();
    PolygonalMesh mesh1 = c1.getCollisionMesh();
    ContactInfo cinfo;
    if (testMode) {
        cinfo = new ContactInfo(mesh0, mesh1);
    } else {
        ColliderType colliderType = behav.getColliderType();
        if (colliderType == ColliderType.SIGNED_DISTANCE) {
            // must be rigid and support signed distance grids
            if ((c0.isDeformable() || !c0.hasDistanceGrid()) && (c1.isDeformable() || !c1.hasDistanceGrid())) {
                colliderType = ColliderType.AJL_CONTOUR;
            }
        }
        // timer.start();
        switch(colliderType) {
            case AJL_CONTOUR:
                {
                    if (myAjlIntersector == null) {
                        myAjlIntersector = new SurfaceMeshIntersector();
                    }
                    // types of regions that we need to compute for mesh0 and mesh1
                    RegionType regions0 = RegionType.INSIDE;
                    RegionType regions1 = RegionType.INSIDE;
                    Method method = behav.getMethod();
                    if (method != Method.VERTEX_EDGE_PENETRATION && method != Method.CONTOUR_REGION && behav.getBodyFaceContact() == false) {
                        // regions for both meshes
                        if (CollisionHandler.isRigid(c0) && !CollisionHandler.isRigid(c1)) {
                            regions0 = RegionType.NONE;
                        } else if (CollisionHandler.isRigid(c1) && !CollisionHandler.isRigid(c0)) {
                            regions1 = RegionType.NONE;
                        }
                    }
                    cinfo = myAjlIntersector.findContoursAndRegions(mesh0, regions0, mesh1, regions1);
                    break;
                }
            case TRI_INTERSECTION:
                {
                    if (myTriTriCollider == null) {
                        myTriTriCollider = new MeshCollider();
                    }
                    cinfo = myTriTriCollider.getContacts(mesh0, mesh1);
                    break;
                }
            case SIGNED_DISTANCE:
                {
                    if (mySDCollider == null) {
                        mySDCollider = new SignedDistanceCollider();
                    }
                    cinfo = mySDCollider.getContacts(mesh0, c0.getDistanceGrid(), mesh1, c1.getDistanceGrid());
                    break;
                }
            default:
                {
                    throw new UnsupportedOperationException("Unimplemented collider type " + colliderType);
                }
        }
    // timer.stop();
    // System.out.println ("time=" + timer.getTimeUsec());
    // cinfo = myCollider.getContacts (mesh0, mesh1);
    }
    if (cinfo != null) {
        addOrUpdateHandler(cinfo, c0, c1, behav);
    }
}
Also used : RegionType(maspack.collision.SurfaceMeshIntersector.RegionType) MeshCollider(maspack.collision.MeshCollider) ContactInfo(maspack.collision.ContactInfo) SurfaceMeshIntersector(maspack.collision.SurfaceMeshIntersector) Method(artisynth.core.mechmodels.CollisionBehavior.Method) SignedDistanceCollider(maspack.collision.SignedDistanceCollider) PolygonalMesh(maspack.geometry.PolygonalMesh)

Aggregations

Method (artisynth.core.mechmodels.CollisionBehavior.Method)1 ContactInfo (maspack.collision.ContactInfo)1 MeshCollider (maspack.collision.MeshCollider)1 SignedDistanceCollider (maspack.collision.SignedDistanceCollider)1 SurfaceMeshIntersector (maspack.collision.SurfaceMeshIntersector)1 RegionType (maspack.collision.SurfaceMeshIntersector.RegionType)1 PolygonalMesh (maspack.geometry.PolygonalMesh)1