generated from ynput/ayon-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
688 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Create shape data instance.""" | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from ayon_core.lib import ( | ||
EnumDef, | ||
UILabelDef, | ||
UISeparatorDef, | ||
) | ||
from ayon_mocha.api.lib import get_shape_exporters | ||
from ayon_mocha.api.plugin import MochaCreator | ||
|
||
if TYPE_CHECKING: | ||
from ayon_core.pipeline import CreatedInstance | ||
|
||
|
||
class CreateShapeData(MochaCreator): | ||
"""Create shape instance.""" | ||
identifier = "io.ayon.creators.mochapro.matteshapes" | ||
label = "Shape Data" | ||
description = __doc__ | ||
product_type = "matteshapes" | ||
icon = "circle" | ||
|
||
def get_attr_defs_for_instance(self, instance: CreatedInstance) -> list: | ||
"""Get attribute definitions for instance.""" | ||
exporter_items = {ex.id: ex.label for ex in get_shape_exporters()} | ||
layers = { | ||
idx: layer.name | ||
for idx, layer in enumerate( | ||
self.create_context.host.get_current_project().layers) | ||
} or {-1: "No layers"} | ||
|
||
return [ | ||
EnumDef("layers", | ||
label="Layers", | ||
items=layers, | ||
multiselection=True), | ||
EnumDef("exporter", | ||
label="Exporter format", | ||
items=exporter_items, multiselection=True), | ||
UISeparatorDef(), | ||
UILabelDef( | ||
"Exporter Options (not all are available in all exporters)"), | ||
EnumDef("layer_mode", label="Layer mode", | ||
items={ | ||
"selected": "Selected layers", | ||
"all": "All layers" | ||
}), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Collect instances for publishing.""" | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, ClassVar | ||
|
||
import pyblish.api | ||
|
||
if TYPE_CHECKING: | ||
from logging import Logger | ||
|
||
class CollectInstances(pyblish.api.InstancePlugin): | ||
"""Collect instances for publishing.""" | ||
label = "Collect Instances" | ||
order = pyblish.api.CollectorOrder - 0.4 | ||
hosts: ClassVar[list[str]] = ["mochapro"] | ||
log: Logger | ||
|
||
def process(self, instance: pyblish.api.Instance) -> None: | ||
"""Process the plugin.""" | ||
self.log.debug("Collecting data for %s", instance) | ||
|
||
# Define nice instance label | ||
instance_node = instance.data.get( | ||
"transientData", {}).get("instance_node") | ||
name = instance_node.label if instance_node else instance.name | ||
label = f"{name} ({instance.data['folderPath']})" | ||
|
||
# Set frame start handle and frame end handle if frame ranges are | ||
# available | ||
if "frameStart" in instance.data and "frameEnd" in instance.data: | ||
# Enforce existence if handles | ||
instance.data.setdefault("handleStart", 0) | ||
instance.data.setdefault("handleEnd", 0) | ||
|
||
# Compute frame start handle and end start handle | ||
frame_start_handle = ( | ||
instance.data["frameStart"] - instance.data["handleStart"] | ||
) | ||
frame_end_handle = ( | ||
instance.data["frameEnd"] - instance.data["handleEnd"] | ||
) | ||
instance.data["frameStartHandle"] = frame_start_handle | ||
instance.data["frameEndHandle"] = frame_end_handle | ||
|
||
# Include frame range in label | ||
label += f" [{int(frame_start_handle)}-{int(frame_end_handle)}]" | ||
|
||
instance.data["label"] = label |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"""Collect Mocha executable paths.""" | ||
from __future__ import annotations | ||
|
||
import platform | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING, ClassVar | ||
|
||
import pyblish.api | ||
from mocha import get_mocha_exec_name | ||
|
||
if TYPE_CHECKING: | ||
from logging import Logger | ||
|
||
from mocha.project import Project | ||
|
||
class CollectMochaPaths(pyblish.api.ContextPlugin): | ||
"""Collect Mocha Pro project.""" | ||
order = pyblish.api.CollectorOrder - 0.45 | ||
label = "Collect Mocha Pro executables" | ||
hosts: ClassVar[list[str]] = ["mochapro"] | ||
log: Logger | ||
|
||
def process(self, context: pyblish.api.Context) -> None: | ||
"""Process the plugin.""" | ||
project: Project = context.data["project"] | ||
self.log.info("Collected Mocha Pro project: %s", project) | ||
|
||
mocha_executable_path = Path(get_mocha_exec_name("mochapro")) | ||
context.data["mocha_executable_path"] = mocha_executable_path | ||
mocha_install_dir = mocha_executable_path.parent.parent | ||
|
||
if platform.system().lower() == "windows": | ||
mocha_python_path = ( | ||
mocha_install_dir / "python" / "python.exe") | ||
mocha_exporter_path = ( | ||
mocha_install_dir / "python" / "mochaexport.py") | ||
elif platform.system().lower() == "darwin": | ||
mocha_python_path = ( | ||
mocha_install_dir / "python3") | ||
mocha_exporter_path = ( | ||
mocha_install_dir / "mochaexport.py") | ||
elif platform.system().lower() == "linux": | ||
mocha_python_path = ( | ||
mocha_install_dir / "python" / "bin" / "python3") | ||
mocha_exporter_path = ( | ||
mocha_install_dir / "python" / "mochaexport.py") | ||
else: | ||
msg = f"Unsupported platform: {platform.system()}" | ||
raise NotImplementedError(msg) | ||
|
||
context.data["mocha_python_path"] = mocha_python_path | ||
context.data["mocha_exporter_path"] = mocha_exporter_path | ||
|
||
self.log.info("Collected Mocha Pro executable path: %s", | ||
mocha_executable_path) | ||
self.log.info("Collected Mocha Pro python executable path: %s", | ||
mocha_python_path) | ||
self.log.info("Collected Mocha Pro python export script path: %s", | ||
mocha_exporter_path) |
32 changes: 32 additions & 0 deletions
32
client/ayon_mocha/plugins/publish/collect_mocha_project.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Collect the current Mocha Pro project.""" | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, ClassVar | ||
|
||
import pyblish.api | ||
from mocha.project import get_current_project | ||
|
||
if TYPE_CHECKING: | ||
from logging import Logger | ||
|
||
|
||
class CollectMochaProject(pyblish.api.ContextPlugin): | ||
"""Inject the current working file into context. | ||
Foo batr baz. | ||
""" | ||
|
||
order = pyblish.api.CollectorOrder - 0.5 | ||
label = "Collect Mocha Pro Project" | ||
hosts: ClassVar[list[str]] = ["mochapro"] | ||
log: Logger | ||
|
||
def process(self, context: pyblish.api.Context) -> None: | ||
"""Inject the current working file.""" | ||
context.data["project"] = get_current_project() | ||
current_file = context.data["project"].project_file | ||
context.data["currentFile"] = current_file | ||
if not current_file: | ||
self.log.warning( | ||
"Current file is not saved. Save the file before continuing." | ||
) |
Oops, something went wrong.