Ejemplo n.º 1
0
  private void createLoaderSceneGraph() {
    loaderBranchGroup = new BranchGroup();
    loaderBranchGroup.setCapability(BranchGroup.ALLOW_DETACH);
    loaderTransformGroup = new TransformGroup();
    loaderTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    addLights(loaderBranchGroup);
    Appearance loaderAppearance = new Appearance();
    Color3f loaderColor = new Color3f(0.5f, 0.5f, 0.5f);
    Material loaderMaterial =
        new Material(loaderColor, new Color3f(), loaderColor, loaderColor, 10);
    loaderMaterial.setLightingEnable(true);
    loaderAppearance.setMaterial(loaderMaterial);
    for (int i = 0; i < 20; i++) {
      Transform3D translate3d = new Transform3D();
      translate3d.setTranslation(new Vector3f(0f, 0f, 0.9f));
      TransformGroup translate = new TransformGroup(translate3d);

      Transform3D rotationY3d = new Transform3D();
      rotationY3d.rotY((Math.PI * 2 * i) / 20);
      TransformGroup rotateY = new TransformGroup(rotationY3d);
      rotateY.addChild(translate);

      Box box = new Box(0.1f, 0.1f, 0.1f, loaderAppearance);
      translate.addChild(box);
      loaderTransformGroup.addChild(rotateY);
    }
    loaderBranchGroup.addChild(loaderTransformGroup);
    sceneBranchGroup.addChild(loaderBranchGroup);
  }
 public void dealData(Sphere shape) {
   String userData = shape.getName();
   String[] str = userData.split(",");
   int state = Integer.parseInt(str[3]);
   float x = Float.parseFloat(str[0]);
   float y = Float.parseFloat(str[1]);
   float z = Float.parseFloat(str[2]);
   if (state == 0) {
     data[getXintValue(x)][getYintValue(y)] =
         data[getXintValue(x)][getYintValue(y)] | getZintValue(z);
     shape.setName(str[0] + "," + str[1] + "," + str[2] + "," + 1);
     Appearance appear = new Appearance();
     Material mater = new Material();
     mater.setDiffuseColor(new Color3f(Color.red));
     appear.setMaterial(mater);
     shape.setAppearance(appear);
     jta.setText(getDataString());
   } else {
     data[getXintValue(x)][getYintValue(y)] =
         data[getXintValue(x)][getYintValue(y)] & (~getZintValue(z));
     shape.setName(str[0] + "," + str[1] + "," + str[2] + "," + 0);
     Appearance appear = new Appearance();
     Material mater = new Material();
     mater.setDiffuseColor(new Color3f(Color.black));
     appear.setMaterial(mater);
     shape.setAppearance(appear);
     jta.setText(getDataString());
   }
 }
Ejemplo n.º 3
0
  /**
   * Method to set color in 3D. Since it must set 3 different colors, it is a function called by
   * setOtherAppearanceValues.
   *
   * @param material material to change if available
   * @param color
   */
  public void set3DColor(Object material, Color color) {
    Material mat = (material == null) ? getMaterial() : (Material) material;

    Color3f objColor = new Color3f(color);
    mat.setDiffuseColor(objColor);
    // mat.setSpecularColor(objColor);
    mat.setAmbientColor(objColor);
    if (getColoringAttributes() != null) getColoringAttributes().setColor(objColor);
  }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
0
 private Appearance makeMaterial(float r, float g, float b, float transparency) {
   Appearance appearance = new Appearance();
   Color3f color3f = new Color3f(r, g, b);
   Material material = new Material(color3f, new Color3f(0f, 0f, 0f), color3f, color3f, 10f);
   material.setLightingEnable(true);
   appearance.setMaterial(material);
   if (!Float.isNaN(transparency)) {
     TransparencyAttributes ta = new TransparencyAttributes();
     ta.setTransparencyMode(TransparencyAttributes.NICEST);
     ta.setTransparency(transparency);
     appearance.setTransparencyAttributes(ta);
   }
   return appearance;
 }
