Utilizes Blender (headless) and Processing to generate images (3D and 2D renderings) for the webshop
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

render_pictureonly.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import bpy
  2. import sys
  3. import mathutils
  4. argv = sys.argv
  5. argv = argv[argv.index("--") + 1:]
  6. width = int(argv[0])
  7. height = int(argv[1])
  8. imgpath = argv[2]
  9. renderPath = argv[3]
  10. def selectObject(name):
  11. ob = bpy.context.scene.objects[name]
  12. bpy.ops.object.select_all(action='DESELECT')
  13. bpy.context.view_layer.objects.active = ob
  14. ob.select_set(True)
  15. def moveObject(name,x,y,z):
  16. selectObject(name)
  17. bpy.context.object.location = x, y, z
  18. def scaleObject(name,x,y,z):
  19. selectObject(name)
  20. bpy.context.object.dimensions = x, y, z
  21. def moveCamLocal(z):
  22. cam = bpy.data.objects["Camera"]
  23. vec = mathutils.Vector((0.0, 0.0, z))
  24. inv = cam.matrix_world.copy()
  25. inv.invert()
  26. vec_rot = vec @ inv
  27. cam.location = cam.location + vec_rot
  28. img = bpy.data.images.load(filepath = imgpath)
  29. selectObject("Canvas")
  30. bpy.context.object.material_slots[0].material.node_tree.nodes["Image Texture"].image = img
  31. diff = max(width,height) - 80
  32. moveCamLocal(diff/55)
  33. moveObject("BarTop",0,0,height/100/2)
  34. moveObject("BarBottom",0,0,-height/100/2)
  35. moveObject("BarLeft",-width/100/2,0,0)
  36. moveObject("BarRight",width/100/2,0,0)
  37. scaleObject("BarTop",width/100-0.06,0.026024,0.02)
  38. scaleObject("BarBottom",width/100-0.06,0.026024,0.02)
  39. scaleObject("BarLeft",height/100-0.06,0.026024,0.02)
  40. scaleObject("BarRight",height/100-0.06,0.026024,0.02)
  41. moveObject("CornerTopRight", width/100/2,0,height/100/2)
  42. moveObject("CornerTopLeft", -width/100/2,0,height/100/2)
  43. moveObject("CornerBottomRight", width/100/2,0,-height/100/2)
  44. moveObject("CornerBottomLeft", -width/100/2,0,-height/100/2)
  45. scaleObject("Glass", width/100,0.002037,height/100)
  46. scaleObject("Canvas",width/100,0.0025,height/100)
  47. bpy.context.scene.render.filepath = renderPath
  48. bpy.ops.render.render(write_still = True)