MCPcopy Index your code
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / read_obj

Function read_obj

inpaint/mesh.py:2205–2264  ·  view source on GitHub ↗
(mesh_fi)

Source from the content-addressed store, hash-verified

2203 raise Exception('Unknown file format')
2204
2205def read_obj(mesh_fi):
2206 mfile = open(mesh_fi, 'r', encoding="utf8")
2207 Height = None
2208 Width = None
2209 hFov = None
2210 vFov = None
2211 mean_loc_depth = None
2212
2213 firstline = mfile.readline().split('\n')[0]
2214 if not firstline.startswith('# depthmap-script'):
2215 raise Exception('This requires a 3D inpainted mesh generated by this extension.')
2216
2217 while True:
2218 line = mfile.readline().split('\n')[0]
2219 if line.startswith('#'):
2220 if line.split(' ')[1] == 'H':
2221 Height = int(line.split(' ')[-1].split('\n')[0])
2222 elif line.split(' ')[1] == 'W':
2223 Width = int(line.split(' ')[-1].split('\n')[0])
2224 elif line.split(' ')[1] == 'hFov':
2225 hFov = float(line.split(' ')[-1].split('\n')[0])
2226 elif line.split(' ')[1] == 'vFov':
2227 vFov = float(line.split(' ')[-1].split('\n')[0])
2228 elif line.split(' ')[1] == 'meanLoc':
2229 mean_loc_depth = float(line.split(' ')[-1].split('\n')[0])
2230 elif line.split(' ')[1] == 'vertices':
2231 num_vertex = int(line.split(' ')[-1])
2232 elif line.split(' ')[1] == 'faces':
2233 num_face = int(line.split(' ')[-1])
2234 # check for start of object
2235 elif line.startswith('o depthmap'):
2236 break
2237
2238 contents = mfile.readlines()
2239 mfile.close()
2240
2241 vertex_infos = contents[:num_vertex]
2242 face_infos = contents[num_vertex:]
2243
2244 verts = [None] * num_vertex
2245 colors = [None] * num_vertex
2246 faces = [None] * num_face
2247 i = 0
2248 for v_info in vertex_infos:
2249 str_info = [float(v) for v in v_info.split('\n')[0].split(' ')[1:]]
2250 vx, vy, vz, r, g, b = str_info
2251 verts[i] = [vx, vy, vz]
2252 colors[i] = [r, g, b]
2253 i = i + 1
2254 verts = np.array(verts)
2255 colors = np.array(colors)
2256
2257 i = 0
2258 for f_info in face_infos:
2259 v1, v2, v3 = [int(f) for f in f_info.split('\n')[0].split(' ')[1:]]
2260 faces[i] = [v1 - 1, v2 - 1, v3 - 1]
2261 i = i + 1
2262 faces = np.array(faces)

Callers 1

read_meshFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected