1
0
Fork 0
This repository has been archived on 2022-10-04. You can view files and clone it, but cannot push or open issues or pull requests.
godot-thunderk-basics/lod/lod_mesh_instance.gd

31 lines
664 B
GDScript

# MeshInstance with Level-of-Detail support
class_name LODMeshInstance
extends MeshInstance
# -- signals --
# -- enums --
# -- constants --
# -- exported variables --
export (Resource) var lod_config = LODConfig.new()
# -- public variables --
# -- private variables --
# -- onready variables --
# -- preloads --
# -- virtual methods --
func _ready():
mesh = lod_config.min_detail_mesh
add_to_group("thunderk-lod")
# -- public methods --
func update_lod(camera_location: Vector3):
var dist = global_transform.origin.distance_to(camera_location)
var lod_mesh = lod_config.get_lod_mesh(dist)
if mesh != lod_mesh:
mesh = lod_mesh
# -- private methods --