PeriDyno 1.0.0
Loading...
Searching...
No Matches
WRenderParamsWidget.cpp
Go to the documentation of this file.
2#include "WSimulationCanvas.h"
3
4#include <Wt/WPushButton.h>
5#include <Wt/WPanel.h>
6#include <Wt/WColorPicker.h>
7#include <Wt/WDoubleSpinBox.h>
8#include <Wt/WLabel.h>
9#include <Wt/WTable.h>
10#include <Wt/WCheckBox.h>
11#include <Wt/WHBoxLayout.h>
12#include <Wt/WVBoxLayout.h>
13#include <Wt/WGridLayout.h>
14#include <Wt/WBorderLayout.h>
15#include <Wt/WSlider.h>
16#include <Wt/WText.h>
17
18#include <GLRenderEngine.h>
19
20using namespace dyno;
21
23{
24 this->setLayoutSizeAware(true);
25 this->setOverflow(Wt::Overflow::Auto);
26 this->setHeight(Wt::WLength("100%"));
27
29 //createCameraPanel();
31
32 mRenderParams = rparams;
33 update();
34
35 // connect signal
36 mAmbientColor->colorInput().connect(this, &WRenderParamsWidget::updateRenderParams);
37 mAmbientScale->valueChanged().connect(this, &WRenderParamsWidget::updateRenderParams);
38 mLightColor->colorInput().connect(this, &WRenderParamsWidget::updateRenderParams);
39 mLightScale->valueChanged().connect(this, &WRenderParamsWidget::updateRenderParams);
40 mLightTheta->valueChanged().connect(this, &WRenderParamsWidget::updateRenderParams);
41 mLightPhi->valueChanged().connect(this, &WRenderParamsWidget::updateRenderParams);
42
43 //mCameraEyeX->changed().connect(this, &WRenderParamsWidget::updateRenderParams);
44 //mCameraEyeY->changed().connect(this, &WRenderParamsWidget::updateRenderParams);
45 //mCameraEyeZ->changed().connect(this, &WRenderParamsWidget::updateRenderParams);
46 //mCameraTargetX->changed().connect(this, &WRenderParamsWidget::updateRenderParams);
47 //mCameraTargetY->changed().connect(this, &WRenderParamsWidget::updateRenderParams);
48 //mCameraTargetZ->changed().connect(this, &WRenderParamsWidget::updateRenderParams);
49 //mCameraUpX->changed().connect(this, &WRenderParamsWidget::updateRenderParams);
50 //mCameraUpY->changed().connect(this, &WRenderParamsWidget::updateRenderParams);
51 //mCameraUpZ->changed().connect(this, &WRenderParamsWidget::updateRenderParams);
52 //mCameraFov->changed().connect(this, &WRenderParamsWidget::updateRenderParams);
53 //mCameraAspect->changed().connect(this, &WRenderParamsWidget::updateRenderParams);
54 //mCameraClipNear->changed().connect(this, &WRenderParamsWidget::updateRenderParams);
55 //mCameraClipFar->changed().connect(this, &WRenderParamsWidget::updateRenderParams);
56
58 //mAxisHelper->changed().connect(this, &WRenderParamsWidget::updateRenderParams);
60 mGroundScale->valueChanged().connect(this, &WRenderParamsWidget::updateRenderParams);
63}
64
65template<class T>
66T* addTableRow(Wt::WTable* table, std::string label, int labelWidth = 120, int widgetWidth = 120)
67{
68 int row = table->rowCount();
69 auto cell0 = table->elementAt(row, 0);
70 auto cell1 = table->elementAt(row, 1);
71
72 cell0->addNew<Wt::WText>(label);
73 cell0->setContentAlignment(Wt::AlignmentFlag::Middle);
74 cell0->setWidth(labelWidth);
75
76 cell1->setContentAlignment(Wt::AlignmentFlag::Middle);
77 cell1->setWidth(widgetWidth);
78
79 T* widget = cell1->addNew<T>();
80 widget->setWidth(widgetWidth);
81 return widget;
82}
83
85{
86 // ambient light
87 {
88 auto panel = this->addNew<Wt::WPanel>();
89 panel->setCollapsible(true);
90 panel->setTitle("Ambient Light");
91 auto table = panel->setCentralWidget(std::make_unique<Wt::WTable>());
92 table->setMargin(10);
93
94 // ambient light
95 mAmbientColor = addTableRow<Wt::WColorPicker>(table, "Ambient Color");
96 mAmbientScale = addTableRow<Wt::WDoubleSpinBox>(table, "Ambient Scale");
97 mAmbientScale->setRange(1, 100);
98 }
99
100 // main directional light
101 {
102 auto panel = this->addNew<Wt::WPanel>();
103 panel->setCollapsible(true);
104 panel->setTitle("Main Directional Light");
105 auto table = panel->setCentralWidget(std::make_unique<Wt::WTable>());
106 table->setMargin(10);
107
108 mLightColor = addTableRow<Wt::WColorPicker>(table, "Light Color");
109 mLightScale = addTableRow<Wt::WDoubleSpinBox>(table, "Light Scale");
110 mLightScale->setRange(1, 100);
111
112 mLightTheta = addTableRow<Wt::WSlider>(table, "Light Theta");
113 mLightPhi = addTableRow<Wt::WSlider>(table, "Light Phi");
114 mLightTheta->setRange(0, 180);
115 mLightPhi->setRange(-180, 180);
116 }
117
118 mAmbientColor->setStyleClass("color-picker");
119 mLightColor->setStyleClass("color-picker");
120
121}
122
124{
125 // light
126 auto panel = this->addNew<Wt::WPanel>();
127 panel->setCollapsible(true);
128 panel->setTitle("Camera Settings");
129 auto table = panel->setCentralWidget(std::make_unique<Wt::WTable>());
130 table->setMargin(10);
131
135
139
143
144 mCameraFov = addTableRow<Wt::WDoubleSpinBox>(table, "FOV(Vertical)");
148
149 table->elementAt(13, 0)->setColumnSpan(2);
150 table->elementAt(13, 0)->setContentAlignment(Wt::AlignmentFlag::Center);
151 auto updateBtn = table->elementAt(13, 0)->addNew<Wt::WPushButton>("Update from Canvas");
152 updateBtn->setMargin(10, Wt::Side::Top);
153 updateBtn->clicked().connect(this, &WRenderParamsWidget::update);
154
155 // aspect is auto computed from framebuffer sizer
156 mCameraAspect->setEnabled(false);
157
158}
159
160
162{
163 auto panel = this->addNew<Wt::WPanel>();
164 panel->setCollapsible(true);
165 panel->setTitle("Render Settings");
166 auto table = panel->setCentralWidget(std::make_unique<Wt::WTable>());
167 table->setMargin(10);
168
169 mSceneBounds = addTableRow<Wt::WCheckBox>(table, "Scene Bound");
170 //mAxisHelper = addTableRow<Wt::WCheckBox>(table, "Axis Helper");
171 mGroundPlane = addTableRow<Wt::WCheckBox>(table, "Ground Plane");
172 mGroundScale = addTableRow<Wt::WSlider>(table, "Ground Scale");
173 mGroundScale->setRange(1, 52);
174 mBackgroudColor0 = addTableRow<Wt::WColorPicker>(table, "Background");
175 mBackgroudColor0->setStyleClass("color-picker");
176 mBackgroudColor1 = addTableRow<Wt::WColorPicker>(table, "Background");
177 mBackgroudColor1->setStyleClass("color-picker");
178
179}
180
181Wt::WColor Glm2WColor(glm::vec3 v)
182{
183 return Wt::WColor(v.x * 255, v.y * 255, v.z * 255);
184}
185
186glm::vec3 WColor2Glm(Wt::WColor clr)
187{
188 return { clr.red() / 255.f, clr.green() / 255.f, clr.blue() / 255.f };
189}
190
191glm::vec3 xyz2sphere(glm::vec3 v)
192{
193 float xz = glm::length(glm::vec2(v.x, v.z));
194 float theta = atan2(xz, v.y);
195 float phi = atan2(v.z, v.x);
196 return glm::vec3(theta, phi, glm::length(v));
197}
198
199glm::vec3 sphere2xyz(glm::vec3 v)
200{
201 float r = v.z;
202 float x = r * sinf(v.x) * cosf(v.y);
203 float y = r * cosf(v.x);
204 float z = r * sinf(v.x) * sinf(v.y);
205 return glm::vec3(x, y, z);
206}
207
209{
210 // light
211 mAmbientColor->setColor(Glm2WColor(mRenderParams->light.ambientColor));
212 mAmbientScale->setValue(mRenderParams->light.ambientScale);
213 mLightColor->setColor(Glm2WColor(mRenderParams->light.mainLightColor));
214 mLightScale->setValue(mRenderParams->light.mainLightScale);
215 //
216 glm::vec3 dir = glm::normalize(mRenderParams->light.mainLightDirection);
217 glm::vec3 polar = xyz2sphere(dir);
218 mLightTheta->setValue(glm::degrees(polar.x));
219 mLightPhi->setValue(glm::degrees(polar.y));
220
221 //TODO:
222 // camera
223// mCameraEyeX->setValue(mRenderParams->camera.eye.x);
224// mCameraEyeY->setValue(mRenderParams->camera.eye.y);
225// mCameraEyeZ->setValue(mRenderParams->camera.eye.z);
226// mCameraTargetX->setValue(mRenderParams->camera.target.x);
227// mCameraTargetY->setValue(mRenderParams->camera.target.y);
228// mCameraTargetZ->setValue(mRenderParams->camera.target.z);
229// mCameraUpX->setValue(mRenderParams->camera.up.x);
230// mCameraUpY->setValue(mRenderParams->camera.up.y);
231// mCameraUpZ->setValue(mRenderParams->camera.up.z);
232// mCameraFov->setValue(mRenderParams->camera.y_fov);
233// mCameraAspect->setValue(mRenderParams->camera.aspect);
234// mCameraClipNear->setValue(mRenderParams->camera.z_min);
235// mCameraClipFar->setValue(mRenderParams->camera.z_max);
236
237 // render
238// mSceneBounds->setChecked(mRenderParams->showSceneBounds);
239// //mAxisHelper->setChecked(mRenderParams->showAxisHelper);
240// mGroundPlane->setChecked(mRenderParams->showGround);
241// mGroundScale->setValue(mRenderParams->planeScale);
242// mBackgroudColor0->setColor(Glm2WColor(mRenderParams->bgColor0));
243// mBackgroudColor1->setColor(Glm2WColor(mRenderParams->bgColor1));
244}
245
247{
248 mRenderParams->light.ambientColor = WColor2Glm(mAmbientColor->color());
249 mRenderParams->light.ambientScale = mAmbientScale->value();
250
251 mRenderParams->light.mainLightColor = WColor2Glm(mLightColor->color());
252 mRenderParams->light.mainLightScale = mLightScale->value();
253
254 glm::vec2 polar = glm::radians(glm::vec2(mLightTheta->value(), mLightPhi->value()));
255 mRenderParams->light.mainLightDirection = sphere2xyz(glm::vec3(polar, 1));
256
257 // mRenderParams->camera.eye.x = mCameraEyeX->value();
258 // mRenderParams->camera.eye.y = mCameraEyeY->value();
259 // mRenderParams->camera.eye.z = mCameraEyeZ->value();
260 //
261 // mRenderParams->camera.target.x = mCameraTargetX->value();
262 // mRenderParams->camera.target.y = mCameraTargetY->value();
263 // mRenderParams->camera.target.z = mCameraTargetZ->value();
264 //
265 // mRenderParams->camera.up.x = mCameraUpX->value();
266 // mRenderParams->camera.up.y = mCameraUpY->value();
267 // mRenderParams->camera.up.z = mCameraUpZ->value();
268 //
269 // mRenderParams->camera.y_fov = mCameraFov->value();
270 // //mRenderParams->camera.aspect = mCameraAspect->value();
271 // mRenderParams->camera.z_min = mCameraClipNear->value();
272 // mRenderParams->camera.z_max = mCameraClipFar->value();
273 //
274 // mRenderParams->showSceneBounds = mSceneBounds->isChecked();
275 // //mRenderParams->showAxisHelper = mAxisHelper->isChecked();
276 // mRenderParams->showGround = mGroundPlane->isChecked();
277 // mRenderParams->planeScale = mGroundScale->value();
278 // mRenderParams->bgColor0 = WColor2Glm(mBackgroudColor0->color());
279 // mRenderParams->bgColor1 = WColor2Glm(mBackgroudColor1->color());
280
281 mSignal.emit();
282}
T * addTableRow(Wt::WTable *table, std::string label, int labelWidth=120, int widgetWidth=120)
Wt::WColor Glm2WColor(glm::vec3 v)
glm::vec3 xyz2sphere(glm::vec3 v)
glm::vec3 WColor2Glm(Wt::WColor clr)
glm::vec3 sphere2xyz(glm::vec3 v)
Wt::WDoubleSpinBox * mCameraEyeZ
Wt::WDoubleSpinBox * mCameraEyeX
Wt::WColorPicker * mBackgroudColor1
Wt::WColorPicker * mBackgroudColor0
Wt::WDoubleSpinBox * mCameraUpZ
Wt::WDoubleSpinBox * mCameraClipNear
WRenderParamsWidget(dyno::RenderParams *rparams)
Wt::WColorPicker * mAmbientColor
dyno::RenderParams * mRenderParams
Wt::WDoubleSpinBox * mCameraTargetY
Wt::WDoubleSpinBox * mAmbientScale
Wt::WDoubleSpinBox * mCameraTargetX
Wt::WDoubleSpinBox * mCameraUpY
Wt::WCheckBox * mGroundPlane
Wt::WDoubleSpinBox * mCameraAspect
Wt::WDoubleSpinBox * mCameraFov
Wt::WCheckBox * mSceneBounds
Wt::WDoubleSpinBox * mCameraTargetZ
Wt::WDoubleSpinBox * mCameraUpX
Wt::WDoubleSpinBox * mCameraClipFar
Wt::WDoubleSpinBox * mLightScale
Wt::WDoubleSpinBox * mCameraEyeY
Wt::WColorPicker * mLightColor
#define T(t)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
DYN_FUNC Complex< Real > polar(const Real &__rho, const Real &__theta=Real(0))
Definition Complex.inl:279