Skip to content
Closed
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 @@ -191,13 +191,11 @@ private void ApplyGeoreferencedTexture(XElement textureElement)
texturePayload = new EncodedImageTexturePayload(
null,
null,
"sRGB",
TextureImportSourceFactory.CreateDatasetEncodedImage(
datasetSource,
resolvedTexturePath,
"sRGB",
$"dataset:{resolvedTexturePath}"),
$"dataset:{resolvedTexturePath}");
$"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 @@ -98,24 +98,13 @@ public sealed record MeshSubmesh(

public abstract record TexturePayload
{
private protected TexturePayload(
string? colorProfile,
string identity,
ITextureImportSource source)
private protected TexturePayload(ITextureImportSource source)
{
if (string.IsNullOrWhiteSpace(identity))
{
throw new ArgumentException("Texture payload identity must be provided.", nameof(identity));
}

ColorProfile = colorProfile;
Identity = identity;
Source = source ?? throw new ArgumentNullException(nameof(source));
}

public string? ColorProfile { get; }
ArgumentNullException.ThrowIfNull(source);
ArgumentException.ThrowIfNullOrWhiteSpace(source.Identity);

public string Identity { get; }
Source = source;
}

public ITextureImportSource Source { get; }
}
Expand All @@ -142,8 +131,8 @@ private RawRgba32TexturePayload(
int height,
string? colorProfile,
byte[] binaryPayload,
(string Identity, ITextureImportSource Source) source)
: base(colorProfile, source.Identity, source.Source)
ITextureImportSource source)
: base(source)
{
ArgumentNullException.ThrowIfNull(binaryPayload);
Width = width;
Expand All @@ -157,7 +146,7 @@ private RawRgba32TexturePayload(

public ImmutableArray<byte> BinaryPayload { get; }

private static (string Identity, ITextureImportSource Source) CreateSource(
private static ITextureImportSource CreateSource(
int width,
int height,
string? colorProfile,
Expand All @@ -166,14 +155,12 @@ private static (string Identity, ITextureImportSource Source) CreateSource(
{
ArgumentNullException.ThrowIfNull(binaryPayload);
string effectiveIdentity = identity ?? Guid.NewGuid().ToString("N");
return (
effectiveIdentity,
TextureImportSourceFactory.CreateInMemoryRaw(
width,
height,
colorProfile,
binaryPayload,
effectiveIdentity));
return TextureImportSourceFactory.CreateInMemoryRaw(
width,
height,
colorProfile,
binaryPayload,
effectiveIdentity);
}
}

Expand All @@ -182,19 +169,8 @@ public sealed record EncodedImageTexturePayload : TexturePayload
public EncodedImageTexturePayload(
int? width,
int? height,
string? colorProfile,
ITextureImportSource source,
string? identity = null)
: this(width, height, colorProfile, CreateSource(source, identity))
{
}

private EncodedImageTexturePayload(
int? width,
int? height,
string? colorProfile,
(string Identity, ITextureImportSource Source) source)
: base(colorProfile, source.Identity, source.Source)
ITextureImportSource source)
: base(source)
{
Width = width;
Height = height;
Expand All @@ -203,14 +179,6 @@ private EncodedImageTexturePayload(
public int? Width { get; }

public int? Height { get; }

private static (string Identity, ITextureImportSource Source) CreateSource(
ITextureImportSource source,
string? identity)
{
ArgumentNullException.ThrowIfNull(source);
return (identity ?? source.Identity, source);
}
}

public enum TextureSourceKind
Expand Down
61 changes: 15 additions & 46 deletions src/PlateauResoniteLink/Targets/Resonite/ResoniteTexturePayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,15 @@ namespace PlateauResoniteLink.Targets.Resonite;

public abstract class ResoniteTexturePayload
{
private protected ResoniteTexturePayload(
string? colorProfile,
string identity,
ITextureImportSource source)
private protected ResoniteTexturePayload(ITextureImportSource source)
{
if (string.IsNullOrWhiteSpace(identity))
Source = source ?? throw new ArgumentNullException(nameof(source));
Comment thread
esnya marked this conversation as resolved.
if (string.IsNullOrWhiteSpace(Source.Identity))
{
throw new ArgumentException("Resonite texture payload identity must be provided.", nameof(identity));
throw new ArgumentException("Texture source identity must be non-empty.", nameof(source));
}

ColorProfile = colorProfile;
Identity = identity;
Source = source ?? throw new ArgumentNullException(nameof(source));
}

public string? ColorProfile { get; }

public string Identity { get; }

public ITextureImportSource Source { get; }
}

Expand All @@ -51,8 +41,8 @@ private RawRgba32ResoniteTexturePayload(
int height,
string? colorProfile,
byte[] binaryPayload,
(string Identity, ITextureImportSource Source) source)
: base(colorProfile, source.Identity, source.Source)
ITextureImportSource source)
: base(source)
{
ArgumentNullException.ThrowIfNull(binaryPayload);
Width = width;
Expand All @@ -66,7 +56,7 @@ private RawRgba32ResoniteTexturePayload(

public ImmutableArray<byte> BinaryPayload { get; }

private static (string Identity, ITextureImportSource Source) CreateSource(
private static ITextureImportSource CreateSource(
int width,
int height,
string? colorProfile,
Expand All @@ -75,14 +65,12 @@ private static (string Identity, ITextureImportSource Source) CreateSource(
{
ArgumentNullException.ThrowIfNull(binaryPayload);
string effectiveIdentity = identity ?? Guid.NewGuid().ToString("N");
return (
effectiveIdentity,
TextureImportSourceFactory.CreateInMemoryRaw(
width,
height,
colorProfile,
binaryPayload,
effectiveIdentity));
return TextureImportSourceFactory.CreateInMemoryRaw(
width,
height,
colorProfile,
binaryPayload,
effectiveIdentity);
}
}

Expand All @@ -91,19 +79,8 @@ public sealed class EncodedImageResoniteTexturePayload : ResoniteTexturePayload
public EncodedImageResoniteTexturePayload(
int? width,
int? height,
string? colorProfile,
ITextureImportSource source,
string? identity = null)
: this(width, height, colorProfile, CreateSource(source, identity))
{
}

private EncodedImageResoniteTexturePayload(
int? width,
int? height,
string? colorProfile,
(string Identity, ITextureImportSource Source) source)
: base(colorProfile, source.Identity, source.Source)
ITextureImportSource source)
: base(source)
{
Width = width;
Height = height;
Expand All @@ -112,12 +89,4 @@ private EncodedImageResoniteTexturePayload(
public int? Width { get; }

public int? Height { get; }

private static (string Identity, ITextureImportSource Source) CreateSource(
ITextureImportSource source,
string? identity)
{
ArgumentNullException.ThrowIfNull(source);
return (identity ?? source.Identity, source);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,13 @@ private static ResoniteTexturePayload ToInternal(TexturePayload payload)
RawRgba32TexturePayload raw => new RawRgba32ResoniteTexturePayload(
raw.Width,
raw.Height,
raw.ColorProfile,
raw.Source.ColorProfile,
raw.BinaryPayload.AsSpan().ToArray(),
raw.Identity),
raw.Source.Identity),
EncodedImageTexturePayload encoded => new EncodedImageResoniteTexturePayload(
encoded.Width,
encoded.Height,
encoded.ColorProfile,
encoded.Source,
encoded.Identity),
encoded.Source),
_ => throw new ArgumentOutOfRangeException(nameof(payload), payload.GetType(), "Unsupported texture payload type."),
};
}
Expand Down
29 changes: 29 additions & 0 deletions tests/PlateauResoniteLink.Tests/Application/TexturePayloadTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

using PlateauResoniteLink.Application.Importing;

namespace PlateauResoniteLink.Tests.Application;
Expand All @@ -14,4 +16,31 @@ public void ConstructorCopiesBinaryPayloadBytes()

Assert.Equal<byte>([1, 2, 3, 4], payload.BinaryPayload);
}

[Fact]
public void ConstructorCarriesIdentityAndColorProfileOnSourceOnly()
{
RawRgba32TexturePayload payload = new(1, 1, "sRGB", [1, 2, 3, 4], "dataset:texture");

Assert.Equal("dataset:texture", payload.Source.Identity);
Assert.Equal("sRGB", payload.Source.ColorProfile);
}

[Fact]
public void ConstructorRejectsTextureSourceWithoutIdentity()
{
Assert.Throws<ArgumentException>(
() => new EncodedImageTexturePayload(null, null, new BlankIdentityTextureImportSource()));
}

private sealed class BlankIdentityTextureImportSource : ITextureImportSource
{
public string Identity => " ";

public string Description => "blank";

public string? ColorProfile => null;

public long? EstimatedByteLength => null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2073,10 +2073,10 @@ public void ProjectCityObjectCullsBottomBandBuildingSurfacesBySemanticOrDownward
materialResolver: new DefaultMaterialResolver(CommonMaterialCatalog.Create()));

Assert.Equal(3, projected.Materials.Count);
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Identity == "ground");
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Identity == "ground-reversed");
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Identity == "outer-floor");
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Identity == "high-outer-floor");
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Source.Identity == "ground");
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Source.Identity == "ground-reversed");
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Source.Identity == "outer-floor");
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Source.Identity == "high-outer-floor");
}

