diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/3d/light_3d.cpp | 13 | ||||
-rw-r--r-- | scene/3d/xr_nodes.cpp | 37 | ||||
-rw-r--r-- | scene/3d/xr_nodes.h | 9 | ||||
-rw-r--r-- | scene/resources/material.cpp | 8 | ||||
-rw-r--r-- | scene/resources/material.h | 3 | ||||
-rw-r--r-- | scene/resources/mesh.cpp | 8 | ||||
-rw-r--r-- | scene/resources/mesh.h | 2 | ||||
-rw-r--r-- | scene/resources/shader.cpp | 7 | ||||
-rw-r--r-- | scene/resources/shader.h | 1 | ||||
-rw-r--r-- | scene/resources/texture.cpp | 53 | ||||
-rw-r--r-- | scene/resources/texture.h | 19 |
11 files changed, 137 insertions, 23 deletions
diff --git a/scene/3d/light_3d.cpp b/scene/3d/light_3d.cpp index 77073ff763..cca84c2b85 100644 --- a/scene/3d/light_3d.cpp +++ b/scene/3d/light_3d.cpp @@ -157,9 +157,16 @@ AABB Light3D::get_aabb() const { return AABB(Vector3(-1, -1, -1) * param[PARAM_RANGE], Vector3(2, 2, 2) * param[PARAM_RANGE]); } else if (type == RenderingServer::LIGHT_SPOT) { - real_t len = param[PARAM_RANGE]; - real_t size = Math::tan(Math::deg_to_rad(param[PARAM_SPOT_ANGLE])) * len; - return AABB(Vector3(-size, -size, -len), Vector3(size * 2, size * 2, len)); + real_t cone_slant_height = param[PARAM_RANGE]; + real_t cone_angle_rad = Math::deg_to_rad(param[PARAM_SPOT_ANGLE]); + + if (cone_angle_rad > Math_PI / 2.0) { + // Just return the AABB of an omni light if the spot angle is above 90 degrees. + return AABB(Vector3(-1, -1, -1) * cone_slant_height, Vector3(2, 2, 2) * cone_slant_height); + } + + real_t size = Math::sin(cone_angle_rad) * cone_slant_height; + return AABB(Vector3(-size, -size, -cone_slant_height), Vector3(2 * size, 2 * size, cone_slant_height)); } return AABB(); diff --git a/scene/3d/xr_nodes.cpp b/scene/3d/xr_nodes.cpp index a758cc5e5e..ac0a47d1a1 100644 --- a/scene/3d/xr_nodes.cpp +++ b/scene/3d/xr_nodes.cpp @@ -432,15 +432,16 @@ PackedStringArray XRNode3D::get_configuration_warnings() const { void XRController3D::_bind_methods() { // passthroughs to information about our related joystick ClassDB::bind_method(D_METHOD("is_button_pressed", "name"), &XRController3D::is_button_pressed); - ClassDB::bind_method(D_METHOD("get_value", "name"), &XRController3D::get_value); - ClassDB::bind_method(D_METHOD("get_axis", "name"), &XRController3D::get_axis); + ClassDB::bind_method(D_METHOD("get_input", "name"), &XRController3D::get_input); + ClassDB::bind_method(D_METHOD("get_float", "name"), &XRController3D::get_float); + ClassDB::bind_method(D_METHOD("get_vector2", "name"), &XRController3D::get_vector2); ClassDB::bind_method(D_METHOD("get_tracker_hand"), &XRController3D::get_tracker_hand); ADD_SIGNAL(MethodInfo("button_pressed", PropertyInfo(Variant::STRING, "name"))); ADD_SIGNAL(MethodInfo("button_released", PropertyInfo(Variant::STRING, "name"))); - ADD_SIGNAL(MethodInfo("input_value_changed", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::FLOAT, "value"))); - ADD_SIGNAL(MethodInfo("input_axis_changed", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::VECTOR2, "value"))); + ADD_SIGNAL(MethodInfo("input_float_changed", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::FLOAT, "value"))); + ADD_SIGNAL(MethodInfo("input_vector2_changed", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::VECTOR2, "value"))); }; void XRController3D::_bind_tracker() { @@ -449,8 +450,8 @@ void XRController3D::_bind_tracker() { // bind to input signals tracker->connect("button_pressed", callable_mp(this, &XRController3D::_button_pressed)); tracker->connect("button_released", callable_mp(this, &XRController3D::_button_released)); - tracker->connect("input_value_changed", callable_mp(this, &XRController3D::_input_value_changed)); - tracker->connect("input_axis_changed", callable_mp(this, &XRController3D::_input_axis_changed)); + tracker->connect("input_float_changed", callable_mp(this, &XRController3D::_input_float_changed)); + tracker->connect("input_vector2_changed", callable_mp(this, &XRController3D::_input_vector2_changed)); } } @@ -459,8 +460,8 @@ void XRController3D::_unbind_tracker() { // unbind input signals tracker->disconnect("button_pressed", callable_mp(this, &XRController3D::_button_pressed)); tracker->disconnect("button_released", callable_mp(this, &XRController3D::_button_released)); - tracker->disconnect("input_value_changed", callable_mp(this, &XRController3D::_input_value_changed)); - tracker->disconnect("input_axis_changed", callable_mp(this, &XRController3D::_input_axis_changed)); + tracker->disconnect("input_float_changed", callable_mp(this, &XRController3D::_input_float_changed)); + tracker->disconnect("input_vector2_changed", callable_mp(this, &XRController3D::_input_vector2_changed)); } XRNode3D::_unbind_tracker(); @@ -476,14 +477,14 @@ void XRController3D::_button_released(const String &p_name) { emit_signal(SNAME("button_released"), p_name); } -void XRController3D::_input_value_changed(const String &p_name, float p_value) { +void XRController3D::_input_float_changed(const String &p_name, float p_value) { // just pass it on... - emit_signal(SNAME("input_value_changed"), p_name, p_value); + emit_signal(SNAME("input_float_changed"), p_name, p_value); } -void XRController3D::_input_axis_changed(const String &p_name, Vector2 p_value) { +void XRController3D::_input_vector2_changed(const String &p_name, Vector2 p_value) { // just pass it on... - emit_signal(SNAME("input_axis_changed"), p_name, p_value); + emit_signal(SNAME("input_vector2_changed"), p_name, p_value); } bool XRController3D::is_button_pressed(const StringName &p_name) const { @@ -496,7 +497,15 @@ bool XRController3D::is_button_pressed(const StringName &p_name) const { } } -float XRController3D::get_value(const StringName &p_name) const { +Variant XRController3D::get_input(const StringName &p_name) const { + if (tracker.is_valid()) { + return tracker->get_input(p_name); + } else { + return Variant(); + } +} + +float XRController3D::get_float(const StringName &p_name) const { if (tracker.is_valid()) { // Inputs should already be of the correct type, our XR runtime handles conversions between raw input and the desired type, but just in case we convert Variant input = tracker->get_input(p_name); @@ -517,7 +526,7 @@ float XRController3D::get_value(const StringName &p_name) const { } } -Vector2 XRController3D::get_axis(const StringName &p_name) const { +Vector2 XRController3D::get_vector2(const StringName &p_name) const { if (tracker.is_valid()) { // Inputs should already be of the correct type, our XR runtime handles conversions between raw input and the desired type, but just in case we convert Variant input = tracker->get_input(p_name); diff --git a/scene/3d/xr_nodes.h b/scene/3d/xr_nodes.h index c93cb14d62..6e56aa28de 100644 --- a/scene/3d/xr_nodes.h +++ b/scene/3d/xr_nodes.h @@ -131,13 +131,14 @@ protected: void _button_pressed(const String &p_name); void _button_released(const String &p_name); - void _input_value_changed(const String &p_name, float p_value); - void _input_axis_changed(const String &p_name, Vector2 p_value); + void _input_float_changed(const String &p_name, float p_value); + void _input_vector2_changed(const String &p_name, Vector2 p_value); public: bool is_button_pressed(const StringName &p_name) const; - float get_value(const StringName &p_name) const; - Vector2 get_axis(const StringName &p_name) const; + Variant get_input(const StringName &p_name) const; + float get_float(const StringName &p_name) const; + Vector2 get_vector2(const StringName &p_name) const; XRPositionalTracker::TrackerHand get_tracker_hand() const; diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 9c3a2ffb87..f4aa0637f7 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -113,6 +113,12 @@ bool Material::_can_use_render_priority() const { return ret; } +Ref<Resource> Material::create_placeholder() const { + Ref<PlaceholderMaterial> placeholder; + placeholder.instantiate(); + return placeholder; +} + void Material::_bind_methods() { ClassDB::bind_method(D_METHOD("set_next_pass", "next_pass"), &Material::set_next_pass); ClassDB::bind_method(D_METHOD("get_next_pass"), &Material::get_next_pass); @@ -123,6 +129,8 @@ void Material::_bind_methods() { ClassDB::bind_method(D_METHOD("inspect_native_shader_code"), &Material::inspect_native_shader_code); ClassDB::set_method_flags(get_class_static(), _scs_create("inspect_native_shader_code"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); + ClassDB::bind_method(D_METHOD("create_placeholder"), &Material::create_placeholder); + ADD_PROPERTY(PropertyInfo(Variant::INT, "render_priority", PROPERTY_HINT_RANGE, itos(RENDER_PRIORITY_MIN) + "," + itos(RENDER_PRIORITY_MAX) + ",1"), "set_render_priority", "get_render_priority"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "next_pass", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_next_pass", "get_next_pass"); diff --git a/scene/resources/material.h b/scene/resources/material.h index 83c7a09cc4..fe1448cd4c 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -74,6 +74,9 @@ public: virtual RID get_rid() const override; virtual RID get_shader_rid() const; virtual Shader::Mode get_shader_mode() const; + + virtual Ref<Resource> create_placeholder() const; + Material(); virtual ~Material(); }; diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 991e060e94..cf9baa2907 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -615,6 +615,13 @@ Size2i Mesh::get_lightmap_size_hint() const { return lightmap_size_hint; } +Ref<Resource> Mesh::create_placeholder() const { + Ref<PlaceholderMesh> placeholder; + placeholder.instantiate(); + placeholder->set_aabb(get_aabb()); + return placeholder; +} + void Mesh::_bind_methods() { ClassDB::bind_method(D_METHOD("set_lightmap_size_hint", "size"), &Mesh::set_lightmap_size_hint); ClassDB::bind_method(D_METHOD("get_lightmap_size_hint"), &Mesh::get_lightmap_size_hint); @@ -627,6 +634,7 @@ void Mesh::_bind_methods() { ClassDB::bind_method(D_METHOD("surface_get_blend_shape_arrays", "surf_idx"), &Mesh::surface_get_blend_shape_arrays); ClassDB::bind_method(D_METHOD("surface_set_material", "surf_idx", "material"), &Mesh::surface_set_material); ClassDB::bind_method(D_METHOD("surface_get_material", "surf_idx"), &Mesh::surface_get_material); + ClassDB::bind_method(D_METHOD("create_placeholder"), &Mesh::create_placeholder); BIND_ENUM_CONSTANT(PRIMITIVE_POINTS); BIND_ENUM_CONSTANT(PRIMITIVE_LINES); diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index 1baa466312..1b870d996a 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -220,6 +220,8 @@ public: virtual int get_builtin_bind_pose_count() const; virtual Transform3D get_builtin_bind_pose(int p_index) const; + virtual Ref<Resource> create_placeholder() const; + Mesh(); }; diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index b3952e745f..a09dbd50cf 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -42,9 +42,12 @@ Shader::Mode Shader::get_mode() const { } void Shader::_dependency_changed() { - RenderingServer::get_singleton()->shader_set_code(shader, RenderingServer::get_singleton()->shader_get_code(shader)); + // Preprocess and compile the code again because a dependency has changed. It also calls emit_changed() for us. + _recompile(); +} - emit_changed(); +void Shader::_recompile() { + set_code(get_code()); } void Shader::set_path(const String &p_path, bool p_take_over) { diff --git a/scene/resources/shader.h b/scene/resources/shader.h index 75c490e912..55608b6c11 100644 --- a/scene/resources/shader.h +++ b/scene/resources/shader.h @@ -60,6 +60,7 @@ private: HashMap<StringName, HashMap<int, Ref<Texture2D>>> default_textures; void _dependency_changed(); + void _recompile(); virtual void _update_shader() const; //used for visual shader Array _get_shader_uniform_list(bool p_get_groups = false); diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index f106eebff5..85e21d6056 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -94,6 +94,13 @@ bool Texture2D::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Re return true; } +Ref<Resource> Texture2D::create_placeholder() const { + Ref<PlaceholderTexture2D> placeholder; + placeholder.instantiate(); + placeholder->set_size(get_size()); + return placeholder; +} + void Texture2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_width"), &Texture2D::get_width); ClassDB::bind_method(D_METHOD("get_height"), &Texture2D::get_height); @@ -103,6 +110,7 @@ void Texture2D::_bind_methods() { ClassDB::bind_method(D_METHOD("draw_rect", "canvas_item", "rect", "tile", "modulate", "transpose"), &Texture2D::draw_rect, DEFVAL(Color(1, 1, 1)), DEFVAL(false)); ClassDB::bind_method(D_METHOD("draw_rect_region", "canvas_item", "rect", "src_rect", "modulate", "transpose", "clip_uv"), &Texture2D::draw_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(true)); ClassDB::bind_method(D_METHOD("get_image"), &Texture2D::get_image); + ClassDB::bind_method(D_METHOD("create_placeholder"), &Texture2D::create_placeholder); ADD_GROUP("", ""); @@ -1137,6 +1145,7 @@ void Texture3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_depth"), &Texture3D::get_depth); ClassDB::bind_method(D_METHOD("has_mipmaps"), &Texture3D::has_mipmaps); ClassDB::bind_method(D_METHOD("get_data"), &Texture3D::_get_datai); + ClassDB::bind_method(D_METHOD("create_placeholder"), &Texture3D::create_placeholder); GDVIRTUAL_BIND(_get_format); GDVIRTUAL_BIND(_get_width); @@ -1145,6 +1154,14 @@ void Texture3D::_bind_methods() { GDVIRTUAL_BIND(_has_mipmaps); GDVIRTUAL_BIND(_get_data); } + +Ref<Resource> Texture3D::create_placeholder() const { + Ref<PlaceholderTexture3D> placeholder; + placeholder.instantiate(); + placeholder->set_size(Vector3i(get_width(), get_height(), get_depth())); + return placeholder; +} + ////////////////////////////////////////// Image::Format ImageTexture3D::get_format() const { @@ -3048,6 +3065,42 @@ ImageTextureLayered::~ImageTextureLayered() { } } +void Texture2DArray::_bind_methods() { + ClassDB::bind_method(D_METHOD("create_placeholder"), &Texture2DArray::create_placeholder); +} + +Ref<Resource> Texture2DArray::create_placeholder() const { + Ref<PlaceholderTexture2DArray> placeholder; + placeholder.instantiate(); + placeholder->set_size(Size2i(get_width(), get_height())); + placeholder->set_layers(get_layers()); + return placeholder; +} + +void Cubemap::_bind_methods() { + ClassDB::bind_method(D_METHOD("create_placeholder"), &Cubemap::create_placeholder); +} + +Ref<Resource> Cubemap::create_placeholder() const { + Ref<PlaceholderCubemap> placeholder; + placeholder.instantiate(); + placeholder->set_size(Size2i(get_width(), get_height())); + placeholder->set_layers(get_layers()); + return placeholder; +} + +void CubemapArray::_bind_methods() { + ClassDB::bind_method(D_METHOD("create_placeholder"), &CubemapArray::create_placeholder); +} + +Ref<Resource> CubemapArray::create_placeholder() const { + Ref<PlaceholderCubemapArray> placeholder; + placeholder.instantiate(); + placeholder->set_size(Size2i(get_width(), get_height())); + placeholder->set_layers(get_layers()); + return placeholder; +} + /////////////////////////////////////////// void CompressedTextureLayered::set_path(const String &p_path, bool p_take_over) { diff --git a/scene/resources/texture.h b/scene/resources/texture.h index bb86910c0c..7f74ae6941 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -82,6 +82,8 @@ public: virtual Ref<Image> get_image() const { return Ref<Image>(); } + virtual Ref<Resource> create_placeholder() const; + Texture2D(); }; @@ -450,25 +452,41 @@ public: class Texture2DArray : public ImageTextureLayered { GDCLASS(Texture2DArray, ImageTextureLayered) + +protected: + static void _bind_methods(); + public: Texture2DArray() : ImageTextureLayered(LAYERED_TYPE_2D_ARRAY) {} + + virtual Ref<Resource> create_placeholder() const; }; class Cubemap : public ImageTextureLayered { GDCLASS(Cubemap, ImageTextureLayered); +protected: + static void _bind_methods(); + public: Cubemap() : ImageTextureLayered(LAYERED_TYPE_CUBEMAP) {} + + virtual Ref<Resource> create_placeholder() const; }; class CubemapArray : public ImageTextureLayered { GDCLASS(CubemapArray, ImageTextureLayered); +protected: + static void _bind_methods(); + public: CubemapArray() : ImageTextureLayered(LAYERED_TYPE_CUBEMAP_ARRAY) {} + + virtual Ref<Resource> create_placeholder() const; }; class CompressedTextureLayered : public TextureLayered { @@ -580,6 +598,7 @@ public: virtual int get_depth() const; virtual bool has_mipmaps() const; virtual Vector<Ref<Image>> get_data() const; + virtual Ref<Resource> create_placeholder() const; }; class ImageTexture3D : public Texture3D { |