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

Some triangles are not rendered #3561

Open
3 tasks done
tpgillam opened this issue Jan 21, 2024 · 2 comments · May be fixed by #4319
Open
3 tasks done

Some triangles are not rendered #3561

tpgillam opened this issue Jan 21, 2024 · 2 comments · May be fixed by #4319

Comments

@tpgillam
Copy link

  • are you running newest version (version from docs) ?
  • can you reproduce the bug with a fresh environment ? (]activate --temp; add Makie)
  • What platform + GPU are you on?

Various platform info:

MacOS 14.2.1 (Apple M2)
Julia 1.10.0
GLMakie 0.9.5, GeometryBasics 0.4.9

Certain triangles - depending on the vertex ordering - are not visible when plotted with GLMakie.mesh.

For example, if the following is run interactively:

using GeometryBasics
using GLMakie
t_ok = Triangle(Point3(0, 0, 0), Point3(1, 0, 3), Point3(0, 3, 2))
t_bad = Triangle(Point3(1, 0, -1), Point3(-1, 0, 3), Point3(0, 3, 2))

mesh(t_ok)

Then a blue triangle is shown, as expected.
image

But if instead mesh(t_bad) is called, then no triangle is visible.
image

I think it's something to do with vertex ordering, because:

t_permuted = Triangle(t_bad.points[2], t_bad.points[1], t_bad.points[3])
mesh(t_permuted)

then shows the expected triangle.
image


Tracing through what is happening inside the mesh call, the eventual problem seems to be that the following call to decompose in GeometryBasics return any faces (the first step at extracting the points works fine, though):

points = decompose(Point{3,Float32}, t_bad)  # This step is fine
decompose(GLTriangleFace, points)            # This returns an empty array

I'm not sure if the "bug" is in GLMakie for not re-ordering the vertices before calling the decompose function, hence I'm filing it here rather than in GeometryBasics -- apologies if this is incorrect.

@Kevin-Mattheus-Moerman
Copy link

@tpgillam @SimonDanisch I can confirm this bug still persists.

I got a bit further in diagnosing it. It does not seem to matter if the Triangle type is:
GeometryBasics.Ngon{3, Int64, 3, Point3{Int64}}
or instead:
GeometryBasics.Ngon{3, Float64, 3, Point3{Float64}}
It seems to be related to how a Triangle is treated by Makie's mesh function. If I instead create a GeometryBasics.Mesh object for this triangle then it visualizes fine as you can see below (I also tested poly):

image

using GeometryBasics
using GLMakie

t_ok = Triangle(Point3(0, 0, 0), Point3(1, 0, 3), Point3(0, 3, 2))
t_bad = Triangle(Point3(1.0, 0.0, -1.0), Point3(-1.0, 0.0, 3.0), Point3(0.0, 3.0, 2.0))

F = [TriangleFace{Int64}(1, 2, 3)] 
V = Point3{Float64}[[1.0,0.0,-1.0],[-1.0,0.0,-3.0],[0.0,3.0,2.0]]
M = GeometryBasics.Mesh(V,F)

## Visualization
fig = Figure(size=(1600,800))

ax1 = Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "t_ok as Triangle with mesh")
mesh!(ax1,t_ok, linewidth = 5, color = :blue, shading=FastShading)

ax2 = Axis3(fig[1, 2], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "t_bad as Triangle with mesh")
mesh!(ax2,t_bad, linewidth = 5, color = :blue, shading=FastShading)

ax3 = Axis3(fig[2, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "t_bad as Mesh with mesh")
mesh!(ax3,M, color = :blue, shading=FastShading)

ax4 = Axis3(fig[2, 2], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "t_bad as Mesh with poly")
poly!(ax4,M, strokecolor=:red, strokewidth = 2, color = :blue, shading=FastShading)

fig

@ffreyer
Copy link
Collaborator

ffreyer commented Aug 26, 2024

@ffreyer ffreyer linked a pull request Sep 14, 2024 that will close this issue
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants