diff options
| author | nokoe <nokoe@mailbox.org> | 2025-06-21 01:52:33 +0200 | 
|---|---|---|
| committer | nokoe <nokoe@mailbox.org> | 2025-06-21 01:52:33 +0200 | 
| commit | 16f72d038c37a2f5dd60a960f034ee2c3ff53f5b (patch) | |
| tree | 9af64de6fe8b2b47a5e46b87adabde94ccd8b88b /client/map/tiles/grass_mesher.gd | |
| parent | 44ca1fe3780b76c73e03070fc20189607c414860 (diff) | |
| download | hurrycurry-16f72d038c37a2f5dd60a960f034ee2c3ff53f5b.tar hurrycurry-16f72d038c37a2f5dd60a960f034ee2c3ff53f5b.tar.bz2 hurrycurry-16f72d038c37a2f5dd60a960f034ee2c3ff53f5b.tar.zst | |
generalize floor meshing; fixes #278
Diffstat (limited to 'client/map/tiles/grass_mesher.gd')
| -rw-r--r-- | client/map/tiles/grass_mesher.gd | 42 | 
1 files changed, 42 insertions, 0 deletions
| diff --git a/client/map/tiles/grass_mesher.gd b/client/map/tiles/grass_mesher.gd new file mode 100644 index 00000000..8535bfe7 --- /dev/null +++ b/client/map/tiles/grass_mesher.gd @@ -0,0 +1,42 @@ +# Hurry Curry! - a game about cooking +# Copyright 2025 nokoe +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License only. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program.  If not, see <https://www.gnu.org/licenses/>. +# +class_name GrassMesher +extends FloorMesher + +const GRASS_MESH: Mesh = preload("res://map/tiles/grass_side.tres") +var multimesh_instance := MultiMeshInstance3D.new() + +func _init(mesh: MeshInstance3D) -> void: +	super(mesh) +	mesh_instance.add_child(multimesh_instance) + +func flush() -> void: +	super() +	var random = RandomNumberGenerator.new() +	random.seed = "gr4ss".hash() + +	var multimesh := MultiMesh.new() +	multimesh.mesh = GRASS_MESH +	multimesh.transform_format = MultiMesh.TRANSFORM_3D +	multimesh.instance_count = tiles.size() * Global.get_setting("graphics.grass_amount") +	var t := tiles.values() +	for i in multimesh.instance_count: +		var p = t[i / Global.get_setting("graphics.grass_amount")] +		var origin := Vector3(random.randf_range(-.5, .5), 0.25, random.randf_range(-.5, .5)) + Vector3(p.x + 0.5, 0.0, p.y + 0.5) +		var basis_ := (Basis(Vector3(0, 1, 0), random.randf_range(0, PI)) * Basis(Vector3(1, 0, 0), PI/2)).scaled(Vector3(0.75, 0.5, 0.75)) +		multimesh.set_instance_transform(i, Transform3D(basis_, origin)) + +	multimesh_instance.multimesh = multimesh | 
