getavalon / core

The safe post-production pipeline - https://getavalon.github.io/2.0
MIT License
213 stars 48 forks source link

Cinema4D Integration #497

Open BigRoy opened 4 years ago

BigRoy commented 4 years ago

Integrate Avalon with Cinema4D

This issue is about Maxon's Cinema4D and building a cinema4d integration for Avalon.

Cinema4D has grown popular amonst many new small-to-medium sized studios because of its ease-of-use. With that stable user base now growing into larger productions it could be great if Avalon could allow them the stable growth to run animation productions efficiently.

Unlike Blender it seems Cinema4D does have some code related to threading which means it could be slightly more trivial to get things up and running nicely.

Implementation notes

BigRoy commented 4 years ago

When Cinema 4D starts, it finds all files in this folder that end with .pyp or .pypv and executes the plugin. A simple plugin possible thus looks like this:

def main():
    print "Hello World!"

main()

Source

As such, this can definitely be used to run code at startup.


The plugin can be contained inside Avalon and pointed to with C4D_PLUGINS_DIR

This C4D_PLUGINS_DIR seems to have been removed since R20 and replaced with g_additionalModulePath as mentioned here and its usage described here


Posted a question regarding adding a Custom Menu with Custom Python Commands to Cinema4D's top menu bar on the Maxon forums as the Enhance Main Menu example left out how to register custom Python commands and add them to the menu.

BigRoy commented 4 years ago

Useful links for future reference:

BigRoy commented 4 years ago

Found an odd bug with Cinema4d where Python scripting gets broken, this is noticable in Extensions > Scripts Manager... (Shift + F11) where the Execute button remains disabled.

The command line log shows:

WARNING: no python vm found [main.cpp(547)]

It seems to happen whenever an empty value is in the PYTHONPATH path separated values, as described here:

# good
set PYTHONPATH=
set PYTHONPATH=a;b;c

# bad
set PYTHONPATH=;
set PYTHONPATH=;a;b
set PYTHONPATH=a;;b;c

Found the issue in Cinema4D R21.115 TRIAL (Build RB297076)

This bug is something to be wary of when we would launch it through the Launcher.

BigRoy commented 4 years ago

Here are some progress previews:

Work Files 2020-01-04-14-11-51

Avalon Qt interfaces opening fine 2020-01-04-14-12-31

Here's the quick and dirty draft integration: https://github.com/BigRoy/core/commit/99bd8bba34659bfb0a764150478b642464ff6c0d

Note:

BigRoy commented 4 years ago

Someone will have to explain me how C4D documents/projects work. Apparently you can have many open at the same time but I just can't find where you can actually switch to another open document/project without closing the one you're working in. (Through the UI that is)

They actually do show in the UI at the bottom of the Window menu item unless you open a document in code with c4d.documents.LoadDocument instead of c4d.documents.LoadFile and not explicitly insert the base document with c4d.documents.InsertBaseDocument. Note that with LoadDocument the file will also not be active automatically (instead its hidden for you) which you can do with c4d.documents.SetActiveDocument however that's all redundant when you instead use c4d.documents.LoadFile.

Still it's confusing. 🗡🐉

save_file should also still set the active document to that path. Now it does save, but your current scene will still think it's set to the old path.

Fixed with https://github.com/BigRoy/core/commit/9dd09ae17aa0acdf1ee585d45f664b703e924e1a

BigRoy commented 4 years ago

Did some quick investigating into how one could create and prepare instances for publishing. In Maya we use objectSets as containers of what to output. In Houdini we have "ROP nodes" that point a specific node to export.

Create publish instances in C4D

UserData tags on a node

For Cinema4D I couldn't find any "selection sets" or "object sets" or "containers" that would allow picking a specific set of nodes for exporting - so that didn't seem like the right way to go. I looked at Layers, but they are exclusive for objects (can't be in two layers at the same time) and are used for rendering too which is an area you wouldn't want any clutter to go.

Then I looked into Tags which seemed pretty nice, however it seems they are always applied to a single node and never shared. Nevertheless that definitely seemed like a nice direction because you can colorize them the way you want, give them a custom icon and there seems to be a "Stub" Tag called "UserData" which would be perfect. You can add custom attributes to the tag that allow the customization per tag we need.

Example: avalon_c4d_userData_tag_example

However the downside is still that it would only allow choosing a specific root note, not specific objects you want to include - but I guess there isn't a simple way to do that in C4D anyway.

UserData tags would be a good way forward.

Or... Inclusion Data on a Null with Inclusion UserData field

Or, a single Null node could be created for each publish instance that has custom attributes defining the settings. There's a specific inclusion user data field in Cinema4D that allows to do some sort of Memberships, like an object set or collection. This could be perfect for what we'd need. However, the UI in managing it is somewhat clunky. Additionally I'm not sure how trivial it is for advanced C4D users to find these relationships (e.g. not even sure if you can find it from e.g. the member itself)

avalon_c4d_null_userData_inclusionMembers

Here's the User data field in the Manage User Data interface:

avalon_c4d_in-exclusion_user_data

Also, this Topic seems related to UserData In-Exclusion fields in C4D and Python access too.

BigRoy commented 4 years ago

Another way of creating instances for publishing using "selection sets" was described on Avalon Gitter, linking it here for future reference. Thanks! Here it is in the Maxon Cinema4D documentation on Selection Object

BigRoy commented 4 years ago

Progress on this Integration will likely slow down on my end because of two reasons:

  1. The obvious, less time on my hands.
  2. More importantly, I can't actually use Cinema4D anymore as my trial period expired. Had some contact with Maxon but they seem unwilling to extend the trial to allow me to continue the integration work in my spare time.

So if anyone needs this in production feel free to still hit me up, and definitely use the above things as a basis. Regarding Pyblish and pyblish plugins for C4D definitely look in the Pyblish for Cinema4D topic and check in with Andre Anjos as he'll be happy to share details too.