Skip to content

load_pointcache

PointCacheLoader

Bases: LoaderPlugin

Motion Builder Point Cache Loader.

Source code in client/ayon_motionbuilder/plugins/load/load_pointcache.py
17
18
19
20
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
class PointCacheLoader(load.LoaderPlugin):
    """Motion Builder Point Cache Loader."""

    product_types = {"model", "animation", "rig", "camera"}
    representations = {"fbx"}
    order = -9
    icon = "code-fork"
    color = "white"

    def load(self, context, name=None, namespace=None, data=None):
        app = FBApplication()
        loadOptions = FBFbxOptions(True)
        loadOptions.SetAll(FBElementAction.kFBElementActionAppend, True)
        namespace = unique_namespace(name + "_", suffix="_")
        namespace_list = FBStringList(namespace)
        loadOptions.SetMultiLoadNamespaceList(namespace_list)
        filename = self.filepath_from_context(context)
        app.FileAppend(filename, True, loadOptions)
        component_List = FBComponentList()
        FBFindObjectsByName(( f"{namespace}:*"), component_List, True, False)
        objects = [obj for obj in component_List]
        return containerise(
            name, context, objects, namespace=namespace,
            loader=self.__class__.__name__
        )

    def update(self, container, context):
        app = FBApplication()
        repre_entity = context["representation"]
        namespace = container["namespace"]
        path = get_representation_path(repre_entity)
        loadOptions = FBFbxOptions(True)
        namespace_list = FBStringList(namespace)
        loadOptions.SetMultiLoadNamespaceList(namespace_list)
        current_file = app.FBXFileName
        merged_filepath = FBStringList(f"{current_file}~{path}" )
        loadOptions.SetAll(FBElementAction.kFBElementActionAppend, True)
        app.FileMerge(merged_filepath, True, loadOptions)
        imprint_repres = {
            "containers": {"representation": repre_entity["id"]}
        }
        imprint(container["instance_node"], imprint_repres, update_asset=True)

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

    def remove(self, container):
        namespace = container["namespace"]
        component_List = FBComponentList()
        container_node = container["instance_node"]
        # Remove container in scene inventory
        try:
            node = get_node_by_name(container_node)
            node.FBDelete()
            # Remove the connected object to the container
            FBFindObjectsByName(f"{namespace}:*", component_List, True, False)
            objects = [obj for obj in component_List]
            for obj in objects:
                if obj in FBSystem().Scene.Components:
                    obj.FBDelete()
            # clear unused namespace
            if FBSystem().Scene.NamespaceEmpty(namespace):
                FBSystem().Scene.NamespaceDelete(namespace)
        except Exception:
            pass