mirror of
https://github.com/Relintai/voxelman.git
synced 2025-02-12 16:30:06 +01:00
Added props top the merger library, also it will now merge together all added prop textures. Also api cleanups.
This commit is contained in:
parent
a2fea26837
commit
919080a1b5
@ -22,6 +22,8 @@ SOFTWARE.
|
||||
|
||||
#include "voxelman_library.h"
|
||||
|
||||
#include "../props/prop_data.h"
|
||||
|
||||
Ref<Material> VoxelmanLibrary::get_material() const {
|
||||
return _material;
|
||||
}
|
||||
@ -51,37 +53,52 @@ void VoxelmanLibrary::set_clutter_material(Ref<Material> mat) {
|
||||
}
|
||||
|
||||
//Surfaces
|
||||
Ref<VoxelSurface> VoxelmanLibrary::get_voxel_surface(int index) const {
|
||||
Ref<VoxelSurface> VoxelmanLibrary::get_voxel_surface(const int index) {
|
||||
return Ref<VoxelSurface>();
|
||||
}
|
||||
void VoxelmanLibrary::add_voxel_surface(Ref<VoxelSurface> value) {
|
||||
}
|
||||
void VoxelmanLibrary::set_voxel_surface(int index, Ref<VoxelSurface> value) {
|
||||
void VoxelmanLibrary::set_voxel_surface(const int index, Ref<VoxelSurface> value) {
|
||||
}
|
||||
void VoxelmanLibrary::remove_surface(int index) {
|
||||
void VoxelmanLibrary::remove_surface(const int index) {
|
||||
}
|
||||
int VoxelmanLibrary::get_num_surfaces() {
|
||||
int VoxelmanLibrary::get_num_surfaces() const {
|
||||
return 0;
|
||||
}
|
||||
void VoxelmanLibrary::clear_surfaces() {
|
||||
}
|
||||
|
||||
//Liquids
|
||||
Ref<VoxelSurface> VoxelmanLibrary::get_liquid_voxel_surface(int index) const {
|
||||
Ref<VoxelSurface> VoxelmanLibrary::get_liquid_surface(const int index) {
|
||||
return Ref<VoxelSurface>();
|
||||
}
|
||||
void VoxelmanLibrary::add_liquid_voxel_surface(Ref<VoxelSurface> value) {
|
||||
void VoxelmanLibrary::add_liquid_surface(Ref<VoxelSurface> value) {
|
||||
}
|
||||
void VoxelmanLibrary::set_liquid_voxel_surface(int index, Ref<VoxelSurface> value) {
|
||||
void VoxelmanLibrary::set_liquid_surface(const int index, Ref<VoxelSurface> value) {
|
||||
}
|
||||
void VoxelmanLibrary::remove_liquid_surface(int index) {
|
||||
void VoxelmanLibrary::remove_liquid_surface(const int index) {
|
||||
}
|
||||
int VoxelmanLibrary::get_liquid_num_surfaces() {
|
||||
int VoxelmanLibrary::get_num_liquid_surfaces() const {
|
||||
return 0;
|
||||
}
|
||||
void VoxelmanLibrary::clear_liquid_surfaces() {
|
||||
}
|
||||
|
||||
Ref<PropData> VoxelmanLibrary::get_prop(const int id) {
|
||||
return Ref<PropData>();
|
||||
}
|
||||
void VoxelmanLibrary::add_prop(Ref<PropData> value) {
|
||||
}
|
||||
void VoxelmanLibrary::set_prop(const int id, Ref<PropData> value) {
|
||||
}
|
||||
void VoxelmanLibrary::remove_prop(const int id) {
|
||||
}
|
||||
int VoxelmanLibrary::get_num_props() const {
|
||||
return 0;
|
||||
}
|
||||
void VoxelmanLibrary::clear_props() {
|
||||
}
|
||||
|
||||
//Rects
|
||||
void VoxelmanLibrary::refresh_rects() {
|
||||
}
|
||||
@ -121,17 +138,26 @@ void VoxelmanLibrary::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "clutter_material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_clutter_material", "get_clutter_material");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_voxel_surface", "index"), &VoxelmanLibrary::get_voxel_surface);
|
||||
ClassDB::bind_method(D_METHOD("add_voxel_surface", "value"), &VoxelmanLibrary::add_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("clear_surfaces"), &VoxelmanLibrary::clear_surfaces);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_liquid_voxel_surface", "index"), &VoxelmanLibrary::get_liquid_voxel_surface);
|
||||
ClassDB::bind_method(D_METHOD("set_liquid_voxel_surface", "index", "surface"), &VoxelmanLibrary::set_liquid_voxel_surface);
|
||||
ClassDB::bind_method(D_METHOD("get_liquid_surface", "index"), &VoxelmanLibrary::get_liquid_surface);
|
||||
ClassDB::bind_method(D_METHOD("add_liquid_surface", "value"), &VoxelmanLibrary::add_liquid_surface);
|
||||
ClassDB::bind_method(D_METHOD("set_liquid_surface", "index", "surface"), &VoxelmanLibrary::set_liquid_surface);
|
||||
ClassDB::bind_method(D_METHOD("remove_liquid_surface", "index"), &VoxelmanLibrary::remove_liquid_surface);
|
||||
ClassDB::bind_method(D_METHOD("get_liquid_num_surfaces"), &VoxelmanLibrary::get_liquid_num_surfaces);
|
||||
ClassDB::bind_method(D_METHOD("get_num_liquid_surfaces"), &VoxelmanLibrary::get_num_liquid_surfaces);
|
||||
ClassDB::bind_method(D_METHOD("clear_liquid_surfaces"), &VoxelmanLibrary::clear_liquid_surfaces);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_prop", "id"), &VoxelmanLibrary::get_prop);
|
||||
ClassDB::bind_method(D_METHOD("add_prop", "value"), &VoxelmanLibrary::add_prop);
|
||||
ClassDB::bind_method(D_METHOD("set_prop", "id", "surface"), &VoxelmanLibrary::set_prop);
|
||||
ClassDB::bind_method(D_METHOD("remove_prop", "id"), &VoxelmanLibrary::remove_prop);
|
||||
ClassDB::bind_method(D_METHOD("get_num_props"), &VoxelmanLibrary::get_num_props);
|
||||
ClassDB::bind_method(D_METHOD("clear_props"), &VoxelmanLibrary::clear_props);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("refresh_rects"), &VoxelmanLibrary::refresh_rects);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("setup_material_albedo", "material_index", "texture"), &VoxelmanLibrary::setup_material_albedo);
|
||||
|
@ -31,6 +31,7 @@ SOFTWARE.
|
||||
|
||||
class VoxelSurface;
|
||||
class VoxelMesher;
|
||||
class PropData;
|
||||
|
||||
class VoxelmanLibrary : public Resource {
|
||||
GDCLASS(VoxelmanLibrary, Resource)
|
||||
@ -56,20 +57,27 @@ public:
|
||||
Ref<Material> get_clutter_material() const;
|
||||
void set_clutter_material(Ref<Material> mat);
|
||||
|
||||
virtual Ref<VoxelSurface> get_voxel_surface(int index) const;
|
||||
virtual Ref<VoxelSurface> get_voxel_surface(const int index);
|
||||
virtual void add_voxel_surface(Ref<VoxelSurface> value);
|
||||
virtual void set_voxel_surface(int index, Ref<VoxelSurface> value);
|
||||
virtual void remove_surface(int index);
|
||||
virtual int get_num_surfaces();
|
||||
virtual void set_voxel_surface(const int index, Ref<VoxelSurface> value);
|
||||
virtual void remove_surface(const int index);
|
||||
virtual int get_num_surfaces() const;
|
||||
virtual void clear_surfaces();
|
||||
|
||||
virtual Ref<VoxelSurface> get_liquid_voxel_surface(int index) const;
|
||||
virtual void add_liquid_voxel_surface(Ref<VoxelSurface> value);
|
||||
virtual void set_liquid_voxel_surface(int index, Ref<VoxelSurface> value);
|
||||
virtual void remove_liquid_surface(int index);
|
||||
virtual int get_liquid_num_surfaces();
|
||||
virtual Ref<VoxelSurface> get_liquid_surface(const int index);
|
||||
virtual void add_liquid_surface(Ref<VoxelSurface> value);
|
||||
virtual void set_liquid_surface(const int index, Ref<VoxelSurface> value);
|
||||
virtual void remove_liquid_surface(const int index);
|
||||
virtual int get_num_liquid_surfaces() const;
|
||||
virtual void clear_liquid_surfaces();
|
||||
|
||||
virtual Ref<PropData> get_prop(const int id);
|
||||
virtual void add_prop(Ref<PropData> value);
|
||||
virtual void set_prop(const int id, Ref<PropData> value);
|
||||
virtual void remove_prop(const int id);
|
||||
virtual int get_num_props() const;
|
||||
virtual void clear_props();
|
||||
|
||||
virtual void refresh_rects();
|
||||
|
||||
void setup_material_albedo(int material_index, Ref<Texture> texture);
|
||||
|
@ -22,11 +22,18 @@ SOFTWARE.
|
||||
|
||||
#include "voxelman_library_merger.h"
|
||||
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
#include "../props/prop_data.h"
|
||||
#include "../props/prop_data_mesh.h"
|
||||
#include "../props/prop_data_prop.h"
|
||||
|
||||
int VoxelmanLibraryMerger::get_texture_flags() const {
|
||||
return _packer->get_texture_flags();
|
||||
}
|
||||
void VoxelmanLibraryMerger::set_texture_flags(const int flags) {
|
||||
_packer->set_texture_flags(flags);
|
||||
_prop_packer->set_texture_flags(flags);
|
||||
}
|
||||
|
||||
int VoxelmanLibraryMerger::get_max_atlas_size() const {
|
||||
@ -34,6 +41,7 @@ int VoxelmanLibraryMerger::get_max_atlas_size() const {
|
||||
}
|
||||
void VoxelmanLibraryMerger::set_max_atlas_size(const int size) {
|
||||
_packer->set_max_atlas_size(size);
|
||||
_prop_packer->set_max_atlas_size(size);
|
||||
}
|
||||
|
||||
bool VoxelmanLibraryMerger::get_keep_original_atlases() const {
|
||||
@ -41,6 +49,7 @@ bool VoxelmanLibraryMerger::get_keep_original_atlases() const {
|
||||
}
|
||||
void VoxelmanLibraryMerger::set_keep_original_atlases(const bool value) {
|
||||
_packer->set_keep_original_atlases(value);
|
||||
_prop_packer->set_keep_original_atlases(value);
|
||||
}
|
||||
|
||||
Color VoxelmanLibraryMerger::get_background_color() const {
|
||||
@ -48,6 +57,7 @@ Color VoxelmanLibraryMerger::get_background_color() const {
|
||||
}
|
||||
void VoxelmanLibraryMerger::set_background_color(const Color color) {
|
||||
_packer->set_background_color(color);
|
||||
_prop_packer->set_background_color(color);
|
||||
}
|
||||
|
||||
int VoxelmanLibraryMerger::get_margin() const {
|
||||
@ -55,10 +65,11 @@ int VoxelmanLibraryMerger::get_margin() const {
|
||||
}
|
||||
void VoxelmanLibraryMerger::set_margin(const int margin) {
|
||||
_packer->set_margin(margin);
|
||||
_prop_packer->set_margin(margin);
|
||||
}
|
||||
|
||||
//Surfaces
|
||||
Ref<VoxelSurface> VoxelmanLibraryMerger::get_voxel_surface(int index) const {
|
||||
Ref<VoxelSurface> VoxelmanLibraryMerger::get_voxel_surface(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _voxel_surfaces.size(), Ref<VoxelSurface>(NULL));
|
||||
|
||||
return _voxel_surfaces[index];
|
||||
@ -73,7 +84,7 @@ void VoxelmanLibraryMerger::add_voxel_surface(Ref<VoxelSurface> value) {
|
||||
_voxel_surfaces.push_back(value);
|
||||
}
|
||||
|
||||
void VoxelmanLibraryMerger::set_voxel_surface(int index, Ref<VoxelSurface> value) {
|
||||
void VoxelmanLibraryMerger::set_voxel_surface(const int index, Ref<VoxelSurface> value) {
|
||||
ERR_FAIL_COND(index < 0);
|
||||
|
||||
if (_voxel_surfaces.size() < index) {
|
||||
@ -91,11 +102,11 @@ void VoxelmanLibraryMerger::set_voxel_surface(int index, Ref<VoxelSurface> value
|
||||
}
|
||||
}
|
||||
|
||||
void VoxelmanLibraryMerger::remove_surface(int index) {
|
||||
void VoxelmanLibraryMerger::remove_surface(const int index) {
|
||||
_voxel_surfaces.remove(index);
|
||||
}
|
||||
|
||||
int VoxelmanLibraryMerger::get_num_surfaces() {
|
||||
int VoxelmanLibraryMerger::get_num_surfaces() const {
|
||||
return _voxel_surfaces.size();
|
||||
}
|
||||
|
||||
@ -146,13 +157,13 @@ void VoxelmanLibraryMerger::set_voxel_surfaces(const Vector<Variant> &surfaces)
|
||||
}
|
||||
|
||||
//Liquids
|
||||
Ref<VoxelSurface> VoxelmanLibraryMerger::get_liquid_voxel_surface(int index) const {
|
||||
Ref<VoxelSurface> VoxelmanLibraryMerger::get_liquid_voxel_surface(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _liquid_surfaces.size(), Ref<VoxelSurface>(NULL));
|
||||
|
||||
return _liquid_surfaces[index];
|
||||
}
|
||||
|
||||
void VoxelmanLibraryMerger::add_liquid_voxel_surface(Ref<VoxelSurface> value) {
|
||||
void VoxelmanLibraryMerger::add_liquid_surface(Ref<VoxelSurface> value) {
|
||||
ERR_FAIL_COND(!value.is_valid());
|
||||
|
||||
value->set_library(Ref<VoxelmanLibraryMerger>(this));
|
||||
@ -161,7 +172,7 @@ void VoxelmanLibraryMerger::add_liquid_voxel_surface(Ref<VoxelSurface> value) {
|
||||
_liquid_surfaces.push_back(value);
|
||||
}
|
||||
|
||||
void VoxelmanLibraryMerger::set_liquid_voxel_surface(int index, Ref<VoxelSurface> value) {
|
||||
void VoxelmanLibraryMerger::set_liquid_voxel_surface(const int index, Ref<VoxelSurface> value) {
|
||||
ERR_FAIL_COND(index < 0);
|
||||
|
||||
if (_liquid_surfaces.size() < index) {
|
||||
@ -179,11 +190,11 @@ void VoxelmanLibraryMerger::set_liquid_voxel_surface(int index, Ref<VoxelSurface
|
||||
}
|
||||
}
|
||||
|
||||
void VoxelmanLibraryMerger::remove_liquid_surface(int index) {
|
||||
void VoxelmanLibraryMerger::remove_liquid_surface(const int index) {
|
||||
_liquid_surfaces.remove(index);
|
||||
}
|
||||
|
||||
int VoxelmanLibraryMerger::get_liquid_num_surfaces() {
|
||||
int VoxelmanLibraryMerger::get_num_liquid_surfaces() const {
|
||||
return _liquid_surfaces.size();
|
||||
}
|
||||
|
||||
@ -223,6 +234,58 @@ void VoxelmanLibraryMerger::set_liquid_voxel_surfaces(const Vector<Variant> &sur
|
||||
}
|
||||
}
|
||||
|
||||
Ref<PropData> VoxelmanLibraryMerger::get_prop(const int id) {
|
||||
if (_props.has(id))
|
||||
return _props[id];
|
||||
|
||||
return Ref<PropData>();
|
||||
}
|
||||
void VoxelmanLibraryMerger::add_prop(Ref<PropData> value) {
|
||||
if (!value.is_valid() || _props.has(value->get_id()))
|
||||
return;
|
||||
|
||||
_props[value->get_id()] = value;
|
||||
}
|
||||
void VoxelmanLibraryMerger::set_prop(const int id, Ref<PropData> value) {
|
||||
_props[value->get_id()] = value;
|
||||
}
|
||||
void VoxelmanLibraryMerger::remove_prop(const int id) {
|
||||
if (_props.has(id))
|
||||
_props.erase(id);
|
||||
}
|
||||
int VoxelmanLibraryMerger::get_num_props() const {
|
||||
return _props.size();
|
||||
}
|
||||
void VoxelmanLibraryMerger::clear_props() {
|
||||
_props.clear();
|
||||
}
|
||||
|
||||
/*
|
||||
Vector<Variant> VoxelmanLibraryMerger::get_props() {
|
||||
Vector<Variant> r;
|
||||
|
||||
for (Map<int, Ref<PropData> >::Element *I = _props.front(); I; I = I->next()) {
|
||||
r.push_back(I->value().get_ref_ptr());
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void VoxelmanLibraryMerger::set_props(const Vector<Variant> &props) {
|
||||
_liquid_surfaces.clear();
|
||||
|
||||
for (int i = 0; i < props.size(); i++) {
|
||||
Ref<VoxelSurfaceMerger> surface = Ref<VoxelSurfaceMerger>(props[i]);
|
||||
|
||||
if (surface.is_valid()) {
|
||||
surface->set_library(this);
|
||||
}
|
||||
|
||||
_liquid_surfaces.push_back(surface);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void VoxelmanLibraryMerger::refresh_rects() {
|
||||
bool texture_added = false;
|
||||
for (int i = 0; i < _voxel_surfaces.size(); i++) {
|
||||
@ -281,6 +344,26 @@ void VoxelmanLibraryMerger::refresh_rects() {
|
||||
setup_material_albedo(MATERIAL_INDEX_VOXELS, tex);
|
||||
}
|
||||
|
||||
texture_added = false;
|
||||
for (Map<int, Ref<PropData> >::Element *I = _props.front(); I; I = I->next()) {
|
||||
Ref<PropData> prop = Ref<PropData>(I->value());
|
||||
|
||||
if (prop.is_valid()) {
|
||||
if (process_prop_textures(prop))
|
||||
texture_added = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (texture_added) {
|
||||
_prop_packer->merge();
|
||||
|
||||
ERR_FAIL_COND(_prop_packer->get_texture_count() == 0);
|
||||
|
||||
Ref<Texture> tex = _prop_packer->get_generated_texture(0);
|
||||
|
||||
setup_material_albedo(MATERIAL_INDEX_PROP, tex);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _voxel_surfaces.size(); i++) {
|
||||
Ref<VoxelSurfaceMerger> surface = _voxel_surfaces[i];
|
||||
|
||||
@ -320,9 +403,25 @@ void VoxelmanLibraryMerger::_setup_material_albedo(int material_index, Ref<Textu
|
||||
|
||||
if (spmat.is_valid()) {
|
||||
spmat->set_texture(SpatialMaterial::TEXTURE_ALBEDO, texture);
|
||||
return;
|
||||
}
|
||||
|
||||
Ref<ShaderMaterial> shmat = get_material();
|
||||
Ref<ShaderMaterial> shmat;
|
||||
|
||||
switch (material_index) {
|
||||
case MATERIAL_INDEX_VOXELS:
|
||||
shmat = get_material();
|
||||
break;
|
||||
case MATERIAL_INDEX_PROP:
|
||||
shmat = get_prop_material();
|
||||
break;
|
||||
case MATERIAL_INDEX_LIQUID:
|
||||
shmat = get_liquid_material();
|
||||
break;
|
||||
case MATERIAL_INDEX_CLUTTER:
|
||||
shmat = get_clutter_material();
|
||||
break;
|
||||
}
|
||||
|
||||
if (shmat.is_valid()) {
|
||||
shmat->set_shader_param("texture_albedo", texture);
|
||||
@ -335,6 +434,12 @@ VoxelmanLibraryMerger::VoxelmanLibraryMerger() {
|
||||
_packer->set_max_atlas_size(1024);
|
||||
_packer->set_keep_original_atlases(false);
|
||||
_packer->set_margin(0);
|
||||
|
||||
_prop_packer.instance();
|
||||
_prop_packer->set_texture_flags(Texture::FLAG_MIPMAPS | Texture::FLAG_FILTER);
|
||||
_prop_packer->set_max_atlas_size(1024);
|
||||
_prop_packer->set_keep_original_atlases(false);
|
||||
_prop_packer->set_margin(0);
|
||||
}
|
||||
|
||||
VoxelmanLibraryMerger::~VoxelmanLibraryMerger() {
|
||||
@ -358,10 +463,46 @@ VoxelmanLibraryMerger::~VoxelmanLibraryMerger() {
|
||||
|
||||
_liquid_surfaces.clear();
|
||||
|
||||
_prop_packer->clear();
|
||||
_prop_packer.unref();
|
||||
|
||||
_packer->clear();
|
||||
_packer.unref();
|
||||
}
|
||||
|
||||
bool VoxelmanLibraryMerger::process_prop_textures(Ref<PropData> prop) {
|
||||
if (!prop.is_valid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool texture_added = false;
|
||||
|
||||
for (int i = 0; i < prop->get_prop_count(); ++i) {
|
||||
Ref<PropDataMesh> pdm = prop->get_prop(i);
|
||||
|
||||
if (pdm.is_valid()) {
|
||||
Ref<Texture> tex = pdm->get_texture();
|
||||
|
||||
if (!tex.is_valid())
|
||||
continue;
|
||||
|
||||
if (!_prop_packer->contains_texture(tex)) {
|
||||
_prop_packer->add_texture(tex);
|
||||
texture_added = true;
|
||||
}
|
||||
}
|
||||
|
||||
Ref<PropDataProp> pdp = prop->get_prop(i);
|
||||
|
||||
if (pdp.is_valid()) {
|
||||
if (process_prop_textures(pdp))
|
||||
texture_added = true;
|
||||
}
|
||||
}
|
||||
|
||||
return texture_added;
|
||||
}
|
||||
|
||||
void VoxelmanLibraryMerger::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_texture_flags"), &VoxelmanLibraryMerger::get_texture_flags);
|
||||
ClassDB::bind_method(D_METHOD("set_texture_flags", "flags"), &VoxelmanLibraryMerger::set_texture_flags);
|
||||
@ -391,5 +532,9 @@ void VoxelmanLibraryMerger::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_liquid_voxel_surfaces"), &VoxelmanLibraryMerger::set_liquid_voxel_surfaces);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "liquid_voxel_surfaces", PROPERTY_HINT_NONE, "17/17:VoxelSurfaceMerger", PROPERTY_USAGE_DEFAULT, "VoxelSurfaceMerger"), "set_liquid_voxel_surfaces", "get_liquid_voxel_surfaces");
|
||||
|
||||
//ClassDB::bind_method(D_METHOD("get_props"), &VoxelmanLibraryMerger::get_props);
|
||||
//ClassDB::bind_method(D_METHOD("set_props"), &VoxelmanLibraryMerger::set_props);
|
||||
//ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "props", PROPERTY_HINT_NONE, "17/17:PropData", PROPERTY_USAGE_DEFAULT, "PropData"), "set_props", "get_props");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_setup_material_albedo", "material_index", "texture"), &VoxelmanLibraryMerger::_setup_material_albedo);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ SOFTWARE.
|
||||
|
||||
#include "voxelman_library.h"
|
||||
|
||||
#include "core/map.h"
|
||||
#include "core/resource.h"
|
||||
#include "scene/resources/material.h"
|
||||
|
||||
@ -33,6 +34,7 @@ SOFTWARE.
|
||||
|
||||
class VoxelSurfaceSimple;
|
||||
class VoxelMesher;
|
||||
class PropData;
|
||||
|
||||
class VoxelmanLibraryMerger : public VoxelmanLibrary {
|
||||
GDCLASS(VoxelmanLibraryMerger, VoxelmanLibrary)
|
||||
@ -53,26 +55,36 @@ public:
|
||||
int get_margin() const;
|
||||
void set_margin(const int margin);
|
||||
|
||||
Ref<VoxelSurface> get_voxel_surface(int index) const;
|
||||
Ref<VoxelSurface> get_voxel_surface(const int index);
|
||||
void add_voxel_surface(Ref<VoxelSurface> value);
|
||||
void set_voxel_surface(int index, Ref<VoxelSurface> value);
|
||||
void remove_surface(int index);
|
||||
int get_num_surfaces();
|
||||
void set_voxel_surface(const int index, Ref<VoxelSurface> value);
|
||||
void remove_surface(const int index);
|
||||
int get_num_surfaces() const;
|
||||
void clear_surfaces();
|
||||
|
||||
Vector<Variant> get_voxel_surfaces();
|
||||
void set_voxel_surfaces(const Vector<Variant> &surfaces);
|
||||
|
||||
Ref<VoxelSurface> get_liquid_voxel_surface(int index) const;
|
||||
void add_liquid_voxel_surface(Ref<VoxelSurface> value);
|
||||
void set_liquid_voxel_surface(int index, Ref<VoxelSurface> value);
|
||||
void remove_liquid_surface(int index);
|
||||
int get_liquid_num_surfaces();
|
||||
Ref<VoxelSurface> get_liquid_voxel_surface(const int index);
|
||||
void add_liquid_surface(Ref<VoxelSurface> value);
|
||||
void set_liquid_voxel_surface(const int index, Ref<VoxelSurface> value);
|
||||
void remove_liquid_surface(const int index);
|
||||
int get_num_liquid_surfaces() const;
|
||||
void clear_liquid_surfaces();
|
||||
|
||||
Vector<Variant> get_liquid_voxel_surfaces();
|
||||
void set_liquid_voxel_surfaces(const Vector<Variant> &surfaces);
|
||||
|
||||
Ref<PropData> get_prop(const int id);
|
||||
void add_prop(Ref<PropData> value);
|
||||
void set_prop(const int id, Ref<PropData> value);
|
||||
void remove_prop(const int id);
|
||||
int get_num_props() const;
|
||||
void clear_props();
|
||||
|
||||
//Vector<Variant> get_props();
|
||||
//void set_props(const Vector<Variant> &props);
|
||||
|
||||
void refresh_rects();
|
||||
|
||||
void _setup_material_albedo(int material_index, Ref<Texture> texture);
|
||||
@ -81,13 +93,18 @@ public:
|
||||
~VoxelmanLibraryMerger();
|
||||
|
||||
protected:
|
||||
bool process_prop_textures(Ref<PropData> prop);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Vector<Ref<VoxelSurfaceMerger> > _voxel_surfaces;
|
||||
Vector<Ref<VoxelSurfaceMerger> > _liquid_surfaces;
|
||||
//Vector<Ref<PropData> > _prop_vector;
|
||||
Map<int, Ref<PropData> > _props;
|
||||
|
||||
Ref<TexturePacker> _packer;
|
||||
Ref<TexturePacker> _prop_packer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -41,7 +41,7 @@ void VoxelmanLibrarySimple::set_atlas_rows(int s) {
|
||||
}
|
||||
|
||||
//Surfaces
|
||||
Ref<VoxelSurface> VoxelmanLibrarySimple::get_voxel_surface(int index) const {
|
||||
Ref<VoxelSurface> VoxelmanLibrarySimple::get_voxel_surface(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _voxel_surfaces.size(), Ref<VoxelSurface>(NULL));
|
||||
|
||||
return _voxel_surfaces[index];
|
||||
@ -56,7 +56,7 @@ void VoxelmanLibrarySimple::add_voxel_surface(Ref<VoxelSurface> value) {
|
||||
_voxel_surfaces.push_back(value);
|
||||
}
|
||||
|
||||
void VoxelmanLibrarySimple::set_voxel_surface(int index, Ref<VoxelSurface> value) {
|
||||
void VoxelmanLibrarySimple::set_voxel_surface(const int index, Ref<VoxelSurface> value) {
|
||||
ERR_FAIL_COND(index < 0);
|
||||
|
||||
if (_voxel_surfaces.size() < index) {
|
||||
@ -74,11 +74,11 @@ void VoxelmanLibrarySimple::set_voxel_surface(int index, Ref<VoxelSurface> value
|
||||
}
|
||||
}
|
||||
|
||||
void VoxelmanLibrarySimple::remove_surface(int index) {
|
||||
void VoxelmanLibrarySimple::remove_surface(const int index) {
|
||||
_voxel_surfaces.remove(index);
|
||||
}
|
||||
|
||||
int VoxelmanLibrarySimple::get_num_surfaces() {
|
||||
int VoxelmanLibrarySimple::get_num_surfaces() const {
|
||||
return _voxel_surfaces.size();
|
||||
}
|
||||
|
||||
@ -110,13 +110,13 @@ void VoxelmanLibrarySimple::set_voxel_surfaces(const Vector<Variant> &surfaces)
|
||||
}
|
||||
|
||||
//Liquids
|
||||
Ref<VoxelSurface> VoxelmanLibrarySimple::get_liquid_voxel_surface(int index) const {
|
||||
Ref<VoxelSurface> VoxelmanLibrarySimple::get_liquid_surface(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _liquid_surfaces.size(), Ref<VoxelSurface>(NULL));
|
||||
|
||||
return _liquid_surfaces[index];
|
||||
}
|
||||
|
||||
void VoxelmanLibrarySimple::add_liquid_voxel_surface(Ref<VoxelSurface> value) {
|
||||
void VoxelmanLibrarySimple::add_liquid_surface(Ref<VoxelSurface> value) {
|
||||
ERR_FAIL_COND(!value.is_valid());
|
||||
|
||||
value->set_library(Ref<VoxelmanLibrarySimple>(this));
|
||||
@ -125,7 +125,7 @@ void VoxelmanLibrarySimple::add_liquid_voxel_surface(Ref<VoxelSurface> value) {
|
||||
_liquid_surfaces.push_back(value);
|
||||
}
|
||||
|
||||
void VoxelmanLibrarySimple::set_liquid_voxel_surface(int index, Ref<VoxelSurface> value) {
|
||||
void VoxelmanLibrarySimple::set_liquid_surface(const int index, Ref<VoxelSurface> value) {
|
||||
ERR_FAIL_COND(index < 0);
|
||||
|
||||
if (_liquid_surfaces.size() < index) {
|
||||
@ -143,11 +143,11 @@ void VoxelmanLibrarySimple::set_liquid_voxel_surface(int index, Ref<VoxelSurface
|
||||
}
|
||||
}
|
||||
|
||||
void VoxelmanLibrarySimple::remove_liquid_surface(int index) {
|
||||
void VoxelmanLibrarySimple::remove_liquid_surface(const int index) {
|
||||
_liquid_surfaces.remove(index);
|
||||
}
|
||||
|
||||
int VoxelmanLibrarySimple::get_liquid_num_surfaces() {
|
||||
int VoxelmanLibrarySimple::get_num_liquid_surfaces() const {
|
||||
return _liquid_surfaces.size();
|
||||
}
|
||||
|
||||
|
@ -44,21 +44,21 @@ public:
|
||||
int get_atlas_rows() const;
|
||||
void set_atlas_rows(int s);
|
||||
|
||||
Ref<VoxelSurface> get_voxel_surface(int index) const;
|
||||
Ref<VoxelSurface> get_voxel_surface(const int index);
|
||||
void add_voxel_surface(Ref<VoxelSurface> value);
|
||||
void set_voxel_surface(int index, Ref<VoxelSurface> value);
|
||||
void remove_surface(int index);
|
||||
int get_num_surfaces();
|
||||
void set_voxel_surface(const int index, Ref<VoxelSurface> value);
|
||||
void remove_surface(const int index);
|
||||
int get_num_surfaces() const;
|
||||
void clear_surfaces();
|
||||
|
||||
Vector<Variant> get_voxel_surfaces();
|
||||
void set_voxel_surfaces(const Vector<Variant> &surfaces);
|
||||
|
||||
Ref<VoxelSurface> get_liquid_voxel_surface(int index) const;
|
||||
void add_liquid_voxel_surface(Ref<VoxelSurface> value);
|
||||
void set_liquid_voxel_surface(int index, Ref<VoxelSurface> value);
|
||||
void remove_liquid_surface(int index);
|
||||
int get_liquid_num_surfaces();
|
||||
Ref<VoxelSurface> get_liquid_surface(const int index);
|
||||
void add_liquid_surface(Ref<VoxelSurface> value);
|
||||
void set_liquid_surface(const int index, Ref<VoxelSurface> value);
|
||||
void remove_liquid_surface(const int index);
|
||||
int get_num_liquid_surfaces() const;
|
||||
void clear_liquid_surfaces();
|
||||
|
||||
Vector<Variant> get_liquid_voxel_surfaces();
|
||||
|
@ -25,6 +25,13 @@ SOFTWARE.
|
||||
#include "../world/voxel_chunk.h"
|
||||
#include "prop_data_prop.h"
|
||||
|
||||
int PropData::get_id() {
|
||||
return _id;
|
||||
}
|
||||
void PropData::set_id(int value) {
|
||||
_id = value;
|
||||
}
|
||||
|
||||
bool PropData::get_snap_to_mesh() {
|
||||
return _snap_to_mesh;
|
||||
}
|
||||
@ -227,6 +234,7 @@ Transform PropData::get_next_snapped_prop_transform_bind(Node *spatial, Transfor
|
||||
}
|
||||
|
||||
PropData::PropData() {
|
||||
_id = 0;
|
||||
_snap_to_mesh = false;
|
||||
_snap_axis = Vector3(0, -1, 0);
|
||||
}
|
||||
|
@ -46,6 +46,9 @@ class PropData : public Resource {
|
||||
GDCLASS(PropData, Resource);
|
||||
|
||||
public:
|
||||
int get_id();
|
||||
void set_id(int value);
|
||||
|
||||
bool get_snap_to_mesh();
|
||||
void set_snap_to_mesh(bool value);
|
||||
|
||||
@ -78,6 +81,7 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
int _id;
|
||||
bool _snap_to_mesh;
|
||||
Vector3 _snap_axis;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user