JuliaIO / MeshIO.jl

IO for Meshes
Other
79 stars 32 forks source link

triangulate polygonal faces with any number of vertices when loading OBJ #18

Closed rdeits closed 8 years ago

rdeits commented 8 years ago

.obj files can contain faces with an arbitrary number of vertices. This patch changes the obj loader to triangulate any polygonal faces when loading the mesh.

Note that this calls decompose() even when it's not strictly necessary (when the face is already a triangle). But the @generated decompose method for such a case compiles down to just a single call to the constructor of the new Face type, so there shouldn't be any additional cost for doing so.

coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.4%) to 96.364% when pulling e55676925e57c8420c2a5ce1e74e90229b3be3a8 on rdeits:obj-polygonal-faces into fe6878bbfe501b4f00c938d37cd0c6e5e7cd0fd7 on JuliaIO:master.

codecov-io commented 8 years ago

Current coverage is 96.36%

Merging #18 into master will increase coverage by 0.38%

@@             master        #18   diff @@
==========================================
  Files             6          6          
  Lines           273        275     +2   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits            262        265     +3   
+ Misses           11         10     -1   
  Partials          0          0          

Powered by Codecov. Last updated by fe6878b...45b88fa

SimonDanisch commented 8 years ago

Great! Do you happen to have a simple model flying around to add to the tests?

rdeits commented 8 years ago

Sure, will do!

rdeits commented 8 years ago

OK, I added a very simple OBJ mesh with a 6-vertex face and a test to verify triangulation.

If you'd like, I can also add one of the actual meshes I've been working with (I'm playing around with the model of the NASA Valkyrie robot: https://github.com/rdeits/RigidBodyTreeInspector.jl/pull/3#issuecomment-222233185 ), but this seemed like a nice minimal way to test the change.

coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.4%) to 96.364% when pulling ce3c4d77d9c0f74b81a020b72e1b0ce444998a95 on rdeits:obj-polygonal-faces into fe6878bbfe501b4f00c938d37cd0c6e5e7cd0fd7 on JuliaIO:master.

rdeits commented 8 years ago

By the way, I also have a pretty slick way of visualizing meshes from Julia now, in case you're interested. I'm part of a robotics group at MIT, and we've got a nice visualizer for 3D geometries as part of our lab's free toolbox: http://drake.mit.edu/ and https://github.com/RobotLocomotion/director/

I've put together some Julia bindings for that package, which currently live here: https://github.com/rdeits/DrakeVisualizer.jl . Currently, that package only works if you've already installed Drake (which is free and supported on all platforms), but I'm hoping to give it the ability to build its own copy of the visualizer using BinDeps soon.

Anyway, with those pieces in place, visualizing a mesh is as easy as:

julia> using FileIO
julia> using MeshIO
julia> mesh = load(joinpath("test/testfiles/test.obj"))
HomogenousMesh(
    normals: 2248xGeometryTypes.Normal{3,Float32},     vertices: 2248xFixedSizeArrays.Point{3,Float32},     faces: 3954xGeometryTypes.Face{3,UInt32,-1}, )
julia> using DrakeVisualizer
julia> vis = Visualizer(mesh)

which causes the viewer to display:

screen shot 2016-05-28 at 6 43 41 pm

and it's easy to adjust the display properties within the viewer:

screen shot 2016-05-28 at 6 45 30 pm

Anyway, if you're interested I'm happy to help make this more user-friendly.

SimonDanisch commented 8 years ago

Did I forgot to merge this? This should be good to go, right?

rdeits commented 8 years ago

Yup, should be good to go 😄

SimonDanisch commented 8 years ago

thanks!