123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import bpy
- import sys
- import mathutils
-
- argv = sys.argv
- argv = argv[argv.index("--") + 1:]
-
- width = int(argv[0])
- height = int(argv[1])
- imgpath = argv[2]
- renderPath = argv[3]
-
- def selectObject(name):
- ob = bpy.context.scene.objects[name]
- bpy.ops.object.select_all(action='DESELECT')
- bpy.context.view_layer.objects.active = ob
- ob.select_set(True)
-
- def moveObject(name,x,y,z):
- selectObject(name)
- bpy.context.object.location = x, y, z
-
- def scaleObject(name,x,y,z):
- selectObject(name)
- bpy.context.object.dimensions = x, y, z
-
- def moveCamLocal(z):
- cam = bpy.data.objects["Camera"]
- vec = mathutils.Vector((0.0, 0.0, z))
- inv = cam.matrix_world.copy()
- inv.invert()
- vec_rot = vec @ inv
- cam.location = cam.location + vec_rot
-
-
- img = bpy.data.images.load(filepath = imgpath)
- selectObject("Canvas")
- bpy.context.object.material_slots[0].material.node_tree.nodes["Image Texture"].image = img
-
- diff = max(width,height) - 80
- moveCamLocal(diff/55)
-
- moveObject("BarTop",0,0,height/100/2)
- moveObject("BarBottom",0,0,-height/100/2)
- moveObject("BarLeft",-width/100/2,0,0)
- moveObject("BarRight",width/100/2,0,0)
-
- scaleObject("BarTop",width/100-0.06,0.026024,0.02)
- scaleObject("BarBottom",width/100-0.06,0.026024,0.02)
- scaleObject("BarLeft",height/100-0.06,0.026024,0.02)
- scaleObject("BarRight",height/100-0.06,0.026024,0.02)
-
- moveObject("CornerTopRight", width/100/2,0,height/100/2)
- moveObject("CornerTopLeft", -width/100/2,0,height/100/2)
- moveObject("CornerBottomRight", width/100/2,0,-height/100/2)
- moveObject("CornerBottomLeft", -width/100/2,0,-height/100/2)
-
- scaleObject("Glass", width/100,0.002037,height/100)
- scaleObject("Canvas",width/100,0.0025,height/100)
-
-
- bpy.context.scene.render.filepath = renderPath
- bpy.ops.render.render(write_still = True)
|