VOXEDIT: added single voxel edit mode
parent
7b31c98407
commit
879b1143c4
|
@ -21,6 +21,7 @@ void ToolsPanel::update(const char *title) {
|
|||
if (ImGui::Begin(title, nullptr, ImGuiWindowFlags_NoDecoration)) {
|
||||
core_trace_scoped(ToolsPanel);
|
||||
modifierRadioButton(ICON_FA_PEN " Place", ModifierType::Place);
|
||||
modifierRadioButton(ICON_FA_PEN " Single", ModifierType::Place | ModifierType::Single);
|
||||
modifierRadioButton(ICON_FA_EXPAND " Select", ModifierType::Select);
|
||||
modifierRadioButton(ICON_FA_ERASER " Delete", ModifierType::Delete);
|
||||
modifierRadioButton(ICON_FK_PENCIL " Pick color", ModifierType::ColorPicker);
|
||||
|
|
|
@ -1851,6 +1851,7 @@ bool SceneManager::update(double nowSeconds) {
|
|||
_loadingFuture = std::future<voxelformat::SceneGraph>();
|
||||
}
|
||||
}
|
||||
_modifier.update(nowSeconds);
|
||||
_volumeRenderer.update();
|
||||
for (int i = 0; i < lengthof(DIRECTIONS); ++i) {
|
||||
if (!_move[i].pressed()) {
|
||||
|
|
|
@ -97,6 +97,15 @@ void Modifier::shutdown() {
|
|||
reset();
|
||||
}
|
||||
|
||||
void Modifier::update(double nowSeconds) {
|
||||
if ((_modifierType & ModifierType::Single) == ModifierType::Single) {
|
||||
if (_actionExecuteButton.pressed() && nowSeconds >= _nextSingleExecution) {
|
||||
_actionExecuteButton.execute(true);
|
||||
_nextSingleExecution = nowSeconds + 0.1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Modifier::reset() {
|
||||
unselect();
|
||||
_gridResolution = 1;
|
||||
|
@ -147,7 +156,7 @@ bool Modifier::aabbStart() {
|
|||
_aabbFirstPos = aabbPosition();
|
||||
_secondPosValid = false;
|
||||
_aabbSecondActionDirection = math::Axis::None;
|
||||
_aabbMode = _modifierType != ModifierType::ColorPicker;
|
||||
_aabbMode = (_modifierType & ModifierType::Single) != ModifierType::Single;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -263,7 +272,7 @@ bool Modifier::executeShapeAction(ModifierVolumeWrapper& wrapper, const glm::ive
|
|||
}
|
||||
|
||||
bool Modifier::needsSecondAction() {
|
||||
if (_modifierType == ModifierType::ColorPicker) {
|
||||
if ((_modifierType & ModifierType::Single) == ModifierType::Single) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -308,7 +317,8 @@ glm::ivec3 Modifier::firstPos() const {
|
|||
math::AABB<int> Modifier::aabb() const {
|
||||
const int size = _gridResolution;
|
||||
const glm::ivec3& pos = aabbPosition();
|
||||
const glm::ivec3& firstP = firstPos();
|
||||
const bool single = (_modifierType & ModifierType::Single) == ModifierType::Single;
|
||||
const glm::ivec3& firstP = single ? pos : firstPos();
|
||||
const glm::ivec3 mins = (glm::min)(firstP, pos);
|
||||
const glm::ivec3 maxs = (glm::max)(firstP, pos) + (size - 1);
|
||||
return math::AABB<int>(mins, maxs);
|
||||
|
@ -333,10 +343,6 @@ bool Modifier::aabbAction(voxel::RawVolume* volume, const std::function<void(con
|
|||
}
|
||||
return false;
|
||||
}
|
||||
if (!_aabbMode) {
|
||||
Log::debug("Not in aabb mode - can't perform action");
|
||||
return false;
|
||||
}
|
||||
|
||||
const math::AABB<int> a = aabb();
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ protected:
|
|||
bool _secondPosValid = false;
|
||||
bool _aabbMode = false;
|
||||
bool _center = false;
|
||||
double _nextSingleExecution = 0;
|
||||
glm::ivec3 _aabbFirstPos {0};
|
||||
glm::ivec3 _aabbSecondPos {0};
|
||||
math::Axis _aabbSecondActionDirection = math::Axis::None;
|
||||
|
@ -74,6 +75,8 @@ public:
|
|||
|
||||
void construct() override;
|
||||
bool init() override;
|
||||
void update(double nowSeconds);
|
||||
|
||||
void shutdown() override;
|
||||
|
||||
virtual bool select(const glm::ivec3& mins, const glm::ivec3& maxs);
|
||||
|
|
|
@ -19,11 +19,11 @@ bool ModifierButton::handleDown(int32_t key, double pressedMillis) {
|
|||
return initialDown;
|
||||
}
|
||||
if (_secondAction) {
|
||||
execute();
|
||||
execute(false);
|
||||
return initialDown;
|
||||
}
|
||||
Modifier& mgr = sceneMgr().modifier();
|
||||
if (initialDown) {
|
||||
Modifier& mgr = sceneMgr().modifier();
|
||||
if (_newType != ModifierType::None) {
|
||||
_oldType = mgr.modifierType();
|
||||
mgr.setModifierType(_newType);
|
||||
|
@ -47,14 +47,14 @@ bool ModifierButton::handleUp(int32_t key, double releasedMillis) {
|
|||
mgr.aabbStep();
|
||||
return allUp;
|
||||
}
|
||||
execute();
|
||||
execute(false);
|
||||
} else {
|
||||
Log::debug("Not all modifier keys were released - skipped action execution");
|
||||
}
|
||||
return allUp;
|
||||
}
|
||||
|
||||
void ModifierButton::execute() {
|
||||
void ModifierButton::execute(bool single) {
|
||||
Modifier& mgr = sceneMgr().modifier();
|
||||
sceneMgr().nodeForeachGroup([&] (int nodeId) {
|
||||
Log::debug("Execute modifier action for node %i", nodeId);
|
||||
|
@ -70,7 +70,9 @@ void ModifierButton::execute() {
|
|||
sceneMgr().trace(true);
|
||||
_oldType = ModifierType::None;
|
||||
}
|
||||
mgr.aabbAbort();
|
||||
if (!single) {
|
||||
mgr.aabbAbort();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
*/
|
||||
ModifierButton(ModifierType newType = ModifierType::None);
|
||||
|
||||
void execute();
|
||||
void execute(bool single);
|
||||
bool handleDown(int32_t key, double pressedMillis) override;
|
||||
bool handleUp(int32_t key, double releasedMillis) override;
|
||||
};
|
||||
|
|
|
@ -8,10 +8,11 @@
|
|||
|
||||
enum class ModifierType {
|
||||
None = 0,
|
||||
Place = 1 << 0,
|
||||
Delete = 1 << 1,
|
||||
Update = 1 << 2,
|
||||
Select = 1 << 3,
|
||||
ColorPicker = 1 << 4
|
||||
Place = (1 << 0),
|
||||
Single = (1 << 1),
|
||||
Delete = (1 << 2),
|
||||
Update = (1 << 3),
|
||||
Select = (1 << 4),
|
||||
ColorPicker = (1 << 5) | Single
|
||||
};
|
||||
CORE_ENUM_BIT_OPERATIONS(ModifierType)
|
||||
|
|
Loading…
Reference in New Issue