Ejemplo n.º 6
0
  public MoonSphere() {
    Color3f eColor = new Color3f(1.0f, 1.0f, 1.0f);

    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3d(0, -100, 0));
    pos.setTransform(t3d);
    addChild(pos);

    // Create a Sphere object, generate one copy of the sphere,
    // and add it into the scene graph.
    Material m = new Material(new Color3f(), eColor, new Color3f(), new Color3f(), 1.0f);
    Appearance a = new Appearance();
    m.setLightingEnable(true);
    a.setMaterial(m);
    Sphere sph = new Sphere(2.0f, Primitive.GENERATE_NORMALS, 80, a);
    pos.addChild(sph);

    pos.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
  }
Ejemplo n.º 7
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;
  }
 public MyMousePickBehavior(Canvas3D canvas, BranchGroup root, Bounds bounds, JTextArea jta) {
   super(canvas, root, bounds);
   this.jta = jta;
   this.setSchedulingBounds(bounds);
   root.addChild(this);
   pickCanvas.setMode(PickTool.GEOMETRY);
   appear = new Appearance();
   mater = new Material();
   mater.setDiffuseColor(new Color3f(Color.red));
   appear.setMaterial(mater);
 }
Ejemplo n.º 9
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;
  }
Ejemplo n.º 10
0
  private void createTriangle() {
    int[] stripCount = {3};

    GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
    gi.setCoordinates(points);
    gi.setStripCounts(stripCount);

    NormalGenerator ng = new NormalGenerator();
    ng.generateNormals(gi);
    gi.recomputeIndices();

    Stripifier st = new Stripifier();
    st.stripify(gi);
    gi.recomputeIndices();

    Appearance appearance = new Appearance();
    Material material = new Material();
    material.setAmbientColor(new Color3f(Color.GREEN));
    appearance.setMaterial(material);

    shape3D = new Shape3D();
    shape3D.setGeometry(gi.getGeometryArray());
    shape3D.setAppearance(appearance);
  }
  public static void writeMeshToObj(String objPath, String mtlPath, Mesh mesh) throws IOException {
    // obj
    PrintWriter writer = new PrintWriter(new FileWriter(objPath));
    Vector3d[] vertices = mesh.getLocalVertices();
    Triangle[] triangles = mesh.getLocalTriangles();

    writer.println("mtllib " + mtlPath.substring(mtlPath.lastIndexOf(File.separator) + 1));
    for (Vector3d vertex : vertices) {
      writer.println("v " + vertex.x + " " + vertex.y + " " + vertex.z);
    }
    writer.println("usemtl Material");
    for (Triangle triangle : triangles) {
      writer.println("f " + (triangle.v0 + 1) + " " + (triangle.v1 + 1) + " " + (triangle.v2 + 1));
    }

    writer.close();

    // mtl
    writer = new PrintWriter(new FileWriter(mtlPath));
    Material material = mesh.getShape().getAppearance().getMaterial();
    Color3f ambientColour = new Color3f();
    material.getAmbientColor(ambientColour);
    Color3f diffuseColour = new Color3f();
    material.getDiffuseColor(diffuseColour);
    Color3f specularColour = new Color3f();
    material.getSpecularColor(specularColour);
    Color3f emissiveColour = new Color3f();
    material.getEmissiveColor(emissiveColour);
    float shininess = material.getShininess();

    writer.println("newmtl Material");
    writer.println("Ns " + shininess);
    writer.println("Ka " + ambientColour.x + " " + ambientColour.y + " " + ambientColour.z);
    writer.println("Kd " + diffuseColour.x + " " + diffuseColour.y + " " + diffuseColour.z);
    writer.println("Ks " + specularColour.x + " " + specularColour.y + " " + specularColour.z);
    writer.close();
  }
