node_3d.cpp 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  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. #include "node_3d.h"
  31. #include "core/object/message_queue.h"
  32. #include "scene/3d/visual_instance_3d.h"
  33. #include "scene/main/viewport.h"
  34. #include "scene/property_utils.h"
  35. #include "scene/scene_string_names.h"
  36. /*
  37. possible algorithms:
  38. Algorithm 1: (current)
  39. definition of invalidation: global is invalid
  40. 1) If a node sets a LOCAL, it produces an invalidation of everything above
  41. . a) If above is invalid, don't keep invalidating upwards
  42. 2) If a node sets a GLOBAL, it is converted to LOCAL (and forces validation of everything pending below)
  43. drawback: setting/reading globals is useful and used very often, and using affine inverses is slow
  44. ---
  45. Algorithm 2: (no longer current)
  46. definition of invalidation: NONE dirty, LOCAL dirty, GLOBAL dirty
  47. 1) If a node sets a LOCAL, it must climb the tree and set it as GLOBAL dirty
  48. . a) marking GLOBALs as dirty up all the tree must be done always
  49. 2) If a node sets a GLOBAL, it marks local as dirty, and that's all?
  50. //is clearing the dirty state correct in this case?
  51. drawback: setting a local down the tree forces many tree walks often
  52. --
  53. future: no idea
  54. */
  55. Node3DGizmo::Node3DGizmo() {
  56. }
  57. void Node3D::_notify_dirty() {
  58. #ifdef TOOLS_ENABLED
  59. if ((!data.gizmos.is_empty() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
  60. #else
  61. if (data.notify_transform && !data.ignore_notification && !xform_change.in_list()) {
  62. #endif
  63. get_tree()->xform_change_list.add(&xform_change);
  64. }
  65. }
  66. void Node3D::_update_local_transform() const {
  67. // 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.
  68. data.local_transform.basis.set_euler_scale(data.euler_rotation, data.scale, data.euler_rotation_order);
  69. data.dirty &= ~DIRTY_LOCAL_TRANSFORM;
  70. }
  71. void Node3D::_update_rotation_and_scale() const {
  72. // This function is called when the Euler rotation (data.euler_rotation) is dirty and the right value is contained in the local transform
  73. data.scale = data.local_transform.basis.get_scale();
  74. data.euler_rotation = data.local_transform.basis.get_euler_normalized(data.euler_rotation_order);
  75. data.dirty &= ~DIRTY_EULER_ROTATION_AND_SCALE;
  76. }
  77. void Node3D::_propagate_transform_changed(Node3D *p_origin) {
  78. if (!is_inside_tree()) {
  79. return;
  80. }
  81. data.children_lock++;
  82. for (Node3D *&E : data.children) {
  83. if (E->data.top_level_active) {
  84. continue; //don't propagate to a top_level
  85. }
  86. E->_propagate_transform_changed(p_origin);
  87. }
  88. #ifdef TOOLS_ENABLED
  89. if ((!data.gizmos.is_empty() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
  90. #else
  91. if (data.notify_transform && !data.ignore_notification && !xform_change.in_list()) {
  92. #endif
  93. get_tree()->xform_change_list.add(&xform_change);
  94. }
  95. data.dirty |= DIRTY_GLOBAL_TRANSFORM;
  96. data.children_lock--;
  97. }
  98. void Node3D::_notification(int p_what) {
  99. switch (p_what) {
  100. case NOTIFICATION_ENTER_TREE: {
  101. ERR_FAIL_COND(!get_tree());
  102. Node *p = get_parent();
  103. if (p) {
  104. data.parent = Object::cast_to<Node3D>(p);
  105. }
  106. if (data.parent) {
  107. data.C = data.parent->data.children.push_back(this);
  108. } else {
  109. data.C = nullptr;
  110. }
  111. if (data.top_level && !Engine::get_singleton()->is_editor_hint()) {
  112. if (data.parent) {
  113. data.local_transform = data.parent->get_global_transform() * get_transform();
  114. data.dirty = DIRTY_EULER_ROTATION_AND_SCALE; // As local transform was updated, rot/scale should be dirty.
  115. }
  116. data.top_level_active = true;
  117. }
  118. data.dirty |= DIRTY_GLOBAL_TRANSFORM; // Global is always dirty upon entering a scene.
  119. _notify_dirty();
  120. notification(NOTIFICATION_ENTER_WORLD);
  121. _update_visibility_parent(true);
  122. } break;
  123. case NOTIFICATION_EXIT_TREE: {
  124. notification(NOTIFICATION_EXIT_WORLD, true);
  125. if (xform_change.in_list()) {
  126. get_tree()->xform_change_list.remove(&xform_change);
  127. }
  128. if (data.C) {
  129. data.parent->data.children.erase(data.C);
  130. }
  131. data.parent = nullptr;
  132. data.C = nullptr;
  133. data.top_level_active = false;
  134. _update_visibility_parent(true);
  135. } break;
  136. case NOTIFICATION_ENTER_WORLD: {
  137. data.inside_world = true;
  138. data.viewport = nullptr;
  139. Node *parent = get_parent();
  140. while (parent && !data.viewport) {
  141. data.viewport = Object::cast_to<Viewport>(parent);
  142. parent = parent->get_parent();
  143. }
  144. ERR_FAIL_COND(!data.viewport);
  145. if (get_script_instance()) {
  146. get_script_instance()->call(SceneStringNames::get_singleton()->_enter_world);
  147. }
  148. #ifdef TOOLS_ENABLED
  149. if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) {
  150. get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringNames::get_singleton()->_spatial_editor_group, SNAME("_request_gizmo_for_id"), get_instance_id());
  151. }
  152. #endif
  153. } break;
  154. case NOTIFICATION_EXIT_WORLD: {
  155. #ifdef TOOLS_ENABLED
  156. clear_gizmos();
  157. #endif
  158. if (get_script_instance()) {
  159. get_script_instance()->call(SceneStringNames::get_singleton()->_exit_world);
  160. }
  161. data.viewport = nullptr;
  162. data.inside_world = false;
  163. } break;
  164. case NOTIFICATION_TRANSFORM_CHANGED: {
  165. #ifdef TOOLS_ENABLED
  166. for (int i = 0; i < data.gizmos.size(); i++) {
  167. data.gizmos.write[i]->transform();
  168. }
  169. #endif
  170. } break;
  171. }
  172. }
  173. void Node3D::set_basis(const Basis &p_basis) {
  174. set_transform(Transform3D(p_basis, data.local_transform.origin));
  175. }
  176. void Node3D::set_quaternion(const Quaternion &p_quaternion) {
  177. if (data.dirty & DIRTY_EULER_ROTATION_AND_SCALE) {
  178. // We need the scale part, so if these are dirty, update it
  179. data.scale = data.local_transform.basis.get_scale();
  180. data.dirty &= ~DIRTY_EULER_ROTATION_AND_SCALE;
  181. }
  182. data.local_transform.basis = Basis(p_quaternion, data.scale);
  183. // Rotscale should not be marked dirty because that would cause precision loss issues with the scale. Instead reconstruct rotation now.
  184. data.euler_rotation = data.local_transform.basis.get_euler_normalized(data.euler_rotation_order);
  185. data.dirty = DIRTY_NONE;
  186. _propagate_transform_changed(this);
  187. if (data.notify_local_transform) {
  188. notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
  189. }
  190. }
  191. Vector3 Node3D::get_global_position() const {
  192. return get_global_transform().get_origin();
  193. }
  194. void Node3D::set_global_position(const Vector3 &p_position) {
  195. Transform3D transform = get_global_transform();
  196. transform.set_origin(p_position);
  197. set_global_transform(transform);
  198. }
  199. Vector3 Node3D::get_global_rotation() const {
  200. return get_global_transform().get_basis().get_euler();
  201. }
  202. Vector3 Node3D::get_global_rotation_degrees() const {
  203. Vector3 radians = get_global_rotation();
  204. return Vector3(Math::rad_to_deg(radians.x), Math::rad_to_deg(radians.y), Math::rad_to_deg(radians.z));
  205. }
  206. void Node3D::set_global_rotation(const Vector3 &p_euler_rad) {
  207. Transform3D transform = get_global_transform();
  208. transform.basis = Basis::from_euler(p_euler_rad);
  209. set_global_transform(transform);
  210. }
  211. void Node3D::set_global_rotation_degrees(const Vector3 &p_euler_degrees) {
  212. 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));
  213. set_global_rotation(radians);
  214. }
  215. void Node3D::set_transform(const Transform3D &p_transform) {
  216. data.local_transform = p_transform;
  217. data.dirty = DIRTY_EULER_ROTATION_AND_SCALE; // Make rot/scale dirty.
  218. _propagate_transform_changed(this);
  219. if (data.notify_local_transform) {
  220. notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
  221. }
  222. }
  223. Basis Node3D::get_basis() const {
  224. return get_transform().basis;
  225. }
  226. Quaternion Node3D::get_quaternion() const {
  227. if (data.dirty & DIRTY_LOCAL_TRANSFORM) {
  228. _update_local_transform();
  229. }
  230. return data.local_transform.basis.get_rotation_quaternion();
  231. }
  232. void Node3D::set_global_transform(const Transform3D &p_transform) {
  233. Transform3D xform = (data.parent && !data.top_level_active)
  234. ? data.parent->get_global_transform().affine_inverse() * p_transform
  235. : p_transform;
  236. set_transform(xform);
  237. }
  238. Transform3D Node3D::get_transform() const {
  239. if (data.dirty & DIRTY_LOCAL_TRANSFORM) {
  240. _update_local_transform();
  241. }
  242. return data.local_transform;
  243. }
  244. Transform3D Node3D::get_global_transform() const {
  245. ERR_FAIL_COND_V(!is_inside_tree(), Transform3D());
  246. if (data.dirty & DIRTY_GLOBAL_TRANSFORM) {
  247. if (data.dirty & DIRTY_LOCAL_TRANSFORM) {
  248. _update_local_transform();
  249. }
  250. if (data.parent && !data.top_level_active) {
  251. data.global_transform = data.parent->get_global_transform() * data.local_transform;
  252. } else {
  253. data.global_transform = data.local_transform;
  254. }
  255. if (data.disable_scale) {
  256. data.global_transform.basis.orthonormalize();
  257. }
  258. data.dirty &= ~DIRTY_GLOBAL_TRANSFORM;
  259. }
  260. return data.global_transform;
  261. }
  262. #ifdef TOOLS_ENABLED
  263. Transform3D Node3D::get_global_gizmo_transform() const {
  264. return get_global_transform();
  265. }
  266. Transform3D Node3D::get_local_gizmo_transform() const {
  267. return get_transform();
  268. }
  269. #endif
  270. Node3D *Node3D::get_parent_node_3d() const {
  271. if (data.top_level) {
  272. return nullptr;
  273. }
  274. return Object::cast_to<Node3D>(get_parent());
  275. }
  276. Transform3D Node3D::get_relative_transform(const Node *p_parent) const {
  277. if (p_parent == this) {
  278. return Transform3D();
  279. }
  280. ERR_FAIL_COND_V(!data.parent, Transform3D());
  281. if (p_parent == data.parent) {
  282. return get_transform();
  283. } else {
  284. return data.parent->get_relative_transform(p_parent) * get_transform();
  285. }
  286. }
  287. void Node3D::set_position(const Vector3 &p_position) {
  288. data.local_transform.origin = p_position;
  289. _propagate_transform_changed(this);
  290. if (data.notify_local_transform) {
  291. notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
  292. }
  293. }
  294. void Node3D::set_rotation_edit_mode(RotationEditMode p_mode) {
  295. if (data.rotation_edit_mode == p_mode) {
  296. return;
  297. }
  298. bool transform_changed = false;
  299. if (data.rotation_edit_mode == ROTATION_EDIT_MODE_BASIS && !(data.dirty & DIRTY_LOCAL_TRANSFORM)) {
  300. data.local_transform.orthogonalize();
  301. transform_changed = true;
  302. }
  303. data.rotation_edit_mode = p_mode;
  304. if (p_mode == ROTATION_EDIT_MODE_EULER && (data.dirty & DIRTY_EULER_ROTATION_AND_SCALE)) {
  305. // If going to Euler mode, ensure that vectors are _not_ dirty, else the retrieved value may be wrong.
  306. // Otherwise keep what is there, so switching back and forth between modes does not break the vectors.
  307. _update_rotation_and_scale();
  308. }
  309. if (transform_changed) {
  310. _propagate_transform_changed(this);
  311. if (data.notify_local_transform) {
  312. notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
  313. }
  314. }
  315. notify_property_list_changed();
  316. }
  317. Node3D::RotationEditMode Node3D::get_rotation_edit_mode() const {
  318. return data.rotation_edit_mode;
  319. }
  320. void Node3D::set_rotation_order(EulerOrder p_order) {
  321. if (data.euler_rotation_order == p_order) {
  322. return;
  323. }
  324. ERR_FAIL_INDEX(int32_t(p_order), 6);
  325. bool transform_changed = false;
  326. if (data.dirty & DIRTY_EULER_ROTATION_AND_SCALE) {
  327. _update_rotation_and_scale();
  328. } else if (data.dirty & DIRTY_LOCAL_TRANSFORM) {
  329. data.euler_rotation = Basis::from_euler(data.euler_rotation, data.euler_rotation_order).get_euler_normalized(p_order);
  330. transform_changed = true;
  331. } else {
  332. data.dirty |= DIRTY_LOCAL_TRANSFORM;
  333. transform_changed = true;
  334. }
  335. data.euler_rotation_order = p_order;
  336. if (transform_changed) {
  337. _propagate_transform_changed(this);
  338. if (data.notify_local_transform) {
  339. notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
  340. }
  341. }
  342. notify_property_list_changed(); // Will change the rotation property.
  343. }
  344. EulerOrder Node3D::get_rotation_order() const {
  345. return data.euler_rotation_order;
  346. }
  347. void Node3D::set_rotation(const Vector3 &p_euler_rad) {
  348. if (data.dirty & DIRTY_EULER_ROTATION_AND_SCALE) {
  349. // Update scale only if rotation and scale are dirty, as rotation will be overridden.
  350. data.scale = data.local_transform.basis.get_scale();
  351. data.dirty &= ~DIRTY_EULER_ROTATION_AND_SCALE;
  352. }
  353. data.euler_rotation = p_euler_rad;
  354. data.dirty = DIRTY_LOCAL_TRANSFORM;
  355. _propagate_transform_changed(this);
  356. if (data.notify_local_transform) {
  357. notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
  358. }
  359. }
  360. void Node3D::set_rotation_degrees(const Vector3 &p_euler_degrees) {
  361. 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));
  362. set_rotation(radians);
  363. }
  364. void Node3D::set_scale(const Vector3 &p_scale) {
  365. if (data.dirty & DIRTY_EULER_ROTATION_AND_SCALE) {
  366. // Update rotation only if rotation and scale are dirty, as scale will be overridden.
  367. data.euler_rotation = data.local_transform.basis.get_euler_normalized(data.euler_rotation_order);
  368. data.dirty &= ~DIRTY_EULER_ROTATION_AND_SCALE;
  369. }
  370. data.scale = p_scale;
  371. data.dirty = DIRTY_LOCAL_TRANSFORM;
  372. _propagate_transform_changed(this);
  373. if (data.notify_local_transform) {
  374. notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
  375. }
  376. }
  377. Vector3 Node3D::get_position() const {
  378. return data.local_transform.origin;
  379. }
  380. Vector3 Node3D::get_rotation() const {
  381. if (data.dirty & DIRTY_EULER_ROTATION_AND_SCALE) {
  382. _update_rotation_and_scale();
  383. }
  384. return data.euler_rotation;
  385. }
  386. Vector3 Node3D::get_rotation_degrees() const {
  387. Vector3 radians = get_rotation();
  388. return Vector3(Math::rad_to_deg(radians.x), Math::rad_to_deg(radians.y), Math::rad_to_deg(radians.z));
  389. }
  390. Vector3 Node3D::get_scale() const {
  391. if (data.dirty & DIRTY_EULER_ROTATION_AND_SCALE) {
  392. _update_rotation_and_scale();
  393. }
  394. return data.scale;
  395. }
  396. void Node3D::update_gizmos() {
  397. #ifdef TOOLS_ENABLED
  398. if (!is_inside_world()) {
  399. return;
  400. }
  401. if (data.gizmos.is_empty()) {
  402. get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringNames::get_singleton()->_spatial_editor_group, SNAME("_request_gizmo_for_id"), get_instance_id());
  403. return;
  404. }
  405. if (data.gizmos_dirty) {
  406. return;
  407. }
  408. data.gizmos_dirty = true;
  409. MessageQueue::get_singleton()->push_callable(callable_mp(this, &Node3D::_update_gizmos));
  410. #endif
  411. }
  412. void Node3D::set_subgizmo_selection(Ref<Node3DGizmo> p_gizmo, int p_id, Transform3D p_transform) {
  413. #ifdef TOOLS_ENABLED
  414. if (!is_inside_world()) {
  415. return;
  416. }
  417. if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) {
  418. 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);
  419. }
  420. #endif
  421. }
  422. void Node3D::clear_subgizmo_selection() {
  423. #ifdef TOOLS_ENABLED
  424. if (!is_inside_world()) {
  425. return;
  426. }
  427. if (data.gizmos.is_empty()) {
  428. return;
  429. }
  430. if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) {
  431. get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_clear_subgizmo_selection, this);
  432. }
  433. #endif
  434. }
  435. void Node3D::add_gizmo(Ref<Node3DGizmo> p_gizmo) {
  436. #ifdef TOOLS_ENABLED
  437. if (data.gizmos_disabled || p_gizmo.is_null()) {
  438. return;
  439. }
  440. data.gizmos.push_back(p_gizmo);
  441. if (p_gizmo.is_valid() && is_inside_world()) {
  442. p_gizmo->create();
  443. if (is_visible_in_tree()) {
  444. p_gizmo->redraw();
  445. }
  446. p_gizmo->transform();
  447. }
  448. #endif
  449. }
  450. void Node3D::remove_gizmo(Ref<Node3DGizmo> p_gizmo) {
  451. #ifdef TOOLS_ENABLED
  452. int idx = data.gizmos.find(p_gizmo);
  453. if (idx != -1) {
  454. p_gizmo->free();
  455. data.gizmos.remove_at(idx);
  456. }
  457. #endif
  458. }
  459. void Node3D::clear_gizmos() {
  460. #ifdef TOOLS_ENABLED
  461. for (int i = 0; i < data.gizmos.size(); i++) {
  462. data.gizmos.write[i]->free();
  463. }
  464. data.gizmos.clear();
  465. #endif
  466. }
  467. TypedArray<Node3DGizmo> Node3D::get_gizmos_bind() const {
  468. TypedArray<Node3DGizmo> ret;
  469. #ifdef TOOLS_ENABLED
  470. for (int i = 0; i < data.gizmos.size(); i++) {
  471. ret.push_back(Variant(data.gizmos[i].ptr()));
  472. }
  473. #endif
  474. return ret;
  475. }
  476. Vector<Ref<Node3DGizmo>> Node3D::get_gizmos() const {
  477. #ifdef TOOLS_ENABLED
  478. return data.gizmos;
  479. #else
  480. return Vector<Ref<Node3DGizmo>>();
  481. #endif
  482. }
  483. void Node3D::_update_gizmos() {
  484. #ifdef TOOLS_ENABLED
  485. if (data.gizmos_disabled || !is_inside_world() || !data.gizmos_dirty) {
  486. data.gizmos_dirty = false;
  487. return;
  488. }
  489. data.gizmos_dirty = false;
  490. for (int i = 0; i < data.gizmos.size(); i++) {
  491. if (is_visible_in_tree()) {
  492. data.gizmos.write[i]->redraw();
  493. } else {
  494. data.gizmos.write[i]->clear();
  495. }
  496. }
  497. #endif
  498. }
  499. void Node3D::set_disable_gizmos(bool p_enabled) {
  500. #ifdef TOOLS_ENABLED
  501. data.gizmos_disabled = p_enabled;
  502. if (!p_enabled) {
  503. clear_gizmos();
  504. }
  505. #endif
  506. }
  507. void Node3D::reparent(Node *p_parent, bool p_keep_global_transform) {
  508. Transform3D temp = get_global_transform();
  509. Node::reparent(p_parent);
  510. if (p_keep_global_transform) {
  511. set_global_transform(temp);
  512. }
  513. }
  514. void Node3D::set_disable_scale(bool p_enabled) {
  515. data.disable_scale = p_enabled;
  516. }
  517. bool Node3D::is_scale_disabled() const {
  518. return data.disable_scale;
  519. }
  520. void Node3D::set_as_top_level(bool p_enabled) {
  521. if (data.top_level == p_enabled) {
  522. return;
  523. }
  524. if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
  525. if (p_enabled) {
  526. set_transform(get_global_transform());
  527. } else if (data.parent) {
  528. set_transform(data.parent->get_global_transform().affine_inverse() * get_global_transform());
  529. }
  530. data.top_level = p_enabled;
  531. data.top_level_active = p_enabled;
  532. } else {
  533. data.top_level = p_enabled;
  534. }
  535. }
  536. bool Node3D::is_set_as_top_level() const {
  537. return data.top_level;
  538. }
  539. Ref<World3D> Node3D::get_world_3d() const {
  540. ERR_FAIL_COND_V(!is_inside_world(), Ref<World3D>());
  541. ERR_FAIL_COND_V(!data.viewport, Ref<World3D>());
  542. return data.viewport->find_world_3d();
  543. }
  544. void Node3D::_propagate_visibility_changed() {
  545. notification(NOTIFICATION_VISIBILITY_CHANGED);
  546. emit_signal(SceneStringNames::get_singleton()->visibility_changed);
  547. #ifdef TOOLS_ENABLED
  548. if (!data.gizmos.is_empty()) {
  549. data.gizmos_dirty = true;
  550. _update_gizmos();
  551. }
  552. #endif
  553. for (Node3D *c : data.children) {
  554. if (!c || !c->data.visible) {
  555. continue;
  556. }
  557. c->_propagate_visibility_changed();
  558. }
  559. }
  560. void Node3D::show() {
  561. set_visible(true);
  562. }
  563. void Node3D::hide() {
  564. set_visible(false);
  565. }
  566. void Node3D::set_visible(bool p_visible) {
  567. if (data.visible == p_visible) {
  568. return;
  569. }
  570. data.visible = p_visible;
  571. if (!is_inside_tree()) {
  572. return;
  573. }
  574. _propagate_visibility_changed();
  575. }
  576. bool Node3D::is_visible() const {
  577. return data.visible;
  578. }
  579. bool Node3D::is_visible_in_tree() const {
  580. const Node3D *s = this;
  581. while (s) {
  582. if (!s->data.visible) {
  583. return false;
  584. }
  585. s = s->data.parent;
  586. }
  587. return true;
  588. }
  589. void Node3D::rotate_object_local(const Vector3 &p_axis, real_t p_angle) {
  590. Transform3D t = get_transform();
  591. t.basis.rotate_local(p_axis, p_angle);
  592. set_transform(t);
  593. }
  594. void Node3D::rotate(const Vector3 &p_axis, real_t p_angle) {
  595. Transform3D t = get_transform();
  596. t.basis.rotate(p_axis, p_angle);
  597. set_transform(t);
  598. }
  599. void Node3D::rotate_x(real_t p_angle) {
  600. Transform3D t = get_transform();
  601. t.basis.rotate(Vector3(1, 0, 0), p_angle);
  602. set_transform(t);
  603. }
  604. void Node3D::rotate_y(real_t p_angle) {
  605. Transform3D t = get_transform();
  606. t.basis.rotate(Vector3(0, 1, 0), p_angle);
  607. set_transform(t);
  608. }
  609. void Node3D::rotate_z(real_t p_angle) {
  610. Transform3D t = get_transform();
  611. t.basis.rotate(Vector3(0, 0, 1), p_angle);
  612. set_transform(t);
  613. }
  614. void Node3D::translate(const Vector3 &p_offset) {
  615. Transform3D t = get_transform();
  616. t.translate_local(p_offset);
  617. set_transform(t);
  618. }
  619. void Node3D::translate_object_local(const Vector3 &p_offset) {
  620. Transform3D t = get_transform();
  621. Transform3D s;
  622. s.translate_local(p_offset);
  623. set_transform(t * s);
  624. }
  625. void Node3D::scale(const Vector3 &p_ratio) {
  626. Transform3D t = get_transform();
  627. t.basis.scale(p_ratio);
  628. set_transform(t);
  629. }
  630. void Node3D::scale_object_local(const Vector3 &p_scale) {
  631. Transform3D t = get_transform();
  632. t.basis.scale_local(p_scale);
  633. set_transform(t);
  634. }
  635. void Node3D::global_rotate(const Vector3 &p_axis, real_t p_angle) {
  636. Transform3D t = get_global_transform();
  637. t.basis.rotate(p_axis, p_angle);
  638. set_global_transform(t);
  639. }
  640. void Node3D::global_scale(const Vector3 &p_scale) {
  641. Transform3D t = get_global_transform();
  642. t.basis.scale(p_scale);
  643. set_global_transform(t);
  644. }
  645. void Node3D::global_translate(const Vector3 &p_offset) {
  646. Transform3D t = get_global_transform();
  647. t.origin += p_offset;
  648. set_global_transform(t);
  649. }
  650. void Node3D::orthonormalize() {
  651. Transform3D t = get_transform();
  652. t.orthonormalize();
  653. set_transform(t);
  654. }
  655. void Node3D::set_identity() {
  656. set_transform(Transform3D());
  657. }
  658. void Node3D::look_at(const Vector3 &p_target, const Vector3 &p_up) {
  659. ERR_FAIL_COND_MSG(!is_inside_tree(), "Node not inside tree. Use look_at_from_position() instead.");
  660. Vector3 origin = get_global_transform().origin;
  661. look_at_from_position(origin, p_target, p_up);
  662. }
  663. void Node3D::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up) {
  664. ERR_FAIL_COND_MSG(p_pos.is_equal_approx(p_target), "Node origin and target are in the same position, look_at() failed.");
  665. ERR_FAIL_COND_MSG(p_up.is_zero_approx(), "The up vector can't be zero, look_at() failed.");
  666. 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.");
  667. Transform3D lookat = Transform3D(Basis::looking_at(p_target - p_pos, p_up), p_pos);
  668. Vector3 original_scale = get_scale();
  669. set_global_transform(lookat);
  670. set_scale(original_scale);
  671. }
  672. Vector3 Node3D::to_local(Vector3 p_global) const {
  673. return get_global_transform().affine_inverse().xform(p_global);
  674. }
  675. Vector3 Node3D::to_global(Vector3 p_local) const {
  676. return get_global_transform().xform(p_local);
  677. }
  678. void Node3D::set_notify_transform(bool p_enabled) {
  679. data.notify_transform = p_enabled;
  680. }
  681. bool Node3D::is_transform_notification_enabled() const {
  682. return data.notify_transform;
  683. }
  684. void Node3D::set_notify_local_transform(bool p_enabled) {
  685. data.notify_local_transform = p_enabled;
  686. }
  687. bool Node3D::is_local_transform_notification_enabled() const {
  688. return data.notify_local_transform;
  689. }
  690. void Node3D::force_update_transform() {
  691. ERR_FAIL_COND(!is_inside_tree());
  692. if (!xform_change.in_list()) {
  693. return; //nothing to update
  694. }
  695. get_tree()->xform_change_list.remove(&xform_change);
  696. notification(NOTIFICATION_TRANSFORM_CHANGED);
  697. }
  698. void Node3D::_update_visibility_parent(bool p_update_root) {
  699. RID new_parent;
  700. if (!visibility_parent_path.is_empty()) {
  701. if (!p_update_root) {
  702. return;
  703. }
  704. Node *parent = get_node_or_null(visibility_parent_path);
  705. ERR_FAIL_COND_MSG(!parent, "Can't find visibility parent node at path: " + visibility_parent_path);
  706. ERR_FAIL_COND_MSG(parent == this, "The visibility parent can't be the same node.");
  707. GeometryInstance3D *gi = Object::cast_to<GeometryInstance3D>(parent);
  708. ERR_FAIL_COND_MSG(!gi, "The visibility parent node must be a GeometryInstance3D, at path: " + visibility_parent_path);
  709. new_parent = gi ? gi->get_instance() : RID();
  710. } else if (data.parent) {
  711. new_parent = data.parent->data.visibility_parent;
  712. }
  713. if (new_parent == data.visibility_parent) {
  714. return;
  715. }
  716. data.visibility_parent = new_parent;
  717. VisualInstance3D *vi = Object::cast_to<VisualInstance3D>(this);
  718. if (vi) {
  719. RS::get_singleton()->instance_set_visibility_parent(vi->get_instance(), data.visibility_parent);
  720. }
  721. for (Node3D *c : data.children) {
  722. c->_update_visibility_parent(false);
  723. }
  724. }
  725. void Node3D::set_visibility_parent(const NodePath &p_path) {
  726. visibility_parent_path = p_path;
  727. if (is_inside_tree()) {
  728. _update_visibility_parent(true);
  729. }
  730. }
  731. NodePath Node3D::get_visibility_parent() const {
  732. return visibility_parent_path;
  733. }
  734. void Node3D::_validate_property(PropertyInfo &p_property) const {
  735. if (data.rotation_edit_mode != ROTATION_EDIT_MODE_BASIS && p_property.name == "basis") {
  736. p_property.usage = 0;
  737. }
  738. if (data.rotation_edit_mode == ROTATION_EDIT_MODE_BASIS && p_property.name == "scale") {
  739. p_property.usage = 0;
  740. }
  741. if (data.rotation_edit_mode != ROTATION_EDIT_MODE_QUATERNION && p_property.name == "quaternion") {
  742. p_property.usage = 0;
  743. }
  744. if (data.rotation_edit_mode != ROTATION_EDIT_MODE_EULER && p_property.name == "rotation") {
  745. p_property.usage = 0;
  746. }
  747. if (data.rotation_edit_mode != ROTATION_EDIT_MODE_EULER && p_property.name == "rotation_order") {
  748. p_property.usage = 0;
  749. }
  750. }
  751. bool Node3D::_property_can_revert(const StringName &p_name) const {
  752. if (p_name == "basis") {
  753. return true;
  754. } else if (p_name == "scale") {
  755. return true;
  756. } else if (p_name == "quaternion") {
  757. return true;
  758. } else if (p_name == "rotation") {
  759. return true;
  760. } else if (p_name == "position") {
  761. return true;
  762. }
  763. return false;
  764. }
  765. bool Node3D::_property_get_revert(const StringName &p_name, Variant &r_property) const {
  766. bool valid = false;
  767. if (p_name == "basis") {
  768. Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
  769. if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
  770. r_property = Transform3D(variant).get_basis();
  771. } else {
  772. r_property = Basis();
  773. }
  774. } else if (p_name == "scale") {
  775. Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
  776. if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
  777. r_property = Transform3D(variant).get_basis().get_scale();
  778. } else {
  779. r_property = Vector3(1.0, 1.0, 1.0);
  780. }
  781. } else if (p_name == "quaternion") {
  782. Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
  783. if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
  784. r_property = Quaternion(Transform3D(variant).get_basis().get_rotation_quaternion());
  785. } else {
  786. r_property = Quaternion();
  787. }
  788. } else if (p_name == "rotation") {
  789. Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
  790. if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
  791. r_property = Transform3D(variant).get_basis().get_euler_normalized(data.euler_rotation_order);
  792. } else {
  793. r_property = Vector3();
  794. }
  795. } else if (p_name == "position") {
  796. Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
  797. if (valid) {
  798. r_property = Transform3D(variant).get_origin();
  799. } else {
  800. r_property = Vector3();
  801. }
  802. } else {
  803. return false;
  804. }
  805. return true;
  806. }
  807. void Node3D::_bind_methods() {
  808. ClassDB::bind_method(D_METHOD("set_transform", "local"), &Node3D::set_transform);
  809. ClassDB::bind_method(D_METHOD("get_transform"), &Node3D::get_transform);
  810. ClassDB::bind_method(D_METHOD("set_position", "position"), &Node3D::set_position);
  811. ClassDB::bind_method(D_METHOD("get_position"), &Node3D::get_position);
  812. ClassDB::bind_method(D_METHOD("set_rotation", "euler_radians"), &Node3D::set_rotation);
  813. ClassDB::bind_method(D_METHOD("get_rotation"), &Node3D::get_rotation);
  814. ClassDB::bind_method(D_METHOD("set_rotation_degrees", "euler_degrees"), &Node3D::set_rotation_degrees);
  815. ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Node3D::get_rotation_degrees);
  816. ClassDB::bind_method(D_METHOD("set_rotation_order", "order"), &Node3D::set_rotation_order);
  817. ClassDB::bind_method(D_METHOD("get_rotation_order"), &Node3D::get_rotation_order);
  818. ClassDB::bind_method(D_METHOD("set_rotation_edit_mode", "edit_mode"), &Node3D::set_rotation_edit_mode);
  819. ClassDB::bind_method(D_METHOD("get_rotation_edit_mode"), &Node3D::get_rotation_edit_mode);
  820. ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Node3D::set_scale);
  821. ClassDB::bind_method(D_METHOD("get_scale"), &Node3D::get_scale);
  822. ClassDB::bind_method(D_METHOD("set_quaternion", "quaternion"), &Node3D::set_quaternion);
  823. ClassDB::bind_method(D_METHOD("get_quaternion"), &Node3D::get_quaternion);
  824. ClassDB::bind_method(D_METHOD("set_basis", "basis"), &Node3D::set_basis);
  825. ClassDB::bind_method(D_METHOD("get_basis"), &Node3D::get_basis);
  826. ClassDB::bind_method(D_METHOD("set_global_transform", "global"), &Node3D::set_global_transform);
  827. ClassDB::bind_method(D_METHOD("get_global_transform"), &Node3D::get_global_transform);
  828. ClassDB::bind_method(D_METHOD("set_global_position", "position"), &Node3D::set_global_position);
  829. ClassDB::bind_method(D_METHOD("get_global_position"), &Node3D::get_global_position);
  830. ClassDB::bind_method(D_METHOD("set_global_rotation", "euler_radians"), &Node3D::set_global_rotation);
  831. ClassDB::bind_method(D_METHOD("get_global_rotation"), &Node3D::get_global_rotation);
  832. ClassDB::bind_method(D_METHOD("set_global_rotation_degrees", "euler_degrees"), &Node3D::set_global_rotation_degrees);
  833. ClassDB::bind_method(D_METHOD("get_global_rotation_degrees"), &Node3D::get_global_rotation_degrees);
  834. ClassDB::bind_method(D_METHOD("get_parent_node_3d"), &Node3D::get_parent_node_3d);
  835. ClassDB::bind_method(D_METHOD("set_ignore_transform_notification", "enabled"), &Node3D::set_ignore_transform_notification);
  836. ClassDB::bind_method(D_METHOD("set_as_top_level", "enable"), &Node3D::set_as_top_level);
  837. ClassDB::bind_method(D_METHOD("is_set_as_top_level"), &Node3D::is_set_as_top_level);
  838. ClassDB::bind_method(D_METHOD("set_disable_scale", "disable"), &Node3D::set_disable_scale);
  839. ClassDB::bind_method(D_METHOD("is_scale_disabled"), &Node3D::is_scale_disabled);
  840. ClassDB::bind_method(D_METHOD("get_world_3d"), &Node3D::get_world_3d);
  841. ClassDB::bind_method(D_METHOD("force_update_transform"), &Node3D::force_update_transform);
  842. ClassDB::bind_method(D_METHOD("set_visibility_parent", "path"), &Node3D::set_visibility_parent);
  843. ClassDB::bind_method(D_METHOD("get_visibility_parent"), &Node3D::get_visibility_parent);
  844. ClassDB::bind_method(D_METHOD("update_gizmos"), &Node3D::update_gizmos);
  845. ClassDB::bind_method(D_METHOD("add_gizmo", "gizmo"), &Node3D::add_gizmo);
  846. ClassDB::bind_method(D_METHOD("get_gizmos"), &Node3D::get_gizmos_bind);
  847. ClassDB::bind_method(D_METHOD("clear_gizmos"), &Node3D::clear_gizmos);
  848. ClassDB::bind_method(D_METHOD("set_subgizmo_selection", "gizmo", "id", "transform"), &Node3D::set_subgizmo_selection);
  849. ClassDB::bind_method(D_METHOD("clear_subgizmo_selection"), &Node3D::clear_subgizmo_selection);
  850. ClassDB::bind_method(D_METHOD("set_visible", "visible"), &Node3D::set_visible);
  851. ClassDB::bind_method(D_METHOD("is_visible"), &Node3D::is_visible);
  852. ClassDB::bind_method(D_METHOD("is_visible_in_tree"), &Node3D::is_visible_in_tree);
  853. ClassDB::bind_method(D_METHOD("show"), &Node3D::show);
  854. ClassDB::bind_method(D_METHOD("hide"), &Node3D::hide);
  855. ClassDB::bind_method(D_METHOD("set_notify_local_transform", "enable"), &Node3D::set_notify_local_transform);
  856. ClassDB::bind_method(D_METHOD("is_local_transform_notification_enabled"), &Node3D::is_local_transform_notification_enabled);
  857. ClassDB::bind_method(D_METHOD("set_notify_transform", "enable"), &Node3D::set_notify_transform);
  858. ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"), &Node3D::is_transform_notification_enabled);
  859. ClassDB::bind_method(D_METHOD("rotate", "axis", "angle"), &Node3D::rotate);
  860. ClassDB::bind_method(D_METHOD("global_rotate", "axis", "angle"), &Node3D::global_rotate);
  861. ClassDB::bind_method(D_METHOD("global_scale", "scale"), &Node3D::global_scale);
  862. ClassDB::bind_method(D_METHOD("global_translate", "offset"), &Node3D::global_translate);
  863. ClassDB::bind_method(D_METHOD("rotate_object_local", "axis", "angle"), &Node3D::rotate_object_local);
  864. ClassDB::bind_method(D_METHOD("scale_object_local", "scale"), &Node3D::scale_object_local);
  865. ClassDB::bind_method(D_METHOD("translate_object_local", "offset"), &Node3D::translate_object_local);
  866. ClassDB::bind_method(D_METHOD("rotate_x", "angle"), &Node3D::rotate_x);
  867. ClassDB::bind_method(D_METHOD("rotate_y", "angle"), &Node3D::rotate_y);
  868. ClassDB::bind_method(D_METHOD("rotate_z", "angle"), &Node3D::rotate_z);
  869. ClassDB::bind_method(D_METHOD("translate", "offset"), &Node3D::translate);
  870. ClassDB::bind_method(D_METHOD("orthonormalize"), &Node3D::orthonormalize);
  871. ClassDB::bind_method(D_METHOD("set_identity"), &Node3D::set_identity);
  872. ClassDB::bind_method(D_METHOD("look_at", "target", "up"), &Node3D::look_at, DEFVAL(Vector3(0, 1, 0)));
  873. ClassDB::bind_method(D_METHOD("look_at_from_position", "position", "target", "up"), &Node3D::look_at_from_position, DEFVAL(Vector3(0, 1, 0)));
  874. ClassDB::bind_method(D_METHOD("to_local", "global_point"), &Node3D::to_local);
  875. ClassDB::bind_method(D_METHOD("to_global", "local_point"), &Node3D::to_global);
  876. BIND_CONSTANT(NOTIFICATION_TRANSFORM_CHANGED);
  877. BIND_CONSTANT(NOTIFICATION_ENTER_WORLD);
  878. BIND_CONSTANT(NOTIFICATION_EXIT_WORLD);
  879. BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED);
  880. BIND_CONSTANT(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
  881. BIND_ENUM_CONSTANT(ROTATION_EDIT_MODE_EULER);
  882. BIND_ENUM_CONSTANT(ROTATION_EDIT_MODE_QUATERNION);
  883. BIND_ENUM_CONSTANT(ROTATION_EDIT_MODE_BASIS);
  884. ADD_GROUP("Transform", "");
  885. ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "transform", PROPERTY_HINT_NONE, "suffix:m", PROPERTY_USAGE_NO_EDITOR), "set_transform", "get_transform");
  886. ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "global_transform", PROPERTY_HINT_NONE, "suffix:m", PROPERTY_USAGE_NONE), "set_global_transform", "get_global_transform");
  887. 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");
  888. 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");
  889. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_rotation_degrees", "get_rotation_degrees");
  890. ADD_PROPERTY(PropertyInfo(Variant::QUATERNION, "quaternion", PROPERTY_HINT_HIDE_QUATERNION_EDIT, "", PROPERTY_USAGE_EDITOR), "set_quaternion", "get_quaternion");
  891. ADD_PROPERTY(PropertyInfo(Variant::BASIS, "basis", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_basis", "get_basis");
  892. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale", PROPERTY_HINT_LINK, "", PROPERTY_USAGE_EDITOR), "set_scale", "get_scale");
  893. ADD_PROPERTY(PropertyInfo(Variant::INT, "rotation_edit_mode", PROPERTY_HINT_ENUM, "Euler,Quaternion,Basis"), "set_rotation_edit_mode", "get_rotation_edit_mode");
  894. ADD_PROPERTY(PropertyInfo(Variant::INT, "rotation_order", PROPERTY_HINT_ENUM, "XYZ,XZY,YXZ,YZX,ZXY,ZYX"), "set_rotation_order", "get_rotation_order");
  895. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "top_level"), "set_as_top_level", "is_set_as_top_level");
  896. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "global_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_position", "get_global_position");
  897. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "global_rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_rotation", "get_global_rotation");
  898. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "global_rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_rotation_degrees", "get_global_rotation_degrees");
  899. ADD_GROUP("Visibility", "");
  900. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
  901. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "visibility_parent", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "GeometryInstance3D"), "set_visibility_parent", "get_visibility_parent");
  902. ADD_SIGNAL(MethodInfo("visibility_changed"));
  903. }
  904. Node3D::Node3D() :
  905. xform_change(this) {}