Esempio n. 1
0
  public void addLinesAroundRegion(TransformGroup tg) {
    Color3f x = new Color3f(Color.green.brighter().brighter());
    Color3f y = new Color3f(Color.yellow.brighter().brighter());
    Color3f z = new Color3f(Color.red.brighter().brighter());

    LineArray wireframe = new LineArray(12 * 2, GeometryArray.COORDINATES | GeometryArray.COLOR_3);

    wireframe.setCapability(LineArray.ALLOW_COLOR_WRITE);
    wireframe.setCapability(LineArray.ALLOW_COORDINATE_READ);
    wireframe.setCapability(LineArray.ALLOW_COUNT_READ);
    ArrayList<Point3f> vx = getVertices();

    // Add lines parallel to x
    wireframe.setCoordinate(0, vx.get(0));
    wireframe.setCoordinate(1, vx.get(2));
    wireframe.setCoordinate(2, vx.get(1));
    wireframe.setCoordinate(3, vx.get(3));

    wireframe.setCoordinate(4, vx.get(4));
    wireframe.setCoordinate(5, vx.get(6));
    wireframe.setCoordinate(6, vx.get(5));
    wireframe.setCoordinate(7, vx.get(7));

    for (int i = 0; i < 8; i++) wireframe.setColor(i, x);

    // Add lines parallel to y
    wireframe.setCoordinate(8, vx.get(0));
    wireframe.setCoordinate(9, vx.get(4));
    wireframe.setCoordinate(10, vx.get(1));
    wireframe.setCoordinate(11, vx.get(5));

    wireframe.setCoordinate(12, vx.get(2));
    wireframe.setCoordinate(13, vx.get(6));
    wireframe.setCoordinate(14, vx.get(3));
    wireframe.setCoordinate(15, vx.get(7));

    for (int i = 8; i < 16; i++) wireframe.setColor(i, y);

    // Add lines parallel to z
    wireframe.setCoordinate(16, vx.get(0));
    wireframe.setCoordinate(17, vx.get(1));
    wireframe.setCoordinate(18, vx.get(2));
    wireframe.setCoordinate(19, vx.get(3));
    wireframe.setCoordinate(20, vx.get(4));
    wireframe.setCoordinate(21, vx.get(5));
    wireframe.setCoordinate(22, vx.get(6));
    wireframe.setCoordinate(23, vx.get(7));

    for (int i = 16; i < 24; i++) wireframe.setColor(i, z);

    Shape3D shape = new Shape3D(wireframe);
    tg.addChild(shape);
  }
Esempio n. 2
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);
  }