extends MultiMeshInstance3D #given a name: get the index for the texture in the shader #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" 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*SCALE_FACTOR) 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) var positions = MapItemSingleton.get_province_positions() # Then resize (otherwise, changing the format is not allowed). multimesh.instance_count = positions.size() multimesh.visible_instance_count = positions.size() var map_positions : PackedVector3Array = PackedVector3Array() for pos_in in positions: var pos = _map_view._map_to_world_coords(pos_in) map_positions.push_back(pos) for i in multimesh.visible_instance_count: multimesh.set_instance_transform(i, Transform3D(Basis(), map_positions[i] )) # 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)