summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorJFonS <JFonS@users.noreply.github.com>2021-08-25 16:22:20 +0200
committerGitHub <noreply@github.com>2021-08-25 16:22:20 +0200
commit353bb45e21fadf8da1f6fbbaaf99b8ac8acafea9 (patch)
tree44e2600ec23515aa449734220b5623b2ac2cdb06 /scene
parentc3378d56505cfb8e282ed4e542fe170d213371f6 (diff)
parentf4ac08a1826a8062f5206192d183d13a1c01c557 (diff)
Merge pull request #51995 from drcd1/sphere-mesh-normals-fix
Fixes the normals of SphereMesh when the sphere/hemisphere is oblong
Diffstat (limited to 'scene')
-rw-r--r--scene/resources/primitive_meshes.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp
index ba85ea4a6c..e7da41db9d 100644
--- a/scene/resources/primitive_meshes.cpp
+++ b/scene/resources/primitive_meshes.cpp
@@ -1420,6 +1420,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
Vector<Vector3> points;
@@ -1443,7 +1445,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;
@@ -1458,7 +1460,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 * radius * w * scale, y / scale, z * radius * w * scale);
+ normals.push_back(normal.normalized());
};
ADD_TANGENT(z, 0.0, -x, 1.0)
uvs.push_back(Vector2(u, v));