Skip to content

Commit fa17b9d

Browse files
authored
Merge pull request #47 from DomCR/obj-reader
Obj reader
2 parents a224527 + b1a0fa0 commit fa17b9d

File tree

13 files changed

+251
-82
lines changed

13 files changed

+251
-82
lines changed

.gitignore

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,17 +351,13 @@ MigrationBackup/
351351

352352
# Custom folders
353353
/.packages
354+
/local
354355
/samples/out
355-
/file_samples
356-
/Utils
357-
/samples/fbx/old
356+
/samples/in/fbx/old
358357

359358
# Exceptions
360359
!MeshIO.OBJ
361-
/local
362-
/src/Tests/outFiles
363-
!src/Tests/inFiles/obj/
364-
!src/Tests/inFiles/obj/*.obj
360+
!samples/in/obj/
361+
!samples/in/obj/*.obj
365362
!src/MeshIO/Formats/Obj
366363
!src/MeshIO.Tests/Formats/Obj
367-
/samples/in/fbx/old

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ FBX7000 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_
2121
STL | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
2222
GLB | | :heavy_check_mark: | | :construction: |
2323
GLTF | :construction: | | :construction: | |
24-
OBJ | :construction: | | :x: | |
24+
OBJ | :heavy_check_mark: | | :construction: | |
2525

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

samples/in/obj/model.obj

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# This is a title comment
2+
o Box
3+
v 0.5 0.5 0.5
4+
v 0.5 0.5 -0.5
5+
v 0.5 -0.5 0.5
6+
v 0.5 -0.5 -0.5
7+
v -0.5 0.5 -0.5
8+
v -0.5 0.5 0.5
9+
v -0.5 -0.5 -0.5
10+
v -0.5 -0.5 0.5
11+
v -0.5 0.5 -0.5
12+
v 0.5 0.5 -0.5
13+
v -0.5 0.5 0.5
14+
v 0.5 0.5 0.5
15+
v -0.5 -0.5 0.5
16+
v 0.5 -0.5 0.5
17+
v -0.5 -0.5 -0.5
18+
v 0.5 -0.5 -0.5
19+
v -0.5 0.5 0.5
20+
v 0.5 0.5 0.5
21+
v -0.5 -0.5 0.5
22+
v 0.5 -0.5 0.5
23+
v 0.5 0.5 -0.5
24+
v -0.5 0.5 -0.5
25+
v 0.5 -0.5 -0.5
26+
v -0.5 -0.5 -0.5
27+
vt 0 1
28+
vt 1 1
29+
vt 0 0
30+
vt 1 0
31+
vt 0 1
32+
vt 1 1
33+
vt 0 0
34+
vt 1 0
35+
vt 0 1
36+
vt 1 1
37+
vt 0 0
38+
vt 1 0
39+
vt 0 1
40+
vt 1 1
41+
vt 0 0
42+
vt 1 0
43+
vt 0 1
44+
vt 1 1
45+
vt 0 0
46+
vt 1 0
47+
vt 0 1
48+
vt 1 1
49+
vt 0 0
50+
vt 1 0
51+
vn 1 0 0
52+
vn 1 0 0
53+
vn 1 0 0
54+
vn 1 0 0
55+
vn -1 0 0
56+
vn -1 0 0
57+
vn -1 0 0
58+
vn -1 0 0
59+
vn 0 1 0
60+
vn 0 1 0
61+
vn 0 1 0
62+
vn 0 1 0
63+
vn 0 -1 0
64+
vn 0 -1 0
65+
vn 0 -1 0
66+
vn 0 -1 0
67+
vn 0 0 1
68+
vn 0 0 1
69+
vn 0 0 1
70+
vn 0 0 1
71+
vn 0 0 -1
72+
vn 0 0 -1
73+
vn 0 0 -1
74+
vn 0 0 -1
75+
f 1/1/1 3/3/3 2/2/2
76+
f 3/3/3 4/4/4 2/2/2
77+
f 5/5/5 7/7/7 6/6/6
78+
f 7/7/7 8/8/8 6/6/6
79+
f 9/9/9 11/11/11 10/10/10
80+
f 11/11/11 12/12/12 10/10/10
81+
f 13/13/13 15/15/15 14/14/14
82+
f 15/15/15 16/16/16 14/14/14
83+
f 17/17/17 19/19/19 18/18/18
84+
f 19/19/19 20/20/20 18/18/18
85+
f 21/21/21 23/23/23 22/22/22
86+
f 23/23/23 24/24/24 22/22/22
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 3ds Max Wavefront OBJ Exporter v0.99 - (c)2007 guruware
2+
# File Created: 04.04.2023 20:09:44
3+
4+
newmtl wire_008061138
5+
Ns 32
6+
d 1
7+
Tr 0
8+
Tf 1 1 1
9+
illum 2
10+
Ka 0.0314 0.2392 0.5412
11+
Kd 0.0314 0.2392 0.5412
12+
Ks 0.3500 0.3500 0.3500
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# 3ds Max Wavefront OBJ Exporter v0.99 - (c)2007 guruware
2+
# File Created: 04.04.2023 20:09:44
3+
4+
mtllib sample_basic_box.mtl
5+
6+
#
7+
# object Box001
8+
#
9+
10+
v -5.0000 0.0000 5.0000
11+
v -5.0000 0.0000 -5.0000
12+
v 5.0000 0.0000 -5.0000
13+
v 5.0000 0.0000 5.0000
14+
v -5.0000 10.0000 5.0000
15+
v 5.0000 10.0000 5.0000
16+
v 5.0000 10.0000 -5.0000
17+
v -5.0000 10.0000 -5.0000
18+
# 8 vertices
19+
20+
vn -0.5774 -0.5774 0.5774
21+
vn -0.5774 -0.5774 -0.5774
22+
vn 0.5774 -0.5774 -0.5774
23+
vn 0.5774 -0.5774 0.5774
24+
vn -0.5774 0.5774 0.5774
25+
vn 0.5774 0.5774 0.5774
26+
vn 0.5774 0.5774 -0.5774
27+
vn -0.5774 0.5774 -0.5774
28+
# 8 vertex normals
29+
30+
vt 1.0000 0.0000 0.0000
31+
vt 1.0000 1.0000 0.0000
32+
vt 0.0000 1.0000 0.0000
33+
vt 0.0000 0.0000 0.0000
34+
# 4 texture coords
35+
36+
o Box001
37+
g Box001
38+
usemtl wire_008061138
39+
s 2
40+
f 1/1/1 2/2/2 3/3/3 4/4/4
41+
s 4
42+
f 5/4/5 6/1/6 7/2/7 8/3/8
43+
s 8
44+
f 1/4/1 4/1/4 6/2/6 5/3/5
45+
s 16
46+
f 4/4/4 3/1/3 7/2/7 6/3/6
47+
s 32
48+
f 3/4/3 2/1/2 8/2/8 7/3/7
49+
s 64
50+
f 2/4/2 1/1/1 5/2/5 8/3/8
51+
# 6 polygons
52+

src/MeshIO.Tests/Formats/Obj/ObjReaderTest.cs renamed to src/MeshIO.Tests/Formats/Obj/ObjReaderTests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
using MeshIO.Formats.Obj;
22
using MeshIO.Tests.Common;
33
using MeshIO.Tests.TestModels;
4-
using System.IO;
54
using Xunit;
65
using Xunit.Abstractions;
76

8-
namespace MeshIO.OBJ.Tests;
7+
namespace MeshIO.Tests.Formats.Obj;
98

10-
public class ObjReaderTest : IOTestsBase
9+
public class ObjReaderTests : IOTestsBase
1110
{
1211
public static TheoryData<FileModel> ObjFiles { get; } = new();
1312

14-
static ObjReaderTest()
13+
static ObjReaderTests()
1514
{
1615
loadSamples("obj", "obj", ObjFiles);
1716
}
1817

19-
public ObjReaderTest(ITestOutputHelper output) : base(output) { }
18+
public ObjReaderTests(ITestOutputHelper output) : base(output) { }
2019

21-
[Theory(Skip = "not implemented")]
20+
[Theory]
2221
[MemberData(nameof(ObjFiles))]
2322
public void ReadTest(FileModel test)
2423
{

src/MeshIO.Tests/Formats/Stl/StlReaderTest.cs renamed to src/MeshIO.Tests/Formats/Stl/StlReaderTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88

99
namespace MeshIO.Tests.Formats.Stl;
1010

11-
public class StlReaderTest : IOTestsBase
11+
public class StlReaderTests : IOTestsBase
1212
{
1313
public static TheoryData<FileModel> StlAsciiFiles { get; } = new();
1414
public static TheoryData<FileModel> StlBinaryFiles { get; } = new();
1515

16-
static StlReaderTest()
16+
static StlReaderTests()
1717
{
1818
loadSamples("stl", "_ascii", "stl", StlAsciiFiles);
1919
loadSamples("stl", "_binary", "stl", StlBinaryFiles);
2020
}
2121

22-
public StlReaderTest(ITestOutputHelper output) : base(output)
22+
public StlReaderTests(ITestOutputHelper output) : base(output)
2323
{
2424
}
2525

src/MeshIO/Formats/Obj/ObjFileParser.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@ public static bool ParseToken(string text, out ObjFileToken token)
88

99
switch (text.ToLower())
1010
{
11+
case "g":
12+
token = ObjFileToken.Group;
13+
return true;
1114
case "o":
1215
token = ObjFileToken.Object;
1316
return true;
1417
case "v":
1518
token = ObjFileToken.Vertice;
1619
return true;
20+
case "s":
21+
token = ObjFileToken.SmoothShading;
22+
return true;
1723
case "f":
1824
token = ObjFileToken.Face;
1925
return true;

src/MeshIO/Formats/Obj/ObjFileToken.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ internal enum ObjFileToken
88
/// </summary>
99
Object,
1010
/// <summary>
11+
/// g
12+
/// </summary>
13+
Group,
14+
/// <summary>
1115
/// v
1216
/// </summary>
1317
Vertice,
@@ -24,6 +28,10 @@ internal enum ObjFileToken
2428
/// </summary>
2529
Face,
2630
/// <summary>
31+
/// s
32+
/// </summary>
33+
SmoothShading,
34+
/// <summary>
2735
/// #
2836
/// </summary>
2937
Comment

0 commit comments

Comments
 (0)