From daf51b4dbe53dcb7780ef2198f8f0f261f8612e8 Mon Sep 17 00:00:00 2001 From: Hunor Laczko Date: Thu, 1 Jun 2023 17:51:01 +0200 Subject: [PATCH] further investigation --- data/cloth3d_io.py | 2 +- data/investigate.py | 71 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/data/cloth3d_io.py b/data/cloth3d_io.py index dc3e57b..4136715 100644 --- a/data/cloth3d_io.py +++ b/data/cloth3d_io.py @@ -342,7 +342,6 @@ import sys sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..') import plotly.graph_objects as go -from custom_utils.custom_utils import _maskFaces def plot_3d(mesh, faces): fig = go.Figure() @@ -371,6 +370,7 @@ def plot_3d(mesh, faces): if __name__ == '__main__': + from custom_utils.custom_utils import _maskFaces folder = '/home/workspace/data/dataset/cloth3d/train' F = np.load("custom_utils/smpl_faces.npy")#.astype(np.int32) diff --git a/data/investigate.py b/data/investigate.py index 93ebaab..7105ef1 100644 --- a/data/investigate.py +++ b/data/investigate.py @@ -4,11 +4,26 @@ import random import numpy as np import plotly.graph_objects as go from pymeshfix import MeshFix +import trimesh sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..') from data.cloth3d_io import read_garment_mask, read_garment_template, read_posed_garment_frame, loadInfo, read_posed_body_frame, read_posed_body, read_posed_garment, read_curvatures, read_curvature_frame, writeOBJ -from custom_utils.custom_utils import _maskFaces +# from custom_utils.custom_utils import _maskFaces +def _maskFaces(V, F, mask, return_unfixed=False): + V_mask = mask + F_mask = np.take(V_mask, F.reshape(-1), axis=0) + F_mask = F_mask.reshape((-1, 3)).sum(axis=1) == 3 + + V_ind = np.zeros(V_mask.shape) + V_ind[V_mask] = np.arange(V_mask.sum()) + F_new = np.take(V_ind, F[F_mask, :].reshape(-1), axis=0).reshape((-1, 3)) + V_new = V[V_mask, :] + + if return_unfixed: + return V_new, F_new, F[F_mask, :] + else: + return V_new, F_new def get_frames(folder, frames_file): frames = [] @@ -133,7 +148,7 @@ def check(folder, frame): v = mesh_posed[mask,:] is_skirt = (garment == 'Dress' or garment == 'Skirt') skirt_mod = '_skirt' if is_skirt else '' - F = np.load(f'custom_utils/smpl_faces{skirt_mod}.npy').astype(np.int32) + F = np.load(f'smpl/smpl_faces{skirt_mod}.npy').astype(np.int32) _, faces, unfixed = _maskFaces(np.zeros((14475,3)), F, mask, True) meshfix = MeshFix(v, faces) @@ -180,7 +195,22 @@ def check(folder, frame): faces_3 = mask_faces(F, mask_2, mask_2_raw, repeated, mesh_posed) # writeOBJ('temp/investigate_3.obj', v_2, faces_3) - plot(v_2, faces_3) + # plot(v_2, faces_3) + + # save stl + # mesh = trimesh.Trimesh(vertices=v_2, faces=faces_3, process=False, validate=False) + # mesh.export('temp/investigate_00761.stl') + + # # read stl file + # mesh = trimesh.load('temp/fixed_00761.stl', process=False, validate=False) + # mesh = trimesh.load('temp/fixed_00761.ply', process=False, validate=False) + + # plotly plot of mesh with v_2 vertices and faces from trimesh mesh + # faces_4 = faces_3 #np.asarray(mesh.faces) + # go.Figure(data = [go.Mesh3d(x=v_2[:, 0], y=v_2[:, 1], z=v_2[:, 2], i=faces_4[:, 0], j=faces_4[:, 1], k=faces_4[:, 2],) + # ]).show() + + # plot repeated @@ -189,9 +219,9 @@ def check(folder, frame): r.extend(rr) x = mesh_posed y = mesh_posed[r,:] - go.Figure(data = [go.Scatter3d(x=x[:, 0], y=x[:, 1], z=x[:, 2], marker=dict(size=3, line=dict(width=0),), mode='markers'), - go.Scatter3d(x=y[:, 0], y=y[:, 1], z=y[:, 2], marker=dict(size=5, line=dict(width=0),), mode='markers'), - ]).show() + # go.Figure(data = [go.Scatter3d(x=x[:, 0], y=x[:, 1], z=x[:, 2], marker=dict(size=3, line=dict(width=0),), mode='markers'), + # go.Scatter3d(x=y[:, 0], y=y[:, 1], z=y[:, 2], marker=dict(size=5, line=dict(width=0),), mode='markers'), + # ]).show() # unq, idx, count = np.unique(v, axis=0, return_counts=True, return_index=True) @@ -207,20 +237,34 @@ def check(folder, frame): # faces_4 = mask_faces(faces.astype(np.int64), mask_3, mask_2_raw, repeated, v) # plot(v[mask_3,:], faces_4) - + return mask_2_raw, faces_3 pass - + + +def remask(folder, frame, mask, out_folder): + id, frame_nr, garment = frame.split() + frame_nr = int(frame_nr) + info = loadInfo(os.path.join(folder, id, 'info.mat')) + + if frame_nr == 0: + mesh_static = read_static_garment(folder, id, garment) + + mesh_posed = read_posed_garment_frame(folder, id, garment, frame_nr, mask=None, shape=None, pose=info['poses'][:,frame_nr], deorient=True, unshape=None) + mesh_posed = mesh_posed[mask,:] + os.makedirs(os.path.join(out_folder, 'mesh_posed_no_orient'), exist_ok=True) + np.savez_compressed(os.path.join(out_folder, 'mesh_posed_no_orient', f'{id}_{frame_nr}.npz'), mesh_posed_no_orient=mesh_posed) + if __name__ == "__main__": - folder = '/home/workspace/data/dataset/cloth3d/train' - frames = get_frames(folder, 'frames_all.txt') + folder = r'D:\Work\Dataset\cloth3d\train' + frames = [f'00761_{i}' for i in range(300)] root = '/'.join(folder.split('/')[:-1]) type = folder.split('/')[-1] use_no_orient = False no_shape = False - is_skirt = True + is_skirt = False skirt_modifier = '_skirt' if is_skirt else '' orient_mod = '_no_orient' if use_no_orient else '' @@ -229,8 +273,9 @@ if __name__ == "__main__": while True: frame = random.choice(frames) - frame = '05936 0 Dress' + frame = '00761 0 Tshirt' - check(folder, frame) + mask, faces = check(folder, frame) + remask(folder, frame, mask, 'temp/00761') pass