use of maspack.collision.IntersectionContour 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);
}
}
use of maspack.collision.IntersectionContour 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();
// }
}
use of maspack.collision.IntersectionContour in project artisynth_core by artisynth.
the class IntersectorTestViewer method render.
public void render(Renderer renderer, int flags) {
RenderObjs objs = myRenderObjs;
if (objs == null) {
return;
}
if (objs.mesh0 != null) {
objs.mesh0.render(renderer, myRenderProps, flags);
}
if (objs.mesh1 != null) {
objs.mesh1.render(renderer, myRenderProps, flags);
}
if (myDrawIntersection && objs.imesh != null) {
objs.imesh.render(renderer, myCSGRenderProps, flags);
}
if (myDrawUnion && objs.umesh != null) {
objs.umesh.render(renderer, myCSGRenderProps, flags);
}
ArrayList<IntersectionContour> contours = null;
if (objs.contactInfo != null) {
contours = objs.contactInfo.getContours();
}
if (contours != null) {
renderer.setLineWidth(3);
renderer.setColor(Color.RED);
renderer.setShading(Shading.NONE);
for (IntersectionContour c : contours) {
if (c.isClosed()) {
renderer.beginDraw(DrawMode.LINE_LOOP);
} else {
renderer.beginDraw(DrawMode.LINE_STRIP);
}
for (IntersectionPoint p : c) {
renderer.addVertex((float) p.x, (float) p.y, (float) p.z);
}
renderer.endDraw();
}
renderer.setShading(Shading.FLAT);
renderer.setLineWidth(1);
}
}
Aggregations