Let’s get the ball rolling with a nice simple add-on for Nuke.
The alembic dropper allows you to drag and drop alembic (.abc) files into your node graph and have them read in correctly. The script makes a distinction between alembic Cameras and alembic Geometry by simply checking if the file contains any scene objects.
Installing
Download from here.
This one requires a little more work to install than a standard plugin import as it uses the nuke DropDataCallback. A callback is just something that runs in response to an event, in this case, when something is dropped in. To install, place the abcDropping.py in your plugins directory, and add the following lines to your menu.py.
# Callback for Alembic drag and drop from abcDropping import abcDropping nukescripts.addDropDataCallback( abcDropping )
This is a handy feature that took me an annoyingly long time to find, but it allows you to add functions that run when something is dropped into the node graph. The way it works is that nuke has a list of all the functions it will try to call on any data dropped in, and will go through this list in reverse until one of the functions successfully handles the data. The above code then adds our function to the end (meaning it’ll be the first to run) so you can very easily make changes to what happens to incoming data. Now it’s very important that the script accurately returns how it handles the data, so let’s look at the type of function that’s needed for a DropDataCallback.
Code Breakdown
def abcDropping( mimeType, text):
The function will always take two variables, mimeType, and text. You can safely ignore the mimeType as that just needs to be there for it to work, but what’s the text? Well, to figure that out, I simply made a tester callback:
def test( mimeType, text): print text return False
In the case of simply dropping a file in, this just prints the filepath. Handy! The return False is to tell nuke that the callback didn’t handle the data, so it will continue through the rest of the functions. If you’re being picky, you might wonder what happens if you just put return True in. Well, it would give out to you, because now it has data that it doesn’t know what to do with.
if text[-4:] == '.abc' and os.path.exists(text): readGeo = nuke.createNode('ReadGeo2', 'file {%s}' % (text))
So now that we can add the callback and know what it’s working with, it’s pretty straightforward. Check if the filepath ends in the extension we want (.abc) and for safe measure, make the sure the text is in fact a filepath (I’m sure there’s other data that could go in, and you don’t want to accidentally break nuke when this callback runs first). If that fails, we can return False so that it will keep looking for a callback that works.
Then create a ReadGeo node and give it the filepath. Hey presto, we’re done right? …Well, not yet. If you’ve ever imported an alembic into Nuke, you’ll know it gives you a pop-up dialog asking what objects from the file you want to bring in. But with this method, you don’t get the dialog, you just get the first object in the file. Not very useful.
allItems = sceneView.getAllItems() if allItems: sceneView.setImportedItems(allItems) sceneView.setSelectedItems(allItems)
To get around this, we check the hidden knob ‘sceneView’ to find all the objects, and if it’s not empty, we import them all (And select them so that they’re visible in the 3d space). It’s now easy to make our distinction if the imported file is a camera.
else: nuke.delete(readGeo) nuke.createNode('Camera2', 'file {%s} read_from_file True' % (text))
Camera alembics have no scene objects, so if it’s an empty alembic, it’s almost certainly a camera (Unless you’re exporting empty alembics, in which case you may want to rethink your workflow). In that case, we can dump the ReadGeo node we just made and put in a camera instead.
Last but not least, we need to return True now that we’ve successfully handled all the data. And that’s it! Go forth and drop alembics.