diff options
author | Nemrav <> | 2024-11-17 22:51:35 +0100 |
---|---|---|
committer | Nemrav <> | 2024-11-17 22:51:35 +0100 |
commit | 0d1f42829b154c172608450e3689c56cbfacb4fd (patch) | |
tree | f5aa2633ea252ba2e602c88fea5d9b77a1b83283 /game | |
parent | 54ddd94739d7efa3b7539d638edaf89b023ef903 (diff) |
billboards placement
Diffstat (limited to 'game')
-rw-r--r-- | game/src/Game/GameSession/BillboardManager.gd | 30 | ||||
-rw-r--r-- | game/src/Game/GameSession/GameSession.tscn | 3 | ||||
-rw-r--r-- | game/src/Game/GameSession/billboard.gdshader | 4 |
3 files changed, 27 insertions, 10 deletions
diff --git a/game/src/Game/GameSession/BillboardManager.gd b/game/src/Game/GameSession/BillboardManager.gd index 5a6fea6..ac1610b 100644 --- a/game/src/Game/GameSession/BillboardManager.gd +++ b/game/src/Game/GameSession/BillboardManager.gd @@ -4,8 +4,10 @@ extends MultiMeshInstance3D #var billboard_names = { #} -var billboard_names = [] +@export var _map_view : MapView +var billboard_names = [] +const SCALE_FACTOR = 1.0/64.0 # Called when the node enters the scene tree for the first time. func _ready(): const name_key : StringName = &"name" @@ -26,7 +28,7 @@ func _ready(): var noFrames = billboard[noOfFrames_key] textures.push_back(AssetManager.get_texture(texture)) frames.push_back(noFrames) - scales.push_back(b_scale) + scales.push_back(b_scale*SCALE_FACTOR) billboard_names.push_back(b_name) var material:ShaderMaterial = load("res://src/Game/GameSession/billboards.tres") @@ -50,18 +52,30 @@ func _ready(): #GameSingleton.get_mapmode_identifier(0) #GameSingleton.get_mapmode_count() - var positions: PackedVector2Array = MapItemSingleton.get_province_positions() + var positions_len = MapItemSingleton.get_province_count() + + print(positions_len) # Then resize (otherwise, changing the format is not allowed). - #multimesh.instance_count = positions.size() - #multimesh.visible_instance_count = positions.size() + multimesh.instance_count = positions_len + multimesh.visible_instance_count = positions_len print("===============") + var positions = MapItemSingleton.get_province_positions() + print("===============") + + var map_positions : PackedVector3Array = PackedVector3Array() + for pos_in in positions: + var pos = _map_view._map_to_world_coords(pos_in)# + Vector3(0, 0.5 * SCALE_FACTOR, 0) + map_positions.push_back(pos) #print(positions) #print(positions.size()) # Set the transform of the instances. - """for i in multimesh.visible_instance_count: + #model.set_position( + #_map_view._map_to_world_coords(unit_dict[position_key]) + # + Vector3(0, 0.1 * MODEL_SCALE, 0)) + for i in multimesh.visible_instance_count: multimesh.set_instance_transform(i, Transform3D(Basis(), - Vector3(positions[i].x, 0.5, positions[i].y) + map_positions[i] )) # custom data is a single vec4 float sent as a color # Info send to the shader is as follows: @@ -73,7 +87,7 @@ func _ready(): var im = r(textures.size()-1) multimesh.set_instance_custom_data(i,Color( im,r(frames[im]),1.0,0 - ))""" + )) func r(x:int=1)->int: return randi_range(0,x) diff --git a/game/src/Game/GameSession/GameSession.tscn b/game/src/Game/GameSession/GameSession.tscn index e8354a5..9356202 100644 --- a/game/src/Game/GameSession/GameSession.tscn +++ b/game/src/Game/GameSession/GameSession.tscn @@ -41,8 +41,9 @@ _game_session_menu = NodePath("UICanvasLayer/UI/GameSessionMenu") script = ExtResource("3_qwk4j") _map_view = NodePath("../MapView") -[node name="BillboardManager" type="MultiMeshInstance3D" parent="."] +[node name="BillboardManager" type="MultiMeshInstance3D" parent="." node_paths=PackedStringArray("_map_view")] script = ExtResource("4_b3l7b") +_map_view = NodePath("../MapView") [node name="UICanvasLayer" type="CanvasLayer" parent="."] diff --git a/game/src/Game/GameSession/billboard.gdshader b/game/src/Game/GameSession/billboard.gdshader index e207ff9..e854bcf 100644 --- a/game/src/Game/GameSession/billboard.gdshader +++ b/game/src/Game/GameSession/billboard.gdshader @@ -5,6 +5,8 @@ uniform sampler2D billboards[255]; uniform int numframes[255]; uniform float sizes[255]; +uniform float height_add_factor = 0.3; + //COLOR/INSTANCE_CUSTOM is our custom data, used as follows: // x=image index // y=frame in image index @@ -19,7 +21,7 @@ void vertex() { vec3 vert_pos_world = cam_right_worldspace * VERTEX.x * size + cam_up_worldspace * VERTEX.y * size; - VERTEX = vert_pos_world; + VERTEX = vert_pos_world + vec3(0,height_add_factor*size,0); } void fragment() { |