Skip to content

Commit

Permalink
Support for having flat normals
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian King committed Feb 5, 2025
1 parent 4e34fe7 commit 42b209c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
13 changes: 11 additions & 2 deletions Robust.Client/ResourceManagement/ResourceTypes/RSIResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,17 @@ internal static void CreatePlaceholderBump(Image<Rgba32> original, Vector2i bloc
}
}

internal static void CreatePlaceholderNormal(Image<Rgba32> original, Vector2i blocksize, out Image<Rgba32> normalmap)
internal static void CreatePlaceholderNormal(Image<Rgba32> original, Vector2i blocksize, out Image<Rgba32> normalmap, bool? flat = false)
{
if (flat ?? false)
{
normalmap = new Image<Rgba32>(original.Width, original.Height);
int x, y;
for (x = 0; x < original.Width; x++)
for (y = 0; y < original.Height; y++)
normalmap[x, y] = new Rgba32(0.5f, 0.5f, 1f);
return;
}
CreatePlaceholderBump(original, blocksize, out var bumpmap);
ConvertBumpToNormal(bumpmap, blocksize, out normalmap);
bumpmap.Dispose();
Expand Down Expand Up @@ -213,7 +222,7 @@ internal static void LoadPreTexture(IResourceManager manager, LoadStepData data,
}
else
{
CreatePlaceholderNormal(texture, stateObject.Size, out normalImage);
CreatePlaceholderNormal(texture, stateObject.Size, out normalImage, metadata.FlatNormal ?? stateObject.FlatNormal ?? false);
}
}
if (normalLoading)
Expand Down
15 changes: 10 additions & 5 deletions Robust.Shared/Resources/RsiLoading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ internal static RsiMetadata LoadRsiMetadata(Stream manifestFile)
var stateName = stateObject.Name;
var normalName = stateObject.Normal;
var bumpName = stateObject.Bump;
var flatNormal = stateObject.FlatNormal;
int dirValue;

if (stateObject.Directions is { } dirVal)
Expand Down Expand Up @@ -93,7 +94,7 @@ internal static RsiMetadata LoadRsiMetadata(Stream manifestFile)
}
}

states[stateI] = new StateMetadata(stateName, normalName, bumpName, size, dirValue, delays);
states[stateI] = new StateMetadata(stateName, normalName, bumpName, flatNormal, size, dirValue, delays);
}

var textureParams = TextureLoadParameters.Default;
Expand All @@ -106,7 +107,7 @@ internal static RsiMetadata LoadRsiMetadata(Stream manifestFile)
};
}

return new RsiMetadata(size, states, textureParams, manifestJson.MetaAtlas);
return new RsiMetadata(size, states, manifestJson.FlatNormal, textureParams, manifestJson.MetaAtlas);
}

public static void Warmup()
Expand All @@ -116,10 +117,11 @@ public static void Warmup()
JsonSerializer.Deserialize<RsiJsonMetadata>(warmupJson, SerializerOptions);
}

internal sealed class RsiMetadata(Vector2i size, StateMetadata[] states, TextureLoadParameters loadParameters, bool metaAtlas)
internal sealed class RsiMetadata(Vector2i size, StateMetadata[] states, bool? flatNormal, TextureLoadParameters loadParameters, bool metaAtlas)
{
public readonly Vector2i Size = size;
public readonly StateMetadata[] States = states;
public readonly bool? FlatNormal = flatNormal;
public readonly TextureLoadParameters LoadParameters = loadParameters;
public readonly bool MetaAtlas = metaAtlas;
}
Expand All @@ -129,15 +131,17 @@ internal sealed class StateMetadata
public readonly string StateId;
public readonly string? NormalId;
public readonly string? BumpId;
public readonly bool? FlatNormal;
public readonly Vector2i Size;
public readonly int DirCount;
public readonly float[][] Delays;

public StateMetadata(string stateId, string? normalId, string? bumpId, Vector2i size, int dirCount, float[][] delays)
public StateMetadata(string stateId, string? normalId, string? bumpId, bool? flatNormal, Vector2i size, int dirCount, float[][] delays)
{
StateId = stateId;
NormalId = normalId;
BumpId = bumpId;
FlatNormal = flatNormal;
Size = size;
DirCount = dirCount;

Expand All @@ -152,11 +156,12 @@ public StateMetadata(string stateId, string? normalId, string? bumpId, Vector2i
private sealed record RsiJsonMetadata(
Vector2i Size,
StateJsonMetadata[] States,
bool? FlatNormal,
RsiJsonLoad? Load,
bool MetaAtlas = true);

[UsedImplicitly]
private sealed record StateJsonMetadata(string Name, string? Normal, string? Bump, int? Directions, float[][]? Delays);
private sealed record StateJsonMetadata(string Name, string? Normal, string? Bump, bool? FlatNormal, int? Directions, float[][]? Delays);

[UsedImplicitly]
private sealed record RsiJsonLoad(bool Srgb = true);
Expand Down

0 comments on commit 42b209c

Please sign in to comment.