[Fact]
Expand Down Expand Up @@ -2113,7 +2113,7 @@ public void ProjectCityObjectKeepsNonBuildingDownwardHorizontalGroundSurface()
materialResolver: new DefaultMaterialResolver(CommonMaterialCatalog.Create()));

Assert.Single(projected.Materials);
Assert.Equal("tran-ground", projected.Materials[0].TexturePayload?.Identity);
Assert.Equal("tran-ground", projected.Materials[0].TexturePayload?.Source.Identity);
Assert.NotEmpty(projected.Mesh.Vertices);
}

Expand Down Expand Up @@ -2171,10 +2171,10 @@ public void ProjectCityObjectCullsBuildingLod1UnknownBottomBandSurfaces()
materialResolver: new DefaultMaterialResolver(CommonMaterialCatalog.Create()));

Assert.Equal(2, projected.Materials.Count);
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Identity == "lod1-bottom");
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Identity == "lod1-bottom-reversed");
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Identity == "lod1-roof");
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Identity == "lod1-wall");
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Source.Identity == "lod1-bottom");
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Source.Identity == "lod1-bottom-reversed");
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Source.Identity == "lod1-roof");
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Source.Identity == "lod1-wall");
}

[Fact]
Expand Down Expand Up @@ -2246,7 +2246,7 @@ public void ProjectCityObjectKeepsSingleDownwardHorizontalBuildingSurfaceWhenNoH
materialResolver: new DefaultMaterialResolver(CommonMaterialCatalog.Create()));

Assert.Single(projected.Materials);
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Identity == "only-surface");
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Source.Identity == "only-surface");
}

[Fact]
Expand Down Expand Up @@ -2378,7 +2378,7 @@ await service.ExecuteAsync(
Assert.NotNull(explicitMaterial.TexturePayload);
Assert.Contains(
"udx/dem/53394525/appearance/mixed_surface.png",
explicitMaterial.TexturePayload!.Identity,
explicitMaterial.TexturePayload!.Source.Identity,
StringComparison.Ordinal);
}

Expand Down
Loading
Loading