📄 simpleuniverse.java
字号:
* @see Viewer * @see ViewingPlatform * @see MultiTransformGroup * @deprecated use ConfiguredUniverse constructors to read a * configuration file */ public SimpleUniverse(HiResCoord origin, int numTransforms, Canvas3D canvas, URL userConfig, LocaleFactory localeFactory ) { ViewingPlatform vwp; createLocale( origin, localeFactory ); // Create the ViewingPlatform and Viewer objects, passing // down the appropriate parameters. vwp = new ViewingPlatform(numTransforms); vwp.setUniverse( this ); viewer = new Viewer[1]; // viewer[0] = new Viewer(canvas, userConfig); viewer[0] = new Viewer(canvas); viewer[0].setViewingPlatform(vwp); // Add the ViewingPlatform to the locale - the scene // graph is now "live". locale.addBranchGraph(vwp); } /** * Creates the "view" side of the scene graph. The passed in parameters * override the default values where appropriate. * * @param viewingPlatform The viewingPlatform to use to create * the "view" side of the scene graph. * @param viewer The viewer object to use to create * the "view" side of the scene graph. */ public SimpleUniverse(ViewingPlatform viewingPlatform, Viewer viewer) { this( viewingPlatform, viewer, null ); } /** * Creates the "view" side of the scene graph. The passed in parameters * override the default values where appropriate. * * @param viewingPlatform The viewingPlatform to use to create * the "view" side of the scene graph. * @param viewer The viewer object to use to create * the "view" side of the scene graph. * @param localeFactory The factory used to create the Locale Object */ public SimpleUniverse(ViewingPlatform viewingPlatform, Viewer viewer, LocaleFactory localeFactory ) { createLocale( null, localeFactory ); viewingPlatform.setUniverse( this ); // Assign object references. this.viewer = new Viewer[1]; this.viewer[0] = viewer; // Add the ViewingPlatform to the Viewer object. this.viewer[0].setViewingPlatform(viewingPlatform); // Add the ViewingPlatform to the locale - the scene // graph is now "live". locale.addBranchGraph(viewingPlatform); } /** * Constructor for use by Configured Universe */ SimpleUniverse( HiResCoord origin, LocaleFactory localeFactory ) { createLocale( origin, localeFactory ); } /** * Create the Locale using the LocaleFactory and HiRes origin, * if specified. */ private void createLocale( HiResCoord origin, LocaleFactory localeFactory ) { if (localeFactory != null) { if (origin != null) locale = localeFactory.createLocale(this, origin); else locale = localeFactory.createLocale(this); } else { if (origin != null) locale = new Locale(this, origin); else locale = new Locale(this); } } /** * Returns the Locale object associated with this scene graph. * * @return The Locale object used in the construction of this scene * graph. */ public Locale getLocale() { return locale; } /** * Returns the Viewer object associated with this scene graph. * SimpleUniverse creates a single Viewer object for use in the * scene graph. * * @return The Viewer object associated with this scene graph. */ public Viewer getViewer() { return viewer[0]; } /** * Returns the ViewingPlatform object associated with this scene graph. * * @return The ViewingPlatform object of this scene graph. */ public ViewingPlatform getViewingPlatform() { return viewer[0].getViewingPlatform(); } /** * Returns the Canvas3D object associated with this Java 3D Universe. * * @return A reference to the Canvas3D object associated with the * Viewer object. This method is equivalent to calling getCanvas(0). * * @see Viewer */ public Canvas3D getCanvas() { return getCanvas(0); } /** * Returns the Canvas3D object at the specified index associated with * this Java 3D Universe. * * @param canvasNum The index of the Canvas3D object to retrieve. * If there is no Canvas3D object for the given index, null is returned. * * @return A reference to the Canvas3D object associated with the * Viewer object. */ public Canvas3D getCanvas(int canvasNum) { return viewer[0].getCanvas3D(canvasNum); } /** * Used to add Nodes to the geometry side (as opposed to the view side) * of the scene graph. This is a short cut to getting the Locale object * and calling that object's addBranchGraph() method. * * @param bg The BranchGroup to attach to this Universe's Locale. */ public void addBranchGraph(BranchGroup bg) { locale.addBranchGraph(bg); } /** * Finds the preferred <code>GraphicsConfiguration</code> object * for the system. This object can then be used to create the * Canvas3D objet for this system. * * @return The best <code>GraphicsConfiguration</code> object for * the system. */ public static GraphicsConfiguration getPreferredConfiguration() { GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D(); String stereo; // Check if the user has set the Java 3D stereo option. // Getting the system properties causes appletviewer to fail with a // security exception without a try/catch. stereo = (String) java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() { public Object run() { return System.getProperty("j3d.stereo"); } }); // update template based on properties. if (stereo != null) { if (stereo.equals("REQUIRED")) template.setStereo(template.REQUIRED); else if (stereo.equals("PREFERRED")) template.setStereo(template.PREFERRED); } // Return the GraphicsConfiguration that best fits our needs. return GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getBestConfiguration(template); } /** * Cleanup memory use and reference by SimpleUniverse. * Typically it should be invoked by the applet's destroy method. */ public void cleanup() { // Get view associated with this SimpleUniverse View view = viewer[0].getView(); // Issue 134: cleanup all off-screen canvases for (int i = view.numCanvas3Ds() - 1; i >= 0; i--) { Canvas3D c = view.getCanvas3D(i); if (c.isOffScreen()) { c.setOffScreenBuffer(null); } } // Remove all canvases from view; remove the viewing platform from // this viewer; remove all locales to cleanup the scene graph view.removeAllCanvas3Ds(); viewer[0].setViewingPlatform(null); removeAllLocales(); // viewerMap cleanup here to prevent memory leak problem. Viewer.clearViewerMap(); Primitive.clearGeometryCache(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -