Applied clang-format.

Since PathEditorPlugin was commented out, it didn't get clang-format'ed.
This commit is contained in:
Ferenc Arn 2017-05-24 17:11:20 -05:00
parent fdf301e78b
commit 42de893f9a
3 changed files with 181 additions and 223 deletions

View File

@ -5988,7 +5988,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

@ -39,54 +39,51 @@ String PathSpatialGizmo::get_handle_name(int p_idx) const {
if (c.is_null()) if (c.is_null())
return ""; return "";
if (p_idx<c->get_point_count()) { if (p_idx < c->get_point_count()) {
return TTR("Curve Point #")+itos(p_idx); return TTR("Curve Point #") + itos(p_idx);
} }
p_idx=p_idx-c->get_point_count()+1; p_idx = p_idx - c->get_point_count() + 1;
int idx=p_idx/2; int idx = p_idx / 2;
int t=p_idx%2; int t = p_idx % 2;
String n = TTR("Curve Point #")+itos(idx); String n = TTR("Curve Point #") + itos(idx);
if (t==0) if (t == 0)
n+=" In"; n += " In";
else else
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 {
Ref<Curve3D> c = path->get_curve(); Ref<Curve3D> c = path->get_curve();
if (c.is_null()) if (c.is_null())
return Variant(); return Variant();
if (p_idx<c->get_point_count()) { if (p_idx < c->get_point_count()) {
original=c->get_point_pos(p_idx); original = c->get_point_pos(p_idx);
return original; return original;
} }
p_idx=p_idx-c->get_point_count()+1; p_idx = p_idx - c->get_point_count() + 1;
int idx=p_idx/2; int idx = p_idx / 2;
int t=p_idx%2; int t = p_idx % 2;
Vector3 ofs; Vector3 ofs;
if (t==0) if (t == 0)
ofs=c->get_point_in(idx); ofs = c->get_point_in(idx);
else else
ofs= c->get_point_out(idx); ofs = c->get_point_out(idx);
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) {
Ref<Curve3D> c = path->get_curve(); Ref<Curve3D> c = path->get_curve();
if (c.is_null()) if (c.is_null())
@ -97,51 +94,49 @@ void PathSpatialGizmo::set_handle(int p_idx,Camera *p_camera, const Point2& p_po
Vector3 ray_from = p_camera->project_ray_origin(p_point); Vector3 ray_from = p_camera->project_ray_origin(p_point);
Vector3 ray_dir = p_camera->project_ray_normal(p_point); Vector3 ray_dir = p_camera->project_ray_normal(p_point);
if (p_idx<c->get_point_count()) { if (p_idx < c->get_point_count()) {
Plane p(gt.xform(original),p_camera->get_transform().basis.get_axis(2)); Plane p(gt.xform(original), p_camera->get_transform().basis.get_axis(2));
Vector3 inters; Vector3 inters;
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);
} }
Vector3 local = gi.xform(inters); Vector3 local = gi.xform(inters);
c->set_point_pos(p_idx,local); c->set_point_pos(p_idx, local);
} }
return; return;
} }
p_idx=p_idx-c->get_point_count()+1; p_idx = p_idx - c->get_point_count() + 1;
int idx=p_idx/2; int idx = p_idx / 2;
int t=p_idx%2; int t = p_idx % 2;
Vector3 base = c->get_point_pos(idx); Vector3 base = c->get_point_pos(idx);
Plane p(gt.xform(original),p_camera->get_transform().basis.get_axis(2)); Plane p(gt.xform(original), p_camera->get_transform().basis.get_axis(2));
Vector3 inters; Vector3 inters;
if (p.intersects_ray(ray_from,ray_dir,&inters)) { if (p.intersects_ray(ray_from, ray_dir, &inters)) {
Vector3 local = gi.xform(inters)-base; Vector3 local = gi.xform(inters) - base;
if (t==0) { if (t == 0) {
c->set_point_in(idx,local); c->set_point_in(idx, local);
} else { } else {
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) {
Ref<Curve3D> c = path->get_curve(); Ref<Curve3D> c = path->get_curve();
if (c.is_null()) if (c.is_null())
@ -149,67 +144,59 @@ void PathSpatialGizmo::commit_handle(int p_idx,const Variant& p_restore,bool p_c
UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo(); UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo();
if (p_idx<c->get_point_count()) { if (p_idx < c->get_point_count()) {
if (p_cancel) { if (p_cancel) {
c->set_point_pos(p_idx,p_restore); c->set_point_pos(p_idx, p_restore);
return; return;
} }
ur->create_action(TTR("Set Curve Point Pos")); ur->create_action(TTR("Set Curve Point Pos"));
ur->add_do_method(c.ptr(),"set_point_pos",p_idx,c->get_point_pos(p_idx)); ur->add_do_method(c.ptr(), "set_point_pos", p_idx, c->get_point_pos(p_idx));
ur->add_undo_method(c.ptr(),"set_point_pos",p_idx,p_restore); ur->add_undo_method(c.ptr(), "set_point_pos", p_idx, p_restore);
ur->commit_action(); ur->commit_action();
return; return;
} }
p_idx=p_idx-c->get_point_count()+1; p_idx = p_idx - c->get_point_count() + 1;
int idx=p_idx/2; int idx = p_idx / 2;
int t=p_idx%2; int t = p_idx % 2;
Vector3 ofs; Vector3 ofs;
if (p_cancel) { if (p_cancel) {
return; return;
} }
if (t == 0) {
if (t==0) {
if (p_cancel) { if (p_cancel) {
c->set_point_in(p_idx,p_restore); c->set_point_in(p_idx, p_restore);
return; return;
} }
ur->create_action(TTR("Set Curve In Pos")); ur->create_action(TTR("Set Curve In Pos"));
ur->add_do_method(c.ptr(),"set_point_in",idx,c->get_point_in(idx)); ur->add_do_method(c.ptr(), "set_point_in", idx, c->get_point_in(idx));
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) {
c->set_point_out(idx,p_restore); c->set_point_out(idx, p_restore);
return; return;
} }
ur->create_action(TTR("Set Curve Out Pos")); ur->create_action(TTR("Set Curve Out Pos"));
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();
@ -217,81 +204,76 @@ void PathSpatialGizmo::redraw(){
if (c.is_null()) if (c.is_null())
return; return;
PoolVector<Vector3> v3a=c->tesselate(); PoolVector<Vector3> v3a = c->tesselate();
//PoolVector<Vector3> 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;
PoolVector<Vector3>::Read r = v3a.read(); PoolVector<Vector3>::Read r = v3a.read();
// BUG: the following won't work when v3s, avoid drawing as a temporary workaround. // 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]);
v3p.push_back(r[i+1]); v3p.push_back(r[i + 1]);
//v3p.push_back(r[i]); //v3p.push_back(r[i]);
//v3p.push_back(r[i]+Vector3(0,0.2,0)); //v3p.push_back(r[i]+Vector3(0,0.2,0));
} }
add_lines(v3p,PathEditorPlugin::singleton->path_material); add_lines(v3p, PathEditorPlugin::singleton->path_material);
add_collision_segments(v3p); add_collision_segments(v3p);
if (PathEditorPlugin::singleton->get_edited_path()==path) { if (PathEditorPlugin::singleton->get_edited_path() == path) {
v3p.clear(); v3p.clear();
Vector<Vector3> handles; Vector<Vector3> handles;
Vector<Vector3> sec_handles; Vector<Vector3> sec_handles;
for(int i=0;i<c->get_point_count();i++) { for (int i = 0; i < c->get_point_count(); i++) {
Vector3 p = c->get_point_pos(i); Vector3 p = c->get_point_pos(i);
handles.push_back(p); handles.push_back(p);
if (i>0) { if (i > 0) {
v3p.push_back(p); v3p.push_back(p);
v3p.push_back(p+c->get_point_in(i)); v3p.push_back(p + c->get_point_in(i));
sec_handles.push_back(p+c->get_point_in(i)); sec_handles.push_back(p + c->get_point_in(i));
} }
if (i<c->get_point_count()-1) { if (i < c->get_point_count() - 1) {
v3p.push_back(p); v3p.push_back(p);
v3p.push_back(p+c->get_point_out(i)); v3p.push_back(p + c->get_point_out(i));
sec_handles.push_back(p+c->get_point_out(i)); sec_handles.push_back(p + c->get_point_out(i));
} }
} }
add_lines(v3p,PathEditorPlugin::singleton->path_thin_material); add_lines(v3p, PathEditorPlugin::singleton->path_thin_material);
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>()));
} }
return Ref<SpatialEditorGizmo>(); return Ref<SpatialEditorGizmo>();
} }
bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera, const Ref<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;
Ref<Curve3D> c=path->get_curve(); Ref<Curve3D> c = path->get_curve();
if (c.is_null()) if (c.is_null())
return false; return false;
Transform gt = path->get_global_transform(); Transform gt = path->get_global_transform();
@ -301,104 +283,97 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera, const Ref<Inp
Ref<InputEventMouseButton> mb = p_event; Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid()) { if (mb.is_valid()) {
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
PoolVector<Vector3> 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;
Vector3 closest_seg_point; Vector3 closest_seg_point;
float closest_d=1e20; float closest_d = 1e20;
if (rc>=2) { if (rc >= 2) {
PoolVector<Vector3>::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 to = r[j + 1];
Vector3 from =r[j];
Vector3 to =r[j+1];
real_t cdist = from.distance_to(to); real_t cdist = from.distance_to(to);
from=gt.xform(from); from = gt.xform(from);
to=gt.xform(to); to = gt.xform(to);
if (cdist>0) { if (cdist > 0) {
Vector2 s[2]; Vector2 s[2];
s[0] = p_camera->unproject_position(from); s[0] = p_camera->unproject_position(from);
s[1] = p_camera->unproject_position(to); s[1] = p_camera->unproject_position(to);
Vector2 inters = Geometry::get_closest_point_to_segment_2d(mbpos,s); Vector2 inters = Geometry::get_closest_point_to_segment_2d(mbpos, s);
float d = inters.distance_to(mbpos); float d = inters.distance_to(mbpos);
if (d<10 && d<closest_d) { if (d < 10 && d < closest_d) {
closest_d = d;
closest_seg = i;
Vector3 ray_from = p_camera->project_ray_origin(mbpos);
Vector3 ray_dir = p_camera->project_ray_normal(mbpos);
closest_d=d; Vector3 ra, rb;
closest_seg=i; Geometry::get_closest_points_between_segments(ray_from, ray_from + ray_dir * 4096, from, to, ra, rb);
Vector3 ray_from=p_camera->project_ray_origin(mbpos);
Vector3 ray_dir=p_camera->project_ray_normal(mbpos);
Vector3 ra,rb; closest_seg_point = it.xform(rb);
Geometry::get_closest_points_between_segments(ray_from,ray_from+ray_dir*4096,from,to,ra,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;
} }
} }
UndoRedo *ur = editor->get_undo_redo(); UndoRedo *ur = editor->get_undo_redo();
if (closest_seg!=-1) { if (closest_seg != -1) {
//subdivide //subdivide
ur->create_action(TTR("Split Path")); ur->create_action(TTR("Split Path"));
ur->add_do_method(c.ptr(),"add_point",closest_seg_point,Vector3(),Vector3(),closest_seg+1); ur->add_do_method(c.ptr(), "add_point", closest_seg_point, Vector3(), Vector3(), closest_seg + 1);
ur->add_undo_method(c.ptr(),"remove_point",closest_seg+1); ur->add_undo_method(c.ptr(), "remove_point", closest_seg + 1);
ur->commit_action(); ur->commit_action();
return true; return true;
} else { } else {
Vector3 org; Vector3 org;
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()-1)); 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);
Vector3 inters; Vector3 inters;
if (p.intersects_ray(ray_from,ray_dir,&inters)) { if (p.intersects_ray(ray_from, ray_dir, &inters)) {
ur->create_action(TTR("Add Point to Curve")); ur->create_action(TTR("Add Point to Curve"));
ur->add_do_method(c.ptr(),"add_point",it.xform(inters),Vector3(),Vector3(),-1); ur->add_do_method(c.ptr(), "add_point", it.xform(inters), Vector3(), Vector3(), -1);
ur->add_undo_method(c.ptr(),"remove_point",c->get_point_count()); ur->add_undo_method(c.ptr(), "remove_point", c->get_point_count());
ur->commit_action(); ur->commit_action();
return true; return true;
} }
@ -406,9 +381,9 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera, const Ref<Inp
//add new at pos //add new at pos
} }
} else if (mb->is_pressed() && ((mb->get_button_index()==BUTTON_LEFT && curve_del->is_pressed()) || (mb->get_button_index()==BUTTON_RIGHT && curve_edit->is_pressed()))) { } else if (mb->is_pressed() && ((mb->get_button_index() == BUTTON_LEFT && curve_del->is_pressed()) || (mb->get_button_index() == BUTTON_RIGHT && curve_edit->is_pressed()))) {
for(int i=0;i<c->get_point_count();i++) { for (int i = 0; i < c->get_point_count(); i++) {
real_t dist_to_p = p_camera->unproject_position(gt.xform(c->get_point_pos(i))).distance_to(mbpos); real_t dist_to_p = p_camera->unproject_position(gt.xform(c->get_point_pos(i))).distance_to(mbpos);
real_t dist_to_p_out = p_camera->unproject_position(gt.xform(c->get_point_pos(i) + c->get_point_out(i))).distance_to(mbpos); real_t dist_to_p_out = p_camera->unproject_position(gt.xform(c->get_point_pos(i) + c->get_point_out(i))).distance_to(mbpos);
real_t dist_to_p_in = p_camera->unproject_position(gt.xform(c->get_point_pos(i) + c->get_point_in(i))).distance_to(mbpos); real_t dist_to_p_in = p_camera->unproject_position(gt.xform(c->get_point_pos(i) + c->get_point_in(i))).distance_to(mbpos);
@ -419,40 +394,38 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera, const Ref<Inp
UndoRedo *ur = editor->get_undo_redo(); UndoRedo *ur = editor->get_undo_redo();
ur->create_action(TTR("Remove Path Point")); ur->create_action(TTR("Remove Path Point"));
ur->add_do_method(c.ptr(),"remove_point",i); ur->add_do_method(c.ptr(), "remove_point", i);
ur->add_undo_method(c.ptr(),"add_point",c->get_point_pos(i),c->get_point_in(i),c->get_point_out(i),i); ur->add_undo_method(c.ptr(), "add_point", c->get_point_pos(i), c->get_point_in(i), c->get_point_out(i), i);
ur->commit_action(); ur->commit_action();
return true; return true;
} else if (dist_to_p_out < click_dist) { } else if (dist_to_p_out < click_dist) {
UndoRedo *ur = editor->get_undo_redo(); UndoRedo *ur = editor->get_undo_redo();
ur->create_action(TTR("Remove Out-Control Point")); ur->create_action(TTR("Remove Out-Control Point"));
ur->add_do_method(c.ptr(),"set_point_out",i,Vector3()); ur->add_do_method(c.ptr(), "set_point_out", i, Vector3());
ur->add_undo_method(c.ptr(),"set_point_out",i,c->get_point_out(i)); ur->add_undo_method(c.ptr(), "set_point_out", i, c->get_point_out(i));
ur->commit_action(); ur->commit_action();
return true; return true;
} else if (dist_to_p_in < click_dist) { } else if (dist_to_p_in < click_dist) {
UndoRedo *ur = editor->get_undo_redo(); UndoRedo *ur = editor->get_undo_redo();
ur->create_action(TTR("Remove In-Control Point")); ur->create_action(TTR("Remove In-Control Point"));
ur->add_do_method(c.ptr(),"set_point_in",i,Vector3()); ur->add_do_method(c.ptr(), "set_point_in", i, Vector3());
ur->add_undo_method(c.ptr(),"set_point_in",i,c->get_point_in(i)); ur->add_undo_method(c.ptr(), "set_point_in", i, c->get_point_in(i));
ur->commit_action(); ur->commit_action();
return true; return true;
} }
} }
} }
} }
return false; return false;
} }
void PathEditorPlugin::edit(Object *p_object) { void PathEditorPlugin::edit(Object *p_object) {
if (p_object) { if (p_object) {
path=p_object->cast_to<Path>(); path = p_object->cast_to<Path>();
if (path) { if (path) {
if (path->get_curve().is_valid()) { if (path->get_curve().is_valid()) {
@ -460,8 +433,8 @@ void PathEditorPlugin::edit(Object *p_object) {
} }
} }
} else { } else {
Path *pre=path; Path *pre = path;
path=NULL; path = NULL;
if (pre) { if (pre) {
pre->get_curve()->emit_signal("changed"); pre->get_curve()->emit_signal("changed");
} }
@ -481,120 +454,115 @@ void PathEditorPlugin::make_visible(bool p_visible) {
curve_create->show(); curve_create->show();
curve_edit->show(); curve_edit->show();
curve_del->show(); curve_del->show();
curve_close->show(); curve_close->show();
sep->show(); sep->show();
} else { } else {
curve_create->hide(); curve_create->hide();
curve_edit->hide(); curve_edit->hide();
curve_del->hide(); curve_del->hide();
curve_close->hide(); curve_close->hide();
sep->hide(); sep->hide();
{ {
Path *pre=path; Path *pre = path;
path=NULL; path = NULL;
if (pre && pre->get_curve().is_valid()) { if (pre && pre->get_curve().is_valid()) {
pre->get_curve()->emit_signal("changed"); pre->get_curve()->emit_signal("changed");
} }
} }
} }
} }
void PathEditorPlugin::_mode_changed(int p_idx) { void PathEditorPlugin::_mode_changed(int p_idx) {
curve_create->set_pressed(p_idx==0); curve_create->set_pressed(p_idx == 0);
curve_edit->set_pressed(p_idx==1); curve_edit->set_pressed(p_idx == 1);
curve_del->set_pressed(p_idx==2); curve_del->set_pressed(p_idx == 2);
} }
void PathEditorPlugin::_close_curve() { void PathEditorPlugin::_close_curve() {
Ref<Curve3D> c = path->get_curve(); Ref<Curve3D> c = path->get_curve();
if (c.is_null()) if (c.is_null())
return ; return;
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) {
if (p_what==NOTIFICATION_ENTER_TREE) { if (p_what == NOTIFICATION_ENTER_TREE) {
curve_create->connect("pressed",this,"_mode_changed",make_binds(0)); curve_create->connect("pressed", this, "_mode_changed", make_binds(0));
curve_edit->connect("pressed",this,"_mode_changed",make_binds(1)); curve_edit->connect("pressed", this, "_mode_changed", make_binds(1));
curve_del->connect("pressed",this,"_mode_changed",make_binds(2)); curve_del->connect("pressed", this, "_mode_changed", make_binds(2));
curve_close->connect("pressed",this,"_close_curve"); curve_close->connect("pressed", this, "_close_curve");
} }
} }
void PathEditorPlugin::_bind_methods() { void PathEditorPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("_mode_changed"),&PathEditorPlugin::_mode_changed); ClassDB::bind_method(D_METHOD("_mode_changed"), &PathEditorPlugin::_mode_changed);
ClassDB::bind_method(D_METHOD("_close_curve"),&PathEditorPlugin::_close_curve); ClassDB::bind_method(D_METHOD("_close_curve"), &PathEditorPlugin::_close_curve);
} }
PathEditorPlugin* PathEditorPlugin::singleton=NULL; PathEditorPlugin *PathEditorPlugin::singleton = NULL;
PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) { PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) {
path=NULL; path = NULL;
editor=p_node; editor = p_node;
singleton=this; singleton = this;
path_material = Ref<SpatialMaterial>( memnew( SpatialMaterial )); path_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
path_material->set_albedo( 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_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); path_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
path_material->set_line_width(3); path_material->set_line_width(3);
path_material->set_cull_mode(SpatialMaterial::CULL_DISABLED); path_material->set_cull_mode(SpatialMaterial::CULL_DISABLED);
path_material->set_flag(SpatialMaterial::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_albedo( 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_feature(SpatialMaterial::FEATURE_TRANSPARENT, 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_cull_mode(SpatialMaterial::CULL_DISABLED); path_thin_material->set_cull_mode(SpatialMaterial::CULL_DISABLED);
path_thin_material->set_flag(SpatialMaterial::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);
sep = memnew( VSeparator); sep = memnew(VSeparator);
sep->hide(); sep->hide();
SpatialEditor::get_singleton()->add_control_to_menu_panel(sep); SpatialEditor::get_singleton()->add_control_to_menu_panel(sep);
curve_edit = memnew( ToolButton ); curve_edit = memnew(ToolButton);
curve_edit->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveEdit","EditorIcons")); curve_edit->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveEdit", "EditorIcons"));
curve_edit->set_toggle_mode(true); curve_edit->set_toggle_mode(true);
curve_edit->hide(); curve_edit->hide();
curve_edit->set_focus_mode(Control::FOCUS_NONE); curve_edit->set_focus_mode(Control::FOCUS_NONE);
curve_edit->set_tooltip(TTR("Select Points")+"\n"+TTR("Shift+Drag: Select Control Points")+"\n"+keycode_get_string(KEY_MASK_CMD)+TTR("Click: Add Point")+"\n"+TTR("Right Click: Delete Point")); curve_edit->set_tooltip(TTR("Select Points") + "\n" + TTR("Shift+Drag: Select Control Points") + "\n" + keycode_get_string(KEY_MASK_CMD) + TTR("Click: Add Point") + "\n" + TTR("Right Click: Delete Point"));
SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_edit); SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_edit);
curve_create = memnew( ToolButton ); curve_create = memnew(ToolButton);
curve_create->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveCreate","EditorIcons")); curve_create->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveCreate", "EditorIcons"));
curve_create->set_toggle_mode(true); curve_create->set_toggle_mode(true);
curve_create->hide(); curve_create->hide();
curve_create->set_focus_mode(Control::FOCUS_NONE); curve_create->set_focus_mode(Control::FOCUS_NONE);
curve_create->set_tooltip(TTR("Add Point (in empty space)")+"\n"+TTR("Split Segment (in curve)")); curve_create->set_tooltip(TTR("Add Point (in empty space)") + "\n" + TTR("Split Segment (in curve)"));
SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_create); SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_create);
curve_del = memnew( ToolButton ); curve_del = memnew(ToolButton);
curve_del->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveDelete","EditorIcons")); curve_del->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveDelete", "EditorIcons"));
curve_del->set_toggle_mode(true); curve_del->set_toggle_mode(true);
curve_del->hide(); curve_del->hide();
curve_del->set_focus_mode(Control::FOCUS_NONE); curve_del->set_focus_mode(Control::FOCUS_NONE);
curve_del->set_tooltip(TTR("Delete Point")); curve_del->set_tooltip(TTR("Delete Point"));
SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_del); SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_del);
curve_close = memnew( ToolButton ); curve_close = memnew(ToolButton);
curve_close->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveClose","EditorIcons")); curve_close->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveClose", "EditorIcons"));
curve_close->hide(); curve_close->hide();
curve_close->set_focus_mode(Control::FOCUS_NONE); curve_close->set_focus_mode(Control::FOCUS_NONE);
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) );
@ -608,12 +576,7 @@ PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) {
collision_polygon_editor->hide(); collision_polygon_editor->hide();
*/ */
} }
PathEditorPlugin::~PathEditorPlugin() {
PathEditorPlugin::~PathEditorPlugin()
{
} }

