Search in sources :

Example 1 with GLViewer

use of maspack.render.GL.GLViewer in project artisynth_core by artisynth.

the class FemCollisions method attach.

@Override
public void attach(DriverInterface driver) {
    super.attach(driver);
    // Enable transparency blending
    GLViewer viewer = getMainViewer();
    if (viewer != null) {
        // viewer will be null if we're in batch mode
        viewer.setBlendDestFactor(BlendFactor.GL_ONE_MINUS_SRC_ALPHA);
    }
}
Also used : GLViewer(maspack.render.GL.GLViewer)

Example 2 with GLViewer

use of maspack.render.GL.GLViewer in project artisynth_core by artisynth.

the class NagataDistanceTest method main.

public static void main(String[] args) {
    NagataDistanceTest tester = new NagataDistanceTest();
    ArrayList<PolygonalMesh> meshes = new ArrayList<PolygonalMesh>();
    // meshes.add (tester.myBaseMesh);
    meshes.add(tester.myFineMesh);
    MeshViewer frame = new MeshViewer(meshes, 640, 480);
    frame.addRenderable(tester);
    GLViewer viewer = frame.getViewer();
    viewer.autoFitOrtho();
    frame.setVisible(true);
}
Also used : GLViewer(maspack.render.GL.GLViewer) ArrayList(java.util.ArrayList) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 3 with GLViewer

use of maspack.render.GL.GLViewer in project artisynth_core by artisynth.

the class MultiViewer method addGL3Viewer.

public void addGL3Viewer(String title, int x, int y, int w, int h) {
    if (gl3resources == null) {
        GLProfile glp3 = GLProfile.get(GLProfile.GL3);
        GLCapabilities cap = new GLCapabilities(glp3);
        cap.setSampleBuffers(true);
        cap.setNumSamples(8);
        // get attribute map from GLSL generator
        StringIntPair[] attributes = GLSLGenerator.ATTRIBUTES;
        GL3VertexAttributeMap attributeMap = new GL3VertexAttributeMap(new GL3VertexAttributeInfo(attributes[0].getString(), attributes[0].getInt()), new GL3VertexAttributeInfo(attributes[1].getString(), attributes[1].getInt()), new GL3VertexAttributeInfo(attributes[2].getString(), attributes[2].getInt()), new GL3VertexAttributeInfo(attributes[3].getString(), attributes[3].getInt()));
        for (int i = 4; i < attributes.length; ++i) {
            attributeMap.add(new GL3VertexAttributeInfo(attributes[i].getString(), attributes[i].getInt()));
        }
        gl3resources = new GL3SharedResources(cap, attributeMap);
    }
    GLViewer viewer = new GL3Viewer(null, gl3resources, w, h);
    addViewer(title, viewer, x, y, w, h);
}
Also used : GL3VertexAttributeInfo(maspack.render.GL.GL3.GL3VertexAttributeInfo) GLCapabilities(com.jogamp.opengl.GLCapabilities) GLViewer(maspack.render.GL.GLViewer) GL3SharedResources(maspack.render.GL.GL3.GL3SharedResources) GL3Viewer(maspack.render.GL.GL3.GL3Viewer) GL3VertexAttributeMap(maspack.render.GL.GL3.GL3VertexAttributeMap) StringIntPair(maspack.render.GL.GL3.GLSLGenerator.StringIntPair) GLProfile(com.jogamp.opengl.GLProfile)

Example 4 with GLViewer

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

use of maspack.render.GL.GLViewer in project artisynth_core by artisynth.

the class GridDisplay method showPropertyDialog.

private void showPropertyDialog() {
    myPropDialog = new PropertyDialog("Grid properties", myGrid, "Done");
    myPropDialog.addWindowListener(new WindowAdapter() {

        public void windowClosed(WindowEvent e) {
            removePropertyDialog();
        }
    });
    GuiUtils.locateRight(myPropDialog, this);
    myPropDialog.addGlobalValueChangeListener(new ValueChangeListener() {

        public void valueChange(ValueChangeEvent e) {
            GLViewer viewer = myGrid.getViewer();
            if (viewer != null) {
                viewer.rerender();
            }
        }
    });
    myPropDialog.setVisible(true);
}
Also used : GLViewer(maspack.render.GL.GLViewer) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Aggregations

GLViewer (maspack.render.GL.GLViewer)36 Vector3d (maspack.matrix.Vector3d)9 File (java.io.File)5 RigidTransform3d (maspack.matrix.RigidTransform3d)4 AxisAngle (maspack.matrix.AxisAngle)3 Point3d (maspack.matrix.Point3d)3 GLViewerFrame (maspack.render.GL.GLViewerFrame)3 RigidBody (artisynth.core.mechmodels.RigidBody)2 ExtensionFileFilter (artisynth.core.util.ExtensionFileFilter)2 JFileChooser (javax.swing.JFileChooser)2 FileFilter (javax.swing.filechooser.FileFilter)2 PolygonalMesh (maspack.geometry.PolygonalMesh)2 RotationMatrix3d (maspack.matrix.RotationMatrix3d)2 GLGridPlane (maspack.render.GL.GLGridPlane)2 RenderProps (maspack.render.RenderProps)2 Transrotator3d (maspack.render.Transrotator3d)2 GenericFileFilter (maspack.util.GenericFileFilter)2 InternalErrorException (maspack.util.InternalErrorException)2 ArgParser (argparser.ArgParser)1 IntHolder (argparser.IntHolder)1