Skip to content

load_zfab

Plugin to load ZFab files into Marvelous Designer.

LoadZfab

Bases: LoaderPlugin

Load ZFab for project.

Source code in client/ayon_marvelousdesigner/plugins/load/load_zfab.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
class LoadZfab(load.LoaderPlugin):
    """Load ZFab for project."""
    product_base_types: ClassVar[set[str]] = {"zfab"}
    product_types: ClassVar[set[str]] = product_base_types
    representations: ClassVar[set[str]] = {"zfab"}

    label = "Load ZFab"
    order = -10
    icon = "code-fork"
    color = "orange"

    def load(
            self,
            context: dict,
            name: Optional[str] = None,
            namespace: Optional[str] = None,
            options: Optional[dict] = None) -> None:
        """Load pointcache into the scene.

        Args:
            context (dict): Context dictionary with representation info.
            name (str): Name of the container.
            namespace (str): Namespace for the loaded data.
            options (dict): Additional options for loading.

        """
        file_path = self._get_filepath(context)

        fabric_index = fabric_api.AddFabric(file_path)
        containerise(
            name=name,
            namespace=namespace,
            context=context,
            loader=self,
            options={"fabricIndex": fabric_index}
        )

    def update(self, container: dict, context: dict) -> None:
        """Update loaded zfab in the scene.

        Args:
            container (dict): Container data.
            context (dict): Context dictionary with representation info.

        """
        file_path = self._get_filepath(context)

        fabric_index = container.get("fabricIndex")
        if fabric_index is not None:
            fabric_api.ReplaceFabric(fabric_index, file_path.as_posix())
        imprint(container["objectName"], {
            "representation": context["representation"]["id"],
        })

    def remove(self, container: dict) -> None:  # noqa: PLR6301
        """Remove loaded zfab from the scene."""
        fabric_index = container.get("fabricIndex")
        if fabric_index is not None:
            fabric_api.DeleteFabric(fabric_index)

        remove_container_data(container["objectName"])

    def _get_filepath(self, context: dict) -> Path:
        """Gets filepath with either representation trait or context data.

        For backward compatibility only.

        Args:
            context (dict): Context dictionary.

        Returns:
            Path: File path to load.

        """
        traits_raw = context["representation"].get("traits")
        if traits_raw is not None:
            # construct Representation object from the context
            representation = Representation.from_dict(
                name=context["representation"]["name"],
                representation_id=context["representation"]["id"],
                trait_data=json.loads(traits_raw),
            )

            file_path: Path = representation.get_trait(FileLocation).file_path
        else:
            filepath = self.filepath_from_context(context)
            file_path = Path(filepath).as_posix()

        return file_path

load(context, name=None, namespace=None, options=None)

Load pointcache into the scene.

Parameters:

Name Type Description Default
context dict

Context dictionary with representation info.

required
name str

Name of the container.

None
namespace str

Namespace for the loaded data.

None
options dict

Additional options for loading.

None
Source code in client/ayon_marvelousdesigner/plugins/load/load_zfab.py
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
def load(
        self,
        context: dict,
        name: Optional[str] = None,
        namespace: Optional[str] = None,
        options: Optional[dict] = None) -> None:
    """Load pointcache into the scene.

    Args:
        context (dict): Context dictionary with representation info.
        name (str): Name of the container.
        namespace (str): Namespace for the loaded data.
        options (dict): Additional options for loading.

    """
    file_path = self._get_filepath(context)

    fabric_index = fabric_api.AddFabric(file_path)
    containerise(
        name=name,
        namespace=namespace,
        context=context,
        loader=self,
        options={"fabricIndex": fabric_index}
    )

remove(container)

Remove loaded zfab from the scene.

Source code in client/ayon_marvelousdesigner/plugins/load/load_zfab.py
75
76
77
78
79
80
81
def remove(self, container: dict) -> None:  # noqa: PLR6301
    """Remove loaded zfab from the scene."""
    fabric_index = container.get("fabricIndex")
    if fabric_index is not None:
        fabric_api.DeleteFabric(fabric_index)

    remove_container_data(container["objectName"])

update(container, context)

Update loaded zfab in the scene.

Parameters:

Name Type Description Default
container dict

Container data.

required
context dict

Context dictionary with representation info.

required
Source code in client/ayon_marvelousdesigner/plugins/load/load_zfab.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def update(self, container: dict, context: dict) -> None:
    """Update loaded zfab in the scene.

    Args:
        container (dict): Container data.
        context (dict): Context dictionary with representation info.

    """
    file_path = self._get_filepath(context)

    fabric_index = container.get("fabricIndex")
    if fabric_index is not None:
        fabric_api.ReplaceFabric(fabric_index, file_path.as_posix())
    imprint(container["objectName"], {
        "representation": context["representation"]["id"],
    })