From 5d51478d70fbe4d2ff202f8d3c70d326635cef99 Mon Sep 17 00:00:00 2001 From: clayjohn Date: Thu, 15 Dec 2022 09:50:14 -0800 Subject: [PATCH] Expose GeometryInstance3D.custom_aabb property --- doc/classes/GeometryInstance3D.xml | 10 +++------- doc/classes/RenderingServer.xml | 2 +- scene/3d/visual_instance_3d.cpp | 14 ++++++++++++-- scene/3d/visual_instance_3d.h | 4 +++- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/doc/classes/GeometryInstance3D.xml b/doc/classes/GeometryInstance3D.xml index 90a983d28bf..1ae4718536b 100644 --- a/doc/classes/GeometryInstance3D.xml +++ b/doc/classes/GeometryInstance3D.xml @@ -16,13 +16,6 @@ Get the value of a shader parameter as set on this instance. - - - - - Overrides the bounding box of this node with a custom one. To remove it, set an [AABB] with all fields set to zero. - - @@ -36,6 +29,9 @@ The selected shadow casting flag. See [enum ShadowCastingSetting] for possible values. + + Overrides the bounding box of this node with a custom one. This can be used to avoid the expensive [AABB] recalculation that happens when a skeleton is used with a [MeshInstance3D] or to have fine control over the [MeshInstance3D]'s bounding box. To remove this, set value to an [AABB] with all fields set to zero. + The extra distance added to the GeometryInstance3D's bounding box ([AABB]) to increase its cull box. diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index 7a9a380032e..d9b83f2acd5 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -1559,7 +1559,7 @@ - Sets a custom AABB to use when culling objects from the view frustum. Equivalent to [method GeometryInstance3D.set_custom_aabb]. + Sets a custom AABB to use when culling objects from the view frustum. Equivalent to setting [member GeometryInstance3D.custom_aabb]. diff --git a/scene/3d/visual_instance_3d.cpp b/scene/3d/visual_instance_3d.cpp index b5b37bf8376..94fcb9214f5 100644 --- a/scene/3d/visual_instance_3d.cpp +++ b/scene/3d/visual_instance_3d.cpp @@ -331,8 +331,16 @@ Variant GeometryInstance3D::get_instance_shader_parameter(const StringName &p_na return RS::get_singleton()->instance_geometry_get_shader_parameter(get_instance(), p_name); } -void GeometryInstance3D::set_custom_aabb(AABB aabb) { - RS::get_singleton()->instance_set_custom_aabb(get_instance(), aabb); +void GeometryInstance3D::set_custom_aabb(AABB p_aabb) { + if (p_aabb == custom_aabb) { + return; + } + custom_aabb = p_aabb; + RS::get_singleton()->instance_set_custom_aabb(get_instance(), custom_aabb); +} + +AABB GeometryInstance3D::get_custom_aabb() const { + return custom_aabb; } void GeometryInstance3D::set_lightmap_scale(LightmapScale p_scale) { @@ -442,6 +450,7 @@ void GeometryInstance3D::_bind_methods() { ClassDB::bind_method(D_METHOD("is_ignoring_occlusion_culling"), &GeometryInstance3D::is_ignoring_occlusion_culling); ClassDB::bind_method(D_METHOD("set_custom_aabb", "aabb"), &GeometryInstance3D::set_custom_aabb); + ClassDB::bind_method(D_METHOD("get_custom_aabb"), &GeometryInstance3D::get_custom_aabb); ClassDB::bind_method(D_METHOD("get_aabb"), &GeometryInstance3D::get_aabb); @@ -451,6 +460,7 @@ void GeometryInstance3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "transparency", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_transparency", "get_transparency"); ADD_PROPERTY(PropertyInfo(Variant::INT, "cast_shadow", PROPERTY_HINT_ENUM, "Off,On,Double-Sided,Shadows Only"), "set_cast_shadows_setting", "get_cast_shadows_setting"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "extra_cull_margin", PROPERTY_HINT_RANGE, "0,16384,0.01,suffix:m"), "set_extra_cull_margin", "get_extra_cull_margin"); + ADD_PROPERTY(PropertyInfo(Variant::AABB, "custom_aabb", PROPERTY_HINT_NONE, "suffix:m"), "set_custom_aabb", "get_custom_aabb"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lod_bias", PROPERTY_HINT_RANGE, "0.001,128,0.001"), "set_lod_bias", "get_lod_bias"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ignore_occlusion_culling"), "set_ignore_occlusion_culling", "is_ignoring_occlusion_culling"); diff --git a/scene/3d/visual_instance_3d.h b/scene/3d/visual_instance_3d.h index f18bff2ddca..c741ef710da 100644 --- a/scene/3d/visual_instance_3d.h +++ b/scene/3d/visual_instance_3d.h @@ -121,6 +121,7 @@ private: mutable HashMap instance_shader_parameter_property_remap; float extra_cull_margin = 0.0; + AABB custom_aabb; LightmapScale lightmap_scale = LIGHTMAP_SCALE_1X; GIMode gi_mode = GI_MODE_STATIC; bool ignore_occlusion_culling = false; @@ -177,7 +178,8 @@ public: void set_instance_shader_parameter(const StringName &p_name, const Variant &p_value); Variant get_instance_shader_parameter(const StringName &p_name) const; - void set_custom_aabb(AABB aabb); + void set_custom_aabb(AABB p_aabb); + AABB get_custom_aabb() const; void set_ignore_occlusion_culling(bool p_enabled); bool is_ignoring_occlusion_culling();