Search in sources :

Example 11 with RenderObject

use of maspack.render.RenderObject in project artisynth_core by artisynth.

the class AuxMaterialElementDescList method buildRenderObjects.

protected void buildRenderObjects() {
    // allocate per-element flag storage that will be used to determine when
    // the render object needs to be rebuilt
    myRobFlags = new byte[size()];
    for (int i = 0; i < size(); i++) {
        AuxMaterialElementDesc desc = get(i);
        // note: flags default to 0 if elem.getRenderProps() != null
        if (desc.getRenderProps() == null) {
            myRobFlags[i] = getRobFlags(desc);
        }
    }
    double wsize = getWidgetSize();
    if (wsize > 0) {
        RenderObject r = new RenderObject();
        r.createTriangleGroup();
        r.createTriangleGroup();
        for (int i = 0; i < size(); i++) {
            AuxMaterialElementDesc desc = get(i);
            if (desc.getRenderProps() == null) {
                int group = desc.isSelected() ? SEL_GRP : REG_GRP;
                r.triangleGroup(group);
                FemElementRenderer.addWidgetFaces(r, desc.myElement);
            }
        }
        myWidgetRob = r;
    } else {
        myWidgetRob = null;
    }
}
Also used : RenderObject(maspack.render.RenderObject)

Example 12 with RenderObject

use of maspack.render.RenderObject in project artisynth_core by artisynth.

the class AuxMaterialElementDescList method render.

public void render(Renderer renderer, int flags) {
    RenderProps props = myRenderProps;
    if (renderer.isSelecting()) {
        for (int i = 0; i < size(); i++) {
            AuxMaterialElementDesc desc = get(i);
            if (desc.getRenderProps() == null && renderer.isSelectable(desc)) {
                renderer.beginSelectionQuery(i);
                desc.render(renderer, myRenderProps, flags);
                renderer.endSelectionQuery();
            }
        }
    } else {
        dorender(renderer, flags, /*selected=*/
        true);
        dorender(renderer, flags, /*selected=*/
        false);
        RenderObject r = myWidgetRob;
        if (r != null) {
            drawWidgets(renderer, r, props, SEL_GRP);
            drawWidgets(renderer, r, props, REG_GRP);
        }
    }
}
Also used : RenderProps(maspack.render.RenderProps) RenderObject(maspack.render.RenderObject)

Example 13 with RenderObject

use of maspack.render.RenderObject in project artisynth_core by artisynth.

the class AuxMaterialElementDescList method prerender.

public void prerender(RenderList list) {
    // will render first and be more visible.
    for (int i = 0; i < size(); i++) {
        AuxMaterialElementDesc desc = get(i);
        if (desc.isSelected() && desc.getRenderProps() != null) {
            list.addIfVisible(desc);
        }
    }
    for (int i = 0; i < size(); i++) {
        AuxMaterialElementDesc desc = get(i);
        if (!desc.isSelected() && desc.getRenderProps() != null) {
            list.addIfVisible(desc);
        }
    }
    if (renderObjectsNeedUpdating() != 0) {
        buildRenderObjects();
    }
    if (myWidgetRob != null) {
        double wsize = getWidgetSize();
        RenderObject r = myWidgetRob;
        int pidx = 0;
        for (int i = 0; i < size(); i++) {
            AuxMaterialElementDesc desc = get(i);
            if (desc.getRenderProps() == null) {
                pidx = FemElementRenderer.updateWidgetPositions(r, desc.myElement, wsize, pidx);
            }
        }
        FemElementRenderer.updateWidgetNormals(r, REG_GRP);
        FemElementRenderer.updateWidgetNormals(r, SEL_GRP);
        r.notifyPositionsModified();
    }
}
Also used : RenderObject(maspack.render.RenderObject)

Example 14 with RenderObject

use of maspack.render.RenderObject in project artisynth_core by artisynth.

the class CollisionRenderer method render.

