Search in sources :

Example 1 with ContactInfo

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

the class MeshCollisionViewer method render.

public void render(Renderer renderer, int flags) {
    ContactInfo cinfo = myContactInfo;
    if (contourWidth > 0 && cinfo != null) {
        renderer.setShading(Shading.NONE);
        renderer.setLineWidth(contourWidth);
        renderer.setPointSize(contourWidth);
        renderer.setColor(contourColor, /*highlight=*/
        false);
        if (cinfo.getContours() != null) {
            for (IntersectionContour contour : cinfo.getContours()) {
                renderer.beginDraw(DrawMode.LINE_LOOP);
                for (IntersectionPoint p : contour) {
                    renderer.addVertex(p);
                }
                renderer.endDraw();
            }
        }
        Point3d pnt = new Point3d();
        renderer.beginDraw(DrawMode.POINTS);
        for (PenetratingPoint p : cinfo.getPenetratingPoints(0)) {
            pnt.set(p.vertex.pnt);
            pnt.transform(myMesh1.getMeshToWorld());
            renderer.addVertex(pnt);
        }
        for (PenetratingPoint p : cinfo.getPenetratingPoints(1)) {
            pnt.set(p.vertex.pnt);
            pnt.transform(myMesh2.getMeshToWorld());
            renderer.addVertex(pnt);
        }
        renderer.endDraw();
        renderer.setShading(Shading.FLAT);
        renderer.setLineWidth(1);
        renderer.setPointSize(1);
    }
}
Also used : IntersectionContour(maspack.collision.IntersectionContour) PenetratingPoint(maspack.collision.PenetratingPoint) IntersectionPoint(maspack.collision.IntersectionPoint) Point3d(maspack.matrix.Point3d) ContactInfo(maspack.collision.ContactInfo)

Example 2 with ContactInfo

use of maspack.collision.ContactInfo 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)

Example 3 with ContactInfo

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

the class CollisionRenderer method prerender.

