Package com.sun.j3d.loaders

Examples of com.sun.j3d.loaders.IncorrectFormatException


          parseObjectLine(tokenizer, baseUrl);
          break;
        case StreamTokenizer.TT_EOL:
          break;
        default :
          throw new IncorrectFormatException("Unexpected token " + tokenizer.sval
              + " at row " + tokenizer.lineno());
      }
    }
   
    try {
View Full Code Here


      } else if (tokenizer.ttype == StreamTokenizer.TT_EOL) {
        // Use default group
        this.currentGroup = this.groups.get("default");
        tokenizer.pushBack();
      } else
        throw new IncorrectFormatException("Expected group or object name at line " + tokenizer.lineno());
      }
      this.currentGroup.setSmooth(smoothingGroup);
      // Skip other names
      while (tokenizer.nextToken() == StreamTokenizer.TT_WORD) {       
      }
      tokenizer.pushBack();    
    } else if ("s".equals(tokenizer.sval)) {
      // Read smoothing group s n
      //                   or s off
      if (tokenizer.nextToken() == StreamTokenizer.TT_WORD) {
        this.currentGroup.setSmooth(!"off".equals(tokenizer.sval));
      } else {
        throw new IncorrectFormatException("Expected smoothing group or off at line " + tokenizer.lineno());
      }
    } else if ("usemtl".equals(tokenizer.sval)) {
      // Read the material name usemtl name
      if (tokenizer.nextToken() == StreamTokenizer.TT_WORD) {
        this.currentMaterial = tokenizer.sval;
      } else {
        throw new IncorrectFormatException("Expected material name at line " + tokenizer.lineno());
      }
    } else if ("mtllib".equals(tokenizer.sval)) {
      int libCount = 0;
      do {
        if (tokenizer.nextToken() == StreamTokenizer.TT_WORD) {
          parseMaterial(tokenizer.sval, baseUrl);
          libCount++;
        }
      }
      while (tokenizer.nextToken() != StreamTokenizer.TT_EOL);       
      if (libCount == 0) {
        throw new IncorrectFormatException("Expected material library at line " + tokenizer.lineno());
      }
      tokenizer.pushBack();
    } else {
      // Skip other lines (including comment lines starting by #)
      int token;
      do {
        token = tokenizer.nextToken();
      } while (token != StreamTokenizer.TT_EOL && token != StreamTokenizer.TT_EOF);
      tokenizer.pushBack();    
    }
   
    int token = tokenizer.nextToken();
    if (token != StreamTokenizer.TT_EOL && token != StreamTokenizer.TT_EOF) {
      throw new IncorrectFormatException("Expected end of line at line " + tokenizer.lineno());
    }
  }
View Full Code Here

  /**
   * Returns the integer contained in the next token.
   */
  private static int parseInteger(StreamTokenizer tokenizer) throws IOException {
    if (tokenizer.nextToken() != StreamTokenizer.TT_WORD) {
      throw new IncorrectFormatException("Expected an integer at line " + tokenizer.lineno());
    } else {
      try {
        return Integer.parseInt(tokenizer.sval);
      } catch (NumberFormatException ex) {
        throw new IncorrectFormatException("Found " + tokenizer.sval +
            " instead of an integer at line " + tokenizer.lineno());
      }
    }
  }
View Full Code Here

  /**
   * Returns the number contained in the next token.
   */
  private static float parseNumber(StreamTokenizer tokenizer) throws IOException {
    if (tokenizer.nextToken() != StreamTokenizer.TT_WORD) {
      throw new IncorrectFormatException("Expected a number at line " + tokenizer.lineno());
    } else {
      try {
        return Float.parseFloat(tokenizer.sval);
      } catch (NumberFormatException ex) {
        throw new IncorrectFormatException("Found " + tokenizer.sval +
            " instead of a number at line " + tokenizer.lineno());
      }
    }
  }
View Full Code Here

              appearances, currentAppearance, baseUrl);
          break;
        case StreamTokenizer.TT_EOL:
          break;
        default :
          throw new IncorrectFormatException("Unexpected token " + tokenizer.sval
              + " at row " + tokenizer.lineno());
      }
    }
    return appearances;
  }