Ejemplo n.º 12
0
 /** Creates the objects on the scene, adds behavior effects and so on. */
 public void addChildren() {
   BranchGroup group = new BranchGroup(); // Root group of the applet.
   Appearance ap = new Appearance(); // Configurate a material for the branch.
   Material mat = new Material();
   mat.setAmbientColor(new Color3f(43 / 255f, 23 / 255f, 5 / 255f)); // Brown.
   ap.setMaterial(mat);
   TransformGroup tg =
       new TransformGroup(); // This will actually store all leaf nodes because we want them to
   // rotate with mouse movements.
   tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
   tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
   BranchShape bs =
       new BranchShape(
           new Branch(
               6,
               0f,
               -0f,
               0.9f,
               new Random(1253312432),
               6,
               0.1f,
               new Point3f(0, -2, 0),
               new Vector3f(0, 1, 0),
               0),
           ap,
           0,
           10);
   bs.addChildren(10, 0.5f, 0.2f, 0.3f, 0.3f, 0.5f, 4, -0.3f, 0.3f, 0.1f, 1.2f, ap);
   tg.addChild(bs);
   bs =
       new BranchShape(
           new Branch(
               6,
               0.0f,
               -0.0f,
               0.9f,
               new Random(125462432),
               6,
               0.1f,
               new Point3f(0, -2, 0),
               new Vector3f(0, 1, 0),
               0),
           ap,
           0,
           10);
   bs.addChildren(10, 0.5f, 0.2f, 0.3f, 0.3f, 0.5f, 4, -0.3f, 0.3f, 0.1f, 1.2f, ap);
   tg.addChild(bs);
   bs =
       new BranchShape(
           new Branch(
               6,
               0.0f,
               -0.0f,
               0.9f,
               new Random(3755678),
               6,
               0.1f,
               new Point3f(0, -2, 0),
               new Vector3f(0, 1, 0),
               0),
           ap,
           0,
           10);
   bs.addChildren(10, 0.5f, 0.2f, 0.3f, 0.3f, 0.5f, 4, -0.3f, 0.3f, 0.1f, 1.2f, ap);
   tg.addChild(bs);
   bs =
       new BranchShape(
           new Branch(
               6,
               0.0f,
               -0.0f,
               0.9f,
               new Random(8765683),
               6,
               0.1f,
               new Point3f(0, -2, 0),
               new Vector3f(0, 1, 0),
               0),
           ap,
           0,
           10);
   bs.addChildren(10, 0.5f, 0.2f, 0.3f, 0.3f, 0.5f, 4, -0.3f, 0.3f, 0.1f, 1.2f, ap);
   tg.addChild(bs);
   // Four branches initialized by three different roots for Random.
   MouseRotate mr = new MouseRotate(tg);
   mr.setSchedulingBounds(new BoundingSphere(new Point3d(), 100));
   mr.setFactor(0.005, 0.001); // Slow rotation.
   tg.addChild(mr);
   group.addChild(tg);
   Color3f light1Color =
       new Color3f(1f, 1f, 1f); // Just to see the model, as a temporary solution.
   BoundingSphere bounds = new BoundingSphere(new Point3d(), 100);
   AmbientLight light1 = new AmbientLight(light1Color);
   light1.setInfluencingBounds(bounds); // Some more j3d magic.
   group.addChild(light1);
   universe.addBranchGraph(group);
 }
