Export procedual mesh animation with alembic
Open, NormalPublic

Description

System Information
Ubuntu 16.04

Blender Version
Broken: a85f457195

Short description of error
I created a small python script that updates a mesh on every frame. Now I want to export the animation using the alembic exporter. There are no error messages but when I import the file I don't see what I would expect.

Exact steps for others to reproduce the error

Case 1:

  1. Open the file (should be on a frame > 10).
  2. Export using alembic.
  3. Open an empty file.
  4. Import the .abc file -> it only imports an empty mesh (not animated)

Case 2:

  1. Open the file.
  2. Go to frame 1.
  3. Export using alembic.
  4. Open an empty file.
  5. Import the .abc file -> not it does not even import a mesh, but an empty.

I guess the reason for this is that the exporter checks whether the mesh is empty or not. However this check should not be made as the mesh can appear at other frames when it is created using scripts. I understand why this is the default behavior but there should be an option to turn it off, otherwise the exporter is useless in some cases.

Case 3:

  1. Open the file (here the frame does not matter).
  2. Add a wave modifier to the object and set its height to 0 -> the mesh does not change.
  3. Export using alembic.
  4. Open an empty file.
  5. Import the .abc file -> now everything works perfectly.

It's great that it works that way but it feels reallyyy hacky. However it's better then not having this functionality at all.

Details

Type
Bug

To define whether or not a mesh is animated, the exporter only checks for the presence of modifiers and shapekeys. Since your script is using a scene handler and recreating the mesh every frame, it is not possible to know that this particular object is animated (unless there is some hidden black magic I am not aware of).

I can only think of two options at the moment to address this issue :

  • add a flag to the exporter to force exporting objects on every frame (but that would affect every object in the scene)
  • make use of a custom property that needs to be set by the user on the objects needing to be exported for every frame

I see, thanks for the clarification.

Both of these options would work for me.
However, having a global option might work in my case but not in more complicated scenarios.

A third option (which I'm not saying should be implemented) is that the export operator can get a list of objects (or object names) that should be exported on every frame.
This would allow script developers to use this functionality, while it is more complicated to use the functionality from the UI only.

The easiest solution would be to just make the third case I described official. So users/developers who want to export an animated mesh (using scripts) have to create a modifier that does not change the mesh at all. It would give the same flexibility we would have with the custom property approach, just that the code does not need to change at all.

The only thing that is very annoying still, is that if the mesh is empty (on the current frame) it is replaced by an empty object. Beside that fact that I don't quite understand why this happens at all, it definitely should not happen if there is any modifier on the object. The problem also appears when you have an empty mesh with an ocean modifier on top -> the ocean is exported as empty object.

@Jacques Lucke (JacquesLucke) I didn't try this, but you could add a custom property to the mesh, and animate that. That way the mesh has animation data; this might be enough for the exporter to consider it "animated" and export it on every frame. Can you give that a try and let us know if it works?

Just tried the approach with the custom property on the mesh. It did not seem to work.

Animation Nodes creates a disabled modifier for objects with mesh animation now, this solves most of the problems I had. However another solution would still be nice.

The bigger problem is that the exporter creates an empty object if the mesh is empty at the moment when the export starts. As I said this is not only a problem that you can get when using scripts.
Here is a test file in which you can see the problem (it's the same scenario I described in my previous comment). Just try to export the ocean, and then import it in a new file:

Currently this problem is solved by always adding at least one vertex to the mesh. However, this hack is much worse compared to the add-modifier-hack because it actually changes the geometry which is irrelevant in most cases but might be important in other cases (when you really want to have the mesh empty..).

Sergey Sharybin (sergey) triaged this task as "Normal" priority.Mon, May 22, 3:23 PM

@Sybren A. Stüvel (sybren), render pipeline will call the frame change post/pre callbacks (this is likely happening via the depsgraph update). So seems reasonable thing to do for alembic export as well?