forked from donkeyProgramming/TheAssetEditor
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request donkeyProgramming#205 from mr-phazer/Unit-Tests-Fo…
…r-Import Unit testing for gltf importing
- Loading branch information
Showing
19 changed files
with
2,374 additions
and
36 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+540 KB
..._Blender/karl_franz_imported_and_saved_to_blendfile_and_exported_to_gltf_from_blender.bin
Binary file not shown.
2,093 changes: 2,093 additions & 0 deletions
2,093
...Blender/karl_franz_imported_and_saved_to_blendfile_and_exported_to_gltf_from_blender.gltf
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...rtExportEditor/Editors.ImportExport/Importing/Importers/GltfToRmv/GltfImporterSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Shared.Core.PackFiles.Models; | ||
using Shared.GameFormats.RigidModel; | ||
using SharpGLTF.Schema2; | ||
using Editors.ImportExport.Importing.Importers.GltfToRmv.Helper; | ||
using System.IO; | ||
using Shared.Core.PackFiles; | ||
using Shared.Ui.BaseDialogs.PackFileBrowser; | ||
using static Shared.Core.PackFiles.IPackFileService; | ||
using Shared.Core.ErrorHandling.Exceptions; | ||
using Shared.Core.Services; | ||
|
||
namespace Editors.ImportExport.Importing.Importers.GltfToRmv | ||
{ | ||
public record GltfImporterSettings | ||
( | ||
string InputGltfFile, | ||
string DestinationPackPath, | ||
PackFileContainer DestinationPackFileContainer, | ||
bool ConvertNormalTextureToOrangeType, | ||
bool ImportAnimations, | ||
bool MirrorMesh | ||
); | ||
} |
45 changes: 45 additions & 0 deletions
45
...ExportEditor/Editors.ImportExport/Importing/Importers/GltfToRmv/Helper/GltfSceneLoader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Shared.Core.ErrorHandling.Exceptions; | ||
using SharpGLTF.Schema2; | ||
using System.Windows; | ||
using Shared.Core.Services; | ||
|
||
namespace Editors.ImportExport.Importing.Importers.GltfToRmv.Helper | ||
{ | ||
public interface IGltfSceneLoader | ||
{ | ||
public ModelRoot? Load(GltfImporterSettings settings); | ||
} | ||
|
||
public class GltfSceneLoader : IGltfSceneLoader | ||
{ | ||
private readonly IStandardDialogs _exceptionService; | ||
|
||
public GltfSceneLoader(IStandardDialogs exceptionService) | ||
{ | ||
_exceptionService = exceptionService; | ||
} | ||
|
||
public ModelRoot? Load(GltfImporterSettings settings) | ||
{ | ||
ModelRoot? modelRoot = null; | ||
try | ||
{ | ||
modelRoot = ModelRoot.Load(settings.InputGltfFile); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_exceptionService.ShowExceptionWindow(ex); | ||
return null; | ||
} | ||
|
||
return modelRoot; | ||
|
||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
...Editor/Test.ImportExport/Importing/Importers/GltfToRmvImporter/GltfIToRmvImporterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Editors.ImportExport.Exporting.Exporters.DdsToMaterialPng; | ||
using Editors.ImportExport.Exporting.Exporters.DdsToNormalPng; | ||
using Editors.ImportExport.Exporting.Exporters.RmvToGltf.Helpers; | ||
using Editors.ImportExport.Importing.Importers.GltfToRmv; | ||
using Editors.ImportExport.Importing.Importers.GltfToRmv.Helper; | ||
using Editors.Shared.Core.Services; | ||
using Moq; | ||
using Shared.Core.Events; | ||
using Shared.Core.PackFiles; | ||
using Shared.Core.PackFiles.Models; | ||
using Shared.Core.Services; | ||
using Shared.GameFormats.RigidModel; | ||
using Shared.TestUtility; | ||
using Shared.Ui.BaseDialogs.StandardDialog; | ||
using SharpGLTF.Schema2; | ||
using Test.ImportExport.Exporting.Exporters.RmvToGlft; | ||
|
||
namespace Test.ImportExport.Importing.Importers.GltfImporterTest | ||
{ | ||
class TestData | ||
{ | ||
public static readonly string InputGtlfFile = PathHelper.GetDataFile(@"Karl_Gltf_Resaved_From_Blender\karl_franz_imported_and_saved_to_blendfile_and_exported_to_gltf_from_blender.gltf"); | ||
public static readonly string InputPack = PathHelper.GetDataFolder("Karl_and_celestialgeneral_Pack"); | ||
|
||
public static class GltfExpected | ||
{ | ||
public const int logicalMaterials = 4; | ||
public const int nodes = 78; | ||
public const int skinCount = 1; | ||
public const int textureCount = 12; | ||
public const int logicalMeshes = 4; | ||
public const int primtivesMesh0 = 1; | ||
public const int primtivesMesh0IndexCount = 25539; | ||
} | ||
|
||
public static class Rmv2Expected | ||
{ | ||
public const string skeletonName = "humanoid01"; | ||
public const int lodCount = 1; | ||
public const int lod0MeshCount = 4; | ||
public const int Lod0Mesh0IndexCount = 25539; | ||
public const int Lod0Mesh0VertexCount = 6397; | ||
} | ||
} | ||
|
||
// Tests Full Import (Importer.Import()) | ||
class GltfToRmv2ImporterTest | ||
{ | ||
[Test] | ||
public void Test() | ||
{ | ||
// Arrange | ||
var pfs = PackFileSerivceTestHelper.Create(TestData.InputPack); | ||
|
||
var meshBuilder = new GltfMeshBuilder(); | ||
var normalExporter = new Mock<IDdsToNormalPngExporter>(); | ||
var materialExporter = new Mock<IDdsToMaterialPngExporter>(); | ||
var eventHub = new Mock<IGlobalEventHub>(); | ||
var skeletontonLookupHelper = new SkeletonAnimationLookUpHelper(pfs, eventHub.Object); | ||
var skeletontonBuilder = new GltfSkeletonBuilder(pfs); | ||
var animationBuilder = new GltfAnimationBuilder(pfs); | ||
var textureHandler = new GltfTextureHandler(normalExporter.Object, materialExporter.Object); | ||
var sceneSaver = new TestGltfSceneSaver(); | ||
var standardDialog = new Mock<IStandardDialogs>(); | ||
var sceneLoader = new GltfSceneLoader(standardDialog.Object); | ||
var importer = new GltfImporter(pfs, standardDialog.Object, skeletontonLookupHelper); | ||
|
||
var packFileContainer = new PackFileContainer("new"); | ||
var settings = new GltfImporterSettings(TestData.InputGtlfFile, "skeletons", packFileContainer, true, true, true); | ||
|
||
// Act | ||
// Do full import | ||
importer.Import(settings); | ||
var rmv2FileName = @$"skeletons\{Path.GetFileNameWithoutExtension(TestData.InputGtlfFile)}.rigid_model_v2".ToLower(); | ||
var isPackFileAdded = packFileContainer.FileList.ContainsKey(rmv2FileName); | ||
|
||
// Assert | ||
// Last step of Importer, is adding the file to PackFileContainer, so we check wether this has happened | ||
Assert.That(isPackFileAdded, Is.EqualTo(true)); | ||
} | ||
} | ||
|
||
// Tests some Components of Importer pipeline | ||
class GltfToRmv2ImporterComponentTest | ||
{ | ||
|
||
[Test] | ||
public void Test() | ||
{ | ||
// Arrange | ||
var pfs = PackFileSerivceTestHelper.Create(TestData.InputPack); | ||
|
||
var meshBuilder = new GltfMeshBuilder(); | ||
var normalExporter = new Mock<IDdsToNormalPngExporter>(); | ||
var materialExporter = new Mock<IDdsToMaterialPngExporter>(); | ||
var eventHub = new Mock<IGlobalEventHub>(); | ||
var standardDialog = new Mock<IStandardDialogs>(); | ||
var skeletontonLookupHelper = new SkeletonAnimationLookUpHelper(pfs, eventHub.Object); | ||
var skeletontonBuilder = new GltfSkeletonBuilder(pfs); | ||
var animationBuilder = new GltfAnimationBuilder(pfs); | ||
var textureHandler = new GltfTextureHandler(normalExporter.Object, materialExporter.Object); | ||
var sceneLoader = new GltfSceneLoader(standardDialog.Object); | ||
var skeletonFile = skeletontonLookupHelper.GetSkeletonFileFromName(TestData.Rmv2Expected.skeletonName); | ||
var packFileContainer = new PackFileContainer("new"); | ||
var settings = new GltfImporterSettings(TestData.InputGtlfFile, "skeletons", packFileContainer, true, true, true); | ||
|
||
// Act.... | ||
var modelRoot = sceneLoader.Load(settings); | ||
|
||
// Assert | ||
// Assert API correct load | ||
Assert.That(modelRoot, Is.Not.Null); | ||
Assert.That(modelRoot.LogicalMaterials!.Count(), Is.EqualTo(TestData.GltfExpected.logicalMaterials)); | ||
Assert.That(modelRoot.LogicalNodes!.Count(), Is.EqualTo(TestData.GltfExpected.nodes)); | ||
Assert.That(modelRoot.LogicalSkins!.Count(), Is.EqualTo(TestData.GltfExpected.skinCount)); | ||
Assert.That(modelRoot.LogicalTextures!.Count(), Is.EqualTo(TestData.GltfExpected.textureCount)); | ||
Assert.That(modelRoot.LogicalMeshes!.Count(), Is.EqualTo(TestData.GltfExpected.logicalMeshes)); | ||
Assert.That(modelRoot.LogicalMeshes[0].Primitives!.Count(), Is.EqualTo(TestData.GltfExpected.primtivesMesh0)); | ||
Assert.That(modelRoot.LogicalMeshes[0].Primitives[0].GetIndices().Count(), Is.EqualTo(TestData.GltfExpected.primtivesMesh0IndexCount)); | ||
|
||
// Assert | ||
// Test Importer code, check if Rmv2 file is created correctly | ||
|
||
Assert.That(skeletonFile, Is.Not.Null); | ||
var rmv2Mesh = RmvMeshBuilder.Build(settings, modelRoot, skeletonFile, TestData.Rmv2Expected.skeletonName); | ||
Assert.That(rmv2Mesh, Is.Not.Null); | ||
Assert.That(rmv2Mesh.Header.SkeletonName, Is.EqualTo(TestData.Rmv2Expected.skeletonName)); | ||
Assert.That(rmv2Mesh.ModelList, Is.Not.Null); | ||
Assert.That(rmv2Mesh.ModelList.Length, Is.EqualTo(TestData.Rmv2Expected.lodCount)); | ||
Assert.That(rmv2Mesh.ModelList[0].Length, Is.EqualTo(TestData.Rmv2Expected.lod0MeshCount)); | ||
Assert.That(rmv2Mesh.ModelList[0][0].Mesh, Is.Not.Null); | ||
Assert.That(rmv2Mesh.ModelList[0][0].Material, Is.Not.Null); | ||
Assert.That(rmv2Mesh.ModelList[0][0].Material.MaterialId, Is.EqualTo(ModelMaterialEnum.weighted)); | ||
Assert.That(rmv2Mesh.ModelList[0][0].Material.BinaryVertexFormat, Is.EqualTo(VertexFormat.Cinematic)); | ||
Assert.That(rmv2Mesh.ModelList[0][0].Mesh.IndexList, Is.Not.Null); | ||
Assert.That(rmv2Mesh.ModelList[0][0].Mesh.IndexList.Length, Is.EqualTo(TestData.Rmv2Expected.Lod0Mesh0IndexCount)); | ||
Assert.That(rmv2Mesh.ModelList[0][0].Mesh.VertexList.Length, Is.EqualTo(TestData.Rmv2Expected.Lod0Mesh0VertexCount)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.