@@ -71,36 +71,39 @@ function vizmesh!(plot, ::Type{<:𝔼}, ::Val{2}, ::Val)
7171 elems = elements (topo)
7272
7373 # coordinates of vertices
74- coords = map (p -> ustrip .( to (p)) , verts)
74+ coords = map (asmakie , verts)
7575
7676 # fan triangulation (assume convexity)
77- tris4elem = map (elems) do elem
77+ ntris = sum (e -> nvertices (pltype (e)) - 2 , elems)
78+ tris = Vector {GB.TriangleFace{Int}} (undef, ntris)
79+ tind = 0
80+ for elem in elems
7881 I = indices (elem)
79- [[I[1 ], I[i], I[i + 1 ]] for i in 2 : (length (I) - 1 )]
82+ for i in 2 : (length (I) - 1 )
83+ tind += 1
84+ tris[tind] = GB. TriangleFace (I[1 ], I[i], I[i + 1 ])
85+ end
8086 end
8187
82- # flatten vector of triangles
83- tris = [tri for tris in tris4elem for tri in tris]
84-
8588 # element vs. vertex coloring
8689 if $ colorant isa AbstractVector
8790 ncolor = length ($ colorant)
8891 if ncolor == nelem # element coloring
8992 # duplicate vertices and adjust
9093 # connectivities to avoid linear
9194 # interpolation of colors
92- nt = 0
95+ tind = 0
9396 elem4tri = Dict {Int,Int} ()
94- for e in 1 : nelem
95- Δs = tris4elem[e]
96- for _ in 1 : length (Δs )
97- nt += 1
98- elem4tri[nt ] = e
97+ sizehint! (elem4tri, ntris)
98+ for (eind, e) in enumerate (elems)
99+ for _ in 1 : ( nvertices ( pltype (e)) - 2 )
100+ tind += 1
101+ elem4tri[tind ] = eind
99102 end
100103 end
101- nv = 3 nt
104+ nv = 3 ntris
102105 tcoords = [coords[i] for tri in tris for i in tri]
103- tconnec = [collect (I ) for I in Iterators . partition ( 1 : nv, 3 )]
106+ tconnec = [GB . TriangleFace (i, i + 1 , i + 2 ) for i in range (start = 1 , step = 3 , length = ntris )]
104107 tcolors = map (1 : nv) do i
105108 t = ceil (Int, i / 3 )
106109 e = elem4tri[t]
@@ -126,22 +129,23 @@ function vizmesh!(plot, ::Type{<:𝔼}, ::Val{2}, ::Val)
126129 tcolors = $ colorant
127130 end
128131
129- # convert connectivities to matrix format
130- tmatrix = reduce (hcat, tconnec) |> transpose
131-
132132 # enable shading in 3D
133133 tshading = dim == 3 ? Makie. FastShading : Makie. NoShading
134134
135- tcoords, tmatrix , tcolors, tshading
135+ tcoords, tconnec , tcolors, tshading
136136 end
137137
138138 # unpack observable of parameters
139139 tcoords = Makie. @lift $ tparams[1 ]
140- tmatrix = Makie. @lift $ tparams[2 ]
140+ tconnec = Makie. @lift $ tparams[2 ]
141141 tcolors = Makie. @lift $ tparams[3 ]
142142 tshading = Makie. @lift $ tparams[4 ]
143143
144- Makie. mesh! (plot, tcoords, tmatrix, color= tcolors, shading= tshading)
144+ # Makie's triangle mesh
145+ mkemesh = Makie. @lift GB. Mesh ($ tcoords, $ tconnec)
146+
147+ # main visualization
148+ Makie. mesh! (plot, mkemesh, color= tcolors, shading= tshading)
145149
146150 if showsegments[]
147151 # retrieve coordinates parameters
0 commit comments