Separated VoxelmanLibrary into 2 different classes.

This commit is contained in:
Relintai 2019-11-09 17:26:16 +01:00
parent 019ad0c8ec
commit f931f3f1bf
10 changed files with 337 additions and 220 deletions

3
SCsub
View File

@ -5,7 +5,10 @@ env.add_source_files(env.modules_sources,"register_types.cpp")
env.add_source_files(env.modules_sources,"collections/vector3i.cpp")
env.add_source_files(env.modules_sources,"library/voxelman_library.cpp")
env.add_source_files(env.modules_sources,"library/voxelman_library_simple.cpp")
env.add_source_files(env.modules_sources,"library/voxel_surface.cpp")
env.add_source_files(env.modules_sources,"library/voxel_surface_simple.cpp")
env.add_source_files(env.modules_sources,"data/voxel_light.cpp")

View File

@ -3,52 +3,22 @@
int VoxelSurface::get_id() const {
return _id;
}
void VoxelSurface::set_id(int value) {
void VoxelSurface::set_id(const int value) {
_id = value;
}
int VoxelSurface::get_atlas_x(const int side) const {
int indx = (side * 2);
ERR_FAIL_INDEX_V(indx, VOXEL_SIDES_ARRAY_SIZE, 0);
return _atlas_positions[indx];
}
void VoxelSurface::set_atlas_x(const int side, int value) {
int indx = (side * 2);
ERR_FAIL_INDEX(indx, VOXEL_SIDES_ARRAY_SIZE);
_atlas_positions[indx] = value;
}
int VoxelSurface::get_atlas_y(const int side) const {
int indx = (side * 2) + 1;
ERR_FAIL_INDEX_V(indx, VOXEL_SIDES_ARRAY_SIZE, 0);
return _atlas_positions[indx];
}
void VoxelSurface::set_atlas_y(const int side, int value) {
int indx = (side * 2) + 1;
ERR_FAIL_INDEX(indx, VOXEL_SIDES_ARRAY_SIZE);
_atlas_positions[indx] = value;
}
bool VoxelSurface::is_transparent() const {
return _is_transparent;
}
void VoxelSurface::set_transparent(bool transparent) {
void VoxelSurface::set_transparent(const bool transparent) {
_is_transparent = transparent;
}
String VoxelSurface::get_voxel_name() const {
return _name;
Rect2 VoxelSurface::get_rect(const VoxelSurfaceSides side) const {
return _rects[side];
}
void VoxelSurface::set_voxel_name(String name) {
_name = name;
void VoxelSurface::set_rect(const VoxelSurfaceSides side, const Rect2 rect) {
_rects[side] = rect;
}
Ref<VoxelmanLibrary> VoxelSurface::get_library() const {
@ -57,41 +27,35 @@ Ref<VoxelmanLibrary> VoxelSurface::get_library() const {
void VoxelSurface::set_library(Ref<VoxelmanLibrary> library) {
_library = (*library);
if (_library != NULL)
refresh_rects();
}
Vector2 VoxelSurface::transform_uv(const int side, const Vector2 uv) const {
float culomn = 1.0 / static_cast<float>(_library->get_atlas_columns());
float row = 1.0 / static_cast<float>(_library->get_atlas_rows());
Vector2 VoxelSurface::transform_uv(const VoxelSurfaceSides p_side, const Vector2 p_uv) const {
Vector2 uv = p_uv;
return Vector2(get_atlas_x(side) * culomn + culomn * uv.x, get_atlas_y(side) * row + row * uv.y);
Rect2 r = _rects[p_side];
uv.x *= r.size.x;
uv.y *= r.size.y;
uv.x += r.position.x;
uv.y += r.position.y;
return uv;
}
void VoxelSurface::refresh_rects() {
}
VoxelSurface::VoxelSurface() {
_id = 0;
for (int i = 0; i < VOXEL_SIDES_ARRAY_SIZE; ++i) {
_atlas_positions[i] = 0;
}
_is_transparent = false;
_library = NULL;
}
VoxelSurface::VoxelSurface(int id) {
_id = id;
for (int i = 0; i < VOXEL_SIDES_ARRAY_SIZE; ++i) {
_atlas_positions[i] = 0;
}
_is_transparent = false;
_library = NULL;
}
VoxelSurface::~VoxelSurface() {
//_library = NULL;
_library = NULL;
}
void VoxelSurface::_bind_methods() {
@ -99,35 +63,22 @@ void VoxelSurface::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_id", "value"), &VoxelSurface::set_id);
ADD_PROPERTY(PropertyInfo(Variant::INT, "id"), "set_id", "get_id");
//create an array
ClassDB::bind_method(D_METHOD("get_atlas_x", "side"), &VoxelSurface::get_atlas_x);
ClassDB::bind_method(D_METHOD("set_atlas_x", "side", "value"), &VoxelSurface::set_atlas_x);
ClassDB::bind_method(D_METHOD("get_atlas_y", "side"), &VoxelSurface::get_atlas_y);
ClassDB::bind_method(D_METHOD("set_atlas_y", "side", "value"), &VoxelSurface::set_atlas_y);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "voxel_name"), "set_name", "get_name");
ADD_PROPERTYI(PropertyInfo(Variant::INT, "top_atlas_x"), "set_atlas_x", "get_atlas_x", VOXEL_SIDE_TOP);
ADD_PROPERTYI(PropertyInfo(Variant::INT, "top_atlas_y"), "set_atlas_y", "get_atlas_y", VOXEL_SIDE_TOP);
ADD_PROPERTYI(PropertyInfo(Variant::INT, "bottom_atlas_x"), "set_atlas_x", "get_atlas_x", VOXEL_SIDE_BOTTOM);
ADD_PROPERTYI(PropertyInfo(Variant::INT, "bottom_atlas_y"), "set_atlas_y", "get_atlas_y", VOXEL_SIDE_BOTTOM);
ADD_PROPERTYI(PropertyInfo(Variant::INT, "side_atlas_x"), "set_atlas_x", "get_atlas_x", VOXEL_SIDE_SIDE);
ADD_PROPERTYI(PropertyInfo(Variant::INT, "side_atlas_y"), "set_atlas_y", "get_atlas_y", VOXEL_SIDE_SIDE);
ClassDB::bind_method(D_METHOD("set_transparent", "transparent"), &VoxelSurface::set_transparent, DEFVAL(false));
ClassDB::bind_method(D_METHOD("set_transparent", "transparent"), &VoxelSurface::set_transparent);
ClassDB::bind_method(D_METHOD("is_transparent"), &VoxelSurface::is_transparent);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transparent"), "set_transparent", "is_transparent");
ClassDB::bind_method(D_METHOD("set_voxel_name", "name"), &VoxelSurface::set_voxel_name);
ClassDB::bind_method(D_METHOD("get_voxel_name"), &VoxelSurface::get_voxel_name);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "voxel_name"), "set_name", "get_name");
ClassDB::bind_method(D_METHOD("get_rect", "side"), &VoxelSurface::get_rect);
ClassDB::bind_method(D_METHOD("set_rect", "side", "rect"), &VoxelSurface::set_rect);
ClassDB::bind_method(D_METHOD("transform_uv", "side", "uv"), &VoxelSurface::transform_uv);
ClassDB::bind_method(D_METHOD("refresh_rects"), &VoxelSurface::refresh_rects);
BIND_ENUM_CONSTANT(VOXEL_SIDE_TOP);
BIND_ENUM_CONSTANT(VOXEL_SIDE_BOTTOM);
BIND_ENUM_CONSTANT(VOXEL_SIDE_SIDE);
BIND_ENUM_CONSTANT(VOXEL_SIDES_COUNT);
BIND_CONSTANT(VOXEL_SIDES_COUNT);
}

View File

@ -1,8 +1,10 @@
#ifndef VOXEL_SURFACE_DEFINITION_H
#define VOXEL_SURFACE_DEFINITION_H
#ifndef VOXEL_SURFACE_H
#define VOXEL_SURFACE_H
#include "core/resource.h"
#include "core/color.h"
#include "core/resource.h"
#include "core/math/rect2.h"
#include "core/vector.h"
#include "scene/resources/material.h"
@ -33,46 +35,40 @@ public:
VOXEL_SIDE_TOP = 0,
VOXEL_SIDE_BOTTOM = 1,
VOXEL_SIDE_SIDE = 2,
};
enum {
VOXEL_SIDES_COUNT = 3,
VOXEL_SIDES_ARRAY_SIZE = VOXEL_SIDES_COUNT * 2,
};
int get_id() const;
void set_id(int value);
int get_atlas_x(const int side) const;
void set_atlas_x(const int side, int value);
int get_atlas_y(const int side) const;
void set_atlas_y(const int side, int value);
void set_id(const int value);
bool is_transparent() const;
void set_transparent(bool transparent);
String get_voxel_name() const;
void set_voxel_name(String name);
void set_transparent(const bool transparent);
Rect2 get_rect(const VoxelSurfaceSides side) const;
void set_rect(const VoxelSurfaceSides side, const Rect2 rect);
Ref<VoxelmanLibrary> get_library() const;
void set_library(Ref<VoxelmanLibrary> library);
Vector2 transform_uv(const int side, const Vector2 uv) const;
Vector2 transform_uv(const VoxelSurfaceSides side, const Vector2 uv) const;
virtual void refresh_rects();
VoxelSurface();
VoxelSurface(int id);
~VoxelSurface();
protected:
static void _bind_methods();
private:
VoxelmanLibrary *_library;
int _id;
String _name;
int _atlas_positions[VOXEL_SIDES_ARRAY_SIZE];
bool _is_transparent;
Rect2 _rects[VOXEL_SIDES_COUNT];
};
VARIANT_ENUM_CAST(VoxelSurface::VoxelSurfaceSides);

View File

@ -0,0 +1,72 @@
#include "voxel_surface_simple.h"
#include "voxelman_library_simple.h"
int VoxelSurfaceSimple::get_atlas_x(const VoxelSurfaceSides side) const {
int indx = (side * 2);
return _atlas_positions[indx];
}
void VoxelSurfaceSimple::set_atlas_x(const VoxelSurfaceSides side, int value) {
int indx = (side * 2);
_atlas_positions[indx] = value;
}
int VoxelSurfaceSimple::get_atlas_y(const VoxelSurfaceSides side) const {
int indx = (side * 2) + 1;
return _atlas_positions[indx];
}
void VoxelSurfaceSimple::set_atlas_y(const VoxelSurfaceSides side, int value) {
int indx = (side * 2) + 1;
_atlas_positions[indx] = value;
}
void VoxelSurfaceSimple::refresh_rects() {
VoxelmanLibrarySimple *lib = Object::cast_to<VoxelmanLibrarySimple>(_library);
ERR_FAIL_COND(!ObjectDB::instance_validate(lib));
for (int i = 0; i < VOXEL_SIDES_COUNT; ++i) {
float culomn = 1.0 / static_cast<float>(lib->get_atlas_columns());
float row = 1.0 / static_cast<float>(lib->get_atlas_rows());
Rect2 r;
r.position.x = _atlas_positions[i * 2] * culomn;
r.position.y = _atlas_positions[i * 2 + 1] * row;
r.size.x = culomn;
r.size.y = row;
_rects[i] = r;
}
}
VoxelSurfaceSimple::VoxelSurfaceSimple() {
for (int i = 0; i < VOXEL_SIDES_ARRAY_SIZE; ++i) {
_atlas_positions[i] = 0;
}
}
VoxelSurfaceSimple::~VoxelSurfaceSimple() {
}
void VoxelSurfaceSimple::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_atlas_x", "side"), &VoxelSurfaceSimple::get_atlas_x);
ClassDB::bind_method(D_METHOD("set_atlas_x", "side", "value"), &VoxelSurfaceSimple::set_atlas_x);
ClassDB::bind_method(D_METHOD("get_atlas_y", "side"), &VoxelSurfaceSimple::get_atlas_y);
ClassDB::bind_method(D_METHOD("set_atlas_y", "side", "value"), &VoxelSurfaceSimple::set_atlas_y);
ADD_PROPERTYI(PropertyInfo(Variant::INT, "top_atlas_x"), "set_atlas_x", "get_atlas_x", VOXEL_SIDE_TOP);
ADD_PROPERTYI(PropertyInfo(Variant::INT, "top_atlas_y"), "set_atlas_y", "get_atlas_y", VOXEL_SIDE_TOP);
ADD_PROPERTYI(PropertyInfo(Variant::INT, "bottom_atlas_x"), "set_atlas_x", "get_atlas_x", VOXEL_SIDE_BOTTOM);
ADD_PROPERTYI(PropertyInfo(Variant::INT, "bottom_atlas_y"), "set_atlas_y", "get_atlas_y", VOXEL_SIDE_BOTTOM);
ADD_PROPERTYI(PropertyInfo(Variant::INT, "side_atlas_x"), "set_atlas_x", "get_atlas_x", VOXEL_SIDE_SIDE);
ADD_PROPERTYI(PropertyInfo(Variant::INT, "side_atlas_y"), "set_atlas_y", "get_atlas_y", VOXEL_SIDE_SIDE);
}

