Search in sources :

Example 1 with GLVersion

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

the class Main method main.

/**
 * the main entry point
 *
 * @param args command line arguments
 */
public static void main(String[] args) {
    // some interfaces (like Matlab) may pass args in as null
    if (args == null) {
        args = new String[0];
    }
    ArgParser parser = new ArgParser("java artisynth.core.driver.Main", false);
    parser.addOption("-help %v #prints help message", printHelp);
    parser.addOption("-width %d #width (pixels)", viewerWidth);
    parser.addOption("-height %d #height (pixels)", viewerHeight);
    parser.addOption("-bgColor %fX3 #background color (3 rgb values, 0 to 1)", bgColor);
    parser.addOption("-maxStep %f #maximum time for a single step (sec)", maxStep);
    parser.addOption("-drawAxes %v #draw coordinate axes", drawAxes);
    parser.addOption("-drawGrid %v #draw grid", drawGrid);
    parser.addOption("-axisLength %f #coordinate axis length", axisLength);
    parser.addOption("-play %v #play model immediately", play);
    parser.addOption("-playFor %f #play model immediately for x seconds", playFor);
    parser.addOption("-exitOnBreak %v #exit artisynth when playing stops", exitOnBreak);
    parser.addOption("-demosFile %s #demo file (e.g. .demoModels)", demosFilename);
    parser.addOption("-demosMenu %s #demo menu file (e.g. .demoMenu.xml)", demosMenuFilename);
    parser.addOption("-historyFile %s #model history file (e.g. .history)", historyFilename);
    parser.addOption("-scriptsFile %s #script file (e.g. .artisynthModels)", scriptsFilename);
    parser.addOption("-mousePrefs %s #kees for pure mouse controls", mousePrefs);
    parser.addOption("-ortho %v #use orthographic viewing", orthographic);
    parser.addOption("-axialView %s{xy,xz} #initial view of x-y or x-z axes", axialView);
    parser.addOption("-noTimeline %v{false} #do not start with a timeline", startWithTimeline);
    parser.addOption("-showJythonConsole %v{true} #create jython console on startup", startWithJython);
    parser.addOption("-largeTimeline %v{true} #start with vertically expanded timeline", largeTimeline);
    parser.addOption("-timelineRight %v{true} #start with a timeline alligned to the right", timelineRight);
    parser.addOption("-fps %f#frames per second", framesPerSecond);
    parser.addOption("-fullscreen %v #full screen renderer", fullScreen);
    // parser.addOption("-yup %v #initialize viewer with Y-axis up", yup);
    parser.addOption("-timelineZoom %d #zoom level for timeline", zoom);
    parser.addOption("-options %v #print options only", printOptions);
    parser.addOption("-abortOnInvertedElems %v #abort on nonlinear element inversion", abortOnInvertedElems);
    parser.addOption("-disableHybridSolves %v #disable hybrid linear solves", disableHybridSolves);
    parser.addOption("-numSolverThreads %d #number of threads to use for linear solver", numSolverThreads);
    parser.addOption("-posCorrection %s{Default,GlobalMass,GlobalStiffness} " + "#position correction mode", posCorrection);
    parser.addOption("-noIncompressDamping %v #ignore incompress stiffness for damping", noIncompressDamping);
    // parser.addOption ("-useOldTimeline %v #use old timeline", useOldTimeline);
    parser.addOption("-useSignedDistanceCollider %v " + "#use SignedDistanceCollider where possible", useSignedDistanceCollider);
    parser.addOption("-useAjlCollision" + "%v #use AJL collision detection", useAjlCollision);
    parser.addOption("-useBodyVelsInSolve" + "%v #use body velocities for dynamic solves", useBodyVelsInSolve);
    parser.addOption("-useArticulatedTransforms %v #enforce articulation " + "constraints with transformers", useArticulatedTransforms);
    parser.addOption("-updateLibs %v #update libraries from ArtiSynth server", updateLibs);
    parser.addOption("-flags %x #flag bits passed to the application", flags);
    parser.addOption("-noGui %v #run ArtiSynth without the GUI", noGui);
    parser.addOption("-openMatlabConnection %v " + "#open a MATLAB connection if possible", openMatlab);
    parser.addOption("-GLVersion %d{2,3} " + "#version of openGL for graphics", glVersion);
    parser.addOption("-useGLJPanel %v " + "#use GLJPanel for creating the openGL viewer", useGLJPanel);
    parser.addOption("-useGLCanvas %v{false} " + "#use GLJCanvas for creating the openGL viewer", useGLJPanel);
    parser.addOption("-logLevel %s", logLevel);
    parser.addOption("-testSaveRestoreState %v #test save/restore state when running models", testSaveRestoreState);
    parser.addOption("-movieFrameRate %f #frame rate to use when making movies", movieFrameRate);
    parser.addOption("-movieMethod %s #method to use when making movies", movieMethod);
    Locale.setDefault(Locale.CANADA);
    URL initUrl = ArtisynthPath.findResource(".artisynthInit");
    if (initUrl == null) {
    // Removed warning message for now
    // System.out.println (".artisynthInit not found");
    } else {
        InputStream is = null;
        try {
            is = initUrl.openStream();
        } catch (Exception e) {
            // do nothing if we can't open
            System.out.println(".artisynthInit not found");
        }
        if (is != null) {
            try {
                args = ArgParser.prependArgs(new InputStreamReader(is), args);
            } catch (Exception e) {
                System.err.println("Error reading init file " + initUrl);
                System.err.println(e.getMessage());
            }
        }
    }
    if (System.getProperty("file.separator").equals("\\")) {
        // then we are running windows, so set noerasebackground to
        // try and remove flicker bug
        System.setProperty("sun.awt.noerasebackground", "true");
    } else {
        System.setProperty("awt.useSystemAAFontSettings", "on");
    }
    // Separate program arguments from model arguments introduced by -M
    ArrayList<String> progArgs = new ArrayList<String>();
    ArrayList<String> modelArgs = null;
    ArrayList<String> scriptArgs = null;
    ArrayList<String> taskManagerArgs = null;
    for (String arg : args) {
        if (modelArgs != null) {
            modelArgs.add(arg);
        } else {
            if (arg.equals("-M")) {
                modelArgs = new ArrayList<String>();
            } else {
                progArgs.add(arg);
            }
        }
    }
    // Match arguments one at a time so we can avoid exitOnError if we are
    // running inside matlab
    String[] pargs = progArgs.toArray(new String[0]);
    int lastSwitch = -1;
    int idx = 0;
    while (idx < pargs.length) {
        try {
            int pidx = idx;
            // check for list of arguments:
            if ("-model".equals(pargs[pidx])) {
                modelName.value = pargs[++idx];
                modelArgs = new ArrayList<String>();
                int nidx = maybeCollectArgs(pargs, ++idx, modelArgs);
                if (nidx == idx) {
                    modelArgs = null;
                }
                idx = nidx;
            } else if ("-script".equals(pargs[pidx])) {
                scriptFile.value = pargs[++idx];
                scriptArgs = new ArrayList<String>();
                int nidx = maybeCollectArgs(pargs, ++idx, scriptArgs);
                if (nidx == idx) {
                    scriptArgs = null;
                }
                idx = nidx;
            } else if ("-taskManager".equals(pargs[pidx])) {
                taskManagerClassName.value = pargs[++idx];
                taskManagerArgs = new ArrayList<String>();
                int nidx = maybeCollectArgs(pargs, ++idx, taskManagerArgs);
                if (nidx == idx) {
                    taskManagerArgs = null;
                }
                idx = nidx;
            } else {
                idx = parser.matchArg(pargs, idx);
            }
            String unmatched;
            if ((unmatched = parser.getUnmatchedArgument()) != null) {
                boolean valid = false;
                if (!valid) {
                    System.err.println("Unrecognized argument: " + unmatched + "\nUse -help for help information");
                    return;
                }
            } else {
                lastSwitch = pidx;
            }
        } catch (Exception e) {
            System.err.println("Error parsing options: " + e.getMessage());
            return;
        }
    }
    // parser.matchAllArgs (progArgs.toArray(new String[0]));
    if (printOptions.value || printHelp.value) {
        System.out.println(parser.getOptionsMessage(2));
        System.out.println("  -model <string> [ <string>... ]\n" + "                        name of model to start, with optional arguments\n" + "                        delimited by square brackets\n" + "  -script <string> [ <string>... ]\n" + "                        script to run immediately, with optional arguments\n" + "                        delimited by square brackets\n" + "  -taskManager <className> [ <string>... ]\n" + "                        name of task manager class to run immediately, with\n" + "                        optional arguments delimited by square brackets\n");
        return;
    }
    // Set system logger level
    Logger.getSystemLogger().setLogLevel(LogLevel.find(logLevel.value));
    MechSystemSolver.myDefaultHybridSolveP = !disableHybridSolves.value;
    if (numSolverThreads.value > 0) {
        PardisoSolver.setDefaultNumThreads(numSolverThreads.value);
    }
    FemModel3d.abortOnInvertedElems = abortOnInvertedElems.value;
    // }
    if (posCorrection.value.equals("GlobalMass")) {
        MechSystemBase.setDefaultStabilization(PosStabilization.GlobalMass);
    } else if (posCorrection.value.equals("GlobalStiffness")) {
        MechSystemBase.setDefaultStabilization(PosStabilization.GlobalStiffness);
    }
    FemModel3d.noIncompressStiffnessDamping = noIncompressDamping.value;
    if (useAjlCollision.value) {
        CollisionManager.setDefaultColliderType(ColliderType.AJL_CONTOUR);
    }
    if (testSaveRestoreState.value) {
        RootModel.testSaveAndRestoreState = true;
    }
    if (useGLJPanel.value == true) {
        maspack.render.GL.GLViewer.useGLJPanel = true;
    }
    if (noGui.value == true) {
        viewerWidth.value = -1;
    }
    GLVersion glv = (glVersion.value == 3 ? GLVersion.GL3 : GLVersion.GL2);
    Main m = new Main(PROJECT_NAME, viewerWidth.value, viewerHeight.value, glv);
    m.setArticulatedTransformsEnabled(useArticulatedTransforms.value);
    if (axialView.value.equals("xy")) {
        m.setDefaultViewOrientation(AxisAngle.IDENTITY);
    } else if (axialView.value.equals("xz")) {
        m.setDefaultViewOrientation(AxisAngle.ROT_X_90);
    } else {
        throw new InternalErrorException("Unknown axial view: " + axialView.value);
    }
    if (m.myFrame != null) {
        m.myViewer.setBackgroundColor(bgColor[0], bgColor[1], bgColor[2]);
        // XXX this should be done in the Main constructor, but needs
        // to be done here instead because of sizing effects
        m.myMenuBarHandler.initToolbar();
        if (movieMethod.value != null) {
            MovieMaker movieMaker = m.getMovieMaker();
            try {
                movieMaker.setMethod(movieMethod.value);
            } catch (Exception e) {
                System.out.println("Warning: unknown movie making method " + movieMethod.value);
            }
        }
        if (movieFrameRate.value != -1) {
            MovieMaker movieMaker = m.getMovieMaker();
            try {
                movieMaker.setFrameRate(movieFrameRate.value);
            } catch (Exception e) {
                System.out.println("Warning: illegal movie frame rate " + movieFrameRate.value);
            }
        }
    }
    if (mousePrefs.value != null && m.myViewer != null) {
        m.setMouseBindings(mousePrefs.value);
    }
    m.setFlags(flags.value);
    if (useBodyVelsInSolve.value) {
        Frame.dynamicVelInWorldCoords = false;
    }
    m.start(startWithTimeline.value, timelineRight.value, largeTimeline.value);
    // because setting it earlier can cause incorrect results
    if (m.myFrame != null) {
        m.setViewerSize(viewerWidth.value, viewerHeight.value);
    }
    if (System.getProperty("os.name").contains("Windows")) {
        // XXX see function docs
        fixPardisoThreadCountHack();
    }
    m.verifyNativeLibraries(updateLibs.value);
    // the whole frame to be visible
    if (m.myFrame != null && orthographic.value) {
        m.getViewer().setOrthographicView(true);
    }
    // XXX store model arguments for future use?
    if (modelArgs != null) {
        m.myModelArgs = modelArgs.toArray(new String[modelArgs.size()]);
    }
    if (modelName.value != null) {
        // load the specified model. See first if the name corresponds to a file
        File file = new File(modelName.value);
        if (file.exists() && file.canRead()) {
            try {
                m.loadModelFile(file);
            } catch (IOException e) {
                System.out.println("Error reading or loading model file " + modelName.value);
                e.printStackTrace();
                m.setRootModel(new RootModel(), null, null);
            }
        } else // otherwise, try to determine the model from the class name or alias
        {
            String className = m.getDemoClassName(modelName.value);
            if (className == null) {
                System.out.println("No class associated with model name " + modelName.value);
                m.setRootModel(new RootModel(), null, null);
            } else {
                String name = modelName.value;
                if (name.indexOf('.') != -1) {
                    name = name.substring(name.lastIndexOf('.') + 1);
                    if (name.length() == 0) {
                        name = "Unknown";
                    }
                }
                // load the model
                ModelInfo mi = new ModelInfo(className, name, createArgArray(modelArgs));
                m.loadModel(mi);
            }
        }
    } else {
        m.setRootModel(new RootModel(), null, null);
    }
    if (exitOnBreak.value) {
        m.myScheduler.addListener(new QuitOnBreakListener(m));
    }
    if (playFor.value > 0) {
        m.play(playFor.value);
    } else if (play.value) {
        m.play();
    }
    if (scriptFile.value != null && taskManagerClassName.value != null) {
        System.out.println("Cannot specify both a script (option '-script') and a task manager (option \n" + "'-taskManager' at the same time");
        System.exit(1);
    } else if (scriptFile.value != null) {
        m.runScriptFile(scriptFile.value, scriptArgs);
    } else if (taskManagerClassName.value != null) {
        m.runTaskManager(taskManagerClassName.value, taskManagerArgs);
    }
    if (m.myJythonConsole != null && m.myJythonFrame == null) {
        m.myJythonConsole.interact();
    }
    if (openMatlab.value) {
        m.openMatlabConnection();
    }
}
Also used : RootModel(artisynth.core.workspace.RootModel) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) InternalErrorException(maspack.util.InternalErrorException) IOException(java.io.IOException) ArgParser(argparser.ArgParser) URL(java.net.URL) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) InternalErrorException(maspack.util.InternalErrorException) WayPoint(artisynth.core.probes.WayPoint) GLVersion(maspack.render.GL.GLViewer.GLVersion) MovieMaker(artisynth.core.moviemaker.MovieMaker) File(java.io.File)

