Files
Blockline/scripts/prepare_styloo_equipment.gd

45 lines
1.9 KiB
GDScript

extends SceneTree
func _initialize() -> void:
call_deferred("run")
func run() -> void:
DirAccess.make_dir_recursive_absolute("res://scenes/equipment")
for id: String in ["nade_low","flashbang_low","incendiary_low","smoke_low","ammobox_low"]:
var source := (load("res://assets/styloo/%s.glb" % id) as PackedScene).instantiate() as Node3D
root.add_child(source)
var bounds := AABB()
var first := true
for mesh: MeshInstance3D in source.find_children("*","MeshInstance3D",true,false):
var box := mesh.global_transform*mesh.mesh.get_aabb()
bounds = box if first else bounds.merge(box)
first = false
var scale_factor := (0.44 if id == "ammobox_low" else 0.24)/maxf(bounds.size.x,maxf(bounds.size.y,bounds.size.z))
var shift := -bounds.get_center()*scale_factor
# Pickup anchor is 25 cm above the fighter's feet; seat the box on that floor.
if id == "ammobox_low": shift.y = -bounds.position.y*scale_factor-0.25
var model := Node3D.new()
model.name = "StylooEquipment"
model.set_meta("asset_id",id)
for mesh: MeshInstance3D in source.find_children("*","MeshInstance3D",true,false):
var copy := MeshInstance3D.new()
copy.name = mesh.name
copy.mesh = mesh.mesh
copy.transform = Transform3D(Basis.IDENTITY.scaled(Vector3.ONE*scale_factor),shift)*mesh.global_transform
model.add_child(copy)
copy.owner = model
for surface in mesh.mesh.get_surface_count():
var material := mesh.get_active_material(surface).duplicate() as StandardMaterial3D
material.roughness = 1.0
material.metallic = 0.0
material.texture_filter = BaseMaterial3D.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC
var path := "res://assets/styloo/%s_%s_%s.tres" % [id,mesh.name,surface]
ResourceSaver.save(material,path)
copy.set_surface_override_material(surface,load(path))
var packed := PackedScene.new()
packed.pack(model)
ResourceSaver.save(packed,"res://scenes/equipment/styloo_%s.tscn" % id)
model.free()
source.free()
quit()