Example #1
0
        static void Exec(bool gui, string input, string output, string export, string format, float magnification)
        {
            // Debug
            bool isDebugMode = false;

#if DEBUG
            isDebugMode = true;
#endif
            if (System.IO.File.Exists("debug.txt") || isDebugMode)
            {
                swig.Native.SetFileLogger(Path.Combine(GUI.Manager.GetEntryDirectory(), "Effekseer.log.txt"));
            }

            var      systemLanguage = EfkN.GetSystemLanguage();
            Language?language       = null;

            if (systemLanguage != swig.SystemLanguage.Unknown)
            {
                language = (Language)systemLanguage;
            }
            else
            {
                language = Language.English;
            }

            Core.OnOutputMessage += new Action <string>(Core_OnOutputMessage);
            Core.Initialize(language);

            if (gui)
            {
                // Failed to compile script
                if (Core.ExportScripts.Count == 0)
                {
                    Script.ExportScript defaultExporter = new Script.ExportScript(
                        Script.ScriptPosition.External,
                        Plugin.ExportDefault.UniqueName,
                        Plugin.ExportDefault.Author,
                        Plugin.ExportDefault.Title,
                        Plugin.ExportDefault.Description,
                        Plugin.ExportDefault.Filter,
                        Plugin.ExportDefault.Call);
                    Core.ExportScripts.Add(defaultExporter);

                    Script.ExportScript glTFExporter = new Script.ExportScript(
                        Script.ScriptPosition.External,
                        Plugin.ExportglTF.UniqueName,
                        Plugin.ExportglTF.Author,
                        Plugin.ExportglTF.Title,
                        Plugin.ExportglTF.Description,
                        Plugin.ExportglTF.Filter,
                        Plugin.ExportglTF.Call);
                    Core.ExportScripts.Add(glTFExporter);

                    Script.ExportScript glbExporter = new Script.ExportScript(
                        Script.ScriptPosition.External,
                        Plugin.Exportglb.UniqueName,
                        Plugin.Exportglb.Author,
                        Plugin.Exportglb.Title,
                        Plugin.Exportglb.Description,
                        Plugin.Exportglb.Filter,
                        Plugin.Exportglb.Call);
                    Core.ExportScripts.Add(glbExporter);
                }

                {
                    var appDirectory = GUI.Manager.GetEntryDirectory();
                    if (Core.Language == Language.Japanese)
                    {
                        var fullPath = Path.Combine(appDirectory, "resources/languages/effekseer_ja.txt");
                        Resources.LoadLanguageFile(fullPath);
                    }
                    if (Core.Language == Language.English)
                    {
                        var fullPath = Path.Combine(appDirectory, "resources/languages/effekseer_en.txt");
                        Resources.LoadLanguageFile(fullPath);
                    }
                }

                System.OperatingSystem os         = System.Environment.OSVersion;
                swig.DeviceType        deviceType = swig.DeviceType.DirectX11;

                if (!(os.Platform == PlatformID.Win32NT ||
                      os.Platform == PlatformID.Win32S ||
                      os.Platform == PlatformID.Win32Windows ||
                      os.Platform == PlatformID.WinCE))
                {
                    deviceType = swig.DeviceType.OpenGL;
                }

                if (!GUI.Manager.Initialize(960, 540, deviceType))
                {
                    return;
                }
            }

            try
            {
                if (input != string.Empty)
                {
                    Core.LoadFrom(input);
                }

                if (output != string.Empty)
                {
                    Core.SaveTo(output);
                }

                if (export != string.Empty)
                {
                    if (magnification == 0.0f)
                    {
                        magnification = Core.Option.Magnification;
                    }

                    if (format == "gltf")
                    {
                        var option = new Effekseer.Exporter.glTFExporterOption();
                        option.Scale = magnification;
                        var exporter = new Effekseer.Exporter.glTFExporter();
                        exporter.Export(export, option);
                    }
                    else if (format == "glb")
                    {
                        var option = new Effekseer.Exporter.glTFExporterOption();
                        option.Scale  = magnification;
                        option.Format = Exporter.glTFExporterFormat.glb;
                        var exporter = new Effekseer.Exporter.glTFExporter();
                        exporter.Export(export, option);
                    }
                    else
                    {
                        var binaryExporter = new Binary.Exporter();
                        var binary         = binaryExporter.Export(magnification);
                        System.IO.File.WriteAllBytes(export, binary);
                    }
                }
            }
            catch (Exception e)
            {
                System.Console.Error.WriteLine(e.Message);
            }

            if (gui)
            {
                while (GUI.Manager.NativeManager.DoEvents())
                {
                    GUI.Manager.Update();
                }

                GUI.Manager.Terminate();
                Process.MaterialEditor.Terminate();
            }

            Core.Dispose();
        }