Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
glow-samples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nils Speetzen
glow-samples
Commits
845f1c42
Commit
845f1c42
authored
3 years ago
by
Aaron Kreuzberg
Browse files
Options
Downloads
Patches
Plain Diff
clang-format
parent
7e5aba81
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
samples/basic/viewer/main.cc
+271
-328
271 additions, 328 deletions
samples/basic/viewer/main.cc
with
271 additions
and
328 deletions
samples/basic/viewer/main.cc
+
271
−
328
View file @
845f1c42
...
...
@@ -199,9 +199,7 @@ void imguizmo(pm::vertex_attribute<tg::pos3> const& pos)
auto
transform
=
tg
::
mat4
::
identity
;
// an interactive view is required
gv
::
interactive
(
[
&
](
float
)
{
gv
::
interactive
([
&
](
float
)
{
// you can define keybindings to select an operation
if
(
ImGui
::
IsKeyPressed
(
GLFW_KEY_T
))
currentGizmoOperation
=
ImGuizmo
::
TRANSLATE
;
...
...
@@ -535,9 +533,7 @@ void advanced_configs(pm::vertex_attribute<tg::pos3> const& pos)
}
// custom configure function
gv
::
view
(
pos
,
"config via lambda"
,
[](
gv
::
SceneConfig
&
cfg
)
{
gv
::
view
(
pos
,
"config via lambda"
,
[](
gv
::
SceneConfig
&
cfg
)
{
cfg
.
enableShadows
=
false
;
cfg
.
bgColorInner
=
{
1
,
0
,
1
};
});
...
...
@@ -736,9 +732,7 @@ void interactive_viewer(pm::vertex_attribute<tg::pos3> const& pos)
// the scene config and all renderables are hashed and the viewer accumulation is cleared when the hash changes
// a simple interactive viewer with some interactive-related controls
gv
::
interactive
(
[
&
](
auto
)
{
gv
::
interactive
([
&
](
auto
)
{
if
(
ImGui
::
Button
(
"make screenshot"
))
gv
::
make_screenshot
(
"screenshot.png"
,
1920
,
1080
);
...
...
@@ -752,23 +746,18 @@ void interactive_viewer(pm::vertex_attribute<tg::pos3> const& pos)
// NOTE: capture by value if the interactive viewer is not the top-most viewer
{
auto
const
r
=
gv
::
make_renderable
(
pos
);
gv
::
interactive
(
[
r
](
auto
dt
)
{
gv
::
interactive
([
r
](
auto
dt
)
{
static
auto
time
=
0.
f
;
time
+=
dt
;
gv
::
view
(
r
,
tg
::
translation
(
tg
::
vec3
(
tg
::
sin
(
tg
::
radians
(
time
*
.5
f
))
*
.5
f
,
0.
f
,
0.
f
)),
"Caching renderables in interactive views increases performance."
);
gv
::
view
(
r
,
tg
::
translation
(
tg
::
vec3
(
tg
::
sin
(
tg
::
radians
(
time
*
.5
f
))
*
.5
f
,
0.
f
,
0.
f
)),
"Caching renderables in interactive views increases performance."
);
});
}
// using imgui in an interactive view
{
auto
const
r
=
gv
::
make_renderable
(
pos
);
gv
::
interactive
(
[
r
](
auto
)
{
gv
::
interactive
([
r
](
auto
)
{
static
float
configurable
=
0.
f
;
ImGui
::
SliderFloat
(
"Height"
,
&
configurable
,
-
3.
f
,
3.
f
);
...
...
@@ -787,8 +776,7 @@ void interactive_viewer(pm::vertex_attribute<tg::pos3> const& pos)
auto
uv
=
m
.
vertices
().
make_attribute
<
tg
::
pos2
>
();
pm
::
objects
::
add_quad
(
m
,
[
&
](
pm
::
vertex_handle
v
,
float
x
,
float
y
)
{
[
&
](
pm
::
vertex_handle
v
,
float
x
,
float
y
)
{
auto
[
cx
,
sx
]
=
tg
::
sin_cos
(
tg
::
pi
<
float
>
*
2
*
x
);
auto
[
cy
,
sy
]
=
tg
::
sin_cos
(
tg
::
pi
<
float
>
*
2
*
y
);
...
...
@@ -811,9 +799,7 @@ void interactive_viewer(pm::vertex_attribute<tg::pos3> const& pos)
auto
a
=
0.
f
;
auto
animate
=
false
;
gv
::
interactive
(
[
&
](
auto
dt
)
{
gv
::
interactive
([
&
](
auto
dt
)
{
ImGui
::
Begin
(
"Torus"
);
ImGui
::
SliderFloat
(
"angle"
,
&
a
,
0.
f
,
360.
f
);
ImGui
::
Checkbox
(
"Animate"
,
&
animate
);
...
...
@@ -937,10 +923,7 @@ void picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_attribut
auto
g
=
gv
::
grid
();
// Only on_left_click callback defined
gv
::
view
(
pos
,
col
,
gv
::
pick
().
onLeftClick
(
[
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
->
gv
::
picking_result
{
gv
::
view
(
pos
,
col
,
gv
::
pick
().
onLeftClick
([
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
->
gv
::
picking_result
{
std
::
cout
<<
"Something has been picked! ON_LEFT_CLICK"
<<
"ID: "
<<
(
int
)
face_id
<<
std
::
endl
;
std
::
cout
<<
"World_Position "
<<
world_pos
<<
std
::
endl
;
...
...
@@ -952,10 +935,7 @@ void picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_attribut
"picking MeshRenderable - callback on left click"
);
// Only on_left_click callback defined - LineRenderable - uncolored
gv
::
view
(
gv
::
lines
(
pos
),
gv
::
pick
().
onLeftClick
(
[
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
gv
::
view
(
gv
::
lines
(
pos
),
gv
::
pick
().
onLeftClick
([
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
std
::
cout
<<
"Something has been picked! ON_LEFT_CLICK"
<<
"ID: "
<<
int
(
face_id
)
<<
std
::
endl
;
std
::
cout
<<
"World_Position"
<<
world_pos
<<
std
::
endl
;
...
...
@@ -965,10 +945,7 @@ void picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_attribut
{
// Only on_left_click callback defined - PointRenderable - uncolored
gv
::
view
(
gv
::
points
(
pos
),
gv
::
pick
().
onLeftClick
(
[
&
](
pm
::
vertex_index
vertex_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
gv
::
view
(
gv
::
points
(
pos
),
gv
::
pick
().
onLeftClick
([
&
](
pm
::
vertex_index
vertex_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
std
::
cout
<<
"Something has been picked! ON_LEFT_CLICK"
<<
"ID: "
<<
int
(
vertex_id
)
<<
std
::
endl
;
std
::
cout
<<
"World_Position"
<<
world_pos
<<
std
::
endl
;
...
...
@@ -981,9 +958,7 @@ void picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_attribut
{
// Only on_left_click callback defined - PointRenderable - uncolored - square billboards - NOT WORKING APPROPRIATELY
gv
::
view
(
gv
::
points
(
pos
).
point_size_world
(
0.03
f
).
camera_facing
().
square
(),
gv
::
pick
().
onLeftClick
(
[
&
](
pm
::
vertex_index
vertex_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
gv
::
pick
().
onLeftClick
([
&
](
pm
::
vertex_index
vertex_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
std
::
cout
<<
"Something has been picked! ON_LEFT_CLICK"
<<
"ID: "
<<
int
(
vertex_id
)
<<
std
::
endl
;
std
::
cout
<<
"World_Position"
<<
world_pos
<<
std
::
endl
;
...
...
@@ -998,10 +973,7 @@ void picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_attribut
auto
g
=
gv
::
grid
();
// Only on_right_click callback defined
gv
::
view
(
pos
,
col
,
gv
::
pick
().
onRightClick
(
[
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
gv
::
view
(
pos
,
col
,
gv
::
pick
().
onRightClick
([
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
std
::
cout
<<
"Something has been picked! ON_RIGHT_CLICK"
<<
"ID: "
<<
int
(
face_id
)
<<
std
::
endl
;
return
;
...
...
@@ -1009,10 +981,7 @@ void picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_attribut
"picking MeshRenderable - callback on right click"
);
// Only on_hover callback defined
gv
::
view
(
pos
,
col
,
gv
::
pick
().
onHover
(
[
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
gv
::
view
(
pos
,
col
,
gv
::
pick
().
onHover
([
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
std
::
cout
<<
"Something has been picked! ON_HOVER"
<<
"ID: "
<<
(
int
)
face_id
<<
std
::
endl
;
return
;
...
...
@@ -1033,13 +1002,8 @@ void picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_attribut
pm
::
vertex_attribute
<
tg
::
pos3
>
pos2
(
m2
);
pos2
.
copy_from
(
pos
);
gv
::
interactive
(
[
&
](
auto
)
{
gv
::
view
(
pos2
,
col
,
gv
::
pick
().
onLeftClick
(
[
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
gv
::
interactive
([
&
](
auto
)
{
gv
::
view
(
pos2
,
col
,
gv
::
pick
().
onLeftClick
([
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
std
::
cout
<<
"Something has been picked! ON_LEFT_CLICK"
<<
"ID: "
<<
int
(
face_id
)
<<
std
::
endl
;
std
::
cout
<<
"World_Position"
<<
world_pos
<<
std
::
endl
;
...
...
@@ -1087,13 +1051,9 @@ void picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_attribut
pm
::
vertex_attribute
<
tg
::
pos3
>
pos2
(
m2
);
pos2
.
copy_from
(
pos
);
gv
::
interactive
(
[
&
](
auto
)
{
gv
::
interactive
([
&
](
auto
)
{
gv
::
view
(
gv
::
points
(
pos2
),
gv
::
pick
().
onLeftClick
(
[
&
vertex_index_i
,
&
world_pos_i
,
&
normal_i
](
pm
::
vertex_index
vertex_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
gv
::
pick
().
onLeftClick
([
&
vertex_index_i
,
&
world_pos_i
,
&
normal_i
](
pm
::
vertex_index
vertex_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
std
::
cout
<<
"Something has been picked! ON_LEFT_CLICK"
<<
"ID: "
<<
int
(
vertex_id
)
<<
std
::
endl
;
std
::
cout
<<
"World_Position"
<<
world_pos
<<
std
::
endl
;
...
...
@@ -1134,23 +1094,17 @@ void picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_attribut
// On_hover, on_right_click, and on_left_click callbacks defined simultaneously
gv
::
view
(
pos
,
col
,
gv
::
pick
()
.
onLeftClick
(
[
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
.
onLeftClick
([
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
std
::
cout
<<
"Something has been picked! ON_LEFT_CLICK"
<<
"ID: "
<<
int
(
face_id
)
<<
std
::
endl
;
return
;
})
.
onRightClick
(
[
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
.
onRightClick
([
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
std
::
cout
<<
"Something has been picked! ON_RIGHT_CLICK"
<<
"ID: "
<<
int
(
face_id
)
<<
std
::
endl
;
return
;
})
.
onHover
(
[
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
.
onHover
([
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
{
std
::
cout
<<
"Something has been picked! ON_HOVER"
<<
"ID: "
<<
int
(
face_id
)
<<
std
::
endl
;
return
;
...
...
@@ -1167,10 +1121,7 @@ void picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_attribut
fa
[
f
]
=
1000
+
i
;
i
++
;
}
gv
::
view
(
pos
,
col
,
gv
::
pick
(
fa
).
onLeftClick
(
[
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
->
gv
::
picking_result
{
gv
::
view
(
pos
,
col
,
gv
::
pick
(
fa
).
onLeftClick
([
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
->
gv
::
picking_result
{
std
::
cout
<<
"Something has been picked! ON_LEFT_CLICK"
<<
"ID: "
<<
(
int
)
face_id
<<
std
::
endl
;
std
::
cout
<<
"World_Position"
<<
world_pos
<<
std
::
endl
;
...
...
@@ -1186,9 +1137,7 @@ void picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_attribut
auto
v
=
gv
::
view
(
pos
,
"pciking multiple renderables: different callbacks defined"
);
// Check multiple Renderables.
gv
::
view
(
pos
,
gv
::
pick
().
onHover
(
[
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
->
gv
::
picking_result
{
gv
::
view
(
pos
,
gv
::
pick
().
onHover
([
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
->
gv
::
picking_result
{
std
::
cout
<<
"Something has been picked! PICKER 1 "
<<
"ID: "
<<
(
int
)
face_id
<<
std
::
endl
;
std
::
cout
<<
"World_Position"
<<
world_pos
<<
std
::
endl
;
...
...
@@ -1209,9 +1158,7 @@ void picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_attribut
pos2
[
p
]
=
pos2
[
p
]
+
tg
::
vec3
(
2
,
2
,
2
);
}
gv
::
view
(
pos2
,
gv
::
pick
().
onLeftClick
(
[
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
->
gv
::
picking_result
{
gv
::
view
(
pos2
,
gv
::
pick
().
onLeftClick
([
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
->
gv
::
picking_result
{
std
::
cout
<<
"Something has been picked! PICKER 2 "
<<
"ID: "
<<
(
int
)
face_id
<<
std
::
endl
;
std
::
cout
<<
"World_Position"
<<
world_pos
<<
std
::
endl
;
...
...
@@ -1330,9 +1277,7 @@ void special_use_cases(pm::vertex_attribute<tg::pos3> const& pos)
{
auto
const
r
=
gv
::
make_renderable
(
pos
);
gv
::
interactive
(
[
r
](
auto
dt
)
{
gv
::
interactive
([
r
](
auto
dt
)
{
static
auto
time
=
0.
f
;
time
+=
dt
;
...
...
@@ -1340,9 +1285,7 @@ void special_use_cases(pm::vertex_attribute<tg::pos3> const& pos)
gv
::
view_cleared
(
r
,
tg
::
translation
(
tg
::
vec3
(
tg
::
sin
(
tg
::
radians
(
time
*
.5
f
))
*
.5
f
,
0.
f
,
0.
f
)));
});
gv
::
interactive
(
[
r
](
auto
)
{
gv
::
interactive
([
r
](
auto
)
{
static
float
configurable
=
0.
f
;
auto
changed
=
false
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment