summaryrefslogtreecommitdiff
path: root/scene/3d
diff options
context:
space:
mode:
authorBastiaan Olij <mux213@gmail.com>2022-12-13 15:13:16 +1100
committerBastiaan Olij <mux213@gmail.com>2022-12-23 19:30:33 +1100
commit6f4f38db07c901a8b7dc74ad871af98030336031 (patch)
tree6d2730e2b086545fa0ca178e20363553756fc6b4 /scene/3d
parentdb6976eed4c59b3a320cb26938898c732ef6b7ca (diff)
Added options for sorting transparent objects (port of PR 63040)
Diffstat (limited to 'scene/3d')
-rw-r--r--scene/3d/visual_instance_3d.cpp26
-rw-r--r--scene/3d/visual_instance_3d.h8
2 files changed, 34 insertions, 0 deletions
diff --git a/scene/3d/visual_instance_3d.cpp b/scene/3d/visual_instance_3d.cpp
index b5b37bf837..73af068c4a 100644
--- a/scene/3d/visual_instance_3d.cpp
+++ b/scene/3d/visual_instance_3d.cpp
@@ -101,6 +101,24 @@ bool VisualInstance3D::get_layer_mask_value(int p_layer_number) const {
return layers & (1 << (p_layer_number - 1));
}
+void VisualInstance3D::set_sorting_offset(float p_offset) {
+ sorting_offset = p_offset;
+ RenderingServer::get_singleton()->instance_set_pivot_data(instance, sorting_offset, sorting_use_aabb_center);
+}
+
+float VisualInstance3D::get_sorting_offset() const {
+ return sorting_offset;
+}
+
+void VisualInstance3D::set_sorting_use_aabb_center(bool p_enabled) {
+ sorting_use_aabb_center = p_enabled;
+ RenderingServer::get_singleton()->instance_set_pivot_data(instance, sorting_offset, sorting_use_aabb_center);
+}
+
+bool VisualInstance3D::is_sorting_use_aabb_center() const {
+ return sorting_use_aabb_center;
+}
+
void VisualInstance3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_base", "base"), &VisualInstance3D::set_base);
ClassDB::bind_method(D_METHOD("get_base"), &VisualInstance3D::get_base);
@@ -109,9 +127,17 @@ void VisualInstance3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_layer_mask"), &VisualInstance3D::get_layer_mask);
ClassDB::bind_method(D_METHOD("set_layer_mask_value", "layer_number", "value"), &VisualInstance3D::set_layer_mask_value);
ClassDB::bind_method(D_METHOD("get_layer_mask_value", "layer_number"), &VisualInstance3D::get_layer_mask_value);
+ ClassDB::bind_method(D_METHOD("set_sorting_offset", "offset"), &VisualInstance3D::set_sorting_offset);
+ ClassDB::bind_method(D_METHOD("get_sorting_offset"), &VisualInstance3D::get_sorting_offset);
+ ClassDB::bind_method(D_METHOD("set_sorting_use_aabb_center", "enabled"), &VisualInstance3D::set_sorting_use_aabb_center);
+ ClassDB::bind_method(D_METHOD("is_sorting_use_aabb_center"), &VisualInstance3D::is_sorting_use_aabb_center);
GDVIRTUAL_BIND(_get_aabb);
ADD_PROPERTY(PropertyInfo(Variant::INT, "layers", PROPERTY_HINT_LAYERS_3D_RENDER), "set_layer_mask", "get_layer_mask");
+
+ ADD_GROUP("Sorting", "sorting_");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sorting_offset"), "set_sorting_offset", "get_sorting_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sorting_use_aabb_center"), "set_sorting_use_aabb_center", "is_sorting_use_aabb_center");
}
void VisualInstance3D::set_base(const RID &p_base) {
diff --git a/scene/3d/visual_instance_3d.h b/scene/3d/visual_instance_3d.h
index f18bff2ddc..8241aef96d 100644
--- a/scene/3d/visual_instance_3d.h
+++ b/scene/3d/visual_instance_3d.h
@@ -39,6 +39,8 @@ class VisualInstance3D : public Node3D {
RID base;
RID instance;
uint32_t layers = 1;
+ float sorting_offset = 0.0;
+ bool sorting_use_aabb_center = true;
protected:
void _update_visibility();
@@ -67,6 +69,12 @@ public:
void set_layer_mask_value(int p_layer_number, bool p_enable);
bool get_layer_mask_value(int p_layer_number) const;
+ void set_sorting_offset(float p_offset);
+ float get_sorting_offset() const;
+
+ void set_sorting_use_aabb_center(bool p_enabled);
+ bool is_sorting_use_aabb_center() const;
+
VisualInstance3D();
~VisualInstance3D();
};