Skip to content

Commit

Permalink
Version 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
IcterusGames authored Feb 6, 2023
1 parent 1f6d06b commit 3c4d268
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 70 deletions.
10 changes: 10 additions & 0 deletions addons/simplegrasstextured/about.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@tool
extends AcceptDialog


func _ready():
get_ok_button().custom_minimum_size.x = 100


func _on_rich_text_label_meta_clicked(meta):
OS.shell_open(str(meta))
52 changes: 52 additions & 0 deletions addons/simplegrasstextured/about.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[gd_scene load_steps=5 format=3 uid="uid://cb8klhv6nwvtl"]

[ext_resource type="Texture2D" uid="uid://bsmcpupaj02v8" path="res://addons/simplegrasstextured/icon.svg" id="1_at31v"]
[ext_resource type="Script" path="res://addons/simplegrasstextured/about.gd" id="1_r23hh"]

[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_hnw4u"]

[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_lwftf"]

[node name="Control" type="AcceptDialog"]
title = "About"
size = Vector2i(520, 215)
min_size = Vector2i(520, 200)
max_size = Vector2i(1280, 720)
script = ExtResource("1_r23hh")

[node name="MarginContainer" type="MarginContainer" parent="."]
offset_left = 8.0
offset_top = 8.0
offset_right = 512.0
offset_bottom = 166.0
theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 10
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 10

[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer"]
layout_mode = 2
theme_override_constants/separation = 20

[node name="TextureRect" type="TextureRect" parent="MarginContainer/HBoxContainer"]
custom_minimum_size = Vector2(48, 48)
layout_mode = 2
texture = ExtResource("1_at31v")
stretch_mode = 4

[node name="RichTextLabel" type="RichTextLabel" parent="MarginContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_styles/focus = SubResource("StyleBoxEmpty_hnw4u")
theme_override_styles/normal = SubResource("StyleBoxEmpty_lwftf")
bbcode_enabled = true
text = "Simple Grass Textured Plugin
v. 1.0.4
by IcterusGames
[font_size=7] [/font_size]
[url]https://icterusgames.itch.io/[/url]
[font_size=7] [/font_size]
[url]https://github.com/IcterusGames/SimpleGrassTextured[/url]
"

[connection signal="meta_clicked" from="MarginContainer/HBoxContainer/RichTextLabel" to="." method="_on_rich_text_label_meta_clicked"]
14 changes: 6 additions & 8 deletions addons/simplegrasstextured/grass.gd
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ func _update_multimesh():
var pos_max := pos_min * -1
var center := Vector3.ZERO
var radius := 0.0
var r_index := []
for trans in _buffer_add:
if pos_min > trans.origin:
pos_min = trans.origin
Expand All @@ -194,14 +193,13 @@ func _update_multimesh():
radius = center.distance_to(pos_min) + 1.0
for i in range(multimesh.instance_count):
var trans := multimesh.get_instance_transform(i)
if trans.origin.distance_to(center) <= radius:
r_index.append(i)
for i in r_index:
var trans := multimesh.get_instance_transform(i)
if trans.origin.distance_to(center) > radius:
continue
for trans_add in _buffer_add:
if trans_add.origin.distance_to(trans.origin) <= sgt_dist_min:
_buffer_add.erase(trans_add)
break
if trans_add.origin.distance_to(trans.origin) > sgt_dist_min:
continue
_buffer_add.erase(trans_add)
break
multi_new.instance_count = count_prev + _buffer_add.size()
for i in range(multimesh.instance_count):
multi_new.set_instance_transform(i, multimesh.get_instance_transform(i))
Expand Down
4 changes: 2 additions & 2 deletions addons/simplegrasstextured/images/win_pattern.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type="CompressedTexture2D"
uid="uid://i566v0wqsfa"
path.s3tc="res://.godot/imported/win_pattern.png-c44fa1ee331bdb684ff53320dba8c2b3.s3tc.ctex"
metadata={
"imported_formats": ["s3tc"],
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}

Expand All @@ -17,9 +17,9 @@ dest_files=["res://.godot/imported/win_pattern.png-c44fa1ee331bdb684ff53320dba8c
[params]

compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
Expand Down
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="1.0.3"
version="1.0.4"
script="plugin.gd"
130 changes: 84 additions & 46 deletions addons/simplegrasstextured/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ extends EditorPlugin

const DEPTH_BRUSH := 10.0

enum EVENT_MOUSE {
EVENT_NONE,
EVENT_MOVE,
EVENT_CLICK,
}

var _raycast_3d : RayCast3D = null
var _decal_pointer : Decal = null
var _grass_selected = null
var _timer_draw : Timer = null
var _position_draw := Vector3.ZERO
var _normal_draw := Vector3.ZERO
var _object_draw : Object = null
Expand All @@ -41,6 +46,11 @@ var _edit_rotation_rand := 1.0
var _edit_draw := true : set = _on_set_draw
var _edit_erase := false : set = _on_set_erase
var _gui_toolbar = null
var _time_draw := 0
var _draw_paused := true
var _mouse_event := EVENT_MOUSE.EVENT_NONE
var _project_ray_origin := Vector3.INF
var _project_ray_normal := Vector3.INF


func _enter_tree():
Expand All @@ -59,11 +69,8 @@ func _enter_tree():
_decal_pointer.set_texture(Decal.TEXTURE_ALBEDO, load("res://addons/simplegrasstextured/images/pointer.png"))
_decal_pointer.visible = false
_decal_pointer.extents = Vector3(_edit_radius, DEPTH_BRUSH, _edit_radius)
_timer_draw = Timer.new()
_timer_draw.timeout.connect(_on_timer_draw_timeout)
add_child(_raycast_3d)
add_child(_decal_pointer)
add_child(_timer_draw)
_gui_toolbar.slider_radius.value_changed.connect(_on_slider_radius_value_changed)
_gui_toolbar.slider_density.value_changed.connect(_on_slider_density_value_changed)
_gui_toolbar.button_draw.toggled.connect(_on_button_draw_toggled)
Expand Down Expand Up @@ -91,72 +98,59 @@ func _get_plugin_name() -> String:
func _handles(object) -> bool:
if object != null and object.has_meta("SimpleGrassTextured") and object.visible:
_grass_selected = object
_update_gui()
return true
_grass_selected = null
return false


func _edit(object : Variant):
_grass_selected = object
_update_gui()


func _make_visible(visible : bool):
if visible:
if _grass_selected != null:
_gui_toolbar.slider_radius.value = _grass_selected.sgt_radius
_gui_toolbar.slider_density.value = _grass_selected.sgt_density
_gui_toolbar.edit_scale.value = _grass_selected.sgt_scale
_gui_toolbar.edit_rotation.value = _grass_selected.sgt_rotation
_gui_toolbar.edit_rotation_rand.value = _grass_selected.sgt_rotation_rand
_gui_toolbar.edit_distance.value = _grass_selected.sgt_dist_min
_gui_toolbar.chk_normals.button_pressed = _grass_selected.sgt_follow_normal
if _grass_selected.multimesh != null:
_gui_toolbar.label_stats.text = "Count: " + str(_grass_selected.multimesh.instance_count)
_update_gui()
_gui_toolbar.visible = true
else:
_gui_toolbar.visible = false
_decal_pointer.visible = false
_grass_selected = null


func _forward_3d_gui_input(viewport_camera: Camera3D, event: InputEvent) -> int:
if _grass_selected == null:
return EditorPlugin.AFTER_GUI_INPUT_PASS
if _grass_selected.multimesh != null:
_gui_toolbar.label_stats.text = "Count: " + str(_grass_selected.multimesh.instance_count)
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT:
if not (_edit_draw or _edit_erase):
return EditorPlugin.AFTER_GUI_INPUT_PASS
if event.pressed:
_raycast_3d.global_transform.origin = viewport_camera.project_ray_origin(event.position)
_raycast_3d.global_transform.basis.y = viewport_camera.project_ray_normal(event.position)
_raycast_3d.target_position = Vector3(0, 100000, 0)
_raycast_3d.force_raycast_update()
if _raycast_3d.is_colliding():
_position_draw = _raycast_3d.get_collision_point()
_normal_draw = _raycast_3d.get_collision_normal()
_object_draw = _raycast_3d.get_collider()
_on_timer_draw_timeout()
_timer_draw.start(0.15)
else:
_object_draw = null
else:
_object_draw = null
_timer_draw.stop()
return EditorPlugin.AFTER_GUI_INPUT_STOP
if event is InputEventMouseMotion:
_raycast_3d.global_transform.origin = viewport_camera.project_ray_origin(event.position)
_raycast_3d.global_transform.basis.y = viewport_camera.project_ray_normal(event.position)
func _physics_process(_delta):
if _mouse_event == EVENT_MOUSE.EVENT_CLICK:
_raycast_3d.global_transform.origin = _project_ray_origin
_raycast_3d.global_transform.basis.y = _project_ray_normal
_raycast_3d.target_position = Vector3(0, 100000, 0)
_raycast_3d.force_raycast_update()
if _raycast_3d.is_colliding():
_position_draw = _raycast_3d.get_collision_point()
_normal_draw = _raycast_3d.get_collision_normal()
_object_draw = _raycast_3d.get_collider()
_eval_brush()
_time_draw = Time.get_ticks_msec()
_draw_paused = false
else:
_time_draw = 0
_draw_paused = true
_object_draw = null
_mouse_event = EVENT_MOUSE.EVENT_NONE
elif _mouse_event == EVENT_MOUSE.EVENT_MOVE:
_raycast_3d.global_transform.origin = _project_ray_origin
_raycast_3d.global_transform.basis.y = _project_ray_normal
_raycast_3d.target_position = Vector3(0, 100000, 0)
_raycast_3d.force_raycast_update()
if ( not _raycast_3d.is_colliding()
or ( _object_draw != null and _raycast_3d.get_collider() != _object_draw )):
_decal_pointer.visible = false
_timer_draw.paused = true
return EditorPlugin.AFTER_GUI_INPUT_PASS
_draw_paused = true
_mouse_event = EVENT_MOUSE.EVENT_NONE
return
else:
_timer_draw.paused = false
_draw_paused = false
_position_draw = _raycast_3d.get_collision_point()
_normal_draw = _raycast_3d.get_collision_normal()
var trans := Transform3D()
Expand All @@ -173,9 +167,53 @@ func _forward_3d_gui_input(viewport_camera: Camera3D, event: InputEvent) -> int:
_decal_pointer.global_transform = trans
_decal_pointer.extents = Vector3(_edit_radius, DEPTH_BRUSH, _edit_radius)
_decal_pointer.visible = _edit_draw or _edit_erase
_mouse_event = EVENT_MOUSE.EVENT_NONE
if _time_draw > 0:
if not _draw_paused:
if Time.get_ticks_msec() - _time_draw >= 150:
_time_draw = Time.get_ticks_msec()
_eval_brush()


func _forward_3d_gui_input(viewport_camera: Camera3D, event: InputEvent) -> int:
if _grass_selected == null:
return EditorPlugin.AFTER_GUI_INPUT_PASS
if _grass_selected.multimesh != null:
_gui_toolbar.label_stats.text = "Count: " + str(_grass_selected.multimesh.instance_count)
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT:
if not (_edit_draw or _edit_erase):
return EditorPlugin.AFTER_GUI_INPUT_PASS
if event.pressed:
_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:
_time_draw = 0
_object_draw = null
_mouse_event = EVENT_MOUSE.EVENT_NONE
return EditorPlugin.AFTER_GUI_INPUT_STOP
if event is InputEventMouseMotion:
if _mouse_event != EVENT_MOUSE.EVENT_CLICK:
_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_MOVE
return EditorPlugin.AFTER_GUI_INPUT_PASS


func _update_gui():
if _grass_selected != null:
_gui_toolbar.slider_radius.value = _grass_selected.sgt_radius
_gui_toolbar.slider_density.value = _grass_selected.sgt_density
_gui_toolbar.edit_scale.value = _grass_selected.sgt_scale
_gui_toolbar.edit_rotation.value = _grass_selected.sgt_rotation
_gui_toolbar.edit_rotation_rand.value = _grass_selected.sgt_rotation_rand
_gui_toolbar.edit_distance.value = _grass_selected.sgt_dist_min
_gui_toolbar.chk_normals.button_pressed = _grass_selected.sgt_follow_normal
if _grass_selected.multimesh != null:
_gui_toolbar.label_stats.text = "Count: " + str(_grass_selected.multimesh.instance_count)


func _on_button_draw_toggled(pressed : bool):
_edit_draw = pressed
if _edit_draw:
Expand Down Expand Up @@ -253,7 +291,7 @@ func _on_set_erase(value : bool):
_gui_toolbar.button_erase.button_pressed = _edit_erase


func _on_timer_draw_timeout():
func _eval_brush():
if _grass_selected == null:
return
if _edit_draw:
Expand Down
4 changes: 2 additions & 2 deletions addons/simplegrasstextured/textures/grassbushcc008.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type="CompressedTexture2D"
uid="uid://c4ggdp0kg5wjk"
path.s3tc="res://.godot/imported/grassbushcc008.png-7110abc2a2a9dc117662bb95ed60be39.s3tc.ctex"
metadata={
"imported_formats": ["s3tc"],
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}

Expand All @@ -17,9 +17,9 @@ dest_files=["res://.godot/imported/grassbushcc008.png-7110abc2a2a9dc117662bb95ed
[params]

compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
Expand Down
8 changes: 8 additions & 0 deletions addons/simplegrasstextured/toolbar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ extends HBoxContainer
@onready var _label_density := $HSliderDensity/Label as Label
@onready var _tween_radius : Tween = null
@onready var _tween_density : Tween = null
var _win_about = load("res://addons/simplegrasstextured/about.tscn").instantiate()


func _ready():
get_window().call_deferred(StringName("add_child"), _win_about)
_on_theme_changed()


Expand Down Expand Up @@ -74,3 +76,9 @@ func _on_theme_changed():
$IconRadius.modulate = get_theme_color("font_color", "Label")
$IconDensity.modulate = get_theme_color("font_color", "Label")
$IconDistance.modulate = get_theme_color("font_color", "Label")


func _on_panel_container_gui_input(event):
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
_win_about.popup_centered()
Loading

0 comments on commit 3c4d268

Please sign in to comment.