Bases: BlenderExtractor
, OptionalPyblishPluginMixin
Extract as the camera as FBX.
Source code in client/ayon_blender/plugins/publish/extract_camera_fbx.py
9
10
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
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 | class ExtractCamera(
plugin.BlenderExtractor, publish.OptionalPyblishPluginMixin
):
"""Extract as the camera as FBX."""
label = "Extract Camera (FBX)"
hosts = ["blender"]
families = ["camera"]
optional = True
def process(self, instance):
if not self.is_active(instance.data):
return
# Define extract output file path
stagingdir = self.staging_dir(instance)
folder_name = instance.data["folderEntity"]["name"]
product_name = instance.data["productName"]
instance_name = f"{folder_name}_{product_name}"
filename = f"{instance_name}.fbx"
filepath = os.path.join(stagingdir, filename)
# Perform extraction
self.log.debug("Performing extraction..")
plugin.deselect_all()
selected = []
camera = None
for obj in instance:
if obj.type == "CAMERA":
obj.select_set(True)
selected.append(obj)
camera = obj
break
assert camera, "No camera found"
context = plugin.create_blender_context(
active=camera, selected=selected)
scene_overrides = {
"frame_start": instance.data.get("frameStart"),
"frame_end": instance.data.get("frameEnd"),
"frame_step": instance.data.get("frameStep"),
"render.fps": instance.data.get("fps")
}
# Skip None value overrides
scene_overrides = {
key: value for key, value in scene_overrides.items()
if value is not None
}
if "render.fps" in scene_overrides:
scene_overrides["render.fps_base"] = 1
with lib.attribute_overrides(bpy.context.scene, scene_overrides):
with bpy.context.temp_override(**context):
# We export the fbx
bpy.ops.export_scene.fbx(
filepath=filepath,
use_active_collection=False,
use_selection=True,
bake_anim_use_nla_strips=False,
bake_anim_use_all_actions=False,
add_leaf_bones=False,
armature_nodetype='ROOT',
object_types={'CAMERA'},
bake_anim_simplify_factor=0.0
)
plugin.deselect_all()
if "representations" not in instance.data:
instance.data["representations"] = []
representation = {
'name': 'fbx',
'ext': 'fbx',
'files': filename,
"stagingDir": stagingdir,
}
instance.data["representations"].append(representation)
self.log.debug("Extracted instance '%s' to: %s",
instance.name, representation)
|