Example 2 with GLVersion

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

the class NURBSViewer method main.

public static void main(String[] args) {
    StringHolder fileName = new StringHolder();
    IntHolder width = new IntHolder(400);
    IntHolder height = new IntHolder(400);
    ArgParser parser = new ArgParser("java maspack.geometry.NURBSViewer");
    parser.addOption("-width %d #width (pixels)", width);
    parser.addOption("-height %d #height (pixels)", height);
    parser.addOption("-drawAxes %v #draw coordinate axes", drawAxes);
    parser.addOption("-file %s #wavefront file name", fileName);
    parser.addOption("-sphere %v #create a NURBS sphere", addSphere);
    parser.addOption("-circle %v #create a NURBS circle", addCircle);
    parser.addOption("-mesh %v #create a mesh for surfaces", addMesh);
    parser.addOption("-collider %v #create a colliding object for meshes", collider);
    parser.addOption("-axisLength %f #coordinate axis length", axisLength);
    parser.addOption("-GLVersion %d{2,3} " + "#version of openGL for graphics", glVersion);
    parser.matchAllArgs(args);
    NURBSViewer viewFrame = null;
    try {
        GLVersion glv = (glVersion.value == 3 ? GLVersion.GL3 : GLVersion.GL2);
        viewFrame = new NURBSViewer(width.value, height.value, glv);
        GLViewer viewer = viewFrame.getViewer();
        if (fileName.value != null) {
            viewFrame.addNURBS(new File(fileName.value));
        }
        if (addSphere.value) {
            NURBSSurface sphere = new NURBSSurface();
            sphere.setSphere(0, 0, 0, 10);
            if (addMesh.value) {
                viewFrame.addNURBSWithMesh(sphere);
            } else {
                viewFrame.addNURBS(sphere);
            }
        }
        if (addCircle.value) {
            NURBSCurve3d circle = new NURBSCurve3d();
            circle.setCircle(0, 0, 10);
            viewFrame.addNURBS(circle);
        }
        viewer.autoFitPerspective();
        if (drawAxes.value) {
            if (axisLength.value > 0) {
                viewer.setAxisLength(axisLength.value);
            } else {
                viewer.setAxisLength(GLViewer.AUTO_FIT);
            }
        }
        if (collider.value) {
            viewFrame.addCollidable();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    viewFrame.setVisible(true);
}
Also used : GLVersion(maspack.render.GL.GLViewer.GLVersion) GLViewer(maspack.render.GL.GLViewer) StringHolder(argparser.StringHolder) NURBSCurve3d(maspack.geometry.NURBSCurve3d) IntHolder(argparser.IntHolder) ArgParser(argparser.ArgParser) File(java.io.File) IOException(java.io.IOException) NURBSSurface(maspack.geometry.NURBSSurface)

Aggregations

ArgParser (argparser.ArgParser)2 File (java.io.File)2 IOException (java.io.IOException)2 GLVersion (maspack.render.GL.GLViewer.GLVersion)2 IntHolder (argparser.IntHolder)1 StringHolder (argparser.StringHolder)1 MovieMaker (artisynth.core.moviemaker.MovieMaker)1 WayPoint (artisynth.core.probes.WayPoint)1 RootModel (artisynth.core.workspace.RootModel)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 NURBSCurve3d (maspack.geometry.NURBSCurve3d)1 NURBSSurface (maspack.geometry.NURBSSurface)1 GLViewer (maspack.render.GL.GLViewer)1 InternalErrorException (maspack.util.InternalErrorException)1