Esempio n. 1
0
  private static IndexedFaceSet bigMesh(int discretization, double cameraHeight, double size) {
    int n = discretization;
    QuadMeshFactory factory = new QuadMeshFactory();
    factory.setULineCount(n);
    factory.setVLineCount(n);
    factory.setGenerateEdgesFromFaces(true);
    factory.setGenerateTextureCoordinates(false);
    double totalAngle = Math.atan(size / cameraHeight);
    double dt = 2 * totalAngle / (n - 1);
    double[] normal = new double[] {0, 0, -1};
    double[][] normals = new double[n * n][];
    Arrays.fill(normals, normal);

    double[][][] coords = new double[n][n][3];

    for (int i = 0; i < n; i++) {
      double y = cameraHeight * Math.tan(-totalAngle + i * dt);
      for (int j = 0; j < n; j++) {
        coords[i][j][0] = cameraHeight * Math.tan(-totalAngle + j * dt);
        coords[i][j][1] = y;
      }
    }

    double[][][] texCoords = new double[n][n][2];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        texCoords[i][j][0] = coords[i][j][0];
        texCoords[i][j][1] = coords[i][j][1];
      }
    }

    factory.setVertexCoordinates(coords);
    factory.setVertexNormals(normals);
    factory.setVertexTextureCoordinates(texCoords);
    factory.update();

    return factory.getIndexedFaceSet();
  }
Esempio n. 2
0
  @Override
  public void addMesh(double[][][] vertices, double[][][] normals, AppearanceState appearance) {

    if (vertices.length == 0) return;
    int l = vertices[0].length;
    for (int i = 0; i < vertices.length; ++i)
      if (vertices[i].length == 0 || vertices[i].length != l) return;

    SceneGraphComponent sgc = SceneGraphUtility.createFullSceneGraphComponent();
    QuadMeshFactory qmf = new QuadMeshFactory();

    qmf.setVLineCount(vertices.length);
    qmf.setULineCount(l);

    qmf.setClosedInUDirection(false);
    qmf.setClosedInVDirection(false);
    qmf.setVertexCoordinates(vertices);
    if (normals == null) {
      qmf.setGenerateFaceNormals(true);
      // qmf.setGenerateVertexNormals(true);
    } else {
      qmf.setVertexNormals(normals);
    }
    qmf.setGenerateTextureCoordinates(false);
    qmf.setGenerateEdgesFromFaces(true);
    qmf.setEdgeFromQuadMesh(true);

    Color[] colors = new Color[vertices.length * l];
    for (int i = 0; i < vertices.length * l; ++i) {
      colors[i] = appearance.getColor();
    }

    qmf.setVertexColors(colors);

    qmf.update();
    sgc.setGeometry(qmf.getGeometry());

    DefaultGeometryShader dgs =
        ShaderUtility.createDefaultGeometryShader(sgc.getAppearance(), true);

    dgs.setShowLines(true);
    dgs.setShowPoints(true);
    dgs.setShowFaces(true);

    dgs.createPointShader("my");

    MyLineShader ls = (MyLineShader) dgs.createLineShader("my");
    ls.setDiffuseColor(appearance.getColor());
    ls.setLineType(0);

    DefaultPolygonShader dps = (DefaultPolygonShader) dgs.getPolygonShader();

    dps.setTransparency(1 - appearance.getOpacity());

    sceneMeshes.addChild(sgc);
  }