blender using representation entity

This commit is contained in:
Jakub Trllo 2024-03-08 12:36:48 +01:00
parent 3467727f11
commit 9acedf2201
13 changed files with 102 additions and 94 deletions

View file

@ -484,7 +484,7 @@ def containerise(name: str,
"name": name,
"namespace": namespace or '',
"loader": str(loader),
"representation": str(context["representation"]["_id"]),
"representation": context["representation"]["id"],
}
metadata_update(container, data)
@ -523,7 +523,7 @@ def containerise_existing(
"name": name,
"namespace": namespace or '',
"loader": str(loader),
"representation": str(context["representation"]["_id"]),
"representation": context["representation"]["id"],
}
metadata_update(container, data)

View file

@ -168,10 +168,10 @@ class CacheModelLoader(plugin.AssetLoader):
"name": name,
"namespace": namespace or '',
"loader": str(self.__class__.__name__),
"representation": str(context["representation"]["_id"]),
"representation": context["representation"]["id"],
"libpath": libpath,
"asset_name": asset_name,
"parent": str(context["representation"]["parent"]),
"parent": context["representation"]["versionId"],
"productType": product_type,
"objectName": group_name
}
@ -191,16 +191,16 @@ class CacheModelLoader(plugin.AssetLoader):
Warning:
No nested collections are supported at the moment!
"""
repre_doc = context["representation"]
repre_entity = context["representation"]
object_name = container["objectName"]
asset_group = bpy.data.objects.get(object_name)
libpath = Path(get_representation_path(repre_doc))
libpath = Path(get_representation_path(repre_entity))
extension = libpath.suffix.lower()
self.log.info(
"Container: %s\nRepresentation: %s",
pformat(container, indent=2),
pformat(repre_doc, indent=2),
pformat(repre_entity, indent=2),
)
assert asset_group, (
@ -245,7 +245,7 @@ class CacheModelLoader(plugin.AssetLoader):
asset_group.matrix_basis = mat
metadata["libpath"] = str(libpath)
metadata["representation"] = str(repre_doc["_id"])
metadata["representation"] = repre_entity["id"]
def exec_remove(self, container: Dict) -> bool:
"""Remove an existing container from a Blender scene.

View file

