Skip to content

Commit 4e7929b

Browse files
committed
Use texture source as payload identity carrier
1 parent 4188c2c commit 4e7929b

11 files changed

Lines changed: 93 additions & 129 deletions

src/PlateauResoniteLink/Application/Importing/CityGmlAppearanceStore.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,11 @@ private void ApplyGeoreferencedTexture(XElement textureElement)
191191
texturePayload = new EncodedImageTexturePayload(
192192
null,
193193
null,
194-
"sRGB",
195194
TextureImportSourceFactory.CreateDatasetEncodedImage(
196195
datasetSource,
197196
resolvedTexturePath,
198197
"sRGB",
199-
$"dataset:{resolvedTexturePath}"),
200-
$"dataset:{resolvedTexturePath}");
198+
$"dataset:{resolvedTexturePath}"));
201199
texturePayloadsByResolvedPath[resolvedTexturePath] = texturePayload;
202200
}
203201

src/PlateauResoniteLink/Application/Importing/MaterialGroupingPolicy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal static MaterialGroupingKey CreateKey(
3333

3434
return new MaterialGroupingKey(
3535
material.MaterialType,
36-
material.TexturePayload?.Identity,
36+
material.TexturePayload?.Source.Identity,
3737
material.TextureSourceKind,
3838
material.Projection,
3939
depthOffset,

src/PlateauResoniteLink/Application/Importing/SceneImportContractTypes.cs

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,14 @@ public sealed record MeshSubmesh(
9898

9999
public abstract record TexturePayload
100100
{
101-
private protected TexturePayload(
102-
string? colorProfile,
103-
string identity,
104-
ITextureImportSource source)
101+
private protected TexturePayload(ITextureImportSource source)
105102
{
106-
if (string.IsNullOrWhiteSpace(identity))
107-
{
108-
throw new ArgumentException("Texture payload identity must be provided.", nameof(identity));
109-
}
103+
ArgumentNullException.ThrowIfNull(source);
104+
ArgumentException.ThrowIfNullOrWhiteSpace(source.Identity);
110105

111-
ColorProfile = colorProfile;
112-
Identity = identity;
113-
Source = source ?? throw new ArgumentNullException(nameof(source));
106+
Source = source;
114107
}
115108

116-
public string? ColorProfile { get; }
117-
118-
public string Identity { get; }
119-
120109
public ITextureImportSource Source { get; }
121110
}
122111

@@ -142,8 +131,8 @@ private RawRgba32TexturePayload(
142131
int height,
143132
string? colorProfile,
144133
byte[] binaryPayload,
145-
(string Identity, ITextureImportSource Source) source)
146-
: base(colorProfile, source.Identity, source.Source)
134+
ITextureImportSource source)
135+
: base(source)
147136
{
148137
ArgumentNullException.ThrowIfNull(binaryPayload);
149138
Width = width;
@@ -157,7 +146,7 @@ private RawRgba32TexturePayload(
157146

158147
public ImmutableArray<byte> BinaryPayload { get; }
159148

160-
private static (string Identity, ITextureImportSource Source) CreateSource(
149+
private static ITextureImportSource CreateSource(
161150
int width,
162151
int height,
163152
string? colorProfile,
@@ -166,14 +155,12 @@ private static (string Identity, ITextureImportSource Source) CreateSource(
166155
{
167156
ArgumentNullException.ThrowIfNull(binaryPayload);
168157
string effectiveIdentity = identity ?? Guid.NewGuid().ToString("N");
169-
return (
170-
effectiveIdentity,
171-
TextureImportSourceFactory.CreateInMemoryRaw(
172-
width,
173-
height,
174-
colorProfile,
175-
binaryPayload,
176-
effectiveIdentity));
158+
return TextureImportSourceFactory.CreateInMemoryRaw(
159+
width,
160+
height,
161+
colorProfile,
162+
binaryPayload,
163+
effectiveIdentity);
177164
}
178165
}
179166

@@ -182,19 +169,8 @@ public sealed record EncodedImageTexturePayload : TexturePayload
182169
public EncodedImageTexturePayload(
183170
int? width,
184171
int? height,
185-
string? colorProfile,
186-
ITextureImportSource source,
187-
string? identity = null)
188-
: this(width, height, colorProfile, CreateSource(source, identity))
189-
{
190-
}
191-
192-
private EncodedImageTexturePayload(
193-
int? width,
194-
int? height,
195-
string? colorProfile,
196-
(string Identity, ITextureImportSource Source) source)
197-
: base(colorProfile, source.Identity, source.Source)
172+
ITextureImportSource source)
173+
: base(source)
198174
{
199175
Width = width;
200176
Height = height;
@@ -203,14 +179,6 @@ private EncodedImageTexturePayload(
203179
public int? Width { get; }
204180

205181
public int? Height { get; }
206-
207-
private static (string Identity, ITextureImportSource Source) CreateSource(
208-
ITextureImportSource source,
209-
string? identity)
210-
{
211-
ArgumentNullException.ThrowIfNull(source);
212-
return (identity ?? source.Identity, source);
213-
}
214182
}
215183

216184
public enum TextureSourceKind

src/PlateauResoniteLink/Targets/Resonite/ResoniteTexturePayload.cs

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,11 @@ namespace PlateauResoniteLink.Targets.Resonite;
77

88
public abstract class ResoniteTexturePayload
99
{
10-
private protected ResoniteTexturePayload(
11-
string? colorProfile,
12-
string identity,
13-
ITextureImportSource source)
10+
private protected ResoniteTexturePayload(ITextureImportSource source)
1411
{
15-
if (string.IsNullOrWhiteSpace(identity))
16-
{
17-
throw new ArgumentException("Resonite texture payload identity must be provided.", nameof(identity));
18-
}
19-
20-
ColorProfile = colorProfile;
21-
Identity = identity;
2212
Source = source ?? throw new ArgumentNullException(nameof(source));
2313
}
2414

25-
public string? ColorProfile { get; }
26-
27-
public string Identity { get; }
28-
2915
public ITextureImportSource Source { get; }
3016
}
3117

@@ -51,8 +37,8 @@ private RawRgba32ResoniteTexturePayload(
5137
int height,
5238
string? colorProfile,
5339
byte[] binaryPayload,
54-
(string Identity, ITextureImportSource Source) source)
55-
: base(colorProfile, source.Identity, source.Source)
40+
ITextureImportSource source)
41+
: base(source)
5642
{
5743
ArgumentNullException.ThrowIfNull(binaryPayload);
5844
Width = width;
@@ -66,7 +52,7 @@ private RawRgba32ResoniteTexturePayload(
6652

6753
public ImmutableArray<byte> BinaryPayload { get; }
6854

69-
private static (string Identity, ITextureImportSource Source) CreateSource(
55+
private static ITextureImportSource CreateSource(
7056
int width,
7157
int height,
7258
string? colorProfile,
@@ -75,14 +61,12 @@ private static (string Identity, ITextureImportSource Source) CreateSource(
7561
{
7662
ArgumentNullException.ThrowIfNull(binaryPayload);
7763
string effectiveIdentity = identity ?? Guid.NewGuid().ToString("N");
78-
return (
79-
effectiveIdentity,
80-
TextureImportSourceFactory.CreateInMemoryRaw(
81-
width,
82-
height,
83-
colorProfile,
84-
binaryPayload,
85-
effectiveIdentity));
64+
return TextureImportSourceFactory.CreateInMemoryRaw(
65+
width,
66+
height,
67+
colorProfile,
68+
binaryPayload,
69+
effectiveIdentity);
8670
}
8771
}
8872

@@ -91,19 +75,8 @@ public sealed class EncodedImageResoniteTexturePayload : ResoniteTexturePayload
9175
public EncodedImageResoniteTexturePayload(
9276
int? width,
9377
int? height,
94-
string? colorProfile,
95-
ITextureImportSource source,
96-
string? identity = null)
97-
: this(width, height, colorProfile, CreateSource(source, identity))
98-
{
99-
}
100-
101-
private EncodedImageResoniteTexturePayload(
102-
int? width,
103-
int? height,
104-
string? colorProfile,
105-
(string Identity, ITextureImportSource Source) source)
106-
: base(colorProfile, source.Identity, source.Source)
78+
ITextureImportSource source)
79+
: base(source)
10780
{
10881
Width = width;
10982
Height = height;
@@ -112,12 +85,4 @@ private EncodedImageResoniteTexturePayload(
11285
public int? Width { get; }
11386

11487
public int? Height { get; }
115-
116-
private static (string Identity, ITextureImportSource Source) CreateSource(
117-
ITextureImportSource source,
118-
string? identity)
119-
{
120-
ArgumentNullException.ThrowIfNull(source);
121-
return (identity ?? source.Identity, source);
122-
}
12388
}

src/PlateauResoniteLink/Targets/Resonite/SceneImportContractMapper.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,13 @@ private static ResoniteTexturePayload ToInternal(TexturePayload payload)
144144
RawRgba32TexturePayload raw => new RawRgba32ResoniteTexturePayload(
145145
raw.Width,
146146
raw.Height,
147-
raw.ColorProfile,
147+
raw.Source.ColorProfile,
148148
raw.BinaryPayload.AsSpan().ToArray(),
149-
raw.Identity),
149+
raw.Source.Identity),
150150
EncodedImageTexturePayload encoded => new EncodedImageResoniteTexturePayload(
151151
encoded.Width,
152152
encoded.Height,
153-
encoded.ColorProfile,
154-
encoded.Source,
155-
encoded.Identity),
153+
encoded.Source),
156154
_ => throw new ArgumentOutOfRangeException(nameof(payload), payload.GetType(), "Unsupported texture payload type."),
157155
};
158156
}

tests/PlateauResoniteLink.Tests/Application/TexturePayloadTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
using PlateauResoniteLink.Application.Importing;
24

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

1517
Assert.Equal<byte>([1, 2, 3, 4], payload.BinaryPayload);
1618
}
19+
20+
[Fact]
21+
public void ConstructorCarriesIdentityAndColorProfileOnSourceOnly()
22+
{
23+
RawRgba32TexturePayload payload = new(1, 1, "sRGB", [1, 2, 3, 4], "dataset:texture");
24+
25+
Assert.Equal("dataset:texture", payload.Source.Identity);
26+
Assert.Equal("sRGB", payload.Source.ColorProfile);
27+
}
28+
29+
[Fact]
30+
public void ConstructorRejectsTextureSourceWithoutIdentity()
31+
{
32+
Assert.Throws<ArgumentException>(
33+
() => new EncodedImageTexturePayload(null, null, new BlankIdentityTextureImportSource()));
34+
}
35+
36+
private sealed class BlankIdentityTextureImportSource : ITextureImportSource
37+
{
38+
public string Identity => " ";
39+
40+
public string Description => "blank";
41+
42+
public string? ColorProfile => null;
43+
44+
public long? EstimatedByteLength => null;
45+
}
1746
}

tests/PlateauResoniteLink.Tests/Profiles/LocalCityGmlObjectProjectionTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,10 +2073,10 @@ public void ProjectCityObjectCullsBottomBandBuildingSurfacesBySemanticOrDownward
20732073
materialResolver: new DefaultMaterialResolver(CommonMaterialCatalog.Create()));
20742074

20752075
Assert.Equal(3, projected.Materials.Count);
2076-
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Identity == "ground");
2077-
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Identity == "ground-reversed");
2078-
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Identity == "outer-floor");
2079-
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Identity == "high-outer-floor");
2076+
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Source.Identity == "ground");
2077+
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Source.Identity == "ground-reversed");
2078+
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Source.Identity == "outer-floor");
2079+
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Source.Identity == "high-outer-floor");
20802080
}
20812081

