Merge pull request #80802 from xiongyaohua/path3d_gizmo_usability
Improve Path3D gizmo usability
This commit is contained in:
commit
cb4879a876
2 changed files with 35 additions and 17 deletions
|
@ -274,6 +274,7 @@ void Path3DGizmo::redraw() {
|
|||
|
||||
Ref<StandardMaterial3D> path_material = gizmo_plugin->get_material("path_material", this);
|
||||
Ref<StandardMaterial3D> path_thin_material = gizmo_plugin->get_material("path_thin_material", this);
|
||||
Ref<StandardMaterial3D> path_tilt_material = gizmo_plugin->get_material("path_tilt_material", this);
|
||||
Ref<StandardMaterial3D> handles_material = gizmo_plugin->get_material("handles");
|
||||
Ref<StandardMaterial3D> sec_handles_material = gizmo_plugin->get_material("sec_handles");
|
||||
|
||||
|
@ -339,6 +340,7 @@ void Path3DGizmo::redraw() {
|
|||
// 2. Draw handles when selected.
|
||||
if (Path3DEditorPlugin::singleton->get_edited_path() == path) {
|
||||
PackedVector3Array handle_lines;
|
||||
PackedVector3Array tilt_handle_lines;
|
||||
PackedVector3Array primary_handle_points;
|
||||
PackedVector3Array secondary_handle_points;
|
||||
PackedInt32Array collected_secondary_handle_ids; // Avoid shadowing member on Node3DEditorGizmo.
|
||||
|
@ -367,7 +369,7 @@ void Path3DGizmo::redraw() {
|
|||
}
|
||||
|
||||
// Collect out-handles except for the last point.
|
||||
if (idx < c->get_point_count()) {
|
||||
if (idx < c->get_point_count() - 1) {
|
||||
info.type = HandleType::HANDLE_TYPE_OUT;
|
||||
const int handle_idx = idx * 3 + 1;
|
||||
collected_secondary_handle_ids.append(handle_idx);
|
||||
|
@ -389,9 +391,9 @@ void Path3DGizmo::redraw() {
|
|||
|
||||
const Basis posture = c->get_point_baked_posture(idx, true);
|
||||
const Vector3 up = posture.get_column(1);
|
||||
secondary_handle_points.append(pos + up);
|
||||
handle_lines.append(pos);
|
||||
handle_lines.append(pos + up);
|
||||
secondary_handle_points.append(pos + up * disk_size);
|
||||
tilt_handle_lines.append(pos);
|
||||
tilt_handle_lines.append(pos + up * disk_size);
|
||||
}
|
||||
|
||||
// Tilt disk.
|
||||
|
@ -403,13 +405,13 @@ void Path3DGizmo::redraw() {
|
|||
PackedVector3Array disk;
|
||||
disk.append(pos);
|
||||
|
||||
const int n = 24;
|
||||
const int n = 36;
|
||||
for (int i = 0; i <= n; i++) {
|
||||
const float a = Math_TAU * i / n;
|
||||
const Vector3 edge = sin(a) * side + cos(a) * up;
|
||||
disk.append(pos + edge);
|
||||
disk.append(pos + edge * disk_size);
|
||||
}
|
||||
add_vertices(disk, path_material, Mesh::PRIMITIVE_LINE_STRIP);
|
||||
add_vertices(disk, path_tilt_material, Mesh::PRIMITIVE_LINE_STRIP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -417,6 +419,11 @@ void Path3DGizmo::redraw() {
|
|||
if (handle_lines.size() > 1) {
|
||||
add_lines(handle_lines, path_thin_material);
|
||||
}
|
||||
|
||||
if (tilt_handle_lines.size() > 1) {
|
||||
add_lines(tilt_handle_lines, path_tilt_material);
|
||||
}
|
||||
|
||||
if (primary_handle_points.size()) {
|
||||
add_handles(primary_handle_points, handles_material);
|
||||
}
|
||||
|
@ -426,8 +433,9 @@ void Path3DGizmo::redraw() {
|
|||
}
|
||||
}
|
||||
|
||||
Path3DGizmo::Path3DGizmo(Path3D *p_path) {
|
||||
Path3DGizmo::Path3DGizmo(Path3D *p_path, float p_disk_size) {
|
||||
path = p_path;
|
||||
disk_size = p_disk_size;
|
||||
set_node_3d(p_path);
|
||||
orig_in_length = 0;
|
||||
orig_out_length = 0;
|
||||
|
@ -555,7 +563,7 @@ EditorPlugin::AfterGUIInput Path3DEditorPlugin::forward_3d_gui_input(Camera3D *p
|
|||
real_t dist_to_p = p_camera->unproject_position(gt.xform(c->get_point_position(i))).distance_to(mbpos);
|
||||
real_t dist_to_p_out = p_camera->unproject_position(gt.xform(c->get_point_position(i) + c->get_point_out(i))).distance_to(mbpos);
|
||||
real_t dist_to_p_in = p_camera->unproject_position(gt.xform(c->get_point_position(i) + c->get_point_in(i))).distance_to(mbpos);
|
||||
real_t dist_to_p_up = p_camera->unproject_position(gt.xform(c->get_point_position(i) + c->get_point_baked_posture(i, true).get_column(1))).distance_to(mbpos);
|
||||
real_t dist_to_p_up = p_camera->unproject_position(gt.xform(c->get_point_position(i) + c->get_point_baked_posture(i, true).get_column(1) * disk_size)).distance_to(mbpos);
|
||||
|
||||
// Find the offset and point index of the place to break up.
|
||||
// Also check for the control points.
|
||||
|
@ -721,8 +729,9 @@ Path3DEditorPlugin::Path3DEditorPlugin() {
|
|||
mirror_handle_angle = true;
|
||||
mirror_handle_length = true;
|
||||
|
||||
Ref<Path3DGizmoPlugin> gizmo_plugin;
|
||||
gizmo_plugin.instantiate();
|
||||
disk_size = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_settings/path3d_tilt_disk_size", 0.8);
|
||||
|
||||
Ref<Path3DGizmoPlugin> gizmo_plugin = memnew(Path3DGizmoPlugin(disk_size));
|
||||
Node3DEditor::get_singleton()->add_gizmo_plugin(gizmo_plugin);
|
||||
|
||||
topmenu_bar = memnew(HBoxContainer);
|
||||
|
@ -789,7 +798,7 @@ Ref<EditorNode3DGizmo> Path3DGizmoPlugin::create_gizmo(Node3D *p_spatial) {
|
|||
|
||||
Path3D *path = Object::cast_to<Path3D>(p_spatial);
|
||||
if (path) {
|
||||
ref = Ref<Path3DGizmo>(memnew(Path3DGizmo(path)));
|
||||
ref = Ref<Path3DGizmo>(memnew(Path3DGizmo(path, disk_size)));
|
||||
}
|
||||
|
||||
return ref;
|
||||
|
@ -803,10 +812,14 @@ int Path3DGizmoPlugin::get_priority() const {
|
|||
return -1;
|
||||
}
|
||||
|
||||
Path3DGizmoPlugin::Path3DGizmoPlugin() {
|
||||
Color path_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/path", Color(0.5, 0.5, 1.0, 0.8));
|
||||
Path3DGizmoPlugin::Path3DGizmoPlugin(float p_disk_size) {
|
||||
Color path_color = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/path", Color(0.5, 0.5, 1.0, 0.9));
|
||||
Color path_tilt_color = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/path_tilt", Color(1.0, 1.0, 0.4, 0.9));
|
||||
disk_size = p_disk_size;
|
||||
|
||||
create_material("path_material", path_color);
|
||||
create_material("path_thin_material", Color(0.5, 0.5, 0.5));
|
||||
create_material("path_thin_material", Color(0.6, 0.6, 0.6));
|
||||
create_material("path_tilt_material", path_tilt_color);
|
||||
create_handle_material("handles", false, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("EditorPathSmoothHandle"), EditorStringName(EditorIcons)));
|
||||
create_handle_material("sec_handles", false, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("EditorCurveHandle"), EditorStringName(EditorIcons)));
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ class Path3DGizmo : public EditorNode3DGizmo {
|
|||
mutable Vector3 original;
|
||||
mutable float orig_in_length;
|
||||
mutable float orig_out_length;
|
||||
mutable float disk_size = 0.8;
|
||||
|
||||
// Cache information of secondary handles.
|
||||
Vector<HandleInfo> _secondary_handles_info;
|
||||
|
@ -69,19 +70,21 @@ public:
|
|||
virtual void commit_handle(int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
|
||||
|
||||
virtual void redraw() override;
|
||||
Path3DGizmo(Path3D *p_path = nullptr);
|
||||
Path3DGizmo(Path3D *p_path = nullptr, float p_disk_size = 0.8);
|
||||
};
|
||||
|
||||
class Path3DGizmoPlugin : public EditorNode3DGizmoPlugin {
|
||||
GDCLASS(Path3DGizmoPlugin, EditorNode3DGizmoPlugin);
|
||||
|
||||
float disk_size = 0.8;
|
||||
|
||||
protected:
|
||||
Ref<EditorNode3DGizmo> create_gizmo(Node3D *p_spatial) override;
|
||||
|
||||
public:
|
||||
String get_gizmo_name() const override;
|
||||
int get_priority() const override;
|
||||
Path3DGizmoPlugin();
|
||||
Path3DGizmoPlugin(float p_disk_size);
|
||||
};
|
||||
|
||||
class Path3DEditorPlugin : public EditorPlugin {
|
||||
|
@ -95,6 +98,8 @@ class Path3DEditorPlugin : public EditorPlugin {
|
|||
Button *curve_close = nullptr;
|
||||
MenuButton *handle_menu = nullptr;
|
||||
|
||||
float disk_size = 0.8;
|
||||
|
||||
enum Mode {
|
||||
MODE_CREATE,
|
||||
MODE_EDIT,
|
||||
|
|
Loading…
Reference in a new issue