Skip to content

Commit

Permalink
clear scene before loading a new model
Browse files Browse the repository at this point in the history
  • Loading branch information
LiangliangNan committed Sep 14, 2023
1 parent 58e1f2f commit db68541
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions tutorials/Tutorial_308_TexturedMesh/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ namespace easy3d {
}


Model *TexturedViewer::add_model(const std::string &file_name) {
Model *TexturedViewer::add_model(const std::string &file_name, bool create_default_drawables) {
clear_scene(); // delete all existing models

if (!file_system::is_file(file_name)) {
LOG(ERROR) << "file does not exist: " << file_name;
return nullptr;
}

if (file_system::extension(file_name, true) != "obj")
return Viewer::add_model(file_name, true);
return Viewer::add_model(file_name, create_default_drawables);

fastObjMesh *fom = fast_obj_read(file_name.c_str());
if (!fom) {
Expand Down Expand Up @@ -203,7 +205,7 @@ namespace easy3d {

// since the mesh has been built, skip texture if material and texcoord information don't exist
if (fom->material_count == 0 || !fom->materials) {
Viewer::add_model(mesh, true);
Viewer::add_model(mesh, create_default_drawables);
return mesh;
}
else
Expand Down Expand Up @@ -269,6 +271,7 @@ namespace easy3d {
drawable->update_texcoord_buffer(d_texcoords);

drawable->set_smooth_shading(false);
drawable->set_distinct_back_color(false); // ignore inconsistent orientations
if (prop_texcoords) {
if (!group.tex_file.empty()) {
Texture *tex = TextureManager::request(group.tex_file, Texture::REPEAT);
Expand Down
2 changes: 1 addition & 1 deletion tutorials/Tutorial_308_TexturedMesh/viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace easy3d {
public:
explicit TexturedViewer(const std::string& title = "");

Model* add_model(const std::string& file_name);
Model* add_model(const std::string& file_name, bool create_default_drawables = true) override;
};

}
Expand Down

0 comments on commit db68541

Please sign in to comment.