Blender 2.8, cube Python, éclairage, mouvement de la circonférence de la caméra

Cette fois, le thème est le mouvement de la caméra. Vidéo Youtube "Blender 2.8 Configurer un appareil photo et animer sur un chemin" qui introduit le mouvement de la caméra le long de la circonférence Ceci (jusqu'à 6m50sec dans la première moitié) est transformé en un script Python. Mouvement sur l'axe Z Je ne l'ai pas encore fait. (bpy_nh13) La vidéo est-elle publiée sur Twitter blender 2.8, python. 1-second movie. 242kB. Camera movement along a circle. Le facteur de décalage est lié à [Insérer une image clé dans l'API Python Offset Factor de l'objet] J'ai lu et mentionné (https://blender.stackexchange.com/questions/185082/insert-keyframe-to-objects-offset-factor-python-api) Camera motion along a circle. I have made this Python script based on "Blender 2.8 Set Up a Camera Rig and Animate On A Path". bpy_nh13PNG.png

# bpy_mouvement cubique du mouvement d'éclairage dans la première moitié de nh13(Première mi-temps NH12)Installation de la seconde moitié de la caméra et mouvement de la circonférence de la caméra(Deuxième mi-temps NH14) 
import bpy
# DELETE ALL mesh, light, camera,2 lignes pour tout supprimer
for item in bpy.data.objects:
	bpy.data.objects.remove(item)

#Script original cubique---- http://tips.hecomi.com/entry/20120818/1345307205
#Matériel de référence élargi tatsuruM Qiita https://qiita.com/tatsuruM/items/9d4222c6c7d96b4c5b3c

START = 0
#END   = 100
N     = 4

# Add color cubes
for x in range(0, N):
    for y in range(0, N):
        for z in range(0, N):
            # Add a color cube
            bpy.ops.mesh.primitive_cube_add( location=(x*3, y*3, z*3),size = (1.2) )
            bpy.ops.transform.resize(value=(0.8, 0.1, 2.0))
            bpy.ops.transform.rotate(value= -3.1415/6 ,orient_axis='X')
            #obj = bpy.context.scene.objects.active #(old blender2.7script)
            obj = bpy.context.view_layer.objects.active
            #mat.diffuse_color = (x/N, y/N, z/N)#(old blender2.7script)
            mat = bpy.data.materials.new('Cube')
            mat.diffuse_color = (x/N, y/N, z/N, 0)
            #mat.use_transparency = True #(Cette ligne est 2.Pas essayé en 8)
            #mat.alpha = 0.6 #(Cette ligne est 2.Pas essayé en 8)
            obj.data.materials.append(mat)

# ====== camera (later) ==================

# new lamps ( stack overflow Can you add a light source in blender using python)
# =============="light_spot3"
# create light datablock, set attributes
light_data = bpy.data.lights.new(name="light_spot3", type='SPOT')
light_data.energy = 2000
# create new object with our light datablock
light_object = bpy.data.objects.new(name="light_spot3", object_data=light_data)
# link light object
bpy.context.collection.objects.link(light_object)
# make it active 
bpy.context.view_layer.objects.active = light_object
#change location
light_object.location = (2, -2, 3)
light_object.delta_rotation_euler = (1.6, 0, 0) #Regardez droit vers le bas à zéro zéro zéro.
# update scene, if needed
dg = bpy.context.evaluated_depsgraph_get() 
dg.update()

# =============="light_spot2"
# create light datablock, set attributes
light_data = bpy.data.lights.new(name="light_spot2", type='SPOT')
light_data.energy = 2000
# create new object with our light datablock
light_object = bpy.data.objects.new(name="light_spot2", object_data=light_data)
# link light object
bpy.context.collection.objects.link(light_object)
# make it active 
bpy.context.view_layer.objects.active = light_object
#change location
light_object.location = (2, -4, 10)
light_object.delta_rotation_euler = (1.5, 0, 0) #Regardez droit vers le bas à zéro zéro zéro.
# update scene, if needed
dg = bpy.context.evaluated_depsgraph_get() 
dg.update()
# ============== "light_spot1"
# create light datablock, set attributes
light_data = bpy.data.lights.new(name="light_spot1", type='SPOT')
light_data.energy = 3000
# create new object with our light datablock
light_object1 = bpy.data.objects.new(name="light_spot1", object_data=light_data)
# link light object
bpy.context.collection.objects.link(light_object1)
# make it active 
bpy.context.view_layer.objects.active = light_object1
#change location
light_object1.location = (5, -5, 10)
light_object1.delta_rotation_euler = (1.3, 0, -0.3) #Regardez droit vers le bas à zéro zéro zéro.
# update scene, if needed
dg = bpy.context.evaluated_depsgraph_get() 
dg.update()
# ================

#  MOVE  SPOT LIGHTs  "light_spot1"
bpy.context.scene.frame_start = 1
bpy.context.scene.frame_end = 30
bpy.context.scene.frame_current = 10
# make light ACTIVE 
bpy.context.scene.objects["light_spot3"].select_set(False) # ----- deselect
bpy.context.scene.objects["light_spot2"].select_set(False) # ----- deselect
bpy.context.scene.objects["light_spot1"].select_set(True) #---- select

cdnow  = bpy.context.object          # get ACTIVE object 
bpy.context.scene.frame_current = 1 # set frame to 1
cdnow.location = (5, -6, 8) # set the location
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME

bpy.context.scene.frame_current = 10 # set frame to 10
cdnow.location = (5, -6, 10) # set the location
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME

bpy.context.scene.frame_current = 20 # set frame to 20
cdnow.location = (2, -6, 10)
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME

bpy.context.scene.frame_current = 30 # set frame to 30
cdnow.location = (5, -6, 8)
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
# ================
#MOVE a LIGHT mesh avec le spot KEY FRAME 2 Lumière mobile_spot2
bpy.context.scene.frame_start = 1
bpy.context.scene.frame_end = 30
bpy.context.scene.frame_current = 10

# make POINT  light ACTIVE 
bpy.context.scene.objects["light_spot3"].select_set(False) # ----- deselect
bpy.context.scene.objects["light_spot1"].select_set(False) # ----- deselect
bpy.context.scene.objects["light_spot2"].select_set(True) #---- select

#cdnow  = bpy.context.object          # get ACTIVE object 
cdnow  = bpy.context.scene.objects["light_spot2"]    # get ACTIVE object 

bpy.context.scene.frame_current = 1 # set frame to 1
cdnow.location = (1,-4,1) # set the location
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME

bpy.context.scene.frame_current = 10 # set frame to 10
cdnow.location = (1,-4,3) # set the location
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME

bpy.context.scene.frame_current = 20 # set frame to 20
cdnow.location = (4,-4,3)
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME

bpy.context.scene.frame_current = 30 # set frame to 30
cdnow.location = (1,-4,1)
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
#  ==================
#MOVE a LIGHT mesh avec le spot KEY FRAME 3 Lumière mobile_spot3
bpy.context.scene.frame_start = 1
bpy.context.scene.frame_end = 30
bpy.context.scene.frame_current = 10

# make POINT  light ACTIVE 
bpy.context.scene.objects["light_spot2"].select_set(False) # ----- deselect
bpy.context.scene.objects["light_spot1"].select_set(False) # ----- deselect
bpy.context.scene.objects["light_spot3"].select_set(True)   #---- select

#cdnow  = bpy.context.object          # get ACTIVE object 
cdnow  = bpy.context.scene.objects["light_spot3"]    # get ACTIVE object 

bpy.context.scene.frame_current = 1 # set frame to 1
cdnow.location = (5,-6,1) # set the location
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME

bpy.context.scene.frame_current = 10 # set frame to 10
cdnow.location = (9,-6,1) # set the location
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME

bpy.context.scene.frame_current = 20 # set frame to 20
cdnow.location = (9,-6,5)
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME

bpy.context.scene.frame_current = 30 # set frame to 30
cdnow.location = (5,-6,1)
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
#  ==================
# world - surface - background (Contexte) 
bpy.data.worlds["World"].node_tree.nodes["Background"].inputs[0].default_value = (0.01, 0.15, 0.25, 1)
bpy.data.worlds["World"].node_tree.nodes["Background"].inputs[1].default_value = 0.7            

#  ================== ================= camera movement
#bpy.ops.mesh.primitive_monkey_add(size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0))

bpy.ops.curve.primitive_bezier_circle_add(enter_editmode=False, align='WORLD', location=(0, 0, 0))
bpy.context.object.scale[0] = 6
bpy.context.object.scale[1] = 6
bpy.ops.object.empty_add(type='CUBE', align='WORLD', location=(0, 0, 0))
bpy.ops.object.camera_add(enter_editmode=False, align='VIEW', location=(0, 0, 0), rotation=(0, 0, 0))

bpy.data.objects['Empty'].select_set(True)
bpy.data.objects['Camera'].select_set(True)

bpy.context.view_layer.objects.active = bpy.data.objects['Empty']
bpy.ops.object.parent_set(type='OBJECT')

bpy.data.objects['Camera'].select_set(False)
bpy.data.objects['Empty'].select_set(True)

bpy.ops.object.constraint_add(type='FOLLOW_PATH')
bpy.context.object.constraints["Follow Path"].target = bpy.data.objects["BezierCircle"]

bpy.context.object.constraints["Follow Path"].use_curve_follow = True
bpy.context.object.constraints["Follow Path"].use_fixed_location = True

bpy.data.objects['Empty'].select_set(False)
bpy.data.objects['Camera'].select_set(True)

bpy.ops.object.constraint_add(type='TRACK_TO')
#bpy.context.object.constraints["Track To"].target = bpy.data.objects["Suzanne"]
bpy.context.object.constraints["Track To"].target = bpy.data.objects["Cube.016"]
bpy.context.object.constraints["Track To"].up_axis = 'UP_Y'
bpy.context.object.constraints["Track To"].track_axis = 'TRACK_NEGATIVE_Z'  #5m00sec
#Camera Keyframe #(Insert keyframe to object's Offset Factor Python API - stack exchange)
bpy.data.objects['Camera'].select_set(False)
bpy.data.objects['Empty'].select_set(True)
bpy.context.scene.frame_current = 1
bpy.context.object.constraints["Follow Path"].offset_factor = 0
ob = bpy.context.object
# ob.constraints['Follow Path']
# bpy.data.objects['Empty'].constraints["Follow Path"]
# [bpy.data.objects['Empty'].constraints["Follow Path"]]
con = ob.constraints.get("Follow Path")
con.offset_factor = 0.0
con.keyframe_insert("offset_factor", frame=1)
con.offset_factor = 0.1
con.keyframe_insert("offset_factor", frame=8)
con.offset_factor = 0.15
con.keyframe_insert("offset_factor", frame=16)
con.offset_factor = 0.2
con.keyframe_insert("offset_factor", frame=18)
con.offset_factor = 0.0
con.keyframe_insert("offset_factor", frame=30)
# ===== end of bph_13 (2020.8.28)


Recommended Posts

Blender 2.8, cube Python, éclairage, mouvement de la circonférence de la caméra
Blender 2.8, mise à l'échelle du cube Python
Blender 2.8, Python, éclairage Spot
Extrusion Python Extrude de Blender 2.9
Blender 2.8, Python, mouvement de la caméra, spécification de couleur aléatoire
mixeur, python, escalier en colimaçon
Exécutez Blender avec python
mélangeur, python, comportement de la sphère
Faire fonctionner Blender avec Python
Capture de caméra Python, OpenCV
Capture de caméra avec Python + OpenCV
Blender 2.9, Python Building, Voiture, Vidéo
mixeur, python, escalier en colimaçon, couleur
Blender 2.9, construction paire impaire Python
Blender 2.9, Python, spécification de couleur hexadécimale
API Blender Python dans Houdini (Python 3)
Générez 8 * 8 (64) cubes avec Blender Python