📄 lwsobject.java
字号:
if (new File(pathname + filename.toLowerCase()).exists()) { return (pathname + filename.toLowerCase()); } // Finally, let's check the local directory if (new File(filename).exists()) { return (filename); } // Try lowercase filename if (new File(filename.toLowerCase()).exists()) { return (filename.toLowerCase()); } // Conditions that determine when we give up on the recursive search if ((pathname.equals(File.separator)) || (pathname == null) || (pathname.equals(""))) { throw new java.io.FileNotFoundException(filename); } // Try to find the file in the upper directories // Chop off the last directory from pathname and recurse StringBuffer newPathName = new StringBuffer(128); StringTokenizer st = new StringTokenizer(pathname, File.separator); int tokenCount = st.countTokens() - 1; if (pathname.startsWith(java.io.File.separator)) newPathName.append(File.separator); for (int i = 0; i < tokenCount; ++i) { String directory = st.nextToken(); newPathName.append(directory); newPathName.append(File.separator); } String newPath = newPathName.toString(); return getQualifiedFilename(newPath, filename); } URL getQualifiedURL(String path, String file) throws MalformedURLException { URL url = null; // try the path and the file -- this is the lightwave spec try { // create url url = new URL(path + file); // see if file exists url.getContent(); // return url if no exception is thrown return url; } catch (IOException e) { // Ignore - try something different } // try a couple other options, but trying to open connections is slow, // so don't try as many options as getQualifiedFilename // try absolute path try { url = new URL(file); url.getContent(); } catch (IOException ex) { // Ignore - try something different } // try the absolute path with the protocol try { url = new URL(protocol + ":" + file); url.getContent(); return url; } catch (IOException ex) { // Nothing else to try so give up throw new MalformedURLException(path + file); } } /** * Returns parent object */ int getParent() { return parent; } /** * Adds the given child to the transform of this node (its parent). */ void addChild(LwsPrimitive child) { debugOutputLn(TRACE, "addChild()"); if (objectTransform != null) { debugOutputLn(LINE_TRACE, "objectTransform = " + objectTransform); if (child.getObjectNode() != null) { debugOutputLn(LINE_TRACE, "child has object node"); if (hasPivot) pivotTransGroup.addChild(child.getObjectNode()); else objectTransform.addChild(child.getObjectNode()); }/* if (child.getObjectBehaviors() != null) { debugOutputLn(LINE_TRACE, "child has behaviors"); Group bg = child.getObjectBehaviors(); debugOutputLn(VALUES, " child behaviors = " + bg); // TODO: should remove intermediate group nodes objectBehavior.addChild(bg); }*/ } } /** * Creates Java3d objects from the data stored for this object. * The objects created consist of: A TransformGroup that holds the * transform specified by the first keyframe, a Behavior that acts * on the TransformGroup if there are more than 1 keyframes, and * some geometry (created by J3dLwoParser) from an external geometry * file (if the object wasn't an lw3d Null object (group)). */ void createJava3dObject(LwsObject cloneObject, int loadBehaviors) throws IncorrectFormatException, ParsingErrorException, FileNotFoundException { String seqToken = new String("_sequence_"); Matrix4d mat = new Matrix4d(); mat.setIdentity(); // Set the node's transform matrix according to the first frame // of the object's motion LwsFrame firstFrame = motion.getFirstFrame(); firstFrame.setMatrix(mat); Transform3D t1 = new Transform3D(); t1.set(mat); objectTransform = new TransformGroup(t1); objectTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); // This following bit is a hack and should probably be removed. // It was put in here in order to handle the "Tloop" functionality // of holosketch, which was needed for the 1998 Javaone conference // (the HighNoon demo, in particular). Having the code here, or // using it, means that some object file names are tagged as special // because they contain the phrase "_sequence_", which tells this // object file reader that that object file is, in fact, a // sequence file. It then creates a SequenceReader object to // read that file and create an animation from the objects defined // in that file. // See SequenceReader.java for more information on this. // By the way, a better/fuller implementation of this functionality // would involve investigating a standard Plug-In for Lightwave // that allows the writing out of sequence files from Bones data. // i think it would be better to base any Tloop stuff on that // standard than on some proprietary hack of our own. if (fileName != null && fileName.indexOf(seqToken) != -1) { // Tloop int index = fileName.indexOf(seqToken); index += seqToken.length(); String seqFilename = fileName.substring(index); int endIndex = seqFilename.indexOf(".lwo"); if (endIndex != -1) seqFilename = seqFilename.substring(0, endIndex); if ((new File(seqFilename)).exists()) { SequenceReader sr = new SequenceReader(seqFilename, motion.totalTime, (int)motion.totalFrames); sr.printLines(); sr.createJava3dObjects(debugPrinter.getValidOutput(), loadBehaviors); Group g = sr.getObjectNode(); if (g != null) objectTransform.addChild(g); // Sequence reader's getObjectBehaviors creates new Vector objectBehavior = sr.getObjectBehaviors(); return; } } // Okay, now that that hack is out of the way, let's get on with // "normal" Lightwave object files. if (fileName != null || urlName != null) { // If this object refers to an obj file, load it and create // geometry from it. if (cloneObject == null) { debugOutputLn(VALUES, "About to load binary file for " + fileName); // Create a J3dLwoParser object to parse the geometry file // and create the appropriate geometry J3dLwoParser objParser = null; switch (fileType) { case Lw3dLoader.FILE_TYPE_FILENAME: objParser = new J3dLwoParser(fileName, debugPrinter.getValidOutput()); break; case Lw3dLoader.FILE_TYPE_URL: objParser = new J3dLwoParser(urlName, debugPrinter.getValidOutput()); break; } objParser.createJava3dGeometry(); // pivot points change the parent transform if (hasPivot) { objectTransform.addChild(pivotTransGroup); } if (objParser.getJava3dShapeList() != null) { shapeList = objParser.getJava3dShapeList(); for (Enumeration e = shapeList.elements() ; e.hasMoreElements() ;) { if (!hasPivot || pivotTransGroup == null) objectTransform.addChild((Shape3D)e.nextElement()); else pivotTransGroup.addChild((Shape3D)e.nextElement()); } } } else { // Already read that file: Clone original object debugOutputLn(LINE_TRACE, "Cloning shapes"); Vector cloneShapeList = cloneObject.getShapeList(); for (Enumeration e = cloneShapeList.elements() ; e.hasMoreElements() ;) { debugOutputLn(LINE_TRACE, " shape clone"); Shape3D shape = (Shape3D)e.nextElement(); Shape3D cloneShape = (Shape3D)shape.cloneTree(); objectTransform.addChild(cloneShape); } } } // Create j3d behaviors for the object's animation objectBehavior = new Vector(); if (loadBehaviors != 0) { motion.createJava3dBehaviors(objectTransform); Behavior b = motion.getBehaviors(); if (b != null) objectBehavior.addElement(b); } } /** * Return list of Shape3D objects for this object file. This is used * when cloning objects (if the scene file requests the same object file * more than once, that object will be cloned instead of recreated each * time). */ Vector getShapeList() { return shapeList; } /** * Return the TransformGroup that holds this object file */ public TransformGroup getObjectNode() { return objectTransform; } /** * Return the Group that holds this object's behaviors. The behaviors * are grouped separately from the geometry so that they can be handled * differently by the parent application. */ public Vector getObjectBehaviors() { debugOutputLn(TRACE, "getObjectBehaviors()"); return objectBehavior; } /** * Utiliy function to print some of the object values. Used in * debugging. */ void printVals() { debugOutputLn(VALUES, " OBJECT vals: "); debugOutputLn(VALUES, " fileName = " + fileName); debugOutputLn(VALUES, " objName = " + objName); motion.printVals(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -