Feat: Support to show GridMap collider in editor
This commit is contained in:
parent
4d1f26e1fd
commit
e658da74e4
3 changed files with 61 additions and 6 deletions
|
|
@ -214,6 +214,9 @@
|
|||
<member name="collision_priority" type="float" setter="set_collision_priority" getter="get_collision_priority" default="1.0">
|
||||
The priority used to solve colliding when occurring penetration. The higher the priority is, the lower the penetration into the object will be. This can for example be used to prevent the player from breaking through the boundaries of a level.
|
||||
</member>
|
||||
<member name="collision_visibility_mode" type="int" setter="set_collision_visibility_mode" getter="get_collision_visibility_mode" enum="GridMap.DebugVisibilityMode" default="0">
|
||||
Show or hide the [GridMap]'s collision shapes. If set to [constant DEBUG_VISIBILITY_MODE_DEFAULT], this depends on the show collision debug settings.
|
||||
</member>
|
||||
<member name="mesh_library" type="MeshLibrary" setter="set_mesh_library" getter="get_mesh_library">
|
||||
The assigned [MeshLibrary].
|
||||
</member>
|
||||
|
|
@ -238,5 +241,14 @@
|
|||
<constant name="INVALID_CELL_ITEM" value="-1">
|
||||
Invalid cell item that can be used in [method set_cell_item] to clear cells (or represent an empty cell in [method get_cell_item]).
|
||||
</constant>
|
||||
<constant name="DEBUG_VISIBILITY_MODE_DEFAULT" value="0" enum="DebugVisibilityMode">
|
||||
Hide the collisions debug shapes in the editor, and use the debug settings to determine their visibility in game (i.e. [member SceneTree.debug_collisions_hint] or [member SceneTree.debug_navigation_hint]).
|
||||
</constant>
|
||||
<constant name="DEBUG_VISIBILITY_MODE_FORCE_SHOW" value="1" enum="DebugVisibilityMode">
|
||||
Always show the collisions debug shapes.
|
||||
</constant>
|
||||
<constant name="DEBUG_VISIBILITY_MODE_FORCE_HIDE" value="2" enum="DebugVisibilityMode">
|
||||
Always hide the collisions debug shapes.
|
||||
</constant>
|
||||
</constants>
|
||||
</class>
|
||||
|
|
|
|||
|
|
@ -213,6 +213,18 @@ real_t GridMap::get_collision_priority() const {
|
|||
return collision_priority;
|
||||
}
|
||||
|
||||
void GridMap::set_collision_visibility_mode(DebugVisibilityMode p_visibility_mode) {
|
||||
if (collision_visibility_mode == p_visibility_mode) {
|
||||
return;
|
||||
}
|
||||
collision_visibility_mode = p_visibility_mode;
|
||||
_recreate_octant_data();
|
||||
}
|
||||
|
||||
GridMap::DebugVisibilityMode GridMap::get_collision_visibility_mode() const {
|
||||
return collision_visibility_mode;
|
||||
}
|
||||
|
||||
void GridMap::set_physics_material(Ref<PhysicsMaterial> p_material) {
|
||||
physics_material = p_material;
|
||||
_update_physics_bodies_characteristics();
|
||||
|
|
@ -395,12 +407,23 @@ void GridMap::set_cell_item(const Vector3i &p_position, int p_item, int p_rot) {
|
|||
PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_BOUNCE, physics_material->computed_bounce());
|
||||
}
|
||||
#endif // PHYSICS_3D_DISABLED
|
||||
SceneTree *st = SceneTree::get_singleton();
|
||||
|
||||
if (st && st->is_debugging_collisions_hint()) {
|
||||
g->collision_debug = RenderingServer::get_singleton()->mesh_create();
|
||||
g->collision_debug_instance = RenderingServer::get_singleton()->instance_create();
|
||||
RenderingServer::get_singleton()->instance_set_base(g->collision_debug_instance, g->collision_debug);
|
||||
bool debug_collisions = false;
|
||||
switch (collision_visibility_mode) {
|
||||
case DEBUG_VISIBILITY_MODE_DEFAULT: {
|
||||
SceneTree *st = SceneTree::get_singleton();
|
||||
debug_collisions = st && !Engine::get_singleton()->is_editor_hint() && st->is_debugging_collisions_hint();
|
||||
} break;
|
||||
case DEBUG_VISIBILITY_MODE_FORCE_HIDE: {
|
||||
debug_collisions = false;
|
||||
} break;
|
||||
case DEBUG_VISIBILITY_MODE_FORCE_SHOW: {
|
||||
debug_collisions = true;
|
||||
} break;
|
||||
}
|
||||
if (debug_collisions) {
|
||||
g->collision_debug = RS::get_singleton()->mesh_create();
|
||||
g->collision_debug_instance = RS::get_singleton()->instance_create();
|
||||
RS::get_singleton()->instance_set_base(g->collision_debug_instance, g->collision_debug);
|
||||
}
|
||||
|
||||
octant_map[octantkey] = g;
|
||||
|
|
@ -1176,6 +1199,9 @@ void GridMap::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_collision_priority", "priority"), &GridMap::set_collision_priority);
|
||||
ClassDB::bind_method(D_METHOD("get_collision_priority"), &GridMap::get_collision_priority);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_collision_visibility_mode", "visibility_mode"), &GridMap::set_collision_visibility_mode);
|
||||
ClassDB::bind_method(D_METHOD("get_collision_visibility_mode"), &GridMap::get_collision_visibility_mode);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_physics_material", "material"), &GridMap::set_physics_material);
|
||||
ClassDB::bind_method(D_METHOD("get_physics_material"), &GridMap::get_physics_material);
|
||||
#endif // PHYSICS_3D_DISABLED
|
||||
|
|
@ -1247,6 +1273,7 @@ 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::FLOAT, "collision_priority"), "set_collision_priority", "get_collision_priority");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_visibility_mode", PROPERTY_HINT_ENUM, "Default,Force Show,Force Hide"), "set_collision_visibility_mode", "get_collision_visibility_mode");
|
||||
#endif // PHYSICS_3D_DISABLED
|
||||
ADD_GROUP("Navigation", "");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bake_navigation"), "set_bake_navigation", "is_baking_navigation");
|
||||
|
|
@ -1255,6 +1282,10 @@ void GridMap::_bind_methods() {
|
|||
|
||||
ADD_SIGNAL(MethodInfo("cell_size_changed", PropertyInfo(Variant::VECTOR3, "cell_size")));
|
||||
ADD_SIGNAL(MethodInfo(CoreStringName(changed)));
|
||||
|
||||
BIND_ENUM_CONSTANT(DEBUG_VISIBILITY_MODE_DEFAULT);
|
||||
BIND_ENUM_CONSTANT(DEBUG_VISIBILITY_MODE_FORCE_SHOW);
|
||||
BIND_ENUM_CONSTANT(DEBUG_VISIBILITY_MODE_FORCE_HIDE);
|
||||
}
|
||||
|
||||
void GridMap::set_cell_scale(float p_scale) {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,12 @@ class PhysicsMaterial;
|
|||
class GridMap : public Node3D {
|
||||
GDCLASS(GridMap, Node3D);
|
||||
|
||||
enum DebugVisibilityMode {
|
||||
DEBUG_VISIBILITY_MODE_DEFAULT,
|
||||
DEBUG_VISIBILITY_MODE_FORCE_SHOW,
|
||||
DEBUG_VISIBILITY_MODE_FORCE_HIDE,
|
||||
};
|
||||
|
||||
enum {
|
||||
MAP_DIRTY_TRANSFORMS = 1,
|
||||
MAP_DIRTY_INSTANCES = 2,
|
||||
|
|
@ -156,6 +162,7 @@ class GridMap : public Node3D {
|
|||
uint32_t collision_layer = 1;
|
||||
uint32_t collision_mask = 1;
|
||||
real_t collision_priority = 1.0;
|
||||
DebugVisibilityMode collision_visibility_mode = DEBUG_VISIBILITY_MODE_DEFAULT;
|
||||
Ref<PhysicsMaterial> physics_material;
|
||||
#endif // PHYSICS_3D_DISABLED
|
||||
bool bake_navigation = false;
|
||||
|
|
@ -255,6 +262,9 @@ public:
|
|||
void set_collision_priority(real_t p_priority);
|
||||
real_t get_collision_priority() const;
|
||||
|
||||
void set_collision_visibility_mode(DebugVisibilityMode p_visibility_mode);
|
||||
DebugVisibilityMode get_collision_visibility_mode() const;
|
||||
|
||||
void set_physics_material(Ref<PhysicsMaterial> p_material);
|
||||
Ref<PhysicsMaterial> get_physics_material() const;
|
||||
|
||||
|
|
@ -326,3 +336,5 @@ public:
|
|||
GridMap();
|
||||
~GridMap();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(GridMap::DebugVisibilityMode);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue