Upload 9 files
Browse files- .gitattributes +2 -0
- scripts/_obj.py +284 -0
- scripts/blendshape_ict.npy +3 -0
- scripts/body_to_render.blend +3 -0
- scripts/example_body_render_job.txt +2 -0
- scripts/example_face_render_job.txt +2 -0
- scripts/face_ict_to_arkit.py +35 -0
- scripts/face_ict_to_render.blend +3 -0
- scripts/face_ict_to_vertices.py +73 -0
- scripts/render_add_audio.py +110 -0
.gitattributes
CHANGED
|
@@ -57,3 +57,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 57 |
# Video files - compressed
|
| 58 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 57 |
# Video files - compressed
|
| 58 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
scripts/body_to_render.blend filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
scripts/face_ict_to_render.blend filter=lfs diff=lfs merge=lfs -text
|
scripts/_obj.py
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class MeshData(object):
|
| 6 |
+
def __init__(self, **kwargs):
|
| 7 |
+
self.name = kwargs.get("name")
|
| 8 |
+
self.vertex_format = [
|
| 9 |
+
('v_pos', 3, 'float'),
|
| 10 |
+
('v_normal', 3, 'float'),
|
| 11 |
+
('v_tc0', 2, 'float'),
|
| 12 |
+
('v_ambient', 3, 'float'),
|
| 13 |
+
('v_diffuse', 3, 'float'),
|
| 14 |
+
('v_specular', 3, 'float')
|
| 15 |
+
]
|
| 16 |
+
self.vertices = []
|
| 17 |
+
self.indices = []
|
| 18 |
+
# Default basic material of mesh object
|
| 19 |
+
self.diffuse_color = np.array([1.0, 1.0, 1.0])
|
| 20 |
+
self.ambient_color = np.array([1.0, 1.0, 1.0])
|
| 21 |
+
self.specular_color = np.array([1.0, 1.0, 1.0])
|
| 22 |
+
self.specular_coefficent = 16.0
|
| 23 |
+
self.transparency = 1.0
|
| 24 |
+
|
| 25 |
+
def set_materials(self, mtl_dict):
|
| 26 |
+
self.diffuse_color = mtl_dict.get('Kd', self.diffuse_color)
|
| 27 |
+
self.diffuse_color = np.array([float(v) for v in self.diffuse_color])
|
| 28 |
+
self.ambient_color = mtl_dict.get('Ka', self.ambient_color)
|
| 29 |
+
self.ambient_color = np.array([float(v) for v in self.ambient_color])
|
| 30 |
+
self.specular_color = mtl_dict.get('Ks', self.specular_color)
|
| 31 |
+
self.specular_color = np.array([float(v) for v in self.specular_color])
|
| 32 |
+
self.specular_coefficent = float(
|
| 33 |
+
mtl_dict.get('Ns', self.specular_coefficent))
|
| 34 |
+
transparency = mtl_dict.get('d')
|
| 35 |
+
if not transparency:
|
| 36 |
+
transparency = 1.0 - float(mtl_dict.get('Tr', 0))
|
| 37 |
+
self.transparency = float(transparency)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class MTL(object):
|
| 41 |
+
def __init__(self, filename):
|
| 42 |
+
self.contents = {}
|
| 43 |
+
self.filename = filename
|
| 44 |
+
if not os.path.exists(filename):
|
| 45 |
+
return
|
| 46 |
+
for line in open(filename, "r"):
|
| 47 |
+
if line.startswith('#'):
|
| 48 |
+
continue
|
| 49 |
+
values = line.split()
|
| 50 |
+
if not values:
|
| 51 |
+
continue
|
| 52 |
+
if values[0] == 'newmtl':
|
| 53 |
+
mtl = self.contents[values[1]] = {}
|
| 54 |
+
elif mtl is None:
|
| 55 |
+
raise ValueError("mtl file doesn't start with newmtl stmt")
|
| 56 |
+
if len(values[1:]) > 1:
|
| 57 |
+
mtl[values[0]] = values[1:]
|
| 58 |
+
else:
|
| 59 |
+
mtl[values[0]] = values[1]
|
| 60 |
+
|
| 61 |
+
def __getitem__(self, key):
|
| 62 |
+
return self.contents[key]
|
| 63 |
+
|
| 64 |
+
def get(self, key, default=None):
|
| 65 |
+
return self.contents.get(key, default)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
class ObjHandle(object):
|
| 69 |
+
""" """
|
| 70 |
+
|
| 71 |
+
def __init__(self, filename=None, swapyz=False, delimiter=None,
|
| 72 |
+
vertices=None, normals=None, texcoords=None, faces=None, face_norms=None, face_texs=None,
|
| 73 |
+
obj_material=None, mtl=None, triangulate=False):
|
| 74 |
+
if filename is not None:
|
| 75 |
+
self.load(filename, swapyz, delimiter, triangulate=triangulate)
|
| 76 |
+
else:
|
| 77 |
+
self.vertices = np.array(vertices) if vertices is not None else np.array([])
|
| 78 |
+
self.normals = np.array(normals) if normals is not None else np.array([])
|
| 79 |
+
self.texcoords = np.array(texcoords) if texcoords is not None else np.array([])
|
| 80 |
+
self.faces = np.array(faces) if faces is not None else np.array([[]])
|
| 81 |
+
self.face_norms = np.array(face_norms) if face_norms is not None else np.empty((self.faces.shape[0], 0))
|
| 82 |
+
self.face_texs = np.array(face_texs) if face_texs is not None else np.empty((self.faces.shape[0], 0))
|
| 83 |
+
if swapyz:
|
| 84 |
+
self.vertices = self.vertices[: [0, 2, 1]]
|
| 85 |
+
self.normals = self.normals[: [0, 2, 1]]
|
| 86 |
+
|
| 87 |
+
self.objects = {}
|
| 88 |
+
self._current_object = None
|
| 89 |
+
self.obj_material = obj_material
|
| 90 |
+
self.mtl = mtl
|
| 91 |
+
|
| 92 |
+
def load(self, filename, swapyz=False, delimiter=None, triangulate=False):
|
| 93 |
+
"""Loads a Wavefront OBJ file. """
|
| 94 |
+
self.objects = {}
|
| 95 |
+
self.vertices = []
|
| 96 |
+
self.normals = []
|
| 97 |
+
self.texcoords = []
|
| 98 |
+
self.faces = []
|
| 99 |
+
self.face_norms = []
|
| 100 |
+
self.face_texs = []
|
| 101 |
+
|
| 102 |
+
self._current_object = None
|
| 103 |
+
self.mtl = None
|
| 104 |
+
self.obj_material = None
|
| 105 |
+
|
| 106 |
+
for line in open(filename, "r", encoding="utf8"):
|
| 107 |
+
if delimiter is not None and delimiter == "# object" and "# object" in line:
|
| 108 |
+
if self._current_object:
|
| 109 |
+
self.finish_object()
|
| 110 |
+
self._current_object = line.split()[2]
|
| 111 |
+
if line.startswith('#'):
|
| 112 |
+
continue
|
| 113 |
+
if line.startswith('s'):
|
| 114 |
+
continue
|
| 115 |
+
values = line.split()
|
| 116 |
+
if not values:
|
| 117 |
+
continue
|
| 118 |
+
if values[0] == 'o' and len(self.vertices) != 0:
|
| 119 |
+
self.finish_object()
|
| 120 |
+
self._current_object = values[1]
|
| 121 |
+
elif values[0] == 'mtllib':
|
| 122 |
+
# load materials file here
|
| 123 |
+
self.mtl = MTL(values[1])
|
| 124 |
+
elif values[0] in ('usemtl', 'usemat'):
|
| 125 |
+
self.obj_material = values[1]
|
| 126 |
+
if values[0] == 'v':
|
| 127 |
+
v = list(map(float, values[1:4]))
|
| 128 |
+
if swapyz:
|
| 129 |
+
v = [v[0], v[2], v[1]]
|
| 130 |
+
#v = [v[1], v[2], v[0]]
|
| 131 |
+
self.vertices.append(v)
|
| 132 |
+
elif values[0] == 'vn':
|
| 133 |
+
v = list(map(float, values[1:4]))
|
| 134 |
+
if swapyz:
|
| 135 |
+
v = [v[0], v[2], v[1]]
|
| 136 |
+
#v = [v[1], v[2], v[0]]
|
| 137 |
+
self.normals.append(v)
|
| 138 |
+
elif values[0] == 'vt':
|
| 139 |
+
self.texcoords.append(list(map(float, values[1:3])))
|
| 140 |
+
elif values[0] == 'f':
|
| 141 |
+
if not triangulate or len(values) == 4:
|
| 142 |
+
face = []
|
| 143 |
+
texcoords = []
|
| 144 |
+
norms = []
|
| 145 |
+
for v in values[1:]:
|
| 146 |
+
w = v.split('/')
|
| 147 |
+
face.append(int(w[0]) - 1)
|
| 148 |
+
if len(w) >= 2 and len(w[1]) > 0:
|
| 149 |
+
if '//' not in v:
|
| 150 |
+
texcoords.append(int(w[1]) - 1)
|
| 151 |
+
else:
|
| 152 |
+
norms.append(int(w[1]) - 1)
|
| 153 |
+
if len(w) >= 3 and len(w[2]) > 0:
|
| 154 |
+
norms.append(int(w[2]) - 1)
|
| 155 |
+
self.faces.append(face)
|
| 156 |
+
self.face_norms.append(norms)
|
| 157 |
+
self.face_texs.append(texcoords)
|
| 158 |
+
else:
|
| 159 |
+
|
| 160 |
+
face = []
|
| 161 |
+
texcoords = []
|
| 162 |
+
norms = []
|
| 163 |
+
for v in values[1:4]:
|
| 164 |
+
w = v.split('/')
|
| 165 |
+
face.append(int(w[0]) - 1)
|
| 166 |
+
if len(w) >= 2 and len(w[1]) > 0:
|
| 167 |
+
if '//' not in v:
|
| 168 |
+
texcoords.append(int(w[1]) - 1)
|
| 169 |
+
else:
|
| 170 |
+
norms.append(int(w[1]) - 1)
|
| 171 |
+
if len(w) >= 3 and len(w[2]) > 0:
|
| 172 |
+
norms.append(int(w[2]) - 1)
|
| 173 |
+
self.faces.append(face)
|
| 174 |
+
self.face_norms.append(norms)
|
| 175 |
+
self.face_texs.append(texcoords)
|
| 176 |
+
|
| 177 |
+
face = []
|
| 178 |
+
texcoords = []
|
| 179 |
+
norms = []
|
| 180 |
+
for v in [values[1], values[3], values[4]]:
|
| 181 |
+
w = v.split('/')
|
| 182 |
+
face.append(int(w[0]) - 1)
|
| 183 |
+
if len(w) >= 2 and len(w[1]) > 0:
|
| 184 |
+
if '//' not in v:
|
| 185 |
+
texcoords.append(int(w[1]) - 1)
|
| 186 |
+
else:
|
| 187 |
+
norms.append(int(w[1]) - 1)
|
| 188 |
+
if len(w) >= 3 and len(w[2]) > 0:
|
| 189 |
+
norms.append(int(w[2]) - 1)
|
| 190 |
+
self.faces.append(face)
|
| 191 |
+
self.face_norms.append(norms)
|
| 192 |
+
self.face_texs.append(texcoords)
|
| 193 |
+
|
| 194 |
+
self.finish_object()
|
| 195 |
+
|
| 196 |
+
def finish_object(self):
|
| 197 |
+
self.vertices = np.array(self.vertices)
|
| 198 |
+
self.normals = np.array(self.normals)
|
| 199 |
+
self.texcoords = np.array(self.texcoords)
|
| 200 |
+
self.faces = np.array(self.faces)
|
| 201 |
+
self.face_norms = np.array(self.face_norms)
|
| 202 |
+
self.face_texs = np.array(self.face_texs)
|
| 203 |
+
if self._current_object is None:
|
| 204 |
+
return
|
| 205 |
+
|
| 206 |
+
mesh = MeshData()
|
| 207 |
+
idx = 0
|
| 208 |
+
material = self.mtl.get(self.obj_material)
|
| 209 |
+
if material:
|
| 210 |
+
mesh.set_materials(material)
|
| 211 |
+
for verts, norms, tcs in zip(self.faces, self.face_norms, self.face_texs):
|
| 212 |
+
# verts = f[0]
|
| 213 |
+
# norms = f[1]
|
| 214 |
+
# tcs = f[2]
|
| 215 |
+
for i in range(3):
|
| 216 |
+
# get normal components
|
| 217 |
+
n = np.array([0.0, 0.0, 0.0])
|
| 218 |
+
if norms is not None:
|
| 219 |
+
n = self.normals[norms[i] - 1]
|
| 220 |
+
|
| 221 |
+
# get texture coordinate components
|
| 222 |
+
t = np.array([0.0, 0.0])
|
| 223 |
+
if tcs is not None:
|
| 224 |
+
t = self.texcoords[tcs[i] - 1]
|
| 225 |
+
|
| 226 |
+
# get vertex components
|
| 227 |
+
v = self.vertices[verts[i] - 1]
|
| 228 |
+
|
| 229 |
+
data = [v[0], v[1], v[2], n[0], n[1], n[2], t[0], t[1]]
|
| 230 |
+
mesh.vertices.extend(data)
|
| 231 |
+
|
| 232 |
+
# add material info in the vertice
|
| 233 |
+
mesh.vertices.extend(
|
| 234 |
+
mesh.ambient_color +
|
| 235 |
+
mesh.diffuse_color +
|
| 236 |
+
mesh.specular_color
|
| 237 |
+
)
|
| 238 |
+
|
| 239 |
+
tri = [idx, idx + 1, idx + 2]
|
| 240 |
+
mesh.indices.extend(tri)
|
| 241 |
+
idx += 3
|
| 242 |
+
|
| 243 |
+
mesh.vertices = np.array(mesh.vertices)
|
| 244 |
+
mesh.indices = np.array(mesh.indices)
|
| 245 |
+
|
| 246 |
+
self.objects[self._current_object] = mesh
|
| 247 |
+
# mesh.calculate_normals()
|
| 248 |
+
self.faces = []
|
| 249 |
+
|
| 250 |
+
def write(self, filename, swapyz=False):
|
| 251 |
+
# NOTE: NO CONSIDERATION FOR DELIMITER NOW
|
| 252 |
+
with open(filename, 'w') as f:
|
| 253 |
+
if self.mtl is not None:
|
| 254 |
+
f.write(f"mtllib {self.mtl.filename}\n")
|
| 255 |
+
for v in self.vertices:
|
| 256 |
+
if swapyz:
|
| 257 |
+
v = v[0], v[2], v[1]
|
| 258 |
+
f.write(f"v {v[0]:.6f} {v[1]:.6f} {v[2]:.6f}\n")
|
| 259 |
+
|
| 260 |
+
if self.texcoords.size != 0:
|
| 261 |
+
for vt in self.texcoords:
|
| 262 |
+
f.write(f"vt {vt[0]:.6f} {vt[1]:.6f}\n")
|
| 263 |
+
if self.normals.size != 0:
|
| 264 |
+
for vn in self.normals:
|
| 265 |
+
if swapyz:
|
| 266 |
+
vn = vn[0], vn[2], vn[1]
|
| 267 |
+
f.write(f"vn {vn[0]:.6f} {vn[1]:.6f} {vn[2]:.6f}\n")
|
| 268 |
+
if self.obj_material is not None:
|
| 269 |
+
f.write(f"usemtl {self.obj_material}\n")
|
| 270 |
+
for verts, norms, tcs in zip(self.faces, self.face_norms, self.face_texs):
|
| 271 |
+
f.write("f ")
|
| 272 |
+
for i in range(verts.shape[0]):
|
| 273 |
+
f.write(f"{verts[i] + 1}")
|
| 274 |
+
|
| 275 |
+
if tcs.size != 0:
|
| 276 |
+
f.write(f"/{tcs[i] + 1}")
|
| 277 |
+
elif norms.size != 0:
|
| 278 |
+
f.write("/")
|
| 279 |
+
if norms.size != 0:
|
| 280 |
+
f.write(f"/{norms[i] + 1}")
|
| 281 |
+
|
| 282 |
+
if i != verts.shape[0] - 1:
|
| 283 |
+
f.write(" ")
|
| 284 |
+
f.write("\n")
|
scripts/blendshape_ict.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ba480e86edf38515942b4ece28e9d834b6dc15871e4a8f5180d91935609fe810
|
| 3 |
+
size 9281048
|
scripts/body_to_render.blend
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4bad6154d30cd059ba5effb4d92cf544128bb1fad94c8dbb240f6da1f5be505a
|
| 3 |
+
size 1524579665
|
scripts/example_body_render_job.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
20231119_051
|
| 2 |
+
20231126_319
|
scripts/example_face_render_job.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
20231119_001_051
|
| 2 |
+
20231126_003_319
|
scripts/face_ict_to_arkit.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This script converts the .npy which currently contains 55 blendshapes
|
| 2 |
+
# to ARKit space which has 51 blendshapes. It removes the 10 and 11th index
|
| 3 |
+
# and merges the 2nd and 3rd index together, and 6th and 7th index together.
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import numpy as np
|
| 7 |
+
import argparse
|
| 8 |
+
|
| 9 |
+
if __name__ == '__main__':
|
| 10 |
+
|
| 11 |
+
parser = argparse.ArgumentParser()
|
| 12 |
+
parser.add_argument('--input', '-i', type=str, default=os.path.join('..', 'face_ict'), help='Path to arkit npy file or folder')
|
| 13 |
+
parser.add_argument('--output', '-o', type=str, default=os.path.join('..', 'face_arkit_copy'), help='Folder path to store output npy sequence file')
|
| 14 |
+
args = parser.parse_args()
|
| 15 |
+
|
| 16 |
+
os.makedirs(args.output, exist_ok=True)
|
| 17 |
+
|
| 18 |
+
input_files = []
|
| 19 |
+
if os.path.isdir(args.input):
|
| 20 |
+
input_files = [os.path.join(args.input, f) for f in sorted(os.listdir(args.input)) if f.endswith('.npy')]
|
| 21 |
+
else:
|
| 22 |
+
input_files = [args.input]
|
| 23 |
+
|
| 24 |
+
for file_path in input_files:
|
| 25 |
+
vert_seq = np.load(file_path) # (N, 55)
|
| 26 |
+
part_1 = vert_seq[:, :2] # (N, 2)
|
| 27 |
+
merge_1 = vert_seq[:, 2:4].mean(axis=1).reshape(-1, 1) # (N, 1)
|
| 28 |
+
part_2 = vert_seq[:, 4:6] # (N, 2)
|
| 29 |
+
merge_2 = vert_seq[:, 6:8].mean(axis=1).reshape(-1, 1) # (N, 1)
|
| 30 |
+
part_3 = vert_seq[:, 8:10] # (N, 2)
|
| 31 |
+
part_4 = vert_seq[:, 12:] # (N, 43)
|
| 32 |
+
new_vert_seq = np.concatenate([part_1, merge_1, part_2, merge_2, part_3, part_4], axis=1) # (N, 51)
|
| 33 |
+
output_path = os.path.join(args.output, os.path.basename(file_path))
|
| 34 |
+
np.save(output_path, new_vert_seq)
|
| 35 |
+
print("Saving to", output_path)
|
scripts/face_ict_to_render.blend
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2bddb3a6e5ac6c11e03f27442ed03533ffd7b5300492086c85d62587c0a2e603
|
| 3 |
+
size 2327017712
|
scripts/face_ict_to_vertices.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import numpy as np
|
| 3 |
+
import argparse
|
| 4 |
+
from scripts._obj import ObjHandle
|
| 5 |
+
from multiprocessing import Pool, cpu_count
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def process_file(args_tuple):
|
| 9 |
+
"""Process a single input file."""
|
| 10 |
+
input_file, bs, vert_neutrals, output_dir = args_tuple
|
| 11 |
+
|
| 12 |
+
arkit_seq = np.load(input_file)
|
| 13 |
+
print(f"Processing: {input_file}")
|
| 14 |
+
|
| 15 |
+
template_key = os.path.basename(input_file).split('_')[1]
|
| 16 |
+
|
| 17 |
+
vert_seq = []
|
| 18 |
+
|
| 19 |
+
for frame_arkit in arkit_seq:
|
| 20 |
+
vert_offset = bs.T @ frame_arkit
|
| 21 |
+
vert_seq.append(vert_offset)
|
| 22 |
+
|
| 23 |
+
vert_seq = np.stack(vert_seq, axis=0)
|
| 24 |
+
vert_neutral = vert_neutrals.get(template_key, vert_neutrals.get('default', next(iter(vert_neutrals.values()))))
|
| 25 |
+
vert_seq = vert_seq + vert_neutral
|
| 26 |
+
|
| 27 |
+
print(f"Output: {vert_seq.shape}")
|
| 28 |
+
|
| 29 |
+
output_file = os.path.join(output_dir, os.path.basename(input_file))
|
| 30 |
+
np.save(output_file, vert_seq)
|
| 31 |
+
|
| 32 |
+
return output_file
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
if __name__ == '__main__':
|
| 36 |
+
|
| 37 |
+
parser = argparse.ArgumentParser()
|
| 38 |
+
parser.add_argument('--input', '-i', type=str, default=os.path.join('..', 'face_ict'), help='Path to arkit npy file or folder')
|
| 39 |
+
parser.add_argument('--templates', '-t', type=str, default=os.path.join('..', 'face_ict_templates'), help='Path to template obj file or folder')
|
| 40 |
+
parser.add_argument('--output', '-o', type=str, default=os.path.join('..', 'face_vertices'), help='Folder path to store output npy sequence file')
|
| 41 |
+
parser.add_argument('--bs', '-p', type=str, default='blendshape_ict.npy', help='Path to PCA model')
|
| 42 |
+
parser.add_argument('--workers', '-w', type=int, default=cpu_count(), help='Number of parallel workers')
|
| 43 |
+
args = parser.parse_args()
|
| 44 |
+
|
| 45 |
+
os.makedirs(args.output, exist_ok=True)
|
| 46 |
+
bs = np.load(args.bs)
|
| 47 |
+
|
| 48 |
+
vert_neutrals = {}
|
| 49 |
+
if os.path.isdir(args.templates):
|
| 50 |
+
for f in sorted(os.listdir(args.templates)):
|
| 51 |
+
if f.endswith('.obj'):
|
| 52 |
+
template_path = os.path.join(args.templates, f)
|
| 53 |
+
obj = ObjHandle(template_path, triangulate=True)
|
| 54 |
+
vert_neutrals[f[:-4]] = obj.vertices.reshape(-1)[None]
|
| 55 |
+
else:
|
| 56 |
+
obj = ObjHandle(args.templates, triangulate=True)
|
| 57 |
+
vert_neutrals['default'] = obj.vertices.reshape(-1)[None]
|
| 58 |
+
|
| 59 |
+
if os.path.isdir(args.input):
|
| 60 |
+
input_files = [os.path.join(args.input, f) for f in sorted(os.listdir(args.input)) if f.endswith('.npy')]
|
| 61 |
+
else:
|
| 62 |
+
input_files = [args.input]
|
| 63 |
+
|
| 64 |
+
print(f"Processing {len(input_files)} files using {args.workers} workers...")
|
| 65 |
+
|
| 66 |
+
# Prepare arguments for each file
|
| 67 |
+
process_args = [(input_file, bs, vert_neutrals, args.output) for input_file in input_files]
|
| 68 |
+
|
| 69 |
+
# Process files in parallel
|
| 70 |
+
with Pool(args.workers) as pool:
|
| 71 |
+
results = pool.map(process_file, process_args)
|
| 72 |
+
|
| 73 |
+
print(f"Done! Processed {len(results)} files.")
|
scripts/render_add_audio.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import argparse
|
| 3 |
+
import re
|
| 4 |
+
import tempfile
|
| 5 |
+
|
| 6 |
+
FRAME_RATE = 30
|
| 7 |
+
|
| 8 |
+
def natural_sort_key(s):
|
| 9 |
+
"""Key function for natural sorting (handles numbers in strings correctly)."""
|
| 10 |
+
return [int(text) if text.isdigit() else text.lower()
|
| 11 |
+
for text in re.split(r'(\d+)', s)]
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def add_audio_to_face_renders(input_path, wav_path, output_path):
|
| 15 |
+
is_meta_render_dir = all(os.path.isdir(os.path.join(input_path, f)) for f in os.listdir(input_path))
|
| 16 |
+
if is_meta_render_dir:
|
| 17 |
+
input_dirs = [os.path.join(input_path, f) for f in sorted(os.listdir(input_path))]
|
| 18 |
+
else:
|
| 19 |
+
input_dirs = [input_path]
|
| 20 |
+
|
| 21 |
+
for dir_path in input_dirs:
|
| 22 |
+
audio_file_path = os.path.join(wav_path, os.path.basename(dir_path) + '.wav')
|
| 23 |
+
output_file_path = os.path.join(output_path, os.path.basename(dir_path) + '.mp4')
|
| 24 |
+
|
| 25 |
+
# Find and sort PNG files
|
| 26 |
+
png_files = [f for f in os.listdir(dir_path) if f.lower().endswith('.png')]
|
| 27 |
+
if not png_files:
|
| 28 |
+
print(f"No PNG files found in {dir_path}. Skipping.")
|
| 29 |
+
continue
|
| 30 |
+
png_files.sort(key=natural_sort_key)
|
| 31 |
+
|
| 32 |
+
# Create temporary file list for ffmpeg concat demuxer
|
| 33 |
+
list_file_content = ""
|
| 34 |
+
for png_file in png_files:
|
| 35 |
+
abs_path = os.path.abspath(os.path.join(dir_path, png_file)).replace('\\', '/')
|
| 36 |
+
list_file_content += f"file '{abs_path}'\n"
|
| 37 |
+
list_file_content += f"duration {1/FRAME_RATE}\n"
|
| 38 |
+
|
| 39 |
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False, encoding='utf-8') as tf:
|
| 40 |
+
tf.write(list_file_content)
|
| 41 |
+
temp_list_file = tf.name
|
| 42 |
+
|
| 43 |
+
temp_list_file_escaped = temp_list_file.replace('\\', '/')
|
| 44 |
+
|
| 45 |
+
print(f"Processing: {dir_path}")
|
| 46 |
+
os.system(f'ffmpeg -f concat -safe 0 -i "{temp_list_file_escaped}" '
|
| 47 |
+
f'-i "{audio_file_path}" '
|
| 48 |
+
f'-c:v libx264 -pix_fmt yuv420p -r {FRAME_RATE} '
|
| 49 |
+
f'-c:a aac -shortest '
|
| 50 |
+
f'-y "{output_file_path}"')
|
| 51 |
+
|
| 52 |
+
os.remove(temp_list_file)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def find_audio_files(wav_path, date, scenario):
|
| 56 |
+
audio_files = []
|
| 57 |
+
for file in os.listdir(os.path.join(wav_path)):
|
| 58 |
+
if not file.endswith('.wav'):
|
| 59 |
+
continue
|
| 60 |
+
parts = file.split('_')
|
| 61 |
+
if parts[0] == date and parts[2].split('.')[0] == scenario:
|
| 62 |
+
audio_files.append(os.path.join(wav_path, file))
|
| 63 |
+
assert len(audio_files) == 2
|
| 64 |
+
return audio_files
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def add_audio_to_body_renders(input_path, wav_path, output_path):
|
| 68 |
+
input_files = []
|
| 69 |
+
if os.path.isdir(input_path):
|
| 70 |
+
input_files = [os.path.join(input_path, f) for f in sorted(os.listdir(input_path)) if f.endswith('.mkv')]
|
| 71 |
+
else:
|
| 72 |
+
input_files = [input_path]
|
| 73 |
+
|
| 74 |
+
for file_path in input_files:
|
| 75 |
+
filename = os.path.basename(file_path)
|
| 76 |
+
date, scenario = filename.split('.')[0].split('_')
|
| 77 |
+
audio_file_paths = find_audio_files(wav_path, date, scenario)
|
| 78 |
+
output_file_path = os.path.join(output_path, filename.replace('.mkv', '.mp4'))
|
| 79 |
+
|
| 80 |
+
print('Processing:', file_path)
|
| 81 |
+
os.system(f"ffmpeg -i {file_path} \
|
| 82 |
+
-i {audio_file_paths[0]} \
|
| 83 |
+
-i {audio_file_paths[1]} \
|
| 84 |
+
-filter_complex \"[1:a][2:a]amix=inputs=2:duration=longest[aout]\" \
|
| 85 |
+
-map 0:v \
|
| 86 |
+
-map \"[aout]\" \
|
| 87 |
+
-c:v copy \
|
| 88 |
+
-c:a aac \
|
| 89 |
+
{output_file_path}")
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
if __name__ == '__main__':
|
| 93 |
+
|
| 94 |
+
parser = argparse.ArgumentParser()
|
| 95 |
+
parser.add_argument('--input_type', '-it', type=str, default='face', help='Type of input to process: face or body')
|
| 96 |
+
parser.add_argument('--input_face', '-if', type=str, default=os.path.join('..', 'face_renders_noaudio'), help='Path to single-instance face render folder or multi-instance folder without audio')
|
| 97 |
+
parser.add_argument('--output_face', '-of', type=str, default=os.path.join('..', 'face_renders_withaudio'), help='Folder path to store output face render folder with audio')
|
| 98 |
+
parser.add_argument('--input_body', '-ib', type=str, default=os.path.join('..', 'body_renders_noaudio'), help='Path to single-instance body render folder or multi-instance folder without audio')
|
| 99 |
+
parser.add_argument('--output_body', '-ob', type=str, default=os.path.join('..', 'body_renders_withaudio'), help='Folder path to store output body render folder with audio')
|
| 100 |
+
parser.add_argument('--wav_path', '-w', type=str, default=os.path.join('..', 'wav'), help='Path to folder containing wav files')
|
| 101 |
+
args = parser.parse_args()
|
| 102 |
+
|
| 103 |
+
if args.input_type == 'face':
|
| 104 |
+
os.makedirs(args.output_face, exist_ok=True)
|
| 105 |
+
add_audio_to_face_renders(args.input_face, args.wav_path, args.output_face)
|
| 106 |
+
elif args.input_type == 'body':
|
| 107 |
+
os.makedirs(args.output_body, exist_ok=True)
|
| 108 |
+
add_audio_to_body_renders(args.input_body, args.wav_path, args.output_body)
|
| 109 |
+
else:
|
| 110 |
+
raise ValueError("Invalid input type. Choose 'face' or 'body'.")
|