rdeits / MeshCat.jl

WebGL-based 3D visualizer in Julia
MIT License
233 stars 42 forks source link

Handle the wireframe and wireframeLinewidth properties #163

Closed rdeits closed 4 years ago

rdeits commented 4 years ago

Resolves #152

Here's a demo of using the new properties to show a mesh, its wireframe, and its vertices:

using MeshCat
using MeshIO, FileIO
using Colors
using GeometryTypes: vertices

function draw_fancy_mesh(vis::Visualizer, mesh)
    # Draw the mesh itself
    setobject!(vis[:mesh], cube, MeshPhongMaterial())

    # Draw it again as a wireframe
    setobject!(vis[:wireframe], cube, MeshPhongMaterial(
        wireframe=true,
        wireframeLinewidth=2,
        color=colorant"black"))

    # Draw it again as a collection of vertices
    setobject!(vis[:vertices], PointCloud(vertices(cube)),
               PointsMaterial(size=0.05))
end

vis = Visualizer()
open(vis)
cube = load("test/data/meshes/cube.stl")
draw_fancy_mesh(vis[:cube], cube)

Screenshot from 2020-05-28 22-20-33

Kevin-Mattheus-Moerman commented 4 years ago

I get the following error trying to run this demo (after replacing the path to the cube.stl file with another valid STL). FYI I'm new to Julia and am also testing Makie which uses GeometryBasics instead of GeometryTypes (I think...). Despite this code having using GeometryTypes: vertices, it still seems to call GeometryBasics. Is that the issue? Thanks.

LoadError: MethodError: no method matching setobject!(::Visualizer, ::GeometryBasics.Mesh{3,Float32,GeometryBasics.Ngon{3,Float32,3,Point{3,Float32}},FaceView{GeometryBasics.Ngon{3,Float32,3,Point{3,Float32}},Point{3,Float32},NgonFace{3,OffsetInteger{-1,UInt32}},Array{Point{3,Float32},1},Array{NgonFace{3,OffsetInteger{-1,UInt32}},1}}}, ::MeshCat.GenericMaterial)
Closest candidates are:
  setobject!(::AbstractVisualizer, !Matched::Union{GeometryTypes.AbstractGeometry, GeometryTypes.AbstractMesh, MeshFileGeometry}, ::AbstractMaterial) at /home/kevin/.julia/packages/MeshCat/nXUuG/src/abstract_visualizer.jl:13
  setobject!(::AbstractVisualizer, !Matched::Union{GeometryTypes.AbstractGeometry, GeometryTypes.AbstractMesh, MeshFileGeometry}) at /home/kevin/.julia/packages/MeshCat/nXUuG/src/abstract_visualizer.jl:12
  setobject!(::Visualizer, !Matched::AbstractObject) at /home/kevin/.julia/packages/MeshCat/nXUuG/src/visualizer.jl:187
in expression starting at /home/kevin/Desktop/julia_tests/test_meshcat.jl:25
draw_fancy_mesh(::Visualizer, ::GeometryBasics.Mesh{3,Float32,GeometryBasics.Ngon{3,Float32,3,Point{3,Float32}},FaceView{GeometryBasics.Ngon{3,Float32,3,Point{3,Float32}},Point{3,Float32},NgonFace{3,OffsetInteger{-1,UInt32}},Array{Point{3,Float32},1},Array{NgonFace{3,OffsetInteger{-1,UInt32}},1}}}) at test_meshcat.jl:8
top-level scope at test_meshcat.jl:25

Also I'm using Julia v1.4.1 on Ubuntu 20.04.

rdeits commented 4 years ago

MeshIO recently updated to a version which is incompatible with MeshCat. You just need to do ]add MeshIO@0.3 in the Julia REPL. See https://github.com/rdeits/MeshCat.jl/issues/154 for more info.

Kevin-Mattheus-Moerman commented 4 years ago

@rdeits thanks. Although now I get:

ERROR: LoadError: MethodError: no method matching MeshCat.GenericMaterial(; _type="MeshPhongMaterial", wireframe=true, wireframeLinewidth=2, color=RGB{N0f8}(0.0,0.0,0.0))
Closest candidates are:
  MeshCat.GenericMaterial(; _type, color, map, depthFunc, depthTest, depthWrite, linewidth, vertexColors, side) at /home/kevin/.julia/packages/Parameters/CVyBv/src/Parameters.jl:468 got unsupported keyword arguments "wireframe", "wireframeLinewidth"
  MeshCat.GenericMaterial(::MeshCat.GenericMaterial; kws...) at /home/kevin/.julia/packages/Parameters/CVyBv/src/Parameters.jl:530
  MeshCat.GenericMaterial(::MeshCat.GenericMaterial, ::AbstractDict) at /home/kevin/.julia/packages/Parameters/CVyBv/src/Parameters.jl:533 got unsupported keyword arguments "_type", "wireframe", "wireframeLinewidth", "color"
  ...
Stacktrace:
 [1] kwerr(::NamedTuple{(:_type, :wireframe, :wireframeLinewidth, :color),Tuple{String,Bool,Int64,RGB{FixedPointNumbers.Normed{UInt8,8}}}}, ::Type{T} where T) at ./error.jl:157
 [2] #MeshPhongMaterial#23 at /home/kevin/.julia/packages/MeshCat/GMobF/src/objects.jl:69 [inlined]
 [3] draw_fancy_mesh(::Visualizer, ::GLNormalMesh) at /home/kevin/Desktop/julia_tests/temp_meshcat_01.jl:11
 [4] top-level scope at /home/kevin/Desktop/julia_tests/temp_meshcat_01.jl:24
in expression starting at /home/kevin/Desktop/julia_tests/temp_meshcat_01.jl:24
rdeits commented 4 years ago

That just looks like you're not running the most up-to-date version of MeshCat.jl master. You can do:

]add MeshCat#master
]build MeshCat

at the Julia REPL to get the latest version (you'll need to restart Julia afterward).

rdeits commented 4 years ago

I'll tag a new release with the wireframe feature soon; I'm just also working on upgrading to the new GeometryBasics so that we don't have issues with using up-to-date versions of MeshIO.

Kevin-Mattheus-Moerman commented 4 years ago

Great thanks. Using ]add MeshCat#master worked. I do still have this issue but I'll try to read around a bit more: https://github.com/rdeits/MeshCat.jl/issues/165