Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global_basis property to Node3D #80512

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/classes/Node3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@
<member name="basis" type="Basis" setter="set_basis" getter="get_basis">
Direct access to the 3x3 basis of the [member transform] property.
</member>
<member name="global_basis" type="Basis" setter="set_global_basis" getter="get_global_basis">
Global basis of this node. This is equivalent to [code]global_transform.basis[/code].
</member>
<member name="global_position" type="Vector3" setter="set_global_position" getter="get_global_position">
Global position of this node. This is equivalent to [code]global_transform.origin[/code].
</member>
Expand Down
15 changes: 15 additions & 0 deletions scene/3d/node_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,25 @@ Vector3 Node3D::get_global_position() const {
return get_global_transform().get_origin();
}

Basis Node3D::get_global_basis() const {
ERR_READ_THREAD_GUARD_V(Basis());
return get_global_transform().get_basis();
}

void Node3D::set_global_position(const Vector3 &p_position) {
ERR_THREAD_GUARD;
Transform3D transform = get_global_transform();
transform.set_origin(p_position);
set_global_transform(transform);
}

void Node3D::set_global_basis(const Basis &p_basis) {
ERR_THREAD_GUARD;
Transform3D transform = get_global_transform();
transform.set_basis(p_basis);
set_global_transform(transform);
}

Vector3 Node3D::get_global_rotation() const {
ERR_READ_THREAD_GUARD_V(Vector3());
return get_global_transform().get_basis().get_euler();
Expand Down Expand Up @@ -1110,6 +1122,8 @@ void Node3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_global_transform"), &Node3D::get_global_transform);
ClassDB::bind_method(D_METHOD("set_global_position", "position"), &Node3D::set_global_position);
ClassDB::bind_method(D_METHOD("get_global_position"), &Node3D::get_global_position);
ClassDB::bind_method(D_METHOD("set_global_basis", "basis"), &Node3D::set_global_basis);
ClassDB::bind_method(D_METHOD("get_global_basis"), &Node3D::get_global_basis);
ClassDB::bind_method(D_METHOD("set_global_rotation", "euler_radians"), &Node3D::set_global_rotation);
ClassDB::bind_method(D_METHOD("get_global_rotation"), &Node3D::get_global_rotation);
ClassDB::bind_method(D_METHOD("set_global_rotation_degrees", "euler_degrees"), &Node3D::set_global_rotation_degrees);
Expand Down Expand Up @@ -1191,6 +1205,7 @@ void Node3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "top_level"), "set_as_top_level", "is_set_as_top_level");

ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "global_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_position", "get_global_position");
ADD_PROPERTY(PropertyInfo(Variant::BASIS, "global_basis", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_basis", "get_global_basis");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "global_rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_rotation", "get_global_rotation");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "global_rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_rotation_degrees", "get_global_rotation_degrees");
ADD_GROUP("Visibility", "");
Expand Down
2 changes: 2 additions & 0 deletions scene/3d/node_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class Node3D : public Node {
void set_scale(const Vector3 &p_scale);

void set_global_position(const Vector3 &p_position);
void set_global_basis(const Basis &p_basis);
void set_global_rotation(const Vector3 &p_euler_rad);
void set_global_rotation_degrees(const Vector3 &p_euler_degrees);

Expand All @@ -193,6 +194,7 @@ class Node3D : public Node {
Vector3 get_scale() const;

Vector3 get_global_position() const;
Basis get_global_basis() const;
Vector3 get_global_rotation() const;
Vector3 get_global_rotation_degrees() const;

Expand Down