Importing to blender

The interface, modeling, 3d editing tools, import/export, feature requests, etc

Moderators: jesterKing, stiv

Post Reply
halal
Posts: 0
Joined: Fri Feb 22, 2013 12:15 pm

Importing to blender

Post by halal »

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

Code: Select all

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   ...
or in numbers

Code: Select all

5        4       ...
0  0  0  1  0  0 ...
0  0  1  1  0  1 ...
Thank you in advance

CoDEmanX
Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX »

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...

halal
Posts: 0
Joined: Fri Feb 22, 2013 12:15 pm

Post by halal »

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

zedeneye1
Posts: 0
Joined: Thu Feb 07, 2013 12:25 pm
Location: Canada

Post by zedeneye1 »

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...

unfortunately I don't know python either...

halal
Posts: 0
Joined: Fri Feb 22, 2013 12:15 pm

Post by halal »

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

halal
Posts: 0
Joined: Fri Feb 22, 2013 12:15 pm

Post by halal »

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.

Code: Select all

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)

Post Reply