Package javax.media.j3d

Examples of javax.media.j3d.Material


      unlockPolygonAttributes(pa);
      pa.setPolygonOffset(polygonOffset);
      pa.setPolygonOffsetFactor(polygonOffsetFactor);
      pa.setBackFaceNormalFlip(true);
        a.setPolygonAttributes(pa);
      Material m = new Material();
        Color selectedColor;
      if (on) selectedColor = highlightColor;
      else selectedColor = baseColor;
       
      float[] colors = selectedColor.getRGBColorComponents(null);
      m.setAmbientColor(colors[0], colors[1], colors[2]);
     
      // Squash specular toward white => keep only hue
      float[] hsb = Color.RGBtoHSB(selectedColor.getRed(), selectedColor.getGreen(), selectedColor.getBlue(), null);
      Color.getHSBColor(hsb[0],hsb[1]/10,1.0f).getRGBColorComponents(colors);
      m.setSpecularColor(colors[0], colors[1], colors[2]);

      // diffuse is same hue and saturation but darker
      Color.getHSBColor(hsb[0],hsb[1],hsb[2]/2).getRGBColorComponents(colors);
      m.setDiffuseColor(colors[0], colors[1], colors[2]);
     
      // no emissive color
      m.setEmissiveColor(0f,0f,0f);

          m.setLightingEnable(true);
          a.setMaterial(m);
    }
        shape.setAppearance(a);
    }
View Full Code Here


        Color3f eColor  = new Color3f(0.0f, 0.0f, 0.0f);
        Color3f sColor  = new Color3f(1.0f, 1.0f, 1.0f);

        Appearance cya=new Appearance();
        cya.setColoringAttributes(new ColoringAttributes(new Color3f(color),ColoringAttributes.SHADE_GOURAUD));
        Material cym = new Material(aColor, eColor, new Color3f(color), sColor, 100.0f);
        cym.setLightingEnable(true);
        cya.setMaterial(cym);
        cy.setAppearance(cya);
        bcy.setAppearance(cya);

        Appearance coa=new Appearance();
        coa.setColoringAttributes(new ColoringAttributes(new Color3f(arrowColor),ColoringAttributes.SHADE_GOURAUD));
        Material com = new Material(aColor, eColor, new Color3f(arrowColor), sColor, 100.0f);
        com.setLightingEnable(true);
        coa.setMaterial(com);
        co.setAppearance(coa);
        bco.setAppearance(coa);
    }
View Full Code Here

                Color3f sColor  = new Color3f(1.0f, 1.0f, 1.0f);

                Appearance cya=new Appearance();
                cya.setColoringAttributes(new ColoringAttributes(new Color3f(Color.WHITE),ColoringAttributes.SHADE_GOURAUD));
                cya.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0));
                Material cym = new Material(aColor, eColor, new Color3f(Color.WHITE), sColor, 100.0f);
                cym.setLightingEnable(true);
                cya.setMaterial(cym);
                sd.setAppearance(cya);

                gn.addChild(sd);
       
View Full Code Here

            Color3f sColor  = new Color3f(1.0f, 1.0f, 1.0f);

            Appearance cya=new Appearance();
            cya.setColoringAttributes(new ColoringAttributes(new Color3f(Color.WHITE),ColoringAttributes.SHADE_GOURAUD));
            cya.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0));
            Material cym = new Material(aColor, eColor, new Color3f(Color.WHITE), sColor, 100.0f);
            cym.setLightingEnable(true);
            cya.setMaterial(cym);
            sd.setAppearance(cya);

            gn.addChild(sd);
   
View Full Code Here

              TransparencyAttributes.NICEST, transparencyValue)); // 0 means opaque in Java 3D
        } else {
          // Set default color if it doesn't exist yet
          Color3f black = new Color3f();
          if (appearance.getMaterial() == null) {
            appearance.setMaterial(new Material(black, black, black, black, 1));
            appearance.setColoringAttributes(new ColoringAttributes(black, ColoringAttributes.SHADE_GOURAUD));
          }
        }
        this.transparentColor = null;
        this.transparency = null;
View Full Code Here

    /**
     * Returns the material of the appearance at <code>effectId</code>.
     */
    private Material getAppearanceMaterial(String effectId) {
      Appearance appearance = this.effectAppearances.get(effectId);
      Material material = appearance.getMaterial();
      if (material == null) {
        material = new Material();
        appearance.setMaterial(material);
      }
      return material;
    }
View Full Code Here

    } 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
View Full Code Here

        checkCurrentThreadIsntInterrupted();
       
        Appearance appearance = appearanceEntry.getKey().getAppearance();       
        String appearanceName = appearanceEntry.getValue();
        writer.write("\nnewmtl " + appearanceName + "\n");
        Material material = appearance.getMaterial();
        if (material != null) {
          if (material instanceof OBJMaterial
              && ((OBJMaterial)material).isIlluminationModelSet()) {
            writer.write("illum " + ((OBJMaterial)material).getIlluminationModel() + "\n");
          } else if (material.getShininess() > 1) {
            writer.write("illum 2\n");
          } else if (material.getLightingEnable()) { 
            writer.write("illum 1\n");
          } else {
            writer.write("illum 0\n");
          }
          Color3f color = new Color3f();
          material.getAmbientColor(color);         
          writer.write("Ka " + format(color.x) + " " + format(color.y) + " " + format(color.z) + "\n");
          material.getDiffuseColor(color);         
          writer.write("Kd " + format(color.x) + " " + format(color.y) + " " + format(color.z) + "\n");
          material.getSpecularColor(color);         
          writer.write("Ks " + format(color.x) + " " + format(color.y) + " " + format(color.z) + "\n");
          writer.write("Ns " + format(material.getShininess()) + "\n");
          if (material instanceof OBJMaterial) {
            OBJMaterial objMaterial = (OBJMaterial)material;
            if (objMaterial.isOpticalDensitySet()) {
              writer.write("Ni " + format(objMaterial.getOpticalDensity()) + "\n");
            }
View Full Code Here

    if (color != null) {
      Color3f materialColor = new Color3f(((color >>> 16) & 0xFF) / 255f,
                                           ((color >>> 8) & 0xFF) / 255f,
                                                   (color & 0xFF) / 255f);
      setMaterial(this.sceneTree.getChild(0),
          new Material(materialColor, new Color3f(), materialColor, materialColor, 64));
    } else {
      // Set default material of model
      setMaterial(this.sceneTree.getChild(0), null);
    }
  }
View Full Code Here

      // Change material of all shape that are not window panes
      if (shapeName == null
          || !shapeName.startsWith(ModelManager.WINDOW_PANE_SHAPE_PREFIX)) {
        Appearance appearance = shape.getAppearance();
        // Use appearance user data to store shape default material
        Material defaultMaterial = (Material)appearance.getUserData();
        if (defaultMaterial == null) {
          defaultMaterial = appearance.getMaterial();
          appearance.setUserData(defaultMaterial);
        }
        // Change material
View Full Code Here

TOP

Related Classes of javax.media.j3d.Material

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.