| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/main/node.h" |
| 34 |
#include "scene/resources/3d/world_3d.h" |
| 35 |
|
| 36 |
class Node3DGizmo : public RefCounted { |
| 37 |
GDCLASS(Node3DGizmo, RefCounted); |
| 38 |
|
| 39 |
public: |
| 40 |
virtual void create() = 0; |
| 41 |
virtual void transform() = 0; |
| 42 |
virtual void clear() = 0; |
| 43 |
virtual void redraw() = 0; |
| 44 |
virtual void free() = 0; |
| 45 |
|
| 46 |
Node3DGizmo(); |
| 47 |
virtual ~Node3DGizmo() {} |
| 48 |
}; |
| 49 |
|
| 50 |
class Node3D : public Node { |
| 51 |
GDCLASS(Node3D, Node); |
| 52 |
|
| 53 |
friend class SceneTreeFTI; |
| 54 |
friend class SceneTreeFTITests; |
| 55 |
|
| 56 |
public: |
| 57 |
static constexpr AncestralClass static_ancestral_class = AncestralClass::NODE_3D; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
enum RotationEditMode { |
| 63 |
ROTATION_EDIT_MODE_EULER, |
| 64 |
ROTATION_EDIT_MODE_QUATERNION, |
| 65 |
ROTATION_EDIT_MODE_BASIS, |
| 66 |
}; |
| 67 |
|
| 68 |
private: |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
enum TransformDirty { |
| 86 |
DIRTY_NONE = 0, |
| 87 |
DIRTY_EULER_ROTATION_AND_SCALE = 1, |
| 88 |
DIRTY_LOCAL_TRANSFORM = 2, |
| 89 |
DIRTY_GLOBAL_TRANSFORM = 4, |
| 90 |
DIRTY_GLOBAL_INTERPOLATED_TRANSFORM = 8, |
| 91 |
}; |
| 92 |
|
| 93 |
struct ClientPhysicsInterpolationData { |
| 94 |
Transform3D global_xform_curr; |
| 95 |
Transform3D global_xform_prev; |
| 96 |
uint64_t current_physics_tick = 0; |
| 97 |
uint64_t timeout_physics_tick = 0; |
| 98 |
}; |
| 99 |
|
| 100 |
mutable SelfList<Node> xform_change; |
| 101 |
SelfList<Node3D> _client_physics_interpolation_node_3d_list; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
struct Data { |
| 106 |
|
| 107 |
|
| 108 |
Transform3D global_transform_interpolated; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
mutable Transform3D global_transform; |
| 114 |
mutable Transform3D local_transform; |
| 115 |
|
| 116 |
|
| 117 |
Transform3D local_transform_prev; |
| 118 |
|
| 119 |
mutable EulerOrder euler_rotation_order = EulerOrder::YXZ; |
| 120 |
mutable Vector3 euler_rotation; |
| 121 |
mutable Vector3 scale = Vector3(1, 1, 1); |
| 122 |
mutable RotationEditMode rotation_edit_mode = ROTATION_EDIT_MODE_EULER; |
| 123 |
|
| 124 |
mutable MTNumeric<uint32_t> dirty; |
| 125 |
|
| 126 |
Viewport *viewport = nullptr; |
| 127 |
|
| 128 |
bool top_level : 1; |
| 129 |
bool inside_world : 1; |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
bool vi_visible : 1; |
| 134 |
|
| 135 |
bool ignore_notification : 1; |
| 136 |
bool notify_local_transform : 1; |
| 137 |
bool notify_transform : 1; |
| 138 |
|
| 139 |
bool visible : 1; |
| 140 |
bool disable_scale : 1; |
| 141 |
|
| 142 |
|
| 143 |
bool fti_on_frame_xform_list : 1; |
| 144 |
bool fti_on_frame_property_list : 1; |
| 145 |
bool fti_on_tick_xform_list : 1; |
| 146 |
bool fti_on_tick_property_list : 1; |
| 147 |
bool fti_global_xform_interp_set : 1; |
| 148 |
bool fti_frame_xform_force_update : 1; |
| 149 |
bool fti_is_identity_xform : 1; |
| 150 |
bool fti_processed : 1; |
| 151 |
|
| 152 |
RID visibility_parent; |
| 153 |
|
| 154 |
Node3D *parent = nullptr; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
LocalVector<Node3D *> node3d_children; |
| 160 |
uint32_t index_in_parent = UINT32_MAX; |
| 161 |
|
| 162 |
ClientPhysicsInterpolationData *client_physics_interpolation_data = nullptr; |
| 163 |
|
| 164 |
#ifdef TOOLS_ENABLED |
| 165 |
Vector<Ref<Node3DGizmo>> gizmos; |
| 166 |
bool gizmos_requested : 1; |
| 167 |
bool gizmos_disabled : 1; |
| 168 |
bool gizmos_dirty : 1; |
| 169 |
bool transform_gizmo_visible : 1; |
| 170 |
#endif |
| 171 |
|
| 172 |
} data; |
| 173 |
|
| 174 |
NodePath visibility_parent_path; |
| 175 |
|
| 176 |
_FORCE_INLINE_ uint32_t _read_dirty_mask() const { return is_group_processing() ? data.dirty.mt.get() : data.dirty.st; } |
| 177 |
_FORCE_INLINE_ bool _test_dirty_bits(uint32_t p_bits) const { return is_group_processing() ? data.dirty.mt.bit_and(p_bits) : (data.dirty.st & p_bits); } |
| 178 |
void _replace_dirty_mask(uint32_t p_mask) const; |
| 179 |
void _set_dirty_bits(uint32_t p_bits) const; |
| 180 |
void _clear_dirty_bits(uint32_t p_bits) const; |
| 181 |
|
| 182 |
void _update_gizmos(); |
| 183 |
void _notify_dirty(); |
| 184 |
void _propagate_transform_changed(Node3D *p_origin); |
| 185 |
|
| 186 |
void _propagate_visibility_changed(); |
| 187 |
|
| 188 |
void _propagate_visibility_parent(); |
| 189 |
void _update_visibility_parent(bool p_update_root); |
| 190 |
void _propagate_transform_changed_deferred(); |
| 191 |
|
| 192 |
protected: |
| 193 |
_FORCE_INLINE_ void set_ignore_transform_notification(bool p_ignore) { data.ignore_notification = p_ignore; } |
| 194 |
|
| 195 |
_FORCE_INLINE_ void _update_local_transform() const; |
| 196 |
_FORCE_INLINE_ void _update_rotation_and_scale() const; |
| 197 |
|
| 198 |
void _set_vi_visible(bool p_visible) { data.vi_visible = p_visible; } |
| 199 |
bool _is_vi_visible() const { return data.vi_visible; } |
| 200 |
Transform3D _get_global_transform_interpolated(real_t p_interpolation_fraction); |
| 201 |
const Transform3D &_get_cached_global_transform_interpolated() const { return data.global_transform_interpolated; } |
| 202 |
void _disable_client_physics_interpolation(); |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
void fti_notify_node_changed(bool p_transform_changed = true); |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
virtual void fti_update_servers_xform() {} |
| 215 |
virtual void fti_update_servers_property() {} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
virtual void fti_pump_xform(); |
| 223 |
virtual void fti_pump_property() {} |
| 224 |
|
| 225 |
void _notification(int p_what); |
| 226 |
static void _bind_methods(); |
| 227 |
|
| 228 |
void _validate_property(PropertyInfo &p_property) const; |
| 229 |
|
| 230 |
bool _property_can_revert(const StringName &p_name) const; |
| 231 |
bool _property_get_revert(const StringName &p_name, Variant &r_property) const; |
| 232 |
|
| 233 |
public: |
| 234 |
enum { |
| 235 |
NOTIFICATION_TRANSFORM_CHANGED = SceneTree::NOTIFICATION_TRANSFORM_CHANGED, |
| 236 |
NOTIFICATION_ENTER_WORLD = 41, |
| 237 |
NOTIFICATION_EXIT_WORLD = 42, |
| 238 |
NOTIFICATION_VISIBILITY_CHANGED = 43, |
| 239 |
NOTIFICATION_LOCAL_TRANSFORM_CHANGED = 44, |
| 240 |
}; |
| 241 |
|
| 242 |
Node3D *get_parent_node_3d() const; |
| 243 |
|
| 244 |
Ref<World3D> get_world_3d() const; |
| 245 |
|
| 246 |
void set_position(const Vector3 &p_position); |
| 247 |
|
| 248 |
void set_rotation_edit_mode(RotationEditMode p_mode); |
| 249 |
RotationEditMode get_rotation_edit_mode() const; |
| 250 |
|
| 251 |
void set_rotation_order(EulerOrder p_order); |
| 252 |
void set_rotation(const Vector3 &p_euler_rad); |
| 253 |
void set_rotation_degrees(const Vector3 &p_euler_degrees); |
| 254 |
void set_scale(const Vector3 &p_scale); |
| 255 |
|
| 256 |
void set_global_position(const Vector3 &p_position); |
| 257 |
void set_global_basis(const Basis &p_basis); |
| 258 |
void set_global_rotation(const Vector3 &p_euler_rad); |
| 259 |
void set_global_rotation_degrees(const Vector3 &p_euler_degrees); |
| 260 |
|
| 261 |
Vector3 get_position() const; |
| 262 |
|
| 263 |
EulerOrder get_rotation_order() const; |
| 264 |
Vector3 get_rotation() const; |
| 265 |
Vector3 get_rotation_degrees() const; |
| 266 |
Vector3 get_scale() const; |
| 267 |
|
| 268 |
Vector3 get_global_position() const; |
| 269 |
Basis get_global_basis() const; |
| 270 |
Vector3 get_global_rotation() const; |
| 271 |
Vector3 get_global_rotation_degrees() const; |
| 272 |
|
| 273 |
void set_transform(const Transform3D &p_transform); |
| 274 |
void set_basis(const Basis &p_basis); |
| 275 |
void set_quaternion(const Quaternion &p_quaternion); |
| 276 |
void set_global_transform(const Transform3D &p_transform); |
| 277 |
|
| 278 |
Transform3D get_transform() const; |
| 279 |
Basis get_basis() const; |
| 280 |
Quaternion get_quaternion() const; |
| 281 |
Transform3D get_global_transform() const; |
| 282 |
|
| 283 |
Transform3D get_global_transform_interpolated(); |
| 284 |
bool update_client_physics_interpolation_data(); |
| 285 |
|
| 286 |
#ifdef TOOLS_ENABLED |
| 287 |
virtual Transform3D get_global_gizmo_transform() const; |
| 288 |
virtual Transform3D get_local_gizmo_transform() const; |
| 289 |
virtual void set_transform_gizmo_visible(bool p_enabled) { data.transform_gizmo_visible = p_enabled; } |
| 290 |
virtual bool is_transform_gizmo_visible() const { return data.transform_gizmo_visible; } |
| 291 |
#endif |
| 292 |
virtual void reparent(RequiredParam<Node> p_parent, bool p_keep_global_transform = true) override; |
| 293 |
|
| 294 |
void set_disable_gizmos(bool p_enabled); |
| 295 |
void update_gizmos(); |
| 296 |
void set_subgizmo_selection(Ref<Node3DGizmo> p_gizmo, int p_id, Transform3D p_transform = Transform3D()); |
| 297 |
void clear_subgizmo_selection(); |
| 298 |
Vector<Ref<Node3DGizmo>> get_gizmos() const; |
| 299 |
TypedArray<Node3DGizmo> get_gizmos_bind() const; |
| 300 |
void add_gizmo(Ref<Node3DGizmo> p_gizmo); |
| 301 |
void remove_gizmo(Ref<Node3DGizmo> p_gizmo); |
| 302 |
void clear_gizmos(); |
| 303 |
|
| 304 |
void set_as_top_level(bool p_enabled); |
| 305 |
void set_as_top_level_keep_local(bool p_enabled); |
| 306 |
bool is_set_as_top_level() const; |
| 307 |
|
| 308 |
void set_disable_scale(bool p_enabled); |
| 309 |
bool is_scale_disabled() const; |
| 310 |
|
| 311 |
_FORCE_INLINE_ bool is_inside_world() const { return data.inside_world; } |
| 312 |
|
| 313 |
Transform3D get_relative_transform(const Node *p_parent) const; |
| 314 |
|
| 315 |
void rotate(const Vector3 &p_axis, real_t p_angle); |
| 316 |
void rotate_x(real_t p_angle); |
| 317 |
void rotate_y(real_t p_angle); |
| 318 |
void rotate_z(real_t p_angle); |
| 319 |
void translate(const Vector3 &p_offset); |
| 320 |
void scale(const Vector3 &p_ratio); |
| 321 |
|
| 322 |
void rotate_object_local(const Vector3 &p_axis, real_t p_angle); |
| 323 |
void scale_object_local(const Vector3 &p_scale); |
| 324 |
void translate_object_local(const Vector3 &p_offset); |
| 325 |
|
| 326 |
void global_rotate(const Vector3 &p_axis, real_t p_angle); |
| 327 |
void global_scale(const Vector3 &p_scale); |
| 328 |
void global_translate(const Vector3 &p_offset); |
| 329 |
|
| 330 |
void look_at(const Vector3 &p_target, const Vector3 &p_up = Vector3::UP, bool p_use_model_front = false); |
| 331 |
void look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up = Vector3::UP, bool p_use_model_front = false); |
| 332 |
|
| 333 |
Vector3 to_local(Vector3 p_global) const; |
| 334 |
Vector3 to_global(Vector3 p_local) const; |
| 335 |
|
| 336 |
void set_notify_transform(bool p_enabled); |
| 337 |
bool is_transform_notification_enabled() const; |
| 338 |
|
| 339 |
void set_notify_local_transform(bool p_enabled); |
| 340 |
bool is_local_transform_notification_enabled() const; |
| 341 |
|
| 342 |
void orthonormalize(); |
| 343 |
void set_identity(); |
| 344 |
|
| 345 |
void set_visible(bool p_visible); |
| 346 |
void show(); |
| 347 |
void hide(); |
| 348 |
bool is_visible() const; |
| 349 |
bool is_visible_in_tree() const; |
| 350 |
|
| 351 |
void force_update_transform(); |
| 352 |
|
| 353 |
void set_visibility_parent(const NodePath &p_path); |
| 354 |
NodePath get_visibility_parent() const; |
| 355 |
|
| 356 |
Node3D(); |
| 357 |
~Node3D(); |
| 358 |
}; |
| 359 |
|
| 360 |
VARIANT_ENUM_CAST(Node3D::RotationEditMode) |