50 lines
2.4 KiB
GDScript
50 lines
2.4 KiB
GDScript
extends SceneTree
|
|||
|
|
|
||
|
|
const ROOT := "res://assets/scan/quarry_realism/"
|
||
|
|
|
||
|
|
func _initialize() -> void:
|
||
|
|
for id: String in ["concrete_road_barrier", "Barrel_02", "old_tyre", "portable_generator", "wooden_crate_02", "covered_car"]:
|
||
|
|
var scene := (load(ROOT + id + "/" + id + ".gltf") as PackedScene).instantiate()
|
||
|
|
var count := 0
|
||
|
|
for child in scene.find_children("*", "MeshInstance3D", true, false):
|
||
|
|
for surface in child.mesh.get_surface_count():
|
||
|
|
var source: StandardMaterial3D = child.get_active_material(surface)
|
||
|
|
var material := source.duplicate() as StandardMaterial3D
|
||
|
|
material.texture_filter = BaseMaterial3D.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC
|
||
|
|
material.normal_enabled = material.normal_texture != null
|
||
|
|
material.normal_scale = 1.0
|
||
|
|
material.roughness_texture_channel = BaseMaterial3D.TEXTURE_CHANNEL_GREEN
|
||
|
|
material.metallic_texture_channel = BaseMaterial3D.TEXTURE_CHANNEL_BLUE
|
||
|
|
material.ao_texture_channel = BaseMaterial3D.TEXTURE_CHANNEL_RED
|
||
|
|
if material.roughness_texture != null and "_arm_" in material.roughness_texture.resource_path:
|
||
|
|
material.ao_enabled = true
|
||
|
|
material.ao_texture = material.roughness_texture
|
||
|
|
var path := ROOT + id + "/material_%d.tres" % count
|
||
|
|
ResourceSaver.save(material, path)
|
||
|
|
child.set_surface_override_material(surface, load(path))
|
||
|
|
count += 1
|
||
|
|
var packed := PackedScene.new()
|
||
|
|
packed.pack(scene)
|
||
|
|
ResourceSaver.save(packed, ROOT + id + "/model.scn")
|
||
|
|
scene.free()
|
||
|
|
print("PREPARED ", id, " surfaces=", count)
|
||
|
|
for id: String in ["aerial_asphalt_01", "concrete_wall_007", "rusty_metal_02"]:
|
||
|
|
var path := "res://assets/textures/quarry_realism/" + id + "/"
|
||
|
|
var mat := StandardMaterial3D.new()
|
||
|
|
mat.albedo_texture = load(path + "Diffuse.jpg")
|
||
|
|
mat.normal_enabled = true
|
||
|
|
mat.normal_texture = load(path + "nor_gl.jpg")
|
||
|
|
mat.roughness_texture = load(path + "Rough.jpg")
|
||
|
|
mat.roughness_texture_channel = BaseMaterial3D.TEXTURE_CHANNEL_RED
|
||
|
|
mat.roughness = 1.0
|
||
|
|
if ResourceLoader.exists(path + "Metal.jpg"):
|
||
|
|
mat.metallic_texture = load(path + "Metal.jpg")
|
||
|
|
mat.metallic_texture_channel = BaseMaterial3D.TEXTURE_CHANNEL_RED
|
||
|
|
mat.metallic = 1.0
|
||
|
|
mat.uv1_triplanar = true
|
||
|
|
mat.uv1_world_triplanar = true
|
||
|
|
mat.uv1_scale = Vector3.ONE / (3.0 if id == "concrete_wall_007" else 2.0)
|
||
|
|
mat.texture_filter = BaseMaterial3D.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC
|
||
|
|
ResourceSaver.save(mat, path + "surface.tres")
|
||
|
|
quit()
|