Skip to content

Commit 8102339

Browse files
authored
Merge pull request #106 from JuliaIO/ff/fix-save
Fix old function name
2 parents ef846a9 + a784939 commit 8102339

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

src/io/obj.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ end
199199
function save(f::Stream{format"OBJ"}, mesh::AbstractMesh)
200200
# TODO: allow saving with faceviews (i.e. build the / or // syntax)
201201
if any(v -> v isa FaceView, values(vertex_attributes(mesh)))
202-
mesh = GeometryBasics.clear_faceviews(mesh)
202+
mesh = GeometryBasics.expand_faceviews(Mesh(mesh))
203203
end
204204

205205
io = stream(f)

test/runtests.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,26 @@ end
146146
@test test_face_indices(msh)
147147

148148
msh = load(joinpath(tf, "cube.obj")) # quads
149+
@test msh isa MetaMesh
149150
@test length(faces(msh)) == 12
150151
@test length(coordinates(msh)) == 8
151152
@test test_face_indices(msh)
152153

154+
@testset "OBJ meta and mtl data" begin
155+
@test msh[:material_names] == ["Material"]
156+
@test msh[:shading] == BitVector([0])
157+
@test msh[:object] == ["Cube"]
158+
@test length(msh[:materials]) == 1
159+
@test length(msh[:materials]["Material"]) == 7
160+
@test msh[:materials]["Material"]["refractive index"] === 1f0
161+
@test msh[:materials]["Material"]["illumination model"] === 2
162+
@test msh[:materials]["Material"]["alpha"] === 1f0
163+
@test msh[:materials]["Material"]["diffuse"] === Vec3f(0.64, 0.64, 0.64)
164+
@test msh[:materials]["Material"]["specular"] === Vec3f(0.5, 0.5, 0.5)
165+
@test msh[:materials]["Material"]["shininess"] === 96.07843f0
166+
@test msh[:materials]["Material"]["ambient"] === Vec3f(0.0, 0.0, 0.0)
167+
end
168+
153169
msh = load(joinpath(tf, "cube_uv.obj"))
154170
@test typeof(msh.uv) == Vector{Vec{2,Float32}}
155171
@test length(msh.uv) == 8
@@ -166,7 +182,28 @@ end
166182
msh = load(joinpath(tf, "test_face_normal.obj"))
167183
@test length(faces(msh)) == 1
168184
@test length(coordinates(msh)) == 3
185+
@test length(normals(msh)) == 3
169186
@test test_face_indices(msh)
187+
@test normals(msh) isa FaceView
188+
189+
# test correctness of reordered vertices
190+
msh2 = expand_faceviews(Mesh(msh))
191+
@test !(normals(msh2) isa FaceView)
192+
@test length(faces(msh2)) == 1
193+
@test coordinates(coordinates(msh2)[faces(msh2)[1]]) == (Vec3f(0), Vec3f(0.062805, 0.591207, 0.902102), Vec3f(0.058382, 0.577691, 0.904429))
194+
@test normals(msh2)[faces(msh2)[1]] == (Vec3f(0.9134, 0.104, 0.3934), Vec3f(0.8079, 0.4428, 0.3887), Vec3f(0.8943, 0.4474, 0.0))
195+
196+
# test that save works with FaceViews
197+
mktempdir() do tmpdir
198+
save(joinpath(tmpdir, "test.obj"), msh)
199+
msh1 = load(joinpath(tmpdir, "test.obj"))
200+
msh3 = expand_faceviews(Mesh(msh1)) # should be unnecessary atm
201+
@test length(faces(msh2)) == length(faces(msh3))
202+
for (f1, f2) in zip(faces(msh2), faces(msh3))
203+
@test coordinates(msh2)[f1] == coordinates(msh3)[f2]
204+
@test normals(msh2)[f1] == normals(msh3)[f2]
205+
end
206+
end
170207
end
171208
@testset "2DM" begin
172209
msh = load(joinpath(tf, "test.2dm"))
File renamed without changes.

test/testfiles/test_face_normal.obj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
v 0.000000 0.000000 0.000000
22
v 0.062805 0.591207 0.902102
33
v 0.058382 0.577691 0.904429
4-
vn 0.913400 0.104000 0.393400
54
vn 0.807900 0.442800 0.388700
5+
vn 0.913400 0.104000 0.393400
66
vn 0.894300 0.447400 0.000000
77
s 1
8-
f 1//1 2//2 3//3
8+
f 1//2 2//1 3//3

0 commit comments

Comments
 (0)