1/**************************************************************************/
2/* node_3d.cpp */
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#include "node_3d.h"
32
33#include "core/object/message_queue.h"
34#include "scene/3d/visual_instance_3d.h"
35#include "scene/main/viewport.h"
36#include "scene/property_utils.h"
37#include "scene/scene_string_names.h"
38
39/*
40
41 possible algorithms:
42
43 Algorithm 1: (current)
44
45 definition of invalidation: global is invalid
46
47 1) If a node sets a LOCAL, it produces an invalidation of everything above
48 . a) If above is invalid, don't keep invalidating upwards
49 2) If a node sets a GLOBAL, it is converted to LOCAL (and forces validation of everything pending below)
50
51 drawback: setting/reading globals is useful and used very often, and using affine inverses is slow
52
53---
54
55 Algorithm 2: (no longer current)
56
57 definition of invalidation: NONE dirty, LOCAL dirty, GLOBAL dirty
58
59 1) If a node sets a LOCAL, it must climb the tree and set it as GLOBAL dirty
60 . a) marking GLOBALs as dirty up all the tree must be done always
61 2) If a node sets a GLOBAL, it marks local as dirty, and that's all?
62
63 //is clearing the dirty state correct in this case?
64
65 drawback: setting a local down the tree forces many tree walks often
66
67--
68
69future: no idea
70
71 */
72
73Node3DGizmo::Node3DGizmo() {
74}
75
76void Node3D::_notify_dirty() {
77#ifdef TOOLS_ENABLED
78 if ((!data.gizmos.is_empty() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
79#else
80 if (data.notify_transform && !data.ignore_notification && !xform_change.in_list()) {
81
82#endif
83 get_tree()->xform_change_list.add(&xform_change);
84 }
85}
86
87void Node3D::_update_local_transform() const {
88 // This function is called when the local transform (data.local_transform) is dirty and the right value is contained in the Euler rotation and scale.
89 data.local_transform.basis.set_euler_scale(data.euler_rotation, data.scale, data.euler_rotation_order);
90 _clear_dirty_bits(DIRTY_LOCAL_TRANSFORM);
91}
92
93void Node3D::_update_rotation_and_scale() const {
94 // This function is called when the Euler rotation (data.euler_rotation) is dirty and the right value is contained in the local transform
95
96 data.scale = data.local_transform.basis.get_scale();
97 data.euler_rotation = data.local_transform.basis.get_euler_normalized(data.euler_rotation_order);
98 _clear_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE);
99}
100
101void Node3D::_propagate_transform_changed_deferred() {
102 if (is_inside_tree() && !xform_change.in_list()) {
103 get_tree()->xform_change_list.add(&xform_change);
104 }
105}
106
107void Node3D::_propagate_transform_changed(Node3D *p_origin) {
108 if (!is_inside_tree()) {
109 return;
110 }
111
112 for (Node3D *&E : data.children) {
113 if (E->data.top_level) {
114 continue; //don't propagate to a top_level
115 }
116 E->_propagate_transform_changed(p_origin);
117 }
118#ifdef TOOLS_ENABLED
119 if ((!data.gizmos.is_empty() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
120#else
121 if (data.notify_transform && !data.ignore_notification && !xform_change.in_list()) {
122#endif
123 if (likely(is_accessible_from_caller_thread())) {
124 get_tree()->xform_change_list.add(&xform_change);
125 } else {
126 // This should very rarely happen, but if it does at least make sure the notification is received eventually.
127 MessageQueue::get_singleton()->push_callable(callable_mp(this, &Node3D::_propagate_transform_changed_deferred));
128 }
129 }
130 _set_dirty_bits(DIRTY_GLOBAL_TRANSFORM);
131}
132
133void Node3D::_notification(int p_what) {
134 ERR_THREAD_GUARD;
135
136 switch (p_what) {
137 case NOTIFICATION_ENTER_TREE: {
138 ERR_FAIL_NULL(get_tree());
139
140 Node *p = get_parent();
141 if (p) {
142 data.parent = Object::cast_to<Node3D>(p);
143 }
144
145 if (data.parent) {
146 data.C = data.parent->data.children.push_back(this);
147 } else {
148 data.C = nullptr;
149 }
150
151 if (data.top_level && !Engine::get_singleton()->is_editor_hint()) {
152 if (data.parent) {
153 data.local_transform = data.parent->get_global_transform() * get_transform();
154 _replace_dirty_mask(DIRTY_EULER_ROTATION_AND_SCALE); // As local transform was updated, rot/scale should be dirty.
155 }
156 }
157
158 _set_dirty_bits(DIRTY_GLOBAL_TRANSFORM); // Global is always dirty upon entering a scene.
159 _notify_dirty();
160
161 notification(NOTIFICATION_ENTER_WORLD);
162 _update_visibility_parent(true);
163 } break;
164
165 case NOTIFICATION_EXIT_TREE: {
166 notification(NOTIFICATION_EXIT_WORLD, true);
167 if (xform_change.in_list()) {
168 get_tree()->xform_change_list.remove(&xform_change);
169 }
170 if (data.C) {
171 data.parent->data.children.erase(data.C);
172 }
173 data.parent = nullptr;
174 data.C = nullptr;
175 _update_visibility_parent(true);
176 } break;
177
178 case NOTIFICATION_ENTER_WORLD: {
179 data.inside_world = true;
180 data.viewport = nullptr;
181 Node *parent = get_parent();
182 while (parent && !data.viewport) {
183 data.viewport = Object::cast_to<Viewport>(parent);
184 parent = parent->get_parent();
185 }
186
187 ERR_FAIL_NULL(data.viewport);
188
189 if (get_script_instance()) {
190 get_script_instance()->call(SceneStringNames::get_singleton()->_enter_world);
191 }
192
193#ifdef TOOLS_ENABLED
194 if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) {
195 get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringNames::get_singleton()->_spatial_editor_group, SNAME("_request_gizmo_for_id"), get_instance_id());
196 }
197#endif
198 } break;
199
200 case NOTIFICATION_EXIT_WORLD: {
201#ifdef TOOLS_ENABLED
202 clear_gizmos();
203#endif
204
205 if (get_script_instance()) {
206 get_script_instance()->call(SceneStringNames::get_singleton()->_exit_world);
207 }
208
209 data.viewport = nullptr;
210 data.inside_world = false;
211 } break;
212
213 case NOTIFICATION_TRANSFORM_CHANGED: {
214#ifdef TOOLS_ENABLED
215 for (int i = 0; i < data.gizmos.size(); i++) {
216 data.gizmos.write[i]->transform();
217 }
218#endif
219 } break;
220 }
221}
222
223void Node3D::set_basis(const Basis &p_basis) {
224 ERR_THREAD_GUARD;
225
226 set_transform(Transform3D(p_basis, data.local_transform.origin));
227}
228void Node3D::set_quaternion(const Quaternion &p_quaternion) {
229 ERR_THREAD_GUARD;
230
231 if (_test_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE)) {
232 // We need the scale part, so if these are dirty, update it
233 data.scale = data.local_transform.basis.get_scale();
234 _clear_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE);
235 }
236 data.local_transform.basis = Basis(p_quaternion, data.scale);
237 // Rotscale should not be marked dirty because that would cause precision loss issues with the scale. Instead reconstruct rotation now.
238 data.euler_rotation = data.local_transform.basis.get_euler_normalized(data.euler_rotation_order);
239
240 _replace_dirty_mask(DIRTY_NONE);
241
242 _propagate_transform_changed(this);
243 if (data.notify_local_transform) {
244 notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
245 }
246}
247
248Vector3 Node3D::get_global_position() const {
249 ERR_READ_THREAD_GUARD_V(Vector3());
250 return get_global_transform().get_origin();
251}
252
253Basis Node3D::get_global_basis() const {
254 ERR_READ_THREAD_GUARD_V(Basis());
255 return get_global_transform().get_basis();
256}
257
258void Node3D::set_global_position(const Vector3 &p_position) {
259 ERR_THREAD_GUARD;
260 Transform3D transform = get_global_transform();
261 transform.set_origin(p_position);
262 set_global_transform(transform);
263}
264
265void Node3D::set_global_basis(const Basis &p_basis) {
266 ERR_THREAD_GUARD;
267 Transform3D transform = get_global_transform();
268 transform.set_basis(p_basis);
269 set_global_transform(transform);
270}
271
272Vector3 Node3D::get_global_rotation() const {
273 ERR_READ_THREAD_GUARD_V(Vector3());
274 return get_global_transform().get_basis().get_euler();
275}
276
277Vector3 Node3D::get_global_rotation_degrees() const {
278 ERR_READ_THREAD_GUARD_V(Vector3());
279 Vector3 radians = get_global_rotation();
280 return Vector3(Math::rad_to_deg(radians.x), Math::rad_to_deg(radians.y), Math::rad_to_deg(radians.z));
281}
282
283void Node3D::set_global_rotation(const Vector3 &p_euler_rad) {
284 ERR_THREAD_GUARD;
285 Transform3D transform = get_global_transform();
286 transform.basis = Basis::from_euler(p_euler_rad);
287 set_global_transform(transform);
288}
289
290void Node3D::set_global_rotation_degrees(const Vector3 &p_euler_degrees) {
291 ERR_THREAD_GUARD;
292 Vector3 radians(Math::deg_to_rad(p_euler_degrees.x), Math::deg_to_rad(p_euler_degrees.y), Math::deg_to_rad(p_euler_degrees.z));
293 set_global_rotation(radians);
294}
295
296void Node3D::set_transform(const Transform3D &p_transform) {
297 ERR_THREAD_GUARD;
298 data.local_transform = p_transform;
299 _replace_dirty_mask(DIRTY_EULER_ROTATION_AND_SCALE); // Make rot/scale dirty.
300
301 _propagate_transform_changed(this);
302 if (data.notify_local_transform) {
303 notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
304 }
305}
306
307Basis Node3D::get_basis() const {
308 ERR_READ_THREAD_GUARD_V(Basis());
309 return get_transform().basis;
310}
311
312Quaternion Node3D::get_quaternion() const {
313 return get_transform().basis.get_rotation_quaternion();
314}
315
316void Node3D::set_global_transform(const Transform3D &p_transform) {
317 ERR_THREAD_GUARD;
318 Transform3D xform = (data.parent && !data.top_level)
319 ? data.parent->get_global_transform().affine_inverse() * p_transform
320 : p_transform;
321
322 set_transform(xform);
323}
324
325Transform3D Node3D::get_transform() const {
326 ERR_READ_THREAD_GUARD_V(Transform3D());
327 if (_test_dirty_bits(DIRTY_LOCAL_TRANSFORM)) {
328 // This update can happen if needed over multiple threads.
329 _update_local_transform();
330 }
331
332 return data.local_transform;
333}
334
335Transform3D Node3D::get_global_transform() const {
336 ERR_FAIL_COND_V(!is_inside_tree(), Transform3D());
337
338 /* Due to how threads work at scene level, while this global transform won't be able to be changed from outside a thread,
339 * it is possible that multiple threads can access it while it's dirty from previous work. Due to this, we must ensure that
340 * the dirty/update process is thread safe by utilizing atomic copies.
341 */
342
343 uint32_t dirty = _read_dirty_mask();
344 if (dirty & DIRTY_GLOBAL_TRANSFORM) {
345 if (dirty & DIRTY_LOCAL_TRANSFORM) {
346 _update_local_transform(); // Update local transform atomically.
347 }
348
349 Transform3D new_global;
350 if (data.parent && !data.top_level) {
351 new_global = data.parent->get_global_transform() * data.local_transform;
352 } else {
353 new_global = data.local_transform;
354 }
355
356 if (data.disable_scale) {
357 new_global.basis.orthonormalize();
358 }
359
360 data.global_transform = new_global;
361 _clear_dirty_bits(DIRTY_GLOBAL_TRANSFORM);
362 }
363
364 return data.global_transform;
365}
366
367#ifdef TOOLS_ENABLED
368Transform3D Node3D::get_global_gizmo_transform() const {
369 return get_global_transform();
370}
371
372Transform3D Node3D::get_local_gizmo_transform() const {
373 return get_transform();
374}
375#endif
376
377Node3D *Node3D::get_parent_node_3d() const {
378 ERR_READ_THREAD_GUARD_V(nullptr); // This can't be changed on threads anyway.
379 if (data.top_level) {
380 return nullptr;
381 }
382
383 return Object::cast_to<Node3D>(get_parent());
384}
385
386Transform3D Node3D::get_relative_transform(const Node *p_parent) const {
387 ERR_READ_THREAD_GUARD_V(Transform3D());
388 if (p_parent == this) {
389 return Transform3D();
390 }
391
392 ERR_FAIL_NULL_V(data.parent, Transform3D());
393
394 if (p_parent == data.parent) {
395 return get_transform();
396 } else {
397 return data.parent->get_relative_transform(p_parent) * get_transform();
398 }
399}
400
401void Node3D::set_position(const Vector3 &p_position) {
402 ERR_THREAD_GUARD;
403 data.local_transform.origin = p_position;
404 _propagate_transform_changed(this);
405 if (data.notify_local_transform) {
406 notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
407 }
408}
409
410void Node3D::set_rotation_edit_mode(RotationEditMode p_mode) {
411 ERR_THREAD_GUARD;
412 if (data.rotation_edit_mode == p_mode) {
413 return;
414 }
415
416 bool transform_changed = false;
417 if (data.rotation_edit_mode == ROTATION_EDIT_MODE_BASIS && !_test_dirty_bits(DIRTY_LOCAL_TRANSFORM)) {
418 data.local_transform.orthogonalize();
419 transform_changed = true;
420 }
421
422 data.rotation_edit_mode = p_mode;
423
424 if (p_mode == ROTATION_EDIT_MODE_EULER && _test_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE)) {
425 // If going to Euler mode, ensure that vectors are _not_ dirty, else the retrieved value may be wrong.
426 // Otherwise keep what is there, so switching back and forth between modes does not break the vectors.
427
428 _update_rotation_and_scale();
429 }
430
431 if (transform_changed) {
432 _propagate_transform_changed(this);
433 if (data.notify_local_transform) {
434 notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
435 }
436 }
437
438 notify_property_list_changed();
439}
440
441Node3D::RotationEditMode Node3D::get_rotation_edit_mode() const {
442 ERR_READ_THREAD_GUARD_V(ROTATION_EDIT_MODE_EULER);
443 return data.rotation_edit_mode;
444}
445
446void Node3D::set_rotation_order(EulerOrder p_order) {
447 ERR_THREAD_GUARD;
448 if (data.euler_rotation_order == p_order) {
449 return;
450 }
451
452 ERR_FAIL_INDEX(int32_t(p_order), 6);
453 bool transform_changed = false;
454
455 uint32_t dirty = _read_dirty_mask();
456 if ((dirty & DIRTY_EULER_ROTATION_AND_SCALE)) {
457 _update_rotation_and_scale();
458 } else if ((dirty & DIRTY_LOCAL_TRANSFORM)) {
459 data.euler_rotation = Basis::from_euler(data.euler_rotation, data.euler_rotation_order).get_euler_normalized(p_order);
460 transform_changed = true;
461 } else {
462 _set_dirty_bits(DIRTY_LOCAL_TRANSFORM);
463 transform_changed = true;
464 }
465
466 data.euler_rotation_order = p_order;
467
468 if (transform_changed) {
469 _propagate_transform_changed(this);
470 if (data.notify_local_transform) {
471 notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
472 }
473 }
474 notify_property_list_changed(); // Will change the rotation property.
475}
476
477EulerOrder Node3D::get_rotation_order() const {
478 ERR_READ_THREAD_GUARD_V(EulerOrder::XYZ);
479 return data.euler_rotation_order;
480}
481
482void Node3D::set_rotation(const Vector3 &p_euler_rad) {
483 ERR_THREAD_GUARD;
484 if (_test_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE)) {
485 // Update scale only if rotation and scale are dirty, as rotation will be overridden.
486 data.scale = data.local_transform.basis.get_scale();
487 _clear_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE);
488 }
489
490 data.euler_rotation = p_euler_rad;
491 _replace_dirty_mask(DIRTY_LOCAL_TRANSFORM);
492 _propagate_transform_changed(this);
493 if (data.notify_local_transform) {
494 notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
495 }
496}
497
498void Node3D::set_rotation_degrees(const Vector3 &p_euler_degrees) {
499 ERR_THREAD_GUARD;
500 Vector3 radians(Math::deg_to_rad(p_euler_degrees.x), Math::deg_to_rad(p_euler_degrees.y), Math::deg_to_rad(p_euler_degrees.z));
501 set_rotation(radians);
502}
503
504void Node3D::set_scale(const Vector3 &p_scale) {
505 ERR_THREAD_GUARD;
506 if (_test_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE)) {
507 // Update rotation only if rotation and scale are dirty, as scale will be overridden.
508 data.euler_rotation = data.local_transform.basis.get_euler_normalized(data.euler_rotation_order);
509 _clear_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE);
510 }
511
512 data.scale = p_scale;
513 _replace_dirty_mask(DIRTY_LOCAL_TRANSFORM);
514 _propagate_transform_changed(this);
515 if (data.notify_local_transform) {
516 notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
517 }
518}
519
520Vector3 Node3D::get_position() const {
521 ERR_READ_THREAD_GUARD_V(Vector3());
522 return data.local_transform.origin;
523}
524
525Vector3 Node3D::get_rotation() const {
526 ERR_READ_THREAD_GUARD_V(Vector3());
527 if (_test_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE)) {
528 _update_rotation_and_scale();
529 }
530
531 return data.euler_rotation;
532}
533
534Vector3 Node3D::get_rotation_degrees() const {
535 ERR_READ_THREAD_GUARD_V(Vector3());
536 Vector3 radians = get_rotation();
537 return Vector3(Math::rad_to_deg(radians.x), Math::rad_to_deg(radians.y), Math::rad_to_deg(radians.z));
538}
539
540Vector3 Node3D::get_scale() const {
541 ERR_READ_THREAD_GUARD_V(Vector3());
542 if (_test_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE)) {
543 _update_rotation_and_scale();
544 }
545
546 return data.scale;
547}
548
549void Node3D::update_gizmos() {
550 ERR_THREAD_GUARD;
551#ifdef TOOLS_ENABLED
552 if (!is_inside_world()) {
553 return;
554 }
555
556 if (data.gizmos.is_empty()) {
557 get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringNames::get_singleton()->_spatial_editor_group, SNAME("_request_gizmo_for_id"), get_instance_id());
558 return;
559 }
560 if (data.gizmos_dirty) {
561 return;
562 }
563 data.gizmos_dirty = true;
564 MessageQueue::get_singleton()->push_callable(callable_mp(this, &Node3D::_update_gizmos));
565#endif
566}
567
568void Node3D::set_subgizmo_selection(Ref<Node3DGizmo> p_gizmo, int p_id, Transform3D p_transform) {
569 ERR_THREAD_GUARD;
570#ifdef TOOLS_ENABLED
571 if (!is_inside_world()) {
572 return;
573 }
574
575 if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) {
576 get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_set_subgizmo_selection, this, p_gizmo, p_id, p_transform);
577 }
578#endif
579}
580
581void Node3D::clear_subgizmo_selection() {
582 ERR_THREAD_GUARD;
583#ifdef TOOLS_ENABLED
584 if (!is_inside_world()) {
585 return;
586 }
587
588 if (data.gizmos.is_empty()) {
589 return;
590 }
591
592 if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) {
593 get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_clear_subgizmo_selection, this);
594 }
595#endif
596}
597
598void Node3D::add_gizmo(Ref<Node3DGizmo> p_gizmo) {
599 ERR_THREAD_GUARD;
600#ifdef TOOLS_ENABLED
601 if (data.gizmos_disabled || p_gizmo.is_null()) {
602 return;
603 }
604 data.gizmos.push_back(p_gizmo);
605
606 if (p_gizmo.is_valid() && is_inside_world()) {
607 p_gizmo->create();
608 if (is_visible_in_tree()) {
609 p_gizmo->redraw();
610 }
611 p_gizmo->transform();
612 }
613#endif
614}
615
616void Node3D::remove_gizmo(Ref<Node3DGizmo> p_gizmo) {
617 ERR_THREAD_GUARD;
618#ifdef TOOLS_ENABLED
619 int idx = data.gizmos.find(p_gizmo);
620 if (idx != -1) {
621 p_gizmo->free();
622 data.gizmos.remove_at(idx);
623 }
624#endif
625}
626
627void Node3D::clear_gizmos() {
628 ERR_THREAD_GUARD;
629#ifdef TOOLS_ENABLED
630 for (int i = 0; i < data.gizmos.size(); i++) {
631 data.gizmos.write[i]->free();
632 }
633 data.gizmos.clear();
634#endif
635}
636
637TypedArray<Node3DGizmo> Node3D::get_gizmos_bind() const {
638 ERR_THREAD_GUARD_V(TypedArray<Node3DGizmo>());
639 TypedArray<Node3DGizmo> ret;
640
641#ifdef TOOLS_ENABLED
642 for (int i = 0; i < data.gizmos.size(); i++) {
643 ret.push_back(Variant(data.gizmos[i].ptr()));
644 }
645#endif
646
647 return ret;
648}
649
650Vector<Ref<Node3DGizmo>> Node3D::get_gizmos() const {
651 ERR_THREAD_GUARD_V(Vector<Ref<Node3DGizmo>>());
652#ifdef TOOLS_ENABLED
653 return data.gizmos;
654#else
655 return Vector<Ref<Node3DGizmo>>();
656#endif
657}
658
659void Node3D::_replace_dirty_mask(uint32_t p_mask) const {
660 if (is_group_processing()) {
661 data.dirty.mt.set(p_mask);
662 } else {
663 data.dirty.st = p_mask;
664 }
665}
666
667void Node3D::_set_dirty_bits(uint32_t p_bits) const {
668 if (is_group_processing()) {
669 data.dirty.mt.bit_or(p_bits);
670 } else {
671 data.dirty.st |= p_bits;
672 }
673}
674
675void Node3D::_clear_dirty_bits(uint32_t p_bits) const {
676 if (is_group_processing()) {
677 data.dirty.mt.bit_and(~p_bits);
678 } else {
679 data.dirty.st &= ~p_bits;
680 }
681}
682
683void Node3D::_update_gizmos() {
684#ifdef TOOLS_ENABLED
685 if (data.gizmos_disabled || !is_inside_world() || !data.gizmos_dirty) {
686 data.gizmos_dirty = false;
687 return;
688 }
689 data.gizmos_dirty = false;
690 for (int i = 0; i < data.gizmos.size(); i++) {
691 if (is_visible_in_tree()) {
692 data.gizmos.write[i]->redraw();
693 } else {
694 data.gizmos.write[i]->clear();
695 }
696 }
697#endif
698}
699
700void Node3D::set_disable_gizmos(bool p_enabled) {
701 ERR_THREAD_GUARD;
702#ifdef TOOLS_ENABLED
703 data.gizmos_disabled = p_enabled;
704 if (!p_enabled) {
705 clear_gizmos();
706 }
707#endif
708}
709
710void Node3D::reparent(Node *p_parent, bool p_keep_global_transform) {
711 ERR_THREAD_GUARD;
712 Transform3D temp = get_global_transform();
713 Node::reparent(p_parent);
714 if (p_keep_global_transform) {
715 set_global_transform(temp);
716 }
717}
718
719void Node3D::set_disable_scale(bool p_enabled) {
720 ERR_THREAD_GUARD;
721 data.disable_scale = p_enabled;
722}
723
724bool Node3D::is_scale_disabled() const {
725 ERR_READ_THREAD_GUARD_V(false);
726 return data.disable_scale;
727}
728
729void Node3D::set_as_top_level(bool p_enabled) {
730 ERR_THREAD_GUARD;
731 if (data.top_level == p_enabled) {
732 return;
733 }
734 if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
735 if (p_enabled) {
736 set_transform(get_global_transform());
737 } else if (data.parent) {
738 set_transform(data.parent->get_global_transform().affine_inverse() * get_global_transform());
739 }
740 }
741 data.top_level = p_enabled;
742}
743
744bool Node3D::is_set_as_top_level() const {
745 ERR_READ_THREAD_GUARD_V(false);
746 return data.top_level;
747}
748
749Ref<World3D> Node3D::get_world_3d() const {
750 ERR_READ_THREAD_GUARD_V(Ref<World3D>()); // World3D can only be set from main thread, so it's safe to obtain on threads.
751 ERR_FAIL_COND_V(!is_inside_world(), Ref<World3D>());
752 ERR_FAIL_NULL_V(data.viewport, Ref<World3D>());
753
754 return data.viewport->find_world_3d();
755}
756
757void Node3D::_propagate_visibility_changed() {
758 notification(NOTIFICATION_VISIBILITY_CHANGED);
759 emit_signal(SceneStringNames::get_singleton()->visibility_changed);
760
761#ifdef TOOLS_ENABLED
762 if (!data.gizmos.is_empty()) {
763 data.gizmos_dirty = true;
764 _update_gizmos();
765 }
766#endif
767
768 for (Node3D *c : data.children) {
769 if (!c || !c->data.visible) {
770 continue;
771 }
772 c->_propagate_visibility_changed();
773 }
774}
775
776void Node3D::show() {
777 ERR_MAIN_THREAD_GUARD;
778 set_visible(true);
779}
780
781void Node3D::hide() {
782 ERR_MAIN_THREAD_GUARD;
783 set_visible(false);
784}
785
786void Node3D::set_visible(bool p_visible) {
787 ERR_MAIN_THREAD_GUARD;
788 if (data.visible == p_visible) {
789 return;
790 }
791
792 data.visible = p_visible;
793
794 if (!is_inside_tree()) {
795 return;
796 }
797 _propagate_visibility_changed();
798}
799
800bool Node3D::is_visible() const {
801 ERR_READ_THREAD_GUARD_V(false);
802 return data.visible;
803}
804
805bool Node3D::is_visible_in_tree() const {
806 ERR_READ_THREAD_GUARD_V(false); // Since visibility can only be changed from main thread, this is safe to call.
807 const Node3D *s = this;
808
809 while (s) {
810 if (!s->data.visible) {
811 return false;
812 }
813 s = s->data.parent;
814 }
815
816 return true;
817}
818
819void Node3D::rotate_object_local(const Vector3 &p_axis, real_t p_angle) {
820 ERR_THREAD_GUARD;
821 Transform3D t = get_transform();
822 t.basis.rotate_local(p_axis, p_angle);
823 set_transform(t);
824}
825
826void Node3D::rotate(const Vector3 &p_axis, real_t p_angle) {
827 ERR_THREAD_GUARD;
828 Transform3D t = get_transform();
829 t.basis.rotate(p_axis, p_angle);
830 set_transform(t);
831}
832
833void Node3D::rotate_x(real_t p_angle) {
834 ERR_THREAD_GUARD;
835 Transform3D t = get_transform();
836 t.basis.rotate(Vector3(1, 0, 0), p_angle);
837 set_transform(t);
838}
839
840void Node3D::rotate_y(real_t p_angle) {
841 ERR_THREAD_GUARD;
842 Transform3D t = get_transform();
843 t.basis.rotate(Vector3(0, 1, 0), p_angle);
844 set_transform(t);
845}
846
847void Node3D::rotate_z(real_t p_angle) {
848 ERR_THREAD_GUARD;
849 Transform3D t = get_transform();
850 t.basis.rotate(Vector3(0, 0, 1), p_angle);
851 set_transform(t);
852}
853
854void Node3D::translate(const Vector3 &p_offset) {
855 ERR_THREAD_GUARD;
856 Transform3D t = get_transform();
857 t.translate_local(p_offset);
858 set_transform(t);
859}
860
861void Node3D::translate_object_local(const Vector3 &p_offset) {
862 ERR_THREAD_GUARD;
863 Transform3D t = get_transform();
864
865 Transform3D s;
866 s.translate_local(p_offset);
867 set_transform(t * s);
868}
869
870void Node3D::scale(const Vector3 &p_ratio) {
871 ERR_THREAD_GUARD;
872 Transform3D t = get_transform();
873 t.basis.scale(p_ratio);
874 set_transform(t);
875}
876
877void Node3D::scale_object_local(const Vector3 &p_scale) {
878 ERR_THREAD_GUARD;
879 Transform3D t = get_transform();
880 t.basis.scale_local(p_scale);
881 set_transform(t);
882}
883
884void Node3D::global_rotate(const Vector3 &p_axis, real_t p_angle) {
885 ERR_THREAD_GUARD;
886 Transform3D t = get_global_transform();
887 t.basis.rotate(p_axis, p_angle);
888 set_global_transform(t);
889}
890
891void Node3D::global_scale(const Vector3 &p_scale) {
892 ERR_THREAD_GUARD;
893 Transform3D t = get_global_transform();
894 t.basis.scale(p_scale);
895 set_global_transform(t);
896}
897
898void Node3D::global_translate(const Vector3 &p_offset) {
899 ERR_THREAD_GUARD;
900 Transform3D t = get_global_transform();
901 t.origin += p_offset;
902 set_global_transform(t);
903}
904
905void Node3D::orthonormalize() {
906 ERR_THREAD_GUARD;
907 Transform3D t = get_transform();
908 t.orthonormalize();
909 set_transform(t);
910}
911
912void Node3D::set_identity() {
913 ERR_THREAD_GUARD;
914 set_transform(Transform3D());
915}
916
917void Node3D::look_at(const Vector3 &p_target, const Vector3 &p_up, bool p_use_model_front) {
918 ERR_THREAD_GUARD;
919 ERR_FAIL_COND_MSG(!is_inside_tree(), "Node not inside tree. Use look_at_from_position() instead.");
920 Vector3 origin = get_global_transform().origin;
921 look_at_from_position(origin, p_target, p_up, p_use_model_front);
922}
923
924void Node3D::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up, bool p_use_model_front) {
925 ERR_THREAD_GUARD;
926 ERR_FAIL_COND_MSG(p_pos.is_equal_approx(p_target), "Node origin and target are in the same position, look_at() failed.");
927 ERR_FAIL_COND_MSG(p_up.is_zero_approx(), "The up vector can't be zero, look_at() failed.");
928 ERR_FAIL_COND_MSG(p_up.cross(p_target - p_pos).is_zero_approx(), "Up vector and direction between node origin and target are aligned, look_at() failed.");
929
930 Vector3 forward = p_target - p_pos;
931 Basis lookat_basis = Basis::looking_at(forward, p_up, p_use_model_front);
932 Vector3 original_scale = get_scale();
933 set_global_transform(Transform3D(lookat_basis, p_pos));
934 set_scale(original_scale);
935}
936
937Vector3 Node3D::to_local(Vector3 p_global) const {
938 ERR_READ_THREAD_GUARD_V(Vector3());
939 return get_global_transform().affine_inverse().xform(p_global);
940}
941
942Vector3 Node3D::to_global(Vector3 p_local) const {
943 ERR_READ_THREAD_GUARD_V(Vector3());
944 return get_global_transform().xform(p_local);
945}
946
947void Node3D::set_notify_transform(bool p_enabled) {
948 ERR_THREAD_GUARD;
949 data.notify_transform = p_enabled;
950}
951
952bool Node3D::is_transform_notification_enabled() const {
953 ERR_READ_THREAD_GUARD_V(false);
954 return data.notify_transform;
955}
956
957void Node3D::set_notify_local_transform(bool p_enabled) {
958 ERR_THREAD_GUARD;
959 data.notify_local_transform = p_enabled;
960}
961
962bool Node3D::is_local_transform_notification_enabled() const {
963 ERR_READ_THREAD_GUARD_V(false);
964 return data.notify_local_transform;
965}
966
967void Node3D::force_update_transform() {
968 ERR_THREAD_GUARD;
969 ERR_FAIL_COND(!is_inside_tree());
970 if (!xform_change.in_list()) {
971 return; //nothing to update
972 }
973 get_tree()->xform_change_list.remove(&xform_change);
974
975 notification(NOTIFICATION_TRANSFORM_CHANGED);
976}
977
978void Node3D::_update_visibility_parent(bool p_update_root) {
979 RID new_parent;
980
981 if (!visibility_parent_path.is_empty()) {
982 if (!p_update_root) {
983 return;
984 }
985 Node *parent = get_node_or_null(visibility_parent_path);
986 ERR_FAIL_NULL_MSG(parent, "Can't find visibility parent node at path: " + visibility_parent_path);
987 ERR_FAIL_COND_MSG(parent == this, "The visibility parent can't be the same node.");
988 GeometryInstance3D *gi = Object::cast_to<GeometryInstance3D>(parent);
989 ERR_FAIL_NULL_MSG(gi, "The visibility parent node must be a GeometryInstance3D, at path: " + visibility_parent_path);
990 new_parent = gi ? gi->get_instance() : RID();
991 } else if (data.parent) {
992 new_parent = data.parent->data.visibility_parent;
993 }
994
995 if (new_parent == data.visibility_parent) {
996 return;
997 }
998
999 data.visibility_parent = new_parent;
1000
1001 VisualInstance3D *vi = Object::cast_to<VisualInstance3D>(this);
1002 if (vi) {
1003 RS::get_singleton()->instance_set_visibility_parent(vi->get_instance(), data.visibility_parent);
1004 }
1005
1006 for (Node3D *c : data.children) {
1007 c->_update_visibility_parent(false);
1008 }
1009}
1010
1011void Node3D::set_visibility_parent(const NodePath &p_path) {
1012 ERR_MAIN_THREAD_GUARD;
1013 visibility_parent_path = p_path;
1014 if (is_inside_tree()) {
1015 _update_visibility_parent(true);
1016 }
1017}
1018
1019NodePath Node3D::get_visibility_parent() const {
1020 ERR_READ_THREAD_GUARD_V(NodePath());
1021 return visibility_parent_path;
1022}
1023
1024void Node3D::_validate_property(PropertyInfo &p_property) const {
1025 if (data.rotation_edit_mode != ROTATION_EDIT_MODE_BASIS && p_property.name == "basis") {
1026 p_property.usage = 0;
1027 }
1028 if (data.rotation_edit_mode == ROTATION_EDIT_MODE_BASIS && p_property.name == "scale") {
1029 p_property.usage = 0;
1030 }
1031 if (data.rotation_edit_mode != ROTATION_EDIT_MODE_QUATERNION && p_property.name == "quaternion") {
1032 p_property.usage = 0;
1033 }
1034 if (data.rotation_edit_mode != ROTATION_EDIT_MODE_EULER && p_property.name == "rotation") {
1035 p_property.usage = 0;
1036 }
1037 if (data.rotation_edit_mode != ROTATION_EDIT_MODE_EULER && p_property.name == "rotation_order") {
1038 p_property.usage = 0;
1039 }
1040}
1041
1042bool Node3D::_property_can_revert(const StringName &p_name) const {
1043 if (p_name == "basis") {
1044 return true;
1045 } else if (p_name == "scale") {
1046 return true;
1047 } else if (p_name == "quaternion") {
1048 return true;
1049 } else if (p_name == "rotation") {
1050 return true;
1051 } else if (p_name == "position") {
1052 return true;
1053 }
1054 return false;
1055}
1056
1057bool Node3D::_property_get_revert(const StringName &p_name, Variant &r_property) const {
1058 bool valid = false;
1059
1060 if (p_name == "basis") {
1061 Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
1062 if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
1063 r_property = Transform3D(variant).get_basis();
1064 } else {
1065 r_property = Basis();
1066 }
1067 } else if (p_name == "scale") {
1068 Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
1069 if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
1070 r_property = Transform3D(variant).get_basis().get_scale();
1071 } else {
1072 r_property = Vector3(1.0, 1.0, 1.0);
1073 }
1074 } else if (p_name == "quaternion") {
1075 Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
1076 if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
1077 r_property = Quaternion(Transform3D(variant).get_basis().get_rotation_quaternion());
1078 } else {
1079 r_property = Quaternion();
1080 }
1081 } else if (p_name == "rotation") {
1082 Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
1083 if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
1084 r_property = Transform3D(variant).get_basis().get_euler_normalized(data.euler_rotation_order);
1085 } else {
1086 r_property = Vector3();
1087 }
1088 } else if (p_name == "position") {
1089 Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
1090 if (valid) {
1091 r_property = Transform3D(variant).get_origin();
1092 } else {
1093 r_property = Vector3();
1094 }
1095 } else {
1096 return false;
1097 }
1098 return true;
1099}
1100
1101void Node3D::_bind_methods() {
1102 ClassDB::bind_method(D_METHOD("set_transform", "local"), &Node3D::set_transform);
1103 ClassDB::bind_method(D_METHOD("get_transform"), &Node3D::get_transform);
1104 ClassDB::bind_method(D_METHOD("set_position", "position"), &Node3D::set_position);
1105 ClassDB::bind_method(D_METHOD("get_position"), &Node3D::get_position);
1106 ClassDB::bind_method(D_METHOD("set_rotation", "euler_radians"), &Node3D::set_rotation);
1107 ClassDB::bind_method(D_METHOD("get_rotation"), &Node3D::get_rotation);
1108 ClassDB::bind_method(D_METHOD("set_rotation_degrees", "euler_degrees"), &Node3D::set_rotation_degrees);
1109 ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Node3D::get_rotation_degrees);
1110 ClassDB::bind_method(D_METHOD("set_rotation_order", "order"), &Node3D::set_rotation_order);
1111 ClassDB::bind_method(D_METHOD("get_rotation_order"), &Node3D::get_rotation_order);
1112 ClassDB::bind_method(D_METHOD("set_rotation_edit_mode", "edit_mode"), &Node3D::set_rotation_edit_mode);
1113 ClassDB::bind_method(D_METHOD("get_rotation_edit_mode"), &Node3D::get_rotation_edit_mode);
1114 ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Node3D::set_scale);
1115 ClassDB::bind_method(D_METHOD("get_scale"), &Node3D::get_scale);
1116 ClassDB::bind_method(D_METHOD("set_quaternion", "quaternion"), &Node3D::set_quaternion);
1117 ClassDB::bind_method(D_METHOD("get_quaternion"), &Node3D::get_quaternion);
1118 ClassDB::bind_method(D_METHOD("set_basis", "basis"), &Node3D::set_basis);
1119 ClassDB::bind_method(D_METHOD("get_basis"), &Node3D::get_basis);
1120
1121 ClassDB::bind_method(D_METHOD("set_global_transform", "global"), &Node3D::set_global_transform);
1122 ClassDB::bind_method(D_METHOD("get_global_transform"), &Node3D::get_global_transform);
1123 ClassDB::bind_method(D_METHOD("set_global_position", "position"), &Node3D::set_global_position);
1124 ClassDB::bind_method(D_METHOD("get_global_position"), &Node3D::get_global_position);
1125 ClassDB::bind_method(D_METHOD("set_global_basis", "basis"), &Node3D::set_global_basis);
1126 ClassDB::bind_method(D_METHOD("get_global_basis"), &Node3D::get_global_basis);
1127 ClassDB::bind_method(D_METHOD("set_global_rotation", "euler_radians"), &Node3D::set_global_rotation);
1128 ClassDB::bind_method(D_METHOD("get_global_rotation"), &Node3D::get_global_rotation);
1129 ClassDB::bind_method(D_METHOD("set_global_rotation_degrees", "euler_degrees"), &Node3D::set_global_rotation_degrees);
1130 ClassDB::bind_method(D_METHOD("get_global_rotation_degrees"), &Node3D::get_global_rotation_degrees);
1131
1132 ClassDB::bind_method(D_METHOD("get_parent_node_3d"), &Node3D::get_parent_node_3d);
1133 ClassDB::bind_method(D_METHOD("set_ignore_transform_notification", "enabled"), &Node3D::set_ignore_transform_notification);
1134 ClassDB::bind_method(D_METHOD("set_as_top_level", "enable"), &Node3D::set_as_top_level);
1135 ClassDB::bind_method(D_METHOD("is_set_as_top_level"), &Node3D::is_set_as_top_level);
1136 ClassDB::bind_method(D_METHOD("set_disable_scale", "disable"), &Node3D::set_disable_scale);
1137 ClassDB::bind_method(D_METHOD("is_scale_disabled"), &Node3D::is_scale_disabled);
1138 ClassDB::bind_method(D_METHOD("get_world_3d"), &Node3D::get_world_3d);
1139
1140 ClassDB::bind_method(D_METHOD("force_update_transform"), &Node3D::force_update_transform);
1141
1142 ClassDB::bind_method(D_METHOD("set_visibility_parent", "path"), &Node3D::set_visibility_parent);
1143 ClassDB::bind_method(D_METHOD("get_visibility_parent"), &Node3D::get_visibility_parent);
1144
1145 ClassDB::bind_method(D_METHOD("update_gizmos"), &Node3D::update_gizmos);
1146 ClassDB::bind_method(D_METHOD("add_gizmo", "gizmo"), &Node3D::add_gizmo);
1147 ClassDB::bind_method(D_METHOD("get_gizmos"), &Node3D::get_gizmos_bind);
1148 ClassDB::bind_method(D_METHOD("clear_gizmos"), &Node3D::clear_gizmos);
1149 ClassDB::bind_method(D_METHOD("set_subgizmo_selection", "gizmo", "id", "transform"), &Node3D::set_subgizmo_selection);
1150 ClassDB::bind_method(D_METHOD("clear_subgizmo_selection"), &Node3D::clear_subgizmo_selection);
1151
1152 ClassDB::bind_method(D_METHOD("set_visible", "visible"), &Node3D::set_visible);
1153 ClassDB::bind_method(D_METHOD("is_visible"), &Node3D::is_visible);
1154 ClassDB::bind_method(D_METHOD("is_visible_in_tree"), &Node3D::is_visible_in_tree);
1155 ClassDB::bind_method(D_METHOD("show"), &Node3D::show);
1156 ClassDB::bind_method(D_METHOD("hide"), &Node3D::hide);
1157
1158 ClassDB::bind_method(D_METHOD("set_notify_local_transform", "enable"), &Node3D::set_notify_local_transform);
1159 ClassDB::bind_method(D_METHOD("is_local_transform_notification_enabled"), &Node3D::is_local_transform_notification_enabled);
1160
1161 ClassDB::bind_method(D_METHOD("set_notify_transform", "enable"), &Node3D::set_notify_transform);
1162 ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"), &Node3D::is_transform_notification_enabled);
1163
1164 ClassDB::bind_method(D_METHOD("rotate", "axis", "angle"), &Node3D::rotate);
1165 ClassDB::bind_method(D_METHOD("global_rotate", "axis", "angle"), &Node3D::global_rotate);
1166 ClassDB::bind_method(D_METHOD("global_scale", "scale"), &Node3D::global_scale);
1167 ClassDB::bind_method(D_METHOD("global_translate", "offset"), &Node3D::global_translate);
1168 ClassDB::bind_method(D_METHOD("rotate_object_local", "axis", "angle"), &Node3D::rotate_object_local);
1169 ClassDB::bind_method(D_METHOD("scale_object_local", "scale"), &Node3D::scale_object_local);
1170 ClassDB::bind_method(D_METHOD("translate_object_local", "offset"), &Node3D::translate_object_local);
1171 ClassDB::bind_method(D_METHOD("rotate_x", "angle"), &Node3D::rotate_x);
1172 ClassDB::bind_method(D_METHOD("rotate_y", "angle"), &Node3D::rotate_y);
1173 ClassDB::bind_method(D_METHOD("rotate_z", "angle"), &Node3D::rotate_z);
1174 ClassDB::bind_method(D_METHOD("translate", "offset"), &Node3D::translate);
1175 ClassDB::bind_method(D_METHOD("orthonormalize"), &Node3D::orthonormalize);
1176 ClassDB::bind_method(D_METHOD("set_identity"), &Node3D::set_identity);
1177
1178 ClassDB::bind_method(D_METHOD("look_at", "target", "up", "use_model_front"), &Node3D::look_at, DEFVAL(Vector3(0, 1, 0)), DEFVAL(false));
1179 ClassDB::bind_method(D_METHOD("look_at_from_position", "position", "target", "up", "use_model_front"), &Node3D::look_at_from_position, DEFVAL(Vector3(0, 1, 0)), DEFVAL(false));
1180
1181 ClassDB::bind_method(D_METHOD("to_local", "global_point"), &Node3D::to_local);
1182 ClassDB::bind_method(D_METHOD("to_global", "local_point"), &Node3D::to_global);
1183
1184 BIND_CONSTANT(NOTIFICATION_TRANSFORM_CHANGED);
1185 BIND_CONSTANT(NOTIFICATION_ENTER_WORLD);
1186 BIND_CONSTANT(NOTIFICATION_EXIT_WORLD);
1187 BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED);
1188 BIND_CONSTANT(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
1189
1190 BIND_ENUM_CONSTANT(ROTATION_EDIT_MODE_EULER);
1191 BIND_ENUM_CONSTANT(ROTATION_EDIT_MODE_QUATERNION);
1192 BIND_ENUM_CONSTANT(ROTATION_EDIT_MODE_BASIS);
1193
1194 ADD_GROUP("Transform", "");
1195 ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "transform", PROPERTY_HINT_NONE, "suffix:m", PROPERTY_USAGE_NO_EDITOR), "set_transform", "get_transform");
1196 ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "global_transform", PROPERTY_HINT_NONE, "suffix:m", PROPERTY_USAGE_NONE), "set_global_transform", "get_global_transform");
1197 ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "position", PROPERTY_HINT_RANGE, "-99999,99999,0.001,or_greater,or_less,hide_slider,suffix:m", PROPERTY_USAGE_EDITOR), "set_position", "get_position");
1198 ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation", PROPERTY_HINT_RANGE, "-360,360,0.1,or_less,or_greater,radians", PROPERTY_USAGE_EDITOR), "set_rotation", "get_rotation");
1199 ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_rotation_degrees", "get_rotation_degrees");
1200 ADD_PROPERTY(PropertyInfo(Variant::QUATERNION, "quaternion", PROPERTY_HINT_HIDE_QUATERNION_EDIT, "", PROPERTY_USAGE_EDITOR), "set_quaternion", "get_quaternion");
1201 ADD_PROPERTY(PropertyInfo(Variant::BASIS, "basis", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_basis", "get_basis");
1202 ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale", PROPERTY_HINT_LINK, "", PROPERTY_USAGE_EDITOR), "set_scale", "get_scale");
1203 ADD_PROPERTY(PropertyInfo(Variant::INT, "rotation_edit_mode", PROPERTY_HINT_ENUM, "Euler,Quaternion,Basis"), "set_rotation_edit_mode", "get_rotation_edit_mode");
1204 ADD_PROPERTY(PropertyInfo(Variant::INT, "rotation_order", PROPERTY_HINT_ENUM, "XYZ,XZY,YXZ,YZX,ZXY,ZYX"), "set_rotation_order", "get_rotation_order");
1205 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "top_level"), "set_as_top_level", "is_set_as_top_level");
1206
1207 ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "global_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_position", "get_global_position");
1208 ADD_PROPERTY(PropertyInfo(Variant::BASIS, "global_basis", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_basis", "get_global_basis");
1209 ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "global_rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_rotation", "get_global_rotation");
1210 ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "global_rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_rotation_degrees", "get_global_rotation_degrees");
1211 ADD_GROUP("Visibility", "");
1212 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
1213 ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "visibility_parent", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "GeometryInstance3D"), "set_visibility_parent", "get_visibility_parent");
1214
1215 ADD_SIGNAL(MethodInfo("visibility_changed"));
1216}
1217
1218Node3D::Node3D() :
1219 xform_change(this) {}
1220