Blender 2.9, Python-Gebäude, Auto, Video

Blender-Videoproduktion, die langsam verlief, aber vorerst in zweieinhalb Monaten "Video von Hira no Ophthalmology Parking Guide" Ist fertig. Ein Absatz hier. Ich hatte das Ziel, fast alles in Python zu schreiben, aber am Ende habe ich die Textur manuell um das Book-Off-Schild geklebt. Es dauerte zweieinhalb Monate für das vier Sekunden lange Video, was die Ineffizienz des Amateurs darstellt, aber es gibt ein Gefühl der Leistung, dass "ich zweieinhalb Monate lang nicht auf halbem Weg aufgehört habe". Der Grund für die Fortsetzung

Sie mögen vielleicht oder nicht mögen, ob Sie die Mitte der Produktion ankündigen oder nicht, aber es scheint besser zu sein, einen Ort zu schaffen, an dem Sie den Menschen auf dem Weg zeigen können. Es ist eine Internetumgebung im Jahr 2020 mit vielen japanischen Python-Materialien, aber es ist schwierig, Materialien zu finden, die unter der Bedingung "2.8 statt Blender 2.7 und Python" gesammelt werden können, es sei denn, Sie suchen sowohl nach Sätzen als auch nach Videos in Englisch und Japanisch. Das gesamte Python-Skript ist unten geschrieben, aber zusätzlich zum Skript sind zwei Bildtexturen (Schildbild) erforderlich, um das Video zu reproduzieren. 14.jpg 21.jpg 34.jpg 51.jpg

#bpy_nh36,Körper, Kartenbau. Treppe,2 Schilder 2020.10.28 Arbeit
import bpy
import bmesh
import math
from math import radians
from mathutils import Matrix

#========= DELETE ALL mesh, light, camera,2 Zeilen, um alle zu löschen=========
for item in bpy.data.objects:
    bpy.data.objects.remove(item)
  
def hex_to_rgb( hex_value ): #=== hex color code to RGB
    b = (hex_value & 0xFF) / 255.0
    g = ((hex_value >> 8) & 0xFF) / 255.0
    r = ((hex_value >> 16) & 0xFF) / 255.0
    return r, g, b

def add_material(obj, material_name, h):  #=== material to cube 
    material = bpy.data.materials.get(material_name)
    if material is None:
        material = bpy.data.materials.new(material_name)
    material.use_nodes = True
    principled_bsdf = material.node_tree.nodes['Principled BSDF']
    if principled_bsdf is not None:
        principled_bsdf.inputs[0].default_value = (*hex_to_rgb(h), 1)  
    obj.active_material = material
# =================== definition , create apartment #FThick=1.5 meter (3 meter per floor )
xy_bump = 1.05 #  building wide and narrow cube xy_bump ( 1 wide cube plus 1 narrow cube makes one floor)
def create_apartment(x_origin, y_origin, z_rot, NumOfStories, xScale, yScale, FThick, odd_color, even_color):
    for i in range (0, 2*NumOfStories, 2):
        bpy.ops.mesh.primitive_cube_add(size=2, enter_editmode=False, align='WORLD', location=(x_origin, y_origin, i * FThick), rotation=(0.0, 0.0, z_rot), scale=(xScale, yScale, FThick))
        obj = bpy.context.object
#        add_material( obj, "color01", odd_color )  
        add_material( obj, "", odd_color )  
        bpy.ops.mesh.primitive_cube_add(size=2, enter_editmode=False, align='WORLD', location=(x_origin, y_origin, FThick + i * FThick), rotation=(0.0, 0.0, z_rot), scale=(xScale*xy_bump, yScale*xy_bump, FThick))
        obj = bpy.context.object
#        add_material( obj, "color02", even_color ) 
        add_material( obj, "", even_color )    
  
# ======== create now z_rot:rotation,  NumOfStories:floors, 
# create_apartment(x_origin, y_origin, z_rot, NumOfStories, xScale, yScale, FThick, odd_color, even_color):
create_apartment(-21, -27, 1/180*3.14, 5, 15, 25, 1.5, 0x2F2F2F, 0xffe4b5) #ryowa #DARKSLATEGRAY#2F4F4F
create_apartment(-31, 4, -30/180*3.14, 15, 15, 18, 1.5, 0x2F2F2F, 0xffe4b5)  #HBF #DARKSLATEGRAY#2F4F4F
create_apartment(-25, 20, -30/180*3.14, 8, 18, 15, 1.5, 0xffe4b5, 0x222222) #apt5 bldg
create_apartment(-23, 40, 0/180*3.14, 2, 15, 30, 1.2, 0xeeeeee, 0x6495ed)  #boff #MAROON#800000 ,#DARKGRAY#A9A9A9  ##lightskyblue#87cefa #cornflowerblue#6495ed

