diff options
author | bnewbold <bnewbold@robocracy.org> | 2016-05-06 15:05:31 -0400 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2016-05-06 15:05:43 -0400 |
commit | e9904217c4bb4e75ef7f4eb78b4795e7d569dbc3 (patch) | |
tree | 80af430057734cd086097d792edaf25a8e20c70f /model_c2rs.py | |
parent | 88608ff1d844d36b824e33aaa90cf25f1e028b1b (diff) | |
download | exuberant-hacks-e9904217c4bb4e75ef7f4eb78b4795e7d569dbc3.tar.gz exuberant-hacks-e9904217c4bb4e75ef7f4eb78b4795e7d569dbc3.zip |
start work
Diffstat (limited to 'model_c2rs.py')
-rwxr-xr-x | model_c2rs.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/model_c2rs.py b/model_c2rs.py new file mode 100755 index 0000000..ee2e0df --- /dev/null +++ b/model_c2rs.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +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] + #print(nums) + assert(len(nums) == 6) + vertices.append(nums[:3]) + normals.append(nums[3:]) + infile.close() + + outfile.write(""" +// This file auto-generated from %s.c using model_c2rs.py +// Don't edit by hand! + +#[derive(Copy, Clone)] +pub struct Vertex { + position: (f32, f32, f32), + normal: (f32, f32, f32), +} +implement_vertex!(Vertex, position, normal); + +pub const %s_vertices: [Vertex; %d] = [ +""" % (fname, fname, 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() |