I’m trying to draw 3D polygons, but the only working way I found is cumbersome: is there some simple command I missed e.g. poly(X, Y, Z, color=C)
that will allow me to plot 3D polygons in Makie ?
using GLMakie
# cols = triangle number (here 4 tris), rows = coordinates for triangle vertex 1->3
X = [0. 1 1 2; 1 1 2 2; 0 0 1 1]
Y = [1. 1 1 1; 1 0 1 0; 0 0 0 0]
Z = [1. 1 1 1; 1 0 1 0; 0 0 0 0]
C = [.5 1. 1. .5; 1. .5 .5 .1667; .333 .333 .5 .5]
ntris = size(X, 2)
# this works, but I find it cumbersome and unefficient
vertices = [Point(X[v, n], Y[v, n], Z[v, n]) for n ∈ 1:ntris for v ∈ 1:3]
indices = [TriangleFace(n, n + 1, n + 2) for n ∈ 1:3:length(X)]
fap = poly(vertices, indices, color=C[:], strokewidth=1)
# fails
shapes = [
Polygon(
Point3f0[
(X[1, n], Y[1, n], Z[1, n]),
(X[2, n], Y[2, n], Z[2, n]),
(X[3, n], Y[3, n], Z[3, n]),
]
) for n ∈ 1:size(X, 2)
]
fap = poly(shapes)
# MethodError: no method matching earcut_triangulate(::Vector{Vector{Point{3, Float32}}})
# converting to Nsimples{3} (triangles) or NNgon{3} (also a triangle) also fails
xyz = reshape([X[:] Y[:] Z[:]]', :)
triangles = connect(connect(xyz, Point{3}), NSimplex{3})
fap = poly(triangles)
# ERROR: `Makie.convert_arguments` for the plot type Scatter{ArgType} where ArgType and its conversion trait PointBased() was unsuccessful.
# wished for, but fails
fap = poly(X, Y, Z, color=C)
# ERROR: `Makie.convert_arguments` for the plot type Scatter{ArgType} where ArgType and its conversion trait PointBased() was unsuccessful.
cam3d!(fap.axis.scene)
display(fap)