Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,14 @@ private void ApplyGeoreferencedTexture(XElement textureElement)
{
if (!texturePayloadsByResolvedPath.TryGetValue(resolvedTexturePath, out TexturePayload? texturePayload))
{
texturePayload = new TexturePayload(
texturePayload = new EncodedImageTexturePayload(
null,
null,
"sRGB",
TextureImportSourceFactory.CreateDatasetEncodedImage(
datasetSource,
resolvedTexturePath,
"sRGB",
$"dataset:{resolvedTexturePath}"),
$"dataset:{resolvedTexturePath}",
TexturePayloadFormat.EncodedImage);
$"dataset:{resolvedTexturePath}"));
texturePayloadsByResolvedPath[resolvedTexturePath] = texturePayload;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal static MaterialGroupingKey CreateKey(

return new MaterialGroupingKey(
material.MaterialType,
material.TexturePayload?.Identity,
material.TexturePayload?.Source.Identity,
material.TextureSourceKind,
material.Projection,
depthOffset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,69 +96,89 @@ public sealed record MeshSubmesh(
int Index,
IReadOnlyList<int> TriangleVertexIndices);

public enum TexturePayloadFormat
public abstract record TexturePayload
{
RawRgba32 = 0,
EncodedImage = 1,
private protected TexturePayload(ITextureImportSource source)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentException.ThrowIfNullOrWhiteSpace(source.Identity);

Source = source;
}

public ITextureImportSource Source { get; }
}

public sealed record TexturePayload
public sealed record RawRgba32TexturePayload : TexturePayload
{
public TexturePayload(
int? width,
int? height,
public RawRgba32TexturePayload(
int width,
int height,
string? colorProfile,
byte[] binaryPayload,
string? identity = null,
TexturePayloadFormat format = TexturePayloadFormat.RawRgba32)
{
Width = width;
Height = height;
ColorProfile = colorProfile;
ArgumentNullException.ThrowIfNull(binaryPayload);
BinaryPayload = ImmutableArray.CreateRange(binaryPayload);
Identity = identity;
Format = format;
Source = TextureImportSourceFactory.CreateInMemory(
string? identity = null)
: this(
width,
height,
colorProfile,
binaryPayload,
identity ?? Guid.NewGuid().ToString("N"),
format);
CreateSource(width, height, colorProfile, binaryPayload, identity))
{
}

public TexturePayload(
int? width,
int? height,
private RawRgba32TexturePayload(
int width,
int height,
string? colorProfile,
ITextureImportSource source,
string? identity = null,
TexturePayloadFormat format = TexturePayloadFormat.EncodedImage)
byte[] binaryPayload,
ITextureImportSource source)
: base(source)
{
Rgba32RawTexturePayload.ValidateByteLength(width, height, binaryPayload);
Width = width;
Height = height;
ColorProfile = colorProfile;
ArgumentNullException.ThrowIfNull(source);
BinaryPayload = [];
Identity = identity ?? source.Identity;
Format = format;
Source = source;
BinaryPayload = ImmutableArray.CreateRange(binaryPayload);
}

public int? Width { get; init; }
public int Width { get; }

public int? Height { get; init; }
public int Height { get; }

public string? ColorProfile { get; init; }
public ImmutableArray<byte> BinaryPayload { get; }

public ImmutableArray<byte> BinaryPayload { get; init; }
private static ITextureImportSource CreateSource(
int width,
int height,
string? colorProfile,
byte[] binaryPayload,
string? identity)
{
ArgumentNullException.ThrowIfNull(binaryPayload);
string effectiveIdentity = identity ?? Guid.NewGuid().ToString("N");
return TextureImportSourceFactory.CreateInMemoryRaw(
width,
height,
colorProfile,
binaryPayload,
effectiveIdentity);
}
}

public string? Identity { get; init; }
public sealed record EncodedImageTexturePayload : TexturePayload
{
public EncodedImageTexturePayload(
int? width,
int? height,
ITextureImportSource source)
: base(source)
{
Width = width;
Height = height;
}

public TexturePayloadFormat Format { get; init; }
public int? Width { get; }

public ITextureImportSource Source { get; init; }
public int? Height { get; }
}

public enum TextureSourceKind
Expand Down
Loading
Loading