public void render(Renderer renderer, CollisionHandler handler, RenderProps props, int flags) {
    RenderObject ro = myRob;
    if (ro == null) {
        // XXX paranoid
        return;
    }
    if (ro.numLines(CONSTRAINT_GRP) > 0) {
        ro.lineGroup(CONSTRAINT_GRP);
        drawLines(renderer, ro, props);
    }
    if (ro.numLines(SEGMENT_GRP) > 0) {
        ro.lineGroup(SEGMENT_GRP);
        drawLines(renderer, ro, props);
    }
    if (ro.numLines(CONTOUR_GRP) > 0) {
        int width = props.getEdgeWidth();
        if (width > 0) {
            ro.lineGroup(CONTOUR_GRP);
            float[] rgb = props.getEdgeColorF();
            if (rgb == null) {
                rgb = props.getLineColorF();
            }
            renderer.setColor(rgb, /*highlight=*/
            false);
            Shading save = renderer.getShading();
            renderer.setShading(Shading.NONE);
            renderer.drawLines(ro, LineStyle.LINE, width);
            renderer.setShading(save);
        }
    }
    if (ro.numPoints() > 0) {
        PointStyle style = props.getPointStyle();
        double width = 0;
        Shading savedShading = null;
        renderer.setPointColoring(props, /*highlight=*/
        false);
        if (style == PointStyle.POINT) {
            width = props.getPointSize();
            savedShading = renderer.setShading(Shading.NONE);
        } else {
            width = props.getPointRadius();
        }
        renderer.drawPoints(ro, style, width);
        if (style == PointStyle.POINT) {
            renderer.setShading(savedShading);
        }
    }
    if (ro.numTriangles() > 0) {
        Shading savedShadeModel = renderer.getShading();
        FaceStyle savedFaceStyle = renderer.getFaceStyle();
        renderer.setFaceColoring(props, /*highlight=*/
        false);
        renderer.setFaceStyle(props.getFaceStyle());
        renderer.setShading(props.getShading());
        renderer.drawTriangles(ro);
        renderer.setFaceStyle(savedFaceStyle);
        renderer.setShading(savedShadeModel);
    }
    RenderObject rd = myDepthRob;
    if (rd != null && rd.numTriangles() > 0) {
        Shading savedShadeModel = renderer.getShading();
        FaceStyle savedFaceStyle = renderer.getFaceStyle();
        renderer.setFaceStyle(props.getFaceStyle());
        // props.getShading());
        renderer.setShading(Shading.SMOOTH);
        renderer.setDepthOffset(2);
        renderer.drawTriangles(rd);
        renderer.setFaceStyle(savedFaceStyle);
        renderer.setShading(savedShadeModel);
    }
}
Also used : PointStyle(maspack.render.Renderer.PointStyle) FaceStyle(maspack.render.Renderer.FaceStyle) Shading(maspack.render.Renderer.Shading) RenderObject(maspack.render.RenderObject) IntersectionPoint(maspack.collision.IntersectionPoint) PenetratingPoint(maspack.collision.PenetratingPoint)

Example 15 with RenderObject

use of maspack.render.RenderObject 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

RenderObject (maspack.render.RenderObject)45 Vector3d (maspack.matrix.Vector3d)8 RenderProps (maspack.render.RenderProps)7 Point3d (maspack.matrix.Point3d)4 Shading (maspack.render.Renderer.Shading)4 Color (java.awt.Color)3 IntersectionPoint (maspack.collision.IntersectionPoint)3 PenetratingPoint (maspack.collision.PenetratingPoint)3 LineSegment (maspack.geometry.LineSegment)3 AffineTransform3d (maspack.matrix.AffineTransform3d)3 RigidTransform3d (maspack.matrix.RigidTransform3d)3 PointStyle (maspack.render.Renderer.PointStyle)3 PenetrationRegion (maspack.collision.PenetrationRegion)2 Face (maspack.geometry.Face)2 Vertex3d (maspack.geometry.Vertex3d)2 Point2d (maspack.matrix.Point2d)2 Renderer (maspack.render.Renderer)2 ColorInterpolation (maspack.render.Renderer.ColorInterpolation)2 LineStyle (maspack.render.Renderer.LineStyle)2 Group (artisynth.core.mechmodels.Collidable.Group)1