Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3dsmax: enhance alembic loader update function #4387

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openpype/hosts/max/api/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def publish_callback(self):

def manage_callback(self):
"""Callback to show Scene Manager/Inventory tool."""
host_tools.show_subset_manager(parent=self.main_widget)
host_tools.show_scene_inventory(parent=self.main_widget)

def library_callback(self):
"""Callback to show Library Loader tool."""
Expand Down
23 changes: 22 additions & 1 deletion openpype/hosts/max/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Pipeline tools for OpenPype Houdini integration."""
import os
import logging
from operator import attrgetter

import json

Expand Down Expand Up @@ -141,5 +142,25 @@ def ls() -> list:
if rt.getUserProp(obj, "id") == AVALON_CONTAINER_ID
]

for container in sorted(containers, key=lambda name: container.name):
for container in sorted(containers, key=attrgetter("name")):
yield lib.read(container)


def containerise(name: str, nodes: list, context, loader=None, suffix="_CON"):
data = {
"schema": "openpype:container-2.0",
"id": AVALON_CONTAINER_ID,
"name": name,
"namespace": "",
"loader": loader,
"representation": context["representation"]["_id"],
}

container_name = f"{name}{suffix}"
container = rt.container(name=container_name)
for node in nodes:
node.Parent = container

if not lib.imprint(container_name, data):
print(f"imprinting of {container_name} failed.")
return container
45 changes: 40 additions & 5 deletions openpype/hosts/max/plugins/load/load_pointcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"""
import os
from openpype.pipeline import (
load
load, get_representation_path
)
from openpype.hosts.max.api.pipeline import containerise
from openpype.hosts.max.api import lib


class AbcLoader(load.LoaderPlugin):
Expand Down Expand Up @@ -52,14 +54,47 @@ def load(self, context, name=None, namespace=None, data=None):

abc_container = abc_containers.pop()

container_name = f"{name}_CON"
container = rt.container(name=container_name)
abc_container.Parent = container
return containerise(
name, [abc_container], context, loader=self.__class__.__name__)

return container
def update(self, container, representation):
from pymxs import runtime as rt

path = get_representation_path(representation)
node = rt.getNodeByName(container["instance_node"])

alembic_objects = self.get_container_children(node, "AlembicObject")
for alembic_object in alembic_objects:
alembic_object.source = path

lib.imprint(container["instance_node"], {
"representation": str(representation["_id"])
})

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

def remove(self, container):
from pymxs import runtime as rt

node = container["node"]
rt.delete(node)

@staticmethod
def get_container_children(parent, type_name):
from pymxs import runtime as rt

def list_children(node):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel get_all_children would be a more explicit name?

children = []
for c in node.Children:
children.append(c)
children += list_children(c)
return children

filtered = []
for child in list_children(parent):
class_type = str(rt.classOf(child.baseObject))
if class_type == type_name:
filtered.append(child)

return filtered