-
Notifications
You must be signed in to change notification settings - Fork 1
/
blender_create_single_sline.py
60 lines (47 loc) · 1.68 KB
/
blender_create_single_sline.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
58
59
60
import bpy
import math
from mathutils import Vector
file_name = "/home/haschka/stream/sline10"
f = open(file_name)
points = f.readlines()
pointlist=[]
v_accumulate = 0.
for i in range(len(points)):
buffer = points[i].split()
pointlist.append((float(buffer[0]), float(buffer[1]), float(buffer[2]), float(buffer[3])))
v_accumulate = v_accumulate + float(buffer[3])
v_mean = v_accumulate/(float(len(points)))
curvedata = bpy.data.curves.new(name = 'Curve1', type = 'CURVE')
curvedata.dimensions = '3D'
objectdata = bpy.data.objects.new("ObjCurve", curvedata)
objectdata.location = (0,0,0)
bpy.context.scene.objects.link(objectdata)
polyline = curvedata.splines.new('POLY')
polyline.points.add(len(pointlist)-1)
for num in range(len(pointlist)):
x, y, z, w = pointlist[num]
polyline.points[num].co = (x, y, z, 1.0)
curvedata.use_path = True
curvedata.use_path_follow = True
curvedata.path_duration = len(pointlist)
bpy.ops.mesh.primitive_cube_add(radius = 0.05, location = (0,0,0))
cube = bpy.context.object
#cyl.rotation_mode = 'XYZ'
cube.name = 'flare'
cube.scale[0] = 0.005
cube.scale[1] = 0.005
cube.scale[2] = 0.08
cube.constraints.new(type='FOLLOW_PATH')
cube.constraints['Follow Path'].target = objectdata
cube.constraints['Follow Path'].use_curve_follow = True
cube.constraints['Follow Path'].use_curve_radius = True
#cyl.constraints['Follow Path'].followpath_path_animate(constraint="Follow Path", owner='OBJECT')
cube.rotation_euler = (math.pi/2.,0,0)
t = 0.
for i in range(len(pointlist)):
x, y, z, v = pointlist[i]
if ( v > 0.):
t = (1/3.)*(1./v)+t
if ( i%20 == 0 ):
curvedata.eval_time = i
curvedata.keyframe_insert("eval_time", frame = t)