Search in sources :

Example 21 with GLViewer

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

the class GeometryInertiaPanel method createDefaultSettings.

/**
 * Creates appropriate default values for GeometrySettings. Called when
 * this panel is created if settings have not been explicitly supplied.
 */
private GeometrySettings createDefaultSettings(RigidBody body) {
    GeometrySettings settings = new GeometrySettings();
    // may be overridden below .,..
    settings.geometryType = GeometryType.Box;
    settings.meshXform = new RigidTransform3d();
    settings.meshFileName = null;
    myFileMesh = null;
    if (body != null) {
        if (myAttachedBody == body) {
            settings.geometryType = GeometryType.Mesh;
            if (body.getMeshFileName() != null) {
                settings.meshFileName = body.getMeshFileName();
            }
            if (body.getMeshFileTransform() != null) {
                settings.meshXform = body.getMeshFileTransform().copy();
            }
            if (body.getMesh() != null) {
                myFileMesh = body.getMesh().copy();
                if (settings.meshXform != null) {
                    myFileMesh.inverseTransform(settings.meshXform);
                }
            }
        } else {
            if (body.getMeshFileName() != null) {
                myFileMesh = loadMeshFromFile(body.getMeshFileName());
            }
            if (myFileMesh != null) {
                settings.meshFileName = body.getMeshFileName();
                if (body.getMeshFileTransform() != null) {
                    settings.meshXform = body.getMeshFileTransform().copy();
                }
            }
        }
    }
    if (body != null) {
        settings.inertiaMethod = body.getInertiaMethod();
        settings.density = body.getDensity();
        body.getInertia(settings.inertia);
    } else {
        settings.density = 1.0;
        // default inertia: unit mass and identity rotational inertia
        settings.inertia.set(1, 1, 1, 1);
        settings.inertiaMethod = InertiaMethod.Density;
    }
    if (body != null && body.getMesh() != null) {
        PolygonalMesh mesh = body.getMesh();
        OBB obb = new OBB(mesh);
        Vector3d widths = new Vector3d();
        obb.getWidths(widths);
        settings.boxWidths.set(widths);
        settings.pointRadius = mesh.computeAverageRadius();
    } else {
        GLViewer viewer = Main.getMain().getViewer();
        double w = (viewer.distancePerPixel(viewer.getCenter()) * viewer.getScreenWidth());
        settings.pointRadius = w / 8;
        settings.boxWidths.set(w / 8, w / 8, w / 8);
    }
    return settings;
}
Also used : GLViewer(maspack.render.GL.GLViewer)

Example 22 with GLViewer

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

the class GLHSVShaderTest method main.

public static void main(String[] args) {
    GLViewerFrame vframe = new GLViewerFrame("GLHSVShader test", 640, 480);
    vframe.setVisible(true);
    GLViewer viewer = vframe.getViewer();
    viewer.setCenter(new Point3d(0, 1, 0));
    viewer.addRenderable(new GLHSVShaderTest());
}
Also used : GLViewer(maspack.render.GL.GLViewer) GLViewerFrame(maspack.render.GL.GLViewerFrame) Point3d(maspack.matrix.Point3d)

Example 23 with GLViewer

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

the class Translator3d method updatePosition.

private void updatePosition(Point3d p0, Point3d p1, MouseRayEvent e) {
    Vector3d del = new Vector3d();
    del.sub(p1, p0);
    // if (dragIsConstrained(e)) {
    if (dragIsConstrained()) {
        Renderer renderer = e.getViewer();
        boolean constrainedToGrid = false;
        if (renderer instanceof GLViewer) {
            GLViewer viewer = (GLViewer) renderer;
            if (viewer.getGridVisible()) {
                GLGridPlane grid = viewer.getGrid();
                RigidTransform3d XDraggerToGrid = new RigidTransform3d();
                XDraggerToGrid.mulInverseLeft(grid.getGridToWorld(), myXDraggerToWorld);
                if (XDraggerToGrid.R.isAxisAligned(EPS)) {
                    // if the dragger orientation is axis-aligned with grid
                    // coordinates, then adjust constrained motions so that the
                    // dragger center always lies on a grid point. (Otherwise, this
                    // can't necessarily be done without causing the dragger to move
                    // off the specified line or plane of translation).
                    Point3d pa = new Point3d(del);
                    pa.transform(XDraggerToGrid);
                    grid.alignPoint(pa, pa);
                    pa.inverseTransform(XDraggerToGrid);
                    del.set(pa);
                    constrainToFixture(del);
                    constrainedToGrid = true;
                }
            }
        }
        if (!constrainedToGrid) {
            // if not possible to constrain to grid, just constrain the step
            // size
            double s = getConstrainedStepSize();
            del.x = s * Math.round(del.x / s);
            del.y = s * Math.round(del.y / s);
            del.z = s * Math.round(del.z / s);
        }
    }
    myXDraggerToWorld.mulXyz(del.x, del.y, del.z);
    myIncrementalTransform.p.set(del.x, del.y, del.z);
    myTransform.mul(myIncrementalTransform);
}
Also used : GLViewer(maspack.render.GL.GLViewer) RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) GLGridPlane(maspack.render.GL.GLGridPlane)

