1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-12 13:20:55 +00:00

Merge pull request #8901 from tagcup/path_editor_plugin

Revive PathEditorPlugin.
This commit is contained in:
Rémi Verschelde
2017-05-26 07:58:13 +02:00
committed by GitHub
3 changed files with 195 additions and 238 deletions

View File

@@ -5944,7 +5944,7 @@ EditorNode::EditorNode() {
add_editor_plugin(memnew(Particles2DEditorPlugin(this))); add_editor_plugin(memnew(Particles2DEditorPlugin(this)));
add_editor_plugin(memnew(GIProbeEditorPlugin(this))); add_editor_plugin(memnew(GIProbeEditorPlugin(this)));
add_editor_plugin(memnew(Path2DEditorPlugin(this))); add_editor_plugin(memnew(Path2DEditorPlugin(this)));
//add_editor_plugin( memnew( PathEditorPlugin(this) ) ); add_editor_plugin(memnew(PathEditorPlugin(this)));
//add_editor_plugin( memnew( BakedLightEditorPlugin(this) ) ); //add_editor_plugin( memnew( BakedLightEditorPlugin(this) ) );
add_editor_plugin(memnew(Line2DEditorPlugin(this))); add_editor_plugin(memnew(Line2DEditorPlugin(this)));
add_editor_plugin(memnew(Polygon2DEditorPlugin(this))); add_editor_plugin(memnew(Polygon2DEditorPlugin(this)));

View File

@@ -33,7 +33,6 @@
#include "scene/resources/curve.h" #include "scene/resources/curve.h"
#include "spatial_editor_plugin.h" #include "spatial_editor_plugin.h"
#if 0
String PathSpatialGizmo::get_handle_name(int p_idx) const { String PathSpatialGizmo::get_handle_name(int p_idx) const {
Ref<Curve3D> c = path->get_curve(); Ref<Curve3D> c = path->get_curve();
@@ -56,8 +55,6 @@ String PathSpatialGizmo::get_handle_name(int p_idx) const {
n += " Out"; n += " Out";
return n; return n;
} }
Variant PathSpatialGizmo::get_handle_value(int p_idx) const { Variant PathSpatialGizmo::get_handle_value(int p_idx) const {
@@ -85,7 +82,6 @@ Variant PathSpatialGizmo::get_handle_value(int p_idx) const{
original = ofs + c->get_point_pos(idx); original = ofs + c->get_point_pos(idx);
return ofs; return ofs;
} }
void PathSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_point) { void PathSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_point) {
@@ -106,8 +102,7 @@ void PathSpatialGizmo::set_handle(int p_idx,Camera *p_camera, const Point2& p_po
if (p.intersects_ray(ray_from, ray_dir, &inters)) { if (p.intersects_ray(ray_from, ray_dir, &inters)) {
if(SpatialEditor::get_singleton()->is_snap_enabled()) if (SpatialEditor::get_singleton()->is_snap_enabled()) {
{
float snap = SpatialEditor::get_singleton()->get_translate_snap(); float snap = SpatialEditor::get_singleton()->get_translate_snap();
inters.snap(snap); inters.snap(snap);
} }
@@ -139,7 +134,6 @@ void PathSpatialGizmo::set_handle(int p_idx,Camera *p_camera, const Point2& p_po
c->set_point_out(idx, local); c->set_point_out(idx, local);
} }
} }
} }
void PathSpatialGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_cancel) { void PathSpatialGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_cancel) {
@@ -174,13 +168,9 @@ void PathSpatialGizmo::commit_handle(int p_idx,const Variant& p_restore,bool p_c
if (p_cancel) { if (p_cancel) {
return; return;
} }
if (t == 0) { if (t == 0) {
if (p_cancel) { if (p_cancel) {
@@ -193,7 +183,6 @@ void PathSpatialGizmo::commit_handle(int p_idx,const Variant& p_restore,bool p_c
ur->add_undo_method(c.ptr(), "set_point_in", idx, p_restore); ur->add_undo_method(c.ptr(), "set_point_in", idx, p_restore);
ur->commit_action(); ur->commit_action();
} else { } else {
if (p_cancel) { if (p_cancel) {
@@ -204,12 +193,9 @@ void PathSpatialGizmo::commit_handle(int p_idx,const Variant& p_restore,bool p_c
ur->add_do_method(c.ptr(), "set_point_out", idx, c->get_point_out(idx)); ur->add_do_method(c.ptr(), "set_point_out", idx, c->get_point_out(idx));
ur->add_undo_method(c.ptr(), "set_point_out", idx, p_restore); ur->add_undo_method(c.ptr(), "set_point_out", idx, p_restore);
ur->commit_action(); ur->commit_action();
} }
} }
void PathSpatialGizmo::redraw() { void PathSpatialGizmo::redraw() {
clear(); clear();
@@ -218,15 +204,16 @@ void PathSpatialGizmo::redraw(){
if (c.is_null()) if (c.is_null())
return; return;
Vector3Array v3a=c->tesselate(); PoolVector<Vector3> v3a = c->tesselate();
//Vector3Array v3a=c->get_baked_points(); //PoolVector<Vector3> v3a=c->get_baked_points();
int v3s = v3a.size(); int v3s = v3a.size();
if (v3s == 0) if (v3s == 0)
return; return;
Vector<Vector3> v3p; Vector<Vector3> v3p;
Vector3Array::Read r = v3a.read(); PoolVector<Vector3>::Read r = v3a.read();
// BUG: the following won't work when v3s, avoid drawing as a temporary workaround.
for (int i = 0; i < v3s - 1; i++) { for (int i = 0; i < v3s - 1; i++) {
v3p.push_back(r[i]); v3p.push_back(r[i]);
@@ -264,21 +251,16 @@ void PathSpatialGizmo::redraw(){
add_handles(handles); add_handles(handles);
add_handles(sec_handles, false, true); add_handles(sec_handles, false, true);
} }
} }
PathSpatialGizmo::PathSpatialGizmo(Path *p_path) { PathSpatialGizmo::PathSpatialGizmo(Path *p_path) {
path = p_path; path = p_path;
set_spatial_node(p_path); set_spatial_node(p_path);
} }
Ref<SpatialEditorGizmo> PathEditorPlugin::create_spatial_gizmo(Spatial *p_spatial) { Ref<SpatialEditorGizmo> PathEditorPlugin::create_spatial_gizmo(Spatial *p_spatial) {
if (p_spatial->cast_to<Path>()) { if (p_spatial->cast_to<Path>()) {
return memnew(PathSpatialGizmo(p_spatial->cast_to<Path>())); return memnew(PathSpatialGizmo(p_spatial->cast_to<Path>()));
@@ -287,7 +269,7 @@ Ref<SpatialEditorGizmo> PathEditorPlugin::create_spatial_gizmo(Spatial* p_spatia
return Ref<SpatialEditorGizmo>(); return Ref<SpatialEditorGizmo>();
} }
bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera,const InputEvent& p_event) { bool PathEditorPlugin::forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event) {
if (!path) if (!path)
return false; return false;
@@ -299,15 +281,15 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera,const InputEve
static const int click_dist = 10; //should make global static const int click_dist = 10; //should make global
Ref<InputEventMouseButton> mb = p_event;
if (p_event.type==InputEvent::MOUSE_BUTTON) { if (mb.is_valid()) {
const InputEventMouseButton &mb=p_event.mouse_button;
Point2 mbpos(mb->get_pos().x, mb->get_pos().y); Point2 mbpos(mb->get_pos().x, mb->get_pos().y);
if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && (curve_create->is_pressed() || (curve_edit->is_pressed() && mb->get_control()))) { if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && (curve_create->is_pressed() || (curve_edit->is_pressed() && mb->get_control()))) {
//click into curve, break it down //click into curve, break it down
Vector3Array v3a = c->tesselate(); PoolVector<Vector3> v3a = c->tesselate();
int idx = 0; int idx = 0;
int rc = v3a.size(); int rc = v3a.size();
int closest_seg = -1; int closest_seg = -1;
@@ -315,19 +297,17 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera,const InputEve
float closest_d = 1e20; float closest_d = 1e20;
if (rc >= 2) { if (rc >= 2) {
Vector3Array::Read r = v3a.read(); PoolVector<Vector3>::Read r = v3a.read();
if (p_camera->unproject_position(gt.xform(c->get_point_pos(0))).distance_to(mbpos) < click_dist) if (p_camera->unproject_position(gt.xform(c->get_point_pos(0))).distance_to(mbpos) < click_dist)
return false; //nope, existing return false; //nope, existing
for (int i = 0; i < c->get_point_count() - 1; i++) { for (int i = 0; i < c->get_point_count() - 1; i++) {
//find the offset and point index of the place to break up //find the offset and point index of the place to break up
int j = idx; int j = idx;
if (p_camera->unproject_position(gt.xform(c->get_point_pos(i + 1))).distance_to(mbpos) < click_dist) if (p_camera->unproject_position(gt.xform(c->get_point_pos(i + 1))).distance_to(mbpos) < click_dist)
return false; //nope, existing return false; //nope, existing
while (j < rc && c->get_point_pos(i + 1) != r[j]) { while (j < rc && c->get_point_pos(i + 1) != r[j]) {
Vector3 from = r[j]; Vector3 from = r[j];
@@ -344,7 +324,6 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera,const InputEve
if (d < 10 && d < closest_d) { if (d < 10 && d < closest_d) {
closest_d = d; closest_d = d;
closest_seg = i; closest_seg = i;
Vector3 ray_from = p_camera->project_ray_origin(mbpos); Vector3 ray_from = p_camera->project_ray_origin(mbpos);
@@ -355,17 +334,14 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera,const InputEve
closest_seg_point = it.xform(rb); closest_seg_point = it.xform(rb);
} }
} }
j++; j++;
} }
if (idx == j) if (idx == j)
idx++; //force next idx++; //force next
else else
idx = j; //swap idx = j; //swap
if (j == rc) if (j == rc)
break; break;
} }
@@ -387,7 +363,7 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera,const InputEve
if (c->get_point_count() == 0) if (c->get_point_count() == 0)
org = path->get_transform().get_origin(); org = path->get_transform().get_origin();
else else
org=gt.xform(c->get_point_pos(c->get_point_count())); org = gt.xform(c->get_point_pos(c->get_point_count() - 1));
Plane p(org, p_camera->get_transform().basis.get_axis(2)); Plane p(org, p_camera->get_transform().basis.get_axis(2));
Vector3 ray_from = p_camera->project_ray_origin(mbpos); Vector3 ray_from = p_camera->project_ray_origin(mbpos);
Vector3 ray_dir = p_camera->project_ray_normal(mbpos); Vector3 ray_dir = p_camera->project_ray_normal(mbpos);
@@ -441,13 +417,11 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera,const InputEve
} }
} }
} }
} }
return false; return false;
} }
void PathEditorPlugin::edit(Object *p_object) { void PathEditorPlugin::edit(Object *p_object) {
if (p_object) { if (p_object) {
@@ -470,7 +444,7 @@ void PathEditorPlugin::edit(Object *p_object) {
bool PathEditorPlugin::handles(Object *p_object) const { bool PathEditorPlugin::handles(Object *p_object) const {
return p_object->is_type("Path"); return p_object->is_class("Path");
} }
void PathEditorPlugin::make_visible(bool p_visible) { void PathEditorPlugin::make_visible(bool p_visible) {
@@ -498,7 +472,6 @@ void PathEditorPlugin::make_visible(bool p_visible) {
} }
} }
} }
} }
void PathEditorPlugin::_mode_changed(int p_idx) { void PathEditorPlugin::_mode_changed(int p_idx) {
@@ -516,7 +489,6 @@ void PathEditorPlugin::_close_curve() {
if (c->get_point_count() < 2) if (c->get_point_count() < 2)
return; return;
c->add_point(c->get_point_pos(0), c->get_point_in(0), c->get_point_out(0)); c->add_point(c->get_point_pos(0), c->get_point_in(0), c->get_point_out(0));
} }
void PathEditorPlugin::_notification(int p_what) { void PathEditorPlugin::_notification(int p_what) {
@@ -538,7 +510,6 @@ void PathEditorPlugin::_bind_methods() {
PathEditorPlugin *PathEditorPlugin::singleton = NULL; PathEditorPlugin *PathEditorPlugin::singleton = NULL;
PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) { PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) {
path = NULL; path = NULL;
@@ -546,18 +517,18 @@ PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) {
singleton = this; singleton = this;
path_material = Ref<SpatialMaterial>(memnew(SpatialMaterial)); path_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
path_material->set_parameter( SpatialMaterial::PARAM_DIFFUSE,Color(0.5,0.5,1.0,0.8) ); path_material->set_albedo(Color(0.5, 0.5, 1.0, 0.8));
path_material->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA, true); path_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
path_material->set_line_width(3); path_material->set_line_width(3);
path_material->set_flag(Material::FLAG_DOUBLE_SIDED,true); path_material->set_cull_mode(SpatialMaterial::CULL_DISABLED);
path_material->set_flag(Material::FLAG_UNSHADED,true); path_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
path_thin_material = Ref<SpatialMaterial>(memnew(SpatialMaterial)); path_thin_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
path_thin_material->set_parameter( SpatialMaterial::PARAM_DIFFUSE,Color(0.5,0.5,1.0,0.4) ); path_thin_material->set_albedo(Color(0.5, 0.5, 1.0, 0.4));
path_thin_material->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA, true); path_thin_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
path_thin_material->set_line_width(1); path_thin_material->set_line_width(1);
path_thin_material->set_flag(Material::FLAG_DOUBLE_SIDED,true); path_thin_material->set_cull_mode(SpatialMaterial::CULL_DISABLED);
path_thin_material->set_flag(Material::FLAG_UNSHADED,true); path_thin_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
//SpatialEditor::get_singleton()->add_gizmo_plugin(this); //SpatialEditor::get_singleton()->add_gizmo_plugin(this);
@@ -592,8 +563,6 @@ PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) {
curve_close->set_tooltip(TTR("Close Curve")); curve_close->set_tooltip(TTR("Close Curve"));
SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_close); SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_close);
curve_edit->set_pressed(true); curve_edit->set_pressed(true);
/* /*
collision_polygon_editor = memnew( PathEditor(p_node) ); collision_polygon_editor = memnew( PathEditor(p_node) );
@@ -607,13 +576,7 @@ PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) {
collision_polygon_editor->hide(); collision_polygon_editor->hide();
*/ */
} }
PathEditorPlugin::~PathEditorPlugin() {
PathEditorPlugin::~PathEditorPlugin()
{
} }
#endif

View File

@@ -32,7 +32,7 @@
#include "editor/spatial_editor_gizmos.h" #include "editor/spatial_editor_gizmos.h"
#include "scene/3d/path.h" #include "scene/3d/path.h"
#if 0
class PathSpatialGizmo : public EditorSpatialGizmo { class PathSpatialGizmo : public EditorSpatialGizmo {
GDCLASS(PathSpatialGizmo, EditorSpatialGizmo); GDCLASS(PathSpatialGizmo, EditorSpatialGizmo);
@@ -41,7 +41,6 @@ class PathSpatialGizmo : public EditorSpatialGizmo {
mutable Vector3 original; mutable Vector3 original;
public: public:
virtual String get_handle_name(int p_idx) const; virtual String get_handle_name(int p_idx) const;
virtual Variant get_handle_value(int p_idx) const; virtual Variant get_handle_value(int p_idx) const;
virtual void set_handle(int p_idx, Camera *p_camera, const Point2 &p_point); virtual void set_handle(int p_idx, Camera *p_camera, const Point2 &p_point);
@@ -49,14 +48,12 @@ public:
void redraw(); void redraw();
PathSpatialGizmo(Path *p_path = NULL); PathSpatialGizmo(Path *p_path = NULL);
}; };
class PathEditorPlugin : public EditorPlugin { class PathEditorPlugin : public EditorPlugin {
GDCLASS(PathEditorPlugin, EditorPlugin); GDCLASS(PathEditorPlugin, EditorPlugin);
Separator *sep; Separator *sep;
ToolButton *curve_create; ToolButton *curve_create;
ToolButton *curve_edit; ToolButton *curve_edit;
@@ -65,23 +62,22 @@ class PathEditorPlugin : public EditorPlugin {
EditorNode *editor; EditorNode *editor;
Path *path; Path *path;
void _mode_changed(int p_idx); void _mode_changed(int p_idx);
void _close_curve(); void _close_curve();
protected: protected:
void _notification(int p_what); void _notification(int p_what);
static void _bind_methods(); static void _bind_methods();
public: public:
Path *get_edited_path() { return path; } Path *get_edited_path() { return path; }
static PathEditorPlugin *singleton; static PathEditorPlugin *singleton;
Ref<SpatialMaterial> path_material; Ref<SpatialMaterial> path_material;
Ref<SpatialMaterial> path_thin_material; Ref<SpatialMaterial> path_thin_material;
virtual bool forward_spatial_gui_input(Camera* p_camera,const InputEvent& p_event); virtual bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event);
//virtual bool forward_gui_input(const InputEvent& p_event) { return collision_polygon_editor->forward_gui_input(p_event); } //virtual bool forward_gui_input(const InputEvent& p_event) { return collision_polygon_editor->forward_gui_input(p_event); }
virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial *p_spatial); virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial *p_spatial);
@@ -93,8 +89,6 @@ public:
PathEditorPlugin(EditorNode *p_node); PathEditorPlugin(EditorNode *p_node);
~PathEditorPlugin(); ~PathEditorPlugin();
}; };
#endif
#endif // PATH_EDITOR_PLUGIN_H #endif // PATH_EDITOR_PLUGIN_H