Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Make a file. This file should contain the name of your models and operations you wish to perform. Put it into ARGV[1]
- # f1+f2 - merge two files, new filename f1f2
- # f1*r - Make a series of x degree rotations, default advtrains-compatible, again and again until passed 359 degrees. Define using ARGV[2]
- # f1*x - Rotate by x degrees
- # =f3 - Set the resulting filename to f3
- rotationAmount = 22.5 # In degrees
- import sys
- if 4 <= len(sys.argv):
- rotationAmount = sys.argv[2]
- # AST generation
- operators = {
- "merge":"+",
- "rotateDegrees":"*",
- "rotateFull":"*r",
- }
- with open(sys.argv[1]) as op:
- operations = op.read()
- operations = operations.split("\n")
- for i in range(len(operations)):
- for o in operators:
- operations[i] = operations[i].replace(operators[o], ".splithere." + o + ".splithere.")
- operations[i] = operations[i].split(".splithere.")
- # AST Parsing
- def rotate(degree, filename):
- import bpy
- import shutil
- blender_bin = shutil.which("blender")
- if blender_bin:
- print("Found:", blender_bin)
- bpy.app.binary_path = blender_bin
- else:
- print("Unable to find blender!")
- expandedFilename = filename + ".obj"
- bpy.ops.wm.read_factory_settings(use_empty=True)
- bpy.ops.import_scene.obj(filename = expandedFilename)
- bpy.ops.transform.rotate(value = degree)
- bpy.ops.export_scene.obj(filename = expandedFilename + str(degree))
- def recurseRotate(filename):
- for i in range(int(360/rotateAmount)):
- rotate(rotateAmount*i, filename)
- def merge(file1, file2):
- with open(file1 + ".obj", "r") as f1:
- file1Contents = f1.read()
- with open(file2 + ".obj", "r") as f2:
- file2Contents = f2.read()
- with open(file1+file2 + ".obj", "w") as f3:
- file3Contents = file1Contents + "\n" + file2Contents
- f3.write(file3Contents)
- for i in range(len(operations)):
- ops = operations[i]
- try:
- if ops[1] == "merge":
- merge(ops[0], ops[2])
- elif ops[1] == "rotateDegrees":
- rotate(ops[2], ops[1])
- elif ops[1] == "rotateFull":
- recurseRotate(ops[0])
- except:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement