mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 22:02:15 +01:00
Reduce redundancy in create action, animation, pointcache, render and review
This commit is contained in:
parent
7cd98fe903
commit
01be65d283
6 changed files with 41 additions and 173 deletions
|
|
@ -237,6 +237,7 @@ class BaseCreator(Creator):
|
|||
"name": collection.name,
|
||||
}
|
||||
|
||||
# Set instance data
|
||||
instance_data.update(
|
||||
{
|
||||
"id": "pyblish.avalon.instance",
|
||||
|
|
@ -248,16 +249,15 @@ class BaseCreator(Creator):
|
|||
}
|
||||
)
|
||||
|
||||
instance = CreatedInstance(
|
||||
self.family, subset_name, instance_data, self
|
||||
self._add_instance_to_context(
|
||||
CreatedInstance(
|
||||
self.family, subset_name, instance_data, self
|
||||
)
|
||||
)
|
||||
self._add_instance_to_context(instance)
|
||||
|
||||
imprint(collection, instance_data)
|
||||
|
||||
if pre_create_data.get("useSelection"):
|
||||
for obj in get_selection():
|
||||
collection.objects.link(obj)
|
||||
return collection
|
||||
|
||||
def collect_instances(self):
|
||||
"""Override abstract method from BaseCreator.
|
||||
|
|
@ -267,7 +267,9 @@ class BaseCreator(Creator):
|
|||
self.cache_subsets(self.collection_shared_data)
|
||||
|
||||
# Get cached subsets
|
||||
cached_subsets = self.collection_shared_data.get('blender_cached_subsets')
|
||||
cached_subsets = self.collection_shared_data.get(
|
||||
"blender_cached_subsets"
|
||||
)
|
||||
if not cached_subsets:
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,11 @@
|
|||
|
||||
import bpy
|
||||
|
||||
from openpype.pipeline import get_current_task_name, CreatedInstance
|
||||
import openpype.hosts.blender.api.plugin
|
||||
from openpype.hosts.blender.api.plugin import BaseCreator, asset_name
|
||||
from openpype.hosts.blender.api import lib
|
||||
from openpype.hosts.blender.api.pipeline import AVALON_PROPERTY
|
||||
|
||||
|
||||
class CreateAction(openpype.hosts.blender.api.plugin.BaseCreator):
|
||||
class CreateAction(BaseCreator):
|
||||
"""Action output for character rigs"""
|
||||
|
||||
identifier = "io.openpype.creators.blender.action"
|
||||
|
|
@ -20,31 +18,13 @@ class CreateAction(openpype.hosts.blender.api.plugin.BaseCreator):
|
|||
def create(
|
||||
self, subset_name: str, instance_data: dict, pre_create_data: dict
|
||||
):
|
||||
self._add_instance_to_context(
|
||||
CreatedInstance(self.family, subset_name, instance_data, self)
|
||||
# Run parent create method
|
||||
collection = super().create(
|
||||
subset_name, instance_data, pre_create_data
|
||||
)
|
||||
|
||||
name = openpype.hosts.blender.api.plugin.asset_name(
|
||||
instance_data["asset"], subset_name
|
||||
)
|
||||
collection = bpy.data.collections.new(name=name)
|
||||
bpy.context.scene.collection.children.link(collection)
|
||||
|
||||
collection[AVALON_PROPERTY] = instance_node = {
|
||||
"name": collection.name,
|
||||
}
|
||||
|
||||
instance_data.update(
|
||||
{
|
||||
"id": "pyblish.avalon.instance",
|
||||
"creator_identifier": self.identifier,
|
||||
"label": subset_name,
|
||||
"task": get_current_task_name(),
|
||||
"subset": subset_name,
|
||||
"instance_node": instance_node,
|
||||
}
|
||||
)
|
||||
lib.imprint(collection, instance_data)
|
||||
# Get instance name
|
||||
name = asset_name(instance_data["asset"], subset_name)
|
||||
|
||||
if pre_create_data.get("useSelection"):
|
||||
for obj in lib.get_selection():
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
"""Create an animation asset."""
|
||||
|
||||
import bpy
|
||||
|
||||
from openpype.pipeline import get_current_task_name, CreatedInstance
|
||||
from openpype.pipeline import CreatedInstance
|
||||
from openpype.hosts.blender.api import plugin, lib, ops
|
||||
from openpype.hosts.blender.api.pipeline import (
|
||||
AVALON_INSTANCES,
|
||||
AVALON_PROPERTY,
|
||||
)
|
||||
|
||||
|
||||
class CreateAnimation(plugin.BaseCreator):
|
||||
|
|
@ -35,43 +30,17 @@ class CreateAnimation(plugin.BaseCreator):
|
|||
def _process(
|
||||
self, subset_name: str, instance_data: dict, pre_create_data: dict
|
||||
):
|
||||
# Get Instance Container or create it if it does not exist
|
||||
instances = bpy.data.collections.get(AVALON_INSTANCES)
|
||||
if not instances:
|
||||
instances = bpy.data.collections.new(name=AVALON_INSTANCES)
|
||||
bpy.context.scene.collection.children.link(instances)
|
||||
|
||||
# Create instance object
|
||||
# name = self.name
|
||||
# if not name:
|
||||
name = plugin.asset_name(instance_data["asset"], subset_name)
|
||||
# asset_group = bpy.data.objects.new(name=name, object_data=None)
|
||||
# asset_group.empty_display_type = 'SINGLE_ARROW'
|
||||
asset_group = bpy.data.collections.new(name=name)
|
||||
instances.children.link(asset_group)
|
||||
|
||||
asset_group[AVALON_PROPERTY] = instance_node = {
|
||||
"name": asset_group.name,
|
||||
}
|
||||
|
||||
instance_data.update(
|
||||
{
|
||||
"id": "pyblish.avalon.instance",
|
||||
"creator_identifier": self.identifier,
|
||||
"label": subset_name,
|
||||
"task": get_current_task_name(),
|
||||
"subset": subset_name,
|
||||
"instance_node": instance_node,
|
||||
}
|
||||
# Run parent create method
|
||||
collection = super().create(
|
||||
subset_name, instance_data, pre_create_data
|
||||
)
|
||||
lib.imprint(asset_group, instance_data)
|
||||
|
||||
if pre_create_data.get("useSelection"):
|
||||
selected = lib.get_selection()
|
||||
for obj in selected:
|
||||
asset_group.objects.link(obj)
|
||||
collection.objects.link(obj)
|
||||
elif pre_create_data.get("asset_group"):
|
||||
obj = (self.options or {}).get("asset_group")
|
||||
asset_group.objects.link(obj)
|
||||
collection.objects.link(obj)
|
||||
|
||||
return asset_group
|
||||
return collection
|
||||
|
|
|
|||
|
|
@ -1,11 +1,6 @@
|
|||
"""Create a pointcache asset."""
|
||||
|
||||
import bpy
|
||||
|
||||
from openpype.pipeline import get_current_task_name, CreatedInstance
|
||||
from openpype.hosts.blender.api import plugin, lib, ops
|
||||
from openpype.hosts.blender.api.pipeline import AVALON_INSTANCES
|
||||
from openpype.hosts.blender.api.pipeline import AVALON_PROPERTY
|
||||
from openpype.hosts.blender.api import plugin, lib
|
||||
|
||||
|
||||
class CreatePointcache(plugin.BaseCreator):
|
||||
|
|
@ -20,32 +15,11 @@ class CreatePointcache(plugin.BaseCreator):
|
|||
def create(
|
||||
self, subset_name: str, instance_data: dict, pre_create_data: dict
|
||||
):
|
||||
self._add_instance_to_context(
|
||||
CreatedInstance(self.family, subset_name, instance_data, self)
|
||||
# Run parent create method
|
||||
collection = super().create(
|
||||
subset_name, instance_data, pre_create_data
|
||||
)
|
||||
|
||||
name = plugin.asset_name(
|
||||
instance_data["asset"], subset_name
|
||||
)
|
||||
collection = bpy.data.collections.new(name=name)
|
||||
bpy.context.scene.collection.children.link(collection)
|
||||
|
||||
collection[AVALON_PROPERTY] = instance_node = {
|
||||
"name": collection.name,
|
||||
}
|
||||
|
||||
instance_data.update(
|
||||
{
|
||||
"id": "pyblish.avalon.instance",
|
||||
"creator_identifier": self.identifier,
|
||||
"label": subset_name,
|
||||
"task": get_current_task_name(),
|
||||
"subset": subset_name,
|
||||
"instance_node": instance_node,
|
||||
}
|
||||
)
|
||||
lib.imprint(collection, instance_data)
|
||||
|
||||
if pre_create_data.get("useSelection"):
|
||||
objects = lib.get_selection()
|
||||
for obj in objects:
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
"""Create render."""
|
||||
import bpy
|
||||
|
||||
from openpype.pipeline import get_current_task_name
|
||||
from openpype.hosts.blender.api import plugin, lib
|
||||
from openpype.hosts.blender.api import plugin
|
||||
from openpype.hosts.blender.api.render_lib import prepare_rendering
|
||||
from openpype.hosts.blender.api.pipeline import (
|
||||
AVALON_INSTANCES,
|
||||
AVALON_PROPERTY,
|
||||
)
|
||||
|
||||
|
||||
class CreateRenderlayer(plugin.BaseCreator):
|
||||
|
|
@ -22,40 +17,16 @@ class CreateRenderlayer(plugin.BaseCreator):
|
|||
def create(
|
||||
self, subset_name: str, instance_data: dict, pre_create_data: dict
|
||||
):
|
||||
# Get Instance Container or create it if it does not exist
|
||||
instances = bpy.data.collections.get(AVALON_INSTANCES)
|
||||
if not instances:
|
||||
instances = bpy.data.collections.new(name=AVALON_INSTANCES)
|
||||
bpy.context.scene.collection.children.link(instances)
|
||||
|
||||
# Create instance object
|
||||
name = plugin.asset_name(instance_data.get("asset"), subset_name)
|
||||
asset_group = bpy.data.collections.new(name=name)
|
||||
|
||||
try:
|
||||
instances.children.link(asset_group)
|
||||
|
||||
asset_group[AVALON_PROPERTY] = instance_node = {
|
||||
"name": asset_group.name
|
||||
}
|
||||
|
||||
instance_data.update(
|
||||
{
|
||||
"id": "pyblish.avalon.instance",
|
||||
"creator_identifier": self.identifier,
|
||||
"label": subset_name,
|
||||
"task": get_current_task_name(),
|
||||
"subset": subset_name,
|
||||
"instance_node": instance_node,
|
||||
}
|
||||
# Run parent create method
|
||||
collection = super().create(
|
||||
subset_name, instance_data, pre_create_data
|
||||
)
|
||||
|
||||
lib.imprint(asset_group, instance_data)
|
||||
|
||||
prepare_rendering(asset_group)
|
||||
prepare_rendering(collection)
|
||||
except Exception:
|
||||
# Remove the instance if there was an error
|
||||
bpy.data.collections.remove(asset_group)
|
||||
bpy.data.collections.remove(collection)
|
||||
raise
|
||||
|
||||
# TODO: this is undesiderable, but it's the only way to be sure that
|
||||
|
|
@ -69,4 +40,4 @@ class CreateRenderlayer(plugin.BaseCreator):
|
|||
# now it is to force the file to be saved.
|
||||
bpy.ops.wm.save_as_mainfile(filepath=bpy.data.filepath)
|
||||
|
||||
return asset_group
|
||||
return collection
|
||||
|
|
|
|||
|
|
@ -1,13 +1,7 @@
|
|||
"""Create review."""
|
||||
|
||||
import bpy
|
||||
|
||||
from openpype.pipeline import get_current_task_name, CreatedInstance
|
||||
from openpype.pipeline import CreatedInstance
|
||||
from openpype.hosts.blender.api import plugin, lib, ops
|
||||
from openpype.hosts.blender.api.pipeline import (
|
||||
AVALON_INSTANCES,
|
||||
AVALON_PROPERTY,
|
||||
)
|
||||
|
||||
|
||||
class CreateReview(plugin.BaseCreator):
|
||||
|
|
@ -35,39 +29,17 @@ class CreateReview(plugin.BaseCreator):
|
|||
def _process(
|
||||
self, subset_name: str, instance_data: dict, pre_create_data: dict
|
||||
):
|
||||
# Get Instance Container or create it if it does not exist
|
||||
instances = bpy.data.collections.get(AVALON_INSTANCES)
|
||||
if not instances:
|
||||
instances = bpy.data.collections.new(name=AVALON_INSTANCES)
|
||||
bpy.context.scene.collection.children.link(instances)
|
||||
|
||||
# Create instance object
|
||||
name = plugin.asset_name(instance_data["asset"], subset_name)
|
||||
asset_group = bpy.data.collections.new(name=name)
|
||||
instances.children.link(asset_group)
|
||||
|
||||
asset_group[AVALON_PROPERTY] = instance_node = {
|
||||
"name": asset_group.name,
|
||||
}
|
||||
|
||||
instance_data.update(
|
||||
{
|
||||
"id": "pyblish.avalon.instance",
|
||||
"creator_identifier": self.identifier,
|
||||
"label": subset_name,
|
||||
"task": get_current_task_name(),
|
||||
"subset": subset_name,
|
||||
"instance_node": instance_node,
|
||||
}
|
||||
# Run parent create method
|
||||
collection = super().create(
|
||||
subset_name, instance_data, pre_create_data
|
||||
)
|
||||
lib.imprint(asset_group, instance_data)
|
||||
|
||||
if pre_create_data.get("useSelection"):
|
||||
selected = lib.get_selection()
|
||||
for obj in selected:
|
||||
asset_group.objects.link(obj)
|
||||
collection.objects.link(obj)
|
||||
elif pre_create_data.get("asset_group"):
|
||||
obj = (self.options or {}).get("asset_group")
|
||||
asset_group.objects.link(obj)
|
||||
collection.objects.link(obj)
|
||||
|
||||
return asset_group
|
||||
return collection
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue