Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.57 KB | None | 0 0
  1. from numpy.random import randint
  2. import random
  3. import bpy
  4. from math import radians
  5.  
  6. def look_at(obj_camera, point,z):
  7.     obj_camera.location = (0, 0, z)
  8.     loc_camera = obj_camera.matrix_world.to_translation()
  9.     direction = point - loc_camera
  10.     rot_quat = direction.to_track_quat('-Z', 'Y')
  11.     obj_camera.rotation_euler = rot_quat.to_euler()
  12.  
  13.  
  14. def importObject(path, n):
  15.     blendfile =  path + str(n) + '.blend'
  16.     section   = '\\Object\\'
  17.     objects    = ['Petal'] ###<-- Add the name of objects you want to append
  18.     directory = blendfile + section
  19.     for obj in objects:  
  20.         filename  = obj
  21.         bpy.ops.wm.append(filename=filename, directory=directory)
  22. ####################################################################
  23. ######TRASFORMA DA CHIUSO AD APERTO################################
  24.  
  25. def trasforma(start,finish,inc):
  26.    
  27.     mesh_start = start.data
  28.     mesh_finish = finish.data
  29.  
  30.     vert_start = mesh_start.vertices
  31.     vert_finish = mesh_finish.vertices
  32.  
  33.     mat_start_world = start.matrix_world
  34.     mat_finish_world = finish.matrix_world
  35.    
  36.     delta = []
  37.  
  38.     #creazione delta
  39.     for n in range(len(vert_start)):
  40.         vr = start.matrix_world @ vert_start[n].co
  41.         vq = finish.matrix_world @ vert_finish[n].co
  42.         delta.append((((vq.x-vr.x)/inc),((vq.y-vr.y)/inc,((vq.z-vr.z)/inc)))
  43.    
  44.     for m in range(inc):
  45.         for v in range(len(vert_start)):
  46.             pos_world = mat_start_world @ vert_start[v].co
  47.             pos_world.x += delta[v][0]
  48.             pos_world.y += delta[v][1]
  49.             pos_world.z += delta[v][2]
  50.             vert_start[v].co = mat_start_world.inverted() @ pos_world  
  51.     #Save .blend file
  52.     #bpy.ops.wm.save_as_mainfile(filepath= path + str(m) + '.blend')
  53.  
  54.     #Save current .jpg
  55.         bpy.context.scene.render.filepath = path_photos + str(m) + '.jpg'
  56.         bpy.ops.render.render(write_still = True)
  57. ##################################################################
  58.  
  59.  
  60.  
  61.  
  62.  
  63. bpy.ops.object.select_all(action='DESELECT')
  64. bpy.data.objects['Cube'].select_set(True) # Blender 2.8x
  65. bpy.ops.object.delete()
  66.  
  67. #RISOLUZIONE FOTO################################################
  68. bpy.context.scene.render.resolution_x = 1000
  69. bpy.context.scene.render.resolution_y = 1000
  70. #################################################################
  71.  
  72. path_photos= 'C:/Users/ghedi/Desktop/Zaffro/zaffro/Photos/'
  73.  
  74. ##################################################################
  75. # METTI CAMERA SULL'ASSE Z CHE GUARDA GIU'########################
  76. ##################################################################
  77.  
  78. obj_camera = bpy.data.objects["Camera"]
  79. obj_other = bpy.data.objects["Petal"]
  80. look_at(obj_camera, obj_other.matrix_world.to_translation(),32)
  81.  
  82. ###################################################################
  83. ##IMPORTA UN FIORE CHIUSO ED UNO APERTO############################
  84. ###################################################################
  85.  
  86. path_aperto = "C:/Users/ghedi/Desktop/Zaffro/zaffro/modelli/Fiori_base/Aperti/fiore_"
  87. path_chiuso = "C:/Users/ghedi/Desktop/Zaffro/zaffro/modelli/Fiori_base/Chiusi/fiore_"
  88. n_aperto = random.randint(0,99)
  89. n_chiuso = random.randint(0,2)
  90. importObject(path_aperto, n_aperto) #importa fiore aperto
  91. fiore_aperto = bpy.data.objects["Petal"]
  92. importObject(path_chiuso, n_chiuso) #importa fiore chiuso
  93. fiore_chiuso = bpy.data.objects["Petal.001"]
  94. #####################################################################
  95. #####TRASFORMA E FAI SCREENSHOT, SALVA SCREENSHOT########
  96. trasforma(fiore_chiuso, fiore_aperto,10)
  97. # 1) position camera
  98. # 2) importa 1 fiore chiuso ed uno aperto
  99. # 3) trasforma da aperto a chiuso chiamando la funzione trasforma
  100. # 4) fai screenshot ad ogni incremento usando la funzione screenshot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement