Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #100 bug in MeshIO when writing OptionalColorNormalMesh without normals but with color #101

Merged
merged 2 commits into from
Apr 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/main/scala/scalismo/faces/io/MeshIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import java.io.{File, IOException}
import scalismo.faces.color.RGBA
import scalismo.faces.io.msh.MSHMeshIO
import scalismo.faces.io.ply.PLYMesh
import scalismo.faces.mesh.{ColorNormalMesh3D, OptionalColorNormalMesh3D, VertexColorMesh3D}
import scalismo.faces.mesh.{ColorNormalMesh3D, OptionalColorNormalMesh3D, TextureMappedProperty, VertexColorMesh3D}
import scalismo.geometry.{Vector, _3D}
import scalismo.mesh.{MeshSurfaceProperty, TriangleMesh3D}
import scalismo.mesh.{MeshSurfaceProperty, SurfacePointProperty, TriangleMesh3D}

import scala.util.{Failure, Try}

Expand Down Expand Up @@ -59,8 +59,15 @@ object MeshIO {
case f if f.toLowerCase.endsWith(".ply") =>
if (mesh.colorNormalMesh3D.isDefined)
Try(PLYMesh.writePLY(mesh.colorNormalMesh3D.get, filename))
else if (mesh.vertexColorMesh3D.isDefined)
Try(PLYMesh.writePLY(mesh.vertexColorMesh3D.get, filename))
else if (mesh.hasColor)
mesh.color.get match {
case texture: TextureMappedProperty[RGBA] =>
Try(PLYMesh.writePLY(mesh.copy(normals = Some(mesh.shape.vertexNormals)).colorNormalMesh3D.get, filename))
case vertexColor: SurfacePointProperty[RGBA] =>
Try(PLYMesh.writePLY(mesh.vertexColorMesh3D.get, filename))
case _ =>
Failure(new IOException("Do not know how to write the color information of the given mesh to the file."))
}
else
Try(PLYMesh.writePLY(mesh.shape, filename))
case _ => Failure(new IOException("Writing mesh: Unknown file type " + filename))
Expand Down