Skip to content

Commit

Permalink
Version 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
IcterusGames authored Jan 20, 2023
1 parent e2e453c commit 27b7f01
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 20 deletions.
33 changes: 26 additions & 7 deletions addons/simplegrasstextured/grass.gd
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@tool
@icon ("icon.png")
class_name SimpleGrassTextured extends MultiMeshInstance3D
extends MultiMeshInstance3D

@export var mesh : Mesh = null : set = _on_set_mesh
@export var player_pos := Vector3(1000000, 1000000, 1000000) : set = _on_set_player_pos
@export var player_radius := 0.5 : set = _on_set_player_radius
@export_color_no_alpha var albedo := Color.WHITE : set = _on_set_albedo
@export var texture_albedo : Texture = preload("textures/grassbushcc008.png") : set = _on_set_texture_albedo
@export var texture_albedo : Texture = load("res://addons/simplegrasstextured/textures/grassbushcc008.png") : set = _on_set_texture_albedo
@export var alpha_scissor_threshold := 0.5 : set = _on_set_alpha_scissor_threshold
@export var scale_h := 1.0 : set = _on_set_scale_h
@export var scale_w := 1.0 : set = _on_set_scale_w
Expand All @@ -45,7 +44,8 @@ var dist_min : float = 0.0

var _default_mesh : Mesh = null
var _buffer_add : Array[Transform3D] = []
var _material := preload("materials/grass.material").duplicate() as ShaderMaterial
var _material := load("res://addons/simplegrasstextured/materials/grass.material").duplicate() as ShaderMaterial
var _force_update_multimesh := false


func _init():
Expand All @@ -57,6 +57,15 @@ func _ready():
set_process(true)
else:
set_process(false)
if not has_meta("SimpleGrassTextured"):
# Update for previous version, now shader needs vertex color
set_meta("SimpleGrassTextured", "1.0.2")
_force_update_multimesh = true
if multimesh != null:
if mesh != null:
multimesh.mesh = mesh
else:
multimesh.mesh = _default_mesh
if multimesh == null:
multimesh = MultiMesh.new()
multimesh.transform_format = MultiMesh.TRANSFORM_3D
Expand All @@ -83,9 +92,9 @@ func _ready():


func _process(_delta : float):
if _buffer_add.size() == 0:
return
_update_multimesh()
if _buffer_add.size() != 0 or _force_update_multimesh:
_force_update_multimesh = false
_update_multimesh()


func add_grass(pos : Vector3, normal : Vector3, scale : Vector3):
Expand Down Expand Up @@ -155,6 +164,7 @@ func _build_default_mesh() -> Mesh:
var array_mesh := ArrayMesh.new()
var vertices := PackedVector3Array()
var normals := PackedVector3Array()
var colors := PackedColorArray()
var uvs := PackedVector2Array()
var index := PackedInt32Array()

Expand Down Expand Up @@ -182,6 +192,14 @@ func _build_default_mesh() -> Mesh:
uvs.push_back(Vector2(1, 1))
uvs.push_back(Vector2(0, 1))
uvs.push_back(Vector2(1, 0))
colors.push_back(Color(1, 0, 0))
colors.push_back(Color(0, 0, 0))
colors.push_back(Color(0, 0, 0))
colors.push_back(Color(1, 0, 0))
colors.push_back(Color(1, 0, 0))
colors.push_back(Color(0, 0, 0))
colors.push_back(Color(0, 0, 0))
colors.push_back(Color(1, 0, 0))
index.push_back(0)
index.push_back(1)
index.push_back(2)
Expand All @@ -200,6 +218,7 @@ func _build_default_mesh() -> Mesh:
arrays[Mesh.ARRAY_VERTEX] = vertices
arrays[ArrayMesh.ARRAY_NORMAL] = normals
arrays[ArrayMesh.ARRAY_TEX_UV] = uvs
arrays[ArrayMesh.ARRAY_COLOR] = colors
arrays[ArrayMesh.ARRAY_INDEX] = index

array_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)
Expand Down
57 changes: 57 additions & 0 deletions addons/simplegrasstextured/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions addons/simplegrasstextured/icon.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bsmcpupaj02v8"
path="res://.godot/imported/icon.svg-9bb625de16d6296dbe2603f14c8d4e58.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/simplegrasstextured/icon.svg"
dest_files=["res://.godot/imported/icon.svg-9bb625de16d6296dbe2603f14c8d4e58.ctex"]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
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.1"
version="1.0.2"
script="plugin.gd"
19 changes: 11 additions & 8 deletions addons/simplegrasstextured/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
@tool
extends EditorPlugin

