|
1 | 1 | import argparse |
2 | 2 | import json |
3 | 3 | import os |
4 | | -from urllib import request |
5 | | -from loguru import logger |
6 | | - |
7 | 4 | import numpy as np |
8 | 5 | import trimesh |
9 | | -from scipy.spatial.transform import Rotation |
| 6 | +import tempfile |
| 7 | +import zipfile |
| 8 | +from urllib import request |
| 9 | +from loguru import logger |
10 | 10 | from videoio import VideoWriter |
11 | 11 |
|
12 | 12 | from blendify import scene |
@@ -132,25 +132,27 @@ def main(args): |
132 | 132 | arguments = parser.parse_args() |
133 | 133 |
|
134 | 134 |
|
135 | | - def download(fileurl, filename): |
| 135 | + def download_zipped(file_url, target_dir): |
136 | 136 | progress_report = lambda block_num, block_size, total_size: print( |
137 | | - f"Downloading {filename}: {block_num * block_size / 2 ** 20:.2f}/{total_size / 2 ** 20:.2f}MB", end="\r") |
138 | | - if not os.path.isfile(filename) or request.urlopen(fileurl).length != os.stat(filename).st_size: |
139 | | - request.urlretrieve(fileurl, filename, progress_report) |
140 | | - print() |
| 137 | + f"Downloading data: {block_num * block_size / 2 ** 20:.2f}/{total_size / 2 ** 20:.2f}MB", end="\r") |
| 138 | + if not os.path.isdir(target_dir): |
| 139 | + with tempfile.TemporaryDirectory() as tmpdirname: |
| 140 | + # Download the zipped file to a temporary directory |
| 141 | + request.urlretrieve(file_url, os.path.join(tmpdirname, "data.zip"), progress_report) |
| 142 | + print() |
| 143 | + os.makedirs(target_dir) |
| 144 | + # Unzip the file to the target directory |
| 145 | + logger.info("Extracting the data") |
| 146 | + with zipfile.ZipFile(os.path.join(tmpdirname, "data.zip"), 'r') as zip_ref: |
| 147 | + zip_ref.extractall(target_dir) |
| 148 | + else: |
| 149 | + logger.info(f"Assets folder {target_dir} exist, skipping download.") |
141 | 150 |
|
142 | 151 |
|
143 | 152 | # Downloading assets if needed |
144 | 153 | if not arguments.skip_download: |
145 | | - os.makedirs("assets/05_smpl_movement", exist_ok=True) |
146 | | - # The scene mesh was generated from HPS dataset (Etage6 pointcloud) using blendify.utils.pointcloud.meshify_pc_from_file |
147 | | - download("https://nextcloud.mpi-klsb.mpg.de/index.php/s/AESiBaXXyagNmrE/download", |
148 | | - "assets/05_smpl_movement/scene_texture.jpg") |
149 | | - download("https://nextcloud.mpi-klsb.mpg.de/index.php/s/QCjTsJqSSrNb5nJ/download", |
150 | | - "assets/05_smpl_movement/scene_mesh.ply") |
151 | | - download("https://nextcloud.mpi-klsb.mpg.de/index.php/s/dNtecaSTPkYoKey/download", |
152 | | - "assets/05_smpl_movement/scene_face_uvmap.npy") |
153 | | - download("https://nextcloud.mpi-klsb.mpg.de/index.php/s/a2SYDcoPc5FoCwe/download", |
154 | | - "assets/05_smpl_movement/animation_data.json") |
| 154 | + # The scene mesh was generated from HPS dataset (MPI_Etage6 pointcloud) using blendify.utils.pointcloud.meshify_pc_from_file |
| 155 | + download_zipped("https://github.com/ptrvilya/blendify/releases/download/v2.0.1/05_smpl_movement_assets.zip", |
| 156 | + "assets/05_smpl_movement") |
155 | 157 |
|
156 | 158 | main(arguments) |
0 commit comments