📄 viewer.java
字号:
} catch(NoSuchMethodError e) {} createFramesAndPanels(setVisible); } else { canvases = new Canvas3D[userCanvases.length]; for (int i=0; i<userCanvases.length; i++) { canvases[i] = userCanvases[i]; try { canvases[i].setFocusable( true ); } catch(NoSuchMethodError e) {} } } // Create a View and attach the Canvas3D and the physical // body and environment to the view. view = new View(); // Fix to issue 424 view.setUserHeadToVworldEnable(true); // Add it to the Viewer's HashMap. synchronized (viewerMap) { Viewer.viewerMap.put(view, this); } for (int i=0; i<canvases.length; i++) { view.addCanvas3D(canvases[i]); } view.setPhysicalBody(physicalBody); view.setPhysicalEnvironment(physicalEnvironment); } /** * Creates a default Viewer object. The default values are used to create * the PhysicalEnvironment and PhysicalBody. A single RGB, double buffered * and depth buffered Canvas3D object is created. The View is created * with a front clip distance of 0.1f and a back clip distance of 10.0f. * * @param userConfig the URL of the user configuration file used to * initialize the PhysicalBody object; this is always ignored * @since Java3D 1.1 * @deprecated create a ConfiguredUniverse to use a configuration file */ public Viewer(URL userConfig) { // Call main constructor. this(null, userConfig); } /** * Creates a default viewer object. The default values are used to create * the PhysicalEnvironment and PhysicalBody. The View is created * with a front clip distance of 0.1f and a back clip distance of 10.0f. * * @param userCanvas the Canvas3D object to be used for rendering; * if this is null then a single RGB, double buffered and depth buffered * Canvas3D object is created * @param userConfig the URL of the user configuration file used to * initialize the PhysicalBody object; this is always ignored * @since Java3D 1.1 * @deprecated create a ConfiguredUniverse to use a configuration file */ public Viewer(Canvas3D userCanvas, URL userConfig) { // Only one PhysicalBody per Universe. if (physicalBody == null) { physicalBody = new PhysicalBody(); } // Only one PhysicalEnvironment per Universe. if (physicalEnvironment == null) { physicalEnvironment = new PhysicalEnvironment(); } // Create Canvas3D object if none was passed in. if (userCanvas == null) { GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); canvases = new Canvas3D[1]; canvases[0] = new Canvas3D(config); createFramesAndPanels(true); } else { canvases = new Canvas3D[1]; canvases[0] = userCanvas; } try { canvases[0].setFocusable( true ); } catch(NoSuchMethodError e) {} // Create a View and attach the Canvas3D and the physical // body and environment to the view. view = new View(); // Fix to issue 424 view.setUserHeadToVworldEnable(true); // Add it to the Viewer's HashMap. synchronized (viewerMap) { Viewer.viewerMap.put(view, this); } view.addCanvas3D(canvases[0]); view.setPhysicalBody(physicalBody); view.setPhysicalEnvironment(physicalEnvironment); } /** * Package-scoped constructor to create a Viewer from the configuration * objects provided by ConfiguredUniverse. * * @param cs array of ConfigScreen objects containing configuration * information for the physical screens in the environment * @param cv ConfigView object containing configuration information about * the view to be created using the given screens * @param setVisible if true, call setVisible(true) on all created Window * components; otherwise, they remain invisible */ Viewer(ConfigScreen[] cs, ConfigView cv, boolean setVisible) { // Retrieve the J3D View object from the ConfigView object. // The physical body and environment have already been set there. view = cv.j3dView; // Add it to the Viewer's HashMap. synchronized (viewerMap) { Viewer.viewerMap.put(view, this); } // Set this Viewer's references to the physical body and environment. physicalBody = cv.physicalBody; physicalEnvironment = cv.physicalEnvironment; // Get available screen devices. // // When running with JDK 1.3.1 or older under the X Window System with // Xinerama enabled, a single screen device is returned which is // actually a virtual screen spanning all the physical screens in the // X display. These can only be configured as a single planar screen // in the configuration file. // // JDK 1.4 and newer returns a screen device for each physical screen, // allowing them to configured as distinct screens with arbitrary // orientations relative to each other. // GraphicsDevice[] devices; GraphicsEnvironment graphicsEnv; graphicsEnv = GraphicsEnvironment.getLocalGraphicsEnvironment(); devices = graphicsEnv.getScreenDevices(); if (devices == null) throw new RuntimeException( "No screen devices available in local environment"); if (debug) { System.out.println ("Viewer: GraphicsEnvironment returned " + devices.length + " GraphicsDevice object" + (devices.length == 1 ? "" : "s")); for (int i = 0; i < devices.length; i++) { System.out.println (devices[i] + "\n" + devices[i].getDefaultConfiguration().getBounds() + "\n"); } } // Allocate the arrays of components to be used. AWT Windows are used // to hold either a JFrame or a JWindow. canvases = new Canvas3D[cs.length]; j3dJFrames = new JFrame[cs.length]; j3dJPanels = new JPanel[cs.length]; j3dWindows = new Window[cs.length]; // Create a graphics template requesting the desired capabilities. GraphicsConfigTemplate3D tpl3D = new GraphicsConfigTemplate3D(); if (cv.stereoEnable) { tpl3D.setStereo(tpl3D.PREFERRED); } if (cv.antialiasingEnable) { tpl3D.setSceneAntialiasing(tpl3D.PREFERRED); } // Loop through all screens. Set up the Swing component structure and // the configured attributes for the Canvas3D and Screen3D associated // with each screen. for (int i = 0; i < cs.length; i++) { if (cs[i].frameBufferNumber >= devices.length) throw new ArrayIndexOutOfBoundsException( cs[i].errorMessage(cs[i].creatingCommand, "Screen " + cs[i].frameBufferNumber + " is invalid; " + (devices.length-1) + " is the maximum local index.")); Rectangle bounds; Container contentPane; GraphicsConfiguration cfg = devices[cs[i].frameBufferNumber].getBestConfiguration(tpl3D); if (cfg == null) throw new RuntimeException( "No GraphicsConfiguration on screen " + cs[i].frameBufferNumber + " conforms to template"); // Workaround for Issue 316 - use the default config for the screen GraphicsConfiguration defCfg = cfg.getDevice().getDefaultConfiguration(); bounds = defCfg.getBounds(); cs[i].j3dJFrame = j3dJFrames[i] = new JFrame(cs[i].instanceName, defCfg); if (cs[i].noBorderFullScreen) { try { // Required by JDK 1.4 AWT for borderless full screen. j3dJFrames[i].setUndecorated(true); cs[i].j3dWindow = j3dWindows[i] = j3dJFrames[i]; contentPane = j3dJFrames[i].getContentPane(); } catch (NoSuchMethodError e) { // Handle borderless full screen running under JDK 1.3.1. JWindow jwin = new JWindow(j3dJFrames[i], cfg); cs[i].j3dWindow = j3dWindows[i] = jwin; contentPane = jwin.getContentPane(); } contentPane.setLayout(new BorderLayout()); j3dWindows[i].setSize(bounds.width, bounds.height); j3dWindows[i].setLocation(bounds.x, bounds.y); } else { cs[i].j3dWindow = j3dWindows[i] = j3dJFrames[i]; contentPane = j3dJFrames[i].getContentPane(); contentPane.setLayout(new BorderLayout()); if (cs[i].fullScreen) { j3dWindows[i].setSize(bounds.width, bounds.height); j3dWindows[i].setLocation(bounds.x, bounds.y); } else { j3dWindows[i].setSize(cs[i].windowWidthInPixels, cs[i].windowHeightInPixels); j3dWindows[i].setLocation(bounds.x + cs[i].windowX, bounds.y + cs[i].windowY) ; } } // Create a Canvas3D and set its attributes. cs[i].j3dCanvas = canvases[i] = new Canvas3D(cfg); canvases[i].setStereoEnable(cv.stereoEnable); canvases[i].setMonoscopicViewPolicy(cs[i].monoscopicViewPolicy); // Get the Screen3D and set its attributes. Screen3D screen = canvases[i].getScreen3D(); if (cs[i].physicalScreenWidth != 0.0) screen.setPhysicalScreenWidth(cs[i].physicalScreenWidth); if (cs[i].physicalScreenHeight != 0.0) screen.setPhysicalScreenHeight(cs[i].physicalScreenHeight); if (cs[i].trackerBaseToImagePlate != null) screen.setTrackerBaseToImagePlate (new Transform3D(cs[i].trackerBaseToImagePlate)); if (cs[i].headTrackerToLeftImagePlate != null) screen.setHeadTrackerToLeftImagePlate (new Transform3D(cs[i].headTrackerToLeftImagePlate)); if (cs[i].headTrackerToRightImagePlate != null) screen.setHeadTrackerToRightImagePlate (new Transform3D(cs[i].headTrackerToRightImagePlate)); // Put the Canvas3D into a JPanel. cs[i].j3dJPanel = j3dJPanels[i] = new JPanel(); j3dJPanels[i].setLayout(new BorderLayout()); j3dJPanels[i].add("Center", canvases[i]); // Put the JPanel into the content pane used by JWindow or JFrame. contentPane.add("Center", j3dJPanels[i]); // Attach the Canvas3D to the View. view.addCanvas3D(canvases[i]); // Add a windowListener to detect the window close event. addWindowCloseListener(j3dWindows[i]); // Set Canvas3D focus as required by the JDK 1.4 focus model for // full screen frames. JDK 1.3.1 sets the focus automatically for // full screen components. try { canvases[i].setFocusable(true) ; } catch (NoSuchMethodError e) { } if (debug) { System.out.println("Viewer: created Canvas3D for screen " + cs[i].frameBufferNumber + " with size\n " + j3dWindows[i].getSize()); System.out.println("Screen3D[" + i + "]: size in pixels (" + screen.getSize().width + " x " + screen.getSize().height + ")"); System.out.println(" physical size in meters: (" + screen.getPhysicalScreenWidth() + " x " + screen.getPhysicalScreenHeight() + ")"); System.out.println(" hashCode = " + screen.hashCode() + "\n"); } } if (setVisible) // Call setVisible() on all created Window components. setVisible(true); } // Create the JFrames and JPanels for application-supplied Canvas3D // objects. private void createFramesAndPanels( boolean setVisible ) { j3dJFrames = new JFrame[canvases.length]; j3dJPanels = new JPanel[canvases.length]; j3dWindows = new Window[canvases.length]; for (int i = 0; i < canvases.length; i++) { j3dWindows[i] = j3dJFrames[i] = new JFrame(); j3dJFrames[i].getContentPane().setLayout(new BorderLayout()); j3dJFrames[i].setSize(256, 256); // Put the Canvas3D into a JPanel. j3dJPanels[i] = new JPanel(); j3dJPanels[i].setLayout(new BorderLayout()); j3dJPanels[i].add("Center", canvases[i]); j3dJFrames[i].getContentPane().add("Center", j3dJPanels[i]); if (setVisible) { j3dJFrames[i].setVisible(true); } addWindowCloseListener(j3dJFrames[i]); } } /** * Call setVisible() on all Window components created by this Viewer. * * @param visible boolean to be passed to the setVisible() calls on the * Window components created by this Viewer * @since Java3D 1.3 */ public void setVisible(boolean visible) { for (int i = 0; i < j3dWindows.length; i++) { j3dWindows[i].setVisible(visible); } } /** * Returns the View object associated with the Viewer object. * * @return The View object of this Viewer. */ public View getView() { return view; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -