Adding UVs on end caps
This commit is contained in:
parent
5738c92b39
commit
9703153396
@ -1666,6 +1666,24 @@ CSGBrush *CSGPolygon::_build_brush() {
|
|||||||
Path *path = NULL;
|
Path *path = NULL;
|
||||||
Ref<Curve3D> curve;
|
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 (mode == MODE_PATH) {
|
||||||
if (!has_node(path_node))
|
if (!has_node(path_node))
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1757,6 +1775,10 @@ CSGBrush *CSGPolygon::_build_brush() {
|
|||||||
v.z -= depth;
|
v.z -= depth;
|
||||||
}
|
}
|
||||||
facesw[face * 3 + k] = v;
|
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;
|
smoothw[face] = false;
|
||||||
@ -1888,6 +1910,7 @@ CSGBrush *CSGPolygon::_build_brush() {
|
|||||||
Vector2 p = final_polygon[triangles[j + src[k]]];
|
Vector2 p = final_polygon[triangles[j + src[k]]];
|
||||||
Vector3 v = Vector3(p.x, p.y, 0);
|
Vector3 v = Vector3(p.x, p.y, 0);
|
||||||
facesw[face * 3 + k] = v;
|
facesw[face * 3 + k] = v;
|
||||||
|
uvsw[face * 3 + k] = (p - final_polygon_min) / final_polygon_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
smoothw[face] = false;
|
smoothw[face] = false;
|
||||||
@ -1905,6 +1928,8 @@ CSGBrush *CSGPolygon::_build_brush() {
|
|||||||
Vector2 p = final_polygon[triangles[j + src[k]]];
|
Vector2 p = final_polygon[triangles[j + src[k]]];
|
||||||
Vector3 v = Vector3(normali_n.x * p.x, p.y, normali_n.z * p.x);
|
Vector3 v = Vector3(normali_n.x * p.x, p.y, normali_n.z * p.x);
|
||||||
facesw[face * 3 + k] = v;
|
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;
|
smoothw[face] = false;
|
||||||
@ -1990,10 +2015,10 @@ CSGBrush *CSGPolygon::_build_brush() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Vector2 u[4] = {
|
Vector2 u[4] = {
|
||||||
Vector2(u1, 0),
|
|
||||||
Vector2(u1, 1),
|
Vector2(u1, 1),
|
||||||
Vector2(u2, 1),
|
Vector2(u1, 0),
|
||||||
Vector2(u2, 0)
|
Vector2(u2, 0),
|
||||||
|
Vector2(u2, 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
// face 1
|
// face 1
|
||||||
@ -2036,6 +2061,7 @@ CSGBrush *CSGPolygon::_build_brush() {
|
|||||||
Vector2 p = final_polygon[triangles[j + src[k]]];
|
Vector2 p = final_polygon[triangles[j + src[k]]];
|
||||||
Vector3 v = Vector3(p.x, p.y, 0);
|
Vector3 v = Vector3(p.x, p.y, 0);
|
||||||
facesw[face * 3 + k] = xf.xform(v);
|
facesw[face * 3 + k] = xf.xform(v);
|
||||||
|
uvsw[face * 3 + k] = (p - final_polygon_min) / final_polygon_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
smoothw[face] = false;
|
smoothw[face] = false;
|
||||||
@ -2053,6 +2079,8 @@ CSGBrush *CSGPolygon::_build_brush() {
|
|||||||
Vector2 p = final_polygon[triangles[j + src[k]]];
|
Vector2 p = final_polygon[triangles[j + src[k]]];
|
||||||
Vector3 v = Vector3(p.x, p.y, 0);
|
Vector3 v = Vector3(p.x, p.y, 0);
|
||||||
facesw[face * 3 + k] = xf.xform(v);
|
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;
|
smoothw[face] = false;
|
||||||
@ -2077,6 +2105,9 @@ CSGBrush *CSGPolygon::_build_brush() {
|
|||||||
} else {
|
} else {
|
||||||
aabb.expand_to(facesw[i]);
|
aabb.expand_to(facesw[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// invert UVs on the Y-axis OpenGL = upside down
|
||||||
|
uvsw[i].y = 1.0 - uvsw[i].y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user