001: /*
002: *
003: * Copyright (c) 2000-2001 Silvere Martin-Michiellot All Rights Reserved.
004: *
005: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
006: * royalty free, license to use, modify but not to redistribute this
007: * software in source and binary code form,
008: * provided that i) this copyright notice and license appear on all copies of
009: * the software; and ii) Licensee does not utilize the software in a manner
010: * which is disparaging to Silvere Martin-Michiellot.
011: *
012: * This software is provided "AS IS," without a warranty of any kind. ALL
013: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
014: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
015: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
016: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
017: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
018: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
019: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
020: * 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 Silvere Martin-Michiellot HAS BEEN
024: * ADVISED OF THE 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: * @Author: Silvere Martin-Michiellot
033: *
034: */
035:
036: package com.db.loaders.j3d;
037:
038: import com.sun.j3d.utils.compression.*;
039: import java.io.*;
040: import java.net.URL;
041: import javax.media.j3d.*;
042: import javax.vecmath.*;
043:
044: import com.db.loaders.*;
045:
046: //use Java3DGeometryFile from the com.db.utils package to write the geometry
047:
048: public class J3DLoader extends LoaderBase {
049:
050: private final boolean debug = true;
051:
052: public J3DLoader() {
053: }
054:
055: //This method doesn't work for this loader
056: public Scene load(Reader reader) {
057:
058: SceneBase scenebase = null;
059:
060: return scenebase;
061:
062: }
063:
064: public Scene load(String s) throws FileNotFoundException {
065:
066: SceneBase scenebase = null;
067: try {
068: scenebase = new SceneBase();
069: scenebase.setSceneGroup(readCompressedGeometry(s));
070: } catch (Exception exception) {
071: System.out.println(exception);
072: }
073:
074: return scenebase;
075:
076: }
077:
078: public Scene load(URL url) throws FileNotFoundException {
079:
080: SceneBase scenebase = null;
081: try {
082: scenebase = new SceneBase();
083: scenebase.setSceneGroup(readCompressedGeometry(url
084: .toString()));
085: } catch (Exception exception) {
086: System.out.println(exception);
087: }
088:
089: return scenebase;
090:
091: }
092:
093: private BranchGroup readCompressedGeometry(String filename) {
094:
095: CompressedGeometryFile compressedGeometryFile;
096: CompressedGeometry compressedGeometry;
097: CompressionStream compressionStream;
098: GeometryCompressor geometryCompressor;
099: Shape3D[] shapes3D;
100:
101: BranchGroup branchGroup = new BranchGroup();
102:
103: if (filename != null) {
104:
105: try {
106:
107: compressedGeometryFile = new CompressedGeometryFile(
108: filename);
109:
110: if (compressedGeometryFile != null) {
111:
112: int j = compressedGeometryFile.getObjectCount();
113:
114: for (int i = 0; i < j; i++) {
115: try {
116: compressedGeometry = compressedGeometryFile
117: .read(i);
118: shapes3D = compressedGeometry.decompress();
119: for (int k = 0; k < shapes3D.length; k++) {
120: branchGroup.addChild(shapes3D[k]);
121: }
122: } catch (Exception exception) {
123: if (debug) {
124: if (exception instanceof java.lang.IndexOutOfBoundsException) {
125: System.out
126: .println("compressed geometry object index is out of range.");
127: } else if (exception instanceof java.io.IOException) {
128: System.out
129: .println("compressed geometry file read failed.");
130: }
131: }
132: }
133: }
134:
135: compressedGeometryFile.close();
136: }
137:
138: } catch (Exception exception) {
139: if (debug) {
140: if (exception instanceof java.io.FileNotFoundException) {
141: System.out
142: .println("compressed geometry file doesn't exist or cannot be read.");
143: } else if (exception instanceof java.lang.IllegalArgumentException) {
144: System.out
145: .println("the file is not a compressed geometry resource file.");
146: } else if (exception instanceof java.io.IOException) {
147: System.out
148: .println("there is a header or directory read error.");
149: }
150: }
151: }
152:
153: }
154:
155: return branchGroup;
156:
157: }
158:
159: }
|