Import and managing 'merged' Alembic
-
Hi everyone,
I'm trying to import an Alembic and then afterwards manage the loaded data (like being able to update versions) via Python. However, I'm already stuck at triggering the "Import Alembic" logic without user interventions (no dialogs). How would I do so?
- How to trigger "import alembic" and return the newly created objects?
- To update the alembics after I'm thinking of updating the filepaths on the Alembic paths, and removing any shapes that do not exist anymore in the alembic and creating new ones. Is there an Alembic API that comes with Cinema4D that allows me to query the contents of the alembic?
- I'd like to also update the "visibility" on updates - do I need to 'key' those, or is it capable of streaming those in? Since the checkbox appears to remain disabled for me?
Code snippet, documentation or links are greatly appreciated!
Note: I'm not familiar with Cinema4D - I'm only trying to tackle the pipeline aspect of it for an open-source pipeline called AYON. So even for simple concepts it'd be nice to get the 'dummy" info about it.
I'm looking to do this in 2023.2.2 and up.
-
Hi @BigRoy,
Loading alembic file through the import process is not different from any other exchange format supported in cinema. Please, have a look at the OBJ Example here. You can also find corresponding symbols for the alembic import settings in our docs: Alembic Import Settings. After setting everything up you can either merge entire abc file directly to your document using MergeDocument() or load it into a separate document using LoadDocument().
There's no special Alembic API. The Alembic generator is accessible in a regular way via getting and setting parameters (GetParameter() and SetParameter()). You can find the list of available alembic parameters here: Alembic. For example, by using the c4d.ALEMBIC_PATH (or/and c4d.ALEMBIC_IDENT_STATE) parameter you can change the path to the alembic file or may be remove the object of the designated filepath doesn't exist anymore.
However, managing internal alembic data is very tricky, as there's no easy way to do it. You can access geometry data by accessing geometry cache (please check my posting on the neighbor thread: How to get the number of points in an object?) or by baking alembic using MCOMMAND_CURRENTSTATETOOBJECT command in the SendModelingCommand() function. However, the animation data is not accessible other than by scrabbing the timeline and accessing the geometry at each frame. Please also have a look at related threads: Change alembic generator state/type and How to preserve the animation of a sphere. There's no default approach here and it would highly depend on your specific scanario.
The enabled state of the streaming attributes is handled dynamically and depends on the data you have in your alembic file. Namely, if the visibility option is grayed out, it means either that the visibility track is not animated in the alembic file (check your scene file or alembic exporter settings, if you use C4D to create those) or you haven't enabled visibility option in the alembic import settings. For such questions you can consult our User Documentation or reach out to our Support Center.
Cheers,
Ilia -
Hi Ilia, this is great - thanks so much. I was able to get what I needed using the
LoadDocument
it seems. Am I correct in understand that the document it 'opens' is only temporary and I do not have to ensure proper deletion (in memory) of the loaded document once I'm done with it?Other than that - part of my code is currently here. It's more of a "spare time" open-source pipeline development because I don't use Cinema4D myself but am hoping it can become useful for others - so thanks for the details!
-
Hi @BigRoy,
in python the lifetime of the objects is handled automatically so you're right, there's no need to do anything special to destruct the object.
Good job on your project! Thanks for sharing it with the community!
Cheers,
Ilia