Skip to content

Commit

Permalink
one at a time, take it or leave it.
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Sep 16, 2022
1 parent 24e3d54 commit 2d73375
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 80 deletions.
2 changes: 1 addition & 1 deletion FModel/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private async void OnLoaded(object sender, RoutedEventArgs e)
#if DEBUG
await _threadWorkerView.Begin(_ =>
_applicationView.CUE4Parse.Extract(
"Hk_project/Content/Character/Zurg/Mesh/SKM_Zurg.uasset"));
"/Game/Weapons/FORT_Melee/Pickaxe_Slurp_Monster/Meshes/Slurp_Monster_Axe.uasset"));
#endif
}

Expand Down
7 changes: 5 additions & 2 deletions FModel/Resources/default.vert
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ layout (location = 4) in vec4 vColor;
layout (location = 5) in ivec4 vBoneIds;
layout (location = 6) in vec4 vWeights;
layout (location = 7) in mat4 vInstanceMatrix;
layout (location = 11) in vec3 vMorphTarget;

uniform mat4 uView;
uniform mat4 uProjection;
uniform float uMorphTime;

out vec3 fPos;
out vec3 fNormal;
Expand All @@ -18,9 +20,10 @@ out vec4 fColor;

void main()
{
gl_Position = uProjection * uView * vInstanceMatrix * vec4(vPos, 1.0);
vec3 pos = mix(vPos, vMorphTarget, uMorphTime);
gl_Position = uProjection * uView * vInstanceMatrix * vec4(pos, 1.0);

fPos = vec3(vInstanceMatrix * vec4(vPos, 1.0));
fPos = vec3(vInstanceMatrix * vec4(pos, 1.0));
fNormal = mat3(transpose(inverse(vInstanceMatrix))) * vNormal;
fTexCoords = vTexCoords;
fColor = vColor;
Expand Down
7 changes: 5 additions & 2 deletions FModel/Resources/outline.vert
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
layout (location = 1) in vec3 vPos;
layout (location = 2) in vec3 vNormal;
layout (location = 7) in mat4 vInstanceMatrix;
layout (location = 11) in vec3 vMorphTarget;

uniform mat4 uView;
uniform mat4 uProjection;
uniform float uMorphTime;
uniform vec3 viewPos;

void main()
{
float scaleFactor = distance(vPos, viewPos) * 0.0025;
vec3 scaleVertex = vPos + vNormal * scaleFactor;
vec3 pos = mix(vPos, vMorphTarget, uMorphTime);
float scaleFactor = distance(pos, viewPos) * 0.0025;
vec3 scaleVertex = pos + vNormal * scaleFactor;
gl_Position = uProjection * uView * vInstanceMatrix * vec4(scaleVertex, 1.0);
}
8 changes: 8 additions & 0 deletions FModel/Views/Snooper/BufferObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public unsafe void Update(int offset, TDataType data)
_gl.BufferSubData(_bufferType, offset * sizeof(TDataType), (nuint) sizeof(TDataType), data);
}

public unsafe void Update(Span<TDataType> data)
{
fixed (void* d = data)
{
_gl.BufferSubData(_bufferType, 0, (nuint) (data.Length * sizeof(TDataType)), d);
}
}

