feat(editor): basics for run/edit mode
This commit is contained in:
parent
be3c7bd6b2
commit
c4ad7d5620
4 changed files with 92 additions and 15 deletions
|
@ -6,6 +6,7 @@
|
||||||
Camera camera(glm::vec3(0.0, 0.0, 3.0));
|
Camera camera(glm::vec3(0.0, 0.0, 3.0));
|
||||||
//std::vector<Part> parts;
|
//std::vector<Part> parts;
|
||||||
std::shared_ptr<DataModel> gDataModel = DataModel::New();
|
std::shared_ptr<DataModel> gDataModel = DataModel::New();
|
||||||
|
std::shared_ptr<DataModel> editModeDataModel = gDataModel;
|
||||||
std::optional<HierarchyPreUpdateHandler> hierarchyPreUpdateHandler;
|
std::optional<HierarchyPreUpdateHandler> hierarchyPreUpdateHandler;
|
||||||
std::optional<HierarchyPostUpdateHandler> hierarchyPostUpdateHandler;
|
std::optional<HierarchyPostUpdateHandler> hierarchyPostUpdateHandler;
|
||||||
std::shared_ptr<Handles> editorToolHandles = Handles::New();
|
std::shared_ptr<Handles> editorToolHandles = Handles::New();
|
||||||
|
|
|
@ -111,7 +111,7 @@ std::optional<std::shared_ptr<Workspace>> Snap::jointWorkspace() {
|
||||||
if (workspace()) return workspace();
|
if (workspace()) return workspace();
|
||||||
|
|
||||||
if (GetParent() && GetParent().value()->GetClass() == &JointsService::TYPE)
|
if (GetParent() && GetParent().value()->GetClass() == &JointsService::TYPE)
|
||||||
return std::dynamic_pointer_cast<DataModel>(GetParent().value()->GetParent().value())->GetService<Workspace>("Workspace");
|
return std::dynamic_pointer_cast<DataModel>(GetParent().value()->GetParent().value())->GetService<Workspace>();
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
|
@ -17,7 +17,13 @@
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool simulationPlaying = false;
|
enum RunState {
|
||||||
|
RUN_STOPPED,
|
||||||
|
RUN_RUNNING,
|
||||||
|
RUN_PAUSED
|
||||||
|
};
|
||||||
|
|
||||||
|
RunState runState = RUN_STOPPED;
|
||||||
|
|
||||||
bool worldSpaceTransforms = false;
|
bool worldSpaceTransforms = false;
|
||||||
|
|
||||||
|
@ -171,7 +177,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
snap->c1 = part0->cframe;
|
snap->c1 = part0->cframe;
|
||||||
|
|
||||||
// gWorkspace()->AddChild(snap);
|
// gWorkspace()->AddChild(snap);
|
||||||
gDataModel->GetService<JointsService>("JointsService").expect()->AddChild(snap);
|
gDataModel->GetService<JointsService>().expect()->AddChild(snap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::closeEvent(QCloseEvent* evt) {
|
void MainWindow::closeEvent(QCloseEvent* evt) {
|
||||||
|
@ -217,7 +223,7 @@ void MainWindow::timerEvent(QTimerEvent* evt) {
|
||||||
float deltaTime = std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - lastTime).count();
|
float deltaTime = std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - lastTime).count();
|
||||||
lastTime = std::chrono::steady_clock::now();
|
lastTime = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
if (simulationPlaying)
|
if (runState == RUN_RUNNING)
|
||||||
gWorkspace()->PhysicsStep(deltaTime);
|
gWorkspace()->PhysicsStep(deltaTime);
|
||||||
ui->mainWidget->update();
|
ui->mainWidget->update();
|
||||||
ui->mainWidget->updateCycle();
|
ui->mainWidget->updateCycle();
|
||||||
|
@ -254,19 +260,45 @@ void MainWindow::connectActionHandlers() {
|
||||||
});
|
});
|
||||||
ui->actionToggleEditSounds->setChecked(true);
|
ui->actionToggleEditSounds->setChecked(true);
|
||||||
|
|
||||||
connect(ui->actionToggleSimulation, &QAction::triggered, this, [&]() {
|
connect(ui->actionRunSimulation, &QAction::triggered, this, [&]() {
|
||||||
simulationPlaying = !simulationPlaying;
|
if (runState == RUN_RUNNING) return;
|
||||||
if (simulationPlaying) {
|
|
||||||
ui->actionToggleSimulation->setText("Pause simulation");
|
if (runState == RUN_PAUSED) {
|
||||||
ui->actionToggleSimulation->setToolTip("Pause the simulation");
|
runState = RUN_RUNNING;
|
||||||
ui->actionToggleSimulation->setIcon(QIcon::fromTheme("media-playback-pause"));
|
ui->actionRunSimulation->setEnabled(false);
|
||||||
} else {
|
ui->actionPauseSimulation->setEnabled(true);
|
||||||
ui->actionToggleSimulation->setText("Resume simulation");
|
return;
|
||||||
ui->actionToggleSimulation->setToolTip("Resume the simulation");
|
|
||||||
ui->actionToggleSimulation->setIcon(QIcon::fromTheme("media-playback-start"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runState = RUN_RUNNING;
|
||||||
|
ui->actionRunSimulation->setEnabled(false);
|
||||||
|
ui->actionPauseSimulation->setEnabled(true);
|
||||||
|
ui->actionStopSimulation->setEnabled(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(ui->actionPauseSimulation, &QAction::triggered, this, [&]() {
|
||||||
|
if (runState != RUN_RUNNING) return;
|
||||||
|
|
||||||
|
runState = RUN_PAUSED;
|
||||||
|
ui->actionRunSimulation->setEnabled(true);
|
||||||
|
ui->actionPauseSimulation->setEnabled(false);
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(ui->actionStopSimulation, &QAction::triggered, this, [&]() {
|
||||||
|
if (runState == RUN_STOPPED) return;
|
||||||
|
|
||||||
|
runState = RUN_STOPPED;
|
||||||
|
ui->actionRunSimulation->setEnabled(true);
|
||||||
|
ui->actionPauseSimulation->setEnabled(false);
|
||||||
|
ui->actionStopSimulation->setEnabled(false);
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
|
||||||
|
ui->actionRunSimulation->setEnabled(true);
|
||||||
|
ui->actionPauseSimulation->setEnabled(false);
|
||||||
|
ui->actionStopSimulation->setEnabled(false);
|
||||||
|
|
||||||
connect(ui->actionToggleSpace, &QAction::triggered, this, [&]() {
|
connect(ui->actionToggleSpace, &QAction::triggered, this, [&]() {
|
||||||
worldSpaceTransforms = !worldSpaceTransforms;
|
worldSpaceTransforms = !worldSpaceTransforms;
|
||||||
updateToolbars();
|
updateToolbars();
|
||||||
|
|
|
@ -188,7 +188,9 @@
|
||||||
<attribute name="toolBarBreak">
|
<attribute name="toolBarBreak">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</attribute>
|
</attribute>
|
||||||
<addaction name="actionToggleSimulation"/>
|
<addaction name="actionRunSimulation"/>
|
||||||
|
<addaction name="actionPauseSimulation"/>
|
||||||
|
<addaction name="actionStopSimulation"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QToolBar" name="surfaceTools">
|
<widget class="QToolBar" name="surfaceTools">
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -675,6 +677,48 @@
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::MenuRole::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionRunSimulation">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="media-playback-start"/>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Run</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Run simulation</string>
|
||||||
|
</property>
|
||||||
|
<property name="menuRole">
|
||||||
|
<enum>QAction::MenuRole::NoRole</enum>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionPauseSimulation">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="media-playback-pause"/>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Pause</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Pause simulation</string>
|
||||||
|
</property>
|
||||||
|
<property name="menuRole">
|
||||||
|
<enum>QAction::MenuRole::NoRole</enum>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionStopSimulation">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="media-playback-stop"/>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Stop</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Stop simulation</string>
|
||||||
|
</property>
|
||||||
|
<property name="menuRole">
|
||||||
|
<enum>QAction::MenuRole::NoRole</enum>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
|
Loading…
Add table
Reference in a new issue