Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #575 from pypeclub/feature/567-Nuke_Publish_Camera
Browse files Browse the repository at this point in the history
Nuke: Publishing, loading and updating alembic cameras
  • Loading branch information
mkolar authored Oct 5, 2020
2 parents f9a3fa8 + ac0ef2a commit 0c2ffde
Show file tree
Hide file tree
Showing 6 changed files with 425 additions and 5 deletions.
3 changes: 0 additions & 3 deletions pype/plugins/nuke/create/create_camera

This file was deleted.

53 changes: 53 additions & 0 deletions pype/plugins/nuke/create/create_camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import avalon.nuke
from avalon.nuke import lib as anlib
import nuke


class CreateCamera(avalon.nuke.Creator):
"""Add Publishable Backdrop"""

name = "camera"
label = "Create 3d Camera"
family = "camera"
icon = "camera"
defaults = ["Main"]

def __init__(self, *args, **kwargs):
super(CreateCamera, self).__init__(*args, **kwargs)
self.nodes = nuke.selectedNodes()
self.node_color = "0xff9100ff"
return

def process(self):
nodes = list()
if (self.options or {}).get("useSelection"):
nodes = self.nodes

if len(nodes) >= 1:
# loop selected nodes
for n in nodes:
data = self.data.copy()
if len(nodes) > 1:
# rename subset name only if more
# then one node are selected
subset = self.family + n["name"].value().capitalize()
data["subset"] = subset

# change node color
n["tile_color"].setValue(int(self.node_color, 16))
# add avalon knobs
anlib.imprint(n, data)
return True
else:
msg = str("Please select nodes you "
"wish to add to a container")
self.log.error(msg)
nuke.message(msg)
return
else:
# if selected is off then create one node
camera_node = nuke.createNode("Camera2")
camera_node["tile_color"].setValue(int(self.node_color, 16))
# add avalon knobs
instance = anlib.imprint(camera_node, self.data)
return instance
1 change: 0 additions & 1 deletion pype/plugins/nuke/load/load_backdrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ def update(self, container, representation):

return update_container(GN, data_imprint)


def switch(self, container, representation):
self.update(container, representation)

Expand Down
187 changes: 187 additions & 0 deletions pype/plugins/nuke/load/load_camera_abc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
from avalon import api, io
from avalon.nuke import lib as anlib
from avalon.nuke import containerise, update_container
import nuke


class AlembicCameraLoader(api.Loader):
"""
This will load alembic camera into script.
"""

families = ["camera"]
representations = ["abc"]

label = "Load Alembic Camera"
icon = "camera"
color = "orange"
node_color = "0x3469ffff"

def load(self, context, name, namespace, data):
# get main variables
version = context['version']
version_data = version.get("data", {})
vname = version.get("name", None)
first = version_data.get("frameStart", None)
last = version_data.get("frameEnd", None)
fps = version_data.get("fps") or nuke.root()["fps"].getValue()
namespace = namespace or context['asset']['name']
object_name = "{}_{}".format(name, namespace)

# prepare data for imprinting
# add additional metadata from the version to imprint to Avalon knob
add_keys = ["source", "author", "fps"]

data_imprint = {"frameStart": first,
"frameEnd": last,
"version": vname,
"objectName": object_name}

for k in add_keys:
data_imprint.update({k: version_data[k]})

# getting file path
file = self.fname.replace("\\", "/")

with anlib.maintained_selection():
camera_node = nuke.createNode(
"Camera2",
"name {} file {} read_from_file True".format(
object_name, file),
inpanel=False
)
camera_node.forceValidate()
camera_node["frame_rate"].setValue(float(fps))

# workaround because nuke's bug is not adding
# animation keys properly
xpos = camera_node.xpos()
ypos = camera_node.ypos()
nuke.nodeCopy("%clipboard%")
nuke.delete(camera_node)
nuke.nodePaste("%clipboard%")
camera_node = nuke.toNode(object_name)
camera_node.setXYpos(xpos, ypos)

# color node by correct color by actual version
self.node_version_color(version, camera_node)

return containerise(
node=camera_node,
name=name,
namespace=namespace,
context=context,
loader=self.__class__.__name__,
data=data_imprint)

def update(self, container, representation):
"""
Called by Scene Inventory when look should be updated to current
version.
If any reference edits cannot be applied, eg. shader renamed and
material not present, reference is unloaded and cleaned.
All failed edits are highlighted to the user via message box.
Args:
container: object that has look to be updated
representation: (dict): relationship data to get proper
representation from DB and persisted
data in .json
Returns:
None
"""
# Get version from io
version = io.find_one({
"type": "version",
"_id": representation["parent"]
})
object_name = container['objectName']
# get corresponding node
camera_node = nuke.toNode(object_name)

# get main variables
version_data = version.get("data", {})
vname = version.get("name", None)
first = version_data.get("frameStart", None)
last = version_data.get("frameEnd", None)
fps = version_data.get("fps") or nuke.root()["fps"].getValue()

# prepare data for imprinting
# add additional metadata from the version to imprint to Avalon knob
add_keys = ["source", "author", "fps"]

data_imprint = {"representation": str(representation["_id"]),
"frameStart": first,
"frameEnd": last,
"version": vname,
"objectName": object_name}

for k in add_keys:
data_imprint.update({k: version_data[k]})

# getting file path
file = api.get_representation_path(representation).replace("\\", "/")

with anlib.maintained_selection():
camera_node = nuke.toNode(object_name)
camera_node['selected'].setValue(True)

# collect input output dependencies
dependencies = camera_node.dependencies()
dependent = camera_node.dependent()

camera_node["frame_rate"].setValue(float(fps))
camera_node["file"].setValue(file)

# workaround because nuke's bug is
# not adding animation keys properly
xpos = camera_node.xpos()
ypos = camera_node.ypos()
nuke.nodeCopy("%clipboard%")
nuke.delete(camera_node)
nuke.nodePaste("%clipboard%")
camera_node = nuke.toNode(object_name)
camera_node.setXYpos(xpos, ypos)

# link to original input nodes
for i, input in enumerate(dependencies):
camera_node.setInput(i, input)
# link to original output nodes
for d in dependent:
index = next((i for i, dpcy in enumerate(
d.dependencies())
if camera_node is dpcy), 0)
d.setInput(index, camera_node)

# color node by correct color by actual version
self.node_version_color(version, camera_node)

self.log.info("udated to version: {}".format(version.get("name")))

return update_container(camera_node, data_imprint)

def node_version_color(self, version, node):
""" Coloring a node by correct color by actual version
"""
# get all versions in list
versions = io.find({
"type": "version",
"parent": version["parent"]
}).distinct('name')

max_version = max(versions)

# change color of node
if version.get("name") not in [max_version]:
node["tile_color"].setValue(int("0xd88467ff", 16))
else:
node["tile_color"].setValue(int(self.node_color, 16))

def switch(self, container, representation):
self.update(container, representation)

def remove(self, container):
from avalon.nuke import viewer_update_and_undo_stop
node = nuke.toNode(container['objectName'])
with viewer_update_and_undo_stop():
nuke.delete(node)
1 change: 0 additions & 1 deletion pype/plugins/nuke/publish/collect_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def process(self, context):

families.append(family)


# except disabled nodes but exclude backdrops in test
if ("nukenodes" not in family) and (node["disable"].value()):
continue
Expand Down
Loading

0 comments on commit 0c2ffde

Please sign in to comment.