Compare commits

..
7 Commits
14 changed files with 306 additions and 10 deletions

No files matched your search

+1
View File
@@ -12,3 +12,4 @@
doc/html/**
doc/latex/**
**.sln.DotSettings.user
+4
View File
@@ -0,0 +1,4 @@
[submodule "tests/ReFuel.Gltf.Tests/assets/gltf-research-scenes"]
path = tests/ReFuel.Gltf.Tests/assets/gltf-research-scenes
url = https://github.com/ErfanMo77/gltf-research-scenes.git
branch = main
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 Halit Utku Maden, et al.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+34 -3
View File
@@ -5,18 +5,49 @@ VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReFuel.Gltf", "ReFuel.Gltf\ReFuel.Gltf.csproj", "{7DDA6046-BC8D-4969-BF6F-8450D515E8AE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0AB3BF05-4346-4AA6-1389-037BE0695223}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReFuel.Gltf.Tests", "tests\ReFuel.Gltf.Tests\ReFuel.Gltf.Tests.csproj", "{5170E91E-B9F9-48B9-AEDB-A426AAB939B2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7DDA6046-BC8D-4969-BF6F-8450D515E8AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7DDA6046-BC8D-4969-BF6F-8450D515E8AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7DDA6046-BC8D-4969-BF6F-8450D515E8AE}.Debug|x64.ActiveCfg = Debug|Any CPU
{7DDA6046-BC8D-4969-BF6F-8450D515E8AE}.Debug|x64.Build.0 = Debug|Any CPU
{7DDA6046-BC8D-4969-BF6F-8450D515E8AE}.Debug|x86.ActiveCfg = Debug|Any CPU
{7DDA6046-BC8D-4969-BF6F-8450D515E8AE}.Debug|x86.Build.0 = Debug|Any CPU
{7DDA6046-BC8D-4969-BF6F-8450D515E8AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7DDA6046-BC8D-4969-BF6F-8450D515E8AE}.Release|Any CPU.Build.0 = Release|Any CPU
{7DDA6046-BC8D-4969-BF6F-8450D515E8AE}.Release|x64.ActiveCfg = Release|Any CPU
{7DDA6046-BC8D-4969-BF6F-8450D515E8AE}.Release|x64.Build.0 = Release|Any CPU
{7DDA6046-BC8D-4969-BF6F-8450D515E8AE}.Release|x86.ActiveCfg = Release|Any CPU
{7DDA6046-BC8D-4969-BF6F-8450D515E8AE}.Release|x86.Build.0 = Release|Any CPU
{5170E91E-B9F9-48B9-AEDB-A426AAB939B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5170E91E-B9F9-48B9-AEDB-A426AAB939B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5170E91E-B9F9-48B9-AEDB-A426AAB939B2}.Debug|x64.ActiveCfg = Debug|Any CPU
{5170E91E-B9F9-48B9-AEDB-A426AAB939B2}.Debug|x64.Build.0 = Debug|Any CPU
{5170E91E-B9F9-48B9-AEDB-A426AAB939B2}.Debug|x86.ActiveCfg = Debug|Any CPU
{5170E91E-B9F9-48B9-AEDB-A426AAB939B2}.Debug|x86.Build.0 = Debug|Any CPU
{5170E91E-B9F9-48B9-AEDB-A426AAB939B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5170E91E-B9F9-48B9-AEDB-A426AAB939B2}.Release|Any CPU.Build.0 = Release|Any CPU
{5170E91E-B9F9-48B9-AEDB-A426AAB939B2}.Release|x64.ActiveCfg = Release|Any CPU
{5170E91E-B9F9-48B9-AEDB-A426AAB939B2}.Release|x64.Build.0 = Release|Any CPU
{5170E91E-B9F9-48B9-AEDB-A426AAB939B2}.Release|x86.ActiveCfg = Release|Any CPU
{5170E91E-B9F9-48B9-AEDB-A426AAB939B2}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5170E91E-B9F9-48B9-AEDB-A426AAB939B2} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
EndGlobalSection
EndGlobal
+1 -1
View File
@@ -189,7 +189,7 @@ namespace ReFuel.Gltf
}
else
{
str.Seek(0, SeekOrigin.Begin);
wrapper.Seek(0, SeekOrigin.Begin);
return OpenJson(wrapper);
}
}
+2 -2
View File
@@ -12,7 +12,7 @@ namespace ReFuel.Gltf
Other
}
public class GltfMaterialTextureInfo : GtlfMiscObject
public class GltfMaterialTextureInfo : GltfMiscObject
{
private GltfSmartId<GltfTexture> _texture;
@@ -65,7 +65,7 @@ namespace ReFuel.Gltf
}
}
public class GltfMetallicRoughness : GtlfMiscObject
public class GltfMetallicRoughness : GltfMiscObject
{
public Vector4 BaseColorFactor { get; set; } = new Vector4(1,1,1,1);
public GltfMaterialTextureInfo? BaseColorTexture { get; set; } = null;
+3 -3
View File
@@ -1,11 +1,11 @@
namespace ReFuel.Gltf
{
public abstract class GtlfMiscObject : GltfObject
public abstract class GltfMiscObject : GltfObject
{
public override GltfObjectKind Kind => GltfObjectKind.Misc;
protected GtlfMiscObject(GltfDocument document) : base(document)
protected GltfMiscObject(GltfDocument document) : base(document)
{
}
}
}
}
+13 -1
View File
@@ -1,10 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net10.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.0.1</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<!--
This section allows the target frameworks to be specified at build time using the environment variable
REFUEL_TARGET_FRAMEWORKS, which is defined by the NUGET compiling docker image.
-->
<PropertyGroup Condition="$(REFUEL_TARGET_FRAMEWORKS) == ''">
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="$(REFUEL_TARGET_FRAMEWORKS) != ''">
<TargetFrameworks>$(REFUEL_GLTF_TARGET_FRAMEWORKS)</TargetFrameworks>
</PropertyGroup>
</Project>
@@ -0,0 +1,85 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using YamlDotNet.Core;
using YamlDotNet.RepresentationModel;
using YamlDotNet.Serialization;
namespace ReFuel.Gltf.Tests;
[DebuggerDisplay("{Kind,nq} path={DocumentUnderTestPath}")]
public class GltfTestDocument(FileInfo documentUnderTestPath) : IDisposable
{
public FileInfo DocumentUnderTestPath { get; } = documentUnderTestPath;
public FileInfo? SummaryDocumentFile { get; init; } = FindSummary(documentUnderTestPath);
public DirectoryInfo WorkingDirectory { get; init; } = documentUnderTestPath.Directory ?? new DirectoryInfo(Environment.CurrentDirectory);
public GltfDocumentKind Kind { get; init; } = documentUnderTestPath.Extension.ToLowerInvariant() switch
{
".gltf" => GltfDocumentKind.Json,
".glb" => GltfDocumentKind.Binary,
_ => GltfDocumentKind.Any,
};
public FileStream? Stream { get; private set; }
public GltfDocument? DocumentUnderTest { get; private set; }
public YamlDocument? SummaryDocument { get; private set; }
public ValidationDocument? ValidationDocument { get; private set; }
public bool HasValidation => SummaryDocumentFile != null;
public GltfDocument Parse()
{
Stream = DocumentUnderTestPath.OpenRead();
return DocumentUnderTest = GltfDocument.Open(Stream);
}
[MemberNotNullWhen(true, nameof(ValidationDocument))]
public bool LoadValidationDocument()
{
if (SummaryDocumentFile == null)
return false;
using StreamReader reader = new StreamReader(SummaryDocumentFile.OpenRead());
ValidationDocument = Deserializer.Deserialize<ValidationDocument>(reader.ReadToEnd());
return true;
}
public void Dispose()
{
DocumentUnderTest?.Dispose();
DocumentUnderTest = null;
Stream?.Dispose();
Stream = null;
}
private static FileInfo? FindSummary(FileInfo documentUnderTest)
{
return
documentUnderTest.Directory?
.EnumerateFiles()
.FirstOrDefault(x => string.Equals(x.Name, "conversion.yaml", StringComparison.InvariantCultureIgnoreCase));
}
public override string ToString()
{
string kind = Kind switch
{
GltfDocumentKind.Json => "Gltf JSON",
GltfDocumentKind.Binary => "Gltf Binary",
_ => "Unknown Gltf",
};
return $"{kind} \"{DocumentUnderTestPath.Name}\" HasValidation={(HasValidation ? "Yes" : "No")}";
}
private static IDeserializer Deserializer { get; }
static GltfTestDocument()
{
Deserializer = new DeserializerBuilder()
.IgnoreUnmatchedProperties()
.Build();
}
}
@@ -0,0 +1 @@
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
@@ -0,0 +1,75 @@
using System.Diagnostics;
using Microsoft.Extensions.FileSystemGlobbing;
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
namespace ReFuel.Gltf.Tests;
[TestClass]
public sealed class ParseCompliantDocuments
{
public static string DocumentsDirectory { get; } = "../../../assets/gltf-research-scenes/scenes";
public static string CoreDocumentGlob { get; } = "**/gltf/*_core.gltf";
public static string ExtendedDocumentGlob { get; } = "**/gltf/*_extended.gltf";
public static IEnumerable<GltfTestDocument> FetchTestDocuments(string glob)
{
Matcher matcher = new Matcher();
matcher.AddInclude(glob);
PatternMatchingResult result = matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(DocumentsDirectory)));
return result.Files.Select(x => new GltfTestDocument(new FileInfo(Path.Combine(DocumentsDirectory, x.Path))));
}
public static IEnumerable<GltfTestDocument> Documents => FetchTestDocuments(ExtendedDocumentGlob);
// [TestMethod]
// [TestCategory("Core")]
// [DynamicData(nameof(CoreDocuments))]
// public void ParseCoreDocuments(GltfTestDocument doc)
// {
// doc.Parse().Dispose();
// }
[TestMethod]
[DynamicData(nameof(Documents))]
public void ParseDocuments(GltfTestDocument doc)
{
doc.Parse().Dispose();
}
[TestMethod]
[DynamicData(nameof(Documents))]
public void AssertExtensionCount(GltfTestDocument doc)
{
GltfDocument gltf = doc.Parse();
if (!doc.LoadValidationDocument())
Assert.Inconclusive();
Assert.HasCount(doc.ValidationDocument.Outputs.ExtendedExtensions.Count, gltf.Extensions);
}
[TestMethod]
[DynamicData(nameof(Documents))]
public void AssertMaterialCount(GltfTestDocument doc)
{
GltfDocument gltf = doc.Parse();
if (!doc.LoadValidationDocument())
Assert.Inconclusive();
Assert.HasCount(doc.ValidationDocument.Summary.Materials, gltf.Materials);
}
[TestMethod]
[DynamicData(nameof(Documents))]
public void AssertTexturesCount(GltfTestDocument doc)
{
GltfDocument gltf = doc.Parse();
if (!doc.LoadValidationDocument())
Assert.Inconclusive();
Assert.HasCount(doc.ValidationDocument.Summary.Textures, gltf.Images);
}
}
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="10.0.13" />
<PackageReference Include="MSTest" Version="4.0.1" />
<PackageReference Include="YamlDotNet" Version="18.1.0" />
</ItemGroup>
<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\ReFuel.Gltf\ReFuel.Gltf.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,41 @@
using YamlDotNet.Serialization;
namespace ReFuel.Gltf.Tests
{
[YamlSerializable]
public class ValidationDocument
{
[YamlMember(Alias = "summary")] public ValidationSummary Summary { get; set; } = new ValidationSummary();
[YamlMember(Alias = "outputs")] public ValidationOutputs Outputs { get; set; } = new ValidationOutputs();
[YamlSerializable]
public class ValidationSummary
{
[YamlMember(Alias = "meshes")]
public int Meshes { get; set; }
[YamlMember(Alias = "triangles")]
public int Triangles { get; set; }
[YamlMember(Alias = "materials")]
public int Materials { get; set; }
[YamlMember(Alias = "textures")]
public int Textures { get; set; }
[YamlMember(Alias = "lights")]
public int Lights { get; set; }
}
[YamlSerializable]
public class ValidationOutputs
{
[YamlMember(Alias = "core")]
public string Core { get; set; } = "";
[YamlMember(Alias = "extended")]
public string Extended { get; set; } = "";
[YamlMember(Alias = "extended_extensions")]
public List<string> ExtendedExtensions { get; set; } = new List<string>();
}
}
}