aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/GameSession/BillboardManager.gd
diff options
context:
space:
mode:
Diffstat (limited to 'game/src/Game/GameSession/BillboardManager.gd')
-rw-r--r--game/src/Game/GameSession/BillboardManager.gd82
1 files changed, 82 insertions, 0 deletions
diff --git a/game/src/Game/GameSession/BillboardManager.gd b/game/src/Game/GameSession/BillboardManager.gd
new file mode 100644
index 0000000..f6b96c0
--- /dev/null
+++ b/game/src/Game/GameSession/BillboardManager.gd
@@ -0,0 +1,82 @@
+extends MultiMeshInstance3D
+
+#given a name: get the index for the texture in the shader
+#var billboard_names = {
+
+#}
+var billboard_names = []
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ const name_key : StringName = &"name"
+ const texture_key : StringName = &"texture"
+ const scale_key : StringName = &"scale"
+ const noOfFrames_key : StringName = &"noFrames"
+
+
+ var textures : Array[Texture2D] = []
+ var frames : Array[int] = []
+ var scales : Array[float] = []
+
+ var billboards:Array[Dictionary] = MapItemSingleton.get_billboards()
+ for billboard in billboards:
+ var b_name = billboard[name_key]
+ var texture = billboard[texture_key]
+ var b_scale = billboard[scale_key]
+ var noFrames = billboard[noOfFrames_key]
+ textures.push_back(AssetManager.get_texture(texture))
+ frames.push_back(noFrames)
+ scales.push_back(b_scale)
+ billboard_names.push_back(b_name)
+
+ var material:ShaderMaterial = load("res://src/Game/GameSession/billboards.tres")
+ material.set_shader_parameter("billboards",textures)
+ material.set_shader_parameter("numframes",frames)
+ material.set_shader_parameter("sizes",scales)
+
+ # Create the multimesh.
+ multimesh = MultiMesh.new()
+
+ # Set the format first.
+ multimesh.transform_format = MultiMesh.TRANSFORM_3D
+ multimesh.mesh = QuadMesh.new()
+ multimesh.use_custom_data = true
+
+ multimesh.mesh.surface_set_material(0,material)
+
+
+ # Need to have one instance for every province
+ # need to get a list of province centers
+ #GameSingleton.get_mapmode_identifier(0)
+ #GameSingleton.get_mapmode_count()
+
+ var positions: PackedVector2Array = MapItemSingleton.get_province_positions()
+
+ # Then resize (otherwise, changing the format is not allowed).
+ #multimesh.instance_count = positions.size()
+ #multimesh.visible_instance_count = positions.size()
+ print("===============")
+ print(positions)
+ print(positions.size())
+ # Set the transform of the instances.
+ """for i in multimesh.visible_instance_count:
+ multimesh.set_instance_transform(i, Transform3D(Basis(),
+ Vector3(positions[i].x, 0.5, positions[i].y)
+ ))
+ # custom data is a single vec4 float sent as a color
+ # Info send to the shader is as follows:
+ # x: image from imageArray
+ # y: frame from selected image
+ # z: visibility
+ # w: unused, perhaps progress for progress bars?
+ #rf()+0.5
+ 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)
+
+func rf(lim:float=1.0)->float:
+ return randf_range(0,lim)