Search in sources :

Example 6 with RenderObject

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

the class PolylineMeshRenderer method buildRenderObject.

@Override
protected RenderObject buildRenderObject(MeshBase mesh, RenderProps props) {
    RenderObject r = super.buildRenderObject(mesh, props);
    PolylineMesh pmesh = (PolylineMesh) mesh;
    int[] nidxs = pmesh.hasNormals() ? pmesh.getNormalIndices() : null;
    int[] cidxs = pmesh.hasColors() ? pmesh.getColorIndices() : null;
    int[] tidxs = pmesh.hasTextureCoords() ? pmesh.getTextureIndices() : null;
    int[] indexOffs = mesh.getFeatureIndexOffsets();
    int[] pidxs = mesh.createVertexIndices();
    ArrayList<Polyline> lines = pmesh.getLines();
    for (int i = 0; i < pmesh.numLines(); i++) {
        // XXX is this needed? or computed from index offsets?
        Polyline line = lines.get(i);
        int loff = indexOffs[i];
        int numv = indexOffs[i + 1] - loff;
        int[] vidxs = new int[numv];
        for (int j = 0; j < numv; j++) {
            vidxs[j] = r.addVertex(pidxs[loff + j], nidxs != null ? nidxs[loff + j] : i, cidxs != null ? cidxs[loff + j] : -1, tidxs != null ? tidxs[loff + j] : -1);
        }
        // triangle fan for faces, line loop for edges
        r.addLineStrip(vidxs);
    }
    return r;
}
Also used : RenderObject(maspack.render.RenderObject)

Example 7 with RenderObject

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

the class MultiViewerTesterBase method addCube.

protected static void addCube(MultiViewer tester) {
    RenderObject cube = new RenderObject();
    // positions                                 // normals
    int[] pIdxs = new int[8];
    int[] nIdxs = new int[6];
    pIdxs[0] = cube.addPosition(-1f, -1f, -1f);
    nIdxs[0] = cube.addNormal(0f, 0f, -1f);
    pIdxs[1] = cube.addPosition(1f, -1f, -1f);
    nIdxs[1] = cube.addNormal(0f, 0f, 1f);
    pIdxs[2] = cube.addPosition(1f, 1f, -1f);
    nIdxs[2] = cube.addNormal(0f, -1f, 0f);
    pIdxs[3] = cube.addPosition(-1f, 1f, -1f);
    nIdxs[3] = cube.addNormal(0f, 1f, 0f);
    pIdxs[4] = cube.addPosition(-1f, -1f, 1f);
    nIdxs[4] = cube.addNormal(-1f, 0f, 0f);
    pIdxs[5] = cube.addPosition(1f, -1f, 1f);
    nIdxs[5] = cube.addNormal(1f, 0f, 0f);
    pIdxs[6] = cube.addPosition(1f, 1f, 1f);
    pIdxs[7] = cube.addPosition(-1f, 1f, 1f);
    // vertices
    int[] vIdxs = new int[24];
    // bottom    indices:(position, normal, color, texture)
    vIdxs[0] = cube.addVertex(0, 0, -1, -1);
    vIdxs[1] = cube.addVertex(1, 0, -1, -1);
    vIdxs[2] = cube.addVertex(2, 0, -1, -1);
    vIdxs[3] = cube.addVertex(3, 0, -1, -1);
    // top
    vIdxs[4] = cube.addVertex(4, 1, -1, -1);
    vIdxs[5] = cube.addVertex(5, 1, -1, -1);
    vIdxs[6] = cube.addVertex(6, 1, -1, -1);
    vIdxs[7] = cube.addVertex(7, 1, -1, -1);
    // left
    vIdxs[8] = cube.addVertex(0, 2, -1, -1);
    vIdxs[9] = cube.addVertex(1, 2, -1, -1);
    vIdxs[10] = cube.addVertex(4, 2, -1, -1);
    vIdxs[11] = cube.addVertex(5, 2, -1, -1);
    // right
    vIdxs[12] = cube.addVertex(2, 3, -1, -1);
    vIdxs[13] = cube.addVertex(3, 3, -1, -1);
    vIdxs[14] = cube.addVertex(6, 3, -1, -1);
    vIdxs[15] = cube.addVertex(7, 3, -1, -1);
    // front
    vIdxs[16] = cube.addVertex(3, 4, -1, -1);
    vIdxs[17] = cube.addVertex(0, 4, -1, -1);
    vIdxs[18] = cube.addVertex(7, 4, -1, -1);
    vIdxs[19] = cube.addVertex(4, 4, -1, -1);
    // back
    vIdxs[20] = cube.addVertex(1, 5, -1, -1);
    vIdxs[21] = cube.addVertex(2, 5, -1, -1);
    vIdxs[22] = cube.addVertex(5, 5, -1, -1);
    vIdxs[23] = cube.addVertex(6, 5, -1, -1);
    // triangular faces
    // bottom
    cube.addTriangle(2, 1, 0);
    // bottom
    cube.addTriangle(3, 2, 0);
    // top
    cube.addTriangle(4, 5, 6);
    // top
    cube.addTriangle(7, 4, 6);
    // left
    cube.addTriangle(8, 9, 10);
    // left
    cube.addTriangle(9, 11, 10);
    // right
    cube.addTriangle(12, 13, 14);
    // right
    cube.addTriangle(13, 15, 14);
    // front
    cube.addTriangle(16, 17, 18);
    // front
    cube.addTriangle(17, 19, 18);
    // back
    cube.addTriangle(20, 21, 22);
    // back
    cube.addTriangle(21, 23, 22);
    // add to renderer
    RenderObjectWrapper cuber = new RenderObjectWrapper(cube);
    AffineTransform3d trans = new AffineTransform3d();
    trans.setTranslation(0.5, 0.5, 0.5);
    trans.applyScaling(0.2, 0.2, 0.2);
    cuber.setTransform(trans);
    RenderProps props = cuber.getRenderProps();
    props.setFaceColor(Color.ORANGE.darker());
    tester.addRenderable(cuber);
}
Also used : RenderProps(maspack.render.RenderProps) RenderObject(maspack.render.RenderObject) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 8 with RenderObject

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

