diff --git a/project/addons/terrain_3d/editor/components/ui.gd b/project/addons/terrain_3d/editor/components/ui.gd index 99aa5e239..27e8039a9 100644 --- a/project/addons/terrain_3d/editor/components/ui.gd +++ b/project/addons/terrain_3d/editor/components/ui.gd @@ -143,15 +143,15 @@ func _on_setting_changed() -> void: brush_data = { "size": int(toolbar_settings.get_setting("size")), "opacity": toolbar_settings.get_setting("opacity") / 100.0, + "height": toolbar_settings.get_setting("height"), "color": toolbar_settings.get_setting("color"), "roughness": toolbar_settings.get_setting("roughness"), - "gamma": toolbar_settings.get_setting("gamma"), - "height": toolbar_settings.get_setting("height"), - "jitter": toolbar_settings.get_setting("jitter"), + "texture_index": plugin.texture_dock.get_selected_index(), "automatic_regions": toolbar_settings.get_setting("automatic_regions"), "align_with_view": toolbar_settings.get_setting("align_with_view"), "show_cursor_while_painting": toolbar_settings.get_setting("show_cursor_while_painting"), - "index": plugin.texture_dock.get_selected_index(), + "gamma": toolbar_settings.get_setting("gamma"), + "jitter": toolbar_settings.get_setting("jitter"), } var brush_imgs: Array = toolbar_settings.get_setting("brush") brush_data["image"] = brush_imgs[0] diff --git a/src/terrain_3d_editor.cpp b/src/terrain_3d_editor.cpp index cb4dd72d6..66bb778bc 100644 --- a/src/terrain_3d_editor.cpp +++ b/src/terrain_3d_editor.cpp @@ -17,23 +17,25 @@ void Terrain3DEditor::Brush::set_data(Dictionary p_data) { for (int i = 0; i < ks.size(); i++) { LOG(DEBUG, ks[i], ": ", p_data[ks[i]]); } - _size = p_data["size"]; - _index = p_data["index"]; - _opacity = p_data["opacity"]; - _height = p_data["height"]; - _color = p_data["color"]; - _roughness = p_data["roughness"]; - _gamma = p_data["gamma"]; - _jitter = p_data["jitter"]; - _texture = p_data["texture"]; _image = p_data["image"]; if (_image.is_valid()) { _img_size = Vector2(_image->get_size()); } else { _img_size = Vector2(0, 0); } - _align_to_view = p_data["align_with_view"]; + _texture = p_data["texture"]; + + _size = p_data["size"]; + _opacity = p_data["opacity"]; + _height = p_data["height"]; + _color = p_data["color"]; + _roughness = p_data["roughness"]; + _texture_index = p_data["texture_index"]; + _auto_regions = p_data["automatic_regions"]; + _align_to_view = p_data["align_with_view"]; + _gamma = p_data["gamma"]; + _jitter = p_data["jitter"]; } /////////////////////////// @@ -104,7 +106,7 @@ void Terrain3DEditor::_operate_map(Vector3 p_global_position, real_t p_camera_di Ref map = storage->get_map_region(map_type, region_index); int brush_size = _brush.get_size(); - int index = _brush.get_index(); + int texture_id = _brush.get_texture_index(); Vector2 img_size = _brush.get_image_size(); real_t opacity = _brush.get_opacity(); real_t height = _brush.get_height(); diff --git a/src/terrain_3d_editor.h b/src/terrain_3d_editor.h index c83e4a048..401414bc0 100644 --- a/src/terrain_3d_editor.h +++ b/src/terrain_3d_editor.h @@ -57,36 +57,41 @@ class Terrain3DEditor : public Object { class Brush { private: - Ref _texture; Ref _image; Vector2 _img_size; + Ref _texture; + int _size = 0; - int _index = 0; real_t _opacity = 0.0; real_t _height = 0.0; Color _color = COLOR_ROUGHNESS; real_t _roughness = 0.5; - real_t _jitter = 0.0; - real_t _gamma = 1.0; - bool _align_to_view = false; + int _texture_index = 0; + bool _auto_regions = false; + bool _align_to_view = false; + real_t _gamma = 1.0; + real_t _jitter = 0.0; public: + void set_data(Dictionary p_data); + real_t get_alpha(Vector2i p_position) { return _image->get_pixelv(p_position).r; } + Ref get_texture() const { return _texture; } Ref get_image() const { return _image; } Vector2 get_image_size() const { return _img_size; } - void set_data(Dictionary p_data); - real_t get_alpha(Vector2i p_position) { return _image->get_pixelv(p_position).r; } + int get_size() const { return _size; } - int get_index() const { return _index; } real_t get_opacity() const { return _opacity; } real_t get_height() const { return _height; } Color get_color() const { return _color; } real_t get_roughness() const { return _roughness; } - real_t get_jitter() const { return _jitter; } - real_t get_gamma() const { return _gamma; } - bool is_aligned_to_view() const { return _align_to_view; } + int get_texture_index() const { return _texture_index; } + bool auto_regions_enabled() const { return _auto_regions; } + bool is_aligned_to_view() const { return _align_to_view; } + real_t get_gamma() const { return _gamma; } + real_t get_jitter() const { return _jitter; } }; // Object references diff --git a/src/util.cpp b/src/util.cpp index 239393840..a81101254 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -8,7 +8,7 @@ /////////////////////////// // Given a float and a 0-1 range array like { 0.0f, .125f, .25f, .334f, .5f, .667f, .8f, 1.0f } -// This function returns the closest index +// This function returns the closest index of a C array of floats int Util::closest_index(float value, const float *p_array, int size) { int index = size - 1; for (int k = 0; k < size; k++) {