Search in sources :

Example 26 with RenderObject

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

the class MultiViewerTesterBase method addHalfBunny.

protected static void addHalfBunny(MultiViewer tester, PolygonalMesh bunny) {
    RenderProps rprops = new RenderProps();
    rprops.setFaceStyle(FaceStyle.FRONT_AND_BACK);
    rprops.setShading(Shading.SMOOTH);
    rprops.setBackColor(Color.MAGENTA.darker());
    rprops.setSpecular(Color.WHITE);
    rprops.setShininess(1000);
    if (bunny != null) {
        RenderObject r = new RenderObject();
        // add all appropriate info
        for (Vertex3d vtx : bunny.getVertices()) {
            Point3d pos = vtx.getPosition();
            r.addPosition((float) pos.x, (float) pos.y, (float) pos.z);
        }
        for (Vector3d nrm : bunny.getNormals()) {
            r.addNormal((float) nrm.x, (float) nrm.y, (float) nrm.z);
        }
        int[] nidxs = bunny.getNormalIndices();
        // left
        r.createTriangleGroup();
        // right
        r.createTriangleGroup();
        // build faces
        List<Face> faces = bunny.getFaces();
        int[] indexOffs = bunny.getFeatureIndexOffsets();
        Vector3d centroid = new Vector3d();
        for (int i = 0; i < faces.size(); i++) {
            Face f = faces.get(i);
            int foff = indexOffs[f.idx];
            int[] pidxs = f.getVertexIndices();
            // vertex indices
            int[] vidxs = new int[pidxs.length];
            for (int j = 0; j < pidxs.length; j++) {
                // only add if unique combination
                vidxs[j] = r.addVertex(pidxs[j], nidxs[foff + j], -1, -1);
            }
            // triangle fan for faces
            f.computeCentroid(centroid);
            if (centroid.x < centroid.y) {
                r.triangleGroup(0);
            } else {
                r.triangleGroup(1);
            }
            r.addTriangleFan(vidxs);
        }
        MultiTriangleGroupWrapper rbunny = new MultiTriangleGroupWrapper(r);
        rbunny.setTransform(new RigidTransform3d(new Vector3d(1.3, 1.3, 0.5), AxisAngle.IDENTITY));
        rbunny.setRenderProps(rprops);
        rbunny.setFaceColors(Color.RED, Color.BLUE);
        tester.addRenderable(rbunny);
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) RenderProps(maspack.render.RenderProps) RenderObject(maspack.render.RenderObject) Face(maspack.geometry.Face)

Example 27 with RenderObject

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

the class MultiPointSpring method prerender.

public void prerender(RenderList list) {
    // can't currently tell the latter, just rebuild every time:
    if (true || !myRenderObjValidP) {
        RenderObject robj = buildRenderObject();
        myRenderObj = robj;
        myRenderObjValidP = true;
    } else {
        updateRenderObject(myRenderObj);
    }
    if (myDrawABPointsP) {
        // for each wrappable segment, update the current list of AB points to
        // be rendered:
        updateABRenderProps();
        for (int i = 0; i < numSegments(); i++) {
            Segment seg = mySegments.get(i);
            if (seg instanceof WrapSegment) {
                WrapSegment wrapSeg = (WrapSegment) seg;
                ArrayList<float[]> renderPoints = null;
                SubSegment sg = wrapSeg.firstSubSegment();
                if (sg != null) {
                    renderPoints = new ArrayList<float[]>(10);
                    while (sg != null) {
                        if (sg.myAttachmentB != null) {
                            renderPoints.add(getRenderCoords(sg.myPntB));
                        }
                        if (sg.myAttachmentA != null) {
                            renderPoints.add(getRenderCoords(sg.myPntA));
                        }
                        sg = sg.myNext;
                    }
                }
                wrapSeg.myRenderABPoints = renderPoints;
            }
        }
    }
}
Also used : RenderObject(maspack.render.RenderObject) LineSegment(maspack.geometry.LineSegment)

Example 28 with RenderObject

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

the class MultiPointSpring method dorender.

void dorender(Renderer renderer, RenderProps props) {
    RenderObject robj = myRenderObj;
    if (myDrawABPointsP) {
        // draw AB points
        for (int i = 0; i < numSegments(); i++) {
            Segment seg = mySegments.get(i);
            if (seg instanceof WrapSegment) {
                WrapSegment wrapSeg = (WrapSegment) seg;
                ArrayList<float[]> renderPoints = wrapSeg.myRenderABPoints;
                if (renderPoints != null) {
                    for (int k = 0; k < renderPoints.size(); k++) {
                        renderer.drawPoint(myABRenderProps, renderPoints.get(k), isSelected());
                    }
                }
            }
        }
    }
    if (robj != null) {
        double size;
        // draw the strands
        LineStyle lineStyle = props.getLineStyle();
        if (lineStyle == LineStyle.LINE) {
            size = props.getLineWidth();
        } else {
            size = props.getLineRadius();
        }
        if (getRenderColor() != null) {
            renderer.setColor(getRenderColor(), isSelected());
        } else {
            renderer.setLineColoring(props, isSelected());
        }
        renderer.drawLines(robj, lineStyle, size);
        if (myDrawKnotsP) {
            // draw the knots, if any
            PointStyle pointStyle = props.getPointStyle();
            if (pointStyle == PointStyle.POINT) {
                size = props.getPointSize();
            } else {
                size = props.getPointRadius();
            }
            renderer.setPointColoring(props, isSelected());
            robj.pointGroup(FREE_KNOTS);
            renderer.drawPoints(robj, pointStyle, size);
            robj.pointGroup(CONTACTING_KNOTS);
            if (myContactingKnotsColor != null) {
                renderer.setColor(myContactingKnotsColor);
            }
            renderer.drawPoints(robj, pointStyle, size);
        }
    }
}
Also used : PointStyle(maspack.render.Renderer.PointStyle) LineStyle(maspack.render.Renderer.LineStyle) RenderObject(maspack.render.RenderObject) LineSegment(maspack.geometry.LineSegment)

Example 29 with RenderObject

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

the class MultiPointSpring method buildRenderObject.

protected RenderObject buildRenderObject() {
    RenderObject robj = new RenderObject();
    robj.createPointGroup();
    robj.createPointGroup();
    // explicitly create a line group, in case the state of the spring
    // causes lines to not be added - in which case, drawLines() would fail
    robj.createLineGroup();
    for (int i = 0; i < numSegments(); i++) {
        Segment seg = mySegments.get(i);
        addRenderPos(robj, seg.myPntB.getRenderCoords(), null);
        if (seg instanceof WrapSegment) {
            WrapSegment wrapSeg = (WrapSegment) seg;
            for (int k = 0; k < wrapSeg.myNumKnots; k++) {
                WrapKnot knot = wrapSeg.myKnots[k];
                addRenderPos(robj, knot.updateRenderPos(), knot);
            }
        }
        if (i == numSegments() - 1) {
            addRenderPos(robj, seg.myPntA.getRenderCoords(), null);
        }
    }
    return robj;
}
Also used : RenderObject(maspack.render.RenderObject) LineSegment(maspack.geometry.LineSegment)

Example 30 with RenderObject

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

the class PolygonalMeshRenderer method buildRenderObject.

@Override
protected RenderObject buildRenderObject(MeshBase mesh, RenderProps props) {
    PolygonalMesh pmesh = (PolygonalMesh) mesh;
    boolean useVertexNormals = props.getShading() != Shading.FLAT;
    RenderObject r = new RenderObject();
    addPositions(r, pmesh);
    if (useVertexNormals) {
        addNormals(r, pmesh);
    } else {
        addFaceNormals(r, pmesh);
    }
    addColors(r, pmesh);
    addTextureCoords(r, pmesh);
    int[] nidxs = useVertexNormals ? pmesh.getNormalIndices() : null;
    int[] cidxs = pmesh.hasColors() ? pmesh.getColorIndices() : null;
    int[] tidxs = pmesh.hasTextureCoords() ? pmesh.getTextureIndices() : null;
    int[] indexOffs = pmesh.getFeatureIndexOffsets();
    int[] pidxs = pmesh.createVertexIndices();
    // FINISH Merge Quad Triangles
    // Shading shadingModel = props.getShading();
    // boolean mergeQuadTriangles = (shadingModel != Shading.FLAT);
    // ensure capacity assume all faces are triangles
    r.ensureVertexCapacity(pmesh.getFaces().size() * 3);
    ArrayList<Face> faces = pmesh.getFaces();
    for (int i = 0; i < faces.size(); i++) {
        // Face f = faces.get(i);   // XXX required?
        int foff = indexOffs[i];
        int numv = indexOffs[i + 1] - foff;
        int[] vidxs = new int[numv];
        for (int j = 0; j < numv; j++) {
            vidxs[j] = r.addVertex(pidxs[foff + j], nidxs != null ? nidxs[foff + j] : i, cidxs != null ? cidxs[foff + j] : -1, tidxs != null ? tidxs[foff + j] : -1);
        }
    // XXX currently handled using separate index list
    // // triangle fan for faces, line loop for edges
    // r.addTriangleFan(vidxs);
    // if (props.getDrawEdges()) {
    // r.addLineLoop(vidxs);
    // }
    }
    return r;
}
Also used : RenderObject(maspack.render.RenderObject)

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