Skip to content

Commit

Permalink
Merge pull request #20584 from JFonS/gizmo_enabling
Browse files Browse the repository at this point in the history
New gizmo structure and gizmo disabling menu
  • Loading branch information
reduz authored Aug 9, 2018
2 parents a71a5fc + 59fd18a commit fbb5ca4
Show file tree
Hide file tree
Showing 12 changed files with 2,347 additions and 2,385 deletions.
13 changes: 0 additions & 13 deletions editor/editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,6 @@ void EditorPlugin::notify_resource_saved(const Ref<Resource> &p_resource) {
emit_signal("resource_saved", p_resource);
}

Ref<SpatialEditorGizmo> EditorPlugin::create_spatial_gizmo(Spatial *p_spatial) {
//??
if (get_script_instance() && get_script_instance()->has_method("create_spatial_gizmo")) {
return get_script_instance()->call("create_spatial_gizmo", p_spatial);
}

return Ref<SpatialEditorGizmo>();
}

bool EditorPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p_event) {

if (get_script_instance() && get_script_instance()->has_method("forward_canvas_gui_input")) {
Expand Down Expand Up @@ -765,10 +756,6 @@ void EditorPlugin::_bind_methods() {
ClassDB::add_virtual_method(get_class_static(), MethodInfo("forward_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control")));
ClassDB::add_virtual_method(get_class_static(), MethodInfo("forward_force_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control")));
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_spatial_gui_input", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
MethodInfo gizmo = MethodInfo(Variant::OBJECT, "create_spatial_gizmo", PropertyInfo(Variant::OBJECT, "for_spatial", PROPERTY_HINT_RESOURCE_TYPE, "Spatial"));
gizmo.return_val.hint = PROPERTY_HINT_RESOURCE_TYPE;
gizmo.return_val.hint_string = "EditorSpatialGizmo";
ClassDB::add_virtual_method(get_class_static(), gizmo);
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_plugin_name"));
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::OBJECT, "get_plugin_icon"));
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "has_main_screen"));
Expand Down
2 changes: 0 additions & 2 deletions editor/editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class Camera;
class EditorSelection;
class EditorExport;
class EditorSettings;
class SpatialEditorGizmo;
class EditorImportPlugin;
class EditorExportPlugin;
class EditorResourcePreview;
Expand Down Expand Up @@ -171,7 +170,6 @@ class EditorPlugin : public Node {
void notify_scene_closed(const String &scene_filepath);
void notify_resource_saved(const Ref<Resource> &p_resource);

virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial *p_spatial);
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event);
virtual void forward_draw_over_viewport(Control *p_overlay);
virtual void forward_force_draw_over_viewport(Control *p_overlay);
Expand Down
93 changes: 55 additions & 38 deletions editor/plugins/path_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ void PathSpatialGizmo::redraw() {

clear();

Ref<SpatialMaterial> path_material = gizmo_plugin->get_material("path_material");
Ref<SpatialMaterial> path_thin_material = gizmo_plugin->get_material("path_thin_material");
Ref<SpatialMaterial> handles_material = gizmo_plugin->get_material("handles");

Ref<Curve3D> c = path->get_curve();
if (c.is_null())
return;
Expand All @@ -238,7 +242,7 @@ void PathSpatialGizmo::redraw() {
}

if (v3p.size() > 1) {
add_lines(v3p, PathEditorPlugin::singleton->path_material);
add_lines(v3p, path_material);
add_collision_segments(v3p);
}

Expand All @@ -265,13 +269,13 @@ void PathSpatialGizmo::redraw() {
}

if (v3p.size() > 1) {
add_lines(v3p, PathEditorPlugin::singleton->path_thin_material);
add_lines(v3p, path_thin_material);
}
if (handles.size()) {
add_handles(handles);
add_handles(handles, handles_material);
}
if (sec_handles.size()) {
add_handles(sec_handles, false, true);
add_handles(sec_handles, handles_material, false, true);
}
}
}
Expand All @@ -282,16 +286,6 @@ PathSpatialGizmo::PathSpatialGizmo(Path *p_path) {
set_spatial_node(p_path);
}

Ref<SpatialEditorGizmo> PathEditorPlugin::create_spatial_gizmo(Spatial *p_spatial) {

if (Object::cast_to<Path>(p_spatial)) {

return memnew(PathSpatialGizmo(Object::cast_to<Path>(p_spatial)));
}

return Ref<SpatialEditorGizmo>();
}

