001: /*
002: * $RCSfile: VrmlScene.java,v $
003: *
004: * @(#)VrmlScene.java 1.21 99/03/11 11:12:44
005: *
006: * Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
007: *
008: * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
009: * modify and redistribute this software in source and binary code form,
010: * provided that i) this copyright notice and license appear on all copies of
011: * the software; and ii) Licensee does not utilize the software in a manner
012: * which is disparaging to Sun.
013: *
014: * This software is provided "AS IS," without a warranty of any kind. ALL
015: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
016: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
017: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
018: * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
019: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
020: * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
021: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
022: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
023: * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
024: * POSSIBILITY OF SUCH DAMAGES.
025: *
026: * This software is not designed or intended for use in on-line control of
027: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
028: * the design, construction, operation or maintenance of any nuclear
029: * facility. Licensee represents and warrants that it will not use or
030: * redistribute the Software for such purposes.
031: *
032: *
033: * $Revision: 1.2 $
034: * $Date: 2005/02/03 23:06:51 $
035: * $State: Exp $
036: */
037: /* @Author: Rick Goldberg
038: * @Author: Doug Gehringer
039: */
040: // Static scene description for time zero loader
041: package org.jdesktop.j3d.loaders.vrml97;
042:
043: import java.util.Enumeration;
044: import java.util.Hashtable;
045: import javax.media.j3d.BranchGroup;
046: import javax.media.j3d.TransformGroup;
047: import org.jdesktop.j3d.loaders.vrml97.node.*;
048: import vrml.*;
049: import vrml.node.*;
050:
051: /** Description of the Class */
052: public class VrmlScene implements com.sun.j3d.loaders.Scene {
053: org.jdesktop.j3d.loaders.vrml97.impl.Scene base;
054: String description;
055: int numTris;
056: BaseNode[] objects;
057: Viewpoint[] viewpoints;
058: Node[] navInfos;
059: Background[] backgrounds;
060: Fog[] fogs;
061: Light[] lights;
062: Hashtable defTable;
063: BranchGroup scene = null;
064:
065: /**
066: *Constructor for the VrmlScene object
067: *
068: *@param base Description of the Parameter
069: */
070: VrmlScene(org.jdesktop.j3d.loaders.vrml97.impl.Scene base) {
071: this .base = base;
072: description = base.description;
073: numTris = base.numTris;
074:
075: objects = new BaseNode[base.objects.size()];
076: Enumeration elems = base.objects.elements();
077: for (int i = 0; i < objects.length; i++) {
078: org.jdesktop.j3d.loaders.vrml97.impl.BaseNode node = (org.jdesktop.j3d.loaders.vrml97.impl.BaseNode) elems
079: .nextElement();
080: objects[i] = node.wrap();
081: }
082:
083: viewpoints = new Viewpoint[base.viewpoints.size()];
084: elems = base.viewpoints.elements();
085: for (int i = 0; i < viewpoints.length; i++) {
086: viewpoints[i] = (org.jdesktop.j3d.loaders.vrml97.node.Viewpoint) ((org.jdesktop.j3d.loaders.vrml97.impl.BaseNode) elems
087: .nextElement()).wrap();
088: }
089:
090: navInfos = new Node[base.navInfos.size()];
091: elems = base.navInfos.elements();
092: for (int i = 0; i < navInfos.length; i++) {
093: navInfos[i] = (vrml.node.Node) ((org.jdesktop.j3d.loaders.vrml97.impl.BaseNode) elems
094: .nextElement()).wrap();
095: }
096:
097: backgrounds = new Background[base.backgrounds.size()];
098: elems = base.backgrounds.elements();
099: for (int i = 0; i < backgrounds.length; i++) {
100: backgrounds[i] = (org.jdesktop.j3d.loaders.vrml97.node.Background) ((org.jdesktop.j3d.loaders.vrml97.impl.BaseNode) elems
101: .nextElement()).wrap();
102: }
103:
104: fogs = new Fog[base.fogs.size()];
105: elems = base.fogs.elements();
106: for (int i = 0; i < fogs.length; i++) {
107: fogs[i] = (org.jdesktop.j3d.loaders.vrml97.node.Fog) ((org.jdesktop.j3d.loaders.vrml97.impl.BaseNode) elems
108: .nextElement()).wrap();
109: }
110:
111: lights = new Light[base.lights.size()];
112: elems = base.lights.elements();
113: for (int i = 0; i < lights.length; i++) {
114: lights[i] = (org.jdesktop.j3d.loaders.vrml97.node.Light) ((org.jdesktop.j3d.loaders.vrml97.impl.BaseNode) elems
115: .nextElement()).wrap();
116: }
117:
118: defTable = new Hashtable();
119: for (elems = base.defTable.keys(); elems.hasMoreElements();) {
120: Object key = elems.nextElement();
121: Object value = ((org.jdesktop.j3d.loaders.vrml97.impl.BaseNode) base.defTable
122: .get(key)).wrap();
123: defTable.put(key, value);
124: }
125: }
126:
127: /**
128: * Gets the sceneGroup attribute of the VrmlScene object
129: *
130: *@return The sceneGroup value
131: */
132: public BranchGroup getSceneGroup() {
133: if (scene == null) {
134: scene = new BranchGroup();
135: for (int i = 0; i < objects.length; i++) {
136: javax.media.j3d.Node j3dNode;
137: if ((j3dNode = objects[i].getImplNode()) != null) {
138: ;
139: scene.addChild(j3dNode);
140: }
141: }
142: }
143: return scene;
144: }
145:
146: /**
147: * The TransformGroups returned will be parented withing the SceneGroup.
148: * The ViewPlatform will be the child of the TransformGroup
149: *
150: *@return The viewGroups value
151: */
152: public TransformGroup[] getViewGroups() {
153: TransformGroup[] views = new TransformGroup[viewpoints.length];
154: for (int i = 0; i < viewpoints.length; i++) {
155: views[i] = (TransformGroup) viewpoints[i].getImplNode();
156: }
157: return views;
158: }
159:
160: /**
161: * Gets the horizontalFOVs attribute of the VrmlScene object
162: *
163: *@return The horizontalFOVs value
164: */
165: public float[] getHorizontalFOVs() {
166: float[] fovs = new float[viewpoints.length];
167: for (int i = 0; i < viewpoints.length; i++) {
168: fovs[i] = viewpoints[i].getFOV();
169: }
170: return fovs;
171: }
172:
173: /**
174: * The Light nodes returned will be parented within the SceneGroup
175: *
176: *@return The lightNodes value
177: */
178: public javax.media.j3d.Light[] getLightNodes() {
179: javax.media.j3d.Light[] j3dLights = new javax.media.j3d.Light[lights.length * 2];
180: for (int i = 0; i < lights.length; i++) {
181: j3dLights[i * 2] = lights[i].getAmbientLight();
182: j3dLights[i * 2 + 1] = lights[i].getLight();
183: }
184: return j3dLights;
185: }
186:
187: /**
188: * Gets the namedObjects attribute of the VrmlScene object
189: *
190: *@return The namedObjects value
191: */
192: public Hashtable getNamedObjects() {
193: Hashtable j3dDefTable = new Hashtable();
194: for (Enumeration elems = defTable.keys(); elems
195: .hasMoreElements();) {
196: Object key = elems.nextElement();
197: BaseNode node = (BaseNode) defTable.get(key);
198: javax.media.j3d.Node value = node.getImplNode();
199: if (value != null) {
200: j3dDefTable.put(key, value);
201: }
202: }
203: return j3dDefTable;
204: }
205:
206: /**
207: * The Background nodes returned will be parented within the SceneGroup
208: *
209: *@return The backgroundNodes value
210: */
211: public javax.media.j3d.Background[] getBackgroundNodes() {
212: javax.media.j3d.Background[] j3dBackgrounds = new javax.media.j3d.Background[backgrounds.length];
213: for (int i = 0; i < backgrounds.length; i++) {
214: j3dBackgrounds[i] = backgrounds[i].getBackgroundImpl();
215: }
216: return j3dBackgrounds;
217: }
218:
219: /**
220: * The Fog nodes returned will be parented within the SceneGroup
221: *
222: *@return The fogNodes value
223: */
224: public javax.media.j3d.Fog[] getFogNodes() {
225: javax.media.j3d.Fog[] j3dFogs = new javax.media.j3d.Fog[fogs.length];
226: for (int i = 0; i < fogs.length; i++) {
227: j3dFogs[i] = fogs[i].getFogImpl();
228: }
229: return j3dFogs;
230: }
231:
232: /**
233: * The VRML loader does not support loading behaviors, this method
234: * returns null.
235: *
236: *@return The behaviorNodes value
237: */
238: public javax.media.j3d.Behavior[] getBehaviorNodes() {
239: return null;
240: }
241:
242: /**
243: * The VRML loader does not support loading sounds, this method
244: * returns null.
245: *
246: *@return The soundNodes value
247: */
248: public javax.media.j3d.Sound[] getSoundNodes() {
249: return null;
250: }
251:
252: /**
253: * Returns the description (if any) from the first WorldInfo node
254: * read. If there is no description specified, null will be returned
255: *
256: *@return The description value
257: */
258: public String getDescription() {
259: return description;
260: }
261:
262: // the VRML specific methods start here
263:
264: /**
265: * Scans the subgraph, clearing the pickable and collidable flags on
266: * the Shape3Ds in the subgraph to allow compilation. The pickable
267: * flag will be set to false if the Shape3D does not have an ancestor
268: * which sets the ALLOW_PICK_REPORTING bit. The collidable flag will
269: * always be set to false.
270: *
271: *@param root Description of the Parameter
272: */
273: public void cleanForCompile(javax.media.j3d.Node root) {
274: org.jdesktop.j3d.loaders.vrml97.impl.TreeCleaner
275: .cleanSubgraph(root);
276: }
277:
278: /**
279: * Returns the base level VRML nodes
280: *
281: *@return The objects value
282: */
283: public BaseNode[] getObjects() {
284: BaseNode nodes[] = new BaseNode[objects.length];
285: for (int i = 0; i < objects.length; i++) {
286: nodes[i] = objects[i];
287: }
288: return nodes;
289: }
290:
291: /**
292: * Returns the Viewpoint nodes in the scene
293: *
294: *@return The viewpoints value
295: */
296: public Viewpoint[] getViewpoints() {
297: Viewpoint[] vps = new Viewpoint[viewpoints.length];
298: for (int i = 0; i < viewpoints.length; i++) {
299: vps[i] = viewpoints[i];
300: }
301: return vps;
302: }
303:
304: /**
305: * Returns the a Hashtable which associated DEF names with Nodes
306: *
307: *@return The defineTable value
308: */
309: public Hashtable getDefineTable() {
310: Hashtable userDefTable = new Hashtable();
311: for (Enumeration elems = defTable.keys(); elems
312: .hasMoreElements();) {
313: Object key = elems.nextElement();
314: Object value = defTable.get(key);
315: userDefTable.put(key, value);
316: }
317: return userDefTable;
318: }
319:
320: /**
321: * Returns the approximate number of triangles in the Scene. For Switch
322: * and LOD nodes, only the triangles on the first child of the node are
323: * counted.
324: *
325: *@return The numTris value
326: */
327: public int getNumTris() {
328: return numTris;
329: }
330: }
|