Skip to content

ADD ability to Export from code and not only Menu Entries #797

Description

@MatthieuKiskonen

Is your feature request related to a problem? Please describe.
Ability to Export a gameobject from code and not only from MenuEntries

Describe the solution you'd like

MenuEntries.cs should be made public and public Export function should be added. This can probably replace existing Export method as the path is optional parameter so non breaking.

public static void Export(bool binary, string name, GameObject[] gameObjects, string path = "")
        {
            var extension = binary ? k_GltfBinaryExtension : k_GltfExtension;
            path = EditorUtility.SaveFilePanel(
                "glTF Export Path",
                SaveFolderPath,
                $"{name}.{extension}",
                extension
            );
            if (!string.IsNullOrEmpty(path))
            {
                SaveFolderPath = Directory.GetParent(path)?.FullName;
                var settings = GetDefaultSettings(binary);
                var goSettings = new GameObjectExportSettings { OnlyActiveInHierarchy = false };
                var export = new GameObjectExport(settings, gameObjectExportSettings: goSettings, logger: new ConsoleLogger());
                export.AddScene(gameObjects, name);
                var success = AsyncHelpers.RunSync(() => export.SaveToFileAndDispose(path));

#if GLTF_VALIDATOR
                if (success)
                {
                    var report = Validator.Validate(path);
                    report.Log();
                }
#endif
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions