예제 #1
0
 private static Appearance getAparencia() {
   if (ap == null) {
     ap = new Appearance();
     // Copper
     Material mat = new Material();
     mat.setAmbientColor(0.19125f, 0.0735f, 0.0225f);
     mat.setDiffuseColor(0.7038f, 0.27048f, 0.0828f);
     mat.setSpecularColor(0.256777f, 0.137622f, 0.086014f);
     mat.setShininess(12.8f);
     ap.setMaterial(mat);
   }
   return ap;
 }
예제 #2
0
  @Override
  protected Appearance createAppearance() {
    Appearance appearance = new Appearance();
    appearance.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
    appearance.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ);

    LineAttributes lineAttrib = new LineAttributes();
    lineAttrib.setCapability(LineAttributes.ALLOW_ANTIALIASING_WRITE);
    lineAttrib.setCapability(LineAttributes.ALLOW_PATTERN_WRITE);
    lineAttrib.setCapability(LineAttributes.ALLOW_WIDTH_WRITE);
    lineAttrib.setLineWidth(linewidth);
    lineAttrib.setLinePattern(pattern);
    appearance.setLineAttributes(lineAttrib);

    PolygonAttributes polyAttrib = new PolygonAttributes();
    polyAttrib.setCapability(PolygonAttributes.ALLOW_MODE_WRITE);
    polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_FILL);
    polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
    polyAttrib.setBackFaceNormalFlip(true);
    appearance.setPolygonAttributes(polyAttrib);

    ColoringAttributes colorAttrib = new ColoringAttributes();
    colorAttrib.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
    colorAttrib.setColor(color);
    appearance.setColoringAttributes(colorAttrib);

    TransparencyAttributes tr = new TransparencyAttributes();
    int mode = transparency == 0f ? TransparencyAttributes.NONE : TransparencyAttributes.FASTEST;
    tr.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
    tr.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    tr.setTransparencyMode(mode);
    tr.setTransparency(transparency);
    appearance.setTransparencyAttributes(tr);

    Material material = new Material();
    material.setCapability(Material.ALLOW_COMPONENT_WRITE);
    material.setAmbientColor(0.1f, 0.1f, 0.1f);
    material.setSpecularColor(0.1f, 0.1f, 0.1f);
    material.setDiffuseColor(0.1f, 0.1f, 0.1f);
    appearance.setMaterial(material);
    return appearance;
  }
예제 #3
0
  @Override
  protected Appearance createAppearance() {
    final Appearance appearance = new Appearance();
    appearance.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
    appearance.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ);

    final PointAttributes pointAttrib = new PointAttributes();
    pointAttrib.setCapability(PointAttributes.ALLOW_ANTIALIASING_WRITE);
    pointAttrib.setCapability(PointAttributes.ALLOW_SIZE_WRITE);
    pointAttrib.setPointSize(pointsize);
    appearance.setPointAttributes(pointAttrib);

    final PolygonAttributes polyAttrib = new PolygonAttributes();
    polyAttrib.setCapability(PolygonAttributes.ALLOW_MODE_WRITE);
    polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_FILL);
    polyAttrib.setCullFace(PolygonAttributes.CULL_BACK);
    polyAttrib.setBackFaceNormalFlip(false);
    appearance.setPolygonAttributes(polyAttrib);

    final ColoringAttributes colorAttrib = new ColoringAttributes();
    colorAttrib.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
    colorAttrib.setColor(color);
    appearance.setColoringAttributes(colorAttrib);

    final TransparencyAttributes tr = new TransparencyAttributes();
    final int mode =
        transparency == 0f ? TransparencyAttributes.NONE : TransparencyAttributes.FASTEST;
    tr.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
    tr.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    tr.setTransparencyMode(mode);
    tr.setTransparency(transparency);
    appearance.setTransparencyAttributes(tr);

    final Material material = new Material();
    material.setCapability(Material.ALLOW_COMPONENT_WRITE);
    material.setAmbientColor(0.1f, 0.1f, 0.1f);
    material.setSpecularColor(0.1f, 0.1f, 0.1f);
    material.setDiffuseColor(0.1f, 0.1f, 0.1f);
    appearance.setMaterial(material);
    return appearance;
  }