create_apartment(-20, 68, 0/180*3.14, 4, 9, 9, 1.5, 0x2F2F2F, 0xffe4b5) #cosmos -20, 67, 10m 10m
create_apartment(14, 70, 0/180*3.14, 4, 22, 11, 1.5, 0x2F2F2F, 0xffe4b5) #seikei  x14,y70, 22m 11m
create_apartment(-50, 53, 0/180*3.14, 10, 10, 10, 1.5, 0x2F2F2F, 0xffe4b5) #lumiere_k1 -49,53,  scale 6,6
create_apartment(-60, 55, 0/180*3.14, 10, 12, 12, 1.5, 0x2F2F2F, 0xffe4b5) #lumiere_k2 -49,53,  scale 6,6
# ====== create kanbans ...  2 planes
bpy.ops.mesh.primitive_plane_add(size=4, enter_editmode=False, align='WORLD', location=(-15, 48, 6.25), rotation=(3.14/2, 0, 3.14/2), scale=(1,1,1))
bpy.context.active_object.name = 'kanban_book'
bpy.ops.mesh.primitive_plane_add(size=4, enter_editmode=False, align='WORLD', location=(-15, 13, 3.5), rotation=(3.14/2, 0, 3.14*0.4), scale=(1,1,1))
bpy.ops.transform.resize(value=(1, 3, 0.7)) 
bpy.context.active_object.name = 'kanban_higa'

#==================== beginning of STAIRS . skew rectangle
pi = math.pi
# URL https://tamaki-py.hatenablog.com/entry/2019/06/03/223545
#'''Muss im Objektmodus starten.Das Skript funktioniert nicht, wenn die Szene leer ist.'''
##Wechseln Sie in den Objektmodus.
#bpy.ops.object.mode_set(mode='OBJECT')
##Wählen Sie alle Objekte aus.
#bpy.ops.object.select_all(action='SELECT')
##Löschen Sie alle ausgewählten Objekte.
#bpy.ops.object.delete()
#'''Erstellen Sie einen Würfel,Wechseln Sie in den Bearbeitungsmodus.'''
#Platziere den Würfel.
#######(-49,60, 0)
# === stairs east face
bpy.ops.mesh.primitive_cube_add(size=1, location=(-51, 61, 0)) ##lumiere_koi_bldg stairs
bpy.ops.transform.resize(value=(0.1, 4, 1.4))

#Wechseln Sie in den Bearbeitungsmodus.
bpy.ops.object.mode_set(mode='EDIT')
#Deaktivieren Sie alle Netze.
bpy.ops.mesh.select_all(action='DESELECT')
'''Wechseln Sie in den Gesichtsmodus,Eine Oberfläche drehen.'''
#In den Gesichtsmodus versetzen.
bpy.ops.mesh.select_mode(type="FACE")
#Bmesh-Objektinstanziierung.
b_mesh = bmesh.from_edit_mesh(bpy.context.object.data)
b_mesh.faces.ensure_lookup_table()
b_mesh.faces[3].select = True # ===  face number (3) south face 
bpy.ops.transform.translate(value=(0, 0, 3)) #=== move a face upward
bpy.ops.object.mode_set(mode='OBJECT')

for i in range(8):
    bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 0, 3), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), })
# === lumiere_koi_bldg stairs west face
bpy.ops.mesh.primitive_cube_add(size=1, location=(-53, 61, 0)) ##lumiere_koi_bldg stairs
bpy.ops.transform.resize(value=(0.1, 4, 1.4))

#Wechseln Sie in den Bearbeitungsmodus.
bpy.ops.object.mode_set(mode='EDIT')
#Deaktivieren Sie alle Netze.
bpy.ops.mesh.select_all(action='DESELECT')
'''Wechseln Sie in den Gesichtsmodus,Eine Oberfläche drehen.'''
#In den Gesichtsmodus versetzen.
bpy.ops.mesh.select_mode(type="FACE")
#Bmesh-Objektinstanziierung.
b_mesh = bmesh.from_edit_mesh(bpy.context.object.data)
b_mesh.faces.ensure_lookup_table()
b_mesh.faces[1].select = True # ===  face number (3) south face 
bpy.ops.transform.translate(value=(0, 0, 3)) #=== move a face upward
bpy.ops.object.mode_set(mode='OBJECT')
for i in range(8):
    bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 0, 3), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), })
