Skip to content

load_pointcache_ornatrix

OxAbcLoader

Bases: LoaderPlugin

Ornatrix Alembic loader.

Source code in client/ayon_max/plugins/load/load_pointcache_ornatrix.py
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
class OxAbcLoader(load.LoaderPlugin):
    """Ornatrix Alembic loader."""

    product_types = {"camera", "animation", "pointcache"}
    label = "Load Alembic with Ornatrix"
    representations = {"abc"}
    order = -10
    icon = "code-fork"
    color = "orange"
    postfix = "param"

    def load(self, context, name=None, namespace=None, data=None):
        plugin_list = get_plugins()
        if "ephere.plugins.autodesk.max.ornatrix.dlo" not in plugin_list:
            raise LoadError("Ornatrix plugin not "
                            "found/installed in Max yet..")

        file_path = os.path.normpath(self.filepath_from_context(context))
        rt.AlembicImport.ImportToRoot = True
        rt.AlembicImport.CustomAttributes = True
        rt.importFile(
            file_path, rt.name("noPrompt"),
            using=rt.Ornatrix_Alembic_Importer)

        scene_object = []
        for obj in rt.rootNode.Children:
            obj_type = rt.ClassOf(obj)
            if str(obj_type).startswith("Ox_"):
                scene_object.append(obj)

        namespace = unique_namespace(
            name + "_",
            suffix="_",
        )
        abc_container = []
        for abc in scene_object:
            abc.name = f"{namespace}:{abc.name}"
            abc_container.append(abc)

        return containerise(
            name, abc_container, context,
            namespace, loader=self.__class__.__name__
        )

    def update(self, container, context):
        repre_entity = context["representation"]
        path = os.path.normpath(self.filepath_from_context(context))
        node_name = container["instance_node"]
        namespace, name = get_namespace(node_name)
        node = rt.getNodeByName(node_name)
        node_list = get_previous_loaded_object(node)
        rt.Select(node_list)
        selections = rt.getCurrentSelection()
        transform_data = object_transform_set(selections)
        for prev_obj in selections:
            if rt.isValidNode(prev_obj):
                rt.Delete(prev_obj)

        rt.AlembicImport.ImportToRoot = False
        rt.AlembicImport.CustomAttributes = True
        rt.importFile(
            path, rt.name("noPrompt"),
            using=rt.Ornatrix_Alembic_Importer)

        scene_object = []
        for obj in rt.rootNode.Children:
            obj_type = rt.ClassOf(obj)
            if str(obj_type).startswith("Ox_"):
                scene_object.append(obj)
        ox_abc_objects = []
        for abc in scene_object:
            abc.Parent = container
            abc.name = f"{namespace}:{abc.name}"
            ox_abc_objects.append(abc)
            ox_transform = f"{abc}.transform"
            if ox_transform in transform_data.keys():
                abc.pos = transform_data[ox_transform] or 0
                abc.scale = transform_data[f"{abc}.scale"] or 0
        update_custom_attribute_data(node, ox_abc_objects)
        lib.imprint(container["instance_node"], {
            "representation": repre_entity["id"],
            "project_name": context["project"]["name"]
        })

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

    def remove(self, container):
        from pymxs import runtime as rt
        node = rt.GetNodeByName(container["instance_node"])
        remove_container_data(node)