Debian Codegraph @

scene/3d/physics/shape_cast_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* shape_cast_3d.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "scene/3d/node_3d.h"
34 #include "scene/resources/3d/shape_3d.h"
35
36 class CollisionObject3D;
37
38 class ShapeCast3D : public Node3D {
39 GDCLASS(ShapeCast3D, Node3D);
40
41 bool enabled = true;
42 #ifndef DISABLE_DEPRECATED
43 void resource_changed(Ref<Resource> p_res);
44 #endif
45
46 Ref<Shape3D> shape;
47 RID shape_rid;
48 Vector3 target_position = Vector3(0, -1, 0);
49
50 HashSet<RID> exclude;
51 real_t margin = 0.0;
52 uint32_t collision_mask = 1;
53 bool exclude_parent_body = true;
54 bool collide_with_areas = false;
55 bool collide_with_bodies = true;
56
57 Ref<Material> debug_material;
58 Color debug_shape_custom_color = Color(0.0, 0.0, 0.0);
59 Vector<Vector3> debug_shape_vertices;
60 Vector<Vector3> debug_line_vertices;
61
62 void _create_debug_shape();
63 void _update_debug_shape();
64 void _update_debug_shape_material(bool p_check_collision = false);
65 void _update_debug_shape_vertices();
66 void _clear_debug_shape();
67
68 // Result
69 int max_results = 32;
70 Vector<PhysicsDirectSpaceState3D::ShapeRestInfo> result;
71 bool collided = false;
72 real_t collision_safe_fraction = 1.0;
73 real_t collision_unsafe_fraction = 1.0;
74
75 RID debug_instance;
76 Ref<ArrayMesh> debug_mesh;
77
78 protected:
79 void _notification(int p_what);
80 void _update_shapecast_state();
81 void _shape_changed();
82 static void _bind_methods();
83
84 public:
85 void set_collide_with_areas(bool p_clip);
86 bool is_collide_with_areas_enabled() const;
87
88 void set_collide_with_bodies(bool p_clip);
89 bool is_collide_with_bodies_enabled() const;
90
91 void set_enabled(bool p_enabled);
92 bool is_enabled() const;
93
94 void set_shape(const Ref<Shape3D> &p_shape);
95 Ref<Shape3D> get_shape() const;
96
97 void set_target_position(const Vector3 &p_point);
98 Vector3 get_target_position() const;
99
100 void set_margin(real_t p_margin);
101 real_t get_margin() const;
102
103 void set_max_results(int p_max_results);
104 int get_max_results() const;
105
106 void set_collision_mask(uint32_t p_mask);
107 uint32_t get_collision_mask() const;
108
109 void set_collision_mask_value(int p_layer_number, bool p_value);
110 bool get_collision_mask_value(int p_layer_number) const;
111
112 void set_exclude_parent_body(bool p_exclude_parent_body);
113 bool get_exclude_parent_body() const;
114
115 const Color &get_debug_shape_custom_color() const;
116 void set_debug_shape_custom_color(const Color &p_color);
117
118 const Vector<Vector3> &get_debug_shape_vertices() const;
119 const Vector<Vector3> &get_debug_line_vertices() const;
120
121 Ref<StandardMaterial3D> get_debug_material();
122
123 Array get_collision_result() const;
124 int get_collision_count() const;
125 Object *get_collider(int p_idx) const;
126 RID get_collider_rid(int p_idx) const;
127 int get_collider_shape(int p_idx) const;
128 Vector3 get_collision_point(int p_idx) const;
129 Vector3 get_collision_normal(int p_idx) const;
130
131 real_t get_closest_collision_safe_fraction() const;
132 real_t get_closest_collision_unsafe_fraction() const;
133
134 void force_shapecast_update();
135 bool is_colliding() const;
136
137 void add_exception_rid(const RID &p_rid);
138 void add_exception(RequiredParam<const CollisionObject3D> rp_node);
139 void remove_exception_rid(const RID &p_rid);
140 void remove_exception(RequiredParam<const CollisionObject3D> rp_node);
141 void clear_exceptions();
142
143 virtual PackedStringArray get_configuration_warnings() const override;
144 };