Skip to content

Commit a100c46

Browse files
committed
Add animated free-surface visualization driven by wave model
Add a real-time animated water surface to the VSG viewer. - Renders a translucent ocean surface whose elevation follows the active wave model. - Updates mesh vertices each frame using WaveBase::GetElevation(x,y,t). - Computes per-vertex normals for correct lighting on wave slopes. - Uses dynamic VSG vertex buffers and robust lifecycle handling across simulations. - Falls back to a static plane when no wave model is present. Pure visualization feature; no impact on hydrodynamics or solver behavior.
1 parent 8f2acba commit a100c46

9 files changed

Lines changed: 530 additions & 20 deletions

File tree

demos/oswec/demo_oswec_reg_waves.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ int main(int argc, char* argv[]) {
215215
// main simulation loop
216216
ui.Init(&system, "OSWEC - Regular Waves");
217217
ui.SetCamera(0, -50, -10, 0, 0, -10);
218+
ui.SetWaveModel(my_hydro_inputs); // Enable animated water surface
218219

219220
while (system.GetChTime() <= simulationDuration) {
220221
if (ui.IsRunning(timestep) == false) break;

demos/rm3/demo_rm3_reg_waves.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ int main(int argc, char* argv[]) {
146146
// main simulation loop
147147
ui.Init(&system, "RM3 - Regular Wave Test");
148148
ui.SetCamera(0, -50, -10, 0, 0, -10);
149+
ui.SetWaveModel(my_hydro_inputs); // Enable animated water surface
149150

150151
while (system.GetChTime() <= simulationDuration) {
151152
if (ui.IsRunning(timestep) == false) break;

demos/sphere/demo_sphere_irreg_waves.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ int main(int argc, char* argv[]) {
159159
// main simulation loop
160160
ui.Init(&system, "Sphere - Irregular Waves Test");
161161
ui.SetCamera(8, -25, 15, 0, 0, 0);
162+
ui.SetWaveModel(my_hydro_inputs); // Enable animated water surface
162163

163164
while (system.GetChTime() <= simulationDuration) {
164165
if (ui.IsRunning(timestep) == false) break;

demos/sphere/demo_sphere_reg_waves.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ int main(int argc, char* argv[]) {
127127
// main simulation loop
128128
ui.Init(&system, "Sphere - Regular Waves Test");
129129
ui.SetCamera(8, -25, 15, 0, 0, 0);
130+
ui.SetWaveModel(my_hydro_inputs); // Enable animated water surface
130131

131132
while (system.GetChTime() <= simulation_duration) {
132133
if (ui.IsRunning(timestep) == false) break;

include/hydroc/gui/guihelper.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ namespace chrono {
66
class ChSystem;
77
}
88

9+
// Forward declaration for wave model
10+
class WaveBase;
11+
912
namespace hydroc {
1013
namespace gui {
1114

@@ -36,6 +39,15 @@ class UI {
3639
*/
3740
virtual bool IsRunning(double timestep);
3841

42+
/**@brief Set the wave model for animated free-surface rendering.
43+
*
44+
* Should be called after Init() and before the simulation loop.
45+
* If not called, a static flat water plane is rendered.
46+
*
47+
* @param wave Shared pointer to the wave model (may be nullptr for still water).
48+
*/
49+
virtual void SetWaveModel(std::shared_ptr<WaveBase> wave);
50+
3951
/**@brief return the internal system.
4052
*
4153
* Should be called after init.
@@ -62,6 +74,7 @@ class GUI : public UI {
6274
void Init(chrono::ChSystem*, const char* title) override;
6375
void SetCamera(double x, double y, double z, double dirx, double diry, double dirz) override;
6476
bool IsRunning(double timestep) override;
77+
void SetWaveModel(std::shared_ptr<WaveBase> wave) override;
6578

6679
private:
6780
std::shared_ptr<hydroc::gui::GUIImpl> pImpl;

src/gui/guihelper.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <hydroc/config.h>
22
#include <hydroc/gui/guihelper.h>
33
#include <hydroc/logging.h>
4+
#include <hydroc/waves/wave_base.h>
45

56
#include "guihelper_impl.h"
67

@@ -28,6 +29,11 @@ bool UI::IsRunning(double timestep) {
2829
return true;
2930
}
3031

32+
void UI::SetWaveModel(std::shared_ptr<WaveBase> wave) {
33+
// Default (headless) UI does not render waves.
34+
(void)wave;
35+
}
36+
3137
// -----------------------------------------------------------------------------
3238

3339
GUI::GUI() {
@@ -54,3 +60,7 @@ void GUI::SetCamera(double x, double y, double z, double dirx, double diry, doub
5460
bool GUI::IsRunning(double timestep) {
5561
return pImpl->IsRunning(timestep);
5662
}
63+
64+
void GUI::SetWaveModel(std::shared_ptr<WaveBase> wave) {
65+
pImpl->SetWaveModel(wave);
66+
}

0 commit comments

Comments
 (0)