View Full Code Here

      // Read material name newmtl name
      if (tokenizer.nextToken() == StreamTokenizer.TT_WORD) {
        currentAppearance = new Appearance();
        appearances.put(tokenizer.sval, currentAppearance);
      } else {
        throw new IncorrectFormatException("Expected material name at line " + tokenizer.lineno());
      }
    } else if ("Ka".equals(tokenizer.sval)) {
      // Read ambient color Ka r g b
      Color3f ambiantColor = new Color3f(parseNumber(tokenizer),
          parseNumber(tokenizer), parseNumber(tokenizer));
      if (currentAppearance != null) {
        Material material = getMaterial(currentAppearance);
        material.setAmbientColor(ambiantColor);
      }
    } else if ("Kd".equals(tokenizer.sval)) {
      // Read diffuse or emissive color Kd r g b
      Color3f diffuseColor = new Color3f(parseNumber(tokenizer),
          parseNumber(tokenizer), parseNumber(tokenizer));
      if (currentAppearance != null) {
        OBJMaterial material = getMaterial(currentAppearance);
        material.setDiffuseColor(diffuseColor);
        currentAppearance.setColoringAttributes(
            new ColoringAttributes(diffuseColor, ColoringAttributes.SHADE_GOURAUD));
      }
    } else if ("Ks".equals(tokenizer.sval)) {
      // Read specular color Ks r g b
      Color3f specularColor = new Color3f(parseNumber(tokenizer),
          parseNumber(tokenizer), parseNumber(tokenizer));
      if (currentAppearance != null) {
        OBJMaterial material = getMaterial(currentAppearance);
        if (!material.isIlluminationModelSet()
            || material.getIlluminationModel() >= 2) {
          material.setSpecularColor(specularColor);
        } else {
          material.setSpecularColor(0, 0, 0);
        }
      }
    } else if ("Ns".equals(tokenizer.sval)) {
      // Read shininess Ns val  with 0 <= val <= 1000
      float shininess = parseNumber(tokenizer);
      if (currentAppearance != null) {
        OBJMaterial material = getMaterial(currentAppearance);
        if (!material.isIlluminationModelSet()
            || material.getIlluminationModel() >= 2) {
          // Use shininess at a max value equal to 128
          material.setShininess(Math.max(1f, Math.min(shininess, 128f)));
        } else {
          material.setShininess(1f);
        }
      }
    } else if ("Ni".equals(tokenizer.sval)) {
      // Read optical density Ni val 
      float opticalDensity = parseNumber(tokenizer);
      if (currentAppearance != null) {
        OBJMaterial material = getMaterial(currentAppearance);
        material.setOpticalDensity(opticalDensity);
      }
    } else if ("sharpness".equals(tokenizer.sval)) {
      // Read sharpness sharpness val 
      float sharpness = parseNumber(tokenizer);
      if (currentAppearance != null) {
        OBJMaterial material = getMaterial(currentAppearance);
        material.setSharpness(sharpness);
      }
    } else if ("d".equals(tokenizer.sval)) {
      // Read transparency d val  with 0 <= val <= 1
      if (tokenizer.nextToken() == StreamTokenizer.TT_WORD) {
        if ("-halo".equals(tokenizer.sval)) {
          // Ignore halo transparency
          parseNumber(tokenizer);
        } else {
          tokenizer.pushBack();    
          float transparency = parseNumber(tokenizer);
          if (currentAppearance != null) {
            if (transparency >= 1) {
              currentAppearance.setTransparencyAttributes(null);
            } else {
              currentAppearance.setTransparencyAttributes(new TransparencyAttributes(
                  TransparencyAttributes.NICEST, 1f - Math.max(0f, transparency)));
            }
          }
        }
      } else {
        throw new IncorrectFormatException("Expected transparency factor at line " + tokenizer.lineno());
      }
    } else if ("illum".equals(tokenizer.sval)) {
      // Read illumination setting illum n
      int illumination = parseInteger(tokenizer);
      if (currentAppearance != null) {
        OBJMaterial material = getMaterial(currentAppearance);
        material.setIlluminationModel(illumination);
        material.setLightingEnable(illumination >= 1);
        if (illumination <= 1) {
          material.setSpecularColor(0, 0, 0);
          material.setShininess(1f);
        }
      }
    } else if ("map_Kd".equals(tokenizer.sval)) {
      // Read material texture map_Kd name
      // Search last parameter that matches image file name
      String imageFileName = null;
      while (tokenizer.nextToken() != StreamTokenizer.TT_EOL) {
        if (tokenizer.ttype == StreamTokenizer.TT_WORD) {
          imageFileName = tokenizer.sval;
        }
      }
     
      if (imageFileName != null) {
        URL textureImageUrl = baseUrl != null
            ? new URL(baseUrl, imageFileName)
            : new File(imageFileName).toURI().toURL();
        BufferedImage textureImage = null;
        try {
          textureImage = ImageIO.read(textureImageUrl);
        } catch (IOException ex) {
          // Ignore images at other format
        }
        if (textureImage != null) {
          TextureLoader textureLoader = new TextureLoader(textureImage);
          Texture texture = textureLoader.getTexture();
          // Keep in user data the URL of the texture image
          texture.setUserData(textureImageUrl);
          currentAppearance.setTexture(texture);
        }
      } else {
        throw new IncorrectFormatException("Expected image file name at line " + tokenizer.lineno());
      }
      tokenizer.pushBack();    
    } else {
      int token;
      do {
        token = tokenizer.nextToken();
      } while (token != StreamTokenizer.TT_EOL && token != StreamTokenizer.TT_EOF);
      tokenizer.pushBack();    
    }
   
    int token = tokenizer.nextToken();
    if (token != StreamTokenizer.TT_EOL && token != StreamTokenizer.TT_EOF) {
      throw new IncorrectFormatException("Expected end of line at line " + tokenizer.lineno());
    }
   
    return currentAppearance;
  }
