-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Oom
committed
Aug 3, 2024
1 parent
626a4ec
commit 1a8ff20
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import json | ||
import numpy as np | ||
import sys | ||
|
||
|
||
def read(path): | ||
with open(path) as f: | ||
return np.array(json.load(f)["triangles"]) | ||
|
||
|
||
def program(args): | ||
triangles = read(args.path) | ||
vertices = triangles.reshape(len(triangles) * 3, 3) | ||
print('usemtl todo') | ||
for vertex in vertices: | ||
print(f'v {vertex[0]} {vertex[1]} {vertex[2]}') | ||
for index in range(1, len(vertices), 3): | ||
print(f'f {index}// {index + 1}// {index + 2}//') | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description="Convert JSON to OBJ", | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter, | ||
) | ||
parser.add_argument("path") | ||
args = parser.parse_args() | ||
sys.exit(program(args)) | ||
|
||
|
||
main() |