Skip to content

Commit

Permalink
Expose debug views from Terrain3D node
Browse files Browse the repository at this point in the history
  • Loading branch information
TokisanGames committed Dec 26, 2024
1 parent c8519b8 commit 5b50116
Show file tree
Hide file tree
Showing 6 changed files with 536 additions and 75 deletions.
431 changes: 377 additions & 54 deletions doc/api/class_terrain3d.rst

Large diffs are not rendered by default.

55 changes: 53 additions & 2 deletions doc/doc_classes/Terrain3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,59 @@
If enabled, heightmaps are saved as 16-bit half-precision to reduce file size. Files are always loaded in 32-bit for editing. Upon save, a copy of the heightmap is converted to 16-bit for writing. It does not change what is currently in memory.
This process is lossy. 16-bit precision gets increasingly worse with every power of 2. At a height of 256m, the precision interval is .25m. At 512m it is .5m. At 1024m it is 1m. Saving a height of 1024.4m will be rounded down to 1024m.
</member>
<member name="show_grid" type="bool" setter="set_show_grid" getter="get_show_grid" default="false">
Draws the region grid directly on the terrain. This is more accurate than the region grid gizmo for determining where the region border is when editing.
<member name="show_autoshader" type="bool" setter="set_show_autoshader" getter="get_show_autoshader" default="false">
Alias for [member Terrain3DMaterial.show_autoshader].
</member>
<member name="show_checkered" type="bool" setter="set_show_checkered" getter="get_show_checkered" default="false">
Alias for [member Terrain3DMaterial.show_checkered].
</member>
<member name="show_colormap" type="bool" setter="set_show_colormap" getter="get_show_colormap" default="false">
Alias for [member Terrain3DMaterial.show_colormap].
</member>
<member name="show_control_angle" type="bool" setter="set_show_control_angle" getter="get_show_control_angle" default="false">
Alias for [member Terrain3DMaterial.show_control_angle].
</member>
<member name="show_control_blend" type="bool" setter="set_show_control_blend" getter="get_show_control_blend" default="false">
Alias for [member Terrain3DMaterial.show_control_blend].
</member>
<member name="show_control_scale" type="bool" setter="set_show_control_scale" getter="get_show_control_scale" default="false">
Alias for [member Terrain3DMaterial.show_control_scale].
</member>
<member name="show_control_texture" type="bool" setter="set_show_control_texture" getter="get_show_control_texture" default="false">
Alias for [member Terrain3DMaterial.show_control_texture].
</member>
<member name="show_grey" type="bool" setter="set_show_grey" getter="get_show_grey" default="false">
Alias for [member Terrain3DMaterial.show_grey].
</member>
<member name="show_grid" type="bool" setter="set_show_region_grid" getter="get_show_region_grid" default="false">
Alias for [member Terrain3DMaterial.show_region_grid].
</member>
<member name="show_heightmap" type="bool" setter="set_show_heightmap" getter="get_show_heightmap" default="false">
Alias for [member Terrain3DMaterial.show_heightmap].
</member>
<member name="show_instancer_grid" type="bool" setter="set_show_instancer_grid" getter="get_show_instancer_grid" default="false">
Alias for [member Terrain3DMaterial.show_instancer_grid].
</member>
<member name="show_navigation" type="bool" setter="set_show_navigation" getter="get_show_navigation" default="false">
Alias for [member Terrain3DMaterial.show_navigation].
</member>
<member name="show_region_grid" type="bool" setter="set_show_region_grid" getter="get_show_region_grid" default="false">
Alias for [member Terrain3DMaterial.show_region_grid].
</member>
<member name="show_roughmap" type="bool" setter="set_show_roughmap" getter="get_show_roughmap" default="false">
Alias for [member Terrain3DMaterial.show_autoshader].
</member>
<member name="show_texture_height" type="bool" setter="set_show_texture_height" getter="get_show_texture_height" default="false">
Alias for [member Terrain3DMaterial.show_texture_height].
</member>
<member name="show_texture_normal" type="bool" setter="set_show_texture_normal" getter="get_show_texture_normal" default="false">
Alias for [member Terrain3DMaterial.show_texture_normal].
</member>
<member name="show_texture_rough" type="bool" setter="set_show_texture_rough" getter="get_show_texture_rough" default="false">
Alias for [member Terrain3DMaterial.show_texture_rough].
</member>
<member name="show_vertex_grid" type="bool" setter="set_show_vertex_grid" getter="get_show_vertex_grid" default="false">
Alias for [member Terrain3DMaterial.show_vertex_grid].
</member>
<member name="version" type="String" setter="" getter="get_version" default="&quot;1.0.0-dev&quot;">
The current version of Terrain3D.
Expand Down
59 changes: 56 additions & 3 deletions src/terrain_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1492,8 +1492,6 @@ void Terrain3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_label_distance"), &Terrain3D::get_label_distance);
ClassDB::bind_method(D_METHOD("set_label_size", "size"), &Terrain3D::set_label_size);
ClassDB::bind_method(D_METHOD("get_label_size"), &Terrain3D::get_label_size);
ClassDB::bind_method(D_METHOD("set_show_grid", "enabled"), &Terrain3D::set_show_grid);
ClassDB::bind_method(D_METHOD("get_show_grid"), &Terrain3D::get_show_grid);

