Skip to content

Commit

Permalink
SceneTree.get_debug_collisions_color is not available in GDExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylann committed Feb 1, 2025
1 parent aae48b5 commit 71ed210
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
3 changes: 2 additions & 1 deletion common.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def get_sources(env, is_editor_build, include_tests):
"util/godot/classes/editor_property.cpp",
"util/godot/classes/editor_settings.cpp",
"util/godot/classes/graph_edit.cpp", # Not editor-only, but only used in editor for now
"util/godot/classes/graph_node.cpp" # Not editor-only, but only used in editor for now
"util/godot/classes/graph_node.cpp", # Not editor-only, but only used in editor for now
"util/godot/classes/shape_3d.cpp" # Not editor-only, but only used in editor for now
]

if include_tests:
Expand Down
2 changes: 1 addition & 1 deletion terrain/fixed_lod/voxel_terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1969,7 +1969,7 @@ void VoxelTerrain::apply_mesh_update(const VoxelEngine::BlockMeshOutput &ob) {
const SceneTree *scene_tree = get_tree();
#if DEBUG_ENABLED
if (collision_shape.is_valid()) {
const Color debug_color = scene_tree->get_debug_collisions_color();
const Color debug_color = zylann::godot::get_shape_3d_default_color(*scene_tree);
zylann::godot::set_shape_3d_debug_color(**collision_shape, debug_color);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion terrain/variable_lod/voxel_lod_terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,7 @@ inline void set_block_collision_shape(
const SceneTree *scene_tree = terrain.get_tree();
#if DEBUG_ENABLED
if (shape.is_valid()) {
const Color debug_color = scene_tree->get_debug_collisions_color();
const Color debug_color = zylann::godot::get_shape_3d_default_color(*scene_tree);
zylann::godot::set_shape_3d_debug_color(**shape, debug_color);
}
#endif
Expand Down
24 changes: 24 additions & 0 deletions util/godot/classes/shape_3d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "shape_3d.h"
#include "../../math/color.h"
#include "project_settings.h"
#include "scene_tree.h"

namespace zylann::godot {

#ifdef TOOLS_ENABLED

Color get_shape_3d_default_color(const SceneTree &scene_tree) {
#if defined(ZN_GODOT)
return scene_tree.get_debug_collisions_color();

#elif defined(ZN_GODOT_EXTENSION)
// TODO GDX: SceneTree.get_debug_collisions_color is not exposed
return ProjectSettings::get_singleton()->get_setting(
"debug/shapes/collision/shape_color", Color(0.0, 0.6, 0.7, 0.42)
)
#endif
}

#endif

} // namespace zylann::godot
9 changes: 9 additions & 0 deletions util/godot/classes/shape_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define ZN_GODOT_SHAPE_3D_H

#include "../core/version.h"
#include "../macros.h"

#if defined(ZN_GODOT)

Expand All @@ -16,9 +17,12 @@
using namespace godot;
#endif

ZN_GODOT_FORWARD_DECLARE(class SceneTree);

namespace zylann::godot {

#ifdef DEBUG_ENABLED

inline void set_shape_3d_debug_color(Shape3D &shape, const Color color) {
// TODO GDX: `set_debug_color` is not exposed to GDExtensions
// Which means there is no way for us to show debug shapes of the terrain when the option is enabled, because they
Expand All @@ -29,6 +33,11 @@ inline void set_shape_3d_debug_color(Shape3D &shape, const Color color) {
#endif
#endif
}

// This function is primarily to implement a workaround...
// See https://github.com/godotengine/godot/pull/100328
Color get_shape_3d_default_color(const SceneTree &scene_tree);

#endif

} // namespace zylann::godot
Expand Down

0 comments on commit 71ed210

Please sign in to comment.