Skip to content

Commit

Permalink
[fix] (editing) actually only *attach* (instead of also replacing vox…
Browse files Browse the repository at this point in the history
…els) when the attach mode is active
  • Loading branch information
begla committed Nov 20, 2023
1 parent 4b73087 commit 366f8c8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
11 changes: 8 additions & 3 deletions iolite_plugins/voxel_editing_plugin/editing_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ static void handle_tool_voxel(io_ref_t shape, const tool_parameters_t& params)
params.placement_mode == placement_mode_paint ||
params.placement_mode == placement_mode_erase;
if (solid_voxels_only)
voxels.remove_non_solid_voxels(shape);
voxels.remove_voxels<remove_mode_non_solid>(shape);
else
voxels.remove_voxels<remove_mode_solid>(shape);

// Apply mirroring (if any)
mirror(shape, params, voxels);
Expand Down Expand Up @@ -588,7 +590,7 @@ static void handle_tool_extrude(io_ref_t shape, tool_parameters_t& params,
{
voxels_extruded =
voxels_extruded.prepare_fill(shape, params.palette_range);
voxels_extruded.remove_non_solid_voxels(shape);
voxels_extruded.remove_voxels<remove_mode_non_solid>(shape);
}

if (!is_left_mouse_buttom_pressed())
Expand Down Expand Up @@ -939,7 +941,10 @@ static void handle_tool_box(io_ref_t shape, tool_parameters_t& params)
mirror(shape, params, voxels);

if (solid_voxels_only)
voxels.remove_non_solid_voxels(shape);
voxels.remove_voxels<remove_mode_non_solid>(shape);
else
voxels.remove_voxels<remove_mode_solid>(shape);

if (is_selection)
voxels.update_from_shape(shape);

Expand Down
23 changes: 20 additions & 3 deletions iolite_plugins/voxel_editing_plugin/sparse_volume.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
// STL
#include <chrono>

//----------------------------------------------------------------------------//
enum remove_mode_
{
remove_mode_solid,
remove_mode_non_solid,
};
using remove_mode_t = uint8_t;

//----------------------------------------------------------------------------//
template <bool UseMortonEncoding = false> struct sparse_occupancy_mask_t
{
Expand Down Expand Up @@ -185,7 +193,7 @@ struct sparse_volume_t
}
}

void remove_non_solid_voxels(io_ref_t shape)
template <remove_mode_t Mode> void remove_voxels(io_ref_t shape)
{
const auto data = io_component_voxel_shape->get_voxel_data(shape);
const auto dim = io_component_voxel_shape->get_dim(shape);
Expand All @@ -203,8 +211,17 @@ struct sparse_volume_t

const uint32_t index =
coord.x + coord.y * dim.x + coord.z * dim.x * dim.y;
if (data[index] == 0u)
continue;

if constexpr (Mode == remove_mode_non_solid)
{
if (data[index] == 0u)
continue;
}
else if constexpr (Mode == remove_mode_solid)
{
if (data[index] != 0u)
continue;
}

updated_volume.set(coord, palette_index, dim);
}
Expand Down

0 comments on commit 366f8c8

Please sign in to comment.