summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorRémi Verschelde <remi@verschelde.fr>2016-04-20 21:12:35 +0200
committerRémi Verschelde <remi@verschelde.fr>2016-04-20 21:12:35 +0200
commitc0ec7e933ac6b6419e564b276b49c8d9a6d03f30 (patch)
treefe24f7fb736cac37c244b3bf4ce5655cb0b14282 /scene
parent1ea4b8e2dc61b39e78fb1691f738a03091ee2138 (diff)
parentb03a892f9574d78da2cfded1b829c549dd1fced1 (diff)
Merge pull request #4302 from Anarchid/gridmap-navmesh
Navmesh support for GridMaps
Diffstat (limited to 'scene')
-rw-r--r--scene/resources/mesh_library.cpp26
-rw-r--r--scene/resources/mesh_library.h5
2 files changed, 30 insertions, 1 deletions
diff --git a/scene/resources/mesh_library.cpp b/scene/resources/mesh_library.cpp
index 76bb1c585f..2b1d022299 100644
--- a/scene/resources/mesh_library.cpp
+++ b/scene/resources/mesh_library.cpp
@@ -48,6 +48,8 @@ bool MeshLibrary::_set(const StringName& p_name, const Variant& p_value) {
set_item_shape(idx,p_value);
else if(what=="preview")
set_item_preview(idx,p_value);
+ else if(what=="navmesh")
+ set_item_navmesh(idx,p_value);
else
return false;
@@ -70,6 +72,8 @@ bool MeshLibrary::_get(const StringName& p_name,Variant &r_ret) const {
r_ret= get_item_mesh(idx);
else if(what=="shape")
r_ret= get_item_shape(idx);
+ else if(what=="navmesh")
+ r_ret= get_item_navmesh(idx);
else if(what=="preview")
r_ret= get_item_preview(idx);
else
@@ -86,6 +90,7 @@ void MeshLibrary::_get_property_list( List<PropertyInfo> *p_list) const {
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::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));
}
}
@@ -130,6 +135,18 @@ void MeshLibrary::set_item_shape(int p_item,const Ref<Shape>& p_shape) {
}
+
+void MeshLibrary::set_item_navmesh(int p_item,const Ref<NavigationMesh>& p_navmesh) {
+
+ ERR_FAIL_COND(!item_map.has(p_item));
+ item_map[p_item].navmesh=p_navmesh;
+ _change_notify();
+ notify_change_to_owners();
+ emit_changed();
+ _change_notify();
+
+}
+
void MeshLibrary::set_item_preview(int p_item,const Ref<Texture>& p_preview) {
ERR_FAIL_COND(!item_map.has(p_item));
@@ -157,6 +174,13 @@ Ref<Shape> MeshLibrary::get_item_shape(int p_item) const {
return item_map[p_item].shape;
}
+Ref<NavigationMesh> MeshLibrary::get_item_navmesh(int p_item) const {
+
+ ERR_FAIL_COND_V(!item_map.has(p_item),Ref<NavigationMesh>());
+ return item_map[p_item].navmesh;
+}
+
+
Ref<Texture> MeshLibrary::get_item_preview(int p_item) const {
ERR_FAIL_COND_V(!item_map.has(p_item),Ref<Texture>());
@@ -223,9 +247,11 @@ void MeshLibrary::_bind_methods() {
ObjectTypeDB::bind_method(_MD("create_item","id"),&MeshLibrary::create_item);
ObjectTypeDB::bind_method(_MD("set_item_name","id","name"),&MeshLibrary::set_item_name);
ObjectTypeDB::bind_method(_MD("set_item_mesh","id","mesh:Mesh"),&MeshLibrary::set_item_mesh);
+ ObjectTypeDB::bind_method(_MD("set_item_navmesh","id","navmesh:NavigationMesh"),&MeshLibrary::set_item_navmesh);
ObjectTypeDB::bind_method(_MD("set_item_shape","id","shape:Shape"),&MeshLibrary::set_item_shape);
ObjectTypeDB::bind_method(_MD("get_item_name","id"),&MeshLibrary::get_item_name);
ObjectTypeDB::bind_method(_MD("get_item_mesh:Mesh","id"),&MeshLibrary::get_item_mesh);
+ ObjectTypeDB::bind_method(_MD("get_item_navmesh:NavigationMesh","id"),&MeshLibrary::get_item_navmesh);
ObjectTypeDB::bind_method(_MD("get_item_shape:Shape","id"),&MeshLibrary::get_item_shape);
ObjectTypeDB::bind_method(_MD("remove_item","id"),&MeshLibrary::remove_item);
ObjectTypeDB::bind_method(_MD("clear"),&MeshLibrary::clear);
diff --git a/scene/resources/mesh_library.h b/scene/resources/mesh_library.h
index bf0107d7a9..e4dba193fc 100644
--- a/scene/resources/mesh_library.h
+++ b/scene/resources/mesh_library.h
@@ -33,6 +33,7 @@
#include "mesh.h"
#include "shape.h"
#include "map.h"
+#include "scene/3d/navigation_mesh.h"
class MeshLibrary : public Resource {
@@ -40,11 +41,11 @@ class MeshLibrary : public Resource {
RES_BASE_EXTENSION("gt");
struct Item {
-
String name;
Ref<Mesh> mesh;
Ref<Shape> shape;
Ref<Texture> preview;
+ Ref<NavigationMesh> navmesh;
};
Map<int,Item> item_map;
@@ -62,10 +63,12 @@ public:
void create_item(int p_item);
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_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;
Ref<Texture> get_item_preview(int p_item) const;