From 5aa2fa44976ea9e7cc553a61ca95934c745e730b Mon Sep 17 00:00:00 2001 From: bnewbold Date: Fri, 10 Jun 2016 02:00:06 -0400 Subject: move model_c2rs.py to original/ --- original/model_c2rs.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 original/model_c2rs.py (limited to 'original') diff --git a/original/model_c2rs.py b/original/model_c2rs.py new file mode 100755 index 0000000..9d6c63b --- /dev/null +++ b/original/model_c2rs.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +""" +This script is intended to be run in the same directory as a bunch of .c files; +it outputs .rs files. +""" + +import sys + +def main(): + if len(sys.argv) != 2 or not sys.argv[1].endswith(".c"): + print("I take a single file to convert; must be a .c file") + sys.exit(-1) + + fname = sys.argv[1][:-2] + infile = open(fname + ".c", 'r') + outfile = open(fname + ".rs", 'w') + + vertices = [] + normals = [] + for line in infile.readlines(): + if line.count(",") != 6: + continue + nums = line.strip().split(",")[:-1] + nums = [n.find(".") != -1 and n or n+".0" for n in nums] + #print(nums) + assert(len(nums) == 6) + normals.append(nums[:3]) + vertices.append(nums[3:]) + infile.close() + + outfile.write(""" +// This file auto-generated from %s.c using model_c2rs.py +// Don't edit by hand! + +use cow_vertex::Vertex; + +pub const %s_VERTICES: [Vertex; %d] = [ +""" % (fname, fname.upper(), len(vertices))) + for i in range(len(vertices)): + v = vertices[i] + n = normals [i] + outfile.write(" Vertex { position: (%s, %s, %s),\n" % (v[0], v[1], v[2])); + outfile.write(" normal: (%s, %s, %s), },\n" % (n[0], n[1], n[2])); + + outfile.write( "];\n") + outfile.close() + print("Done!") + +if __name__ == "__main__": + main() -- cgit v1.2.3