rabbitKabbit commited on
Commit
75a765b
·
verified ·
1 Parent(s): 401f402

Pipeline: lift carpets 2 cm in compose(); add lift_carpets.py for existing GLBs

Browse files
P64/Metascenes1_Spatiallm1_MasterSlam1/lift_carpets.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Lift flat carpet meshes to LIFT m above the floor (y up) so they do not z-fight with the floor plane.
2
+ Edits node matrices in the GLB JSON only (binary chunk untouched). Idempotent. Backs up to <file>.prelift."""
3
+ import sys, json, struct, shutil, os, numpy as np, trimesh
4
+ LIFT = 0.02
5
+ def fix(path):
6
+ s = trimesh.load(path)
7
+ shifts = {}
8
+ for n in s.graph.nodes_geometry:
9
+ if "carpet" not in n.lower(): continue
10
+ T, g = s.graph[n]; m = s.geometry[g].copy(); m.apply_transform(T)
11
+ d = LIFT - m.bounds[0][1]
12
+ if d > 1e-4: shifts[n] = d
13
+ if not shifts: return 0
14
+ b = open(path, "rb").read()
15
+ jl = struct.unpack("<I", b[12:16])[0]; j = json.loads(b[20:20+jl]); rest = b[20+jl:]
16
+ k = 0
17
+ for nd in j["nodes"]:
18
+ nm = nd.get("name", "")
19
+ if nm in shifts or nm.replace("/", "_") in shifts:
20
+ d = shifts.get(nm, shifts.get(nm.replace("/", "_")))
21
+ if "matrix" in nd: nd["matrix"][13] += d
22
+ else: nd["translation"] = [0, d, 0]
23
+ k += 1
24
+ js = json.dumps(j, separators=(",", ":")).encode(); js += b" " * (-len(js) % 4)
25
+ out = b[:8] + struct.pack("<I", 12 + 8 + len(js) + len(rest)) + struct.pack("<I", len(js)) + b"JSON" + js + rest
26
+ if not os.path.exists(path + ".prelift"): shutil.copy(path, path + ".prelift")
27
+ open(path, "wb").write(out)
28
+ return k
29
+ if __name__ == "__main__":
30
+ for p in sys.argv[1:]: print(p, fix(p))
P64/Metascenes1_Spatiallm1_MasterSlam1/rose_scan2sim.py CHANGED
@@ -376,6 +376,9 @@ def compose(room_glb, out, deltas, dst):
376
  for name, D in deltas.items():
377
  o = trimesh.load(os.path.join(out, "objects", name + ".glb"), force="scene", process=False)
378
  o.apply_transform(ZUP2GLTF @ np.asarray(D))
 
 
 
379
  for node in o.graph.nodes_geometry:
380
  T, g = o.graph[node]
381
  scene.add_geometry(o.geometry[g].copy(), node_name=f"{name}/{node}", geom_name=f"{name}/{g}", transform=T)
 
376
  for name, D in deltas.items():
377
  o = trimesh.load(os.path.join(out, "objects", name + ".glb"), force="scene", process=False)
378
  o.apply_transform(ZUP2GLTF @ np.asarray(D))
379
+ if "carpet" in name.lower(): # flat carpets: keep >= 2 cm above the floor plane (y=0) so they do not z-fight with it
380
+ lift = 0.02 - o.bounds[0][1]
381
+ if lift > 0: o.apply_translation([0, lift, 0])
382
  for node in o.graph.nodes_geometry:
383
  T, g = o.graph[node]
384
  scene.add_geometry(o.geometry[g].copy(), node_name=f"{name}/{node}", geom_name=f"{name}/{g}", transform=T)