Debian Codegraph @

scene/3d/physics/soft_body_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* soft_body_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/mesh_instance_3d.h"
34 #include "servers/physics_3d/physics_server_3d.h"
35
36 class PhysicsBody3D;
37
38 class SoftBodyRenderingServerHandler : public PhysicsServer3DRenderingServerHandler {
39 friend class SoftBody3D;
40
41 RID mesh;
42 int surface = 0;
43 Vector<uint8_t> buffer;
44 uint32_t stride = 0;
45 uint32_t normal_stride = 0;
46 uint32_t offset_vertices = 0;
47 uint32_t offset_normal = 0;
48
49 uint8_t *write_buffer = nullptr;
50
51 private:
52 SoftBodyRenderingServerHandler();
53 bool is_ready(RID p_mesh_rid) const { return mesh.is_valid() && mesh == p_mesh_rid; }
54 void prepare(RID p_mesh_rid, int p_surface);
55 void clear();
56 void open();
57 void close();
58 void commit_changes();
59
60 public:
61 void set_vertex(int p_vertex_id, const Vector3 &p_vertex) override;
62 void set_normal(int p_vertex_id, const Vector3 &p_normal) override;
63 void set_aabb(const AABB &p_aabb) override;
64 };
65
66 class SoftBody3D : public MeshInstance3D {
67 GDCLASS(SoftBody3D, MeshInstance3D);
68
69 public:
70 enum DisableMode {
71 DISABLE_MODE_REMOVE,
72 DISABLE_MODE_KEEP_ACTIVE,
73 };
74
75 struct PinnedPoint {
76 int point_index = -1;
77 NodePath spatial_attachment_path;
78 Node3D *spatial_attachment = nullptr; // Cache
79 Vector3 offset;
80
81 PinnedPoint();
82 PinnedPoint(const PinnedPoint &obj_tocopy);
83 void operator=(const PinnedPoint &obj);
84 };
85
86 private:
87 SoftBodyRenderingServerHandler *rendering_server_handler = nullptr;
88
89 RID physics_rid;
90
91 DisableMode disable_mode = DISABLE_MODE_REMOVE;
92
93 RID owned_mesh;
94 uint32_t collision_mask = 1;
95 uint32_t collision_layer = 1;
96 NodePath parent_collision_ignore;
97 Vector<PinnedPoint> pinned_points;
98 bool simulation_started = false;
99 bool pinned_points_cache_dirty = true;
100
101 Ref<ArrayMesh> debug_mesh_cache;
102 class MeshInstance3D *debug_mesh = nullptr;
103
104 bool capture_input_on_drag = false;
105 bool ray_pickable = true;
106
107 void _update_pickable();
108
109 void _update_physics_server();
110 void _draw_soft_mesh();
111
112 void _prepare_physics_server();
113 void _become_mesh_owner();
114
115 protected:
116 bool _set(const StringName &p_name, const Variant &p_value);
117 bool _get(const StringName &p_name, Variant &r_ret) const;
118 void _get_property_list(List<PropertyInfo> *p_list) const;
119
120 bool _set_property_pinned_points_indices(const Array &p_indices);
121 bool _set_property_pinned_points_attachment(int p_item, const String &p_what, const Variant &p_value);
122 bool _get_property_pinned_points(int p_item, const String &p_what, Variant &r_ret) const;
123
124 void _notification(int p_what);
125 static void _bind_methods();
126
127 #ifndef DISABLE_DEPRECATED
128 void _pin_point_bind_compat_94684(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path = NodePath());
129 static void _bind_compatibility_methods();
130 #endif
131
132 PackedStringArray get_configuration_warnings() const override;
133
134 public:
135 RID get_physics_rid() const { return physics_rid; }
136
137 void set_collision_mask(uint32_t p_mask);
138 uint32_t get_collision_mask() const;
139
140 void set_collision_layer(uint32_t p_layer);
141 uint32_t get_collision_layer() const;
142
143 void set_collision_layer_value(int p_layer_number, bool p_value);
144 bool get_collision_layer_value(int p_layer_number) const;
145
146 void set_collision_mask_value(int p_layer_number, bool p_value);
147 bool get_collision_mask_value(int p_layer_number) const;
148
149 void set_disable_mode(DisableMode p_mode);
150 DisableMode get_disable_mode() const;
151
152 void set_parent_collision_ignore(const NodePath &p_parent_collision_ignore);
153 const NodePath &get_parent_collision_ignore() const;
154
155 void set_pinned_points_indices(Vector<PinnedPoint> p_pinned_points_indices);
156 Vector<PinnedPoint> get_pinned_points_indices();
157
158 void set_simulation_precision(int p_simulation_precision);
159 int get_simulation_precision();
160
161 void set_total_mass(real_t p_total_mass);
162 real_t get_total_mass();
163
164 void set_linear_stiffness(real_t p_linear_stiffness);
165 real_t get_linear_stiffness();
166
167 void set_shrinking_factor(real_t p_shrinking_factor);
168 real_t get_shrinking_factor();
169
170 void set_pressure_coefficient(real_t p_pressure_coefficient);
171 real_t get_pressure_coefficient();
172
173 void set_damping_coefficient(real_t p_damping_coefficient);
174 real_t get_damping_coefficient();
175
176 void set_drag_coefficient(real_t p_drag_coefficient);
177 real_t get_drag_coefficient();
178
179 TypedArray<PhysicsBody3D> get_collision_exceptions();
180 void add_collision_exception_with(RequiredParam<Node> rp_node);
181 void remove_collision_exception_with(RequiredParam<Node> rp_node);
182
183 Vector3 get_point_transform(int p_point_index);
184
185 void pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path = NodePath(), int p_insert_at = -1);
186 bool is_point_pinned(int p_point_index) const;
187
188 void _pin_point_deferred(int p_point_index, bool pin, const NodePath p_spatial_attachment_path);
189
190 void set_ray_pickable(bool p_ray_pickable);
191 bool is_ray_pickable() const;
192
193 void apply_impulse(int p_point_index, const Vector3 &p_impulse);
194 void apply_force(int p_point_index, const Vector3 &p_force);
195 void apply_central_impulse(const Vector3 &p_impulse);
196 void apply_central_force(const Vector3 &p_force);
197
198 SoftBody3D();
199 ~SoftBody3D();
200
201 private:
202 void _make_cache_dirty();
203 void _update_cache_pin_points_datas();
204
205 void _pin_point_on_physics_server(int p_point_index, bool pin);
206 void _add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path, int p_insert_at = -1);
207 void _reset_points_offsets();
208
209 void _remove_pinned_point(int p_point_index);
210 int _get_pinned_point(int p_point_index, PinnedPoint *&r_point) const;
211 int _has_pinned_point(int p_point_index) const;
212 };
213
214 VARIANT_ENUM_CAST(SoftBody3D::DisableMode);