Skip to content

Commit a224527

Browse files
authored
Merge pull request #44 from DomCR/fbx-writer
Fbx writer
2 parents 4ffea41 + 4a49ae8 commit a224527

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+797
-595
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ MeshIO allows to read or create 3D files using .Net and also extract or modify e
1616

1717
| | Read-ASCII | Read-Binary | Write-ASCII | Write-Binary |
1818
------ | :-------: | :-------: | :-------: | :-------: |
19-
FBX6000 | :heavy_check_mark: | :heavy_check_mark: | :construction: | :construction: |
19+
FBX6000 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
2020
FBX7000 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
21-
STL | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
22-
GLB | | :heavy_check_mark: | | :construction: |
23-
GLTF | :construction: | | :construction: | |
24-
OBJ | :construction: | | :x: | |
21+
STL | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
22+
GLB | | :heavy_check_mark: | | :construction: |
23+
GLTF | :construction: | | :construction: | |
24+
OBJ | :construction: | | :x: | |
2525

2626
The goal of this project is to give full support for all the formats in the table.
2727

src/MeshIO.Tests/Common/IOTestsBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using MeshIO.Tests.TestModels;
1+
using MeshIO.Formats;
2+
using MeshIO.Tests.TestModels;
23
using System.IO;
34
using Xunit;
45
using Xunit.Abstractions;
Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using MeshIO.Entities.Geometries;
22
using MeshIO.Entities.Primitives;
3+
using MeshIO.Formats;
34
using MeshIO.Formats.Fbx;
45
using MeshIO.Tests.Common;
6+
using MeshIO.Tests.TestModels;
7+
using System;
58
using System.IO;
69
using Xunit;
710
using Xunit.Abstractions;
@@ -10,76 +13,37 @@ namespace MeshIO.Tests.Formats.Fbx;
1013

1114
public class FbxWriterTests : IOTestsBase
1215
{
13-
public static readonly TheoryData<FbxVersion> Versions = FbxTestCasesData.Versions;
14-
15-
public FbxWriterTests(ITestOutputHelper output) : base(output) { }
16-
17-
[Theory]
18-
[MemberData(nameof(Versions))]
19-
public void WriteEmptyAsciiStream(FbxVersion version)
20-
{
21-
FbxWriterOptions options = new FbxWriterOptions
22-
{
23-
IsBinaryFormat = false,
24-
Version = version,
25-
};
16+
public static TheoryData<FbxFileModel> TestCases { get; } = new();
2617

27-
using (FbxWriter writer = new FbxWriter(new MemoryStream(), new Scene(), options))
28-
{
29-
writer.OnNotification += this.onNotification;
30-
writer.Write(new FbxWriterOptions() { IsBinaryFormat = false });
31-
}
32-
}
18+
public static readonly TheoryData<FbxVersion> Versions = FbxTestCasesData.Versions;
3319

34-
[Theory]
35-
[MemberData(nameof(Versions))]
36-
public void WriteAsciiFbxWithMesh(FbxVersion version)
20+
static FbxWriterTests()
3721
{
38-
FbxWriterOptions options = new FbxWriterOptions
39-
{
40-
IsBinaryFormat = false,
41-
Version = version,
42-
};
43-
44-
string path = Path.Combine(FolderPath.OutFilesFbx, $"box_{version}_ascii.fbx");
45-
46-
Scene scene = this.createScene();
22+
string folder = Path.Combine(TestVariables.OutputSamplesFolder, "fbx");
23+
Directory.CreateDirectory(folder);
4724

48-
this.writeFile(path, scene, options);
25+
TestCases.Add(new FbxFileModel(folder, FbxVersion.v6100, ContentType.ASCII));
26+
TestCases.Add(new FbxFileModel(folder, FbxVersion.v6100, ContentType.Binary));
27+
TestCases.Add(new FbxFileModel(folder, FbxVersion.v7700, ContentType.ASCII));
28+
TestCases.Add(new FbxFileModel(folder, FbxVersion.v7700, ContentType.Binary));
4929
}
5030

51-
[Theory]
52-
[MemberData(nameof(Versions))]
53-
public void WriteEmptyBinaryStream(FbxVersion version)
31+
public FbxWriterTests(ITestOutputHelper output) : base(output)
5432
{
55-
FbxWriterOptions options = new FbxWriterOptions
56-
{
57-
IsBinaryFormat = true,
58-
Version = version,
59-
};
60-
61-
using (FbxWriter writer = new FbxWriter(new MemoryStream(), new Scene()))
62-
{
63-
writer.OnNotification += this.onNotification;
64-
writer.Write(new FbxWriterOptions() { IsBinaryFormat = true });
65-
}
6633
}
6734

6835
[Theory]
69-
[MemberData(nameof(Versions))]
70-
public void WriteBinaryFbxWithMesh(FbxVersion version)
36+
[MemberData(nameof(TestCases))]
37+
public void WriteTest(FbxFileModel test)
7138
{
7239
FbxWriterOptions options = new FbxWriterOptions
7340
{
74-
IsBinaryFormat = true,
75-
Version = version,
41+
ContentType = test.Content,
42+
Version = test.Version,
7643
};
7744

78-
string path = Path.Combine(FolderPath.OutFilesFbx, $"box_{version}_binary.fbx");
79-
8045
Scene scene = this.createScene();
81-
82-
this.writeFile(path, scene, options);
46+
this.writeFile(test.Path, scene, options);
8347
}
8448

8549
private Scene createScene()
@@ -100,7 +64,7 @@ private void writeFile(string path, Scene scene, FbxWriterOptions options)
10064
using (FbxWriter writer = new FbxWriter(path, scene, options))
10165
{
10266
writer.OnNotification += this.onNotification;
103-
writer.Write(options);
67+
writer.Write();
10468
}
10569
}
106-
}
70+
}

