feat: updated engine version to 4.4-rc1
This commit is contained in:
parent
ee00efde1f
commit
21ba8e33af
5459 changed files with 1128836 additions and 198305 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
from misc.utility.scons_hints import *
|
||||
|
||||
Import("env")
|
||||
|
||||
|
|
|
|||
|
|
@ -352,14 +352,14 @@ void CharacterBody2D::_apply_floor_snap(bool p_wall_as_floor) {
|
|||
floor_normal = result.collision_normal;
|
||||
_set_platform_data(result);
|
||||
|
||||
if (floor_stop_on_slope) {
|
||||
// move and collide may stray the object a bit because of pre un-stucking,
|
||||
// so only ensure that motion happens on floor direction in this case.
|
||||
if (result.travel.length() > margin) {
|
||||
result.travel = up_direction * up_direction.dot(result.travel);
|
||||
} else {
|
||||
result.travel = Vector2();
|
||||
}
|
||||
// Ensure that we only move the body along the up axis, because
|
||||
// move_and_collide may stray the object a bit when getting it unstuck.
|
||||
// Canceling this motion should not affect move_and_slide, as previous
|
||||
// calls to move_and_collide already took care of freeing the body.
|
||||
if (result.travel.length() > margin) {
|
||||
result.travel = up_direction * up_direction.dot(result.travel);
|
||||
} else {
|
||||
result.travel = Vector2();
|
||||
}
|
||||
|
||||
parameters.from.columns[2] += result.travel;
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ void CollisionObject2D::_notification(int p_what) {
|
|||
|
||||
if (!disabled || (disable_mode != DISABLE_MODE_REMOVE)) {
|
||||
Ref<World2D> world_ref = get_world_2d();
|
||||
ERR_FAIL_COND(!world_ref.is_valid());
|
||||
ERR_FAIL_COND(world_ref.is_null());
|
||||
RID space = world_ref->get_space();
|
||||
if (area) {
|
||||
PhysicsServer2D::get_singleton()->area_set_space(rid, space);
|
||||
|
|
@ -582,7 +582,7 @@ void CollisionObject2D::_update_pickable() {
|
|||
}
|
||||
|
||||
PackedStringArray CollisionObject2D::get_configuration_warnings() const {
|
||||
PackedStringArray warnings = Node::get_configuration_warnings();
|
||||
PackedStringArray warnings = Node2D::get_configuration_warnings();
|
||||
|
||||
if (shapes.is_empty()) {
|
||||
warnings.push_back(RTR("This node has no shape, so it can't collide or interact with other objects.\nConsider adding a CollisionShape2D or CollisionPolygon2D as a child to define its shape."));
|
||||
|
|
|
|||
|
|
@ -36,8 +36,6 @@
|
|||
#include "scene/resources/2d/concave_polygon_shape_2d.h"
|
||||
#include "scene/resources/2d/convex_polygon_shape_2d.h"
|
||||
|
||||
#include "thirdparty/misc/polypartition.h"
|
||||
|
||||
void CollisionPolygon2D::_build_polygon() {
|
||||
collision_object->shape_owner_clear_shapes(owner_id);
|
||||
|
||||
|
|
@ -217,7 +215,7 @@ CollisionPolygon2D::BuildMode CollisionPolygon2D::get_build_mode() const {
|
|||
return build_mode;
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
#ifdef DEBUG_ENABLED
|
||||
Rect2 CollisionPolygon2D::_edit_get_rect() const {
|
||||
return aabb;
|
||||
}
|
||||
|
|
@ -232,7 +230,7 @@ bool CollisionPolygon2D::_edit_is_selected_on_click(const Point2 &p_point, doubl
|
|||
#endif
|
||||
|
||||
PackedStringArray CollisionPolygon2D::get_configuration_warnings() const {
|
||||
PackedStringArray warnings = Node::get_configuration_warnings();
|
||||
PackedStringArray warnings = Node2D::get_configuration_warnings();
|
||||
|
||||
if (!Object::cast_to<CollisionObject2D>(get_parent())) {
|
||||
warnings.push_back(RTR("CollisionPolygon2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidBody2D, CharacterBody2D, etc. to give them a shape."));
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ protected:
|
|||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
#ifdef TOOLS_ENABLED
|
||||
#ifdef DEBUG_ENABLED
|
||||
virtual Rect2 _edit_get_rect() const override;
|
||||
virtual bool _edit_use_rect() const override;
|
||||
virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override;
|
||||
|
|
|
|||
|
|
@ -49,11 +49,6 @@ void CollisionShape2D::_update_in_shape_owner(bool p_xform_only) {
|
|||
collision_object->shape_owner_set_one_way_collision_margin(owner_id, one_way_collision_margin);
|
||||
}
|
||||
|
||||
Color CollisionShape2D::_get_default_debug_color() const {
|
||||
SceneTree *st = SceneTree::get_singleton();
|
||||
return st ? st->get_debug_collisions_color() : Color();
|
||||
}
|
||||
|
||||
void CollisionShape2D::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_PARENTED: {
|
||||
|
|
@ -94,7 +89,7 @@ void CollisionShape2D::_notification(int p_what) {
|
|||
break;
|
||||
}
|
||||
|
||||
if (!shape.is_valid()) {
|
||||
if (shape.is_null()) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -166,7 +161,7 @@ Ref<Shape2D> CollisionShape2D::get_shape() const {
|
|||
}
|
||||
|
||||
bool CollisionShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
|
||||
if (!shape.is_valid()) {
|
||||
if (shape.is_null()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -174,13 +169,13 @@ bool CollisionShape2D::_edit_is_selected_on_click(const Point2 &p_point, double
|
|||
}
|
||||
|
||||
PackedStringArray CollisionShape2D::get_configuration_warnings() const {
|
||||
PackedStringArray warnings = Node::get_configuration_warnings();
|
||||
PackedStringArray warnings = Node2D::get_configuration_warnings();
|
||||
|
||||
CollisionObject2D *col_object = Object::cast_to<CollisionObject2D>(get_parent());
|
||||
if (col_object == nullptr) {
|
||||
warnings.push_back(RTR("CollisionShape2D only serves to provide a collision shape to a CollisionObject2D derived node.\nPlease only use it as a child of Area2D, StaticBody2D, RigidBody2D, CharacterBody2D, etc. to give them a shape."));
|
||||
}
|
||||
if (!shape.is_valid()) {
|
||||
if (shape.is_null()) {
|
||||
warnings.push_back(RTR("A shape must be provided for CollisionShape2D to function. Please create a shape resource for it!"));
|
||||
}
|
||||
if (one_way_collision && Object::cast_to<Area2D>(col_object)) {
|
||||
|
|
@ -190,7 +185,7 @@ PackedStringArray CollisionShape2D::get_configuration_warnings() const {
|
|||
Ref<ConvexPolygonShape2D> convex = shape;
|
||||
Ref<ConcavePolygonShape2D> concave = shape;
|
||||
if (convex.is_valid() || concave.is_valid()) {
|
||||
warnings.push_back(RTR("Polygon-based shapes are not meant be used nor edited directly through the CollisionShape2D node. Please use the CollisionPolygon2D node instead."));
|
||||
warnings.push_back(RTR("The CollisionShape2D node has limited editing options for polygon-based shapes. Consider using a CollisionPolygon2D node instead."));
|
||||
}
|
||||
|
||||
return warnings;
|
||||
|
|
@ -232,7 +227,16 @@ real_t CollisionShape2D::get_one_way_collision_margin() const {
|
|||
return one_way_collision_margin;
|
||||
}
|
||||
|
||||
Color CollisionShape2D::_get_default_debug_color() const {
|
||||
const SceneTree *st = SceneTree::get_singleton();
|
||||
return st ? st->get_debug_collisions_color() : Color(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
void CollisionShape2D::set_debug_color(const Color &p_color) {
|
||||
if (debug_color == p_color) {
|
||||
return;
|
||||
}
|
||||
|
||||
debug_color = p_color;
|
||||
queue_redraw();
|
||||
}
|
||||
|
|
@ -241,6 +245,8 @@ Color CollisionShape2D::get_debug_color() const {
|
|||
return debug_color;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
|
||||
bool CollisionShape2D::_property_can_revert(const StringName &p_name) const {
|
||||
if (p_name == "debug_color") {
|
||||
return true;
|
||||
|
|
@ -266,6 +272,8 @@ void CollisionShape2D::_validate_property(PropertyInfo &p_property) const {
|
|||
}
|
||||
}
|
||||
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
void CollisionShape2D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_shape", "shape"), &CollisionShape2D::set_shape);
|
||||
ClassDB::bind_method(D_METHOD("get_shape"), &CollisionShape2D::get_shape);
|
||||
|
|
@ -275,16 +283,18 @@ void CollisionShape2D::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("is_one_way_collision_enabled"), &CollisionShape2D::is_one_way_collision_enabled);
|
||||
ClassDB::bind_method(D_METHOD("set_one_way_collision_margin", "margin"), &CollisionShape2D::set_one_way_collision_margin);
|
||||
ClassDB::bind_method(D_METHOD("get_one_way_collision_margin"), &CollisionShape2D::get_one_way_collision_margin);
|
||||
ClassDB::bind_method(D_METHOD("set_debug_color", "color"), &CollisionShape2D::set_debug_color);
|
||||
ClassDB::bind_method(D_METHOD("get_debug_color"), &CollisionShape2D::get_debug_color);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D"), "set_shape", "get_shape");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disabled"), "set_disabled", "is_disabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_way_collision"), "set_one_way_collision", "is_one_way_collision_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "one_way_collision_margin", PROPERTY_HINT_RANGE, "0,128,0.1,suffix:px"), "set_one_way_collision_margin", "get_one_way_collision_margin");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_debug_color", "color"), &CollisionShape2D::set_debug_color);
|
||||
ClassDB::bind_method(D_METHOD("get_debug_color"), &CollisionShape2D::get_debug_color);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "debug_color"), "set_debug_color", "get_debug_color");
|
||||
// Default value depends on a project setting, override for doc generation purposes.
|
||||
ADD_PROPERTY_DEFAULT("debug_color", Color());
|
||||
ADD_PROPERTY_DEFAULT("debug_color", Color(0.0, 0.0, 0.0, 0.0));
|
||||
}
|
||||
|
||||
CollisionShape2D::CollisionShape2D() {
|
||||
|
|
|
|||
|
|
@ -45,25 +45,32 @@ class CollisionShape2D : public Node2D {
|
|||
bool disabled = false;
|
||||
bool one_way_collision = false;
|
||||
real_t one_way_collision_margin = 1.0;
|
||||
Color debug_color;
|
||||
|
||||
void _shape_changed();
|
||||
void _update_in_shape_owner(bool p_xform_only = false);
|
||||
|
||||
// Not wrapped in `#ifdef DEBUG_ENABLED` as it is used for rendering.
|
||||
Color debug_color = Color(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
Color _get_default_debug_color() const;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
bool _property_can_revert(const StringName &p_name) const;
|
||||
bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
|
||||
void _validate_property(PropertyInfo &p_property) const;
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
#ifdef TOOLS_ENABLED
|
||||
#ifdef DEBUG_ENABLED
|
||||
virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override;
|
||||
#else
|
||||
virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;
|
||||
#endif // TOOLS_ENABLED
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
void set_shape(const Ref<Shape2D> &p_shape);
|
||||
Ref<Shape2D> get_shape() const;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
from misc.utility.scons_hints import *
|
||||
|
||||
Import("env")
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@
|
|||
|
||||
#include "kinematic_collision_2d.h"
|
||||
|
||||
#include "scene/2d/physics/character_body_2d.h"
|
||||
#include "scene/2d/physics/physics_body_2d.h"
|
||||
|
||||
Vector2 KinematicCollision2D::get_position() const {
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ void PhysicalBone2D::_find_joint_child() {
|
|||
}
|
||||
|
||||
PackedStringArray PhysicalBone2D::get_configuration_warnings() const {
|
||||
PackedStringArray warnings = Node::get_configuration_warnings();
|
||||
PackedStringArray warnings = RigidBody2D::get_configuration_warnings();
|
||||
|
||||
if (!parent_skeleton) {
|
||||
warnings.push_back(RTR("A PhysicalBone2D only works with a Skeleton2D or another PhysicalBone2D as a parent node!"));
|
||||
|
|
|
|||
|
|
@ -126,8 +126,7 @@ bool PhysicsBody2D::test_move(const Transform2D &p_from, const Vector2 &p_motion
|
|||
PhysicsServer2D::MotionResult *r = nullptr;
|
||||
PhysicsServer2D::MotionResult temp_result;
|
||||
if (r_collision.is_valid()) {
|
||||
// Needs const_cast because method bindings don't support non-const Ref.
|
||||
r = const_cast<PhysicsServer2D::MotionResult *>(&r_collision->result);
|
||||
r = &r_collision->result;
|
||||
} else {
|
||||
r = &temp_result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@
|
|||
#ifndef PHYSICS_BODY_2D_H
|
||||
#define PHYSICS_BODY_2D_H
|
||||
|
||||
#include "core/templates/vset.h"
|
||||
#include "scene/2d/physics/collision_object_2d.h"
|
||||
#include "scene/2d/physics/kinematic_collision_2d.h"
|
||||
#include "scene/resources/physics_material.h"
|
||||
|
|
|
|||
|
|
@ -641,7 +641,7 @@ void RigidBody2D::_notification(int p_what) {
|
|||
PackedStringArray RigidBody2D::get_configuration_warnings() const {
|
||||
Transform2D t = get_transform();
|
||||
|
||||
PackedStringArray warnings = CollisionObject2D::get_configuration_warnings();
|
||||
PackedStringArray warnings = PhysicsBody2D::get_configuration_warnings();
|
||||
|
||||
if (ABS(t.columns[0].length() - 1.0) > 0.05 || ABS(t.columns[1].length() - 1.0) > 0.05) {
|
||||
warnings.push_back(RTR("Size changes to RigidBody2D will be overridden by the physics engine when running.\nChange the size in children collision shapes instead."));
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@
|
|||
#ifndef RIGID_BODY_2D_H
|
||||
#define RIGID_BODY_2D_H
|
||||
|
||||
#include "scene/2d/physics/static_body_2d.h"
|
||||
#include "core/templates/vset.h"
|
||||
#include "scene/2d/physics/physics_body_2d.h"
|
||||
|
||||
class RigidBody2D : public PhysicsBody2D {
|
||||
GDCLASS(RigidBody2D, PhysicsBody2D);
|
||||
|
|
|
|||
|
|
@ -32,9 +32,8 @@
|
|||
|
||||
#include "core/config/engine.h"
|
||||
#include "scene/2d/physics/collision_object_2d.h"
|
||||
#include "scene/2d/physics/physics_body_2d.h"
|
||||
#include "scene/resources/2d/circle_shape_2d.h"
|
||||
#include "servers/physics_2d/godot_physics_server_2d.h"
|
||||
#include "scene/resources/world_2d.h"
|
||||
#include "servers/physics_server_2d.h"
|
||||
|
||||
void ShapeCast2D::set_target_position(const Vector2 &p_point) {
|
||||
target_position = p_point;
|
||||
|
|
@ -382,7 +381,7 @@ bool ShapeCast2D::is_collide_with_bodies_enabled() const {
|
|||
return collide_with_bodies;
|
||||
}
|
||||
|
||||
Array ShapeCast2D::_get_collision_result() const {
|
||||
Array ShapeCast2D::get_collision_result() const {
|
||||
Array ret;
|
||||
|
||||
for (int i = 0; i < result.size(); ++i) {
|
||||
|
|
@ -464,7 +463,7 @@ void ShapeCast2D::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &ShapeCast2D::set_collide_with_bodies);
|
||||
ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &ShapeCast2D::is_collide_with_bodies_enabled);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_get_collision_result"), &ShapeCast2D::_get_collision_result);
|
||||
ClassDB::bind_method(D_METHOD("get_collision_result"), &ShapeCast2D::get_collision_result);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D"), "set_shape", "get_shape");
|
||||
|
|
@ -473,7 +472,7 @@ void ShapeCast2D::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin", PROPERTY_HINT_RANGE, "0,100,0.01,suffix:px"), "set_margin", "get_margin");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_results"), "set_max_results", "get_max_results");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_mask", "get_collision_mask");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "collision_result", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "", "_get_collision_result");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "collision_result", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "", "get_collision_result");
|
||||
ADD_GROUP("Collide With", "collide_with");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collide_with_areas", "is_collide_with_areas_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collide_with_bodies", "is_collide_with_bodies_enabled");
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "scene/resources/2d/shape_2d.h"
|
||||
#include "scene/resources/world_2d.h"
|
||||
#include "servers/physics_server_2d.h"
|
||||
|
||||
class CollisionObject2D;
|
||||
|
||||
|
|
@ -60,7 +60,6 @@ class ShapeCast2D : public Node2D {
|
|||
real_t collision_safe_fraction = 1.0;
|
||||
real_t collision_unsafe_fraction = 1.0;
|
||||
|
||||
Array _get_collision_result() const;
|
||||
void _shape_changed();
|
||||
|
||||
protected:
|
||||
|
|
@ -102,6 +101,7 @@ public:
|
|||
void force_shapecast_update();
|
||||
bool is_colliding() const;
|
||||
|
||||
Array get_collision_result() const;
|
||||
int get_collision_count() const;
|
||||
Object *get_collider(int p_idx) const;
|
||||
RID get_collider_rid(int p_idx) const;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,18 @@
|
|||
|
||||
#include "static_body_2d.h"
|
||||
|
||||
#include "scene/resources/2d/capsule_shape_2d.h"
|
||||
#include "scene/resources/2d/circle_shape_2d.h"
|
||||
#include "scene/resources/2d/concave_polygon_shape_2d.h"
|
||||
#include "scene/resources/2d/convex_polygon_shape_2d.h"
|
||||
#include "scene/resources/2d/navigation_mesh_source_geometry_data_2d.h"
|
||||
#include "scene/resources/2d/navigation_polygon.h"
|
||||
#include "scene/resources/2d/rectangle_shape_2d.h"
|
||||
#include "servers/navigation_server_2d.h"
|
||||
|
||||
Callable StaticBody2D::_navmesh_source_geometry_parsing_callback;
|
||||
RID StaticBody2D::_navmesh_source_geometry_parser;
|
||||
|
||||
void StaticBody2D::set_constant_linear_velocity(const Vector2 &p_vel) {
|
||||
constant_linear_velocity = p_vel;
|
||||
|
||||
|
|
@ -77,6 +89,131 @@ void StaticBody2D::_reload_physics_characteristics() {
|
|||
}
|
||||
}
|
||||
|
||||
void StaticBody2D::navmesh_parse_init() {
|
||||
ERR_FAIL_NULL(NavigationServer2D::get_singleton());
|
||||
if (!_navmesh_source_geometry_parser.is_valid()) {
|
||||
_navmesh_source_geometry_parsing_callback = callable_mp_static(&StaticBody2D::navmesh_parse_source_geometry);
|
||||
_navmesh_source_geometry_parser = NavigationServer2D::get_singleton()->source_geometry_parser_create();
|
||||
NavigationServer2D::get_singleton()->source_geometry_parser_set_callback(_navmesh_source_geometry_parser, _navmesh_source_geometry_parsing_callback);
|
||||
}
|
||||
}
|
||||
|
||||
void StaticBody2D::navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_node) {
|
||||
StaticBody2D *static_body = Object::cast_to<StaticBody2D>(p_node);
|
||||
|
||||
if (static_body == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
NavigationPolygon::ParsedGeometryType parsed_geometry_type = p_navigation_mesh->get_parsed_geometry_type();
|
||||
if (!(parsed_geometry_type == NavigationPolygon::PARSED_GEOMETRY_STATIC_COLLIDERS || parsed_geometry_type == NavigationPolygon::PARSED_GEOMETRY_BOTH)) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t parsed_collision_mask = p_navigation_mesh->get_parsed_collision_mask();
|
||||
if (!(static_body->get_collision_layer() & parsed_collision_mask)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<uint32_t> shape_owners;
|
||||
static_body->get_shape_owners(&shape_owners);
|
||||
|
||||
for (uint32_t shape_owner : shape_owners) {
|
||||
if (static_body->is_shape_owner_disabled(shape_owner)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const int shape_count = static_body->shape_owner_get_shape_count(shape_owner);
|
||||
|
||||
for (int shape_index = 0; shape_index < shape_count; shape_index++) {
|
||||
Ref<Shape2D> s = static_body->shape_owner_get_shape(shape_owner, shape_index);
|
||||
|
||||
if (s.is_null()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const Transform2D static_body_xform = p_source_geometry_data->root_node_transform * static_body->get_global_transform() * static_body->shape_owner_get_transform(shape_owner);
|
||||
|
||||
RectangleShape2D *rectangle_shape = Object::cast_to<RectangleShape2D>(*s);
|
||||
if (rectangle_shape) {
|
||||
Vector<Vector2> shape_outline;
|
||||
|
||||
const Vector2 &rectangle_size = rectangle_shape->get_size();
|
||||
|
||||
shape_outline.resize(5);
|
||||
shape_outline.write[0] = static_body_xform.xform(-rectangle_size * 0.5);
|
||||
shape_outline.write[1] = static_body_xform.xform(Vector2(rectangle_size.x, -rectangle_size.y) * 0.5);
|
||||
shape_outline.write[2] = static_body_xform.xform(rectangle_size * 0.5);
|
||||
shape_outline.write[3] = static_body_xform.xform(Vector2(-rectangle_size.x, rectangle_size.y) * 0.5);
|
||||
shape_outline.write[4] = static_body_xform.xform(-rectangle_size * 0.5);
|
||||
|
||||
p_source_geometry_data->add_obstruction_outline(shape_outline);
|
||||
}
|
||||
|
||||
CapsuleShape2D *capsule_shape = Object::cast_to<CapsuleShape2D>(*s);
|
||||
if (capsule_shape) {
|
||||
const real_t capsule_height = capsule_shape->get_height();
|
||||
const real_t capsule_radius = capsule_shape->get_radius();
|
||||
|
||||
Vector<Vector2> shape_outline;
|
||||
const real_t turn_step = Math_TAU / 12.0;
|
||||
shape_outline.resize(14);
|
||||
int shape_outline_inx = 0;
|
||||
for (int i = 0; i < 12; i++) {
|
||||
Vector2 ofs = Vector2(0, (i > 3 && i <= 9) ? -capsule_height * 0.5 + capsule_radius : capsule_height * 0.5 - capsule_radius);
|
||||
|
||||
shape_outline.write[shape_outline_inx] = static_body_xform.xform(Vector2(Math::sin(i * turn_step), Math::cos(i * turn_step)) * capsule_radius + ofs);
|
||||
shape_outline_inx += 1;
|
||||
if (i == 3 || i == 9) {
|
||||
shape_outline.write[shape_outline_inx] = static_body_xform.xform(Vector2(Math::sin(i * turn_step), Math::cos(i * turn_step)) * capsule_radius - ofs);
|
||||
shape_outline_inx += 1;
|
||||
}
|
||||
}
|
||||
|
||||
p_source_geometry_data->add_obstruction_outline(shape_outline);
|
||||
}
|
||||
|
||||
CircleShape2D *circle_shape = Object::cast_to<CircleShape2D>(*s);
|
||||
if (circle_shape) {
|
||||
const real_t circle_radius = circle_shape->get_radius();
|
||||
|
||||
Vector<Vector2> shape_outline;
|
||||
int circle_edge_count = 12;
|
||||
shape_outline.resize(circle_edge_count);
|
||||
|
||||
const real_t turn_step = Math_TAU / real_t(circle_edge_count);
|
||||
for (int i = 0; i < circle_edge_count; i++) {
|
||||
shape_outline.write[i] = static_body_xform.xform(Vector2(Math::cos(i * turn_step), Math::sin(i * turn_step)) * circle_radius);
|
||||
}
|
||||
|
||||
p_source_geometry_data->add_obstruction_outline(shape_outline);
|
||||
}
|
||||
|
||||
ConcavePolygonShape2D *concave_polygon_shape = Object::cast_to<ConcavePolygonShape2D>(*s);
|
||||
if (concave_polygon_shape) {
|
||||
Vector<Vector2> shape_outline = concave_polygon_shape->get_segments();
|
||||
|
||||
for (int i = 0; i < shape_outline.size(); i++) {
|
||||
shape_outline.write[i] = static_body_xform.xform(shape_outline[i]);
|
||||
}
|
||||
|
||||
p_source_geometry_data->add_obstruction_outline(shape_outline);
|
||||
}
|
||||
|
||||
ConvexPolygonShape2D *convex_polygon_shape = Object::cast_to<ConvexPolygonShape2D>(*s);
|
||||
if (convex_polygon_shape) {
|
||||
Vector<Vector2> shape_outline = convex_polygon_shape->get_points();
|
||||
|
||||
for (int i = 0; i < shape_outline.size(); i++) {
|
||||
shape_outline.write[i] = static_body_xform.xform(shape_outline[i]);
|
||||
}
|
||||
|
||||
p_source_geometry_data->add_obstruction_outline(shape_outline);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StaticBody2D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_constant_linear_velocity", "vel"), &StaticBody2D::set_constant_linear_velocity);
|
||||
ClassDB::bind_method(D_METHOD("set_constant_angular_velocity", "vel"), &StaticBody2D::set_constant_angular_velocity);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@
|
|||
|
||||
#include "scene/2d/physics/physics_body_2d.h"
|
||||
|
||||
class NavigationPolygon;
|
||||
class NavigationMeshSourceGeometryData2D;
|
||||
|
||||
class StaticBody2D : public PhysicsBody2D {
|
||||
GDCLASS(StaticBody2D, PhysicsBody2D);
|
||||
|
||||
|
|
@ -57,6 +60,14 @@ public:
|
|||
|
||||
StaticBody2D(PhysicsServer2D::BodyMode p_mode = PhysicsServer2D::BODY_MODE_STATIC);
|
||||
|
||||
private:
|
||||
static Callable _navmesh_source_geometry_parsing_callback;
|
||||
static RID _navmesh_source_geometry_parser;
|
||||
|
||||
public:
|
||||
static void navmesh_parse_init();
|
||||
static void navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_node);
|
||||
|
||||
private:
|
||||
void _reload_physics_characteristics();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue