-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug_eye_uv.gd
More file actions
40 lines (36 loc) · 1.64 KB
/
Copy pathdebug_eye_uv.gd
File metadata and controls
40 lines (36 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
## Debug: dump the UV cells used by the eye mesh and the palette colors there.
extends SceneTree
func _init() -> void:
var scene: PackedScene = load("res://synty_assets/meshes/Species/Humans/SK_HUMN_BASE_01_05EYEL_HU01.fbx")
var instance := scene.instantiate()
var meshes: Array[MeshInstance3D] = []
_collect(instance, meshes)
var image := (load("res://synty_assets/textures/T_ColorMap.png") as Texture2D).get_image()
for mesh_instance in meshes:
var mesh := mesh_instance.mesh
for surface in mesh.get_surface_count():
var arrays := mesh.surface_get_arrays(surface)
var uvs: PackedVector2Array = arrays[Mesh.ARRAY_TEX_UV]
var min_uv := Vector2(INF, INF)
var max_uv := Vector2(-INF, -INF)
var cells := {}
for uv in uvs:
min_uv = min_uv.min(uv)
max_uv = max_uv.max(uv)
var cu := clampi(int(floor(uv.x * 16.0)), 0, 15)
var cv := clampi(int(floor(uv.y * 16.0)), 0, 15)
cells[Vector2i(cu, cv)] = cells.get(Vector2i(cu, cv), 0) + 1
print("%s surface %d: %d verts, uv min=%s max=%s" % [mesh_instance.name, surface, uvs.size(), min_uv, max_uv])
for cell: Vector2i in cells:
# Godot images are top-left origin; UV.y=0 is the TOP of the image in Godot.
var px := cell.x * 2
var py := cell.y * 2
var color := image.get_pixel(px, py)
print(" godot-uv cell (%d,%d) -> pixel(%d,%d) color=%s verts=%d" % [cell.x, cell.y, px, py, color.to_html(false), cells[cell]])
instance.free()
quit(0)
func _collect(node: Node, result: Array[MeshInstance3D]) -> void:
if node is MeshInstance3D and (node as MeshInstance3D).mesh != null:
result.append(node)
for child in node.get_children():
_collect(child, result)