humanoidBench / sharpa11_20261107 /scripts /sharpa11_floor_boundary.py
JoeyYuzy's picture
Add 11 Sharpa Gaussian homes with repaired flat floors, collision and 44 RTX views
bf3194a verified
Raw History Blame Contribute Delete
3.34 kB
"""Extend invisible floor support at scan boundaries without touching visuals."""
import json
from pathlib import Path
import numpy as np
from scipy import ndimage as ndi
from pxr import Usd, UsdGeom, Vt
from sharpa11_build import OUT, save
def patch(directory):
report = json.loads((directory/'floor_repair.json').read_text())
if report.get('boundary_support_margin_m'):
return
provenance = np.load(directory/'floor_repair_indices.npz')
cells = provenance['footprint_cells']
resolution = float(provenance['footprint_resolution'])
origin = provenance['footprint_origin'].copy()
occupied = np.zeros(cells.max(0)+2, bool)
occupied[cells[:,0],cells[:,1]] = True
occupied = np.pad(occupied,7)
origin -= 7*resolution
occupied = ndi.binary_dilation(occupied, iterations=5)
occupied = ndi.binary_closing(occupied,iterations=1)
labels,_=ndi.label(ndi.binary_fill_holes(occupied)&~occupied)
sizes=np.bincount(labels.ravel()); small=sizes<int(2.0/resolution**2); small[0]=False
occupied |= small[labels]
cells=np.argwhere(occupied)
corners=np.unique(np.concatenate([cells,cells+[1,0],cells+[1,1],cells+[0,1]]),axis=0)
index=-np.ones(np.array(occupied.shape)+1,np.int32)
index[corners[:,0],corners[:,1]]=np.arange(len(corners))
xy=origin+corners*resolution; N=len(corners)
points=np.r_[np.c_[xy,np.zeros(N)],np.c_[xy,np.full(N,-.12)]].astype('f')
quads=np.column_stack([index[cells[:,0],cells[:,1]],index[cells[:,0]+1,cells[:,1]],
index[cells[:,0]+1,cells[:,1]+1],index[cells[:,0],cells[:,1]+1]])
faces=[quads,quads[:,::-1]+N]
for edge,delta in enumerate([[-1,0],[0,-1],[1,0],[0,1]]):
neighbor=cells+delta; valid=((neighbor>=0)&(neighbor<occupied.shape)).all(1)
present=np.zeros(len(cells),bool);present[valid]=occupied[neighbor[valid,0],neighbor[valid,1]]
a,b=[(3,0),(0,1),(1,2),(2,3)][edge];q=quads[~present]
faces.append(np.c_[q[:,b],q[:,a],q[:,a]+N,q[:,b]+N])
faces=np.concatenate(faces).astype(np.int32)
stage=Usd.Stage.Open(str(directory/'scene.usdc'))
floor=UsdGeom.Mesh(stage.GetPrimAtPath('/World/FlatFloorCollision'))
floor.GetPointsAttr().Set(Vt.Vec3fArray.FromNumpy(points))
floor.GetFaceVertexCountsAttr().Set(Vt.IntArray.FromNumpy(np.full(len(faces),4,np.int32)))
floor.GetFaceVertexIndicesAttr().Set(Vt.IntArray.FromNumpy(faces.ravel()))
stage.GetRootLayer().Save()
np.savez_compressed(directory/'floor_repair_indices.npz',leveled_source_indices=provenance['leveled_source_indices'],
footprint_cells=cells,footprint_origin=origin,footprint_resolution=resolution)
report['boundary_support_margin_m']=.20
report['collision_floor_area_before_boundary_support_m2']=report['collision_floor_area_m2']
report['collision_floor_area_m2']=float(len(cells)*resolution**2)
report['boundary_support_note']='Invisible planar support extended 20 cm at observed boundaries; small enclosed scan gaps filled; no visual Gaussian attributes changed'
save(directory/'floor_repair.json',report)
print('SUPPORTED',directory.name,report['collision_floor_area_m2'],flush=True)
if __name__=='__main__':
for directory in sorted(OUT.iterdir()):
if (directory/'floor_repair.json').exists():patch(directory)