const _TOOLBAR := preload("toolbar.gd")

var _raycast_3d : RayCast3D = null
var _decal_pointer : Decal = null
var _grass_selected : SimpleGrassTextured = null
var _grass_selected = null
var _timer_draw : Timer = null
var _position_draw := Vector3.ZERO
var _normal_draw := Vector3.ZERO
Expand All @@ -37,17 +35,23 @@ var _edit_radius := 2.0 : set = _on_set_radius
var _edit_scale := Vector3.ONE
var _edit_draw := true : set = _on_set_draw
var _edit_erase := false : set = _on_set_erase
var _gui_toolbar : _TOOLBAR = preload("toolbar.tscn").instantiate()
var _gui_toolbar = null


func _enter_tree():
add_custom_type("SimpleGrassTextured", "MultiMeshInstance3D", preload("grass.gd"), preload("icon.png"))
add_custom_type(
"SimpleGrassTextured",
"MultiMeshInstance3D",
load("res://addons/simplegrasstextured/grass.gd"),
load("res://addons/simplegrasstextured/icon.svg")
)
_gui_toolbar = load("res://addons/simplegrasstextured/toolbar.tscn").instantiate()
_gui_toolbar.visible = false
add_control_to_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_BOTTOM, _gui_toolbar)
_raycast_3d = RayCast3D.new()
_raycast_3d.visible = false
_decal_pointer = Decal.new()
_decal_pointer.set_texture(Decal.TEXTURE_ALBEDO, preload("images/pointer.png"))
_decal_pointer.set_texture(Decal.TEXTURE_ALBEDO, load("res://addons/simplegrasstextured/images/pointer.png"))
_decal_pointer.visible = false
_decal_pointer.scale = Vector3(_edit_radius, 20, _edit_radius)
_timer_draw = Timer.new()
Expand Down Expand Up @@ -77,7 +81,7 @@ func _get_plugin_name() -> String:


func _handles(object) -> bool:
if object is SimpleGrassTextured and object.visible:
if object != null and object.has_meta("SimpleGrassTextured") and object.visible:
_grass_selected = object
return true
_grass_selected = null
Expand Down Expand Up @@ -208,4 +212,3 @@ func _on_timer_draw_timeout():
_grass_selected.erase(_position_draw, _edit_radius)
if _grass_selected.multimesh != null:
_gui_toolbar.label_stats.text = "Count: " + str(_grass_selected.multimesh.instance_count)

2 changes: 1 addition & 1 deletion addons/simplegrasstextured/shaders/grass.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ uniform float optimization_level = 7.0;


void vertex() {
float lev = 1.0 - UV.y;
float lev = COLOR.r;
float varid = float(INSTANCE_ID);
VERTEX.x += sin((TIME + varid) * wind_speed) * lev * ((1.0 - grass_strength) / 10.0);
VERTEX.x += wind_dir.x * lev * (wind_strength + (sin(TIME + varid) * 0.2 * (1.0 - grass_strength) * min(1.0, wind_speed)));
Expand Down
6 changes: 3 additions & 3 deletions addons/simplegrasstextured/toolbar.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=3 uid="uid://dsim5cbhc6kwm"]

[ext_resource type="Script" path="res://addons/simplegrasstextured/toolbar.gd" id="1_aa1o6"]
[ext_resource type="Texture2D" uid="uid://bydmhs1jeab4x" path="res://addons/simplegrasstextured/icon.png" id="1_b52yy"]
[ext_resource type="Texture2D" uid="uid://bsmcpupaj02v8" path="res://addons/simplegrasstextured/icon.svg" id="2_2ni6b"]

[node name="Control" type="HBoxContainer"]
anchors_preset = 15
Expand All @@ -18,8 +18,8 @@ layout_mode = 2
[node name="TextureRect" type="TextureRect" parent="."]
custom_minimum_size = Vector2(24, 0)
layout_mode = 2
texture = ExtResource("1_b52yy")
stretch_mode = 5
texture = ExtResource("2_2ni6b")
stretch_mode = 3

[node name="ButtonDraw" type="Button" parent="."]
layout_mode = 2
Expand Down

0 comments on commit 27b7f01

Please sign in to comment.