mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-24 04:46:48 +01:00
Backported from godot4: Change GridMap navigation_layers to be per mesh_library item
Changes GridMap navigation_layers from a single bitmask for the entire GridMap to a bitmask for each item used in the mesh_library with a baked navmesh.
- smix8
61f33e205c
This commit is contained in:
parent
c055e8aeed
commit
dfb5323cc1
@ -79,11 +79,11 @@
|
||||
Returns an array of [Transform] and [Mesh] references corresponding to the non-empty cells in the grid. The transforms are specified in world space.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_navigation_layer_value" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<argument index="0" name="layer_number" type="int" />
|
||||
<method name="get_navigation_map" qualifiers="const">
|
||||
<return type="RID" />
|
||||
<description>
|
||||
Returns whether or not the specified layer of the [member navigation_layers] bitmask is enabled, given a [code]layer_number[/code] between 1 and 32.
|
||||
Returns the [RID] of the navigation map this GridMap node uses for its cell baked navigation meshes.
|
||||
This function returns always the map set on the GridMap node and not the map on the NavigationServer. If the map is changed directly with the NavigationServer API the GridMap node will not be aware of the map change.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_used_cells" qualifiers="const">
|
||||
@ -161,14 +161,6 @@
|
||||
Sets an individual bit on the [member collision_mask].
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_navigation_layer_value">
|
||||
<return type="void" />
|
||||
<argument index="0" name="layer_number" type="int" />
|
||||
<argument index="1" name="value" type="bool" />
|
||||
<description>
|
||||
Based on [code]value[/code], enables or disables the specified layer in the [member navigation_layers] bitmask, given a [code]layer_number[/code] between 1 and 32.
|
||||
</description>
|
||||
</method>
|
||||
<method name="world_to_map" qualifiers="const">
|
||||
<return type="Vector3" />
|
||||
<argument index="0" name="pos" type="Vector3" />
|
||||
@ -187,7 +179,7 @@
|
||||
</methods>
|
||||
<members>
|
||||
<member name="bake_navigation" type="bool" setter="set_bake_navigation" getter="is_baking_navigation" default="false">
|
||||
If [code]true[/code], this GridMap uses cell navigation mesh resources to create navigation regions.
|
||||
If [code]true[/code], this GridMap creates a navigation region for each cell that uses a [member mesh_library] item with a navigation mesh. The created navigation region will use the navigation layers bitmask assigned to the [MeshLibrary]'s item.
|
||||
</member>
|
||||
<member name="cell_center_x" type="bool" setter="set_center_x" getter="get_center_x" default="true">
|
||||
If [code]true[/code], grid items are centered on the X axis.
|
||||
@ -219,9 +211,6 @@
|
||||
<member name="mesh_library" type="MeshLibrary" setter="set_mesh_library" getter="get_mesh_library">
|
||||
The assigned [MeshLibrary].
|
||||
</member>
|
||||
<member name="navigation_layers" type="int" setter="set_navigation_layers" getter="get_navigation_layers" default="1">
|
||||
The navigation layers the GridMap generates its navigation regions in.
|
||||
</member>
|
||||
<member name="physics_material" type="PhysicsMaterial" setter="set_physics_material" getter="get_physics_material">
|
||||
Overrides the default friction and bounce physics properties for the whole [GridMap].
|
||||
</member>
|
||||
|
@ -59,6 +59,13 @@
|
||||
Returns the item's name.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_item_navigation_layers" qualifiers="const">
|
||||
<return type="int" />
|
||||
<param index="0" name="id" type="int" />
|
||||
<description>
|
||||
Returns the item's navigation layers bitmask.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_item_navigation_mesh" qualifiers="const">
|
||||
<return type="NavigationMesh" />
|
||||
<argument index="0" name="id" type="int" />
|
||||
@ -126,6 +133,14 @@
|
||||
This name is shown in the editor. It can also be used to look up the item later using [method find_item_by_name].
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_item_navigation_layers">
|
||||
<return type="void" />
|
||||
<param index="0" name="id" type="int" />
|
||||
<param index="1" name="navigation_layers" type="int" />
|
||||
<description>
|
||||
Sets the item's navigation layers bitmask.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_item_navigation_mesh">
|
||||
<return type="void" />
|
||||
<argument index="0" name="id" type="int" />
|
||||
|
@ -252,33 +252,6 @@ RID GridMap::get_navigation_map() const {
|
||||
return RID();
|
||||
}
|
||||
|
||||
void GridMap::set_navigation_layers(uint32_t p_navigation_layers) {
|
||||
navigation_layers = p_navigation_layers;
|
||||
_recreate_octant_data();
|
||||
}
|
||||
|
||||
uint32_t GridMap::get_navigation_layers() const {
|
||||
return navigation_layers;
|
||||
}
|
||||
|
||||
void GridMap::set_navigation_layer_value(int p_layer_number, bool p_value) {
|
||||
ERR_FAIL_COND_MSG(p_layer_number < 1, "Navigation layer number must be between 1 and 32 inclusive.");
|
||||
ERR_FAIL_COND_MSG(p_layer_number > 32, "Navigation layer number must be between 1 and 32 inclusive.");
|
||||
uint32_t _navigation_layers = get_navigation_layers();
|
||||
if (p_value) {
|
||||
_navigation_layers |= 1 << (p_layer_number - 1);
|
||||
} else {
|
||||
_navigation_layers &= ~(1 << (p_layer_number - 1));
|
||||
}
|
||||
set_navigation_layers(_navigation_layers);
|
||||
}
|
||||
|
||||
bool GridMap::get_navigation_layer_value(int p_layer_number) const {
|
||||
ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Navigation layer number must be between 1 and 32 inclusive.");
|
||||
ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Navigation layer number must be between 1 and 32 inclusive.");
|
||||
return get_navigation_layers() & (1 << (p_layer_number - 1));
|
||||
}
|
||||
|
||||
void GridMap::set_mesh_library(const Ref<MeshLibrary> &p_mesh_library) {
|
||||
if (!mesh_library.is_null()) {
|
||||
mesh_library->unregister_owner(this);
|
||||
@ -606,11 +579,12 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
|
||||
if (navigation_mesh.is_valid()) {
|
||||
Octant::NavigationCell nm;
|
||||
nm.xform = xform * mesh_library->get_item_navigation_mesh_transform(c.item);
|
||||
nm.navigation_layers = mesh_library->get_item_navigation_layers(c.item);
|
||||
|
||||
if (bake_navigation) {
|
||||
RID region = NavigationServer::get_singleton()->region_create();
|
||||
NavigationServer::get_singleton()->region_set_owner_id(region, get_instance_id());
|
||||
NavigationServer::get_singleton()->region_set_navigation_layers(region, navigation_layers);
|
||||
NavigationServer::get_singleton()->region_set_navigation_layers(region, nm.navigation_layers);
|
||||
NavigationServer::get_singleton()->region_set_navigation_mesh(region, navigation_mesh);
|
||||
NavigationServer::get_singleton()->region_set_transform(region, get_global_transform() * nm.xform);
|
||||
if (is_inside_tree()) {
|
||||
@ -728,10 +702,11 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) {
|
||||
for (RBMap<IndexKey, Octant::NavigationCell>::Element *E = g.navigation_cell_ids.front(); E; E = E->next()) {
|
||||
if (cell_map.has(E->key()) && E->get().region.is_valid() == false) {
|
||||
Ref<NavigationMesh> nm = mesh_library->get_item_navigation_mesh(cell_map[E->key()].item);
|
||||
|
||||
if (nm.is_valid()) {
|
||||
RID region = NavigationServer::get_singleton()->region_create();
|
||||
NavigationServer::get_singleton()->region_set_owner_id(region, get_instance_id());
|
||||
NavigationServer::get_singleton()->region_set_navigation_layers(region, navigation_layers);
|
||||
NavigationServer::get_singleton()->region_set_navigation_layers(region, E->get().navigation_layers);
|
||||
NavigationServer::get_singleton()->region_set_navigation_mesh(region, nm);
|
||||
NavigationServer::get_singleton()->region_set_transform(region, get_global_transform() * E->get().xform);
|
||||
NavigationServer::get_singleton()->region_set_map(region, get_navigation_map());
|
||||
@ -1026,12 +1001,6 @@ void GridMap::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_navigation_map", "navigation_map"), &GridMap::set_navigation_map);
|
||||
ClassDB::bind_method(D_METHOD("get_navigation_map"), &GridMap::get_navigation_map);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_navigation_layers", "navigation_layers"), &GridMap::set_navigation_layers);
|
||||
ClassDB::bind_method(D_METHOD("get_navigation_layers"), &GridMap::get_navigation_layers);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_navigation_layer_value", "layer_number", "value"), &GridMap::set_navigation_layer_value);
|
||||
ClassDB::bind_method(D_METHOD("get_navigation_layer_value", "layer_number"), &GridMap::get_navigation_layer_value);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_mesh_library", "mesh_library"), &GridMap::set_mesh_library);
|
||||
ClassDB::bind_method(D_METHOD("get_mesh_library"), &GridMap::get_mesh_library);
|
||||
|
||||
@ -1097,7 +1066,6 @@ void GridMap::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bake_navigation"), "set_bake_navigation", "is_baking_navigation");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_layers", PROPERTY_HINT_LAYERS_3D_NAVIGATION), "set_navigation_layers", "get_navigation_layers");
|
||||
|
||||
BIND_CONSTANT(INVALID_CELL_ITEM);
|
||||
|
||||
@ -1341,7 +1309,6 @@ GridMap::GridMap() {
|
||||
cell_scale = 1.0;
|
||||
|
||||
bake_navigation = false;
|
||||
navigation_layers = 1;
|
||||
|
||||
navigation = nullptr;
|
||||
set_notify_transform(true);
|
||||
|
@ -91,6 +91,11 @@ class GridMap : public Spatial {
|
||||
RID region;
|
||||
Transform xform;
|
||||
RID navigation_mesh_debug_instance;
|
||||
uint32_t navigation_layers;
|
||||
|
||||
NavigationCell() {
|
||||
navigation_layers = 1;
|
||||
}
|
||||
};
|
||||
|
||||
struct MultimeshInstance {
|
||||
@ -142,7 +147,6 @@ class GridMap : public Spatial {
|
||||
Ref<PhysicsMaterial> physics_material;
|
||||
bool bake_navigation;
|
||||
RID map_override;
|
||||
uint32_t navigation_layers;
|
||||
|
||||
Transform last_transform;
|
||||
|
||||
@ -246,12 +250,6 @@ public:
|
||||
void set_navigation_map(RID p_navigation_map);
|
||||
RID get_navigation_map() const;
|
||||
|
||||
void set_navigation_layers(uint32_t p_navigation_layers);
|
||||
uint32_t get_navigation_layers() const;
|
||||
|
||||
void set_navigation_layer_value(int p_layer_number, bool p_value);
|
||||
bool get_navigation_layer_value(int p_layer_number) const;
|
||||
|
||||
void set_mesh_library(const Ref<MeshLibrary> &p_mesh_library);
|
||||
Ref<MeshLibrary> get_mesh_library() const;
|
||||
|
||||
|
@ -33,6 +33,10 @@
|
||||
#include "scene/resources/box_shape.h"
|
||||
#include "scene/resources/navigation_mesh.h"
|
||||
|
||||
MeshLibrary::Item::Item() {
|
||||
navigation_layers = 1;
|
||||
}
|
||||
|
||||
bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
|
||||
String name = p_name;
|
||||
if (name.begins_with("item/")) {
|
||||
@ -62,6 +66,8 @@ bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
|
||||
set_item_navigation_mesh(idx, p_value);
|
||||
} else if (what == "navigation_mesh_transform") {
|
||||
set_item_navigation_mesh_transform(idx, p_value);
|
||||
} else if (what == "navigation_layers") {
|
||||
set_item_navigation_layers(idx, p_value);
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
} else if (what == "navmesh") { // Renamed after 4.0
|
||||
set_item_navigation_mesh(idx, p_value);
|
||||
@ -96,6 +102,8 @@ bool MeshLibrary::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
r_ret = get_item_navigation_mesh(idx);
|
||||
} else if (what == "navigation_mesh_transform") {
|
||||
r_ret = get_item_navigation_mesh_transform(idx);
|
||||
} else if (what == "navigation_layers") {
|
||||
r_ret = get_item_navigation_layers(idx);
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
} else if (what == "navmesh") { // Renamed after 4.0
|
||||
r_ret = get_item_navigation_mesh(idx);
|
||||
@ -120,6 +128,7 @@ void MeshLibrary::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
p_list->push_back(PropertyInfo(Variant::ARRAY, name + ("shapes")));
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, name + ("navigation_mesh"), PROPERTY_HINT_RESOURCE_TYPE, "NavigationMesh"));
|
||||
p_list->push_back(PropertyInfo(Variant::TRANSFORM, name + ("navigation_mesh_transform")));
|
||||
p_list->push_back(PropertyInfo(Variant::INT, name + ("navigation_layers"), PROPERTY_HINT_LAYERS_3D_NAVIGATION));
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, name + ("preview"), PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_EDITOR_HELPER));
|
||||
}
|
||||
}
|
||||
@ -180,6 +189,15 @@ void MeshLibrary::set_item_navigation_mesh_transform(int p_item, const Transform
|
||||
_change_notify();
|
||||
}
|
||||
|
||||
void MeshLibrary::set_item_navigation_layers(int p_item, uint32_t p_navigation_layers) {
|
||||
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
||||
item_map[p_item].navigation_layers = p_navigation_layers;
|
||||
_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_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
||||
item_map[p_item].preview = p_preview;
|
||||
@ -217,6 +235,11 @@ Transform MeshLibrary::get_item_navigation_mesh_transform(int p_item) const {
|
||||
return item_map[p_item].navigation_mesh_transform;
|
||||
}
|
||||
|
||||
uint32_t MeshLibrary::get_item_navigation_layers(int p_item) const {
|
||||
ERR_FAIL_COND_V_MSG(!item_map.has(p_item), 0, "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
||||
return item_map[p_item].navigation_layers;
|
||||
}
|
||||
|
||||
Ref<Texture> MeshLibrary::get_item_preview(int p_item) const {
|
||||
ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Ref<Texture>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
||||
return item_map[p_item].preview;
|
||||
@ -325,6 +348,7 @@ void MeshLibrary::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_item_mesh_transform", "id", "mesh_transform"), &MeshLibrary::set_item_mesh_transform);
|
||||
ClassDB::bind_method(D_METHOD("set_item_navigation_mesh", "id", "navigation_mesh"), &MeshLibrary::set_item_navigation_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_item_navigation_mesh_transform", "id", "navigation_mesh"), &MeshLibrary::set_item_navigation_mesh_transform);
|
||||
ClassDB::bind_method(D_METHOD("set_item_navigation_layers", "id", "navigation_layers"), &MeshLibrary::set_item_navigation_layers);
|
||||
ClassDB::bind_method(D_METHOD("set_item_shapes", "id", "shapes"), &MeshLibrary::_set_item_shapes);
|
||||
ClassDB::bind_method(D_METHOD("set_item_preview", "id", "texture"), &MeshLibrary::set_item_preview);
|
||||
ClassDB::bind_method(D_METHOD("get_item_name", "id"), &MeshLibrary::get_item_name);
|
||||
@ -332,6 +356,7 @@ void MeshLibrary::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_item_mesh_transform", "id"), &MeshLibrary::get_item_mesh_transform);
|
||||
ClassDB::bind_method(D_METHOD("get_item_navigation_mesh", "id"), &MeshLibrary::get_item_navigation_mesh);
|
||||
ClassDB::bind_method(D_METHOD("get_item_navigation_mesh_transform", "id"), &MeshLibrary::get_item_navigation_mesh_transform);
|
||||
ClassDB::bind_method(D_METHOD("get_item_navigation_layers", "id"), &MeshLibrary::get_item_navigation_layers);
|
||||
ClassDB::bind_method(D_METHOD("get_item_shapes", "id"), &MeshLibrary::_get_item_shapes);
|
||||
ClassDB::bind_method(D_METHOD("get_item_preview", "id"), &MeshLibrary::get_item_preview);
|
||||
ClassDB::bind_method(D_METHOD("remove_item", "id"), &MeshLibrary::remove_item);
|
||||
|
@ -33,8 +33,8 @@
|
||||
|
||||
#include "core/containers/rb_map.h"
|
||||
#include "core/object/resource.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
#include "scene/3d/navigation_mesh_instance.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
#include "scene/resources/shape.h"
|
||||
|
||||
class NavigationMesh;
|
||||
@ -56,6 +56,9 @@ public:
|
||||
Transform navigation_mesh_transform;
|
||||
Transform mesh_transform;
|
||||
Ref<NavigationMesh> navigation_mesh;
|
||||
uint32_t navigation_layers;
|
||||
|
||||
Item() ;
|
||||
};
|
||||
|
||||
RBMap<int, Item> item_map;
|
||||
@ -77,6 +80,7 @@ public:
|
||||
void set_item_mesh_transform(int p_item, const Transform &p_transform);
|
||||
void set_item_navigation_mesh(int p_item, const Ref<NavigationMesh> &p_navigation_mesh);
|
||||
void set_item_navigation_mesh_transform(int p_item, const Transform &p_transform);
|
||||
void set_item_navigation_layers(int p_item, uint32_t p_navigation_layers);
|
||||
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;
|
||||
@ -84,6 +88,7 @@ public:
|
||||
Transform get_item_mesh_transform(int p_item) const;
|
||||
Ref<NavigationMesh> get_item_navigation_mesh(int p_item) const;
|
||||
Transform get_item_navigation_mesh_transform(int p_item) const;
|
||||
uint32_t get_item_navigation_layers(int p_item) const;
|
||||
Vector<ShapeData> get_item_shapes(int p_item) const;
|
||||
Ref<Texture> get_item_preview(int p_item) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user