View File

@ -33,29 +33,26 @@
#include "editor/spatial_editor_gizmos.h" #include "editor/spatial_editor_gizmos.h"
#include "scene/3d/path.h" #include "scene/3d/path.h"
class PathSpatialGizmo : public EditorSpatialGizmo { class PathSpatialGizmo : public EditorSpatialGizmo {
GDCLASS(PathSpatialGizmo,EditorSpatialGizmo); GDCLASS(PathSpatialGizmo, EditorSpatialGizmo);
Path* path; Path *path;
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);
virtual void commit_handle(int p_idx,const Variant& p_restore,bool p_cancel=false); virtual void commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false);
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;
@ -65,26 +62,25 @@ 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 Ref<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);
virtual String get_name() const { return "Path"; } virtual String get_name() const { return "Path"; }
bool has_main_screen() const { return false; } bool has_main_screen() const { return false; }
virtual void edit(Object *p_node); virtual void edit(Object *p_node);
@ -93,7 +89,6 @@ public:
PathEditorPlugin(EditorNode *p_node); PathEditorPlugin(EditorNode *p_node);
~PathEditorPlugin(); ~PathEditorPlugin();
}; };
#endif // PATH_EDITOR_PLUGIN_H #endif // PATH_EDITOR_PLUGIN_H