Skip to content
Snippets Groups Projects
Commit 0843da0e authored by Arch de Noé's avatar Arch de Noé
Browse files

feat: automatic animation

parent 83f16e5b
No related merge requests found
......@@ -51,12 +51,10 @@ void MorphistViewer::process_imgui()
ImGui::Text("%s", this->mesh2_path.filename().c_str());
ImGui::Dummy(ImVec2(0.0f, 10.0f));
ImGui::SeparatorText("Pre-Compute");
ImGui::Spacing();
if (ImGui::InputInt("Resolution", &this->bake_resolution, 1))
......@@ -79,17 +77,13 @@ void MorphistViewer::process_imgui()
this->is_baking = false;
this->is_mesh_baked = true;
SDF sdf_final = morpher.morphing_sdf(morph_percentage);
mesh_ = morpher.reconstruct_surfaces(sdf_final);
pmp::BoundingBox bb = bounds(mesh_);
pmp::flip_faces(mesh_);
update_morph();
pmp::BoundingBox bb = bounds(mesh_);
set_scene((pmp::vec3)bb.center(), 0.5 * bb.size());
update_mesh();
}
if (ImGui::Button("Bake"))
if (ImGui::Button("Bake", ImVec2(300, 20)))
{
this->is_baking = true;
ImGui::SameLine();
......@@ -102,26 +96,31 @@ void MorphistViewer::process_imgui()
ImGui::SeparatorText("Morphing");
if (ImGui::SliderFloat("##", &morph_percentage, 0.0f, 1.0f))
if (ImGui::SliderFloat("Percentage", &morph_percentage, 0.0f, 1.0f))
{
SDF sdf_final = morpher.morphing_sdf(morph_percentage);
mesh_ = morpher.reconstruct_surfaces(sdf_final);
pmp::flip_faces(mesh_);
update_mesh();
this->is_morph_playing = false;
update_morph();
}
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
if (this->is_morph_playing)
if (ImGui::Button(this->is_morph_playing ? "Pause" : "Play", ImVec2(300, 20)))
{
if (ImGui::Button("Pause"))
{
this->is_morph_playing = false;
}
this->is_morph_playing = !this->is_morph_playing;
}
else if (ImGui::Button("Play"))
ImGui::SliderFloat("Speed", &this->animation_speed, 0.0, 5.0);
if (is_morph_playing)
{
this->is_morph_playing = true;
animation_driver += ImGui::GetIO().DeltaTime * animation_speed;
this->morph_percentage = cos(animation_driver + M_PI) * 0.5 + 0.5;
update_morph();
}
ImGui::EndDisabled();
show_help();
......@@ -168,6 +167,11 @@ void MorphistViewer::show_help()
}
}
void MorphistViewer::mouse(int button, int action, int mods)
void MorphistViewer::update_morph()
{
SDF sdf_final = morpher.morphing_sdf(morph_percentage);
mesh_ = morpher.reconstruct_surfaces(sdf_final);
pmp::flip_faces(mesh_);
update_mesh();
}
......@@ -16,9 +16,6 @@ public:
MorphistViewer(const char* title, int width, int height);
protected:
//! this function handles mouse button presses
void mouse(int button, int action, int mods) override;
//! draw the scene in different draw modes
void process_imgui() override;
......@@ -26,6 +23,8 @@ protected:
void show_help();
void update_morph();
private:
bool is_baking = false;
......@@ -37,4 +36,6 @@ private:
// Between 0 and 1
float morph_percentage = 0.0f;
float animation_driver = 0.0f;
float animation_speed = 1.0f;
};
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment