-
Notifications
You must be signed in to change notification settings - Fork 16
/
render.py
57 lines (42 loc) · 1.82 KB
/
render.py
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
import bpy
import numpy as np
import math
def generate_animation(data, frame_divisor, muliplier=50):
data_length = data.shape[0]
no_frames = data_length / frame_divisor
scene = bpy.context.scene
# Add circle for path animation
bpy.ops.curve.primitive_bezier_circle_add(radius=0.1)
# Add bezier to show the path
curvedata = bpy.data.curves.new(name='pathcurve', type='CURVE')
curvedata.dimensions = '3D'
objectdata = bpy.data.objects.new('pathobj', curvedata)
objectdata.location = (0, 0, 0) # object origin
bpy.context.scene.objects.link(objectdata)
polyline = curvedata.splines.new('BEZIER')
polyline.bezier_points.add(no_frames)
# Attach circle to the curve
curvedata.bevel_object = scene.objects['BezierCircle']
drone = scene.objects['drone']
scene.frame_end = no_frames
cur_frame = 0
for frame_no in range(0, data_length, frame_divisor):
scene.frame_set(cur_frame)
current_data = state[frame_no]
location = tuple(
x * muliplier for x in (current_data[0], current_data[1], current_data[2]))
# print(current_data[6], current_data[7], current_data[8])
drone.location = location
drone.rotation_euler = (
current_data[6], current_data[7], current_data[8])
# print(drone.rotation_euler)
drone.keyframe_insert(data_path="location")
drone.keyframe_insert(data_path="rotation_euler")
polyline.bezier_points[cur_frame].co = location
polyline.bezier_points[cur_frame].handle_left = location
polyline.bezier_points[cur_frame].handle_right = location
curvedata.bevel_factor_end = cur_frame / no_frames
curvedata.keyframe_insert(data_path='bevel_factor_end')
cur_frame += 1
state = np.load('./quaddata.npy')
generate_animation(state, 6, 75)