mirror of
https://github.com/Relintai/voxelman.git
synced 2025-03-12 18:18:50 +01:00
Brought back the old Prop implementation, and PropTool, because not only this implementation was already done, it will work better than spawning possibly thousands of nodes with the props module, but I also found a way to eventually make it more user friendly.
This commit is contained in:
parent
014e6919c8
commit
88ab910eb8
18
SCsub
18
SCsub
@ -10,6 +10,7 @@ if os.path.isdir('../texture_packer'):
|
||||
has_texture_packer = True
|
||||
|
||||
if os.path.isdir('../mesh_data_resource'):
|
||||
print("adadadadadadadadadadada")
|
||||
module_env.Append(CPPDEFINES=['MESH_DATA_RESOURCE_PRESENT'])
|
||||
|
||||
if os.path.isdir('../props'):
|
||||
@ -19,6 +20,21 @@ sources = [
|
||||
|
||||
"register_types.cpp",
|
||||
|
||||
"props/prop_data.cpp",
|
||||
"props/prop_data_entry.cpp",
|
||||
"props/prop_data_scene.cpp",
|
||||
"props/prop_data_mesh.cpp",
|
||||
"props/prop_data_light.cpp",
|
||||
"props/prop_data_prop.cpp",
|
||||
"props/prop_data_entity.cpp",
|
||||
|
||||
"prop_tool/prop_tool.cpp",
|
||||
"prop_tool/prop_tool_entity.cpp",
|
||||
"prop_tool/prop_tool_prop.cpp",
|
||||
"prop_tool/prop_tool_scene.cpp",
|
||||
"prop_tool/prop_tool_light.cpp",
|
||||
"prop_tool/prop_tool_mesh.cpp",
|
||||
|
||||
"library/voxelman_library.cpp",
|
||||
"library/voxelman_library_simple.cpp",
|
||||
|
||||
@ -75,6 +91,8 @@ if has_texture_packer:
|
||||
sources.append("library/voxelman_library_merger.cpp")
|
||||
sources.append("library/voxel_surface_merger.cpp")
|
||||
|
||||
if env['tools']:
|
||||
sources.append("prop_tool/prop_tool_editor_plugin.cpp")
|
||||
|
||||
if ARGUMENTS.get('custom_modules_shared', 'no') == 'yes':
|
||||
# Shared lib compilation
|
||||
|
15
config.py
15
config.py
@ -10,6 +10,21 @@ def configure(env):
|
||||
|
||||
def get_doc_classes():
|
||||
return [
|
||||
"PropDataEntity",
|
||||
"PropDataEntry",
|
||||
"PropDataLight",
|
||||
"PropDataMesh",
|
||||
"PropDataProp",
|
||||
"PropDataScene",
|
||||
"PropData",
|
||||
|
||||
"PropTool",
|
||||
"PropToolEntity",
|
||||
"PropToolLight",
|
||||
"PropToolMesh",
|
||||
"PropToolProp",
|
||||
"PropToolScene",
|
||||
|
||||
"WorldArea",
|
||||
|
||||
"VoxelLight",
|
||||
|
@ -22,6 +22,7 @@ SOFTWARE.
|
||||
|
||||
#include "voxelman_library.h"
|
||||
|
||||
#include "../props/prop_data.h"
|
||||
#include "scene/resources/packed_scene.h"
|
||||
|
||||
#include "../defines.h"
|
||||
@ -123,6 +124,55 @@ void VoxelmanLibrary::set_liquid_materials(const Vector<Variant> &materials) {
|
||||
}
|
||||
}
|
||||
|
||||
//Prop Materials
|
||||
Ref<Material> VoxelmanLibrary::get_prop_material(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _prop_materials.size(), Ref<VoxelSurface>(NULL));
|
||||
|
||||
return _prop_materials[index];
|
||||
}
|
||||
|
||||
void VoxelmanLibrary::add_prop_material(const Ref<Material> &value) {
|
||||
ERR_FAIL_COND(!value.is_valid());
|
||||
|
||||
_prop_materials.push_back(value);
|
||||
}
|
||||
|
||||
void VoxelmanLibrary::set_prop_material(const int index, const Ref<Material> &value) {
|
||||
ERR_FAIL_INDEX(index, _prop_materials.size());
|
||||
|
||||
_prop_materials.set(index, value);
|
||||
}
|
||||
|
||||
void VoxelmanLibrary::remove_prop_material(const int index) {
|
||||
_prop_materials.remove(index);
|
||||
}
|
||||
|
||||
int VoxelmanLibrary::get_num_prop_materials() const {
|
||||
return _prop_materials.size();
|
||||
}
|
||||
|
||||
void VoxelmanLibrary::clear_prop_materials() {
|
||||
_prop_materials.clear();
|
||||
}
|
||||
|
||||
Vector<Variant> VoxelmanLibrary::get_prop_materials() {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _prop_materials.size(); i++) {
|
||||
r.push_back(_prop_materials[i].get_ref_ptr());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
void VoxelmanLibrary::set_prop_materials(const Vector<Variant> &materials) {
|
||||
_prop_materials.clear();
|
||||
|
||||
for (int i = 0; i < materials.size(); i++) {
|
||||
Ref<Material> material = Ref<Material>(materials[i]);
|
||||
|
||||
_prop_materials.push_back(material);
|
||||
}
|
||||
}
|
||||
|
||||
//Surfaces
|
||||
Ref<VoxelSurface> VoxelmanLibrary::get_voxel_surface(const int index) {
|
||||
return Ref<VoxelSurface>();
|
||||
@ -139,12 +189,27 @@ int VoxelmanLibrary::get_num_surfaces() const {
|
||||
void VoxelmanLibrary::clear_surfaces() {
|
||||
}
|
||||
|
||||
Ref<PackedScene> VoxelmanLibrary::get_prop(const int id) {
|
||||
Ref<PackedScene> VoxelmanLibrary::get_scene(const int id) {
|
||||
return Ref<PackedScene>();
|
||||
}
|
||||
void VoxelmanLibrary::add_prop(Ref<PackedScene> value) {
|
||||
void VoxelmanLibrary::add_scene(Ref<PackedScene> value) {
|
||||
}
|
||||
void VoxelmanLibrary::set_prop(int id, Ref<PackedScene> value) {
|
||||
void VoxelmanLibrary::set_scene(int id, Ref<PackedScene> value) {
|
||||
}
|
||||
void VoxelmanLibrary::remove_scene(const int id) {
|
||||
}
|
||||
int VoxelmanLibrary::get_num_scenes() const {
|
||||
return 0;
|
||||
}
|
||||
void VoxelmanLibrary::clear_scenes() {
|
||||
}
|
||||
|
||||
Ref<PropData> VoxelmanLibrary::get_prop(const int id) {
|
||||
return Ref<PropData>();
|
||||
}
|
||||
void VoxelmanLibrary::add_prop(Ref<PropData> value) {
|
||||
}
|
||||
void VoxelmanLibrary::set_prop(int id, Ref<PropData> value) {
|
||||
}
|
||||
void VoxelmanLibrary::remove_prop(const int id) {
|
||||
}
|
||||
@ -171,6 +236,7 @@ VoxelmanLibrary::VoxelmanLibrary() {
|
||||
VoxelmanLibrary::~VoxelmanLibrary() {
|
||||
_materials.clear();
|
||||
_liquid_materials.clear();
|
||||
_prop_materials.clear();
|
||||
}
|
||||
|
||||
void VoxelmanLibrary::_bind_methods() {
|
||||
@ -202,6 +268,17 @@ void VoxelmanLibrary::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_liquid_materials"), &VoxelmanLibrary::set_liquid_materials);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "liquid_materials", PROPERTY_HINT_NONE, "17/17:Material", PROPERTY_USAGE_DEFAULT, "Material"), "set_liquid_materials", "get_liquid_materials");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_prop_material", "index"), &VoxelmanLibrary::get_prop_material);
|
||||
ClassDB::bind_method(D_METHOD("add_prop_material", "value"), &VoxelmanLibrary::add_prop_material);
|
||||
ClassDB::bind_method(D_METHOD("set_prop_material", "index", "value"), &VoxelmanLibrary::set_prop_material);
|
||||
ClassDB::bind_method(D_METHOD("remove_prop_material", "index"), &VoxelmanLibrary::remove_prop_material);
|
||||
ClassDB::bind_method(D_METHOD("get_num_prop_materials"), &VoxelmanLibrary::get_num_prop_materials);
|
||||
ClassDB::bind_method(D_METHOD("clear_prop_materials"), &VoxelmanLibrary::clear_prop_materials);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_prop_materials"), &VoxelmanLibrary::get_prop_materials);
|
||||
ClassDB::bind_method(D_METHOD("set_prop_materials"), &VoxelmanLibrary::set_prop_materials);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "prop_materials", PROPERTY_HINT_NONE, "17/17:Material", PROPERTY_USAGE_DEFAULT, "Material"), "set_prop_materials", "get_prop_materials");
|
||||
|
||||
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);
|
||||
@ -222,4 +299,5 @@ void VoxelmanLibrary::_bind_methods() {
|
||||
|
||||
BIND_CONSTANT(MATERIAL_INDEX_VOXELS);
|
||||
BIND_CONSTANT(MATERIAL_INDEX_LIQUID);
|
||||
BIND_CONSTANT(MATERIAL_INDEX_PROP);
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ SOFTWARE.
|
||||
class VoxelSurface;
|
||||
class VoxelMesher;
|
||||
class PackedScene;
|
||||
class PropData;
|
||||
|
||||
class VoxelmanLibrary : public Resource {
|
||||
GDCLASS(VoxelmanLibrary, Resource)
|
||||
@ -40,6 +41,7 @@ public:
|
||||
enum {
|
||||
MATERIAL_INDEX_VOXELS = 0,
|
||||
MATERIAL_INDEX_LIQUID = 1,
|
||||
MATERIAL_INDEX_PROP = 2,
|
||||
};
|
||||
|
||||
public:
|
||||
@ -66,6 +68,16 @@ public:
|
||||
Vector<Variant> get_liquid_materials();
|
||||
void set_liquid_materials(const Vector<Variant> &materials);
|
||||
|
||||
Ref<Material> get_prop_material(const int index);
|
||||
void add_prop_material(const Ref<Material> &value);
|
||||
void set_prop_material(const int index, const Ref<Material> &value);
|
||||
void remove_prop_material(const int index);
|
||||
int get_num_prop_materials() const;
|
||||
void clear_prop_materials();
|
||||
|
||||
Vector<Variant> get_prop_materials();
|
||||
void set_prop_materials(const Vector<Variant> &materials);
|
||||
|
||||
virtual Ref<VoxelSurface> get_voxel_surface(const int index);
|
||||
virtual void add_voxel_surface(Ref<VoxelSurface> value);
|
||||
virtual void set_voxel_surface(const int index, Ref<VoxelSurface> value);
|
||||
@ -73,9 +85,16 @@ public:
|
||||
virtual int get_num_surfaces() const;
|
||||
virtual void clear_surfaces();
|
||||
|
||||
virtual Ref<PackedScene> get_prop(const int id);
|
||||
virtual void add_prop(Ref<PackedScene> value);
|
||||
virtual void set_prop(const int id, Ref<PackedScene> value);
|
||||
virtual Ref<PackedScene> get_scene(const int id);
|
||||
virtual void add_scene(Ref<PackedScene> value);
|
||||
virtual void set_scene(const int id, Ref<PackedScene> value);
|
||||
virtual void remove_scene(const int id);
|
||||
virtual int get_num_scenes() const;
|
||||
virtual void clear_scenes();
|
||||
|
||||
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();
|
||||
@ -94,6 +113,7 @@ private:
|
||||
bool _initialized;
|
||||
Vector<Ref<Material> > _materials;
|
||||
Vector<Ref<Material> > _liquid_materials;
|
||||
Vector<Ref<Material> > _prop_materials;
|
||||
};
|
||||
|
||||
#endif // VOXEL_LIBRARY_H
|
||||
|
@ -25,6 +25,10 @@ SOFTWARE.
|
||||
#include "scene/resources/packed_scene.h"
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
#include "../props/prop_data.h"
|
||||
#include "../props/prop_data_mesh.h"
|
||||
#include "../props/prop_data_prop.h"
|
||||
|
||||
#include "../defines.h"
|
||||
|
||||
int VoxelmanLibraryMerger::get_texture_flags() const {
|
||||
@ -32,6 +36,7 @@ int VoxelmanLibraryMerger::get_texture_flags() const {
|
||||
}
|
||||
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 {
|
||||
@ -39,6 +44,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 {
|
||||
@ -46,6 +52,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 {
|
||||
@ -53,6 +60,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 {
|
||||
@ -60,6 +68,7 @@ int VoxelmanLibraryMerger::get_margin() const {
|
||||
}
|
||||
void VoxelmanLibraryMerger::set_margin(const int margin) {
|
||||
_packer->set_margin(margin);
|
||||
_prop_packer->set_margin(margin);
|
||||
}
|
||||
|
||||
//Surfaces
|
||||
@ -136,31 +145,56 @@ void VoxelmanLibraryMerger::set_voxel_surfaces(const Vector<Variant> &surfaces)
|
||||
}
|
||||
}
|
||||
|
||||
Ref<PackedScene> VoxelmanLibraryMerger::get_prop(const int id) {
|
||||
//if (_props.has(id))
|
||||
// return _props[id];
|
||||
Ref<PropData> VoxelmanLibraryMerger::get_prop(const int id) {
|
||||
if (_props.has(id))
|
||||
return _props[id];
|
||||
|
||||
return Ref<PackedScene>();
|
||||
return Ref<PropData>();
|
||||
}
|
||||
void VoxelmanLibraryMerger::add_prop(Ref<PackedScene> value) {
|
||||
//if (!value.is_valid() || _props.has(value->get_id()))
|
||||
// return;
|
||||
void VoxelmanLibraryMerger::add_prop(Ref<PropData> value) {
|
||||
if (!value.is_valid() || _props.has(value->get_id()))
|
||||
return;
|
||||
|
||||
////_props[value->get_id()] = value;
|
||||
_props[value->get_id()] = value;
|
||||
}
|
||||
void VoxelmanLibraryMerger::set_prop(const int id, const Ref<PackedScene> &value) {
|
||||
//_props[value->get_id()] = value;
|
||||
void VoxelmanLibraryMerger::set_prop(const int id, const Ref<PropData> &value) {
|
||||
_props[value->get_id()] = value;
|
||||
}
|
||||
void VoxelmanLibraryMerger::remove_prop(const int id) {
|
||||
//if (_props.has(id))
|
||||
// _props.erase(id);
|
||||
if (_props.has(id))
|
||||
_props.erase(id);
|
||||
}
|
||||
int VoxelmanLibraryMerger::get_num_props() const {
|
||||
return _props.size();
|
||||
}
|
||||
void VoxelmanLibraryMerger::clear_props() {
|
||||
//_props.clear();
|
||||
_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) {
|
||||
_props.clear();
|
||||
|
||||
for (int i = 0; i < props.size(); i++) {
|
||||
Ref<VoxelSurfaceMerger> surface = Ref<VoxelSurfaceMerger>(props[i]);
|
||||
|
||||
if (surface.is_valid()) {
|
||||
surface->set_library(this);
|
||||
}
|
||||
|
||||
_props.push_back(surface);
|
||||
}
|
||||
//_props.clear();
|
||||
}*/
|
||||
|
||||
void VoxelmanLibraryMerger::refresh_rects() {
|
||||
bool texture_added = false;
|
||||
@ -195,6 +229,26 @@ void VoxelmanLibraryMerger::refresh_rects() {
|
||||
setup_material_albedo(MATERIAL_INDEX_LIQUID, 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];
|
||||
|
||||
@ -218,6 +272,9 @@ void VoxelmanLibraryMerger::_setup_material_albedo(const int material_index, con
|
||||
case MATERIAL_INDEX_LIQUID:
|
||||
count = get_num_liquid_materials();
|
||||
break;
|
||||
case MATERIAL_INDEX_PROP:
|
||||
count = get_num_prop_materials();
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
@ -229,6 +286,9 @@ void VoxelmanLibraryMerger::_setup_material_albedo(const int material_index, con
|
||||
case MATERIAL_INDEX_LIQUID:
|
||||
mat = get_liquid_material(i);
|
||||
break;
|
||||
case MATERIAL_INDEX_PROP:
|
||||
mat = get_prop_material(i);
|
||||
break;
|
||||
}
|
||||
|
||||
Ref<SpatialMaterial> spmat;
|
||||
@ -259,7 +319,7 @@ VoxelmanLibraryMerger::VoxelmanLibraryMerger() {
|
||||
_packer.instance();
|
||||
|
||||
#if GODOT4
|
||||
#warning implement
|
||||
#warning implement
|
||||
#else
|
||||
_packer->set_texture_flags(Texture::FLAG_MIPMAPS | Texture::FLAG_FILTER);
|
||||
#endif
|
||||
@ -267,6 +327,18 @@ VoxelmanLibraryMerger::VoxelmanLibraryMerger() {
|
||||
_packer->set_max_atlas_size(1024);
|
||||
_packer->set_keep_original_atlases(false);
|
||||
_packer->set_margin(0);
|
||||
|
||||
_prop_packer.instance();
|
||||
|
||||
#if GODOT4
|
||||
#warning implement
|
||||
#else
|
||||
_prop_packer->set_texture_flags(Texture::FLAG_MIPMAPS | Texture::FLAG_FILTER);
|
||||
#endif
|
||||
|
||||
_prop_packer->set_max_atlas_size(1024);
|
||||
_prop_packer->set_keep_original_atlases(false);
|
||||
_prop_packer->set_margin(0);
|
||||
}
|
||||
|
||||
VoxelmanLibraryMerger::~VoxelmanLibraryMerger() {
|
||||
@ -282,6 +354,42 @@ VoxelmanLibraryMerger::~VoxelmanLibraryMerger() {
|
||||
|
||||
_packer->clear();
|
||||
_packer.unref();
|
||||
|
||||
_prop_packer->clear();
|
||||
_prop_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() {
|
||||
@ -309,5 +417,10 @@ void VoxelmanLibraryMerger::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_voxel_surfaces"), &VoxelmanLibraryMerger::set_voxel_surfaces);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "voxel_surfaces", PROPERTY_HINT_NONE, "17/17:VoxelSurfaceMerger", PROPERTY_USAGE_DEFAULT, "VoxelSurfaceMerger"), "set_voxel_surfaces", "get_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");
|
||||
//ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "props", PROPERTY_HINT_NONE, "17/17:PackedScene", PROPERTY_USAGE_DEFAULT, "PackedScene"), "set_props", "get_props");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_setup_material_albedo", "material_index", "texture"), &VoxelmanLibraryMerger::_setup_material_albedo);
|
||||
}
|
||||
|
@ -65,9 +65,9 @@ public:
|
||||
Vector<Variant> get_voxel_surfaces();
|
||||
void set_voxel_surfaces(const Vector<Variant> &surfaces);
|
||||
|
||||
Ref<PackedScene> get_prop(const int id);
|
||||
void add_prop(Ref<PackedScene> value);
|
||||
void set_prop(const int id, const Ref<PackedScene> &value);
|
||||
Ref<PropData> get_prop(const int id);
|
||||
void add_prop(Ref<PropData> value);
|
||||
void set_prop(const int id, const Ref<PropData> &value);
|
||||
void remove_prop(const int id);
|
||||
int get_num_props() const;
|
||||
void clear_props();
|
||||
@ -83,13 +83,16 @@ public:
|
||||
~VoxelmanLibraryMerger();
|
||||
|
||||
protected:
|
||||
bool process_prop_textures(Ref<PropData> prop);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Vector<Ref<VoxelSurfaceMerger> > _voxel_surfaces;
|
||||
Map<int, Ref<PackedScene> > _props;
|
||||
Map<int, Ref<PropData> > _props;
|
||||
|
||||
Ref<TexturePacker> _packer;
|
||||
Ref<TexturePacker> _prop_packer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
213
prop_tool/prop_tool.cpp
Normal file
213
prop_tool/prop_tool.cpp
Normal file
@ -0,0 +1,213 @@
|
||||
#include "prop_tool.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "../props/prop_data.h"
|
||||
#include "../props/prop_data_entity.h"
|
||||
#include "../props/prop_data_light.h"
|
||||
#include "../props/prop_data_mesh.h"
|
||||
#include "../props/prop_data_prop.h"
|
||||
#include "../props/prop_data_scene.h"
|
||||
|
||||
#include "prop_tool_entity.h"
|
||||
#include "prop_tool_light.h"
|
||||
#include "prop_tool_mesh.h"
|
||||
#include "prop_tool_prop.h"
|
||||
#include "prop_tool_scene.h"
|
||||
|
||||
#include "core/io/resource_saver.h"
|
||||
#include "prop_tool_editor_plugin.h"
|
||||
|
||||
void PropTool::edit(const Ref<PropData> &prop) {
|
||||
}
|
||||
|
||||
void PropTool::save() {
|
||||
if (!_target_prop.is_valid())
|
||||
return;
|
||||
|
||||
print_verbose("save " + _target_prop->get_path());
|
||||
|
||||
while (_target_prop->get_prop_count() > 0)
|
||||
_target_prop->remove_prop(0);
|
||||
|
||||
for (int i = 0; i < get_child_count(); ++i) {
|
||||
save_node(get_child(i), get_transform());
|
||||
}
|
||||
|
||||
_target_prop->set_snap_to_mesh(_snap_to_mesh);
|
||||
_target_prop->set_snap_axis(_snap_axis);
|
||||
|
||||
ResourceSaver::save(_target_prop->get_path(), _target_prop);
|
||||
}
|
||||
|
||||
void PropTool::save_node(Node *node, Transform parent_transform) {
|
||||
Spatial *snode = Object::cast_to<Spatial>(node);
|
||||
|
||||
if (ObjectDB::instance_validate(snode) && snode->has_method("get_data")) {
|
||||
Ref<PropDataEntry> prop = node->call("get_data");
|
||||
|
||||
if (prop.is_valid()) {
|
||||
prop->set_transform(parent_transform * snode->get_transform());
|
||||
|
||||
_target_prop->add_prop(prop);
|
||||
}
|
||||
|
||||
if (snode->has_method("evaluate_children") && !snode->call("evaluate_children"))
|
||||
return;
|
||||
|
||||
for (int i = 0; i < get_child_count(); ++i) {
|
||||
save_node(get_child(i), parent_transform * snode->get_transform());
|
||||
}
|
||||
} else {
|
||||
if (node->has_method("set_target_prop") && node->has_method("get_target_prop")) {
|
||||
Ref<PropData> tprop = node->call("get_target_prop");
|
||||
|
||||
if (tprop.is_valid()) {
|
||||
Ref<PropDataProp> prop;
|
||||
prop.instance();
|
||||
|
||||
prop->set_prop(tprop);
|
||||
|
||||
prop->set_transform(parent_transform * snode->get_transform());
|
||||
|
||||
_target_prop->add_prop(prop);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < get_child_count(); ++i) {
|
||||
save_node(get_child(i), parent_transform * snode->get_transform());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PropTool::rebuild_hierarchy() {
|
||||
for (int i = 0; i < get_child_count(); ++i)
|
||||
get_child(i)->queue_delete();
|
||||
|
||||
if (!_target_prop.is_valid())
|
||||
return;
|
||||
|
||||
_snap_to_mesh = _target_prop->get_snap_to_mesh();
|
||||
_snap_axis = _target_prop->get_snap_axis();
|
||||
|
||||
for (int i = 0; i < _target_prop->get_prop_count(); ++i) {
|
||||
Ref<PropDataEntry> prop = _target_prop->get_prop(i);
|
||||
|
||||
Ref<PropDataLight> prop_light = prop;
|
||||
Ref<PropDataMesh> prop_mesh = prop;
|
||||
Ref<PropDataScene> prop_scene = prop;
|
||||
Ref<PropDataProp> prop_prop = prop;
|
||||
Ref<PropDataEntity> prop_entity = prop;
|
||||
|
||||
if (prop_light.is_valid()) {
|
||||
PropToolLight *l = memnew(PropToolLight);
|
||||
|
||||
add_child(l);
|
||||
l->set_owner(this);
|
||||
l->set_transform(prop->get_transform());
|
||||
|
||||
l->set_data(prop_light);
|
||||
} else if (prop_mesh.is_valid()) {
|
||||
PropToolMesh *m = memnew(PropToolMesh);
|
||||
|
||||
add_child(m);
|
||||
m->set_owner(this);
|
||||
m->set_transform(prop->get_transform());
|
||||
|
||||
m->set_data(prop_mesh);
|
||||
} else if (prop_scene.is_valid()) {
|
||||
PropToolScene *s = memnew(PropToolScene);
|
||||
|
||||
add_child(s);
|
||||
s->set_owner(this);
|
||||
s->set_transform(prop->get_transform());
|
||||
|
||||
s->set_data(prop_scene);
|
||||
} else if (prop_prop.is_valid()) {
|
||||
PropTool *s = _plugin->create_or_get_scene(prop_prop->get_prop());
|
||||
|
||||
add_child(s);
|
||||
s->set_owner(this);
|
||||
s->set_transform(prop->get_transform());
|
||||
s->set_target_prop(prop_prop->get_prop());
|
||||
} else if (prop_entity.is_valid()) {
|
||||
PropToolEntity *s = memnew(PropToolEntity);
|
||||
|
||||
add_child(s);
|
||||
s->set_owner(this);
|
||||
s->set_transform(prop->get_transform());
|
||||
|
||||
s->set_data(prop_entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PropTool::refresh_set(bool value) {
|
||||
if (value)
|
||||
rebuild_hierarchy();
|
||||
}
|
||||
|
||||
void PropTool::set_target_prop(const Ref<PropData> &prop) {
|
||||
_target_prop = prop;
|
||||
|
||||
rebuild_hierarchy();
|
||||
}
|
||||
|
||||
void PropTool::target_prop_set(const Ref<PropData> &prop) {
|
||||
_target_prop = prop;
|
||||
|
||||
if (!prop.is_valid())
|
||||
return;
|
||||
|
||||
PropTool *last_prop_tool = this;
|
||||
Node *root = this;
|
||||
|
||||
while (root->get_parent() != NULL) {
|
||||
root = root->get_parent();
|
||||
|
||||
if (root && root->has_method("target_prop_set"))
|
||||
last_prop_tool = Object::cast_to<PropTool>(root);
|
||||
}
|
||||
|
||||
if (last_prop_tool == this)
|
||||
return;
|
||||
|
||||
last_prop_tool->load_scene_for(this, prop);
|
||||
}
|
||||
|
||||
void PropTool::load_scene_for(PropTool *t, const Ref<PropData> &prop) {
|
||||
if (_plugin == NULL)
|
||||
return;
|
||||
|
||||
t->queue_delete();
|
||||
|
||||
Node *s = _plugin->create_or_get_scene(prop);
|
||||
|
||||
add_child(s);
|
||||
//s->set_owner(this);
|
||||
}
|
||||
|
||||
PropToolEditorPlugin *PropTool::get_plugin() {
|
||||
return _plugin;
|
||||
}
|
||||
|
||||
void PropTool::set_plugin(PropToolEditorPlugin *plugin) {
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
PropTool::PropTool() {
|
||||
_snap_to_mesh = false;
|
||||
_snap_axis = Vector3(0, -1, 0);
|
||||
}
|
||||
PropTool::PropTool(EditorNode *p_editor) {
|
||||
_snap_to_mesh = false;
|
||||
_snap_axis = Vector3(0, -1, 0);
|
||||
}
|
||||
PropTool::~PropTool() {
|
||||
_target_prop.unref();
|
||||
}
|
||||
|
||||
void PropTool::_bind_methods() {
|
||||
}
|
||||
|
||||
#endif
|
71
prop_tool/prop_tool.h
Normal file
71
prop_tool/prop_tool.h
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
Copyright (c) 2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PROP_TOOL_H
|
||||
#define PROP_TOOL_H
|
||||
|
||||
class EditorNode;
|
||||
class EditorPlugin;
|
||||
class PropData;
|
||||
|
||||
#include "core/math/vector3.h"
|
||||
#include "core/reference.h"
|
||||
#include "scene/3d/spatial.h"
|
||||
|
||||
class propData;
|
||||
class PropToolEditorPlugin;
|
||||
|
||||
class PropTool : public Spatial {
|
||||
GDCLASS(PropTool, Spatial);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
public:
|
||||
void edit(const Ref<PropData> &prop);
|
||||
|
||||
void save();
|
||||
void save_node(Node *node, Transform parent_transform);
|
||||
void rebuild_hierarchy();
|
||||
void refresh_set(bool value);
|
||||
void set_target_prop(const Ref<PropData> &prop);
|
||||
void target_prop_set(const Ref<PropData> &prop);
|
||||
void load_scene_for(PropTool *t, const Ref<PropData> &prop);
|
||||
|
||||
PropToolEditorPlugin *get_plugin();
|
||||
void set_plugin(PropToolEditorPlugin *plugin);
|
||||
|
||||
PropTool();
|
||||
PropTool(EditorNode *p_editor);
|
||||
~PropTool();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
bool _refresh;
|
||||
Ref<PropData> _target_prop;
|
||||
bool _snap_to_mesh;
|
||||
Vector3 _snap_axis;
|
||||
PropToolEditorPlugin *_plugin;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
340
prop_tool/prop_tool_editor_plugin.cpp
Normal file
340
prop_tool/prop_tool_editor_plugin.cpp
Normal file
@ -0,0 +1,340 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "prop_tool_editor_plugin.h"
|
||||
|
||||
#include "core/os/dir_access.h"
|
||||
#include "core/os/file_access.h"
|
||||
#include "editor/editor_scale.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "scene/resources/packed_scene.h"
|
||||
|
||||
#include "../props/prop_data.h"
|
||||
|
||||
#include "prop_tool.h"
|
||||
#include "prop_tool_entity.h"
|
||||
#include "prop_tool_light.h"
|
||||
#include "prop_tool_mesh.h"
|
||||
#include "prop_tool_scene.h"
|
||||
|
||||
#include "editor/plugins/spatial_editor_plugin.h"
|
||||
|
||||
void PropToolEditorPlugin::edit(Object *p_object) {
|
||||
Ref<PropData> pedited_prop(Object::cast_to<PropData>(p_object));
|
||||
|
||||
String p = create_or_get_scene_path(pedited_prop);
|
||||
|
||||
get_editor_interface()->open_scene_from_path(p);
|
||||
}
|
||||
|
||||
bool PropToolEditorPlugin::handles(Object *p_object) const {
|
||||
|
||||
bool handles = p_object->is_class("PropData");
|
||||
|
||||
return handles;
|
||||
}
|
||||
|
||||
void PropToolEditorPlugin::make_visible(bool p_visible) {
|
||||
}
|
||||
|
||||
String PropToolEditorPlugin::create_or_get_scene_path(const Ref<PropData> &data) {
|
||||
ERR_FAIL_COND_V(!data.is_valid(), "");
|
||||
|
||||
String temp_path = EditorSettings::get_singleton()->get("editors/prop_tool/temp_path");
|
||||
|
||||
String path = temp_path + data->get_path().get_file().get_basename() + ".tscn";
|
||||
|
||||
if (!FileAccess::exists(path))
|
||||
create_scene(data);
|
||||
|
||||
return path;
|
||||
}
|
||||
PropTool *PropToolEditorPlugin::create_or_get_scene(const Ref<PropData> &data) {
|
||||
ERR_FAIL_COND_V(!data.is_valid(), NULL);
|
||||
|
||||
String temp_path = EditorSettings::get_singleton()->get("editors/prop_tool/temp_path");
|
||||
|
||||
String path = temp_path + data->get_path().get_file().get_basename() + ".tscn";
|
||||
|
||||
Ref<PackedScene> ps;
|
||||
|
||||
if (!FileAccess::exists(path))
|
||||
ps = create_scene(data);
|
||||
else
|
||||
ps = ResourceLoader::load(path, "PackedScene");
|
||||
|
||||
if (!ps.is_valid())
|
||||
return NULL;
|
||||
|
||||
PropTool *pt = Object::cast_to<PropTool>(ps->instance());
|
||||
pt->set_plugin(this);
|
||||
return pt;
|
||||
}
|
||||
Ref<PackedScene> PropToolEditorPlugin::create_scene(const Ref<PropData> &data) {
|
||||
PropTool *pt = memnew(PropTool);
|
||||
|
||||
pt->set_plugin(this);
|
||||
pt->set_target_prop(data);
|
||||
|
||||
Ref<PackedScene> ps;
|
||||
ps.instance();
|
||||
ps->pack(pt);
|
||||
|
||||
String temp_path = EditorSettings::get_singleton()->get("editors/prop_tool/temp_path");
|
||||
|
||||
Error err = ResourceSaver::save(temp_path + data->get_path().get_file().get_basename() + ".tscn", ps);
|
||||
|
||||
if (err)
|
||||
print_error("PropTool: create_scene failed! Error_code:" + String::num(err));
|
||||
|
||||
pt->queue_delete();
|
||||
return ps;
|
||||
}
|
||||
|
||||
void PropToolEditorPlugin::on_scene_changed(Node *scene) {
|
||||
PropTool *pt = Object::cast_to<PropTool>(scene);
|
||||
|
||||
if (ObjectDB::instance_validate(pt)) {
|
||||
pt->set_plugin(this);
|
||||
|
||||
light_button->show();
|
||||
mesh_button->show();
|
||||
prop_button->show();
|
||||
scene_button->show();
|
||||
entity_button->show();
|
||||
} else {
|
||||
light_button->hide();
|
||||
mesh_button->hide();
|
||||
prop_button->hide();
|
||||
scene_button->hide();
|
||||
entity_button->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void PropToolEditorPlugin::apply_changes() {
|
||||
Node *scene = get_editor_interface()->get_edited_scene_root();
|
||||
PropTool *pt = Object::cast_to<PropTool>(scene);
|
||||
|
||||
if (ObjectDB::instance_validate(pt)) {
|
||||
pt->save();
|
||||
}
|
||||
}
|
||||
|
||||
void PropToolEditorPlugin::add_light() {
|
||||
Array selection = get_editor_interface()->get_selection()->get_selected_nodes();
|
||||
|
||||
Node *selected;
|
||||
|
||||
if (selection.size() != 1)
|
||||
selected = get_editor_interface()->get_edited_scene_root();
|
||||
else
|
||||
selected = selection[0];
|
||||
|
||||
Node *s = selected;
|
||||
PropToolLight *n = memnew(PropToolLight);
|
||||
|
||||
UndoRedo &u = get_undo_redo();
|
||||
u.create_action("Add Light");
|
||||
u.add_do_method(s, "add_child", n);
|
||||
u.add_do_property(n, "owner", get_editor_interface()->get_edited_scene_root());
|
||||
u.add_undo_method(s, "remove_child", n);
|
||||
u.commit_action();
|
||||
|
||||
get_editor_interface()->get_selection()->clear();
|
||||
get_editor_interface()->get_selection()->add_node(n);
|
||||
}
|
||||
|
||||
void PropToolEditorPlugin::add_mesh() {
|
||||
Array selected = get_editor_interface()->get_selection()->get_selected_nodes();
|
||||
|
||||
if (selected.size() != 1)
|
||||
return;
|
||||
|
||||
Node *s = selected[0];
|
||||
PropToolMesh *n = memnew(PropToolMesh);
|
||||
|
||||
UndoRedo &u = get_undo_redo();
|
||||
u.create_action("Add Mesh");
|
||||
u.add_do_method(s, "add_child", n);
|
||||
u.add_do_property(n, "owner", get_editor_interface()->get_edited_scene_root());
|
||||
u.add_undo_method(s, "remove_child", n);
|
||||
u.commit_action();
|
||||
|
||||
get_editor_interface()->get_selection()->clear();
|
||||
get_editor_interface()->get_selection()->add_node(n);
|
||||
}
|
||||
|
||||
void PropToolEditorPlugin::add_prop() {
|
||||
|
||||
Array selected = get_editor_interface()->get_selection()->get_selected_nodes();
|
||||
|
||||
if (selected.size() != 1)
|
||||
return;
|
||||
|
||||
Node *s = selected[0];
|
||||
PropTool *n = memnew(PropTool);
|
||||
|
||||
UndoRedo &u = get_undo_redo();
|
||||
u.create_action("Add Prop");
|
||||
u.add_do_method(s, "add_child", n);
|
||||
u.add_do_property(n, "owner", get_editor_interface()->get_edited_scene_root());
|
||||
u.add_undo_method(s, "remove_child", n);
|
||||
u.commit_action();
|
||||
|
||||
get_editor_interface()->get_selection()->clear();
|
||||
get_editor_interface()->get_selection()->add_node(n);
|
||||
}
|
||||
|
||||
void PropToolEditorPlugin::add_scene() {
|
||||
Array selected = get_editor_interface()->get_selection()->get_selected_nodes();
|
||||
|
||||
if (selected.size() != 1)
|
||||
return;
|
||||
|
||||
Node *s = selected[0];
|
||||
PropToolScene *n = memnew(PropToolScene);
|
||||
|
||||
UndoRedo &u = get_undo_redo();
|
||||
u.create_action("Add Scene");
|
||||
u.add_do_method(s, "add_child", n);
|
||||
u.add_do_property(n, "owner", get_editor_interface()->get_edited_scene_root());
|
||||
u.add_undo_method(s, "remove_child", n);
|
||||
u.commit_action();
|
||||
|
||||
get_editor_interface()->get_selection()->clear();
|
||||
get_editor_interface()->get_selection()->add_node(n);
|
||||
}
|
||||
|
||||
void PropToolEditorPlugin::add_entity() {
|
||||
Array selected = get_editor_interface()->get_selection()->get_selected_nodes();
|
||||
|
||||
if (selected.size() != 1)
|
||||
return;
|
||||
|
||||
Node *s = selected[0];
|
||||
PropToolEntity *n = memnew(PropToolEntity);
|
||||
|
||||
UndoRedo &u = get_undo_redo();
|
||||
u.create_action("Add Entity");
|
||||
u.add_do_method(s, "add_child", n);
|
||||
u.add_do_property(n, "owner", get_editor_interface()->get_edited_scene_root());
|
||||
u.add_undo_method(s, "remove_child", n);
|
||||
u.commit_action();
|
||||
|
||||
get_editor_interface()->get_selection()->clear();
|
||||
get_editor_interface()->get_selection()->add_node(n);
|
||||
}
|
||||
|
||||
PropToolEditorPlugin::PropToolEditorPlugin(EditorNode *p_node) {
|
||||
EDITOR_DEF("editors/prop_tool/temp_path", "res://.prop_tool_temp/");
|
||||
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "editors/prop_tool/temp_path"));
|
||||
|
||||
String tp = EditorSettings::get_singleton()->get("editors/prop_tool/temp_path");
|
||||
|
||||
if (!tp.ends_with("/")) {
|
||||
tp += "/";
|
||||
EditorSettings::get_singleton()->set("editors/prop_tool/temp_path", tp);
|
||||
}
|
||||
|
||||
if (!DirAccess::exists(tp)) {
|
||||
DirAccess *d = DirAccess::create_for_path(tp);
|
||||
|
||||
Error err = d->make_dir_recursive(tp);
|
||||
|
||||
memdelete(d);
|
||||
|
||||
if (err)
|
||||
print_error("PropTool: Temporary directory creation failed: error code: " + String::num(err));
|
||||
}
|
||||
|
||||
editor = p_node;
|
||||
|
||||
light_button = memnew(ToolButton);
|
||||
light_button->set_text("Light");
|
||||
light_button->connect("pressed", this, "add_light");
|
||||
|
||||
mesh_button = memnew(ToolButton);
|
||||
mesh_button->set_text("Mesh");
|
||||
mesh_button->connect("pressed", this, "add_mesh");
|
||||
|
||||
prop_button = memnew(ToolButton);
|
||||
prop_button->set_text("Prop");
|
||||
prop_button->connect("pressed", this, "add_prop");
|
||||
|
||||
scene_button = memnew(ToolButton);
|
||||
scene_button->set_text("Scene");
|
||||
scene_button->connect("pressed", this, "add_scene");
|
||||
|
||||
entity_button = memnew(ToolButton);
|
||||
entity_button->set_text("Entity");
|
||||
entity_button->connect("pressed", this, "add_entity");
|
||||
|
||||
add_control_to_container(EditorPlugin::CONTAINER_SPATIAL_EDITOR_MENU, light_button);
|
||||
add_control_to_container(EditorPlugin::CONTAINER_SPATIAL_EDITOR_MENU, mesh_button);
|
||||
add_control_to_container(EditorPlugin::CONTAINER_SPATIAL_EDITOR_MENU, prop_button);
|
||||
add_control_to_container(EditorPlugin::CONTAINER_SPATIAL_EDITOR_MENU, scene_button);
|
||||
add_control_to_container(EditorPlugin::CONTAINER_SPATIAL_EDITOR_MENU, entity_button);
|
||||
|
||||
light_button->hide();
|
||||
mesh_button->hide();
|
||||
prop_button->hide();
|
||||
scene_button->hide();
|
||||
entity_button->hide();
|
||||
|
||||
call_deferred("connect", "scene_changed", this, "on_scene_changed");
|
||||
}
|
||||
|
||||
PropToolEditorPlugin::~PropToolEditorPlugin() {
|
||||
_edited_prop.unref();
|
||||
}
|
||||
|
||||
void PropToolEditorPlugin::_notification(int p_what) {
|
||||
if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
|
||||
|
||||
String tp = EditorSettings::get_singleton()->get("editors/prop_tool/temp_path");
|
||||
|
||||
if (!tp.ends_with("/")) {
|
||||
tp += "/";
|
||||
EditorSettings::get_singleton()->set("editors/prop_tool/temp_path", tp);
|
||||
}
|
||||
|
||||
if (!DirAccess::exists(tp)) {
|
||||
DirAccess *d = DirAccess::create_for_path(tp);
|
||||
|
||||
Error err = d->make_dir_recursive(tp);
|
||||
|
||||
memdelete(d);
|
||||
|
||||
ERR_FAIL_COND_MSG(err, "PropTool: Temporary directory creation failed: error code: " + String::num(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PropToolEditorPlugin::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("on_scene_changed", "scene_root"), &PropToolEditorPlugin::on_scene_changed);
|
||||
ClassDB::bind_method(D_METHOD("apply_changes"), &PropToolEditorPlugin::apply_changes);
|
||||
ClassDB::bind_method(D_METHOD("add_light"), &PropToolEditorPlugin::add_light);
|
||||
ClassDB::bind_method(D_METHOD("add_mesh"), &PropToolEditorPlugin::add_mesh);
|
||||
ClassDB::bind_method(D_METHOD("add_prop"), &PropToolEditorPlugin::add_prop);
|
||||
ClassDB::bind_method(D_METHOD("add_scene"), &PropToolEditorPlugin::add_scene);
|
||||
ClassDB::bind_method(D_METHOD("add_entity"), &PropToolEditorPlugin::add_entity);
|
||||
}
|
75
prop_tool/prop_tool_editor_plugin.h
Normal file
75
prop_tool/prop_tool_editor_plugin.h
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PROP_TOOL_EDITOR_PLUGIN_H
|
||||
#define PROP_TOOL_EDITOR_PLUGIN_H
|
||||
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_plugin.h"
|
||||
|
||||
class PropData;
|
||||
class PropTool;
|
||||
|
||||
class PropToolEditorPlugin : public EditorPlugin {
|
||||
GDCLASS(PropToolEditorPlugin, EditorPlugin);
|
||||
|
||||
public:
|
||||
virtual String get_name() const { return "PropData"; }
|
||||
bool has_main_screen() const { return false; }
|
||||
virtual void edit(Object *p_object);
|
||||
virtual bool handles(Object *p_object) const;
|
||||
virtual void make_visible(bool p_visible);
|
||||
|
||||
String create_or_get_scene_path(const Ref<PropData> &data);
|
||||
PropTool *create_or_get_scene(const Ref<PropData> &data);
|
||||
Ref<PackedScene> create_scene(const Ref<PropData> &data);
|
||||
|
||||
void on_scene_changed(Node *scene);
|
||||
void apply_changes();
|
||||
void add_light();
|
||||
void add_mesh();
|
||||
void add_prop();
|
||||
void add_scene();
|
||||
void add_entity();
|
||||
|
||||
PropToolEditorPlugin(EditorNode *p_node);
|
||||
~PropToolEditorPlugin();
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
ToolButton *light_button;
|
||||
ToolButton *mesh_button;
|
||||
ToolButton *prop_button;
|
||||
ToolButton *scene_button;
|
||||
ToolButton *entity_button;
|
||||
|
||||
ToolButton *edited_prop;
|
||||
|
||||
EditorNode *editor;
|
||||
|
||||
Ref<PropData> _edited_prop;
|
||||
};
|
||||
|
||||
#endif
|
152
prop_tool/prop_tool_entity.cpp
Normal file
152
prop_tool/prop_tool_entity.cpp
Normal file
@ -0,0 +1,152 @@
|
||||
/*
|
||||
Copyright (c) 2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "prop_tool_entity.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "../../entity_spell_system/entities/data/entity_data.h"
|
||||
#include "../../entity_spell_system/entities/entity.h"
|
||||
|
||||
Ref<PropDataEntity> PropToolEntity::get_data() {
|
||||
if (!is_visible() || !_entity_data.is_valid())
|
||||
return Ref<PropDataEntity>();
|
||||
|
||||
if (!_prop_entity.is_valid())
|
||||
_prop_entity.instance();
|
||||
|
||||
_prop_entity->set_entity_data_id(_entity_data_id);
|
||||
_prop_entity->set_level(_level);
|
||||
|
||||
return _prop_entity;
|
||||
}
|
||||
void PropToolEntity::set_data(const Ref<PropDataEntity> &data) {
|
||||
_prop_entity = data;
|
||||
|
||||
if (!_prop_entity.is_valid())
|
||||
return;
|
||||
|
||||
_entity_data_id = _prop_entity->get_entity_data_id();
|
||||
_level = _prop_entity->get_level();
|
||||
|
||||
/*
|
||||
TODO generic solution
|
||||
var dir = Directory.new()
|
||||
if dir.open("res://data/entities/") == OK:
|
||||
dir.list_dir_begin()
|
||||
var file_name = dir.get_next()
|
||||
|
||||
while (file_name != ""):
|
||||
if not dir.current_is_dir():
|
||||
var ed : EntityData = ResourceLoader.load("res://data/entities/" + file_name, "EntityData")
|
||||
|
||||
if ed != null and ed.id == entity_data_id:
|
||||
set_entity_data(ed)
|
||||
return
|
||||
|
||||
file_name = dir.get_next()
|
||||
|
||||
print("PropToolEntity: Entity not found!")
|
||||
*/
|
||||
}
|
||||
|
||||
Ref<EntityData> PropToolEntity::get_entity_data() {
|
||||
return _entity_data;
|
||||
}
|
||||
void PropToolEntity::set_entity_data(const Ref<EntityData> &data) {
|
||||
_entity_data = data;
|
||||
|
||||
if (!_entity_data.is_valid())
|
||||
return;
|
||||
|
||||
_entity_data_id = _entity_data->get_id();
|
||||
|
||||
if (_entity == NULL) {
|
||||
//TODO generic solutiuon
|
||||
|
||||
//var scene : PackedScene = load("res://addons/prop_tool/player/PropToolDisplayPlayer.tscn")
|
||||
|
||||
//_entity = scene.instance() as Entity
|
||||
|
||||
// add_child(_entity)
|
||||
//_entity.owner = owner
|
||||
|
||||
//_entity.get_node(_entity.character_skeleton_path).owner = owner
|
||||
//_entity.get_node(_entity.character_skeleton_path).refresh_in_editor = true
|
||||
//_entity.get_character_skeleton().refresh_in_editor = true
|
||||
|
||||
// _entity.sentity_data = entity_data
|
||||
|
||||
//name = entity_data.text_name
|
||||
}
|
||||
}
|
||||
|
||||
int PropToolEntity::get_entity_data_id() const {
|
||||
return _entity_data_id;
|
||||
}
|
||||
void PropToolEntity::set_entity_data_id(const int value) {
|
||||
_entity_data_id = value;
|
||||
}
|
||||
|
||||
int PropToolEntity::get_level() const {
|
||||
return _level;
|
||||
}
|
||||
void PropToolEntity::set_level(const int value) {
|
||||
_level = value;
|
||||
}
|
||||
|
||||
bool PropToolEntity::evaluate_children() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
PropToolEntity::PropToolEntity() {
|
||||
_entity_data_id = 0;
|
||||
_level = 1;
|
||||
|
||||
_entity = NULL;
|
||||
}
|
||||
PropToolEntity::~PropToolEntity() {
|
||||
_entity_data.unref();
|
||||
_prop_entity.unref();
|
||||
}
|
||||
|
||||
void PropToolEntity::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_data"), &PropToolEntity::get_data);
|
||||
ClassDB::bind_method(D_METHOD("set_data", "value"), &PropToolEntity::set_data);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "PropDataProp"), "set_data", "get_data");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_entity_data_id"), &PropToolEntity::get_entity_data_id);
|
||||
ClassDB::bind_method(D_METHOD("set_entity_data_id", "value"), &PropToolEntity::set_entity_data_id);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "entity_data_id"), "set_entity_data_id", "get_entity_data_id");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_level"), &PropToolEntity::get_level);
|
||||
ClassDB::bind_method(D_METHOD("set_level", "value"), &PropToolEntity::set_level);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "level"), "set_level", "get_level");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_entity_data"), &PropToolEntity::get_entity_data);
|
||||
ClassDB::bind_method(D_METHOD("set_entity_data", "value"), &PropToolEntity::set_entity_data);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "entity_data", PROPERTY_HINT_RESOURCE_TYPE, "EntityData"), "set_entity_data", "get_entity_data");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("evaluate_children"), &PropToolEntity::evaluate_children);
|
||||
}
|
||||
|
||||
#endif
|
69
prop_tool/prop_tool_entity.h
Normal file
69
prop_tool/prop_tool_entity.h
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
Copyright (c) 2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PROP_TOOL_ENTITY_H
|
||||
#define PROP_TOOL_ENTITY_H
|
||||
|
||||
#include "scene/3d/spatial.h"
|
||||
|
||||
#include "../props/prop_data.h"
|
||||
#include "../props/prop_data_entity.h"
|
||||
|
||||
class EntityData;
|
||||
class Entity;
|
||||
|
||||
class PropToolEntity : public Spatial {
|
||||
GDCLASS(PropToolEntity, Spatial);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
public:
|
||||
Ref<PropDataEntity> get_data();
|
||||
void set_data(const Ref<PropDataEntity> &data);
|
||||
|
||||
Ref<EntityData> get_entity_data();
|
||||
void set_entity_data(const Ref<EntityData> &data);
|
||||
|
||||
int get_entity_data_id() const;
|
||||
void set_entity_data_id(const int value);
|
||||
|
||||
int get_level() const;
|
||||
void set_level(const int value);
|
||||
|
||||
bool evaluate_children() const;
|
||||
|
||||
PropToolEntity();
|
||||
~PropToolEntity();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Ref<EntityData> _entity_data;
|
||||
int _entity_data_id;
|
||||
int _level;
|
||||
|
||||
Ref<PropDataEntity> _prop_entity;
|
||||
Entity *_entity;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
74
prop_tool/prop_tool_light.cpp
Normal file
74
prop_tool/prop_tool_light.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
Copyright (c) 2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "prop_tool_light.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
Ref<PropDataLight> PropToolLight::get_data() {
|
||||
|
||||
if (!is_visible())
|
||||
return Ref<PropDataLight>();
|
||||
|
||||
if (!_prop_light.is_valid())
|
||||
_prop_light.instance();
|
||||
|
||||
_prop_light->set_light_color(get_color());
|
||||
_prop_light->set_light_size(get_param(Light::PARAM_RANGE));
|
||||
|
||||
return _prop_light;
|
||||
}
|
||||
void PropToolLight::set_data(const Ref<PropDataLight> &data) {
|
||||
_prop_light = data;
|
||||
|
||||
if (!_prop_light.is_valid())
|
||||
return;
|
||||
|
||||
set_color(_prop_light->get_light_color());
|
||||
set_param(Light::PARAM_RANGE, _prop_light->get_light_size());
|
||||
set_param(Light::PARAM_ENERGY, _prop_light->get_light_size());
|
||||
}
|
||||
|
||||
bool PropToolLight::get_snap_to_mesh() const {
|
||||
return _snap_to_mesh;
|
||||
}
|
||||
void PropToolLight::set_snap_to_mesh(const bool value) {
|
||||
_snap_to_mesh = value;
|
||||
}
|
||||
|
||||
PropToolLight::PropToolLight() {
|
||||
}
|
||||
PropToolLight::~PropToolLight() {
|
||||
_prop_light.unref();
|
||||
}
|
||||
|
||||
void PropToolLight::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_data"), &PropToolLight::get_data);
|
||||
ClassDB::bind_method(D_METHOD("set_data", "value"), &PropToolLight::set_data);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "PropDataLight"), "set_data", "get_data");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_to_mesh"), &PropToolLight::get_snap_to_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_to_mesh", "value"), &PropToolLight::set_snap_to_mesh);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_to_mesh"), "set_snap_to_mesh", "get_snap_to_mesh");
|
||||
}
|
||||
|
||||
#endif
|
58
prop_tool/prop_tool_light.h
Normal file
58
prop_tool/prop_tool_light.h
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
Copyright (c) 2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PROP_TOOL_LIGHT_H
|
||||
#define PROP_TOOL_LIGHT_H
|
||||
|
||||
class EditorNode;
|
||||
class EditorPlugin;
|
||||
class PropData;
|
||||
|
||||
#include "../props/prop_data_light.h"
|
||||
#include "scene/3d/light.h"
|
||||
|
||||
class propData;
|
||||
|
||||
class PropToolLight : public OmniLight {
|
||||
GDCLASS(PropToolLight, OmniLight);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
public:
|
||||
Ref<PropDataLight> get_data();
|
||||
void set_data(const Ref<PropDataLight> &data);
|
||||
|
||||
bool get_snap_to_mesh() const;
|
||||
void set_snap_to_mesh(const bool value);
|
||||
|
||||
PropToolLight();
|
||||
~PropToolLight();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Ref<PropDataLight> _prop_light;
|
||||
bool _snap_to_mesh;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
183
prop_tool/prop_tool_mesh.cpp
Normal file
183
prop_tool/prop_tool_mesh.cpp
Normal file
@ -0,0 +1,183 @@
|
||||
/*
|
||||
Copyright (c) 2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "prop_tool_mesh.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
Ref<MeshDataResource> PropToolMesh::get_mesh_data() {
|
||||
return _mesh_data;
|
||||
}
|
||||
void PropToolMesh::set_mesh_data(const Ref<MeshDataResource> &data) {
|
||||
_mesh_data = data;
|
||||
}
|
||||
|
||||
Ref<PropDataMesh> PropToolMesh::get_data() {
|
||||
return _prop_mesh;
|
||||
|
||||
if (!is_visible() || !_mesh_data.is_valid())
|
||||
return Ref<PropDataMesh>();
|
||||
|
||||
if (!_prop_mesh.is_valid())
|
||||
_prop_mesh.instance();
|
||||
|
||||
_prop_mesh->set_mesh(_mesh_data);
|
||||
_prop_mesh->set_texture(_texture);
|
||||
_prop_mesh->set_snap_to_mesh(_snap_to_mesh);
|
||||
_prop_mesh->set_snap_axis(_snap_axis);
|
||||
|
||||
return _prop_mesh;
|
||||
}
|
||||
void PropToolMesh::set_data(const Ref<PropDataMesh> &data) {
|
||||
_prop_mesh = data;
|
||||
|
||||
if (!_prop_mesh.is_valid())
|
||||
return;
|
||||
|
||||
_texture = _prop_mesh->get_texture();
|
||||
|
||||
_snap_to_mesh = _prop_mesh->get_snap_to_mesh();
|
||||
_snap_axis = _prop_mesh->get_snap_axis();
|
||||
|
||||
set_generate(true);
|
||||
}
|
||||
|
||||
Ref<Texture> PropToolMesh::get_texture() {
|
||||
return _texture;
|
||||
}
|
||||
void PropToolMesh::set_texture(const Ref<Texture> &tex) {
|
||||
_texture = tex;
|
||||
}
|
||||
|
||||
bool PropToolMesh::get_snap_to_mesh() const {
|
||||
return _snap_to_mesh;
|
||||
}
|
||||
void PropToolMesh::set_snap_to_mesh(const bool value) {
|
||||
_snap_to_mesh = value;
|
||||
}
|
||||
|
||||
Vector3 PropToolMesh::get_snap_axis() const {
|
||||
return _snap_axis;
|
||||
}
|
||||
void PropToolMesh::set_snap_axis(const Vector3 &value) {
|
||||
_snap_axis = value;
|
||||
}
|
||||
|
||||
Ref<MeshDataResource> PropToolMesh::get_prop_mesh() {
|
||||
return _prop_mesh;
|
||||
}
|
||||
void PropToolMesh::set_prop_mesh(const Ref<MeshDataResource> &data) {
|
||||
_prop_mesh = data;
|
||||
}
|
||||
|
||||
void PropToolMesh::generate() {
|
||||
}
|
||||
|
||||
PropToolMesh::PropToolMesh() {
|
||||
_snap_to_mesh = false;
|
||||
_snap_axis = Vector3(0, -1, 0);
|
||||
}
|
||||
PropToolMesh::~PropToolMesh() {
|
||||
_prop_mesh.unref();
|
||||
_material.unref();
|
||||
}
|
||||
|
||||
void PropToolMesh::set_generate(bool value) {
|
||||
if (!value)
|
||||
return;
|
||||
|
||||
if (!_mesh_data.is_valid()) {
|
||||
mesh.unref();
|
||||
return;
|
||||
}
|
||||
|
||||
Ref<ArrayMesh> m;
|
||||
m.instance();
|
||||
|
||||
Array arr;
|
||||
arr.resize(ArrayMesh::ARRAY_MAX);
|
||||
|
||||
Array mda = _mesh_data->get_array();
|
||||
|
||||
PoolVector3Array v;
|
||||
v.append_array(mda[Mesh::ARRAY_VERTEX]);
|
||||
arr.set(Mesh::ARRAY_VERTEX, v);
|
||||
|
||||
PoolVector3Array norm;
|
||||
norm.append_array(mda[Mesh::ARRAY_NORMAL]);
|
||||
arr.set(Mesh::ARRAY_NORMAL, norm);
|
||||
|
||||
PoolVector2Array uv;
|
||||
uv.append_array(mda[Mesh::ARRAY_TEX_UV]);
|
||||
arr.set(Mesh::ARRAY_TEX_UV, uv);
|
||||
|
||||
PoolIntArray ind;
|
||||
ind.append_array(mda[Mesh::ARRAY_INDEX]);
|
||||
arr.set(Mesh::ARRAY_INDEX, ind);
|
||||
|
||||
m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, arr);
|
||||
|
||||
mesh = m;
|
||||
|
||||
if (_texture.is_valid()) {
|
||||
if (!_material.is_valid())
|
||||
_material.instance();
|
||||
|
||||
_material->set_texture(SpatialMaterial::TEXTURE_ALBEDO, _texture);
|
||||
|
||||
set_material_override(_material);
|
||||
}
|
||||
}
|
||||
|
||||
void PropToolMesh::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_mesh_data"), &PropToolMesh::get_mesh_data);
|
||||
ClassDB::bind_method(D_METHOD("set_mesh_data", "value"), &PropToolMesh::set_mesh_data);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh_data", PROPERTY_HINT_RESOURCE_TYPE, "MeshDataResource"), "set_mesh_data", "get_mesh_data");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_data"), &PropToolMesh::get_data);
|
||||
ClassDB::bind_method(D_METHOD("set_data", "value"), &PropToolMesh::set_data);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "PropDataMesh"), "set_data", "get_data");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_texture"), &PropToolMesh::get_texture);
|
||||
ClassDB::bind_method(D_METHOD("set_texture", "value"), &PropToolMesh::set_texture);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_to_mesh"), &PropToolMesh::get_snap_to_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_to_mesh", "value"), &PropToolMesh::set_snap_to_mesh);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_to_mesh"), "set_snap_to_mesh", "get_snap_to_mesh");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_axis"), &PropToolMesh::get_snap_axis);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_axis", "value"), &PropToolMesh::set_snap_axis);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "snap_axis"), "set_snap_axis", "get_snap_axis");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_prop_mesh"), &PropToolMesh::get_prop_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_prop_mesh", "value"), &PropToolMesh::set_prop_mesh);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop_mesh", PROPERTY_HINT_RESOURCE_TYPE, "MeshDataResource"), "set_prop_mesh", "get_prop_mesh");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("generate"), &PropToolMesh::generate);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_generate"), &PropToolMesh::get_generate);
|
||||
ClassDB::bind_method(D_METHOD("set_generate"), &PropToolMesh::set_generate);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "generate"), "set_generate", "get_generate");
|
||||
}
|
||||
|
||||
#endif
|
75
prop_tool/prop_tool_mesh.h
Normal file
75
prop_tool/prop_tool_mesh.h
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
Copyright (c) 2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PROP_TOOL_MESH_H
|
||||
#define PROP_TOOL_MESH_H
|
||||
|
||||
#include "core/math/vector3.h"
|
||||
|
||||
#include "../props/prop_data_mesh.h"
|
||||
#include "scene/3d/mesh_instance.h"
|
||||
|
||||
class PropToolMesh : public MeshInstance {
|
||||
GDCLASS(PropToolMesh, MeshInstance);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
public:
|
||||
Ref<MeshDataResource> get_mesh_data();
|
||||
void set_mesh_data(const Ref<MeshDataResource> &data);
|
||||
|
||||
Ref<PropDataMesh> get_data();
|
||||
void set_data(const Ref<PropDataMesh> &data);
|
||||
|
||||
Ref<Texture> get_texture();
|
||||
void set_texture(const Ref<Texture> &tex);
|
||||
|
||||
bool get_snap_to_mesh() const;
|
||||
void set_snap_to_mesh(const bool value);
|
||||
|
||||
Vector3 get_snap_axis() const;
|
||||
void set_snap_axis(const Vector3 &value);
|
||||
|
||||
Ref<MeshDataResource> get_prop_mesh();
|
||||
void set_prop_mesh(const Ref<MeshDataResource> &data);
|
||||
|
||||
void generate();
|
||||
|
||||
PropToolMesh();
|
||||
~PropToolMesh();
|
||||
|
||||
protected:
|
||||
bool get_generate() { return false; }
|
||||
void set_generate(bool value);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Ref<MeshDataResource> _mesh_data;
|
||||
Ref<PropDataMesh> _prop_mesh;
|
||||
Ref<Texture> _texture;
|
||||
Ref<SpatialMaterial> _material;
|
||||
bool _snap_to_mesh;
|
||||
Vector3 _snap_axis;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
99
prop_tool/prop_tool_prop.cpp
Normal file
99
prop_tool/prop_tool_prop.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
Copyright (c) 2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "prop_tool_prop.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
Ref<PropDataProp> PropToolProp::get_data() {
|
||||
if (!is_visible() || !_prop_data.is_valid())
|
||||
return Ref<PropDataProp>();
|
||||
|
||||
if (!_prop_data.is_valid())
|
||||
_prop_data.instance();
|
||||
|
||||
_prop_prop->set_prop(_prop_data);
|
||||
_prop_prop->set_snap_to_mesh(_snap_to_mesh);
|
||||
_prop_prop->set_snap_axis(_snap_axis);
|
||||
|
||||
return _prop_prop;
|
||||
}
|
||||
void PropToolProp::set_data(const Ref<PropDataProp> &data) {
|
||||
_prop_prop = data;
|
||||
|
||||
if (!_prop_prop.is_valid())
|
||||
return;
|
||||
|
||||
_prop_data = _prop_prop->get_prop();
|
||||
_snap_to_mesh = _prop_prop->get_snap_to_mesh();
|
||||
_snap_axis = _prop_prop->get_snap_axis();
|
||||
}
|
||||
|
||||
Ref<PropData> PropToolProp::get_prop_data() {
|
||||
return _prop_data;
|
||||
}
|
||||
void PropToolProp::set_prop_data(const Ref<PropData> &data) {
|
||||
_prop_data = data;
|
||||
}
|
||||
|
||||
bool PropToolProp::get_snap_to_mesh() const {
|
||||
return _snap_to_mesh;
|
||||
}
|
||||
void PropToolProp::set_snap_to_mesh(const bool value) {
|
||||
_snap_to_mesh = value;
|
||||
}
|
||||
|
||||
Vector3 PropToolProp::get_snap_axis() const {
|
||||
return _snap_axis;
|
||||
}
|
||||
void PropToolProp::set_snap_axis(const Vector3 &value) {
|
||||
_snap_axis = value;
|
||||
}
|
||||
|
||||
PropToolProp::PropToolProp() {
|
||||
_snap_to_mesh = false;
|
||||
_snap_axis = Vector3(0, -1, 0);
|
||||
}
|
||||
PropToolProp::~PropToolProp() {
|
||||
_prop_data.unref();
|
||||
_prop_prop.unref();
|
||||
}
|
||||
|
||||
void PropToolProp::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_data"), &PropToolProp::get_data);
|
||||
ClassDB::bind_method(D_METHOD("set_data", "value"), &PropToolProp::set_data);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "PropDataProp"), "set_data", "get_data");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_to_mesh"), &PropToolProp::get_snap_to_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_to_mesh", "value"), &PropToolProp::set_snap_to_mesh);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_to_mesh"), "set_snap_to_mesh", "get_snap_to_mesh");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_axis"), &PropToolProp::get_snap_axis);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_axis", "value"), &PropToolProp::set_snap_axis);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "snap_axis"), "set_snap_axis", "get_snap_axis");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_prop_data"), &PropToolProp::get_prop_data);
|
||||
ClassDB::bind_method(D_METHOD("set_prop_data", "value"), &PropToolProp::set_prop_data);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop_data", PROPERTY_HINT_RESOURCE_TYPE, "PropData"), "set_prop_data", "get_prop_data");
|
||||
}
|
||||
|
||||
#endif
|
62
prop_tool/prop_tool_prop.h
Normal file
62
prop_tool/prop_tool_prop.h
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
Copyright (c) 2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PROP_TOOL_PROP_H
|
||||
#define PROP_TOOL_PROP_H
|
||||
|
||||
#include "scene/3d/spatial.h"
|
||||
|
||||
#include "../props/prop_data.h"
|
||||
#include "../props/prop_data_prop.h"
|
||||
|
||||
class PropToolProp : public Spatial {
|
||||
GDCLASS(PropToolProp, Spatial);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
public:
|
||||
Ref<PropDataProp> get_data();
|
||||
void set_data(const Ref<PropDataProp> &data);
|
||||
|
||||
Ref<PropData> get_prop_data();
|
||||
void set_prop_data(const Ref<PropData> &data);
|
||||
|
||||
bool get_snap_to_mesh() const;
|
||||
void set_snap_to_mesh(const bool value);
|
||||
|
||||
Vector3 get_snap_axis() const;
|
||||
void set_snap_axis(const Vector3 &value);
|
||||
|
||||
PropToolProp();
|
||||
~PropToolProp();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Ref<PropData> _prop_data;
|
||||
bool _snap_to_mesh;
|
||||
Vector3 _snap_axis;
|
||||
Ref<PropDataProp> _prop_prop;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
99
prop_tool/prop_tool_scene.cpp
Normal file
99
prop_tool/prop_tool_scene.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
Copyright (c) 2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "prop_tool_scene.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
Ref<PropDataScene> PropToolScene::get_data() {
|
||||
if (!is_visible() || !_scene_data.is_valid())
|
||||
return Ref<PropDataScene>();
|
||||
|
||||
if (!_prop_scene.is_valid())
|
||||
_prop_scene.instance();
|
||||
|
||||
_prop_scene->set_scene(_scene_data);
|
||||
_prop_scene->set_snap_to_mesh(_snap_to_mesh);
|
||||
_prop_scene->set_snap_axis(_snap_axis);
|
||||
|
||||
return _prop_scene;
|
||||
}
|
||||
void PropToolScene::set_data(const Ref<PropDataScene> &data) {
|
||||
_prop_scene = data;
|
||||
|
||||
if (!_prop_scene.is_valid())
|
||||
return;
|
||||
|
||||
_scene_data = _prop_scene->get_scene();
|
||||
_snap_to_mesh = _prop_scene->get_snap_to_mesh();
|
||||
_snap_axis = _prop_scene->get_snap_axis();
|
||||
}
|
||||
|
||||
Ref<PackedScene> PropToolScene::get_scene_data() {
|
||||
return _scene_data;
|
||||
}
|
||||
void PropToolScene::set_scene_data(const Ref<PackedScene> &data) {
|
||||
_scene_data = data;
|
||||
}
|
||||
|
||||
bool PropToolScene::get_snap_to_mesh() const {
|
||||
return _snap_to_mesh;
|
||||
}
|
||||
void PropToolScene::set_snap_to_mesh(const bool value) {
|
||||
_snap_to_mesh = value;
|
||||
}
|
||||
|
||||
Vector3 PropToolScene::get_snap_axis() const {
|
||||
return _snap_axis;
|
||||
}
|
||||
void PropToolScene::set_snap_axis(const Vector3 &value) {
|
||||
_snap_axis = value;
|
||||
}
|
||||
|
||||
PropToolScene::PropToolScene() {
|
||||
_snap_to_mesh = false;
|
||||
_snap_axis = Vector3(0, -1, 0);
|
||||
}
|
||||
PropToolScene::~PropToolScene() {
|
||||
_scene_data.unref();
|
||||
_prop_scene.unref();
|
||||
}
|
||||
|
||||
void PropToolScene::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_data"), &PropToolScene::get_data);
|
||||
ClassDB::bind_method(D_METHOD("set_data", "value"), &PropToolScene::set_data);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "PropDataScene"), "set_data", "get_data");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_to_mesh"), &PropToolScene::get_snap_to_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_to_mesh", "value"), &PropToolScene::set_snap_to_mesh);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_to_mesh"), "set_snap_to_mesh", "get_snap_to_mesh");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_axis"), &PropToolScene::get_snap_axis);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_axis", "value"), &PropToolScene::set_snap_axis);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "snap_axis"), "set_snap_axis", "get_snap_axis");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_scene_data"), &PropToolScene::get_scene_data);
|
||||
ClassDB::bind_method(D_METHOD("set_scene_data", "value"), &PropToolScene::set_scene_data);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scene_data", PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"), "set_scene_data", "get_scene_data");
|
||||
}
|
||||
|
||||
#endif
|
61
prop_tool/prop_tool_scene.h
Normal file
61
prop_tool/prop_tool_scene.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright (c) 2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PROP_TOOL_SCENE_H
|
||||
#define PROP_TOOL_SCENE_H
|
||||
|
||||
#include "scene/3d/spatial.h"
|
||||
|
||||
#include "../props/prop_data_scene.h"
|
||||
|
||||
class PropToolScene : public Spatial {
|
||||
GDCLASS(PropToolScene, Spatial);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
public:
|
||||
Ref<PropDataScene> get_data();
|
||||
void set_data(const Ref<PropDataScene> &data);
|
||||
|
||||
Ref<PackedScene> get_scene_data();
|
||||
void set_scene_data(const Ref<PackedScene> &data);
|
||||
|
||||
bool get_snap_to_mesh() const;
|
||||
void set_snap_to_mesh(const bool value);
|
||||
|
||||
Vector3 get_snap_axis() const;
|
||||
void set_snap_axis(const Vector3 &value);
|
||||
|
||||
PropToolScene();
|
||||
~PropToolScene();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Ref<PackedScene> _scene_data;
|
||||
bool _snap_to_mesh;
|
||||
Vector3 _snap_axis;
|
||||
Ref<PropDataScene> _prop_scene;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
264
props/prop_data.cpp
Normal file
264
props/prop_data.cpp
Normal file
@ -0,0 +1,264 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "prop_data.h"
|
||||
|
||||
#include "../world/voxel_chunk.h"
|
||||
#include "prop_data_prop.h"
|
||||
|
||||
int PropData::get_id() const {
|
||||
return _id;
|
||||
}
|
||||
void PropData::set_id(const int value) {
|
||||
_id = value;
|
||||
}
|
||||
|
||||
bool PropData::get_snap_to_mesh() const {
|
||||
return _snap_to_mesh;
|
||||
}
|
||||
void PropData::set_snap_to_mesh(const bool value) {
|
||||
_snap_to_mesh = value;
|
||||
}
|
||||
|
||||
Vector3 PropData::get_snap_axis() const {
|
||||
return _snap_axis;
|
||||
}
|
||||
void PropData::set_snap_axis(const Vector3 &value) {
|
||||
_snap_axis = value;
|
||||
}
|
||||
|
||||
Ref<PropDataEntry> PropData::get_prop(const int index) const {
|
||||
ERR_FAIL_INDEX_V(index, _props.size(), Ref<PropDataEntry>());
|
||||
|
||||
return _props.get(index);
|
||||
}
|
||||
void PropData::set_prop(const int index, const Ref<PropDataEntry> prop) {
|
||||
ERR_FAIL_INDEX(index, _props.size());
|
||||
|
||||
_props.set(index, prop);
|
||||
}
|
||||
void PropData::add_prop(const Ref<PropDataEntry> prop) {
|
||||
_props.push_back(prop);
|
||||
}
|
||||
void PropData::remove_prop(const int index) {
|
||||
ERR_FAIL_INDEX(index, _props.size());
|
||||
|
||||
_props.remove(index);
|
||||
}
|
||||
|
||||
int PropData::get_prop_count() const {
|
||||
return _props.size();
|
||||
}
|
||||
|
||||
Vector<Variant> PropData::get_props() {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _props.size(); i++) {
|
||||
r.push_back(_props[i].get_ref_ptr());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void PropData::set_props(const Vector<Variant> &props) {
|
||||
_props.clear();
|
||||
for (int i = 0; i < props.size(); i++) {
|
||||
Ref<PropDataEntry> prop = Ref<PropDataEntry>(props[i]);
|
||||
|
||||
_props.push_back(prop);
|
||||
}
|
||||
}
|
||||
|
||||
void PropData::add_textures_into(Ref<TexturePacker> texture_packer) {
|
||||
ERR_FAIL_COND(!texture_packer.is_valid());
|
||||
|
||||
for (int i = 0; i < _props.size(); ++i) {
|
||||
Ref<PropDataEntry> entry = _props.get(i);
|
||||
|
||||
Ref<PropDataMesh> pmesh = entry;
|
||||
|
||||
if (pmesh.is_valid() && pmesh->get_texture().is_valid()) {
|
||||
texture_packer->add_texture(pmesh->get_texture());
|
||||
}
|
||||
|
||||
Ref<PropDataProp> pdataprop = entry;
|
||||
|
||||
if (pdataprop.is_valid() && pdataprop->get_prop().is_valid()) {
|
||||
pdataprop->get_prop()->add_textures_into(texture_packer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PropData::add_prop_lights_into(Ref<VoxelChunk> chunk, Transform parent_transform, bool allow_snap) {
|
||||
ERR_FAIL_COND(!chunk.is_valid());
|
||||
|
||||
for (int i = 0; i < _props.size(); ++i) {
|
||||
Ref<PropDataEntry> entry = _props.get(i);
|
||||
|
||||
Ref<PropDataLight> pl = entry;
|
||||
|
||||
if (pl.is_valid()) {
|
||||
Transform t = parent_transform * pl->get_transform();
|
||||
|
||||
Vector3 px = t.origin / chunk->get_voxel_scale();
|
||||
|
||||
Ref<VoxelLight> vl;
|
||||
vl.instance();
|
||||
vl->set_world_position(px.x + chunk->get_position_x() * chunk->get_size_x(), px.y + chunk->get_position_y() * chunk->get_size_y(), px.z + chunk->get_position_z() * chunk->get_size_z());
|
||||
vl->set_color(pl->get_light_color());
|
||||
vl->set_size(pl->get_light_size());
|
||||
|
||||
chunk->bake_light(vl);
|
||||
}
|
||||
|
||||
Ref<PropDataProp> pdataprop = entry;
|
||||
|
||||
if (pdataprop.is_valid() && pdataprop->get_prop().is_valid()) {
|
||||
Ref<PropData> pd = pdataprop->get_prop();
|
||||
|
||||
if (allow_snap) {
|
||||
if (pd->get_snap_to_mesh())
|
||||
print_error(pd->get_name());
|
||||
|
||||
pd->add_prop_lights_into(chunk, get_next_snapped_prop_transform(chunk->get_voxel_world(), parent_transform * pdataprop->get_transform(), pd->get_snap_to_mesh(), pd->get_snap_axis()), allow_snap);
|
||||
} else {
|
||||
pd->add_prop_lights_into(chunk, parent_transform * pdataprop->get_transform(), allow_snap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PropData::add_meshes_into(Ref<VoxelMesher> mesher, Ref<TexturePacker> texture_packer, Transform parent_transform, Spatial *snap_spatial) {
|
||||
ERR_FAIL_COND(!mesher.is_valid());
|
||||
ERR_FAIL_COND(!texture_packer.is_valid());
|
||||
ERR_FAIL_COND(texture_packer->get_generated_texture_count() == 0);
|
||||
ERR_FAIL_COND(snap_spatial != NULL && !ObjectDB::instance_validate(snap_spatial));
|
||||
|
||||
Vector2 texsize = texture_packer->get_generated_texture(0)->get_size();
|
||||
|
||||
for (int i = 0; i < _props.size(); ++i) {
|
||||
Ref<PropDataEntry> entry = _props.get(i);
|
||||
|
||||
Ref<PropDataMesh> pmesh = entry;
|
||||
|
||||
if (pmesh.is_valid()) {
|
||||
|
||||
Rect2 reg = Rect2(0, 0, 1, 1);
|
||||
|
||||
if (pmesh->get_texture().is_valid()) {
|
||||
|
||||
Ref<AtlasTexture> at = texture_packer->get_texture(pmesh->get_texture());
|
||||
|
||||
reg = at->get_region();
|
||||
|
||||
reg.position.x /= texsize.x;
|
||||
reg.position.y /= texsize.y;
|
||||
reg.size.x /= texsize.x;
|
||||
reg.size.y /= texsize.y;
|
||||
}
|
||||
|
||||
if (snap_spatial != NULL)
|
||||
mesher->add_mesh_data_resource_transform(pmesh->get_mesh(), get_next_snapped_prop_transform(snap_spatial, parent_transform * pmesh->get_transform(), pmesh->get_snap_to_mesh(), pmesh->get_snap_axis()), reg);
|
||||
else
|
||||
mesher->add_mesh_data_resource_transform(pmesh->get_mesh(), parent_transform * pmesh->get_transform(), reg);
|
||||
}
|
||||
|
||||
Ref<PropDataProp> pdataprop = entry;
|
||||
|
||||
if (pdataprop.is_valid() && pdataprop->get_prop().is_valid()) {
|
||||
|
||||
if (snap_spatial != NULL)
|
||||
pdataprop->get_prop()->add_meshes_into(mesher, texture_packer, get_next_snapped_prop_transform(snap_spatial, parent_transform * pdataprop->get_transform(), pdataprop->get_snap_to_mesh(), pdataprop->get_snap_axis()), snap_spatial);
|
||||
else
|
||||
pdataprop->get_prop()->add_meshes_into(mesher, texture_packer, parent_transform * pmesh->get_transform(), snap_spatial);
|
||||
}
|
||||
}
|
||||
}
|
||||
void PropData::add_meshes_into_bind(Ref<VoxelMesher> mesher, Ref<TexturePacker> texture_packer, Transform parent_transform, Node *snap_spatial) {
|
||||
Spatial *s = Object::cast_to<Spatial>(snap_spatial);
|
||||
|
||||
ERR_FAIL_COND(s != NULL && !ObjectDB::instance_validate(s));
|
||||
|
||||
add_meshes_into(mesher, texture_packer, parent_transform, s);
|
||||
}
|
||||
|
||||
Transform PropData::get_next_snapped_prop_transform(Spatial *s, Transform parent_transform, bool snap_to_mesh, Vector3 snap_axis) {
|
||||
if (snap_to_mesh) {
|
||||
Vector3 pos = s->to_global(parent_transform.origin);
|
||||
Vector3 world_snap_axis = s->to_global(parent_transform.xform(snap_axis));
|
||||
Vector3 world_snap_dir = world_snap_axis - pos;
|
||||
world_snap_dir *= 100;
|
||||
|
||||
PhysicsDirectSpaceState *space_state = s->get_world()->get_direct_space_state();
|
||||
|
||||
ERR_FAIL_COND_V(space_state == NULL, parent_transform);
|
||||
|
||||
PhysicsDirectSpaceState::RayResult res;
|
||||
|
||||
if (space_state->intersect_ray(pos - world_snap_dir, pos + world_snap_dir, res, Set<RID>(), 1)) {
|
||||
parent_transform.origin = s->to_local(res.position);
|
||||
}
|
||||
}
|
||||
|
||||
return parent_transform;
|
||||
}
|
||||
Transform PropData::get_next_snapped_prop_transform_bind(Node *spatial, Transform parent_transform, bool snap_to_mesh, Vector3 snap_axis) {
|
||||
Spatial *s = Object::cast_to<Spatial>(spatial);
|
||||
|
||||
ERR_FAIL_COND_V(!ObjectDB::instance_validate(s), parent_transform);
|
||||
|
||||
return get_next_snapped_prop_transform(s, parent_transform, snap_to_mesh, snap_axis);
|
||||
}
|
||||
|
||||
PropData::PropData() {
|
||||
_id = 0;
|
||||
_snap_to_mesh = false;
|
||||
_snap_axis = Vector3(0, -1, 0);
|
||||
}
|
||||
PropData::~PropData() {
|
||||
_props.clear();
|
||||
}
|
||||
|
||||
void PropData::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_snap_to_mesh"), &PropData::get_snap_to_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_to_mesh", "value"), &PropData::set_snap_to_mesh);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_to_mesh"), "set_snap_to_mesh", "get_snap_to_mesh");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_axis"), &PropData::get_snap_axis);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_axis", "value"), &PropData::set_snap_axis);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "snap_axis"), "set_snap_axis", "get_snap_axis");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_prop", "index"), &PropData::get_prop);
|
||||
ClassDB::bind_method(D_METHOD("set_prop", "index", "spell"), &PropData::set_prop);
|
||||
ClassDB::bind_method(D_METHOD("add_prop", "prop"), &PropData::add_prop);
|
||||
ClassDB::bind_method(D_METHOD("remove_prop", "index"), &PropData::remove_prop);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_prop_count"), &PropData::get_prop_count);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_props"), &PropData::get_props);
|
||||
ClassDB::bind_method(D_METHOD("set_props", "props"), &PropData::set_props);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "props", PROPERTY_HINT_NONE, "17/17:PropDataEntry", PROPERTY_USAGE_DEFAULT, "PropDataEntry"), "set_props", "get_props");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_textures_into", "texture_packer"), &PropData::add_textures_into);
|
||||
ClassDB::bind_method(D_METHOD("add_prop_lights_into", "chunk", "parent_transform", "allow_snap"), &PropData::add_prop_lights_into);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_meshes_into", "mesher", "texture_packer", "parent_transform", "snap_spatial"), &PropData::add_meshes_into_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_next_snapped_prop_transform", "spatial", "parent_transform", "snap_to_mesh", "snap_axis"), &PropData::get_next_snapped_prop_transform_bind);
|
||||
}
|
90
props/prop_data.h
Normal file
90
props/prop_data.h
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PROP_DATA_H
|
||||
#define PROP_DATA_H
|
||||
|
||||
#include "core/math/rect2.h"
|
||||
#include "core/math/transform.h"
|
||||
#include "core/math/vector2.h"
|
||||
#include "core/math/vector3.h"
|
||||
#include "core/reference.h"
|
||||
#include "core/vector.h"
|
||||
|
||||
#include "servers/physics_server.h"
|
||||
|
||||
#include "prop_data_entry.h"
|
||||
#include "prop_data_mesh.h"
|
||||
|
||||
#include "../meshers/voxel_mesher.h"
|
||||
|
||||
#include "../../texture_packer/texture_packer.h"
|
||||
|
||||
class Spatial;
|
||||
class VoxelChunk;
|
||||
|
||||
class PropData : public Resource {
|
||||
GDCLASS(PropData, Resource);
|
||||
|
||||
public:
|
||||
int get_id() const;
|
||||
void set_id(const int value);
|
||||
|
||||
bool get_snap_to_mesh() const;
|
||||
void set_snap_to_mesh(const bool value);
|
||||
|
||||
Vector3 get_snap_axis() const;
|
||||
void set_snap_axis(const Vector3 &value);
|
||||
|
||||
Ref<PropDataEntry> get_prop(const int index) const;
|
||||
void set_prop(const int index, const Ref<PropDataEntry> prop);
|
||||
void add_prop(const Ref<PropDataEntry> prop);
|
||||
void remove_prop(const int index);
|
||||
|
||||
int get_prop_count() const;
|
||||
|
||||
Vector<Variant> get_props();
|
||||
void set_props(const Vector<Variant> &props);
|
||||
|
||||
void add_textures_into(Ref<TexturePacker> texture_packer);
|
||||
void add_prop_lights_into(Ref<VoxelChunk> chunk, Transform parent_transform, bool allow_snap);
|
||||
void add_meshes_into(Ref<VoxelMesher> mesher, Ref<TexturePacker> texture_packer, Transform parent_transform, Spatial *snap_spatial = NULL);
|
||||
void add_meshes_into_bind(Ref<VoxelMesher> mesher, Ref<TexturePacker> texture_packer, Transform parent_transform, Node *snap_spatial = NULL);
|
||||
|
||||
Transform get_next_snapped_prop_transform(Spatial *s, Transform parent_transform, bool snap_to_mesh, Vector3 snap_axis);
|
||||
Transform get_next_snapped_prop_transform_bind(Node *spatial, Transform parent_transform, bool snap_to_mesh, Vector3 snap_axis);
|
||||
|
||||
PropData();
|
||||
~PropData();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
int _id;
|
||||
bool _snap_to_mesh;
|
||||
Vector3 _snap_axis;
|
||||
|
||||
Vector<Ref<PropDataEntry> > _props;
|
||||
};
|
||||
|
||||
#endif
|
54
props/prop_data_entity.cpp
Normal file
54
props/prop_data_entity.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "prop_data_entity.h"
|
||||
|
||||
int PropDataEntity::get_entity_data_id() const {
|
||||
return _entity_data_id;
|
||||
}
|
||||
void PropDataEntity::set_entity_data_id(const int value) {
|
||||
_entity_data_id = value;
|
||||
}
|
||||
|
||||
int PropDataEntity::get_level() const {
|
||||
return _level;
|
||||
}
|
||||
void PropDataEntity::set_level(const int value) {
|
||||
_level = value;
|
||||
}
|
||||
|
||||
PropDataEntity::PropDataEntity() {
|
||||
_entity_data_id = 0;
|
||||
_level = 1;
|
||||
}
|
||||
PropDataEntity::~PropDataEntity() {
|
||||
}
|
||||
|
||||
void PropDataEntity::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_entity_data_id"), &PropDataEntity::get_entity_data_id);
|
||||
ClassDB::bind_method(D_METHOD("set_entity_data_id", "value"), &PropDataEntity::set_entity_data_id);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "entity_data_id"), "set_entity_data_id", "get_entity_data_id");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_level"), &PropDataEntity::get_level);
|
||||
ClassDB::bind_method(D_METHOD("set_level", "value"), &PropDataEntity::set_level);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "level"), "set_level", "get_level");
|
||||
}
|
49
props/prop_data_entity.h
Normal file
49
props/prop_data_entity.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PROP_DATA_ENTITY_H
|
||||
#define PROP_DATA_ENTITY_H
|
||||
|
||||
#include "prop_data_entry.h"
|
||||
|
||||
class PropDataEntity : public PropDataEntry {
|
||||
GDCLASS(PropDataEntity, PropDataEntry);
|
||||
|
||||
public:
|
||||
int get_entity_data_id() const;
|
||||
void set_entity_data_id(const int value);
|
||||
|
||||
int get_level() const;
|
||||
void set_level(const int value);
|
||||
|
||||
PropDataEntity();
|
||||
~PropDataEntity();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
int _level;
|
||||
int _entity_data_id;
|
||||
};
|
||||
|
||||
#endif
|
41
props/prop_data_entry.cpp
Normal file
41
props/prop_data_entry.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "prop_data_entry.h"
|
||||
|
||||
Transform PropDataEntry::get_transform() const {
|
||||
return _transform;
|
||||
}
|
||||
void PropDataEntry::set_transform(const Transform value) {
|
||||
_transform = value;
|
||||
}
|
||||
|
||||
PropDataEntry::PropDataEntry() {
|
||||
}
|
||||
PropDataEntry::~PropDataEntry() {
|
||||
}
|
||||
|
||||
void PropDataEntry::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_transform"), &PropDataEntry::get_transform);
|
||||
ClassDB::bind_method(D_METHOD("set_transform", "value"), &PropDataEntry::set_transform);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "transform"), "set_transform", "get_transform");
|
||||
}
|
46
props/prop_data_entry.h
Normal file
46
props/prop_data_entry.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PROP_DATA_DATA_H
|
||||
#define PROP_DATA_DATA_H
|
||||
|
||||
#include "core/math/transform.h"
|
||||
#include "core/resource.h"
|
||||
|
||||
class PropDataEntry : public Resource {
|
||||
GDCLASS(PropDataEntry, Resource);
|
||||
|
||||
public:
|
||||
Transform get_transform() const;
|
||||
void set_transform(const Transform value);
|
||||
|
||||
PropDataEntry();
|
||||
~PropDataEntry();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Transform _transform;
|
||||
};
|
||||
|
||||
#endif
|
53
props/prop_data_light.cpp
Normal file
53
props/prop_data_light.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "prop_data_light.h"
|
||||
|
||||
Color PropDataLight::get_light_color() const {
|
||||
return _light_color;
|
||||
}
|
||||
void PropDataLight::set_light_color(const Color value) {
|
||||
_light_color = value;
|
||||
}
|
||||
|
||||
int PropDataLight::get_light_size() const {
|
||||
return _light_size;
|
||||
}
|
||||
void PropDataLight::set_light_size(const int value) {
|
||||
_light_size = value;
|
||||
}
|
||||
|
||||
PropDataLight::PropDataLight() {
|
||||
_light_size = 5;
|
||||
}
|
||||
PropDataLight::~PropDataLight() {
|
||||
}
|
||||
|
||||
void PropDataLight::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_light_color"), &PropDataLight::get_light_color);
|
||||
ClassDB::bind_method(D_METHOD("set_light_color", "value"), &PropDataLight::set_light_color);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "light_color"), "set_light_color", "get_light_color");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_light_size"), &PropDataLight::get_light_size);
|
||||
ClassDB::bind_method(D_METHOD("set_light_size", "value"), &PropDataLight::set_light_size);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "light_size"), "set_light_size", "get_light_size");
|
||||
}
|
51
props/prop_data_light.h
Normal file
51
props/prop_data_light.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PROP_DATA_LIGHT_H
|
||||
#define PROP_DATA_LIGHT_H
|
||||
|
||||
#include "prop_data_entry.h"
|
||||
|
||||
#include "core/color.h"
|
||||
|
||||
class PropDataLight : public PropDataEntry {
|
||||
GDCLASS(PropDataLight, PropDataEntry);
|
||||
|
||||
public:
|
||||
Color get_light_color() const;
|
||||
void set_light_color(const Color value);
|
||||
|
||||
int get_light_size() const;
|
||||
void set_light_size(const int value);
|
||||
|
||||
PropDataLight();
|
||||
~PropDataLight();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Color _light_color;
|
||||
int _light_size;
|
||||
};
|
||||
|
||||
#endif
|
78
props/prop_data_mesh.cpp
Normal file
78
props/prop_data_mesh.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "prop_data_mesh.h"
|
||||
|
||||
Ref<MeshDataResource> PropDataMesh::get_mesh() const {
|
||||
return _mesh;
|
||||
}
|
||||
void PropDataMesh::set_mesh(const Ref<MeshDataResource> mesh) {
|
||||
_mesh = mesh;
|
||||
}
|
||||
|
||||
Ref<Texture> PropDataMesh::get_texture() const {
|
||||
return _texture;
|
||||
}
|
||||
void PropDataMesh::set_texture(const Ref<Texture> texture) {
|
||||
_texture = texture;
|
||||
}
|
||||
|
||||
bool PropDataMesh::get_snap_to_mesh() {
|
||||
return _snap_to_mesh;
|
||||
}
|
||||
void PropDataMesh::set_snap_to_mesh(bool value) {
|
||||
_snap_to_mesh = value;
|
||||
}
|
||||
|
||||
Vector3 PropDataMesh::get_snap_axis() {
|
||||
return _snap_axis;
|
||||
}
|
||||
void PropDataMesh::set_snap_axis(Vector3 value) {
|
||||
_snap_axis = value;
|
||||
}
|
||||
|
||||
PropDataMesh::PropDataMesh() {
|
||||
_snap_to_mesh = true;
|
||||
_snap_axis = Vector3(0, 1, 0);
|
||||
}
|
||||
PropDataMesh::~PropDataMesh() {
|
||||
if (_mesh.is_valid())
|
||||
_mesh.unref();
|
||||
}
|
||||
|
||||
void PropDataMesh::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_mesh"), &PropDataMesh::get_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_mesh", "value"), &PropDataMesh::set_mesh);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "MeshDataResource"), "set_mesh", "get_mesh");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_texture"), &PropDataMesh::get_texture);
|
||||
ClassDB::bind_method(D_METHOD("set_texture", "value"), &PropDataMesh::set_texture);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_to_mesh"), &PropDataMesh::get_snap_to_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_to_mesh", "value"), &PropDataMesh::set_snap_to_mesh);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_to_mesh"), "set_snap_to_mesh", "get_snap_to_mesh");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_axis"), &PropDataMesh::get_snap_axis);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_axis", "value"), &PropDataMesh::set_snap_axis);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "snap_axis"), "set_snap_axis", "get_snap_axis");
|
||||
}
|
62
props/prop_data_mesh.h
Normal file
62
props/prop_data_mesh.h
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PROP_DATA_MESH_H
|
||||
#define PROP_DATA_MESH_H
|
||||
|
||||
#include "core/math/vector3.h"
|
||||
#include "prop_data_entry.h"
|
||||
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
#include "../../mesh_data_resource/mesh_data_resource.h"
|
||||
|
||||
class PropDataMesh : public PropDataEntry {
|
||||
GDCLASS(PropDataMesh, PropDataEntry);
|
||||
|
||||
public:
|
||||
Ref<MeshDataResource> get_mesh() const;
|
||||
void set_mesh(const Ref<MeshDataResource> mesh);
|
||||
|
||||
Ref<Texture> get_texture() const;
|
||||
void set_texture(const Ref<Texture> texture);
|
||||
|
||||
bool get_snap_to_mesh();
|
||||
void set_snap_to_mesh(bool value);
|
||||
|
||||
Vector3 get_snap_axis();
|
||||
void set_snap_axis(Vector3 value);
|
||||
|
||||
PropDataMesh();
|
||||
~PropDataMesh();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
bool _snap_to_mesh;
|
||||
Vector3 _snap_axis;
|
||||
Ref<MeshDataResource> _mesh;
|
||||
Ref<Texture> _texture;
|
||||
};
|
||||
|
||||
#endif
|
67
props/prop_data_prop.cpp
Normal file
67
props/prop_data_prop.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "prop_data_prop.h"
|
||||
|
||||
Ref<PropData> PropDataProp::get_prop() const {
|
||||
return _prop;
|
||||
}
|
||||
void PropDataProp::set_prop(const Ref<PropData> value) {
|
||||
_prop = value;
|
||||
}
|
||||
|
||||
bool PropDataProp::get_snap_to_mesh() {
|
||||
return _snap_to_mesh;
|
||||
}
|
||||
void PropDataProp::set_snap_to_mesh(bool value) {
|
||||
_snap_to_mesh = value;
|
||||
}
|
||||
|
||||
Vector3 PropDataProp::get_snap_axis() {
|
||||
return _snap_axis;
|
||||
}
|
||||
void PropDataProp::set_snap_axis(Vector3 value) {
|
||||
_snap_axis = value;
|
||||
}
|
||||
|
||||
PropDataProp::PropDataProp() {
|
||||
_snap_to_mesh = false;
|
||||
_snap_axis = Vector3(0, 1, 0);
|
||||
}
|
||||
PropDataProp::~PropDataProp() {
|
||||
if (_prop.is_valid())
|
||||
_prop.unref();
|
||||
}
|
||||
|
||||
void PropDataProp::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_prop"), &PropDataProp::get_prop);
|
||||
ClassDB::bind_method(D_METHOD("set_prop", "value"), &PropDataProp::set_prop);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop", PROPERTY_HINT_RESOURCE_TYPE, "PropData"), "set_prop", "get_prop");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_to_mesh"), &PropDataProp::get_snap_to_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_to_mesh", "value"), &PropDataProp::set_snap_to_mesh);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_to_mesh"), "set_snap_to_mesh", "get_snap_to_mesh");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_axis"), &PropDataProp::get_snap_axis);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_axis", "value"), &PropDataProp::set_snap_axis);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "snap_axis"), "set_snap_axis", "get_snap_axis");
|
||||
}
|
56
props/prop_data_prop.h
Normal file
56
props/prop_data_prop.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PROP_DATA_PROP_H
|
||||
#define PROP_DATA_PROP_H
|
||||
|
||||
#include "core/math/vector3.h"
|
||||
#include "prop_data_entry.h"
|
||||
|
||||
#include "prop_data.h"
|
||||
|
||||
class PropDataProp : public PropDataEntry {
|
||||
GDCLASS(PropDataProp, PropDataEntry);
|
||||
|
||||
public:
|
||||
Ref<PropData> get_prop() const;
|
||||
void set_prop(const Ref<PropData> value);
|
||||
|
||||
bool get_snap_to_mesh();
|
||||
void set_snap_to_mesh(bool value);
|
||||
|
||||
Vector3 get_snap_axis();
|
||||
void set_snap_axis(Vector3 value);
|
||||
|
||||
PropDataProp();
|
||||
~PropDataProp();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
bool _snap_to_mesh;
|
||||
Vector3 _snap_axis;
|
||||
Ref<PropData> _prop;
|
||||
};
|
||||
|
||||
#endif
|
67
props/prop_data_scene.cpp
Normal file
67
props/prop_data_scene.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "prop_data_scene.h"
|
||||
|
||||
Ref<PackedScene> PropDataScene::get_scene() const {
|
||||
return _scene;
|
||||
}
|
||||
void PropDataScene::set_scene(const Ref<PackedScene> value) {
|
||||
_scene = value;
|
||||
}
|
||||
|
||||
bool PropDataScene::get_snap_to_mesh() {
|
||||
return _snap_to_mesh;
|
||||
}
|
||||
void PropDataScene::set_snap_to_mesh(bool value) {
|
||||
_snap_to_mesh = value;
|
||||
}
|
||||
|
||||
Vector3 PropDataScene::get_snap_axis() {
|
||||
return _snap_axis;
|
||||
}
|
||||
void PropDataScene::set_snap_axis(Vector3 value) {
|
||||
_snap_axis = value;
|
||||
}
|
||||
|
||||
PropDataScene::PropDataScene() {
|
||||
_snap_to_mesh = true;
|
||||
_snap_axis = Vector3(0, 1, 0);
|
||||
}
|
||||
PropDataScene::~PropDataScene() {
|
||||
if (_scene.is_valid())
|
||||
_scene.unref();
|
||||
}
|
||||
|
||||
void PropDataScene::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_scene"), &PropDataScene::get_scene);
|
||||
ClassDB::bind_method(D_METHOD("set_scene", "value"), &PropDataScene::set_scene);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scene", PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"), "set_scene", "get_scene");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_to_mesh"), &PropDataScene::get_snap_to_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_to_mesh", "value"), &PropDataScene::set_snap_to_mesh);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_to_mesh"), "set_snap_to_mesh", "get_snap_to_mesh");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_axis"), &PropDataScene::get_snap_axis);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_axis", "value"), &PropDataScene::set_snap_axis);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "snap_axis"), "set_snap_axis", "get_snap_axis");
|
||||
}
|
56
props/prop_data_scene.h
Normal file
56
props/prop_data_scene.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PROP_DATA_SCENE_H
|
||||
#define PROP_DATA_SCENE_H
|
||||
|
||||
#include "core/math/vector3.h"
|
||||
#include "prop_data_entry.h"
|
||||
|
||||
#include "scene/resources/packed_scene.h"
|
||||
|
||||
class PropDataScene : public PropDataEntry {
|
||||
GDCLASS(PropDataScene, PropDataEntry);
|
||||
|
||||
public:
|
||||
Ref<PackedScene> get_scene() const;
|
||||
void set_scene(const Ref<PackedScene> value);
|
||||
|
||||
bool get_snap_to_mesh();
|
||||
void set_snap_to_mesh(bool value);
|
||||
|
||||
Vector3 get_snap_axis();
|
||||
void set_snap_axis(Vector3 value);
|
||||
|
||||
PropDataScene();
|
||||
~PropDataScene();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
bool _snap_to_mesh;
|
||||
Vector3 _snap_axis;
|
||||
Ref<PackedScene> _scene;
|
||||
};
|
||||
|
||||
#endif
|
@ -22,6 +22,25 @@ SOFTWARE.
|
||||
|
||||
#include "register_types.h"
|
||||
|
||||
#include "props/prop_data.h"
|
||||
#include "props/prop_data_entity.h"
|
||||
#include "props/prop_data_entry.h"
|
||||
#include "props/prop_data_light.h"
|
||||
#include "props/prop_data_mesh.h"
|
||||
#include "props/prop_data_prop.h"
|
||||
#include "props/prop_data_scene.h"
|
||||
|
||||
#include "prop_tool/prop_tool.h"
|
||||
#include "prop_tool/prop_tool_entity.h"
|
||||
#include "prop_tool/prop_tool_light.h"
|
||||
#include "prop_tool/prop_tool_mesh.h"
|
||||
#include "prop_tool/prop_tool_prop.h"
|
||||
#include "prop_tool/prop_tool_scene.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
#include "prop_tool/prop_tool_editor_plugin.h"
|
||||
#endif
|
||||
|
||||
#include "library/voxel_surface.h"
|
||||
#include "library/voxel_surface_simple.h"
|
||||
|
||||
@ -72,6 +91,21 @@ SOFTWARE.
|
||||
#include "world/marching_cubes/voxel_world_marching_cubes.h"
|
||||
|
||||
void register_voxelman_types() {
|
||||
ClassDB::register_class<PropData>();
|
||||
ClassDB::register_class<PropDataEntry>();
|
||||
ClassDB::register_class<PropDataScene>();
|
||||
ClassDB::register_class<PropDataMesh>();
|
||||
ClassDB::register_class<PropDataLight>();
|
||||
ClassDB::register_class<PropDataProp>();
|
||||
ClassDB::register_class<PropDataEntity>();
|
||||
|
||||
ClassDB::register_class<PropTool>();
|
||||
ClassDB::register_class<PropToolEntity>();
|
||||
ClassDB::register_class<PropToolProp>();
|
||||
ClassDB::register_class<PropToolMesh>();
|
||||
ClassDB::register_class<PropToolLight>();
|
||||
ClassDB::register_class<PropToolScene>();
|
||||
|
||||
ClassDB::register_class<VoxelMesher>();
|
||||
ClassDB::register_class<VoxelMesherDefault>();
|
||||
|
||||
@ -122,6 +156,7 @@ void register_voxelman_types() {
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
EditorPlugins::add_by_type<VoxelWorldEditorPlugin>();
|
||||
EditorPlugins::add_by_type<PropToolEditorPlugin>();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1437,6 +1437,96 @@ void VoxelChunkDefault::_build_phase(int phase) {
|
||||
|
||||
return;
|
||||
}
|
||||
case BUILD_PHASE_PROP_MESH: {
|
||||
for (int i = 0; i < _meshers.size(); ++i) {
|
||||
Ref<VoxelMesher> mesher = _meshers.get(i);
|
||||
|
||||
ERR_CONTINUE(!mesher.is_valid());
|
||||
|
||||
mesher->reset();
|
||||
}
|
||||
|
||||
if (_props.size() > 0) {
|
||||
if (!has_meshes(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH)) {
|
||||
create_meshes(MESH_INDEX_PROP, 1); //TODO LOD
|
||||
}
|
||||
|
||||
for (int i = 0; i < _meshers.size(); ++i) {
|
||||
Ref<VoxelMesher> mesher = _meshers.get(i);
|
||||
|
||||
ERR_CONTINUE(!mesher.is_valid());
|
||||
|
||||
mesher->bake_colors(this);
|
||||
mesher->set_material(get_library()->get_material(0));
|
||||
|
||||
RID prop_mesh_rid = get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 0);
|
||||
|
||||
ERR_FAIL_COND(prop_mesh_rid == RID());
|
||||
|
||||
VS::get_singleton()->mesh_clear(prop_mesh_rid);
|
||||
|
||||
if (mesher->get_vertex_count() == 0) {
|
||||
next_phase();
|
||||
return;
|
||||
}
|
||||
|
||||
Array arr = mesher->build_mesh();
|
||||
|
||||
VS::get_singleton()->mesh_add_surface_from_arrays(prop_mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, arr);
|
||||
|
||||
if (_library->get_material(0).is_valid())
|
||||
VS::get_singleton()->mesh_surface_set_material(prop_mesh_rid, 0, _library->get_material(0)->get_rid());
|
||||
}
|
||||
}
|
||||
|
||||
next_phase();
|
||||
|
||||
return;
|
||||
}
|
||||
case BUILD_PHASE_PROP_COLLIDER: {
|
||||
if ((_build_flags & BUILD_FLAG_CREATE_COLLIDER) == 0) {
|
||||
next_phase();
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < _meshers.size(); ++i) {
|
||||
Ref<VoxelMesher> mesher = _meshers.get(i);
|
||||
|
||||
ERR_CONTINUE(!mesher.is_valid());
|
||||
|
||||
temp_arr_collider.append_array(mesher->build_collider());
|
||||
}
|
||||
|
||||
for (int i = 0; i < _meshers.size(); ++i) {
|
||||
Ref<VoxelMesher> mesher = _meshers.get(i);
|
||||
|
||||
ERR_CONTINUE(!mesher.is_valid());
|
||||
|
||||
mesher->reset();
|
||||
}
|
||||
|
||||
if (temp_arr_collider.size() == 0) {
|
||||
next_phase();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_is_build_threaded) {
|
||||
set_active_build_phase_type(BUILD_PHASE_TYPE_PHYSICS_PROCESS);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!has_meshes(MESH_INDEX_PROP, MESH_TYPE_INDEX_SHAPE)) {
|
||||
create_colliders(MESH_INDEX_PROP);
|
||||
}
|
||||
|
||||
PhysicsServer::get_singleton()->shape_set_data(get_mesh_rid(MESH_INDEX_PROP, MESH_TYPE_INDEX_SHAPE), temp_arr_collider);
|
||||
|
||||
//temp_arr_collider.resize(0);
|
||||
|
||||
next_phase();
|
||||
|
||||
return;
|
||||
}
|
||||
case BUILD_PHASE_FINALIZE: {
|
||||
update_transforms();
|
||||
|
||||
@ -1478,6 +1568,17 @@ void VoxelChunkDefault::_build_phase_physics_process(int phase) {
|
||||
PhysicsServer::get_singleton()->shape_set_data(get_mesh_rid(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_SHAPE), temp_arr_collider_liquid);
|
||||
|
||||
temp_arr_collider_liquid.resize(0);
|
||||
} else if (phase == BUILD_PHASE_PROP_COLLIDER) {
|
||||
|
||||
if (!has_meshes(MESH_INDEX_PROP, MESH_TYPE_INDEX_SHAPE)) {
|
||||
create_colliders(MESH_INDEX_PROP);
|
||||
}
|
||||
|
||||
PhysicsServer::get_singleton()->shape_set_data(get_mesh_rid(MESH_INDEX_PROP, MESH_TYPE_INDEX_SHAPE), temp_arr_collider);
|
||||
//temp_arr_collider.resize(0);
|
||||
|
||||
set_active_build_phase_type(BUILD_PHASE_TYPE_NORMAL);
|
||||
next_phase();
|
||||
}
|
||||
|
||||
set_active_build_phase_type(BUILD_PHASE_TYPE_NORMAL);
|
||||
@ -1658,6 +1759,8 @@ void VoxelChunkDefault::_bind_methods() {
|
||||
BIND_CONSTANT(BUILD_PHASE_TERRARIN_MESH_SETUP);
|
||||
BIND_CONSTANT(BUILD_PHASE_TERRARIN_MESH_COLLIDER);
|
||||
BIND_CONSTANT(BUILD_PHASE_TERRARIN_MESH);
|
||||
BIND_CONSTANT(BUILD_PHASE_PROP_MESH);
|
||||
BIND_CONSTANT(BUILD_PHASE_PROP_COLLIDER);
|
||||
BIND_CONSTANT(BUILD_PHASE_LIGHTS);
|
||||
BIND_CONSTANT(BUILD_PHASE_FINALIZE);
|
||||
BIND_CONSTANT(BUILD_PHASE_MAX);
|
||||
|
@ -76,6 +76,8 @@ public:
|
||||
BUILD_PHASE_TERRARIN_MESH_COLLIDER,
|
||||
BUILD_PHASE_LIGHTS,
|
||||
BUILD_PHASE_TERRARIN_MESH,
|
||||
BUILD_PHASE_PROP_MESH,
|
||||
BUILD_PHASE_PROP_COLLIDER,
|
||||
BUILD_PHASE_FINALIZE,
|
||||
BUILD_PHASE_MAX
|
||||
};
|
||||
|
@ -53,6 +53,12 @@ include_pool_vector
|
||||
|
||||
#include "core/version.h"
|
||||
|
||||
#include "../props/prop_data.h"
|
||||
#include "../props/prop_data_entry.h"
|
||||
#include "../props/prop_data_light.h"
|
||||
#include "../props/prop_data_mesh.h"
|
||||
#include "../props/prop_data_scene.h"
|
||||
|
||||
#if VERSION_MAJOR >= 4
|
||||
#define Texture Texture2D
|
||||
#endif
|
||||
|
@ -24,6 +24,55 @@ SOFTWARE.
|
||||
|
||||
#include "voxel_chunk.h"
|
||||
|
||||
int VoxelChunkPropData::get_x() {
|
||||
return _x;
|
||||
}
|
||||
void VoxelChunkPropData::set_x(int value) {
|
||||
_x = value;
|
||||
}
|
||||
|
||||
int VoxelChunkPropData::get_y() {
|
||||
return _y;
|
||||
}
|
||||
void VoxelChunkPropData::set_y(int value) {
|
||||
_y = value;
|
||||
}
|
||||
|
||||
int VoxelChunkPropData::get_z() {
|
||||
return _z;
|
||||
}
|
||||
void VoxelChunkPropData::set_z(int value) {
|
||||
_z = value;
|
||||
}
|
||||
|
||||
Vector3 VoxelChunkPropData::get_rotation() {
|
||||
return _rotation;
|
||||
}
|
||||
void VoxelChunkPropData::set_rotation(Vector3 value) {
|
||||
_rotation = value;
|
||||
}
|
||||
|
||||
Vector3 VoxelChunkPropData::get_scale() {
|
||||
return _scale;
|
||||
}
|
||||
void VoxelChunkPropData::set_scale(Vector3 value) {
|
||||
_scale = value;
|
||||
}
|
||||
|
||||
bool VoxelChunkPropData::get_snap_to_mesh() {
|
||||
return _snap_to_mesh;
|
||||
}
|
||||
void VoxelChunkPropData::set_snap_to_mesh(bool value) {
|
||||
_snap_to_mesh = value;
|
||||
}
|
||||
|
||||
Vector3 VoxelChunkPropData::get_snap_axis() {
|
||||
return _snap_axis;
|
||||
}
|
||||
void VoxelChunkPropData::set_snap_axis(Vector3 value) {
|
||||
_snap_axis = value;
|
||||
}
|
||||
|
||||
Ref<VoxelChunk> VoxelChunkPropData::get_owner() {
|
||||
return _owner;
|
||||
}
|
||||
@ -52,6 +101,34 @@ void VoxelChunkPropData::set_scene(const Ref<PackedScene> &value) {
|
||||
_scene = value;
|
||||
}
|
||||
|
||||
Ref<MeshDataResource> VoxelChunkPropData::get_mesh() {
|
||||
return _mesh;
|
||||
}
|
||||
void VoxelChunkPropData::set_mesh(const Ref<MeshDataResource> &value) {
|
||||
_mesh = value;
|
||||
}
|
||||
|
||||
Ref<Texture> VoxelChunkPropData::get_mesh_texture() {
|
||||
return _texture;
|
||||
}
|
||||
void VoxelChunkPropData::set_mesh_texture(const Ref<Texture> &value) {
|
||||
_texture = value;
|
||||
}
|
||||
|
||||
Ref<PropDataLight> VoxelChunkPropData::get_light() {
|
||||
return _light;
|
||||
}
|
||||
void VoxelChunkPropData::set_light(const Ref<PropDataLight> &value) {
|
||||
_light = value;
|
||||
}
|
||||
|
||||
Ref<PropData> VoxelChunkPropData::get_prop() {
|
||||
return _prop;
|
||||
}
|
||||
void VoxelChunkPropData::set_prop(const Ref<PropData> &value) {
|
||||
_prop = value;
|
||||
}
|
||||
|
||||
Node *VoxelChunkPropData::get_spawned_prop() const {
|
||||
return _spawned_prop;
|
||||
}
|
||||
@ -69,15 +146,55 @@ void VoxelChunkPropData::set_translation_for_chunk(const Ref<VoxelChunk> &chunk,
|
||||
}
|
||||
|
||||
VoxelChunkPropData::VoxelChunkPropData() {
|
||||
_x = 0;
|
||||
_y = 0;
|
||||
_z = 0;
|
||||
_scale = Vector3(1, 1, 1);
|
||||
_snap_to_mesh = false;
|
||||
_snap_axis = Vector3(0, -1, 0);
|
||||
|
||||
_spawned_prop = NULL;
|
||||
_scene_id = 0;
|
||||
}
|
||||
VoxelChunkPropData::~VoxelChunkPropData() {
|
||||
_owner.unref();
|
||||
_mesh.unref();
|
||||
_texture.unref();
|
||||
_light.unref();
|
||||
_prop.unref();
|
||||
_scene.unref();
|
||||
|
||||
_owner.unref();
|
||||
}
|
||||
|
||||
void VoxelChunkPropData::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_x"), &VoxelChunkPropData::get_x);
|
||||
ClassDB::bind_method(D_METHOD("set_x", "value"), &VoxelChunkPropData::set_x);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "x"), "set_x", "get_x");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_y"), &VoxelChunkPropData::get_y);
|
||||
ClassDB::bind_method(D_METHOD("set_y", "value"), &VoxelChunkPropData::set_y);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "y"), "set_y", "get_y");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_z"), &VoxelChunkPropData::get_z);
|
||||
ClassDB::bind_method(D_METHOD("set_z", "value"), &VoxelChunkPropData::set_z);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "z"), "set_z", "get_z");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_rotation"), &VoxelChunkPropData::get_rotation);
|
||||
ClassDB::bind_method(D_METHOD("set_rotation", "value"), &VoxelChunkPropData::set_rotation);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation"), "set_rotation", "get_rotation");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_scale"), &VoxelChunkPropData::get_scale);
|
||||
ClassDB::bind_method(D_METHOD("set_scale", "value"), &VoxelChunkPropData::set_scale);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale"), "set_scale", "get_scale");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_to_mesh"), &VoxelChunkPropData::get_snap_to_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_to_mesh", "value"), &VoxelChunkPropData::set_snap_to_mesh);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_to_mesh"), "set_snap_to_mesh", "get_snap_to_mesh");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_axis"), &VoxelChunkPropData::get_snap_axis);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_axis", "value"), &VoxelChunkPropData::set_snap_axis);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "snap_axis"), "set_snap_axis", "get_snap_axis");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_owner"), &VoxelChunkPropData::get_owner);
|
||||
ClassDB::bind_method(D_METHOD("set_owner", "value"), &VoxelChunkPropData::set_owner);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "owner", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk"), "set_owner", "get_owner");
|
||||
@ -90,10 +207,6 @@ void VoxelChunkPropData::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_transform", "value"), &VoxelChunkPropData::set_transform);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "transform"), "set_transform", "get_transform");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_scene"), &VoxelChunkPropData::get_scene);
|
||||
ClassDB::bind_method(D_METHOD("set_scene", "value"), &VoxelChunkPropData::set_scene);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scene", PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"), "set_scene", "get_scene");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_spawned_prop"), &VoxelChunkPropData::get_spawned_prop);
|
||||
ClassDB::bind_method(D_METHOD("set_spawned_prop", "value"), &VoxelChunkPropData::set_spawned_prop);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "spawned_prop", PROPERTY_HINT_RESOURCE_TYPE, "Node"), "set_spawned_prop", "get_spawned_prop");
|
||||
@ -102,4 +215,24 @@ void VoxelChunkPropData::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("free_prop"), &VoxelChunkPropData::free_prop);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_translation_for_chunk", "chunk", "local_x", "local_y", "local_z"), &VoxelChunkPropData::set_translation_for_chunk);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_mesh"), &VoxelChunkPropData::get_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_mesh", "value"), &VoxelChunkPropData::set_mesh);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "MeshDataResource"), "set_mesh", "get_mesh");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_mesh_texture"), &VoxelChunkPropData::get_mesh_texture);
|
||||
ClassDB::bind_method(D_METHOD("set_mesh_texture", "value"), &VoxelChunkPropData::set_mesh_texture);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_mesh_texture", "get_mesh_texture");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_light"), &VoxelChunkPropData::get_light);
|
||||
ClassDB::bind_method(D_METHOD("set_light", "value"), &VoxelChunkPropData::set_light);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "light", PROPERTY_HINT_RESOURCE_TYPE, "PropDataLight"), "set_light", "get_light");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_prop"), &VoxelChunkPropData::get_prop);
|
||||
ClassDB::bind_method(D_METHOD("set_prop", "value"), &VoxelChunkPropData::set_prop);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop", PROPERTY_HINT_RESOURCE_TYPE, "PropData"), "set_prop", "get_prop");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_scene"), &VoxelChunkPropData::get_scene);
|
||||
ClassDB::bind_method(D_METHOD("set_scene", "value"), &VoxelChunkPropData::set_scene);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scene", PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"), "set_scene", "get_scene");
|
||||
}
|
||||
|
@ -23,20 +23,58 @@ SOFTWARE.
|
||||
#ifndef VOXEL_CHUNK_PROP_DATA_H
|
||||
#define VOXEL_CHUNK_PROP_DATA_H
|
||||
|
||||
#include "core/resource.h"
|
||||
|
||||
#include "core/math/transform.h"
|
||||
|
||||
#include "core/resource.h"
|
||||
#include "scene/main/node.h"
|
||||
|
||||
#include "scene/resources/packed_scene.h"
|
||||
|
||||
#include "../../mesh_data_resource/mesh_data_resource.h"
|
||||
#include "../props/prop_data.h"
|
||||
#include "../props/prop_data_light.h"
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
class VoxelChunk;
|
||||
|
||||
class VoxelChunkPropData : public Resource {
|
||||
GDCLASS(VoxelChunkPropData, Resource);
|
||||
|
||||
public:
|
||||
int get_x();
|
||||
void set_x(int value);
|
||||
|
||||
int get_y();
|
||||
void set_y(int value);
|
||||
|
||||
int get_z();
|
||||
void set_z(int value);
|
||||
|
||||
Vector3 get_rotation();
|
||||
void set_rotation(Vector3 value);
|
||||
|
||||
Vector3 get_scale();
|
||||
void set_scale(Vector3 value);
|
||||
|
||||
bool get_snap_to_mesh();
|
||||
void set_snap_to_mesh(bool value);
|
||||
|
||||
Vector3 get_snap_axis();
|
||||
void set_snap_axis(Vector3 value);
|
||||
|
||||
Ref<MeshDataResource> get_mesh();
|
||||
void set_mesh(const Ref<MeshDataResource> &value);
|
||||
|
||||
Ref<Texture> get_mesh_texture();
|
||||
void set_mesh_texture(const Ref<Texture> &value);
|
||||
|
||||
Ref<PropDataLight> get_light();
|
||||
void set_light(const Ref<PropDataLight> &value);
|
||||
|
||||
Ref<PropData> get_prop();
|
||||
void set_prop(const Ref<PropData> &value);
|
||||
|
||||
Ref<PackedScene> get_scene();
|
||||
void set_scene(const Ref<PackedScene> &value);
|
||||
|
||||
Ref<VoxelChunk> get_owner();
|
||||
void set_owner(const Ref<VoxelChunk> &chunk);
|
||||
|
||||
@ -46,9 +84,6 @@ public:
|
||||
Transform get_transform() const;
|
||||
void set_transform(const Transform &value);
|
||||
|
||||
Ref<PackedScene> get_scene();
|
||||
void set_scene(const Ref<PackedScene> &value);
|
||||
|
||||
Node *get_spawned_prop() const;
|
||||
void set_spawned_prop(Node *value);
|
||||
|
||||
@ -64,11 +99,25 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
int _x;
|
||||
int _y;
|
||||
int _z;
|
||||
Vector3 _rotation;
|
||||
Vector3 _scale;
|
||||
|
||||
bool _snap_to_mesh;
|
||||
Vector3 _snap_axis;
|
||||
|
||||
Ref<VoxelChunk> _owner;
|
||||
int _scene_id;
|
||||
Transform _transform;
|
||||
Node *_spawned_prop;
|
||||
Ref<PackedScene> _scene;
|
||||
|
||||
Ref<MeshDataResource> _mesh;
|
||||
Ref<Texture> _texture;
|
||||
Ref<PropDataLight> _light;
|
||||
Ref<PropData> _prop;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user