Example #1
0
 private void renderMeshes() {
   for (int i = bsRenderMesh.nextSetBit(0); i >= 0; i = bsRenderMesh.nextSetBit(i + 1)) {
     if (meshes[i].normalsTemp != null) {
       meshes[i].setNormixes(meshes[i].normalsTemp);
       meshes[i].normalsTemp = null;
     } else if (meshes[i].normixes == null) {
       meshes[i].initialize(T.frontlit, null, null);
     }
     renderMesh(meshes[i]);
   }
 }
  @Override
  protected void outputSurface(
      P3[] vertices,
      V3[] normals,
      short[] colixes,
      int[][] indices,
      short[] polygonColixes,
      int nVertices,
      int nPolygons,
      int nFaces,
      BS bsPolygons,
      int faceVertexMax,
      short colix,
      List<Short> colorList,
      Map<Short, Integer> htColixes,
      P3 offset) {
    if (polygonColixes != null) {
      boolean isAll = (bsPolygons == null);
      int i0 = (isAll ? nPolygons - 1 : bsPolygons.nextSetBit(0));
      for (int i = i0; i >= 0; i = (isAll ? i - 1 : bsPolygons.nextSetBit(i + 1))) {
        // if ((p++) % 10 == 0)
        //  output("\n");
        output("polygon { 4\n");
        for (int j = 0; j <= 3; j++) outputVertex(vertices[indices[i][j % 3]], offset);
        output("\n");
        output("pigment{rgbt<" + color4(colix = polygonColixes[i]) + ">}\n");
        output("  translucentFinish(" + translucencyFractionalFromColix(colix) + ")\n");
        output("  check_shadow()\n");
        output("  clip()\n");
        output("}\n");
      }
      return;
    }

    output("mesh2 {\n");
    output("vertex_vectors { " + nVertices);
    for (int i = 0; i < nVertices; i++) outputVertex(vertices[i], offset);
    output("\n}\n");

    boolean haveNormals = (normals != null);
    if (haveNormals) {
      output("normal_vectors { " + nVertices);
      for (int i = 0; i < nVertices; i++) {
        setTempVertex(vertices[i], offset, tempP2);
        output(getScreenNormal(tempP2, normals[i], 1));
        output("\n");
      }
      output("\n}\n");
    }

    if (colixes != null) {
      int nColix = colorList.size();
      output("texture_list { " + nColix);
      // just using the transparency of the first colix there...
      String finish =
          ">}" + " translucentFinish(" + translucencyFractionalFromColix(colixes[0]) + ")}";
      for (int i = 0; i < nColix; i++)
        output("\n, texture{pigment{rgbt<" + color4(colorList.get(i).shortValue()) + finish);
      output("\n}\n");
    }
    output("face_indices { " + nFaces);
    boolean isAll = (bsPolygons == null);
    int i0 = (isAll ? nPolygons - 1 : bsPolygons.nextSetBit(0));
    for (int i = i0; i >= 0; i = (isAll ? i - 1 : bsPolygons.nextSetBit(i + 1))) {
      output(", <" + getTriad(indices[i]) + ">");
      if (colixes != null) {
        output("," + htColixes.get(Short.valueOf(colixes[indices[i][0]])));
        output("," + htColixes.get(Short.valueOf(colixes[indices[i][1]])));
        output("," + htColixes.get(Short.valueOf(colixes[indices[i][2]])));
      }
      if (faceVertexMax == 4 && indices[i].length == 4) {
        output(", <" + indices[i][0] + "," + indices[i][2] + "," + indices[i][3] + ">");
        if (colixes != null) {
          output("," + htColixes.get(Short.valueOf(colixes[indices[i][0]])));
          output("," + htColixes.get(Short.valueOf(colixes[indices[i][2]])));
          output("," + htColixes.get(Short.valueOf(colixes[indices[i][3]])));
        }
      }
      output("\n");
    }
    output("\n}\n");

    if (colixes == null) {
      output("pigment{rgbt<" + color4(colix) + ">}\n");
      output("  translucentFinish(" + translucencyFractionalFromColix(colix) + ")\n");
    }
    output("  check_shadow()\n");
    output("  clip()\n");
    output("}\n");

    /*
    mesh2 {
    vertex_vectors {
    9,
    <0,0,0>, <0.5,0,0>, <0.5,0.5,0>,
    <1,0,0>, <1,0.5,0>, <1,1,0>
    <0.5,1,0>, <0,1,0>, <0,0.5,0>
    }
    normal_vectors {
    9,
    <-1,-1,0>, <0,-1,0>, <0,0,1>,
    <1,-1,0>, <1,0,0>, <1,1,0>,
    <0,1,0>, <-1,1,0>, <-1,0,0>
    }
    texture_list {
    3,
    texture{pigment{rgb <0,0,1>}},
    texture{pigment{rgb 1}},
    texture{pigment{rgb <1,0,0>}}
    }
    face_indices {
    8,
    <0,1,2>,0,1,2,  <1,3,2>,1,0,2,
    <3,4,2>,0,1,2,  <4,5,2>,1,0,2,
    <5,6,2>,0,1,2,  <6,7,2>,1,0,2,
    <7,8,2>,0,1,2,  <8,0,2>,1,0,2
    }
    }
    */

  }