| … | … | @@ -0,0 +1,57 @@ |
| 1 | ## Feed a REAL cage (from Blender, M-converted) into a bridged graph and report |
| 2 | ## the bounding box, so the result can be compared against Blender's own. |
| 3 | extends SceneTree |
| 4 | func _init() -> void: |
| 5 | var a := OS.get_cmdline_user_args() |
| 6 | var f := FileAccess.open(a[0], FileAccess.READ) |
| 7 | var head := f.get_line().split(" ") |
| 8 | var nv := int(head[0]) |
| 9 | var nt := int(head[1]) |
| 10 | var pos := PackedVector3Array() |
| 11 | pos.resize(nv) |
| 12 | for i in range(nv): |
| 13 | var p := f.get_line().split(" ") |
| 14 | pos[i] = Vector3(float(p[0]), float(p[1]), float(p[2])) |
| 15 | var idx := PackedInt32Array() |
| 16 | idx.resize(nt * 3) |
| 17 | for i in range(nt): |
| 18 | var p := f.get_line().split(" ") |
| 19 | idx[i*3] = int(p[0]); idx[i*3+1] = int(p[1]); idx[i*3+2] = int(p[2]) |
| 20 | f.close() |
| 21 | var arrays := [] |
| 22 | arrays.resize(Mesh.ARRAY_MAX) |
| 23 | arrays[Mesh.ARRAY_VERTEX] = pos |
| 24 | arrays[Mesh.ARRAY_INDEX] = idx |
| 25 | var am := ArrayMesh.new() |
| 26 | am.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays) |
| 27 | print("cage in: %d verts, %d tris" % [nv, nt]) |
| 28 | # ⛔ ISOLATION: read the ArrayMesh straight back, with proc-nodes nowhere |
| 29 | # near it. If the bbox is already swapped here, the harness is the liar. |
| 30 | var rt: PackedVector3Array = am.surface_get_arrays(0)[Mesh.ARRAY_VERTEX] |
| 31 | var rlo := Vector3(1e30, 1e30, 1e30) |
| 32 | var rhi := Vector3(-1e30, -1e30, -1e30) |
| 33 | for p2 in rt: |
| 34 | rlo = rlo.min(p2); rhi = rhi.max(p2) |
| 35 | print("ROUND TRIP (no graph): x %.2f..%.2f y %.2f..%.2f z %.2f..%.2f" |
| 36 | % [rlo.x, rhi.x, rlo.y, rhi.y, rlo.z, rhi.z]) |
| 37 | |
| 38 | var g: ProcNodeGraph = GraphImporter.import_from_json( |
| 39 | FileAccess.get_file_as_string(a[1])) |
| 40 | var host := ProcGeometryNode.new() |
| 41 | host.use_gpu = true |
| 42 | host.set_input_mesh(am) |
| 43 | host.set_graph(g) |
| 44 | get_root().add_child(host) |
| 45 | var m: ArrayMesh = host.bake_mesh() |
| 46 | if m == null or m.get_surface_count() == 0: |
| 47 | print("BAKE: no mesh") |
| 48 | quit(1) |
| 49 | return |
| 50 | var v: PackedVector3Array = m.surface_get_arrays(0)[Mesh.ARRAY_VERTEX] |
| 51 | var lo := Vector3(1e30, 1e30, 1e30) |
| 52 | var hi := Vector3(-1e30, -1e30, -1e30) |
| 53 | for p in v: |
| 54 | lo = lo.min(p); hi = hi.max(p) |
| 55 | print("GODOT result bbox: x %.2f..%.2f y %.2f..%.2f z %.2f..%.2f (%d verts)" |
| 56 | % [lo.x, hi.x, lo.y, hi.y, lo.z, hi.z, v.size()]) |
| 57 | quit(0) |