New gizmo structure and new gizmo disabling menu

This commit is contained in:
JFonS 2018-07-25 00:08:49 +02:00
parent 9bd5315d30
commit 59fd18ab1a
12 changed files with 2206 additions and 2244 deletions

View File

@ -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")) {
@ -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"));

View File

@ -51,7 +51,6 @@ class Camera;
class EditorSelection;
class EditorExport;
class EditorSettings;
class SpatialEditorGizmo;
class EditorImportPlugin;
class EditorExportPlugin;
class EditorResourcePreview;
@ -171,7 +170,6 @@ public:
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);

View File

@ -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;
@ -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);
}
@ -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);
}
}
}
@ -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)
@ -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();
@ -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->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 = 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();
*/
}
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)));
return ref;
}
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");
}

View File

@ -49,10 +49,22 @@ public:
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);
@ -88,12 +100,10 @@ public:
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);

View File

@ -184,49 +184,6 @@ Transform SpatialEditorViewport::to_camera_transform(const Cursor &p_cursor) con
return camera_transform;
}
String SpatialEditorGizmo::get_handle_name(int p_idx) const {
if (get_script_instance() && get_script_instance()->has_method("get_handle_name"))
return get_script_instance()->call("get_handle_name", p_idx);
return "";
}
Variant SpatialEditorGizmo::get_handle_value(int p_idx) const {
if (get_script_instance() && get_script_instance()->has_method("get_handle_value"))
return get_script_instance()->call("get_handle_value", p_idx);
return Variant();
}
void SpatialEditorGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_point) {
if (get_script_instance() && get_script_instance()->has_method("set_handle"))
get_script_instance()->call("set_handle", p_idx, p_camera, p_point);
}
void SpatialEditorGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_cancel) {
if (get_script_instance() && get_script_instance()->has_method("commit_handle"))
get_script_instance()->call("commit_handle", p_idx, p_restore, p_cancel);
}
bool SpatialEditorGizmo::intersect_frustum(const Camera *p_camera, const Vector<Plane> &p_frustum) {
return false;
}
bool SpatialEditorGizmo::intersect_ray(Camera *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal, int *r_gizmo_handle, bool p_sec_first) {
return false;
}
SpatialEditorGizmo::SpatialEditorGizmo() {
selected = false;
}
int SpatialEditorViewport::get_selected_count() const {
Map<Node *, Object *> &selection = editor_selection->get_selection();
@ -346,7 +303,7 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append,
Vector3 pos = _get_ray_pos(p_pos);
Vector<ObjectID> instances = VisualServer::get_singleton()->instances_cull_ray(pos, ray, get_tree()->get_root()->get_world()->get_scenario());
Set<Ref<SpatialEditorGizmo> > found_gizmos;
Set<Ref<EditorSpatialGizmo> > found_gizmos;
Node *edited_scene = get_tree()->get_edited_scene_root();
ObjectID closest = 0;
@ -361,7 +318,7 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append,
if (!spat)
continue;
Ref<SpatialEditorGizmo> seg = spat->get_gizmo();
Ref<EditorSpatialGizmo> seg = spat->get_gizmo();
if ((!seg.is_valid()) || found_gizmos.has(seg)) {
continue;
@ -418,7 +375,7 @@ void SpatialEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_incl
Vector3 pos = _get_ray_pos(p_pos);
Vector<ObjectID> instances = VisualServer::get_singleton()->instances_cull_ray(pos, ray, get_tree()->get_root()->get_world()->get_scenario());
Set<Ref<SpatialEditorGizmo> > found_gizmos;
Set<Ref<EditorSpatialGizmo> > found_gizmos;
r_includes_current = false;
@ -429,7 +386,7 @@ void SpatialEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_incl
if (!spat)
continue;
Ref<SpatialEditorGizmo> seg = spat->get_gizmo();
Ref<EditorSpatialGizmo> seg = spat->get_gizmo();
if (!seg.is_valid())
continue;
@ -559,7 +516,7 @@ void SpatialEditorViewport::_select_region() {
if (selected.find(root_sp) != -1) continue;
Ref<SpatialEditorGizmo> seg = sp->get_gizmo();
Ref<EditorSpatialGizmo> seg = sp->get_gizmo();
if (!seg.is_valid())
continue;
@ -963,7 +920,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
if (b->is_pressed() && _edit.gizmo.is_valid()) {
//restore
_edit.gizmo->commit_handle(_edit.gizmo_handle, _edit.gizmo_initial_value, true);
_edit.gizmo = Ref<SpatialEditorGizmo>();
_edit.gizmo = Ref<EditorSpatialGizmo>();
}
if (_edit.mode == TRANSFORM_NONE && b->is_pressed()) {
@ -1079,7 +1036,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
if (can_select_gizmos && spatial_editor->get_selected()) {
Ref<SpatialEditorGizmo> seg = spatial_editor->get_selected()->get_gizmo();
Ref<EditorSpatialGizmo> seg = spatial_editor->get_selected()->get_gizmo();
if (seg.is_valid()) {
int handle = -1;
Vector3 point;
@ -1158,7 +1115,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
Spatial *spa = Object::cast_to<Spatial>(ObjectDB::get_instance(clicked));
if (spa) {
Ref<SpatialEditorGizmo> seg = spa->get_gizmo();
Ref<EditorSpatialGizmo> seg = spa->get_gizmo();
if (seg.is_valid()) {
_edit.gizmo = seg;
@ -1175,7 +1132,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
if (_edit.gizmo.is_valid()) {
_edit.gizmo->commit_handle(_edit.gizmo_handle, _edit.gizmo_initial_value, false);
_edit.gizmo = Ref<SpatialEditorGizmo>();
_edit.gizmo = Ref<EditorSpatialGizmo>();
break;
}
if (clicked) {
@ -1233,7 +1190,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
if (spatial_editor->get_selected()) {
Ref<SpatialEditorGizmo> seg = spatial_editor->get_selected()->get_gizmo();
Ref<EditorSpatialGizmo> seg = spatial_editor->get_selected()->get_gizmo();
if (seg.is_valid()) {
int selected_handle = -1;
@ -3099,7 +3056,7 @@ Vector3 SpatialEditorViewport::_get_instance_position(const Point2 &p_pos) const
Vector3 world_pos = _get_ray_pos(p_pos);
Vector<ObjectID> instances = VisualServer::get_singleton()->instances_cull_ray(world_pos, world_ray, get_tree()->get_root()->get_world()->get_scenario());
Set<Ref<SpatialEditorGizmo> > found_gizmos;
Set<Ref<EditorSpatialGizmo> > found_gizmos;
float closest_dist = MAX_DISTANCE;
@ -3113,7 +3070,7 @@ Vector3 SpatialEditorViewport::_get_instance_position(const Point2 &p_pos) const
if (!mesh_instance)
continue;
Ref<SpatialEditorGizmo> seg = mesh_instance->get_gizmo();
Ref<EditorSpatialGizmo> seg = mesh_instance->get_gizmo();
if ((!seg.is_valid()) || found_gizmos.has(seg)) {
continue;
@ -4048,6 +4005,16 @@ Dictionary SpatialEditor::get_state() const {
d["znear"] = get_znear();
d["zfar"] = get_zfar();
Dictionary gizmos_status;
for (int i = 0; i < gizmo_plugins.size(); i++) {
if (!gizmo_plugins[i]->can_be_hidden()) continue;
bool checked = gizmos_menu->get_popup()->is_item_checked(gizmos_menu->get_popup()->get_item_index(i));
String name = gizmo_plugins[i]->get_name();
gizmos_status[name] = checked;
}
d["gizmos_status"] = gizmos_status;
return d;
}
void SpatialEditor::set_state(const Dictionary &p_state) {
@ -4121,6 +4088,24 @@ void SpatialEditor::set_state(const Dictionary &p_state) {
VisualServer::get_singleton()->instance_set_visible(origin_instance, use);
}
}
if (d.has("gizmos_status")) {
Dictionary gizmos_status = d["gizmos_status"];
List<Variant> keys;
gizmos_status.get_key_list(&keys);
for (int j = 0; j < gizmo_plugins.size(); ++j) {
if (!gizmo_plugins[j]->can_be_hidden()) continue;
bool checked = true;
for (uint32_t i = 0; i < keys.size(); i++) {
if (gizmo_plugins.write[j]->get_name() == keys[i]) {
checked = gizmos_status[keys[i]];
}
}
gizmos_menu->get_popup()->set_item_checked(gizmos_menu->get_popup()->get_item_index(j), checked);
gizmo_plugins.write[j]->set_hidden(!checked);
}
}
}
void SpatialEditor::edit(Spatial *p_spatial) {
@ -4128,7 +4113,7 @@ void SpatialEditor::edit(Spatial *p_spatial) {
if (p_spatial != selected) {
if (selected) {
Ref<SpatialEditorGizmo> seg = selected->get_gizmo();
Ref<EditorSpatialGizmo> seg = selected->get_gizmo();
if (seg.is_valid()) {
seg->set_selected(false);
selected->update_gizmo();
@ -4140,7 +4125,7 @@ void SpatialEditor::edit(Spatial *p_spatial) {
if (selected) {
Ref<SpatialEditorGizmo> seg = selected->get_gizmo();
Ref<EditorSpatialGizmo> seg = selected->get_gizmo();
if (seg.is_valid()) {
seg->set_selected(true);
selected->update_gizmo();
@ -4214,6 +4199,15 @@ void SpatialEditor::_menu_item_toggled(bool pressed, int p_option) {
}
}
void SpatialEditor::_menu_gizmo_toggled(int p_option) {
bool is_checked = gizmos_menu->get_popup()->is_item_checked(gizmos_menu->get_popup()->get_item_index(p_option));
is_checked = !is_checked;
gizmo_plugins.write[p_option]->set_hidden(!is_checked);
gizmos_menu->get_popup()->set_item_checked(gizmos_menu->get_popup()->get_item_index(p_option), is_checked);
}
void SpatialEditor::_menu_item_pressed(int p_option) {
switch (p_option) {
@ -4725,6 +4719,27 @@ void SpatialEditor::_init_indicators() {
_generate_selection_box();
}
struct _GizmoPluginComparator {
bool operator()(const Ref<EditorSpatialGizmoPlugin> &p_a, const Ref<EditorSpatialGizmoPlugin> &p_b) const {
return p_a->get_name() < p_b->get_name();
}
};
void SpatialEditor::_init_gizmos_menu() {
_register_all_gizmos();
PopupMenu *p = gizmos_menu->get_popup();
gizmo_plugins.sort_custom<_GizmoPluginComparator>();
for (int i = 0; i < gizmo_plugins.size(); ++i) {
if (!gizmo_plugins[i]->can_be_hidden()) continue;
String plugin_name = gizmo_plugins[i]->get_name();
p->add_check_item(TTR(plugin_name), i);
}
}
void SpatialEditor::_init_grid() {
PoolVector<Color> grid_colors[3];
@ -5018,14 +5033,13 @@ void SpatialEditor::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
gizmos = memnew(SpatialEditorGizmos);
_init_gizmos_menu();
_init_indicators();
}
if (p_what == NOTIFICATION_EXIT_TREE) {
_finish_indicators();
memdelete(gizmos);
}
if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
tool_button[SpatialEditor::TOOL_MODE_SELECT]->set_icon(get_icon("ToolSelect", "EditorIcons"));
@ -5084,25 +5098,21 @@ void SpatialEditor::_request_gizmo(Object *p_obj) {
return;
if (editor->get_edited_scene() && (sp == editor->get_edited_scene() || (sp->get_owner() && editor->get_edited_scene()->is_a_parent_of(sp)))) {
Ref<SpatialEditorGizmo> seg;
Ref<EditorSpatialGizmo> seg;
for (int i = 0; i < EditorNode::get_singleton()->get_editor_data().get_editor_plugin_count(); i++) {
for (int i = 0; i < gizmo_plugins.size(); ++i) {
seg = gizmo_plugins.write[i]->get_gizmo(sp);
if (seg.is_valid()) {
sp->set_gizmo(seg);
if (sp == selected) {
seg->set_selected(true);
selected->update_gizmo();
}
seg = EditorNode::get_singleton()->get_editor_data().get_editor_plugin(i)->create_spatial_gizmo(sp);
if (seg.is_valid())
break;
}
if (!seg.is_valid()) {
seg = gizmos->get_gizmo(sp);
}
if (seg.is_valid()) {
sp->set_gizmo(seg);
}
if (seg.is_valid() && sp == selected) {
seg->set_selected(true);
selected->update_gizmo();
}
}
}
}
@ -5158,11 +5168,35 @@ void SpatialEditor::_node_removed(Node *p_node) {
selected = NULL;
}
void SpatialEditor::_register_all_gizmos() {
register_gizmo_plugin(Ref<CameraSpatialGizmoPlugin>(memnew(CameraSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<LightSpatialGizmoPlugin>(memnew(LightSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<AudioStreamPlayer3DSpatialGizmoPlugin>(memnew(AudioStreamPlayer3DSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<MeshInstanceSpatialGizmoPlugin>(memnew(MeshInstanceSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<SoftBodySpatialGizmoPlugin>(memnew(SoftBodySpatialGizmoPlugin)));
register_gizmo_plugin(Ref<Sprite3DSpatialGizmoPlugin>(memnew(Sprite3DSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<Position3DSpatialGizmoPlugin>(memnew(Position3DSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<SkeletonSpatialGizmoPlugin>(memnew(SkeletonSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<RayCastSpatialGizmoPlugin>(memnew(RayCastSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<VehicleWheelSpatialGizmoPlugin>(memnew(VehicleWheelSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<VisibilityNotifierGizmoPlugin>(memnew(VisibilityNotifierGizmoPlugin)));
register_gizmo_plugin(Ref<ParticlesGizmoPlugin>(memnew(ParticlesGizmoPlugin)));
register_gizmo_plugin(Ref<ReflectionProbeGizmoPlugin>(memnew(ReflectionProbeGizmoPlugin)));
register_gizmo_plugin(Ref<GIProbeGizmoPlugin>(memnew(GIProbeGizmoPlugin)));
register_gizmo_plugin(Ref<BakedIndirectLightGizmoPlugin>(memnew(BakedIndirectLightGizmoPlugin)));
register_gizmo_plugin(Ref<CollisionShapeSpatialGizmoPlugin>(memnew(CollisionShapeSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<CollisionPolygonSpatialGizmoPlugin>(memnew(CollisionPolygonSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<NavigationMeshSpatialGizmoPlugin>(memnew(NavigationMeshSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<JointSpatialGizmoPlugin>(memnew(JointSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<PhysicalBoneSpatialGizmoPlugin>(memnew(PhysicalBoneSpatialGizmoPlugin)));
}
void SpatialEditor::_bind_methods() {
ClassDB::bind_method("_unhandled_key_input", &SpatialEditor::_unhandled_key_input);
ClassDB::bind_method("_node_removed", &SpatialEditor::_node_removed);
ClassDB::bind_method("_menu_item_pressed", &SpatialEditor::_menu_item_pressed);
ClassDB::bind_method("_menu_gizmo_toggled", &SpatialEditor::_menu_gizmo_toggled);
ClassDB::bind_method("_menu_item_toggled", &SpatialEditor::_menu_item_toggled);
ClassDB::bind_method("_xform_dialog_action", &SpatialEditor::_xform_dialog_action);
ClassDB::bind_method("_get_editor_data", &SpatialEditor::_get_editor_data);
@ -5376,6 +5410,12 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
p->connect("id_pressed", this, "_menu_item_pressed");
gizmos_menu = memnew(MenuButton);
gizmos_menu->set_text(TTR("Gizmos"));
hbc_menu->add_child(gizmos_menu);
gizmos_menu->get_popup()->set_hide_on_checkable_item_selection(false);
gizmos_menu->get_popup()->connect("id_pressed", this, "_menu_gizmo_toggled");
/* REST OF MENU */
palette_split = memnew(HSplitContainer);
@ -5583,6 +5623,10 @@ void SpatialEditorPlugin::snap_cursor_to_plane(const Plane &p_plane) {
spatial_editor->snap_cursor_to_plane(p_plane);
}
void SpatialEditor::register_gizmo_plugin(Ref<EditorSpatialGizmoPlugin> ref) {
gizmo_plugins.push_back(ref);
}
SpatialEditorPlugin::SpatialEditorPlugin(EditorNode *p_node) {
editor = p_node;
@ -5596,3 +5640,171 @@ SpatialEditorPlugin::SpatialEditorPlugin(EditorNode *p_node) {
SpatialEditorPlugin::~SpatialEditorPlugin() {
}
void EditorSpatialGizmoPlugin::create_material(const String &p_name, const Color &p_color, bool p_billboard, bool p_on_top, bool p_use_vertex_color) {
Color instanced_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/instanced");
Vector<Ref<SpatialMaterial> > mats;
for (int i = 0; i < 4; i++) {
bool selected = i % 2 == 1;
bool instanced = i < 2;
Ref<SpatialMaterial> material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
Color color = instanced ? instanced_color : p_color;
if (!selected) {
color.a *= 0.3;
}
material->set_albedo(color);
material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
if (p_use_vertex_color) {
material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
material->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
}
if (p_billboard) {
material->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED);
}
if (p_on_top && selected) {
material->set_on_top_of_alpha();
}
mats.push_back(material);
}
materials[p_name] = mats;
}
void EditorSpatialGizmoPlugin::create_icon_material(const String &p_name, const Ref<Texture> &p_texture, bool p_on_top, const Color &p_albedo) {
Color instanced_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/instanced");
Vector<Ref<SpatialMaterial> > icons;
for (int i = 0; i < 4; i++) {
bool selected = i % 2 == 1;
bool instanced = i < 2;
Ref<SpatialMaterial> icon = Ref<SpatialMaterial>(memnew(SpatialMaterial));
Color color = instanced ? instanced_color : p_albedo;
if (!selected) {
color.a *= 0.3;
}
icon->set_albedo(color);
icon->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
icon->set_cull_mode(SpatialMaterial::CULL_DISABLED);
icon->set_depth_draw_mode(SpatialMaterial::DEPTH_DRAW_DISABLED);
icon->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
icon->set_texture(SpatialMaterial::TEXTURE_ALBEDO, p_texture);
icon->set_flag(SpatialMaterial::FLAG_FIXED_SIZE, true);
icon->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED);
if (p_on_top && selected) {
icon->set_on_top_of_alpha();
}
icons.push_back(icon);
}
materials[p_name] = icons;
}
void EditorSpatialGizmoPlugin::create_handle_material(const String &p_name, bool p_billboard) {
Ref<SpatialMaterial> handle_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
handle_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
handle_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
handle_material->set_flag(SpatialMaterial::FLAG_USE_POINT_SIZE, true);
Ref<Texture> handle_t = SpatialEditor::get_singleton()->get_icon("Editor3DHandle", "EditorIcons");
handle_material->set_point_size(handle_t->get_width());
handle_material->set_texture(SpatialMaterial::TEXTURE_ALBEDO, handle_t);
handle_material->set_albedo(Color(1, 1, 1));
handle_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
handle_material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
handle_material->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
handle_material->set_on_top_of_alpha();
if (p_billboard) {
handle_material->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED);
handle_material->set_on_top_of_alpha();
}
materials[p_name] = Vector<Ref<SpatialMaterial> >();
materials[p_name].push_back(handle_material);
}
void EditorSpatialGizmoPlugin::add_material(const String &p_name, Ref<SpatialMaterial> p_material) {
materials[p_name] = Vector<Ref<SpatialMaterial> >();
materials[p_name].push_back(p_material);
}
Ref<SpatialMaterial> EditorSpatialGizmoPlugin::get_material(const String &p_name, EditorSpatialGizmo *p_gizmo) {
ERR_FAIL_COND_V(!materials.has(p_name), Ref<SpatialMaterial>());
ERR_FAIL_COND_V(materials[p_name].size() == 0, Ref<SpatialMaterial>());
if (p_gizmo == NULL) return materials[p_name][0];
int index = (p_gizmo->is_selected() ? 1 : 0) + (p_gizmo->is_editable() ? 2 : 0);
return materials[p_name][index];
}
Ref<EditorSpatialGizmo> EditorSpatialGizmoPlugin::get_gizmo(Spatial *p_spatial) {
Ref<EditorSpatialGizmo> ref = create_gizmo(p_spatial);
if (ref.is_null()) return ref;
ref->set_plugin(this);
ref->set_spatial_node(p_spatial);
ref->set_hidden(hidden);
current_gizmos.push_back(ref.ptr());
return ref;
}
bool EditorSpatialGizmoPlugin::has_gizmo(Spatial *p_spatial) {
return false;
}
Ref<EditorSpatialGizmo> EditorSpatialGizmoPlugin::create_gizmo(Spatial *p_spatial) {
Ref<EditorSpatialGizmo> ref;
if (has_gizmo(p_spatial)) ref.instance();
return ref;
}
bool EditorSpatialGizmoPlugin::can_be_hidden() const {
return true;
}
bool EditorSpatialGizmoPlugin::is_selectable_when_hidden() const {
return false;
}
void EditorSpatialGizmoPlugin::set_hidden(bool p_hidden) {
hidden = p_hidden;
for (int i = 0; i < current_gizmos.size(); ++i) {
current_gizmos[i]->set_hidden(hidden);
}
}
void EditorSpatialGizmoPlugin::unregister_gizmo(EditorSpatialGizmo *p_gizmo) {
current_gizmos.erase(p_gizmo);
}
EditorSpatialGizmoPlugin::EditorSpatialGizmoPlugin() {
hidden = false;
}
EditorSpatialGizmoPlugin::~EditorSpatialGizmoPlugin() {
}

View File

@ -43,11 +43,11 @@
class Camera;
class SpatialEditor;
class SpatialEditorGizmos;
class EditorSpatialGizmoPlugin;
class SpatialEditorGizmo : public SpatialGizmo {
class EditorSpatialGizmo : public SpatialGizmo {
GDCLASS(SpatialEditorGizmo, SpatialGizmo);
GDCLASS(EditorSpatialGizmo, SpatialGizmo);
bool selected;
bool instanced;
@ -56,15 +56,86 @@ public:
void set_selected(bool p_selected) { selected = p_selected; }
bool is_selected() const { return selected; }
struct Instance {
RID instance;
Ref<ArrayMesh> mesh;
RID skeleton;
bool billboard;
bool unscaled;
bool can_intersect;
bool extra_margin;
Instance() {
billboard = false;
unscaled = false;
can_intersect = false;
extra_margin = false;
}
void create_instance(Spatial *p_base, bool p_hidden = false);
};
Vector<Vector3> collision_segments;
Ref<TriangleMesh> collision_mesh;
struct Handle {
Vector3 pos;
bool billboard;
};
Vector<Vector3> handles;
Vector<Vector3> secondary_handles;
float selectable_icon_size = -1.0f;
bool billboard_handle;
bool valid;
bool hidden;
Spatial *base;
Vector<Instance> instances;
Spatial *spatial_node;
EditorSpatialGizmoPlugin *gizmo_plugin;
void _set_spatial_node(Node *p_node) { set_spatial_node(Object::cast_to<Spatial>(p_node)); }
protected:
static void _bind_methods();
public:
void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false);
void add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard = false, const RID &p_skeleton = RID());
void add_collision_segments(const Vector<Vector3> &p_lines);
void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh);
void add_unscaled_billboard(const Ref<Material> &p_material, float p_scale = 1);
void add_handles(const Vector<Vector3> &p_handles, const Ref<Material> &p_material, bool p_billboard = false, bool p_secondary = false);
void add_solid_box(Ref<Material> &p_material, Vector3 p_size, Vector3 p_position = Vector3());
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);
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 bool is_gizmo_handle_highlighted(int idx) const { return false; }
virtual bool intersect_frustum(const Camera *p_camera, const Vector<Plane> &p_frustum);
virtual bool intersect_ray(Camera *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal, int *r_gizmo_handle = NULL, bool p_sec_first = false);
SpatialEditorGizmo();
void set_spatial_node(Spatial *p_node);
Spatial *get_spatial_node() const { return spatial_node; }
Vector3 get_handle_pos(int p_idx) const;
bool intersect_frustum(const Camera *p_camera, const Vector<Plane> &p_frustum);
bool intersect_ray(Camera *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal, int *r_gizmo_handle = NULL, bool p_sec_first = false);
virtual void clear();
virtual void create();
virtual void transform();
virtual void redraw();
virtual void free();
//TODO remove (?)
virtual bool is_editable() const;
virtual bool can_draw() const;
void set_hidden(bool p_hidden);
void set_plugin(EditorSpatialGizmoPlugin *p_gizmo);
EditorSpatialGizmo();
~EditorSpatialGizmo();
};
class SpatialEditorViewport : public Control {
@ -233,7 +304,7 @@ private:
int edited_gizmo;
Point2 mouse_pos;
bool snap;
Ref<SpatialEditorGizmo> gizmo;
Ref<EditorSpatialGizmo> gizmo;
int gizmo_handle;
Variant gizmo_initial_value;
Vector3 gizmo_initial_pos;
@ -500,6 +571,7 @@ private:
Button *tool_option_button[TOOL_OPT_MAX];
MenuButton *transform_menu;
MenuButton *gizmos_menu;
MenuButton *view_menu;
ToolButton *lock_button;
@ -531,6 +603,7 @@ private:
void _xform_dialog_action();
void _menu_item_pressed(int p_option);
void _menu_item_toggled(bool pressed, int p_option);
void _menu_gizmo_toggled(int p_option);
HBoxContainer *hbc_menu;
@ -539,6 +612,7 @@ private:
void _instance_scene();
void _init_indicators();
void _init_gizmos_menu();
void _init_grid();
void _finish_indicators();
void _finish_grid();
@ -558,7 +632,10 @@ private:
static SpatialEditor *singleton;
void _node_removed(Node *p_node);
SpatialEditorGizmos *gizmos;
Vector<Ref<EditorSpatialGizmoPlugin> > gizmo_plugins;
void _register_all_gizmos();
SpatialEditor();
bool is_any_freelook_active() const;
@ -632,6 +709,8 @@ public:
return viewports[p_idx];
}
void register_gizmo_plugin(Ref<EditorSpatialGizmoPlugin> ref);
Camera *get_camera() { return NULL; }
void edit(Spatial *p_spatial);
void clear();
@ -668,4 +747,43 @@ public:
~SpatialEditorPlugin();
};
class EditorSpatialGizmoPlugin : public Resource {
GDCLASS(EditorSpatialGizmoPlugin, Resource);
bool hidden;
List<EditorSpatialGizmo *> current_gizmos;
HashMap<String, Vector<Ref<SpatialMaterial> > > materials;
protected:
virtual bool has_gizmo(Spatial *p_spatial);
virtual Ref<EditorSpatialGizmo> create_gizmo(Spatial *p_spatial);
public:
void create_material(const String &p_name, const Color &p_color, bool p_billboard = false, bool p_on_top = false, bool p_use_vertex_color = false);
void create_icon_material(const String &p_name, const Ref<Texture> &p_texture, bool p_on_top = false, const Color &p_albedo = Color(1, 1, 1, 1));
void create_handle_material(const String &p_name, bool p_billboard = false);
void add_material(const String &p_name, Ref<SpatialMaterial> p_material);
Ref<SpatialMaterial> get_material(const String &p_name, EditorSpatialGizmo *p_gizmo = NULL);
virtual String get_name() const = 0;
virtual bool can_be_hidden() const;
virtual bool is_selectable_when_hidden() const;
virtual void redraw(EditorSpatialGizmo *p_gizmo) {}
virtual String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const { return ""; }
virtual Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const { return Variant(); }
virtual void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point) {}
virtual void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false) {}
virtual bool is_gizmo_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int idx) const { return false; }
Ref<EditorSpatialGizmo> get_gizmo(Spatial *p_spatial);
void set_hidden(bool p_hidden);
void unregister_gizmo(EditorSpatialGizmo *p_gizmo);
EditorSpatialGizmoPlugin();
virtual ~EditorSpatialGizmoPlugin();
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -55,187 +55,120 @@
class Camera;
class EditorSpatialGizmo : public SpatialEditorGizmo {
class LightSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(EditorSpatialGizmo, SpatialGizmo);
struct Instance {
RID instance;
Ref<ArrayMesh> mesh;
RID skeleton;
bool billboard;
bool unscaled;
bool can_intersect;
bool extra_margin;
Instance() {
billboard = false;
unscaled = false;
can_intersect = false;
extra_margin = false;
}
void create_instance(Spatial *p_base);
};
Vector<Vector3> collision_segments;
Ref<TriangleMesh> collision_mesh;
struct Handle {
Vector3 pos;
bool billboard;
};
Vector<Vector3> handles;
Vector<Vector3> secondary_handles;
float selectable_icon_size = -1.0f;
bool billboard_handle;
bool valid;
Spatial *base;
Vector<Instance> instances;
Spatial *spatial_node;
void _set_spatial_node(Node *p_node) { set_spatial_node(Object::cast_to<Spatial>(p_node)); }
protected:
void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false);
void add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard = false, const RID &p_skeleton = RID());
void add_collision_segments(const Vector<Vector3> &p_lines);
void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh);
void add_unscaled_billboard(const Ref<Material> &p_material, float p_scale = 1);
void add_handles(const Vector<Vector3> &p_handles, bool p_billboard = false, bool p_secondary = false);
void add_solid_box(Ref<Material> &p_material, Vector3 p_size, Vector3 p_position = Vector3());
void set_spatial_node(Spatial *p_node);
const Spatial *get_spatial_node() const { return spatial_node; }
static void _bind_methods();
Ref<SpatialMaterial> create_material(const String &p_name, const Color &p_color, bool p_billboard = false, bool p_on_top = false, bool p_use_vertex_color = false);
Ref<SpatialMaterial> create_icon_material(const String &p_name, const Ref<Texture> &p_texture, bool p_on_top = false, const Color &p_albedo = Color(1, 1, 1, 1));
GDCLASS(LightSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
virtual Vector3 get_handle_pos(int p_idx) const;
virtual bool intersect_frustum(const Camera *p_camera, const Vector<Plane> &p_frustum);
virtual bool intersect_ray(Camera *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal, int *r_gizmo_handle = NULL, bool p_sec_first = false);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
void clear();
void create();
void transform();
virtual void redraw();
void free();
virtual bool is_editable() const;
virtual bool can_draw() const;
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
void redraw(EditorSpatialGizmo *p_gizmo);
EditorSpatialGizmo();
~EditorSpatialGizmo();
LightSpatialGizmoPlugin();
};
class LightSpatialGizmo : public EditorSpatialGizmo {
class AudioStreamPlayer3DSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(LightSpatialGizmo, EditorSpatialGizmo);
Light *light;
GDCLASS(AudioStreamPlayer3DSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
virtual String get_handle_name(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 commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
void redraw();
LightSpatialGizmo(Light *p_light = NULL);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
void redraw(EditorSpatialGizmo *p_gizmo);
AudioStreamPlayer3DSpatialGizmoPlugin();
};
class AudioStreamPlayer3DSpatialGizmo : public EditorSpatialGizmo {
class CameraSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(AudioStreamPlayer3DSpatialGizmo, EditorSpatialGizmo);
AudioStreamPlayer3D *player;
GDCLASS(CameraSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
virtual String get_handle_name(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 commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
void redraw();
AudioStreamPlayer3DSpatialGizmo(AudioStreamPlayer3D *p_player = NULL);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
void redraw(EditorSpatialGizmo *p_gizmo);
CameraSpatialGizmoPlugin();
};
class CameraSpatialGizmo : public EditorSpatialGizmo {
class MeshInstanceSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(CameraSpatialGizmo, EditorSpatialGizmo);
Camera *camera;
GDCLASS(MeshInstanceSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
virtual String get_handle_name(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 commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
bool can_be_hidden() const;
void redraw(EditorSpatialGizmo *p_gizmo);
void redraw();
CameraSpatialGizmo(Camera *p_camera = NULL);
MeshInstanceSpatialGizmoPlugin();
};
class MeshInstanceSpatialGizmo : public EditorSpatialGizmo {
class Sprite3DSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(MeshInstanceSpatialGizmo, EditorSpatialGizmo);
MeshInstance *mesh;
GDCLASS(Sprite3DSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
virtual bool can_draw() const;
void redraw();
MeshInstanceSpatialGizmo(MeshInstance *p_mesh = NULL);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
bool can_be_hidden() const;
void redraw(EditorSpatialGizmo *p_gizmo);
Sprite3DSpatialGizmoPlugin();
};
class Sprite3DSpatialGizmo : public EditorSpatialGizmo {
class Position3DSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(Sprite3DSpatialGizmo, EditorSpatialGizmo);
GDCLASS(Position3DSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
SpriteBase3D *sprite;
Ref<ArrayMesh> pos3d_mesh;
Vector<Vector3> cursor_points;
public:
virtual bool can_draw() const;
void redraw();
Sprite3DSpatialGizmo(SpriteBase3D *p_sprite = NULL);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
void redraw(EditorSpatialGizmo *p_gizmo);
Position3DSpatialGizmoPlugin();
};
class Position3DSpatialGizmo : public EditorSpatialGizmo {
class SkeletonSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(Position3DSpatialGizmo, EditorSpatialGizmo);
Position3D *p3d;
GDCLASS(SkeletonSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
void redraw();
Position3DSpatialGizmo(Position3D *p_p3d = NULL);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
void redraw(EditorSpatialGizmo *p_gizmo);
SkeletonSpatialGizmoPlugin();
};
class SkeletonSpatialGizmo : public EditorSpatialGizmo {
class PhysicalBoneSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(SkeletonSpatialGizmo, EditorSpatialGizmo);
Skeleton *skel;
GDCLASS(PhysicalBoneSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
void redraw();
SkeletonSpatialGizmo(Skeleton *p_skel = NULL);
};
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
void redraw(EditorSpatialGizmo *p_gizmo);
class PhysicalBoneSpatialGizmo : public EditorSpatialGizmo {
GDCLASS(PhysicalBoneSpatialGizmo, EditorSpatialGizmo);
PhysicalBone *physical_bone;
public:
//virtual Transform get_global_gizmo_transform();
virtual void redraw();
PhysicalBoneSpatialGizmo(PhysicalBone *p_pb = NULL);
PhysicalBoneSpatialGizmoPlugin();
};
#if 0
@ -251,154 +184,166 @@ public:
};
#endif
class VisibilityNotifierGizmo : public EditorSpatialGizmo {
class RayCastSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(VisibilityNotifierGizmo, EditorSpatialGizmo);
VisibilityNotifier *notifier;
GDCLASS(RayCastSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
virtual String get_handle_name(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 commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
void redraw(EditorSpatialGizmo *p_gizmo);
void redraw();
VisibilityNotifierGizmo(VisibilityNotifier *p_notifier = NULL);
RayCastSpatialGizmoPlugin();
};
class ParticlesGizmo : public EditorSpatialGizmo {
class VehicleWheelSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(ParticlesGizmo, EditorSpatialGizmo);
Particles *particles;
GDCLASS(VehicleWheelSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
virtual String get_handle_name(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 commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
void redraw(EditorSpatialGizmo *p_gizmo);
void redraw();
ParticlesGizmo(Particles *p_particles = NULL);
VehicleWheelSpatialGizmoPlugin();
};
class ReflectionProbeGizmo : public EditorSpatialGizmo {
class SoftBodySpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(ReflectionProbeGizmo, EditorSpatialGizmo);
ReflectionProbe *probe;
GDCLASS(SoftBodySpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
virtual String get_handle_name(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 commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
bool is_selectable_when_hidden() const;
void redraw(EditorSpatialGizmo *p_gizmo);
void redraw();
ReflectionProbeGizmo(ReflectionProbe *p_probe = NULL);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel);
bool is_gizmo_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int idx) const;
SoftBodySpatialGizmoPlugin();
};
class GIProbeGizmo : public EditorSpatialGizmo {
class VisibilityNotifierGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(GIProbeGizmo, EditorSpatialGizmo);
GIProbe *probe;
GDCLASS(VisibilityNotifierGizmoPlugin, EditorSpatialGizmoPlugin);
public:
virtual String get_handle_name(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 commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
void redraw(EditorSpatialGizmo *p_gizmo);
void redraw();
GIProbeGizmo(GIProbe *p_probe = NULL);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
VisibilityNotifierGizmoPlugin();
};
class BakedIndirectLightGizmo : public EditorSpatialGizmo {
class ParticlesGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(BakedIndirectLightGizmo, EditorSpatialGizmo);
BakedLightmap *baker;
GDCLASS(ParticlesGizmoPlugin, EditorSpatialGizmoPlugin);
public:
virtual String get_handle_name(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 commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
bool is_selectable_when_hidden() const;
void redraw(EditorSpatialGizmo *p_gizmo);
void redraw();
BakedIndirectLightGizmo(BakedLightmap *p_baker = NULL);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
ParticlesGizmoPlugin();
};
class SoftBodySpatialGizmo : public EditorSpatialGizmo {
GDCLASS(SoftBodySpatialGizmo, EditorSpatialGizmo);
class ReflectionProbeGizmoPlugin : public EditorSpatialGizmoPlugin {
class SoftBody *soft_body;
//RID physics_sphere_shape; // Used for raycast that doesn't work, in this moment, with softbody
GDCLASS(ReflectionProbeGizmoPlugin, EditorSpatialGizmoPlugin);
public:
void redraw();
virtual bool intersect_ray(Camera *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal, int *r_gizmo_handle = NULL, bool p_sec_first = false);
virtual void commit_handle(int p_idx, const Variant &p_restore, bool p_cancel);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
void redraw(EditorSpatialGizmo *p_gizmo);
virtual bool is_gizmo_handle_highlighted(int idx) const;
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
SoftBodySpatialGizmo(SoftBody *p_soft_physics_body = NULL);
~SoftBodySpatialGizmo();
ReflectionProbeGizmoPlugin();
};
class CollisionShapeSpatialGizmo : public EditorSpatialGizmo {
class GIProbeGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(CollisionShapeSpatialGizmo, EditorSpatialGizmo);
CollisionShape *cs;
GDCLASS(GIProbeGizmoPlugin, EditorSpatialGizmoPlugin);
public:
virtual String get_handle_name(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 commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false);
void redraw();
CollisionShapeSpatialGizmo(CollisionShape *p_cs = NULL);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
void redraw(EditorSpatialGizmo *p_gizmo);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
GIProbeGizmoPlugin();
};
class CollisionPolygonSpatialGizmo : public EditorSpatialGizmo {
class BakedIndirectLightGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(CollisionPolygonSpatialGizmo, EditorSpatialGizmo);
CollisionPolygon *polygon;
GDCLASS(BakedIndirectLightGizmoPlugin, EditorSpatialGizmoPlugin);
public:
void redraw();
CollisionPolygonSpatialGizmo(CollisionPolygon *p_polygon = NULL);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
void redraw(EditorSpatialGizmo *p_gizmo);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
BakedIndirectLightGizmoPlugin();
};
class RayCastSpatialGizmo : public EditorSpatialGizmo {
class CollisionShapeSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(RayCastSpatialGizmo, EditorSpatialGizmo);
RayCast *raycast;
GDCLASS(CollisionShapeSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
void redraw();
RayCastSpatialGizmo(RayCast *p_raycast = NULL);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
void redraw(EditorSpatialGizmo *p_gizmo);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
CollisionShapeSpatialGizmoPlugin();
};
class VehicleWheelSpatialGizmo : public EditorSpatialGizmo {
class CollisionPolygonSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(VehicleWheelSpatialGizmo, EditorSpatialGizmo);
VehicleWheel *car_wheel;
GDCLASS(CollisionPolygonSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
void redraw();
VehicleWheelSpatialGizmo(VehicleWheel *p_car_wheel = NULL);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
void redraw(EditorSpatialGizmo *p_gizmo);
CollisionPolygonSpatialGizmoPlugin();
};
class NavigationMeshSpatialGizmo : public EditorSpatialGizmo {
class NavigationMeshSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(NavigationMeshSpatialGizmo, EditorSpatialGizmo);
GDCLASS(NavigationMeshSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
struct _EdgeKey {
@ -408,11 +353,12 @@ class NavigationMeshSpatialGizmo : public EditorSpatialGizmo {
bool operator<(const _EdgeKey &p_with) const { return from == p_with.from ? to < p_with.to : from < p_with.from; }
};
NavigationMeshInstance *navmesh;
public:
void redraw();
NavigationMeshSpatialGizmo(NavigationMeshInstance *p_navmesh = NULL);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
void redraw(EditorSpatialGizmo *p_gizmo);
NavigationMeshSpatialGizmoPlugin();
};
class JointGizmosDrawer {
@ -421,7 +367,7 @@ public:
static Basis look_body_toward(Vector3::Axis p_axis, const Transform &joint_transform, const Transform &body_transform);
static Basis look_body_toward_x(const Transform &p_joint_transform, const Transform &p_body_transform);
static Basis look_body_toward_y(const Transform &p_joint_transform, const Transform &p_body_transform);
/// Special function just used for physics joints, it that returns a basis constrained toward Joint Z axis
/// Special function just used for physics joints, it returns a basis constrained toward Joint Z axis
/// with axis X and Y that are looking toward the body and oriented toward up
static Basis look_body_toward_z(const Transform &p_joint_transform, const Transform &p_body_transform);
@ -430,66 +376,20 @@ public:
static void draw_cone(const Transform &p_offset, const Basis &p_base, real_t p_swing, real_t p_twist, Vector<Vector3> &r_points);
};
class PinJointSpatialGizmo : public EditorSpatialGizmo {
class JointSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(PinJointSpatialGizmo, EditorSpatialGizmo);
PinJoint *p3d;
GDCLASS(JointSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
static void CreateGizmo(const Transform &p_offset, Vector<Vector3> &r_cursor_points);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
void redraw(EditorSpatialGizmo *p_gizmo);
void redraw();
PinJointSpatialGizmo(PinJoint *p_p3d = NULL);
};
class HingeJointSpatialGizmo : public EditorSpatialGizmo {
GDCLASS(HingeJointSpatialGizmo, EditorSpatialGizmo);
HingeJoint *p3d;
public:
static void CreateGizmo(const Transform &p_offset, const Transform &p_trs_joint, const Transform &p_trs_body_a, const Transform &p_trs_body_b, real_t p_limit_lower, real_t p_limit_upper, bool p_use_limit, Vector<Vector3> &r_common_points, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points);
void redraw();
HingeJointSpatialGizmo(HingeJoint *p_p3d = NULL);
};
class SliderJointSpatialGizmo : public EditorSpatialGizmo {
GDCLASS(SliderJointSpatialGizmo, EditorSpatialGizmo);
SliderJoint *p3d;
public:
static void CreateGizmo(const Transform &p_offset, const Transform &p_trs_joint, const Transform &p_trs_body_a, const Transform &p_trs_body_b, real_t p_angular_limit_lower, real_t p_angular_limit_upper, real_t p_linear_limit_lower, real_t p_linear_limit_upper, Vector<Vector3> &r_points, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points);
void redraw();
SliderJointSpatialGizmo(SliderJoint *p_p3d = NULL);
};
class ConeTwistJointSpatialGizmo : public EditorSpatialGizmo {
GDCLASS(ConeTwistJointSpatialGizmo, EditorSpatialGizmo);
ConeTwistJoint *p3d;
public:
static void CreateGizmo(const Transform &p_offset, const Transform &p_trs_joint, const Transform &p_trs_body_a, const Transform &p_trs_body_b, real_t p_swing, real_t p_twist, Vector<Vector3> &r_points, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points);
void redraw();
ConeTwistJointSpatialGizmo(ConeTwistJoint *p_p3d = NULL);
};
class Generic6DOFJointSpatialGizmo : public EditorSpatialGizmo {
GDCLASS(Generic6DOFJointSpatialGizmo, EditorSpatialGizmo);
Generic6DOFJoint *p3d;
public:
static void CreateGizmo(
static void CreatePinJointGizmo(const Transform &p_offset, Vector<Vector3> &r_cursor_points);
static void CreateHingeJointGizmo(const Transform &p_offset, const Transform &p_trs_joint, const Transform &p_trs_body_a, const Transform &p_trs_body_b, real_t p_limit_lower, real_t p_limit_upper, bool p_use_limit, Vector<Vector3> &r_common_points, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points);
static void CreateSliderJointGizmo(const Transform &p_offset, const Transform &p_trs_joint, const Transform &p_trs_body_a, const Transform &p_trs_body_b, real_t p_angular_limit_lower, real_t p_angular_limit_upper, real_t p_linear_limit_lower, real_t p_linear_limit_upper, Vector<Vector3> &r_points, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points);
static void CreateConeTwistJointGizmo(const Transform &p_offset, const Transform &p_trs_joint, const Transform &p_trs_body_a, const Transform &p_trs_body_b, real_t p_swing, real_t p_twist, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points);
static void CreateGeneric6DOFJointGizmo(
const Transform &p_offset,
const Transform &p_trs_joint,
const Transform &p_trs_body_a,
@ -516,26 +416,7 @@ public:
Vector<Vector3> *r_body_a_points,
Vector<Vector3> *r_body_b_points);
void redraw();
Generic6DOFJointSpatialGizmo(Generic6DOFJoint *p_p3d = NULL);
JointSpatialGizmoPlugin();
};
class SpatialEditorGizmos {
public:
HashMap<String, Ref<SpatialMaterial> > material_cache;
Ref<SpatialMaterial> handle2_material;
Ref<SpatialMaterial> handle2_material_billboard;
Ref<SpatialMaterial> handle_material;
Ref<SpatialMaterial> handle_material_billboard;
Ref<Texture> handle_t;
Ref<ArrayMesh> pos3d_mesh;
Ref<ArrayMesh> listener_line_mesh;
static SpatialEditorGizmos *singleton;
Ref<SpatialEditorGizmo> get_gizmo(Spatial *p_spatial);
SpatialEditorGizmos();
};
#endif // SPATIAL_EDITOR_GIZMOS_H

View File

@ -32,7 +32,16 @@
///////////
String CSGShapeSpatialGizmo::get_handle_name(int p_idx) const {
CSGShapeSpatialGizmoPlugin::CSGShapeSpatialGizmoPlugin() {
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/csg", Color(0.2, 0.5, 1, 0.1));
create_material("shape_material", gizmo_color);
create_handle_material("handles");
}
String CSGShapeSpatialGizmoPlugin::get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const {
CSGShape *cs = Object::cast_to<CSGShape>(p_gizmo->get_spatial_node());
if (Object::cast_to<CSGSphere>(cs)) {
@ -57,7 +66,9 @@ String CSGShapeSpatialGizmo::get_handle_name(int p_idx) const {
return "";
}
Variant CSGShapeSpatialGizmo::get_handle_value(int p_idx) const {
Variant CSGShapeSpatialGizmoPlugin::get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const {
CSGShape *cs = Object::cast_to<CSGShape>(p_gizmo->get_spatial_node());
if (Object::cast_to<CSGSphere>(cs)) {
@ -89,10 +100,12 @@ Variant CSGShapeSpatialGizmo::get_handle_value(int p_idx) const {
return Variant();
}
void CSGShapeSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_point) {
void CSGShapeSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point) {
CSGShape *cs = Object::cast_to<CSGShape>(p_gizmo->get_spatial_node());
Transform gt = cs->get_global_transform();
gt.orthonormalize();
//gt.orthonormalize();
Transform gi = gt.affine_inverse();
Vector3 ray_from = p_camera->project_ray_origin(p_point);
@ -170,7 +183,9 @@ void CSGShapeSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const Point2
s->set_outer_radius(d);
}
}
void CSGShapeSpatialGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_cancel) {
void CSGShapeSpatialGizmoPlugin::commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) {
CSGShape *cs = Object::cast_to<CSGShape>(p_gizmo->get_spatial_node());
if (Object::cast_to<CSGSphere>(cs)) {
CSGSphere *s = Object::cast_to<CSGSphere>(cs);
@ -260,12 +275,26 @@ void CSGShapeSpatialGizmo::commit_handle(int p_idx, const Variant &p_restore, bo
ur->commit_action();
}
}
void CSGShapeSpatialGizmo::redraw() {
bool CSGShapeSpatialGizmoPlugin::has_gizmo(Spatial *p_spatial) {
return Object::cast_to<CSGSphere>(p_spatial) || Object::cast_to<CSGBox>(p_spatial) || Object::cast_to<CSGCylinder>(p_spatial) || Object::cast_to<CSGTorus>(p_spatial) || Object::cast_to<CSGMesh>(p_spatial) || Object::cast_to<CSGPolygon>(p_spatial);
}
clear();
String CSGShapeSpatialGizmoPlugin::get_name() const {
return "CSGShapes";
}
Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/csg");
Ref<Material> material = create_material("shape_material", gizmo_color);
bool CSGShapeSpatialGizmoPlugin::is_selectable_when_hidden() const {
return true;
}
void CSGShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
CSGShape *cs = Object::cast_to<CSGShape>(p_gizmo->get_spatial_node());
p_gizmo->clear();
Ref<Material> material = get_material("shape_material", p_gizmo);
Ref<Material> handles_material = get_material("handles");
PoolVector<Vector3> faces = cs->get_brush_faces();
@ -284,8 +313,8 @@ void CSGShapeSpatialGizmo::redraw() {
}
}
add_lines(lines, material);
add_collision_segments(lines);
p_gizmo->add_lines(lines, material);
p_gizmo->add_collision_segments(lines);
if (Object::cast_to<CSGSphere>(cs)) {
CSGSphere *s = Object::cast_to<CSGSphere>(cs);
@ -293,7 +322,7 @@ void CSGShapeSpatialGizmo::redraw() {
float r = s->get_radius();
Vector<Vector3> handles;
handles.push_back(Vector3(r, 0, 0));
add_handles(handles);
p_gizmo->add_handles(handles, handles_material);
}
if (Object::cast_to<CSGBox>(cs)) {
@ -303,7 +332,7 @@ void CSGShapeSpatialGizmo::redraw() {
handles.push_back(Vector3(s->get_width(), 0, 0));
handles.push_back(Vector3(0, s->get_height(), 0));
handles.push_back(Vector3(0, 0, s->get_depth()));
add_handles(handles);
p_gizmo->add_handles(handles, handles_material);
}
if (Object::cast_to<CSGCylinder>(cs)) {
@ -312,7 +341,7 @@ void CSGShapeSpatialGizmo::redraw() {
Vector<Vector3> handles;
handles.push_back(Vector3(s->get_radius(), 0, 0));
handles.push_back(Vector3(0, s->get_height() * 0.5, 0));
add_handles(handles);
p_gizmo->add_handles(handles, handles_material);
}
if (Object::cast_to<CSGTorus>(cs)) {
@ -321,25 +350,11 @@ void CSGShapeSpatialGizmo::redraw() {
Vector<Vector3> handles;
handles.push_back(Vector3(s->get_inner_radius(), 0, 0));
handles.push_back(Vector3(s->get_outer_radius(), 0, 0));
add_handles(handles);
p_gizmo->add_handles(handles, handles_material);
}
}
CSGShapeSpatialGizmo::CSGShapeSpatialGizmo(CSGShape *p_cs) {
cs = p_cs;
set_spatial_node(p_cs);
}
Ref<SpatialEditorGizmo> EditorPluginCSG::create_spatial_gizmo(Spatial *p_spatial) {
if (Object::cast_to<CSGSphere>(p_spatial) || Object::cast_to<CSGBox>(p_spatial) || Object::cast_to<CSGCylinder>(p_spatial) || Object::cast_to<CSGTorus>(p_spatial) || Object::cast_to<CSGMesh>(p_spatial) || Object::cast_to<CSGPolygon>(p_spatial)) {
Ref<CSGShapeSpatialGizmo> csg = memnew(CSGShapeSpatialGizmo(Object::cast_to<CSGShape>(p_spatial)));
return csg;
}
return Ref<SpatialEditorGizmo>();
}
EditorPluginCSG::EditorPluginCSG(EditorNode *p_editor) {
EDITOR_DEF("editors/3d_gizmos/gizmo_colors/csg", Color(0.2, 0.5, 1, 0.1));
Ref<CSGShapeSpatialGizmoPlugin> gizmo_plugin = Ref<CSGShapeSpatialGizmoPlugin>(memnew(CSGShapeSpatialGizmoPlugin));
SpatialEditor::get_singleton()->register_gizmo_plugin(gizmo_plugin);
}

View File

@ -35,25 +35,27 @@
#include "editor/editor_plugin.h"
#include "editor/spatial_editor_gizmos.h"
class CSGShapeSpatialGizmo : public EditorSpatialGizmo {
class CSGShapeSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(CSGShapeSpatialGizmo, EditorSpatialGizmo);
CSGShape *cs;
GDCLASS(CSGShapeSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
virtual String get_handle_name(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 commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false);
void redraw();
CSGShapeSpatialGizmo(CSGShape *p_cs = NULL);
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
bool is_selectable_when_hidden() const;
void redraw(EditorSpatialGizmo *p_gizmo);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel);
CSGShapeSpatialGizmoPlugin();
};
class EditorPluginCSG : public EditorPlugin {
GDCLASS(EditorPluginCSG, EditorPlugin)
public:
virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial *p_spatial);
EditorPluginCSG(EditorNode *p_editor);
};

View File

@ -202,6 +202,7 @@ void Spatial::_notification(int p_what) {
#ifdef TOOLS_ENABLED
if (data.gizmo.is_valid()) {
data.gizmo->free();
data.gizmo.unref();
}
#endif

View File

@ -51,6 +51,7 @@ public:
virtual bool can_draw() const = 0;
SpatialGizmo();
virtual ~SpatialGizmo() {}
};
class Spatial : public Node {