Search in sources :

Example 1 with RenderList

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

the class GLViewer method numSelectionQueriesNeeded.

public int numSelectionQueriesNeeded() {
    int num = myInternalRenderList.numSelectionQueriesNeeded();
    RenderList elist = myExternalRenderList;
    if (elist != null) {
        num += elist.numSelectionQueriesNeeded();
    }
    return num;
}
Also used : RenderList(maspack.render.RenderList)

Example 2 with RenderList

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

the class TextTester method addContent.

@Override
protected void addContent(MultiViewer mv) {
    final HashMap<String, Font> fontMap = new HashMap<>();
    for (Font font : GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts()) {
        fontMap.put(font.getName(), font);
    }
    mv.addRenderable(new SimpleSelectable() {

        JFrame debugframe = null;

        @Override
        public void updateBounds(Vector3d pmin, Vector3d pmax) {
            Point3d p1 = new Point3d(-3, -3, -3);
            Point3d p2 = new Point3d(3, 3, 3);
            p1.updateBounds(pmin, pmax);
            p2.updateBounds(pmin, pmax);
        }

        @Override
        public void render(Renderer renderer, int flags) {
            if (debugframe == null) {
                TextImageStore store = ((GLViewer) renderer).getTextRenderer().getImageStore();
                debugframe = TextImageStore.createDisplayFrame(store);
                debugframe.setVisible(true);
            }
            renderer.setShading(Shading.FLAT);
            renderer.setColor(Color.WHITE);
            renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
            // renderer.drawSphere (Point3d.ZERO, 0.01);
            Font font = new Font(Font.SANS_SERIF, 0, 54);
            renderer.drawText(font, "Hello world! And goodnight to all.", new float[] { 0.4f, 0.3f, 0.3f }, 0.25);
            renderer.setColor(Color.ORANGE);
            String text = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
            renderer.drawText(font, text, new float[] { -2f, 0f, 0f }, 0.25);
            Font comic = fontMap.get("Comic Sans MS");
            if (comic == null) {
                comic = new Font(Font.MONOSPACED, Font.BOLD, 32);
            } else {
                comic = comic.deriveFont(Font.BOLD, 32);
            }
            renderer.setColor(Color.CYAN);
            text = "Cowabunga";
            Rectangle2D rect = renderer.getTextBounds(comic, text, 0.25);
            renderer.drawText(comic, text, new float[] { -(float) (rect.getWidth()), 0.5f, 0f }, 0.25);
            renderer.setColor(Color.MAGENTA);
            text = "Flip me!";
            font = new Font(Font.SERIF, Font.PLAIN, 64);
            rect = renderer.getTextBounds(font, text, 0.3);
            renderer.pushModelMatrix();
            RigidTransform3d trans = new RigidTransform3d(new Vector3d(0, -0.4, 0), new AxisAngle(0, 1, 0, Math.toRadians(30)));
            renderer.mulModelMatrix(trans);
            renderer.setFaceStyle(FaceStyle.FRONT);
            renderer.drawText(font, text, Point3d.ZERO, 0.3);
            trans = new RigidTransform3d(Vector3d.ZERO, new AxisAngle(0, 1, 0, Math.PI));
            renderer.mulModelMatrix(trans);
            renderer.drawText(font, text, new Point3d(-rect.getWidth(), 0, 0), 0.3);
            trans = new RigidTransform3d(Vector3d.ZERO, new AxisAngle(0.1, 1, 0, Math.PI * 1));
            renderer.mulModelMatrix(trans);
            renderer.setShading(Shading.NONE);
            renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
            renderer.setColor(Color.GREEN);
            text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sagittis hendrerit consequat. Duis id purus neque. Nulla luctus pretium lorem vel convallis. Praesent non ex eu risus porttitor scelerisque vel et lorem. Maecenas ultricies imperdiet tortor, ac varius enim. Integer sagittis dui lacus. Nulla vitae egestas orci. Phasellus vel metus vitae nibh imperdiet imperdiet ut a urna.";
            drawMultiline(renderer, font, text, new float[] { -1.75f, -0.2f, -0.5f }, 0.1, 2);
            renderer.popModelMatrix();
        }

        public void drawMultiline(Renderer renderer, Font font, String text, float[] loc, double size, double linelength) {
            float left = loc[0];
            float[] nloc = { loc[0], loc[1], loc[2] };
            Rectangle2D rect = renderer.getTextBounds(font, text, size);
            float lineheight = (float) (rect.getHeight());
            String[] words = text.split(" ");
            int w = 0;
            while (w < words.length) {
                String word = words[w];
                nloc[0] += renderer.drawText(font, word, nloc, size);
                ++w;
                while (w < words.length && nloc[0] < left + linelength) {
                    word = " " + words[w];
                    rect = renderer.getTextBounds(font, word, size);
                    double ll = nloc[0] + rect.getWidth();
                    if (ll < left + linelength) {
                        renderer.drawText(font, word, nloc, size);
                        ++w;
                    }
                    nloc[0] = (float) ll;
                }
                // newline
                nloc[0] = left;
                nloc[1] -= lineheight;
            }
        }

        @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() {
            return false;
        }
    });
    mv.setAxialView(AxisAlignedRotation.X_Y);
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) HashMap(java.util.HashMap) Rectangle2D(java.awt.geom.Rectangle2D) Font(java.awt.Font) RenderList(maspack.render.RenderList) GLViewer(maspack.render.GL.GLViewer) AxisAngle(maspack.matrix.AxisAngle) SimpleSelectable(maspack.test.GL.MultiViewer.SimpleSelectable) JFrame(javax.swing.JFrame) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) Renderer(maspack.render.Renderer) TextImageStore(maspack.render.TextImageStore)

