blender-运动基础

1. blender 运动基础: 平移、旋转

创建一个立方体,按照动作设定坐标后新建关键帧,就可以了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# give Python access to Blender's functionality
import bpy
# extend Python's math functionality
import math

# add a cube into the scene
bpy.ops.mesh.primitive_cube_add()
# get a reference to the currently active object
cube = bpy.context.active_object

# insert keyframe at frame one
cube.keyframe_insert("rotation_euler", frame=1)
# change the rotation of the cube around z-axis
cube.rotation_euler.z = math.radians(360)

# insert keyframe at the last frame
cube.keyframe_insert("rotation_euler", frame=90)

# change the location of the cube on the z-axis
cube.location.z = 0
cube.keyframe_insert("location", frame=100)
cube.location.z = 5
cube.keyframe_insert("location", frame=150)


ref:
Beginner Python Exercise in Blender: Simple cube location animation
https://www.youtube.com/watch?v=nmJqIaSZlRs

Final Code:
https://gist.github.com/CGArtPython/83a324c9938216c91df746c15179e992

Beginner Blender Python Exercise: Easy cube rotation animation
https://www.youtube.com/watch?v=tBPuEWh88Lo

Final Code:
https://gist.github.com/CGArtPython/11927dffa39a378fa00f7ab514e76f07

https://twitter.com/cgpython

2. blender 阵列实体旋转运动

  • 创建立方体阵列,沿Z轴堆叠,并旋转(每隔3°);
  • 运动动画:逐个从下到上旋转一圈。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# give Python access to Blender's functionality
import bpy
# extend Python's math functionality
import math
# extend Python functionality to generate random numbers
import random


def animate_rotation(obj, current_frame, rotation_frame_count):
# remove the animation data from the duplicated object
obj.animation_data_clear()

# insert key frame
obj.keyframe_insert("rotation_euler", frame=current_frame)

# rotate object
obj.rotation_euler.z += math.radians(360)

# calculate the end frame
frame = current_frame + rotation_frame_count

# insert key frame
obj.keyframe_insert("rotation_euler", frame=frame)


# add first cube mesh into the scene
bpy.ops.mesh.primitive_cube_add(scale=(0.5, 2, 0.1))
obj = bpy.context.active_object
obj.rotation_euler.z = math.radians(random.uniform(0, 360))
bpy.ops.object.transform_apply()

# create variables for stacking and rotating
angle_step = 3
current_angle = 3

# create variables for animating the rotation
current_frame = 1
frame_step = 1
rotation_frame_count = 90

# animate the original mesh
animate_rotation(obj, current_frame, rotation_frame_count)

# stack and rotate the mesh
while current_angle < 360:
# duplicate the mesh
bpy.ops.object.duplicate(linked=True)

# set location and rotation
obj = bpy.context.active_object
obj.location.z += obj.dimensions.z
obj.rotation_euler.z = math.radians(current_angle)

animate_rotation(obj, current_frame, rotation_frame_count)

# update the angle for the next iteration
current_angle += angle_step
# update the current_frame
current_frame += frame_step

# update the end frame for the whole animation
bpy.context.scene.frame_end = current_frame + rotation_frame_count


ref:
Beginner Blender Python Tutorial: for loop practice

https://www.youtube.com/watch?v=AcoYA4T2ErU
https://www.youtube.com/watch?v=tC_Bu-VO8p0

Start code:
https://gist.github.com/CGArtPython/004d414871f04bfb2c7605a88ea1e7a7

Final code:
https://gist.github.com/CGArtPython/cf74ed708ff8c7fc76d2aeda1710e034