bool PathEditorPlugin::forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event) {

if (!path)
Expand Down Expand Up @@ -567,21 +561,9 @@ PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) {
mirror_handle_angle = true;
mirror_handle_length = true;

path_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
path_material->set_albedo(Color(0.5, 0.5, 1.0, 0.8));
path_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
path_material->set_line_width(3);
path_material->set_cull_mode(SpatialMaterial::CULL_DISABLED);
path_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);

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_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
path_thin_material->set_line_width(1);
path_thin_material->set_cull_mode(SpatialMaterial::CULL_DISABLED);
path_thin_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);

//SpatialEditor::get_singleton()->add_gizmo_plugin(this);
Ref<PathSpatialGizmoPlugin> gizmo_plugin;
gizmo_plugin.instance();
SpatialEditor::get_singleton()->register_gizmo_plugin(gizmo_plugin);

sep = memnew(VSeparator);
sep->hide();
Expand Down Expand Up @@ -630,18 +612,53 @@ PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) {

curve_edit->set_pressed(true);
/*
collision_polygon_editor = memnew( PathEditor(p_node) );
editor->get_viewport()->add_child(collision_polygon_editor);
collision_polygon_editor = memnew( PathEditor(p_node) );
editor->get_viewport()->add_child(collision_polygon_editor);
collision_polygon_editor->set_margin(MARGIN_LEFT,200);
collision_polygon_editor->set_margin(MARGIN_RIGHT,230);
collision_polygon_editor->set_margin(MARGIN_TOP,0);
collision_polygon_editor->set_margin(MARGIN_BOTTOM,10);
collision_polygon_editor->hide();
*/
}

collision_polygon_editor->set_margin(MARGIN_LEFT,200);
collision_polygon_editor->set_margin(MARGIN_RIGHT,230);
collision_polygon_editor->set_margin(MARGIN_TOP,0);
collision_polygon_editor->set_margin(MARGIN_BOTTOM,10);
PathEditorPlugin::~PathEditorPlugin() {
}

Ref<EditorSpatialGizmo> PathSpatialGizmoPlugin::create_gizmo(Spatial *p_spatial) {
Ref<PathSpatialGizmo> ref;

Path *path = Object::cast_to<Path>(p_spatial);
if (path) ref = Ref<PathSpatialGizmo>(memnew(PathSpatialGizmo(path)));

collision_polygon_editor->hide();
*/
return ref;
}

PathEditorPlugin::~PathEditorPlugin() {
String PathSpatialGizmoPlugin::get_name() const {
return "Path";
}

PathSpatialGizmoPlugin::PathSpatialGizmoPlugin() {

Color path_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/path", Color(0.5, 0.5, 1.0, 0.8));

Ref<SpatialMaterial> path_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
path_color.a = 0.8;
path_material->set_albedo(path_color);
path_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
path_material->set_line_width(3);
path_material->set_cull_mode(SpatialMaterial::CULL_DISABLED);
path_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);

Ref<SpatialMaterial> path_thin_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
path_color.a = 0.4;
path_thin_material->set_albedo(path_color);
path_thin_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
path_thin_material->set_line_width(1);
path_thin_material->set_cull_mode(SpatialMaterial::CULL_DISABLED);
path_thin_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);

add_material("path_material", path_material);
add_material("path_thin_material", path_thin_material);
create_handle_material("handles");
}
18 changes: 14 additions & 4 deletions editor/plugins/path_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,22 @@ class PathSpatialGizmo : public EditorSpatialGizmo {
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);

void redraw();
virtual void redraw();
PathSpatialGizmo(Path *p_path = NULL);
};

class PathSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {

GDCLASS(PathSpatialGizmoPlugin, EditorSpatialGizmoPlugin);

protected:
Ref<EditorSpatialGizmo> create_gizmo(Spatial *p_spatial);

public:
String get_name() const;
PathSpatialGizmoPlugin();
};

class PathEditorPlugin : public EditorPlugin {

GDCLASS(PathEditorPlugin, EditorPlugin);
Expand Down Expand Up @@ -88,12 +100,10 @@ class PathEditorPlugin : public EditorPlugin {
Path *get_edited_path() { return path; }

static PathEditorPlugin *singleton;
Ref<SpatialMaterial> path_material;
Ref<SpatialMaterial> path_thin_material;
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 Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial *p_spatial);
//virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial *p_spatial);
virtual String get_name() const { return "Path"; }
bool has_main_screen() const { return false; }
virtual void edit(Object *p_object);
Expand Down
Loading

0 comments on commit fbb5ca4

Please sign in to comment.