diff options
Diffstat (limited to 'scene')
28 files changed, 310 insertions, 147 deletions
diff --git a/scene/2d/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp index 19484442b1..abbfbf83b7 100644 --- a/scene/2d/navigation_region_2d.cpp +++ b/scene/2d/navigation_region_2d.cpp @@ -118,7 +118,7 @@ Array NavigationPolygon::_get_polygons() const { return ret; } -void NavigationPolygon::_set_outlines(const TypedArray<Vector<int32_t>> &p_array) { +void NavigationPolygon::_set_outlines(const TypedArray<Vector<Vector2>> &p_array) { outlines.resize(p_array.size()); for (int i = 0; i < p_array.size(); i++) { diff --git a/scene/2d/navigation_region_2d.h b/scene/2d/navigation_region_2d.h index cbfe4299fb..e730df6373 100644 --- a/scene/2d/navigation_region_2d.h +++ b/scene/2d/navigation_region_2d.h @@ -58,7 +58,7 @@ protected: void _set_polygons(const TypedArray<Vector<int32_t>> &p_array); Array _get_polygons() const; - void _set_outlines(const TypedArray<Vector<int32_t>> &p_array); + void _set_outlines(const TypedArray<Vector<Vector2>> &p_array); Array _get_outlines() const; public: diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index ac8a77b6cb..1ea51be148 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -42,6 +42,7 @@ Dictionary Node2D::_edit_get_state() const { state["position"] = get_position(); state["rotation"] = get_rotation(); state["scale"] = get_scale(); + state["skew"] = get_skew(); return state; } @@ -51,11 +52,14 @@ void Node2D::_edit_set_state(const Dictionary &p_state) { pos = p_state["position"]; angle = p_state["rotation"]; _scale = p_state["scale"]; + skew = p_state["skew"]; _update_transform(); _change_notify("rotation"); _change_notify("rotation_degrees"); _change_notify("scale"); + _change_notify("skew"); + _change_notify("skew_degrees"); _change_notify("position"); } @@ -111,7 +115,7 @@ void Node2D::_edit_set_rect(const Rect2 &p_edit_rect) { Point2 new_pos = p_edit_rect.position + p_edit_rect.size * zero_offset; Transform2D postxf; - postxf.set_rotation_and_scale(angle, _scale); + postxf.set_rotation_scale_and_skew(angle, _scale, skew); new_pos = postxf.xform(new_pos); pos += new_pos; @@ -128,12 +132,13 @@ void Node2D::_update_xform_values() { pos = _mat.elements[2]; angle = _mat.get_rotation(); _scale = _mat.get_scale(); + skew = _mat.get_skew(); _xform_dirty = false; } void Node2D::_update_transform() { - _mat.set_rotation_and_scale(angle, _scale); + _mat.set_rotation_scale_and_skew(angle, _scale, skew); _mat.elements[2] = pos; RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), _mat); @@ -163,11 +168,26 @@ void Node2D::set_rotation(float p_radians) { _change_notify("rotation_degrees"); } +void Node2D::set_skew(float p_radians) { + + if (_xform_dirty) + ((Node2D *)this)->_update_xform_values(); + skew = p_radians; + _update_transform(); + _change_notify("skew"); + _change_notify("skew_degrees"); +} + void Node2D::set_rotation_degrees(float p_degrees) { set_rotation(Math::deg2rad(p_degrees)); } +void Node2D::set_skew_degrees(float p_degrees) { + + set_skew(Math::deg2rad(p_degrees)); +} + void Node2D::set_scale(const Size2 &p_scale) { if (_xform_dirty) @@ -196,11 +216,22 @@ float Node2D::get_rotation() const { return angle; } +float Node2D::get_skew() const { + if (_xform_dirty) + ((Node2D *)this)->_update_xform_values(); + + return skew; +} + float Node2D::get_rotation_degrees() const { return Math::rad2deg(get_rotation()); } +float Node2D::get_skew_degrees() const { + + return Math::rad2deg(get_skew()); +} Size2 Node2D::get_scale() const { if (_xform_dirty) ((Node2D *)this)->_update_xform_values(); @@ -398,11 +429,15 @@ void Node2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_position", "position"), &Node2D::set_position); ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Node2D::set_rotation); ClassDB::bind_method(D_METHOD("set_rotation_degrees", "degrees"), &Node2D::set_rotation_degrees); + ClassDB::bind_method(D_METHOD("set_skew", "radians"), &Node2D::set_skew); + ClassDB::bind_method(D_METHOD("set_skew_degrees", "degrees"), &Node2D::set_skew_degrees); ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Node2D::set_scale); ClassDB::bind_method(D_METHOD("get_position"), &Node2D::get_position); ClassDB::bind_method(D_METHOD("get_rotation"), &Node2D::get_rotation); ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Node2D::get_rotation_degrees); + ClassDB::bind_method(D_METHOD("get_skew"), &Node2D::get_skew); + ClassDB::bind_method(D_METHOD("get_skew_degrees"), &Node2D::get_skew_degrees); ClassDB::bind_method(D_METHOD("get_scale"), &Node2D::get_scale); ClassDB::bind_method(D_METHOD("rotate", "radians"), &Node2D::rotate); @@ -443,6 +478,8 @@ void Node2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_rotation", "get_rotation"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rotation_degrees", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater", PROPERTY_USAGE_EDITOR), "set_rotation_degrees", "get_rotation_degrees"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "skew", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_skew", "get_skew"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "skew_degrees", PROPERTY_HINT_RANGE, "-89.9,89.9,0.1", PROPERTY_USAGE_EDITOR), "set_skew_degrees", "get_skew_degrees"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "transform", PROPERTY_HINT_NONE, "", 0), "set_transform", "get_transform"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_position", PROPERTY_HINT_NONE, "", 0), "set_global_position", "get_global_position"); @@ -460,6 +497,7 @@ Node2D::Node2D() { angle = 0; _scale = Vector2(1, 1); + skew = 0; _xform_dirty = false; z_index = 0; z_relative = true; diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h index abed05ed0c..0afec36254 100644 --- a/scene/2d/node_2d.h +++ b/scene/2d/node_2d.h @@ -40,6 +40,7 @@ class Node2D : public CanvasItem { Point2 pos; float angle; Size2 _scale; + float skew; int z_index; bool z_relative; @@ -75,6 +76,8 @@ public: void set_position(const Point2 &p_pos); void set_rotation(float p_radians); void set_rotation_degrees(float p_degrees); + void set_skew(float p_radians); + void set_skew_degrees(float p_radians); void set_scale(const Size2 &p_scale); void rotate(float p_radians); @@ -86,7 +89,9 @@ public: Point2 get_position() const; float get_rotation() const; + float get_skew() const; float get_rotation_degrees() const; + float get_skew_degrees() const; Size2 get_scale() const; Point2 get_global_position() const; diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 9628c01718..86e61fe878 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -940,13 +940,10 @@ void TileMap::update_bitmask_area(const Vector2 &p_pos) { void TileMap::update_bitmask_region(const Vector2 &p_start, const Vector2 &p_end) { if ((p_end.x < p_start.x || p_end.y < p_start.y) || (p_end.x == p_start.x && p_end.y == p_start.y)) { - int i; Array a = get_used_cells(); - for (i = 0; i < a.size(); i++) { - // update_bitmask_area() in order to update cells adjacent to the - // current cell, since ordering in array may not be reliable + for (int i = 0; i < a.size(); i++) { Vector2 vector = (Vector2)a[i]; - update_bitmask_area(Vector2(vector.x, vector.y)); + update_cell_bitmask(vector.x, vector.y); } return; } diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 28a8b01437..f2395d35fb 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -385,8 +385,8 @@ void AudioStreamPlayer3D::_notification(int p_what) { linear_velocity = velocity_tracker->get_tracked_linear_velocity(); } - Ref<World3D> world = get_world(); - ERR_FAIL_COND(world.is_null()); + Ref<World3D> world_3d = get_world_3d(); + ERR_FAIL_COND(world_3d.is_null()); int new_output_count = 0; @@ -396,7 +396,7 @@ void AudioStreamPlayer3D::_notification(int p_what) { //check if any area is diverting sound into a bus - PhysicsDirectSpaceState3D *space_state = PhysicsServer3D::get_singleton()->space_get_direct_state(world->get_space()); + PhysicsDirectSpaceState3D *space_state = PhysicsServer3D::get_singleton()->space_get_direct_state(world_3d->get_space()); PhysicsDirectSpaceState3D::ShapeResult sr[MAX_INTERSECT_AREAS]; @@ -419,7 +419,7 @@ void AudioStreamPlayer3D::_notification(int p_what) { } List<Camera3D *> cameras; - world->get_camera_list(&cameras); + world_3d->get_camera_list(&cameras); for (List<Camera3D *>::Element *E = cameras.front(); E; E = E->next()) { diff --git a/scene/3d/camera_3d.cpp b/scene/3d/camera_3d.cpp index 706c49b43b..2fcb2715be 100644 --- a/scene/3d/camera_3d.cpp +++ b/scene/3d/camera_3d.cpp @@ -95,8 +95,8 @@ void Camera3D::_update_camera() { get_viewport()->_camera_transform_changed_notify(); - if (get_world().is_valid()) { - get_world()->_update_camera(this); + if (get_world_3d().is_valid()) { + get_world_3d()->_update_camera(this); } } @@ -144,12 +144,12 @@ void Camera3D::_notification(int p_what) { } break; case NOTIFICATION_BECAME_CURRENT: { if (viewport) { - viewport->find_world()->_register_camera(this); + viewport->find_world_3d()->_register_camera(this); } } break; case NOTIFICATION_LOST_CURRENT: { if (viewport) { - viewport->find_world()->_remove_camera(this); + viewport->find_world_3d()->_remove_camera(this); } } break; } @@ -743,7 +743,7 @@ void ClippedCamera3D::_notification(int p_what) { return; } - PhysicsDirectSpaceState3D *dspace = get_world()->get_direct_space_state(); + PhysicsDirectSpaceState3D *dspace = get_world_3d()->get_direct_space_state(); ERR_FAIL_COND(!dspace); // most likely physics set to threads Vector3 cam_fw = -get_global_transform().basis.get_axis(Vector3::AXIS_Z).normalized(); diff --git a/scene/3d/collision_object_3d.cpp b/scene/3d/collision_object_3d.cpp index e6cd7bfe7e..5d050e32b0 100644 --- a/scene/3d/collision_object_3d.cpp +++ b/scene/3d/collision_object_3d.cpp @@ -44,7 +44,7 @@ void CollisionObject3D::_notification(int p_what) { else PhysicsServer3D::get_singleton()->body_set_state(rid, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform()); - RID space = get_world()->get_space(); + RID space = get_world_3d()->get_space(); if (area) { PhysicsServer3D::get_singleton()->area_set_space(rid, space); } else diff --git a/scene/3d/cpu_particles_3d.cpp b/scene/3d/cpu_particles_3d.cpp index 12c105b0f4..4c25f55f0b 100644 --- a/scene/3d/cpu_particles_3d.cpp +++ b/scene/3d/cpu_particles_3d.cpp @@ -69,6 +69,7 @@ void CPUParticles3D::set_amount(int p_amount) { for (int i = 0; i < p_amount; i++) { w[i].active = false; + w[i].custom[3] = 0.0; // Make sure w component isn't garbage data } } diff --git a/scene/3d/node_3d.cpp b/scene/3d/node_3d.cpp index 0b7407e049..913a3ea49f 100644 --- a/scene/3d/node_3d.cpp +++ b/scene/3d/node_3d.cpp @@ -507,12 +507,12 @@ bool Node3D::is_set_as_toplevel() const { return data.toplevel; } -Ref<World3D> Node3D::get_world() const { +Ref<World3D> Node3D::get_world_3d() const { ERR_FAIL_COND_V(!is_inside_world(), Ref<World3D>()); ERR_FAIL_COND_V(!data.viewport, Ref<World3D>()); - return data.viewport->find_world(); + return data.viewport->find_world_3d(); } void Node3D::_propagate_visibility_changed() { @@ -756,7 +756,7 @@ void Node3D::_bind_methods() { ClassDB::bind_method(D_METHOD("is_set_as_toplevel"), &Node3D::is_set_as_toplevel); ClassDB::bind_method(D_METHOD("set_disable_scale", "disable"), &Node3D::set_disable_scale); ClassDB::bind_method(D_METHOD("is_scale_disabled"), &Node3D::is_scale_disabled); - ClassDB::bind_method(D_METHOD("get_world"), &Node3D::get_world); + ClassDB::bind_method(D_METHOD("get_world_3d"), &Node3D::get_world_3d); ClassDB::bind_method(D_METHOD("force_update_transform"), &Node3D::force_update_transform); diff --git a/scene/3d/node_3d.h b/scene/3d/node_3d.h index f97a8a97dc..a4191eb2b3 100644 --- a/scene/3d/node_3d.h +++ b/scene/3d/node_3d.h @@ -124,7 +124,7 @@ public: Node3D *get_parent_spatial() const; - Ref<World3D> get_world() const; + Ref<World3D> get_world_3d() const; void set_translation(const Vector3 &p_translation); void set_rotation(const Vector3 &p_euler_rad); diff --git a/scene/3d/physics_joint_3d.cpp b/scene/3d/physics_joint_3d.cpp index 591c17a91e..140d887d9a 100644 --- a/scene/3d/physics_joint_3d.cpp +++ b/scene/3d/physics_joint_3d.cpp @@ -807,6 +807,9 @@ void Generic6DOFJoint3D::_bind_methods() { BIND_ENUM_CONSTANT(PARAM_LINEAR_DAMPING); BIND_ENUM_CONSTANT(PARAM_LINEAR_MOTOR_TARGET_VELOCITY); BIND_ENUM_CONSTANT(PARAM_LINEAR_MOTOR_FORCE_LIMIT); + BIND_ENUM_CONSTANT(PARAM_LINEAR_SPRING_STIFFNESS); + BIND_ENUM_CONSTANT(PARAM_LINEAR_SPRING_DAMPING); + BIND_ENUM_CONSTANT(PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT); BIND_ENUM_CONSTANT(PARAM_ANGULAR_LOWER_LIMIT); BIND_ENUM_CONSTANT(PARAM_ANGULAR_UPPER_LIMIT); BIND_ENUM_CONSTANT(PARAM_ANGULAR_LIMIT_SOFTNESS); @@ -816,6 +819,9 @@ void Generic6DOFJoint3D::_bind_methods() { BIND_ENUM_CONSTANT(PARAM_ANGULAR_ERP); BIND_ENUM_CONSTANT(PARAM_ANGULAR_MOTOR_TARGET_VELOCITY); BIND_ENUM_CONSTANT(PARAM_ANGULAR_MOTOR_FORCE_LIMIT); + BIND_ENUM_CONSTANT(PARAM_ANGULAR_SPRING_STIFFNESS); + BIND_ENUM_CONSTANT(PARAM_ANGULAR_SPRING_DAMPING); + BIND_ENUM_CONSTANT(PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT); BIND_ENUM_CONSTANT(PARAM_MAX); BIND_ENUM_CONSTANT(FLAG_ENABLE_LINEAR_LIMIT); diff --git a/scene/3d/ray_cast_3d.cpp b/scene/3d/ray_cast_3d.cpp index a18da61656..304a5e1254 100644 --- a/scene/3d/ray_cast_3d.cpp +++ b/scene/3d/ray_cast_3d.cpp @@ -196,7 +196,7 @@ void RayCast3D::_notification(int p_what) { } void RayCast3D::_update_raycast_state() { - Ref<World3D> w3d = get_world(); + Ref<World3D> w3d = get_world_3d(); ERR_FAIL_COND(w3d.is_null()); PhysicsDirectSpaceState3D *dss = PhysicsServer3D::get_singleton()->space_get_direct_state(w3d->get_space()); diff --git a/scene/3d/soft_body_3d.cpp b/scene/3d/soft_body_3d.cpp index 6092818252..850ffab292 100644 --- a/scene/3d/soft_body_3d.cpp +++ b/scene/3d/soft_body_3d.cpp @@ -270,7 +270,7 @@ void SoftBody3D::_notification(int p_what) { add_change_receptor(this); } - RID space = get_world()->get_space(); + RID space = get_world_3d()->get_space(); PhysicsServer3D::get_singleton()->soft_body_set_space(physics_rid, space); prepare_physics_server(); } break; diff --git a/scene/3d/spring_arm_3d.cpp b/scene/3d/spring_arm_3d.cpp index 0ffde7aa8f..1410b730fd 100644 --- a/scene/3d/spring_arm_3d.cpp +++ b/scene/3d/spring_arm_3d.cpp @@ -147,7 +147,7 @@ void SpringArm3D::process_spring() { if (shape.is_null()) { motion = Vector3(cast_direction * (spring_length)); PhysicsDirectSpaceState3D::RayResult r; - bool intersected = get_world()->get_direct_space_state()->intersect_ray(get_global_transform().origin, get_global_transform().origin + motion, r, excluded_objects, mask); + bool intersected = get_world_3d()->get_direct_space_state()->intersect_ray(get_global_transform().origin, get_global_transform().origin + motion, r, excluded_objects, mask); if (intersected) { float dist = get_global_transform().origin.distance_to(r.position); dist -= margin; @@ -155,7 +155,7 @@ void SpringArm3D::process_spring() { } } else { motion = Vector3(cast_direction * spring_length); - get_world()->get_direct_space_state()->cast_motion(shape->get_rid(), get_global_transform(), motion, 0, motion_delta, motion_delta_unsafe, excluded_objects, mask); + get_world_3d()->get_direct_space_state()->cast_motion(shape->get_rid(), get_global_transform(), motion, 0, motion_delta, motion_delta_unsafe, excluded_objects, mask); } current_spring_length = spring_length * motion_delta; diff --git a/scene/3d/visibility_notifier_3d.cpp b/scene/3d/visibility_notifier_3d.cpp index 2f657fe7b1..2707a0a514 100644 --- a/scene/3d/visibility_notifier_3d.cpp +++ b/scene/3d/visibility_notifier_3d.cpp @@ -68,7 +68,7 @@ void VisibilityNotifier3D::set_aabb(const AABB &p_aabb) { aabb = p_aabb; if (is_inside_world()) { - get_world()->_update_notifier(this, get_global_transform().xform(aabb)); + get_world_3d()->_update_notifier(this, get_global_transform().xform(aabb)); } _change_notify("aabb"); @@ -85,15 +85,15 @@ void VisibilityNotifier3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_WORLD: { - get_world()->_register_notifier(this, get_global_transform().xform(aabb)); + get_world_3d()->_register_notifier(this, get_global_transform().xform(aabb)); } break; case NOTIFICATION_TRANSFORM_CHANGED: { - get_world()->_update_notifier(this, get_global_transform().xform(aabb)); + get_world_3d()->_update_notifier(this, get_global_transform().xform(aabb)); } break; case NOTIFICATION_EXIT_WORLD: { - get_world()->_remove_notifier(this); + get_world_3d()->_remove_notifier(this); } break; } } diff --git a/scene/3d/visual_instance_3d.cpp b/scene/3d/visual_instance_3d.cpp index 604bc53422..ce8672c1dd 100644 --- a/scene/3d/visual_instance_3d.cpp +++ b/scene/3d/visual_instance_3d.cpp @@ -60,8 +60,8 @@ void VisualInstance3D::_notification(int p_what) { if (skeleton) RenderingServer::get_singleton()->instance_attach_skeleton( instance, skeleton->get_skeleton() ); */ - ERR_FAIL_COND(get_world().is_null()); - RenderingServer::get_singleton()->instance_set_scenario(instance, get_world()->get_scenario()); + ERR_FAIL_COND(get_world_3d().is_null()); + RenderingServer::get_singleton()->instance_set_scenario(instance, get_world_3d()->get_scenario()); _update_visibility(); } break; diff --git a/scene/3d/world_environment.cpp b/scene/3d/world_environment.cpp index 8cf4554653..8dbb709ae4 100644 --- a/scene/3d/world_environment.cpp +++ b/scene/3d/world_environment.cpp @@ -36,50 +36,50 @@ void WorldEnvironment::_notification(int p_what) { if (p_what == Node3D::NOTIFICATION_ENTER_WORLD || p_what == Node3D::NOTIFICATION_ENTER_TREE) { if (environment.is_valid()) { - if (get_viewport()->find_world()->get_environment().is_valid()) { + if (get_viewport()->find_world_3d()->get_environment().is_valid()) { WARN_PRINT("World already has an environment (Another WorldEnvironment?), overriding."); } - get_viewport()->find_world()->set_environment(environment); - add_to_group("_world_environment_" + itos(get_viewport()->find_world()->get_scenario().get_id())); + get_viewport()->find_world_3d()->set_environment(environment); + add_to_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); } if (camera_effects.is_valid()) { - if (get_viewport()->find_world()->get_camera_effects().is_valid()) { + if (get_viewport()->find_world_3d()->get_camera_effects().is_valid()) { WARN_PRINT("World already has a camera effects (Another WorldEnvironment?), overriding."); } - get_viewport()->find_world()->set_camera_effects(camera_effects); - add_to_group("_world_camera_effects_" + itos(get_viewport()->find_world()->get_scenario().get_id())); + get_viewport()->find_world_3d()->set_camera_effects(camera_effects); + add_to_group("_world_camera_effects_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); } } else if (p_what == Node3D::NOTIFICATION_EXIT_WORLD || p_what == Node3D::NOTIFICATION_EXIT_TREE) { - if (environment.is_valid() && get_viewport()->find_world()->get_environment() == environment) { - get_viewport()->find_world()->set_environment(Ref<Environment>()); - remove_from_group("_world_environment_" + itos(get_viewport()->find_world()->get_scenario().get_id())); + if (environment.is_valid() && get_viewport()->find_world_3d()->get_environment() == environment) { + get_viewport()->find_world_3d()->set_environment(Ref<Environment>()); + remove_from_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); } - if (camera_effects.is_valid() && get_viewport()->find_world()->get_camera_effects() == camera_effects) { - get_viewport()->find_world()->set_camera_effects(Ref<CameraEffects>()); - remove_from_group("_world_camera_effects_" + itos(get_viewport()->find_world()->get_scenario().get_id())); + if (camera_effects.is_valid() && get_viewport()->find_world_3d()->get_camera_effects() == camera_effects) { + get_viewport()->find_world_3d()->set_camera_effects(Ref<CameraEffects>()); + remove_from_group("_world_camera_effects_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); } } } void WorldEnvironment::set_environment(const Ref<Environment> &p_environment) { - if (is_inside_tree() && environment.is_valid() && get_viewport()->find_world()->get_environment() == environment) { - get_viewport()->find_world()->set_environment(Ref<Environment>()); - remove_from_group("_world_environment_" + itos(get_viewport()->find_world()->get_scenario().get_id())); + if (is_inside_tree() && environment.is_valid() && get_viewport()->find_world_3d()->get_environment() == environment) { + get_viewport()->find_world_3d()->set_environment(Ref<Environment>()); + remove_from_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); //clean up } environment = p_environment; if (is_inside_tree() && environment.is_valid()) { - if (get_viewport()->find_world()->get_environment().is_valid()) { + if (get_viewport()->find_world_3d()->get_environment().is_valid()) { WARN_PRINT("World already has an environment (Another WorldEnvironment?), overriding."); } - get_viewport()->find_world()->set_environment(environment); - add_to_group("_world_environment_" + itos(get_viewport()->find_world()->get_scenario().get_id())); + get_viewport()->find_world_3d()->set_environment(environment); + add_to_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); } update_configuration_warning(); @@ -92,19 +92,19 @@ Ref<Environment> WorldEnvironment::get_environment() const { void WorldEnvironment::set_camera_effects(const Ref<CameraEffects> &p_camera_effects) { - if (is_inside_tree() && camera_effects.is_valid() && get_viewport()->find_world()->get_camera_effects() == camera_effects) { - get_viewport()->find_world()->set_camera_effects(Ref<CameraEffects>()); - remove_from_group("_world_camera_effects_" + itos(get_viewport()->find_world()->get_scenario().get_id())); + if (is_inside_tree() && camera_effects.is_valid() && get_viewport()->find_world_3d()->get_camera_effects() == camera_effects) { + get_viewport()->find_world_3d()->set_camera_effects(Ref<CameraEffects>()); + remove_from_group("_world_camera_effects_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); //clean up } camera_effects = p_camera_effects; if (is_inside_tree() && camera_effects.is_valid()) { - if (get_viewport()->find_world()->get_camera_effects().is_valid()) { + if (get_viewport()->find_world_3d()->get_camera_effects().is_valid()) { WARN_PRINT("World already has an camera_effects (Another WorldEnvironment?), overriding."); } - get_viewport()->find_world()->set_camera_effects(camera_effects); - add_to_group("_world_camera_effects_" + itos(get_viewport()->find_world()->get_scenario().get_id())); + get_viewport()->find_world_3d()->set_camera_effects(camera_effects); + add_to_group("_world_camera_effects_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); } update_configuration_warning(); @@ -125,7 +125,7 @@ String WorldEnvironment::get_configuration_warning() const { return String(); List<Node *> nodes; - get_tree()->get_nodes_in_group("_world_environment_" + itos(get_viewport()->find_world()->get_scenario().get_id()), &nodes); + get_tree()->get_nodes_in_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()), &nodes); if (nodes.size() > 1) { return TTR("Only one WorldEnvironment is allowed per scene (or set of instanced scenes)."); diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 9ef6b9864a..8228cf67bd 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -950,13 +950,13 @@ void AnimationPlayer::_animation_process(float p_delta) { play(queued.front()->get()); String new_name = playback.assigned; queued.pop_front(); - if (end_notify || playback.seeked) + if (end_notify) emit_signal(SceneStringNames::get_singleton()->animation_changed, old, new_name); } else { //stop(); playing = false; _set_process(false); - if (end_notify || playback.seeked) + if (end_notify) emit_signal(SceneStringNames::get_singleton()->animation_finished, playback.assigned); } end_reached = false; diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index bc28c38e2c..d0c6cac8cf 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -126,14 +126,17 @@ bool Tween::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; if (name == "playback/speed" || name == "speed") { // Backwards compatibility set_speed_scale(p_value); + return true; } else if (name == "playback/active") { set_active(p_value); + return true; } else if (name == "playback/repeat") { set_repeat(p_value); + return true; } - return true; + return false; } bool Tween::_get(const StringName &p_name, Variant &r_ret) const { @@ -142,14 +145,17 @@ bool Tween::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; if (name == "playback/speed") { // Backwards compatibility r_ret = speed_scale; + return true; } else if (name == "playback/active") { r_ret = is_active(); + return true; } else if (name == "playback/repeat") { r_ret = is_repeat(); + return true; } - return true; + return false; } void Tween::_get_property_list(List<PropertyInfo> *p_list) const { diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 9ee7456d26..25fc6d82c8 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1153,7 +1153,7 @@ void TextEdit::_notification(int p_what) { highlighted_text_col = _get_column_pos_of_word(highlighted_text, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0); if (select_identifiers_enabled && highlighted_word.length() != 0) { - if (_is_char(highlighted_word[0])) { + if (_is_char(highlighted_word[0]) || highlighted_word[0] == '.') { highlighted_word_col = _get_column_pos_of_word(highlighted_word, fullstr, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0); } } diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 22cd1c98ab..07cb8e3cd2 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -504,7 +504,7 @@ bool SceneTree::idle(float p_time) { String env_path = ProjectSettings::get_singleton()->get("rendering/environment/default_environment"); env_path = env_path.strip_edges(); //user may have added a space or two String cpath; - Ref<Environment> fallback = get_root()->get_world()->get_fallback_environment(); + Ref<Environment> fallback = get_root()->get_world_3d()->get_fallback_environment(); if (fallback.is_valid()) { cpath = fallback->get_path(); } @@ -519,7 +519,7 @@ bool SceneTree::idle(float p_time) { } else { fallback.unref(); } - get_root()->get_world()->set_fallback_environment(fallback); + get_root()->get_world_3d()->set_fallback_environment(fallback); } } @@ -1409,8 +1409,8 @@ SceneTree::SceneTree() { root = memnew(Window); root->set_name("root"); - if (!root->get_world().is_valid()) - root->set_world(Ref<World3D>(memnew(World3D))); + if (!root->get_world_3d().is_valid()) + root->set_world_3d(Ref<World3D>(memnew(World3D))); // Initialize network state multiplayer_poll = true; @@ -1447,7 +1447,7 @@ SceneTree::SceneTree() { if (env_path != String()) { Ref<Environment> env = ResourceLoader::load(env_path); if (env.is_valid()) { - root->get_world()->set_fallback_environment(env); + root->get_world_3d()->set_fallback_environment(env); } else { if (Engine::get_singleton()->is_editor_hint()) { //file was erased, clear the field. diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index b0718eed79..e9827d521b 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -215,7 +215,7 @@ void Viewport::update_worlds() { find_world_2d()->_update_viewport(this, xformed_rect); find_world_2d()->_update(); - find_world()->_update(get_tree()->get_frame()); + find_world_3d()->_update(get_tree()->get_frame()); } void Viewport::_collision_object_input_event(CollisionObject3D *p_object, Camera3D *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape) { @@ -422,22 +422,22 @@ void Viewport::_sub_window_remove(Window *p_window) { RenderingServer::get_singleton()->viewport_set_parent_viewport(p_window->viewport, p_window->parent ? p_window->parent->viewport : RID()); } -void Viewport::_own_world_changed() { - ERR_FAIL_COND(world.is_null()); - ERR_FAIL_COND(own_world.is_null()); +void Viewport::_own_world_3d_changed() { + ERR_FAIL_COND(world_3d.is_null()); + ERR_FAIL_COND(own_world_3d.is_null()); if (is_inside_tree()) { _propagate_exit_world(this); } - own_world = world->duplicate(); + own_world_3d = world_3d->duplicate(); if (is_inside_tree()) { _propagate_enter_world(this); } if (is_inside_tree()) { - RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); + RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world_3d()->get_scenario()); } _update_listener(); @@ -459,7 +459,7 @@ void Viewport::_notification(int p_what) { } current_canvas = find_world_2d()->get_canvas(); - RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); + RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world_3d()->get_scenario()); RenderingServer::get_singleton()->viewport_attach_canvas(viewport, current_canvas); _update_listener(); @@ -474,14 +474,14 @@ void Viewport::_notification(int p_what) { contact_2d_debug = RenderingServer::get_singleton()->canvas_item_create(); RenderingServer::get_singleton()->canvas_item_set_parent(contact_2d_debug, find_world_2d()->get_canvas()); //3D - PhysicsServer3D::get_singleton()->space_set_debug_contacts(find_world()->get_space(), get_tree()->get_collision_debug_contact_count()); + PhysicsServer3D::get_singleton()->space_set_debug_contacts(find_world_3d()->get_space(), get_tree()->get_collision_debug_contact_count()); contact_3d_debug_multimesh = RenderingServer::get_singleton()->multimesh_create(); RenderingServer::get_singleton()->multimesh_allocate(contact_3d_debug_multimesh, get_tree()->get_collision_debug_contact_count(), RS::MULTIMESH_TRANSFORM_3D, true); RenderingServer::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh, 0); RenderingServer::get_singleton()->multimesh_set_mesh(contact_3d_debug_multimesh, get_tree()->get_debug_contact_mesh()->get_rid()); contact_3d_debug_instance = RenderingServer::get_singleton()->instance_create(); RenderingServer::get_singleton()->instance_set_base(contact_3d_debug_instance, contact_3d_debug_multimesh); - RenderingServer::get_singleton()->instance_set_scenario(contact_3d_debug_instance, find_world()->get_scenario()); + RenderingServer::get_singleton()->instance_set_scenario(contact_3d_debug_instance, find_world_3d()->get_scenario()); //RenderingServer::get_singleton()->instance_geometry_set_flag(contact_3d_debug_instance, RS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS, true); } @@ -576,8 +576,8 @@ void Viewport::_notification(int p_what) { if (get_tree()->is_debugging_collisions_hint() && contact_3d_debug_multimesh.is_valid()) { - Vector<Vector3> points = PhysicsServer3D::get_singleton()->space_get_contacts(find_world()->get_space()); - int point_count = PhysicsServer3D::get_singleton()->space_get_contact_count(find_world()->get_space()); + Vector<Vector3> points = PhysicsServer3D::get_singleton()->space_get_contacts(find_world_3d()->get_space()); + int point_count = PhysicsServer3D::get_singleton()->space_get_contact_count(find_world_3d()->get_space()); RS::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh, point_count); } @@ -805,7 +805,7 @@ void Viewport::_notification(int p_what) { Vector3 from = camera->project_ray_origin(pos); Vector3 dir = camera->project_ray_normal(pos); - PhysicsDirectSpaceState3D *space = PhysicsServer3D::get_singleton()->space_get_direct_state(find_world()->get_space()); + PhysicsDirectSpaceState3D *space = PhysicsServer3D::get_singleton()->space_get_direct_state(find_world_3d()->get_space()); if (space) { bool col = space->intersect_ray(from, from + dir * 10000, result, Set<RID>(), 0xFFFFFFFF, true, true, true); @@ -1185,7 +1185,7 @@ void Viewport::set_world_2d(const Ref<World2D> &p_world_2d) { return; if (parent && parent->find_world_2d() == p_world_2d) { - WARN_PRINT("Unable to use parent world as world_2d"); + WARN_PRINT("Unable to use parent world_3d as world_2d"); return; } @@ -1197,7 +1197,7 @@ void Viewport::set_world_2d(const Ref<World2D> &p_world_2d) { if (p_world_2d.is_valid()) world_2d = p_world_2d; else { - WARN_PRINT("Invalid world"); + WARN_PRINT("Invalid world_3d"); world_2d = Ref<World2D>(memnew(World2D)); } @@ -1235,7 +1235,7 @@ void Viewport::_propagate_enter_world(Node *p_node) { Viewport *v = Object::cast_to<Viewport>(p_node); if (v) { - if (v->world.is_valid() || v->own_world.is_valid()) + if (v->world_3d.is_valid() || v->own_world_3d.is_valid()) return; } #ifndef _3D_DISABLED @@ -1275,7 +1275,7 @@ void Viewport::_propagate_exit_world(Node *p_node) { Viewport *v = Object::cast_to<Viewport>(p_node); if (v) { - if (v->world.is_valid() || v->own_world.is_valid()) + if (v->world_3d.is_valid() || v->own_world_3d.is_valid()) return; } #ifndef _3D_DISABLED @@ -1289,26 +1289,26 @@ void Viewport::_propagate_exit_world(Node *p_node) { } } -void Viewport::set_world(const Ref<World3D> &p_world) { +void Viewport::set_world_3d(const Ref<World3D> &p_world_3d) { - if (world == p_world) + if (world_3d == p_world_3d) return; if (is_inside_tree()) _propagate_exit_world(this); - if (own_world.is_valid() && world.is_valid()) { - world->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Viewport::_own_world_changed)); + if (own_world_3d.is_valid() && world_3d.is_valid()) { + world_3d->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Viewport::_own_world_3d_changed)); } - world = p_world; + world_3d = p_world_3d; - if (own_world.is_valid()) { - if (world.is_valid()) { - own_world = world->duplicate(); - world->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Viewport::_own_world_changed)); + if (own_world_3d.is_valid()) { + if (world_3d.is_valid()) { + own_world_3d = world_3d->duplicate(); + world_3d->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Viewport::_own_world_3d_changed)); } else { - own_world = Ref<World3D>(memnew(World3D)); + own_world_3d = Ref<World3D>(memnew(World3D)); } } @@ -1316,15 +1316,15 @@ void Viewport::set_world(const Ref<World3D> &p_world) { _propagate_enter_world(this); if (is_inside_tree()) { - RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); + RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world_3d()->get_scenario()); } _update_listener(); } -Ref<World3D> Viewport::get_world() const { +Ref<World3D> Viewport::get_world_3d() const { - return world; + return world_3d; } Ref<World2D> Viewport::get_world_2d() const { @@ -1332,14 +1332,14 @@ Ref<World2D> Viewport::get_world_2d() const { return world_2d; } -Ref<World3D> Viewport::find_world() const { +Ref<World3D> Viewport::find_world_3d() const { - if (own_world.is_valid()) - return own_world; - else if (world.is_valid()) - return world; + if (own_world_3d.is_valid()) + return own_world_3d; + else if (world_3d.is_valid()) + return world_3d; else if (parent) - return parent->find_world(); + return parent->find_world_3d(); else return Ref<World3D>(); } @@ -3077,25 +3077,25 @@ void Viewport::unhandled_input(const Ref<InputEvent> &p_event, bool p_local_coor } } -void Viewport::set_use_own_world(bool p_world) { +void Viewport::set_use_own_world_3d(bool p_world_3d) { - if (p_world == own_world.is_valid()) + if (p_world_3d == own_world_3d.is_valid()) return; if (is_inside_tree()) _propagate_exit_world(this); - if (!p_world) { - own_world = Ref<World3D>(); - if (world.is_valid()) { - world->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Viewport::_own_world_changed)); + if (!p_world_3d) { + own_world_3d = Ref<World3D>(); + if (world_3d.is_valid()) { + world_3d->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Viewport::_own_world_3d_changed)); } } else { - if (world.is_valid()) { - own_world = world->duplicate(); - world->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Viewport::_own_world_changed)); + if (world_3d.is_valid()) { + own_world_3d = world_3d->duplicate(); + world_3d->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Viewport::_own_world_3d_changed)); } else { - own_world = Ref<World3D>(memnew(World3D)); + own_world_3d = Ref<World3D>(memnew(World3D)); } } @@ -3103,15 +3103,15 @@ void Viewport::set_use_own_world(bool p_world) { _propagate_enter_world(this); if (is_inside_tree()) { - RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); + RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world_3d()->get_scenario()); } _update_listener(); } -bool Viewport::is_using_own_world() const { +bool Viewport::is_using_own_world_3d() const { - return own_world.is_valid(); + return own_world_3d.is_valid(); } void Viewport::set_physics_object_picking(bool p_enable) { @@ -3366,9 +3366,9 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_world_2d", "world_2d"), &Viewport::set_world_2d); ClassDB::bind_method(D_METHOD("get_world_2d"), &Viewport::get_world_2d); ClassDB::bind_method(D_METHOD("find_world_2d"), &Viewport::find_world_2d); - ClassDB::bind_method(D_METHOD("set_world", "world"), &Viewport::set_world); - ClassDB::bind_method(D_METHOD("get_world"), &Viewport::get_world); - ClassDB::bind_method(D_METHOD("find_world"), &Viewport::find_world); + ClassDB::bind_method(D_METHOD("set_world_3d", "world_3d"), &Viewport::set_world_3d); + ClassDB::bind_method(D_METHOD("get_world_3d"), &Viewport::get_world_3d); + ClassDB::bind_method(D_METHOD("find_world_3d"), &Viewport::find_world_3d); ClassDB::bind_method(D_METHOD("set_canvas_transform", "xform"), &Viewport::set_canvas_transform); ClassDB::bind_method(D_METHOD("get_canvas_transform"), &Viewport::get_canvas_transform); @@ -3404,8 +3404,8 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("update_worlds"), &Viewport::update_worlds); - ClassDB::bind_method(D_METHOD("set_use_own_world", "enable"), &Viewport::set_use_own_world); - ClassDB::bind_method(D_METHOD("is_using_own_world"), &Viewport::is_using_own_world); + ClassDB::bind_method(D_METHOD("set_use_own_world_3d", "enable"), &Viewport::set_use_own_world_3d); + ClassDB::bind_method(D_METHOD("is_using_own_world_3d"), &Viewport::is_using_own_world_3d); ClassDB::bind_method(D_METHOD("get_camera"), &Viewport::get_camera); @@ -3453,8 +3453,8 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_default_canvas_item_texture_repeat", "mode"), &Viewport::set_default_canvas_item_texture_repeat); ClassDB::bind_method(D_METHOD("get_default_canvas_item_texture_repeat"), &Viewport::get_default_canvas_item_texture_repeat); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "own_world"), "set_use_own_world", "is_using_own_world"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world", PROPERTY_HINT_RESOURCE_TYPE, "World"), "set_world", "get_world"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "own_world_3d"), "set_use_own_world_3d", "is_using_own_world_3d"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world_3d", PROPERTY_HINT_RESOURCE_TYPE, "World3D"), "set_world_3d", "get_world_3d"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world_2d", PROPERTY_HINT_RESOURCE_TYPE, "World2D", 0), "set_world_2d", "get_world_2d"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transparent_bg"), "set_transparent_background", "has_transparent_background"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "handle_input_locally"), "set_handle_input_locally", "is_handling_input_locally"); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 7e2df9fe42..7da57347fd 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -253,8 +253,8 @@ private: Map<ObjectID, uint64_t> physics_2d_mouseover; Ref<World2D> world_2d; - Ref<World3D> world; - Ref<World3D> own_world; + Ref<World3D> world_3d; + Ref<World3D> own_world_3d; Rect2i to_screen_rect; StringName input_group; @@ -430,7 +430,7 @@ private: void _gui_set_root_order_dirty(); - void _own_world_changed(); + void _own_world_3d_changed(); friend class Window; @@ -477,10 +477,10 @@ public: Rect2 get_visible_rect() const; RID get_viewport_rid() const; - void set_world(const Ref<World3D> &p_world); + void set_world_3d(const Ref<World3D> &p_world_3d); void set_world_2d(const Ref<World2D> &p_world_2d); - Ref<World3D> get_world() const; - Ref<World3D> find_world() const; + Ref<World3D> get_world_3d() const; + Ref<World3D> find_world_3d() const; Ref<World2D> get_world_2d() const; Ref<World2D> find_world_2d() const; @@ -519,8 +519,8 @@ public: Vector2 get_camera_coords(const Vector2 &p_viewport_coords) const; Vector2 get_camera_rect_size() const; - void set_use_own_world(bool p_world); - bool is_using_own_world() const; + void set_use_own_world_3d(bool p_world_3d); + bool is_using_own_world_3d() const; void input_text(const String &p_text); void input(const Ref<InputEvent> &p_event, bool p_local_coords = false); diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index 310a7ef4e4..3b245f908a 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -1630,9 +1630,11 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = { { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "light_vec", "vec3(LIGHT_VEC, 0.0)" }, { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "light_height", "LIGHT_HEIGHT" }, { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "light_color", "LIGHT_COLOR.rgb" }, - { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "light_alpha", "LIGHT_COLOR.a" }, + { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "light_alpha", "LIGHT_COLOR.a" }, { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "light_uv", "vec3(LIGHT_UV, 0.0)" }, { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "shadow_color", "SHADOW_COLOR.rgb" }, + { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "shadow_alpha", "SHADOW_COLOR.a" }, + { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "shadow_vec", "vec3(SHADOW_VEC, 0.0)" }, { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "screen_uv", "vec3(SCREEN_UV, 0.0)" }, { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "texture_pixel_size", "vec3(TEXTURE_PIXEL_SIZE, 1.0)" }, { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "point_coord", "vec3(POINT_COORD, 0.0)" }, @@ -2156,12 +2158,43 @@ String VisualShaderNodeUniform::get_uniform_name() const { return uniform_name; } +void VisualShaderNodeUniform::set_qualifier(VisualShaderNodeUniform::Qualifier p_qual) { + qualifier = p_qual; + emit_changed(); +} + +VisualShaderNodeUniform::Qualifier VisualShaderNodeUniform::get_qualifier() const { + return qualifier; +} + void VisualShaderNodeUniform::_bind_methods() { ClassDB::bind_method(D_METHOD("set_uniform_name", "name"), &VisualShaderNodeUniform::set_uniform_name); ClassDB::bind_method(D_METHOD("get_uniform_name"), &VisualShaderNodeUniform::get_uniform_name); + ClassDB::bind_method(D_METHOD("set_qualifier", "qualifier"), &VisualShaderNodeUniform::set_qualifier); + ClassDB::bind_method(D_METHOD("get_qualifier"), &VisualShaderNodeUniform::get_qualifier); + ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "uniform_name"), "set_uniform_name", "get_uniform_name"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "qualifier", PROPERTY_HINT_ENUM, "None,Global,Instance"), "set_qualifier", "get_qualifier"); + + BIND_ENUM_CONSTANT(QUAL_NONE); + BIND_ENUM_CONSTANT(QUAL_GLOBAL); + BIND_ENUM_CONSTANT(QUAL_INSTANCE); +} + +String VisualShaderNodeUniform::_get_qual_str() const { + if (is_qualifier_supported(qualifier)) { + switch (qualifier) { + case QUAL_NONE: + break; + case QUAL_GLOBAL: + return "global "; + case QUAL_INSTANCE: + return "instance "; + } + } + return String(); } String VisualShaderNodeUniform::get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const { @@ -2171,11 +2204,21 @@ String VisualShaderNodeUniform::get_warning(Shader::Mode p_mode, VisualShader::T if (keyword_list.find(uniform_name)) { return TTR("Uniform name cannot be equal to a shader keyword. Choose another name."); } + if (!is_qualifier_supported(qualifier)) { + return "This uniform type does not support that qualifier."; + } return String(); } +Vector<StringName> VisualShaderNodeUniform::get_editable_properties() const { + Vector<StringName> props; + props.push_back("qualifier"); + return props; +} + VisualShaderNodeUniform::VisualShaderNodeUniform() { + qualifier = QUAL_NONE; } ////////////// GroupBase diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h index ecf3f93fbb..56f8e74d2b 100644 --- a/scene/resources/visual_shader.h +++ b/scene/resources/visual_shader.h @@ -369,21 +369,38 @@ public: class VisualShaderNodeUniform : public VisualShaderNode { GDCLASS(VisualShaderNodeUniform, VisualShaderNode); +public: + enum Qualifier { + QUAL_NONE, + QUAL_GLOBAL, + QUAL_INSTANCE, + }; + private: String uniform_name; + Qualifier qualifier; protected: static void _bind_methods(); + String _get_qual_str() const; public: void set_uniform_name(const String &p_name); String get_uniform_name() const; + void set_qualifier(Qualifier p_qual); + Qualifier get_qualifier() const; + + virtual bool is_qualifier_supported(Qualifier p_qual) const = 0; + + virtual Vector<StringName> get_editable_properties() const; virtual String get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const; VisualShaderNodeUniform(); }; +VARIANT_ENUM_CAST(VisualShaderNodeUniform::Qualifier) + class VisualShaderNodeGroupBase : public VisualShaderNode { GDCLASS(VisualShaderNodeGroupBase, VisualShaderNode); diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp index 2064ca10f3..7b9953a90f 100644 --- a/scene/resources/visual_shader_nodes.cpp +++ b/scene/resources/visual_shader_nodes.cpp @@ -3283,11 +3283,11 @@ String VisualShaderNodeFloatUniform::get_output_port_name(int p_port) const { String VisualShaderNodeFloatUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { if (hint == HINT_RANGE) { - return "uniform float " + get_uniform_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ");\n"; + return _get_qual_str() + "uniform float " + get_uniform_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ");\n"; } else if (hint == HINT_RANGE_STEP) { - return "uniform float " + get_uniform_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ", " + rtos(hint_range_step) + ");\n"; + return _get_qual_str() + "uniform float " + get_uniform_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ", " + rtos(hint_range_step) + ");\n"; } - return "uniform float " + get_uniform_name() + ";\n"; + return _get_qual_str() + "uniform float " + get_uniform_name() + ";\n"; } String VisualShaderNodeFloatUniform::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { @@ -3353,8 +3353,12 @@ void VisualShaderNodeFloatUniform::_bind_methods() { BIND_ENUM_CONSTANT(HINT_RANGE_STEP); } +bool VisualShaderNodeFloatUniform::is_qualifier_supported(Qualifier p_qual) const { + return true; // all qualifiers are supported +} + Vector<StringName> VisualShaderNodeFloatUniform::get_editable_properties() const { - Vector<StringName> props; + Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties(); props.push_back("hint"); if (hint == HINT_RANGE || hint == HINT_RANGE_STEP) { props.push_back("min"); @@ -3405,11 +3409,11 @@ String VisualShaderNodeIntUniform::get_output_port_name(int p_port) const { String VisualShaderNodeIntUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { if (hint == HINT_RANGE) { - return "uniform int " + get_uniform_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ");\n"; + return _get_qual_str() + "uniform int " + get_uniform_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ");\n"; } else if (hint == HINT_RANGE_STEP) { - return "uniform int " + get_uniform_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ", " + rtos(hint_range_step) + ");\n"; + return _get_qual_str() + "uniform int " + get_uniform_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ", " + rtos(hint_range_step) + ");\n"; } - return "uniform int " + get_uniform_name() + ";\n"; + return _get_qual_str() + "uniform int " + get_uniform_name() + ";\n"; } String VisualShaderNodeIntUniform::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { @@ -3475,8 +3479,12 @@ void VisualShaderNodeIntUniform::_bind_methods() { BIND_ENUM_CONSTANT(HINT_RANGE_STEP); } +bool VisualShaderNodeIntUniform::is_qualifier_supported(Qualifier p_qual) const { + return true; // all qualifiers are supported +} + Vector<StringName> VisualShaderNodeIntUniform::get_editable_properties() const { - Vector<StringName> props; + Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties(); props.push_back("hint"); if (hint == HINT_RANGE || hint == HINT_RANGE_STEP) { props.push_back("min"); @@ -3526,13 +3534,17 @@ String VisualShaderNodeBooleanUniform::get_output_port_name(int p_port) const { } String VisualShaderNodeBooleanUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { - return "uniform bool " + get_uniform_name() + ";\n"; + return _get_qual_str() + "uniform bool " + get_uniform_name() + ";\n"; } String VisualShaderNodeBooleanUniform::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; } +bool VisualShaderNodeBooleanUniform::is_qualifier_supported(Qualifier p_qual) const { + return true; // all qualifiers are supported +} + VisualShaderNodeBooleanUniform::VisualShaderNodeBooleanUniform() { } @@ -3568,7 +3580,7 @@ String VisualShaderNodeColorUniform::get_output_port_name(int p_port) const { String VisualShaderNodeColorUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { - return "uniform vec4 " + get_uniform_name() + " : hint_color;\n"; + return _get_qual_str() + "uniform vec4 " + get_uniform_name() + " : hint_color;\n"; } String VisualShaderNodeColorUniform::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { @@ -3577,6 +3589,10 @@ String VisualShaderNodeColorUniform::generate_code(Shader::Mode p_mode, VisualSh return code; } +bool VisualShaderNodeColorUniform::is_qualifier_supported(Qualifier p_qual) const { + return true; // all qualifiers are supported +} + VisualShaderNodeColorUniform::VisualShaderNodeColorUniform() { } @@ -3611,13 +3627,17 @@ String VisualShaderNodeVec3Uniform::get_output_port_name(int p_port) const { } String VisualShaderNodeVec3Uniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { - return "uniform vec3 " + get_uniform_name() + ";\n"; + return _get_qual_str() + "uniform vec3 " + get_uniform_name() + ";\n"; } String VisualShaderNodeVec3Uniform::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; } +bool VisualShaderNodeVec3Uniform::is_qualifier_supported(Qualifier p_qual) const { + return true; // all qualifiers are supported +} + VisualShaderNodeVec3Uniform::VisualShaderNodeVec3Uniform() { } @@ -3652,13 +3672,17 @@ String VisualShaderNodeTransformUniform::get_output_port_name(int p_port) const } String VisualShaderNodeTransformUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { - return "uniform mat4 " + get_uniform_name() + ";\n"; + return _get_qual_str() + "uniform mat4 " + get_uniform_name() + ";\n"; } String VisualShaderNodeTransformUniform::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; } +bool VisualShaderNodeTransformUniform::is_qualifier_supported(Qualifier p_qual) const { + return true; // all qualifiers are supported +} + VisualShaderNodeTransformUniform::VisualShaderNodeTransformUniform() { } @@ -3713,7 +3737,7 @@ String VisualShaderNodeTextureUniform::get_output_port_name(int p_port) const { } String VisualShaderNodeTextureUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { - String code = "uniform sampler2D " + get_uniform_name(); + String code = _get_qual_str() + "uniform sampler2D " + get_uniform_name(); switch (texture_type) { case TYPE_DATA: @@ -3778,7 +3802,7 @@ VisualShaderNodeTextureUniform::ColorDefault VisualShaderNodeTextureUniform::get } Vector<StringName> VisualShaderNodeTextureUniform::get_editable_properties() const { - Vector<StringName> props; + Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties(); props.push_back("texture_type"); props.push_back("color_default"); return props; @@ -3810,6 +3834,18 @@ String VisualShaderNodeTextureUniform::get_input_port_default_hint(int p_port) c return ""; } +bool VisualShaderNodeTextureUniform::is_qualifier_supported(Qualifier p_qual) const { + switch (p_qual) { + case Qualifier::QUAL_NONE: + return true; + case Qualifier::QUAL_GLOBAL: + return true; + case Qualifier::QUAL_INSTANCE: + return false; + } + return false; +} + VisualShaderNodeTextureUniform::VisualShaderNodeTextureUniform() { texture_type = TYPE_DATA; color_default = COLOR_DEFAULT_WHITE; @@ -3952,7 +3988,7 @@ String VisualShaderNodeCubemapUniform::get_input_port_default_hint(int p_port) c } String VisualShaderNodeCubemapUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { - String code = "uniform samplerCube " + get_uniform_name(); + String code = _get_qual_str() + "uniform samplerCube " + get_uniform_name(); switch (texture_type) { case TYPE_DATA: diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h index 035e39230c..69f42f621a 100644 --- a/scene/resources/visual_shader_nodes.h +++ b/scene/resources/visual_shader_nodes.h @@ -1457,6 +1457,8 @@ public: void set_step(float p_value); float get_step() const; + bool is_qualifier_supported(Qualifier p_qual) const; + virtual Vector<StringName> get_editable_properties() const; VisualShaderNodeFloatUniform(); @@ -1509,6 +1511,8 @@ public: void set_step(int p_value); int get_step() const; + bool is_qualifier_supported(Qualifier p_qual) const; + virtual Vector<StringName> get_editable_properties() const; VisualShaderNodeIntUniform(); @@ -1535,6 +1539,8 @@ public: virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const; virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty + bool is_qualifier_supported(Qualifier p_qual) const; + VisualShaderNodeBooleanUniform(); }; @@ -1557,6 +1563,8 @@ public: virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const; virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty + bool is_qualifier_supported(Qualifier p_qual) const; + VisualShaderNodeColorUniform(); }; @@ -1579,6 +1587,8 @@ public: virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const; virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty + bool is_qualifier_supported(Qualifier p_qual) const; + VisualShaderNodeVec3Uniform(); }; @@ -1601,6 +1611,8 @@ public: virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const; virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty + bool is_qualifier_supported(Qualifier p_qual) const; + VisualShaderNodeTransformUniform(); }; @@ -1652,6 +1664,8 @@ public: void set_color_default(ColorDefault p_default); ColorDefault get_color_default() const; + bool is_qualifier_supported(Qualifier p_qual) const; + VisualShaderNodeTextureUniform(); }; |