Added layer and mask in the gridmap node
This commit is contained in:
parent
bcf684f9d7
commit
5a15e6e75c
@ -198,6 +198,58 @@ void GridMap::_get_property_list(List<PropertyInfo> *p_list) const {
|
|||||||
p_list->push_back(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
|
p_list->push_back(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GridMap::set_collision_layer(uint32_t p_layer) {
|
||||||
|
|
||||||
|
collision_layer = p_layer;
|
||||||
|
_reset_physic_bodies_collision_filters();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t GridMap::get_collision_layer() const {
|
||||||
|
|
||||||
|
return collision_layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridMap::set_collision_mask(uint32_t p_mask) {
|
||||||
|
|
||||||
|
collision_mask = p_mask;
|
||||||
|
_reset_physic_bodies_collision_filters();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t GridMap::get_collision_mask() const {
|
||||||
|
|
||||||
|
return collision_mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridMap::set_collision_mask_bit(int p_bit, bool p_value) {
|
||||||
|
|
||||||
|
uint32_t mask = get_collision_mask();
|
||||||
|
if (p_value)
|
||||||
|
mask |= 1 << p_bit;
|
||||||
|
else
|
||||||
|
mask &= ~(1 << p_bit);
|
||||||
|
set_collision_mask(mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GridMap::get_collision_mask_bit(int p_bit) const {
|
||||||
|
|
||||||
|
return get_collision_mask() & (1 << p_bit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridMap::set_collision_layer_bit(int p_bit, bool p_value) {
|
||||||
|
|
||||||
|
uint32_t mask = get_collision_layer();
|
||||||
|
if (p_value)
|
||||||
|
mask |= 1 << p_bit;
|
||||||
|
else
|
||||||
|
mask &= ~(1 << p_bit);
|
||||||
|
set_collision_layer(mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GridMap::get_collision_layer_bit(int p_bit) const {
|
||||||
|
|
||||||
|
return get_collision_layer() & (1 << p_bit);
|
||||||
|
}
|
||||||
|
|
||||||
void GridMap::set_theme(const Ref<MeshLibrary> &p_theme) {
|
void GridMap::set_theme(const Ref<MeshLibrary> &p_theme) {
|
||||||
|
|
||||||
if (!theme.is_null())
|
if (!theme.is_null())
|
||||||
@ -311,6 +363,8 @@ void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) {
|
|||||||
g->dirty = true;
|
g->dirty = true;
|
||||||
g->static_body = PhysicsServer::get_singleton()->body_create(PhysicsServer::BODY_MODE_STATIC);
|
g->static_body = PhysicsServer::get_singleton()->body_create(PhysicsServer::BODY_MODE_STATIC);
|
||||||
PhysicsServer::get_singleton()->body_attach_object_instance_id(g->static_body, get_instance_id());
|
PhysicsServer::get_singleton()->body_attach_object_instance_id(g->static_body, get_instance_id());
|
||||||
|
PhysicsServer::get_singleton()->body_set_collision_layer(g->static_body, collision_layer);
|
||||||
|
PhysicsServer::get_singleton()->body_set_collision_mask(g->static_body, collision_mask);
|
||||||
SceneTree *st = SceneTree::get_singleton();
|
SceneTree *st = SceneTree::get_singleton();
|
||||||
|
|
||||||
if (st && st->is_debugging_collisions_hint()) {
|
if (st && st->is_debugging_collisions_hint()) {
|
||||||
@ -575,6 +629,13 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GridMap::_reset_physic_bodies_collision_filters() {
|
||||||
|
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
|
||||||
|
PhysicsServer::get_singleton()->body_set_collision_layer(E->get()->static_body, collision_layer);
|
||||||
|
PhysicsServer::get_singleton()->body_set_collision_mask(E->get()->static_body, collision_mask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GridMap::_octant_enter_world(const OctantKey &p_key) {
|
void GridMap::_octant_enter_world(const OctantKey &p_key) {
|
||||||
|
|
||||||
ERR_FAIL_COND(!octant_map.has(p_key));
|
ERR_FAIL_COND(!octant_map.has(p_key));
|
||||||
@ -815,6 +876,18 @@ void GridMap::_update_octants_callback() {
|
|||||||
|
|
||||||
void GridMap::_bind_methods() {
|
void GridMap::_bind_methods() {
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &GridMap::set_collision_layer);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_collision_layer"), &GridMap::get_collision_layer);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &GridMap::set_collision_mask);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_collision_mask"), &GridMap::get_collision_mask);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &GridMap::set_collision_mask_bit);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &GridMap::get_collision_mask_bit);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &GridMap::set_collision_layer_bit);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &GridMap::get_collision_layer_bit);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_theme", "theme"), &GridMap::set_theme);
|
ClassDB::bind_method(D_METHOD("set_theme", "theme"), &GridMap::set_theme);
|
||||||
ClassDB::bind_method(D_METHOD("get_theme"), &GridMap::get_theme);
|
ClassDB::bind_method(D_METHOD("get_theme"), &GridMap::get_theme);
|
||||||
|
|
||||||
@ -855,6 +928,10 @@ void GridMap::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("clear_baked_meshes"), &GridMap::clear_baked_meshes);
|
ClassDB::bind_method(D_METHOD("clear_baked_meshes"), &GridMap::clear_baked_meshes);
|
||||||
ClassDB::bind_method(D_METHOD("make_baked_meshes", "gen_lightmap_uv", "lightmap_uv_texel_size"), &GridMap::make_baked_meshes, DEFVAL(false), DEFVAL(0.1));
|
ClassDB::bind_method(D_METHOD("make_baked_meshes", "gen_lightmap_uv", "lightmap_uv_texel_size"), &GridMap::make_baked_meshes, DEFVAL(false), DEFVAL(0.1));
|
||||||
|
|
||||||
|
ADD_GROUP("Collision", "collision_");
|
||||||
|
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");
|
||||||
|
|
||||||
BIND_CONSTANT(INVALID_CELL_ITEM);
|
BIND_CONSTANT(INVALID_CELL_ITEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1067,6 +1144,9 @@ RID GridMap::get_bake_mesh_instance(int p_idx) {
|
|||||||
|
|
||||||
GridMap::GridMap() {
|
GridMap::GridMap() {
|
||||||
|
|
||||||
|
collision_layer = 1;
|
||||||
|
collision_mask = 1;
|
||||||
|
|
||||||
cell_size = Vector3(2, 2, 2);
|
cell_size = Vector3(2, 2, 2);
|
||||||
octant_size = 8;
|
octant_size = 8;
|
||||||
awaiting_update = false;
|
awaiting_update = false;
|
||||||
|
@ -136,6 +136,9 @@ class GridMap : public Spatial {
|
|||||||
OctantKey() { key = 0; }
|
OctantKey() { key = 0; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uint32_t collision_layer;
|
||||||
|
uint32_t collision_mask;
|
||||||
|
|
||||||
Transform last_transform;
|
Transform last_transform;
|
||||||
|
|
||||||
bool _in_tree;
|
bool _in_tree;
|
||||||
@ -173,6 +176,7 @@ class GridMap : public Spatial {
|
|||||||
return Vector3(p_key.x, p_key.y, p_key.z) * cell_size * octant_size;
|
return Vector3(p_key.x, p_key.y, p_key.z) * cell_size * octant_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _reset_physic_bodies_collision_filters();
|
||||||
void _octant_enter_world(const OctantKey &p_key);
|
void _octant_enter_world(const OctantKey &p_key);
|
||||||
void _octant_exit_world(const OctantKey &p_key);
|
void _octant_exit_world(const OctantKey &p_key);
|
||||||
bool _octant_update(const OctantKey &p_key);
|
bool _octant_update(const OctantKey &p_key);
|
||||||
@ -210,6 +214,18 @@ public:
|
|||||||
INVALID_CELL_ITEM = -1
|
INVALID_CELL_ITEM = -1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void set_collision_layer(uint32_t p_layer);
|
||||||
|
uint32_t get_collision_layer() const;
|
||||||
|
|
||||||
|
void set_collision_mask(uint32_t p_mask);
|
||||||
|
uint32_t get_collision_mask() const;
|
||||||
|
|
||||||
|
void set_collision_layer_bit(int p_bit, bool p_value);
|
||||||
|
bool get_collision_layer_bit(int p_bit) const;
|
||||||
|
|
||||||
|
void set_collision_mask_bit(int p_bit, bool p_value);
|
||||||
|
bool get_collision_mask_bit(int p_bit) const;
|
||||||
|
|
||||||
void set_theme(const Ref<MeshLibrary> &p_theme);
|
void set_theme(const Ref<MeshLibrary> &p_theme);
|
||||||
Ref<MeshLibrary> get_theme() const;
|
Ref<MeshLibrary> get_theme() const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user