remove long edges in post
This commit is contained in:
+82
-4
@@ -33,7 +33,7 @@ sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
|
||||
from data.cloth3d_io import readPC2, loadInfo, writePC2, readOBJ, quads2tris, readPC2Frame
|
||||
from data.utils import Frame
|
||||
from smpl.smpl_torch import SMPL
|
||||
from custom_utils.custom_utils import _maskFaces
|
||||
from custom_utils.custom_utils import _maskFaces, remove_long_edges
|
||||
|
||||
|
||||
def create_extras_file(folder):
|
||||
@@ -631,7 +631,6 @@ def create_frames_file_partial(folder, out_folder, split=0.9, part=0.1):
|
||||
f.write(f'{frame.id} {frame.frame_nr} {frame.garment}\n')
|
||||
|
||||
|
||||
|
||||
def check_irregular_poses(folder, folder_reg, out_folder):
|
||||
for i in range(100, 200, 5):
|
||||
frame: Frame = Frame('01512', i, 'Dress')
|
||||
@@ -800,6 +799,83 @@ def get_ids():
|
||||
pass
|
||||
|
||||
|
||||
def generate_fixed_masks(folder, out_folder):
|
||||
ids = sorted(os.listdir(folder))
|
||||
os.makedirs(os.path.join(out_folder, 'mesh_fixed'), exist_ok=True)
|
||||
F = np.load('smpl/smpl_faces.npy')
|
||||
F_skirt = np.load('smpl/smpl_faces_skirt.npy')
|
||||
|
||||
import random
|
||||
# import trimesh
|
||||
import pyvista as pv
|
||||
random.shuffle(ids)
|
||||
|
||||
|
||||
for id in tqdm(ids):
|
||||
garment_dir = os.path.join(folder, id)
|
||||
if not os.path.isdir(garment_dir):
|
||||
continue
|
||||
|
||||
garments = [f.replace('.obj','') for f in os.listdir(garment_dir) if f.endswith('.obj')]
|
||||
|
||||
for garment in garments:
|
||||
if os.path.exists(os.path.join(out_folder, f'{id}_{garment}.pc16')):
|
||||
continue
|
||||
|
||||
is_skirt = garment in ['Dress', 'Skirt']
|
||||
|
||||
mesh_static = np.load(os.path.join(out_folder, 'mesh_static', f'{id}_{garment}.npy'))
|
||||
mask = np.load(os.path.join(out_folder, 'mesh_mask', f'{id}_{garment}.npy'))
|
||||
_, faces = _maskFaces(np.zeros((14475, 3)), F_skirt if is_skirt else F, mask)
|
||||
_, new_mask = remove_long_edges(mesh_static, faces.astype(np.int32), 0.2 if is_skirt else 0.1)
|
||||
new_mask_full = np.zeros((14475), dtype=bool)
|
||||
new_mask_full[mask] = new_mask
|
||||
_, new_faces = _maskFaces(np.zeros((14475, 3)), F_skirt if is_skirt else F, new_mask_full)
|
||||
|
||||
mesh_new = mesh_static[new_mask]
|
||||
|
||||
# fig = go.Figure(data=[go.Mesh3d(x=mesh_new[:,0], y=mesh_new[:,1], z=mesh_new[:,2], i=new_faces[:,0], j=new_faces[:,1], k=new_faces[:,2])])
|
||||
# fig.update_layout(scene_aspectmode='cube')
|
||||
# fig.update_layout(scene=dict(xaxis=dict(range=[-1,1]), yaxis=dict(range=[-1,1]), zaxis=dict(range=[-1,1])))
|
||||
# fig.show()
|
||||
|
||||
flattened_faces = np.asarray([np.concatenate((np.array([3]), f)) for f in new_faces.astype(np.int32)]).flatten()
|
||||
m = pv.PolyData(mesh_new, flattened_faces)
|
||||
|
||||
m.fill_holes(0.03, inplace=True, progress_bar=False)
|
||||
|
||||
# m = trimesh.Trimesh(vertices=mesh_new, faces=new_faces, process=False, validate=False)
|
||||
# trimesh.repair.fill_holes(m)
|
||||
|
||||
mesh_new = np.asarray(m.points)
|
||||
new_faces = np.asarray(m.faces).reshape([-1, 4])[:, 1:]
|
||||
|
||||
m = tm.Trimesh(vertices=mesh_new, faces=new_faces, process=False, validate=False)
|
||||
tm.repair.fix_winding(m)
|
||||
|
||||
mesh_new = np.asarray(m.vertices)
|
||||
new_faces = np.asarray(m.faces)
|
||||
|
||||
# fig = go.Figure(data=[go.Mesh3d(x=mesh_new[:,0], y=mesh_new[:,1], z=mesh_new[:,2], i=new_faces[:,0], j=new_faces[:,1], k=new_faces[:,2])])
|
||||
# fig.update_layout(scene_aspectmode='cube')
|
||||
# fig.update_layout(scene=dict(xaxis=dict(range=[-1,1]), yaxis=dict(range=[-1,1]), zaxis=dict(range=[-1,1])))
|
||||
# fig.show()
|
||||
|
||||
# fig = go.Figure(data=[go.Mesh3d(x=mesh_static[:,0], y=mesh_static[:,1], z=mesh_static[:,2], i=faces[:,0], j=faces[:,1], k=faces[:,2])])
|
||||
# fig.update_layout(scene_aspectmode='cube')
|
||||
# fig.update_layout(scene=dict(xaxis=dict(range=[-1,1]), yaxis=dict(range=[-1,1]), zaxis=dict(range=[-1,1])))
|
||||
# fig.show()
|
||||
|
||||
# print((~new_mask).sum())
|
||||
|
||||
np.savez_compressed(os.path.join(out_folder, 'mesh_fixed', f'{id}_{garment}.npz'), mask=new_mask_full, mas_convert=new_mask, faces=new_faces)
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
|
||||
@@ -832,9 +908,11 @@ if __name__ == '__main__':
|
||||
# calculate_average(folder, out_folder)
|
||||
|
||||
# create_frames_file(folder, out_folder)
|
||||
get_ids()
|
||||
# get_ids()
|
||||
# create_frames_file_test(folder, out_folder)
|
||||
# create_frames_file_partial(folder, out_folder, part=0.5)
|
||||
|
||||
# folder = '/data-local/127_2/cape_processed/test/female'
|
||||
# create_mesh_normals_cape(folder, None)
|
||||
# create_mesh_normals_cape(folder, None)
|
||||
|
||||
generate_fixed_masks(folder, out_folder)
|
||||
Reference in New Issue
Block a user