142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249 | class SubstanceLoadProjectMesh(load.LoaderPlugin):
"""Load mesh for project"""
product_types = {"*"}
representations = {"abc", "fbx", "obj", "gltf", "usd", "usda", "usdc"}
label = "Load mesh"
order = -10
icon = "code-fork"
color = "orange"
# Defined via settings
project_templates = []
def load(self, context, name, namespace, options=None):
# Get user inputs
result = SubstanceProjectConfigurationWindow.prompt(
self.project_templates)
if not result:
# cancelling loader action
return
if not substance_painter.project.is_open():
# Allow to 'initialize' a new project
path = self.filepath_from_context(context)
sp_settings = substance_painter.project.Settings(
import_cameras=result["import_cameras"],
normal_map_format=result["normal_map_format"],
project_workflow=result["project_workflow"],
tangent_space_mode=result["tangent_space_mode"],
default_texture_resolution=result["default_texture_resolution"]
)
settings = substance_painter.project.create(
mesh_file_path=path, settings=sp_settings
)
else:
# Reload the mesh
settings = substance_painter.project.MeshReloadingSettings(
import_cameras=result["import_cameras"],
preserve_strokes=result["preserve_strokes"])
def on_mesh_reload(status: substance_painter.project.ReloadMeshStatus): # noqa
if status == substance_painter.project.ReloadMeshStatus.SUCCESS: # noqa
self.log.info("Reload succeeded")
else:
raise LoadError("Reload of mesh failed")
path = self.filepath_from_context(context)
substance_painter.project.reload_mesh(path,
settings,
on_mesh_reload)
# Store container
container = {}
project_mesh_object_name = "_ProjectMesh_"
imprint_container(container,
name=project_mesh_object_name,
namespace=project_mesh_object_name,
context=context,
loader=self)
# We want store some options for updating to keep consistent behavior
# from the user's original choice. We don't store 'preserve_strokes'
# as we always preserve strokes on updates.
container["options"] = {
"import_cameras": result["import_cameras"],
}
set_container_metadata(project_mesh_object_name, container)
def switch(self, container, context):
self.update(container, context)
def update(self, container, context):
repre_entity = context["representation"]
path = get_representation_path(repre_entity)
# Reload the mesh
container_options = container.get("options", {})
settings = substance_painter.project.MeshReloadingSettings(
import_cameras=container_options.get("import_cameras", True),
preserve_strokes=True
)
def on_mesh_reload(status: substance_painter.project.ReloadMeshStatus):
if status == substance_painter.project.ReloadMeshStatus.SUCCESS:
self.log.info("Reload succeeded")
else:
raise LoadError("Reload of mesh failed")
substance_painter.project.reload_mesh(path, settings, on_mesh_reload)
# Update container representation
object_name = container["objectName"]
update_data = {
"representation": repre_entity["id"],
"project_name": context["project"]["name"]
}
set_container_metadata(object_name, update_data, update=True)
def remove(self, container):
# Remove OpenPype related settings about what model was loaded
# or close the project?
# TODO: This is likely best 'hidden' away to the user because
# this will leave the project's mesh unmanaged.
remove_container_metadata(container["objectName"])
|