📄 configureduniverse.java
字号:
* @param localeFactory the factory object used to create the Locale * @param origin the origin used to set the origin of the Locale object; * if this object is null, then 0.0 is used * @param setVisible if true, calls <code>setVisible(true)</code> on all * created window components; otherwise, they remain invisible * * @see Locale * @see Viewer * @see ViewingPlatform * @see MultiTransformGroup */ ConfiguredUniverse(int transformCount, Canvas3D[] canvases, URL userConfig, LocaleFactory localeFactory, HiResCoord origin, boolean setVisible) { super(origin, localeFactory); if (userConfig == null) { viewer = new Viewer[1]; viewer[0] = new Viewer(canvases, null, null, setVisible); createDefaultViewingPlatform(transformCount); } else { // Create a ConfigContainer without attaching behaviors. The // package-scope constructor is used for backward compatibility. configContainer = new ConfigContainer (userConfig, setVisible, transformCount, false); Collection c = configContainer.getViewers(); if (c == null || c.size() == 0) throw new IllegalArgumentException( "no views defined in configuration file"); viewer = (Viewer[])c.toArray(new Viewer[1]); // Get ViewingPlatforms from the ConfigContainer and add them to // the locale. The package-scoped findConfigObjects() accesor is // used so that backward compatibility can be maintained for older // configuration files. c = configContainer.findConfigObjects("ViewPlatform"); if (c == null || c.size() == 0) { createDefaultViewingPlatform(transformCount); } else { Iterator i = c.iterator(); while (i.hasNext()) { ConfigViewPlatform cvp = (ConfigViewPlatform)i.next(); ViewingPlatform vp = cvp.viewingPlatform; // For backward compatibility, handle the default // attachment of one Viewer to one ViewingPlatform. If // there are multiple Viewers and ViewingPlatforms then // attachments must be made explicitly in the config file. if (vp.getViewers() == null && viewer.length == 1 && c.size() == 1) { if (cvp.viewAttachPolicy == -1) { setDerivedAttachPolicy(viewer[0], vp) ; } viewer[0].setViewingPlatform(vp); } vp.setUniverse(this); locale.addBranchGraph(vp); // If there's a behavior associated with the platform, // attach it now after the setting the universe reference. cvp.processBehavior(); } } } } /** * Creates a default ViewingPlatform, attaches the first Viewer, and then * attaches the platform to the Locale. * * @param transformCount number of TransformGroups to create in the * ViewingPlatform */ private void createDefaultViewingPlatform(int transformCount) { ViewingPlatform vp = new ViewingPlatform(transformCount); setDerivedAttachPolicy(viewer[0], vp); viewer[0].setViewingPlatform(vp); vp.setUniverse(this); locale.addBranchGraph(vp); } /** * Sets a view attach policy appropriate for a window eyepoint policy. * * @param v Viewer to which the ViewingPlatform will be attached * @param vp ViewingPlatform to which the Viewer will be attached */ private void setDerivedAttachPolicy(Viewer v, ViewingPlatform vp) { if (v.getView().getWindowEyepointPolicy() != View.RELATIVE_TO_FIELD_OF_VIEW) { vp.getViewPlatform().setViewAttachPolicy(View.NOMINAL_SCREEN); } } /** * Returns the Viewer object specified by the given index. * * @param index The index of which Viewer object to return. * * @return The Viewer object specified by the given index. */ public Viewer getViewer(int index) { return viewer[index]; } /** * Returns all of the Viewer objects associated with this scene graph. * * @return The Viewer objects associated with this scene graph. */ public Viewer[] getViewers() { Viewer[] ret = new Viewer[viewer.length]; for (int i = 0; i < viewer.length; i++) { ret[i] = viewer[i]; } return ret; } /** * Call <code>setVisible()</code> on all AWT components created by this * ConfiguredUniverse instance.<p> * * @param visible boolean to be passed to the <code>setVisible()</code> * calls on the window components created by this * ConfiguredUniverse instance */ public void setVisible(boolean visible) { for (int i = 0; i < viewer.length; i++) if (viewer[i] != null) viewer[i].setVisible(visible); } /** * Returns the config file URL based on system properties. This is * equivalent to calling <code>ConfigContainer.getConfigURL()</code>. The * current implementation of this method parses the j3d.configURL property * as a URL string. For example, the following command line would specify * that the config file is taken from the file "j3dconfig" in the current * directory: * <ul> * <code>java -Dj3d.configURL=file:j3dconfig ...</code> * </ul> * * @return the URL of the config file; null is returned if no valid * URL is defined by the system properties */ public static URL getConfigURL() { return ConfigContainer.getConfigURL(null); } /** * Returns the config file URL based on system properties. This is the * same as calling <code>ConfigContainer.getConfigURL(String)</code>. The * current implementation of this method parses the j3d.configURL property * as a URL string. For example, the following command line would specify * that the config file is taken from the file "j3dconfig" in the current * directory: * <ul> * <code>java -Dj3d.configURL=file:j3dconfig ...</code> * </ul> * * @param defaultURLString the default string used to construct * the URL if the appropriate system properties are not defined * @return the URL of the config file; null is returned if no * valid URL is defined either by the system properties or the * default URL string */ public static URL getConfigURL(String defaultURLString) { return ConfigContainer.getConfigURL(defaultURLString); } /** * Returns all named Sensors defined by the configuration file used to * create the ConfiguredUniverse, if any. Equivalent to * <code>getConfigContainer().getNamedSensors()</code>.<p> * * With the sole exception of the Sensor assigned to the head tracker, * none of the Sensors defined in the configuration file are placed into * the Sensor array maintained by PhysicalEnvironment. The head tracker * Sensor is the only one read by the Java 3D core and must generate reads * with a full 6 degrees of freedom (3D position and 3D orientation).<p> * * Other Sensors need not generate reads with a full 6 degrees of freedom, * although their reads must be expressed using Transform3D. Some * joysticks may provide only 2D relative X and Y axis movement; dials, * levers, and sliders are 1D devices, and some devices may combine dials * and levers to generate 3D positional data.<p> * * The index names to identify left / right / dominant / non-dominant hand * Sensors in the PhysicalEnvironement Sensor array are not adequate to * distinguish these differences, so this method allows applications to * look up Sensors based on the names bound to them in the configuration * file. There are no set rules on naming. Applications that use Sensors * may set up conventions for generic devices such as "mouse6D" or * "joystick2D" or specific product names.<p> * * @return read-only Map which maps Sensor names to the associated Sensors, * or null if no Sensors have been named */ public Map getNamedSensors() { if (configContainer == null) return null; else return configContainer.getNamedSensors(); } /** * Returns all named ViewPlatformBehaviors defined by the configuration * file used to create the ConfiguredUniverse, if any. Equivalent * to <code>getConfigContainer().getNamedViewPlatformBehaviors()</code>.<p> * * @return read-only Map which maps behavior names to the associated * ViewPlatformBehavior instances, or null if none have been named. * @since Java 3D 1.3.1 */ public Map getNamedBehaviors() { if (configContainer == null) return null; else return configContainer.getNamedViewPlatformBehaviors(); } /** * Returns a container holding all the objects defined by the * configuration file used to create the ConfiguredUniverse. * * @return the container * @since Java 3D 1.3.1 */ public ConfigContainer getConfigContainer() { return configContainer; } /** * Cleanup memory references used by ConfiguredUniverse. * @since Java 3D 1.3.1 */ public void cleanup() { if (viewer != null) { for (int i = 0 ; i < viewer.length ; i++) { viewer[i].getView().removeAllCanvas3Ds(); viewer[i].setViewingPlatform(null); viewer[i] = null; } } locale = null; removeAllLocales(); Viewer.clearViewerMap(); configContainer.clear(); configContainer = null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -