aboutsummaryrefslogtreecommitdiffstats
path: root/original
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-06-10 02:00:06 -0400
committerbnewbold <bnewbold@robocracy.org>2016-06-10 02:00:06 -0400
commit5aa2fa44976ea9e7cc553a61ca95934c745e730b (patch)
tree8227d33a1262173a8a971a295d5030e5340b38c2 /original
parentb793755808abedd2b9f1a11ff8e7f22df9ad8180 (diff)
downloadexuberant-hacks-5aa2fa44976ea9e7cc553a61ca95934c745e730b.tar.gz
exuberant-hacks-5aa2fa44976ea9e7cc553a61ca95934c745e730b.zip
move model_c2rs.py to original/
Diffstat (limited to 'original')
-rwxr-xr-xoriginal/model_c2rs.py51
1 files changed, 51 insertions, 0 deletions
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()