Package com.sun.j3d.loaders.lw3d

Source Code of com.sun.j3d.loaders.lw3d.LwoSurface

/*     */ package com.sun.j3d.loaders.lw3d;
/*     */
/*     */ import com.sun.j3d.internal.J3dUtilsI18N;
/*     */ import com.sun.j3d.loaders.IncorrectFormatException;
/*     */ import com.sun.j3d.loaders.ParsingErrorException;
/*     */ import java.awt.Image;
/*     */ import java.io.FileNotFoundException;
/*     */ import java.io.IOException;
/*     */ import java.util.Vector;
/*     */ import javax.vecmath.Color3f;
/*     */ import javax.vecmath.Vector3f;
/*     */
/*     */ class LwoSurface extends ParserObject
/*     */ {
/*     */   LWOBFileReader theReader;
/*  67 */   int red = 255; int green = 255; int blue = 255;
/*  68 */   float diffuse = 0.0F; float specular = 0.0F; float transparency = 0.0F; float luminosity = 0.0F;
/*  69 */   float creaseAngle = 0.0F;
/*  70 */   int gloss = 128;
/*     */   Color3f color;
/*     */   Color3f diffuseColor;
/*     */   Color3f specularColor;
/*     */   Color3f emissiveColor;
/*     */   float shininess;
/*  73 */   Image theImage = null;
/*  74 */   Vector3f textureCenter = null; Vector3f textureSize = null;
/*     */   int textureAxis;
/*     */   String surfName;
/*  77 */   Vector textureList = new Vector();
/*     */
/*     */   LwoSurface(LWOBFileReader reader, int length, int debugVals)
/*     */     throws FileNotFoundException
/*     */   {
/*  86 */     super(debugVals);
/*  87 */     debugOutputLn(1, "LwoSurface()");
/*  88 */     this.theReader = reader;
/*  89 */     getSurf(length);
/*  90 */     setJ3dColors();
/*     */   }
/*     */
/*     */   void setJ3dColors()
/*     */   {
/*  97 */     this.color = new Color3f(this.red / 255.0F, this.green / 255.0F, this.blue / 255.0F);
/*     */
/* 100 */     this.diffuseColor = new Color3f(this.diffuse * this.color.x, this.diffuse * this.color.y, this.diffuse * this.color.z);
/*     */
/* 103 */     this.specularColor = new Color3f(this.specular * this.color.x, this.specular * this.color.y, this.specular * this.color.z);
/*     */
/* 106 */     this.emissiveColor = new Color3f(this.luminosity * this.color.x, this.luminosity * this.color.y, this.luminosity * this.color.z);
/*     */
/* 109 */     this.shininess = ((float)(128.0D * (this.gloss / 1024.0D)));
/*     */   }
/*     */
/*     */   Color3f getColor() {
/* 113 */     return this.color;
/*     */   }
/*     */
/*     */   Color3f getDiffuseColor() {
/* 117 */     return this.diffuseColor;
/*     */   }
/*     */
/*     */   Color3f getSpecularColor() {
/* 121 */     return this.specularColor;
/*     */   }
/*     */
/*     */   Color3f getEmissiveColor() {
/* 125 */     return this.emissiveColor;
/*     */   }
/*     */
/*     */   float getShininess() {
/* 129 */     return this.shininess;
/*     */   }
/*     */
/*     */   float getCreaseAngle() {
/* 133 */     return this.creaseAngle;
/*     */   }
/*     */
/*     */   LwoTexture getTexture()
/*     */   {
/* 143 */     debugOutputLn(1, "getTexture()");
/*     */     try {
/* 145 */       if (this.textureList.isEmpty()) {
/* 146 */         return null;
/*     */       }
/*     */
/* 149 */       return (LwoTexture)this.textureList.elementAt(0);
/*     */     }
/*     */     catch (ArrayIndexOutOfBoundsException e)
/*     */     {
/* 153 */       debugOutputLn(16, "getTexture(), exception returning first element: " + e);
/*     */     }
/* 155 */     return null;
/*     */   }
/*     */
/*     */   String getSurfName()
/*     */   {
/* 160 */     return this.surfName;
/*     */   }
/*     */
/*     */   float getTransparency() {
/* 164 */     return this.transparency;
/*     */   }
/*     */
/*     */   void getSurf(int length)
/*     */     throws FileNotFoundException, IncorrectFormatException, ParsingErrorException
/*     */   {
/* 174 */     debugOutputLn(1, "getSurf()");
/*     */
/* 179 */     boolean gotLuminosityFloat = false;
/* 180 */     boolean gotTransparencyFloat = false;
/* 181 */     boolean gotDiffuseFloat = false;
/* 182 */     boolean gotSpecularFloat = false;
/* 183 */     int surfStopMarker = this.theReader.getMarker() + length;
/* 184 */     this.surfName = this.theReader.getString();
/* 185 */     String tokenString = this.theReader.getToken();
/*     */
/* 187 */     while ((tokenString != null) && (this.theReader.getMarker() < surfStopMarker)) {
/* 188 */       debugOutputLn(2, "  tokenString = " + tokenString);
/* 189 */       debugOutputLn(2, "  marker, stop = " + this.theReader.getMarker() + ", " + surfStopMarker);
/*     */
/* 191 */       String textureToken = null;
/* 192 */       int fieldLength = this.theReader.getShortInt();
/* 193 */       debugOutputLn(2, "  fl = " + fieldLength);
/*     */
/* 195 */       if (tokenString.equals("COLR")) {
/* 196 */         debugOutputLn(8, "  COLR");
/*     */         try {
/* 198 */           this.red = this.theReader.read();
/* 199 */           this.green = this.theReader.read();
/* 200 */           this.blue = this.theReader.read();
/* 201 */           this.theReader.read();
/*     */         }
/*     */         catch (IOException e) {
/* 204 */           throw new ParsingErrorException(e.getMessage());
/*     */         }
/* 206 */         if (fieldLength != 4) {
/* 207 */           throw new IncorrectFormatException(J3dUtilsI18N.getString("LwoSurface0"));
/*     */         }
/*     */       }
/* 210 */       else if (tokenString.equals("FLAG")) {
/* 211 */         debugOutputLn(8, "  FLAG");
/* 212 */         this.theReader.skipLength(fieldLength);
/*     */       }
/* 214 */       else if (tokenString.equals("VLUM")) {
/* 215 */         debugOutputLn(8, "  VLUM");
/* 216 */         this.luminosity = this.theReader.getFloat();
/* 217 */         gotLuminosityFloat = true;
/*     */       }
/* 219 */       else if (tokenString.equals("LUMI")) {
/* 220 */         debugOutputLn(8, "  LUMI");
/* 221 */         if (gotLuminosityFloat)
/* 222 */           this.theReader.skipLength(fieldLength);
/*     */         else
/* 224 */           this.luminosity = (this.theReader.getShortInt() / 255.0F);
/*     */       }
/* 226 */       else if (tokenString.equals("VDIF")) {
/* 227 */         debugOutputLn(8, "  VDIF");
/* 228 */         if (fieldLength != 4)
/* 229 */           throw new IncorrectFormatException("VDIF problem");
/* 230 */         this.diffuse = this.theReader.getFloat();
/* 231 */         gotDiffuseFloat = true;
/* 232 */         debugOutputLn(2, "diff = " + this.diffuse);
/*     */       }
/* 234 */       else if (tokenString.equals("DIFF")) {
/* 235 */         debugOutputLn(8, "  DIFF");
/* 236 */         if (gotDiffuseFloat)
/* 237 */           this.theReader.skipLength(fieldLength);
/*     */         else
/* 239 */           this.diffuse = (this.theReader.getShortInt() / 255.0F);
/*     */       }
/* 241 */       else if (tokenString.equals("VTRN")) {
/* 242 */         debugOutputLn(8, "  VTRN");
/* 243 */         this.transparency = this.theReader.getFloat();
/* 244 */         gotTransparencyFloat = true;
/*     */       }
/* 246 */       else if (tokenString.equals("TRAN")) {
/* 247 */         debugOutputLn(8, "  TRAN");
/* 248 */         if (gotTransparencyFloat)
/* 249 */           this.theReader.skipLength(fieldLength);
/*     */         else
/* 251 */           this.transparency = (this.theReader.getShortInt() / 255.0F);
/*     */       }
/* 253 */       else if (tokenString.equals("VSPC")) {
/* 254 */         debugOutputLn(8, "  VSPC");
/* 255 */         this.specular = this.theReader.getFloat();
/* 256 */         gotSpecularFloat = true;
/* 257 */         debugOutputLn(2, "spec = " + this.specular);
/*     */       }
/* 259 */       else if (tokenString.equals("SPEC")) {
/* 260 */         debugOutputLn(8, "  SPEC");
/* 261 */         if (gotSpecularFloat) {
/* 262 */           this.theReader.skipLength(fieldLength);
/*     */         }
/* 264 */         else if (fieldLength == 4)
/* 265 */           this.specular = (this.theReader.getInt() / 255.0F);
/*     */         else {
/* 267 */           this.specular = (this.theReader.getShortInt() / 255.0F);
/*     */         }
/*     */       }
/* 270 */       else if (tokenString.equals("GLOS")) {
/* 271 */         debugOutputLn(8, "  GLOS");
/* 272 */         if (fieldLength == 4)
/* 273 */           this.gloss = this.theReader.getInt();
/*     */         else
/* 275 */           this.gloss = this.theReader.getShortInt();
/*     */       }
/* 277 */       else if (tokenString.equals("SMAN")) {
/* 278 */         debugOutputLn(8, "  SMAN");
/* 279 */         this.creaseAngle = this.theReader.getFloat();
/*     */       }
/* 281 */       else if (tokenString.endsWith("TEX"))
/*     */       {
/* 284 */         LwoTexture texture = new LwoTexture(this.theReader, surfStopMarker - this.theReader.getMarker(), tokenString, this.debugPrinter.getValidOutput());
/*     */
/* 289 */         textureToken = texture.getNextToken();
/* 290 */         if (texture.isHandled())
/* 291 */           this.textureList.addElement(texture);
/* 292 */         debugOutputLn(64, "val = " + tokenString);
/*     */       }
/*     */       else {
/* 295 */         debugOutputLn(64, "unrecognized token: " + tokenString);
/*     */
/* 297 */         this.theReader.skipLength(fieldLength);
/*     */       }
/* 299 */       if (this.theReader.getMarker() < surfStopMarker)
/* 300 */         if (textureToken == null)
/* 301 */           tokenString = this.theReader.getToken();
/*     */         else
/* 303 */           tokenString = textureToken;
/*     */     }
/*     */   }
/*     */ }

/* Location:           Z:\System\Library\Java\Extensions\j3dutils.jar
* Qualified Name:     com.sun.j3d.loaders.lw3d.LwoSurface
* JD-Core Version:    0.6.2
*/
TOP

Related Classes of com.sun.j3d.loaders.lw3d.LwoSurface

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.