Skip to content

Commit

Permalink
Reverting winding, clockwise topdwon definitions for wall's frontness…
Browse files Browse the repository at this point in the history
… consistent
  • Loading branch information
AlvaroHG committed Sep 22, 2022
1 parent 6648c4a commit cc49eb6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion unity/Assets/Scripts/ProceduralTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ int precision
var dist = x0 * z1 - x1 * z0;
edgeSum += dist;
}
if (edgeSum < 0) {
if (edgeSum > 0) {

wallLoop = wallLoop.Reverse<((double row, double col), (double row, double col))>().Select(p => (p.Item2, p.Item1)).ToList();
}
Expand Down
25 changes: 15 additions & 10 deletions unity/Assets/Scripts/ProceduralTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,10 @@ public class Rectangle {
p0 = -(width / 2.0f) * Vector3.right - new Vector3(0.0f, toCreate.height / 2.0f, toCreate.thickness / 2.0f);
p1 = (width / 2.0f) * Vector3.right - new Vector3(0.0f, toCreate.height / 2.0f, toCreate.thickness / 2.0f);

// normal = -Vector3.Cross(Vector3.right, Vector3.up);
normal = Vector3.forward;
p0p1_norm = Vector3.right;

wallGO.transform.position = center;

wallGO.transform.rotation = Quaternion.AngleAxis(theta * 180.0f / Mathf.PI, Vector3.up);
Expand Down Expand Up @@ -783,14 +785,16 @@ public class Rectangle {

};

// This would be for a left hand local axis space, so front being counter-clockwise of topdown polygon from inside the polygon
// triangles = new List<int>() {
// 0, 1, 2, 1, 3, 2, 1, 4, 3, 3, 4, 5, 4, 6, 5, 5, 6, 7, 7, 6, 0, 0, 2, 7
// };


triangles = new List<int>() {
7, 2, 0, 0, 6, 7, 7, 6, 5, 5, 6, 4, 5, 4, 3, 3, 4, 1, 2, 3, 1, 2, 1, 0
0, 1, 2, 1, 3, 2, 1, 4, 3, 3, 4, 5, 4, 6, 5, 5, 6, 7, 7, 6, 0, 0, 2, 7
};


// This would be for a left hand local axis space, so front being counter-clockwise of topdown polygon from inside the polygon
// triangles = new List<int>() {
// 7, 2, 0, 0, 6, 7, 7, 6, 5, 5, 6, 4, 5, 4, 3, 3, 4, 1, 2, 3, 1, 2, 1, 0
// };

if (toCreate.id == "wall_0_2") {

Expand Down Expand Up @@ -824,16 +828,17 @@ public class Rectangle {
p1
};

// triangles = new List<int>() { 1, 2, 0, 2, 3, 0 };
triangles = new List<int>() { 1, 2, 0, 2, 3, 0 };

// Right hand rule
triangles = new List<int>() { 0, 3, 2, 0, 2, 1 };
// Counter clockwise wall definition left hand rule
// triangles = new List<int>() { 0, 3, 2, 0, 2, 1 };
if (generateBackFaces) {
triangles.AddRange(triangles.AsEnumerable().Reverse().ToList());
}
}

normals = Enumerable.Repeat(normal, vertices.Count).ToList();//.Concat(Enumerable.Repeat(-normal, vertices.Count)).ToList();
normals = Enumerable.Repeat(-normal, vertices.Count).ToList();
// normals = Enumerable.Repeat(normal, vertices.Count).ToList();//.Concat(Enumerable.Repeat(-normal, vertices.Count)).ToList();

uv = vertices.Select(v =>
new Vector2(Vector3.Dot(p0p1_norm, v - p0) / width, v.y / toCreate.height))
Expand Down

0 comments on commit cc49eb6

Please sign in to comment.