瀏覽代碼

Merge pull request #51995 from drcd1/sphere-mesh-normals-fix

Fixes the normals of SphereMesh when the sphere/hemisphere is oblong
JFonS 4 年之前
父節點
當前提交
353bb45e21
共有 1 個文件被更改,包括 5 次插入2 次删除
  1. 5 2
      scene/resources/primitive_meshes.cpp

+ 5 - 2
scene/resources/primitive_meshes.cpp

@@ -1420,6 +1420,8 @@ void SphereMesh::_create_mesh_array(Array &p_arr) const {
 	int i, j, prevrow, thisrow, point;
 	int i, j, prevrow, thisrow, point;
 	float x, y, z;
 	float x, y, z;
 
 
+	float scale = height * (is_hemisphere ? 1.0 : 0.5);
+
 	// set our bounding box
 	// set our bounding box
 
 
 	Vector<Vector3> points;
 	Vector<Vector3> points;
@@ -1443,7 +1445,7 @@ void SphereMesh::_create_mesh_array(Array &p_arr) const {
 
 
 		v /= (rings + 1);
 		v /= (rings + 1);
 		w = sin(Math_PI * v);
 		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++) {
 		for (i = 0; i <= radial_segments; i++) {
 			float u = i;
 			float u = i;
@@ -1458,7 +1460,8 @@ void SphereMesh::_create_mesh_array(Array &p_arr) const {
 			} else {
 			} else {
 				Vector3 p = Vector3(x * radius * w, y, z * radius * w);
 				Vector3 p = Vector3(x * radius * w, y, z * radius * w);
 				points.push_back(p);
 				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)
 			ADD_TANGENT(z, 0.0, -x, 1.0)
 			uvs.push_back(Vector2(u, v));
 			uvs.push_back(Vector2(u, v));