📄 lw3dloader.java
字号:
sb.append('/'); sb.append('/'); } else { sb.append(a); // urls use / on windows also// sb.append( java.io.File.separator ); sb.append('/'); } } internalBaseUrl = sb.toString();// System.out.println("internalBaseUrl = " + internalBaseUrl); } /** * Standardizes the filename for use in the loader */ void setInternalBasePath(String fileName) { java.util.StringTokenizer stok = new java.util.StringTokenizer(fileName, java.io.File.separator); int tocount = stok.countTokens()-1; StringBuffer sb = new StringBuffer(80); if (fileName!= null && fileName.startsWith(java.io.File.separator)) sb.append(java.io.File.separator); for(int ji = 0; ji < tocount ; ji++) { String a = stok.nextToken(); sb.append(a); sb.append( java.io.File.separator ); } internalBasePath = sb.toString(); } String getInternalBasePath() { return internalBasePath; } String getInternalBaseUrl() { return internalBaseUrl; } int getFileType() { return fileType; } /** * This method parents all objects in the scene appropriately. If * the scen file specifies a Parent node for the object, then the * object is parented to that node. If not, then the object is * parented to the scene's root. */ void parentObjects() { debugOutputLn(TRACE, "parentObjects()"); for (Enumeration e = objectList.elements(); e.hasMoreElements(); ) { LwsObject obj = (LwsObject)e.nextElement(); if (obj.getParent() != -1) { LwsObject parent = (LwsObject) objectList.elementAt(obj.getParent() - 1); parent.addChild(obj); debugOutputLn(VALUES, "added child successfully"); } else { if (obj.getObjectNode() != null) sceneGroupNode.addChild(obj.getObjectNode()); } // Collect all behaviors if (loadBehaviors != 0) { if (!(obj.getObjectBehaviors()).isEmpty()) { sceneBehaviors.addAll(obj.getObjectBehaviors()); } } } debugOutputLn(LINE_TRACE, "Done with parentObjects()"); } /** * This method sets the base URL name for data files * associated with the file passed into the load(URL) method. * The basePath should be null by default, which is an * indicator to the loader that it should look for any * associated files starting from the same directory as the * file passed into the load(URL) method. */ public void setBaseUrl(URL url) { baseUrl = url; } /** * This method sets the base path to be used when searching for all * data files within a Lightwave scene. */ public void setBasePath(String pathName) { // This routine standardizes path names so that all pathnames // will have standard file separators, they'll end in a separator // character, and if the user passes in null or "" (meaning to // set the current directory as the base path), this will become // "./" (or ".\") basePath = pathName; if (basePath == null || basePath == "") basePath = "." + java.io.File.separator; basePath = basePath.replace('/', java.io.File.separatorChar); basePath = basePath.replace('\\', java.io.File.separatorChar); if (!basePath.endsWith(java.io.File.separator)) basePath = basePath + java.io.File.separator; } /** * Returns the current base URL setting. */ public URL getBaseUrl() { return baseUrl; } /** * Returns the current base path setting. */ public String getBasePath() { return basePath; } /** * This method sets the load flags for the file. The flags should * equal 0 by default (which tells the loader to only load geometry). */ public void setFlags(int flags) { loadFlags = flags; } /** * Returns the current loading flags setting. */ public int getFlags() { return loadFlags; } /** * getObject() iterates through the objectList checking the given * name against the fileName and objectName of each object in turn. * For the filename, it carves off the pathname and just checks the * final name (e.g., "missile.lwo"). * If name has []'s at the end, it will use the number inside those * brackets to pick which object out of an ordered set it will * send back (objectList is created in the order that objects * exist in the file, so this order should correspond to the order * specified by the user). If no []'s exist, just pass back the * first one encountered that matches. */ public TransformGroup getObject(String name) { debugOutputLn(TRACE, "getObject()"); int indexNumber = -1; int currentObjectCount = 0; String subobjectName = name; if (name.indexOf("[") != -1) { // caller wants specifically numbered subjbect; get that number int bracketsIndex = name.indexOf("["); subobjectName = name.substring(0, bracketsIndex); String bracketsString = name.substring(bracketsIndex); int bracketEndIndex = bracketsString.indexOf("]"); String indexString = bracketsString.substring(1, bracketEndIndex); indexNumber = (new Integer(indexString)).intValue(); } for (Enumeration e = objectList.elements() ; e.hasMoreElements() ;) { LwsObject tempObj = (LwsObject)e.nextElement(); debugOutputLn(VALUES, "tempObj, file, objname = " + tempObj + tempObj.fileName + tempObj.objName); if ((tempObj.fileName != null && tempObj.fileName.indexOf(subobjectName) != -1) || (tempObj.objName != null && tempObj.objName.indexOf(subobjectName) != -1)) { if (indexNumber < 0 || indexNumber == currentObjectCount) return tempObj.getObjectNode(); else currentObjectCount++; } } debugOutputLn(VALUES, " no luck - wanted " + name + " returning null"); return null; } /** * This method sets up the StreamTokenizer for the scene file. Note * that we're not parsing numbers as numbers because the tokenizer * does not interpret scientific notation correctly. */ void setupTokenizer(StreamTokenizer tokenizer) { tokenizer.resetSyntax(); tokenizer.wordChars('a', 'z'); tokenizer.wordChars('A', 'Z'); tokenizer.wordChars(128 + 32, 255); tokenizer.whitespaceChars(0, ' '); tokenizer.commentChar('/'); tokenizer.quoteChar('"'); tokenizer.quoteChar('\''); tokenizer.wordChars('0', '9'); tokenizer.wordChars('.', '.'); tokenizer.wordChars('-', '-'); tokenizer.wordChars('/', '/'); tokenizer.wordChars('\\', '\\'); tokenizer.wordChars('_', '_'); tokenizer.wordChars('&', '&'); tokenizer.ordinaryChar('('); tokenizer.ordinaryChar(')'); tokenizer.whitespaceChars('\r', '\r'); // add ':' as wordchar so urls will work tokenizer.wordChars(':', ':'); // add '~' as wordchar for urls tokenizer.wordChars('~', '~'); } /** * Adds Ambient lighting effects to the scene */ void addAmbient() { AmbientLight aLgt = new AmbientLight(ambientColor); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100000.0); aLgt.setInfluencingBounds(bounds); sceneGroupNode.addChild(aLgt); // scope ambient light to the lw3d scene aLgt.addScope(sceneGroupNode); scene.addLightNode(aLgt); } /** * Add any defined lights to the java3d scene */ void addLights() { // Add lights to the scene for (Enumeration e1 = lightList.elements(); e1.hasMoreElements(); ) { debugOutputLn(LINE_TRACE, "adding light to scene group"); LwsLight light = (LwsLight)e1.nextElement(); if (light.getObjectNode() != null) { // scope light to the lw3d scene light.getLight().addScope(sceneGroupNode); if (light.getParent() != -1) { LwsObject parent = (LwsObject) objectList.elementAt(light.getParent() - 1); parent.addChild(light); } else { // No parent - add to scene group sceneGroupNode.addChild(light.getObjectNode()); } // collect behaviors if LOAD_BEHAVIOR_NODES is set if (loadBehaviors != 0) { if (!(light.getObjectBehaviors()).isEmpty()) sceneBehaviors.addAll(light.getObjectBehaviors()); } scene.addLightNode(light.getLight()); } else debugOutputLn(LINE_TRACE, "light object null?"); } } /** * Adds the Camera's transform group to the scene, either by parenting * it to the appropriate object or by adding it to the scene root. * To use this camera data, users can request the camera/view data * for the scene and can then insert a ViewPlatform in the transform group. */ void addCamera() { // Add camera effects to scene. if (camera != null) { if (camera.getParent() != -1) { debugOutputLn(VALUES, "camera parent = " + camera.getParent()); LwsObject parent = (LwsObject) objectList.elementAt(camera.getParent() - 1); parent.addChild(camera); debugOutputLn(VALUES, "added child successfully"); } else { sceneGroupNode.addChild(camera.getObjectNode()); } // collect behaviors if LOAD_BEHAVIOR_NODES is set if (loadBehaviors != 0) { if (!(camera.getObjectBehaviors()).isEmpty()) sceneBehaviors.addAll(camera.getObjectBehaviors()); } scene.addViewGroup(camera.getObjectNode()); } } /** * Add appropriate fog effects to the scene */ void addFog() { if (fog != null) { Fog fogNode = fog.getObjectNode(); if (fogNode != null) { sceneGroupNode.addChild(fogNode); scene.addFogNode(fogNode); } } } /** * Add the behaviors to the scene */ void addBehaviors() { if (!sceneBehaviors.isEmpty()) { Enumeration e = sceneBehaviors.elements(); while (e.hasMoreElements()) { scene.addBehaviorNode((Behavior)e.nextElement()); } } } /** * Add appropriate background effects to the scene. Note that the java3d * background may not have all of the information of the lw3d background, * as the loader does not currently process items such as gradients between * the horizon and sky colors */ void addBackground() { if (background != null) { Background bgNode = background.getObjectNode(); if (bgNode != null) { sceneGroupNode.addChild(bgNode); scene.addBackgroundNode(bgNode); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -