From 37da8155a4500a9386027b4d791a86186bc7ab4a Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 27 Aug 2017 16:00:59 -0300 Subject: -Largely rewrote gridmap to simplify it -Got editor working again -Added a current-floor marker on selection --- scene/resources/mesh_library.cpp | 61 +++++++++++++++++++++++++++++++--------- scene/resources/mesh_library.h | 14 +++++++-- 2 files changed, 59 insertions(+), 16 deletions(-) (limited to 'scene') diff --git a/scene/resources/mesh_library.cpp b/scene/resources/mesh_library.cpp index cbdf42dc2b..6abbcfb90b 100644 --- a/scene/resources/mesh_library.cpp +++ b/scene/resources/mesh_library.cpp @@ -43,9 +43,15 @@ bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) { set_item_name(idx, p_value); else if (what == "mesh") set_item_mesh(idx, p_value); - else if (what == "shape") - set_item_shape(idx, p_value); - else if (what == "preview") + else if (what == "shape") { + Vector shapes; + ShapeData sd; + sd.shape = p_value; + shapes.push_back(sd); + set_item_shapes(idx, shapes); + } else if (what == "shapes") { + _set_item_shapes(idx, p_value); + } else if (what == "preview") set_item_preview(idx, p_value); else if (what == "navmesh") set_item_navmesh(idx, p_value); @@ -69,8 +75,8 @@ bool MeshLibrary::_get(const StringName &p_name, Variant &r_ret) const { r_ret = get_item_name(idx); else if (what == "mesh") r_ret = get_item_mesh(idx); - else if (what == "shape") - r_ret = get_item_shape(idx); + else if (what == "shapes") + r_ret = _get_item_shapes(idx); else if (what == "navmesh") r_ret = get_item_navmesh(idx); else if (what == "preview") @@ -88,7 +94,7 @@ void MeshLibrary::_get_property_list(List *p_list) const { String name = "item/" + itos(E->key()) + "/"; p_list->push_back(PropertyInfo(Variant::STRING, name + "name")); p_list->push_back(PropertyInfo(Variant::OBJECT, name + "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh")); - p_list->push_back(PropertyInfo(Variant::OBJECT, name + "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape")); + p_list->push_back(PropertyInfo(Variant::ARRAY, name + "shapes")); p_list->push_back(PropertyInfo(Variant::OBJECT, name + "navmesh", PROPERTY_HINT_RESOURCE_TYPE, "NavigationMesh")); p_list->push_back(PropertyInfo(Variant::OBJECT, name + "preview", PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_EDITOR_HELPER)); } @@ -118,10 +124,10 @@ void MeshLibrary::set_item_mesh(int p_item, const Ref &p_mesh) { _change_notify(); } -void MeshLibrary::set_item_shape(int p_item, const Ref &p_shape) { +void MeshLibrary::set_item_shapes(int p_item, const Vector &p_shapes) { ERR_FAIL_COND(!item_map.has(p_item)); - item_map[p_item].shape = p_shape; + item_map[p_item].shapes = p_shapes; _change_notify(); notify_change_to_owners(); emit_changed(); @@ -156,10 +162,10 @@ Ref MeshLibrary::get_item_mesh(int p_item) const { return item_map[p_item].mesh; } -Ref MeshLibrary::get_item_shape(int p_item) const { +Vector MeshLibrary::get_item_shapes(int p_item) const { - ERR_FAIL_COND_V(!item_map.has(p_item), Ref()); - return item_map[p_item].shape; + ERR_FAIL_COND_V(!item_map.has(p_item), Vector()); + return item_map[p_item].shapes; } Ref MeshLibrary::get_item_navmesh(int p_item) const { @@ -226,17 +232,46 @@ int MeshLibrary::get_last_unused_item_id() const { return item_map.back()->key() + 1; } +void MeshLibrary::_set_item_shapes(int p_item, const Array &p_shapes) { + + ERR_FAIL_COND(p_shapes.size() & 1); + Vector shapes; + for (int i = 0; i < p_shapes.size(); i += 2) { + ShapeData sd; + sd.shape = p_shapes[i + 0]; + sd.local_transform = p_shapes[i + 1]; + + if (sd.shape.is_valid()) { + shapes.push_back(sd); + } + } + + set_item_shapes(p_item, shapes); +} + +Array MeshLibrary::_get_item_shapes(int p_item) const { + + Vector shapes = get_item_shapes(p_item); + Array ret; + for (int i = 0; i < shapes.size(); i++) { + ret.push_back(shapes[i].shape); + ret.push_back(shapes[i].local_transform); + } + + return ret; +} + void MeshLibrary::_bind_methods() { ClassDB::bind_method(D_METHOD("create_item", "id"), &MeshLibrary::create_item); ClassDB::bind_method(D_METHOD("set_item_name", "id", "name"), &MeshLibrary::set_item_name); ClassDB::bind_method(D_METHOD("set_item_mesh", "id", "mesh"), &MeshLibrary::set_item_mesh); ClassDB::bind_method(D_METHOD("set_item_navmesh", "id", "navmesh"), &MeshLibrary::set_item_navmesh); - ClassDB::bind_method(D_METHOD("set_item_shape", "id", "shape"), &MeshLibrary::set_item_shape); + ClassDB::bind_method(D_METHOD("set_item_shapes", "id", "shapes"), &MeshLibrary::_set_item_shapes); ClassDB::bind_method(D_METHOD("get_item_name", "id"), &MeshLibrary::get_item_name); ClassDB::bind_method(D_METHOD("get_item_mesh", "id"), &MeshLibrary::get_item_mesh); ClassDB::bind_method(D_METHOD("get_item_navmesh", "id"), &MeshLibrary::get_item_navmesh); - ClassDB::bind_method(D_METHOD("get_item_shape", "id"), &MeshLibrary::get_item_shape); + ClassDB::bind_method(D_METHOD("get_item_shapes", "id"), &MeshLibrary::_get_item_shapes); ClassDB::bind_method(D_METHOD("remove_item", "id"), &MeshLibrary::remove_item); ClassDB::bind_method(D_METHOD("clear"), &MeshLibrary::clear); ClassDB::bind_method(D_METHOD("get_item_list"), &MeshLibrary::get_item_list); diff --git a/scene/resources/mesh_library.h b/scene/resources/mesh_library.h index a9044881f7..99b6b48d61 100644 --- a/scene/resources/mesh_library.h +++ b/scene/resources/mesh_library.h @@ -41,16 +41,24 @@ class MeshLibrary : public Resource { GDCLASS(MeshLibrary, Resource); RES_BASE_EXTENSION("meshlib"); +public: + struct ShapeData { + Ref shape; + Transform local_transform; + }; struct Item { String name; Ref mesh; - Ref shape; + Vector shapes; Ref preview; Ref navmesh; }; Map item_map; + void _set_item_shapes(int p_item, const Array &p_shapes); + Array _get_item_shapes(int p_item) const; + protected: bool _set(const StringName &p_name, const Variant &p_value); bool _get(const StringName &p_name, Variant &r_ret) const; @@ -63,12 +71,12 @@ public: void set_item_name(int p_item, const String &p_name); void set_item_mesh(int p_item, const Ref &p_mesh); void set_item_navmesh(int p_item, const Ref &p_navmesh); - void set_item_shape(int p_item, const Ref &p_shape); + void set_item_shapes(int p_item, const Vector &p_shapes); void set_item_preview(int p_item, const Ref &p_preview); String get_item_name(int p_item) const; Ref get_item_mesh(int p_item) const; Ref get_item_navmesh(int p_item) const; - Ref get_item_shape(int p_item) const; + Vector get_item_shapes(int p_item) const; Ref get_item_preview(int p_item) const; void remove_item(int p_item); -- cgit v1.2.3