Skip to content

Commit

Permalink
Merge pull request #33 from IcterusGames/v-2.0.6-dev-2
Browse files Browse the repository at this point in the history
support for undo/redo
  • Loading branch information
IcterusGames authored Nov 11, 2024
2 parents 4753a8d + fc90f43 commit 546c4f2
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 37 deletions.
2 changes: 1 addition & 1 deletion addons/simplegrasstextured/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="SimpleGrassTextured"
description="Create simple grass textured"
author="IcterusGames"
version="2.0.6d1"
version="2.0.6d2"
script="plugin.gd"
13 changes: 13 additions & 0 deletions addons/simplegrasstextured/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,23 @@ func _forward_3d_gui_input(viewport_camera: Camera3D, event: InputEvent) -> int:
if not (_edit_draw or _edit_fill or _edit_erase):
return EditorPlugin.AFTER_GUI_INPUT_PASS
if event.pressed:
if _edit_draw:
get_undo_redo().create_action(_grass_selected.name + " Draw")
elif _edit_fill:
get_undo_redo().create_action(_grass_selected.name + " Fill")
elif _edit_erase:
get_undo_redo().create_action(_grass_selected.name + " Erase")
else:
get_undo_redo().create_action(_grass_selected.name)
get_undo_redo().add_undo_property(_grass_selected, &"baked_height_map", _grass_selected.baked_height_map)
get_undo_redo().add_undo_property(_grass_selected, &"multimesh", _grass_selected.multimesh)
_project_ray_origin = viewport_camera.project_ray_origin(event.position)
_project_ray_normal = viewport_camera.project_ray_normal(event.position)
_mouse_event = EVENT_MOUSE.EVENT_CLICK
else:
get_undo_redo().add_do_property(_grass_selected, &"baked_height_map", _grass_selected.baked_height_map)
get_undo_redo().add_do_property(_grass_selected, &"multimesh", _grass_selected.multimesh)
get_undo_redo().commit_action()
_time_draw = 0
_object_draw = null
_mouse_event = EVENT_MOUSE.EVENT_NONE
Expand Down
38 changes: 19 additions & 19 deletions addons/simplegrasstextured/shaders/grass.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ This file is part of: SimpleGrassTextured
Copyright (c) 2023 IcterusGames

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/