View File

@ -0,0 +1,28 @@
#ifndef VOXEL_SURFACE_SIMPLE_H
#define VOXEL_SURFACE_SIMPLE_H
#include "voxel_surface.h"
class VoxelSurfaceSimple : public VoxelSurface {
GDCLASS(VoxelSurfaceSimple, VoxelSurface)
public:
int get_atlas_x(const VoxelSurfaceSides side) const;
void set_atlas_x(const VoxelSurfaceSides side, int value);
int get_atlas_y(const VoxelSurfaceSides side) const;
void set_atlas_y(const VoxelSurfaceSides side, int value);
void refresh_rects();
VoxelSurfaceSimple();
~VoxelSurfaceSimple();
protected:
static void _bind_methods();
private:
int _atlas_positions[VOXEL_SIDES_ARRAY_SIZE];
};
#endif

View File

@ -1,112 +1,32 @@
#include "voxelman_library.h"
VoxelmanLibrary::VoxelmanLibrary() {
_atlas_rows = 8;
_atlas_columns = 8;
_is_textured = true;
}
VoxelmanLibrary::~VoxelmanLibrary() {
for (int i = 0; i < _voxel_surfaces.size(); ++i) {
if (_voxel_surfaces[i].is_valid()) {
_voxel_surfaces.get(i)->set_library(Ref<VoxelmanLibrary>(NULL));
_voxel_surfaces.get(i).unref();
}
}
_voxel_surfaces.clear();
_material.unref();
_prop_material.unref();
}
Ref<VoxelSurface> VoxelmanLibrary::get_voxel_surface(int index) const {
ERR_FAIL_INDEX_V(index, _voxel_surfaces.size(), Ref<VoxelSurface>(NULL));
return _voxel_surfaces[index];
return Ref<VoxelSurface>();
}
void VoxelmanLibrary::set_voxel_surface(int index, Ref<VoxelSurface> value) {
ERR_FAIL_COND(index < 0);
if (_voxel_surfaces.size() < index) {
_voxel_surfaces.resize(index + 1);
}
if (_voxel_surfaces[index].is_valid()) {
_voxel_surfaces.get(index)->set_library(Ref<VoxelmanLibrary>(NULL));
}
if (value.is_valid()) {
value->set_library(Ref<VoxelmanLibrary>(this));
_voxel_surfaces.set(index, Ref<VoxelSurface>(value));
}
}
Vector<Variant> VoxelmanLibrary::get_voxel_surfaces() {
Vector<Variant> r;
for (int i = 0; i < _voxel_surfaces.size(); i++) {
r.push_back(_voxel_surfaces[i].get_ref_ptr());
}
return r;
void VoxelmanLibrary::remove_surface(int index) {
}
void VoxelmanLibrary::set_voxel_surfaces(const Vector<Variant> &effects) {
_voxel_surfaces.clear();
for (int i = 0; i < effects.size(); i++) {
Ref<VoxelSurface> surface = Ref<VoxelSurface>(effects[i]);
if (surface.is_valid())
surface->set_library(this);
_voxel_surfaces.push_back(surface);
}
int VoxelmanLibrary::get_num_surfaces() {
return 0;
}
int VoxelmanLibrary::get_voxel_types_count() {
return _voxel_surfaces.size();
}
void VoxelmanLibrary::refresh_rects() {
int VoxelmanLibrary::get_voxel_count() const {
return _voxel_surfaces.size();
}
void VoxelmanLibrary::set_atlas_columns(int s) {
ERR_FAIL_COND(s < 0);
_atlas_columns = s;
}
void VoxelmanLibrary::set_atlas_rows(int s) {
ERR_FAIL_COND(s < 0);
_atlas_rows = s;
}
bool VoxelmanLibrary::get_is_textured() const {
return _is_textured;
}
void VoxelmanLibrary::set_is_textured(bool value) {
_is_textured = value;
}
void VoxelmanLibrary::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_surface", "id"), &VoxelmanLibrary::get_surface);
ClassDB::bind_method(D_METHOD("get_atlas_columns"), &VoxelmanLibrary::get_atlas_columns);
ClassDB::bind_method(D_METHOD("set_atlas_columns", "value"), &VoxelmanLibrary::set_atlas_columns);
ADD_PROPERTY(PropertyInfo(Variant::INT, "atlas_columns"), "set_atlas_columns", "get_atlas_columns");
ClassDB::bind_method(D_METHOD("get_atlas_rows"), &VoxelmanLibrary::get_atlas_rows);
ClassDB::bind_method(D_METHOD("set_atlas_rows", "value"), &VoxelmanLibrary::set_atlas_rows);
ADD_PROPERTY(PropertyInfo(Variant::INT, "atlas_rows"), "set_atlas_rows", "get_atlas_rows");
ClassDB::bind_method(D_METHOD("get_is_textured"), &VoxelmanLibrary::get_is_textured);
ClassDB::bind_method(D_METHOD("set_is_textured", "value"), &VoxelmanLibrary::set_is_textured);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "is_textured"), "set_is_textured", "get_is_textured");
ClassDB::bind_method(D_METHOD("get_material"), &VoxelmanLibrary::get_material);
ClassDB::bind_method(D_METHOD("set_material", "value"), &VoxelmanLibrary::set_material);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_material", "get_material");
@ -115,13 +35,10 @@ void VoxelmanLibrary::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_prop_material", "value"), &VoxelmanLibrary::set_prop_material);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop_material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_prop_material", "get_prop_material");
ClassDB::bind_method(D_METHOD("get_voxel_types_count"), &VoxelmanLibrary::get_voxel_types_count);
ClassDB::bind_method(D_METHOD("get_voxel_surface", "index"), &VoxelmanLibrary::get_voxel_surface);
ClassDB::bind_method(D_METHOD("set_voxel_surface", "index", "surface"), &VoxelmanLibrary::set_voxel_surface);
ClassDB::bind_method(D_METHOD("remove_surface", "index"), &VoxelmanLibrary::remove_surface);
ClassDB::bind_method(D_METHOD("get_num_surfaces"), &VoxelmanLibrary::get_num_surfaces);
ClassDB::bind_method(D_METHOD("get_voxel_surfaces"), &VoxelmanLibrary::get_voxel_surfaces);
ClassDB::bind_method(D_METHOD("set_voxel_surfaces"), &VoxelmanLibrary::set_voxel_surfaces);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "voxel_surfaces", PROPERTY_HINT_NONE, "17/17:VoxelSurface", PROPERTY_USAGE_DEFAULT, "VoxelSurface"), "set_voxel_surfaces", "get_voxel_surfaces");
ClassDB::bind_method(D_METHOD("refresh_rects"), &VoxelmanLibrary::refresh_rects);
}

