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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146 | 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"
# Settings
scale = 1.0
@classmethod
def apply_settings(cls, project_settings: dict) -> None:
"""Apply settings from project settings."""
md_load_setting = (
project_settings["marvelous_designer"]
["load"]
["LoadPointCache"]
)
cls.scale = md_load_setting.get("scale", cls.scale)
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)
def load_options(self, 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":
alembic_options = ApiTypes.ImportAlembicOption()
alembic_options.aScale = self.scale
return alembic_options
if extension in {".fbx", ".obj"}:
import_options = ApiTypes.ImportExportOption()
import_options.scale = self.scale
return import_options
msg = f"Unsupported pointcache format: {extension}"
raise LoadError(msg)
def _get_filepath(self, context: dict) -> str:
"""Gets filepath with either representation trait or context data.
For backward compatibility only.
Args:
context (dict): Context dictionary.
Returns:
str: 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)
return file_path.as_posix()
|
apply_settings(project_settings) classmethod
Apply settings from project settings.
Source code in client/ayon_marvelousdesigner/plugins/load/load_pointcache.py
37
38
39
40
41
42
43
44
45 | @classmethod
def apply_settings(cls, project_settings: dict) -> None:
"""Apply settings from project settings."""
md_load_setting = (
project_settings["marvelous_designer"]
["load"]
["LoadPointCache"]
)
cls.scale = md_load_setting.get("scale", cls.scale)
|
load(context, name=None, namespace=None, options=None)
Load pointcache into the scene.
Source code in client/ayon_marvelousdesigner/plugins/load/load_pointcache.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 | 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)
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
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 | def load_options(self, 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":
alembic_options = ApiTypes.ImportAlembicOption()
alembic_options.aScale = self.scale
return alembic_options
if extension in {".fbx", ".obj"}:
import_options = ApiTypes.ImportExportOption()
import_options.scale = self.scale
return import_options
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
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 | @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)
|