// Collision
ClassDB::bind_method(D_METHOD("set_collision_enabled", "enabled"), &Terrain3D::set_collision_enabled);
Expand Down Expand Up @@ -1529,6 +1527,42 @@ void Terrain3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_cull_margin"), &Terrain3D::get_cull_margin);
ClassDB::bind_method(D_METHOD("is_compatibility_mode"), &Terrain3D::is_compatibility_mode);

// Debug Views
ClassDB::bind_method(D_METHOD("set_show_checkered", "enabled"), &Terrain3D::set_show_checkered);
ClassDB::bind_method(D_METHOD("get_show_checkered"), &Terrain3D::get_show_checkered);
ClassDB::bind_method(D_METHOD("set_show_grey", "enabled"), &Terrain3D::set_show_grey);
ClassDB::bind_method(D_METHOD("get_show_grey"), &Terrain3D::get_show_grey);
ClassDB::bind_method(D_METHOD("set_show_heightmap", "enabled"), &Terrain3D::set_show_heightmap);
ClassDB::bind_method(D_METHOD("get_show_heightmap"), &Terrain3D::get_show_heightmap);
ClassDB::bind_method(D_METHOD("set_show_colormap", "enabled"), &Terrain3D::set_show_colormap);
ClassDB::bind_method(D_METHOD("get_show_colormap"), &Terrain3D::get_show_colormap);
ClassDB::bind_method(D_METHOD("set_show_roughmap", "enabled"), &Terrain3D::set_show_roughmap);
ClassDB::bind_method(D_METHOD("get_show_roughmap"), &Terrain3D::get_show_roughmap);
ClassDB::bind_method(D_METHOD("set_show_control_texture", "enabled"), &Terrain3D::set_show_control_texture);
ClassDB::bind_method(D_METHOD("get_show_control_texture"), &Terrain3D::get_show_control_texture);
ClassDB::bind_method(D_METHOD("set_show_control_angle", "enabled"), &Terrain3D::set_show_control_angle);
ClassDB::bind_method(D_METHOD("get_show_control_angle"), &Terrain3D::get_show_control_angle);
ClassDB::bind_method(D_METHOD("set_show_control_scale", "enabled"), &Terrain3D::set_show_control_scale);
ClassDB::bind_method(D_METHOD("get_show_control_scale"), &Terrain3D::get_show_control_scale);
ClassDB::bind_method(D_METHOD("set_show_control_blend", "enabled"), &Terrain3D::set_show_control_blend);
ClassDB::bind_method(D_METHOD("get_show_control_blend"), &Terrain3D::get_show_control_blend);
ClassDB::bind_method(D_METHOD("set_show_autoshader", "enabled"), &Terrain3D::set_show_autoshader);
ClassDB::bind_method(D_METHOD("get_show_autoshader"), &Terrain3D::get_show_autoshader);
ClassDB::bind_method(D_METHOD("set_show_navigation", "enabled"), &Terrain3D::set_show_navigation);
ClassDB::bind_method(D_METHOD("get_show_navigation"), &Terrain3D::get_show_navigation);
ClassDB::bind_method(D_METHOD("set_show_texture_height", "enabled"), &Terrain3D::set_show_texture_height);
ClassDB::bind_method(D_METHOD("get_show_texture_height"), &Terrain3D::get_show_texture_height);
ClassDB::bind_method(D_METHOD("set_show_texture_normal", "enabled"), &Terrain3D::set_show_texture_normal);
ClassDB::bind_method(D_METHOD("get_show_texture_normal"), &Terrain3D::get_show_texture_normal);
ClassDB::bind_method(D_METHOD("set_show_texture_rough", "enabled"), &Terrain3D::set_show_texture_rough);
ClassDB::bind_method(D_METHOD("get_show_texture_rough"), &Terrain3D::get_show_texture_rough);
ClassDB::bind_method(D_METHOD("set_show_region_grid", "enabled"), &Terrain3D::set_show_region_grid);
ClassDB::bind_method(D_METHOD("get_show_region_grid"), &Terrain3D::get_show_region_grid);
ClassDB::bind_method(D_METHOD("set_show_instancer_grid", "enabled"), &Terrain3D::set_show_instancer_grid);
ClassDB::bind_method(D_METHOD("get_show_instancer_grid"), &Terrain3D::get_show_instancer_grid);
ClassDB::bind_method(D_METHOD("set_show_vertex_grid", "enabled"), &Terrain3D::set_show_vertex_grid);
ClassDB::bind_method(D_METHOD("get_show_vertex_grid"), &Terrain3D::get_show_vertex_grid);

