Example usage for javax.media.j3d Material Material

List of usage examples for javax.media.j3d Material Material

Introduction

In this page you can find the example usage for javax.media.j3d Material Material.

Prototype

public Material(Color3f ambientColor, Color3f emissiveColor, Color3f diffuseColor, Color3f specularColor,
        float shininess) 

Source Link

Document

Constructs and initializes a new material object using the specified parameters.

Usage

From source file:FourByFour.java

PickDragBehavior(Canvas2D canvas2D, Canvas3D canvas3D, Positions positions, BranchGroup branchGroup,
        TransformGroup transformGroup) {

    this.canvas2D = canvas2D;
    this.canvas3D = canvas3D;
    this.positions = positions;
    this.branchGroup = branchGroup;
    this.transformGroup = transformGroup;

    modelTrans = new Transform3D();
    transformX = new Transform3D();
    transformY = new Transform3D();

    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f green = new Color3f(0.0f, 1.0f, 0.0f);

    highlight = new Appearance();
    highlight.setMaterial(new Material(green, black, green, white, 80.f));

    parallel = true;/*from w  w w  .ja  v  a2s  . co  m*/
}

From source file:org.deegree.ogcwebservices.wpvs.j3d.Object3DFactory.java

/**
 * creates a Surface from the passed feature. It is assumed the feature
 * is simple, contains one surfac/polygon geometry and optional has
 * material and/or texture informations. The GML schema for a valid 
 * feature is defined as:/*from w w w  . j a  v a  2  s .  co m*/
 * <pre>
 *  <xsd:schema targetNamespace="http://www.deegree.org/app" xmlns:app="http://www.deegree.org/app" xmlns:ogc="http://www.opengis.net/ogc" xmlns:deegreewfs="http://www.deegree.org/wfs" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" attributeFormDefault="unqualified">
 *      <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/3.1.1/base/feature.xsd"/>
 *       <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/3.1.1/base/geometryAggregates.xsd"/>
 *       <xsd:element name="WPVS" type="app:WPVSType" substitutionGroup="gml:_Feature"/>
 *       <xsd:complexType name="WPVSType">
 *           <xsd:complexContent>
 *               <xsd:extension base="gml:AbstractFeatureType">
 *                   <xsd:sequence>
 *                       <xsd:element name="fk_feature" type="xsd:double"/>
 *                       <xsd:element name="geometry" type="gml:GeometryPropertyType"/>
 *                       <xsd:element name="shininess" type="xsd:double" minOccurs="0"/>
 *                       <xsd:element name="transparency" type="xsd:double" minOccurs="0"/>
 *                       <xsd:element name="ambientintensity" type="xsd:double" minOccurs="0"/>
 *                       <xsd:element name="specularcolor" type="xsd:string" minOccurs="0"/>
 *                       <xsd:element name="diffusecolor" type="xsd:string" minOccurs="0"/>
 *                       <xsd:element name="emissivecolor" type="xsd:string" minOccurs="0"/>
 *                       <xsd:element name="texturemap" type="xsd:string" minOccurs="0"/>
 *                       <xsd:element name="texturecoordinates" type="xsd:string" minOccurs="0"/>
 *                       <xsd:element name="texturetype" type="xsd:string" minOccurs="0"/>
 *                       <xsd:element name="repeat" type="xsd:integer" minOccurs="0"/>
 *                   </xsd:sequence>
 *               </xsd:extension>
 *           </xsd:complexContent>
 *       </xsd:complexType>
 *   </xsd:schema>
 * </pre> 
 * @param feature
 * @return a DefaultSurface which is derivtive of a Shape3D.
 */
public DefaultSurface createSurface(Feature feature) {

    double oId = (Double) feature.getDefaultProperty(objectID).getValue(-1d);

    BufferedImage textImage = null;
    FeatureProperty[] fp = feature.getProperties(textMapQn);
    if (fp != null && fp.length > 0) {
        String tmp = (String) feature.getProperties(textMapQn)[0].getValue();
        if ((textImage = textImgMap.get(tmp)) == null) {
            String lt = tmp.toLowerCase();
            try {
                if (lt.startsWith("file:") || lt.startsWith("http:")) {
                    textImage = ImageUtils.loadImage(new URL(tmp));
                } else {
                    textImage = ImageUtils.loadImage(tmp);
                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            textImgMap.put(tmp, textImage);
        }
    }
    float[][] textCoords = new float[1][];
    fp = feature.getProperties(textCoordsQn);
    if (fp != null && fp.length > 0) {
        String tmp = (String) feature.getProperties(textCoordsQn)[0].getValue();
        if (tmp != null) {
            textCoords[0] = StringTools.toArrayFloat(tmp, ", ");
        }
    }
    double shininess = (Double) feature.getDefaultProperty(shininessQn).getValue(1d);
    double transparency = (Double) feature.getDefaultProperty(transparencyQn).getValue(0d);
    double ambientintensity = (Double) feature.getDefaultProperty(ambientintensityQn).getValue(1d);
    Color3f ambientcolor = new Color3f((float) ambientintensity, (float) ambientintensity,
            (float) ambientintensity);

    String tmp = (String) feature.getDefaultProperty(specularcolorQn).getValue("1 1 1");
    float[] tmpFl = StringTools.toArrayFloat(tmp.trim(), " ");
    Color3f specularcolor = new Color3f(tmpFl[0], tmpFl[1], tmpFl[2]);

    tmp = (String) feature.getDefaultProperty(diffusecolorQn).getValue("1 1 1");
    tmpFl = StringTools.toArrayFloat(tmp.trim(), " ");
    Color3f diffusecolor = new Color3f(tmpFl[0], tmpFl[1], tmpFl[2]);

    tmp = (String) feature.getDefaultProperty(emissivecolorQn).getValue("1 1 1");
    tmpFl = StringTools.toArrayFloat(tmp.trim(), " ");
    Color3f emissivecolor = new Color3f(tmpFl[0], tmpFl[1], tmpFl[2]);

    Material material = new Material(ambientcolor, emissivecolor, diffusecolor, specularcolor,
            (float) shininess);

    Surface geom = (Surface) feature.getDefaultGeometryPropertyValue();
    LOG.logDebug("3D-Surface: ", geom);

    DefaultSurface surface = null;
    if (textImage != null) {
        surface = new TexturedSurface(feature.getId(), String.valueOf(oId), geom, material,
                (float) transparency, textImage, textCoords);
    } else {
        surface = new ColoredSurface(feature.getId(), String.valueOf(oId), geom, material,
                (float) transparency);
    }

    surface.compile();
    return surface;
}