2016-05-01 06:00:02 -07:00
|
|
|
#include "voxel_buffer.h"
|
2018-09-29 17:55:09 -07:00
|
|
|
|
2018-09-19 12:25:04 -07:00
|
|
|
#include <core/math/math_funcs.h>
|
2017-08-12 16:19:39 -07:00
|
|
|
#include <string.h>
|
2016-05-01 06:00:02 -07:00
|
|
|
|
2019-05-29 16:46:08 -07:00
|
|
|
const char *VoxelBuffer::CHANNEL_ID_HINT_STRING = "Type,Sdf,Data2,Data3,Data4,Data5,Data6,Data7";
|
|
|
|
|
2016-05-01 06:00:02 -07:00
|
|
|
VoxelBuffer::VoxelBuffer() {
|
2019-04-27 16:23:10 -07:00
|
|
|
_channels[CHANNEL_ISOLEVEL].defval = 255;
|
2016-05-01 06:00:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
VoxelBuffer::~VoxelBuffer() {
|
2016-12-31 19:40:16 -08:00
|
|
|
clear();
|
2016-05-01 06:00:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelBuffer::create(int sx, int sy, int sz) {
|
2016-12-31 19:40:16 -08:00
|
|
|
if (sx <= 0 || sy <= 0 || sz <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Vector3i new_size(sx, sy, sz);
|
|
|
|
if (new_size != _size) {
|
|
|
|
for (unsigned int i = 0; i < MAX_CHANNELS; ++i) {
|
2017-08-12 16:19:39 -07:00
|
|
|
Channel &channel = _channels[i];
|
2016-12-31 19:40:16 -08:00
|
|
|
if (channel.data) {
|
2019-04-22 12:15:19 -07:00
|
|
|
// Channel already contained data
|
2016-12-31 19:40:16 -08:00
|
|
|
// TODO Optimize with realloc
|
2017-01-04 17:39:40 -08:00
|
|
|
delete_channel(i);
|
2019-04-22 12:15:19 -07:00
|
|
|
create_channel(i, new_size, channel.defval);
|
2016-12-31 19:40:16 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_size = new_size;
|
|
|
|
}
|
2016-05-01 06:00:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelBuffer::clear() {
|
2016-12-31 19:40:16 -08:00
|
|
|
for (unsigned int i = 0; i < MAX_CHANNELS; ++i) {
|
2017-08-12 16:19:39 -07:00
|
|
|
Channel &channel = _channels[i];
|
2016-12-31 19:40:16 -08:00
|
|
|
if (channel.data) {
|
2017-01-04 17:39:40 -08:00
|
|
|
delete_channel(i);
|
2016-12-31 19:40:16 -08:00
|
|
|
}
|
|
|
|
}
|
2016-05-01 06:00:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelBuffer::clear_channel(unsigned int channel_index, int clear_value) {
|
2016-12-31 19:40:16 -08:00
|
|
|
ERR_FAIL_INDEX(channel_index, MAX_CHANNELS);
|
2019-04-21 11:31:35 -07:00
|
|
|
if (_channels[channel_index].data) {
|
2017-01-04 17:39:40 -08:00
|
|
|
delete_channel(channel_index);
|
2019-04-21 11:31:35 -07:00
|
|
|
}
|
2016-12-31 19:40:16 -08:00
|
|
|
_channels[channel_index].defval = clear_value;
|
2016-05-01 06:00:02 -07:00
|
|
|
}
|
|
|
|
|
2017-01-04 17:39:40 -08:00
|
|
|
void VoxelBuffer::set_default_values(uint8_t values[VoxelBuffer::MAX_CHANNELS]) {
|
2017-08-12 16:19:39 -07:00
|
|
|
for (unsigned int i = 0; i < MAX_CHANNELS; ++i) {
|
2017-01-04 17:39:40 -08:00
|
|
|
_channels[i].defval = values[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-01 06:00:02 -07:00
|
|
|
int VoxelBuffer::get_voxel(int x, int y, int z, unsigned int channel_index) const {
|
2017-01-04 17:39:40 -08:00
|
|
|
ERR_FAIL_INDEX_V(channel_index, MAX_CHANNELS, 0);
|
2016-12-31 19:40:16 -08:00
|
|
|
|
2017-08-12 16:19:39 -07:00
|
|
|
const Channel &channel = _channels[channel_index];
|
2016-12-31 19:40:16 -08:00
|
|
|
|
|
|
|
if (validate_pos(x, y, z) && channel.data) {
|
2017-08-12 16:19:39 -07:00
|
|
|
return channel.data[index(x, y, z)];
|
|
|
|
} else {
|
2016-12-31 19:40:16 -08:00
|
|
|
return channel.defval;
|
|
|
|
}
|
2016-05-01 06:00:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelBuffer::set_voxel(int value, int x, int y, int z, unsigned int channel_index) {
|
2017-08-12 16:19:39 -07:00
|
|
|
ERR_FAIL_INDEX(channel_index, MAX_CHANNELS);
|
2016-12-31 19:40:16 -08:00
|
|
|
ERR_FAIL_COND(!validate_pos(x, y, z));
|
2016-05-01 06:00:02 -07:00
|
|
|
|
2017-08-12 16:19:39 -07:00
|
|
|
Channel &channel = _channels[channel_index];
|
2016-05-01 06:00:02 -07:00
|
|
|
|
2017-03-29 13:36:42 -07:00
|
|
|
if (channel.data == NULL) {
|
|
|
|
if (channel.defval != value) {
|
2019-04-22 12:15:19 -07:00
|
|
|
// Allocate channel with same initial values as defval
|
|
|
|
create_channel(channel_index, _size, channel.defval);
|
2017-03-29 13:36:42 -07:00
|
|
|
channel.data[index(x, y, z)] = value;
|
2016-12-31 19:40:16 -08:00
|
|
|
}
|
2017-08-12 16:19:39 -07:00
|
|
|
} else {
|
2017-03-29 13:36:42 -07:00
|
|
|
channel.data[index(x, y, z)] = value;
|
2016-12-31 19:40:16 -08:00
|
|
|
}
|
2016-05-01 06:00:02 -07:00
|
|
|
}
|
|
|
|
|
2018-10-04 15:13:03 -07:00
|
|
|
// This version does not cause errors if out of bounds. Use only if it's okay to be outside.
|
|
|
|
void VoxelBuffer::try_set_voxel(int x, int y, int z, int value, unsigned int channel_index) {
|
|
|
|
ERR_FAIL_INDEX(channel_index, MAX_CHANNELS);
|
2019-04-21 11:31:35 -07:00
|
|
|
if (!validate_pos(x, y, z)) {
|
2018-10-04 15:13:03 -07:00
|
|
|
return;
|
2019-04-21 11:31:35 -07:00
|
|
|
}
|
2018-10-04 15:13:03 -07:00
|
|
|
|
|
|
|
Channel &channel = _channels[channel_index];
|
|
|
|
|
|
|
|
if (channel.data == NULL) {
|
|
|
|
if (channel.defval != value) {
|
2019-04-22 12:15:19 -07:00
|
|
|
create_channel(channel_index, _size, channel.defval);
|
2018-10-04 15:13:03 -07:00
|
|
|
channel.data[index(x, y, z)] = value;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
channel.data[index(x, y, z)] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-01 06:00:02 -07:00
|
|
|
void VoxelBuffer::set_voxel_v(int value, Vector3 pos, unsigned int channel_index) {
|
2016-12-31 19:40:16 -08:00
|
|
|
set_voxel(value, pos.x, pos.y, pos.z, channel_index);
|
2016-05-01 06:00:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelBuffer::fill(int defval, unsigned int channel_index) {
|
2016-12-31 19:40:16 -08:00
|
|
|
ERR_FAIL_INDEX(channel_index, MAX_CHANNELS);
|
2016-05-05 12:08:52 -07:00
|
|
|
|
2017-08-12 16:19:39 -07:00
|
|
|
Channel &channel = _channels[channel_index];
|
2018-09-02 10:48:08 -07:00
|
|
|
if (channel.data == NULL) {
|
|
|
|
// Channel is already optimized and uniform
|
2019-04-20 09:32:10 -07:00
|
|
|
if (channel.defval == defval) {
|
2018-09-02 10:48:08 -07:00
|
|
|
// No change
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
// Just change default value
|
|
|
|
channel.defval = defval;
|
|
|
|
return;
|
|
|
|
}
|
2019-04-21 11:31:35 -07:00
|
|
|
} else {
|
2016-12-31 19:40:16 -08:00
|
|
|
create_channel_noinit(channel_index, _size);
|
2019-04-21 11:31:35 -07:00
|
|
|
}
|
2016-05-05 12:08:52 -07:00
|
|
|
|
2016-12-31 19:40:16 -08:00
|
|
|
unsigned int volume = get_volume();
|
|
|
|
memset(channel.data, defval, volume);
|
2016-05-01 06:00:02 -07:00
|
|
|
}
|
|
|
|
|
2016-05-05 12:08:52 -07:00
|
|
|
void VoxelBuffer::fill_area(int defval, Vector3i min, Vector3i max, unsigned int channel_index) {
|
2016-12-31 19:40:16 -08:00
|
|
|
ERR_FAIL_INDEX(channel_index, MAX_CHANNELS);
|
|
|
|
|
|
|
|
Vector3i::sort_min_max(min, max);
|
|
|
|
|
2018-10-04 15:13:03 -07:00
|
|
|
min.clamp_to(Vector3i(0, 0, 0), _size + Vector3i(1, 1, 1));
|
2017-08-12 16:19:39 -07:00
|
|
|
max.clamp_to(Vector3i(0, 0, 0), _size + Vector3i(1, 1, 1));
|
2016-12-31 19:40:16 -08:00
|
|
|
Vector3i area_size = max - min;
|
|
|
|
|
2019-04-21 11:31:35 -07:00
|
|
|
if (area_size.x == 0 || area_size.y == 0 || area_size.z == 0) {
|
2018-10-04 15:13:03 -07:00
|
|
|
return;
|
2019-04-21 11:31:35 -07:00
|
|
|
}
|
2018-10-04 15:13:03 -07:00
|
|
|
|
2017-08-12 16:19:39 -07:00
|
|
|
Channel &channel = _channels[channel_index];
|
2016-12-31 19:40:16 -08:00
|
|
|
if (channel.data == NULL) {
|
2019-04-21 11:31:35 -07:00
|
|
|
if (channel.defval == defval) {
|
2016-12-31 19:40:16 -08:00
|
|
|
return;
|
2019-04-21 11:31:35 -07:00
|
|
|
} else {
|
2019-04-22 12:15:19 -07:00
|
|
|
create_channel(channel_index, _size, channel.defval);
|
2019-04-21 11:31:35 -07:00
|
|
|
}
|
2016-12-31 19:40:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector3i pos;
|
2019-06-17 22:24:56 -07:00
|
|
|
unsigned int volume = get_volume();
|
2016-12-31 19:40:16 -08:00
|
|
|
for (pos.z = min.z; pos.z < max.z; ++pos.z) {
|
|
|
|
for (pos.x = min.x; pos.x < max.x; ++pos.x) {
|
|
|
|
unsigned int dst_ri = index(pos.x, pos.y + min.y, pos.z);
|
2018-10-04 15:13:03 -07:00
|
|
|
CRASH_COND(dst_ri >= volume);
|
2016-12-31 19:40:16 -08:00
|
|
|
memset(&channel.data[dst_ri], defval, area_size.y * sizeof(uint8_t));
|
|
|
|
}
|
|
|
|
}
|
2016-05-05 12:08:52 -07:00
|
|
|
}
|
|
|
|
|
2017-04-06 14:44:11 -07:00
|
|
|
bool VoxelBuffer::is_uniform(unsigned int channel_index) const {
|
2016-12-31 19:40:16 -08:00
|
|
|
ERR_FAIL_INDEX_V(channel_index, MAX_CHANNELS, true);
|
|
|
|
|
2017-08-12 16:19:39 -07:00
|
|
|
const Channel &channel = _channels[channel_index];
|
2019-04-21 11:31:35 -07:00
|
|
|
if (channel.data == NULL) {
|
2017-08-27 16:47:38 -07:00
|
|
|
// Channel has been optimized
|
2016-12-31 19:40:16 -08:00
|
|
|
return true;
|
2019-04-21 11:31:35 -07:00
|
|
|
}
|
2016-12-31 19:40:16 -08:00
|
|
|
|
2017-08-27 16:47:38 -07:00
|
|
|
// Channel isn't optimized, so must look at each voxel
|
2016-12-31 19:40:16 -08:00
|
|
|
uint8_t voxel = channel.data[0];
|
|
|
|
unsigned int volume = get_volume();
|
2018-09-02 10:48:08 -07:00
|
|
|
for (unsigned int i = 1; i < volume; ++i) {
|
2016-12-31 19:40:16 -08:00
|
|
|
if (channel.data[i] != voxel) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-05-01 06:00:02 -07:00
|
|
|
}
|
|
|
|
|
2019-05-25 07:51:59 -07:00
|
|
|
void VoxelBuffer::compress_uniform_channels() {
|
2016-12-31 19:40:16 -08:00
|
|
|
for (unsigned int i = 0; i < MAX_CHANNELS; ++i) {
|
|
|
|
if (_channels[i].data && is_uniform(i)) {
|
|
|
|
clear_channel(i, _channels[i].data[0]);
|
|
|
|
}
|
|
|
|
}
|
2016-05-01 06:00:02 -07:00
|
|
|
}
|
|
|
|
|
2019-05-27 16:40:09 -07:00
|
|
|
void VoxelBuffer::decompress_channel(unsigned int channel_index) {
|
|
|
|
ERR_FAIL_INDEX(channel_index, MAX_CHANNELS);
|
|
|
|
Channel channel = _channels[channel_index];
|
|
|
|
if (channel.data == nullptr) {
|
|
|
|
create_channel(channel_index, _size, channel.defval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VoxelBuffer::Compression VoxelBuffer::get_channel_compression(unsigned int channel_index) const {
|
|
|
|
ERR_FAIL_INDEX_V(channel_index, MAX_CHANNELS, VoxelBuffer::COMPRESSION_NONE);
|
|
|
|
Channel channel = _channels[channel_index];
|
|
|
|
if (channel.data == nullptr) {
|
|
|
|
return COMPRESSION_UNIFORM;
|
|
|
|
}
|
|
|
|
return COMPRESSION_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelBuffer::grab_channel_data(uint8_t *in_buffer, unsigned int channel_index, Compression compression) {
|
|
|
|
CRASH_COND(channel_index >= MAX_CHANNELS);
|
|
|
|
|
|
|
|
// Only case supported at the moment
|
|
|
|
CRASH_COND(in_buffer == nullptr);
|
|
|
|
CRASH_COND(compression != COMPRESSION_NONE);
|
|
|
|
|
|
|
|
Channel &channel = _channels[channel_index];
|
|
|
|
if (channel.data) {
|
|
|
|
delete_channel(channel_index);
|
|
|
|
}
|
|
|
|
// Takes ownership of the provided buffer
|
|
|
|
channel.data = in_buffer;
|
|
|
|
}
|
|
|
|
|
2017-08-12 16:19:39 -07:00
|
|
|
void VoxelBuffer::copy_from(const VoxelBuffer &other, unsigned int channel_index) {
|
2016-12-31 19:40:16 -08:00
|
|
|
ERR_FAIL_INDEX(channel_index, MAX_CHANNELS);
|
|
|
|
ERR_FAIL_COND(other._size == _size);
|
|
|
|
|
2017-08-12 16:19:39 -07:00
|
|
|
Channel &channel = _channels[channel_index];
|
|
|
|
const Channel &other_channel = other._channels[channel_index];
|
2016-12-31 19:40:16 -08:00
|
|
|
|
|
|
|
if (other_channel.data) {
|
|
|
|
if (channel.data == NULL) {
|
|
|
|
create_channel_noinit(channel_index, _size);
|
|
|
|
}
|
|
|
|
memcpy(channel.data, other_channel.data, get_volume() * sizeof(uint8_t));
|
2017-08-12 16:19:39 -07:00
|
|
|
} else if (channel.data) {
|
2017-01-04 17:39:40 -08:00
|
|
|
delete_channel(channel_index);
|
2016-12-31 19:40:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
channel.defval = other_channel.defval;
|
2016-05-05 12:08:52 -07:00
|
|
|
}
|
|
|
|
|
2017-08-12 16:19:39 -07:00
|
|
|
void VoxelBuffer::copy_from(const VoxelBuffer &other, Vector3i src_min, Vector3i src_max, Vector3i dst_min, unsigned int channel_index) {
|
2017-03-29 13:36:42 -07:00
|
|
|
|
2016-12-31 19:40:16 -08:00
|
|
|
ERR_FAIL_INDEX(channel_index, MAX_CHANNELS);
|
|
|
|
|
2017-08-12 16:19:39 -07:00
|
|
|
Channel &channel = _channels[channel_index];
|
|
|
|
const Channel &other_channel = other._channels[channel_index];
|
2016-12-31 19:40:16 -08:00
|
|
|
|
|
|
|
Vector3i::sort_min_max(src_min, src_max);
|
|
|
|
|
|
|
|
src_min.clamp_to(Vector3i(0, 0, 0), other._size);
|
2017-08-12 16:19:39 -07:00
|
|
|
src_max.clamp_to(Vector3i(0, 0, 0), other._size + Vector3i(1, 1, 1));
|
2016-12-31 19:40:16 -08:00
|
|
|
|
|
|
|
dst_min.clamp_to(Vector3i(0, 0, 0), _size);
|
|
|
|
Vector3i area_size = src_max - src_min;
|
|
|
|
//Vector3i dst_max = dst_min + area_size;
|
|
|
|
|
|
|
|
if (area_size == _size) {
|
|
|
|
copy_from(other, channel_index);
|
2017-08-12 16:19:39 -07:00
|
|
|
} else {
|
2016-12-31 19:40:16 -08:00
|
|
|
if (other_channel.data) {
|
|
|
|
if (channel.data == NULL) {
|
2019-04-22 12:15:19 -07:00
|
|
|
create_channel(channel_index, _size, channel.defval);
|
2016-12-31 19:40:16 -08:00
|
|
|
}
|
|
|
|
// Copy row by row
|
|
|
|
Vector3i pos;
|
|
|
|
for (pos.z = 0; pos.z < area_size.z; ++pos.z) {
|
|
|
|
for (pos.x = 0; pos.x < area_size.x; ++pos.x) {
|
|
|
|
// Row direction is Y
|
|
|
|
unsigned int src_ri = other.index(pos.x + src_min.x, pos.y + src_min.y, pos.z + src_min.z);
|
|
|
|
unsigned int dst_ri = index(pos.x + dst_min.x, pos.y + dst_min.y, pos.z + dst_min.z);
|
|
|
|
memcpy(&channel.data[dst_ri], &other_channel.data[src_ri], area_size.y * sizeof(uint8_t));
|
|
|
|
}
|
|
|
|
}
|
2017-08-12 16:19:39 -07:00
|
|
|
} else if (channel.defval != other_channel.defval) {
|
2016-12-31 19:40:16 -08:00
|
|
|
if (channel.data == NULL) {
|
2019-04-22 12:15:19 -07:00
|
|
|
create_channel(channel_index, _size, channel.defval);
|
2016-12-31 19:40:16 -08:00
|
|
|
}
|
|
|
|
// Set row by row
|
|
|
|
Vector3i pos;
|
|
|
|
for (pos.z = 0; pos.z < area_size.z; ++pos.z) {
|
|
|
|
for (pos.x = 0; pos.x < area_size.x; ++pos.x) {
|
|
|
|
unsigned int dst_ri = index(pos.x + dst_min.x, pos.y + dst_min.y, pos.z + dst_min.z);
|
|
|
|
memset(&channel.data[dst_ri], other_channel.defval, area_size.y * sizeof(uint8_t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-05 12:08:52 -07:00
|
|
|
}
|
|
|
|
|
2019-05-27 16:40:09 -07:00
|
|
|
Ref<VoxelBuffer> VoxelBuffer::duplicate() const {
|
|
|
|
VoxelBuffer *d = memnew(VoxelBuffer);
|
|
|
|
d->copy_from(*this);
|
|
|
|
return Ref<VoxelBuffer>(d);
|
|
|
|
}
|
|
|
|
|
2018-09-29 17:55:09 -07:00
|
|
|
uint8_t *VoxelBuffer::get_channel_raw(unsigned int channel_index) const {
|
|
|
|
ERR_FAIL_INDEX_V(channel_index, MAX_CHANNELS, NULL);
|
|
|
|
const Channel &channel = _channels[channel_index];
|
|
|
|
return channel.data;
|
|
|
|
}
|
|
|
|
|
2016-05-01 06:00:02 -07:00
|
|
|
void VoxelBuffer::create_channel(int i, Vector3i size, uint8_t defval) {
|
2016-12-31 19:40:16 -08:00
|
|
|
create_channel_noinit(i, size);
|
|
|
|
memset(_channels[i].data, defval, get_volume() * sizeof(uint8_t));
|
2016-05-05 12:08:52 -07:00
|
|
|
}
|
2016-05-01 06:00:02 -07:00
|
|
|
|
2016-05-05 12:08:52 -07:00
|
|
|
void VoxelBuffer::create_channel_noinit(int i, Vector3i size) {
|
2017-08-12 16:19:39 -07:00
|
|
|
Channel &channel = _channels[i];
|
2016-12-31 19:40:16 -08:00
|
|
|
unsigned int volume = size.x * size.y * size.z;
|
2017-08-12 16:19:39 -07:00
|
|
|
channel.data = (uint8_t *)memalloc(volume * sizeof(uint8_t));
|
2016-05-01 06:00:02 -07:00
|
|
|
}
|
|
|
|
|
2017-01-04 17:39:40 -08:00
|
|
|
void VoxelBuffer::delete_channel(int i) {
|
2017-08-12 16:19:39 -07:00
|
|
|
Channel &channel = _channels[i];
|
2017-01-04 17:39:40 -08:00
|
|
|
ERR_FAIL_COND(channel.data == NULL);
|
2016-12-31 19:40:16 -08:00
|
|
|
memfree(channel.data);
|
|
|
|
channel.data = NULL;
|
2016-05-01 06:00:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelBuffer::_bind_methods() {
|
|
|
|
|
2017-03-24 17:23:36 -07:00
|
|
|
ClassDB::bind_method(D_METHOD("create", "sx", "sy", "sz"), &VoxelBuffer::create);
|
|
|
|
ClassDB::bind_method(D_METHOD("clear"), &VoxelBuffer::clear);
|
2016-05-01 06:00:02 -07:00
|
|
|
|
2019-04-26 18:06:09 -07:00
|
|
|
ClassDB::bind_method(D_METHOD("get_size"), &VoxelBuffer::_get_size_binding);
|
2017-03-24 17:23:36 -07:00
|
|
|
ClassDB::bind_method(D_METHOD("get_size_x"), &VoxelBuffer::get_size_x);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_size_y"), &VoxelBuffer::get_size_y);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_size_z"), &VoxelBuffer::get_size_z);
|
2016-05-01 06:00:02 -07:00
|
|
|
|
2017-03-24 17:23:36 -07:00
|
|
|
ClassDB::bind_method(D_METHOD("set_voxel", "value", "x", "y", "z", "channel"), &VoxelBuffer::_set_voxel_binding, DEFVAL(0));
|
2019-04-28 08:28:49 -07:00
|
|
|
ClassDB::bind_method(D_METHOD("set_voxel_f", "value", "x", "y", "z", "channel"), &VoxelBuffer::_set_voxel_f_binding, DEFVAL(0));
|
2017-03-24 17:23:36 -07:00
|
|
|
ClassDB::bind_method(D_METHOD("set_voxel_v", "value", "pos", "channel"), &VoxelBuffer::set_voxel_v, DEFVAL(0));
|
|
|
|
ClassDB::bind_method(D_METHOD("get_voxel", "x", "y", "z", "channel"), &VoxelBuffer::_get_voxel_binding, DEFVAL(0));
|
2019-04-28 08:28:49 -07:00
|
|
|
ClassDB::bind_method(D_METHOD("get_voxel_f", "x", "y", "z", "channel"), &VoxelBuffer::get_voxel_f, DEFVAL(0));
|
2016-05-01 06:00:02 -07:00
|
|
|
|
2017-03-24 17:23:36 -07:00
|
|
|
ClassDB::bind_method(D_METHOD("fill", "value", "channel"), &VoxelBuffer::fill, DEFVAL(0));
|
2019-04-28 08:28:49 -07:00
|
|
|
ClassDB::bind_method(D_METHOD("fill_f", "value", "channel"), &VoxelBuffer::fill_f, DEFVAL(0));
|
2017-03-24 17:23:36 -07:00
|
|
|
ClassDB::bind_method(D_METHOD("fill_area", "value", "min", "max", "channel"), &VoxelBuffer::_fill_area_binding, DEFVAL(0));
|
2017-08-12 15:08:53 -07:00
|
|
|
ClassDB::bind_method(D_METHOD("copy_from", "other", "channel"), &VoxelBuffer::_copy_from_binding, DEFVAL(0));
|
|
|
|
ClassDB::bind_method(D_METHOD("copy_from_area", "other", "src_min", "src_max", "dst_min", "channel"), &VoxelBuffer::_copy_from_area_binding, DEFVAL(0));
|
2016-05-01 06:00:02 -07:00
|
|
|
|
2019-04-27 16:27:17 -07:00
|
|
|
ClassDB::bind_method(D_METHOD("is_uniform", "channel"), &VoxelBuffer::is_uniform);
|
2019-05-25 07:51:59 -07:00
|
|
|
ClassDB::bind_method(D_METHOD("optimize"), &VoxelBuffer::compress_uniform_channels);
|
2019-04-21 11:31:35 -07:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(CHANNEL_TYPE);
|
|
|
|
BIND_ENUM_CONSTANT(CHANNEL_ISOLEVEL);
|
|
|
|
BIND_ENUM_CONSTANT(CHANNEL_DATA2);
|
|
|
|
BIND_ENUM_CONSTANT(CHANNEL_DATA3);
|
2019-04-22 13:17:19 -07:00
|
|
|
BIND_ENUM_CONSTANT(CHANNEL_DATA4);
|
|
|
|
BIND_ENUM_CONSTANT(CHANNEL_DATA5);
|
|
|
|
BIND_ENUM_CONSTANT(CHANNEL_DATA6);
|
|
|
|
BIND_ENUM_CONSTANT(CHANNEL_DATA7);
|
2019-04-21 11:31:35 -07:00
|
|
|
BIND_ENUM_CONSTANT(MAX_CHANNELS);
|
2016-05-01 06:00:02 -07:00
|
|
|
}
|
|
|
|
|
2016-05-05 12:08:52 -07:00
|
|
|
void VoxelBuffer::_copy_from_binding(Ref<VoxelBuffer> other, unsigned int channel) {
|
2016-12-31 19:40:16 -08:00
|
|
|
ERR_FAIL_COND(other.is_null());
|
|
|
|
copy_from(**other, channel);
|
2016-05-05 12:08:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelBuffer::_copy_from_area_binding(Ref<VoxelBuffer> other, Vector3 src_min, Vector3 src_max, Vector3 dst_min, unsigned int channel) {
|
2016-12-31 19:40:16 -08:00
|
|
|
ERR_FAIL_COND(other.is_null());
|
|
|
|
copy_from(**other, Vector3i(src_min), Vector3i(src_max), Vector3i(dst_min), channel);
|
2016-05-05 12:08:52 -07:00
|
|
|
}
|