@ -126,18 +126,18 @@ class BlendActionLoader(plugin.AssetLoader):
Warning:
No nested collections are supported at the moment!
"""
repre_doc = context["representation"]
repre_entity = context["representation"]
collection = bpy.data.collections.get(
container["objectName"]
)
libpath = Path(get_representation_path(repre_doc))
libpath = Path(get_representation_path(repre_entity))
extension = libpath.suffix.lower()
logger.info(
"Container: %s\nRepresentation: %s",
pformat(container, indent=2),
pformat(repre_doc, indent=2),
pformat(repre_entity, indent=2),
)
assert collection, (
@ -241,7 +241,7 @@ class BlendActionLoader(plugin.AssetLoader):
# Save the list of objects in the metadata container
collection_metadata["objects"] = objects_list
collection_metadata["libpath"] = str(libpath)
collection_metadata["representation"] = str(repre_doc["_id"])
collection_metadata["representation"] = repre_entity["id"]
bpy.ops.object.select_all(action='DESELECT')

View file

@ -83,10 +83,10 @@ class AudioLoader(plugin.AssetLoader):
"name": name,
"namespace": namespace or '',
"loader": str(self.__class__.__name__),
"representation": str(context["representation"]["_id"]),
"representation": context["representation"]["id"],
"libpath": libpath,
"asset_name": asset_name,
"parent": str(context["representation"]["parent"]),
"parent": context["representation"]["versionId"],
"productType": context["product"]["productType"],
"objectName": group_name,
"audio": audio
@ -105,15 +105,15 @@ class AudioLoader(plugin.AssetLoader):
representation (openpype:representation-1.0): Representation to
update, from `host.ls()`.
"""
repre_doc = context["representation"]
repre_entity = context["representation"]
object_name = container["objectName"]
asset_group = bpy.data.objects.get(object_name)
libpath = Path(get_representation_path(repre_doc))
libpath = Path(get_representation_path(repre_entity))
self.log.info(
"Container: %s\nRepresentation: %s",
pformat(container, indent=2),
pformat(repre_doc, indent=2),
pformat(repre_entity, indent=2),
)
assert asset_group, (
@ -176,8 +176,8 @@ class AudioLoader(plugin.AssetLoader):
window_manager.windows[-1].screen.areas[0].type = old_type
metadata["libpath"] = str(libpath)
metadata["representation"] = str(repre_doc["_id"])
metadata["parent"] = str(repre_doc["parent"])
metadata["representation"] = repre_entity["id"]
metadata["parent"] = repre_entity["versionId"]
metadata["audio"] = new_audio
def exec_remove(self, container: Dict) -> bool:

View file

@ -135,7 +135,7 @@ class BlendLoader(plugin.AssetLoader):
except ValueError:
product_type = "model"
representation = str(context["representation"]["_id"])
representation = context["representation"]["id"]
asset_name = plugin.prepare_scene_name(folder_name, product_name)
unique_number = plugin.get_unique_number(folder_name, product_name)
@ -162,10 +162,10 @@ class BlendLoader(plugin.AssetLoader):
"name": name,
"namespace": namespace or '',
"loader": str(self.__class__.__name__),
"representation": str(context["representation"]["_id"]),
"representation": context["representation"]["id"],
"libpath": libpath,
"asset_name": asset_name,
"parent": str(context["representation"]["parent"]),
"parent": context["representation"]["versionId"],
"productType": context["product"]["productType"],
"objectName": group_name,
"members": members,
@ -185,10 +185,10 @@ class BlendLoader(plugin.AssetLoader):
"""
Update the loaded asset.
"""
repre_doc = context["representation"]
repre_entity = context["representation"]
group_name = container["objectName"]
asset_group = bpy.data.objects.get(group_name)
libpath = Path(get_representation_path(repre_doc)).as_posix()
libpath = Path(get_representation_path(repre_entity)).as_posix()
assert asset_group, (
f"The asset is not loaded: {container['objectName']}"
@ -235,8 +235,8 @@ class BlendLoader(plugin.AssetLoader):
new_data = {
"libpath": libpath,
"representation": str(repre_doc["_id"]),
"parent": str(repre_doc["parent"]),
"representation": repre_entity["id"],
"parent": repre_entity["versionId"],
"members": members,
}

View file

@ -114,10 +114,10 @@ class BlendSceneLoader(plugin.AssetLoader):
"name": name,
"namespace": namespace or '',
"loader": str(self.__class__.__name__),
"representation": str(context["representation"]["_id"]),
"representation": context["representation"]["id"],
"libpath": libpath,
"asset_name": asset_name,
"parent": str(context["representation"]["parent"]),
"parent": context["representation"]["versionId"],
"productType": context["product"]["productType"],
"objectName": group_name,
"members": members,
@ -137,10 +137,10 @@ class BlendSceneLoader(plugin.AssetLoader):
"""
Update the loaded asset.
"""
repre_doc = context["representation"]
repre_entity = context["representation"]
group_name = container["objectName"]
asset_group = bpy.data.collections.get(group_name)
libpath = Path(get_representation_path(repre_doc)).as_posix()
libpath = Path(get_representation_path(repre_entity)).as_posix()
assert asset_group, (
f"The asset is not loaded: {container['objectName']}"
@ -202,8 +202,8 @@ class BlendSceneLoader(plugin.AssetLoader):
new_data = {
"libpath": libpath,
"representation": str(repre_doc["_id"]),
"parent": str(repre_doc["parent"]),
"representation": repre_entity["id"],
"parent": repre_entity["versionId"],
"members": members,
}

View file

@ -119,10 +119,10 @@ class AbcCameraLoader(plugin.AssetLoader):
"name": name,
"namespace": namespace or "",
"loader": str(self.__class__.__name__),
"representation": str(context["representation"]["_id"]),
"representation": context["representation"]["id"],
"libpath": libpath,
"asset_name": asset_name,
"parent": str(context["representation"]["parent"]),
"parent": context["representation"]["versionId"],
"productType": context["product"]["productType"],
"objectName": group_name,
}
@ -142,16 +142,16 @@ class AbcCameraLoader(plugin.AssetLoader):
Warning:
No nested collections are supported at the moment!
"""
repre_doc = context["representation"]
repre_entity = context["representation"]
object_name = container["objectName"]
asset_group = bpy.data.objects.get(object_name)
libpath = Path(get_representation_path(repre_doc))
libpath = Path(get_representation_path(repre_entity))
extension = libpath.suffix.lower()
self.log.info(
"Container: %s\nRepresentation: %s",
pformat(container, indent=2),
pformat(repre_doc, indent=2),
pformat(repre_entity, indent=2),
)
assert asset_group, (
@ -186,7 +186,7 @@ class AbcCameraLoader(plugin.AssetLoader):
asset_group.matrix_basis = mat
metadata["libpath"] = str(libpath)
metadata["representation"] = str(repre_doc["_id"])
metadata["representation"] = repre_entity["id"]
def exec_remove(self, container: Dict) -> bool:
"""Remove an existing container from a Blender scene.

View file

@ -122,10 +122,10 @@ class FbxCameraLoader(plugin.AssetLoader):
"name": name,
"namespace": namespace or '',
"loader": str(self.__class__.__name__),
"representation": str(context["representation"]["_id"]),
"representation": context["representation"]["id"],
"libpath": libpath,
"asset_name": asset_name,
"parent": str(context["representation"]["parent"]),
"parent": context["representation"]["versionId"],
"productType": context["product"]["productType"],
"objectName": group_name
}
@ -145,16 +145,16 @@ class FbxCameraLoader(plugin.AssetLoader):
Warning:
No nested collections are supported at the moment!
"""
repre_doc = context["representation"]
repre_entity = context["representation"]
object_name = container["objectName"]
asset_group = bpy.data.objects.get(object_name)
libpath = Path(get_representation_path(repre_doc))
libpath = Path(get_representation_path(repre_entity))
extension = libpath.suffix.lower()
self.log.info(
"Container: %s\nRepresentation: %s",
pformat(container, indent=2),
pformat(repre_doc, indent=2),
pformat(repre_entity, indent=2),
)
assert asset_group, (
@ -196,7 +196,7 @@ class FbxCameraLoader(plugin.AssetLoader):
asset_group.matrix_basis = mat
metadata["libpath"] = str(libpath)
metadata["representation"] = str(repre_doc["_id"])
metadata["representation"] = repre_entity["id"]
def exec_remove(self, container: Dict) -> bool:
"""Remove an existing container from a Blender scene.

View file

@ -166,10 +166,10 @@ class FbxModelLoader(plugin.AssetLoader):
"name": name,
"namespace": namespace or '',
"loader": str(self.__class__.__name__),
"representation": str(context["representation"]["_id"]),
"representation": context["representation"]["id"],
"libpath": libpath,
"asset_name": asset_name,
"parent": str(context["representation"]["parent"]),
"parent": context["representation"]["versionId"],
"productType": context["product"]["productType"],
"objectName": group_name
}
@ -189,16 +189,16 @@ class FbxModelLoader(plugin.AssetLoader):
Warning:
No nested collections are supported at the moment!
"""
repre_doc = context["representation"]
repre_entity = context["representation"]
object_name = container["objectName"]
asset_group = bpy.data.objects.get(object_name)
libpath = Path(get_representation_path(repre_doc))
libpath = Path(get_representation_path(repre_entity))
extension = libpath.suffix.lower()
self.log.info(
"Container: %s\nRepresentation: %s",
pformat(container, indent=2),
pformat(repre_doc, indent=2),
pformat(repre_entity, indent=2),
)
assert asset_group, (
@ -251,7 +251,7 @@ class FbxModelLoader(plugin.AssetLoader):
asset_group.matrix_basis = mat
metadata["libpath"] = str(libpath)
metadata["representation"] = str(repre_doc["_id"])
metadata["representation"] = repre_entity["id"]
def exec_remove(self, container: Dict) -> bool:
"""Remove an existing container from a Blender scene.