예제 #4
0
  private void readNode(Node node) {
    EnvironmentDom dom;
    NamedNodeMap attrs = node.getAttributes();
    try {
      dom = EnvironmentDom.valueOf(node.getNodeName());
    } catch (java.lang.IllegalArgumentException ex) {
      return;
    }
    switch (dom) {
      case background:
        String type = attrs.getNamedItem("type").getTextContent();
        if (type.equals("color"))
          mainScene.setBackgroundColor(
              new Color3f(Converter.stringToFloatArray(node.getTextContent())));
        else if (type.equals("image")) {
          try {
            File bgFile = new File(attrs.getNamedItem("src").getTextContent());
            mainScene.setBackgroundFile(bgFile);
          } catch (NullPointerException ex) {
            System.err.println(ex.getMessage());
          }
        }
        break;
      case limits:
        float width = Float.parseFloat(attrs.getNamedItem("width").getTextContent());
        float height = Float.parseFloat(attrs.getNamedItem("height").getTextContent());
        float deepness = Float.parseFloat(attrs.getNamedItem("deepness").getTextContent());
        float thickness = Float.parseFloat(attrs.getNamedItem("thickness").getTextContent());
        mainScene.getEnvironmentLimits().updateLimits(width, height, deepness, thickness);
        //                mainScene.getEnvironmentLimits().calculateUniverseBounds();
        break;
      case light:
        type = attrs.getNamedItem("type").getTextContent();
        sceneLight = new SceneLight(LightType.valueOf(type));
        scene.addLightNode(sceneLight.getLight());
        mainScene.addLight(sceneLight);
        break;
      case object:
        type = attrs.getNamedItem("type").getTextContent();
        String src = attrs.getNamedItem("src").getTextContent();
        String id = attrs.getNamedItem("id").getTextContent();

        object =
            new MainSceneComponent(
                Integer.parseInt(id), ComponentType.valueOf(type), new File(src));
        object.loadType();
        if (attrs.getNamedItem("scale") != null) {
          String sca = attrs.getNamedItem("scale").getTextContent();
          object.setScale(Double.valueOf(sca));
        }
        if (attrs.getNamedItem("name") != null) {
          String name = attrs.getNamedItem("name").getTextContent();
          object.setComponentName(name);
        }
        scene.addViewGroup(object.getTransformGroup());
        mainScene.addComponent(object);
        break;
      case appearance:
        limitApp = new Appearance();
        break;
      case material:
        material = new Material();
        break;
      case texture:
        //                TextureLoader textureLoad = new
        // TextureLoader(attrs.getNamedItem("src").getTextContent(), null);
        //                ImageComponent2D textureIm = textureLoad.getScaledImage(128, 128);
        //                texture = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGB,
        // textureIm.getWidth(), textureIm.getHeight());
        //                texture.setImage(0, textureIm);
        //                limitApp.setTexture(texture);
        //                TextureAttributes textureAttr = new TextureAttributes();
        //                textureAttr.setTextureMode(TextureAttributes.REPLACE);
        //                limitApp.setTextureAttributes(textureAttr);
        //                TexCoordGeneration tcg = new
        // TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR,
        //
        // TexCoordGeneration.TEXTURE_COORDINATE_2);
        //                limitApp.setTexCoordGeneration(tcg);
        ////                limitApp.setTransparencyAttributes(new
        // TransparencyAttributes(TransparencyAttributes.NICEST, 0.7f));
        ////                mainScene.getEnvironmentLimits().setAppearance(EnvironmentLimits.RIGHT,
        // limitApp);
        //                mainScene.getEnvironmentLimits().setAppearance(limitApp);
        mainScene
            .getEnvironmentLimits()
            .setTexture(new File(attrs.getNamedItem("src").getTextContent()));
        boolean enabled = Boolean.parseBoolean(attrs.getNamedItem("enabled").getTextContent());
        mainScene.getEnvironmentLimits().setTextureFlag(enabled);
        break;
      case ambient:
        material.setAmbientColor(new Color3f(Converter.stringToFloatArray(node.getTextContent())));
        break;
      case emissive:
        material.setEmissiveColor(new Color3f(Converter.stringToFloatArray(node.getTextContent())));
        break;
      case diffuse:
        material.setDiffuseColor(new Color3f(Converter.stringToFloatArray(node.getTextContent())));
        break;
      case specular:
        material.setSpecularColor(new Color3f(Converter.stringToFloatArray(node.getTextContent())));
        break;
      case shininess:
        material.setShininess(Float.parseFloat(node.getTextContent()));
        limitApp.setMaterial(material);
        //                mainScene.getEnvironmentLimits().setAppearance(limitApp);
        break;
      case color:
        sceneLight.setColor(new Color3f(Converter.stringToFloatArray(node.getTextContent())));
        break;
      case position:
        sceneLight.setPosition(new Point3f(Converter.stringToFloatArray(node.getTextContent())));
        //                if(sceneLight instanceof PointLight){
        //                    PointLight pl = (PointLight)sceneLight;
        //                    pl.setPosition(new Point3f(Converter.stringToFloatArray
        //                                                    (node.getTextContent())));
        //                } else if(sceneLight instanceof DirectionalLight){
        //                    DirectionalLight dl = (DirectionalLight)sceneLight;
        //                    dl.setDirection(new Vector3f(Converter.stringToFloatArray
        //                                                    (node.getTextContent())));
        //                }
        break;
      case direction:
        sceneLight.setDirection(new Vector3f(Converter.stringToFloatArray(node.getTextContent())));
      case atenuation:
        //                PointLight pl = (PointLight)sceneLight;
        //                pl.setAttenuation(new Point3f(Converter.stringToFloatArray(
        //                                                     node.getTextContent())));
        sceneLight.setAttenuation(new Point3f(Converter.stringToFloatArray(node.getTextContent())));
        break;
      case objPos:
        object.setPosition(Converter.stringToDoubleArray(node.getTextContent()));
        break;
      case angles:
        double rotation[] = Converter.stringToDoubleArray(node.getTextContent());
        object.setRotation(rotation);
        break;
    }
  }