shader_type spatial;
Expand Down Expand Up @@ -92,11 +92,11 @@ void vertex() {
float rand = wrap(dot(NODE_POSITION_WORLD, NODE_POSITION_WORLD * 10.0), 0.0, 256.0);
float randf = fract(rand);
int randi = int(randf * 10.0);

uv_align = vec2(float(randi % int(texture_frames.x)), float(int(randf * 100.0) % int(texture_frames.y)));
uv_align /= texture_frames;
uv_scale = vec2(1.0 / texture_frames.x, 1.0 / texture_frames.y);

float text_wind = texture(sgt_wind_pattern, (vec2(NODE_POSITION_WORLD.x, NODE_POSITION_WORLD.z) * 0.005) - sgt_wind_movement.xz).r;
VERTEX.x += text_wind * lev * sgt_wind_strength * sgt_wind_direction.x * (1.0 - grass_strength);
VERTEX.z += text_wind * lev * sgt_wind_strength * sgt_wind_direction.z * (1.0 - grass_strength);
Expand All @@ -106,7 +106,7 @@ void vertex() {
VERTEX.y += sgt_wind_direction.y * lev * (sgt_wind_strength + (sin(TIME + rand) * 0.2 * (1.0 - grass_strength) * min(1.0, sgt_wind_turbulence))) * (1.0 - grass_strength);
VERTEX.z += cos(rand + sgt_wind_movement.y) * lev * ((1.0 - grass_strength) / 10.0);
VERTEX.z += sgt_wind_direction.z * lev * (sgt_wind_strength + (sin(TIME + rand) * 0.2 * (1.0 - grass_strength) * min(1.0, sgt_wind_turbulence))) * (1.0 - grass_strength);

vec3 align = VERTEX - NODE_POSITION_WORLD;
float scale_rand = ((float(randi % 5) / 5.0) * scale_var);
float dist = 1.0;
Expand All @@ -115,10 +115,10 @@ void vertex() {
dist = 1.0 - clamp(0.0, 1.0, float(randi % int(max(1.0, node_dist / optimization_level))));
dist *= smoothstep(optimization_dist_max, optimization_dist_min, node_dist);
}

vec3 scale = vec3(scale_w, scale_h, scale_w) * (1.0 + scale_rand);
VERTEX = NODE_POSITION_WORLD + (align * dist * scale);

if(dist > 0.0 && interactive_mode) {
float node_x = NODE_POSITION_WORLD.x / 50.0;
float node_z = NODE_POSITION_WORLD.z / 50.0;
Expand Down
28 changes: 14 additions & 14 deletions addons/simplegrasstextured/shaders/motion1.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ This file is part of: SimpleGrassTextured
Copyright (c) 2023 IcterusGames

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/

shader_type canvas_item;
Expand Down
1 change: 1 addition & 0 deletions addons/simplegrasstextured/singleton.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ shader_parameter/normal_texture = ExtResource("5_3dhao")

[sub_resource type="ShaderMaterial" id="ShaderMaterial_bi14c"]
shader = ExtResource("3_amjfl")
shader_parameter/delta = 1.0

[sub_resource type="ShaderMaterial" id="ShaderMaterial_5hmhs"]
shader = ExtResource("4_5b1gv")
Expand Down
35 changes: 32 additions & 3 deletions addons/simplegrasstextured/toolbar_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ enum MENU_ID {
RECALCULATE_AABB,
}

var _plugin: EditorPlugin = null
var _grass_selected = null
var _tools_menu :PopupMenu = null


func set_plugin(_plugin :EditorPlugin) -> void:
func set_plugin(plugin :EditorPlugin) -> void:
var popup := get_popup()
_plugin = plugin
_tools_menu = PopupMenu.new()
_tools_menu.name = &"ToolsMenu"
_tools_menu.add_check_item("Follow terrain's normal", MENU_ID.TOOL_FOLLOW_NORMAL)
Expand All @@ -50,7 +52,7 @@ func set_plugin(_plugin :EditorPlugin) -> void:
popup.add_separator()
popup.add_item("Auto center position", MENU_ID.AUTO_CENTER_POSITION)
popup.add_item("Recalculate custom AABB", MENU_ID.RECALCULATE_AABB)
popup.add_check_item("Bake height map", MENU_ID.BAKE_HEIGHT_MAP)
popup.add_item("Bake height map", MENU_ID.BAKE_HEIGHT_MAP)
popup.add_check_item("Cast shadow", MENU_ID.CAST_SHADOW)
popup.add_item("Global parameters", MENU_ID.GLOBAL_PARAMETERS)
popup.add_separator()
Expand All @@ -71,7 +73,12 @@ func set_current_grass(grass_selected) -> void:
popup.set_item_checked(popup.get_item_index(MENU_ID.CAST_SHADOW), false)
else:
popup.set_item_checked(popup.get_item_index(MENU_ID.CAST_SHADOW), true)
popup.set_item_checked(popup.get_item_index(MENU_ID.BAKE_HEIGHT_MAP), _grass_selected.baked_height_map != null)
if _grass_selected.baked_height_map != null:
popup.set_item_text(popup.get_item_index(MENU_ID.BAKE_HEIGHT_MAP), "Bake height map (already baked)")
popup.set_item_disabled(popup.get_item_index(MENU_ID.BAKE_HEIGHT_MAP), true)
else:
popup.set_item_text(popup.get_item_index(MENU_ID.BAKE_HEIGHT_MAP), "Bake height map")
popup.set_item_disabled(popup.get_item_index(MENU_ID.BAKE_HEIGHT_MAP), false)
_tools_menu.set_item_checked(_tools_menu.get_item_index(MENU_ID.TOOL_FOLLOW_NORMAL), _grass_selected.sgt_follow_normal)


Expand All @@ -80,14 +87,30 @@ func _on_sgt_menu_button(id :int) -> void:
return
match id:
MENU_ID.AUTO_CENTER_POSITION:
_plugin.get_undo_redo().create_action(_grass_selected.name + " Auto Center Position")
_plugin.get_undo_redo().add_undo_property(_grass_selected, &"baked_height_map", _grass_selected.baked_height_map)
_plugin.get_undo_redo().add_undo_property(_grass_selected, &"multimesh", _grass_selected.multimesh)
_plugin.get_undo_redo().add_undo_property(_grass_selected, &"global_position", _grass_selected.global_position)
_grass_selected.auto_center_position()
_plugin.get_undo_redo().add_do_property(_grass_selected, &"baked_height_map", _grass_selected.baked_height_map)
_plugin.get_undo_redo().add_do_property(_grass_selected, &"multimesh", _grass_selected.multimesh)
_plugin.get_undo_redo().add_do_property(_grass_selected, &"global_position", _grass_selected.global_position)
_plugin.get_undo_redo().commit_action()
MENU_ID.RECALCULATE_AABB:
_plugin.get_undo_redo().create_action(_grass_selected.name + " Recalculate Custom AABB")
_plugin.get_undo_redo().add_undo_property(_grass_selected, &"custom_aabb", _grass_selected.custom_aabb)
_grass_selected.recalculate_custom_aabb()
_plugin.get_undo_redo().add_do_property(_grass_selected, &"custom_aabb", _grass_selected.custom_aabb)
_plugin.get_undo_redo().commit_action()
MENU_ID.CAST_SHADOW:
_plugin.get_undo_redo().create_action(_grass_selected.name + " Toogle Cast Shadow")
_plugin.get_undo_redo().add_undo_property(_grass_selected, &"cast_shadow", _grass_selected.cast_shadow)
if _grass_selected.cast_shadow == GeometryInstance3D.SHADOW_CASTING_SETTING_OFF:
_grass_selected.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_ON
else:
_grass_selected.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
_plugin.get_undo_redo().add_do_property(_grass_selected, &"cast_shadow", _grass_selected.cast_shadow)
_plugin.get_undo_redo().commit_action()
MENU_ID.BAKE_HEIGHT_MAP:
_grass_selected.bake_height_map()
MENU_ID.GLOBAL_PARAMETERS:
Expand Down Expand Up @@ -121,4 +144,10 @@ func _on_about_to_popup() -> void:
func _on_clear_all_confirmation_dialog_confirmed() -> void:
if _grass_selected == null:
return
_plugin.get_undo_redo().create_action(_grass_selected.name + " Clear All Grass")
_plugin.get_undo_redo().add_undo_property(_grass_selected, &"baked_height_map", _grass_selected.baked_height_map)
_plugin.get_undo_redo().add_undo_property(_grass_selected, &"multimesh", _grass_selected.multimesh)
_grass_selected.clear_all()
_plugin.get_undo_redo().add_do_property(_grass_selected, &"baked_height_map", _grass_selected.baked_height_map)
_plugin.get_undo_redo().add_do_property(_grass_selected, &"multimesh", _grass_selected.multimesh)
_plugin.get_undo_redo().commit_action()

0 comments on commit 546c4f2

Please sign in to comment.