# === lumiere_koi_bldg stairs north rectrangle face 
bpy.ops.mesh.primitive_cube_add(size=1, location=(-52, 63, 0)) ##lumiere_koi_bldg stairs
bpy.ops.transform.resize(value=(2,0.1,1.4)) #(0.1, 4, 1.4))
for i in range(8):
    bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 0, 3), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), })
#============================ end of STAIRS 

## === hodoukyo horizontal part
bpy.ops.mesh.primitive_cube_add(size=1, location=(-52, 67, 2.5))
bpy.ops.transform.resize(value=(2, 8, 1))
## === hodoukyo "v-shape" arch over the bridge
vlen = 12
vb_height =5 #apex height
ct_x = -52 # center x 
ct_y =  67 # center y
for i in range(-vlen, (vlen +1) ):  #(  (-3, 3)Wenn Sie schreiben, 3 auf der Minus-Seite, 1 auf dem Ursprung, 2 auf der Plus-Seite, insgesamt 6)
    x= i/2
    y= i/2
    z= vb_height - abs(i) / 8
    bpy.ops.mesh.primitive_cube_add(size=0.3, location=(ct_x + x*0.3, ct_y + y*0.3, z))
    bpy.ops.mesh.primitive_cube_add(size=0.3, location=(ct_x + x*0.3, ct_y -y*0.3, z))
    bpy.ops.mesh.primitive_cube_add(size=0.3, location=(ct_x + x*0.3, ct_y + -vlen*0.3/2, 3.5))
    bpy.ops.mesh.primitive_cube_add(size=0.3, location=(ct_x + x*0.3, ct_y + vlen*0.3/2, 3.5))
## === hodoukyo stairs part
bpy.ops.mesh.primitive_cube_add(size=1, location=(-49, 70, 1.3))
bpy.ops.transform.resize(value=(6, 2, 0.3))
# URL https://suzulang.com/blender-2-8-python-rotate/
#Geben Sie das aktuell aktive Objekt in obj an
obj = bpy.context.active_object

def rotate_object(rot_mat):
    # decompose world_matrix's components, and from them assemble 4x4 matrices
    orig_loc, orig_rot, orig_scale = obj.matrix_world.decompose()
    #
    orig_loc_mat   = Matrix.Translation(orig_loc)
    orig_rot_mat   = orig_rot.to_matrix().to_4x4()
    orig_scale_mat = (Matrix.Scale(orig_scale[0],4,(1,0,0)) @ 
                      Matrix.Scale(orig_scale[1],4,(0,1,0)) @ 
                      Matrix.Scale(orig_scale[2],4,(0,0,1)))
    #
    # assemble the new matrix
    obj.matrix_world = orig_loc_mat @ rot_mat @ orig_rot_mat @ orig_scale_mat 
# Matrix.Erstellen Sie mit Rotation eine Rotationsmatrix
# Matrix.Rotation(Radian Drehwinkel, 4 ,Drehachse)
#4 bedeutet 4x4 Matrix
#Die Drehachse ist(x,y,z)Neben dem Format'X'Oder'Y'Oder'Z'Sie können auch den Achsnamen wie angeben
rotate_object( Matrix.Rotation( radians(30), 4, (0,1,0) ) )


## === end of  hodoukyo

# =====  road
bpy.ops.mesh.primitive_plane_add(size=2, enter_editmode=False, align='WORLD', location=(-7, 90, 0), scale=(1, 1, 1))
bpy.ops.transform.resize(value=(3, 200, 1))
bpy.ops.mesh.primitive_plane_add(size=2, enter_editmode=False, align='WORLD', location=(-0.6, 120, 0), scale=(1, 1, 1), rotation=(0.0, 0.0, -6/180*3.14))
bpy.ops.transform.resize(value=(100, 1, 1))

# Add a plane for ground  ==================
bpy.ops.mesh.primitive_plane_add(size=400.0, align='WORLD', location=(0.0, 0.0, -0.5), rotation=(0.0, 0.0, 0.0) )
matp = bpy.data.materials.new('Plane')
matp.diffuse_color = (0.08, 0.08, 0.03, 0) 
obj = bpy.context.view_layer.objects.active
obj.data.materials.append(matp)

