mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
update on the ornatrix laoder
This commit is contained in:
parent
35feb0dfec
commit
8440d65949
2 changed files with 38 additions and 59 deletions
|
|
@ -15,10 +15,8 @@ from openpype.pipeline import (
|
||||||
)
|
)
|
||||||
from openpype.hosts.max.api.menu import OpenPypeMenu
|
from openpype.hosts.max.api.menu import OpenPypeMenu
|
||||||
from openpype.hosts.max.api import lib
|
from openpype.hosts.max.api import lib
|
||||||
from openpype.hosts.max.api.plugin import MS_CUSTOM_ATTRIB
|
|
||||||
from openpype.hosts.max import MAX_HOST_DIR
|
from openpype.hosts.max import MAX_HOST_DIR
|
||||||
|
|
||||||
|
|
||||||
from pymxs import runtime as rt # noqa
|
from pymxs import runtime as rt # noqa
|
||||||
|
|
||||||
log = logging.getLogger("openpype.hosts.max")
|
log = logging.getLogger("openpype.hosts.max")
|
||||||
|
|
@ -173,52 +171,3 @@ def containerise(name: str, nodes: list, context,
|
||||||
if not lib.imprint(container_name, data):
|
if not lib.imprint(container_name, data):
|
||||||
print(f"imprinting of {container_name} failed.")
|
print(f"imprinting of {container_name} failed.")
|
||||||
return container
|
return container
|
||||||
|
|
||||||
|
|
||||||
def load_custom_attribute_data():
|
|
||||||
"""Re-loading the Openpype/AYON custom parameter built by the creator
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
attribute: re-loading the custom OP attributes set in Maxscript
|
|
||||||
"""
|
|
||||||
return rt.Execute(MS_CUSTOM_ATTRIB)
|
|
||||||
|
|
||||||
|
|
||||||
def import_custom_attribute_data(container: str, selections: list):
|
|
||||||
"""Importing the Openpype/AYON custom parameter built by the creator
|
|
||||||
|
|
||||||
Args:
|
|
||||||
container (str): target container which adds custom attributes
|
|
||||||
selections (list): nodes to be added into
|
|
||||||
group in custom attributes
|
|
||||||
"""
|
|
||||||
attrs = load_custom_attribute_data()
|
|
||||||
modifier = rt.EmptyModifier()
|
|
||||||
rt.addModifier(container, modifier)
|
|
||||||
container.modifiers[0].name = "OP Data"
|
|
||||||
rt.custAttributes.add(container.modifiers[0], attrs)
|
|
||||||
nodes = {}
|
|
||||||
for i in selections:
|
|
||||||
nodes = {
|
|
||||||
str(i): rt.NodeTransformMonitor(node=i),
|
|
||||||
}
|
|
||||||
# Setting the property
|
|
||||||
rt.setProperty(
|
|
||||||
container.modifiers[0].openPypeData,
|
|
||||||
"all_handles", nodes.values())
|
|
||||||
rt.setProperty(
|
|
||||||
container.modifiers[0].openPypeData,
|
|
||||||
"sel_list", nodes.keys())
|
|
||||||
|
|
||||||
|
|
||||||
def update_custom_attribute_data(container: str, selections: list):
|
|
||||||
"""Updating the Openpype/AYON custom parameter built by the creator
|
|
||||||
|
|
||||||
Args:
|
|
||||||
container (str): target container which adds custom attributes
|
|
||||||
selections (list): nodes to be added into
|
|
||||||
group in custom attributes
|
|
||||||
"""
|
|
||||||
if container.modifiers[0].name == "OP Data":
|
|
||||||
rt.deleteModifier(container, container.modifiers[0])
|
|
||||||
import_custom_attribute_data(container, selections)
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,15 @@
|
||||||
import os
|
import os
|
||||||
from openpype.pipeline import load, get_representation_path
|
from openpype.pipeline import load, get_representation_path
|
||||||
from openpype.hosts.max.api.pipeline import containerise
|
from openpype.hosts.max.api.pipeline import (
|
||||||
|
containerise,
|
||||||
|
import_custom_attribute_data,
|
||||||
|
update_custom_attribute_data
|
||||||
|
)
|
||||||
|
from openpype.hosts.max.api.lib import (
|
||||||
|
unique_namespace,
|
||||||
|
get_namespace,
|
||||||
|
object_transform_set
|
||||||
|
)
|
||||||
from openpype.hosts.max.api import lib
|
from openpype.hosts.max.api import lib
|
||||||
from pymxs import runtime as rt
|
from pymxs import runtime as rt
|
||||||
|
|
||||||
|
|
@ -14,6 +23,7 @@ class OxAbcLoader(load.LoaderPlugin):
|
||||||
order = -10
|
order = -10
|
||||||
icon = "code-fork"
|
icon = "code-fork"
|
||||||
color = "orange"
|
color = "orange"
|
||||||
|
postfix = "param"
|
||||||
|
|
||||||
def load(self, context, name=None, namespace=None, data=None):
|
def load(self, context, name=None, namespace=None, data=None):
|
||||||
plugin_list = get_plugins()
|
plugin_list = get_plugins()
|
||||||
|
|
@ -34,21 +44,37 @@ class OxAbcLoader(load.LoaderPlugin):
|
||||||
if str(obj_type).startswith("Ox_"):
|
if str(obj_type).startswith("Ox_"):
|
||||||
scene_object.append(obj)
|
scene_object.append(obj)
|
||||||
|
|
||||||
abc_container = rt.Container(name=name)
|
namespace = unique_namespace(
|
||||||
|
name + "_",
|
||||||
|
suffix="_",
|
||||||
|
)
|
||||||
|
|
||||||
|
abc_container = rt.Container()
|
||||||
for abc in scene_object:
|
for abc in scene_object:
|
||||||
abc.Parent = abc_container
|
abc.Parent = abc_container
|
||||||
|
abc.name = f"{namespace}:{abc.name}"
|
||||||
|
# rename the abc container with namespace
|
||||||
|
abc_container_name = f"{namespace}:{name}_{self.postfix}"
|
||||||
|
abc_container.name = abc_container_name
|
||||||
|
import_custom_attribute_data(
|
||||||
|
abc_container, abc_container.Children)
|
||||||
|
|
||||||
return containerise(
|
return containerise(
|
||||||
name, [abc_container], context, loader=self.__class__.__name__
|
name, [abc_container], context,
|
||||||
|
namespace, loader=self.__class__.__name__
|
||||||
)
|
)
|
||||||
|
|
||||||
def update(self, container, representation):
|
def update(self, container, representation):
|
||||||
path = get_representation_path(representation)
|
path = get_representation_path(representation)
|
||||||
node_name = container["instance_node"]
|
node_name = container["instance_node"]
|
||||||
instance_name, _ = os.path.splitext(node_name)
|
namespace, name = get_namespace(node_name)
|
||||||
container = rt.getNodeByName(instance_name)
|
sub_node_name = f"{namespace}:{name}_{self.postfix}"
|
||||||
for children in container.Children:
|
inst_container = rt.getNodeByName(sub_node_name)
|
||||||
rt.Delete(children)
|
rt.Select(inst_container.Children)
|
||||||
|
transform_data = object_transform_set(inst_container.Children)
|
||||||
|
for prev_obj in rt.selection:
|
||||||
|
if rt.isValidNode(prev_obj):
|
||||||
|
rt.Delete(prev_obj)
|
||||||
|
|
||||||
rt.AlembicImport.ImportToRoot = False
|
rt.AlembicImport.ImportToRoot = False
|
||||||
rt.AlembicImport.CustomAttributes = True
|
rt.AlembicImport.CustomAttributes = True
|
||||||
|
|
@ -61,9 +87,13 @@ class OxAbcLoader(load.LoaderPlugin):
|
||||||
obj_type = rt.ClassOf(obj)
|
obj_type = rt.ClassOf(obj)
|
||||||
if str(obj_type).startswith("Ox_"):
|
if str(obj_type).startswith("Ox_"):
|
||||||
scene_object.append(obj)
|
scene_object.append(obj)
|
||||||
|
update_custom_attribute_data(
|
||||||
|
inst_container, scene_object.Children)
|
||||||
for abc in scene_object:
|
for abc in scene_object:
|
||||||
abc.Parent = container
|
abc.Parent = container
|
||||||
|
abc.name = f"{namespace}:{abc.name}"
|
||||||
|
abc.pos = transform_data[f"{abc.name}.transform"]
|
||||||
|
abc.scale = transform_data[f"{abc.name}.scale"]
|
||||||
|
|
||||||
lib.imprint(
|
lib.imprint(
|
||||||
container["instance_node"],
|
container["instance_node"],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue