feat: load shapes from ply files

This commit is contained in:
s3lph 2024-12-23 17:46:53 +01:00
parent 016e5a2949
commit 4d3d2fb44d
Signed by: s3lph
GPG key ID: 0AA29A52FB33CFB5
3 changed files with 13 additions and 4 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
venv
*.pyc
__pycache__

11
map.py
View file

@ -6,6 +6,7 @@ import os
import sys import sys
import numpy as np import numpy as np
from plyfile import PlyData
from tqdm import tqdm, trange from tqdm import tqdm, trange
@ -114,9 +115,11 @@ def map_poly(tri, poly, ref=None):
def main(ns): def main(ns):
with open(ns.faces, 'r') as f: with open(ns.faces, 'rb') as f:
j = json.load(f) plydata = PlyData.read(f)
faces = [Face([np.array(v)*ns.scale for v in vs]) for vs in j] 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: with open(ns.geojson, 'r') as f:
geojson = json.load(f) geojson = json.load(f)
@ -161,6 +164,6 @@ if __name__ == '__main__':
ap.add_argument('--geojson', '-g', default='countries.geojson') ap.add_argument('--geojson', '-g', default='countries.geojson')
ap.add_argument('--faces', '-f', default='shapes/cube.json') ap.add_argument('--faces', '-f', default='shapes/cube.json')
ap.add_argument('--out', '-o', default='faces/{faces}/face{face}.svg') 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() ns = ap.parse_args()
main(ns) main(ns)

3
requirements.txt Normal file
View file

@ -0,0 +1,3 @@
numpy==2.2.0
plyfile==1.1
tqdm==4.67.1