Beispiel #1
0
  /**
   * Create geometry for horizontal segments
   *
   * @param offset Should we offset vertically
   * @param offsetField A full SFVec3f that we only use the height off for offset
   */
  private X3DNode[] createSegmentGeom(
      X3DExecutionContext mainScene,
      X3DNode appearance,
      MFInt32 geomIndicesField,
      MFNode geometryField,
      MFFloat heightField,
      MFVec3f startField,
      MFVec3f endField,
      boolean offset,
      MFFloat offsetField,
      int vertices,
      int shapesToCreate,
      int panelsPerShape,
      boolean sRepeatPerMeter,
      boolean tRepeatPerMeter,
      float sMeterMult,
      float tMeterMult) {

    float[] post_coord;
    float[] post_normal;
    float[] post_texCoord;
    int[] post_index;
    X3DNode[] ret_val = new X3DNode[shapesToCreate];
    int shape_idx = 0;
    float[] start = new float[3];
    float[] end = new float[3];
    int num = 0;

    float sRepeat;
    float tRepeat;

    for (int n = 0; n < shapesToCreate; n++) {

      int[] index = new int[2 * 3 * vertices];
      float[] point = new float[4 * 3 * vertices];
      float[] tc = new float[4 * 2 * vertices];
      int iidx = 0;
      int pidx = 0;
      int tidx = 0;
      float height;
      float offsetVal = 0;

      // Panel Shape
      X3DNode panel_shape = mainScene.createNode("Shape");
      SFNode shape_appearance = (SFNode) (panel_shape.getField("appearance"));
      shape_appearance.setValue(appearance);

      SFNode shape_geometry = (SFNode) (panel_shape.getField("geometry"));
      X3DNode its = mainScene.createNode("IndexedTriangleSet");
      SFBool its_solid = (SFBool) its.getField("solid");
      its_solid.setValue(false);

      X3DNode coord = mainScene.createNode("Coordinate");
      SFNode its_coord = (SFNode) (its.getField("coord"));
      MFVec3f point_field = (MFVec3f) coord.getField("point");
      X3DNode normal = mainScene.createNode("Normal");
      SFNode its_normal = (SFNode) (its.getField("normal"));
      X3DNode texcoord = mainScene.createNode("TextureCoordinate");
      SFNode its_texcoord = (SFNode) (its.getField("texCoord"));
      MFVec2f tcpoint_field = (MFVec2f) texcoord.getField("point");
      MFInt32 its_index = (MFInt32) (its.getField("index"));

      for (int i = 0; i < panelsPerShape; i++) {

        startField.get1Value(num, start);
        endField.get1Value(num, end);
        height = heightField.get1Value(num);

        if (sRepeatPerMeter) {
          // calculate the length of the panel from start to end
          float x_delta = end[0] - start[0];
          float y_delta = end[1] - start[1];
          float z_delta = end[2] - start[2];
          float length =
              (float) Math.sqrt(x_delta * x_delta + y_delta * y_delta + z_delta * z_delta);
          // the s repeat factor is the length, in meters
          sRepeat = length * sMeterMult;
        } else {
          // the s repeat factor is 1 per panel
          sRepeat = 1.0f;
        }

        if (tRepeatPerMeter) {
          // the t repeat factor is the height, in meters
          tRepeat = height * tMeterMult;
        } else {
          // the t repeat factor is 1 per panel
          tRepeat = 1.0f;
        }
        // System.out.println( "sRepeat = "+ sRepeat +", tRepeat = "+ tRepeat );
        if (offset) {
          offsetVal = offsetField.get1Value(num);
        }

        num++;

        index[iidx++] = i * 4;
        index[iidx++] = i * 4 + 1;
        index[iidx++] = i * 4 + 2;
        index[iidx++] = i * 4 + 1;
        index[iidx++] = i * 4 + 3;
        index[iidx++] = i * 4 + 2;

        point[pidx++] = start[0];
        point[pidx++] = offsetVal + height + start[1];
        point[pidx++] = start[2];

        point[pidx++] = start[0];
        point[pidx++] = offsetVal + 0 + start[1];
        point[pidx++] = start[2];

        point[pidx++] = end[0];
        point[pidx++] = offsetVal + height + end[1];
        point[pidx++] = end[2];

        point[pidx++] = end[0];
        point[pidx++] = offsetVal + 0 + end[1];
        point[pidx++] = end[2];

        tc[tidx++] = 0;
        tc[tidx++] = 0;
        tc[tidx++] = 0;
        tc[tidx++] = tRepeat;
        tc[tidx++] = sRepeat;
        tc[tidx++] = 0;
        tc[tidx++] = sRepeat;
        tc[tidx++] = tRepeat;
      }

      // System.out.println("Points: " + java.util.Arrays.toString(point));
      // System.out.println("Index: " + java.util.Arrays.toString(index));
      // System.out.println("TexCoord: " + java.util.Arrays.toString(tc));

      if (CREATE_PANELS) {
        point_field.setValue(point.length / 3, point);
        tcpoint_field.setValue(tc.length / 2, tc);
        its_coord.setValue(coord);
        its_texcoord.setValue(texcoord);
        its_index.setValue(index.length, index);

        shape_geometry.setValue(its);
      }

      // System.out.println("Placing panel at: " + shape_idx);

      ret_val[shape_idx++] = panel_shape;
    }

    return ret_val;
  }
 /**
  * Set the skyAngle field.
  *
  * @param val The float[] to set.
  */
 public void setSkyAngle(float[] val) {
   if (skyAngle == null) {
     skyAngle = (MFFloat) getField("skyAngle");
   }
   skyAngle.setValue(val.length, val);
 }
 /**
  * Set the groundAngle field.
  *
  * @param val The float[] to set.
  */
 public void setGroundAngle(float[] val) {
   if (groundAngle == null) {
     groundAngle = (MFFloat) getField("groundAngle");
   }
   groundAngle.setValue(val.length, val);
 }
 /**
  * Return the number of MFFloat items in the skyAngle field.
  *
  * @return the number of MFFloat items in the skyAngle field.
  */
 public int getNumSkyAngle() {
   if (skyAngle == null) {
     skyAngle = (MFFloat) getField("skyAngle");
   }
   return (skyAngle.getSize());
 }
 /**
  * Return the number of MFFloat items in the groundAngle field.
  *
  * @return the number of MFFloat items in the groundAngle field.
  */
 public int getNumGroundAngle() {
   if (groundAngle == null) {
     groundAngle = (MFFloat) getField("groundAngle");
   }
   return (groundAngle.getSize());
 }