Skip to content

Commit

Permalink
VOXEDIT: improved result of normal calculation by offering the option…
Browse files Browse the repository at this point in the history
… to fill/hollow automatically
  • Loading branch information
mgerhardy committed Oct 22, 2024
1 parent 89778bf commit 7690118
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
20 changes: 20 additions & 0 deletions data/shared/de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,26 @@ msgstr "Normalen Modus"
msgid "Recalculate all normals"
msgstr "All Normalen neu berechnen"

msgid "Model is hollow"
msgstr "Modell ist hohl"

msgid ""
"Fill hollows to re-calculate the normals and\n"
"hollow the model afterwards again.\n"
"\n"
"For calculating normals it is needed that the model has a closed\n"
"surface and the hollow area is filled.\n"
"\n"
"Either do it manually or activate this option."
msgstr ""
"Hohlräume füllen, um die Normalen neu zu berechnen und\n"
"das Modell danach wieder auszuhöhlen.\n"
"\n"
"Für die Berechnung der Normalen ist es notwendig, dass das Modell eine geschlossene\n"
"Oberfläche hat und der hohle Bereich gefüllt ist.\n"
"\n"
"Entweder manuell durchführen, oder diese Option aktivieren."

msgid "Calculate normals"
msgstr "Normalen berechnen"

Expand Down
13 changes: 13 additions & 0 deletions data/vengi.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,19 @@ msgstr ""
msgid "Recalculate all normals"
msgstr ""

msgid "Model is hollow"
msgstr ""

msgid ""
"Fill hollows to re-calculate the normals and\n"
"hollow the model afterwards again.\n"
"\n"
"For calculating normals it is needed that the model has a closed\n"
"surface and the hollow area is filled.\n"
"\n"
"Either do it manually or activate this option."
msgstr ""

msgid "Calculate normals"
msgstr ""

Expand Down
10 changes: 8 additions & 2 deletions src/tools/voxedit/modules/voxedit-ui/NormalPalettePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "app/I18N.h"
#include "command/CommandHandler.h"
#include "imgui.h"
#include "palette/PaletteFormatDescription.h"
#include "palette/NormalPalette.h"
#include "palette/PaletteFormatDescription.h"
#include "ui/IMGUIApp.h"
#include "voxedit-util/Config.h"
#include "voxedit-util/SceneManager.h"
Expand Down Expand Up @@ -107,14 +107,20 @@ void NormalPalettePanel::paletteMenuBar(scenegraph::SceneGraphNode &node, comman
ImGui::EndCombo();
}
ImGui::Checkbox(_("Recalculate all normals"), &_recalcAll);
ImGui::Checkbox(_("Model is hollow"), &_onlySurfaceVoxels);
ImGui::SetItemTooltip(
_("Fill hollows to re-calculate the normals and\nhollow the model afterwards again.\n\n"
"For calculating normals it is needed that the model has a closed\n"
"surface and the hollow area is filled.\n\n"
"Either do it manually or activate this option."));
if (ImGui::IconMenuItem(ICON_LC_PLAY, _("Calculate normals"))) {
voxel::Connectivity connectivity = voxel::Connectivity::SixConnected;
if (currentNormalMode == 1) {
connectivity = voxel::Connectivity::EighteenConnected;
} else if (currentNormalMode == 2) {
connectivity = voxel::Connectivity::TwentySixConnected;
}
_sceneMgr->calculateNormals(node.id(), connectivity, _recalcAll);
_sceneMgr->calculateNormals(node.id(), connectivity, _recalcAll, _onlySurfaceVoxels);
}

ImGui::EndMenu();
Expand Down
1 change: 1 addition & 0 deletions src/tools/voxedit/modules/voxedit-ui/NormalPalettePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class NormalPalettePanel : public ui::Panel {
using Super = ui::Panel;
SceneManagerPtr _sceneMgr;
bool _recalcAll = false;
bool _onlySurfaceVoxels = true;

void paletteMenuBar(scenegraph::SceneGraphNode &node, command::CommandExecutionListener &listener);
void addColor(float startingPosX, uint8_t paletteColorIdx, scenegraph::SceneGraphNode &node,
Expand Down
8 changes: 7 additions & 1 deletion src/tools/voxedit/modules/voxedit-util/SceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,16 @@ bool SceneManager::importPalette(const core::String& file, bool setActive, bool
return setActivePalette(palette, searchBestColors);
}

bool SceneManager::calculateNormals(int nodeId, voxel::Connectivity connectivity, bool recalcAll) {
bool SceneManager::calculateNormals(int nodeId, voxel::Connectivity connectivity, bool recalcAll, bool fillAndHollow) {
if (scenegraph::SceneGraphNode *node = sceneGraphModelNode(nodeId)) {
if (!node->hasNormalPalette()) {
Log::warn("Node %i has no normal palette", nodeId);
return false;
}
voxel::RawVolumeWrapper wrapper(node->volume());
if (fillAndHollow) {
voxelutil::fillHollow(wrapper, _modifierFacade.cursorVoxel());
}
voxel::RawVolumeWrapper::Sampler sampler(wrapper);
const palette::NormalPalette &normalPalette = node->normalPalette();
voxelutil::visitSurfaceVolume(*node->volume(), [&] (int x, int y, int z, const voxel::Voxel &voxel) {
Expand All @@ -174,6 +177,9 @@ bool SceneManager::calculateNormals(int nodeId, voxel::Connectivity connectivity
const voxel::Voxel newVoxel = voxel::createVoxel(voxel.getMaterial(), voxel.getColor(), normalIndex, voxel.getFlags());
wrapper.setVoxel(x, y, z, newVoxel);
});
if (fillAndHollow) {
voxelutil::hollow(wrapper);
}
modified(nodeId, wrapper.dirtyRegion());
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/voxedit/modules/voxedit-util/SceneManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class SceneManager : public core::DeltaFrameSeconds {
*/
bool loadPalette(const core::String &paletteName, bool searchBestColors, bool save);

bool calculateNormals(int nodeId, voxel::Connectivity connectivity, bool recalcAll = false);
bool calculateNormals(int nodeId, voxel::Connectivity connectivity, bool recalcAll = false, bool fillAndHollow = false);

/**
* @brief Create a new procgen tree
Expand Down

0 comments on commit 7690118

Please sign in to comment.