summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-08-27 16:00:59 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-08-27 16:02:00 -0300
commit37da8155a4500a9386027b4d791a86186bc7ab4a (patch)
tree685c9f1f1ef8c2bd2c3b02e55266895c61bd9128 /scene
parentbd282ff43f23fe845f29a3e25c8efc01bd65ffb0 (diff)
-Largely rewrote gridmap to simplify it
-Got editor working again -Added a current-floor marker on selection
Diffstat (limited to 'scene')
-rw-r--r--scene/resources/mesh_library.cpp61
-rw-r--r--scene/resources/mesh_library.h14
2 files changed, 59 insertions, 16 deletions
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<ShapeData> 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<PropertyInfo> *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<Mesh> &p_mesh) {
_change_notify();
}
-void MeshLibrary::set_item_shape(int p_item, const Ref<Shape> &p_shape) {
+void MeshLibrary::set_item_shapes(int p_item, const Vector<ShapeData> &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<Mesh> MeshLibrary::get_item_mesh(int p_item) const {
return item_map[p_item].mesh;
}
-Ref<Shape> MeshLibrary::get_item_shape(int p_item) const {
+Vector<MeshLibrary::ShapeData> MeshLibrary::get_item_shapes(int p_item) const {
- ERR_FAIL_COND_V(!item_map.has(p_item), Ref<Shape>());
- return item_map[p_item].shape;
+ ERR_FAIL_COND_V(!item_map.has(p_item), Vector<ShapeData>());
+ return item_map[p_item].shapes;
}
Ref<NavigationMesh> 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<ShapeData> 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<ShapeData> 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> shape;
+ Transform local_transform;
+ };
struct Item {
String name;
Ref<Mesh> mesh;
- Ref<Shape> shape;
+ Vector<ShapeData> shapes;
Ref<Texture> preview;
Ref<NavigationMesh> navmesh;
};
Map<int, Item> 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<Mesh> &p_mesh);
void set_item_navmesh(int p_item, const Ref<NavigationMesh> &p_navmesh);
- void set_item_shape(int p_item, const Ref<Shape> &p_shape);
+ void set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes);
void set_item_preview(int p_item, const Ref<Texture> &p_preview);
String get_item_name(int p_item) const;
Ref<Mesh> get_item_mesh(int p_item) const;
Ref<NavigationMesh> get_item_navmesh(int p_item) const;
- Ref<Shape> get_item_shape(int p_item) const;
+ Vector<ShapeData> get_item_shapes(int p_item) const;
Ref<Texture> get_item_preview(int p_item) const;
void remove_item(int p_item);