View File

@ -14,50 +14,28 @@ class VoxelmanLibrary : public Resource {
GDCLASS(VoxelmanLibrary, Resource)
public:
VoxelmanLibrary();
~VoxelmanLibrary();
int get_atlas_columns() const { return _atlas_columns; }
void set_atlas_columns(int s);
int get_atlas_rows() const { return _atlas_rows; }
void set_atlas_rows(int s);
bool get_is_textured() const;
void set_is_textured(bool s);
Ref<Material> get_material() const { return _material; }
void set_material(Ref<Material> mat) { _material = mat; }
Ref<Material> get_prop_material() const { return _prop_material; }
void set_prop_material(Ref<Material> mat) { _prop_material = mat; }
int get_voxel_count() const;
virtual Ref<VoxelSurface> get_voxel_surface(int index) const;
virtual void set_voxel_surface(int index, Ref<VoxelSurface> value);
virtual void remove_surface(int index);
virtual int get_num_surfaces();
Ref<VoxelSurface> get_voxel_surface(int index) const;
void set_voxel_surface(int index, Ref<VoxelSurface> value);
virtual void refresh_rects();
Vector<Variant> get_voxel_surfaces();
void set_voxel_surfaces(const Vector<Variant> &effects);
int get_voxel_types_count();
_FORCE_INLINE_ bool has_voxel(int id) const { return _voxel_surfaces[id].is_valid(); }
_FORCE_INLINE_ Ref<VoxelSurface> get_surface(int id) const { return _voxel_surfaces[id]; }
VoxelmanLibrary();
~VoxelmanLibrary();
protected:
static void _bind_methods();
private:
Vector<Ref<VoxelSurface> > _voxel_surfaces;
Ref<Material> _material;
Ref<Material> _prop_material;
//atlas
int _atlas_columns;
int _atlas_rows;
bool _is_textured;
};
#endif // VOXEL_LIBRARY_H