20822082
[Fact]
@@ -2113,7 +2113,7 @@ public void ProjectCityObjectKeepsNonBuildingDownwardHorizontalGroundSurface()
21132113
materialResolver: new DefaultMaterialResolver(CommonMaterialCatalog.Create()));
21142114

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

@@ -2171,10 +2171,10 @@ public void ProjectCityObjectCullsBuildingLod1UnknownBottomBandSurfaces()
21712171
materialResolver: new DefaultMaterialResolver(CommonMaterialCatalog.Create()));
21722172

21732173
Assert.Equal(2, projected.Materials.Count);
2174-
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Identity == "lod1-bottom");
2175-
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Identity == "lod1-bottom-reversed");
2176-
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Identity == "lod1-roof");
2177-
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Identity == "lod1-wall");
2174+
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Source.Identity == "lod1-bottom");
2175+
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Source.Identity == "lod1-bottom-reversed");
2176+
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Source.Identity == "lod1-roof");
2177+
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Source.Identity == "lod1-wall");
21782178
}
21792179

21802180
[Fact]
@@ -2246,7 +2246,7 @@ public void ProjectCityObjectKeepsSingleDownwardHorizontalBuildingSurfaceWhenNoH
22462246
materialResolver: new DefaultMaterialResolver(CommonMaterialCatalog.Create()));
22472247

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

22522252
[Fact]
@@ -2381,7 +2381,7 @@ await service.ExecuteAsync(
23812381
Assert.NotNull(explicitMaterial.TexturePayload);
23822382
Assert.Contains(
23832383
"udx/dem/53394525/appearance/mixed_surface.png",
2384-
explicitMaterial.TexturePayload!.Identity,
2384+
explicitMaterial.TexturePayload!.Source.Identity,
23852385
StringComparison.Ordinal);
23862386
}
23872387

0 commit comments

Comments
 (0)