summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-11-20 13:59:46 +0100
committerGitHub <noreply@github.com>2018-11-20 13:59:46 +0100
commit84dcf9ca19a63864f5f769a0f4ab4678ba2ea0dc (patch)
tree03d252ab37f60dd0378a7b108535643075b8e9a5
parenta837c33442166650d6eba7fb794f4c63221df19e (diff)
parent970315339609d18093b406efd43e22996c43dc50 (diff)
Merge pull request #23824 from BastiaanOlij/polygon_caps
Adding UVs on end caps for CSGPolygon
-rw-r--r--modules/csg/csg_shape.cpp37
1 files changed, 34 insertions, 3 deletions
diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp
index 23d879e1cd..e1607c4326 100644
--- a/modules/csg/csg_shape.cpp
+++ b/modules/csg/csg_shape.cpp
@@ -1666,6 +1666,24 @@ CSGBrush *CSGPolygon::_build_brush() {
Path *path = NULL;
Ref<Curve3D> curve;
+ // get bounds for our polygon
+ Vector2 final_polygon_min;
+ Vector2 final_polygon_max;
+ for (int i = 0; i < final_polygon.size(); i++) {
+ Vector2 p = final_polygon[i];
+ if (i == 0) {
+ final_polygon_min = p;
+ final_polygon_max = final_polygon_min;
+ } else {
+ if (p.x < final_polygon_min.x) final_polygon_min.x = p.x;
+ if (p.y < final_polygon_min.y) final_polygon_min.y = p.y;
+
+ if (p.x > final_polygon_max.x) final_polygon_max.x = p.x;
+ if (p.y > final_polygon_max.y) final_polygon_max.y = p.y;
+ }
+ }
+ Vector2 final_polygon_size = final_polygon_max - final_polygon_min;
+
if (mode == MODE_PATH) {
if (!has_node(path_node))
return NULL;
@@ -1757,6 +1775,10 @@ CSGBrush *CSGPolygon::_build_brush() {
v.z -= depth;
}
facesw[face * 3 + k] = v;
+ uvsw[face * 3 + k] = (p - final_polygon_min) / final_polygon_size;
+ if (i == 0) {
+ uvsw[face * 3 + k].x = 1.0 - uvsw[face * 3 + k].x; /* flip x */
+ }
}
smoothw[face] = false;
@@ -1888,6 +1910,7 @@ CSGBrush *CSGPolygon::_build_brush() {
Vector2 p = final_polygon[triangles[j + src[k]]];
Vector3 v = Vector3(p.x, p.y, 0);
facesw[face * 3 + k] = v;
+ uvsw[face * 3 + k] = (p - final_polygon_min) / final_polygon_size;
}
smoothw[face] = false;
@@ -1905,6 +1928,8 @@ CSGBrush *CSGPolygon::_build_brush() {
Vector2 p = final_polygon[triangles[j + src[k]]];
Vector3 v = Vector3(normali_n.x * p.x, p.y, normali_n.z * p.x);
facesw[face * 3 + k] = v;
+ uvsw[face * 3 + k] = (p - final_polygon_min) / final_polygon_size;
+ uvsw[face * 3 + k].x = 1.0 - uvsw[face * 3 + k].x; /* flip x */
}
smoothw[face] = false;
@@ -1990,10 +2015,10 @@ CSGBrush *CSGPolygon::_build_brush() {
};
Vector2 u[4] = {
- Vector2(u1, 0),
Vector2(u1, 1),
- Vector2(u2, 1),
- Vector2(u2, 0)
+ Vector2(u1, 0),
+ Vector2(u2, 0),
+ Vector2(u2, 1)
};
// face 1
@@ -2036,6 +2061,7 @@ CSGBrush *CSGPolygon::_build_brush() {
Vector2 p = final_polygon[triangles[j + src[k]]];
Vector3 v = Vector3(p.x, p.y, 0);
facesw[face * 3 + k] = xf.xform(v);
+ uvsw[face * 3 + k] = (p - final_polygon_min) / final_polygon_size;
}
smoothw[face] = false;
@@ -2053,6 +2079,8 @@ CSGBrush *CSGPolygon::_build_brush() {
Vector2 p = final_polygon[triangles[j + src[k]]];
Vector3 v = Vector3(p.x, p.y, 0);
facesw[face * 3 + k] = xf.xform(v);
+ uvsw[face * 3 + k] = (p - final_polygon_min) / final_polygon_size;
+ uvsw[face * 3 + k].x = 1.0 - uvsw[face * 3 + k].x; /* flip x */
}
smoothw[face] = false;
@@ -2077,6 +2105,9 @@ CSGBrush *CSGPolygon::_build_brush() {
} else {
aabb.expand_to(facesw[i]);
}
+
+ // invert UVs on the Y-axis OpenGL = upside down
+ uvsw[i].y = 1.0 - uvsw[i].y;
}
}