diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-02-19 22:02:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-19 22:02:02 +0100 |
commit | e7fb14351533f823cdc1261c3905ac8d5cb82f47 (patch) | |
tree | 907e6556bd23349e36d6aa1b633b237e7e1d59a4 /editor | |
parent | 1d2d08da5b04abcd1c956c32d5cec4733b281d40 (diff) | |
parent | 04d0a0b96deb1f1699915efd4aa723529172ae0b (diff) |
Merge pull request #14433 from PJB3005/17-12-08-3d_grid_color_setting_update
Makes 3D editor grid color update without restart.
Diffstat (limited to 'editor')
-rw-r--r-- | editor/plugins/spatial_editor_plugin.cpp | 123 | ||||
-rw-r--r-- | editor/plugins/spatial_editor_plugin.h | 2 |
2 files changed, 74 insertions, 51 deletions
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 63762651d7..6fd93c2f28 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -4282,67 +4282,26 @@ void SpatialEditor::_init_indicators() { indicator_mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); indicator_mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); - PoolVector<Color> grid_colors[3]; - PoolVector<Vector3> grid_points[3]; Vector<Color> origin_colors; Vector<Vector3> origin_points; - Color grid_color = EditorSettings::get_singleton()->get("editors/3d/grid_color"); - for (int i = 0; i < 3; i++) { Vector3 axis; axis[i] = 1; - Vector3 axis_n1; - axis_n1[(i + 1) % 3] = 1; - Vector3 axis_n2; - axis_n2[(i + 2) % 3] = 1; + + grid_enable[i] = false; + grid_visible[i] = false; origin_colors.push_back(Color(axis.x, axis.y, axis.z)); origin_colors.push_back(Color(axis.x, axis.y, axis.z)); origin_points.push_back(axis * 4096); origin_points.push_back(axis * -4096); -#define ORIGIN_GRID_SIZE 50 - - for (int j = -ORIGIN_GRID_SIZE; j <= ORIGIN_GRID_SIZE; j++) { - - Vector3 p1 = axis_n1 * j + axis_n2 * -ORIGIN_GRID_SIZE; - Vector3 p1_dest = p1 * (-axis_n2 + axis_n1); - Vector3 p2 = axis_n2 * j + axis_n1 * -ORIGIN_GRID_SIZE; - Vector3 p2_dest = p2 * (-axis_n1 + axis_n2); - - Color line_color = grid_color; - if (j == 0) { - continue; - } else if (j % 10 == 0) { - line_color *= 1.5; - } - - grid_points[i].push_back(p1); - grid_points[i].push_back(p1_dest); - grid_colors[i].push_back(line_color); - grid_colors[i].push_back(line_color); - - grid_points[i].push_back(p2); - grid_points[i].push_back(p2_dest); - grid_colors[i].push_back(line_color); - grid_colors[i].push_back(line_color); - } + } - grid[i] = VisualServer::get_singleton()->mesh_create(); - Array d; - d.resize(VS::ARRAY_MAX); - d[VisualServer::ARRAY_VERTEX] = grid_points[i]; - d[VisualServer::ARRAY_COLOR] = grid_colors[i]; - VisualServer::get_singleton()->mesh_add_surface_from_arrays(grid[i], VisualServer::PRIMITIVE_LINES, d); - VisualServer::get_singleton()->mesh_surface_set_material(grid[i], 0, indicator_mat->get_rid()); - grid_instance[i] = VisualServer::get_singleton()->instance_create2(grid[i], get_tree()->get_root()->get_world()->get_scenario()); + grid_enable[1] = true; + grid_visible[1] = true; - grid_visible[i] = false; - grid_enable[i] = false; - VisualServer::get_singleton()->instance_set_visible(grid_instance[i], false); - VisualServer::get_singleton()->instance_geometry_set_cast_shadows_setting(grid_instance[i], VS::SHADOW_CASTING_SETTING_OFF); - VS::get_singleton()->instance_set_layer_mask(grid_instance[i], 1 << SpatialEditorViewport::GIZMO_GRID_LAYER); - } + _init_grid(); origin = VisualServer::get_singleton()->mesh_create(); Array d; @@ -4358,9 +4317,6 @@ void SpatialEditor::_init_indicators() { VisualServer::get_singleton()->instance_geometry_set_cast_shadows_setting(origin_instance, VS::SHADOW_CASTING_SETTING_OFF); - VisualServer::get_singleton()->instance_set_visible(grid_instance[1], true); - grid_enable[1] = true; - grid_visible[1] = true; grid_enabled = true; last_grid_snap = 1; } @@ -4629,10 +4585,71 @@ void SpatialEditor::_init_indicators() { _generate_selection_box(); } +void SpatialEditor::_init_grid() { + + PoolVector<Color> grid_colors[3]; + PoolVector<Vector3> grid_points[3]; + + Color grid_color = EditorSettings::get_singleton()->get("editors/3d/grid_color"); + + for (int i = 0; i < 3; i++) { + Vector3 axis; + axis[i] = 1; + Vector3 axis_n1; + axis_n1[(i + 1) % 3] = 1; + Vector3 axis_n2; + axis_n2[(i + 2) % 3] = 1; + +#define ORIGIN_GRID_SIZE 50 + + for (int j = -ORIGIN_GRID_SIZE; j <= ORIGIN_GRID_SIZE; j++) { + Vector3 p1 = axis_n1 * j + axis_n2 * -ORIGIN_GRID_SIZE; + Vector3 p1_dest = p1 * (-axis_n2 + axis_n1); + Vector3 p2 = axis_n2 * j + axis_n1 * -ORIGIN_GRID_SIZE; + Vector3 p2_dest = p2 * (-axis_n1 + axis_n2); + + Color line_color = grid_color; + if (j == 0) { + continue; + } else if (j % 10 == 0) { + line_color *= 1.5; + } + + grid_points[i].push_back(p1); + grid_points[i].push_back(p1_dest); + grid_colors[i].push_back(line_color); + grid_colors[i].push_back(line_color); + + grid_points[i].push_back(p2); + grid_points[i].push_back(p2_dest); + grid_colors[i].push_back(line_color); + grid_colors[i].push_back(line_color); + } + + grid[i] = VisualServer::get_singleton()->mesh_create(); + Array d; + d.resize(VS::ARRAY_MAX); + d[VisualServer::ARRAY_VERTEX] = grid_points[i]; + d[VisualServer::ARRAY_COLOR] = grid_colors[i]; + VisualServer::get_singleton()->mesh_add_surface_from_arrays(grid[i], VisualServer::PRIMITIVE_LINES, d); + VisualServer::get_singleton()->mesh_surface_set_material(grid[i], 0, indicator_mat->get_rid()); + grid_instance[i] = VisualServer::get_singleton()->instance_create2(grid[i], get_tree()->get_root()->get_world()->get_scenario()); + + VisualServer::get_singleton()->instance_set_visible(grid_instance[i], grid_visible[i]); + VisualServer::get_singleton()->instance_geometry_set_cast_shadows_setting(grid_instance[i], VS::SHADOW_CASTING_SETTING_OFF); + VS::get_singleton()->instance_set_layer_mask(grid_instance[i], 1 << SpatialEditorViewport::GIZMO_GRID_LAYER); + } +} + void SpatialEditor::_finish_indicators() { VisualServer::get_singleton()->free(origin_instance); VisualServer::get_singleton()->free(origin); + + _finish_grid(); +} + +void SpatialEditor::_finish_grid() { for (int i = 0; i < 3; i++) { VisualServer::get_singleton()->free(grid_instance[i]); VisualServer::get_singleton()->free(grid[i]); @@ -4770,6 +4787,10 @@ void SpatialEditor::_notification(int p_what) { view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), get_icon("Panels3", "EditorIcons")); view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), get_icon("Panels3Alt", "EditorIcons")); view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), get_icon("Panels4", "EditorIcons")); + + // Update grid color by rebuilding grid. + _finish_grid(); + _init_grid(); } } diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index 55866cac99..d1fcdf8d54 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -531,7 +531,9 @@ private: void _instance_scene(); void _init_indicators(); + void _init_grid(); void _finish_indicators(); + void _finish_grid(); void _toggle_maximize_view(Object *p_viewport); |