Skip to content

Commit

Permalink
handle null color and texcoord2 values
Browse files Browse the repository at this point in the history
  • Loading branch information
PassiveModding committed Jan 12, 2025
1 parent c807bbb commit 35dddf6
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions Meddle/Meddle.Utils/MeshBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private static Vector4 GetColor(Vertex vertex, MaterialBuilder materialBuilder)
{
return paintBuilder.VertexPaint switch
{
true => vertex.Color!.Value,
true => vertex.Color ?? new Vector4(0, 0, 0, 0),
false => new Vector4(1, 1, 1, 1)
};
}
Expand Down Expand Up @@ -356,15 +356,15 @@ private static IVertexMaterial CreateMaterialParamCache(Vertex vertex, Type type
if (type == typeof(VertexColor1Texture3))
{
var texCoord = ToVec2(vertex.TexCoord!.Value);
var texCoord2 = ToVec2(vertex.TexCoord2!.Value);
return new VertexColor1Texture3(GetColor(vertex, materialBuilder), texCoord.XY, texCoord.ZW, texCoord2.XY);
(Vector2 xy, Vector2 zw) texCoord2 = vertex.TexCoord2 != null ? ToVec2(vertex.TexCoord2!.Value) : (Vector2.Zero, Vector2.Zero);
return new VertexColor1Texture3(GetColor(vertex, materialBuilder), texCoord.XY, texCoord.ZW, texCoord2.xy);
}

if (type == typeof(VertexColor1Texture4))
{
var texCoord = ToVec2(vertex.TexCoord!.Value);
var texCoord2 = ToVec2(vertex.TexCoord2!.Value);
return new VertexColor1Texture4(GetColor(vertex, materialBuilder), texCoord.XY, texCoord.ZW, texCoord2.XY, texCoord2.ZW);
(Vector2 xy, Vector2 zw) texCoord2 = vertex.TexCoord2 != null ? ToVec2(vertex.TexCoord2!.Value) : (Vector2.Zero, Vector2.Zero);
return new VertexColor1Texture4(GetColor(vertex, materialBuilder), texCoord.XY, texCoord.ZW, texCoord2.xy, texCoord2.zw);
}

if (type == typeof(VertexTexture1))
Expand All @@ -381,15 +381,16 @@ private static IVertexMaterial CreateMaterialParamCache(Vertex vertex, Type type
if (type == typeof(VertexTexture3))
{
var texCoord = ToVec2(vertex.TexCoord!.Value);
var texCoord2 = ToVec2(vertex.TexCoord2!.Value);
return new VertexTexture3(texCoord.XY, texCoord.ZW, texCoord2.XY);
(Vector2 xy, Vector2 zw) texCoord2 = vertex.TexCoord2 != null ? ToVec2(vertex.TexCoord2!.Value) : (Vector2.Zero, Vector2.Zero);
return new VertexTexture3(texCoord.XY, texCoord.ZW, texCoord2.xy);
}

if (type == typeof(VertexTexture4))
{
var texCoord = ToVec2(vertex.TexCoord!.Value);
var texCoord2 = ToVec2(vertex.TexCoord2!.Value);
return new VertexTexture4(texCoord.XY, texCoord.ZW, texCoord2.XY, texCoord2.ZW);

(Vector2 xy, Vector2 zw) texCoord2 = vertex.TexCoord2 != null ? ToVec2(vertex.TexCoord2!.Value) : (Vector2.Zero, Vector2.Zero);
return new VertexTexture4(texCoord.XY, texCoord.ZW, texCoord2.xy, texCoord2.zw);
}

return new VertexEmpty();
Expand Down

0 comments on commit 35dddf6

Please sign in to comment.