1 /** 2 Most basic 3D game object, parent of all 3D related nodes. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.spatial; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.classdb; 23 import godot.node; 24 import godot.world; 25 import godot.spatialgizmo; 26 /** 27 Most basic 3D game object, parent of all 3D related nodes. 28 29 Most basic 3D game object, with a 3D $(D Transform) and visibility settings. All other 3D game objects inherit from Spatial. Use Spatial as a parent node to move, scale, rotate and show/hide children in a 3D project. 30 Affine operations (rotate, scale, translate) happen in parent's local coordinate system, unless the Spatial object is set as top level. Affine operations in this coordinate system correspond to direct affine operations on the Spatial's transform. The word local below refers to this coordinate system. The coordinate system that is attached to the Spatial object itself is referred to as object-local coordinate system. 31 */ 32 @GodotBaseClass struct Spatial 33 { 34 enum string _GODOT_internal_name = "Spatial"; 35 public: 36 @nogc nothrow: 37 union { godot_object _godot_object; Node _GODOT_base; } 38 alias _GODOT_base this; 39 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 40 package(godot) __gshared bool _classBindingInitialized = false; 41 package(godot) static struct _classBinding 42 { 43 __gshared: 44 @GodotName("set_transform") GodotMethod!(void, Transform) setTransform; 45 @GodotName("get_transform") GodotMethod!(Transform) getTransform; 46 @GodotName("set_translation") GodotMethod!(void, Vector3) setTranslation; 47 @GodotName("get_translation") GodotMethod!(Vector3) getTranslation; 48 @GodotName("set_rotation") GodotMethod!(void, Vector3) setRotation; 49 @GodotName("get_rotation") GodotMethod!(Vector3) getRotation; 50 @GodotName("set_rotation_degrees") GodotMethod!(void, Vector3) setRotationDegrees; 51 @GodotName("get_rotation_degrees") GodotMethod!(Vector3) getRotationDegrees; 52 @GodotName("set_scale") GodotMethod!(void, Vector3) setScale; 53 @GodotName("get_scale") GodotMethod!(Vector3) getScale; 54 @GodotName("set_global_transform") GodotMethod!(void, Transform) setGlobalTransform; 55 @GodotName("get_global_transform") GodotMethod!(Transform) getGlobalTransform; 56 @GodotName("get_parent_spatial") GodotMethod!(Spatial) getParentSpatial; 57 @GodotName("set_ignore_transform_notification") GodotMethod!(void, bool) setIgnoreTransformNotification; 58 @GodotName("set_as_toplevel") GodotMethod!(void, bool) setAsToplevel; 59 @GodotName("is_set_as_toplevel") GodotMethod!(bool) isSetAsToplevel; 60 @GodotName("set_disable_scale") GodotMethod!(void, bool) setDisableScale; 61 @GodotName("is_scale_disabled") GodotMethod!(bool) isScaleDisabled; 62 @GodotName("get_world") GodotMethod!(World) getWorld; 63 @GodotName("force_update_transform") GodotMethod!(void) forceUpdateTransform; 64 @GodotName("_update_gizmo") GodotMethod!(void) _updateGizmo; 65 @GodotName("update_gizmo") GodotMethod!(void) updateGizmo; 66 @GodotName("set_gizmo") GodotMethod!(void, SpatialGizmo) setGizmo; 67 @GodotName("get_gizmo") GodotMethod!(SpatialGizmo) getGizmo; 68 @GodotName("set_visible") GodotMethod!(void, bool) setVisible; 69 @GodotName("is_visible") GodotMethod!(bool) isVisible; 70 @GodotName("is_visible_in_tree") GodotMethod!(bool) isVisibleInTree; 71 @GodotName("show") GodotMethod!(void) show; 72 @GodotName("hide") GodotMethod!(void) hide; 73 @GodotName("set_notify_local_transform") GodotMethod!(void, bool) setNotifyLocalTransform; 74 @GodotName("is_local_transform_notification_enabled") GodotMethod!(bool) isLocalTransformNotificationEnabled; 75 @GodotName("set_notify_transform") GodotMethod!(void, bool) setNotifyTransform; 76 @GodotName("is_transform_notification_enabled") GodotMethod!(bool) isTransformNotificationEnabled; 77 @GodotName("rotate") GodotMethod!(void, Vector3, double) rotate; 78 @GodotName("global_rotate") GodotMethod!(void, Vector3, double) globalRotate; 79 @GodotName("global_scale") GodotMethod!(void, Vector3) globalScale; 80 @GodotName("global_translate") GodotMethod!(void, Vector3) globalTranslate; 81 @GodotName("rotate_object_local") GodotMethod!(void, Vector3, double) rotateObjectLocal; 82 @GodotName("scale_object_local") GodotMethod!(void, Vector3) scaleObjectLocal; 83 @GodotName("translate_object_local") GodotMethod!(void, Vector3) translateObjectLocal; 84 @GodotName("rotate_x") GodotMethod!(void, double) rotateX; 85 @GodotName("rotate_y") GodotMethod!(void, double) rotateY; 86 @GodotName("rotate_z") GodotMethod!(void, double) rotateZ; 87 @GodotName("translate") GodotMethod!(void, Vector3) translate; 88 @GodotName("orthonormalize") GodotMethod!(void) orthonormalize; 89 @GodotName("set_identity") GodotMethod!(void) setIdentity; 90 @GodotName("look_at") GodotMethod!(void, Vector3, Vector3) lookAt; 91 @GodotName("look_at_from_position") GodotMethod!(void, Vector3, Vector3, Vector3) lookAtFromPosition; 92 @GodotName("to_local") GodotMethod!(Vector3, Vector3) toLocal; 93 @GodotName("to_global") GodotMethod!(Vector3, Vector3) toGlobal; 94 } 95 bool opEquals(in Spatial other) const { return _godot_object.ptr is other._godot_object.ptr; } 96 Spatial opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 97 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 98 mixin baseCasts; 99 static Spatial _new() 100 { 101 static godot_class_constructor constructor; 102 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Spatial"); 103 if(constructor is null) return typeof(this).init; 104 return cast(Spatial)(constructor()); 105 } 106 @disable new(size_t s); 107 /// 108 enum Constants : int 109 { 110 /** 111 Spatial nodes receives this notification when their global transform changes. This means that either the current or a parent node changed its transform. 112 In order for NOTIFICATION_TRANSFORM_CHANGED to work user first needs to ask for it, with set_notify_transform(true). 113 */ 114 notificationTransformChanged = 29, 115 /** 116 Spatial nodes receives this notification when they are registered to new $(D World) resource. 117 */ 118 notificationEnterWorld = 41, 119 /** 120 Spatial nodes receives this notification when they are unregistered from current $(D World) resource. 121 */ 122 notificationExitWorld = 42, 123 /** 124 Spatial nodes receives this notification when their visibility changes. 125 */ 126 notificationVisibilityChanged = 43, 127 } 128 /** 129 130 */ 131 void setTransform(in Transform local) 132 { 133 checkClassBinding!(typeof(this))(); 134 ptrcall!(void)(_classBinding.setTransform, _godot_object, local); 135 } 136 /** 137 138 */ 139 Transform getTransform() const 140 { 141 checkClassBinding!(typeof(this))(); 142 return ptrcall!(Transform)(_classBinding.getTransform, _godot_object); 143 } 144 /** 145 146 */ 147 void setTranslation(in Vector3 translation) 148 { 149 checkClassBinding!(typeof(this))(); 150 ptrcall!(void)(_classBinding.setTranslation, _godot_object, translation); 151 } 152 /** 153 154 */ 155 Vector3 getTranslation() const 156 { 157 checkClassBinding!(typeof(this))(); 158 return ptrcall!(Vector3)(_classBinding.getTranslation, _godot_object); 159 } 160 /** 161 162 */ 163 void setRotation(in Vector3 euler) 164 { 165 checkClassBinding!(typeof(this))(); 166 ptrcall!(void)(_classBinding.setRotation, _godot_object, euler); 167 } 168 /** 169 170 */ 171 Vector3 getRotation() const 172 { 173 checkClassBinding!(typeof(this))(); 174 return ptrcall!(Vector3)(_classBinding.getRotation, _godot_object); 175 } 176 /** 177 178 */ 179 void setRotationDegrees(in Vector3 euler_degrees) 180 { 181 checkClassBinding!(typeof(this))(); 182 ptrcall!(void)(_classBinding.setRotationDegrees, _godot_object, euler_degrees); 183 } 184 /** 185 186 */ 187 Vector3 getRotationDegrees() const 188 { 189 checkClassBinding!(typeof(this))(); 190 return ptrcall!(Vector3)(_classBinding.getRotationDegrees, _godot_object); 191 } 192 /** 193 194 */ 195 void setScale(in Vector3 scale) 196 { 197 checkClassBinding!(typeof(this))(); 198 ptrcall!(void)(_classBinding.setScale, _godot_object, scale); 199 } 200 /** 201 202 */ 203 Vector3 getScale() const 204 { 205 checkClassBinding!(typeof(this))(); 206 return ptrcall!(Vector3)(_classBinding.getScale, _godot_object); 207 } 208 /** 209 210 */ 211 void setGlobalTransform(in Transform global) 212 { 213 checkClassBinding!(typeof(this))(); 214 ptrcall!(void)(_classBinding.setGlobalTransform, _godot_object, global); 215 } 216 /** 217 218 */ 219 Transform getGlobalTransform() const 220 { 221 checkClassBinding!(typeof(this))(); 222 return ptrcall!(Transform)(_classBinding.getGlobalTransform, _godot_object); 223 } 224 /** 225 Returns the parent `Spatial`, or an empty $(D GodotObject) if no parent exists or parent is not of type `Spatial`. 226 */ 227 Spatial getParentSpatial() const 228 { 229 checkClassBinding!(typeof(this))(); 230 return ptrcall!(Spatial)(_classBinding.getParentSpatial, _godot_object); 231 } 232 /** 233 Set whether the node ignores notification that its transformation (global or local) changed. 234 */ 235 void setIgnoreTransformNotification(in bool enabled) 236 { 237 checkClassBinding!(typeof(this))(); 238 ptrcall!(void)(_classBinding.setIgnoreTransformNotification, _godot_object, enabled); 239 } 240 /** 241 Makes the node ignore its parents transformations. Node transformations are only in global space. 242 */ 243 void setAsToplevel(in bool enable) 244 { 245 checkClassBinding!(typeof(this))(); 246 ptrcall!(void)(_classBinding.setAsToplevel, _godot_object, enable); 247 } 248 /** 249 Returns whether this node is set as Toplevel, that is whether it ignores its parent nodes transformations. 250 */ 251 bool isSetAsToplevel() const 252 { 253 checkClassBinding!(typeof(this))(); 254 return ptrcall!(bool)(_classBinding.isSetAsToplevel, _godot_object); 255 } 256 /** 257 258 */ 259 void setDisableScale(in bool disable) 260 { 261 checkClassBinding!(typeof(this))(); 262 ptrcall!(void)(_classBinding.setDisableScale, _godot_object, disable); 263 } 264 /** 265 266 */ 267 bool isScaleDisabled() const 268 { 269 checkClassBinding!(typeof(this))(); 270 return ptrcall!(bool)(_classBinding.isScaleDisabled, _godot_object); 271 } 272 /** 273 Returns the current $(D World) resource this Spatial node is registered to. 274 */ 275 Ref!World getWorld() const 276 { 277 checkClassBinding!(typeof(this))(); 278 return ptrcall!(World)(_classBinding.getWorld, _godot_object); 279 } 280 /** 281 282 */ 283 void forceUpdateTransform() 284 { 285 checkClassBinding!(typeof(this))(); 286 ptrcall!(void)(_classBinding.forceUpdateTransform, _godot_object); 287 } 288 /** 289 290 */ 291 void _updateGizmo() 292 { 293 Array _GODOT_args = Array.empty_array; 294 String _GODOT_method_name = String("_update_gizmo"); 295 this.callv(_GODOT_method_name, _GODOT_args); 296 } 297 /** 298 Updates the $(D SpatialGizmo) of this node. 299 */ 300 void updateGizmo() 301 { 302 checkClassBinding!(typeof(this))(); 303 ptrcall!(void)(_classBinding.updateGizmo, _godot_object); 304 } 305 /** 306 307 */ 308 void setGizmo(SpatialGizmo gizmo) 309 { 310 checkClassBinding!(typeof(this))(); 311 ptrcall!(void)(_classBinding.setGizmo, _godot_object, gizmo); 312 } 313 /** 314 315 */ 316 Ref!SpatialGizmo getGizmo() const 317 { 318 checkClassBinding!(typeof(this))(); 319 return ptrcall!(SpatialGizmo)(_classBinding.getGizmo, _godot_object); 320 } 321 /** 322 323 */ 324 void setVisible(in bool visible) 325 { 326 checkClassBinding!(typeof(this))(); 327 ptrcall!(void)(_classBinding.setVisible, _godot_object, visible); 328 } 329 /** 330 331 */ 332 bool isVisible() const 333 { 334 checkClassBinding!(typeof(this))(); 335 return ptrcall!(bool)(_classBinding.isVisible, _godot_object); 336 } 337 /** 338 Returns whether the node is visible, taking into consideration that its parents visibility. 339 */ 340 bool isVisibleInTree() const 341 { 342 checkClassBinding!(typeof(this))(); 343 return ptrcall!(bool)(_classBinding.isVisibleInTree, _godot_object); 344 } 345 /** 346 Enables rendering of this node. Change Spatial Visible property to "True". 347 */ 348 void show() 349 { 350 checkClassBinding!(typeof(this))(); 351 ptrcall!(void)(_classBinding.show, _godot_object); 352 } 353 /** 354 Disables rendering of this node. Change Spatial Visible property to false. 355 */ 356 void hide() 357 { 358 checkClassBinding!(typeof(this))(); 359 ptrcall!(void)(_classBinding.hide, _godot_object); 360 } 361 /** 362 Set whether the node notifies about its local transformation changes. Spatial will not propagate this by default. 363 */ 364 void setNotifyLocalTransform(in bool enable) 365 { 366 checkClassBinding!(typeof(this))(); 367 ptrcall!(void)(_classBinding.setNotifyLocalTransform, _godot_object, enable); 368 } 369 /** 370 Returns whether node notifies about its local transformation changes. Spatial will not propagate this by default. 371 */ 372 bool isLocalTransformNotificationEnabled() const 373 { 374 checkClassBinding!(typeof(this))(); 375 return ptrcall!(bool)(_classBinding.isLocalTransformNotificationEnabled, _godot_object); 376 } 377 /** 378 Set whether the node notifies about its global and local transformation changes. Spatial will not propagate this by default. 379 */ 380 void setNotifyTransform(in bool enable) 381 { 382 checkClassBinding!(typeof(this))(); 383 ptrcall!(void)(_classBinding.setNotifyTransform, _godot_object, enable); 384 } 385 /** 386 Returns whether the node notifies about its global and local transformation changes. Spatial will not propagate this by default. 387 */ 388 bool isTransformNotificationEnabled() const 389 { 390 checkClassBinding!(typeof(this))(); 391 return ptrcall!(bool)(_classBinding.isTransformNotificationEnabled, _godot_object); 392 } 393 /** 394 Rotates the local transformation around axis, a unit $(D Vector3), by specified angle in radians. 395 */ 396 void rotate(in Vector3 axis, in double angle) 397 { 398 checkClassBinding!(typeof(this))(); 399 ptrcall!(void)(_classBinding.rotate, _godot_object, axis, angle); 400 } 401 /** 402 Rotates the global (world) transformation around axis, a unit $(D Vector3), by specified angle in radians. The rotation axis is in global coordinate system. 403 */ 404 void globalRotate(in Vector3 axis, in double angle) 405 { 406 checkClassBinding!(typeof(this))(); 407 ptrcall!(void)(_classBinding.globalRotate, _godot_object, axis, angle); 408 } 409 /** 410 411 */ 412 void globalScale(in Vector3 scale) 413 { 414 checkClassBinding!(typeof(this))(); 415 ptrcall!(void)(_classBinding.globalScale, _godot_object, scale); 416 } 417 /** 418 Moves the global (world) transformation by $(D Vector3) offset. The offset is in global coordinate system. 419 */ 420 void globalTranslate(in Vector3 offset) 421 { 422 checkClassBinding!(typeof(this))(); 423 ptrcall!(void)(_classBinding.globalTranslate, _godot_object, offset); 424 } 425 /** 426 Rotates the local transformation around axis, a unit $(D Vector3), by specified angle in radians. The rotation axis is in object-local coordinate system. 427 */ 428 void rotateObjectLocal(in Vector3 axis, in double angle) 429 { 430 checkClassBinding!(typeof(this))(); 431 ptrcall!(void)(_classBinding.rotateObjectLocal, _godot_object, axis, angle); 432 } 433 /** 434 Scales the local transformation by given 3D scale factors in object-local coordinate system. 435 */ 436 void scaleObjectLocal(in Vector3 scale) 437 { 438 checkClassBinding!(typeof(this))(); 439 ptrcall!(void)(_classBinding.scaleObjectLocal, _godot_object, scale); 440 } 441 /** 442 443 */ 444 void translateObjectLocal(in Vector3 offset) 445 { 446 checkClassBinding!(typeof(this))(); 447 ptrcall!(void)(_classBinding.translateObjectLocal, _godot_object, offset); 448 } 449 /** 450 Rotates the local transformation around the X axis by angle in radians 451 */ 452 void rotateX(in double angle) 453 { 454 checkClassBinding!(typeof(this))(); 455 ptrcall!(void)(_classBinding.rotateX, _godot_object, angle); 456 } 457 /** 458 Rotates the local transformation around the Y axis by angle in radians. 459 */ 460 void rotateY(in double angle) 461 { 462 checkClassBinding!(typeof(this))(); 463 ptrcall!(void)(_classBinding.rotateY, _godot_object, angle); 464 } 465 /** 466 Rotates the local transformation around the Z axis by angle in radians. 467 */ 468 void rotateZ(in double angle) 469 { 470 checkClassBinding!(typeof(this))(); 471 ptrcall!(void)(_classBinding.rotateZ, _godot_object, angle); 472 } 473 /** 474 Changes the node's position by given offset $(D Vector3). 475 */ 476 void translate(in Vector3 offset) 477 { 478 checkClassBinding!(typeof(this))(); 479 ptrcall!(void)(_classBinding.translate, _godot_object, offset); 480 } 481 /** 482 Resets this node's transformations (like scale, skew and taper) preserving its rotation and translation by performing Gram-Schmidt orthonormalization on this node's $(D Transform3D). 483 */ 484 void orthonormalize() 485 { 486 checkClassBinding!(typeof(this))(); 487 ptrcall!(void)(_classBinding.orthonormalize, _godot_object); 488 } 489 /** 490 Reset all transformations for this node. Set its $(D Transform3D) to identity matrix. 491 */ 492 void setIdentity() 493 { 494 checkClassBinding!(typeof(this))(); 495 ptrcall!(void)(_classBinding.setIdentity, _godot_object); 496 } 497 /** 498 Rotates itself so that the local -Z axis points towards the `target` position. 499 The transform will first be rotated around the given `up` vector, and then fully aligned to the target by a further rotation around an axis perpendicular to both the `target` and `up` vectors. 500 Operations take place in global space. 501 */ 502 void lookAt(in Vector3 target, in Vector3 up) 503 { 504 checkClassBinding!(typeof(this))(); 505 ptrcall!(void)(_classBinding.lookAt, _godot_object, target, up); 506 } 507 /** 508 Moves the node to the specified `position`, and then rotates itself to point toward the `target` as per $(D lookAt). Operations take place in global space. 509 */ 510 void lookAtFromPosition(in Vector3 position, in Vector3 target, in Vector3 up) 511 { 512 checkClassBinding!(typeof(this))(); 513 ptrcall!(void)(_classBinding.lookAtFromPosition, _godot_object, position, target, up); 514 } 515 /** 516 Transforms $(D Vector3) "global_point" from world space to this node's local space. 517 */ 518 Vector3 toLocal(in Vector3 global_point) const 519 { 520 checkClassBinding!(typeof(this))(); 521 return ptrcall!(Vector3)(_classBinding.toLocal, _godot_object, global_point); 522 } 523 /** 524 Transforms $(D Vector3) "local_point" from this node's local space to world space. 525 */ 526 Vector3 toGlobal(in Vector3 local_point) const 527 { 528 checkClassBinding!(typeof(this))(); 529 return ptrcall!(Vector3)(_classBinding.toGlobal, _godot_object, local_point); 530 } 531 /** 532 World space (global) $(D Transform) of this node. 533 */ 534 @property Transform globalTransform() 535 { 536 return getGlobalTransform(); 537 } 538 /// ditto 539 @property void globalTransform(Transform v) 540 { 541 setGlobalTransform(v); 542 } 543 /** 544 Local translation of this node. 545 */ 546 @property Vector3 translation() 547 { 548 return getTranslation(); 549 } 550 /// ditto 551 @property void translation(Vector3 v) 552 { 553 setTranslation(v); 554 } 555 /** 556 Rotation part of the local transformation in degrees, specified in terms of YXZ-Euler angles in the format (X-angle, Y-angle, Z-angle). 557 */ 558 @property Vector3 rotationDegrees() 559 { 560 return getRotationDegrees(); 561 } 562 /// ditto 563 @property void rotationDegrees(Vector3 v) 564 { 565 setRotationDegrees(v); 566 } 567 /** 568 Rotation part of the local transformation in radians, specified in terms of YXZ-Euler angles in the format (X-angle, Y-angle, Z-angle). 569 Note that in the mathematical sense, rotation is a matrix and not a vector. The three Euler angles, which are the three independent parameters of the Euler-angle parametrization of the rotation matrix, are stored in a $(D Vector3) data structure not because the rotation is a vector, but only because $(D Vector3) exists as a convenient data-structure to store 3 floating point numbers. Therefore, applying affine operations on the rotation "vector" is not meaningful. 570 */ 571 @property Vector3 rotation() 572 { 573 return getRotation(); 574 } 575 /// ditto 576 @property void rotation(Vector3 v) 577 { 578 setRotation(v); 579 } 580 /** 581 Scale part of the local transformation. 582 */ 583 @property Vector3 scale() 584 { 585 return getScale(); 586 } 587 /// ditto 588 @property void scale(Vector3 v) 589 { 590 setScale(v); 591 } 592 /** 593 Local space $(D Transform) of this node, with respect to the parent node. 594 */ 595 @property Transform transform() 596 { 597 return getTransform(); 598 } 599 /// ditto 600 @property void transform(Transform v) 601 { 602 setTransform(v); 603 } 604 /** 605 If `true` this node is drawn. Default value: `true`. 606 */ 607 @property bool visible() 608 { 609 return isVisible(); 610 } 611 /// ditto 612 @property void visible(bool v) 613 { 614 setVisible(v); 615 } 616 /** 617 The SpatialGizmo for this node. Used for example in $(D EditorSpatialGizmo) as custom visualization and editing handles in Editor. 618 */ 619 @property SpatialGizmo gizmo() 620 { 621 return getGizmo(); 622 } 623 /// ditto 624 @property void gizmo(SpatialGizmo v) 625 { 626 setGizmo(v); 627 } 628 }