mirror of
https://github.com/Relintai/godot_voxel.git
synced 2024-11-22 17:57:24 +01:00
Added VoxelIsoSurfaceTool::do_heightmap(), untested
This commit is contained in:
parent
1a4c6ec33d
commit
b3dd85bd36
@ -114,12 +114,44 @@ void VoxelIsoSurfaceTool::do_cube(Transform transform, Vector3 extents, Operatio
|
||||
for (int y = 0; y < buffer.get_size().y; ++y) {
|
||||
|
||||
Vector3 pos = inv_transform.xform(Vector3(x, y, z));
|
||||
do_op(buffer, x, y, z, sdf_cube(pos, extents), op);
|
||||
do_op(buffer, x, y, z, sdf_cube(pos, extents) * _iso_scale, op);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VoxelIsoSurfaceTool::do_heightmap(Ref<Image> heightmap, Vector3 offset, real_t vertical_scale, Operation op) {
|
||||
|
||||
ERR_FAIL_COND(_buffer.is_null());
|
||||
VoxelBuffer &buffer = **_buffer;
|
||||
|
||||
ERR_FAIL_COND(heightmap.is_null());
|
||||
Image &im = **heightmap;
|
||||
|
||||
offset += _offset;
|
||||
|
||||
im.lock();
|
||||
|
||||
for (int z = 0; z < buffer.get_size().z; ++z) {
|
||||
for (int x = 0; x < buffer.get_size().x; ++x) {
|
||||
|
||||
int px = int(Math::fmod(x + offset.x, im.get_width()));
|
||||
int py = int(Math::fmod(z + offset.z, im.get_height()));
|
||||
|
||||
float h = im.get_pixel(px, py).r * vertical_scale + offset.y;
|
||||
|
||||
for (int y = 0; y < buffer.get_size().y; ++y) {
|
||||
|
||||
// Not a true distance to heightmap, but might be enough
|
||||
float d = (y - h) * _iso_scale;
|
||||
do_op(buffer, x, y, z, d, op);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
im.unlock();
|
||||
}
|
||||
|
||||
void VoxelIsoSurfaceTool::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_buffer", "voxel_buffer"), &VoxelIsoSurfaceTool::set_buffer);
|
||||
@ -134,6 +166,7 @@ void VoxelIsoSurfaceTool::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("do_sphere", "center", "radius", "op"), &VoxelIsoSurfaceTool::do_sphere, DEFVAL(OP_ADD));
|
||||
ClassDB::bind_method(D_METHOD("do_plane", "plane", "op"), &VoxelIsoSurfaceTool::do_plane, DEFVAL(OP_ADD));
|
||||
ClassDB::bind_method(D_METHOD("do_cube", "transform", "extents", "op"), &VoxelIsoSurfaceTool::do_cube, DEFVAL(OP_ADD));
|
||||
ClassDB::bind_method(D_METHOD("do_heightmap", "heightmap", "offset", "vertical_scale", "op"), &VoxelIsoSurfaceTool::do_cube, DEFVAL(OP_ADD));
|
||||
|
||||
BIND_ENUM_CONSTANT(OP_ADD);
|
||||
BIND_ENUM_CONSTANT(OP_SUBTRACT);
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define VOXEL_ISOSURFACE_TOOL_H
|
||||
|
||||
#include "voxel_buffer.h"
|
||||
#include <core/image.h>
|
||||
|
||||
class VoxelIsoSurfaceTool : public Reference {
|
||||
GDCLASS(VoxelIsoSurfaceTool, Reference)
|
||||
@ -26,6 +27,7 @@ public:
|
||||
void do_sphere(Vector3 center, real_t radius, Operation op);
|
||||
void do_plane(Plane plane, Operation op);
|
||||
void do_cube(Transform transform, Vector3 extents, Operation op);
|
||||
void do_heightmap(Ref<Image> heightmap, Vector3 offset, real_t vertical_scale, Operation op);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
Loading…
Reference in New Issue
Block a user