Ejemplo n.º 13
0
  private void setOtherAppearanceValues(int mode, float factor, Color color, boolean visible) {
    // Transparency values
    TransparencyAttributes ta = new TransparencyAttributes(mode, factor);
    ta.setCapability(TransparencyAttributes.ALLOW_VALUE_READ);
    ta.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
    ta.setCapability(TransparencyAttributes.ALLOW_MODE_READ);
    ta.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    setTransparencyAttributes(ta);

    setCapability(ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
    setCapability(ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
    // For highlight
    setCapability(ALLOW_MATERIAL_READ);
    setCapability(ALLOW_MATERIAL_WRITE);
    // For visibility
    setCapability(ALLOW_RENDERING_ATTRIBUTES_READ);
    setCapability(ALLOW_RENDERING_ATTRIBUTES_WRITE);
    // Color
    setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
    setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);

    // Adding Rendering attributes to access visibility flag if layer is available
    if (layer != null) {
      RenderingAttributes ra = new RenderingAttributes();
      ra.setCapability(RenderingAttributes.ALLOW_VISIBLE_READ);
      ra.setCapability(RenderingAttributes.ALLOW_VISIBLE_WRITE);
      ra.setCapability(RenderingAttributes.ALLOW_DEPTH_ENABLE_READ);
      ra.setCapability(RenderingAttributes.ALLOW_DEPTH_ENABLE_WRITE);
      ra.setVisible(visible);
      setRenderingAttributes(ra);
      if (mode != TransparencyAttributes.NONE) ra.setDepthBufferEnable(true);
    }

    // Set up the polygon attributes
    // PolygonAttributes pa = new PolygonAttributes();
    // pa.setCullFace(PolygonAttributes.CULL_NONE);
    // pa.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    // setPolygonAttributes(pa);

    // TextureAttributes texAttr = new TextureAttributes();
    // texAttr.setTextureMode(TextureAttributes.MODULATE);
    // texAttr.setTextureColorTable(pattern);
    // setTextureAttributes(texAttr);

    // LineAttributes lineAttr = new LineAttributes();
    // lineAttr.setLineAntialiasingEnable(true);
    // setLineAttributes(lineAttr);

    // Adding to internal material
    //				Material mat = new Material(objColor, black, objColor, white, 70.0f);
    if (color != null) {
      Color3f objColor = new Color3f(color);
      // Emissive is black and specular is plastic!
      // Color3f specular = new Color3f(color.brighter());
      Material mat =
          new Material(objColor, J3DUtils.black, objColor, J3DUtils.plastic /*J3DUtils.white*/, 17);
      mat.setLightingEnable(true);
      mat.setCapability(Material.ALLOW_COMPONENT_READ);
      mat.setCapability(Material.ALLOW_COMPONENT_WRITE);
      mat.setCapability(Material.AMBIENT_AND_DIFFUSE);
      setMaterial(mat);
    }
  }
Ejemplo n.º 14
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;
    }
  }
  /**
   * Build the 3D scene on a Java3D enabled draw.
   *
   * @param objRot the transform object
   */
  @Override
  public void buildJava3DScene(TransformGroup objRot) {
    if (objRot == null) return;

    AtomInfo ai = AtomInfo.getInstance();
    double xMin = gridProperty.getBoundingBox().getUpperLeft().getX(),
        yMin = gridProperty.getBoundingBox().getUpperLeft().getY(),
        zMin = gridProperty.getBoundingBox().getUpperLeft().getZ();
    double f1, f2, f3;
    double[] functionValues = gridProperty.getFunctionValues();
    double incInX = gridProperty.getXIncrement(),
        incInY = gridProperty.getYIncrement(),
        incInZ = gridProperty.getZIncrement();
    int pointsAlongX = gridProperty.getNoOfPointsAlongX(),
        pointsAlongY = gridProperty.getNoOfPointsAlongY(),
        pointsAlongZ = gridProperty.getNoOfPointsAlongZ();

    int i, j, k;

    Atom atom;
    String symbol;
    SphereTriSetGenerator stsg;
    Point3DI point1, point2, point3;

    int noOfAtoms = molecule.getNumberOfAtoms();
    int pointsAlongSlice = pointsAlongY * pointsAlongZ;
    HashMap<String, SphereTriSetGenerator> triSetTableTmp =
        new HashMap<String, SphereTriSetGenerator>(5);

    if (noOfAtoms > largeMoleculeSize) triSetTableTmp = triSetTable;

    Matrix3D tmat = new Matrix3D();
    tmat.unit();

    TransformGroup surfaceScene = new TransformGroup();

    for (int atomIndex = 0; atomIndex < noOfAtoms; atomIndex++) {
      atom = molecule.getAtom(atomIndex);

      // check to see if we are with in the bounding box?
      if (!gridProperty.getBoundingBox().contains(atom.getAtomCenter())) continue;

      symbol = atom.getSymbol();

      if ((stsg = triSetTableTmp.get(symbol)) == null) {
        stsg =
            new SphereTriSetGenerator(
                atom.getAtomCenter(), ai.getVdwRadius(symbol), numberOfSphereDivisions);
        triSetTableTmp.put(symbol, stsg);
      } // end if

      // setup color
      Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
      Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f);
      Color3f objColor = new Color3f(colorMap.getInterpolatedColor(currentFunctionValue));

      Appearance app = new Appearance();
      Material mm = new Material(objColor, eColor, objColor, sColor, 100.0f);
      mm.setLightingEnable(true);
      app.setMaterial(mm);

      if (fillTransperency > 0) {
        app.setTransparencyAttributes(
            new TransparencyAttributes(
                TransparencyAttributes.NICEST, (float) (fillTransperency / 255.0)));
      } // end if

      int idx = 0;

      stsg.setTransform(tmat);
      stsg.setCenter(atom.getAtomCenter());

      ArrayList<Point3d> validPoints = new ArrayList<Point3d>();
      ArrayList<Color3f> validColors = new ArrayList<Color3f>();

      while (true) {
        Triangle t = stsg.nextVisibleTriSet();

        if (t == null) break;

        // first point
        point1 = t.getPoint1();
        i = (int) Math.round(Math.abs((point1.getX() - xMin) / incInX));
        j = (int) Math.round(Math.abs((point1.getY() - yMin) / incInY));
        k = (int) Math.round(Math.abs((point1.getZ() - zMin) / incInZ));

        if (i > pointsAlongX - 1) i = pointsAlongX - 1;
        if (j > pointsAlongY - 1) j = pointsAlongY - 1;
        if (k > pointsAlongZ - 1) k = pointsAlongZ - 1;

        f1 = functionValues[(i * pointsAlongSlice) + (j * pointsAlongZ) + k];

        // second point
        point2 = t.getPoint2();
        i = (int) Math.round(Math.abs((point2.getX() - xMin) / incInX));
        j = (int) Math.round(Math.abs((point2.getY() - yMin) / incInY));
        k = (int) Math.round(Math.abs((point2.getZ() - zMin) / incInZ));

        if (i > pointsAlongX - 1) i = pointsAlongX - 1;
        if (j > pointsAlongY - 1) j = pointsAlongY - 1;
        if (k > pointsAlongZ - 1) k = pointsAlongZ - 1;

        f2 = functionValues[(i * pointsAlongSlice) + (j * pointsAlongZ) + k];

        // third point
        point3 = t.getPoint3();
        i = (int) Math.round(Math.abs((point3.getX() - xMin) / incInX));
        j = (int) Math.round(Math.abs((point3.getY() - yMin) / incInY));
        k = (int) Math.round(Math.abs((point3.getZ() - zMin) / incInZ));

        if (i > pointsAlongX - 1) i = pointsAlongX - 1;
        if (j > pointsAlongY - 1) j = pointsAlongY - 1;
        if (k > pointsAlongZ - 1) k = pointsAlongZ - 1;

        f3 = functionValues[(i * pointsAlongSlice) + (j * pointsAlongZ) + k];

        validPoints.add(new Point3d(point1.getX(), point1.getY(), point1.getZ()));
        validColors.add(new Color3f(colorMap.getInterpolatedColor(f1)));

        validPoints.add(new Point3d(point2.getX(), point2.getY(), point2.getZ()));
        validColors.add(new Color3f(colorMap.getInterpolatedColor(f2)));

        validPoints.add(new Point3d(point3.getX(), point3.getY(), point3.getZ()));
        validColors.add(new Color3f(colorMap.getInterpolatedColor(f3)));
      } // end while

      TriangleArray ta =
          new TriangleArray(validPoints.size(), GeometryArray.COORDINATES | GeometryArray.COLOR_3);

      for (idx = 0; idx < validPoints.size(); idx++) {
        ta.setCoordinate(idx, validPoints.get(idx));
        ta.setColor(idx, validColors.get(idx));
      }

      validColors = null;
      validPoints = null;

      GeometryInfo gi = new GeometryInfo(ta);
      gi.compact();
      gi.recomputeIndices();

      // generate normals
      NormalGenerator ng = new NormalGenerator();
      ng.generateNormals(gi);

      // stripify
      Stripifier st = new Stripifier();
      st.stripify(gi);

      surfaceScene.addChild(new Shape3D(gi.getGeometryArray(), app));
    } // end for

    if (showBoundingBox) {
      boundingBox.setTransform(transform);
      boundingBox.applyTransforms();
      (new ScreenCuboidJ3D(boundingBox)).buildJava3DScene(surfaceScene);
    } // end if

    objRot.addChild(surfaceScene);
  }