001: /*
002: * $RCSfile: LwsEnvelopeLightIntensity.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 javax.media.j3d.TransformGroup;
051:
052: /**
053: * This class creates a LightIntensityPathInterpolator object from the
054: * keyframe-based envelope specified in a Scene file.
055: */
056:
057: class LwsEnvelopeLightIntensity extends LwsEnvelope {
058:
059: /**
060: * Constructor: Calls superclass, which will parse the stream
061: * and store the envelope data
062: */
063: LwsEnvelopeLightIntensity(StreamTokenizer st, int frames, float time) {
064: super (st, frames, time);
065: }
066:
067: /**
068: * Creates Java3d behaviors given the stored envelope data. The
069: * Behavior created is a LightIntensityPathInterpolator
070: */
071: void createJava3dBehaviors(Object target) {
072: if (numFrames <= 1)
073: behaviors = null;
074: else {
075: long alphaAtOne = 0;
076: int loopCount;
077: if (loop)
078: loopCount = -1;
079: else
080: loopCount = 1;
081: // Note: hardcoded to always loop...
082: loopCount = -1;
083: debugOutputLn(VALUES, "totalTime = " + totalTime);
084: debugOutputLn(VALUES, "loopCount = " + loopCount);
085: float animTime = 1000.0f
086: * totalTime
087: * (float) (frames[numFrames - 1].getFrameNum() / (float) totalFrames);
088: debugOutputLn(VALUES, " anim time: " + animTime);
089: debugOutputLn(VALUES, " totalFrames = " + totalFrames);
090: debugOutputLn(VALUES, " lastFrame = "
091: + frames[numFrames - 1].getFrameNum());
092: if (!loop)
093: alphaAtOne = (long) (1000.0 * totalTime - animTime);
094: Alpha theAlpha = new Alpha(loopCount,
095: Alpha.INCREASING_ENABLE, 0, 0, (long) animTime, 0,
096: alphaAtOne, 0, 0, 0);
097: float knots[] = new float[numFrames];
098: float values[] = new float[numFrames];
099: for (int i = 0; i < numFrames; ++i) {
100: values[i] = (float) frames[i].getValue();
101: knots[i] = (float) (frames[i].getFrameNum())
102: / (float) (frames[numFrames - 1].getFrameNum());
103: debugOutputLn(VALUES, "value, knot = " + values[i]
104: + ", " + knots[i]);
105: }
106: LightIntensityPathInterpolator l = new LightIntensityPathInterpolator(
107: theAlpha, knots, values, target);
108: if (l != null) {
109: behaviors = l;
110: BoundingSphere bounds = new BoundingSphere(new Point3d(
111: 0.0, 0.0, 0.0), 1000000.0);
112: behaviors.setSchedulingBounds(bounds);
113: ((TransformGroup) target)
114: .setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
115: ((TransformGroup) target).addChild(behaviors);
116: }
117: }
118: }
119:
120: Behavior getBehaviors() {
121: return behaviors;
122: }
123:
124: LwsEnvelopeFrame getFirstFrame() {
125: if (numFrames > 0)
126: return frames[0];
127: else
128: return null;
129: }
130:
131: void printVals() {
132: debugOutputLn(VALUES, " name = " + name);
133: debugOutputLn(VALUES, " numChannels = " + numChannels);
134: debugOutputLn(VALUES, " numFrames = " + numFrames);
135: debugOutputLn(VALUES, " loop = " + loop);
136: for (int i = 0; i < numFrames; ++i) {
137: debugOutputLn(VALUES, " FRAME " + i);
138: frames[i].printVals();
139: }
140: }
141:
142: }
|