Java 类net.minecraftforge.client.model.obj.Face 实例源码

项目:Chisel-2    文件:RenderAutoChisel.java   
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
    Tessellator tes = Tessellator.instance;
    IIcon icon = renderer.hasOverrideBlockTexture() ? renderer.overrideBlockTexture : block.getIcon(0, 0);
    tes.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
    tes.setColorOpaque_F(1, 1, 1);
    tes.addTranslation(x, y, z + 1);
    for (GroupObject go : model.groupObjects) {
        for (Face f : go.faces) {
            Vertex n = f.faceNormal;
            tes.setNormal(n.x, n.y, n.z);
            for (int i = 0; i < f.vertices.length; i++) {
                Vertex vert = f.vertices[i];
                TextureCoordinate t = f.textureCoordinates[i];
                if (!renderer.hasOverrideBlockTexture()) {
                    tes.addVertexWithUV(vert.x, vert.y, vert.z, icon.getInterpolatedU(t.u * 16), icon.getInterpolatedV(t.v * 16));
                } else {
                    tes.addVertexWithUV(vert.x, vert.y, vert.z, icon.getInterpolatedU((t.u * 64) % 16), icon.getInterpolatedV((t.v * 64) % 16));
                }
            }
        }
    }
    tes.addTranslation(-x, -y, -z - 1);
    return true;
}
项目:EnderCore    文件:TechneUtil.java   
public static void renderWithIcon(GroupObject go, IIcon icon, IIcon override, Tessellator tes, IBlockAccess world, int x, int y, int z, VertexTransform vt,
    boolean isbrh) {
  for (Face f : go.faces) {
    Vertex n = f.faceNormal;
    tes.setNormal(n.x, n.y, n.z);
    ForgeDirection normal = getNormalFor(n);
    ForgeDirection right = normal.getRotation(ForgeDirection.DOWN);
    if (normal == right) {
      right = ForgeDirection.EAST;
    }
    ForgeDirection down = normal.getRotation(right.getOpposite());

    if (isbrh && world != null && world.getBlock(x, y, z).getLightOpacity() > 0) {
      int bx = x + normal.offsetX;
      int by = y + normal.offsetY;
      int bz = z + normal.offsetZ;
      tes.setBrightness(world.getBlock(bx, by, bz).getMixedBrightnessForBlock(world, bx, by, bz));
    }

    for (int i = 0; i < f.vertices.length; i++) {
      Vertex vert = f.vertices[i];
      Vector3d v = new Vector3d(vert);
      Vector3d tv = new Vector3d(v);
      tv.add(0.5, 0, 0.5);
      if (vt != null) {
        vt.apply(v);
        // TODO BLECH
        if (vt instanceof VertexRotationFacing) {
          normal = ((VertexRotationFacing) vt).rotate(normal);
        }
        if (vt instanceof VertexTransformComposite) {
          for (VertexTransform xform : ((VertexTransformComposite) vt).xforms) {
            if (xform instanceof VertexRotationFacing) {
              normal = ((VertexRotationFacing) xform).rotate(normal);
            }
          }
        }
      }

      if (isbrh) {
        int c = (int) (0xFF * RenderUtil.getColorMultiplierForFace(normal));
        tes.setColorOpaque(c, c, c);
      }

      if (override != null) {

        double interpX = Math.abs(tv.x * right.offsetX + tv.y * right.offsetY + tv.z * right.offsetZ);
        double interpY = Math.abs(tv.x * down.offsetX + tv.y * down.offsetY + tv.z * down.offsetZ);

        // Handles verts outside block bounds. Modulo fails at 1.0.
        while (interpX > 1) {
          interpX--;
        }
        while (interpY > 1) {
          interpY--;
        }

        if (normal == ForgeDirection.SOUTH || normal == ForgeDirection.WEST) {
          interpX = 1 - interpX;
        }
        if (normal != ForgeDirection.UP && normal != ForgeDirection.DOWN) {
          interpY = 1 - interpY;
        }
        tes.addVertexWithUV(v.x, v.y, v.z, override.getInterpolatedU(interpX * 16), override.getInterpolatedV(interpY * 16));
      } else {
        TextureCoordinate t = f.textureCoordinates[i];
        tes.addVertexWithUV(v.x, v.y, v.z, getInterpolatedU(icon, t.u), getInterpolatedV(icon, t.v));
      }
    }
  }
}