Skip to content

Commit

Permalink
VOXEDIT: preview and height for PlaneBrush (Extrude) #472
Browse files Browse the repository at this point in the history
converted the plane brush into an AABBBrush and implemented the preview
by using the new XXRegion functions from the voxelutil module

also removed the manually specified thickness parameter that was added
in a few commits before
  • Loading branch information
mgerhardy committed Jun 10, 2024
1 parent b1ca038 commit c60f867
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 41 deletions.
8 changes: 0 additions & 8 deletions src/tools/voxedit/modules/voxedit-ui/BrushPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,6 @@ void BrushPanel::updatePlaneBrushPanel(command::CommandExecutionListener &listen
} else if (modifier.isMode(ModifierType::Override)) {
ImGui::TextWrappedUnformatted(_("Override voxels"));
}

if (modifier.isMode(ModifierType::Place)) {
PlaneBrush &brush = modifier.planeBrush();
int factor = brush.thickness();
if (ImGui::InputInt(_("Thickness"), &factor)) {
brush.setThickness(factor);
}
}
}

void BrushPanel::updateLineBrushPanel(command::CommandExecutionListener &listener) {
Expand Down
6 changes: 6 additions & 0 deletions src/tools/voxedit/modules/voxedit-util/modifier/Modifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ AABBBrush *Modifier::activeAABBBrush() {
if (_brushType == BrushType::Paint) {
return &_paintBrush;
}
if (_brushType == BrushType::Plane) {
return &_planeBrush;
}
return nullptr;
}

Expand All @@ -449,6 +452,9 @@ const AABBBrush *Modifier::activeAABBBrush() const {
if (_brushType == BrushType::Paint) {
return &_paintBrush;
}
if (_brushType == BrushType::Plane) {
return &_planeBrush;
}
return nullptr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void ModifierFacade::updateBrushVolumePreview(palette::Palette &activePalette) {

// operate on existing voxels
voxel::RawVolume *existingVolume = nullptr;
if (_modifierType == ModifierType::Paint) {
if (_modifierType == ModifierType::Paint || (_brushType == BrushType::Plane && _modifierType == ModifierType::Place)) {
existingVolume = activeVolume;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,66 @@
*/

#include "PlaneBrush.h"
#include "core/Log.h"
#include "math/Axis.h"
#include "voxedit-util/modifier/ModifierType.h"
#include "voxedit-util/modifier/ModifierVolumeWrapper.h"
#include "voxel/Face.h"
#include "voxel/RawVolume.h"
#include "voxel/Region.h"
#include "voxelutil/VoxelUtil.h"

namespace voxedit {

bool PlaneBrush::start(const BrushContext &context) {
if (!Super::start(context)) {
return false;
}
_hitVoxel = context.hitCursorVoxel;
return true;
}

voxel::Region PlaneBrush::calcRegion(const BrushContext &context) const {
return voxel::Region::InvalidRegion;
return _region;
}

int PlaneBrush::calculateThickness(const BrushContext &context) const {
const math::Axis axis = voxel::faceToAxis(_aabbFace);
const int idx = math::getIndexForAxis(axis);
const voxel::Region region = Super::calcRegion(context);
return core_max(1, region.getDimensionsInVoxels()[idx]);
}

template<class Volume>
static void generateForModifier(Volume &volume, ModifierType type, const BrushContext &context, const glm::ivec3 &pos,
voxel::FaceNames face, const voxel::Voxel &initialPosVoxel, int thickness) {
if (type == ModifierType::Place) {
voxelutil::extrudePlane(volume, pos, face, initialPosVoxel, context.cursorVoxel, thickness);
} else if (type == ModifierType::Erase) {
voxelutil::erasePlane(volume, pos, face, initialPosVoxel);
} else if (type == ModifierType::Override) {
voxelutil::overridePlane(volume, pos, face, context.cursorVoxel);
}
}

void PlaneBrush::preExecute(const BrushContext &context, const voxel::RawVolume *volume) {
const int thickness = calculateThickness(context);
ModifierType type = ModifierType::Place;
if (type == ModifierType::Place) {
_region =
voxelutil::extrudePlaneRegion(*volume, _aabbFirstPos, _aabbFace, _hitVoxel, context.cursorVoxel, thickness);
} else if (type == ModifierType::Erase) {
_region = voxelutil::erasePlaneRegion(*volume, _aabbFirstPos, _aabbFace, _hitVoxel);
} else if (type == ModifierType::Override) {
_region = voxelutil::overridePlaneRegion(*volume, _aabbFirstPos, _aabbFace, context.cursorVoxel);
}
_region.grow(1);
}

void PlaneBrush::generate(scenegraph::SceneGraph &sceneGraph, ModifierVolumeWrapper &wrapper,
const BrushContext &context, const voxel::Region &region) {
voxel::Voxel hitVoxel = context.hitCursorVoxel;
// TODO: context.gridResolution
// TODO: context.lockedAxis support
const glm::ivec3 &mins = context.cursorPosition;
if (wrapper.modifierType() == ModifierType::Place) {
voxelutil::extrudePlane(wrapper, mins, context.cursorFace, hitVoxel, context.cursorVoxel, _thickness);
} else if (wrapper.modifierType() == ModifierType::Erase) {
voxelutil::erasePlane(wrapper, mins, context.cursorFace, hitVoxel);
} else if (wrapper.modifierType() == ModifierType::Override) {
voxelutil::overridePlane(wrapper, mins, context.cursorFace, context.cursorVoxel);
}
const int thickness = calculateThickness(context);
generateForModifier(wrapper, wrapper.modifierType(), context, _aabbFirstPos, _aabbFace, _hitVoxel, thickness);
}

} // namespace voxedit
29 changes: 9 additions & 20 deletions src/tools/voxedit/modules/voxedit-util/modifier/brush/PlaneBrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,32 @@

#pragma once

#include "Brush.h"
#include "AABBBrush.h"

namespace voxedit {

/**
* @brief A brush that generates voxels on a whole plane or extrudes on existing voxels
* @ingroup Brushes
*/
class PlaneBrush : public Brush {
class PlaneBrush : public AABBBrush {
private:
using Super = Brush;
int _thickness = 1;
using Super = AABBBrush;
voxel::Voxel _hitVoxel;
voxel::Region _region;

protected:
void generate(scenegraph::SceneGraph &sceneGraph, ModifierVolumeWrapper &wrapper, const BrushContext &context,
const voxel::Region &region) override;
voxel::Region calcRegion(const BrushContext &context) const override;

int calculateThickness(const BrushContext &context) const;
public:
PlaneBrush() : Super(BrushType::Plane) {
}
virtual ~PlaneBrush() = default;

void setThickness(int thickness);
int thickness() const;
bool start(const BrushContext &context) override;
void preExecute(const BrushContext &ctx, const voxel::RawVolume *volume) override;
voxel::Region calcRegion(const BrushContext &context) const override;
};

inline void PlaneBrush::setThickness(int thickness) {
_thickness = thickness;
if (_thickness < 1)
_thickness = 1;

markDirty();
}

inline int PlaneBrush::thickness() const {
return _thickness;
}

} // namespace voxedit

0 comments on commit c60f867

Please sign in to comment.