diff --git a/SCsub b/SCsub index 4b6fdd9..4fbd012 100644 --- a/SCsub +++ b/SCsub @@ -14,6 +14,15 @@ 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", + + "clutter/ground_clutter.cpp", "clutter/ground_clutter_foliage.cpp", diff --git a/config.py b/config.py index 3b44539..dd9ba59 100644 --- a/config.py +++ b/config.py @@ -10,6 +10,13 @@ def configure(env): def get_doc_classes(): return [ + "PropDataEntity", + "PropDataEntry", + "PropDataLight", + "PropDataMesh", + "PropDataProp", + "PropDataScene", + "PropData", "GroundClutterFoliage", "GroundClutter", diff --git a/props/prop_data.cpp b/props/prop_data.cpp new file mode 100644 index 0000000..7839d88 --- /dev/null +++ b/props/prop_data.cpp @@ -0,0 +1,265 @@ +/* +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 "prop_data_prop.h" + +#include "../../voxelman/world/voxel_chunk.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 PropData::get_prop(const int index) const { + ERR_FAIL_INDEX_V(index, _props.size(), Ref()); + + return _props.get(index); +} +void PropData::set_prop(const int index, const Ref prop) { + ERR_FAIL_INDEX(index, _props.size()); + + _props.set(index, prop); +} +void PropData::add_prop(const Ref 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 PropData::get_props() { + Vector 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 &props) { + _props.clear(); + for (int i = 0; i < props.size(); i++) { + Ref prop = Ref(props[i]); + + _props.push_back(prop); + } +} + +void PropData::add_textures_into(Ref texture_packer) { + ERR_FAIL_COND(!texture_packer.is_valid()); + + for (int i = 0; i < _props.size(); ++i) { + Ref entry = _props.get(i); + + Ref pmesh = entry; + + if (pmesh.is_valid() && pmesh->get_texture().is_valid()) { + texture_packer->add_texture(pmesh->get_texture()); + } + + Ref 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 chunk, Transform parent_transform, bool allow_snap) { + ERR_FAIL_COND(!chunk.is_valid()); + + for (int i = 0; i < _props.size(); ++i) { + Ref entry = _props.get(i); + + Ref pl = entry; + + if (pl.is_valid()) { + Transform t = parent_transform * pl->get_transform(); + + Vector3 px = t.origin / chunk->get_voxel_scale(); + + Ref 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 pdataprop = entry; + + if (pdataprop.is_valid() && pdataprop->get_prop().is_valid()) { + Ref 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 mesher, Ref 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 entry = _props.get(i); + + Ref pmesh = entry; + + if (pmesh.is_valid()) { + + Rect2 reg = Rect2(0, 0, 1, 1); + + if (pmesh->get_texture().is_valid()) { + + Ref 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 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 mesher, Ref texture_packer, Transform parent_transform, Node *snap_spatial) { + Spatial *s = Object::cast_to(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(), 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); + + 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); +} diff --git a/props/prop_data.h b/props/prop_data.h new file mode 100644 index 0000000..28d1e86 --- /dev/null +++ b/props/prop_data.h @@ -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 "../../voxelman/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 get_prop(const int index) const; + void set_prop(const int index, const Ref prop); + void add_prop(const Ref prop); + void remove_prop(const int index); + + int get_prop_count() const; + + Vector get_props(); + void set_props(const Vector &props); + + void add_textures_into(Ref texture_packer); + void add_prop_lights_into(Ref chunk, Transform parent_transform, bool allow_snap); + void add_meshes_into(Ref mesher, Ref texture_packer, Transform parent_transform, Spatial *snap_spatial = NULL); + void add_meshes_into_bind(Ref mesher, Ref 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 > _props; +}; + +#endif diff --git a/props/prop_data_entity.cpp b/props/prop_data_entity.cpp new file mode 100644 index 0000000..89e47e8 --- /dev/null +++ b/props/prop_data_entity.cpp @@ -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"); +} diff --git a/props/prop_data_entity.h b/props/prop_data_entity.h new file mode 100644 index 0000000..bd1531b --- /dev/null +++ b/props/prop_data_entity.h @@ -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 diff --git a/props/prop_data_entry.cpp b/props/prop_data_entry.cpp new file mode 100644 index 0000000..4330e35 --- /dev/null +++ b/props/prop_data_entry.cpp @@ -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"); +} diff --git a/props/prop_data_entry.h b/props/prop_data_entry.h new file mode 100644 index 0000000..0657162 --- /dev/null +++ b/props/prop_data_entry.h @@ -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 diff --git a/props/prop_data_light.cpp b/props/prop_data_light.cpp new file mode 100644 index 0000000..3e7e466 --- /dev/null +++ b/props/prop_data_light.cpp @@ -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"); +} diff --git a/props/prop_data_light.h b/props/prop_data_light.h new file mode 100644 index 0000000..db9349b --- /dev/null +++ b/props/prop_data_light.h @@ -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 diff --git a/props/prop_data_mesh.cpp b/props/prop_data_mesh.cpp new file mode 100644 index 0000000..f5471aa --- /dev/null +++ b/props/prop_data_mesh.cpp @@ -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 PropDataMesh::get_mesh() const { + return _mesh; +} +void PropDataMesh::set_mesh(const Ref mesh) { + _mesh = mesh; +} + +Ref PropDataMesh::get_texture() const { + return _texture; +} +void PropDataMesh::set_texture(const Ref 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"); +} diff --git a/props/prop_data_mesh.h b/props/prop_data_mesh.h new file mode 100644 index 0000000..314f57a --- /dev/null +++ b/props/prop_data_mesh.h @@ -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 get_mesh() const; + void set_mesh(const Ref mesh); + + Ref get_texture() const; + void set_texture(const Ref 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 _mesh; + Ref _texture; +}; + +#endif diff --git a/props/prop_data_prop.cpp b/props/prop_data_prop.cpp new file mode 100644 index 0000000..21e8cc0 --- /dev/null +++ b/props/prop_data_prop.cpp @@ -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 PropDataProp::get_prop() const { + return _prop; +} +void PropDataProp::set_prop(const Ref 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"); +} diff --git a/props/prop_data_prop.h b/props/prop_data_prop.h new file mode 100644 index 0000000..8c14f92 --- /dev/null +++ b/props/prop_data_prop.h @@ -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 get_prop() const; + void set_prop(const Ref 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 _prop; +}; + +#endif diff --git a/props/prop_data_scene.cpp b/props/prop_data_scene.cpp new file mode 100644 index 0000000..80d35d7 --- /dev/null +++ b/props/prop_data_scene.cpp @@ -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 PropDataScene::get_scene() const { + return _scene; +} +void PropDataScene::set_scene(const Ref 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"); +} diff --git a/props/prop_data_scene.h b/props/prop_data_scene.h new file mode 100644 index 0000000..c9c4e62 --- /dev/null +++ b/props/prop_data_scene.h @@ -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 get_scene() const; + void set_scene(const Ref 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 _scene; +}; + +#endif diff --git a/register_types.cpp b/register_types.cpp index 00623ef..99cdc5d 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -22,6 +22,14 @@ 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 "clutter/ground_clutter.h" #include "clutter/ground_clutter_foliage.h" @@ -35,6 +43,14 @@ SOFTWARE. #include "prop_instance_job.h" void register_props_types() { + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class();