Using Meshes.ji

645 views
Skip to first unread message

Ashley Kleinhans

unread,
Nov 9, 2015, 9:55:57 AM11/9/15
to julia-users
Hi,

I am new at this - but have decided that Julia is my language of choice. So I begin silly question stage:

Could someone talk me through how to access and display an .obj file?

I have gotten so far:

using Meshes
using PyPlot
using FileIO
using MeshIO

obj
= load(filename)
vts
= obj.vertices


Which gives me:

502-element Array{FixedSizeArrays.Point{3,Float32},1}:



One example point being:

Point(0.00117,-0.02631,0.03907)    

                                                                              
 

How do I access the verticies to use them with plot?

-A


Steve Kelly

unread,
Nov 9, 2015, 11:45:01 AM11/9/15
to julia...@googlegroups.com

The faces can be accessed with faces(load("foo.obj")) or mesh.faces.

Probably the easiest way to display the mesh at this point is with ThreeJS.jl: https://github.com/rohitvarkey/ThreeJS.jl/blob/master/examples/mesh.jl. This approach should work in IJulia and Blink.

GLVisualize has some good demos and a much more responsive backend, but it needs some work to run in OpenGL < 3.3 and the working commits aren't on Metadata yet. Meshes is kind of a weird state right now, and most of the functionality can be had with GeometryTypes, Meshing, and MeshIO. We have been working the past few months to finish the coupling between data structures for geometry and visualization. It would be great to hear your application, and see if we could achieve something in the short term that would work for you. Personally I use Meshlab when I do solid modelling in Julia which slows down my iteration time, and it would be nice to have a mesh viewer in the workflow.

Best,
Steve

Rohit Thankachan

unread,
Nov 10, 2015, 6:20:44 AM11/10/15
to julia-users
I've made a few changes to the file Steve pointed you to. It can be found at https://gist.github.com/rohitvarkey/5be4542faff17014afc7.

If you use Escher to run that file, you can load .obj files by just typing in the filename (provided you ran the Escher server from the directory the file exists) or the absolute path to the file in the input field. A very primitive mesh viewer in Julia I guess. :)

Regards,
Rohit  

kleinsplash

unread,
Nov 23, 2015, 6:50:00 AM11/23/15
to julia-users
Thanks guys :)

kleinsplash

unread,
Nov 23, 2015, 6:53:50 AM11/23/15
to julia-users
Looks like accessing has changed a bit - so to get to the faces I did

obj = load("path.obj")
faces = obj.faces

So far I haven't had much luck in either plotting this or accessing the faces and the verticies. As soon as I figure it out I will get back. This is linked to my other question, for some reason I wasn't automatically subscribed to this one.

kleinsplash

unread,
Nov 23, 2015, 9:53:24 AM11/23/15
to julia-users
Thanks to group managed to plot using GLVisualize:

using GLVisualize
using FileIO
w
,r = glscreen()
view
(visualize(obj))
r
()

from Simon's answer here: https://groups.google.com/d/msg/julia-users/W8D6kAJhREI/N89EOObzCAAJ 

kleinsplash

unread,
Nov 24, 2015, 5:30:56 AM11/24/15
to julia-users
I know this is a really simple question - so forgive me for asking.. I am not a programmer but I do want to make Julia the language I use - and move away from the others that shall not be named.. I would really like an explicit syntax answer to this:


obj_file = "pathto.obj"
obj
= load(obj_file)
display
(obj.vertices)


which gives me:

502-element Array{FixedSizeArrays.Point{3,Float32},1}:

 
Point(0.00117,-0.02631,0.03907)  
 
Point(-0.00896,-0.02466,0.03908)
 
                               

 
Point(-0.01634,-0.0178,-0.05919)
 
Point(-0.01751,-0.01913,-0.06169)

How do I access this info?
So I can then do a scatter3D plot.

I have tried:
obj.vertices[1,:][1,1]

which gets me this far

FixedSizeArrays.Point{3,Float32}((0.00117f0,-0.02631f0,0.03907f0))

and this
obj.vertices[1,:][1,1][1]
which gets the first value

0.00117f0

But it really doesn't seem that elegant.. which typically means I am doing something wrong.

I want to put all vertices in a matrix and not look like its a hack.

Simon Danisch

unread,
Nov 24, 2015, 7:10:09 AM11/24/15
to julia-users
This is the best GLVisualize can do for you right meow:



You get this with:


using GLVisualize, FileIO, Colors, GeometryTypes, GLAbstraction
window, renderloop = glscreen()
obj = load("cat.obj")
obj_vizz = visualize(obj, color=RGBA{Float32}(0,0,0,0.1))
point3d_vizz = visualize(vertices(obj), scale=Vec3f0(0.01))
axis = visualize(boundingbox(point3d_vizz).value, :grid)
view(obj_vizz)
view(point3d_vizz)
view(axis)
renderloop()

A lot of improvements are on its way (like better camera, more consistent API and better axis), but this is still not out yet.

I'm not sure what would be possible with a combination of MeshIO and e.g. PyPlot, but I guess it could be better axis/labels + print quality, while being slower ;)
You quite likely need to do something like:

points = vertices(obj) #GeometryTypes exports vertices(...)
x,y,z = [p[1] for p in points], map(p->p[2], points), map(last, points) # three different ways of getting the x,y,z coordinates

and then go from there with the PyPlot/matplotlib docs.


Am Montag, 9. November 2015 15:55:57 UTC+1 schrieb kleinsplash:

kleinsplash

unread,
Nov 25, 2015, 1:52:07 AM11/25/15
to julia-users
That cat is awesome. And so is the script thank you. The only thing is my screen comes up really small and I cant zoom in. This is as far as it goes:



That is a wine glass. I want it bigger so I can fill it with virtual wine :)

Thank you! I doubt I would have gotten to those mapping options right.

Side Note: I am getting a warning from glscreen() saying: WARNING: Base.Uint8 is deprecated, use UInt8 instead.
Auto Generated Inline Image 1
Reply all
Reply to author
Forward
0 new messages