Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from numpy.random import randint
- import random
- import bpy
- from math import radians
- def look_at(obj_camera, point,z):
- obj_camera.location = (0, 0, z)
- loc_camera = obj_camera.matrix_world.to_translation()
- direction = point - loc_camera
- rot_quat = direction.to_track_quat('-Z', 'Y')
- obj_camera.rotation_euler = rot_quat.to_euler()
- def importObject(path, n):
- blendfile = path + str(n) + '.blend'
- section = '\\Object\\'
- objects = ['Petal'] ###<-- Add the name of objects you want to append
- directory = blendfile + section
- for obj in objects:
- filename = obj
- bpy.ops.wm.append(filename=filename, directory=directory)
- ####################################################################
- ######TRASFORMA DA CHIUSO AD APERTO################################
- def trasforma(start,finish,inc):
- mesh_start = start.data
- mesh_finish = finish.data
- vert_start = mesh_start.vertices
- vert_finish = mesh_finish.vertices
- mat_start_world = start.matrix_world
- mat_finish_world = finish.matrix_world
- delta = []
- #creazione delta
- for n in range(len(vert_start)):
- vr = start.matrix_world @ vert_start[n].co
- vq = finish.matrix_world @ vert_finish[n].co
- delta.append((((vq.x-vr.x)/inc),((vq.y-vr.y)/inc,((vq.z-vr.z)/inc)))
- for m in range(inc):
- for v in range(len(vert_start)):
- pos_world = mat_start_world @ vert_start[v].co
- pos_world.x += delta[v][0]
- pos_world.y += delta[v][1]
- pos_world.z += delta[v][2]
- vert_start[v].co = mat_start_world.inverted() @ pos_world
- #Save .blend file
- #bpy.ops.wm.save_as_mainfile(filepath= path + str(m) + '.blend')
- #Save current .jpg
- bpy.context.scene.render.filepath = path_photos + str(m) + '.jpg'
- bpy.ops.render.render(write_still = True)
- ##################################################################
- bpy.ops.object.select_all(action='DESELECT')
- bpy.data.objects['Cube'].select_set(True) # Blender 2.8x
- bpy.ops.object.delete()
- #RISOLUZIONE FOTO################################################
- bpy.context.scene.render.resolution_x = 1000
- bpy.context.scene.render.resolution_y = 1000
- #################################################################
- path_photos= 'C:/Users/ghedi/Desktop/Zaffro/zaffro/Photos/'
- ##################################################################
- # METTI CAMERA SULL'ASSE Z CHE GUARDA GIU'########################
- ##################################################################
- obj_camera = bpy.data.objects["Camera"]
- obj_other = bpy.data.objects["Petal"]
- look_at(obj_camera, obj_other.matrix_world.to_translation(),32)
- ###################################################################
- ##IMPORTA UN FIORE CHIUSO ED UNO APERTO############################
- ###################################################################
- path_aperto = "C:/Users/ghedi/Desktop/Zaffro/zaffro/modelli/Fiori_base/Aperti/fiore_"
- path_chiuso = "C:/Users/ghedi/Desktop/Zaffro/zaffro/modelli/Fiori_base/Chiusi/fiore_"
- n_aperto = random.randint(0,99)
- n_chiuso = random.randint(0,2)
- importObject(path_aperto, n_aperto) #importa fiore aperto
- fiore_aperto = bpy.data.objects["Petal"]
- importObject(path_chiuso, n_chiuso) #importa fiore chiuso
- fiore_chiuso = bpy.data.objects["Petal.001"]
- #####################################################################
- #####TRASFORMA E FAI SCREENSHOT, SALVA SCREENSHOT########
- trasforma(fiore_chiuso, fiore_aperto,10)
- # 1) position camera
- # 2) importa 1 fiore chiuso ed uno aperto
- # 3) trasforma da aperto a chiuso chiamando la funzione trasforma
- # 4) fai screenshot ad ogni incremento usando la funzione screenshot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement