Skip to content

extract_fbx

ExtractFbx

Bases: Extractor

Extract Fbx.

Source code in client/ayon_unreal/plugins/publish/extract_fbx.py
 7
 8
 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
class ExtractFbx(publish.Extractor):
    """Extract Fbx."""

    label = "Extract Fbx (Static Mesh)"
    hosts = ["unreal"]
    families = ["staticMesh"]

    def process(self, instance):
        staging_dir = self.staging_dir(instance)
        # TODO: select the asset during context
        fbx_exporter = unreal.StaticMeshExporterFBX()
        fbx_exporter.set_editor_property('text', False)

        options = unreal.FbxExportOption()
        options.set_editor_property('ascii', False)
        options.set_editor_property('collision', False)
        fbx_filename = f"{instance.name}.fbx"

        task = unreal.AssetExportTask()
        task.exporter = fbx_exporter
        task.options = options
        members = set(instance.data.get("members", []))
        asset_registry = unreal.AssetRegistryHelpers.get_asset_registry()
        for member in members:
            task.object = asset_registry.get_asset_by_object_path(member).get_asset()
            task.automated = True
            task.filename = os.path.join(staging_dir, fbx_filename).replace("\\", "/")
            task.selected = False
            task.use_file_archive = False
            task.write_empty_files = False

            unreal.Exporter.run_asset_export_task(task)

        if "representations" not in instance.data:
            instance.data["representations"] = []

        representation = {
            'name': 'fbx',
            'ext': 'fbx',
            'files': fbx_filename,
            "stagingDir": staging_dir,
        }

        instance.data["representations"].append(representation)
        self.log.debug(f"{staging_dir}/{fbx_filename}")