node_3d.cpp 41 KB

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