Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for GeometryBasics refactor #4319

Draft
wants to merge 47 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d7d704f
get Makie to compile
ffreyer Sep 4, 2024
256822b
get GLMakie to compile
ffreyer Sep 4, 2024
3819a34
fix nromal rename, meshscatter
ffreyer Sep 4, 2024
b9fc885
fix pointtype in mesh conversion
ffreyer Sep 4, 2024
2ff3b65
avoid matrix in vector rotation
ffreyer Sep 5, 2024
97b17bc
fix more tests
ffreyer Sep 6, 2024
cd0db10
update GeometryBasics functions/interface
ffreyer Sep 6, 2024
cef70e4
fix voronoiplot clipping
ffreyer Sep 6, 2024
decdc83
update CairoMakie
ffreyer Sep 6, 2024
78fff6c
update RPRMakie
ffreyer Sep 6, 2024
1b72110
prepare WGLMakie
ffreyer Sep 6, 2024
26ff1d3
Update CI to use the GeometryBasics refactor branch (#4326)
asinghvi17 Sep 6, 2024
74e5801
update _faces
ffreyer Sep 6, 2024
2bd82bc
normals -> normal
ffreyer Sep 6, 2024
6ee1726
add ShaderAbstractions to ci
ffreyer Sep 6, 2024
8a33cf2
update docs, normals deprecation
ffreyer Sep 8, 2024
10e2042
Merge branch 'ff/GeometryBasics_refactor' of https://github.com/Makie…
ffreyer Sep 8, 2024
8d87754
fix branch names
ffreyer Sep 9, 2024
4b646de
fix catmesh getting normals regenerated
ffreyer Sep 9, 2024
c9c218c
Merge branch 'ff/GeometryBasics_refactor' of https://github.com/Makie…
ffreyer Sep 9, 2024
7bfad9e
update for ShaderAbstractions
ffreyer Sep 9, 2024
898a04b
handle voxel clipping in CairoMakie like in GLMakie
ffreyer Sep 9, 2024
24f38b9
fix another two "normals"
ffreyer Sep 9, 2024
ff76818
add dev branches for RPRMakie CI
ffreyer Sep 9, 2024
1179da4
fix missing kwarg name in conversion
ffreyer Sep 10, 2024
378e006
update for FaceViews
ffreyer Sep 12, 2024
2454cb4
Merge branch 'master' into ff/GeometryBasics_refactor
ffreyer Sep 12, 2024
9d01754
add example for per-face colors and normals
ffreyer Sep 14, 2024
6509e21
improve typing
ffreyer Sep 14, 2024
31aa47d
Merge branch 'master' into ff/GeometryBasics_refactor
ffreyer Sep 14, 2024
a8a6120
fix Sampler, allow mipmap via Sampler
ffreyer Sep 15, 2024
4f44333
try to fix benchmarks
SimonDanisch Sep 18, 2024
9e784ab
add to correct env
SimonDanisch Sep 18, 2024
a9cd8f0
remove from master project
SimonDanisch Sep 18, 2024
9631841
fix docs
SimonDanisch Sep 18, 2024
11fb653
fix Rect decomposition
ffreyer Sep 18, 2024
c8ec1be
Merge branch 'ff/GeometryBasics_refactor' of https://github.com/Makie…
ffreyer Sep 18, 2024
b1180d8
fix poly converts
ffreyer Sep 19, 2024
9657e6a
Merge branch 'master' into ff/GeometryBasics_refactor
ffreyer Sep 19, 2024
4c7ba89
fix typo
ffreyer Sep 20, 2024
f9871d1
Merge branch 'master' into ff/GeometryBasics_refactor
ffreyer Sep 26, 2024
0f7bddc
improve precompilation by avoiding constprop and more direct icon loa…
SimonDanisch Sep 27, 2024
5ac306e
fix CairoMakie precompile
SimonDanisch Sep 27, 2024
9003123
Merge branch 'master' into ff/GeometryBasics_refactor
ffreyer Oct 2, 2024
dfac11c
Merge branch 'master' into ff/GeometryBasics_refactor
SimonDanisch Oct 9, 2024
a3eb7a5
fix old syntax
ffreyer Oct 9, 2024
d8be6c7
fix ambient light
ffreyer Oct 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ jobs:
pkg"registry up"
Pkg.update()
pkg"dev . ./MakieCore"
pkg"add GeometryBasics#ff/refactor"
pkg"add MeshIO#ff/GeometryBasics_refactor"
pkg"add ShaderAbstractions#ff/GeometryBasics_refactor"
Pkg.test("Makie"; coverage=true)

- uses: julia-actions/julia-processcoverage@v1
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/reference_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ jobs:
# dev mono repo versions
pkg"registry up"
Pkg.update()
pkg"add MeshIO#ff/GeometryBasics_refactor"
pkg"add GeometryBasics#ff/refactor"
pkg"add ShaderAbstractions#ff/GeometryBasics_refactor"
pkg"dev . ./MakieCore ./CairoMakie ./ReferenceTests"
- name: Run the tests
continue-on-error: true
Expand Down Expand Up @@ -95,6 +98,9 @@ jobs:
# dev mono repo versions
pkg"registry up"
Pkg.update()
pkg"add MeshIO#ff/GeometryBasics_refactor"
pkg"add GeometryBasics#ff/refactor"
pkg"add ShaderAbstractions#ff/GeometryBasics_refactor"
pkg"dev . ./MakieCore ./GLMakie ./ReferenceTests"
- name: Run the tests
id: referencetests
Expand Down Expand Up @@ -145,6 +151,9 @@ jobs:
# dev mono repo versions
pkg"registry up"
Pkg.update()
pkg"add MeshIO#ff/GeometryBasics_refactor"
pkg"add GeometryBasics#ff/refactor"
pkg"add ShaderAbstractions#ff/GeometryBasics_refactor"
pkg"dev . ./MakieCore ./WGLMakie ./ReferenceTests"
- name: Run the tests
continue-on-error: true
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/rprmakie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ jobs:
using Pkg;
pkg"registry up"
Pkg.update()
pkg"add GeometryBasics#ff/refactor"
pkg"add MeshIO#ff/GeometryBasics_refactor"
pkg"add ShaderAbstractions#ff/GeometryBasics_refactor"
# dev mono repo versions
pkg"dev . ./MakieCore ./RPRMakie ./ReferenceTests"
- name: Run the tests
Expand Down
32 changes: 12 additions & 20 deletions CairoMakie/src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,6 @@ function draw_atomic(scene::Scene, screen::Screen, @nospecialize(primitive::Unio

isempty(positions) && return

# workaround for a LineSegments object created from a GLNormalMesh
# the input argument is a view of points using faces, which results in
# a vector of tuples of two points. we convert those to a list of points
# so they don't trip up the rest of the pipeline
# TODO this shouldn't be necessary anymore!
if positions isa SubArray{<:Point3, 1, P, <:Tuple{Array{<:AbstractFace}}} where P
positions = let
pos = Point3f[]
for tup in positions
push!(pos, tup[1])
push!(pos, tup[2])
end
pos
end
end

# color is now a color or an array of colors
# if it's an array of colors, each segment must be stroked separately
color = to_color(primitive.calculated_colors[])
Expand Down Expand Up @@ -1200,7 +1184,7 @@ function draw_atomic(scene::Scene, screen::Screen, @nospecialize(primitive::Maki

pos = primitive[1][]
# For correct z-ordering we need to be in view/camera or screen space
model = copy(model)
model = copy(model)::Mat4d
view = scene.camera.view[]

zorder = sortperm(pos, by = p -> begin
Expand Down Expand Up @@ -1253,10 +1237,18 @@ function draw_atomic(scene::Scene, screen::Screen, @nospecialize(primitive::Maki
pos = Makie.voxel_positions(primitive)
scale = Makie.voxel_size(primitive)
colors = Makie.voxel_colors(primitive)
marker = normal_mesh(Rect3f(Point3f(-0.5), Vec3f(1)))

# Face culling
if !isempty(primitive.clip_planes[]) && Makie.is_data_space(primitive.space[])
valid = [is_visible(primitive.clip_planes[], p) for p in pos]
pos = pos[valid]
colors = colors[valid]
end

marker = GeometryBasics.clear_faceviews(normal_mesh(Rect3f(Point3f(-0.5), Vec3f(1))))

# For correct z-ordering we need to be in view/camera or screen space
model = copy(primitive.model[])
model = copy(primitive.model[])::Mat4d
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems weird to copy an immutable? Not part of this PR, but still we may want to remove it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may come from my first attempt to get 3D meshes working in CairoMakie where I didn't know what kind of types to expect. I guess technically you could do plot(..., model = rand(4, 4) and pass a Base.Matrix, but iirc this errored when copy(::Mat4d) was generating a Base.Matrix anyway...

view = scene.camera.view[]

zorder = sortperm(pos, by = p -> begin
Expand All @@ -1271,7 +1263,7 @@ function draw_atomic(scene::Scene, screen::Screen, @nospecialize(primitive::Maki
specular = primitive.specular, shininess = primitive.shininess,
faceculling = get(primitive, :faceculling, -10),
transformation = Makie.transformation(primitive),
clip_planes = primitive.clip_planes
clip_planes = Plane3f[]
)

for i in zorder
Expand Down
2 changes: 1 addition & 1 deletion GLMakie/src/GLAbstraction/GLTexture.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function Texture(s::ShaderAbstractions.Sampler{T, N}; kwargs...) where {T, N}
pointer(s.data), size(s.data),
minfilter = s.minfilter, magfilter = s.magfilter,
x_repeat = s.repeat[1], y_repeat = s.repeat[min(2, N)], z_repeat = s.repeat[min(3, N)],
anisotropic = s.anisotropic; kwargs...
mipmap = s.mipmap, anisotropic = s.anisotropic; kwargs...
)
obsfunc = ShaderAbstractions.connect!(s, tex)
push!(tex.observers, obsfunc)
Expand Down
1 change: 0 additions & 1 deletion GLMakie/src/GLAbstraction/GLTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ function RenderObject(
pre::Pre, post,
context=current_context()
) where Pre

switch_context!(context)

# This is a lazy workaround for disabling updates of `requires_update` when
Expand Down
8 changes: 5 additions & 3 deletions GLMakie/src/GLAbstraction/GLUniforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ function glsl_typename(t::Type{T}) where T <: Mat
string(opengl_prefix(eltype(t)), "mat", M==N ? M : string(N, "x", M))
end
toglsltype_string(t::Observable) = toglsltype_string(to_value(t))
toglsltype_string(x::T) where {T<:Union{Real, Mat, StaticVector, Texture, Colorant, TextureBuffer, Nothing}} = "uniform $(glsl_typename(x))"
function toglsltype_string(x::T) where {T<:Union{Real, Mat, StaticVector, Texture, Colorant, TextureBuffer, Nothing}}
return "uniform $(glsl_typename(x))"
end
#Handle GLSL structs, which need to be addressed via single fields
function toglsltype_string(x::T) where T
if isa_gl_struct(x)
string("uniform ", T.name.name)
else
error("can't splice $T into an OpenGL shader. Make sure all fields are of a concrete type and isbits(FieldType)-->true")
error("can't splice $T into an OpenGL shader. Make sure all fields are of a concrete type and isbits(FieldType)-->true\n\n$x")
end
end
toglsltype_string(t::Union{GLBuffer{T}, GPUVector{T}}) where {T} = string("in ", glsl_typename(T))
Expand Down Expand Up @@ -237,7 +239,7 @@ gl_convert(a::T) where {T <: NATIVE_TYPES} = a
gl_convert(s::Observable{T}) where {T <: NATIVE_TYPES} = s
gl_convert(s::Observable{T}) where T = const_lift(gl_convert, s)
gl_convert(x::StaticVector{N, T}) where {N, T} = map(gl_promote(T), x)
gl_convert(x::Mat{N, M, T}) where {N, M, T} = map(gl_promote(T), x)
gl_convert(x::Mat{N, M, T}) where {N, M, T} = Mat{N, M, gl_promote(T)}(x)
gl_convert(a::AbstractVector{<: AbstractFace}) = indexbuffer(s)
gl_convert(t::Type{T}, a::T; kw_args...) where T <: NATIVE_TYPES = a
gl_convert(::Type{<: GPUArray}, a::StaticVector) = gl_convert(a)
Expand Down
10 changes: 8 additions & 2 deletions GLMakie/src/drawing_primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ function mesh_inner(screen::Screen, mesh, transfunc, gl_attributes, plot, space=
color = pop!(gl_attributes, :color)
interp = to_value(pop!(gl_attributes, :interpolate, true))
interp = interp ? :linear : :nearest

if to_value(color) isa Colorant
gl_attributes[:vertex_color] = color
delete!(gl_attributes, :color_map)
Expand All @@ -739,6 +740,10 @@ function mesh_inner(screen::Screen, mesh, transfunc, gl_attributes, plot, space=
return convert_attribute(uv_transform, key"uv_transform"())
end
end
elseif to_value(color) isa ShaderAbstractions.Sampler
gl_attributes[:image] = Texture(lift(el32convert, plot, color))
delete!(gl_attributes, :color_map)
delete!(gl_attributes, :color_norm)
elseif to_value(color) isa AbstractMatrix{<:Colorant}
gl_attributes[:image] = Texture(lift(el32convert, plot, color), minfilter = interp)
delete!(gl_attributes, :color_map)
Expand All @@ -763,13 +768,14 @@ function mesh_inner(screen::Screen, mesh, transfunc, gl_attributes, plot, space=
end

# TODO: avoid intermediate observable
positions = map(m -> metafree(coordinates(m)), mesh)
# TODO: Should these use direct getters? (faces, normals, texturecoordinates)
positions = map(coordinates, mesh)
gl_attributes[:vertices] = apply_transform_and_f32_conversion(plot, pop!(gl_attributes, :f32c), positions)
gl_attributes[:faces] = lift(x-> decompose(GLTriangleFace, x), mesh)
if hasproperty(to_value(mesh), :uv)
gl_attributes[:texturecoordinates] = lift(decompose_uv, mesh)
end
if hasproperty(to_value(mesh), :normals) && (shading !== NoShading || matcap_active)
if hasproperty(to_value(mesh), :normal) && (shading !== NoShading || matcap_active)
gl_attributes[:normals] = lift(decompose_normals, mesh)
end
return draw_mesh(screen, gl_attributes)
Expand Down
25 changes: 12 additions & 13 deletions GLMakie/src/glshaders/mesh.jl
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
function to_opengl_mesh!(result, mesh_obs::TOrSignal{<: GeometryBasics.Mesh})
m_attr = map(convert(Observable, mesh_obs)) do m
return (m, GeometryBasics.attributes(m))
end

result[:faces] = indexbuffer(map(((m,_),)-> faces(m), m_attr))
result[:vertices] = GLBuffer(map(((m, _),) -> metafree(coordinates(m)), m_attr))

attribs = m_attr[][2]
m = convert(Observable, mesh_obs)

result[:faces] = indexbuffer(map(faces, m))
result[:vertices] = GLBuffer(map(coordinates, m))

function to_buffer(name, target)
if haskey(attribs, name)
val = attribs[name]
if hasproperty(m[], name)
val = getproperty(m[], name)
if mesh_obs isa Observable
val = map(((m, a),)-> a[name], m_attr)
val = map(m -> getproperty(m, name), m)
end
if val[] isa AbstractVector
result[target] = GLBuffer(map(metafree, val))
result[target] = GLBuffer(val)
elseif val[] isa AbstractMatrix
result[target] = Texture(val)
else
error("unsupported attribute: $(name)")
end
end
end

to_buffer(:color, :vertex_color)
to_buffer(:uv, :texturecoordinates)
to_buffer(:uvw, :texturecoordinates)

# Only emit normals, when we shadin'
shading = get(result, :shading, NoShading)::Makie.MakieCore.ShadingAlgorithm
matcap_active = !isnothing(to_value(get(result, :matcap, nothing)))
if matcap_active || shading != NoShading
to_buffer(:normals, :normals)
to_buffer(:normal, :normals)
end
to_buffer(:attribute_id, :attribute_id)

return result
end

Expand Down
2 changes: 1 addition & 1 deletion RPRMakie/src/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function to_rpr_object(context, matsys, scene, plot::Makie.Surface)
faces = decompose(GLTriangleFace, r)
uv = decompose_uv(r)
# with this we can beuild a mesh
mesh = GeometryBasics.Mesh(meta(vec(positions[]), uv=uv), faces)
mesh = GeometryBasics.Mesh(vec(positions[]), faces, uv = uv)

rpr_mesh = RPR.Shape(context, mesh)
color = plot.color[]
Expand Down
8 changes: 4 additions & 4 deletions ReferenceTests/src/tests/examples3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end
function colormesh((geometry, color))
mesh1 = normal_mesh(geometry)
npoints = length(GeometryBasics.coordinates(mesh1))
return GeometryBasics.pointmeta(mesh1; color=fill(color, npoints))
return GeometryBasics.mesh(mesh1; color=fill(color, npoints))
end
# create an array of differently colored boxes in the direction of the 3 axes
x = Vec3f(0); baselen = 0.2f0; dirlen = 1f0
Expand Down Expand Up @@ -318,7 +318,7 @@ end
N = 3; nbfacese = 30; radius = 0.02

large_sphere = Sphere(Point3f(0), 1f0)
positions = decompose(Point3f, large_sphere, 30)
positions = decompose(Point3f, Tesselation(large_sphere, 30))
np = length(positions)
pts = [positions[k][l] for k = 1:length(positions), l = 1:3]
pts = vcat(pts, 1.1 .* pts + RNG.randn(size(pts)) / perturbfactor) # light position influence ?
Expand Down Expand Up @@ -423,7 +423,7 @@ end
end

@reference_test "Normals of a Cat" begin
x = loadasset("cat.obj")
x = GeometryBasics.clear_faceviews(loadasset("cat.obj"))
f, a, p = mesh(x, color=:black)
pos = map(decompose(Point3f, x), GeometryBasics.normals(x)) do p, n
p => p .+ Point(normalize(n) .* 0.05f0)
Expand All @@ -446,7 +446,7 @@ end
function colormesh((geometry, color))
mesh1 = normal_mesh(geometry)
npoints = length(GeometryBasics.coordinates(mesh1))
return GeometryBasics.pointmeta(mesh1; color=fill(color, npoints))
return GeometryBasics.mesh(mesh1; color=fill(color, npoints))
end
# create an array of differently colored boxes in the direction of the 3 axes
x = Vec3f(0); baselen = 0.2f0; dirlen = 1f0
Expand Down
2 changes: 1 addition & 1 deletion ReferenceTests/src/tests/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ end
f, a, p = surface(1..10, 1..10, ns, colormap = [:lightblue, :lightblue])
# plot a wireframe so we can see what's going on, and in which cells.
m = Makie.surface2mesh(to_value.(p.converted)...)
scatter!(a, m.position, color = isnan.(m.normals), depth_shift = -1f-3)
scatter!(a, m.position, color = isnan.(m.normal), depth_shift = -1f-3)
wireframe!(a, m, depth_shift = -1f-3, color = :black)
f
end
Expand Down
2 changes: 1 addition & 1 deletion WGLMakie/assets/mesh.vert
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void main(){
}
vec4 position_world = model * vec4(vertex_position, 1);

render(position_world, get_normals(), view, projection);
render(position_world, get_normal(), view, projection);
frag_uv = apply_uv_transform(get_uv_transform(), get_uv());
frag_color = vertex_color(get_color(), get_colorrange(), colormap);

Expand Down
2 changes: 1 addition & 1 deletion WGLMakie/assets/particles.vert
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void main(){
// get_* gets the global inputs (uniform, sampler, position array)
// those functions will get inserted by the shader creation pipeline
vec3 vertex_position = get_markersize() * to_vec3(get_position());
vec3 N = get_normals() / get_markersize(); // see issue #3702
vec3 N = get_normal() / get_markersize(); // see issue #3702
rotate(get_rotation(), vertex_position, N);
vertex_position = to_vec3(get_offset()) + vertex_position;
vec4 position_world = model * vec4(vertex_position, 1);
Expand Down
4 changes: 3 additions & 1 deletion WGLMakie/src/Serialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export function delete_plots(plot_uuids) {
function convert_texture(scene, data) {
const tex = create_texture(scene, data);
tex.needsUpdate = true;
tex.generateMipmaps = data.mipmap;
tex.minFilter = THREE[data.minFilter];
tex.magFilter = THREE[data.magFilter];
tex.anisotropy = data.anisotropy;
Expand Down Expand Up @@ -266,12 +267,13 @@ function connect_uniforms(mesh, updater) {
function convert_RGB_to_RGBA(rgbArray) {
const length = rgbArray.length;
const rgbaArray = new rgbArray.constructor((length / 3) * 4);
const a = (rgbArray instanceof Uint8Array) ? 255 : 1.0;

for (let i = 0, j = 0; i < length; i += 3, j += 4) {
rgbaArray[j] = rgbArray[i]; // R
rgbaArray[j + 1] = rgbArray[i + 1]; // G
rgbaArray[j + 2] = rgbArray[i + 2]; // B
rgbaArray[j + 3] = 1.0; // A
rgbaArray[j + 3] = a; // A
}

return rgbaArray;
Expand Down
4 changes: 2 additions & 2 deletions WGLMakie/src/imagelike.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function create_shader(mscene::Scene, plot::Surface)
return invert ? -ns : ns
end)

per_vertex = Dict(:positions => positions, :faces => faces, :uv => uv, :normals => normals)
per_vertex = Dict(:positions => positions, :faces => faces, :uv => uv, :normal => normals)
uniforms = Dict(:uniform_color => color, :color => false, :model => model)

# TODO: allow passing Mat{2, 3, Float32} (and nothing)
Expand All @@ -54,7 +54,7 @@ function create_shader(mscene::Scene, plot::Union{Heatmap, Image})
f32c, model = Makie.patch_model(plot)
mesh = limits_to_uvmesh(plot, f32c)
uniforms = Dict(
:normals => Vec3f(0),
:normal => Vec3f(0),
:shading => false,
:diffuse => Vec3f(0),
:specular => Vec3f(0),
Expand Down
9 changes: 5 additions & 4 deletions WGLMakie/src/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ function handle_color!(plot, uniforms, buffers, uniform_color_name = :uniform_co

if color[] isa Colorant
uniforms[uniform_color_name] = color
elseif color[] isa ShaderAbstractions.Sampler
uniforms[uniform_color_name] = to_value(color)
elseif color[] isa AbstractVector
buffers[:color] = Buffer(color)
elseif color[] isa Makie.AbstractPattern
Expand Down Expand Up @@ -93,23 +95,22 @@ function draw_mesh(mscene::Scene, per_vertex, plot, uniforms; permute_tex=true)
uniforms[:object_id] = UInt32(0)
pos = pop!(per_vertex, :positions)
faces = pop!(per_vertex, :faces)
mesh = GeometryBasics.Mesh(meta(pos; per_vertex...), faces)
mesh = GeometryBasics.Mesh(pos, faces; per_vertex...)
return Program(WebGL(), lasset("mesh.vert"), lasset("mesh.frag"), mesh, uniforms)
end

function create_shader(scene::Scene, plot::Makie.Mesh)
# Potentially per instance attributes
mesh_signal = plot[1]
mattributes = GeometryBasics.attributes
get_attribute(mesh, key) = lift(x -> getproperty(x, key), plot, mesh)
data = mattributes(mesh_signal[])
data = GeometryBasics.vertex_attributes(mesh_signal[])

uniforms = Dict{Symbol,Any}()
attributes = Dict{Symbol,Any}()

uniforms[:interpolate_in_fragment_shader] = get(plot, :interpolate_in_fragment_shader, true)

for (key, default) in (:uv => Vec2f(0), :normals => Vec3f(0))
for (key, default) in (:uv => Vec2f(0), :normal => Vec3f(0))
if haskey(data, key)
attributes[key] = Buffer(get_attribute(mesh_signal, key))
else
Expand Down
Loading
Loading