mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Merge branch 'develop' into feature/harmony_publish_render
# Conflicts: # pype/harmony/__init__.py # pype/plugins/harmony/publish/collect_instances.py
This commit is contained in:
commit
ffaf11208f
5 changed files with 179 additions and 1 deletions
|
|
@ -81,7 +81,8 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin):
|
|||
"assembly",
|
||||
"fbx",
|
||||
"textures",
|
||||
"action"
|
||||
"action",
|
||||
"harmony.template"
|
||||
]
|
||||
exclude_families = ["clip"]
|
||||
db_representation_context_keys = [
|
||||
|
|
|
|||
12
pype/plugins/harmony/create/create_template.py
Normal file
12
pype/plugins/harmony/create/create_template.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from avalon import harmony
|
||||
|
||||
|
||||
class CreateTemplate(harmony.Creator):
|
||||
"""Composite node for publishing to templates."""
|
||||
|
||||
name = "templateDefault"
|
||||
label = "Template"
|
||||
family = "harmony.template"
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(CreateTemplate, self).__init__(*args, **kwargs)
|
||||
48
pype/plugins/harmony/load/load_template.py
Normal file
48
pype/plugins/harmony/load/load_template.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import tempfile
|
||||
import zipfile
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from avalon import api, harmony
|
||||
|
||||
|
||||
class ImportTemplateLoader(api.Loader):
|
||||
"""Import templates."""
|
||||
|
||||
families = ["harmony.template"]
|
||||
representations = ["*"]
|
||||
label = "Import Template"
|
||||
|
||||
def load(self, context, name=None, namespace=None, data=None):
|
||||
temp_dir = tempfile.mkdtemp()
|
||||
zip_file = api.get_representation_path(context["representation"])
|
||||
template_path = os.path.join(temp_dir, "temp.tpl")
|
||||
with zipfile.ZipFile(zip_file, "r") as zip_ref:
|
||||
zip_ref.extractall(template_path)
|
||||
|
||||
func = """function func(args)
|
||||
{
|
||||
var template_path = args[0];
|
||||
var drag_object = copyPaste.copyFromTemplate(
|
||||
template_path, 0, 0, copyPaste.getCurrentCreateOptions()
|
||||
);
|
||||
copyPaste.pasteNewNodes(
|
||||
drag_object, "", copyPaste.getCurrentPasteOptions()
|
||||
);
|
||||
}
|
||||
func
|
||||
"""
|
||||
|
||||
func = """function func(args)
|
||||
{
|
||||
var template_path = args[0];
|
||||
var drag_object = copyPaste.pasteTemplateIntoGroup(
|
||||
template_path, "Top", 1
|
||||
);
|
||||
}
|
||||
func
|
||||
"""
|
||||
|
||||
harmony.send({"function": func, "args": [template_path]})
|
||||
|
||||
shutil.rmtree(temp_dir)
|
||||
27
pype/plugins/harmony/publish/collect_current_file.py
Normal file
27
pype/plugins/harmony/publish/collect_current_file.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import os
|
||||
|
||||
import pyblish.api
|
||||
from avalon import harmony
|
||||
|
||||
|
||||
class CollectCurrentFile(pyblish.api.ContextPlugin):
|
||||
"""Inject the current working file into context"""
|
||||
|
||||
order = pyblish.api.CollectorOrder - 0.5
|
||||
label = "Current File"
|
||||
hosts = ["harmony"]
|
||||
|
||||
def process(self, context):
|
||||
"""Inject the current working file"""
|
||||
func = """function func()
|
||||
{
|
||||
return (
|
||||
scene.currentProjectPath() + "/" +
|
||||
scene.currentVersionName() + ".xstage"
|
||||
);
|
||||
}
|
||||
func
|
||||
"""
|
||||
|
||||
current_file = harmony.send({"function": func})["result"]
|
||||
context.data["currentFile"] = os.path.normpath(current_file)
|
||||
90
pype/plugins/harmony/publish/extract_template.py
Normal file
90
pype/plugins/harmony/publish/extract_template.py
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
import os
|
||||
import shutil
|
||||
|
||||
import pype.api
|
||||
from avalon import harmony
|
||||
|
||||
|
||||
class ExtractTemplate(pype.api.Extractor):
|
||||
"""Extract the connected nodes to the composite instance."""
|
||||
label = "Extract Template"
|
||||
hosts = ["harmony"]
|
||||
families = ["harmony.template"]
|
||||
|
||||
def process(self, instance):
|
||||
staging_dir = self.staging_dir(instance)
|
||||
|
||||
self.log.info("Outputting template to %s" % staging_dir)
|
||||
|
||||
self.dependencies = []
|
||||
self.get_dependencies(instance[0])
|
||||
|
||||
func = """function func(args)
|
||||
{
|
||||
var nodes = args[0];
|
||||
selection.clearSelection();
|
||||
for (var i = 0 ; i < nodes.length; i++)
|
||||
{
|
||||
selection.addNodeToSelection(nodes[i]);
|
||||
}
|
||||
}
|
||||
func
|
||||
"""
|
||||
harmony.send({"function": func, "args": [self.dependencies]})
|
||||
func = """function func(args)
|
||||
{
|
||||
copyPaste.createTemplateFromSelection(args[0], args[1]);
|
||||
}
|
||||
func
|
||||
"""
|
||||
harmony.send(
|
||||
{
|
||||
"function": func,
|
||||
"args": ["{}.tpl".format(instance.name), staging_dir]
|
||||
}
|
||||
)
|
||||
|
||||
os.chdir(staging_dir)
|
||||
shutil.make_archive(
|
||||
"{}".format(instance.name),
|
||||
"zip",
|
||||
os.path.join(staging_dir, "{}.tpl".format(instance.name))
|
||||
)
|
||||
|
||||
representation = {
|
||||
"name": "tpl",
|
||||
"ext": "zip",
|
||||
"files": "{}.zip".format(instance.name),
|
||||
"stagingDir": staging_dir,
|
||||
}
|
||||
instance.data["representations"] = [representation]
|
||||
|
||||
def get_dependencies(self, node):
|
||||
func = """function func(args)
|
||||
{
|
||||
var target_node = args[0];
|
||||
var numInput = node.numberOfInputPorts(target_node);
|
||||
var dependencies = [];
|
||||
for (var i = 0 ; i < numInput; i++)
|
||||
{
|
||||
dependencies.push(node.srcNode(target_node, i));
|
||||
}
|
||||
return dependencies;
|
||||
}
|
||||
func
|
||||
"""
|
||||
|
||||
current_dependencies = harmony.send(
|
||||
{"function": func, "args": [node]}
|
||||
)["result"]
|
||||
|
||||
for dependency in current_dependencies:
|
||||
if not dependency:
|
||||
continue
|
||||
|
||||
if dependency in self.dependencies:
|
||||
continue
|
||||
|
||||
self.dependencies.append(dependency)
|
||||
|
||||
self.get_dependencies(dependency)
|
||||
Loading…
Add table
Add a link
Reference in a new issue