View File

@ -0,0 +1,117 @@
#include "voxelman_library_simple.h"
int VoxelmanLibrarySimple::get_atlas_columns() const {
return _atlas_columns;
}
void VoxelmanLibrarySimple::set_atlas_columns(int s) {
ERR_FAIL_COND(s < 0);
_atlas_columns = s;
}
int VoxelmanLibrarySimple::get_atlas_rows() const {
return _atlas_rows;
}
void VoxelmanLibrarySimple::set_atlas_rows(int s) {
ERR_FAIL_COND(s < 0);
_atlas_rows = s;
}
Ref<VoxelSurface> VoxelmanLibrarySimple::get_voxel_surface(int index) const {
ERR_FAIL_INDEX_V(index, _voxel_surfaces.size(), Ref<VoxelSurface>(NULL));
return _voxel_surfaces[index];
}
void VoxelmanLibrarySimple::set_voxel_surface(int index, Ref<VoxelSurface> value) {
ERR_FAIL_COND(index < 0);
if (_voxel_surfaces.size() < index) {
_voxel_surfaces.resize(index + 1);
}
if (_voxel_surfaces[index].is_valid()) {
_voxel_surfaces.get(index)->set_library(Ref<VoxelmanLibrarySimple>(NULL));
}
if (value.is_valid()) {
value->set_library(Ref<VoxelmanLibrarySimple>(this));
_voxel_surfaces.set(index, value);
}
}
void VoxelmanLibrarySimple::remove_surface(int index) {
_voxel_surfaces.remove(index);
}
int VoxelmanLibrarySimple::get_num_surfaces() {
return _voxel_surfaces.size();
}
Vector<Variant> VoxelmanLibrarySimple::get_voxel_surfaces() {
Vector<Variant> r;
for (int i = 0; i < _voxel_surfaces.size(); i++) {
r.push_back(_voxel_surfaces[i].get_ref_ptr());
}
return r;
}
void VoxelmanLibrarySimple::set_voxel_surfaces(const Vector<Variant> &surfaces) {
_voxel_surfaces.clear();
for (int i = 0; i < surfaces.size(); i++) {
Ref<VoxelSurfaceSimple> surface = Ref<VoxelSurfaceSimple>(surfaces[i]);
if (surface.is_valid()) {
surface->set_library(this);
}
_voxel_surfaces.push_back(surface);
}
}
void VoxelmanLibrarySimple::refresh_rects() {
for (int i = 0; i < _voxel_surfaces.size(); i++) {
Ref<VoxelSurfaceSimple> surface = Ref<VoxelSurfaceSimple>(_voxel_surfaces[i]);
if (surface.is_valid()) {
surface->refresh_rects();
}
}
}
VoxelmanLibrarySimple::VoxelmanLibrarySimple() {
_atlas_rows = 8;
_atlas_columns = 8;
}
VoxelmanLibrarySimple::~VoxelmanLibrarySimple() {
for (int i = 0; i < _voxel_surfaces.size(); ++i) {
Ref<VoxelSurface> surface = _voxel_surfaces[i];
if (surface.is_valid()) {
surface->set_library(Ref<VoxelmanLibrarySimple>());
surface.unref();
}
}
_voxel_surfaces.clear();
}
void VoxelmanLibrarySimple::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_atlas_columns"), &VoxelmanLibrarySimple::get_atlas_columns);
ClassDB::bind_method(D_METHOD("set_atlas_columns", "value"), &VoxelmanLibrarySimple::set_atlas_columns);
ADD_PROPERTY(PropertyInfo(Variant::INT, "atlas_columns"), "set_atlas_columns", "get_atlas_columns");
ClassDB::bind_method(D_METHOD("get_atlas_rows"), &VoxelmanLibrarySimple::get_atlas_rows);
ClassDB::bind_method(D_METHOD("set_atlas_rows", "value"), &VoxelmanLibrarySimple::set_atlas_rows);
ADD_PROPERTY(PropertyInfo(Variant::INT, "atlas_rows"), "set_atlas_rows", "get_atlas_rows");
ClassDB::bind_method(D_METHOD("get_voxel_surfaces"), &VoxelmanLibrarySimple::get_voxel_surfaces);
ClassDB::bind_method(D_METHOD("set_voxel_surfaces"), &VoxelmanLibrarySimple::set_voxel_surfaces);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "voxel_surfaces", PROPERTY_HINT_NONE, "17/17:VoxelSurfaceSimple", PROPERTY_USAGE_DEFAULT, "VoxelSurfaceSimple"), "set_voxel_surfaces", "get_voxel_surfaces");
}

