/* */ package com.sun.j3d.loaders.lw3d;
/* */
/* */ import com.sun.j3d.loaders.IncorrectFormatException;
/* */ import com.sun.j3d.loaders.ParsingErrorException;
/* */ import java.io.File;
/* */ import java.io.FileNotFoundException;
/* */ import java.io.IOException;
/* */ import java.io.StreamTokenizer;
/* */ import java.util.Enumeration;
/* */ import java.util.Hashtable;
/* */ import java.util.Vector;
/* */ import javax.media.j3d.Alpha;
/* */ import javax.media.j3d.Behavior;
/* */ import javax.media.j3d.BoundingSphere;
/* */ import javax.media.j3d.Group;
/* */ import javax.media.j3d.Link;
/* */ import javax.media.j3d.Shape3D;
/* */ import javax.media.j3d.SharedGroup;
/* */ import javax.media.j3d.Switch;
/* */ import javax.media.j3d.SwitchValueInterpolator;
/* */ import javax.media.j3d.TransformGroup;
/* */ import javax.vecmath.Point3d;
/* */
/* */ class SequenceLine
/* */ {
/* */ int startFrame;
/* */ int endFrame;
/* */ String fileName;
/* 115 */ Group geometryGroup = null;
/* */ Behavior behaviors;
/* */ int numFrames;
/* */ float totalTime;
/* */ int totalFrames;
/* 122 */ static Hashtable storedRefList = new Hashtable();
/* */
/* */ SequenceLine(StreamTokenizer st, float time, int frames) throws ParsingErrorException
/* */ {
/* */ try {
/* 127 */ this.totalTime = time;
/* 128 */ this.totalFrames = frames;
/* 129 */ this.startFrame = ((int)st.nval);
/* 130 */ st.nextToken();
/* 131 */ this.endFrame = ((int)st.nval);
/* 132 */ st.nextToken();
/* 133 */ this.fileName = st.sval;
/* 134 */ this.numFrames = (this.endFrame - this.startFrame + 1);
/* */ }
/* */ catch (IOException e) {
/* 137 */ throw new ParsingErrorException(e.getMessage());
/* */ }
/* */ }
/* */
/* */ private void createSwitchBehavior(Switch target)
/* */ {
/* 152 */ int loopCount = -1;
/* 153 */ float animTime = 1000.0F * this.totalTime * target.numChildren() / this.totalFrames;
/* */
/* 155 */ float startTime = 1000.0F * this.totalTime * this.startFrame / this.totalFrames;
/* */
/* 157 */ Alpha theAlpha = new Alpha(-1, ()startTime, 0L, ()animTime, 0L, 0L);
/* */
/* 160 */ SwitchValueInterpolator b = new SwitchValueInterpolator(theAlpha, target);
/* 161 */ this.behaviors = b;
/* 162 */ BoundingSphere bounds = new BoundingSphere(new Point3d(0.0D, 0.0D, 0.0D), 1000000.0D);
/* */
/* 164 */ b.setSchedulingBounds(bounds);
/* 165 */ target.setCapability(18);
/* 166 */ target.addChild(this.behaviors);
/* */ }
/* */
/* */ void createJava3dObjects(int debugVals, int loadBehaviors)
/* */ throws IncorrectFormatException, FileNotFoundException
/* */ {
/* 180 */ if (this.fileName.indexOf("000") != -1) {
/* 181 */ int index = this.fileName.indexOf("000");
/* 182 */ String fileNameBase = this.fileName.substring(0, index);
/* 183 */ Switch s = new Switch();
/* 184 */ s.setCapability(17);
/* 185 */ s.setCapability(18);
/* 186 */ String tempFileName = this.fileName;
/* 187 */ int fileNum = 0;
/* 188 */ while (new File(tempFileName).exists()) {
/* 189 */ if (storedRefList.get(tempFileName) != null)
/* */ {
/* 192 */ SharedGroup storedGroup = (SharedGroup)storedRefList.get(tempFileName);
/* */
/* 194 */ Link newLink = new Link(storedGroup);
/* 195 */ s.addChild(newLink);
/* */ }
/* */ else
/* */ {
/* 199 */ J3dLwoParser objParser = new J3dLwoParser(tempFileName, debugVals);
/* */
/* 201 */ objParser.createJava3dGeometry();
/* 202 */ TransformGroup t = new TransformGroup();
/* 203 */ SharedGroup newSharedGroup = new SharedGroup();
/* 204 */ storedRefList.put(tempFileName, newSharedGroup);
/* 205 */ newSharedGroup.addChild(t);
/* 206 */ Link newLink = new Link(newSharedGroup);
/* 207 */ s.addChild(newLink);
/* 208 */ if (objParser.getJava3dShapeList() != null) {
/* 209 */ Enumeration e = objParser.getJava3dShapeList().elements();
/* */
/* 211 */ while (e.hasMoreElements()) {
/* 212 */ t.addChild((Shape3D)e.nextElement());
/* */ }
/* */ }
/* */ }
/* 216 */ fileNum++;
/* 217 */ String fileNumString = String.valueOf(fileNum);
/* 218 */ if (fileNum < 10)
/* 219 */ fileNumString = "00" + fileNumString;
/* 220 */ else if (fileNum < 100)
/* 221 */ fileNumString = "0" + fileNumString;
/* 222 */ tempFileName = fileNameBase + fileNumString + ".lwo";
/* */ }
/* 224 */ this.behaviors = null;
/* 225 */ if (loadBehaviors != 0) {
/* 226 */ createSwitchBehavior(s);
/* */ }
/* 228 */ this.geometryGroup = s;
/* */ }
/* */ else {
/* 231 */ this.geometryGroup = new Group();
/* 232 */ if (storedRefList.get(this.fileName) != null)
/* */ {
/* 234 */ SharedGroup storedGroup = (SharedGroup)storedRefList.get(this.fileName);
/* */
/* 236 */ Link newLink = new Link(storedGroup);
/* 237 */ this.geometryGroup.addChild(newLink);
/* */ }
/* */ else
/* */ {
/* 241 */ J3dLwoParser objParser = new J3dLwoParser(this.fileName, debugVals);
/* */
/* 243 */ objParser.createJava3dGeometry();
/* 244 */ TransformGroup t = new TransformGroup();
/* 245 */ if (objParser.getJava3dShapeList() != null) {
/* 246 */ Enumeration e = objParser.getJava3dShapeList().elements();
/* 247 */ while (e.hasMoreElements()) {
/* 248 */ t.addChild((Shape3D)e.nextElement());
/* */ }
/* */ }
/* 251 */ SharedGroup newSharedGroup = new SharedGroup();
/* 252 */ newSharedGroup.addChild(t);
/* 253 */ Link newLink = new Link(newSharedGroup);
/* 254 */ this.geometryGroup.addChild(newLink);
/* 255 */ storedRefList.put(this.fileName, newSharedGroup);
/* */ }
/* */ }
/* */ }
/* */
/* */ Group getGeometry() {
/* 261 */ return this.geometryGroup;
/* */ }
/* */
/* */ Behavior getBehavior() {
/* 265 */ return this.behaviors;
/* */ }
/* */ }
/* Location: Z:\System\Library\Java\Extensions\j3dutils.jar
* Qualified Name: com.sun.j3d.loaders.lw3d.SequenceLine
* JD-Core Version: 0.6.2
*/