VOXEDIT: implemented axis locking via editor mode (like scale, rotate and move)
parent
9c6f98deac
commit
37d3a21309
|
@ -15,3 +15,4 @@ r rotatemode
|
|||
g movemode
|
||||
s scalemode
|
||||
, resetcamera
|
||||
l togglelockaxis
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
* @brief The tick time gives you the time in milliseconds when the tick was started.
|
||||
* @note Updated once per tick
|
||||
*/
|
||||
unsigned long tickTime() const {
|
||||
inline unsigned long tickTime() const {
|
||||
return _tickTime;
|
||||
}
|
||||
|
||||
|
|
|
@ -137,9 +137,10 @@ core::AppState VoxEdit::onInit() {
|
|||
COMMAND_MAINWINDOW(cut, "Delete selected volume from model volume");
|
||||
COMMAND_MAINWINDOW(toggleviewport, "Toggle quad view on/off");
|
||||
COMMAND_MAINWINDOW(togglefreelook, "Toggle free look on/off");
|
||||
COMMAND_MAINWINDOW(rotatemode, "Activates the rotate mode");
|
||||
COMMAND_MAINWINDOW(scalemode, "Activates the scale mode");
|
||||
COMMAND_MAINWINDOW(movemode, "Activates the move mode");
|
||||
COMMAND_MAINWINDOW(rotatemode, "Activates the rotate mode (next keys are axis x, y, or z and the rotation value in degrees)");
|
||||
COMMAND_MAINWINDOW(scalemode, "Activates the scale mode (next keys are axis x, y, or z and the numeric scale value)");
|
||||
COMMAND_MAINWINDOW(movemode, "Activates the move mode (next keys are axis x, y, or z and the translation values in voxels)");
|
||||
COMMAND_MAINWINDOW(togglelockaxis, "Activates the lock mode (next key is axis x, y, or z)");
|
||||
COMMAND_MAINWINDOW(resetcamera, "Reset cameras");
|
||||
|
||||
newFile(true);
|
||||
|
|
|
@ -102,6 +102,10 @@ bool VoxEditWindow::init() {
|
|||
_cursorY = getWidgetByType<tb::TBEditField>("cursory");
|
||||
_cursorZ = getWidgetByType<tb::TBEditField>("cursorz");
|
||||
|
||||
_lockedX = getWidgetByType<tb::TBCheckBox>("lockx");
|
||||
_lockedY = getWidgetByType<tb::TBCheckBox>("locky");
|
||||
_lockedZ = getWidgetByType<tb::TBCheckBox>("lockz");
|
||||
|
||||
_showAABB = getWidgetByType<tb::TBCheckBox>("optionshowaabb");
|
||||
_showGrid = getWidgetByType<tb::TBCheckBox>("optionshowgrid");
|
||||
_showAxis = getWidgetByType<tb::TBCheckBox>("optionshowaxis");
|
||||
|
@ -156,23 +160,28 @@ void VoxEditWindow::addMenuItem(tb::TBSelectItemSourceList<tb::TBGenericStringIt
|
|||
}
|
||||
|
||||
void VoxEditWindow::rotate(int x, int y, int z) {
|
||||
Log::debug("execute rotate by %i:%i:%i", x, y, z);
|
||||
_scene->rotate(x, y, z);
|
||||
}
|
||||
|
||||
void VoxEditWindow::scale(float x, float y, float z) {
|
||||
Log::debug("execute scale by %f:%f:%f", x, y, z);
|
||||
_scene->scaleCursorShape(glm::vec3(x, y, z));
|
||||
}
|
||||
|
||||
void VoxEditWindow::move(int x, int y, int z) {
|
||||
Log::debug("execute move by %i:%i:%i", x, y, z);
|
||||
_scene->move(x, y, z);
|
||||
}
|
||||
|
||||
void VoxEditWindow::executeMode() {
|
||||
if (_mode == ModifierMode::None) {
|
||||
_modeNumberBuf[0] = '\0';
|
||||
_lastModePress = -1l;
|
||||
_axis = voxedit::Axis::None;
|
||||
return;
|
||||
}
|
||||
|
||||
Log::info("buf: %s", _modeNumberBuf);
|
||||
if (_modeNumberBuf[0] != '\0') {
|
||||
if (_mode == ModifierMode::Scale) {
|
||||
const float value = core::string::toFloat(_modeNumberBuf);
|
||||
|
@ -207,6 +216,14 @@ void VoxEditWindow::executeMode() {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (_mode == ModifierMode::Lock) {
|
||||
const voxedit::Axis locked = _scene->lockedAxis();
|
||||
#define VOXEDIT_LOCK(axis) if ((_axis & axis) != voxedit::Axis::None) { _scene->setLockedAxis(axis, (locked & axis) != voxedit::Axis::None); _lockedDirty = true; }
|
||||
VOXEDIT_LOCK(voxedit::Axis::X)
|
||||
VOXEDIT_LOCK(voxedit::Axis::Y)
|
||||
VOXEDIT_LOCK(voxedit::Axis::Z)
|
||||
#undef VOXEDIT_LOCK
|
||||
}
|
||||
|
||||
_modeNumberBuf[0] = '\0';
|
||||
_lastModePress = -1l;
|
||||
|
@ -251,6 +268,12 @@ void VoxEditWindow::movemode() {
|
|||
_modeNumberBuf[0] = '\0';
|
||||
}
|
||||
|
||||
void VoxEditWindow::togglelockaxis() {
|
||||
_mode = ModifierMode::Lock;
|
||||
_axis = voxedit::Axis::None;
|
||||
_modeNumberBuf[0] = '\0';
|
||||
}
|
||||
|
||||
void VoxEditWindow::togglefreelook() {
|
||||
if (_freeLook == nullptr) {
|
||||
return;
|
||||
|
@ -518,19 +541,34 @@ void VoxEditWindow::OnProcess() {
|
|||
}
|
||||
const glm::ivec3& pos = _scene->cursorPosition();
|
||||
char buf[64];
|
||||
if (_cursorX != nullptr) {
|
||||
if (_cursorX != nullptr && !_cursorX->GetState(tb::WIDGET_STATE_FOCUSED)) {
|
||||
SDL_snprintf(buf, sizeof(buf), "%i", pos.x);
|
||||
_cursorX->SetText(buf);
|
||||
}
|
||||
if (_cursorY != nullptr) {
|
||||
if (_cursorY != nullptr && !_cursorY->GetState(tb::WIDGET_STATE_FOCUSED)) {
|
||||
SDL_snprintf(buf, sizeof(buf), "%i", pos.y);
|
||||
_cursorY->SetText(buf);
|
||||
}
|
||||
if (_cursorZ != nullptr) {
|
||||
if (_cursorZ != nullptr && !_cursorZ->GetState(tb::WIDGET_STATE_FOCUSED)) {
|
||||
SDL_snprintf(buf, sizeof(buf), "%i", pos.z);
|
||||
_cursorZ->SetText(buf);
|
||||
}
|
||||
|
||||
if (_lockedDirty) {
|
||||
_lockedDirty = false;
|
||||
Log::info("_lockedDirty = true;");
|
||||
const voxedit::Axis axis = _scene->lockedAxis();
|
||||
if (_lockedX != nullptr) {
|
||||
_lockedX->SetValue((axis & voxedit::Axis::X) != voxedit::Axis::None);
|
||||
}
|
||||
if (_lockedY != nullptr) {
|
||||
_lockedY->SetValue((axis & voxedit::Axis::Y) != voxedit::Axis::None);
|
||||
}
|
||||
if (_lockedZ != nullptr) {
|
||||
_lockedZ->SetValue((axis & voxedit::Axis::Z) != voxedit::Axis::None);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < SDL_arraysize(actions); ++i) {
|
||||
tb::TBWidget* w = GetWidgetByID(actions[i].id);
|
||||
if (w == nullptr) {
|
||||
|
@ -585,11 +623,14 @@ bool VoxEditWindow::OnEvent(const tb::TBWidgetEvent &ev) {
|
|||
|
||||
if (_mode != ModifierMode::None) {
|
||||
if (key == SDLK_x) {
|
||||
Log::debug("Set axis to x");
|
||||
_axis |= voxedit::Axis::X;
|
||||
} else if (key == SDLK_y) {
|
||||
_axis |= voxedit::Axis::Y;
|
||||
Log::debug("Set axis to y");
|
||||
} else if (key == SDLK_z) {
|
||||
_axis |= voxedit::Axis::Z;
|
||||
Log::debug("Set axis to z");
|
||||
}
|
||||
_lastModePress = _app->timeProvider()->tickTime();
|
||||
}
|
||||
|
|
|
@ -37,6 +37,10 @@ private:
|
|||
tb::TBEditField* _cursorY = nullptr;
|
||||
tb::TBEditField* _cursorZ = nullptr;
|
||||
|
||||
tb::TBCheckBox* _lockedX = nullptr;
|
||||
tb::TBCheckBox* _lockedY = nullptr;
|
||||
tb::TBCheckBox* _lockedZ = nullptr;
|
||||
|
||||
std::string _voxelizeFile;
|
||||
std::string _loadFile;
|
||||
|
||||
|
@ -47,6 +51,7 @@ private:
|
|||
|
||||
std::string _exportFilter;
|
||||
bool _fourViewAvailable = false;
|
||||
bool _lockedDirty = false;
|
||||
|
||||
void addMenuItem(tb::TBSelectItemSourceList<tb::TBGenericStringItem>& items, const char *text, const char *id = nullptr);
|
||||
|
||||
|
@ -57,7 +62,8 @@ private:
|
|||
None,
|
||||
Rotate,
|
||||
Scale,
|
||||
Move
|
||||
Move,
|
||||
Lock
|
||||
};
|
||||
ModifierMode _mode = ModifierMode::None;
|
||||
voxedit::Axis _axis = voxedit::Axis::None;
|
||||
|
@ -99,6 +105,7 @@ private:
|
|||
void movemode();
|
||||
void scalemode();
|
||||
void rotatemode();
|
||||
void togglelockaxis();
|
||||
void unselectall();
|
||||
bool voxelize(std::string_view file);
|
||||
bool save(std::string_view file);
|
||||
|
|
Loading…
Reference in New Issue