# ================== world - surface - background (Hintergrund) 
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      

# ============== "light"
# create light datablock, set attributes
#light_data = bpy.data.lights.new(name="light_spot1", type='SPOT')
light_data = bpy.data.lights.new(name="light_spot1", type='SUN')
light_data.energy = 5
# 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 = (20, -10, 50)
light_object1.delta_rotation_euler = (1.3, 0, 0.3) #Schauen Sie direkt auf Null Null Null.
# update scene, if needed
dg = bpy.context.evaluated_depsgraph_get() 
dg.update()

light_data = bpy.data.lights.new(name="light_spot2", type='SPOT')
light_data.energy = 20000
# create new object with our light datablock
light_object2 = bpy.data.objects.new(name="light_spot2", object_data=light_data)
# link light object
bpy.context.collection.objects.link(light_object2)
# make it active 
bpy.context.view_layer.objects.active = light_object2
#change location
light_object2.location = (-20, 60, 40)
light_object2.delta_rotation_euler = (0.1, 0, 0.3) #Schauen Sie direkt auf Null Null Null.
# update scene, if needed
dg = bpy.context.evaluated_depsgraph_get() 
dg.update()

light_data = bpy.data.lights.new(name="light_spot3", type='SPOT')
light_data.energy = 20000
# create new object with our light datablock
light_object3 = bpy.data.objects.new(name="light_spot3", object_data=light_data)
# link light object
bpy.context.collection.objects.link(light_object3)
# make it active 
bpy.context.view_layer.objects.active = light_object3
#change location
light_object3.location = (-50, 60, 40)
light_object3.delta_rotation_euler = (0.1, 0, 0.3) #Schauen Sie direkt auf Null Null Null.
# update scene, if needed
dg = bpy.context.evaluated_depsgraph_get() 
dg.update()


# ================
#======= KOI HONMACHI Map ======
bpy.ops.object.load_reference_image(filepath="/Users/nh7/Dropbox/blenderF/bpykmapR2.jpg ")
bpy.context.active_object.name = 'plane_map1'

bpy.context.object.scale[0] = 106
bpy.context.object.scale[1] = 106
bpy.context.object.location[0] = -58.6
bpy.context.object.location[1] = 70.7
#======= KOI HONMACHI Map ======END 


#======= car body manufacturing start
bpy.ops.mesh.primitive_cube_add(size=1, location=(0, 0, 0), scale=(1, 1, 1))
bpy.context.active_object.name = 'b_base'
bpy.ops.transform.resize(value=(1.5,3.4,0.9))
bpy.ops.mesh.primitive_plane_add(size=1, location=(0, -0.45, 0.4))
bpy.context.active_object.name = 'b_top'
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.inset(thickness=0.1, depth=0.6)
bpy.ops.object.editmode_toggle()
bpy.ops.transform.resize(value=(1.5,2.5,1))
bpy.data.objects['b_base'].select_set(True)
bpy.data.objects['b_top'].select_set(True)
for x in bpy.context.selected_objects: # same COLOR on tires and body
    objdd =  x.data
    mat = bpy.data.materials.new('Car_color')
    #h = 0xdc143c  ###0xdc143c= crimson
    h = 0x800000 #ox800000=maroon
    mat.diffuse_color = (*hex_to_rgb(h), 1) #======   COLOR
    objdd.materials.append(mat)
bpy.data.objects['b_base'].select_set(False)
bpy.data.objects['b_top'].select_set(False)

bpy.ops.mesh.primitive_cylinder_add(vertices=16, radius=0.3 , depth=1.6, end_fill_type='NGON', location=(0,1.0,-0.3) )
bpy.context.active_object.name = 'tire_fr'
bpy.ops.transform.rotate(value=90/180*3.14, orient_axis='Y' )
bpy.ops.mesh.primitive_cylinder_add(vertices=16, radius=0.3 , depth=1.6, end_fill_type='NGON', location=(0,-1.2,-0.3) )
bpy.context.active_object.name = 'tire_rr'
bpy.ops.transform.rotate(value=90/180*3.14, orient_axis='Y' )
bpy.data.objects['tire_fr'].select_set(True)
bpy.data.objects['tire_rr'].select_set(True)
for x in bpy.context.selected_objects: # same COLOR on tires and body
    objdd =  x.data
    mat = bpy.data.materials.new('Car_color') 
    h = 0x2f4f4f ###gray?????darkslategray
    mat.diffuse_color = (*hex_to_rgb(h), 1) #======   COLOR
    objdd.materials.append(mat)