// Utility
ClassDB::bind_method(D_METHOD("get_intersection", "src_pos", "direction", "gpu_mode"), &Terrain3D::get_intersection, DEFVAL(false));
ClassDB::bind_method(D_METHOD("bake_mesh", "lod", "filter"), &Terrain3D::bake_mesh);
Expand All @@ -1549,7 +1583,7 @@ void Terrain3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "save_16_bit"), "set_save_16_bit", "get_save_16_bit");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "label_distance", PROPERTY_HINT_RANGE, "0.0,10000.0,0.5,or_greater"), "set_label_distance", "get_label_distance");
ADD_PROPERTY(PropertyInfo(Variant::INT, "label_size", PROPERTY_HINT_RANGE, "24,128,1"), "set_label_size", "get_label_size");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_grid"), "set_show_grid", "get_show_grid");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_grid"), "set_show_region_grid", "get_show_region_grid");

ADD_GROUP("Collision", "");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision_enabled"), "set_collision_enabled", "get_collision_enabled");
Expand All @@ -1570,6 +1604,25 @@ void Terrain3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "gi_mode", PROPERTY_HINT_ENUM, "Disabled,Static,Dynamic"), "set_gi_mode", "get_gi_mode");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "cull_margin", PROPERTY_HINT_RANGE, "0.0,10000.0,.5,or_greater"), "set_cull_margin", "get_cull_margin");

ADD_GROUP("Debug Views", "show_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_checkered", PROPERTY_HINT_NONE), "set_show_checkered", "get_show_checkered");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_grey", PROPERTY_HINT_NONE), "set_show_grey", "get_show_grey");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_heightmap", PROPERTY_HINT_NONE), "set_show_heightmap", "get_show_heightmap");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_colormap", PROPERTY_HINT_NONE), "set_show_colormap", "get_show_colormap");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_roughmap", PROPERTY_HINT_NONE), "set_show_roughmap", "get_show_roughmap");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_control_texture", PROPERTY_HINT_NONE), "set_show_control_texture", "get_show_control_texture");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_control_angle", PROPERTY_HINT_NONE), "set_show_control_angle", "get_show_control_angle");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_control_scale", PROPERTY_HINT_NONE), "set_show_control_scale", "get_show_control_scale");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_control_blend", PROPERTY_HINT_NONE), "set_show_control_blend", "get_show_control_blend");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_autoshader", PROPERTY_HINT_NONE), "set_show_autoshader", "get_show_autoshader");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_navigation", PROPERTY_HINT_NONE), "set_show_navigation", "get_show_navigation");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_texture_height", PROPERTY_HINT_NONE), "set_show_texture_height", "get_show_texture_height");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_texture_normal", PROPERTY_HINT_NONE), "set_show_texture_normal", "get_show_texture_normal");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_texture_rough", PROPERTY_HINT_NONE), "set_show_texture_rough", "get_show_texture_rough");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_region_grid", PROPERTY_HINT_NONE), "set_show_region_grid", "get_show_region_grid");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_instancer_grid", PROPERTY_HINT_NONE), "set_show_instancer_grid", "get_show_instancer_grid");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_vertex_grid", PROPERTY_HINT_NONE), "set_show_vertex_grid", "get_show_vertex_grid");

