fixing the bug of not being able to update the scene when using maxSceneloader and some clean up

This commit is contained in:
Kayla Man 2023-08-16 21:37:49 +08:00
parent ae42d524c8
commit 8aa150cfe5
6 changed files with 46 additions and 41 deletions

View file

@ -45,12 +45,11 @@ class FbxLoader(load.LoaderPlugin):
from pymxs import runtime as rt
path = get_representation_path(representation)
node = rt.GetNodeByName(container["instance_node"])
inst_name, _ = os.path.split(container["instance_node"])
container = rt.getNodeByName(inst_name)
node_name = container["instance_node"]
node = rt.getNodeByName(node_name)
inst_name, _ = node_name.split("_")
rt.Select(node.Children)
update_custom_attribute_data(
container, rt.GetCurrentSelection())
rt.FBXImporterSetParam("Animation", True)
rt.FBXImporterSetParam("Camera", True)
rt.FBXImporterSetParam("Mode", rt.Name("merge"))
@ -58,7 +57,9 @@ class FbxLoader(load.LoaderPlugin):
rt.FBXImporterSetParam("Preserveinstances", True)
rt.ImportFile(
path, rt.name("noPrompt"), using=rt.FBXIMP)
inst_container = rt.getNodeByName(inst_name)
update_custom_attribute_data(
inst_container, rt.GetCurrentSelection())
with maintained_selection():
rt.Select(node)

View file

@ -42,27 +42,28 @@ class MaxSceneLoader(load.LoaderPlugin):
path = get_representation_path(representation)
node_name = container["instance_node"]
node = rt.GetNodeByName(node_name)
inst_name, _ = os.path.splitext(node_name)
old_container = rt.getNodeByName(inst_name)
prev_max_objects = rt.getLastMergedNodes()
node = rt.getNodeByName(node_name)
inst_name, _ = node_name.split("_")
inst_container = rt.getNodeByName(inst_name)
# delete the old container with attribute
# delete old duplicate
rt.Delete(old_container)
prev_max_object_names = [obj.name for obj in rt.getLastMergedNodes()]
rt.MergeMaxFile(path, rt.Name("deleteOldDups"))
new_container = rt.Container(name=inst_name)
current_max_objects = rt.getLastMergedNodes()
for current_object in current_max_objects:
prev_max_objects = prev_max_objects.remove(current_object)
for prev_object in prev_max_objects:
rt.Delete(prev_object)
max_objects_list = []
max_objects_list.append(new_container)
max_objects_list.extend(current_max_objects)
for max_object in max_objects_list:
current_max_objects = rt.getLastMergedNodes()
current_max_object_names = [obj.name for obj in rt.getLastMergedNodes()]
for obj in current_max_object_names:
idx = rt.findItem(prev_max_object_names, obj)
if idx:
prev_max_object_names = rt.deleteItem(prev_max_object_names, idx)
for object_name in prev_max_object_names:
prev_max_object = rt.getNodeByName(object_name)
rt.Delete(prev_max_object)
update_custom_attribute_data(inst_container, current_max_objects)
for max_object in current_max_objects:
max_object.Parent = node
update_custom_attribute_data(new_container, current_max_objects)
lib.imprint(container["instance_node"], {
"representation": str(representation["_id"])
})

View file

@ -70,9 +70,9 @@ class ModelAbcLoader(load.LoaderPlugin):
update_custom_attribute_data(abc, abc.Children)
rt.Select(abc.Children)
for abc_con in rt.Selection:
container = rt.GetNodeByName(abc_con.name)
container.source = path
rt.Select(container.Children)
abc_container = rt.GetNodeByName(abc_con.name)
abc_container.source = path
rt.Select(abc_container.Children)
for abc_obj in rt.Selection:
alembic_obj = rt.GetNodeByName(abc_obj.name)
alembic_obj.source = path

View file

@ -26,7 +26,10 @@ class FbxModelLoader(load.LoaderPlugin):
rt.FBXImporterSetParam("Preserveinstances", True)
rt.importFile(filepath, rt.name("noPrompt"), using=rt.FBXIMP)
container = rt.GetNodeByName(name)
container = rt.Container(name=name)
selections = rt.GetCurrentSelection()
import_custom_attribute_data(container, selections)
@ -40,8 +43,9 @@ class FbxModelLoader(load.LoaderPlugin):
def update(self, container, representation):
from pymxs import runtime as rt
path = get_representation_path(representation)
node = rt.getNodeByName(container["instance_node"])
inst_name, _ = os.path.splitext(container["instance_node"])
node_name = container["instance_node"]
node = rt.getNodeByName(node_name)
inst_name, _ = node_name.split("_")
rt.select(node.Children)
rt.FBXImporterSetParam("Animation", False)
@ -52,14 +56,14 @@ class FbxModelLoader(load.LoaderPlugin):
rt.FBXImporterSetParam("Preserveinstances", True)
rt.importFile(path, rt.name("noPrompt"), using=rt.FBXIMP)
container = rt.getNodeByName(inst_name)
inst_container = rt.getNodeByName(inst_name)
update_custom_attribute_data(
container, rt.GetCurrentSelection())
inst_container, rt.GetCurrentSelection())
with maintained_selection():
rt.Select(node)
lib.imprint(
container["instance_node"],
node_name,
{"representation": str(representation["_id"])},
)

View file

@ -33,7 +33,6 @@ class ObjLoader(load.LoaderPlugin):
# get current selection
for selection in selections:
selection.Parent = container
self.log.debug(f"{container.ClassID}")
return containerise(
name, [container], context, loader=self.__class__.__name__)
@ -46,7 +45,7 @@ class ObjLoader(load.LoaderPlugin):
node = rt.GetNodeByName(node_name)
instance_name, _ = node_name.split("_")
container = rt.GetNodeByName(instance_name)
inst_container = rt.GetNodeByName(instance_name)
for child in container.Children:
rt.Delete(child)
@ -54,8 +53,8 @@ class ObjLoader(load.LoaderPlugin):
# get current selection
selections = rt.GetCurrentSelection()
for selection in selections:
selection.Parent = container
update_custom_attribute_data(container, selections)
selection.Parent = inst_container
update_custom_attribute_data(inst_container, selections)
with maintained_selection():
rt.Select(node)

View file

@ -70,10 +70,6 @@ class AbcLoader(load.LoaderPlugin):
path = get_representation_path(representation)
node = rt.GetNodeByName(container["instance_node"])
lib.imprint(
container["instance_node"],
{"representation": str(representation["_id"])},
)
nodes_list = []
with maintained_selection():
rt.Select(node.Children)
@ -83,14 +79,18 @@ class AbcLoader(load.LoaderPlugin):
update_custom_attribute_data(abc, abc.Children)
rt.Select(abc.Children)
for abc_con in rt.Selection:
container = rt.GetNodeByName(abc_con.name)
container.source = path
rt.Select(container.Children)
abc_container = rt.GetNodeByName(abc_con.name)
abc_container.source = path
rt.Select(abc_container.Children)
for abc_obj in rt.Selection:
alembic_obj = rt.GetNodeByName(abc_obj.name)
alembic_obj.source = path
nodes_list.append(alembic_obj)
lib.imprint(
container["instance_node"],
{"representation": str(representation["_id"])},
)
def switch(self, container, representation):
self.update(container, representation)