Skip to content

Commit

Permalink
Add json to obj conversion script
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Oom committed Aug 3, 2024
1 parent 626a4ec commit 1a8ff20
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pybits/json_to_obj.py
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()

0 comments on commit 1a8ff20

Please sign in to comment.