Point cache loader plugin for Marvelous Designer integration.
This module provides LoadPointCache class for loading various point cache formats (ABC, FBX, OBJ) into Marvelous Designer through the AYON pipeline.
LoadPointCache
Bases: LoaderPlugin
Load Pointcache for project.
Source code in client/ayon_marvelousdesigner/plugins/load/load_pointcache.py
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131 | class LoadPointCache(load.LoaderPlugin):
"""Load Pointcache for project."""
product_base_types: ClassVar[set[str]] = {"*"}
product_types: ClassVar[set[str]] = product_base_types
representations: ClassVar[set[str]] = {"abc", "fbx", "obj"}
label = "Load Pointcache"
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."""
file_path = self._get_filepath(context)
extension = os.path.splitext(file_path)[-1].lower()
loaded_options = self.load_options(extension)
self.load_pointcache(file_path, extension, loaded_options)
containerise(
name=name,
namespace=namespace,
context=context,
loader=self
)
@staticmethod
def load_pointcache(
file_path: Path,
extension: str,
options: Union[ApiTypes.ImportAlembicOption,
ApiTypes.ImportExportOption]) -> None:
"""Actual loading logic for pointcache.
Args:
file_path (Path): Path to pointcache file.
extension (str): Extension of pointcache file.
options (ApiTypes.ImportExportOption): Options for loading.
Raises:
LoadError: If the pointcache format is unsupported.
"""
if extension == ".abc":
import_api.ImportAlembic(file_path, options)
elif extension == ".fbx":
import_api.ImportFBX(file_path, options)
elif extension == ".obj":
import_api.ImportOBJ(file_path, options)
else:
msg = f"Unsupported pointcache format: {extension}"
raise LoadError(msg)
@staticmethod
def load_options(extension: str) -> Union[
ApiTypes.ImportAlembicOption, ApiTypes.ImportExportOption]:
"""Return options for loading pointcache.
Args:
extension (str): Extension of pointcache file.
Returns:
Union[
ApiTypes.ImportAlembicOption,
ApiTypes.ImportExportOption]: Options for loading.
Raises:
LoadError: If the pointcache format is unsupported.
"""
if extension == ".abc":
return ApiTypes.ImportAlembicOption()
if extension in {".fbx", ".obj"}:
return ApiTypes.ImportExportOption()
msg = f"Unsupported pointcache format: {extension}"
raise LoadError(msg)
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.
Source code in client/ayon_marvelousdesigner/plugins/load/load_pointcache.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 | def load(self,
context: dict,
name: Optional[str] = None,
namespace: Optional[str] = None,
options: Optional[dict] = None) -> None:
"""Load pointcache into the scene."""
file_path = self._get_filepath(context)
extension = os.path.splitext(file_path)[-1].lower()
loaded_options = self.load_options(extension)
self.load_pointcache(file_path, extension, loaded_options)
containerise(
name=name,
namespace=namespace,
context=context,
loader=self
)
|
load_options(extension) staticmethod
Return options for loading pointcache.
Parameters:
| Name | Type | Description | Default |
extension | str | Extension of pointcache file. | required |
Returns:
| Type | Description |
Union[ImportAlembicOption, ImportExportOption] | Union[ ApiTypes.ImportAlembicOption, ApiTypes.ImportExportOption]: Options for loading. |
Raises:
| Type | Description |
LoadError | If the pointcache format is unsupported. |
Source code in client/ayon_marvelousdesigner/plugins/load/load_pointcache.py
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 | @staticmethod
def load_options(extension: str) -> Union[
ApiTypes.ImportAlembicOption, ApiTypes.ImportExportOption]:
"""Return options for loading pointcache.
Args:
extension (str): Extension of pointcache file.
Returns:
Union[
ApiTypes.ImportAlembicOption,
ApiTypes.ImportExportOption]: Options for loading.
Raises:
LoadError: If the pointcache format is unsupported.
"""
if extension == ".abc":
return ApiTypes.ImportAlembicOption()
if extension in {".fbx", ".obj"}:
return ApiTypes.ImportExportOption()
msg = f"Unsupported pointcache format: {extension}"
raise LoadError(msg)
|
load_pointcache(file_path, extension, options) staticmethod
Actual loading logic for pointcache.
Parameters:
| Name | Type | Description | Default |
file_path | Path | | required |
extension | str | Extension of pointcache file. | required |
options | ImportExportOption | | required |
Raises:
| Type | Description |
LoadError | If the pointcache format is unsupported. |
Source code in client/ayon_marvelousdesigner/plugins/load/load_pointcache.py
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 | @staticmethod
def load_pointcache(
file_path: Path,
extension: str,
options: Union[ApiTypes.ImportAlembicOption,
ApiTypes.ImportExportOption]) -> None:
"""Actual loading logic for pointcache.
Args:
file_path (Path): Path to pointcache file.
extension (str): Extension of pointcache file.
options (ApiTypes.ImportExportOption): Options for loading.
Raises:
LoadError: If the pointcache format is unsupported.
"""
if extension == ".abc":
import_api.ImportAlembic(file_path, options)
elif extension == ".fbx":
import_api.ImportFBX(file_path, options)
elif extension == ".obj":
import_api.ImportOBJ(file_path, options)
else:
msg = f"Unsupported pointcache format: {extension}"
raise LoadError(msg)
|