"""Make a glTF relief from one rectilinear image and a 16-bit relative inverse-depth estimate.""" from pathlib import Path import json, struct, sys import numpy as np from PIL import Image def write_glb(photo, depth_path, destination): W,H=Image.open(photo).size d=np.asarray(Image.open(depth_path),dtype=np.float32)/65535 assert d.shape==(H,W) u,v=np.meshgrid(np.linspace(0,1,193),np.linspace(0,1,105)) distance=1/(.10+.90*d[np.rint(v*(H-1)).astype(int),np.rint(u*(W-1)).astype(int)]) f=W/(2*np.tan(np.radians(102)/2)) pos=np.stack([(u-.5)*W/f*distance,(.5-v)*H/f*distance,-distance],-1).astype('