public void Bind()
{
_gl.BindBuffer(_bufferType, _handle);
Expand Down
74 changes: 37 additions & 37 deletions FModel/Views/Snooper/Cube.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,48 @@ public Cube(UObject owner, string name, string type, UMaterialInterface unrealMa
32, 33, 34, 35
};
Vertices = new float[] {
//X Y Z Normals U V
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f,
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f,
// I X Y Z Normals U V
-1, -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f,
-1, 0.5f, -0.5f, -0.5f, 0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.0f, 0.0f, 1.0f, 0.0f,
-1, 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
-1, -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
-1, -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f
};

Sections = new Section[1];
Expand Down
47 changes: 37 additions & 10 deletions FModel/Views/Snooper/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Model : IDisposable

private BufferObject<uint> _ebo;
private BufferObject<float> _vbo;
private BufferObject<float> _morphVbo;
private BufferObject<Matrix4x4> _matrixVbo;
private VertexArrayObject<float, uint> _vao;

Expand Down Expand Up @@ -45,6 +46,8 @@ public class Model : IDisposable
public bool IsSavable;
public bool DisplayVertexColors;
public bool DisplayBones;
public int SelectedMorph;
public float MorphTime;

protected Model(UObject owner, string name, string type)
{
Expand Down Expand Up @@ -146,6 +149,13 @@ public void UpdateMatrix(int index)
_matrixVbo.Unbind();
}

public void UpdateMorph()
{
_morphVbo.Bind();
_morphVbo.Update(Morphs[SelectedMorph].Vertices);
_morphVbo.Unbind();
}

public void Setup(GL gl)
{
_gl = gl;
Expand All @@ -164,17 +174,28 @@ public void Setup(GL gl)
_vao.VertexAttributePointer(5, 4, VertexAttribPointerType.Int, _vertexSize, 13); // boneids
_vao.VertexAttributePointer(6, 4, VertexAttribPointerType.Float, _vertexSize, 17); // boneweights

TransformsCount = Transforms.Count;
var instanceMatrix = new Matrix4x4[TransformsCount];
for (var i = 0; i < instanceMatrix.Length; i++)
instanceMatrix[i] = Transforms[i].Matrix;
_matrixVbo = new BufferObject<Matrix4x4>(_gl, instanceMatrix, BufferTargetARB.ArrayBuffer);
_vao.BindInstancing();
{ // instanced models transform
TransformsCount = Transforms.Count;
var instanceMatrix = new Matrix4x4[TransformsCount];
for (var i = 0; i < instanceMatrix.Length; i++)
instanceMatrix[i] = Transforms[i].Matrix;
_matrixVbo = new BufferObject<Matrix4x4>(_gl, instanceMatrix, BufferTargetARB.ArrayBuffer);
_vao.BindInstancing(); // VertexAttributePointer 7, 8, 9, 10
}

for (uint morph = 0; morph < Morphs.Length; morph++)
if (HasMorphTargets)
{
Morphs[morph].Setup(gl);
for (uint morph = 0; morph < Morphs.Length; morph++)
{
Morphs[morph].Setup(gl);
if (morph == SelectedMorph)
_morphVbo = new BufferObject<float>(_gl, Morphs[morph].Vertices, BufferTargetARB.ArrayBuffer);
}
_vao.Bind();
_vao.VertexAttributePointer(11, 3, VertexAttribPointerType.Float, _vertexSize, 1); // morph position
_vao.Unbind();
}

for (int section = 0; section < Sections.Length; section++)
{
Sections[section].Setup(_gl);
Expand All @@ -190,6 +211,7 @@ public void Bind(Shader shader)
}

_vao.Bind();
shader.SetUniform("uMorphTime", MorphTime);
shader.SetUniform("display_vertex_colors", DisplayVertexColors);
for (int section = 0; section < Sections.Length; section++)
{
Expand All @@ -212,6 +234,7 @@ public void Outline(Shader shader)

_vao.Bind();
shader.Use();
shader.SetUniform("uMorphTime", MorphTime);
for (int section = 0; section < Sections.Length; section++)
{
if (!Sections[section].Show) continue;
Expand All @@ -230,9 +253,13 @@ public void Dispose()
_vbo.Dispose();
_matrixVbo.Dispose();
_vao.Dispose();
for (var morph = 0; morph < Morphs.Length; morph++)
if (HasMorphTargets)
{
Morphs[morph].Dispose();
_morphVbo.Dispose();
for (var morph = 0; morph < Morphs.Length; morph++)
{
Morphs[morph].Dispose();
}
}
for (int section = 0; section < Sections.Length; section++)
{
Expand Down
13 changes: 0 additions & 13 deletions FModel/Views/Snooper/Morph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ public class Morph : IDisposable
private uint _handle;
private GL _gl;

private BufferObject<float> _vbo;

public readonly string Name;
public readonly float[] Vertices;

public float Value;

public Morph(float[] vertices, uint vertexSize, UMorphTarget morphTarget)
{
Name = morphTarget.Name;
Expand Down Expand Up @@ -49,20 +45,11 @@ bool TryFindVertex(uint index, out FVector positionDelta)
public void Setup(GL gl)
{
_gl = gl;

_handle = _gl.CreateProgram();

_vbo = new BufferObject<float>(_gl, Vertices, BufferTargetARB.ArrayBuffer);
}

public void Bind(Shader shader)
{
shader.SetUniform("uMorphTime", Value);
}

public void Dispose()
{
_vbo.Dispose();
_gl.DeleteProgram(_handle);
}
}
38 changes: 23 additions & 15 deletions FModel/Views/Snooper/SnimGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,18 +313,26 @@ private void DrawProperties(Camera camera, IDictionary<FGuid, Model> models)
ImGui.EndTabItem();
}

ImGui.BeginDisabled(!model.HasMorphTargets);
if (ImGui.BeginTabItem("Shape Keys"))
if (model.HasMorphTargets && ImGui.BeginTabItem("Morph Targets"))
{
for (int i = 0; i < model.Morphs.Length; i++)
if (ImGui.BeginListBox("", new Vector2(ImGui.GetContentRegionAvail().X, _propertiesSize.Y / 2)))
{
ImGui.PushID(i);
ImGui.DragFloat(model.Morphs[i].Name, ref model.Morphs[i].Value, 0.001f, 0.0f, 1.0f, "%.2f", ImGuiSliderFlags.AlwaysClamp);
ImGui.PopID();
for (int i = 0; i < model.Morphs.Length; i++)
{
ImGui.PushID(i);
if (ImGui.Selectable(model.Morphs[i].Name, model.SelectedMorph == i))
{
model.SelectedMorph = i;
model.UpdateMorph();
}
ImGui.PopID();
}
ImGui.EndListBox();
ImGui.Separator();
ImGui.DragFloat("Value", ref model.MorphTime, 0.001f, 0.0f, 1.0f, "%.2f", ImGuiSliderFlags.AlwaysClamp);
}
ImGui.EndTabItem();
}
ImGui.EndDisabled();
}

ImGui.End();
Expand All @@ -349,7 +357,7 @@ private void DrawTextures(IDictionary<FGuid, Model> models)
{
ImGui.SetNextItemWidth(300);
ImGui.ColorEdit4(section.TexturesLabels[0], ref section.DiffuseColor, ImGuiColorEditFlags.AlphaPreview | ImGuiColorEditFlags.AlphaBar);
if (section.Textures[1] is { } normalMap) DrawTexture(normalMap);
if (section.Textures[1] is { } normalMap) DrawTexture(normalMap, "Normal");
}
else
{
Expand All @@ -358,27 +366,22 @@ private void DrawTextures(IDictionary<FGuid, Model> models)
if (section.Textures[i] is not {} texture)
continue;

DrawTexture(texture);
DrawTexture(texture, section.TexturesLabels[i]);

if (i == 3) // emissive, show color
{
ImGui.SameLine();
ImGui.SetNextItemWidth(300);
ImGui.ColorEdit4($"{section.TexturesLabels[i]} Color", ref section.EmissionColor, ImGuiColorEditFlags.NoAlpha);
}
var text = section.TexturesLabels[i];
var width = ImGui.GetCursorPos().X;
ImGui.SetCursorPosX(width + ImGui.CalcTextSize(text).X * 0.5f);
ImGui.Text(text);
ImGui.EndGroup();
}
}
ImGui.EndGroup();

ImGui.End();
}

private void DrawTexture(Texture texture)
private void DrawTexture(Texture texture, string label)
{
ImGui.SameLine();
ImGui.BeginGroup();
Expand All @@ -403,6 +406,11 @@ private void DrawTexture(Texture texture)
texture.Label = "(?) Copied to Clipboard";
});
}

var width = ImGui.GetCursorPos().X;
ImGui.SetCursorPosX(width + ImGui.CalcTextSize(label).X * 0.5f);
ImGui.Text(label);
ImGui.EndGroup();
}

private void Draw3DViewport(FramebufferObject framebuffer, Camera camera, IMouse mouse)
Expand Down

0 comments on commit 2d73375

Please sign in to comment.