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
01379709
There was an error fetching the commit references. Please try again later.
Commit
01379709
authored
5 years ago
by
Philip Trettner
Browse files
Options
Downloads
Patches
Plain Diff
finished sample rework
parent
57fde9d1
No related branches found
No related tags found
No related merge requests found
Pipeline
#13913
failed
5 years ago
Stage: Build
Changes
3
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
extern/glow-extras
+1
-1
1 addition, 1 deletion
extern/glow-extras
extern/polymesh
+1
-1
1 addition, 1 deletion
extern/polymesh
samples/basic/viewer/main.cc
+75
-51
75 additions, 51 deletions
samples/basic/viewer/main.cc
with
77 additions
and
53 deletions
glow-extras
@
38ce73ea
Subproject commit
d24f6bfa89995994ecec1b7fb7a4791b3de7fd7a
Subproject commit
38ce73ea211cc54f861caa10778d903f94f508b5
This diff is collapsed.
Click to expand it.
polymesh
@
ee575532
Subproject commit
422b371894d4326a41d6dcc81ed5a998c7406b25
Subproject commit
ee575532d0eba2da77b672219bbda8082638e657
This diff is collapsed.
Click to expand it.
samples/basic/viewer/main.cc
+
75
−
51
View file @
01379709
...
...
@@ -146,8 +146,77 @@ void advanced_objects(pm::vertex_attribute<tg::pos3> const& pos)
void
advanced_visualization
(
pm
::
vertex_attribute
<
tg
::
pos3
>
const
&
pos
)
{
// gv::opaque, gv::transparent
// colors, textures, mappings
// the args in gv::view(obj, args) do not only configure the viewer but also change how the renderable is visualized
pm
::
Mesh
const
&
m
=
pos
.
mesh
();
// RNG for creating some random sample values
tg
::
rng
rng
;
// colors
{
auto
g
=
gv
::
grid
();
// generate some random color attributes
pm
::
face_attribute
<
tg
::
color3
>
random_face_colors
=
m
.
faces
().
map
([
&
](
pm
::
face_handle
)
{
return
tg
::
uniform
<
tg
::
color3
>
(
rng
);
});
pm
::
vertex_attribute
<
tg
::
color3
>
random_vertex_colors
=
m
.
vertices
().
map
([
&
](
pm
::
vertex_handle
)
{
return
tg
::
uniform
<
tg
::
color3
>
(
rng
);
});
// map positions to colors
pm
::
vertex_attribute
<
tg
::
color3
>
vcolors
=
m
.
vertices
().
map
([
&
](
pm
::
vertex_handle
v
)
{
return
tg
::
color3
(
pos
[
v
]
*
0.5
f
+
0.5
f
);
});
gv
::
view
(
pos
,
tg
::
color3
::
red
,
"solid color for whole mesh"
);
gv
::
view
(
pos
,
random_face_colors
,
"random face colors"
);
gv
::
view
(
pos
,
random_vertex_colors
,
"random vertex colors"
);
gv
::
view
(
gv
::
points
(
pos
),
vcolors
,
"point cloud with xyz colors"
);
}
// data mapping
{
auto
g
=
gv
::
grid
();
// a scalar field consisting of vertex y coordinate
pm
::
vertex_attribute
<
float
>
vdata
=
pos
.
map
([](
tg
::
pos3
v
)
{
return
v
.
y
;
});
// a scalar field consisting of face areas
pm
::
face_attribute
<
float
>
fdata
=
m
.
faces
().
map
([
&
](
pm
::
face_handle
f
)
{
return
pm
::
face_area
(
f
,
pos
);
});
// map vertex data to black-red, from 0.1 .. 0.3 (repeats outside)
gv
::
view
(
pos
,
gv
::
mapping
(
vdata
).
linear
(
tg
::
color3
::
black
,
tg
::
color3
::
red
,
0.1
f
,
0.3
f
),
"vertex data"
);
// map face data to red (small) to green (big) from 0.05 .. 0.5 (data outside this range is clamped)
gv
::
view
(
pos
,
gv
::
mapping
(
fdata
).
linear
(
tg
::
color3
::
red
,
tg
::
color3
::
green
,
0.05
f
,
0.5
f
).
clamped
(),
"face data"
);
}
// textures
{
auto
g
=
gv
::
grid
();
// taking xy as UV for now
// NOTE: halfedge attributes also work
pm
::
vertex_attribute
<
tg
::
pos2
>
uv
=
pos
.
map
([](
tg
::
pos3
v
)
{
return
tg
::
pos2
(
v
.
x
,
v
.
y
);
});
// textures can be loaded directly or async
// TODO: gv::textured with a filename (and color space)
glow
::
SharedTexture2D
tex
=
glow
::
Texture2D
::
createFromFile
(
dataPath
+
"textures/tiles.color.png"
,
glow
::
ColorSpace
::
sRGB
);
glow
::
AsyncTexture2D
atex
=
glow
::
AsyncTextureLoader
::
load2D
(
dataPath
+
"textures/tiles.color.png"
,
glow
::
ColorSpace
::
sRGB
);
gv
::
view
(
pos
,
gv
::
textured
(
uv
,
tex
),
"textured"
);
gv
::
view
(
pos
,
gv
::
textured
(
uv
,
atex
),
"textured (async)"
);
gv
::
view
(
pos
,
gv
::
textured
(
uv
,
tex
).
flip
(),
"flipped y axis"
);
gv
::
view
(
pos
,
gv
::
textured
(
uv
,
tex
).
transform
(
tg
::
scaling
(
3.0
f
,
0.5
f
)),
"transformed UVs"
);
}
// transparency
{
auto
g
=
gv
::
grid
();
// if colors with alpha < 1 are provided, transparency is enabled
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"
);
// it can be explicitly controlled via gv::transparent and gv::opaque
gv
::
view
(
pos
,
tg
::
color4
(
0.3
f
,
0.1
f
,
0.3
f
,
0.5
f
),
gv
::
transparent
,
"explicitly transparent"
);
gv
::
view
(
pos
,
tg
::
color4
(
0.3
f
,
0.1
f
,
0.3
f
,
0.2
f
),
gv
::
opaque
,
"transparent color but disabled transparency"
);
}
// TODO: complex material (e.g. PBR)
}
...
...
@@ -431,30 +500,18 @@ void special_use_cases(pm::vertex_attribute<tg::pos3> const& pos)
int
main
()
{
//
C
reate a context
//
c
reate a
rendering
context
glow
::
glfw
::
GlfwContext
ctx
;
tg
::
rng
rng
;
//
L
oad a sample polymesh mesh
//
l
oad a sample polymesh mesh
pm
::
Mesh
m
;
auto
pos
=
m
.
vertices
().
make_attribute
<
tg
::
pos3
>
();
load
(
dataPath
+
"suzanne.obj"
,
m
,
pos
);
normalize
(
pos
);
// make it -1..1
// prepare some data
pm
::
vertex_attribute
<
glm
::
vec2
>
uv
=
pos
.
map
([](
tg
::
pos3
v
)
{
return
glm
::
vec2
(
v
.
x
,
v
.
y
);
});
pm
::
vertex_attribute
<
float
>
vdata
=
pos
.
map
([](
tg
::
pos3
v
)
{
return
v
.
y
;
});
pm
::
vertex_attribute
<
tg
::
vec3
>
vnormals
=
vertex_normals_by_area
(
pos
);
pm
::
face_attribute
<
float
>
fdata
=
m
.
faces
().
map
([
&
](
pm
::
face_handle
f
)
{
return
f
.
vertices
().
avg
(
pos
).
z
;
});
glow
::
SharedTexture2D
tex
=
glow
::
Texture2D
::
createFromFile
(
dataPath
+
"textures/tiles.color.png"
,
glow
::
ColorSpace
::
sRGB
);
glow
::
AsyncTexture2D
atex
=
glow
::
AsyncTextureLoader
::
load2D
(
dataPath
+
"textures/tiles.color.png"
,
glow
::
ColorSpace
::
sRGB
);
pm
::
face_attribute
<
tg
::
color3
>
fcolors
=
m
.
faces
().
map
([
&
](
pm
::
face_handle
)
{
return
tg
::
uniform
<
tg
::
color3
>
(
rng
);
});
pm
::
vertex_attribute
<
tg
::
color3
>
vcolors
=
attribute
(
m
.
vertices
(),
tg
::
color3
(
1
,
0
,
0
));
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
);
});
// basics demos
// basic demos
{
simple_view
(
pos
);
...
...
@@ -487,38 +544,5 @@ int main()
headless_screenshot
(
pos
);
}
// Grid of examples
{
// Configuration nesting
{
// Colored faces
gv
::
view
(
pos
,
fcolors
,
"colored faces"
);
{
// Colored vertices
gv
::
view
(
pos
,
vcolors
,
"colored vertices"
);
}
}
// Mapped 1D vertex data
gv
::
view
(
pos
,
gv
::
mapping
(
vdata
).
linear
({
0
,
0
,
0
},
{
1
,
0
,
0
},
0.1
f
,
0.3
f
),
"vertex data"
);
// Mapped 1D face data
gv
::
view
(
pos
,
gv
::
mapping
(
fdata
).
linear
({
0
,
1
,
0
},
{
0
,
0
,
1
},
-
0.5
f
,
0.5
f
).
clamped
(),
"face data"
);
// Textured mesh
gv
::
view
(
pos
,
gv
::
textured
(
uv
,
tex
),
"textured"
);
// Textured mesh (async texture)
gv
::
view
(
pos
,
gv
::
textured
(
uv
,
atex
),
"textured (async)"
);
// 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"
);
{
}
}
return
0
;
return
EXIT_SUCCESS
;
}
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