Package com.sun.j3d.loaders.lw3d

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

/*     */ package com.sun.j3d.loaders.lw3d;
/*     */
/*     */ import com.sun.j3d.loaders.ParsingErrorException;
/*     */ import com.sun.j3d.utils.image.TextureLoader;
/*     */ import java.awt.Image;
/*     */ import java.awt.image.BufferedImage;
/*     */ import java.io.FileNotFoundException;
/*     */ import java.io.IOException;
/*     */ import java.util.Hashtable;
/*     */ import javax.media.j3d.Texture;
/*     */ import javax.media.j3d.Texture2D;
/*     */ import javax.vecmath.Color3f;
/*     */ import javax.vecmath.Vector3f;
/*     */
/*     */ class LwoTexture extends ParserObject
/*     */ {
/*     */   LWOBFileReader theReader;
/*  80 */   int red = 255; int green = 255; int blue = 255;
/*     */   Color3f color;
/*     */   Color3f diffuseColor;
/*     */   Color3f specularColor;
/*     */   Color3f emissiveColor;
/*  82 */   Image theImage = null;
/*  83 */   String imageFile = null;
/*  84 */   Vector3f textureSize = new Vector3f(1.0F, 1.0F, 1.0F);
/*  85 */   Vector3f textureCenter = new Vector3f(0.0F, 0.0F, 0.0F);
/*     */   int textureAxis;
/*  87 */   int flags = 0;
/*     */   String type;
/*     */   String mappingType;
/*  90 */   String nextToken = null;
/*  91 */   static Hashtable imageTable = new Hashtable();
/*  92 */   static Hashtable textureTable = new Hashtable();
/*     */
/*     */   LwoTexture(LWOBFileReader reader, int length, String typename, int debugVals)
/*     */     throws FileNotFoundException
/*     */   {
/* 100 */     super(debugVals);
/* 101 */     debugOutputLn(1, "Constructor");
/* 102 */     this.theReader = reader;
/* 103 */     this.type = typename;
/* 104 */     readTexture(length);
/*     */   }
/*     */
/*     */   String getNextToken() {
/* 108 */     return this.nextToken;
/*     */   }
/*     */
/*     */   boolean isHandled()
/*     */   {
/* 117 */     if (((this.type.equals("CTEX")) || (this.type.equals("DTEX"))) && (this.theImage != null))
/*     */     {
/* 120 */       return true;
/* 121 */     }debugOutputLn(8, "failed isHandled(), type, theImage = " + this.type + ", " + this.theImage);
/*     */
/* 123 */     return false;
/*     */   }
/*     */
/*     */   Texture getTexture()
/*     */   {
/* 132 */     debugOutputLn(1, "getTexture()");
/* 133 */     if (this.theImage == null)
/* 134 */       return null;
/* 135 */     Texture2D t2d = (Texture2D)textureTable.get(this.theImage);
/* 136 */     if (t2d == null) {
/* 137 */       ImageScaler scaler = new ImageScaler((BufferedImage)this.theImage);
/* 138 */       BufferedImage scaledImage = (BufferedImage)scaler.getScaledImage();
/* 139 */       TextureLoader tl = new TextureLoader(scaledImage);
/* 140 */       t2d = (Texture2D)tl.getTexture();
/* 141 */       textureTable.put(this.theImage, t2d);
/*     */     }
/*     */
/* 144 */     return t2d;
/*     */   }
/*     */
/*     */   String getType() {
/* 148 */     return this.type;
/*     */   }
/*     */
/*     */   Color3f getColor() {
/* 152 */     return this.color;
/*     */   }
/*     */
/*     */   Image getImage() {
/* 156 */     return this.theImage;
/*     */   }
/*     */
/*     */   Vector3f getTextureSize() {
/* 160 */     return this.textureSize;
/*     */   }
/*     */
/*     */   int getTextureAxis() {
/* 164 */     return this.textureAxis;
/*     */   }
/*     */
/*     */   Vector3f getTextureCenter() {
/* 168 */     return this.textureCenter;
/*     */   }
/*     */
/*     */   String getMappingType() {
/* 172 */     return this.mappingType;
/*     */   }
/*     */
/*     */   void readTexture(int length)
/*     */     throws FileNotFoundException, ParsingErrorException
/*     */   {
/* 184 */     debugOutputLn(1, "readTexture()");
/*     */
/* 186 */     int surfStopMarker = this.theReader.getMarker() + length;
/* 187 */     this.mappingType = this.theReader.getString();
/* 188 */     debugOutputLn(2, "mappingType = " + this.mappingType);
/* 189 */     String tokenString = this.theReader.getToken();
/* 190 */     while ((tokenString != null) && (this.theReader.getMarker() < surfStopMarker))
/*     */     {
/* 192 */       debugOutputLn(2, "  tokenString = " + tokenString);
/* 193 */       debugOutputLn(2, "  marker, stop = " + this.theReader.getMarker() + ", " + surfStopMarker);
/*     */
/* 195 */       if ((tokenString.endsWith("TEX")) || (!tokenString.startsWith("T")) || (tokenString.equals("TRAN")))
/*     */       {
/* 197 */         this.nextToken = tokenString;
/* 198 */         return;
/*     */       }
/*     */
/* 201 */       int fieldLength = this.theReader.getShortInt();
/* 202 */       debugOutputLn(2, "  fl = " + fieldLength);
/*     */
/* 204 */       if (tokenString.equals("TFLG")) {
/* 205 */         debugOutputLn(64, "Not yet handling: " + tokenString);
/* 206 */         this.flags = this.theReader.getShortInt();
/* 207 */         this.textureAxis = (this.flags & 0x7);
/* 208 */         debugOutputLn(64, "val = " + this.flags);
/*     */       }
/* 210 */       else if (tokenString.equals("TCLR")) {
/* 211 */         debugOutputLn(64, "Not yet handling: " + tokenString);
/*     */         try {
/* 213 */           this.red = this.theReader.read();
/* 214 */           this.green = this.theReader.read();
/* 215 */           this.blue = this.theReader.read();
/* 216 */           this.theReader.read();
/*     */         }
/*     */         catch (IOException e) {
/* 219 */           throw new ParsingErrorException(e.getMessage());
/*     */         }
/* 221 */         debugOutputLn(64, "val = " + this.red + ", " + this.green + ", " + this.blue);
/*     */       }
/* 224 */       else if (tokenString.equals("TIMG")) {
/* 225 */         debugOutputLn(64, "Not yet handling: " + tokenString);
/* 226 */         this.imageFile = this.theReader.getString();
/* 227 */         debugOutputLn(2, "imageFile = " + this.imageFile);
/* 228 */         if ((this.imageFile.indexOf("none") == -1) &&
/* 229 */           ((this.theImage = (Image)imageTable.get(this.imageFile)) == null)) {
/*     */           try
/*     */           {
/* 232 */             TargaReader tr = new TargaReader(this.imageFile, this.debugPrinter.getValidOutput());
/*     */
/* 235 */             this.theImage = tr.getImage();
/* 236 */             imageTable.put(this.imageFile, this.theImage);
/*     */           }
/*     */           catch (FileNotFoundException e)
/*     */           {
/* 240 */             debugOutputLn(64, "Image File skipped: " + this.imageFile);
/*     */           }
/*     */
/*     */         }
/*     */
/* 245 */         debugOutputLn(64, "val = __" + this.imageFile + "__");
/*     */       }
/* 247 */       else if (tokenString.equals("TWRP")) {
/* 248 */         debugOutputLn(64, "Not yet handling: " + tokenString);
/* 249 */         int widthWrap = this.theReader.getShortInt();
/* 250 */         int heightWrap = this.theReader.getShortInt();
/* 251 */         debugOutputLn(64, "val = " + widthWrap + ", " + heightWrap);
/*     */       }
/* 254 */       else if (tokenString.equals("TCTR")) {
/* 255 */         debugOutputLn(64, "Not yet handling: " + tokenString);
/* 256 */         this.textureCenter.x = this.theReader.getFloat();
/* 257 */         this.textureCenter.y = this.theReader.getFloat();
/* 258 */         this.textureCenter.z = this.theReader.getFloat();
/* 259 */         debugOutputLn(64, "val = " + this.textureCenter);
/*     */       }
/* 261 */       else if (tokenString.equals("TSIZ")) {
/* 262 */         debugOutputLn(64, "Not yet handling: " + tokenString);
/* 263 */         this.textureSize.x = this.theReader.getFloat();
/* 264 */         this.textureSize.y = this.theReader.getFloat();
/* 265 */         this.textureSize.z = this.theReader.getFloat();
/* 266 */         debugOutputLn(64, "val = " + this.textureSize);
/*     */       }
/*     */       else {
/* 269 */         debugOutputLn(64, "unrecognized token: " + tokenString);
/*     */
/* 271 */         this.theReader.skipLength(fieldLength);
/*     */       }
/* 273 */       if (this.theReader.getMarker() < surfStopMarker)
/* 274 */         tokenString = this.theReader.getToken();
/*     */     }
/*     */   }
/*     */ }

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

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

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.