bpy.data.objects['b_base'].select_set(True)
bpy.data.objects['b_top'].select_set(True)
bpy.data.objects['tire_fr'].select_set(True)
bpy.data.objects['tire_rr'].select_set(True)
bpy.ops.object.join()
bpy.context.active_object.name = 'joined_car1'
bpy.data.objects['joined_car1'].select_set(True)


#======= END of car body manufacturing 

# ================ CAR movement with KEY FRAME 
bpy.context.scene.frame_start = 1
bpy.context.scene.frame_end = 60
bpy.context.scene.frame_current = 10

bpy.data.objects['joined_car1'].select_set(True)
objects = bpy.data.objects

bpy.context.scene.frame_current = 1 # set frame to 1
objects['joined_car1'].location = (-8,-9,1)  # set location
bpy.ops.transform.rotate(value=0/180*3.14, orient_axis='Z' )
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
bpy.ops.anim.keyframe_insert_menu(type='Rotation')

bpy.context.scene.frame_current = 10 # set frame to 10
objects['joined_car1'].location = (-8,15,1)
bpy.ops.transform.rotate(value=0/180*3.14, orient_axis='Z' )
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
bpy.ops.anim.keyframe_insert_menu(type='Rotation')

bpy.context.scene.frame_current = 20
objects['joined_car1'].location = (-8,53,1)
bpy.ops.transform.rotate(value=-2/180*3.14, orient_axis='Z' )
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
bpy.ops.anim.keyframe_insert_menu(type='Rotation')

bpy.context.scene.frame_current = 22
objects['joined_car1'].location = (-10,59,1)
bpy.ops.transform.rotate(value=-30/180*3.14, orient_axis='Z' )
#objects['car_body'].rotation = (0,0,15/180*3.14)
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
bpy.ops.anim.keyframe_insert_menu(type='Rotation')

bpy.context.scene.frame_current = 25
objects['joined_car1'].location = (-14,60,1)
bpy.ops.transform.rotate(value=-30/180*3.14, orient_axis='Z' )
#objects['car_body'].rotation = (0,0,15/180*3.14)
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
bpy.ops.anim.keyframe_insert_menu(type='Rotation')

bpy.context.scene.frame_current = 40
objects['joined_car1'].location = (-30,64,1)
bpy.ops.transform.rotate(value=-30/180*3.14, orient_axis='Z' )
#objects['car_body'].rotation = (0,0,30/180*3.14)
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
bpy.ops.anim.keyframe_insert_menu(type='Rotation')

bpy.context.scene.frame_current = 50
objects['joined_car1'].location = (-45,65,1)
#bpy.ops.transform.rotate(value=0/180*3.14, orient_axis='Z' )
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
bpy.ops.anim.keyframe_insert_menu(type='Rotation')

bpy.context.scene.frame_current = 60
objects['joined_car1'].location = (-65,65,1)
bpy.ops.transform.rotate(value=0/180*3.14, orient_axis='Z' )
#objects['car_body'].rotation = (0,0,30/180*3.14)
bpy.ops.anim.keyframe_insert_menu(type='Location') # KEY FRAME
bpy.ops.anim.keyframe_insert_menu(type='Rotation')

bpy.ops.transform.rotate(value=0, orient_axis='Z' )

# ================ END of CAR movement

# ================ make a new CURVE for camera movement
# ==== nunoheya BEGIN
curvedata = bpy.data.curves.new("my curve", type='CURVE')    
curvedata.dimensions = '3D'    

polyline = curvedata.splines.new('BEZIER')
polyline.bezier_points.add(2) #Anzahl der Kontrollpunkte-1

polyline.bezier_points[0].co = -1,-61,18
polyline.bezier_points[0].handle_left = -1,-74,18
polyline.bezier_points[0].handle_right = -6,-45,18

polyline.bezier_points[1].co = 0,30,18
polyline.bezier_points[1].handle_left = -3,15,18
polyline.bezier_points[1].handle_right = 0,43,18

polyline.bezier_points[2].co = -18,62,20
polyline.bezier_points[2].handle_left = 0,58,20
polyline.bezier_points[2].handle_right = -30,62,20

obj = bpy.data.objects.new("my bezier", curvedata) 
#Erstellen Sie eine neue Sammlung
newCol = bpy.data.collections.new('Collection 1')
#Verknüpfung der Sammlung mit der aktuellen Szene
bpy.context.scene.collection.children.link(newCol)
#Verknüpfen Sie Objekte mit der Sammlung
newCol.objects.link(obj)
# ==== nunoheya END


