Spaces:
Sleeping
Sleeping
updated to save temp mesh file
Browse files
app.py
CHANGED
@@ -201,51 +201,12 @@ def proc_all(mesh_path, mode_path):
|
|
201 |
alldicts.append(single)
|
202 |
return alldicts
|
203 |
|
204 |
-
def create_scene(
|
205 |
-
|
206 |
-
verts = np.array(mesh.vertices)
|
207 |
-
colors = []
|
208 |
-
for i in range(len(verts)):
|
209 |
-
if i in dicts[plane_idx]['left']:
|
210 |
-
color = [8, 136, 255]
|
211 |
-
elif i in dicts[plane_idx]['right']:
|
212 |
-
color = [204, 20, 245]
|
213 |
-
else:
|
214 |
-
color = [225, 225, 225]
|
215 |
-
colors.append(color)
|
216 |
-
|
217 |
-
mesh.visual.vertex_colors = colors
|
218 |
-
newplane = dicts[plane_idx]['plane']
|
219 |
-
newplane.visual.vertex_colors = np.tile([100, 100, 100, 100], (4, 1))
|
220 |
-
scene = trimesh.Scene([mesh, newplane])
|
221 |
temp_file = f"/tmp/scene_{plane_idx}.obj"
|
222 |
scene.export(temp_file)
|
223 |
return temp_file
|
224 |
|
225 |
-
# def load_mesh_max(mesh_file_name):
|
226 |
-
# plane_path = "planes_processed/" + mesh_file_name.split('/')[-1].split('.')[0][:-7] + "_planes.pickle"
|
227 |
-
# with open(plane_path, 'rb') as f:
|
228 |
-
# dicts = pickle.load(f)
|
229 |
-
# #dicts = proc_all(mesh_file_name) # Assuming proc_all is defined and returns a list of dictionaries
|
230 |
-
# allmesh = []
|
231 |
-
# for i in range(min(5, len(dicts))): # Limiting to maximum 5 outputs
|
232 |
-
# temp_file = create_scene(mesh_file_name, dicts, -(i+1))
|
233 |
-
# allmesh.append(temp_file)
|
234 |
-
# return allmesh + [None] * (5 - len(allmesh)) # Fill the rest with None if less than 5
|
235 |
-
|
236 |
-
# def load_mesh_min(mesh_file_name):
|
237 |
-
# plane_path = "planes_processed/" + mesh_file_name.split('/')[-1].split('.')[0][:-7] + "_planes.pickle"
|
238 |
-
# with open(plane_path, 'rb') as f:
|
239 |
-
# dicts = pickle.load(f)
|
240 |
-
# #dicts = proc_all(mesh_file_name) # Assuming proc_all is defined and returns a list of dictionaries
|
241 |
-
# allmesh = []
|
242 |
-
# for i in range(min(5, len(dicts))): # Limiting to maximum 5 outputs
|
243 |
-
# temp_file = create_scene(mesh_file_name, dicts, i)
|
244 |
-
# allmesh.append(temp_file)
|
245 |
-
# return allmesh + [None] * (5 - len(allmesh)) # Fill the rest with None if less than 5
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
def load_mesh_max(scene_path):
|
250 |
dict_path = "planes_processed/" + scene_path.split('/')[-1].split('.')[0][:-7] + "_dicts.pickle"
|
251 |
with open(dict_path, 'rb') as f:
|
@@ -254,8 +215,13 @@ def load_mesh_max(scene_path):
|
|
254 |
scenes = pickle.load(f)
|
255 |
alllengths = [dic['len'] for dic in dicts]
|
256 |
sort_idcs = np.argsort(alllengths)
|
257 |
-
sorted_planes = np.array(scenes)[
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
259 |
|
260 |
def load_mesh_min(scene_path):
|
261 |
dict_path = "planes_processed/" + scene_path.split('/')[-1].split('.')[0][:-7] + "_dicts.pickle"
|
@@ -266,13 +232,19 @@ def load_mesh_min(scene_path):
|
|
266 |
alllengths = [dic['len'] for dic in dicts]
|
267 |
sort_idcs = np.argsort(alllengths)
|
268 |
sorted_planes = np.array(scenes)[sort_idcs]
|
269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
|
271 |
|
272 |
def reset_outputs():
|
273 |
# Returns a list of None, one for each 3D model output to reset them
|
274 |
return [None] * 10 # Adjust to the total number of Model3D components you have
|
275 |
-
|
276 |
examples = glob.glob("planes_processed/*_planes.pickle")
|
277 |
|
278 |
with gr.Blocks() as demo:
|
@@ -303,4 +275,4 @@ with gr.Blocks() as demo:
|
|
303 |
|
304 |
|
305 |
if __name__ == "__main__":
|
306 |
-
demo.launch()
|
|
|
201 |
alldicts.append(single)
|
202 |
return alldicts
|
203 |
|
204 |
+
def create_scene(allscenes, plane_idx):
|
205 |
+
scene = allscenes[plane_idx]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
temp_file = f"/tmp/scene_{plane_idx}.obj"
|
207 |
scene.export(temp_file)
|
208 |
return temp_file
|
209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
def load_mesh_max(scene_path):
|
211 |
dict_path = "planes_processed/" + scene_path.split('/')[-1].split('.')[0][:-7] + "_dicts.pickle"
|
212 |
with open(dict_path, 'rb') as f:
|
|
|
215 |
scenes = pickle.load(f)
|
216 |
alllengths = [dic['len'] for dic in dicts]
|
217 |
sort_idcs = np.argsort(alllengths)
|
218 |
+
sorted_planes = np.array(scenes)[sort_idcs]
|
219 |
+
allmesh = []
|
220 |
+
for i in range(min(5, len(dicts))): # Limiting to maximum 5 outputs
|
221 |
+
temp_file = create_scene(sorted_planes, -(i+1))
|
222 |
+
allmesh.append(temp_file)
|
223 |
+
return allmesh + [None] * (5 - len(allmesh)) # Fill the rest with None if less than 5
|
224 |
+
|
225 |
|
226 |
def load_mesh_min(scene_path):
|
227 |
dict_path = "planes_processed/" + scene_path.split('/')[-1].split('.')[0][:-7] + "_dicts.pickle"
|
|
|
232 |
alllengths = [dic['len'] for dic in dicts]
|
233 |
sort_idcs = np.argsort(alllengths)
|
234 |
sorted_planes = np.array(scenes)[sort_idcs]
|
235 |
+
allmesh = []
|
236 |
+
for i in range(min(5, len(dicts))): # Limiting to maximum 5 outputs
|
237 |
+
temp_file = create_scene(sorted_planes, i)
|
238 |
+
allmesh.append(temp_file)
|
239 |
+
return allmesh + [None] * (5 - len(allmesh)) # Fill the rest with None if less than 5
|
240 |
+
|
241 |
+
|
242 |
|
243 |
|
244 |
def reset_outputs():
|
245 |
# Returns a list of None, one for each 3D model output to reset them
|
246 |
return [None] * 10 # Adjust to the total number of Model3D components you have
|
247 |
+
|
248 |
examples = glob.glob("planes_processed/*_planes.pickle")
|
249 |
|
250 |
with gr.Blocks() as demo:
|
|
|
275 |
|
276 |
|
277 |
if __name__ == "__main__":
|
278 |
+
demo.launch(debug=True)
|