Skip to content

Commit

Permalink
Fix binary ply save.
Browse files Browse the repository at this point in the history
  • Loading branch information
spelufo committed Jun 5, 2024
1 parent c5f49ad commit 413a70a
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/io/ply.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
function save(f::Stream{format"PLY_BINARY"}, msh::AbstractMesh)
io = stream(f)
points = decompose(Point{3, Float32}, msh)
points = coordinates(msh)
point_normals = normals(msh)
faces = decompose(GLTriangleFace, msh)

meshfaces = faces(msh)
n_points = length(points)
n_faces = length(faces)
n_faces = length(meshfaces)

# write the header
write(io, "ply\n")
Expand All @@ -30,9 +29,9 @@ function save(f::Stream{format"PLY_BINARY"}, msh::AbstractMesh)
end
end

for f in faces
write(io, convert(UInt8, 3))
write(io, raw.(f)...)
for f in meshfaces
write(io, convert(UInt8, length(f)))
write(io, raw.(ZeroIndex.(f))...)
end
close(io)
end
Expand All @@ -42,19 +41,18 @@ function save(f::Stream{format"PLY_ASCII"}, msh::AbstractMesh)
points = coordinates(msh)
point_normals = normals(msh)
meshfaces = faces(msh)

n_faces = length(points)
n_points = length(meshfaces)
n_points = length(points)
n_faces = length(meshfaces)

# write the header
write(io, "ply\n")
write(io, "format ascii 1.0\n")
write(io, "element vertex $n_faces\n")
write(io, "element vertex $n_points\n")
write(io, "property float x\nproperty float y\nproperty float z\n")
if !isnothing(point_normals)
write(io, "property float nx\nproperty float ny\nproperty float nz\n")

Check warning on line 53 in src/io/ply.jl

View check run for this annotation

Codecov / codecov/patch

src/io/ply.jl#L53

Added line #L53 was not covered by tests
end
write(io, "element face $n_points\n")
write(io, "element face $n_faces\n")
write(io, "property list uchar int vertex_index\n")
write(io, "end_header\n")

Expand Down

0 comments on commit 413a70a

Please sign in to comment.