neverhood311 / Stop-motion-OBJ

A Blender add-on for importing a sequence of OBJ meshes as frames
GNU General Public License v3.0
687 stars 52 forks source link

Importing Linked Mesh Sequences & animation #133

Open rezural opened 3 years ago

rezural commented 3 years ago

Is your feature request related to a problem? Please describe. I have found that for large meshes, having a external file that does the loading & importing is a good way to go in general with blender. However it appears stop-motion-obj doesnt support actually animating from the linked mesh-sequence.

Describe the solution you'd like It would be good for the animation to work.

Describe alternatives you've considered The only alternative is importing, but this is a PITA if having multiple meshes, it takes quite a while to load initially for meshes of any size (i.e > 1mb per mesh)

Additional context I'd be keen to look at adding this functionality myself.

neverhood311 commented 3 years ago

Hi @rezural, thanks for the post. Just so we're on the same page, when you say "having an external file that does the loading & importing", are you referring to Blender's File > Link... option, described here?

rezural commented 3 years ago

Yes, that is what I am referring to.

Also, to allow for moving of objects, the objects need to be proxies Object > Relations > Make Proxy.

If you have any thoughts on what part of the code would need to be updated, drop some comments, and I will have a look at this.

neverhood311 commented 3 years ago

I looked into this a bit. I found the problem, a workaround, and a possible solution.

The problem is that, under the hood, the mesh sequence is not stored as a single object, but as a container object (bpy.types.Object) that "points" to multiple meshes (bpy.types.Mesh). During playback, the addon determines which mesh should be visible on any given frame and swaps out the current one for the new one. When you link or append a mesh sequence from another file, it brings in the object and the current mesh, but Blender doesn't know to bring in the rest of the meshes. (You can go back and bring in all of the meshes manually. The mesh sequence will appear to be working, but it's not properly initialized and as soon as you save and close, all of the other meshes will be discarded).

There's a workaround. It's not ideal, but it might work, depending on your needs. In your "library" .blend file, import your mesh sequence and set it up exactly how you need it (playback mode, speed, start frame, etc.). Now bake the sequence, save your .blend file, and close. Now create a new file and Link the old one. You need to bring in all of the objects (not meshes) for the sequence. If you want, you can also bring in their parent object (C_[something]_sequence_baked). You'll have to parent the mesh objects to the parent object manually.

I have one idea for supporting Linking in the addon, but I'm not super thrilled by it. You'd have to create your own UI for Linking/Appending mesh sequences. Under the hood, it would call the built-in bpy.ops.wm.link function, read the object's mesh_sequence_settings.meshNameArray, then go back and call bpy.ops.wm.link on each of the meshes. It would also have to delete the new objects (but not the meshes), and give each mesh a fake user.

neverhood311 commented 3 years ago

FYI, if you end up trying to implement this (as I think you implied you might want to do), you should start from this branch: https://github.com/neverhood311/Stop-motion-OBJ/tree/version-2.2 I wouldn't want you to waste your time starting from master, only to have an ugly rebase.

rezural commented 3 years ago

Thanks for this, and apologies for the delay in replying.

I will most likely have a look at this within the next month or so, and hopefully find the time to update it. Thanks for the heads up about the new version branch.

I will get my head around your comments, and will need to familiarise myself with the parts of the blender python API that you are talking about. If it is not too hacky, I will try to implement this, but that also depends on what you are willing to accept.

Thanks