diff options
41 files changed, 166 insertions, 141 deletions
diff --git a/doc/classes/PhysicsServer2D.xml b/doc/classes/PhysicsServer2D.xml index 387d79d210..1df2fd0158 100644 --- a/doc/classes/PhysicsServer2D.xml +++ b/doc/classes/PhysicsServer2D.xml @@ -716,11 +716,6 @@ Sets a joint parameter. See [enum JointParam] for a list of available parameters. </description> </method> - <method name="line_shape_create"> - <return type="RID" /> - <description> - </description> - </method> <method name="rectangle_shape_create"> <return type="RID" /> <description> @@ -812,6 +807,11 @@ Sets the value for a space parameter. See [enum SpaceParameter] for a list of available parameters. </description> </method> + <method name="world_margin_shape_create"> + <return type="RID" /> + <description> + </description> + </method> </methods> <constants> <constant name="SPACE_PARAM_CONTACT_RECYCLE_RADIUS" value="0" enum="SpaceParameter"> @@ -837,11 +837,11 @@ </constant> <constant name="SPACE_PARAM_TEST_MOTION_MIN_CONTACT_DEPTH" value="7" enum="SpaceParameter"> </constant> - <constant name="SHAPE_LINE" value="0" enum="ShapeType"> - This is the constant for creating line shapes. A line shape is an infinite line with an origin point, and a normal. Thus, it can be used for front/behind checks. + <constant name="SHAPE_WORLD_MARGIN" value="0" enum="ShapeType"> + This is the constant for creating world margin shapes. A world margin shape is an [i]infinite[/i] line with an origin point, and a normal. Thus, it can be used for front/behind checks. </constant> <constant name="SHAPE_SEGMENT" value="1" enum="ShapeType"> - This is the constant for creating segment shapes. A segment shape is a line from a point A to a point B. It can be checked for intersections. + This is the constant for creating segment shapes. A segment shape is a [i]finite[/i] line from a point A to a point B. It can be checked for intersections. </constant> <constant name="SHAPE_CIRCLE" value="2" enum="ShapeType"> This is the constant for creating circle shapes. A circle shape only has a radius. It can be used for intersections and inside/outside checks. diff --git a/doc/classes/LineShape2D.xml b/doc/classes/WorldMarginShape2D.xml index 434e6fba8e..1839ab16ad 100644 --- a/doc/classes/LineShape2D.xml +++ b/doc/classes/WorldMarginShape2D.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="LineShape2D" inherits="Shape2D" version="4.0"> +<class name="WorldMarginShape2D" inherits="Shape2D" version="4.0"> <brief_description> Line shape for 2D collisions. </brief_description> diff --git a/editor/icons/LineShape2D.svg b/editor/icons/WorldMarginShape2D.svg index f1dbe97c6f..f1dbe97c6f 100644 --- a/editor/icons/LineShape2D.svg +++ b/editor/icons/WorldMarginShape2D.svg diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index df01ecd1be..ef3b0588b8 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -261,7 +261,7 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) Transform2D xform = canvas_item_editor->get_canvas_transform() * _get_node()->get_global_transform(); Vector2 gpoint = mb->get_position(); - Vector2 cpoint = _get_node()->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mb->get_position()))); + Vector2 cpoint = _get_node()->to_local(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mb->get_position()))); if (mode == MODE_EDIT || (_is_line() && mode == MODE_CREATE)) { if (mb->get_button_index() == MOUSE_BUTTON_LEFT) { @@ -396,7 +396,7 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) Vector2 gpoint = mm->get_position(); if (edited_point.valid() && (wip_active || (mm->get_button_mask() & MOUSE_BUTTON_MASK_LEFT))) { - Vector2 cpoint = _get_node()->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint))); + Vector2 cpoint = _get_node()->to_local(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint))); //Move the point in a single axis. Should only work when editing a polygon and while holding shift. if (mode == MODE_EDIT && mm->is_shift_pressed()) { diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp index 4266e0f676..486f947e43 100644 --- a/editor/plugins/collision_shape_2d_editor_plugin.cpp +++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp @@ -36,9 +36,9 @@ #include "scene/resources/circle_shape_2d.h" #include "scene/resources/concave_polygon_shape_2d.h" #include "scene/resources/convex_polygon_shape_2d.h" -#include "scene/resources/line_shape_2d.h" #include "scene/resources/rectangle_shape_2d.h" #include "scene/resources/segment_shape_2d.h" +#include "scene/resources/world_margin_shape_2d.h" void CollisionShape2DEditor::_node_removed(Node *p_node) { if (p_node == node) { @@ -74,8 +74,8 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const { case CONVEX_POLYGON_SHAPE: { } break; - case LINE_SHAPE: { - Ref<LineShape2D> line = node->get_shape(); + case WORLD_MARGIN_SHAPE: { + Ref<WorldMarginShape2D> line = node->get_shape(); if (idx == 0) { return line->get_distance(); @@ -142,9 +142,9 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) { case CONVEX_POLYGON_SHAPE: { } break; - case LINE_SHAPE: { + case WORLD_MARGIN_SHAPE: { if (idx < 2) { - Ref<LineShape2D> line = node->get_shape(); + Ref<WorldMarginShape2D> line = node->get_shape(); if (idx == 0) { line->set_distance(p_point.length()); @@ -241,8 +241,8 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { // Cannot be edited directly, use CollisionPolygon2D instead. } break; - case LINE_SHAPE: { - Ref<LineShape2D> line = node->get_shape(); + case WORLD_MARGIN_SHAPE: { + Ref<WorldMarginShape2D> line = node->get_shape(); if (idx == 0) { undo_redo->add_do_method(line.ptr(), "set_distance", line->get_distance()); @@ -397,8 +397,8 @@ void CollisionShape2DEditor::_get_current_shape_type() { shape_type = CONCAVE_POLYGON_SHAPE; } else if (Object::cast_to<ConvexPolygonShape2D>(*s)) { shape_type = CONVEX_POLYGON_SHAPE; - } else if (Object::cast_to<LineShape2D>(*s)) { - shape_type = LINE_SHAPE; + } else if (Object::cast_to<WorldMarginShape2D>(*s)) { + shape_type = WORLD_MARGIN_SHAPE; } else if (Object::cast_to<RectangleShape2D>(*s)) { shape_type = RECTANGLE_SHAPE; } else if (Object::cast_to<SegmentShape2D>(*s)) { @@ -464,8 +464,8 @@ void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overla case CONVEX_POLYGON_SHAPE: { } break; - case LINE_SHAPE: { - Ref<LineShape2D> shape = node->get_shape(); + case WORLD_MARGIN_SHAPE: { + Ref<WorldMarginShape2D> shape = node->get_shape(); handles.resize(2); handles.write[0] = shape->get_normal() * shape->get_distance(); diff --git a/editor/plugins/collision_shape_2d_editor_plugin.h b/editor/plugins/collision_shape_2d_editor_plugin.h index 130ec708cf..056e1b5b7d 100644 --- a/editor/plugins/collision_shape_2d_editor_plugin.h +++ b/editor/plugins/collision_shape_2d_editor_plugin.h @@ -46,7 +46,7 @@ class CollisionShape2DEditor : public Control { CIRCLE_SHAPE, CONCAVE_POLYGON_SHAPE, CONVEX_POLYGON_SHAPE, - LINE_SHAPE, + WORLD_MARGIN_SHAPE, RECTANGLE_SHAPE, SEGMENT_SHAPE }; diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index 8866e8c53e..584eb84ecd 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -77,7 +77,7 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = mb->get_position(); - Vector2 cpoint = node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mb->get_position()))); + Vector2 cpoint = node->to_local(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mb->get_position()))); if (mb->is_pressed() && action == ACTION_NONE) { Ref<Curve2D> curve = node->get_curve(); diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index ac75d81272..13b37aa2b2 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -96,7 +96,7 @@ Transform2D Camera2D::get_camera_transform() { Size2 screen_size = _get_camera_screen_size(); - Point2 new_camera_pos = get_global_transform().get_origin(); + Point2 new_camera_pos = get_global_position(); Point2 ret_camera_pos; if (!first) { @@ -169,7 +169,7 @@ Transform2D Camera2D::get_camera_transform() { Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom) : Point2()); - real_t angle = get_global_transform().get_rotation(); + real_t angle = get_global_rotation(); if (rotating) { screen_offset = screen_offset.rotated(angle); } @@ -305,8 +305,8 @@ void Camera2D::_notification(int p_what) { limit_drawing_width = 3; } - Vector2 camera_origin = get_global_transform().get_origin(); - Vector2 camera_scale = get_global_transform().get_scale().abs(); + Vector2 camera_origin = get_global_position(); + Vector2 camera_scale = get_global_scale().abs(); Vector2 limit_points[4] = { (Vector2(limit[SIDE_LEFT], limit[SIDE_TOP]) - camera_origin) / camera_scale, (Vector2(limit[SIDE_RIGHT], limit[SIDE_TOP]) - camera_origin) / camera_scale, @@ -489,7 +489,7 @@ void Camera2D::align() { Size2 screen_size = _get_camera_screen_size(); - Point2 current_camera_pos = get_global_transform().get_origin(); + Point2 current_camera_pos = get_global_position(); if (anchor_mode == ANCHOR_MODE_DRAG_CENTER) { if (drag_horizontal_offset < 0) { camera_pos.x = current_camera_pos.x + screen_size.x * 0.5 * drag_margin[SIDE_RIGHT] * drag_horizontal_offset; diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp index eabbf313d0..4a6606256e 100644 --- a/scene/2d/joints_2d.cpp +++ b/scene/2d/joints_2d.cpp @@ -252,7 +252,7 @@ void PinJoint2D::_notification(int p_what) { } void PinJoint2D::_configure_joint(RID p_joint, PhysicsBody2D *body_a, PhysicsBody2D *body_b) { - PhysicsServer2D::get_singleton()->joint_make_pin(p_joint, get_global_transform().get_origin(), body_a->get_rid(), body_b ? body_b->get_rid() : RID()); + PhysicsServer2D::get_singleton()->joint_make_pin(p_joint, get_global_position(), body_a->get_rid(), body_b ? body_b->get_rid() : RID()); PhysicsServer2D::get_singleton()->pin_joint_set_param(p_joint, PhysicsServer2D::PIN_JOINT_SOFTNESS, softness); } diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp index 927f6c1c42..2f00978123 100644 --- a/scene/2d/navigation_agent_2d.cpp +++ b/scene/2d/navigation_agent_2d.cpp @@ -102,7 +102,7 @@ void NavigationAgent2D::_notification(int p_what) { } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { if (agent_parent) { - NavigationServer2D::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().get_origin()); + NavigationServer2D::get_singleton()->agent_set_position(agent, agent_parent->get_global_position()); _check_distance_to_target(); } } break; @@ -185,7 +185,7 @@ Vector2 NavigationAgent2D::get_next_location() { update_navigation(); if (navigation_path.size() == 0) { ERR_FAIL_COND_V(agent_parent == nullptr, Vector2()); - return agent_parent->get_global_transform().get_origin(); + return agent_parent->get_global_position(); } else { return navigation_path[nav_path_index]; } @@ -193,7 +193,7 @@ Vector2 NavigationAgent2D::get_next_location() { real_t NavigationAgent2D::distance_to_target() const { ERR_FAIL_COND_V(agent_parent == nullptr, 0.0); - return agent_parent->get_global_transform().get_origin().distance_to(target_location); + return agent_parent->get_global_position().distance_to(target_location); } bool NavigationAgent2D::is_target_reached() const { @@ -260,7 +260,7 @@ void NavigationAgent2D::update_navigation() { update_frame_id = Engine::get_singleton()->get_physics_frames(); - Vector2 o = agent_parent->get_global_transform().get_origin(); + Vector2 o = agent_parent->get_global_position(); bool reload_path = false; diff --git a/scene/2d/navigation_obstacle_2d.cpp b/scene/2d/navigation_obstacle_2d.cpp index c99b9777cd..0a105826c0 100644 --- a/scene/2d/navigation_obstacle_2d.cpp +++ b/scene/2d/navigation_obstacle_2d.cpp @@ -53,7 +53,7 @@ void NavigationObstacle2D::_notification(int p_what) { } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { if (parent_node2d) { - NavigationServer2D::get_singleton()->agent_set_position(agent, parent_node2d->get_global_transform().get_origin()); + NavigationServer2D::get_singleton()->agent_set_position(agent, parent_node2d->get_global_position()); } } break; } @@ -92,13 +92,13 @@ void NavigationObstacle2D::update_agent_shape() { // and add the enclosing shape radius r += cs->get_shape()->get_enclosing_radius(); } - Size2 s = cs->get_global_transform().get_scale(); + Size2 s = cs->get_global_scale(); r *= MAX(s.x, s.y); // Takes the biggest radius radius = MAX(radius, r); } } - Vector2 s = parent_node2d->get_global_transform().get_scale(); + Vector2 s = parent_node2d->get_global_scale(); radius *= MAX(s.x, s.y); if (radius == 0.0) { diff --git a/scene/2d/skeleton_2d.cpp b/scene/2d/skeleton_2d.cpp index 3d44c629d3..4bbbc3575d 100644 --- a/scene/2d/skeleton_2d.cpp +++ b/scene/2d/skeleton_2d.cpp @@ -325,7 +325,7 @@ bool Bone2D::_editor_get_bone_shape(Vector<Vector2> *p_shape, Vector<Vector2> *p Vector2 rel; if (p_other_bone) { - rel = (p_other_bone->get_global_transform().get_origin() - get_global_transform().get_origin()); + rel = (p_other_bone->get_global_position() - get_global_position()); rel = rel.rotated(-get_global_rotation()); // Undo Bone2D node's rotation so its drawn correctly regardless of the node's rotation } else { real_t angle_to_use = get_rotation() + bone_angle; @@ -454,7 +454,7 @@ void Bone2D::calculate_length_and_rotation() { for (int i = 0; i < child_count; i++) { Bone2D *child = Object::cast_to<Bone2D>(get_child(i)); if (child) { - Vector2 child_local_pos = to_local(child->get_global_transform().get_origin()); + Vector2 child_local_pos = to_local(child->get_global_position()); length = child_local_pos.length(); bone_angle = Math::atan2(child_local_pos.normalized().y, child_local_pos.normalized().x); calculated = true; diff --git a/scene/3d/SCsub b/scene/3d/SCsub index 40bdaee47d..fc61250247 100644 --- a/scene/3d/SCsub +++ b/scene/3d/SCsub @@ -2,7 +2,4 @@ Import("env") -if env["disable_3d"]: - env.add_source_files(env.scene_sources, "node_3d.cpp") -else: - env.add_source_files(env.scene_sources, "*.cpp") +env.add_source_files(env.scene_sources, "*.cpp") diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 711e7fbd5a..d2424c9a3b 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -428,7 +428,7 @@ void AudioStreamPlayer3D::_notification(int p_what) { if (area && area->is_using_reverb_bus() && area->get_reverb_uniformity() > 0) { area_sound_pos = space_state->get_closest_point_to_object_volume(area->get_rid(), listener_node->get_global_transform().origin); - listener_area_pos = listener_node->get_global_transform().affine_inverse().xform(area_sound_pos); + listener_area_pos = listener_node->to_local(area_sound_pos); } if (max_distance > 0) { diff --git a/scene/3d/physics_joint_3d.cpp b/scene/3d/physics_joint_3d.cpp index 59440bd1a8..12938946a0 100644 --- a/scene/3d/physics_joint_3d.cpp +++ b/scene/3d/physics_joint_3d.cpp @@ -259,11 +259,11 @@ real_t PinJoint3D::get_param(Param p_param) const { void PinJoint3D::_configure_joint(RID p_joint, PhysicsBody3D *body_a, PhysicsBody3D *body_b) { Vector3 pinpos = get_global_transform().origin; - Vector3 local_a = body_a->get_global_transform().affine_inverse().xform(pinpos); + Vector3 local_a = body_a->to_local(pinpos); Vector3 local_b; if (body_b) { - local_b = body_b->get_global_transform().affine_inverse().xform(pinpos); + local_b = body_b->to_local(pinpos); } else { local_b = pinpos; } diff --git a/scene/SCsub b/scene/SCsub index ccd2bab8ff..92288211bb 100644 --- a/scene/SCsub +++ b/scene/SCsub @@ -10,7 +10,8 @@ env.add_source_files(env.scene_sources, "*.cpp") # Chain load SCsubs SConscript("main/SCsub") SConscript("gui/SCsub") -SConscript("3d/SCsub") +if not env["disable_3d"]: + SConscript("3d/SCsub") SConscript("2d/SCsub") SConscript("animation/SCsub") SConscript("audio/SCsub") diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index 869f2f68f7..df1aece80a 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -90,7 +90,7 @@ Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Arra ERR_FAIL_COND_V(p_args.size() < 1, ERR_INVALID_DATA); Transform2D transform = p_args[1]; scene_tree->get_root()->set_canvas_transform_override(transform); - +#ifndef _3D_DISABLED } else if (p_msg == "override_camera_3D:set") { ERR_FAIL_COND_V(p_args.size() < 1, ERR_INVALID_DATA); bool enable = p_args[0]; @@ -109,7 +109,7 @@ Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Arra scene_tree->get_root()->set_camera_3d_override_orthogonal(size_or_fov, near, far); } scene_tree->get_root()->set_camera_3d_override_transform(transform); - +#endif // _3D_DISABLED } else if (p_msg == "set_object_property") { ERR_FAIL_COND_V(p_args.size() < 3, ERR_INVALID_DATA); _set_object_property(p_args[0], p_args[1], p_args[2]); diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index a76b6c91ee..5b707498a7 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -499,7 +499,7 @@ bool SceneTree::process(double p_time) { _call_idle_callbacks(); #ifdef TOOLS_ENABLED - +#ifndef _3D_DISABLED if (Engine::get_singleton()->is_editor_hint()) { //simple hack to reload fallback environment if it changed from editor String env_path = ProjectSettings::get_singleton()->get(SNAME("rendering/environment/defaults/default_environment")); @@ -522,8 +522,8 @@ bool SceneTree::process(double p_time) { get_root()->get_world_3d()->set_fallback_environment(fallback); } } - -#endif +#endif // _3D_DISABLED +#endif // TOOLS_ENABLED return _quit; } @@ -1333,15 +1333,16 @@ SceneTree::SceneTree() { root = memnew(Window); root->set_name("root"); +#ifndef _3D_DISABLED if (!root->get_world_3d().is_valid()) { root->set_world_3d(Ref<World3D>(memnew(World3D))); } + root->set_as_audio_listener_3d(true); +#endif // _3D_DISABLED // Initialize network state. set_multiplayer(Ref<MultiplayerAPI>(memnew(MultiplayerAPI))); - //root->set_world_2d( Ref<World2D>( memnew( World2D ))); - root->set_as_audio_listener_3d(true); root->set_as_audio_listener_2d(true); current_scene = nullptr; @@ -1397,6 +1398,7 @@ SceneTree::SceneTree() { ProjectSettings::get_singleton()->set_custom_property_info("rendering/2d/sdf/oversize", PropertyInfo(Variant::INT, "rendering/2d/sdf/oversize", PROPERTY_HINT_ENUM, "100%,120%,150%,200%")); ProjectSettings::get_singleton()->set_custom_property_info("rendering/2d/sdf/scale", PropertyInfo(Variant::INT, "rendering/2d/sdf/scale", PROPERTY_HINT_ENUM, "100%,50%,25%")); +#ifndef _3D_DISABLED { // Load default fallback environment. // Get possible extensions. List<String> exts; @@ -1428,6 +1430,7 @@ SceneTree::SceneTree() { } } } +#endif // _3D_DISABLED root->set_physics_object_picking(GLOBAL_DEF("physics/common/enable_object_picking", true)); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index b85f1cc0b8..78fa0985a9 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -36,10 +36,12 @@ #include "core/templates/pair.h" #include "scene/2d/camera_2d.h" #include "scene/2d/collision_object_2d.h" +#ifndef _3D_DISABLED #include "scene/3d/camera_3d.h" #include "scene/3d/collision_object_3d.h" #include "scene/3d/listener_3d.h" #include "scene/3d/world_environment.h" +#endif // _3D_DISABLED #include "scene/gui/control.h" #include "scene/gui/label.h" #include "scene/gui/popup.h" @@ -377,14 +379,17 @@ void Viewport::_notification(int p_what) { current_canvas = find_world_2d()->get_canvas(); RenderingServer::get_singleton()->viewport_attach_canvas(viewport, current_canvas); _update_listener_2d(); +#ifndef _3D_DISABLED RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world_3d()->get_scenario()); _update_listener_3d(); +#endif // _3D_DISABLED add_to_group("_viewports"); if (get_tree()->is_debugging_collisions_hint()) { PhysicsServer2D::get_singleton()->space_set_debug_contacts(find_world_2d()->get_space(), get_tree()->get_collision_debug_contact_count()); contact_2d_debug = RenderingServer::get_singleton()->canvas_item_create(); RenderingServer::get_singleton()->canvas_item_set_parent(contact_2d_debug, find_world_2d()->get_canvas()); +#ifndef _3D_DISABLED 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_data(contact_3d_debug_multimesh, get_tree()->get_collision_debug_contact_count(), RS::MULTIMESH_TRANSFORM_3D, true); @@ -394,10 +399,12 @@ void Viewport::_notification(int p_what) { 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_3d()->get_scenario()); //RenderingServer::get_singleton()->instance_geometry_set_flag(contact_3d_debug_instance, RS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS, true); +#endif // _3D_DISABLED } } break; case NOTIFICATION_READY: { +#ifndef _3D_DISABLED if (listener_3d_set.size() && !listener_3d) { Listener3D *first = nullptr; for (Set<Listener3D *>::Element *E = listener_3d_set.front(); E; E = E->next()) { @@ -424,7 +431,7 @@ void Viewport::_notification(int p_what) { first->make_current(); } } - +#endif // _3D_DISABLED } break; case NOTIFICATION_EXIT_TREE: { _gui_cancel_tooltip(); @@ -462,6 +469,7 @@ void Viewport::_notification(int p_what) { RenderingServer::get_singleton()->canvas_item_add_rect(contact_2d_debug, Rect2(points[i] - Vector2(2, 2), Vector2(5, 5)), ccol); } } +#ifndef _3D_DISABLED if (get_tree()->is_debugging_collisions_hint() && contact_3d_debug_multimesh.is_valid()) { 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()); @@ -474,6 +482,7 @@ void Viewport::_notification(int p_what) { RS::get_singleton()->multimesh_instance_set_transform(contact_3d_debug_multimesh, i, point_transform); } } +#endif // _3D_DISABLED } break; case NOTIFICATION_WM_MOUSE_EXIT: { _drop_physics_mouseover(); @@ -506,10 +515,6 @@ void Viewport::_process_picking() { _drop_physics_mouseover(true); - Vector2 last_pos(1e20, 1e20); - CollisionObject3D *last_object = nullptr; - ObjectID last_id; - PhysicsDirectSpaceState3D::RayResult result; PhysicsDirectSpaceState2D *ss2d = PhysicsServer2D::get_singleton()->space_get_direct_state(find_world_2d()->get_space()); if (physics_has_last_mousepos) { @@ -669,6 +674,11 @@ void Viewport::_process_picking() { } } +#ifndef _3D_DISABLED + Vector2 last_pos(1e20, 1e20); + CollisionObject3D *last_object = nullptr; + ObjectID last_id; + PhysicsDirectSpaceState3D::RayResult result; bool captured = false; if (physics_object_capture.is_valid()) { @@ -741,6 +751,7 @@ void Viewport::_process_picking() { last_pos = pos; } } +#endif // _3D_DISABLED } } @@ -2204,6 +2215,7 @@ void Viewport::_drop_physics_mouseover(bool p_paused_only) { _cleanup_mouseover_colliders(true, p_paused_only); +#ifndef _3D_DISABLED if (physics_object_over.is_valid()) { CollisionObject3D *co = Object::cast_to<CollisionObject3D>(ObjectDB::get_instance(physics_object_over)); if (co) { @@ -2214,6 +2226,7 @@ void Viewport::_drop_physics_mouseover(bool p_paused_only) { } } } +#endif // _3D_DISABLED } void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paused_only, uint64_t p_frame_reference) { @@ -3063,6 +3076,7 @@ Viewport::SDFScale Viewport::get_sdf_scale() const { return sdf_scale; } +#ifndef _3D_DISABLED Listener3D *Viewport::get_listener_3d() const { return listener_3d; } @@ -3460,6 +3474,7 @@ void Viewport::set_use_xr(bool p_use_xr) { bool Viewport::is_using_xr() { return use_xr; } +#endif // _3D_DISABLED void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_world_2d", "world_2d"), &Viewport::set_world_2d); @@ -3565,6 +3580,7 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("_process_picking"), &Viewport::_process_picking); +#ifndef _3D_DISABLED 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); @@ -3587,6 +3603,7 @@ void Viewport::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_listener_enable_3d"), "set_as_audio_listener_3d", "is_audio_listener_3d"); 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"); +#endif // _3D_DISABLED ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world_2d", PROPERTY_HINT_RESOURCE_TYPE, "World2D", PROPERTY_USAGE_NONE), "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 87cfef2e05..9c51f404d7 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -34,10 +34,12 @@ #include "scene/main/node.h" #include "scene/resources/texture.h" +#ifndef _3D_DISABLED class Camera3D; class CollisionObject3D; class Listener3D; class World3D; +#endif // _3D_DISABLED class Camera2D; class CanvasItem; @@ -573,6 +575,7 @@ public: void pass_mouse_focus_to(Viewport *p_viewport, Control *p_control); +#ifndef _3D_DISABLED bool use_xr = false; friend class Listener3D; Listener3D *listener_3d = nullptr; @@ -644,6 +647,7 @@ public: void set_use_xr(bool p_use_xr); bool is_using_xr(); +#endif // _3D_DISABLED Viewport(); ~Viewport(); diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 0c83c57de6..47c7e57e3f 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -148,7 +148,6 @@ #include "scene/resources/gradient.h" #include "scene/resources/height_map_shape_3d.h" #include "scene/resources/immediate_mesh.h" -#include "scene/resources/line_shape_2d.h" #include "scene/resources/material.h" #include "scene/resources/mesh.h" #include "scene/resources/mesh_data_tool.h" @@ -187,6 +186,7 @@ #include "scene/resources/visual_shader_sdf_nodes.h" #include "scene/resources/world_2d.h" #include "scene/resources/world_3d.h" +#include "scene/resources/world_margin_shape_2d.h" #include "scene/resources/world_margin_shape_3d.h" #include "scene/scene_string_names.h" @@ -823,7 +823,7 @@ void register_scene_types() { OS::get_singleton()->yield(); //may take time to init GDREGISTER_VIRTUAL_CLASS(Shape2D); - GDREGISTER_CLASS(LineShape2D); + GDREGISTER_CLASS(WorldMarginShape2D); GDREGISTER_CLASS(SegmentShape2D); GDREGISTER_CLASS(CircleShape2D); GDREGISTER_CLASS(RectangleShape2D); @@ -910,6 +910,7 @@ void register_scene_types() { ClassDB::add_compatibility_class("KinematicBody2D", "CharacterBody2D"); ClassDB::add_compatibility_class("KinematicCollision", "KinematicCollision3D"); ClassDB::add_compatibility_class("Light", "Light3D"); + ClassDB::add_compatibility_class("LineShape2D", "WorldMarginShape2D"); ClassDB::add_compatibility_class("Listener", "Listener3D"); ClassDB::add_compatibility_class("MeshInstance", "MeshInstance3D"); ClassDB::add_compatibility_class("MultiMeshInstance", "MultiMeshInstance3D"); diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index eddbb9a842..54bfc427c4 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -162,12 +162,14 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const { } WARN_PRINT(vformat("Node %s of type %s cannot be created. A placeholder will be created instead.", snames[n.name], snames[n.type]).ascii().get_data()); if (n.parent >= 0 && n.parent < nc && ret_nodes[n.parent]) { - if (Object::cast_to<Node3D>(ret_nodes[n.parent])) { - obj = memnew(Node3D); - } else if (Object::cast_to<Control>(ret_nodes[n.parent])) { + if (Object::cast_to<Control>(ret_nodes[n.parent])) { obj = memnew(Control); } else if (Object::cast_to<Node2D>(ret_nodes[n.parent])) { obj = memnew(Node2D); +#ifndef _3D_DISABLED + } else if (Object::cast_to<Node3D>(ret_nodes[n.parent])) { + obj = memnew(Node3D); +#endif // _3D_DISABLED } } diff --git a/scene/resources/skeleton_modification_2d.cpp b/scene/resources/skeleton_modification_2d.cpp index b52a60006a..2d5b42ddf4 100644 --- a/scene/resources/skeleton_modification_2d.cpp +++ b/scene/resources/skeleton_modification_2d.cpp @@ -166,13 +166,13 @@ void SkeletonModification2D::editor_draw_angle_constraints(Bone2D *p_operation_b if (operation_bone_parent_bone) { stack->skeleton->draw_set_transform( - stack->skeleton->get_global_transform().affine_inverse().xform(p_operation_bone->get_global_position()), + stack->skeleton->to_local(p_operation_bone->get_global_position()), operation_bone_parent_bone->get_global_rotation() - stack->skeleton->get_global_rotation()); } else { - stack->skeleton->draw_set_transform(stack->skeleton->get_global_transform().affine_inverse().xform(p_operation_bone->get_global_position())); + stack->skeleton->draw_set_transform(stack->skeleton->to_local(p_operation_bone->get_global_position())); } } else { - stack->skeleton->draw_set_transform(stack->skeleton->get_global_transform().affine_inverse().xform(p_operation_bone->get_global_position())); + stack->skeleton->draw_set_transform(stack->skeleton->to_local(p_operation_bone->get_global_position())); } if (p_constraint_inverted) { @@ -186,7 +186,7 @@ void SkeletonModification2D::editor_draw_angle_constraints(Bone2D *p_operation_b stack->skeleton->draw_line(Vector2(0, 0), Vector2(Math::cos(arc_angle_max), Math::sin(arc_angle_max)) * p_operation_bone->get_length(), bone_ik_color, 1.0); } else { - stack->skeleton->draw_set_transform(stack->skeleton->get_global_transform().affine_inverse().xform(p_operation_bone->get_global_position())); + stack->skeleton->draw_set_transform(stack->skeleton->to_local(p_operation_bone->get_global_position())); stack->skeleton->draw_arc(Vector2(0, 0), p_operation_bone->get_length(), 0, Math_PI * 2, 32, bone_ik_color, 1.0); stack->skeleton->draw_line(Vector2(0, 0), Vector2(1, 0) * p_operation_bone->get_length(), bone_ik_color, 1.0); } diff --git a/scene/resources/skeleton_modification_2d_ccdik.cpp b/scene/resources/skeleton_modification_2d_ccdik.cpp index 7ea60e584e..6eab8d4afe 100644 --- a/scene/resources/skeleton_modification_2d_ccdik.cpp +++ b/scene/resources/skeleton_modification_2d_ccdik.cpp @@ -201,18 +201,18 @@ void SkeletonModification2DCCDIK::_execute_ccdik_joint(int p_joint_idx, Node2D * if (ccdik_data.rotate_from_joint) { // To rotate from the joint, simply look at the target! operation_transform.set_rotation( - operation_transform.looking_at(p_target->get_global_transform().get_origin()).get_rotation() - operation_bone->get_bone_angle()); + operation_transform.looking_at(p_target->get_global_position()).get_rotation() - operation_bone->get_bone_angle()); } else { // How to rotate from the tip: get the difference of rotation needed from the tip to the target, from the perspective of the joint. // Because we are only using the offset, we do not need to account for the bone angle of the Bone2D node. - float joint_to_tip = operation_transform.get_origin().angle_to_point(p_tip->get_global_transform().get_origin()); - float joint_to_target = operation_transform.get_origin().angle_to_point(p_target->get_global_transform().get_origin()); + float joint_to_tip = operation_transform.get_origin().angle_to_point(p_tip->get_global_position()); + float joint_to_target = operation_transform.get_origin().angle_to_point(p_target->get_global_position()); operation_transform.set_rotation( operation_transform.get_rotation() + (joint_to_target - joint_to_tip)); } // Reset scale - operation_transform.set_scale(operation_bone->get_global_transform().get_scale()); + operation_transform.set_scale(operation_bone->get_global_scale()); // Apply constraints in globalspace: if (ccdik_data.enable_constraint && !ccdik_data.constraint_in_localspace) { diff --git a/scene/resources/skeleton_modification_2d_fabrik.cpp b/scene/resources/skeleton_modification_2d_fabrik.cpp index aef852f7e4..c03a92b503 100644 --- a/scene/resources/skeleton_modification_2d_fabrik.cpp +++ b/scene/resources/skeleton_modification_2d_fabrik.cpp @@ -161,25 +161,25 @@ void SkeletonModification2DFABRIK::_execute(float p_delta) { } Bone2D *final_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[fabrik_data_chain.size() - 1].bone2d_node_cache)); - float final_bone2d_angle = final_bone2d_node->get_global_transform().get_rotation(); + float final_bone2d_angle = final_bone2d_node->get_global_rotation(); if (fabrik_data_chain[fabrik_data_chain.size() - 1].use_target_rotation) { final_bone2d_angle = target_global_pose.get_rotation(); } Vector2 final_bone2d_direction = Vector2(Math::cos(final_bone2d_angle), Math::sin(final_bone2d_angle)); float final_bone2d_length = final_bone2d_node->get_length() * MIN(final_bone2d_node->get_global_scale().x, final_bone2d_node->get_global_scale().y); - float target_distance = (final_bone2d_node->get_global_transform().get_origin() + (final_bone2d_direction * final_bone2d_length)).distance_to(target->get_global_transform().get_origin()); + float target_distance = (final_bone2d_node->get_global_position() + (final_bone2d_direction * final_bone2d_length)).distance_to(target->get_global_position()); chain_iterations = 0; while (target_distance > chain_tolarance) { chain_backwards(); chain_forwards(); - final_bone2d_angle = final_bone2d_node->get_global_transform().get_rotation(); + final_bone2d_angle = final_bone2d_node->get_global_rotation(); if (fabrik_data_chain[fabrik_data_chain.size() - 1].use_target_rotation) { final_bone2d_angle = target_global_pose.get_rotation(); } final_bone2d_direction = Vector2(Math::cos(final_bone2d_angle), Math::sin(final_bone2d_angle)); - target_distance = (final_bone2d_node->get_global_transform().get_origin() + (final_bone2d_direction * final_bone2d_length)).distance_to(target->get_global_transform().get_origin()); + target_distance = (final_bone2d_node->get_global_position() + (final_bone2d_direction * final_bone2d_length)).distance_to(target->get_global_position()); chain_iterations += 1; if (chain_iterations >= chain_max_iterations) { @@ -210,7 +210,7 @@ void SkeletonModification2DFABRIK::_execute(float p_delta) { chain_trans.set_rotation(chain_trans.get_rotation() - joint_bone2d_node->get_bone_angle()); // Reset scale - chain_trans.set_scale(joint_bone2d_node->get_global_transform().get_scale()); + chain_trans.set_scale(joint_bone2d_node->get_global_scale()); // Apply to the bone, and to the override joint_bone2d_node->set_global_transform(chain_trans); diff --git a/scene/resources/skeleton_modification_2d_jiggle.cpp b/scene/resources/skeleton_modification_2d_jiggle.cpp index 2547083336..84abc9d020 100644 --- a/scene/resources/skeleton_modification_2d_jiggle.cpp +++ b/scene/resources/skeleton_modification_2d_jiggle.cpp @@ -171,7 +171,7 @@ void SkeletonModification2DJiggle::_execute_jiggle_joint(int p_joint_idx, Node2D } Transform2D operation_bone_trans = operation_bone->get_global_transform(); - Vector2 target_position = p_target->get_global_transform().get_origin(); + Vector2 target_position = p_target->get_global_position(); jiggle_data_chain.write[p_joint_idx].force = (target_position - jiggle_data_chain[p_joint_idx].dynamic_position) * jiggle_data_chain[p_joint_idx].stiffness * p_delta; @@ -215,7 +215,7 @@ void SkeletonModification2DJiggle::_execute_jiggle_joint(int p_joint_idx, Node2D operation_bone_trans.set_rotation(operation_bone_trans.get_rotation() - operation_bone->get_bone_angle()); // Reset scale - operation_bone_trans.set_scale(operation_bone->get_global_transform().get_scale()); + operation_bone_trans.set_scale(operation_bone->get_global_scale()); operation_bone->set_global_transform(operation_bone_trans); stack->skeleton->set_bone_local_pose_override(jiggle_data_chain[p_joint_idx].bone_idx, operation_bone->get_transform(), stack->strength, true); @@ -244,7 +244,7 @@ void SkeletonModification2DJiggle::_setup_modification(SkeletonModificationStack int bone_idx = jiggle_data_chain[i].bone_idx; if (bone_idx > 0 && bone_idx < stack->skeleton->get_bone_count()) { Bone2D *bone2d_node = stack->skeleton->get_bone(bone_idx); - jiggle_data_chain.write[i].dynamic_position = bone2d_node->get_global_transform().get_origin(); + jiggle_data_chain.write[i].dynamic_position = bone2d_node->get_global_position(); } } } diff --git a/scene/resources/skeleton_modification_2d_lookat.cpp b/scene/resources/skeleton_modification_2d_lookat.cpp index fd5c8c7cc2..2da770f012 100644 --- a/scene/resources/skeleton_modification_2d_lookat.cpp +++ b/scene/resources/skeleton_modification_2d_lookat.cpp @@ -147,7 +147,7 @@ void SkeletonModification2DLookAt::_execute(float p_delta) { // Look at the target! operation_transform = operation_transform.looking_at(target_trans.get_origin()); // Apply whatever scale it had prior to looking_at - operation_transform.set_scale(operation_bone->get_global_transform().get_scale()); + operation_transform.set_scale(operation_bone->get_global_scale()); // Account for the direction the bone faces in: operation_transform.set_rotation(operation_transform.get_rotation() - operation_bone->get_bone_angle()); diff --git a/scene/resources/skeleton_modification_2d_twoboneik.cpp b/scene/resources/skeleton_modification_2d_twoboneik.cpp index 0a91290015..88d80a501f 100644 --- a/scene/resources/skeleton_modification_2d_twoboneik.cpp +++ b/scene/resources/skeleton_modification_2d_twoboneik.cpp @@ -142,7 +142,7 @@ void SkeletonModification2DTwoBoneIK::_execute(float p_delta) { // http://theorangeduck.com/page/simple-two-joint // https://www.alanzucconi.com/2018/05/02/ik-2d-2/ // With modifications by TwistedTwigleg - Vector2 target_difference = target->get_global_transform().get_origin() - joint_one_bone->get_global_transform().get_origin(); + Vector2 target_difference = target->get_global_position() - joint_one_bone->get_global_position(); float joint_one_to_target = target_difference.length(); float angle_atan = Math::atan2(target_difference.y, target_difference.x); @@ -206,7 +206,7 @@ void SkeletonModification2DTwoBoneIK::_draw_editor_gizmo() { return; } stack->skeleton->draw_set_transform( - stack->skeleton->get_global_transform().affine_inverse().xform(operation_bone_one->get_global_position()), + stack->skeleton->to_local(operation_bone_one->get_global_position()), operation_bone_one->get_global_rotation() - stack->skeleton->get_global_rotation()); Color bone_ik_color = Color(1.0, 0.65, 0.0, 0.4); diff --git a/scene/resources/line_shape_2d.cpp b/scene/resources/world_margin_shape_2d.cpp index d206f12287..3b43681528 100644 --- a/scene/resources/line_shape_2d.cpp +++ b/scene/resources/world_margin_shape_2d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* line_shape_2d.cpp */ +/* world_margin_shape_2d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,13 +28,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "line_shape_2d.h" +#include "world_margin_shape_2d.h" #include "core/math/geometry_2d.h" #include "servers/physics_server_2d.h" #include "servers/rendering_server.h" -bool LineShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { +bool WorldMarginShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { Vector2 point = get_distance() * get_normal(); Vector2 l[2][2] = { { point - get_normal().orthogonal() * 100, point + get_normal().orthogonal() * 100 }, { point, point + get_normal() * 30 } }; @@ -48,7 +48,7 @@ bool LineShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tol return false; } -void LineShape2D::_update_shape() { +void WorldMarginShape2D::_update_shape() { Array arr; arr.push_back(normal); arr.push_back(distance); @@ -56,25 +56,25 @@ void LineShape2D::_update_shape() { emit_changed(); } -void LineShape2D::set_normal(const Vector2 &p_normal) { +void WorldMarginShape2D::set_normal(const Vector2 &p_normal) { normal = p_normal; _update_shape(); } -void LineShape2D::set_distance(real_t p_distance) { +void WorldMarginShape2D::set_distance(real_t p_distance) { distance = p_distance; _update_shape(); } -Vector2 LineShape2D::get_normal() const { +Vector2 WorldMarginShape2D::get_normal() const { return normal; } -real_t LineShape2D::get_distance() const { +real_t WorldMarginShape2D::get_distance() const { return distance; } -void LineShape2D::draw(const RID &p_to_rid, const Color &p_color) { +void WorldMarginShape2D::draw(const RID &p_to_rid, const Color &p_color) { Vector2 point = get_distance() * get_normal(); Vector2 l1[2] = { point - get_normal().orthogonal() * 100, point + get_normal().orthogonal() * 100 }; @@ -83,7 +83,7 @@ void LineShape2D::draw(const RID &p_to_rid, const Color &p_color) { RS::get_singleton()->canvas_item_add_line(p_to_rid, l2[0], l2[1], p_color, 3); } -Rect2 LineShape2D::get_rect() const { +Rect2 WorldMarginShape2D::get_rect() const { Vector2 point = get_distance() * get_normal(); Vector2 l1[2] = { point - get_normal().orthogonal() * 100, point + get_normal().orthogonal() * 100 }; @@ -96,22 +96,22 @@ Rect2 LineShape2D::get_rect() const { return rect; } -real_t LineShape2D::get_enclosing_radius() const { +real_t WorldMarginShape2D::get_enclosing_radius() const { return distance; } -void LineShape2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_normal", "normal"), &LineShape2D::set_normal); - ClassDB::bind_method(D_METHOD("get_normal"), &LineShape2D::get_normal); +void WorldMarginShape2D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_normal", "normal"), &WorldMarginShape2D::set_normal); + ClassDB::bind_method(D_METHOD("get_normal"), &WorldMarginShape2D::get_normal); - ClassDB::bind_method(D_METHOD("set_distance", "distance"), &LineShape2D::set_distance); - ClassDB::bind_method(D_METHOD("get_distance"), &LineShape2D::get_distance); + ClassDB::bind_method(D_METHOD("set_distance", "distance"), &WorldMarginShape2D::set_distance); + ClassDB::bind_method(D_METHOD("get_distance"), &WorldMarginShape2D::get_distance); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "normal"), "set_normal", "get_normal"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "distance"), "set_distance", "get_distance"); } -LineShape2D::LineShape2D() : - Shape2D(PhysicsServer2D::get_singleton()->line_shape_create()) { +WorldMarginShape2D::WorldMarginShape2D() : + Shape2D(PhysicsServer2D::get_singleton()->world_margin_shape_create()) { _update_shape(); } diff --git a/scene/resources/line_shape_2d.h b/scene/resources/world_margin_shape_2d.h index 210a1aa9e6..3c1d593ffe 100644 --- a/scene/resources/line_shape_2d.h +++ b/scene/resources/world_margin_shape_2d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* line_shape_2d.h */ +/* world_margin_shape_2d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef LINE_SHAPE_2D_H -#define LINE_SHAPE_2D_H +#ifndef WORLD_MARGIN_SHAPE_2D_H +#define WORLD_MARGIN_SHAPE_2D_H #include "scene/resources/shape_2d.h" -class LineShape2D : public Shape2D { - GDCLASS(LineShape2D, Shape2D); +class WorldMarginShape2D : public Shape2D { + GDCLASS(WorldMarginShape2D, Shape2D); - // LineShape2D is often used for one-way platforms, where the normal pointing up makes sense. + // WorldMarginShape2D is often used for one-way platforms, where the normal pointing up makes sense. Vector2 normal = Vector2(0, -1); real_t distance = 0.0; @@ -58,7 +58,7 @@ public: virtual Rect2 get_rect() const override; virtual real_t get_enclosing_radius() const override; - LineShape2D(); + WorldMarginShape2D(); }; -#endif // LINE_SHAPE_2D_H +#endif // WORLD_MARGIN_SHAPE_2D_H diff --git a/servers/physics_2d/collision_solver_2d_sat.cpp b/servers/physics_2d/collision_solver_2d_sat.cpp index 45b9e6414d..30a99d3d74 100644 --- a/servers/physics_2d/collision_solver_2d_sat.cpp +++ b/servers/physics_2d/collision_solver_2d_sat.cpp @@ -1114,12 +1114,12 @@ static void _collision_convex_polygon_convex_polygon(const Shape2DSW *p_a, const bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Vector2 &p_motion_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, const Vector2 &p_motion_B, CollisionSolver2DSW::CallbackResult p_result_callback, void *p_userdata, bool p_swap, Vector2 *sep_axis, real_t p_margin_A, real_t p_margin_B) { PhysicsServer2D::ShapeType type_A = p_shape_A->get_type(); - ERR_FAIL_COND_V(type_A == PhysicsServer2D::SHAPE_LINE, false); + ERR_FAIL_COND_V(type_A == PhysicsServer2D::SHAPE_WORLD_MARGIN, false); ERR_FAIL_COND_V(p_shape_A->is_concave(), false); PhysicsServer2D::ShapeType type_B = p_shape_B->get_type(); - ERR_FAIL_COND_V(type_B == PhysicsServer2D::SHAPE_LINE, false); + ERR_FAIL_COND_V(type_B == PhysicsServer2D::SHAPE_WORLD_MARGIN, false); ERR_FAIL_COND_V(p_shape_B->is_concave(), false); static const CollisionFunc collision_table[5][5] = { diff --git a/servers/physics_2d/collision_solver_2d_sw.cpp b/servers/physics_2d/collision_solver_2d_sw.cpp index ed398a24e5..8f8a4a862c 100644 --- a/servers/physics_2d/collision_solver_2d_sw.cpp +++ b/servers/physics_2d/collision_solver_2d_sw.cpp @@ -34,14 +34,14 @@ #define collision_solver sat_2d_calculate_penetration //#define collision_solver gjk_epa_calculate_penetration -bool CollisionSolver2DSW::solve_static_line(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result) { - const LineShape2DSW *line = static_cast<const LineShape2DSW *>(p_shape_A); - if (p_shape_B->get_type() == PhysicsServer2D::SHAPE_LINE) { +bool CollisionSolver2DSW::solve_static_world_margin(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result) { + const WorldMarginShape2DSW *world_margin = static_cast<const WorldMarginShape2DSW *>(p_shape_A); + if (p_shape_B->get_type() == PhysicsServer2D::SHAPE_WORLD_MARGIN) { return false; } - Vector2 n = p_transform_A.basis_xform(line->get_normal()).normalized(); - Vector2 p = p_transform_A.xform(line->get_normal() * line->get_d()); + Vector2 n = p_transform_A.basis_xform(world_margin->get_normal()).normalized(); + Vector2 p = p_transform_A.xform(world_margin->get_normal() * world_margin->get_d()); real_t d = n.dot(p); Vector2 supports[2]; @@ -166,15 +166,15 @@ bool CollisionSolver2DSW::solve(const Shape2DSW *p_shape_A, const Transform2D &p swap = true; } - if (type_A == PhysicsServer2D::SHAPE_LINE) { - if (type_B == PhysicsServer2D::SHAPE_LINE) { + if (type_A == PhysicsServer2D::SHAPE_WORLD_MARGIN) { + if (type_B == PhysicsServer2D::SHAPE_WORLD_MARGIN) { return false; } if (swap) { - return solve_static_line(p_shape_B, p_transform_B, p_shape_A, p_transform_A, p_result_callback, p_userdata, true); + return solve_static_world_margin(p_shape_B, p_transform_B, p_shape_A, p_transform_A, p_result_callback, p_userdata, true); } else { - return solve_static_line(p_shape_A, p_transform_A, p_shape_B, p_transform_B, p_result_callback, p_userdata, false); + return solve_static_world_margin(p_shape_A, p_transform_A, p_shape_B, p_transform_B, p_result_callback, p_userdata, false); } } else if (concave_B) { diff --git a/servers/physics_2d/collision_solver_2d_sw.h b/servers/physics_2d/collision_solver_2d_sw.h index 4f12ca9e88..17c0c2fe70 100644 --- a/servers/physics_2d/collision_solver_2d_sw.h +++ b/servers/physics_2d/collision_solver_2d_sw.h @@ -38,7 +38,7 @@ public: typedef void (*CallbackResult)(const Vector2 &p_point_A, const Vector2 &p_point_B, void *p_userdata); private: - static bool solve_static_line(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result); + static bool solve_static_world_margin(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result); static void concave_callback(void *p_userdata, Shape2DSW *p_convex); static bool solve_concave(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Vector2 &p_motion_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, const Vector2 &p_motion_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis = nullptr, real_t p_margin_A = 0, real_t p_margin_B = 0); static bool solve_raycast(const Shape2DSW *p_shape_A, const Vector2 &p_motion_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis = nullptr); diff --git a/servers/physics_2d/physics_server_2d_sw.cpp b/servers/physics_2d/physics_server_2d_sw.cpp index 4dcc4a9cfd..88c097453e 100644 --- a/servers/physics_2d/physics_server_2d_sw.cpp +++ b/servers/physics_2d/physics_server_2d_sw.cpp @@ -42,8 +42,8 @@ RID PhysicsServer2DSW::_shape_create(ShapeType p_shape) { Shape2DSW *shape = nullptr; switch (p_shape) { - case SHAPE_LINE: { - shape = memnew(LineShape2DSW); + case SHAPE_WORLD_MARGIN: { + shape = memnew(WorldMarginShape2DSW); } break; case SHAPE_SEGMENT: { shape = memnew(SegmentShape2DSW); @@ -75,8 +75,8 @@ RID PhysicsServer2DSW::_shape_create(ShapeType p_shape) { return id; } -RID PhysicsServer2DSW::line_shape_create() { - return _shape_create(SHAPE_LINE); +RID PhysicsServer2DSW::world_margin_shape_create() { + return _shape_create(SHAPE_WORLD_MARGIN); } RID PhysicsServer2DSW::segment_shape_create() { diff --git a/servers/physics_2d/physics_server_2d_sw.h b/servers/physics_2d/physics_server_2d_sw.h index e1ad6a56ee..3610f43f93 100644 --- a/servers/physics_2d/physics_server_2d_sw.h +++ b/servers/physics_2d/physics_server_2d_sw.h @@ -87,7 +87,7 @@ public: Vector2 *ptr; }; - virtual RID line_shape_create() override; + virtual RID world_margin_shape_create() override; virtual RID segment_shape_create() override; virtual RID circle_shape_create() override; virtual RID rectangle_shape_create() override; diff --git a/servers/physics_2d/physics_server_2d_wrap_mt.h b/servers/physics_2d/physics_server_2d_wrap_mt.h index 7bc1096f93..b93178919d 100644 --- a/servers/physics_2d/physics_server_2d_wrap_mt.h +++ b/servers/physics_2d/physics_server_2d_wrap_mt.h @@ -79,7 +79,7 @@ public: #include "servers/server_wrap_mt_common.h" //FUNC1RID(shape,ShapeType); todo fix - FUNCRID(line_shape) + FUNCRID(world_margin_shape) FUNCRID(segment_shape) FUNCRID(circle_shape) FUNCRID(rectangle_shape) diff --git a/servers/physics_2d/shape_2d_sw.cpp b/servers/physics_2d/shape_2d_sw.cpp index b16efbfe64..b3e4ca84c3 100644 --- a/servers/physics_2d/shape_2d_sw.cpp +++ b/servers/physics_2d/shape_2d_sw.cpp @@ -88,15 +88,15 @@ Shape2DSW::~Shape2DSW() { /*********************************************************/ /*********************************************************/ -void LineShape2DSW::get_supports(const Vector2 &p_normal, Vector2 *r_supports, int &r_amount) const { +void WorldMarginShape2DSW::get_supports(const Vector2 &p_normal, Vector2 *r_supports, int &r_amount) const { r_amount = 0; } -bool LineShape2DSW::contains_point(const Vector2 &p_point) const { +bool WorldMarginShape2DSW::contains_point(const Vector2 &p_point) const { return normal.dot(p_point) < d; } -bool LineShape2DSW::intersect_segment(const Vector2 &p_begin, const Vector2 &p_end, Vector2 &r_point, Vector2 &r_normal) const { +bool WorldMarginShape2DSW::intersect_segment(const Vector2 &p_begin, const Vector2 &p_end, Vector2 &r_point, Vector2 &r_normal) const { Vector2 segment = p_begin - p_end; real_t den = normal.dot(segment); @@ -118,11 +118,11 @@ bool LineShape2DSW::intersect_segment(const Vector2 &p_begin, const Vector2 &p_e return true; } -real_t LineShape2DSW::get_moment_of_inertia(real_t p_mass, const Size2 &p_scale) const { +real_t WorldMarginShape2DSW::get_moment_of_inertia(real_t p_mass, const Size2 &p_scale) const { return 0; } -void LineShape2DSW::set_data(const Variant &p_data) { +void WorldMarginShape2DSW::set_data(const Variant &p_data) { ERR_FAIL_COND(p_data.get_type() != Variant::ARRAY); Array arr = p_data; ERR_FAIL_COND(arr.size() != 2); @@ -131,7 +131,7 @@ void LineShape2DSW::set_data(const Variant &p_data) { configure(Rect2(Vector2(-1e4, -1e4), Vector2(1e4 * 2, 1e4 * 2))); } -Variant LineShape2DSW::get_data() const { +Variant WorldMarginShape2DSW::get_data() const { Array arr; arr.resize(2); arr[0] = normal; diff --git a/servers/physics_2d/shape_2d_sw.h b/servers/physics_2d/shape_2d_sw.h index 3e4271b156..2de0f3cb9f 100644 --- a/servers/physics_2d/shape_2d_sw.h +++ b/servers/physics_2d/shape_2d_sw.h @@ -36,7 +36,7 @@ /* -SHAPE_LINE, ///< plane:"plane" +SHAPE_WORLD_MARGIN, ///< plane:"plane" SHAPE_SEGMENT, ///< real_t:"length" SHAPE_CIRCLE, ///< real_t:"radius" SHAPE_RECTANGLE, ///< vec3:"extents" @@ -152,7 +152,7 @@ public: r_max = MAX(maxa, maxb); \ } -class LineShape2DSW : public Shape2DSW { +class WorldMarginShape2DSW : public Shape2DSW { Vector2 normal; real_t d; @@ -160,7 +160,7 @@ public: _FORCE_INLINE_ Vector2 get_normal() const { return normal; } _FORCE_INLINE_ real_t get_d() const { return d; } - virtual PhysicsServer2D::ShapeType get_type() const { return PhysicsServer2D::SHAPE_LINE; } + virtual PhysicsServer2D::ShapeType get_type() const { return PhysicsServer2D::SHAPE_WORLD_MARGIN; } virtual void project_rangev(const Vector2 &p_normal, const Transform2D &p_transform, real_t &r_min, real_t &r_max) const { project_range(p_normal, p_transform, r_min, r_max); } virtual void get_supports(const Vector2 &p_normal, Vector2 *r_supports, int &r_amount) const; diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp index c2dedde0be..092c3ae7a9 100644 --- a/servers/physics_server_2d.cpp +++ b/servers/physics_server_2d.cpp @@ -513,7 +513,7 @@ bool PhysicsServer2D::_body_test_motion(RID p_body, const Transform2D &p_from, c } void PhysicsServer2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("line_shape_create"), &PhysicsServer2D::line_shape_create); + ClassDB::bind_method(D_METHOD("world_margin_shape_create"), &PhysicsServer2D::world_margin_shape_create); ClassDB::bind_method(D_METHOD("segment_shape_create"), &PhysicsServer2D::segment_shape_create); ClassDB::bind_method(D_METHOD("circle_shape_create"), &PhysicsServer2D::circle_shape_create); ClassDB::bind_method(D_METHOD("rectangle_shape_create"), &PhysicsServer2D::rectangle_shape_create); @@ -674,7 +674,7 @@ void PhysicsServer2D::_bind_methods() { BIND_ENUM_CONSTANT(SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS); BIND_ENUM_CONSTANT(SPACE_PARAM_TEST_MOTION_MIN_CONTACT_DEPTH); - BIND_ENUM_CONSTANT(SHAPE_LINE); + BIND_ENUM_CONSTANT(SHAPE_WORLD_MARGIN); BIND_ENUM_CONSTANT(SHAPE_SEGMENT); BIND_ENUM_CONSTANT(SHAPE_CIRCLE); BIND_ENUM_CONSTANT(SHAPE_RECTANGLE); diff --git a/servers/physics_server_2d.h b/servers/physics_server_2d.h index dbbc128793..27bc654594 100644 --- a/servers/physics_server_2d.h +++ b/servers/physics_server_2d.h @@ -219,7 +219,7 @@ public: static PhysicsServer2D *get_singleton(); enum ShapeType { - SHAPE_LINE, ///< plane:"plane" + SHAPE_WORLD_MARGIN, ///< plane:"plane" SHAPE_SEGMENT, ///< float:"length" SHAPE_CIRCLE, ///< float:"radius" SHAPE_RECTANGLE, ///< vec3:"extents" @@ -229,7 +229,7 @@ public: SHAPE_CUSTOM, ///< Server-Implementation based custom shape, calling shape_create() with this value will result in an error }; - virtual RID line_shape_create() = 0; + virtual RID world_margin_shape_create() = 0; virtual RID segment_shape_create() = 0; virtual RID circle_shape_create() = 0; virtual RID rectangle_shape_create() = 0; diff --git a/tests/test_physics_2d.cpp b/tests/test_physics_2d.cpp index 40dc74e89c..61b8951afa 100644 --- a/tests/test_physics_2d.cpp +++ b/tests/test_physics_2d.cpp @@ -255,7 +255,7 @@ protected: arr.push_back(p_normal); arr.push_back(p_d); - RID plane = ps->line_shape_create(); + RID plane = ps->world_margin_shape_create(); ps->shape_set_data(plane, arr); RID plane_body = ps->body_create(); |