extends SceneTree var failures := 0 func check(ok: bool, label: String) -> void: if not ok: failures += 1 if failures < 6: printerr("FAIL: " + label) func _init() -> void: call_deferred("run") func run() -> void: var world = ClassDB.instantiate("Metin2World") world.auto_load = false world.objects_enabled = false world.env_enabled = false world.assets_root = AssetRoot.path() world.map_path = "OutdoorA1/metin2_map_a1" root.add_child(world) check(world.load_map(), "real A1 loads") var pieces := 0 var vertices_checked := 0 var near_shore := 0 var boundary_vertices := 0 for mesh in world.find_children("*", "MeshInstance3D", true, false): if not String(mesh.name).begins_with("Water"): continue pieces += 1 var material: ShaderMaterial = mesh.mesh.surface_get_material(0) check(material.shader.code.contains("unshaded") and material.shader.code.contains("ALBEDO = tex;") and material.shader.code.contains("ALPHA = COLOR.a;"), "water selects texture RGB / vertex alpha") var arrays: Array = mesh.mesh.surface_get_arrays(0) var vertices: PackedVector3Array = arrays[Mesh.ARRAY_VERTEX] var colors: PackedColorArray = arrays[Mesh.ARRAY_COLOR] for i in vertices.size(): var v := vertices[i] # sample_height selects a neighbouring chunk on the outer border; # no such chunk exists there. The mesh still has its padded edge data. if v.x >= 1024.0 or v.z >= 1280.0: boundary_vertices += 1 continue var depth := (v.y - float(world.sample_height(v.x, v.z))) * 100.0 var expected := clampf(depth / 200.0, 0.0, 0.8) # A1 HeightScale=0.5 # ArrayMesh stores vertex colors as RGBA8, like legacy diffuse DWORD. check(absf(colors[i].a - expected) < 1.0 / 255.0 + 0.0001, "real shoreline depth formula pos=%s actual=%s expected=%s" % [v, colors[i].a, expected]) if colors[i].a < 0.12: near_shore += 1 vertices_checked += 1 for i in range(0, vertices.size(), 4): check(absf(vertices[i + 1].x - vertices[i].x - 2.0) < 0.001, "retain every water cell's depth samples") check(pieces > 0 and vertices_checked > 0 and near_shore > 0, "water and shallow shoreline exercised") world.free() await process_frame print("water_reference_test: failures=%d pieces=%d vertices=%d shallow=%d boundary_skipped=%d (geometry/material, not 40250 pixels)" % [failures, pieces, vertices_checked, near_shore, boundary_vertices]) quit(1 if failures else 0)