/* */ 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.net.MalformedURLException;
/* */ import java.net.URL;
/* */ import java.util.Enumeration;
/* */ import java.util.StringTokenizer;
/* */ import java.util.Vector;
/* */ import javax.media.j3d.Behavior;
/* */ import javax.media.j3d.Group;
/* */ import javax.media.j3d.Shape3D;
/* */ import javax.media.j3d.Transform3D;
/* */ import javax.media.j3d.TransformGroup;
/* */ import javax.vecmath.Matrix4d;
/* */ import javax.vecmath.Vector3f;
/* */
/* */ class LwsObject extends TextfileParser
/* */ implements LwsPrimitive
/* */ {
/* */ String fileName;
/* */ String objName;
/* */ LwsMotion motion;
/* */ int parent;
/* */ TransformGroup objectTransform;
/* */ Vector objectBehavior;
/* 79 */ Vector shapeList = null;
/* 80 */ boolean hasPivot = false;
/* 81 */ TransformGroup pivotTransGroup = null;
/* */ URL urlName;
/* */ String protocol;
/* */ int fileType;
/* */
/* */ LwsObject(StreamTokenizer st, boolean loadObject, int firstFrame, int totalFrames, float totalTime, Lw3dLoader loader, int debugVals)
/* */ throws FileNotFoundException, ParsingErrorException
/* */ {
/* 104 */ this.debugPrinter.setValidOutput(debugVals);
/* 105 */ this.parent = -1;
/* */
/* 107 */ this.fileType = loader.getFileType();
/* */ try
/* */ {
/* 110 */ if (loadObject)
/* */ {
/* 113 */ this.fileName = getString(st);
/* 114 */ String path = null;
/* 115 */ switch (loader.getFileType())
/* */ {
/* */ case 2:
/* 118 */ path = loader.getBasePath();
/* 119 */ if (path == null)
/* 120 */ path = loader.getInternalBasePath();
/* 121 */ if (path != null)
/* */ {
/* 141 */ this.fileName = getQualifiedFilename(path, this.fileName); } break;
/* */ case 1:
/* 145 */ path = "";
/* 146 */ URL pathUrl = loader.getBaseUrl();
/* 147 */ if (pathUrl != null) {
/* 148 */ path = pathUrl.toString();
/* */
/* 150 */ this.protocol = pathUrl.getProtocol();
/* */ }
/* */ else {
/* 153 */ path = loader.getInternalBaseUrl();
/* */
/* 155 */ this.protocol = new URL(path).getProtocol();
/* */ }
/* */
/* 158 */ this.urlName = getQualifiedURL(path, this.fileName);
/* */ }
/* */
/* */ }
/* */ else
/* */ {
/* 165 */ this.objName = getString(st);
/* 166 */ }skip(st, "ShowObject", 2);
/* 167 */ debugOutputLn(8, "skipped showobject, about to get objectmotion");
/* */
/* 169 */ getAndCheckString(st, "ObjectMotion");
/* 170 */ debugOutputLn(8, "got string " + st.sval);
/* */
/* 172 */ this.motion = new LwsMotion(st, firstFrame, totalFrames, totalTime, debugVals);
/* */
/* 174 */ debugOutputLn(8, "got motion");
/* 175 */ boolean hasParent = false;
/* */
/* 180 */ while (!isCurrentToken(st, "ShadowOptions"))
/* */ {
/* */ EnvelopeHandler env;
/* 181 */ if ((!hasParent) && (isCurrentToken(st, "ParentObject")))
/* */ {
/* 183 */ this.parent = ((int)getNumber(st));
/* 184 */ hasParent = true;
/* */ }
/* 186 */ else if (isCurrentToken(st, "PivotPoint"))
/* */ {
/* 191 */ this.hasPivot = true;
/* 192 */ float x = (float)getNumber(st);
/* 193 */ float y = (float)getNumber(st);
/* 194 */ float z = (float)getNumber(st);
/* 195 */ Vector3f pivotPoint = new Vector3f(-x, -y, z);
/* 196 */ Transform3D pivotTransform = new Transform3D();
/* 197 */ pivotTransform.set(pivotPoint);
/* 198 */ this.pivotTransGroup = new TransformGroup(pivotTransform);
/* 199 */ this.pivotTransGroup.setCapability(18);
/* */ }
/* 202 */ else if (isCurrentToken(st, "ObjDissolve"))
/* */ {
/* 204 */ env = new EnvelopeHandler(st, totalFrames, totalTime);
/* */ }
/* */
/* 207 */ st.nextToken();
/* */ }
/* 209 */ getNumber(st);
/* 210 */ debugOutputLn(8, "done with LwsObject constructor");
/* */ }
/* */ catch (MalformedURLException e) {
/* 213 */ throw new FileNotFoundException(e.getMessage());
/* */ }
/* */ catch (IOException e) {
/* 216 */ throw new ParsingErrorException(e.getMessage());
/* */ }
/* */ catch (NumberFormatException e) {
/* 219 */ throw new ParsingErrorException("Expected a number, got " + e.getMessage());
/* */ }
/* */ }
/* */
/* */ String getQualifiedFilename(String pathname, String filename)
/* */ throws FileNotFoundException
/* */ {
/* 245 */ String pathname2 = "";
/* */
/* 250 */ if (filename.indexOf(File.separator) == 0)
/* */ {
/* */ int index;
/* 251 */ if ((index = filename.lastIndexOf(File.separator)) != -1) {
/* 252 */ pathname2 = filename.substring(0, index + 1);
/* 253 */ filename = filename.substring(index + 1);
/* */ }
/* */ else {
/* 256 */ return null;
/* */ }
/* */
/* */ }
/* */
/* */ try
/* */ {
/* 265 */ if (new File(pathname2 + filename).exists())
/* 266 */ return pathname2 + filename;
/* */ }
/* */ catch (NullPointerException ex)
/* */ {
/* 270 */ ex.printStackTrace();
/* */ }
/* */
/* 273 */ if (new File(pathname2 + filename.toLowerCase()).exists()) {
/* 274 */ return pathname2 + filename.toLowerCase();
/* */ }
/* */
/* 278 */ if (new File(pathname + filename).exists()) {
/* 279 */ return pathname + filename;
/* */ }
/* */
/* 282 */ if (new File(pathname + filename.toLowerCase()).exists()) {
/* 283 */ return pathname + filename.toLowerCase();
/* */ }
/* */
/* 287 */ if (new File(filename).exists()) {
/* 288 */ return filename;
/* */ }
/* */
/* 291 */ if (new File(filename.toLowerCase()).exists()) {
/* 292 */ return filename.toLowerCase();
/* */ }
/* */
/* 296 */ if ((pathname.equals(File.separator)) || (pathname == null) || (pathname.equals("")))
/* */ {
/* 300 */ throw new FileNotFoundException(filename);
/* */ }
/* */
/* 305 */ StringBuffer newPathName = new StringBuffer(128);
/* 306 */ StringTokenizer st = new StringTokenizer(pathname, File.separator);
/* 307 */ int tokenCount = st.countTokens() - 1;
/* 308 */ if (pathname.startsWith(File.separator))
/* 309 */ newPathName.append(File.separator);
/* 310 */ for (int i = 0; i < tokenCount; i++) {
/* 311 */ String directory = st.nextToken();
/* 312 */ newPathName.append(directory);
/* 313 */ newPathName.append(File.separator);
/* */ }
/* */
/* 316 */ String newPath = newPathName.toString();
/* 317 */ return getQualifiedFilename(newPath, filename);
/* */ }
/* */
/* */ URL getQualifiedURL(String path, String file)
/* */ throws MalformedURLException
/* */ {
/* 323 */ URL url = null;
/* */ try
/* */ {
/* 328 */ url = new URL(path + file);
/* */
/* 330 */ url.getContent();
/* */
/* 332 */ return url;
/* */ }
/* */ catch (IOException e)
/* */ {
/* */ try
/* */ {
/* 343 */ url = new URL(file);
/* 344 */ url.getContent();
/* */ }
/* */ catch (IOException ex)
/* */ {
/* */ }
/* */
/* */ try
/* */ {
/* 352 */ url = new URL(this.protocol + ":" + file);
/* 353 */ url.getContent();
/* 354 */ return url;
/* */ } catch (IOException ex) {
/* */ }
/* */ }
/* 358 */ throw new MalformedURLException(path + file);
/* */ }
/* */
/* */ int getParent()
/* */ {
/* 366 */ return this.parent;
/* */ }
/* */
/* */ void addChild(LwsPrimitive child)
/* */ {
/* 373 */ debugOutputLn(1, "addChild()");
/* 374 */ if (this.objectTransform != null) {
/* 375 */ debugOutputLn(8, "objectTransform = " + this.objectTransform);
/* 376 */ if (child.getObjectNode() != null) {
/* 377 */ debugOutputLn(8, "child has object node");
/* 378 */ if (this.hasPivot)
/* 379 */ this.pivotTransGroup.addChild(child.getObjectNode());
/* */ else
/* 381 */ this.objectTransform.addChild(child.getObjectNode());
/* */ }
/* */ }
/* */ }
/* */
/* */ void createJava3dObject(LwsObject cloneObject, int loadBehaviors)
/* */ throws IncorrectFormatException, ParsingErrorException, FileNotFoundException
/* */ {
/* 407 */ String seqToken = new String("_sequence_");
/* 408 */ Matrix4d mat = new Matrix4d();
/* 409 */ mat.setIdentity();
/* */
/* 412 */ LwsFrame firstFrame = this.motion.getFirstFrame();
/* 413 */ firstFrame.setMatrix(mat);
/* 414 */ Transform3D t1 = new Transform3D();
/* 415 */ t1.set(mat);
/* 416 */ this.objectTransform = new TransformGroup(t1);
/* 417 */ this.objectTransform.setCapability(18);
/* */
/* 436 */ if ((this.fileName != null) && (this.fileName.indexOf(seqToken) != -1))
/* */ {
/* 438 */ int index = this.fileName.indexOf(seqToken);
/* 439 */ index += seqToken.length();
/* 440 */ String seqFilename = this.fileName.substring(index);
/* 441 */ int endIndex = seqFilename.indexOf(".lwo");
/* 442 */ if (endIndex != -1)
/* 443 */ seqFilename = seqFilename.substring(0, endIndex);
/* 444 */ if (new File(seqFilename).exists()) {
/* 445 */ SequenceReader sr = new SequenceReader(seqFilename, this.motion.totalTime, this.motion.totalFrames);
/* */
/* 449 */ sr.printLines();
/* 450 */ sr.createJava3dObjects(this.debugPrinter.getValidOutput(), loadBehaviors);
/* */
/* 452 */ Group g = sr.getObjectNode();
/* 453 */ if (g != null) {
/* 454 */ this.objectTransform.addChild(g);
/* */ }
/* */
/* 457 */ this.objectBehavior = sr.getObjectBehaviors();
/* */
/* 459 */ return;
/* */ }
/* */
/* */ }
/* */
/* 465 */ if ((this.fileName != null) || (this.urlName != null))
/* */ {
/* 468 */ if (cloneObject == null) {
/* 469 */ debugOutputLn(2, "About to load binary file for " + this.fileName);
/* */
/* 473 */ J3dLwoParser objParser = null;
/* 474 */ switch (this.fileType) {
/* */ case 2:
/* 476 */ objParser = new J3dLwoParser(this.fileName, this.debugPrinter.getValidOutput());
/* */
/* 479 */ break;
/* */ case 1:
/* 481 */ objParser = new J3dLwoParser(this.urlName, this.debugPrinter.getValidOutput());
/* */ }
/* */
/* 485 */ objParser.createJava3dGeometry();
/* */
/* 487 */ if (this.hasPivot) {
/* 488 */ this.objectTransform.addChild(this.pivotTransGroup);
/* */ }
/* 490 */ if (objParser.getJava3dShapeList() != null) {
/* 491 */ this.shapeList = objParser.getJava3dShapeList();
/* 492 */ Enumeration e = this.shapeList.elements();
/* 493 */ while (e.hasMoreElements()) {
/* 494 */ if ((!this.hasPivot) || (this.pivotTransGroup == null))
/* 495 */ this.objectTransform.addChild((Shape3D)e.nextElement());
/* */ else
/* 497 */ this.pivotTransGroup.addChild((Shape3D)e.nextElement());
/* */ }
/* */ }
/* */ }
/* */ else
/* */ {
/* 503 */ debugOutputLn(8, "Cloning shapes");
/* 504 */ Vector cloneShapeList = cloneObject.getShapeList();
/* 505 */ Enumeration e = cloneShapeList.elements();
/* 506 */ while (e.hasMoreElements()) {
/* 507 */ debugOutputLn(8, " shape clone");
/* 508 */ Shape3D shape = (Shape3D)e.nextElement();
/* 509 */ Shape3D cloneShape = (Shape3D)shape.cloneTree();
/* 510 */ this.objectTransform.addChild(cloneShape);
/* */ }
/* */ }
/* */
/* */ }
/* */
/* 516 */ this.objectBehavior = new Vector();
/* 517 */ if (loadBehaviors != 0) {
/* 518 */ this.motion.createJava3dBehaviors(this.objectTransform);
/* 519 */ Behavior b = this.motion.getBehaviors();
/* 520 */ if (b != null)
/* 521 */ this.objectBehavior.addElement(b);
/* */ }
/* */ }
/* */
/* */ Vector getShapeList()
/* */ {
/* 532 */ return this.shapeList;
/* */ }
/* */
/* */ public TransformGroup getObjectNode()
/* */ {
/* 539 */ return this.objectTransform;
/* */ }
/* */
/* */ public Vector getObjectBehaviors()
/* */ {
/* 549 */ debugOutputLn(1, "getObjectBehaviors()");
/* 550 */ return this.objectBehavior;
/* */ }
/* */
/* */ void printVals()
/* */ {
/* 560 */ debugOutputLn(2, " OBJECT vals: ");
/* 561 */ debugOutputLn(2, " fileName = " + this.fileName);
/* 562 */ debugOutputLn(2, " objName = " + this.objName);
/* 563 */ this.motion.printVals();
/* */ }
/* */ }
/* Location: Z:\System\Library\Java\Extensions\j3dutils.jar
* Qualified Name: com.sun.j3d.loaders.lw3d.LwsObject
* JD-Core Version: 0.6.2
*/