I am working on particle interactions in matlab and I am looking for a better way to visualize results. Does blender have a way of importing position data for multiple particles over a lot of frames? If so what format to use?
For example something like
size of particle 1 size of particle 2 ...
Position of p. 1 in 1st frame Position of p. 2 in 1st frame ...
Position of p. 1 in 2nd frame Position of p. 2 in 2nd frame ...
since this looks like a really simple, custom format, it wouldn't be hard to write a python script to import the data as empties or vertices. I suggest to create objects and then change their location, don't create new obs for every frame!
I'm sitting, waiting, wishing, building Blender in superstition...
I never used python and neither did I use blender (I used other 3d software though) but I will look into it.
I was thinking of creating the particle by the first 2 rows (and by every 3 columns) and then move them every frame according to each new line.
Thanks
it really depends on how many particles you're talking about and how long an animation you require. If theres lots of particles and lots of frames, its not feasible doing this manually (adjusting each and every single particle in each and every single frame). You'll have to get someone to write some code for you...
Yes, there is going to be a lot of particles and a lot of frames. It won't be possible to do it manually. I am currently looking at python tutorials to figure out how to automate it
Ok, it wasn't that hard to make it work. I am just not sure about some parts of the code. Give me some advice if you see something stupid (especially the path declaration is pretty weird). I added the three dots to make it less confusing in this forum.
import bpy
all = [item.name for item in bpy.data.objects]
for object in all:
bpy.data.objects[object].select = 1
bpy.ops.object.delete(use_global=False)
path=bpy.data.filepath
fullpath=path.split('testing.blend')[0]+'out10.xyz'
file = open(fullpath, "r")
diameters=file.readline()
diameter=[float(x) for x in diameters.split()]
nn=len(diameter)
starts=file.readline()
start=[float(x) for x in starts.split()]
frame_num=0
bpy.context.scene.frame_set(frame_num)
for i in range(0, nn):
loc=(start[3*i],start[3*i+1],start[3*i+2])
print(loc)
bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=2,... ...size=diameter[i], location=loc)
obj = bpy.context.active_object
pname = 'Particle' + str(i)
obj.name = pname
bpy.ops.anim.keyframe_insert(type='Location',... ...confirm_success=True)
for line in file:
newframe=[float(x) for x in line.split()]
frame_num += 1
print(frame_num)
bpy.context.scene.frame_set(frame_num)
for i in range(0, nn):
pname = 'Particle' + str(i)
bpy.context.scene.objects.active = bpy.data.objects[pname]
ob = bpy.context.active_object
bpy.data.objects[pname].select = 1
position=(newframe[3*i],newframe[3*i+1],newframe[3*i+2])
ob.location = position
bpy.ops.anim.keyframe_insert(type='Location',... ...confirm_success=True)