diff --git a/FModel/Resources/default.frag b/FModel/Resources/default.frag
index 88f2be43..84b656d9 100644
--- a/FModel/Resources/default.frag
+++ b/FModel/Resources/default.frag
@@ -89,7 +89,7 @@ struct Light {
uniform Parameters uParameters;
uniform Light uLights[MAX_LIGHT_COUNT];
uniform int uNumLights;
-uniform int uNumTexCoords;
+uniform int uUvCount;
uniform bool uHasVertexColors;
uniform bool bVertexColors[6];
uniform vec3 uViewPos;
@@ -98,7 +98,7 @@ out vec4 FragColor;
int LayerToIndex()
{
- return clamp(int(fTexLayer), 0, uNumTexCoords - 1);
+ return clamp(int(fTexLayer), 0, uUvCount - 1);
}
vec2 ScaledTexCoords()
diff --git a/FModel/Views/Snooper/Material.cs b/FModel/Views/Snooper/Material.cs
index 71482cac..4211357e 100644
--- a/FModel/Views/Snooper/Material.cs
+++ b/FModel/Views/Snooper/Material.cs
@@ -65,11 +65,11 @@ public class Material : IDisposable
unrealMaterial.GetParams(Parameters);
}
- public void Setup(Options options, int numTexCoords)
+ public void Setup(Options options, int uvCount)
{
_handle = GL.CreateProgram();
- if (numTexCoords < 1 || Parameters.IsNull)
+ if (uvCount < 1 || Parameters.IsNull)
{
Diffuse = new[] { new Texture(new FLinearColor(1f, 0f, 0f, 1f)) };
Normals = new[] { new Texture(new FLinearColor(0.498f, 0.498f, 0.996f, 1f))};
@@ -81,15 +81,15 @@ public class Material : IDisposable
else
{
{ // textures
- Diffuse = FillTextures(options, numTexCoords, Parameters.HasTopDiffuse, CMaterialParams2.Diffuse, CMaterialParams2.FallbackDiffuse, true);
- Normals = FillTextures(options, numTexCoords, Parameters.HasTopNormals, CMaterialParams2.Normals, CMaterialParams2.FallbackNormals);
- SpecularMasks = FillTextures(options, numTexCoords, Parameters.HasTopSpecularMasks, CMaterialParams2.SpecularMasks, CMaterialParams2.FallbackSpecularMasks);
- Emissive = FillTextures(options, numTexCoords, true, CMaterialParams2.Emissive, CMaterialParams2.FallbackEmissive);
+ Diffuse = FillTextures(options, uvCount, Parameters.HasTopDiffuse, CMaterialParams2.Diffuse, CMaterialParams2.FallbackDiffuse, true);
+ Normals = FillTextures(options, uvCount, Parameters.HasTopNormals, CMaterialParams2.Normals, CMaterialParams2.FallbackNormals);
+ SpecularMasks = FillTextures(options, uvCount, Parameters.HasTopSpecularMasks, CMaterialParams2.SpecularMasks, CMaterialParams2.FallbackSpecularMasks);
+ Emissive = FillTextures(options, uvCount, true, CMaterialParams2.Emissive, CMaterialParams2.FallbackEmissive);
}
{ // colors
- DiffuseColor = FillColors(numTexCoords, Diffuse, CMaterialParams2.DiffuseColors, Vector4.One);
- EmissiveColor = FillColors(numTexCoords, Emissive, CMaterialParams2.EmissiveColors, Vector4.One);
+ DiffuseColor = FillColors(uvCount, Diffuse, CMaterialParams2.DiffuseColors, Vector4.One);
+ EmissiveColor = FillColors(uvCount, Emissive, CMaterialParams2.EmissiveColors, Vector4.One);
}
{ // scalars
@@ -133,17 +133,17 @@ public class Material : IDisposable
}
/// just the cache object
- /// number of item in the array
+ /// number of item in the array
/// has at least 1 clearly defined texture, else will go straight to fallback
/// list of texture parameter names by uv channel
/// fallback texture name to use if no top texture found
/// if no top texture, no fallback texture, then use the first texture found
- private Texture[] FillTextures(Options options, int numTexCoords, bool top, IReadOnlyList triggers, string fallback, bool first = false)
+ private Texture[] FillTextures(Options options, int uvCount, bool top, IReadOnlyList triggers, string fallback, bool first = false)
{
UTexture2D original;
Texture transformed;
var fix = fallback == CMaterialParams2.FallbackSpecularMasks;
- var textures = new Texture[numTexCoords];
+ var textures = new Texture[uvCount];
if (top)
{
@@ -168,13 +168,13 @@ public class Material : IDisposable
return textures;
}
- /// number of item in the array
+ /// number of item in the array
/// reference array
/// list of color parameter names by uv channel
/// fallback color to use if no trigger was found
- private Vector4[] FillColors(int numTexCoords, IReadOnlyList textures, IReadOnlyList triggers, Vector4 fallback)
+ private Vector4[] FillColors(int uvCount, IReadOnlyList textures, IReadOnlyList triggers, Vector4 fallback)
{
- var colors = new Vector4[numTexCoords];
+ var colors = new Vector4[uvCount];
for (int i = 0; i < colors.Length; i++)
{
if (textures[i] == null) continue;
@@ -297,8 +297,8 @@ public class Material : IDisposable
{
if (ImGui.BeginTable("material_textures", 2))
{
- SnimGui.Layout("Channel");ImGui.PushID(1); ImGui.BeginDisabled(model.NumTexCoords < 2);
- ImGui.DragInt("", ref SelectedChannel, _step, 0, model.NumTexCoords - 1, "UV %i", ImGuiSliderFlags.AlwaysClamp);
+ SnimGui.Layout("Channel");ImGui.PushID(1); ImGui.BeginDisabled(model.UvCount < 2);
+ ImGui.DragInt("", ref SelectedChannel, _step, 0, model.UvCount - 1, "UV %i", ImGuiSliderFlags.AlwaysClamp);
ImGui.EndDisabled();ImGui.PopID();SnimGui.Layout("Type");ImGui.PushID(2);
ImGui.Combo("texture_type", ref SelectedTexture, "Diffuse\0Normals\0Specular\0Ambient Occlusion\0Emissive\0");
ImGui.PopID();
diff --git a/FModel/Views/Snooper/Model.cs b/FModel/Views/Snooper/Model.cs
index 12c3c60b..6e1acd9e 100644
--- a/FModel/Views/Snooper/Model.cs
+++ b/FModel/Views/Snooper/Model.cs
@@ -37,7 +37,7 @@ public class Model : IDisposable
public readonly string Type;
public readonly bool HasVertexColors;
public readonly bool HasMorphTargets;
- public readonly int NumTexCoords;
+ public readonly int UvCount;
public uint[] Indices;
public float[] Vertices;
public Section[] Sections;
@@ -64,13 +64,13 @@ public class Model : IDisposable
Path = _export.GetPathName();
Name = Path.SubstringAfterLast('/').SubstringBefore('.');
Type = export.ExportType;
- NumTexCoords = 1;
+ UvCount = 1;
Transforms = new List();
}
public Model(UStaticMesh export, CStaticMesh staticMesh) : this(export, staticMesh, Transform.Identity) {}
- public Model(UStaticMesh export, CStaticMesh staticMesh, Transform transform) : this(export, export.Materials, null, staticMesh.LODs[0], staticMesh.LODs[0].Verts, transform) {}
- private Model(USkeletalMesh export, CSkeletalMesh skeletalMesh, Transform transform) : this(export, export.Materials, export.Skeleton, skeletalMesh.LODs[0], skeletalMesh.LODs[0].Verts, transform) {}
+ public Model(UStaticMesh export, CStaticMesh staticMesh, Transform transform) : this(export, export.Materials, null, staticMesh.LODs.Count, staticMesh.LODs[0], staticMesh.LODs[0].Verts, transform) {}
+ private Model(USkeletalMesh export, CSkeletalMesh skeletalMesh, Transform transform) : this(export, export.Materials, export.Skeleton, skeletalMesh.LODs.Count, skeletalMesh.LODs[0], skeletalMesh.LODs[0].Verts, transform) {}
public Model(USkeletalMesh export, CSkeletalMesh skeletalMesh) : this(export, skeletalMesh, Transform.Identity)
{
var morphTargets = export.MorphTargets;
@@ -89,9 +89,10 @@ public class Model : IDisposable
ApplicationService.ApplicationView.Status.UpdateStatusLabel("");
}
- private Model(UObject export, ResolvedObject[] materials, FPackageIndex skeleton, CBaseMeshLod lod, CMeshVertex[] vertices, Transform transform = null) : this(export)
+ private Model(UObject export, ResolvedObject[] materials, FPackageIndex skeleton, int numLods, CBaseMeshLod lod, CMeshVertex[] vertices, Transform transform = null) : this(export)
{
- NumTexCoords = lod.NumTexCoords;
+ var hasCustomUvs = lod.ExtraUV.IsValueCreated;
+ UvCount = hasCustomUvs ? Math.Max(lod.NumTexCoords, numLods) : lod.NumTexCoords;
Materials = new Material[materials.Length];
for (int m = 0; m < Materials.Length; m++)
@@ -136,7 +137,7 @@ public class Model : IDisposable
Vertices[baseIndex + count++] = vert.Tangent.Y;
Vertices[baseIndex + count++] = vert.UV.U;
Vertices[baseIndex + count++] = vert.UV.V;
- Vertices[baseIndex + count++] = lod.ExtraUV.IsValueCreated ? lod.ExtraUV.Value[0][i].U : .5f;
+ Vertices[baseIndex + count++] = hasCustomUvs ? lod.ExtraUV.Value[0][i].U : .5f;
if (HasVertexColors)
{
@@ -226,7 +227,7 @@ public class Model : IDisposable
for (var i = 0; i < Materials.Length; i++)
{
if (!Materials[i].IsUsed) continue;
- Materials[i].Setup(options, broken ? 1 : NumTexCoords);
+ Materials[i].Setup(options, broken ? 1 : UvCount);
}
if (HasMorphTargets)
@@ -261,7 +262,7 @@ public class Model : IDisposable
_vao.Bind();
shader.SetUniform("uMorphTime", MorphTime);
- shader.SetUniform("uNumTexCoords", NumTexCoords);
+ shader.SetUniform("uUvCount", UvCount);
shader.SetUniform("uHasVertexColors", HasVertexColors);
GL.PolygonMode(MaterialFace.FrontAndBack, Wireframe ? PolygonMode.Line : PolygonMode.Fill);
diff --git a/FModel/Views/Snooper/Renderer.cs b/FModel/Views/Snooper/Renderer.cs
index b08d6db0..cc71db28 100644
--- a/FModel/Views/Snooper/Renderer.cs
+++ b/FModel/Views/Snooper/Renderer.cs
@@ -65,7 +65,7 @@ public class Renderer : IDisposable
if (!Options.TryGetModel(out var model) || !Options.TryGetSection(model, out var section)) return;
model.Materials[section.MaterialIndex].SwapMaterial(unrealMaterial);
- Application.Current.Dispatcher.Invoke(() => model.Materials[section.MaterialIndex].Setup(Options, model.NumTexCoords));
+ Application.Current.Dispatcher.Invoke(() => model.Materials[section.MaterialIndex].Setup(Options, model.UvCount));
Options.SwapMaterial(false);
}
diff --git a/FModel/Views/Snooper/SnimGui.cs b/FModel/Views/Snooper/SnimGui.cs
index e2df5cf5..22198c8b 100644
--- a/FModel/Views/Snooper/SnimGui.cs
+++ b/FModel/Views/Snooper/SnimGui.cs
@@ -321,7 +321,7 @@ hello world!
ImGui.Text(model.TransformsCount.ToString("D"));
ImGui.TableNextColumn();
- ImGui.Text(model.NumTexCoords.ToString("D"));
+ ImGui.Text(model.UvCount.ToString("D"));
ImGui.TableNextColumn();
if (ImGui.Selectable(model.Name, s.Renderer.Options.SelectedModel == guid, ImGuiSelectableFlags.SpanAllColumns))
{