Re-namespaced VoxelToolOps

master
Marc Gilleron 2022-01-03 23:33:29 +00:00
parent 3eb6641c4f
commit 1d63067b6b
4 changed files with 25 additions and 20 deletions

View File

@ -9,9 +9,7 @@
class VoxelBuffer;
using namespace zylann;
namespace VoxelToolOps {
namespace zylann::voxel::ops {
template <typename Op, typename Shape> struct SdfOperation16bit {
Op op;
@ -74,12 +72,12 @@ struct TextureBlendSphereOp {
const float distance_from_radius = radius - Math::sqrt(distance_squared);
const float target_weight =
tp.opacity * math::clamp(tp.sharpness * (distance_from_radius / radius), 0.f, 1.f);
voxel::blend_texture_packed_u16(tp.index, target_weight, indices, weights);
blend_texture_packed_u16(tp.index, target_weight, indices, weights);
}
}
};
}; // namespace VoxelToolOps
}; // namespace zylann::voxel::ops
// TODO Need to review VoxelTool to account for transformed volumes
@ -223,7 +221,7 @@ protected:
Mode _mode = MODE_ADD;
// Used on smooth terrain
VoxelToolOps::TextureParams _texture_params;
zylann::voxel::ops::TextureParams _texture_params;
};
VARIANT_ENUM_CAST(VoxelTool::Mode)

View File

@ -3,6 +3,9 @@
#include "../util/profiling.h"
#include "funcs.h"
using namespace zylann;
using namespace voxel;
VoxelToolBuffer::VoxelToolBuffer(Ref<VoxelBuffer> vb) {
ERR_FAIL_COND(vb.is_null());
_buffer = vb;
@ -28,9 +31,9 @@ void VoxelToolBuffer::do_sphere(Vector3 center, float radius) {
Vector3iUtil::create(Math::ceil(radius) * 2));
box.clip(Box3i(Vector3i(), _buffer->get_buffer().get_size()));
_buffer->get_buffer().write_box_2_template<VoxelToolOps::TextureBlendSphereOp, uint16_t, uint16_t>(box,
_buffer->get_buffer().write_box_2_template<ops::TextureBlendSphereOp, uint16_t, uint16_t>(box,
VoxelBufferInternal::CHANNEL_INDICES, VoxelBufferInternal::CHANNEL_WEIGHTS,
VoxelToolOps::TextureBlendSphereOp(center, radius, _texture_params), Vector3i());
ops::TextureBlendSphereOp(center, radius, _texture_params), Vector3i());
_post_edit(box);
}

View File

@ -165,7 +165,7 @@ Ref<VoxelRaycastResult> VoxelToolLodTerrain::raycast(
return res;
}
namespace {
namespace zylann::voxel::ops {
struct DoSphere {
Vector3 center;
@ -174,11 +174,10 @@ struct DoSphere {
VoxelDataGrid blocks;
float sdf_scale;
Box3i box;
VoxelToolOps::TextureParams texture_params;
TextureParams texture_params;
void operator()() {
VOXEL_PROFILE_SCOPE();
using namespace VoxelToolOps;
switch (mode) {
case VoxelTool::MODE_ADD: {
@ -218,7 +217,7 @@ struct DoSphere {
}
};
} // namespace
} //namespace zylann::voxel::ops
void VoxelToolLodTerrain::do_sphere(Vector3 center, float radius) {
VOXEL_PROFILE_SCOPE();
@ -241,7 +240,7 @@ void VoxelToolLodTerrain::do_sphere(Vector3 center, float radius) {
preload_box(*data, box, _terrain->get_generator().ptr());
}
DoSphere op;
ops::DoSphere op;
op.box = box;
op.center = center;
op.mode = get_mode();
@ -257,13 +256,15 @@ void VoxelToolLodTerrain::do_sphere(Vector3 center, float radius) {
_post_edit(box);
}
template <typename Op_T> class VoxelToolAsyncEdit : public zylann::IThreadedTask {
namespace zylann::voxel {
template <typename Op_T> class VoxelToolAsyncEdit : public IThreadedTask {
public:
VoxelToolAsyncEdit(Op_T op, std::shared_ptr<VoxelDataLodMap> data) : _op(op), _data(data) {
_tracker = gd_make_shared<zylann::AsyncDependencyTracker>(1);
}
void run(zylann::ThreadedTaskContext ctx) override {
void run(ThreadedTaskContext ctx) override {
VOXEL_PROFILE_SCOPE();
CRASH_COND(_data == nullptr);
VoxelDataLodMap::Lod &data_lod = _data->lods[0];
@ -281,7 +282,7 @@ public:
}
void apply_result() override {}
std::shared_ptr<zylann::AsyncDependencyTracker> get_tracker() {
std::shared_ptr<AsyncDependencyTracker> get_tracker() {
return _tracker;
}
@ -289,9 +290,11 @@ private:
Op_T _op;
// We reference this just to keep map pointers alive
std::shared_ptr<VoxelDataLodMap> _data;
std::shared_ptr<zylann::AsyncDependencyTracker> _tracker;
std::shared_ptr<AsyncDependencyTracker> _tracker;
};
} // namespace zylann::voxel
void VoxelToolLodTerrain::do_sphere_async(Vector3 center, float radius) {
ERR_FAIL_COND(_terrain == nullptr);
@ -307,7 +310,7 @@ void VoxelToolLodTerrain::do_sphere_async(Vector3 center, float radius) {
std::shared_ptr<VoxelDataLodMap> data = _terrain->get_storage();
ERR_FAIL_COND(data == nullptr);
DoSphere op;
ops::DoSphere op;
op.box = box;
op.center = center;
op.mode = get_mode();
@ -318,7 +321,7 @@ void VoxelToolLodTerrain::do_sphere_async(Vector3 center, float radius) {
// TODO How do I use unique_ptr with Godot's memnew/memdelete instead?
// (without having to mention it everywhere I pass this around)
VoxelToolAsyncEdit<DoSphere> *task = memnew(VoxelToolAsyncEdit<DoSphere>(op, data));
VoxelToolAsyncEdit<ops::DoSphere> *task = memnew(VoxelToolAsyncEdit<ops::DoSphere>(op, data));
_terrain->push_async_edit(task, op.box, task->get_tracker());
}

View File

@ -6,6 +6,7 @@
#include "../util/voxel_raycast.h"
using namespace zylann;
using namespace voxel;
VoxelToolTerrain::VoxelToolTerrain() {}
@ -174,7 +175,7 @@ void VoxelToolTerrain::do_sphere(Vector3 center, float radius) {
}
_terrain->get_storage().write_box_2(box, VoxelBuffer::CHANNEL_INDICES, VoxelBuffer::CHANNEL_WEIGHTS,
VoxelToolOps::TextureBlendSphereOp{ center, radius, _texture_params });
ops::TextureBlendSphereOp{ center, radius, _texture_params });
_post_edit(box);
}