Example 3 with RenderList

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

the class TextureEgyptianTest method addContent.

@Override
protected void addContent(MultiViewer mv) {
    JFrame frame = new JFrame();
    JPanel controls = new JPanel();
    frame.add(controls);
    PolygonalMesh plane = MeshFactory.createRectangle(4000, 400, 32, 8, /*texture=*/
    true);
    RenderProps rprops = plane.getRenderProps();
    if (rprops == null) {
        rprops = new RenderProps();
    }
    rprops.setShading(Shading.SMOOTH);
    rprops.setShininess(20);
    rprops.setFaceColor(new Color(155, 196, 30));
    rprops.setSpecular(new Color(255, 113, 0));
    rprops.setFaceStyle(FaceStyle.FRONT_AND_BACK);
    plane.transform(new RigidTransform3d(Vector3d.ZERO, AxisAngle.ROT_X_90));
    String srcDir = PathFinder.findSourceDir(this);
    ColorMapProps dprops = new ColorMapProps();
    dprops.setFileName(srcDir + "/data/specular_map.jpg");
    dprops.setColorMixing(ColorMixing.MODULATE);
    dprops.setEnabled(true);
    NormalMapProps normalProps = new NormalMapProps();
    normalProps.setFileName(srcDir + "/data/foil_normal_map2.png");
    normalProps.setScaling(0.3f);
    normalProps.setEnabled(true);
    BumpMapProps bumpProps = new BumpMapProps();
    bumpProps.setFileName(srcDir + "/data/egyptian_friz_2.png");
    bumpProps.setScaling(2.5f);
    bumpProps.setEnabled(true);
    rprops.setColorMap(dprops);
    rprops.setNormalMap(normalProps);
    rprops.setBumpMap(bumpProps);
    // FixedMeshBody fm = new FixedMeshBody(plane);
    // fm.setRenderProps(rprops);
    mv.addRenderable(plane);
    if (false) {
        mv.addRenderable(new IsRenderable() {

            @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) {
                renderer.setColor(Color.CYAN);
                renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
                renderer.drawSphere(Point3d.ZERO, 1);
            }

            @Override
            public void prerender(RenderList list) {
            // TODO Auto-generated method stub
            }

            @Override
            public int getRenderHints() {
                // TODO Auto-generated method stub
                return 0;
            }
        });
    }
    mv.autoFitViewers();
    LabeledComponentBase base = PropertyWidget.create("Color texture", rprops.getColorMap(), "enabled");
    controls.add(base);
    base = PropertyWidget.create("Normal map", rprops.getNormalMap(), "enabled");
    controls.add(base);
    base = PropertyWidget.create("Bump map", rprops.getBumpMap(), "enabled");
    controls.add(base);
    base = PropertyWidget.create("Specular", rprops.getColorMap(), "specularColoring");
    controls.add(base);
    base = PropertyWidget.create("Bump map scale", rprops.getBumpMap(), "scaling");
    controls.add(base);
    base = PropertyWidget.create("Normal map scale", rprops.getNormalMap(), "scaling");
    controls.add(base);
    frame.pack();
    frame.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) RigidTransform3d(maspack.matrix.RigidTransform3d) Color(java.awt.Color) ColorMapProps(maspack.render.ColorMapProps) RenderProps(maspack.render.RenderProps) PolygonalMesh(maspack.geometry.PolygonalMesh) RenderList(maspack.render.RenderList) BumpMapProps(maspack.render.BumpMapProps) IsRenderable(maspack.render.IsRenderable) JFrame(javax.swing.JFrame) Vector3d(maspack.matrix.Vector3d) Renderer(maspack.render.Renderer) LabeledComponentBase(maspack.widgets.LabeledComponentBase) NormalMapProps(maspack.render.NormalMapProps)

Example 4 with RenderList

use of maspack.render.RenderList 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 5 with RenderList

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

the class ViewerManager method buildRenderList.

RenderList buildRenderList() {
    RenderList list = new RenderList();
    list.addIfVisibleAll(myRenderables);
    RootModel root = Main.getMain().getRootModel();
    if (root != null) {
        // modified by Ian: add RootModel to the render list,
        // note that prerender is called by addIfVisible()
        // root.prerender (list);
        list.addIfVisible(root);
    }
    return list;
}
Also used : RootModel(artisynth.core.workspace.RootModel) RenderList(maspack.render.RenderList)

Aggregations

RenderList (maspack.render.RenderList)12 Vector3d (maspack.matrix.Vector3d)7 Renderer (maspack.render.Renderer)7 SimpleSelectable (maspack.test.GL.MultiViewer.SimpleSelectable)5 LinkedList (java.util.LinkedList)4 RenderProps (maspack.render.RenderProps)4 IsRenderable (maspack.render.IsRenderable)3 Point (java.awt.Point)2 JFrame (javax.swing.JFrame)2 PolygonalMesh (maspack.geometry.PolygonalMesh)2 Point3d (maspack.matrix.Point3d)2 RigidTransform3d (maspack.matrix.RigidTransform3d)2 Dragger3d (maspack.render.Dragger3d)2 GLClipPlane (maspack.render.GL.GLClipPlane)2 RootModel (artisynth.core.workspace.RootModel)1 GL2 (com.jogamp.opengl.GL2)1 Color (java.awt.Color)1 Font (java.awt.Font)1 Rectangle2D (java.awt.geom.Rectangle2D)1 ArrayList (java.util.ArrayList)1