View File

@ -0,0 +1,49 @@
#ifndef VOXELMAN_LIBRARY_SIMPLE_H
#define VOXELMAN_LIBRARY_SIMPLE_H
#include "voxelman_library.h"
#include "core/resource.h"
#include "scene/resources/material.h"
#include "../data/voxel_light.h"
#include "voxel_surface_simple.h"
class VoxelSurfaceSimple;
class VoxelMesher;
class VoxelmanLibrarySimple : public VoxelmanLibrary {
GDCLASS(VoxelmanLibrarySimple, VoxelmanLibrary)
public:
int get_atlas_columns() const;
void set_atlas_columns(int s);
int get_atlas_rows() const;
void set_atlas_rows(int s);
Ref<VoxelSurface> get_voxel_surface(int index) const;
void set_voxel_surface(int index, Ref<VoxelSurface> value);
void remove_surface(int index);
int get_num_surfaces();
Vector<Variant> get_voxel_surfaces();
void set_voxel_surfaces(const Vector<Variant> &surfaces);
void refresh_rects();
VoxelmanLibrarySimple();
~VoxelmanLibrarySimple();
protected:
static void _bind_methods();
private:
Vector<Ref<VoxelSurfaceSimple> > _voxel_surfaces;
//atlas
int _atlas_columns;
int _atlas_rows;
};
#endif // VOXEL_LIBRARY_H

View File

@ -1,7 +1,10 @@
#include "register_types.h"
#include "library/voxel_surface.h"
#include "library/voxel_surface_simple.h"
#include "library/voxelman_library.h"
#include "library/voxelman_library_simple.h"
#include "data/voxel_light.h"
#include "meshers/voxel_mesher.h"
@ -52,7 +55,10 @@ void register_voxelman_types() {
ClassDB::register_class<TransvoxelCellData>();
ClassDB::register_class<VoxelSurface>();
ClassDB::register_class<VoxelSurfaceSimple>();
ClassDB::register_class<VoxelmanLibrary>();
ClassDB::register_class<VoxelmanLibrarySimple>();
ClassDB::register_class<VoxelLight>();