Package com.sun.j3d.loaders.lw3d

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

/*     */ package com.sun.j3d.loaders.lw3d;
/*     */
/*     */ import com.sun.j3d.loaders.ParsingErrorException;
/*     */ import java.io.IOException;
/*     */ import java.io.StreamTokenizer;
/*     */ import java.util.Vector;
/*     */ import javax.media.j3d.Behavior;
/*     */ import javax.media.j3d.BoundingSphere;
/*     */ import javax.media.j3d.DirectionalLight;
/*     */ import javax.media.j3d.Light;
/*     */ import javax.media.j3d.PointLight;
/*     */ import javax.media.j3d.SpotLight;
/*     */ import javax.media.j3d.Transform3D;
/*     */ import javax.media.j3d.TransformGroup;
/*     */ import javax.vecmath.Color3f;
/*     */ import javax.vecmath.Matrix4d;
/*     */ import javax.vecmath.Point3d;
/*     */ import javax.vecmath.Point3f;
/*     */ import javax.vecmath.Vector3f;
/*     */
/*     */ class LwsLight extends TextfileParser
/*     */   implements LwsPrimitive
/*     */ {
/*     */   String fileName;
/*     */   String objName;
/*     */   LwsMotion motion;
/*     */   int parent;
/*     */   TransformGroup objectTransform;
/*     */   Vector objectBehavior;
/*     */   Color3f color;
/*     */   int type;
/*  68 */   Point3f attenuation = new Point3f(1.0F, 0.0F, 0.0F);
/*  69 */   float spotConeAngle = 3.141593F;
/*     */   LwLightObject lwLight;
/*  73 */   LwsEnvelopeLightIntensity intensityEnvelope = null;
/*  74 */   Light light = null;
/*     */   static final int DIRECTIONAL = 0;
/*     */   static final int POINT = 1;
/*     */   static final int SPOT = 2;
/*     */
/*     */   LwsLight(StreamTokenizer st, int totalFrames, float totalTime, int debugVals)
/*     */     throws ParsingErrorException
/*     */   {
/*  84 */     this.debugPrinter.setValidOutput(debugVals);
/*     */
/*  86 */     debugOutput(1, "LwsLight()");
/*  87 */     this.color = new Color3f(1.0F, 1.0F, 1.0F);
/*  88 */     this.lwLight = new LwLightObject(null, 0.0F, null);
/*     */
/*  90 */     this.parent = -1;
/*  91 */     debugOutputLn(8, "about to get LightName");
/*  92 */     getAndCheckString(st, "LightName");
/*  93 */     debugOutputLn(8, "about to get LightName value");
/*  94 */     this.objName = getName(st);
/*  95 */     debugOutputLn(8, "got LightName");
/*  96 */     skip(st, "ShowLight", 2);
/*  97 */     debugOutputLn(8, "got ShowLight");
/*  98 */     getAndCheckString(st, "LightMotion");
/*  99 */     debugOutputLn(8, "got LightMotion");
/* 100 */     this.motion = new LwsMotion(st, totalFrames, totalTime);
/* 101 */     debugOutputLn(8, "got motions");
/*     */
/* 108 */     while ((!isCurrentToken(st, "ShowCamera")) && (!isCurrentToken(st, "AddLight")))
/*     */     {
/* 117 */       debugOutputLn(8, "currentToken = " + st.sval);
/*     */
/* 119 */       if (isCurrentToken(st, "ParentObject")) {
/* 120 */         this.parent = ((int)getNumber(st));
/*     */       }
/* 122 */       else if (isCurrentToken(st, "LightColor")) {
/* 123 */         this.color.x = ((float)getNumber(st) / 255.0F);
/* 124 */         this.color.y = ((float)getNumber(st) / 255.0F);
/* 125 */         this.color.z = ((float)getNumber(st) / 255.0F);
/* 126 */         this.lwLight.setColor(this.color);
/*     */       }
/* 128 */       else if (isCurrentToken(st, "LgtIntensity"))
/*     */       {
/* 130 */         String className = getClass().getName();
/* 131 */         int classIndex = className.lastIndexOf('.');
/*     */         String packageName;
/*     */         String packageName;
/* 133 */         if (classIndex < 0)
/* 134 */           packageName = "";
/*     */         else
/* 136 */           packageName = className.substring(0, classIndex) + ".";
/* 137 */         EnvelopeHandler env = new EnvelopeHandler(st, totalFrames, totalTime, packageName + "LwsEnvelopeLightIntensity");
/*     */
/* 140 */         if (env.hasValue) {
/* 141 */           float intensity = env.theValue;
/* 142 */           this.color.x *= intensity;
/* 143 */           this.color.y *= intensity;
/* 144 */           this.color.z *= intensity;
/* 145 */           this.lwLight.setIntensity(intensity);
/*     */         }
/*     */         else {
/* 148 */           this.intensityEnvelope = ((LwsEnvelopeLightIntensity)env.theEnvelope);
/*     */         }
/*     */
/*     */       }
/* 152 */       else if (isCurrentToken(st, "LightType")) {
/* 153 */         this.type = ((int)getNumber(st));
/*     */       }
/* 155 */       else if (isCurrentToken(st, "Falloff")) {
/* 156 */         float falloff = (float)getNumber(st);
/* 157 */         this.attenuation.y = (1.0F / (1.0F - falloff) - 1.0F);
/*     */       }
/* 159 */       else if (isCurrentToken(st, "ConeAngle")) {
/* 160 */         this.spotConeAngle = ((float)getNumber(st) * 0.01745329F);
/*     */       }
/*     */       try {
/* 163 */         st.nextToken();
/*     */       }
/*     */       catch (IOException e) {
/* 166 */         throw new ParsingErrorException(e.getMessage());
/*     */       }
/*     */     }
/* 169 */     st.pushBack();
/*     */   }
/*     */
/*     */   int getParent() {
/* 173 */     return this.parent;
/*     */   }
/*     */
/*     */   void createJava3dObject(int loadBehaviors)
/*     */   {
/* 180 */     Matrix4d mat = new Matrix4d();
/* 181 */     mat.setIdentity();
/*     */
/* 184 */     LwsFrame firstFrame = this.motion.getFirstFrame();
/* 185 */     firstFrame.setMatrix(mat);
/* 186 */     debugOutputLn(2, "Light transform = " + mat);
/* 187 */     Transform3D t1 = new Transform3D();
/* 188 */     t1.set(mat);
/* 189 */     this.objectTransform = new TransformGroup(t1);
/* 190 */     this.objectTransform.setCapability(18);
/* 191 */     Vector3f defaultDir = new Vector3f(0.0F, 0.0F, -1.0F);
/* 192 */     Point3f defaultPos = new Point3f(0.0F, 0.0F, 0.0F);
/*     */
/* 194 */     switch (this.type) {
/*     */     case 0:
/* 196 */       this.light = new DirectionalLight(this.color, defaultDir);
/* 197 */       break;
/*     */     case 1:
/* 199 */       this.light = new PointLight(this.color, defaultPos, this.attenuation);
/* 200 */       break;
/*     */     case 2:
/* 203 */       this.light = new SpotLight(this.color, defaultPos, this.attenuation, defaultDir, 2.0F * this.spotConeAngle, 0.0F);
/*     */
/* 205 */       break;
/*     */     }
/*     */
/* 211 */     this.light.setCapability(15);
/* 212 */     if (this.light != null) {
/* 213 */       this.lwLight.setLight(this.light);
/* 214 */       BoundingSphere bounds = new BoundingSphere(new Point3d(0.0D, 0.0D, 0.0D), 100000.0D);
/*     */
/* 216 */       this.light.setInfluencingBounds(bounds);
/* 217 */       this.objectTransform.addChild(this.light);
/*     */
/* 220 */       this.objectBehavior = new Vector();
/* 221 */       if (loadBehaviors != 0)
/*     */       {
/* 223 */         Behavior b = null;
/* 224 */         this.motion.createJava3dBehaviors(this.objectTransform);
/* 225 */         b = this.motion.getBehaviors();
/* 226 */         if (b != null) {
/* 227 */           this.objectBehavior.addElement(b);
/*     */         }
/* 229 */         if (this.intensityEnvelope != null) {
/* 230 */           b = null;
/* 231 */           this.intensityEnvelope.createJava3dBehaviors(this.lwLight);
/* 232 */           b = this.intensityEnvelope.getBehaviors();
/* 233 */           if (b != null)
/* 234 */             this.objectBehavior.addElement(b);
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */
/*     */   public TransformGroup getObjectNode()
/*     */   {
/* 242 */     return this.objectTransform;
/*     */   }
/*     */
/*     */   Light getLight() {
/* 246 */     return this.light;
/*     */   }
/*     */
/*     */   public Vector getObjectBehaviors()
/*     */   {
/* 251 */     debugOutputLn(1, "getObjectBehaviors()");
/* 252 */     return this.objectBehavior;
/*     */   }
/*     */
/*     */   void printVals()
/*     */   {
/* 258 */     debugOutputLn(2, "  LIGHT vals: ");
/* 259 */     debugOutputLn(2, "   objName = " + this.objName);
/* 260 */     this.motion.printVals();
/*     */   }
/*     */ }

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

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

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.