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
Model registry
Operate
Environments
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
Glow
glow-samples
Commits
63df40b5
Commit
63df40b5
authored
3 years ago
by
Aaron Kreuzberg
Browse files
Options
Downloads
Patches
Plain Diff
grid samples. grid bug not yet fixed.
parent
4659e490
No related branches found
No related tags found
1 merge request
!16
picking samples
Pipeline
#19367
passed
3 years ago
Stage: Build
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
extern/glow-extras
+1
-1
1 addition, 1 deletion
extern/glow-extras
samples/basic/viewer/main.cc
+304
-223
304 additions, 223 deletions
samples/basic/viewer/main.cc
with
305 additions
and
224 deletions
glow-extras
@
1978c6b5
Subproject commit
6d4ea26072854d9ca74d9249b6654823c965e01
3
Subproject commit
1978c6b5209d2de5fbfbb250f74385817149b19
3
This diff is collapsed.
Click to expand it.
samples/basic/viewer/main.cc
+
304
−
223
View file @
63df40b5
...
...
@@ -29,34 +29,122 @@ std::string const dataPath = glow::util::pathOf(__FILE__) + "/../../../data/";
void
simple_picking
(
pm
::
Mesh
&
m
,
pm
::
vertex_attribute
<
tg
::
pos3
>&
pos
,
pm
::
face_attribute
<
tg
::
color3
>
const
&
col
)
{
{
// In this case a Picker is defined for the Renderable (Picking Texture filled) but no callback will be executed.
gv
::
view
(
pos
,
col
,
gv
::
pick
(),
"Picker defined without callback"
);
}
//
{
//
// In this case a Picker is defined for the Renderable (Picking Texture filled) but no callback will be executed.
//
gv::view(pos, col, gv::pick(), "Picker defined without callback");
//
}
{
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
)
->
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
;
std
::
cout
<<
"Normal "
<<
normal
<<
std
::
endl
;
picking_result
res
;
gv
::
picking_result
res
;
res
.
mPickingColor
=
tg
::
color3
::
cyan
;
return
res
;
}),
"simple picking: callback on left click"
);
}
"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
;
std
::
cout
<<
"Normal"
<<
normal
<<
std
::
endl
;
}),
"picking LineRenderable - callback on left click"
);
{
// 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
)
{
std
::
cout
<<
"Something has been picked! ON_LEFT_CLICK"
<<
"ID: "
<<
int
(
vertex_id
)
<<
std
::
endl
;
std
::
cout
<<
"World_Position"
<<
world_pos
<<
std
::
endl
;
std
::
cout
<<
"Normal"
<<
normal
<<
std
::
endl
;
return
;
}),
"picking PointRenderable - callback on left click - spheres"
);
}
{
// 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
)
{
std
::
cout
<<
"Something has been picked! ON_LEFT_CLICK"
<<
"ID: "
<<
int
(
vertex_id
)
<<
std
::
endl
;
std
::
cout
<<
"World_Position"
<<
world_pos
<<
std
::
endl
;
std
::
cout
<<
"Normal"
<<
normal
<<
std
::
endl
;
return
;
}),
"picking PointRenderables - callback on left click - billboards"
);
}
}
{
auto
r1
=
gv
::
make_and_configure_renderable
(
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
;
}),
"picking MeshRenderable - callback on right click"
);
auto
r2
=
gv
::
make_and_configure_renderable
(
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
;
}),
"picking MeshRenderable - callback on hover"
);
gv
::
interactive
(
[
&
](
float
)
{
auto
g
=
gv
::
grid
();
gv
::
view
(
r1
);
gv
::
view
(
r2
);
});
}
{
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
)
{
std
::
cout
<<
"Something has been picked! ON_RIGHT_CLICK"
<<
"ID: "
<<
int
(
face_id
)
<<
std
::
endl
;
return
;
}),
"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
)
{
std
::
cout
<<
"Something has been picked! ON_HOVER"
<<
"ID: "
<<
(
int
)
face_id
<<
std
::
endl
;
return
;
}),
"picking MeshRenderable - callback on hover"
);
}
{
...
...
@@ -72,8 +160,13 @@ void simple_picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_a
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
;
...
...
@@ -125,9 +218,13 @@ void simple_picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_a
// auto m2 = copy._Myfirst._Val.get();
// auto pos2 = copy._Get_rest()._Myfirst._Val;
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
;
...
...
@@ -164,66 +261,27 @@ void simple_picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_a
});
}
{
// 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
)
{
std
::
cout
<<
"Something has been picked! ON_LEFT_CLICK"
<<
"ID: "
<<
int
(
vertex_id
)
<<
std
::
endl
;
std
::
cout
<<
"World_Position"
<<
world_pos
<<
std
::
endl
;
std
::
cout
<<
"Normal"
<<
normal
<<
std
::
endl
;
return
;
}),
"picking PointRenderable - callback on left click - spheres"
);
}
{
// 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
)
{
std
::
cout
<<
"Something has been picked! ON_LEFT_CLICK"
<<
"ID: "
<<
int
(
vertex_id
)
<<
std
::
endl
;
std
::
cout
<<
"World_Position"
<<
world_pos
<<
std
::
endl
;
std
::
cout
<<
"Normal"
<<
normal
<<
std
::
endl
;
return
;
}),
"picking PointRenderables - callback on left click - billboards"
);
}
{
// 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
)
{
std
::
cout
<<
"Something has been picked! ON_RIGHT_CLICK"
<<
"ID: "
<<
int
(
face_id
)
<<
std
::
endl
;
return
;
}),
"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
)
{
std
::
cout
<<
"Something has been picked! ON_HOVER"
<<
"ID: "
<<
(
int
)
face_id
<<
std
::
endl
;
return
;
}),
"picking MeshRenderable - callback on hover"
);
}
{
// 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
;
...
...
@@ -242,12 +300,15 @@ void simple_picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_a
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
)
->
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
;
std
::
cout
<<
"Normal"
<<
normal
<<
std
::
endl
;
picking_result
res
;
gv
::
picking_result
res
;
res
.
mPickingColor
=
tg
::
color3
::
cyan
;
return
res
;
}),
...
...
@@ -258,12 +319,14 @@ void simple_picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_a
auto
v
=
gv
::
view
(
pos
,
"Multiple renderables"
);
// Check multiple Renderables.
gv
::
view
(
pos
,
gv
::
pick
().
onLeftClick
([
&
](
pm
::
face_index
face_id
,
tg
::
pos3
world_pos
,
tg
::
vec3
normal
)
->
picking_result
{
gv
::
view
(
pos
,
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 1 "
<<
"ID: "
<<
(
int
)
face_id
<<
std
::
endl
;
std
::
cout
<<
"World_Position"
<<
world_pos
<<
std
::
endl
;
std
::
cout
<<
"Normal"
<<
normal
<<
std
::
endl
;
picking_result
res
;
gv
::
picking_result
res
;
res
.
mPickingColor
=
tg
::
color3
::
cyan
;
return
res
;
}));
...
...
@@ -279,12 +342,14 @@ void simple_picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_a
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
)
->
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
;
std
::
cout
<<
"Normal"
<<
normal
<<
std
::
endl
;
picking_result
res
;
gv
::
picking_result
res
;
res
.
mPickingColor
=
tg
::
color3
::
cyan
;
return
res
;
}));
...
...
@@ -684,7 +749,9 @@ 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
};
});
...
...
@@ -883,7 +950,9 @@ 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
);
...
...
@@ -897,18 +966,23 @@ 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
);
...
...
@@ -927,7 +1001,8 @@ 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
);
...
...
@@ -950,7 +1025,9 @@ 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
);
...
...
@@ -1171,7 +1248,9 @@ 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
;
...
...
@@ -1179,7 +1258,9 @@ 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