Skip to content

Commit a08783d

Browse files
authored
Merge pull request vpenades#279 from bertt/accessor-bufferview-missing-test
Add failing test loading model with bufferView defined in Extension not in Accessor
2 parents c1b03f4 + 23d4ed1 commit a08783d

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using NUnit.Framework;
2+
using SharpGLTF.Schema2;
3+
4+
namespace SharpGLTF.ThirdParty
5+
{
6+
public class AccessorBufferViewMissing
7+
{
8+
[Test]
9+
public void ModelLoadFailsWhenAccessorBufferViewMissing()
10+
{
11+
ExtensionsFactory.RegisterExtension<MeshPrimitive, SpzGaussianSplatsCompression>("KHR_spz_gaussian_splats_compression", p => new SpzGaussianSplatsCompression(p));
12+
13+
// Currently, the model loading fails with SharpGLTF.Validation.SchemaException: 'Accessor[0] _bufferView: must be defined.Model'
14+
// This is because the accessor does not have a bufferView defined,
15+
// the bufferView is defined in the Splat extension.
16+
var modelRoot = ModelRoot.Load("./TestFixtures/tower.glb");
17+
}
18+
19+
}
20+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
using JSONREADER = System.Text.Json.Utf8JsonReader;
5+
using JSONWRITER = System.Text.Json.Utf8JsonWriter;
6+
using FIELDINFO = SharpGLTF.Reflection.FieldInfo;
7+
using SharpGLTF.Schema2;
8+
9+
namespace SharpGLTF.ThirdParty
10+
{
11+
partial class SpzGaussianSplatsCompression
12+
{
13+
private MeshPrimitive meshPrimitive;
14+
15+
internal SpzGaussianSplatsCompression(MeshPrimitive meshPrimitive)
16+
{
17+
this.meshPrimitive = meshPrimitive;
18+
}
19+
20+
public int BufferViewIndex
21+
{
22+
get => _bufferView;
23+
set
24+
{
25+
_bufferView = value;
26+
}
27+
}
28+
}
29+
30+
31+
32+
33+
/// <summary>
34+
/// Compressed data for SPZ primitive.
35+
/// </summary>
36+
#if NET6_0_OR_GREATER
37+
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]
38+
#endif
39+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")]
40+
partial class SpzGaussianSplatsCompression : ExtraProperties
41+
{
42+
43+
#region reflection
44+
45+
public new const string SCHEMANAME = "KHR_spz_gaussian_splats_compression";
46+
protected override string GetSchemaName() => SCHEMANAME;
47+
48+
protected override IEnumerable<string> ReflectFieldsNames()
49+
{
50+
yield return "bufferView";
51+
foreach (var f in base.ReflectFieldsNames()) yield return f;
52+
}
53+
protected override bool TryReflectField(string name, out FIELDINFO value)
54+
{
55+
switch (name)
56+
{
57+
case "bufferView": value = FIELDINFO.From("bufferView", this, instance => instance._bufferView); return true;
58+
default: return base.TryReflectField(name, out value);
59+
}
60+
}
61+
62+
#endregion
63+
64+
#region data
65+
66+
private Int32 _bufferView;
67+
68+
#endregion
69+
70+
#region serialization
71+
72+
protected override void SerializeProperties(JSONWRITER writer)
73+
{
74+
base.SerializeProperties(writer);
75+
SerializeProperty(writer, "bufferView", _bufferView);
76+
}
77+
78+
protected override void DeserializeProperty(string jsonPropertyName, ref JSONREADER reader)
79+
{
80+
switch (jsonPropertyName)
81+
{
82+
case "bufferView": DeserializePropertyValue<SpzGaussianSplatsCompression, Int32>(ref reader, this, out _bufferView); break;
83+
default: base.DeserializeProperty(jsonPropertyName, ref reader); break;
84+
}
85+
}
86+
87+
#endregion
88+
89+
}
90+
}

tests/SharpGLTF.ThirdParty.Tests/SharpGLTF.ThirdParty.Tests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,10 @@
2929
<ProjectReference Include="..\SharpGLTF.NUnit\SharpGLTF.NUnit.csproj" />
3030
</ItemGroup>
3131

32+
<ItemGroup>
33+
<None Update="TestFixtures\tower.glb">
34+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
35+
</None>
36+
</ItemGroup>
37+
3238
</Project>
1.44 MB
Binary file not shown.

0 commit comments

Comments
 (0)