mirror of
https://github.com/Relintai/godot_voxel.git
synced 2024-11-11 20:35:08 +01:00
Upgraded to Godot 3.0
This commit is contained in:
parent
06a399f932
commit
fa5e419549
@ -8,14 +8,14 @@
|
|||||||
|
|
||||||
void register_voxel_types() {
|
void register_voxel_types() {
|
||||||
|
|
||||||
ObjectTypeDB::register_type<Voxel>();
|
ClassDB::register_class<Voxel>();
|
||||||
ObjectTypeDB::register_type<VoxelBuffer>();
|
ClassDB::register_class<VoxelBuffer>();
|
||||||
ObjectTypeDB::register_type<VoxelMesher>();
|
ClassDB::register_class<VoxelMesher>();
|
||||||
ObjectTypeDB::register_type<VoxelLibrary>();
|
ClassDB::register_class<VoxelLibrary>();
|
||||||
ObjectTypeDB::register_type<VoxelMap>();
|
ClassDB::register_class<VoxelMap>();
|
||||||
ObjectTypeDB::register_type<VoxelTerrain>();
|
ClassDB::register_class<VoxelTerrain>();
|
||||||
ObjectTypeDB::register_type<VoxelProvider>();
|
ClassDB::register_class<VoxelProvider>();
|
||||||
ObjectTypeDB::register_type<VoxelProviderTest>();
|
ClassDB::register_class<VoxelProviderTest>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,8 +40,8 @@ struct Vector3i {
|
|||||||
return x*x + y*y + z*z;
|
return x*x + y*y + z*z;
|
||||||
}
|
}
|
||||||
|
|
||||||
_FORCE_INLINE_ float length() const {
|
_FORCE_INLINE_ real_t length() const {
|
||||||
return Math::sqrt(length_sq());
|
return Math::sqrt((real_t)length_sq());
|
||||||
}
|
}
|
||||||
|
|
||||||
_FORCE_INLINE_ Vector3i & operator=(const Vector3i & other) {
|
_FORCE_INLINE_ Vector3i & operator=(const Vector3i & other) {
|
||||||
|
30
voxel.cpp
30
voxel.cpp
@ -99,7 +99,7 @@ Ref<Voxel> Voxel::set_cube_geometry(float sy) {
|
|||||||
|
|
||||||
for (unsigned int side = 0; side < SIDE_COUNT; ++side) {
|
for (unsigned int side = 0; side < SIDE_COUNT; ++side) {
|
||||||
_model_side_vertices[side].resize(6);
|
_model_side_vertices[side].resize(6);
|
||||||
DVector<Vector3>::Write w = _model_side_vertices[side].write();
|
PoolVector<Vector3>::Write w = _model_side_vertices[side].write();
|
||||||
for (unsigned int i = 0; i < 6; ++i) {
|
for (unsigned int i = 0; i < 6; ++i) {
|
||||||
w[i] = vertices[side][i];
|
w[i] = vertices[side][i];
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ Ref<Voxel> Voxel::_set_cube_uv_sides(const Vector2 atlas_pos[6]) {
|
|||||||
|
|
||||||
for (unsigned int side = 0; side < SIDE_COUNT; ++side) {
|
for (unsigned int side = 0; side < SIDE_COUNT; ++side) {
|
||||||
_model_side_uv[side].resize(6);
|
_model_side_uv[side].resize(6);
|
||||||
DVector<Vector2>::Write w = _model_side_uv[side].write();
|
PoolVector<Vector2>::Write w = _model_side_uv[side].write();
|
||||||
for (unsigned int i = 0; i < 6; ++i) {
|
for (unsigned int i = 0; i < 6; ++i) {
|
||||||
w[i] = (atlas_pos[side] + uv[uv6[side][i]]) * s;
|
w[i] = (atlas_pos[side] + uv[uv6[side][i]]) * s;
|
||||||
}
|
}
|
||||||
@ -178,24 +178,24 @@ Ref<Voxel> Voxel::set_cube_uv_tbs_sides(Vector2 top_atlas_pos, Vector2 side_atla
|
|||||||
|
|
||||||
void Voxel::_bind_methods() {
|
void Voxel::_bind_methods() {
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_name:Voxel", "name"), &Voxel::set_name);
|
ClassDB::bind_method(D_METHOD("set_name:Voxel", "name"), &Voxel::set_name);
|
||||||
ObjectTypeDB::bind_method(_MD("get_name"), &Voxel::get_name);
|
ClassDB::bind_method(D_METHOD("get_name"), &Voxel::get_name);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_id:Voxel", "id"), &Voxel::set_id);
|
ClassDB::bind_method(D_METHOD("set_id:Voxel", "id"), &Voxel::set_id);
|
||||||
ObjectTypeDB::bind_method(_MD("get_id"), &Voxel::get_id);
|
ClassDB::bind_method(D_METHOD("get_id"), &Voxel::get_id);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_color:Voxel", "color"), &Voxel::set_color);
|
ClassDB::bind_method(D_METHOD("set_color:Voxel", "color"), &Voxel::set_color);
|
||||||
ObjectTypeDB::bind_method(_MD("get_color"), &Voxel::get_color);
|
ClassDB::bind_method(D_METHOD("get_color"), &Voxel::get_color);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_transparent:Voxel", "color"), &Voxel::set_transparent, DEFVAL(true));
|
ClassDB::bind_method(D_METHOD("set_transparent:Voxel", "color"), &Voxel::set_transparent, DEFVAL(true));
|
||||||
ObjectTypeDB::bind_method(_MD("is_transparent"), &Voxel::is_transparent);
|
ClassDB::bind_method(D_METHOD("is_transparent"), &Voxel::is_transparent);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_material_id", "id"), &Voxel::set_material_id);
|
ClassDB::bind_method(D_METHOD("set_material_id", "id"), &Voxel::set_material_id);
|
||||||
ObjectTypeDB::bind_method(_MD("get_material_id"), &Voxel::get_material_id);
|
ClassDB::bind_method(D_METHOD("get_material_id"), &Voxel::get_material_id);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_cube_geometry:Voxel", "height"), &Voxel::set_cube_geometry, DEFVAL(1.f));
|
ClassDB::bind_method(D_METHOD("set_cube_geometry:Voxel", "height"), &Voxel::set_cube_geometry, DEFVAL(1.f));
|
||||||
ObjectTypeDB::bind_method(_MD("set_cube_uv_all_sides:Voxel", "atlas_pos"), &Voxel::set_cube_uv_all_sides);
|
ClassDB::bind_method(D_METHOD("set_cube_uv_all_sides:Voxel", "atlas_pos"), &Voxel::set_cube_uv_all_sides);
|
||||||
ObjectTypeDB::bind_method(_MD("set_cube_uv_tbs_sides:Voxel", "top_atlas_pos", "side_atlas_pos", "bottom_atlas_pos"), &Voxel::set_cube_uv_tbs_sides);
|
ClassDB::bind_method(D_METHOD("set_cube_uv_tbs_sides:Voxel", "top_atlas_pos", "side_atlas_pos", "bottom_atlas_pos"), &Voxel::set_cube_uv_tbs_sides);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
voxel.h
22
voxel.h
@ -9,7 +9,7 @@ class VoxelLibrary;
|
|||||||
// A voxel can be a simple coloured cube, or a more complex model.
|
// A voxel can be a simple coloured cube, or a more complex model.
|
||||||
// Important: it is recommended that you create voxels from a library rather than using new().
|
// Important: it is recommended that you create voxels from a library rather than using new().
|
||||||
class Voxel : public Reference {
|
class Voxel : public Reference {
|
||||||
OBJ_TYPE(Voxel, Reference)
|
GDCLASS(Voxel, Reference)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Side {
|
enum Side {
|
||||||
@ -51,11 +51,11 @@ public:
|
|||||||
|
|
||||||
// Getters for native usage only
|
// Getters for native usage only
|
||||||
|
|
||||||
const DVector<Vector3> & get_model_vertices() const { return _model_vertices; }
|
const PoolVector<Vector3> & get_model_vertices() const { return _model_vertices; }
|
||||||
const DVector<Vector3> & get_model_normals() const { return _model_normals; }
|
const PoolVector<Vector3> & get_model_normals() const { return _model_normals; }
|
||||||
const DVector<Vector2> & get_model_uv() const { return _model_uv; }
|
const PoolVector<Vector2> & get_model_uv() const { return _model_uv; }
|
||||||
const DVector<Vector3> & get_model_side_vertices(unsigned int side) const { return _model_side_vertices[side]; }
|
const PoolVector<Vector3> & get_model_side_vertices(unsigned int side) const { return _model_side_vertices[side]; }
|
||||||
const DVector<Vector2> & get_model_side_uv(unsigned int side) const { return _model_side_uv[side]; }
|
const PoolVector<Vector2> & get_model_side_uv(unsigned int side) const { return _model_side_uv[side]; }
|
||||||
|
|
||||||
void set_library_ptr(VoxelLibrary * lib) { _library = lib; }
|
void set_library_ptr(VoxelLibrary * lib) { _library = lib; }
|
||||||
|
|
||||||
@ -77,11 +77,11 @@ private:
|
|||||||
|
|
||||||
// Model
|
// Model
|
||||||
Color _color;
|
Color _color;
|
||||||
DVector<Vector3> _model_vertices;
|
PoolVector<Vector3> _model_vertices;
|
||||||
DVector<Vector3> _model_normals;
|
PoolVector<Vector3> _model_normals;
|
||||||
DVector<Vector2> _model_uv;
|
PoolVector<Vector2> _model_uv;
|
||||||
DVector<Vector3> _model_side_vertices[SIDE_COUNT];
|
PoolVector<Vector3> _model_side_vertices[SIDE_COUNT];
|
||||||
DVector<Vector2> _model_side_uv[SIDE_COUNT];
|
PoolVector<Vector2> _model_side_uv[SIDE_COUNT];
|
||||||
|
|
||||||
// TODO Child voxel types
|
// TODO Child voxel types
|
||||||
|
|
||||||
|
@ -239,24 +239,24 @@ void VoxelBuffer::delete_channel(int i) {
|
|||||||
|
|
||||||
void VoxelBuffer::_bind_methods() {
|
void VoxelBuffer::_bind_methods() {
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("create", "sx", "sy", "sz"), &VoxelBuffer::create);
|
ClassDB::bind_method(D_METHOD("create", "sx", "sy", "sz"), &VoxelBuffer::create);
|
||||||
ObjectTypeDB::bind_method(_MD("clear"), &VoxelBuffer::clear);
|
ClassDB::bind_method(D_METHOD("clear"), &VoxelBuffer::clear);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("get_size_x"), &VoxelBuffer::get_size_x);
|
ClassDB::bind_method(D_METHOD("get_size_x"), &VoxelBuffer::get_size_x);
|
||||||
ObjectTypeDB::bind_method(_MD("get_size_y"), &VoxelBuffer::get_size_y);
|
ClassDB::bind_method(D_METHOD("get_size_y"), &VoxelBuffer::get_size_y);
|
||||||
ObjectTypeDB::bind_method(_MD("get_size_z"), &VoxelBuffer::get_size_z);
|
ClassDB::bind_method(D_METHOD("get_size_z"), &VoxelBuffer::get_size_z);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_voxel", "value", "x", "y", "z", "channel"), &VoxelBuffer::_set_voxel_binding, DEFVAL(0));
|
ClassDB::bind_method(D_METHOD("set_voxel", "value", "x", "y", "z", "channel"), &VoxelBuffer::_set_voxel_binding, DEFVAL(0));
|
||||||
ObjectTypeDB::bind_method(_MD("set_voxel_v", "value", "pos", "channel"), &VoxelBuffer::set_voxel_v, DEFVAL(0));
|
ClassDB::bind_method(D_METHOD("set_voxel_v", "value", "pos", "channel"), &VoxelBuffer::set_voxel_v, DEFVAL(0));
|
||||||
ObjectTypeDB::bind_method(_MD("get_voxel", "x", "y", "z", "channel"), &VoxelBuffer::_get_voxel_binding, DEFVAL(0));
|
ClassDB::bind_method(D_METHOD("get_voxel", "x", "y", "z", "channel"), &VoxelBuffer::_get_voxel_binding, DEFVAL(0));
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("fill", "value", "channel"), &VoxelBuffer::fill, DEFVAL(0));
|
ClassDB::bind_method(D_METHOD("fill", "value", "channel"), &VoxelBuffer::fill, DEFVAL(0));
|
||||||
ObjectTypeDB::bind_method(_MD("fill_area", "value", "min", "max", "channel"), &VoxelBuffer::_fill_area_binding, DEFVAL(0));
|
ClassDB::bind_method(D_METHOD("fill_area", "value", "min", "max", "channel"), &VoxelBuffer::_fill_area_binding, DEFVAL(0));
|
||||||
ObjectTypeDB::bind_method(_MD("copy_from", "other:VoxelBuffer", "channel"), &VoxelBuffer::_copy_from_binding, DEFVAL(0));
|
ClassDB::bind_method(D_METHOD("copy_from", "other:VoxelBuffer", "channel"), &VoxelBuffer::_copy_from_binding, DEFVAL(0));
|
||||||
ObjectTypeDB::bind_method(_MD("copy_from_area", "other:VoxelBuffer", "src_min", "src_max", "dst_min", "channel"), &VoxelBuffer::_copy_from_area_binding, DEFVAL(0));
|
ClassDB::bind_method(D_METHOD("copy_from_area", "other:VoxelBuffer", "src_min", "src_max", "dst_min", "channel"), &VoxelBuffer::_copy_from_area_binding, DEFVAL(0));
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("is_uniform", "channel"), &VoxelBuffer::is_uniform, DEFVAL(0));
|
ClassDB::bind_method(D_METHOD("is_uniform", "channel"), &VoxelBuffer::is_uniform, DEFVAL(0));
|
||||||
ObjectTypeDB::bind_method(_MD("optimize"), &VoxelBuffer::optimize);
|
ClassDB::bind_method(D_METHOD("optimize"), &VoxelBuffer::optimize);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
// Note: for float storage (marching cubes for example), you can map [0..256] to [0..1] and save 3 bytes per cell
|
// Note: for float storage (marching cubes for example), you can map [0..256] to [0..1] and save 3 bytes per cell
|
||||||
|
|
||||||
class VoxelBuffer : public Reference {
|
class VoxelBuffer : public Reference {
|
||||||
OBJ_TYPE(VoxelBuffer, Reference)
|
GDCLASS(VoxelBuffer, Reference)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Arbitrary value, 8 should be enough. Tweak for your needs.
|
// Arbitrary value, 8 should be enough. Tweak for your needs.
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
#include "voxel_library.h"
|
#include "voxel_library.h"
|
||||||
|
|
||||||
VoxelLibrary::VoxelLibrary() : Reference(), _atlas_size(1) {
|
VoxelLibrary::VoxelLibrary() : Reference(), _atlas_size(1) {
|
||||||
|
// Defaults
|
||||||
create_voxel(0, "air")->set_transparent(true);
|
create_voxel(0, "air")->set_transparent(true);
|
||||||
|
create_voxel(1, "solid")->set_transparent(false)->set_cube_geometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelLibrary::~VoxelLibrary() {
|
VoxelLibrary::~VoxelLibrary() {
|
||||||
@ -34,10 +36,10 @@ Ref<Voxel> VoxelLibrary::_get_voxel_bind(int id) {
|
|||||||
|
|
||||||
void VoxelLibrary::_bind_methods() {
|
void VoxelLibrary::_bind_methods() {
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("create_voxel:Voxel", "id", "name"), &VoxelLibrary::create_voxel);
|
ClassDB::bind_method(D_METHOD("create_voxel:Voxel", "id", "name"), &VoxelLibrary::create_voxel);
|
||||||
ObjectTypeDB::bind_method(_MD("get_voxel", "id"), &VoxelLibrary::_get_voxel_bind);
|
ClassDB::bind_method(D_METHOD("get_voxel", "id"), &VoxelLibrary::_get_voxel_bind);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_atlas_size", "square_size"), &VoxelLibrary::set_atlas_size);
|
ClassDB::bind_method(D_METHOD("set_atlas_size", "square_size"), &VoxelLibrary::set_atlas_size);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "voxel.h"
|
#include "voxel.h"
|
||||||
|
|
||||||
class VoxelLibrary : public Reference {
|
class VoxelLibrary : public Reference {
|
||||||
OBJ_TYPE(VoxelLibrary, Reference)
|
GDCLASS(VoxelLibrary, Reference)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const unsigned int MAX_VOXEL_TYPES = 256; // Required limit because voxel types are stored in 8 bits
|
static const unsigned int MAX_VOXEL_TYPES = 256; // Required limit because voxel types are stored in 8 bits
|
||||||
|
@ -242,16 +242,16 @@ void VoxelMap::clear() {
|
|||||||
|
|
||||||
void VoxelMap::_bind_methods() {
|
void VoxelMap::_bind_methods() {
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("get_voxel", "x", "y", "z", "c"), &VoxelMap::_get_voxel_binding, DEFVAL(0));
|
ClassDB::bind_method(D_METHOD("get_voxel", "x", "y", "z", "c"), &VoxelMap::_get_voxel_binding, DEFVAL(0));
|
||||||
ObjectTypeDB::bind_method(_MD("set_voxel", "value", "x", "y", "z", "c"), &VoxelMap::_set_voxel_binding, DEFVAL(0));
|
ClassDB::bind_method(D_METHOD("set_voxel", "value", "x", "y", "z", "c"), &VoxelMap::_set_voxel_binding, DEFVAL(0));
|
||||||
ObjectTypeDB::bind_method(_MD("get_default_voxel", "channel"), &VoxelMap::get_default_voxel, DEFVAL(0));
|
ClassDB::bind_method(D_METHOD("get_default_voxel", "channel"), &VoxelMap::get_default_voxel, DEFVAL(0));
|
||||||
ObjectTypeDB::bind_method(_MD("set_default_voxel", "value", "channel"), &VoxelMap::set_default_voxel, DEFVAL(0));
|
ClassDB::bind_method(D_METHOD("set_default_voxel", "value", "channel"), &VoxelMap::set_default_voxel, DEFVAL(0));
|
||||||
ObjectTypeDB::bind_method(_MD("has_block", "x", "y", "z"), &VoxelMap::_has_block_binding);
|
ClassDB::bind_method(D_METHOD("has_block", "x", "y", "z"), &VoxelMap::_has_block_binding);
|
||||||
ObjectTypeDB::bind_method(_MD("get_buffer_copy", "min_pos", "out_buffer:VoxelBuffer", "channel"), &VoxelMap::_get_buffer_copy_binding, DEFVAL(0));
|
ClassDB::bind_method(D_METHOD("get_buffer_copy", "min_pos", "out_buffer:VoxelBuffer", "channel"), &VoxelMap::_get_buffer_copy_binding, DEFVAL(0));
|
||||||
ObjectTypeDB::bind_method(_MD("set_block_buffer", "block_pos", "buffer:VoxelBuffer"), &VoxelMap::_set_block_buffer_binding);
|
ClassDB::bind_method(D_METHOD("set_block_buffer", "block_pos", "buffer:VoxelBuffer"), &VoxelMap::_set_block_buffer_binding);
|
||||||
ObjectTypeDB::bind_method(_MD("voxel_to_block", "voxel_pos"), &VoxelMap::_voxel_to_block_binding);
|
ClassDB::bind_method(D_METHOD("voxel_to_block", "voxel_pos"), &VoxelMap::_voxel_to_block_binding);
|
||||||
ObjectTypeDB::bind_method(_MD("block_to_voxel", "block_pos"), &VoxelMap::_block_to_voxel_binding);
|
ClassDB::bind_method(D_METHOD("block_to_voxel", "block_pos"), &VoxelMap::_block_to_voxel_binding);
|
||||||
ObjectTypeDB::bind_method(_MD("get_block_size"), &VoxelMap::get_block_size);
|
ClassDB::bind_method(D_METHOD("get_block_size"), &VoxelMap::get_block_size);
|
||||||
|
|
||||||
//ADD_PROPERTY(PropertyInfo(Variant::INT, "iterations"), _SCS("set_iterations"), _SCS("get_iterations"));
|
//ADD_PROPERTY(PropertyInfo(Variant::INT, "iterations"), _SCS("set_iterations"), _SCS("get_iterations"));
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ public:
|
|||||||
Ref<VoxelBuffer> voxels; // SIZE*SIZE*SIZE voxels
|
Ref<VoxelBuffer> voxels; // SIZE*SIZE*SIZE voxels
|
||||||
Vector3i pos;
|
Vector3i pos;
|
||||||
NodePath mesh_instance_path;
|
NodePath mesh_instance_path;
|
||||||
|
//NodePath body_path; // TODO
|
||||||
|
|
||||||
static VoxelBlock * create(Vector3i bpos, Ref<VoxelBuffer> buffer);
|
static VoxelBlock * create(Vector3i bpos, Ref<VoxelBuffer> buffer);
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ private:
|
|||||||
|
|
||||||
// Infinite voxel storage by means of octants like Gridmap
|
// Infinite voxel storage by means of octants like Gridmap
|
||||||
class VoxelMap : public Reference {
|
class VoxelMap : public Reference {
|
||||||
OBJ_TYPE(VoxelMap, Reference)
|
GDCLASS(VoxelMap, Reference)
|
||||||
public:
|
public:
|
||||||
// Converts voxel coodinates into block coordinates
|
// Converts voxel coodinates into block coordinates
|
||||||
static _FORCE_INLINE_ Vector3i voxel_to_block(Vector3i pos) {
|
static _FORCE_INLINE_ Vector3i voxel_to_block(Vector3i pos) {
|
||||||
|
@ -218,7 +218,7 @@ Ref<Mesh> VoxelMesher::build(const VoxelBuffer & buffer) {
|
|||||||
// Sides
|
// Sides
|
||||||
for (unsigned int side = 0; side < Voxel::SIDE_COUNT; ++side) {
|
for (unsigned int side = 0; side < Voxel::SIDE_COUNT; ++side) {
|
||||||
|
|
||||||
const DVector<Vector3> & vertices = voxel.get_model_side_vertices(side);
|
const PoolVector<Vector3> & vertices = voxel.get_model_side_vertices(side);
|
||||||
if (vertices.size() != 0) {
|
if (vertices.size() != 0) {
|
||||||
|
|
||||||
Vector3i normal = g_side_normals[side];
|
Vector3i normal = g_side_normals[side];
|
||||||
@ -266,8 +266,8 @@ Ref<Mesh> VoxelMesher::build(const VoxelBuffer & buffer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DVector<Vector3>::Read rv = vertices.read();
|
PoolVector<Vector3>::Read rv = vertices.read();
|
||||||
DVector<Vector2>::Read rt = voxel.get_model_side_uv(side).read();
|
PoolVector<Vector2>::Read rt = voxel.get_model_side_uv(side).read();
|
||||||
Vector3 pos(x - 1, y - 1, z - 1);
|
Vector3 pos(x - 1, y - 1, z - 1);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < vertices.size(); ++i) {
|
for (unsigned int i = 0; i < vertices.size(); ++i) {
|
||||||
@ -305,10 +305,10 @@ Ref<Mesh> VoxelMesher::build(const VoxelBuffer & buffer) {
|
|||||||
// Inside
|
// Inside
|
||||||
if (voxel.get_model_vertices().size() != 0) {
|
if (voxel.get_model_vertices().size() != 0) {
|
||||||
|
|
||||||
const DVector<Vector3> & vertices = voxel.get_model_vertices();
|
const PoolVector<Vector3> & vertices = voxel.get_model_vertices();
|
||||||
DVector<Vector3>::Read rv = voxel.get_model_vertices().read();
|
PoolVector<Vector3>::Read rv = voxel.get_model_vertices().read();
|
||||||
DVector<Vector3>::Read rn = voxel.get_model_normals().read();
|
PoolVector<Vector3>::Read rn = voxel.get_model_normals().read();
|
||||||
DVector<Vector2>::Read rt = voxel.get_model_uv().read();
|
PoolVector<Vector2>::Read rt = voxel.get_model_uv().read();
|
||||||
Vector3 pos(x - 1, y - 1, z - 1);
|
Vector3 pos(x - 1, y - 1, z - 1);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < vertices.size(); ++i) {
|
for (unsigned int i = 0; i < vertices.size(); ++i) {
|
||||||
@ -344,18 +344,18 @@ Ref<Mesh> VoxelMesher::build(const VoxelBuffer & buffer) {
|
|||||||
|
|
||||||
void VoxelMesher::_bind_methods() {
|
void VoxelMesher::_bind_methods() {
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_material", "material", "id"), &VoxelMesher::set_material);
|
ClassDB::bind_method(D_METHOD("set_material", "material", "id"), &VoxelMesher::set_material);
|
||||||
ObjectTypeDB::bind_method(_MD("get_material:Material", "id"), &VoxelMesher::get_material);
|
ClassDB::bind_method(D_METHOD("get_material:Material", "id"), &VoxelMesher::get_material);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_library", "voxel_library"), &VoxelMesher::set_library);
|
ClassDB::bind_method(D_METHOD("set_library", "voxel_library"), &VoxelMesher::set_library);
|
||||||
ObjectTypeDB::bind_method(_MD("get_library:VoxelLibrary"), &VoxelMesher::get_library);
|
ClassDB::bind_method(D_METHOD("get_library:VoxelLibrary"), &VoxelMesher::get_library);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_occlusion_enabled", "enable"), &VoxelMesher::set_occlusion_enabled);
|
ClassDB::bind_method(D_METHOD("set_occlusion_enabled", "enable"), &VoxelMesher::set_occlusion_enabled);
|
||||||
ObjectTypeDB::bind_method(_MD("get_occlusion_enabled"), &VoxelMesher::get_occlusion_enabled);
|
ClassDB::bind_method(D_METHOD("get_occlusion_enabled"), &VoxelMesher::get_occlusion_enabled);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_occlusion_darkness", "value"), &VoxelMesher::set_occlusion_darkness);
|
ClassDB::bind_method(D_METHOD("set_occlusion_darkness", "value"), &VoxelMesher::set_occlusion_darkness);
|
||||||
ObjectTypeDB::bind_method(_MD("get_occlusion_darkness"), &VoxelMesher::get_occlusion_darkness);
|
ClassDB::bind_method(D_METHOD("get_occlusion_darkness"), &VoxelMesher::get_occlusion_darkness);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("build", "voxel_buffer"), &VoxelMesher::build_ref);
|
ClassDB::bind_method(D_METHOD("build", "voxel_buffer"), &VoxelMesher::build_ref);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include "voxel_library.h"
|
#include "voxel_library.h"
|
||||||
|
|
||||||
class VoxelMesher : public Reference {
|
class VoxelMesher : public Reference {
|
||||||
OBJ_TYPE(VoxelMesher, Reference)
|
GDCLASS(VoxelMesher, Reference)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const unsigned int MAX_MATERIALS = 8; // Arbitrary. Tweak if needed.
|
static const unsigned int MAX_MATERIALS = 8; // Arbitrary. Tweak if needed.
|
||||||
|
@ -38,8 +38,8 @@ void VoxelProvider::_immerge_block(Ref<VoxelBuffer> buffer, Vector3 block_pos) {
|
|||||||
|
|
||||||
void VoxelProvider::_bind_methods() {
|
void VoxelProvider::_bind_methods() {
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("emerge_block", "out_buffer:VoxelBuffer", "block_pos:Vector3"), &VoxelProvider::_emerge_block);
|
ClassDB::bind_method(D_METHOD("emerge_block", "out_buffer:VoxelBuffer", "block_pos:Vector3"), &VoxelProvider::_emerge_block);
|
||||||
ObjectTypeDB::bind_method(_MD("immerge_block", "buffer:VoxelBuffer", "block_pos:Vector3"), &VoxelProvider::_immerge_block);
|
ClassDB::bind_method(D_METHOD("immerge_block", "buffer:VoxelBuffer", "block_pos:Vector3"), &VoxelProvider::_immerge_block);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class VoxelProvider : public Reference {
|
class VoxelProvider : public Reference {
|
||||||
OBJ_TYPE(VoxelProvider, Reference)
|
GDCLASS(VoxelProvider, Reference)
|
||||||
public:
|
public:
|
||||||
virtual void emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i block_pos);
|
virtual void emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i block_pos);
|
||||||
virtual void immerge_block(Ref<VoxelBuffer> buffer, Vector3i block_pos);
|
virtual void immerge_block(Ref<VoxelBuffer> buffer, Vector3i block_pos);
|
||||||
|
@ -93,17 +93,17 @@ void VoxelProviderTest::generate_block_waves(VoxelBuffer & out_buffer, Vector3i
|
|||||||
|
|
||||||
void VoxelProviderTest::_bind_methods() {
|
void VoxelProviderTest::_bind_methods() {
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_mode", "mode"), &VoxelProviderTest::set_mode);
|
ClassDB::bind_method(D_METHOD("set_mode", "mode"), &VoxelProviderTest::set_mode);
|
||||||
ObjectTypeDB::bind_method(_MD("get_mode"), &VoxelProviderTest::get_mode);
|
ClassDB::bind_method(D_METHOD("get_mode"), &VoxelProviderTest::get_mode);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_voxel_type", "id"), &VoxelProviderTest::set_voxel_type);
|
ClassDB::bind_method(D_METHOD("set_voxel_type", "id"), &VoxelProviderTest::set_voxel_type);
|
||||||
ObjectTypeDB::bind_method(_MD("get_voxel_type"), &VoxelProviderTest::get_voxel_type);
|
ClassDB::bind_method(D_METHOD("get_voxel_type"), &VoxelProviderTest::get_voxel_type);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_pattern_size", "size"), &VoxelProviderTest::_set_pattern_size);
|
ClassDB::bind_method(D_METHOD("set_pattern_size", "size"), &VoxelProviderTest::_set_pattern_size);
|
||||||
ObjectTypeDB::bind_method(_MD("get_pattern_size"), &VoxelProviderTest::_get_pattern_size);
|
ClassDB::bind_method(D_METHOD("get_pattern_size"), &VoxelProviderTest::_get_pattern_size);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_pattern_offset", "offset"), &VoxelProviderTest::_set_pattern_offset);
|
ClassDB::bind_method(D_METHOD("set_pattern_offset", "offset"), &VoxelProviderTest::_set_pattern_offset);
|
||||||
ObjectTypeDB::bind_method(_MD("get_pattern_offset"), &VoxelProviderTest::_get_pattern_offset);
|
ClassDB::bind_method(D_METHOD("get_pattern_offset"), &VoxelProviderTest::_get_pattern_offset);
|
||||||
|
|
||||||
BIND_CONSTANT(MODE_FLAT);
|
BIND_CONSTANT(MODE_FLAT);
|
||||||
BIND_CONSTANT(MODE_WAVES);
|
BIND_CONSTANT(MODE_WAVES);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class VoxelProviderTest : public VoxelProvider {
|
class VoxelProviderTest : public VoxelProvider {
|
||||||
OBJ_TYPE(VoxelProviderTest, VoxelProvider)
|
GDCLASS(VoxelProviderTest, VoxelProvider)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Mode {
|
enum Mode {
|
||||||
|
@ -186,19 +186,19 @@ void VoxelTerrain::update_block_mesh(Vector3i block_pos) {
|
|||||||
|
|
||||||
void VoxelTerrain::_bind_methods() {
|
void VoxelTerrain::_bind_methods() {
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_provider", "provider:VoxelProvider"), &VoxelTerrain::set_provider);
|
ClassDB::bind_method(D_METHOD("set_provider", "provider:VoxelProvider"), &VoxelTerrain::set_provider);
|
||||||
ObjectTypeDB::bind_method(_MD("get_provider:VoxelProvider"), &VoxelTerrain::get_provider);
|
ClassDB::bind_method(D_METHOD("get_provider:VoxelProvider"), &VoxelTerrain::get_provider);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("get_block_update_count"), &VoxelTerrain::get_block_update_count);
|
ClassDB::bind_method(D_METHOD("get_block_update_count"), &VoxelTerrain::get_block_update_count);
|
||||||
ObjectTypeDB::bind_method(_MD("get_mesher:VoxelMesher"), &VoxelTerrain::get_mesher);
|
ClassDB::bind_method(D_METHOD("get_mesher:VoxelMesher"), &VoxelTerrain::get_mesher);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("get_map:VoxelMap"), &VoxelTerrain::get_map);
|
ClassDB::bind_method(D_METHOD("get_map:VoxelMap"), &VoxelTerrain::get_map);
|
||||||
|
|
||||||
// TODO Make those two static in VoxelMap?
|
// TODO Make those two static in VoxelMap?
|
||||||
ObjectTypeDB::bind_method(_MD("voxel_to_block", "voxel_pos"), &VoxelTerrain::_voxel_to_block_binding);
|
ClassDB::bind_method(D_METHOD("voxel_to_block", "voxel_pos"), &VoxelTerrain::_voxel_to_block_binding);
|
||||||
ObjectTypeDB::bind_method(_MD("block_to_voxel", "block_pos"), &VoxelTerrain::_block_to_voxel_binding);
|
ClassDB::bind_method(D_METHOD("block_to_voxel", "block_pos"), &VoxelTerrain::_block_to_voxel_binding);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("force_load_blocks", "center", "extents"), &VoxelTerrain::_force_load_blocks_binding);
|
ClassDB::bind_method(D_METHOD("force_load_blocks", "center", "extents"), &VoxelTerrain::_force_load_blocks_binding);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
// Infinite static terrain made of voxels.
|
// Infinite static terrain made of voxels.
|
||||||
// It is loaded around VoxelTerrainStreamers.
|
// It is loaded around VoxelTerrainStreamers.
|
||||||
class VoxelTerrain : public Node /*, public IVoxelMapObserver*/ {
|
class VoxelTerrain : public Node /*, public IVoxelMapObserver*/ {
|
||||||
OBJ_TYPE(VoxelTerrain, Node)
|
GDCLASS(VoxelTerrain, Node)
|
||||||
public:
|
public:
|
||||||
VoxelTerrain();
|
VoxelTerrain();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user