From 4d3d2fb44dc24621a12d9da5bd1dca74e4ff99b7 Mon Sep 17 00:00:00 2001 From: s3lph Date: Mon, 23 Dec 2024 17:46:53 +0100 Subject: [PATCH] feat: load shapes from ply files --- .gitignore | 3 +++ map.py | 11 +++++++---- requirements.txt | 3 +++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..541b9a0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +venv +*.pyc +__pycache__ diff --git a/map.py b/map.py index 094b42b..aec330a 100644 --- a/map.py +++ b/map.py @@ -6,6 +6,7 @@ import os import sys import numpy as np +from plyfile import PlyData from tqdm import tqdm, trange @@ -114,9 +115,11 @@ def map_poly(tri, poly, ref=None): def main(ns): - with open(ns.faces, 'r') as f: - j = json.load(f) - faces = [Face([np.array(v)*ns.scale for v in vs]) for vs in j] + with open(ns.faces, 'rb') as f: + plydata = PlyData.read(f) + vs = plydata['vertex'] + fs = plydata['face']['vertex_indices'] + faces = [Face([np.array(vs[vi].tolist())*ns.scale for vi in fvs]) for fvs in fs] with open(ns.geojson, 'r') as f: geojson = json.load(f) @@ -161,6 +164,6 @@ if __name__ == '__main__': ap.add_argument('--geojson', '-g', default='countries.geojson') ap.add_argument('--faces', '-f', default='shapes/cube.json') ap.add_argument('--out', '-o', default='faces/{faces}/face{face}.svg') - ap.add_argument('--scale', '-s', type=int, default=1) + ap.add_argument('--scale', '-s', type=float, default=1) ns = ap.parse_args() main(ns) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..76a585a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +numpy==2.2.0 +plyfile==1.1 +tqdm==4.67.1