-
-
Notifications
You must be signed in to change notification settings - Fork 23.3k
Organize 3D editor code and rename a few 3D things #108767
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
base: master
Are you sure you want to change the base?
Conversation
3667a95
to
b60ef17
Compare
|
||
#include "core/object/gdvirtual.gen.inc" | ||
#include "core/object/ref_counted.h" | ||
#include "core/object/script_language.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a small number of cases where a header needs a class to work, but wasn't including it. These things were being included transitively when 3D is enabled in the editor, but fail to compile otherwise. This PR fixes these cases by adding the includes, including this one include in the core folder, and a few others elsewhere.
switch (p_what) { | ||
case NOTIFICATION_ENTER_TREE: { | ||
Node3DEditor::get_singleton()->connect(SNAME("transform_key_request"), callable_mp(this, &AnimationPlayerEditorPlugin::_transform_key_request)); | ||
Node3DEditor::get_singleton()->connect(SNAME("transform_3d_key_request"), callable_mp(this, &AnimationPlayerEditorPlugin::_transform_3d_key_request)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were a few APIs in the animation editor, and this signal for communicating with Node3DEditor
, with "transform" in the name, but these APIs only operate on 3D transform. I've renamed them with "3d" for clarity. These are internal APIs, not exposed anywhere.
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node); | ||
if (canvas_item) { | ||
new_additive_node_entry.transform_2d = canvas_item->get_transform(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This preserves the transform data of CanvasItems, though the data still doesn't end up being used currently. I didn't want to change too much in this PR but this would enable us to support Control nodes in EditorNode::reload_instances_with_path_in_edited_scenes()
later if we wanted to.
|
||
Ref<ORMMaterial3DConversionPlugin> orm_mat_convert; | ||
orm_mat_convert.instantiate(); | ||
resource_conversion_plugins.push_back(orm_mat_convert); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This groups together EditorNode's registration of 3D material conversion plugins.
void _insert_collision_object_rid_recursive(Node *p_node, HashSet<RID> &p_col_obj_rids) { | ||
CollisionObject3D *col_obj = Object::cast_to<CollisionObject3D>(p_node); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several renames for clarity, and to match Godot's p_
naming convention. node
-> p_node
, rids
-> p_col_obj_rids
, co
-> col_obj
, and below rids
-> col_obj_rids_to_exclude
.
AnimatedSprite2D *as2d = Object::cast_to<AnimatedSprite2D>(selected); | ||
AnimatedSprite3D *as3d = Object::cast_to<AnimatedSprite3D>(selected); | ||
if (as2d || as3d) { | ||
if (selected->has_method("get_sprite_frames")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is using ->call("get_sprite_frames")
immediately below, so this is less code and more straightforward of a check. Technically could allow user-made AnimatedSprite classes, but that wasn't a goal here, just a happy consequence.
} else if (res_atlas_texture.is_valid()) { | ||
r = res_atlas_texture->get_region(); | ||
} | ||
Rect2 r = _get_edited_object_region(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change reduces code duplication, since this logic is already present in the _get_edited_object_region
helper function. However, that function also contains this code:
const Ref<Texture2D> object_texture = _get_edited_object_texture();
if (region == Rect2() && object_texture.is_valid()) {
region = Rect2(Vector2(), object_texture->get_size());
}
I think that's fine, since it only happens when region
is a zero rect, and my guess is that using object_texture
's rect as a fallback is better than no fallback, but I can't be certain of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested it and don't see any difference in behavior.
undo_redo->add_do_method(node_sprite_3d, "set_region_rect", node_sprite_3d->get_region_rect()); | ||
undo_redo->add_undo_method(node_sprite_3d, "set_region_rect", rect_prev); | ||
} else if (node_ninepatch) { | ||
if (node_ninepatch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In these if statements, put Control-based things first, and Node2D/Node3D things after it. This is arguably more organized, but the motivation here was so you can put #ifndef _2D_DISABLED
above the } else if (condition) {
.
PhysicsServer3D::get_singleton()->body_add_shape(root_collision_instance, root_collision_shape->get_rid()); | ||
PhysicsServer3D::get_singleton()->body_set_space(root_collision_instance, get_world_3d()->get_space()); | ||
PhysicsServer3D::get_singleton()->body_attach_object_instance_id(root_collision_instance, get_instance_id()); | ||
root_collision_body = PhysicsServer3D::get_singleton()->body_create(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is only ever null or the result of body_create()
, so it's a body. The word "instance" is too generic, it's not clear if it's a body, area, shape, etc. Therefore, I renamed it.
This comment was marked as resolved.
This comment was marked as resolved.
b60ef17
to
3525dcf
Compare
3525dcf
to
49eed2c
Compare
49eed2c
to
73478e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally, it works as expected. Code looks good to me.
undo_redo->add_undo_method(this, "_set_owner_for_node_and_children", n2d, editor_root); | ||
} | ||
undo_redo->commit_action(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated noisy change IMO, I'd restore
|
||
case CONTAINER_SPATIAL_EDITOR_MENU: { | ||
Node3DEditor::get_singleton()->add_control_to_menu_panel(p_control); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove them, it's unnecessary noise for minor nitpicking change
// Make sure MeshLibrary is updated in the editor. | ||
ResourceLoader::load(p_file)->reload_from_file(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please restore
73478e9
to
b6fe79b
Compare
As a follow-up to some recent editor organization efforts, this PR organizes more of the 3D editor code.
The way I made this PR is by working on my own changes to allow disabling the 3D in the editor, but without any intention to merge those in. Instead, I want to only merge in organizational changes that makes sense even without that ability.
Rather than making a bulleted list, I have left review comments below. It may be a good idea to review this PR by reading those and using 👍 if that part looks good to you, or replying if not.