src/MeshIO.Tests/Formats/SceneWriterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private Scene createScene()
4545
return scene;
4646
}
4747

48-
private void onNotification(object sender, MeshIO.NotificationEventArgs e)
48+
private void onNotification(object sender, MeshIO.Formats.NotificationEventArgs e)
4949
{
5050
this._output.WriteLine(e.Message);
5151
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using MeshIO.Formats;
2+
using MeshIO.Formats.Fbx;
3+
using Xunit.Abstractions;
4+
5+
namespace MeshIO.Tests.TestModels;
6+
7+
public class FbxFileModel : FileModel
8+
{
9+
public ContentType Content { get; private set; }
10+
11+
public FbxVersion Version { get; private set; }
12+
13+
public FbxFileModel()
14+
: base()
15+
{
16+
}
17+
18+
public FbxFileModel(string path)
19+
: base(path)
20+
{
21+
}
22+
23+
public FbxFileModel(string folder, FbxVersion version, ContentType content)
24+
: this(System.IO.Path.Combine(folder, $"{version}_{content}.fbx"))
25+
{
26+
this.Version = version;
27+
this.Content = content;
28+
}
29+
30+
public override void Deserialize(IXunitSerializationInfo info)
31+
{
32+
base.Deserialize(info);
33+
34+
this.Content = info.GetValue<ContentType>(nameof(this.Content));
35+
this.Version = info.GetValue<FbxVersion>(nameof(this.Version));
36+
}
37+
38+
public override void Serialize(IXunitSerializationInfo info)
39+
{
40+
base.Serialize(info);
41+
42+
info.AddValue(nameof(this.Version), this.Version);
43+
info.AddValue(nameof(this.Content), this.Content);
44+
}
45+
}

src/MeshIO.Tests/TestModels/FileModel.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ public class FileModel : IXunitSerializable
88

99
public string FileName { get; private set; }
1010

11+
public string Folder { get { return System.IO.Path.GetDirectoryName(this.Path); } }
12+
1113
public string NoExtensionName { get { return System.IO.Path.GetFileNameWithoutExtension(this.Path); } }
1214

1315
public string Path { get; private set; }
1416

15-
public string Folder { get { return System.IO.Path.GetDirectoryName(this.Path); } }
16-
17-
public bool IsDxf { get { return System.IO.Path.GetExtension(this.Path) == ".dxf"; } }
18-
1917
public FileModel()
2018
{
2119
this.FileName = string.Empty;
@@ -27,13 +25,13 @@ public FileModel(string path)
2725
this.FileName = System.IO.Path.GetFileName(this.Path);
2826
}
2927

30-
public void Deserialize(IXunitSerializationInfo info)
28+
public virtual void Deserialize(IXunitSerializationInfo info)
3129
{
3230
this.Path = info.GetValue<string>(nameof(this.Path));
3331
this.FileName = info.GetValue<string>(nameof(this.FileName));
3432
}
3533

36-
public void Serialize(IXunitSerializationInfo info)
34+
public virtual void Serialize(IXunitSerializationInfo info)
3735
{
3836
info.AddValue(nameof(this.Path), this.Path);
3937
info.AddValue(nameof(this.FileName), this.FileName);
@@ -43,4 +41,4 @@ public override string ToString()
4341
{
4442
return this.FileName;
4543
}
46-
}
44+
}

src/MeshIO.sln

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "CSMath", "CSUtilities\CSMat
1111
EndProject
1212
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "CSUtilities", "CSUtilities\CSUtilities\CSUtilities.shproj", "{AD858F2B-04A1-41DD-BB3B-DDE4804CD2E6}"
1313
EndProject
14-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "repo", "repo", "{F37B65A4-9A24-41EA-9A72-D3439074C3D2}"
15-
ProjectSection(SolutionItems) = preProject
16-
..\.editorconfig = ..\.editorconfig
17-
..\.gitignore = ..\.gitignore
18-
..\.gitmodules = ..\.gitmodules
19-
Directory.Build.props = Directory.Build.props
20-
..\README.md = ..\README.md
21-
EndProjectSection
22-
EndProject
2314
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MeshIO.Tests", "MeshIO.Tests\MeshIO.Tests.csproj", "{94C45D19-8231-437F-AB4D-02FA072A923C}"
2415
EndProject
2516
Global

src/MeshIO/Formats/Fbx/Builders/FbxBuilderFactory.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/MeshIO/Formats/Fbx/Builders/FbxGeometryBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public override void Build(FbxFileBuilderBase builder)
2929
readLayers(builder.Version);
3030
}
3131

32-
protected override void processProperties(Dictionary<string, FbxProperty> properties)
32+
protected override void buildProperties(Dictionary<string, FbxProperty> properties)
3333
{
3434
if (properties.Remove("Primary Visibility", out FbxProperty isVisible))
3535
{
@@ -46,7 +46,7 @@ protected override void processProperties(Dictionary<string, FbxProperty> proper
4646
_element.ReceiveShadows = (bool)receiveShadows.ToProperty().Value;
4747
}
4848

49-
base.processProperties(properties);
49+
base.buildProperties(properties);
5050
}
5151

5252
protected void readLayers(FbxVersion version)

0 commit comments

Comments
 (0)