the class InstanceTest method addContent.

@Override
protected void addContent(MultiViewer mv) {
    SimpleSelectable renderable = new SimpleSelectable() {

        RenderObject robj = null;

        @Override
        public void updateBounds(Vector3d pmin, Vector3d pmax) {
            Point3d.X_UNIT.updateBounds(pmin, pmax);
            Point3d.Y_UNIT.updateBounds(pmin, pmax);
            Point3d.Z_UNIT.updateBounds(pmin, pmax);
            Point3d.NEG_X_UNIT.updateBounds(pmin, pmax);
            Point3d.NEG_Y_UNIT.updateBounds(pmin, pmax);
            Point3d.NEG_Z_UNIT.updateBounds(pmin, pmax);
        }

        @Override
        public void render(Renderer renderer, int flags) {
            if (robj == null) {
                robj = new RenderObject();
                float x = 0.5f;
                robj.addPoint(new float[] { -x, -x, -x });
                robj.addPoint(new float[] { x, -x, -x });
                robj.addPoint(new float[] { -x, x, -x });
                robj.addPoint(new float[] { x, x, -x });
                robj.addPoint(new float[] { -x, -x, x });
                robj.addPoint(new float[] { x, -x, x });
                robj.addPoint(new float[] { -x, x, x });
                robj.addPoint(new float[] { x, x, x });
                robj.addLine(0, 1);
                robj.addLine(1, 3);
                robj.addLine(3, 2);
                robj.addLine(2, 0);
                robj.addLine(4, 5);
                robj.addLine(5, 7);
                robj.addLine(7, 6);
                robj.addLine(6, 4);
                robj.createLineGroup();
                robj.addLine(0, 4);
                robj.addLine(4, 5);
                robj.addLine(5, 1);
                robj.addLine(1, 0);
            }
            // renderer.drawPoints (robj, PointStyle.POINT, 10);
            renderer.setFrontColor(new float[] { 0.8f, 0.8f, 0.8f, 1.0f });
            renderer.drawPoints(robj, PointStyle.SPHERE, 0.1);
            renderer.drawLines(robj, 0, LineStyle.CYLINDER, 0.025);
            renderer.drawLines(robj, 1, LineStyle.SOLID_ARROW, 0.05);
        }

        @Override
        public void prerender(RenderList list) {
        }

        @Override
        public int getRenderHints() {
            return 0;
        }

        @Override
        public int numSelectionQueriesNeeded() {
            return 0;
        }

        @Override
        public boolean isSelectable() {
            return false;
        }

        @Override
        public void getSelection(LinkedList<Object> list, int qid) {
        }

        @Override
        public void setSelected(boolean set) {
        }

        @Override
        public boolean isSelected() {
            // TODO Auto-generated method stub
            return false;
        }
    };
    mv.addRenderable(renderable);
    for (SimpleViewerApp app : mv.getWindows()) {
        app.viewer.setAxialView(AxisAlignedRotation.X_Y);
    }
}
Also used : SimpleSelectable(maspack.test.GL.MultiViewer.SimpleSelectable) Vector3d(maspack.matrix.Vector3d) Renderer(maspack.render.Renderer) SimpleViewerApp(maspack.test.GL.MultiViewer.SimpleViewerApp) RenderObject(maspack.render.RenderObject) RenderList(maspack.render.RenderList) LinkedList(java.util.LinkedList)

Example 9 with RenderObject

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

the class MuscleElementDescList method render.

public void render(Renderer renderer, int flags) {
    RenderProps props = myRenderProps;
    if (renderer.isSelecting()) {
        for (int i = 0; i < size(); i++) {
            MuscleElementDesc 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 10 with RenderObject

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

the class MuscleElementDescList method prerender.

public void prerender(RenderList list) {
    for (int i = 0; i < size(); i++) {
        MuscleElementDesc desc = get(i);
        // Call to getWarpingData is to ensure that the invJ0 in the warping
        // data is updated in the current (simulation) thread.
        desc.myElement.getWarpingData();
        if (desc.getRenderProps() != null) {
            desc.setExcitationColors(desc.getRenderProps());
        } else {
            desc.setExcitationColors(myRenderProps);
        }
    }
    // will render first and be more visible.
    for (int i = 0; i < size(); i++) {
        MuscleElementDesc desc = get(i);
        if (desc.isSelected() && desc.getRenderProps() != null) {
            list.addIfVisible(desc);
        }
    }
    for (int i = 0; i < size(); i++) {
        MuscleElementDesc 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++) {
            MuscleElementDesc 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)

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