View Full Code Here

        try {
          // Check magic number 0x4D4D
          InputStream in = url.openStream();
          if (in.read() != 0x4D
              && in.read() != 0x4D) {
            throw new IncorrectFormatException("Bad magic number");
          }
          in.close();
        } catch (FileNotFoundException ex) {
          throw ex;
        } catch (IOException ex) {
View Full Code Here

/* 138 */       boolean leftToRight = (flags & 0x10) == 0;
/* 139 */       this.bufferedReader.skip(idLength);
/*     */
/* 142 */       if ((colormapPresent == 1) || (imageType != 2) || ((depth != 24) && (depth != 32)))
/*     */       {
/* 147 */         throw new IncorrectFormatException("This format is not readable by the Lightwave loader.  Only 24- or 32-bit true-color uncompressed Targa images will work");
/*     */       }
/*     */
/* 154 */       BufferedImage bImage = new BufferedImage(width, height, 2);
/*     */
/* 156 */       int[] imageBits = ((DataBufferInt)bImage.getRaster().getDataBuffer()).getData();
View Full Code Here

/*     */     throws IncorrectFormatException, ParsingErrorException
/*     */   {
/*  89 */     debugOutputLn(1, "getEnvelope()");
/*  90 */     this.numChannels = ((int)getNumber(st));
/*  91 */     if (this.numChannels != 1) {
/*  92 */       throw new IncorrectFormatException(J3dUtilsI18N.getString("LwsEnvelope0"));
/*     */     }
/*     */
/*  95 */     debugOutputLn(8, "got channels");
/*     */
/*  97 */     this.numFrames = ((int)getNumber(st));
View Full Code Here

/* 135 */           surf = tempSurf;
/* 136 */           break;
/*     */         }
/*     */       }
/* 139 */       if (surf == null) {
/* 140 */         throw new IncorrectFormatException("bad surf for surfnum/name = " + shape.numSurf + ", " + surfName);
/*     */       }
/*     */
/* 144 */       debugOutputLn(2, "surf = " + surf);
/*     */
/* 147 */       LwoTexture texture = surf.getTexture();
View Full Code Here

TOP

Related Classes of com.sun.j3d.loaders.IncorrectFormatException

Copyright © 2018 www.massapicom. 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.