如何为多个 objects 的移动和旋转设置动画?
How to animate the movement and the rotation of multiple objects?
我有一架由多个objects组成的无人机。问题是,当我旋转无人机并将其移动到其他点时,它会失去形状(撕成碎片),无人机的每个部分都与主 body 断开连接。如何在不变形的情况下旋转和移动无人机?
我试着把无人机的 body 变成所有零件的 parent。当我只旋转或移动 body 时它工作。
config
import math
import bpy
import mathutils
import subprocess as sp
from math import sqrt, degrees, acos, pow
sp.call('cls', shell=True)
drone_objects_names = ['Cube.008', 'Cylinder.007', 'Cube.007', 'Cube.006', 'Sphere.005', 'Sphere.004', 'Cylinder.008',
'Sphere.003', 'Cylinder.006', 'Cube.005', 'Cube.004', 'Sphere.002', 'Cylinder.005', 'Sphere.001',
'Cylinder.004', 'Sphere', 'Cylinder.003', 'Cube.003', 'Cylinder.002', 'Cylinder.001', 'Cube.002',
'Cube.001', 'Cylinder', 'Cube']
X = 10
Y = 10
Z = 5
frame_num = 0
teta = 0
factor = 0.97
def set_keyframe():
for object_name in drone_objects_names:
bpy.data.objects[object_name].keyframe_insert(data_path="location", index=-1)
def send_drone_to_center():
move_drone(-bpy.data.objects['Cylinder.003'].location)
def select_drone():
for object_name in drone_objects_names:
bpy.data.objects[object_name].select_set(True)
def move_drone(v):
bpy.ops.transform.translate(value=v)
def angle_between_z(vc, uc):
nominator = vc[0] * uc[0] + vc[2] * uc[2]
denominator = sqrt(pow(vc[0], 2) + pow(vc[2], 2)) * sqrt(pow(uc[0], 2) + pow(uc[2], 2))
return acos(nominator / denominator)
def angle_between_y(vc, uc):
nominator = vc[0] * uc[0] + vc[2] * uc[2]
denominator = sqrt(pow(vc[0], 2) + pow(vc[2], 2)) * sqrt(pow(uc[0], 2) + pow(uc[2], 2))
return acos(nominator / denominator)
def do_step():
global factor, teta, frame_num, X, Y, Z
factor = 0.97
x_new = X * math.cos(math.radians(teta))
y_new = Y * math.sin(math.radians(teta))
bpy.context.scene.frame_set(frame_num)
move_drone(-bpy.data.objects['Cylinder.003'].location)
move_drone((x_new, y_new, Z * factor))
angle = angle_between_z((x_new, y_new, Z * factor), (X, Y, Z))
bpy.data.objects['Cylinder.003'].rotate_euler[2] = angle
set_keyframe()
frame_num += 3
X *= factor
Y *= factor
Z *= factor
teta += 10
select_drone()
send_drone_to_center()
move_drone((X, Y, Z))
while math.sqrt(X * X + Y * Y + Z * Z) > 1:
do_step()
e = bpy.data.objects['Cylinder.003'].location
print(X, Y, e[0], e[2])
bpy.context.scene.frame_end = frame_num
我希望无人机在参考中心的中心不会变形...
drone lose it's shape
我在这个项目中使用的无人机(如果你想尝试......):drone
您的脚本正在对无人机的每个部分应用相同的运动。作为子对象,对象的位置是相对于父对象的,通过更改子对象的位置,它正在远离父对象,而父对象也正在移动。
要么删除父对象,要么只为父对象设置动画。
我有一架由多个objects组成的无人机。问题是,当我旋转无人机并将其移动到其他点时,它会失去形状(撕成碎片),无人机的每个部分都与主 body 断开连接。如何在不变形的情况下旋转和移动无人机?
我试着把无人机的 body 变成所有零件的 parent。当我只旋转或移动 body 时它工作。 config
import math
import bpy
import mathutils
import subprocess as sp
from math import sqrt, degrees, acos, pow
sp.call('cls', shell=True)
drone_objects_names = ['Cube.008', 'Cylinder.007', 'Cube.007', 'Cube.006', 'Sphere.005', 'Sphere.004', 'Cylinder.008',
'Sphere.003', 'Cylinder.006', 'Cube.005', 'Cube.004', 'Sphere.002', 'Cylinder.005', 'Sphere.001',
'Cylinder.004', 'Sphere', 'Cylinder.003', 'Cube.003', 'Cylinder.002', 'Cylinder.001', 'Cube.002',
'Cube.001', 'Cylinder', 'Cube']
X = 10
Y = 10
Z = 5
frame_num = 0
teta = 0
factor = 0.97
def set_keyframe():
for object_name in drone_objects_names:
bpy.data.objects[object_name].keyframe_insert(data_path="location", index=-1)
def send_drone_to_center():
move_drone(-bpy.data.objects['Cylinder.003'].location)
def select_drone():
for object_name in drone_objects_names:
bpy.data.objects[object_name].select_set(True)
def move_drone(v):
bpy.ops.transform.translate(value=v)
def angle_between_z(vc, uc):
nominator = vc[0] * uc[0] + vc[2] * uc[2]
denominator = sqrt(pow(vc[0], 2) + pow(vc[2], 2)) * sqrt(pow(uc[0], 2) + pow(uc[2], 2))
return acos(nominator / denominator)
def angle_between_y(vc, uc):
nominator = vc[0] * uc[0] + vc[2] * uc[2]
denominator = sqrt(pow(vc[0], 2) + pow(vc[2], 2)) * sqrt(pow(uc[0], 2) + pow(uc[2], 2))
return acos(nominator / denominator)
def do_step():
global factor, teta, frame_num, X, Y, Z
factor = 0.97
x_new = X * math.cos(math.radians(teta))
y_new = Y * math.sin(math.radians(teta))
bpy.context.scene.frame_set(frame_num)
move_drone(-bpy.data.objects['Cylinder.003'].location)
move_drone((x_new, y_new, Z * factor))
angle = angle_between_z((x_new, y_new, Z * factor), (X, Y, Z))
bpy.data.objects['Cylinder.003'].rotate_euler[2] = angle
set_keyframe()
frame_num += 3
X *= factor
Y *= factor
Z *= factor
teta += 10
select_drone()
send_drone_to_center()
move_drone((X, Y, Z))
while math.sqrt(X * X + Y * Y + Z * Z) > 1:
do_step()
e = bpy.data.objects['Cylinder.003'].location
print(X, Y, e[0], e[2])
bpy.context.scene.frame_end = frame_num
我希望无人机在参考中心的中心不会变形... drone lose it's shape
我在这个项目中使用的无人机(如果你想尝试......):drone
您的脚本正在对无人机的每个部分应用相同的运动。作为子对象,对象的位置是相对于父对象的,通过更改子对象的位置,它正在远离父对象,而父对象也正在移动。
要么删除父对象,要么只为父对象设置动画。