View file

@ -132,7 +132,7 @@ class JsonLayoutLoader(plugin.AssetLoader):
# # name=f"{unique_number}_{product[name]}_animation",
# asset=asset,
# options={"useSelection": False}
# # data={"dependencies": str(context["representation"]["_id"])}
# # data={"dependencies": context["representation"]["id"]}
# )
def process_asset(self,
@ -177,10 +177,10 @@ class JsonLayoutLoader(plugin.AssetLoader):
"name": name,
"namespace": namespace or '',
"loader": str(self.__class__.__name__),
"representation": str(context["representation"]["_id"]),
"representation": context["representation"]["id"],
"libpath": libpath,
"asset_name": asset_name,
"parent": str(context["representation"]["parent"]),
"parent": context["representation"]["versionId"],
"productType": context["product"]["productType"],
"objectName": group_name
}
@ -197,16 +197,16 @@ class JsonLayoutLoader(plugin.AssetLoader):
will not be removed, only unlinked. Normally this should not be the
case though.
"""
repre_doc = context["representation"]
repre_entity = context["representation"]
object_name = container["objectName"]
asset_group = bpy.data.objects.get(object_name)
libpath = Path(get_representation_path(repre_doc))
libpath = Path(get_representation_path(repre_entity))
extension = libpath.suffix.lower()
self.log.info(
"Container: %s\nRepresentation: %s",
pformat(container, indent=2),
pformat(repre_doc, indent=2),
pformat(repre_entity, indent=2),
)
assert asset_group, (
@ -270,7 +270,7 @@ class JsonLayoutLoader(plugin.AssetLoader):
asset_group.matrix_basis = mat
metadata["libpath"] = str(libpath)
metadata["representation"] = str(repre_doc["_id"])
metadata["representation"] = repre_entity["id"]
def exec_remove(self, container: Dict) -> bool:
"""Remove an existing container from a Blender scene.

