Search in sources :

Example 1 with EdgeEdgeContact

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

Group (artisynth.core.mechmodels.Collidable.Group)1 Method (artisynth.core.mechmodels.CollisionBehavior.Method)1 ContactInfo (maspack.collision.ContactInfo)1 ContactPlane (maspack.collision.ContactPlane)1 EdgeEdgeContact (maspack.collision.EdgeEdgeContact)1 IntersectionContour (maspack.collision.IntersectionContour)1 IntersectionPoint (maspack.collision.IntersectionPoint)1 PenetratingPoint (maspack.collision.PenetratingPoint)1 PenetrationRegion (maspack.collision.PenetrationRegion)1 TriTriIntersection (maspack.geometry.TriTriIntersection)1 Point3d (maspack.matrix.Point3d)1 RenderObject (maspack.render.RenderObject)1