aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/GameSession/BillboardManager.gd
blob: 5a6fea6954b22ebfe50e43496a9b402bb28e187a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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)