public void prerender(CollisionHandler handler, RenderProps props) {
    RenderObject ro = new RenderObject();
    ro.clearAll();
    // constraints
    ro.createLineGroup();
    // segments
    ro.createLineGroup();
    // contours
    ro.createLineGroup();
    // contact info
    ro.createPointGroup();
    // intersection faces
    ro.createTriangleGroup();
    // create default dummy normal
    ro.addNormal(0, 0, 0);
    CollisionBehavior behav = handler.myBehavior;
    ContactInfo cinfo = handler.getLastContactInfo();
    if (behav.myDrawConstraints) {
        ro.lineGroup(CONSTRAINT_GRP);
        double nrmlLen = handler.getContactNormalLen();
        if (nrmlLen > 0) {
            addConstraintRenderInfo(ro, handler.myBilaterals0.values(), nrmlLen);
            addConstraintRenderInfo(ro, handler.myBilaterals1.values(), nrmlLen);
            addConstraintRenderInfo(ro, handler.myUnilaterals, nrmlLen);
        }
    }
    double normalLen = 0;
    if (behav.getDrawContactNormals()) {
        normalLen = handler.getContactNormalLen();
    }
    if (normalLen != 0 && cinfo != null) {
        ro.lineGroup(SEGMENT_GRP);
        Method method = handler.getMethod();
        if (method == Method.CONTOUR_REGION) {
            int numc = 0;
            for (ContactPlane region : cinfo.getContactPlanes()) {
                for (Point3d p : region.points) {
                    if (numc >= handler.myMaxUnilaterals) {
                        break;
                    }
                    addLineSeg(ro, p, region.normal, normalLen);
                }
            }
        } else if (method != Method.INACTIVE) {
            for (ContactConstraint cc : handler.myBilaterals0.values()) {
                maybeAddVertexFaceNormal(ro, cc, normalLen);
            }
            for (ContactConstraint cc : handler.myBilaterals1.values()) {
                maybeAddVertexFaceNormal(ro, cc, normalLen);
            }
        }
    }
    if (behav.myDrawIntersectionContours && props.getEdgeWidth() > 0 && cinfo != null) {
        ro.lineGroup(CONTOUR_GRP);
        // offset lines
        if (cinfo.getContours() != null) {
            for (IntersectionContour contour : cinfo.getContours()) {
                int vidx0 = ro.numVertices();
                for (IntersectionPoint p : contour) {
                    ro.addVertex(ro.addPosition((float) p.x, (float) p.y, (float) p.z));
                }
                int vidx1 = ro.numVertices() - 1;
                ro.addLineLoop(vidx0, vidx1);
            }
        } else if (cinfo.getIntersections() != null) {
            // use intersections to render lines
            for (TriTriIntersection tsect : cinfo.getIntersections()) {
                addLineSeg(ro, tsect.points[0], tsect.points[1]);
            }
        }
    }
    if (behav.myDrawIntersectionPoints && cinfo != null) {
        if (cinfo.getIntersections() != null) {
            for (TriTriIntersection tsect : cinfo.getIntersections()) {
                for (Point3d pnt : tsect.points) {
                    addPoint(ro, pnt);
                }
            }
        }
        for (PenetratingPoint cpp : cinfo.getPenetratingPoints(0)) {
            if (cpp.distance > 0) {
                addPoint(ro, cpp.vertex.getWorldPoint());
            }
        }
        for (PenetratingPoint cpp : cinfo.getPenetratingPoints(1)) {
            if (cpp.distance > 0) {
                addPoint(ro, cpp.vertex.getWorldPoint());
            }
        }
        if (behav.getMethod() == CollisionBehavior.Method.VERTEX_EDGE_PENETRATION) {
            if (cinfo.getEdgeEdgeContacts() != null) {
                for (EdgeEdgeContact eec : cinfo.getEdgeEdgeContacts()) {
                    addPoint(ro, eec.point0);
                    addPoint(ro, eec.point1);
                }
            }
        }
    }
    if (behav.myDrawIntersectionFaces && cinfo != null) {
        ArrayList<TriTriIntersection> intersections = cinfo.getIntersections();
        if (intersections != null) {
            buildFaceSegments(ro, handler, intersections);
        }
    }
    RenderObject oldRob = myRob;
    myRob = ro;
    // if (oldRob != null) {
    // oldRob.dispose();
    // }
    RenderObject rd = null;
    if (behav.myDrawPenetrationDepth != -1 && cinfo != null) {
        int num = behav.myDrawPenetrationDepth;
        Collidable b0 = behav.getCollidable(0);
        CollidableBody h0 = handler.getCollidable(0);
        if (!(b0 instanceof Group)) {
            if (h0 != b0 && h0.getCollidableAncestor() != b0) {
                // then we want the *other* collidable body, so switch num
                num = (num == 0 ? 1 : 0);
            }
        }
        ArrayList<PenetrationRegion> regions;
        ArrayList<PenetratingPoint> points;
        if (num == 0) {
            regions = cinfo.getRegions(0);
            points = cinfo.getPenetratingPoints(0);
        } else {
            regions = cinfo.getRegions(1);
            points = cinfo.getPenetratingPoints(1);
        }
        if (regions != null && regions.size() > 0) {
            rd = createPenetrationRenderObject(handler, points, regions);
        }
    }
    oldRob = myDepthRob;
    myDepthRob = rd;
// if (oldRob != null) {
// oldRob.dispose();
// }
}
Also used : Group(artisynth.core.mechmodels.Collidable.Group) ContactPlane(maspack.collision.ContactPlane) TriTriIntersection(maspack.geometry.TriTriIntersection) Method(artisynth.core.mechmodels.CollisionBehavior.Method) IntersectionPoint(maspack.collision.IntersectionPoint) PenetratingPoint(maspack.collision.PenetratingPoint) EdgeEdgeContact(maspack.collision.EdgeEdgeContact) IntersectionContour(maspack.collision.IntersectionContour) PenetratingPoint(maspack.collision.PenetratingPoint) IntersectionPoint(maspack.collision.IntersectionPoint) Point3d(maspack.matrix.Point3d) ContactInfo(maspack.collision.ContactInfo) RenderObject(maspack.render.RenderObject) PenetrationRegion(maspack.collision.PenetrationRegion)

Aggregations

ContactInfo (maspack.collision.ContactInfo)3 Method (artisynth.core.mechmodels.CollisionBehavior.Method)2 IntersectionContour (maspack.collision.IntersectionContour)2 IntersectionPoint (maspack.collision.IntersectionPoint)2 PenetratingPoint (maspack.collision.PenetratingPoint)2 Point3d (maspack.matrix.Point3d)2 Group (artisynth.core.mechmodels.Collidable.Group)1 ContactPlane (maspack.collision.ContactPlane)1 EdgeEdgeContact (maspack.collision.EdgeEdgeContact)1 MeshCollider (maspack.collision.MeshCollider)1 PenetrationRegion (maspack.collision.PenetrationRegion)1 SignedDistanceCollider (maspack.collision.SignedDistanceCollider)1 SurfaceMeshIntersector (maspack.collision.SurfaceMeshIntersector)1 RegionType (maspack.collision.SurfaceMeshIntersector.RegionType)1 PolygonalMesh (maspack.geometry.PolygonalMesh)1 TriTriIntersection (maspack.geometry.TriTriIntersection)1 RenderObject (maspack.render.RenderObject)1