001: /*
002: * $RCSfile: LwsFog.java,v $
003: *
004: * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * - Redistribution of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * - Redistribution in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * Neither the name of Sun Microsystems, Inc. or the names of
019: * contributors may be used to endorse or promote products derived
020: * from this software without specific prior written permission.
021: *
022: * This software is provided "AS IS," without a warranty of any
023: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
024: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
025: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
026: * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
027: * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
028: * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
029: * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
030: * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
031: * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
032: * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
033: * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
034: * POSSIBILITY OF SUCH DAMAGES.
035: *
036: * You acknowledge that this software is not designed, licensed or
037: * intended for use in the design, construction, operation or
038: * maintenance of any nuclear facility.
039: *
040: * $Revision: 1.4 $
041: * $Date: 2007/02/09 17:20:08 $
042: * $State: Exp $
043: */
044:
045: package com.sun.j3d.loaders.lw3d;
046:
047: import java.io.*;
048: import javax.media.j3d.*;
049: import javax.vecmath.*;
050: import java.util.Enumeration;
051: import com.sun.j3d.loaders.ParsingErrorException;
052:
053: /**
054: * This class creates a Fog object from the data in a Scene file.
055: */
056:
057: class LwsFog extends TextfileParser {
058:
059: // data from the file
060: float minDist, maxDist, minAmount, maxAmount;
061: int backdropFog;
062: Color3f color;
063: int type;
064: Fog fogObject = null;
065:
066: /**
067: * Constructor: parses stream and stores fog data
068: */
069: LwsFog(StreamTokenizer st, int debugVals)
070: throws ParsingErrorException {
071: debugPrinter.setValidOutput(debugVals);
072: debugOutput(TRACE, "LwsFog()");
073: color = new Color3f(0f, 0f, 0f);
074:
075: while (!isCurrentToken(st, "DitherIntensity")) {
076: debugOutputLn(LINE_TRACE, "currentToken = " + st.sval);
077:
078: if (isCurrentToken(st, "FogMinDist")) {
079: minDist = (float) getNumber(st);
080: } else if (isCurrentToken(st, "FogMaxDist")) {
081: maxDist = (float) getNumber(st);
082: } else if (isCurrentToken(st, "FogMinAmount")) {
083: minAmount = (float) getNumber(st);
084: } else if (isCurrentToken(st, "FogMaxAmount")) {
085: maxAmount = (float) getNumber(st);
086: } else if (isCurrentToken(st, "BackdropFog")) {
087: backdropFog = (int) getNumber(st);
088: } else if (isCurrentToken(st, "FogColor")) {
089: color.x = (float) getNumber(st) / 255f;
090: color.y = (float) getNumber(st) / 255f;
091: color.z = (float) getNumber(st) / 255f;
092: }
093: try {
094: st.nextToken();
095: } catch (IOException e) {
096: throw new ParsingErrorException(e.getMessage());
097: }
098: }
099: st.pushBack(); // push token back on stack
100: }
101:
102: /**
103: * Creates Java3d Fog object given the fog parameters in the file.
104: * Note that various fog parameters in lw3d are not currently handled.
105: */
106: void createJava3dObject() {
107: // TODO: there are various attributes of lw fog that
108: // we're not currently handing, including non-linear fog
109: // (need to understand the two different types - these may
110: // map onto java3d's expontential fog node), non-solid
111: // backdrop colors (how to handle this?), min/max amount
112: // (j3d only handles 0 -> 1 case)
113:
114: fogObject = new LinearFog(color, minDist, maxDist);
115: debugOutputLn(VALUES,
116: "just set linearFog with color, minDist, maxDist = "
117: + color + ", " + minDist + ", " + maxDist);
118: BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,
119: 0.0, 0.0), 100000.0);
120: fogObject.setInfluencingBounds(bounds);
121: }
122:
123: Fog getObjectNode() {
124: return fogObject;
125: }
126:
127: void printVals() {
128: debugOutputLn(VALUES, " FOG vals: ");
129: }
130:
131: }
|