neverix commited on
Commit
724a768
1 Parent(s): fb6e634

Add full app

Browse files
Files changed (3) hide show
  1. app.py +2 -2
  2. pulsar_clip.py +2 -2
  3. utils.py +4 -17
app.py CHANGED
@@ -24,8 +24,8 @@ def generate(*args):
24
  im.save(p.stdin, "PNG")
25
  p.stdin.close()
26
  p.wait()
27
- model_path = f"{filename}.ply"
28
- pc.save_ply(model_path)
29
  # model_path = None # TODO
30
  return [video_path, model_path]
31
 
 
24
  im.save(p.stdin, "PNG")
25
  p.stdin.close()
26
  p.wait()
27
+ model_path = f"{filename}.obj"
28
+ pc.save_obj(model_path)
29
  # model_path = None # TODO
30
  return [video_path, model_path]
31
 
pulsar_clip.py CHANGED
@@ -226,8 +226,8 @@ class PulsarCLIP(object):
226
  pass
227
 
228
 
229
- def save_ply(self, fn):
230
- utils.save_ply(self.get_points(), fn)
231
 
232
 
233
  class DotDict(dict):
 
226
  pass
227
 
228
 
229
+ def save_obj(self, fn):
230
+ utils.save_obj(self.get_points(), fn)
231
 
232
 
233
  class DotDict(dict):
utils.py CHANGED
@@ -120,7 +120,7 @@ def ico_at(xyz=np.array([0, 0, 0]), radius=1.0, i=0):
120
  return vert * radius + xyz, [[y + i for y in x] for x in idx]
121
 
122
 
123
- def save_ply(points, out_path):
124
  with torch.inference_mode():
125
  vert_pos, vert_col, vert_rad, vert_opa = (x.detach().cpu().numpy() for x in points)
126
 
@@ -129,24 +129,11 @@ def save_ply(points, out_path):
129
  for xyz, radius, (r, g, b), a in zip(vert_pos, vert_rad, vert_col, vert_opa):
130
  v, i = ico_at(xyz, radius, len(verts))
131
  for x, y, z in v:
132
- verts.append((x, y, z, int(r * 255), int(g * 255), int(b * 255), int(a * 255)))
133
  faces += i
134
 
135
  with open(out_path, "w") as out_file:
136
- out_file.write("ply\n")
137
- out_file.write("format ascii 1.0\n")
138
- out_file.write(f"element vertex {len(verts)}\n")
139
- out_file.write("property float x\n")
140
- out_file.write("property float y\n")
141
- out_file.write("property float z\n")
142
- out_file.write("property uchar red\n")
143
- out_file.write("property uchar green\n")
144
- out_file.write("property uchar blue\n")
145
- out_file.write("property uchar alpha\n")
146
- out_file.write(f"element face {len(faces)}\n")
147
- out_file.write("property list uchar int vertex_index\n")
148
- out_file.write("end_header\n")
149
  for v in verts:
150
- out_file.write(" ".join(map(str, v)) + "\n")
151
  for f in faces:
152
- out_file.write(" ".join(map(str, [len(f)] + f)) + "\n")
 
120
  return vert * radius + xyz, [[y + i for y in x] for x in idx]
121
 
122
 
123
+ def save_obj(points, out_path):
124
  with torch.inference_mode():
125
  vert_pos, vert_col, vert_rad, vert_opa = (x.detach().cpu().numpy() for x in points)
126
 
 
129
  for xyz, radius, (r, g, b), a in zip(vert_pos, vert_rad, vert_col, vert_opa):
130
  v, i = ico_at(xyz, radius, len(verts))
131
  for x, y, z in v:
132
+ verts.append((x, y, z, r, g, b)) # int(r * 255), int(g * 255), int(b * 255), int(a * 255)))
133
  faces += i
134
 
135
  with open(out_path, "w") as out_file:
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  for v in verts:
137
+ out_file.write("v " + " ".join(map(str, v)) + "\n")
138
  for f in faces:
139
+ out_file.write("f " + " ".join(map(str, f)) + "\n")