Skip to content

Commit 35dddf6

Browse files
handle null color and texcoord2 values
1 parent c807bbb commit 35dddf6

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Meddle/Meddle.Utils/MeshBuilder.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ private static Vector4 GetColor(Vertex vertex, MaterialBuilder materialBuilder)
297297
{
298298
return paintBuilder.VertexPaint switch
299299
{
300-
true => vertex.Color!.Value,
300+
true => vertex.Color ?? new Vector4(0, 0, 0, 0),
301301
false => new Vector4(1, 1, 1, 1)
302302
};
303303
}
@@ -356,15 +356,15 @@ private static IVertexMaterial CreateMaterialParamCache(Vertex vertex, Type type
356356
if (type == typeof(VertexColor1Texture3))
357357
{
358358
var texCoord = ToVec2(vertex.TexCoord!.Value);
359-
var texCoord2 = ToVec2(vertex.TexCoord2!.Value);
360-
return new VertexColor1Texture3(GetColor(vertex, materialBuilder), texCoord.XY, texCoord.ZW, texCoord2.XY);
359+
(Vector2 xy, Vector2 zw) texCoord2 = vertex.TexCoord2 != null ? ToVec2(vertex.TexCoord2!.Value) : (Vector2.Zero, Vector2.Zero);
360+
return new VertexColor1Texture3(GetColor(vertex, materialBuilder), texCoord.XY, texCoord.ZW, texCoord2.xy);
361361
}
362362

363363
if (type == typeof(VertexColor1Texture4))
364364
{
365365
var texCoord = ToVec2(vertex.TexCoord!.Value);
366-
var texCoord2 = ToVec2(vertex.TexCoord2!.Value);
367-
return new VertexColor1Texture4(GetColor(vertex, materialBuilder), texCoord.XY, texCoord.ZW, texCoord2.XY, texCoord2.ZW);
366+
(Vector2 xy, Vector2 zw) texCoord2 = vertex.TexCoord2 != null ? ToVec2(vertex.TexCoord2!.Value) : (Vector2.Zero, Vector2.Zero);
367+
return new VertexColor1Texture4(GetColor(vertex, materialBuilder), texCoord.XY, texCoord.ZW, texCoord2.xy, texCoord2.zw);
368368
}
369369

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

388388
if (type == typeof(VertexTexture4))
389389
{
390390
var texCoord = ToVec2(vertex.TexCoord!.Value);
391-
var texCoord2 = ToVec2(vertex.TexCoord2!.Value);
392-
return new VertexTexture4(texCoord.XY, texCoord.ZW, texCoord2.XY, texCoord2.ZW);
391+
392+
(Vector2 xy, Vector2 zw) texCoord2 = vertex.TexCoord2 != null ? ToVec2(vertex.TexCoord2!.Value) : (Vector2.Zero, Vector2.Zero);
393+
return new VertexTexture4(texCoord.XY, texCoord.ZW, texCoord2.xy, texCoord2.zw);
393394
}
394395

395396
return new VertexEmpty();

0 commit comments

Comments
 (0)