Example #1
0
  public Triangle(Mesh owner, int index0, int index1, int index2, Material material) {
    this.owner = owner;
    index = new int[3];
    index[0] = index0;
    index[1] = index1;
    index[2] = index2;

    Point3 v0 = owner.getVertex(index0);
    Point3 v1 = owner.getVertex(index1);
    Point3 v2 = owner.getVertex(index2);

    if (!owner.existsNormals()) {
      Vector3 e0 = new Vector3(), e1 = new Vector3();
      e0.sub(v1, v0);
      e1.sub(v2, v0);
      norm = new Vector3();
      norm.cross(e0, e1);
    }
    a = v0.x - v1.x;
    b = v0.y - v1.y;
    c = v0.z - v1.z;

    d = v0.x - v2.x;
    e = v0.y - v2.y;
    f = v0.z - v2.z;

    this.setMaterial(material);
  }
 public void updateArea() {
   Vector3 u = new Vector3(), v = new Vector3(), n = new Vector3();
   u.set(
       mesh.verts[3 * v1] - mesh.verts[3 * v0],
       mesh.verts[3 * v1 + 1] - mesh.verts[3 * v0 + 1],
       mesh.verts[3 * v1 + 2] - mesh.verts[3 * v0 + 2]);
   v.set(
       mesh.verts[3 * v2] - mesh.verts[3 * v0],
       mesh.verts[3 * v2 + 1] - mesh.verts[3 * v0 + 1],
       mesh.verts[3 * v2 + 2] - mesh.verts[3 * v0 + 2]);
   n.cross(u, v);
   area = 0.5 * n.length();
   oneOverArea = 1. / area;
 }