Re-namespaced VoxelToolOps
parent
3eb6641c4f
commit
1d63067b6b
|
@ -9,9 +9,7 @@
|
||||||
|
|
||||||
class VoxelBuffer;
|
class VoxelBuffer;
|
||||||
|
|
||||||
using namespace zylann;
|
namespace zylann::voxel::ops {
|
||||||
|
|
||||||
namespace VoxelToolOps {
|
|
||||||
|
|
||||||
template <typename Op, typename Shape> struct SdfOperation16bit {
|
template <typename Op, typename Shape> struct SdfOperation16bit {
|
||||||
Op op;
|
Op op;
|
||||||
|
@ -74,12 +72,12 @@ struct TextureBlendSphereOp {
|
||||||
const float distance_from_radius = radius - Math::sqrt(distance_squared);
|
const float distance_from_radius = radius - Math::sqrt(distance_squared);
|
||||||
const float target_weight =
|
const float target_weight =
|
||||||
tp.opacity * math::clamp(tp.sharpness * (distance_from_radius / radius), 0.f, 1.f);
|
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
|
// TODO Need to review VoxelTool to account for transformed volumes
|
||||||
|
|
||||||
|
@ -223,7 +221,7 @@ protected:
|
||||||
Mode _mode = MODE_ADD;
|
Mode _mode = MODE_ADD;
|
||||||
|
|
||||||
// Used on smooth terrain
|
// Used on smooth terrain
|
||||||
VoxelToolOps::TextureParams _texture_params;
|
zylann::voxel::ops::TextureParams _texture_params;
|
||||||
};
|
};
|
||||||
|
|
||||||
VARIANT_ENUM_CAST(VoxelTool::Mode)
|
VARIANT_ENUM_CAST(VoxelTool::Mode)
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
#include "../util/profiling.h"
|
#include "../util/profiling.h"
|
||||||
#include "funcs.h"
|
#include "funcs.h"
|
||||||
|
|
||||||
|
using namespace zylann;
|
||||||
|
using namespace voxel;
|
||||||
|
|
||||||
VoxelToolBuffer::VoxelToolBuffer(Ref<VoxelBuffer> vb) {
|
VoxelToolBuffer::VoxelToolBuffer(Ref<VoxelBuffer> vb) {
|
||||||
ERR_FAIL_COND(vb.is_null());
|
ERR_FAIL_COND(vb.is_null());
|
||||||
_buffer = vb;
|
_buffer = vb;
|
||||||
|
@ -28,9 +31,9 @@ void VoxelToolBuffer::do_sphere(Vector3 center, float radius) {
|
||||||
Vector3iUtil::create(Math::ceil(radius) * 2));
|
Vector3iUtil::create(Math::ceil(radius) * 2));
|
||||||
box.clip(Box3i(Vector3i(), _buffer->get_buffer().get_size()));
|
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,
|
VoxelBufferInternal::CHANNEL_INDICES, VoxelBufferInternal::CHANNEL_WEIGHTS,
|
||||||
VoxelToolOps::TextureBlendSphereOp(center, radius, _texture_params), Vector3i());
|
ops::TextureBlendSphereOp(center, radius, _texture_params), Vector3i());
|
||||||
|
|
||||||
_post_edit(box);
|
_post_edit(box);
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,7 +165,7 @@ Ref<VoxelRaycastResult> VoxelToolLodTerrain::raycast(
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace zylann::voxel::ops {
|
||||||
|
|
||||||
struct DoSphere {
|
struct DoSphere {
|
||||||
Vector3 center;
|
Vector3 center;
|
||||||
|
@ -174,11 +174,10 @@ struct DoSphere {
|
||||||
VoxelDataGrid blocks;
|
VoxelDataGrid blocks;
|
||||||
float sdf_scale;
|
float sdf_scale;
|
||||||
Box3i box;
|
Box3i box;
|
||||||
VoxelToolOps::TextureParams texture_params;
|
TextureParams texture_params;
|
||||||
|
|
||||||
void operator()() {
|
void operator()() {
|
||||||
VOXEL_PROFILE_SCOPE();
|
VOXEL_PROFILE_SCOPE();
|
||||||
using namespace VoxelToolOps;
|
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case VoxelTool::MODE_ADD: {
|
case VoxelTool::MODE_ADD: {
|
||||||
|
@ -218,7 +217,7 @@ struct DoSphere {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} //namespace zylann::voxel::ops
|
||||||
|
|
||||||
void VoxelToolLodTerrain::do_sphere(Vector3 center, float radius) {
|
void VoxelToolLodTerrain::do_sphere(Vector3 center, float radius) {
|
||||||
VOXEL_PROFILE_SCOPE();
|
VOXEL_PROFILE_SCOPE();
|
||||||
|
@ -241,7 +240,7 @@ void VoxelToolLodTerrain::do_sphere(Vector3 center, float radius) {
|
||||||
preload_box(*data, box, _terrain->get_generator().ptr());
|
preload_box(*data, box, _terrain->get_generator().ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
DoSphere op;
|
ops::DoSphere op;
|
||||||
op.box = box;
|
op.box = box;
|
||||||
op.center = center;
|
op.center = center;
|
||||||
op.mode = get_mode();
|
op.mode = get_mode();
|
||||||
|
@ -257,13 +256,15 @@ void VoxelToolLodTerrain::do_sphere(Vector3 center, float radius) {
|
||||||
_post_edit(box);
|
_post_edit(box);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Op_T> class VoxelToolAsyncEdit : public zylann::IThreadedTask {
|
namespace zylann::voxel {
|
||||||
|
|
||||||
|
template <typename Op_T> class VoxelToolAsyncEdit : public IThreadedTask {
|
||||||
public:
|
public:
|
||||||
VoxelToolAsyncEdit(Op_T op, std::shared_ptr<VoxelDataLodMap> data) : _op(op), _data(data) {
|
VoxelToolAsyncEdit(Op_T op, std::shared_ptr<VoxelDataLodMap> data) : _op(op), _data(data) {
|
||||||
_tracker = gd_make_shared<zylann::AsyncDependencyTracker>(1);
|
_tracker = gd_make_shared<zylann::AsyncDependencyTracker>(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void run(zylann::ThreadedTaskContext ctx) override {
|
void run(ThreadedTaskContext ctx) override {
|
||||||
VOXEL_PROFILE_SCOPE();
|
VOXEL_PROFILE_SCOPE();
|
||||||
CRASH_COND(_data == nullptr);
|
CRASH_COND(_data == nullptr);
|
||||||
VoxelDataLodMap::Lod &data_lod = _data->lods[0];
|
VoxelDataLodMap::Lod &data_lod = _data->lods[0];
|
||||||
|
@ -281,7 +282,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void apply_result() override {}
|
void apply_result() override {}
|
||||||
std::shared_ptr<zylann::AsyncDependencyTracker> get_tracker() {
|
std::shared_ptr<AsyncDependencyTracker> get_tracker() {
|
||||||
return _tracker;
|
return _tracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,9 +290,11 @@ private:
|
||||||
Op_T _op;
|
Op_T _op;
|
||||||
// We reference this just to keep map pointers alive
|
// We reference this just to keep map pointers alive
|
||||||
std::shared_ptr<VoxelDataLodMap> _data;
|
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) {
|
void VoxelToolLodTerrain::do_sphere_async(Vector3 center, float radius) {
|
||||||
ERR_FAIL_COND(_terrain == nullptr);
|
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();
|
std::shared_ptr<VoxelDataLodMap> data = _terrain->get_storage();
|
||||||
ERR_FAIL_COND(data == nullptr);
|
ERR_FAIL_COND(data == nullptr);
|
||||||
|
|
||||||
DoSphere op;
|
ops::DoSphere op;
|
||||||
op.box = box;
|
op.box = box;
|
||||||
op.center = center;
|
op.center = center;
|
||||||
op.mode = get_mode();
|
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?
|
// TODO How do I use unique_ptr with Godot's memnew/memdelete instead?
|
||||||
// (without having to mention it everywhere I pass this around)
|
// (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());
|
_terrain->push_async_edit(task, op.box, task->get_tracker());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "../util/voxel_raycast.h"
|
#include "../util/voxel_raycast.h"
|
||||||
|
|
||||||
using namespace zylann;
|
using namespace zylann;
|
||||||
|
using namespace voxel;
|
||||||
|
|
||||||
VoxelToolTerrain::VoxelToolTerrain() {}
|
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,
|
_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);
|
_post_edit(box);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue