Bases: BlenderLoader
Load animations from a .blend file.
Warning
Loading the same asset more then once is not properly supported at the moment.
Source code in client/ayon_blender/plugins/load/load_animation.py
11
12
13
14
15
16
17
18
19
20
21
22
23
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 | class BlendAnimationLoader(plugin.BlenderLoader):
"""Load animations from a .blend file.
Warning:
Loading the same asset more then once is not properly supported at the
moment.
"""
product_types = {"animation"}
representations = {"blend"}
label = "Link Animation"
icon = "code-fork"
color = "orange"
def process_asset(
self, context: dict, name: str, namespace: Optional[str] = None,
options: Optional[Dict] = None
) -> Optional[List]:
"""
Arguments:
name: Use pre-defined name
namespace: Use pre-defined namespace
context: Full parenthood of representation to load
options: Additional settings dictionary
"""
libpath = self.filepath_from_context(context)
with bpy.data.libraries.load(
libpath, link=True, relative=False
) as (data_from, data_to):
data_to.objects = data_from.objects
data_to.actions = data_from.actions
container = data_to.objects[0]
assert container, "No asset group found"
target_namespace = container.get(AVALON_PROPERTY).get('namespace', namespace)
action = data_to.actions[0].make_local().copy()
for obj in bpy.data.objects:
if obj.get(AVALON_PROPERTY) and obj.get(AVALON_PROPERTY).get(
'namespace', namespace) == target_namespace:
if obj.children[0]:
if not obj.children[0].animation_data:
obj.children[0].animation_data_create()
obj.children[0].animation_data.action = action
break
bpy.data.objects.remove(container)
filename = bpy.path.basename(libpath)
# Blender has a limit of 63 characters for any data name.
# If the filename is longer, it will be truncated.
if len(filename) > 63:
filename = filename[:63]
library = bpy.data.libraries.get(filename)
bpy.data.libraries.remove(library)
|
process_asset(context, name, namespace=None, options=None)
Parameters:
Name | Type | Description | Default |
name | str | | required |
namespace | Optional[str] | Use pre-defined namespace | None |
context | dict | Full parenthood of representation to load | required |
options | Optional[Dict] | Additional settings dictionary | None |
Source code in client/ayon_blender/plugins/load/load_animation.py
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 | def process_asset(
self, context: dict, name: str, namespace: Optional[str] = None,
options: Optional[Dict] = None
) -> Optional[List]:
"""
Arguments:
name: Use pre-defined name
namespace: Use pre-defined namespace
context: Full parenthood of representation to load
options: Additional settings dictionary
"""
libpath = self.filepath_from_context(context)
with bpy.data.libraries.load(
libpath, link=True, relative=False
) as (data_from, data_to):
data_to.objects = data_from.objects
data_to.actions = data_from.actions
container = data_to.objects[0]
assert container, "No asset group found"
target_namespace = container.get(AVALON_PROPERTY).get('namespace', namespace)
action = data_to.actions[0].make_local().copy()
for obj in bpy.data.objects:
if obj.get(AVALON_PROPERTY) and obj.get(AVALON_PROPERTY).get(
'namespace', namespace) == target_namespace:
if obj.children[0]:
if not obj.children[0].animation_data:
obj.children[0].animation_data_create()
obj.children[0].animation_data.action = action
break
bpy.data.objects.remove(container)
filename = bpy.path.basename(libpath)
# Blender has a limit of 63 characters for any data name.
# If the filename is longer, it will be truncated.
if len(filename) > 63:
filename = filename[:63]
library = bpy.data.libraries.get(filename)
bpy.data.libraries.remove(library)
|