Use 2d marker in Makie `meshscatter`

Hello !

I’m trying to display a large set of 3D points (about 80k) with GLMakie. Initially, I used meshscatter, unfortunately my PC doesn’t have a discrete GPU so I’m trying to reduce the stress on the iGPU by using scatter. The good thing is that this works well, but in a sense couldn’t I just use a meshscatter with marker=:circle ?

My experience says that this doesn’t work. I tried with the solution discussed in Using arbitrary polygons as markers in Makie.jl - #13 by yakir12, but this doesn’t handle the plotting of 2D objects in a 3D space.

Any ideas on how to proceed ?

Could you post a simple MWE to illustrate what exactly doesn’t work?

So for instance you can do

using GeometryBasics, GLMakie
points = rand(Point3f,1000)

# Does work
scatter(points)
# Does not work
meshscatter(points,marker=:circle)

To make it as simple as possible, how can I reproduce the scatter output with meshscatter.

I tried adding a polygon as a marker like in the linked post above with e.g.

p = Polygon([Point3f0(0), Point3f0(1,0,0), Point3f0(0,1,0)]);
meshscatter(points,marker=p)

but that fails with

ERROR: MethodError: no method matching earcut_triangulate(::Vector{Vector{Point{3, Float32}}})

In meshscatter’s help it says:

 •  marker::Union{Symbol, GeometryBasics.GeometryPrimitive, GeometryBasics.Mesh} sets the scattered mesh.

so I tried:

meshscatter(points, marker=Sphere(Point3f(0,0,0), 0.2))

which results in:

Apparently, the default marker is a sphere, so you only need to specify the marker size to change it:

meshscatter(points, markersize=0.02)

Yes, I know this is the default, but in that regard scatter and meshscatter behave differently. While meshscatter plots a sphere, scatter plots a circle. I just want to know how to make meshscatter plot a circle as well.

I understand. But in the same way you can’t plot a sphere into a 2D axes, you can’t plot a 2D marker (a circle) into a 3D axis.

What exactly do you want it to look like…?

Well if so, how do you explain how scatter plots a circle then, even in 3D ?

Not the best answer I got, but: I think it doesn’t? If you rotate the plot around the marker is still round, like a sphere would behave.

Frankly, I would normally agree with you, but the marker field of a scatter plot remains by default a :circle, even in 3D axes like a LScene. Also, if you plot around 100k points, at least it’s roughly the threshold I have on my gear, scatter is definitely much faster than meshscatter so I do not think the objects are the same behind the curtains.

1 Like

Why do you want to use meshscatter with marker circle and not scatter? That’s the main question here, which I can’t see an answer for in the thread.
scatter is exactly faster, because it only draws 2d shapes, which is much easier then drawing 3D meshes, which is the only difference between meshscatter + scatter.
The only other difference is, that markerspace for meshscatter is always :data… I suppose then, that you want scatter(points; markerspace=:data)?

You can also try scatter(..., marker = Circle) which I think still uses a different algorithm on the gpu that might be faster than :circle

Btw, the fastest is scatter(...; marker=PixelMarker), but that only draws pixel like rects…

The thing is I do like the meshscatter result very much in general, and I have made recipes based on that. The only problem is performance on large datasets. So either I need to modify my recipes to call scatter or meshscatter based on some heuristic on the size of the data, or if it is possible, find a way to make scatter look like meshscatter, or the other way around.

Well, they’re different functions because they do something different - hence the performance difference… So you cant make them look alike!
Whats the look you’re aiming for anyways?

To speed up meshscatter, you can try to use a marker with less triangles though.
Try marker=Rect and see if that brings you to the desired framerate

I tried with other markers in meshscatter, but it did not feel much smoother in terms of framerate. I guess I’ll just implement the heuristic and switch to scatter for large datasets.