ADD_SIGNAL(MethodInfo("material_changed"));
ADD_SIGNAL(MethodInfo("assets_changed"));
}
38 changes: 36 additions & 2 deletions src/terrain_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ class Terrain3D : public Node3D {
void set_label_size(const int p_size);
int get_label_size() const { return _label_size; }
void update_region_labels();
void set_show_grid(const bool p_enabled) { (_material != nullptr) ? _material->set_show_region_grid(p_enabled) : void(); }
bool get_show_grid() { return (_material != nullptr) ? _material->get_show_region_grid() : false; }

// Collision
void set_collision_enabled(const bool p_enabled);
Expand Down Expand Up @@ -210,6 +208,42 @@ class Terrain3D : public Node3D {
real_t get_cull_margin() const { return _cull_margin; };
bool is_compatibility_mode() const { return _compatibility; };

// Debug Views
void set_show_checkered(const bool p_enabled) { (_material != nullptr) ? _material->set_show_checkered(p_enabled) : void(); }
bool get_show_checkered() { return (_material != nullptr) ? _material->get_show_checkered() : false; }
void set_show_grey(const bool p_enabled) { (_material != nullptr) ? _material->set_show_grey(p_enabled) : void(); }
bool get_show_grey() { return (_material != nullptr) ? _material->get_show_grey() : false; }
void set_show_heightmap(const bool p_enabled) { (_material != nullptr) ? _material->set_show_heightmap(p_enabled) : void(); }
bool get_show_heightmap() { return (_material != nullptr) ? _material->get_show_heightmap() : false; }
void set_show_colormap(const bool p_enabled) { (_material != nullptr) ? _material->set_show_colormap(p_enabled) : void(); }
bool get_show_colormap() { return (_material != nullptr) ? _material->get_show_colormap() : false; }
void set_show_roughmap(const bool p_enabled) { (_material != nullptr) ? _material->set_show_roughmap(p_enabled) : void(); }
bool get_show_roughmap() { return (_material != nullptr) ? _material->get_show_roughmap() : false; }
void set_show_control_texture(const bool p_enabled) { (_material != nullptr) ? _material->set_show_control_texture(p_enabled) : void(); }
bool get_show_control_texture() { return (_material != nullptr) ? _material->get_show_control_texture() : false; }
void set_show_control_angle(const bool p_enabled) { (_material != nullptr) ? _material->set_show_control_angle(p_enabled) : void(); }
bool get_show_control_angle() { return (_material != nullptr) ? _material->get_show_control_angle() : false; }
void set_show_control_scale(const bool p_enabled) { (_material != nullptr) ? _material->set_show_control_scale(p_enabled) : void(); }
bool get_show_control_scale() { return (_material != nullptr) ? _material->get_show_control_scale() : false; }
void set_show_control_blend(const bool p_enabled) { (_material != nullptr) ? _material->set_show_control_blend(p_enabled) : void(); }
bool get_show_control_blend() { return (_material != nullptr) ? _material->get_show_control_blend() : false; }
void set_show_autoshader(const bool p_enabled) { (_material != nullptr) ? _material->set_show_autoshader(p_enabled) : void(); }
bool get_show_autoshader() { return (_material != nullptr) ? _material->get_show_autoshader() : false; }
void set_show_navigation(const bool p_enabled) { (_material != nullptr) ? _material->set_show_navigation(p_enabled) : void(); }
bool get_show_navigation() { return (_material != nullptr) ? _material->get_show_navigation() : false; }
void set_show_texture_height(const bool p_enabled) { (_material != nullptr) ? _material->set_show_texture_height(p_enabled) : void(); }
bool get_show_texture_height() { return (_material != nullptr) ? _material->get_show_texture_height() : false; }
void set_show_texture_normal(const bool p_enabled) { (_material != nullptr) ? _material->set_show_texture_normal(p_enabled) : void(); }
bool get_show_texture_normal() { return (_material != nullptr) ? _material->get_show_texture_normal() : false; }
void set_show_texture_rough(const bool p_enabled) { (_material != nullptr) ? _material->set_show_texture_rough(p_enabled) : void(); }
bool get_show_texture_rough() { return (_material != nullptr) ? _material->get_show_texture_rough() : false; }
void set_show_region_grid(const bool p_enabled) { (_material != nullptr) ? _material->set_show_region_grid(p_enabled) : void(); }
bool get_show_region_grid() { return (_material != nullptr) ? _material->get_show_region_grid() : false; }
void set_show_instancer_grid(const bool p_enabled) { (_material != nullptr) ? _material->set_show_instancer_grid(p_enabled) : void(); }
bool get_show_instancer_grid() { return (_material != nullptr) ? _material->get_show_instancer_grid() : false; }
void set_show_vertex_grid(const bool p_enabled) { (_material != nullptr) ? _material->set_show_vertex_grid(p_enabled) : void(); }
bool get_show_vertex_grid() { return (_material != nullptr) ? _material->get_show_vertex_grid() : false; }

// Processing
void snap(const Vector3 &p_cam_pos);
void update_aabbs();
Expand Down
Loading

0 comments on commit 5b50116

Please sign in to comment.