Fixes the normals of SphereMesh when the sphere/hemisphere is oblong

(cherry picked from commits f4ac08a182
and 7d53755ca7)
This commit is contained in:
Duarte David 2021-08-22 21:04:14 +01:00 committed by Rémi Verschelde
parent bf65c0e479
commit a4fecbb0da
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -1456,6 +1456,8 @@ void SphereMesh::_create_mesh_array(Array &p_arr) const {
int i, j, prevrow, thisrow, point;
float x, y, z;
float scale = height * (is_hemisphere ? 1.0 : 0.5);
// set our bounding box
PoolVector<Vector3> points;
@ -1479,7 +1481,7 @@ void SphereMesh::_create_mesh_array(Array &p_arr) const {
v /= (rings + 1);
w = sin(Math_PI * v);
y = height * (is_hemisphere ? 1.0 : 0.5) * cos(Math_PI * v);
y = scale * cos(Math_PI * v);
for (i = 0; i <= radial_segments; i++) {
float u = i;
@ -1494,7 +1496,8 @@ void SphereMesh::_create_mesh_array(Array &p_arr) const {
} else {
Vector3 p = Vector3(x * radius * w, y, z * radius * w);
points.push_back(p);
normals.push_back(p.normalized());
Vector3 normal = Vector3(x * w * scale, radius * (y / scale), z * w * scale);
normals.push_back(normal.normalized());
};
ADD_TANGENT(z, 0.0, -x, 1.0)
uvs.push_back(Vector2(u, v));