Skip to content

Commit

Permalink
More fixes for multiple UVs, viewing multiple color channels, and exp…
Browse files Browse the repository at this point in the history
…orting.
  • Loading branch information
KillzXGaming committed Oct 17, 2024
1 parent e84323f commit 995e16f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static void SetVertexBuffer(IOMesh mesh, ResFile resFile, Shape shape, Model mod
var indices0 = TryGetValues(helper, "_i0");
var texCoordsCombined1 = TryGetValues(helper, "_g3d_02_u0_u1");
var texCoordsCombined2 = TryGetValues(helper, "_g3d_02_u2_u1");
var texCoordsCombined3 = TryGetValues(helper, "_g3d_02_u2_u3");

//Get the position attribute and use the length for the vertex count
for (int v = 0; v < positions.Length; v++)
Expand All @@ -105,6 +106,16 @@ static void SetVertexBuffer(IOMesh mesh, ResFile resFile, Shape shape, Model mod
vertex.SetUV(texCoordsCombined1[v].X, 1 - texCoordsCombined1[v].Y, 0);
vertex.SetUV(texCoordsCombined1[v].Z, 1 - texCoordsCombined1[v].W, 1);
}
if (texCoordsCombined2.Length > 0)
{
vertex.SetUV(texCoordsCombined2[v].X, 1 - texCoordsCombined2[v].Y, 2);
vertex.SetUV(texCoordsCombined2[v].Z, 1 - texCoordsCombined2[v].W, 3);
}
if (texCoordsCombined3.Length > 0)
{
vertex.SetUV(texCoordsCombined3[v].X, 1 - texCoordsCombined3[v].Y, 2);
vertex.SetUV(texCoordsCombined3[v].Z, 1 - texCoordsCombined3[v].W, 3);
}

if (colors.Length > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -989,43 +989,36 @@ private static VertexBuffer GenerateVertexBuffer(ResFile resFile, IOMesh mesh, S
});
}

for (int i = 0; i < TexCoords.Length; i++)
if (settings.CombineUVs && TexCoords.Length > 0)
{
var format = i == 0 ? settings.UVs.Format : settings.UV_Layers.Format;

if (settings.UseTexCoord[i])
//Combine types will use 2 layer types
attributes.Add(new VertexBufferHelperAttrib()
{
Name = $"_g3d_02_u0_u1",
Data = TexCoords[0],
Format = GX2AttribFormat.Format_16_16_16_16_Single,
});
if (TexCoords.Length > 1)
{
if (settings.CombineUVs)
attributes.Add(new VertexBufferHelperAttrib()
{
//Combine and only use even coords
if (i % 2 == 0 && i < TexCoords.Length - 1)
{
attributes.Add(new VertexBufferHelperAttrib()
{
Name = $"_g3d_02_u0_u1",
Data = TexCoords[i],
Format = GX2AttribFormat.Format_16_16_16_16_Single,
});
}
else if (i == TexCoords.Length - 1) //else check if last element
{
attributes.Add(new VertexBufferHelperAttrib()
{
Name = $"_u{i}",
Data = TexCoords[i],
Format = format,
});
}
}
else
Name = $"_g3d_02_u2_u3",
Data = TexCoords[1],
Format = GX2AttribFormat.Format_16_16_16_16_Single,
});
}
}
else
{
for (int i = 0; i < TexCoords.Length; i++)
{
var format = i == 0 ? settings.UVs.Format : settings.UV_Layers.Format;
attributes.Add(new VertexBufferHelperAttrib()
{
attributes.Add(new VertexBufferHelperAttrib()
{
Name = $"_u{i}",
Data = TexCoords[i],
Format = format,
});
}
Name = $"_u{i}",
Data = TexCoords[i],
Format = format,
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion Plugins/CafeLibrary/Bfres/Imgui/Mesh/BfresVertexViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override void Render()
}

ImGui.NextColumn();
if (ActiveAttribute.Name.StartsWith("_c0"))
if (ActiveAttribute.Name.StartsWith("_c"))
{
for (int j = 0; j < elements.Length - 1; j++)
{
Expand Down

0 comments on commit 995e16f

Please sign in to comment.