-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Format] Add writeobj support (Wavefront OBJ)
- Loading branch information
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# ========================================================================================= | ||
""" | ||
function writeobj{T}( | ||
stream::IOStream, | ||
model ::Model{T, Triangle{T}} | ||
) | ||
Creates a Wavefront OBJ file from a given surface model. | ||
# Specification | ||
<https://www.loc.gov/preservation/digital/formats/fdd/fdd000507.shtml> | ||
<http://paulbourke.net/dataformats/obj/> | ||
# Return type | ||
`Void` | ||
# Alias | ||
writeobj{T}( | ||
fname::String, | ||
model::Model{T, Triangle{T}} | ||
) | ||
Creates the OBJ file by name rather than `IOStream` object. | ||
""" | ||
function writeobj( | ||
stream::IOStream, | ||
model ::Model{T, Triangle{T}} | ||
) where T | ||
# nodes | ||
for node in model.nodes | ||
println(stream, "v ", node[1], " ", node[2], " ", node[3]) | ||
end | ||
# vertex normals | ||
vns = vertexnormals(model) | ||
for vn in vns | ||
println(stream, "vn ", vn[1], " ", vn[2], " ", vn[3]) | ||
end | ||
# elements | ||
ridx = reverseindex(model.nodes) | ||
for elm in model.elements | ||
print(stream, "f ") | ||
print(stream, ridx[objectid(elm.v1)], "//", ridx[objectid(elm.v1)], " ") | ||
print(stream, ridx[objectid(elm.v2)], "//", ridx[objectid(elm.v2)], " ") | ||
println(stream, ridx[objectid(elm.v3)], "//", ridx[objectid(elm.v3)]) | ||
end | ||
end | ||
|
||
function writeobj(fname::String, model::Model{T, Triangle{T}}) where T | ||
open(fh -> writeobj(fh, model), fname, "w") | ||
end |
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,3 @@ | ||
@testset "writeobj" begin | ||
@test_skip writeobj | ||
end |
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