Skip to content

Commit 7b9bdf1

Browse files
committed
MorphTarget: adjusting normals and tangents in visualizer
1 parent 467ab3b commit 7b9bdf1

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

MeshInstance/SkelMeshInstance.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1444,11 +1444,26 @@ bool CSkelMeshInstance::BuildMorphVerts()
14441444
// Copy unmodified vertices
14451445
memcpy(MorphedVerts, Lod.Verts, Lod.NumVerts * sizeof(CSkelMeshVertex));
14461446

1447-
// Apply delta
1447+
// Apply deltas
14481448
for (const CMorphVertex& Delta : Deltas)
14491449
{
14501450
CSkelMeshVertex& V = MorphedVerts[Delta.VertexIndex];
1451+
// Morph position
14511452
VectorAdd(V.Position, Delta.PositionDelta, V.Position);
1453+
// Morph normal
1454+
CVec3 Normal;
1455+
int8 W = V.Normal.GetW();
1456+
Unpack(Normal, V.Normal);
1457+
VectorAdd(Normal, Delta.NormalDelta, Normal);
1458+
Pack(V.Normal, Normal);
1459+
V.Normal.SetW(W);
1460+
// Adjust tangent vector to make basis orthonormal
1461+
CVec3 Tangent;
1462+
Unpack(Tangent, V.Tangent);
1463+
float shift = dot(Normal, Tangent); // it will be zero if vertices are perpendicular
1464+
VectorMA(Tangent, -shift, Normal); // shift alongside the normal to make vertices perpendicular again
1465+
Tangent.NormalizeFast(); // ensure result is normalized
1466+
Pack(V.Tangent, Tangent);
14521467
}
14531468

14541469
return true;

readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ keyboard shortcuts by pressing 'H' (Help) key. Here's the list of some shortcuts
9898
Shift+Up/Down change scene FOV
9999
Ctrl+L switch lighting modes
100100
Ctrl+Q toggle visualization of debug information (text, 3D axis etc)
101-
Ctrl+G toggle OpenGL 2.0 / OpenGL 1.1 renderer
101+
Ctrl+G toggle between OpenGL 2.0 (using shaders) and OpenGL 1.1 (no shaders)
102102
Esc exit from the umodel
103103

104104
You may attach the AnimSet to the SkeletalMesh object using Ctrl+A key. Animation
@@ -212,6 +212,10 @@ detex
212212

213213
Changes
214214
~~~~~~~
215+
15.10.2019
216+
- loading and visualizing of UE3 and UE4 MorphTargets; switching between morphs is done with Ctrl+[ and Ctrl+]
217+
keys
218+
215219
13.10.2019
216220
- added full vertex color support (loading, viewing, exporting)
217221

umodel

8 KB
Binary file not shown.

umodel.exe

4.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)