From 21ba963409ed5cc9ff328bff1e7b133aa0445a7b Mon Sep 17 00:00:00 2001 From: Hunor Laczko Date: Tue, 28 Feb 2023 18:50:46 +0000 Subject: [PATCH] export stl for blender --- plot_examples.py | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/plot_examples.py b/plot_examples.py index 161b862..7e4b68d 100644 --- a/plot_examples.py +++ b/plot_examples.py @@ -38,6 +38,14 @@ def write_obj(file, vertices, faces, colors): line = 'f ' + ' '.join([str(_) for _ in f]) + '\n' file.write(line) +def write_obj_2(file, vertices, faces): + with open(file, 'w') as file: + for v in vertices: + line = 'v ' + ' '.join([str(_) for _ in v]) + '\n' + file.write(line) + for f in faces: + line = 'f ' + ' '.join([str(_) for _ in f]) + '\n' + file.write(line) def export_to_ply(mesh, file): ply = tm.exchange.ply.export_ply(mesh, encoding='ascii', vertex_normal=True, include_attributes=True) @@ -196,8 +204,8 @@ if __name__ == '__main__': shuffle=True, do_repeat=False, resolutions=[512, 32], - frames_file='/home/workspace/data/dataset/test_ready/frames_pose_cluster_20_sample_10.txt', - # frames_file='/home/workspace/data/dataset/test_ready/frames_00438_146.txt', + # frames_file='/home/workspace/data/dataset/test_ready/frames_pose_cluster_20_sample_10.txt', + frames_file='/home/workspace/data/dataset/test_ready/frames_00438_146.txt', ) static_dataset = StaticDataset(folder='/home/workspace/data/dataset/test_ready', resolutions=[512, 32], @@ -252,6 +260,36 @@ if __name__ == '__main__': x = np.concatenate((body, posed), axis=0) # m = tm.Trimesh(x, faces, process=False, validate=False, vertex_colors=colors) + + x = posed + x_1 = unposed.copy() + x_1[:, 0] = x_1[:, 0] + 0.75 + x_2 = unposed_shaped.copy() + x_2[:, 0] = x_2[:, 0] + 1.75 + garments = np.concatenate((x, x_1, x_2), axis=0) + all_faces = np.concatenate((faces_garment, faces_garment + x.shape[0], faces_garment + 2*x.shape[0]), axis=0).astype(np.int32) + mesh = garments + faces = all_faces + fig = go.Figure() + fig.add_trace(go.Mesh3d( + x=mesh[:,0], + y=mesh[:,2], + z=mesh[:,1], + i = faces[:,0], + j = faces[:,1], + k = faces[:,2], + text="", + lighting={ 'ambient':0.8, 'diffuse':0.5, 'roughness':0.5 }, + + ),) + fig.show() + from stl import mesh as mesh_stl + obj = mesh_stl.Mesh(np.zeros(faces.shape[0], dtype=mesh_stl.Mesh.dtype)) + for i, f in enumerate(faces): + for j in range(3): + obj.vectors[i][j] = mesh[f[j],:] + write_obj_2('temp/blender_test_2.obj', garments, all_faces) + # fig = plot_fixed(x, faces, colors) # fig.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_posed.svg')