Example 24 with GLViewer

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

the class MenuBarHandler method saveViewerImage.

private void saveViewerImage() {
    JFileChooser chooser;
    if ((chooser = myViewerImageFileChooser) == null) {
        chooser = new JFileChooser();
        chooser.setApproveButtonText("Save");
        chooser.setCurrentDirectory(ArtisynthPath.getWorkingDir());
        for (FileFilter ff : chooser.getChoosableFileFilters()) {
            chooser.removeChoosableFileFilter(ff);
        }
        // create filters
        String[] fmts = ImageIO.getWriterFormatNames();
        for (String fmt : fmts) {
            ExtensionFileFilter filter = new ExtensionFileFilter("." + fmt + " files", fmt);
            chooser.addChoosableFileFilter(filter);
        }
        chooser.setFileFilter(chooser.getChoosableFileFilters()[0]);
        myViewerImageFileChooser = chooser;
    }
    int returnVal = chooser.showSaveDialog(myFrame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        ExtensionFileFilter filter = (ExtensionFileFilter) chooser.getFileFilter();
        String ext = filter.getExtensions()[0];
        File file = chooser.getSelectedFile();
        if (!file.getName().toLowerCase().endsWith(ext.toLowerCase())) {
            file = new File(file.getPath() + "." + ext);
        }
        int confirmation = JOptionPane.YES_OPTION;
        if (file.exists()) {
            confirmation = JOptionPane.showConfirmDialog(myFrame, "File " + file.getName() + " aleady exists. Proceed?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        }
        if (confirmation == JOptionPane.YES_OPTION) {
            GLViewer viewer = myMain.getViewer();
            viewer.setupScreenShot(viewer.getScreenWidth(), viewer.getScreenHeight(), file, ext);
            viewer.repaint();
        // while (viewer.grabPending()) {
        // try {
        // Thread.sleep (10);
        // }
        // catch (Exception e){
        // }
        // }
        }
    }
}
Also used : GLViewer(maspack.render.GL.GLViewer) JFileChooser(javax.swing.JFileChooser) ExtensionFileFilter(artisynth.core.util.ExtensionFileFilter) GenericFileFilter(maspack.util.GenericFileFilter) FileFilter(javax.swing.filechooser.FileFilter) ExtensionFileFilter(artisynth.core.util.ExtensionFileFilter) File(java.io.File)

Example 25 with GLViewer

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

the class MenuBarHandler method actionPerformed.

/**
 * action performed to process all the menu and button actions in this class
 */
public void actionPerformed(ActionEvent event) {
    String cmd = event.getActionCommand();
    // Scripts menu
    if (isScriptMenuItem(event.getSource())) {
        String scriptName = myMain.getScriptName(cmd);
        runScript(scriptName);
    } else if (cmd.equals("load script from file")) {
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setCurrentDirectory(ArtisynthPath.getWorkingDir());
        FileFilter jythonFilter = new GenericFileFilter(new String[] { "py", "jy" }, "Jython files");
        fileChooser.addChoosableFileFilter(jythonFilter);
        fileChooser.setFileFilter(jythonFilter);
        int result = fileChooser.showOpenDialog(myFrame);
        if (result == JFileChooser.APPROVE_OPTION) {
            File selectedFile = fileChooser.getSelectedFile();
            runScript(selectedFile.getAbsolutePath());
        }
    } else // 
    if (myMain.isDemoClassName(cmd)) {
        ModelInfo mi = new ModelInfo(myMain.getDemoClassName(cmd), cmd, null);
        doLoadModelSafely(mi);
    } else // 
    if (cmd.equals("Clear model")) {
        doClearModel();
    } else if (cmd.equals("New blank MechModel")) {
        doBlankMechmodel();
    } else if (cmd.equals("Save model")) {
        doSaveModel();
    } else if (cmd.equals("Save model as ...")) {
        doSaveModelAs();
    } else if (cmd.equals("Reload model")) {
        doReloadModel();
    } else if (cmd.equals("Load model ...")) {
        doLoadModel();
    } else if (cmd.equals("Load from class ...")) {
        doLoadFromClass();
    } else if (cmd.equals("Switch workspace ...")) {
        doSwitchWorkspace();
    } else if (cmd.equals("Open MATLAB connection")) {
        doOpenMatlab();
    } else if (cmd.equals("Close MATLAB connection")) {
        doCloseMatlab();
    } else if (cmd.equals("Load probes ...")) {
        doLoadProbes();
    } else if (cmd.equals("Save probes")) {
        doSaveProbes();
    } else if (cmd.equals("Save probes as ...")) {
        doSaveProbesAs();
    } else if (cmd.equals("Load probes from ...")) {
        newLoadProbesFrom();
    } else if (cmd.equals("Save probes new")) {
        newSaveProbes();
    } else if (cmd.equals("Save probes in ...")) {
        newSaveProbesIn();
    } else if (cmd.equals("Save viewer image ...")) {
        saveViewerImage();
    } else if (cmd.equals("Quit")) {
        myMain.quit();
    } else // 
    if (cmd.equals("Add input probe")) {
        doAddInputProbe();
    } else if (cmd.equals("Add output probe")) {
        doAddOutputProbe();
    } else if (cmd.equals("Add control panel")) {
        doAddControlPanel();
    } else if (cmd.equals("Load control panel")) {
        doLoadControlPanel();
    } else if (cmd.equals("Print selection")) {
        SelectionManager sm = myMain.getSelectionManager();
        for (ModelComponent c : sm.getCurrentSelection()) {
            System.out.println(ComponentUtils.getPathName(c));
        }
    } else if (cmd.equals("Undo")) {
        doUndoCommand();
    } else // 
    if (cmd.equals("Background color")) {
        setBackgroundColor();
    } else if (cmd.equals("Selection color")) {
        setSelectionColor();
    } else if (cmd.equals("Enable selection highlighting")) {
        setSelectionColorEnabled(true);
    } else if (cmd.equals("Disable selection highlighting")) {
        setSelectionColorEnabled(false);
    } else if (cmd.equals("Visual display rate")) {
        setVisualDisplayRate();
    } else if (cmd.equals("Real-time scaling")) {
        setRealTimeScaling();
    } else if (cmd.equals("Mouse Preferences ...")) {
        openMouseSettingsDialog();
    } else if (cmd.equals("Init draggers in world coords")) {
        myMain.setInitDraggersInWorldCoords(true);
    } else if (cmd.equals("Init draggers in local coords")) {
        myMain.setInitDraggersInWorldCoords(false);
    } else if (cmd.equals("Enable articulated transforms")) {
        myMain.setArticulatedTransformsEnabled(true);
    } else if (cmd.equals("Disable articulated transforms")) {
        myMain.setArticulatedTransformsEnabled(false);
    } else // }
    if (cmd.equals("PullController properties ...")) {
        showPullControllerPropertyDialog();
    } else if (cmd.equals("PullController render props ...")) {
        showPullControllerRenderPropsDialog();
    } else // 
    if (cmd.equals("Center view on selection")) {
        myMain.centerViewOnSelection();
    } else if (cmd.equals("Hide timeline")) {
        myMain.setTimelineVisible(false);
        isTimelineVisible = false;
    } else if (cmd.equals("Show timeline")) {
        myMain.setTimelineVisible(true);
        isTimelineVisible = true;
    } else if (cmd.equals("Reset view")) {
        GLViewer v = myMain.getViewer();
        v.setAxialView(v.getAxialView());
        v.autoFit();
    } else if (cmd.equals("Perspective view")) {
        myMain.getViewer().setOrthographicView(false);
    } else if (cmd.equals("Orthographic view")) {
        myMain.getViewer().setOrthographicView(true);
    } else if (cmd.equals("Hide Jython console")) {
        setJythonConsoleVisible(false);
    } else if (cmd.equals("Show Jython console")) {
        setJythonConsoleVisible(true);
    } else if (cmd.equals("Show Inverse panel")) {
        myMain.getInverseManager().showInversePanel(myMain.getRootModel(), InverseManager.findInverseController());
    } else if (cmd.equals("Hide Inverse panel")) {
        myMain.getInverseManager().hideInversePanel();
    } else if (cmd.equals("Show movie panel")) {
        myFrame.getMain().getViewer().getCanvas().display();
        myMain.getMovieMaker().showDialog(myFrame);
    } else if (cmd.equals("Hide movie panel")) {
        // TODO: this isn't implemented yet because we need to set
        // this up as an action
        myMain.getMovieMaker().closeDialog();
    } else if (cmd.equals("Show empty components in navpanel")) {
        myFrame.getNavPanel().setHideEmptyComponents(false);
    } else if (cmd.equals("Hide empty components in navpanel")) {
        myFrame.getNavPanel().setHideEmptyComponents(true);
    } else if (cmd.equals("New viewer")) {
        myMain.createViewerFrame();
    } else if (cmd.equals("Clear traces")) {
        myMain.getRootModel().clearTraces();
    } else if (cmd.equals("Disable all tracing")) {
        myMain.getRootModel().disableAllTracing();
    } else if (cmd.equals("Remove traces")) {
        RemoveComponentsCommand rmCmd = new RemoveComponentsCommand("remove traces", myMain.getRootModel().getTracingProbes());
        myMain.getUndoManager().saveStateAndExecute(rmCmd);
        myMain.rerender();
    } else if (cmd.equals("Set traces visible")) {
        myMain.getRootModel().setTracingProbesVisible(true);
        myMain.rerender();
    } else if (cmd.equals("Set traces invisible")) {
        myMain.getRootModel().setTracingProbesVisible(false);
        myMain.rerender();
    } else if (cmd.equals("Hide viewer toolbar")) {
        isToolbarVisible = false;
        detachViewerToolbar(toolbarPanel);
    } else if (cmd.equals("Show viewer toolbar")) {
        isToolbarVisible = true;
        attachViewerToolbar(toolbarPanel);
    } else if (cmd.equals("Merge control panels")) {
        myMain.getRootModel().mergeAllControlPanels(true);
    } else if (cmd.equals("Separate control panels")) {
        myMain.getRootModel().mergeAllControlPanels(false);
    } else if (cmd.equals("Show progress")) {
        spawnProgressBar();
    } else // 
    if (cmd.equals("About ArtiSynth")) {
        myFrame.displayAboutArtisynth();
    } else if (cmd.equals("About the current model")) {
        myFrame.displayAboutModel(myMain.getRootModel());
    } else if (cmd.equals("Keybindings")) {
        myFrame.displayKeybindings();
    } else // 
    if (cmd.equals("Hide NavBar")) {
        myFrame.getNavPanel().setStatus(!myFrame.getNavPanel().getStatus());
        myFrame.refreshSplitPane();
        navBarButton.setToolTipText("Show Navbar");
        navBarButton.setActionCommand("Show Navbar");
    } else if (cmd.equals("Show Navbar")) {
        myFrame.getNavPanel().setStatus(!myFrame.getNavPanel().getStatus());
        myFrame.refreshSplitPane();
        navBarButton.setToolTipText("Hide NavBar");
        navBarButton.setActionCommand("Hide NavBar");
    } else if (cmd.equals("Re-render")) {
        myMain.rerender();
    } else if (cmd.equals("Reset")) {
        myMain.getScheduler().reset();
    } else if (cmd.equals("Rewind")) {
        myMain.getScheduler().rewind();
    } else if (cmd.equals("Play")) {
        myMain.getScheduler().play();
    } else if (cmd.equals("Pause")) {
        myMain.getScheduler().pause();
    } else if (cmd.equals("Single step")) {
        myMain.getScheduler().step();
    } else if (cmd.equals("Fast forward")) {
        myMain.getScheduler().fastForward();
    } else if (cmd.equals("cancel")) {
        return;
    } else {
        throw new InternalErrorException("Unimplemented command: " + cmd);
    }
}
Also used : SelectionManager(artisynth.core.gui.selectionManager.SelectionManager) GLViewer(maspack.render.GL.GLViewer) JFileChooser(javax.swing.JFileChooser) ModelComponent(artisynth.core.modelbase.ModelComponent) RemoveComponentsCommand(artisynth.core.gui.editorManager.RemoveComponentsCommand) GenericFileFilter(maspack.util.GenericFileFilter) InternalErrorException(maspack.util.InternalErrorException) ExtensionFileFilter(artisynth.core.util.ExtensionFileFilter) GenericFileFilter(maspack.util.GenericFileFilter) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

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