Skip to content

Commit

Permalink
Port PrusaSlicer's Measure & Cut gizmos (#2603)
Browse files Browse the repository at this point in the history
Build on top of #2520 and replaces it.

This PR includes:
- Rewrite the opengl rendering code, which now renders (almost)
everything using shaders instead of legacy opengl function calls
- Rewriting the gizmo mouse handling code that moves the mouse handling
coding into each gizmo themselves
- Rewriting the mouse picking code, now it uses ray casting to figure
out what's under the mouse cursor
- Porting of the PrusaSlicer's measure tool
- Replacing existing cuting tool with the better one PrusaSlicer has
- Updating of other gizmos using PrusaSlicer's latest code base

There was a plan to also port PrusaSlicer's emboss & svg tools, but this
PR is already very big and the changes needed for emboss will be even
bigger and might take forever to finish. So I decided to separate them
so we can get something out and start rolling out testing builds for
people to play with as soon as possible.

This was developed mainly using Windows, be prepared it could have
graphic issue under Linux & macOS.

Huge credit to Prusa for their amazing job!


![image](https://github.com/SoftFever/OrcaSlicer/assets/1537155/b7ec85d7-1013-4d8e-9914-c2b4d8cb5360)

![image](https://github.com/SoftFever/OrcaSlicer/assets/1537155/1e97d744-99c0-402d-9b23-456d95e07bba)

![image](https://github.com/SoftFever/OrcaSlicer/assets/1537155/f0a5dbea-677a-43f5-918b-c6817ff659c8)


Fixes #717
Fixes #1150
Fixes #1590
  • Loading branch information
SoftFever authored Nov 19, 2023
2 parents 0e6197f + df48b05 commit e9f519d
Show file tree
Hide file tree
Showing 208 changed files with 21,650 additions and 9,664 deletions.
37 changes: 37 additions & 0 deletions resources/images/copy_menu.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions resources/images/copy_menu_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 93 additions & 0 deletions resources/images/toolbar_measure.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 93 additions & 0 deletions resources/images/toolbar_measure_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions resources/shaders/110/background.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#version 110

uniform vec4 top_color;
uniform vec4 bottom_color;

varying vec2 tex_coord;

void main()
{
gl_FragColor = mix(bottom_color, top_color, tex_coord.y);
}
12 changes: 12 additions & 0 deletions resources/shaders/110/background.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 110

attribute vec3 v_position;
attribute vec2 v_tex_coord;

varying vec2 tex_coord;

void main()
{
tex_coord = v_tex_coord;
gl_Position = vec4(v_position, 1.0);
}
File renamed without changes.
11 changes: 11 additions & 0 deletions resources/shaders/110/flat.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#version 110

uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;

attribute vec3 v_position;

void main()
{
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
}
15 changes: 15 additions & 0 deletions resources/shaders/110/flat_clip.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 110

const vec3 ZERO = vec3(0.0, 0.0, 0.0);

uniform vec4 uniform_color;

varying vec3 clipping_planes_dots;

void main()
{
if (any(lessThan(clipping_planes_dots, ZERO)))
discard;

gl_FragColor = uniform_color;
}
23 changes: 23 additions & 0 deletions resources/shaders/110/flat_clip.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#version 110

uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
uniform mat4 volume_world_matrix;

// Clipping plane, x = min z, y = max z. Used by the FFF and SLA previews to clip with a top / bottom plane.
uniform vec2 z_range;
// Clipping plane - general orientation. Used by the SLA gizmo.
uniform vec4 clipping_plane;

attribute vec3 v_position;

varying vec3 clipping_planes_dots;

void main()
{
// Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded.
vec4 world_pos = volume_world_matrix * vec4(v_position, 1.0);
clipping_planes_dots = vec3(dot(world_pos, clipping_plane), world_pos.z - z_range.x, z_range.y - world_pos.z);

gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
}
10 changes: 10 additions & 0 deletions resources/shaders/110/flat_texture.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 110

uniform sampler2D uniform_texture;

varying vec2 tex_coord;

void main()
{
gl_FragColor = texture2D(uniform_texture, tex_coord);
}
15 changes: 15 additions & 0 deletions resources/shaders/110/flat_texture.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 110

uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;

attribute vec3 v_position;
attribute vec2 v_tex_coord;

varying vec2 tex_coord;

void main()
{
tex_coord = v_tex_coord;
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
}
Loading

0 comments on commit e9f519d

Please sign in to comment.