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

Avoid clipping on 3D zoom to be able to inspect meshes up close #3792

Open
3 tasks done
Kevin-Mattheus-Moerman opened this issue Apr 17, 2024 · 7 comments · May be fixed by #3793
Open
3 tasks done

Avoid clipping on 3D zoom to be able to inspect meshes up close #3792

Kevin-Mattheus-Moerman opened this issue Apr 17, 2024 · 7 comments · May be fixed by #3793

Comments

@Kevin-Mattheus-Moerman
Copy link

Kevin-Mattheus-Moerman commented Apr 17, 2024

  • 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? -> Ubuntu 22.04, NVidia

I am hoping to create a visualisation for meshes whereby I can zoom in as much as I want (and for any orientation) without clipping occurring. So far I've been unsuccessful with setting far and near. The below gif shows the issue as well. Any help would be appreciated.

Here is an example code:

using GeometryBasics
using GLMakie

## BUILD CUBE 

# Create vertices       
s = 1/sqrt(3.0)

V = Vector{GeometryBasics.Point{3, Float64}}(undef,8)
V[1 ] = GeometryBasics.Point{3, Float64}( -s, -s, -s)
V[2 ] = GeometryBasics.Point{3, Float64}( -s,  s, -s)
V[3 ] = GeometryBasics.Point{3, Float64}(  s,  s, -s)
V[4 ] = GeometryBasics.Point{3, Float64}(  s, -s, -s)
V[5 ] = GeometryBasics.Point{3, Float64}( -s, -s,  s)
V[6 ] = GeometryBasics.Point{3, Float64}( -s,  s,  s)
V[7 ] = GeometryBasics.Point{3, Float64}(  s,  s,  s)
V[8 ] = GeometryBasics.Point{3, Float64}(  s, -s,  s)
    
# Create faces
F = Vector{QuadFace{Int64}}(undef,6)
F[1 ] = QuadFace{Int64}(1,2,3,4)
F[2 ] = QuadFace{Int64}(8,7,6,5)
F[3 ] = QuadFace{Int64}(5,6,2,1)
F[4 ] = QuadFace{Int64}(6,7,3,2)    
F[5 ] = QuadFace{Int64}(7,8,4,3)    
F[6 ] = QuadFace{Int64}(8,5,1,4)    

M = GeometryBasics.Mesh(V,F)

## VISUALIZATION

fig = Figure(size=(800,800))

# ax1 = Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Cube mesh")

ax1 = LScene(fig[1,1],show_axis=true, scenekw = (backgroundcolor=:white,)) 
cc = Makie.Camera3D(ax1.scene, projectiontype = Makie.Orthographic, clipping_mode=:bbox_relative)#,near=0, far=10000, zoom_shift_lookat = true, cad =false)
translate_cam!(ax1.scene, cameracontrols(ax1.scene), Vec3f(0, 0, 1000))

hp = poly!(ax1,M, strokewidth=3,shading=FastShading,strokecolor=:red, color=:white, transparency=true, overdraw=false)

fig

Peek 2024-04-17 16-33

@ffreyer
Copy link
Collaborator

ffreyer commented Apr 17, 2024

Calling fig / display(fig) resets the camera position, so it undoes translate_cam!(). If you call translate_cam!(ax1.scene, Vec3f(0, 0, 1)) after opening a window you'll end up with a lookat around the nearest corner of the cube. If you zoom straight in you won't clip into it anymore. If you rotate you'll be rotating around that corner and be able to clip inside at other positions.

@asinghvi17
Copy link
Member

display(fig; update = false) should solve that.

@ffreyer ffreyer linked a pull request Apr 17, 2024 that will close this issue
5 tasks
@Kevin-Mattheus-Moerman
Copy link
Author

Kevin-Mattheus-Moerman commented Apr 17, 2024

@ffreyer thanks. However, what you propose is not really a practical solution as it is really awkward to rotate around these off centered predetermined points. In addition clipping still occurs for the other areas of the model. I need to be able to rotate arbitrarily and zoom in on any area.

@asinghvi17 that option didn't work unfortunately, it messes up other things, e.g. the axis appears to be not well placed:

image

@Kevin-Mattheus-Moerman
Copy link
Author

Kevin-Mattheus-Moerman commented Apr 17, 2024

Example video (from the use of MATLAB) showing how I would like to be able to zoom in on model regions, e.g. here to inspect if the mesh smoothing algorithm did a good job. I sometimes have to zoom in on a single element on the mesh or check if two points are coincident.

Peek.2021-10-12.15-10.mp4

Inspecting local normal directions (again in MATLAB but this is what I'd like to do with Makie in Julia):

Peek.2021-12-08.21-43.mp4

@Kevin-Mattheus-Moerman
Copy link
Author

@ffreyer any updates on this? Would you be able to describe why zooming for Axis3 is inherently not possible? I'd also be happy to organise a chat e.g. to see if I can somehow help with this. Thanks!

@ffreyer
Copy link
Collaborator

ffreyer commented Apr 22, 2024

#3793 adds a setting that avoids translating the camera for zooming, i.e. avoids clipping.

The problem with zooming Axis3 is that we want data that's outside the limits of the Axis to be clipped. For the 2d Axis that very simple because we can just limit the drawing area. For 3D this needs to happen in 3d via clipping planes. OpenGL and WebGL support those, but GLMakie and WGLMakie do not. I experimented with this for GLMakie in #2783, but I didn'/don'tt know how to go about it in WGLMakie.

@Kevin-Mattheus-Moerman
Copy link
Author

@ffreyer thanks for the update. Would it not be possible to avoid clipping again and to only support zoom like this:
zoom

I.e. bring everything closer including the axis, and leave the limits as is.

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.

4 participants