View file

@ -130,7 +130,7 @@ class BlendLookLoader(plugin.AssetLoader):
metadata["objects"] = objects
metadata["materials"] = materials
metadata["parent"] = str(context["representation"]["parent"])
metadata["parent"] = context["representation"]["versionId"]
metadata["product_type"] = context["product"]["productType"]
nodes = list(container.objects)
@ -140,14 +140,14 @@ class BlendLookLoader(plugin.AssetLoader):
def update(self, container: Dict, context: Dict):
collection = bpy.data.collections.get(container["objectName"])
repre_doc = context["representation"]
libpath = Path(get_representation_path(repre_doc))
repre_entity = context["representation"]
libpath = Path(get_representation_path(repre_entity))
extension = libpath.suffix.lower()
self.log.info(
"Container: %s\nRepresentation: %s",
pformat(container, indent=2),
pformat(repre_doc, indent=2),
pformat(repre_entity, indent=2),
)
assert collection, (
@ -202,7 +202,7 @@ class BlendLookLoader(plugin.AssetLoader):
collection_metadata["objects"] = objects
collection_metadata["materials"] = materials
collection_metadata["libpath"] = str(libpath)
collection_metadata["representation"] = str(repre_doc["_id"])
collection_metadata["representation"] = repre_entity["id"]
def remove(self, container: Dict) -> bool:
collection = bpy.data.collections.get(container["objectName"])

View file

@ -5,7 +5,8 @@ import bpy
import bpy_extras
import bpy_extras.anim_utils
from ayon_core.client import get_representation_by_name
from ayon_api import get_representations
from ayon_core.pipeline import publish
from ayon_core.hosts.blender.api import plugin
from ayon_core.hosts.blender.api.pipeline import AVALON_PROPERTY
@ -134,6 +135,8 @@ class ExtractLayout(publish.Extractor, publish.OptionalPyblishPluginMixin):
fbx_count = 0
project_name = instance.context.data["projectName"]
version_ids = set()
filtered_assets = []
for asset in asset_group.children:
metadata = asset.get(AVALON_PROPERTY)
if not metadata:
@ -146,42 +149,47 @@ class ExtractLayout(publish.Extractor, publish.OptionalPyblishPluginMixin):
)
continue
filtered_assets.append((asset, metadata))
version_ids.add(metadata["parent"])
repre_entities = get_representations(
project_name,
representation_names={"blend", "fbx", "abc"},
version_ids=version_ids,
fields={"id", "versionId", "name"}
)
repre_mapping_by_version_id = {
version_id: {}
for version_id in version_ids
}
for repre_entity in repre_entities:
version_id = repre_entity["versionId"]
repre_mapping_by_version_id[version_id][repre_entity["name"]] = (
repre_entity
)
for asset, metadata in filtered_assets:
version_id = metadata["parent"]
product_type = metadata.get("product_type")
if product_type is None:
product_type = metadata["family"]
repres_by_name = repre_mapping_by_version_id[version_id]
self.log.debug("Parent: {}".format(version_id))
# Get blend reference
blend = get_representation_by_name(
project_name, "blend", version_id, fields=["_id"]
)
blend_id = None
if blend:
blend_id = blend["_id"]
# Get fbx reference
fbx = get_representation_by_name(
project_name, "fbx", version_id, fields=["_id"]
)
fbx_id = None
if fbx:
fbx_id = fbx["_id"]
# Get abc reference
abc = get_representation_by_name(
project_name, "abc", version_id, fields=["_id"]
)
abc_id = None
if abc:
abc_id = abc["_id"]
json_element = {}
if blend_id:
json_element["reference"] = str(blend_id)
if fbx_id:
json_element["reference_fbx"] = str(fbx_id)
if abc_id:
json_element["reference_abc"] = str(abc_id)
# Get blend, fbx and abc reference
blend_id = repres_by_name.get("blend", {}).get("id")
fbx_id = repres_by_name.get("fbx", {}).get("id")
abc_id = repres_by_name.get("abc", {}).get("id")
json_element = {
key: value
for key, value in (
("reference", blend_id),
("reference_fbx", fbx_id),
("reference_abc", abc_id),
)
if value
}
json_element["product_type"] = product_type
json_element["instance_name"] = asset.name
json_element["asset_name"] = metadata["asset_name"]

View file

@ -44,7 +44,7 @@ class IntegrateAnimation(
break
if not rep:
continue
obj_id = rep["representation"]["_id"]
obj_id = rep["representation"]["id"]
if obj_id:
json_dict["representation_id"] = str(obj_id)