The source file containing the main() function:
28#include <easy3d/core/surface_mesh.h>
29#include <easy3d/renderer/drawable_triangles.h>
30#include <easy3d/renderer/renderer.h>
31#include <easy3d/util/resource.h>
32#include <easy3d/util/initializer.h>
42int main(
int argc,
char **argv) {
45 const std::string file_name = resource::directory() +
"/data/torusknot.obj";
48 TutorialTransparency viewer(EXAMPLE_TITLE);
51 if (!viewer.add_model(file_name,
true)) {
52 LOG(ERROR) <<
"failed to load model. Please make sure the file exists and format is correct.";
56 auto drawable = viewer.current_model()->renderer()->get_triangles_drawable(
"faces");
57 drawable->set_smooth_shading(
true);
58 drawable->set_distinct_back_color(
false);
Definition: collider.cpp:182
void initialize(bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition: initializer.cpp:35
The header file of the viewer class:
27#ifndef EASY3D_TUTORIAL_TRANSPARENCY_H
28#define EASY3D_TUTORIAL_TRANSPARENCY_H
30#include <easy3d/viewer/viewer.h>
43 explicit TutorialTransparency(
const std::string& title =
"");
44 ~TutorialTransparency()
override;
47 bool key_press_event(
int key,
int modifiers)
override;
48 void draw()
const override;
Base class for rendering with transparency.
Definition: transparency.h:44
The built-in Easy3D viewer.
Definition: viewer.h:61
The source file of the viewer class:
28#include <easy3d/core/model.h>
29#include <easy3d/renderer/average_color_blending.h>
30#include <easy3d/renderer/dual_depth_peeling.h>
31#include <easy3d/renderer/drawable_triangles.h>
32#include <easy3d/renderer/renderer.h>
33#include <easy3d/renderer/camera.h>
38TutorialTransparency::TutorialTransparency(
const std::string& title) :
Viewer(title) {
40 std::cout <<
"method: Dual Depth Peeling" << std::endl;
44 "------------------------ Transparency usage ------------------------ \n"
45 "Press key 'space' to turn on/off or switch between different transparency techniques\n"
46 "Press 'up/down' to increase/decrease the transparency of the current model\n"
47 "-------------------------------------------------------------------- \n";
51TutorialTransparency::~TutorialTransparency() {
59bool TutorialTransparency::key_press_event(
int key,
int modifiers) {
60 if (key == KEY_SPACE) {
63 transparency_ =
nullptr;
66 method_ = (method_ + 1) % 3;
70 std::cout <<
"method: NULL(transparency disabled)" << std::endl;
74 std::cout <<
"method: Average Color Blending" << std::endl;
78 std::cout <<
"method: Dual Depth Peeling" << std::endl;
84 else if (key == KEY_DOWN) {
85 auto faces = current_model()->renderer()->get_triangles_drawable(
"faces");
87 float o = faces->opacity();
89 faces->set_opacity(o - 0.1f);
91 if (faces->opacity() <= 0)
92 faces->set_opacity(0.1f);
93 std::cout <<
"opacity: " << faces->opacity() << std::endl;
98 else if (key == KEY_UP) {
99 auto faces = current_model()->renderer()->get_triangles_drawable(
"faces");
101 float o = faces->opacity();
103 faces->set_opacity(o + 0.1f);
105 if (faces->opacity() >= 1.0f)
106 faces->set_opacity(1.0f);
107 std::cout <<
"opacity: " << faces->opacity() << std::endl;
113 return Viewer::key_press_event(key, modifiers);
117void TutorialTransparency::draw()
const {
118 if (!current_model()) {
122 std::vector<TrianglesDrawable*> surfaces;
123 for (
auto m : models_) {
124 for (
auto d : m->renderer()->triangles_drawables()) {
125 if (d->type() == Drawable::DT_TRIANGLES)
131 transparency_->draw(surfaces);
Transparency effect using average color blending.
Definition: average_color_blending.h:49
Transparency effect using dual depth peeling.
Definition: dual_depth_peeling.h:89
The drawable for rendering a set of triangles, e.g., the surface of a triangular mesh.
Definition: drawable_triangles.h:46