Skip to content

Commit f2f5437

Browse files
committed
Merge pull request #112046 from BlueCube3310/mat-preview-fix
Fix the material preview sphere model
2 parents d6d7e3c + 3b16d96 commit f2f5437

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

editor/inspector/editor_preview_plugins.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() {
393393

394394
int lats = 32;
395395
int lons = 32;
396-
const double lat_step = Math::TAU / lats;
396+
const double lat_step = Math::PI / lats;
397397
const double lon_step = Math::TAU / lons;
398398
real_t radius = 1.0;
399399

@@ -428,22 +428,27 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() {
428428
Vector3(x0 * zr0, z0, y0 * zr0)
429429
};
430430

431-
#define ADD_POINT(m_idx) \
432-
normals.push_back(v[m_idx]); \
433-
vertices.push_back(v[m_idx] * radius); \
434-
{ \
435-
Vector2 uv(Math::atan2(v[m_idx].x, v[m_idx].z), Math::atan2(-v[m_idx].y, v[m_idx].z)); \
436-
uv /= Math::PI; \
437-
uv *= 4.0; \
438-
uv = uv * 0.5 + Vector2(0.5, 0.5); \
439-
uvs.push_back(uv); \
440-
} \
441-
{ \
442-
Vector3 t = tt.xform(v[m_idx]); \
443-
tangents.push_back(t.x); \
444-
tangents.push_back(t.y); \
445-
tangents.push_back(t.z); \
446-
tangents.push_back(1.0); \
431+
#define ADD_POINT(m_idx) \
432+
normals.push_back(v[m_idx]); \
433+
vertices.push_back(v[m_idx] * radius); \
434+
{ \
435+
Vector2 uv; \
436+
if (j >= lons / 2) { \
437+
uv = Vector2(Math::atan2(-v[m_idx].x, -v[m_idx].z), Math::atan2(v[m_idx].y, -v[m_idx].z)); \
438+
} else { \
439+
uv = Vector2(Math::atan2(v[m_idx].x, v[m_idx].z), Math::atan2(-v[m_idx].y, v[m_idx].z)); \
440+
} \
441+
uv /= Math::PI; \
442+
uv *= 4.0; \
443+
uv = uv * 0.5 + Vector2(0.5, 0.5); \
444+
uvs.push_back(uv); \
445+
} \
446+
{ \
447+
Vector3 t = tt.xform(v[m_idx]); \
448+
tangents.push_back(t.x); \
449+
tangents.push_back(t.y); \
450+
tangents.push_back(t.z); \
451+
tangents.push_back(1.0); \
447452
}
448453

449454
ADD_POINT(0);

0 commit comments

Comments
 (0)