#  ================== = camera movement
#bpy.ops.curve.primitive_bezier_circle_add(enter_editmode=False, align='WORLD', location=(20, 20, 30))
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"].target = bpy.data.objects["my bezier"]

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["Cube.016"]
bpy.context.object.constraints["Track To"].target = bpy.data.objects["joined_car1"]
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.25
con.keyframe_insert("offset_factor", frame=12)
con.offset_factor = 0.50
con.keyframe_insert("offset_factor", frame=18)
con.offset_factor = 0.70
con.keyframe_insert("offset_factor", frame=30)
con.offset_factor = 0.80
con.keyframe_insert("offset_factor", frame=50)
con.offset_factor = 0.99
con.keyframe_insert("offset_factor", frame=60)

# ==== END of camera movement

# ======== to EDIT mode, then OBJECT mode ===

#「#Übergang in den Bearbeitungsmodus "2.Verbesserte ungefähr 2 Zeilen für 8.
 
#Übergang in den Bearbeitungsmodus
#Argument arg_Objektname: Angegebener Objektname
#Rückgabewert
def set_mode_edit(arg_objectname='Default'):
  #Scannen Sie alle Objekte, damit der Vorgang nicht auf andere Objekte angewendet wird
  for ob in bpy.context.scene.objects:
    #In den nicht ausgewählten Zustand versetzen
    #ob.select=False  #blender2.7
    ob.select_set(False)
  #Holen Sie sich das angegebene Objekt
  selectob = bpy.data.objects[arg_objectname]
  #Ändern Sie das Änderungsobjekt so, dass es aktiv ist
  #bpy.context.scene.objects.active = selectob  #blender2.7
  bpy.context.view_layer.objects.active = selectob
  #
  #Wechseln Sie in den Bearbeitungsmodus
  bpy.ops.object.mode_set(mode='EDIT', toggle=False)
  return
#Beispiel für die Funktionsausführung
set_mode_edit('my bezier')
# =====
#「#Übergang in den Objektmodus "2.Verbesserte ungefähr 2 Zeilen für 8.

#Übergang in den Objektmodus
#Argument arg_Objektname: Angegebener Objektname
#Rückgabewert
def set_mode_object(arg_objectname='Default'):
  #Scannen Sie alle Objekte, damit der Vorgang nicht auf andere Objekte angewendet wird
    for ob in bpy.context.scene.objects:
    #In den nicht ausgewählten Zustand versetzen
    #ob.select=False
        ob.select_set(False)
  #Holen Sie sich das angegebene Objekt
    selectob = bpy.data.objects[arg_objectname]
  #Ändern Sie das Änderungsobjekt so, dass es aktiv ist
  #bpy.context.scene.objects.active = selectob
    bpy.context.view_layer.objects.active = selectob
  #Wechseln Sie in den Objektmodus
    bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
    return
#Beispiel für die Funktionsausführung
set_mode_object('my bezier')
# ======== to EDIT mode, then OBJECT mode ===   END


Recommended Posts

Blender 2.9, Python-Gebäude, Auto, Video
Blender 2.9 Python Extrude extrudieren
Mixer, Python, Wendeltreppe
Führen Sie Blender mit Python aus
Mixer, Python, Kugelverhalten
Blender 2.8, Python-Cube-Skalierung
Betreiben Sie Blender mit Python
Mixer, Python, Wendeltreppe, Farbe
Blender 2.9, Python ungerade gerade Gebäude
Blender 2.9, Python, hexadezimale Farbspezifikation
Blender 2.8, Python, Licht Spotbeleuchtung
Blender Python API in Houdini (Python 3)
Generieren Sie 8 * 8 (64) Cubes mit Blender Python
Zeichnen Sie Sinuswellen mit Blender Python
Mixer 2.8, Python-Würfel, Beleuchtung, Bewegung des Kameraumfangs
Führen Sie mruby mit Python oder Blender aus
Installieren Sie Pytorch unter Blender 2.90 Python unter Windows
Verwenden Sie Blender als Python-Modul
[Blender x Python] Lass uns zufällig meistern !!
[Blender x Python] Lass uns die Rotation meistern !!
Greifen Sie über Python auf die Shader-Knoten von Blender zu
Beginnen Sie mit Python mit Blender
Blender 2.9, Python-Hintergrundlicht-Farbtest