mirror of
https://github.com/4sval/FModel.git
synced 2026-06-21 07:20:05 -05:00
one at a time, take it or leave it.
This commit is contained in:
parent
24e3d549f5
commit
2d73375392
|
|
@ -79,7 +79,7 @@ public partial class MainWindow
|
|||
#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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,14 @@ public class BufferObject<TDataType> : IDisposable where TDataType : unmanaged
|
|||
_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);
|
||||
|
|
|
|||
|
|
@ -18,48 +18,48 @@ public class Cube : Model
|
|||
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,
|
||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0f, 0.0f, 1.0f,
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
||||
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
|
||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f
|
||||
-1, -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||
-1, 0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.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, 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];
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
@ -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)
|
||||
{
|
||||
|
|
@ -146,6 +149,13 @@ public class Model : IDisposable
|
|||
_matrixVbo.Unbind();
|
||||
}
|
||||
|
||||
public void UpdateMorph()
|
||||
{
|
||||
_morphVbo.Bind();
|
||||
_morphVbo.Update(Morphs[SelectedMorph].Vertices);
|
||||
_morphVbo.Unbind();
|
||||
}
|
||||
|
||||
public void Setup(GL gl)
|
||||
{
|
||||
_gl = gl;
|
||||
|
|
@ -164,17 +174,28 @@ public class Model : IDisposable
|
|||
_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();
|
||||
|
||||
for (uint morph = 0; morph < Morphs.Length; morph++)
|
||||
{
|
||||
Morphs[morph].Setup(gl);
|
||||
{ // 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
|
||||
}
|
||||
|
||||
if (HasMorphTargets)
|
||||
{
|
||||
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);
|
||||
|
|
@ -190,6 +211,7 @@ public class Model : IDisposable
|
|||
}
|
||||
|
||||
_vao.Bind();
|
||||
shader.SetUniform("uMorphTime", MorphTime);
|
||||
shader.SetUniform("display_vertex_colors", DisplayVertexColors);
|
||||
for (int section = 0; section < Sections.Length; section++)
|
||||
{
|
||||
|
|
@ -212,6 +234,7 @@ public class Model : IDisposable
|
|||
|
||||
_vao.Bind();
|
||||
shader.Use();
|
||||
shader.SetUniform("uMorphTime", MorphTime);
|
||||
for (int section = 0; section < Sections.Length; section++)
|
||||
{
|
||||
if (!Sections[section].Show) continue;
|
||||
|
|
@ -230,9 +253,13 @@ public class Model : IDisposable
|
|||
_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++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -49,20 +45,11 @@ public class Morph : IDisposable
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -313,18 +313,26 @@ public class SnimGui : IDisposable
|
|||
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();
|
||||
|
|
@ -349,7 +357,7 @@ public class SnimGui : IDisposable
|
|||
{
|
||||
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
|
||||
{
|
||||
|
|
@ -358,7 +366,7 @@ public class SnimGui : IDisposable
|
|||
if (section.Textures[i] is not {} texture)
|
||||
continue;
|
||||
|
||||
DrawTexture(texture);
|
||||
DrawTexture(texture, section.TexturesLabels[i]);
|
||||
|
||||
if (i == 3) // emissive, show color
|
||||
{
|
||||
|
|
@ -366,11 +374,6 @@ public class SnimGui : IDisposable
|
|||
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();
|
||||
|
|
@ -378,7 +381,7 @@ public class SnimGui : IDisposable
|
|||
ImGui.End();
|
||||
}
|
||||
|
||||
private void DrawTexture(Texture texture)
|
||||
private void DrawTexture(Texture texture, string label)
|
||||
{
|
||||
ImGui.SameLine();
|
||||
ImGui.BeginGroup();
|
||||
|
|
@ -403,6 +406,11 @@ public class SnimGui : IDisposable
|
|||
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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user