Files
render-images-for-webshop/data/render.py
2022-07-14 09:13:39 +02:00

51 lines
1.5 KiB
Python

import bpy
import sys
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
img = bpy.data.images.load(filepath = imgpath)
selectObject("Canvas")
bpy.context.object.material_slots[0].material.node_tree.nodes["Image Texture"].image = img
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.019024,0.02)
scaleObject("BarBottom",width/100-0.06,0.019024,0.02)
scaleObject("BarLeft",height/100-0.06,0.019024,0.02)
scaleObject("BarRight",height/100-0.06,0.019024,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)