From 2e0fb66c6f5dd280a28bffb1233e400afa1a698d Mon Sep 17 00:00:00 2001 From: Andrea Catania Date: Fri, 21 Feb 2020 12:19:24 +0100 Subject: Renamed PlaneShape to WorldMarginShape --- doc/classes/PhysicsServer.xml | 2 +- doc/classes/PlaneShape.xml | 20 ----- doc/classes/WorldMarginShape.xml | 20 +++++ editor/icons/PlaneMesh.svg | 1 - editor/icons/WorldMarginShape.svg | 1 + editor/import/resource_importer_scene.cpp | 8 +- editor/spatial_editor_gizmos.cpp | 6 +- main/tests/test_physics.cpp | 6 +- modules/gdnavigation/navigation_mesh_generator.cpp | 2 +- scene/3d/collision_shape.cpp | 6 +- scene/register_scene_types.cpp | 6 +- scene/resources/plane_shape.cpp | 95 ---------------------- scene/resources/plane_shape.h | 57 ------------- scene/resources/world_margin_shape.cpp | 95 ++++++++++++++++++++++ scene/resources/world_margin_shape.h | 57 +++++++++++++ 15 files changed, 189 insertions(+), 193 deletions(-) delete mode 100644 doc/classes/PlaneShape.xml create mode 100644 doc/classes/WorldMarginShape.xml delete mode 100644 editor/icons/PlaneMesh.svg create mode 100644 editor/icons/WorldMarginShape.svg delete mode 100644 scene/resources/plane_shape.cpp delete mode 100644 scene/resources/plane_shape.h create mode 100644 scene/resources/world_margin_shape.cpp create mode 100644 scene/resources/world_margin_shape.h diff --git a/doc/classes/PhysicsServer.xml b/doc/classes/PhysicsServer.xml index 592d3d8e4e..c9f4accee2 100644 --- a/doc/classes/PhysicsServer.xml +++ b/doc/classes/PhysicsServer.xml @@ -1467,7 +1467,7 @@ If [code]set[/code] there is a linear motor on this axis that targets a specific velocity. - The [Shape] is a [PlaneShape]. + The [Shape] is a [WorldMarginShape]. The [Shape] is a [RayShape]. diff --git a/doc/classes/PlaneShape.xml b/doc/classes/PlaneShape.xml deleted file mode 100644 index b40e133d00..0000000000 --- a/doc/classes/PlaneShape.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - Infinite plane shape for 3D collisions. - - - An infinite plane shape for 3D collisions. Note that the [Plane]'s normal matters; anything "below" the plane will collide with it. If the [PlaneShape] is used in a [PhysicsBody], it will cause colliding objects placed "below" it to teleport "above" the plane. - - - - - - - - The [Plane] used by the [PlaneShape] for collision. - - - - - diff --git a/doc/classes/WorldMarginShape.xml b/doc/classes/WorldMarginShape.xml new file mode 100644 index 0000000000..54f76a066b --- /dev/null +++ b/doc/classes/WorldMarginShape.xml @@ -0,0 +1,20 @@ + + + + Infinite plane shape for 3D collisions. + + + An infinite plane shape for 3D collisions. Note that the [Plane]'s normal matters; anything "below" the plane will collide with it. If the [WorldMarginShape] is used in a [PhysicsBody], it will cause colliding objects placed "below" it to teleport "above" the plane. + + + + + + + + The [Plane] used by the [WorldMarginShape] for collision. + + + + + diff --git a/editor/icons/PlaneMesh.svg b/editor/icons/PlaneMesh.svg deleted file mode 100644 index ddcc623c67..0000000000 --- a/editor/icons/PlaneMesh.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/editor/icons/WorldMarginShape.svg b/editor/icons/WorldMarginShape.svg new file mode 100644 index 0000000000..2c90cf6d53 --- /dev/null +++ b/editor/icons/WorldMarginShape.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index dbd67d1e22..5651197fa3 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -41,10 +41,10 @@ #include "scene/resources/animation.h" #include "scene/resources/box_shape.h" #include "scene/resources/packed_scene.h" -#include "scene/resources/plane_shape.h" #include "scene/resources/ray_shape.h" #include "scene/resources/resource_format_text.h" #include "scene/resources/sphere_shape.h" +#include "scene/resources/world_margin_shape.h" uint32_t EditorSceneImporter::get_import_flags() const { @@ -446,9 +446,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map colshape->set_name("RayShape"); Object::cast_to(sb)->rotate_x(Math_PI / 2); } else if (empty_draw_type == "IMAGE") { - PlaneShape *planeShape = memnew(PlaneShape); - colshape->set_shape(planeShape); - colshape->set_name("PlaneShape"); + WorldMarginShape *world_margin_shape = memnew(WorldMarginShape); + colshape->set_shape(world_margin_shape); + colshape->set_name("WorldMarginShape"); } else { SphereShape *sphereShape = memnew(SphereShape); sphereShape->set_radius(1); diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index f240654487..c155430eae 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -58,11 +58,11 @@ #include "scene/resources/convex_polygon_shape.h" #include "scene/resources/cylinder_shape.h" #include "scene/resources/height_map_shape.h" -#include "scene/resources/plane_shape.h" #include "scene/resources/primitive_meshes.h" #include "scene/resources/ray_shape.h" #include "scene/resources/sphere_shape.h" #include "scene/resources/surface_tool.h" +#include "scene/resources/world_margin_shape.h" #define HANDLE_HALF_SIZE 9.5 @@ -3575,9 +3575,9 @@ void CollisionShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { p_gizmo->add_handles(handles, handles_material); } - if (Object::cast_to(*s)) { + if (Object::cast_to(*s)) { - Ref ps = s; + Ref ps = s; Plane p = ps->get_plane(); Vector points; diff --git a/main/tests/test_physics.cpp b/main/tests/test_physics.cpp index 43958a9493..0304e8f6dd 100644 --- a/main/tests/test_physics.cpp +++ b/main/tests/test_physics.cpp @@ -110,13 +110,13 @@ protected: PhysicsServer *ps = PhysicsServer::get_singleton(); - RID plane_shape = ps->shape_create(PhysicsServer::SHAPE_PLANE); - ps->shape_set_data(plane_shape, p_plane); + RID world_margin_shape = ps->shape_create(PhysicsServer::SHAPE_PLANE); + ps->shape_set_data(world_margin_shape, p_plane); RID b = ps->body_create(PhysicsServer::BODY_MODE_STATIC); ps->body_set_space(b, space); //todo set space - ps->body_add_shape(b, plane_shape); + ps->body_add_shape(b, world_margin_shape); return b; } diff --git a/modules/gdnavigation/navigation_mesh_generator.cpp b/modules/gdnavigation/navigation_mesh_generator.cpp index 7f8761dac8..e7038b38a2 100644 --- a/modules/gdnavigation/navigation_mesh_generator.cpp +++ b/modules/gdnavigation/navigation_mesh_generator.cpp @@ -42,10 +42,10 @@ #include "scene/resources/concave_polygon_shape.h" #include "scene/resources/convex_polygon_shape.h" #include "scene/resources/cylinder_shape.h" -#include "scene/resources/plane_shape.h" #include "scene/resources/primitive_meshes.h" #include "scene/resources/shape.h" #include "scene/resources/sphere_shape.h" +#include "scene/resources/world_margin_shape.h" #include "modules/modules_enabled.gen.h" #ifdef TOOLS_ENABLED diff --git a/scene/3d/collision_shape.cpp b/scene/3d/collision_shape.cpp index d0d775d557..c7a92b66e1 100644 --- a/scene/3d/collision_shape.cpp +++ b/scene/3d/collision_shape.cpp @@ -33,9 +33,9 @@ #include "scene/resources/capsule_shape.h" #include "scene/resources/concave_polygon_shape.h" #include "scene/resources/convex_polygon_shape.h" -#include "scene/resources/plane_shape.h" #include "scene/resources/ray_shape.h" #include "scene/resources/sphere_shape.h" +#include "scene/resources/world_margin_shape.h" #include "servers/visual_server.h" //TODO: Implement CylinderShape and HeightMapShape? #include "core/math/quick_hull.h" @@ -123,10 +123,6 @@ String CollisionShape::get_configuration_warning() const { return TTR("A shape must be provided for CollisionShape to function. Please create a shape resource for it."); } - if (shape->is_class("PlaneShape")) { - return TTR("Plane shapes don't work well and will be removed in future versions. Please don't use them."); - } - return String(); } diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index f11d0a21d4..ae365a5064 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -151,7 +151,6 @@ #include "scene/resources/packed_scene.h" #include "scene/resources/particles_material.h" #include "scene/resources/physics_material.h" -#include "scene/resources/plane_shape.h" #include "scene/resources/polygon_path_finder.h" #include "scene/resources/primitive_meshes.h" #include "scene/resources/ray_shape.h" @@ -169,6 +168,7 @@ #include "scene/resources/visual_shader_nodes.h" #include "scene/resources/world.h" #include "scene/resources/world_2d.h" +#include "scene/resources/world_margin_shape.h" #include "scene/scene_string_names.h" #ifndef _3D_DISABLED @@ -190,8 +190,8 @@ #include "scene/3d/multimesh_instance.h" #include "scene/3d/navigation.h" #include "scene/3d/navigation_agent.h" -#include "scene/3d/navigation_region.h" #include "scene/3d/navigation_obstacle.h" +#include "scene/3d/navigation_region.h" #include "scene/3d/particles.h" #include "scene/3d/path.h" #include "scene/3d/physics_body.h" @@ -643,7 +643,7 @@ void register_scene_types() { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); - ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); diff --git a/scene/resources/plane_shape.cpp b/scene/resources/plane_shape.cpp deleted file mode 100644 index ddc820233e..0000000000 --- a/scene/resources/plane_shape.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/*************************************************************************/ -/* plane_shape.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "plane_shape.h" - -#include "servers/physics_server.h" - -Vector PlaneShape::get_debug_mesh_lines() { - - Plane p = get_plane(); - Vector points; - - Vector3 n1 = p.get_any_perpendicular_normal(); - Vector3 n2 = p.normal.cross(n1).normalized(); - - Vector3 pface[4] = { - p.normal * p.d + n1 * 10.0 + n2 * 10.0, - p.normal * p.d + n1 * 10.0 + n2 * -10.0, - p.normal * p.d + n1 * -10.0 + n2 * -10.0, - p.normal * p.d + n1 * -10.0 + n2 * 10.0, - }; - - points.push_back(pface[0]); - points.push_back(pface[1]); - points.push_back(pface[1]); - points.push_back(pface[2]); - points.push_back(pface[2]); - points.push_back(pface[3]); - points.push_back(pface[3]); - points.push_back(pface[0]); - points.push_back(p.normal * p.d); - points.push_back(p.normal * p.d + p.normal * 3); - - return points; -} - -void PlaneShape::_update_shape() { - - PhysicsServer::get_singleton()->shape_set_data(get_shape(), plane); - Shape::_update_shape(); -} - -void PlaneShape::set_plane(Plane p_plane) { - - plane = p_plane; - _update_shape(); - notify_change_to_owners(); - _change_notify("plane"); -} - -Plane PlaneShape::get_plane() const { - - return plane; -} - -void PlaneShape::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_plane", "plane"), &PlaneShape::set_plane); - ClassDB::bind_method(D_METHOD("get_plane"), &PlaneShape::get_plane); - - ADD_PROPERTY(PropertyInfo(Variant::PLANE, "plane"), "set_plane", "get_plane"); -} - -PlaneShape::PlaneShape() : - Shape(PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_PLANE)) { - - set_plane(Plane(0, 1, 0, 0)); -} diff --git a/scene/resources/plane_shape.h b/scene/resources/plane_shape.h deleted file mode 100644 index 360f9dbbe9..0000000000 --- a/scene/resources/plane_shape.h +++ /dev/null @@ -1,57 +0,0 @@ -/*************************************************************************/ -/* plane_shape.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef PLANE_SHAPE_H -#define PLANE_SHAPE_H - -#include "scene/resources/shape.h" - -class PlaneShape : public Shape { - - GDCLASS(PlaneShape, Shape); - Plane plane; - -protected: - static void _bind_methods(); - virtual void _update_shape(); - -public: - void set_plane(Plane p_plane); - Plane get_plane() const; - - virtual Vector get_debug_mesh_lines(); - virtual real_t get_enclosing_radius() const { - // Should be infinite? - return 0; - } - - PlaneShape(); -}; -#endif // PLANE_SHAPE_H diff --git a/scene/resources/world_margin_shape.cpp b/scene/resources/world_margin_shape.cpp new file mode 100644 index 0000000000..b5b701327c --- /dev/null +++ b/scene/resources/world_margin_shape.cpp @@ -0,0 +1,95 @@ +/*************************************************************************/ +/* world_margin_shape.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "world_margin_shape.h" + +#include "servers/physics_server.h" + +Vector WorldMarginShape::get_debug_mesh_lines() { + + Plane p = get_plane(); + Vector points; + + Vector3 n1 = p.get_any_perpendicular_normal(); + Vector3 n2 = p.normal.cross(n1).normalized(); + + Vector3 pface[4] = { + p.normal * p.d + n1 * 10.0 + n2 * 10.0, + p.normal * p.d + n1 * 10.0 + n2 * -10.0, + p.normal * p.d + n1 * -10.0 + n2 * -10.0, + p.normal * p.d + n1 * -10.0 + n2 * 10.0, + }; + + points.push_back(pface[0]); + points.push_back(pface[1]); + points.push_back(pface[1]); + points.push_back(pface[2]); + points.push_back(pface[2]); + points.push_back(pface[3]); + points.push_back(pface[3]); + points.push_back(pface[0]); + points.push_back(p.normal * p.d); + points.push_back(p.normal * p.d + p.normal * 3); + + return points; +} + +void WorldMarginShape::_update_shape() { + + PhysicsServer::get_singleton()->shape_set_data(get_shape(), plane); + Shape::_update_shape(); +} + +void WorldMarginShape::set_plane(Plane p_plane) { + + plane = p_plane; + _update_shape(); + notify_change_to_owners(); + _change_notify("plane"); +} + +Plane WorldMarginShape::get_plane() const { + + return plane; +} + +void WorldMarginShape::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_plane", "plane"), &WorldMarginShape::set_plane); + ClassDB::bind_method(D_METHOD("get_plane"), &WorldMarginShape::get_plane); + + ADD_PROPERTY(PropertyInfo(Variant::PLANE, "plane"), "set_plane", "get_plane"); +} + +WorldMarginShape::WorldMarginShape() : + Shape(PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_PLANE)) { + + set_plane(Plane(0, 1, 0, 0)); +} diff --git a/scene/resources/world_margin_shape.h b/scene/resources/world_margin_shape.h new file mode 100644 index 0000000000..055107c956 --- /dev/null +++ b/scene/resources/world_margin_shape.h @@ -0,0 +1,57 @@ +/*************************************************************************/ +/* world_margin_shape.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef world_margin_shape_H +#define world_margin_shape_H + +#include "scene/resources/shape.h" + +class WorldMarginShape : public Shape { + + GDCLASS(WorldMarginShape, Shape); + Plane plane; + +protected: + static void _bind_methods(); + virtual void _update_shape(); + +public: + void set_plane(Plane p_plane); + Plane get_plane() const; + + virtual Vector get_debug_mesh_lines(); + virtual real_t get_enclosing_radius() const { + // Should be infinite? + return 0; + } + + WorldMarginShape(); +}; +#endif // world_margin_shape_H -- cgit v1.2.3