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
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container 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
Yanjiang He
glow-samples
Commits
57fde9d1
Commit
57fde9d1
authored
5 years ago
by
Philip Trettner
Browse files
Options
Downloads
Patches
Plain Diff
working on samples
parent
2ed32341
Branches
Branches containing commit
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
+82
-18
82 additions, 18 deletions
samples/basic/viewer/main.cc
with
82 additions
and
18 deletions
samples/basic/viewer/main.cc
+
82
−
18
View file @
57fde9d1
...
...
@@ -61,7 +61,84 @@ void basic_concepts(pm::vertex_attribute<tg::pos3> const& pos)
void
advanced_objects
(
pm
::
vertex_attribute
<
tg
::
pos3
>
const
&
pos
)
{
// lines, points, polygons
pm
::
Mesh
const
&
m
=
pos
.
mesh
();
// by default, gv::view(obj, ...) chooses gv::make_renderable(obj) to create a renderable
// this can be overridden by gv::polygons, gv::lines, gv::points
// by default, polymesh Meshes are rendered:
// - with gv::polygons if mesh.faces().size() > 0
// - otherwise with gv::lines if mesh.edges().size() > 0
// - otherwise with gv::points
// this can be overridden:
{
auto
g
=
gv
::
grid
();
gv
::
view
(
gv
::
polygons
(
pos
),
"gv::polygons(pos)"
);
gv
::
view
(
gv
::
lines
(
pos
),
"gv::lines(pos)"
);
gv
::
view
(
gv
::
points
(
pos
),
"gv::points(pos)"
);
}
// rendering can be customized by a builder-pattern:
{
// gv::polygons assumes planar faces and creates a triangle fan per face
// normals used for shading can be customized
auto
g
=
gv
::
grid
();
gv
::
view
(
gv
::
polygons
(
pos
).
face_normals
(),
"face normals (default)"
);
gv
::
view
(
gv
::
polygons
(
pos
).
smooth_normals
(),
"smooth normals"
);
pm
::
vertex_attribute
<
tg
::
vec3
>
vnormals
=
pm
::
vertex_normals_by_area
(
pos
);
gv
::
view
(
gv
::
polygons
(
pos
).
normals
(
vnormals
),
"custom normals"
);
// see PolygonBuilder.hh for more information
}
{
// gv::lines performs line rendering
// by default, lines are rendered as 3D capsule with a fixed screen-space size
// customization includes
// - billboard mode (camera-facing or oriented by normals)
// - cap mode (round, square, none)
// - line width (screen space or world space)
auto
g
=
gv
::
grid
();
pm
::
vertex_attribute
<
tg
::
vec3
>
vnormals
=
pm
::
vertex_normals_by_area
(
pos
);
pm
::
vertex_attribute
<
float
>
line_widths
=
pos
.
map
([](
tg
::
pos3
p
)
{
return
0.01
f
*
tg
::
abs
(
p
.
x
);
});
gv
::
view
(
gv
::
lines
(
pos
).
camera_facing
(),
"camera facing"
);
gv
::
view
(
gv
::
lines
(
pos
).
line_width_world
(
0.01
f
).
normals
(
vnormals
),
"oriented billboard lines"
);
gv
::
view
(
gv
::
lines
(
pos
).
line_width_world
(
0.01
f
).
normals
(
vnormals
).
round_caps
(),
"round caps"
);
gv
::
view
(
gv
::
lines
(
pos
).
line_width_world
(
0.01
f
).
normals
(
vnormals
).
square_caps
(),
"square caps"
);
gv
::
view
(
gv
::
lines
(
pos
).
line_width_world
(
0.01
f
).
normals
(
vnormals
).
no_caps
(),
"no caps"
);
gv
::
view
(
gv
::
lines
(
pos
).
line_width_px
(
30
),
"30px line width"
);
gv
::
view
(
gv
::
lines
(
pos
).
line_width_world
(
0.01
f
),
"1cm line width"
);
gv
::
view
(
gv
::
lines
(
pos
).
line_width_world
(
line_widths
),
"per-line width"
);
// see LineBuilder.hh for more information
}
{
auto
g
=
gv
::
grid
();
pm
::
vertex_attribute
<
tg
::
vec3
>
vnormals
=
pm
::
vertex_normals_by_area
(
pos
);
// compute per-vertex average edge length as point size
pm
::
edge_attribute
<
float
>
edge_lengths
=
m
.
edges
().
map
([
&
](
pm
::
edge_handle
e
)
{
return
edge_length
(
e
,
pos
);
});
pm
::
vertex_attribute
<
float
>
ptsize
=
m
.
vertices
().
map
([
&
](
pm
::
vertex_handle
v
)
{
return
v
.
edges
().
avg
(
edge_lengths
);
});
// Square, oriented point cloud with adaptive point size
gv
::
view
(
gv
::
points
(
pos
).
point_size_world
(
ptsize
).
normals
(
vnormals
).
square
(),
"normal oriented squares"
);
gv
::
view
(
gv
::
points
(
pos
).
spheres
().
point_size_world
(
0.03
f
),
"3D sphere cloud"
);
gv
::
view
(
gv
::
points
(
pos
).
camera_facing
().
unlit
(),
tg
::
color3
::
red
,
"no shading"
);
// see PointBuilder.hh for more information
}
// gv::polygons, gv::lines, gv::points can also be used to customize other inputs
// see typed_geometry_objects() example
// TODO: text
// TODO: images
...
...
@@ -75,7 +152,7 @@ void advanced_visualization(pm::vertex_attribute<tg::pos3> const& pos)
// TODO: complex material (e.g. PBR)
}
void
typed_geometry_objects
(
pm
::
vertex_attribute
<
tg
::
pos3
>
const
&
pos
)
void
typed_geometry_objects
()
{
auto
g
=
gv
::
grid
();
...
...
@@ -303,6 +380,8 @@ void headless_screenshot(pm::vertex_attribute<tg::pos3> const& pos)
void
special_use_cases
(
pm
::
vertex_attribute
<
tg
::
pos3
>
const
&
pos
)
{
// TODO: decoupled camera
gv
::
view
(
pos
,
gv
::
maybe_empty
,
"allows empty renderable"
);
gv
::
view
(
pos
,
gv
::
infinite_accumulation
,
"progressive rendering is not stopped early"
);
...
...
@@ -386,7 +465,7 @@ int main()
{
advanced_objects
(
pos
);
typed_geometry_objects
(
pos
);
typed_geometry_objects
();
advanced_visualization
(
pos
);
...
...
@@ -410,9 +489,6 @@ int main()
// Grid of examples
{
// smooth normals
gv
::
view
(
gv
::
polygons
(
pos
).
smooth_normals
(),
"smoothed normals"
);
// Configuration nesting
{
// Colored faces
...
...
@@ -436,18 +512,6 @@ int main()
// Textured mesh (async texture)
gv
::
view
(
pos
,
gv
::
textured
(
uv
,
atex
),
"textured (async)"
);
// Simple point cloud
gv
::
view
(
gv
::
points
(
pos
),
"point cloud"
);
// Square, oriented point cloud with adaptive point size
gv
::
view
(
gv
::
points
(
pos
).
point_size_world
(
ptsize
).
normals
(
vnormals
).
square
(),
"normal oriented squares"
);
// Points rendered as 3D spheres
gv
::
view
(
gv
::
points
(
pos
).
spheres
().
point_size_world
(
0.03
f
),
"sphere cloud"
);
// Simple line soup
gv
::
view
(
gv
::
lines
(
pos
),
"edges"
);
// transparencies
gv
::
view
(
pos
,
tg
::
color4
(
0
,
0.4
f
,
0.3
f
,
0.2
f
),
"transparency with fresnel"
);
gv
::
view
(
pos
,
tg
::
color4
(
0
,
0.4
f
,
0.3
f
,
0.2
f
),
gv
::
no_fresnel
,
"transparency without fresnel"
);
...
...
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