Closed j-fu closed 4 years ago
Hello, here is something I've tried.
In the latest release (v0.11.3), MeshCat.jl uses GeometryTypes. But in the master branch (v0.12.0), the supported package changes to GeometryBasics. The following codes are how I import an obj file for v0.12.0.
mesh_obj = MeshFileGeometry("test.obj")
mesh = MeshObject(mesh_obj)
Thanks! However I am bound to GeometryTypes and I plan to construct the mesh on the fly...
Sorry, I'm a little confused about which one you want to use, GeometryBasics or GeometryTypes? If it is in the latest version, MeshCat.jl can receive GeometryBasics.Mesh type.
Sorry I was confused... In fact I mixed GeometryTypes and GeometryBasics...
I created a mesh using points and connectivities. I can plot this with Makie.poly(), but wanted to try this with MeshCat.
The error I am getting is:
MethodError: no method matching setobject!(::MeshCat.Visualizer, ::GeometryBasics.Mesh{2,Float32,GeometryBasics.Ngon{2,Float32,3,GeometryBasics.Point{2,Float32}},FaceView{GeometryBasics.Ngon{2,Float32,3,GeometryBasics.Point{2,Float32}}}}, ::MeshCat.GenericMaterial)
Edit: here is the MWE as Pluto notebook: meshcat2.jl
And this is the output: meshcat2.pdf
I think it's the problem with the version of MeshCat.jl. The following codes can work well.
using Pkg
Pkg.activate(".")
Pkg.instantiate()
Pkg.add(url="https://github.com/rdeits/MeshCat.jl")
Pkg.add(["GeometryBasics", "Colors"])
using MeshCat
using GeometryBasics, Colors
points=[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0]
faces=[1 13 2 14 3 15 4 16 5 17 6 18 7 19 8 20 9 21 10 22 12 24 13 25 14 26 15 27 16 28 17 29 18 30 19 31 20 32 21 33 23 35 24 36 25 37 26 38 27 39 28 40 29 41 30 42 31 43 32 44 34 46 35 47 36 48 37 49 38 50 39 51 40 52 41 53 42 54 43 55 45 57 46 58 47 59 48 60 49 61 50 62 51 63 52 64 53 65 54 66 56 68 57 69 58 70 59 71 60 72 61 73 62 74 63 75 64 76 65 77 67 79 68 80 69 81 70 82 71 83 72 84 73 85 74 86 75 87 76 88 78 90 79 91 80 92 81 93 82 94 83 95 84 96 85 97 86 98 87 99 89 101 90 102 91 103 92 104 93 105 94 106 95 107 96 108 97 109 98 110 100 112 101 113 102 114 103 115 104 116 105 117 106 118 107 119 108 120 109 121; 2 12 3 13 4 14 5 15 6 16 7 17 8 18 9 19 10 20 11 21 13 23 14 24 15 25 16 26 17 27 18 28 19 29 20 30 21 31 22 32 24 34 25 35 26 36 27 37 28 38 29 39 30 40 31 41 32 42 33 43 35 45 36 46 37 47 38 48 39 49 40 50 41 51 42 52 43 53 44 54 46 56 47 57 48 58 49 59 50 60 51 61 52 62 53 63 54 64 55 65 57 67 58 68 59 69 60 70 61 71 62 72 63 73 64 74 65 75 66 76 68 78 69 79 70 80 71 81 72 82 73 83 74 84 75 85 76 86 77 87 79 89 80 90 81 91 82 92 83 93 84 94 85 95 86 96 87 97 88 98 90 100 91 101 92 102 93 103 94 104 95 105 96 106 97 107 98 108 99 109 101 111 102 112 103 113 104 114 105 115 106 116 107 117 108 118 109 119 110 120; 13 1 14 2 15 3 16 4 17 5 18 6 19 7 20 8 21 9 22 10 24 12 25 13 26 14 27 15 28 16 29 17 30 18 31 19 32 20 33 21 35 23 36 24 37 25 38 26 39 27 40 28 41 29 42 30 43 31 44 32 46 34 47 35 48 36 49 37 50 38 51 39 52 40 53 41 54 42 55 43 57 45 58 46 59 47 60 48 61 49 62 50 63 51 64 52 65 53 66 54 68 56 69 57 70 58 71 59 72 60 73 61 74 62 75 63 76 64 77 65 79 67 80 68 81 69 82 70 83 71 84 72 85 73 86 74 87 75 88 76 90 78 91 79 92 80 93 81 94 82 95 83 96 84 97 85 98 86 99 87 101 89 102 90 103 91 104 92 105 93 106 94 107 95 108 96 109 97 110 98 112 100 113 101 114 102 115 103 116 104 117 105 118 106 119 107 120 108 121 109]
func=Base.map( (x,y) -> Float32(sin(5*x)*cos(5*y)),points[1,:],points[2,:]);
function make_mesh(points, faces, func)
npoints=size(points,2)
nfaces=size(faces,2)
meshpoints=Vector{Point3f0}(undef,npoints)
for i=1:npoints
meshpoints[i]=Point3f0(points[1,i],points[2,i],func[i])
end
meshfaces=Vector{GLTriangleFace}(undef,nfaces)
for i=1:nfaces
meshfaces[i]=TriangleFace(faces[1,i],faces[2,i],faces[3,i])
end
GeometryBasics.Mesh(meshpoints,meshfaces)
end
mesh=make_mesh(points,faces,func)
vis = Visualizer()
setobject!(vis, mesh, MeshPhongMaterial(color=RGBA{Float32}(1.0, 0.0,0.0,1.0)))
Great, works! Just need to wait for the release :+1:
Is it possible to set material (color) per point (with Gouraud shading) and/or per face ?
I'm not sure what the right way is. But set each face as a mesh object might accomplish it although it looks not good...
Ok opened #182 to discuss point colors as this is off-topic for this issue. Moreover IMHO is resolved in the development version.
Thanks for providing the workaround, @PikaPei! I've just opened the PR to register version 0.12, so it should be available later today: https://github.com/JuliaRegistries/General/pull/21831
Hi, Was impressed that this immediately works in a pluto notebook!
I tried to display a triangular mesh created GeometryBasics.Mesh. It seems it is not supported. Is this true ? In that case - which of the primitives from that module will/can be supported ?
Jürgen