update on the ornatrix laoder

This commit is contained in:
Kayla Man 2023-09-04 20:32:16 +08:00
parent 35feb0dfec
commit 8440d65949
2 changed files with 38 additions and 59 deletions

View file

@ -15,10 +15,8 @@ from openpype.pipeline import (
)
from openpype.hosts.max.api.menu import OpenPypeMenu
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 pymxs import runtime as rt # noqa
log = logging.getLogger("openpype.hosts.max")
@ -173,52 +171,3 @@ def containerise(name: str, nodes: list, context,
if not lib.imprint(container_name, data):
print(f"imprinting of {container_name} failed.")
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)

View file

@ -1,6 +1,15 @@
import os
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 pymxs import runtime as rt
@ -14,6 +23,7 @@ class OxAbcLoader(load.LoaderPlugin):
order = -10
icon = "code-fork"
color = "orange"
postfix = "param"
def load(self, context, name=None, namespace=None, data=None):
plugin_list = get_plugins()
@ -34,21 +44,37 @@ class OxAbcLoader(load.LoaderPlugin):
if str(obj_type).startswith("Ox_"):
scene_object.append(obj)
abc_container = rt.Container(name=name)
namespace = unique_namespace(
name + "_",
suffix="_",
)
abc_container = rt.Container()
for abc in scene_object:
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(
name, [abc_container], context, loader=self.__class__.__name__
name, [abc_container], context,
namespace, loader=self.__class__.__name__
)
def update(self, container, representation):
path = get_representation_path(representation)
node_name = container["instance_node"]
instance_name, _ = os.path.splitext(node_name)
container = rt.getNodeByName(instance_name)
for children in container.Children:
rt.Delete(children)
namespace, name = get_namespace(node_name)
sub_node_name = f"{namespace}:{name}_{self.postfix}"
inst_container = rt.getNodeByName(sub_node_name)
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.CustomAttributes = True
@ -61,9 +87,13 @@ class OxAbcLoader(load.LoaderPlugin):
obj_type = rt.ClassOf(obj)
if str(obj_type).startswith("Ox_"):
scene_object.append(obj)
update_custom_attribute_data(
inst_container, scene_object.Children)
for abc in scene_object:
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(
container["instance_node"],