示例#1
0
  /**
   * Simple algorithm to add or remove an edge from the selection Ideas: 1. Use one shape per quad
   * => easy, but can become very fast too big to fit in memory. => pb: flicker when adding /
   * removing because the scene is detached 2. Use only one shape, modify geometry TODO: pre-create
   * an empty shape to avoid initial flicker
   *
   * @param on
   * @param p
   * @param u
   * @param v
   * @param groupIdx2
   */
  protected void toggleSelectedEdge(boolean on, SelectionEdge se) {
    if (on) {
      // add the given edge to the list
      if (edgeSelection.contains(se)) return; // already in
      edgeSelection.add(se);
    } else {
      // remove the given edge from the list
      if (!edgeSelection.contains(se)) return; // not present
      edgeSelection.remove(se);
      if (edgeSelection.size() == 0) {
        LineArray la = (LineArray) edgeSelectionShape.getGeometry();
        la.setValidVertexCount(0);
        return;
      }
    }
    // Use in-memory arrays instead of NIO because edgeSelection should not
    // be too big
    // => faster
    LineArray la =
        new LineArray(
            edgeSelection.size() * 2,
            GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.BY_REFERENCE);
    double[] coords = new double[edgeSelection.size() * 2 * 3];
    float[] colors = new float[edgeSelection.size() * 2 * 3];

    for (int i = 0; i < coords.length; i += 6) {
      SelectionEdge edge = edgeSelection.get(i / 6);
      edge.updateCoords(grid, coords, i);
      edge.updateColors(colors, i);
    }
    la.setCoordRefDouble(coords);
    la.setColorRefFloat(colors);
    la.setCapability(GeometryArray.ALLOW_COUNT_WRITE);
    // update edgeSelection Shape with the new edgeSelection list
    if (edgeSelectionShape == null) {
      Appearance a = new Appearance();
      // PolygonAttributes pa = new
      // PolygonAttributes(PolygonAttributes.POLYGON_LINE,
      // PolygonAttributes.CULL_NONE, 0);
      // pa.setPolygonOffset(1); // above edges
      // pa.setPolygonOffsetFactor(1);
      LineAttributes lat = new LineAttributes();
      lat.setLineWidth(2.0f);
      lat.setLineAntialiasingEnable(true);
      a.setLineAttributes(lat);
      // a.setPolygonAttributes(pa);
      edgeSelectionShape = new Shape3D(la, a);
      edgeSelectionShape.setUserData(this);
      edgeSelectionShape.setPickable(false);
      edgeSelectionShape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
      edgeSelectionShape.setCapability(Shape3D.ALLOW_GEOMETRY_READ);

      BranchGroup bg = new BranchGroup();
      bg.addChild(edgeSelectionShape);
      addChild(bg);
    } else edgeSelectionShape.setGeometry(la);
  }
示例#2
0
  /**
   * Method to access appearance for cells in 3D
   *
   * @param initValue no null if appearance has to be changed according to user value. Using this
   *     mechanism to avoid the creation of new Boolean() just for the checking
   */
  public static void setCellAppearanceValues(Object initValue) {
    Color3f userColor = new Color3f(new Color(User.getColor(User.ColorPrefType.INSTANCE_3D)));

    if (cellApp == null) {
      cellApp = new J3DAppearance(TransparencyAttributes.SCREEN_DOOR, 0, null);

      RenderingAttributes ra = new RenderingAttributes();
      ra.setCapability(RenderingAttributes.ALLOW_VISIBLE_READ);
      ra.setCapability(RenderingAttributes.ALLOW_VISIBLE_WRITE);
      ra.setVisible(J3DUtils.is3DCellBndOn());
      cellApp.setRenderingAttributes(ra);

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

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

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

      // ** Data for cells
      ColoringAttributes ca = new ColoringAttributes();
      ca.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
      ca.setCapability(ColoringAttributes.ALLOW_COLOR_READ);
      ca.setColor(userColor);
      cellApp.setColoringAttributes(ca);
      cellApp.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
      cellApp.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
    } else if (initValue == null) // redoing color only when it was changed in GUI
    {
      ColoringAttributes ca = cellApp.getColoringAttributes();
      Color3f curColor = new Color3f();
      ca.getColor(curColor);
      if (!userColor.equals(curColor)) ca.setColor(userColor);
    }
  }
示例#3
0
  /**
   * Method to access appearance of axes in 3D
   *
   * @param initValue false if appearance has to be changed according to user value
   */
  public static void setAxisAppearanceValues(Object initValue) {
    int[] colors = J3DUtils.get3DColorAxes();

    for (int i = 0; i < axisApps.length; i++) {
      Color userColor = new Color(colors[i]);

      if (axisApps[i] == null) {
        axisApps[i] = new J3DAppearance(TransparencyAttributes.NONE, 0.5f, userColor);

        // Turn off face culling so we can see the back side of the labels
        // (since we're not using font extrusion)
        PolygonAttributes polygonAttributes = new PolygonAttributes();
        polygonAttributes.setCullFace(PolygonAttributes.CULL_NONE);

        // Make the axis lines 2 pixels wide
        LineAttributes lineAttributes = new LineAttributes();
        lineAttributes.setLineWidth(3.0f);

        ColoringAttributes colorAttrib = new ColoringAttributes();
        colorAttrib.setColor(new Color3f(userColor));
        colorAttrib.setCapability(ColoringAttributes.ALLOW_COLOR_READ);
        colorAttrib.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
        axisApps[i].setColoringAttributes(colorAttrib);
        axisApps[i].setPolygonAttributes(polygonAttributes);
        axisApps[i].setLineAttributes(lineAttributes);
        axisApps[i].setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
        axisApps[i].setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);

        RenderingAttributes ra = new RenderingAttributes();
        ra.setCapability(RenderingAttributes.ALLOW_VISIBLE_READ);
        ra.setCapability(RenderingAttributes.ALLOW_VISIBLE_WRITE);
        ra.setVisible(J3DUtils.is3DAxesOn());
        axisApps[i].setRenderingAttributes(ra);
      } else if (initValue == null) // redoing color only when it was changed in GUI
      axisApps[i].set3DColor(null, userColor);
    }
  }