pytim/wavefront_obj.py
# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding: utf-8 -*-
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
from __future__ import print_function
from . import utilities
def consecutive_filename(universe, basename):
if basename.endswith('.obj'):
basename = basename[:-4]
return utilities.consecutive_filename(universe, basename, 'obj')
def write_file(filename, vertices, faces):
"""write a triangulation on a wavefront obj file
:param file f: the file
:param array vertices: triangulation vertices
:param array(dtype=int) faces: indices (starting from 1) to the vertices
"""
with open(filename, 'w') as f:
f.write("# generated by pytim\n")
for v in vertices:
f.write("v {:f} {:f} {:f}\n".format(v[2], v[1], v[0]))
for face in faces:
f.write("f {:d} {:d} {:d}\n".format(face[0] + 1, face[1] + 1,
face[2] + 1))