1
$\begingroup$

I have a problem importing my files into blender. First of all, here it is what I have, for example:

https://www.youtube.com/watch?v=GltBwX6kSgY

My system is more complex, but works in the same way. Every frame has been calculated using molecular dynamics programs. I can save every frame as an "obj" file. The problem is that when I try to import them, I have all the frames in the same scene and same frame. Is it any way to load every frame of my simulation as a frame in blender?

Thanks

Ferchu

$\endgroup$
1
  • $\begingroup$ You might try the Blender add-on Stop Motion OBJ. It supports sequences of .PLY, .OBJ, and .STL files. It also supports geometry with different vertex counts from frame to frame.github.com/neverhood311/Stop-motion-OBJ $\endgroup$
    – Justin
    Commented May 16, 2017 at 17:42

1 Answer 1

1
$\begingroup$

As you are importing an object for each frame, you want to keyframe the visibility of each object so that it is only visible on the frame that it is made for.

You can use the following script to import each obj and keyframe it's visibility.

import bpy
scn = bpy.context.scene
for f in range(scn.frame_start, scn.frame_end):
    fpath = bpy.path.abspath('//sim_data_{}.obj'.format(f))
    bpy.ops.import_scene.obj(filepath=fpath)
    obj = bpy.context.selected_objects[0]
    # key as visible on the current frame
    obj.keyframe_insert('hide',frame=f)
    obj.keyframe_insert('hide_render',frame=f)
    # hide it
    obj.hide = True
    obj.hide_render = True
    # key as hidden on the previous frame
    obj.keyframe_insert('hide',frame=f-1)
    obj.keyframe_insert('hide_render',frame=f-1)
    # key as hidden on the next frame
    obj.keyframe_insert('hide',frame=f+1)
    obj.keyframe_insert('hide_render',frame=f+1)

If you have the option to export in .mdd or .pc2 format, you could look at using the mesh cache modifier.

Depending on how much the "particles" in the simulation deform, you may also want to look at exporting a location and size of each item per frame. This way you could just use the exported data to keyframe the location of each object.

$\endgroup$
2
  • $\begingroup$ Thanks a lot, sambler! I just had a problem with the selection of the active object: AttributeError: 'NoneType' object has no attribute 'keyframe_insert' but I've included these lines: bpy.context.scene.objects.active = bpy.context.selected_objects[0] bpy.ops.anim.keyframe_insert(type="Location") and now it works! Maybe can you explain me why "obj" didn't take any value of the active object function? Thanks for the help again! $\endgroup$
    – user29801
    Commented Aug 25, 2016 at 13:27
  • $\begingroup$ It seems the stl importer imports an object and makes it active, the obj importer is scene based and only selects the objects in the obj file but doesn't change the active object. While using bpy.ops.anim.keyframe_insert will keyframe the selected objects you will want to change the current frame so that the keyframe is added where you want. Another way is to change the use of active_object to selected_objects[0]. $\endgroup$
    – sambler
    Commented Aug 26, 2016 at 18:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .