Ejemplo n.º 1
0
 void EditorManager_SceneEvent(object sender, SceneEventArgs e)
 {
     if (e.action == SceneEventArgs.Action.AfterClosing)
     {
         // clear out the settings collection
         m_settingsDictionary = null;
         UpdateSettingsListView();
     }
     else if (e.action == SceneEventArgs.Action.BeforeExport)
     {
         ExportSceneEventArgs exportEventArgs = e as ExportSceneEventArgs;
         if (tsb_Build.ToolTipText == BUILD_DIRTY_STR)
         {
         }
     }
 }
Ejemplo n.º 2
0
        private bool _ExportSceneNotSaveSettings(string absPath)
        {
            if (EditorManager.Settings.SaveResourcesAtExportTime)
            EditorManager.TriggerSaveResources();

              // Incorporate the current asset profile name into the given export path...
              string profileName = EditorManager.ProfileManager.GetActiveProfile().ToString();
              string oldExtension = Path.GetExtension(absPath);
              absPath = Path.ChangeExtension(absPath, profileName) + oldExtension;

              // ...and into the export profile export path (to then end up in the absolute zone export folder <sigh>).
              string oldExportPath = CurrentExportProfile.ExportPath;
              string exportProfileOwnerFileName = CurrentExportProfile.OwnerScene.FileName;
              CurrentExportProfile.ExportPath = Path.ChangeExtension(oldExportPath, profileName) + Path.GetExtension(oldExportPath);

              // That's Not Particularly Nice (tm): We try to figure out if the old export path was derived from the owner's filename
              // or whether it was set explicitly.
              oldExportPath = (oldExportPath == Path.ChangeExtension(exportProfileOwnerFileName, SceneExportProfile.FILE_EXTENSION_EXPORT))
            ? null : oldExportPath;

              bool bOK = true;
              try
              {
            bool bForceLocalPos = EditorManager.Settings.AllowZonePivots;

            /// Recreate all engine instances before export.
            /// This fixes the problem of script instances not being up to date
            /// on export (see ticket #16991).
            this.RecreateSceneEntityInstances();

            // create the directory where all the zone files (and vscene specific files) go
            string folder = this.AbsoluteZoneExportFolder;
            try
            {
              if (!Directory.Exists(folder))
            Directory.CreateDirectory(folder);
            }
            catch (Exception ex)
            {
              EditorManager.DumpException(ex, true);
              bOK = false;
            }

            // start the actual export process
            SceneExportInfo info = new SceneExportInfo();
            info.ExportType = SceneExportInfo.ExportType_e.VScene;
            info.ExportFlags = CurrentExportProfile.ExportFlags;
            info.IncludeVisibility = CurrentExportProfile.IncludeVisibilityInfo;
            info.EmbedCustomLitFile = CurrentExportProfile.EmbedCustomLitFile;
            info.AbsoluteFilename = absPath;
            info.AbsoluteExportDataFolder = folder;
            info.RelevantExportZones = GetExportRelevantZones();
            info.RelevantEmbeddedZones = GetRelevantEmbeddedZones(); // this collection might change later

            switch (EditorManager.ProfileManager.GetActiveProfile().GetPlatform())
            {
              case TargetDevice_e.TARGETDEVICE_DX9:
            info.ShapeFilter = (int)TargetPlatformSupport.DX9;
            break;
              case TargetDevice_e.TARGETDEVICE_DX11:
            info.ShapeFilter = (int)TargetPlatformSupport.DX11;
            break;
              case TargetDevice_e.TARGETDEVICE_XBOX360:
            info.ShapeFilter = (int)TargetPlatformSupport.Xbox360;
            break;
              case TargetDevice_e.TARGETDEVICE_PS3:
            info.ShapeFilter = (int)TargetPlatformSupport.PS3;
            break;
              case TargetDevice_e.TARGETDEVICE_PSP2:
            info.ShapeFilter = (int)TargetPlatformSupport.PSP2;
            break;
              case TargetDevice_e.TARGETDEVICE_IOS:
            info.ShapeFilter = (int)TargetPlatformSupport.IOS;
            break;
              case TargetDevice_e.TARGETDEVICE_ANDROID:
            info.ShapeFilter = (int)TargetPlatformSupport.ANDROID;
            break;
              case TargetDevice_e.TARGETDEVICE_WIIU:
            info.ShapeFilter = (int)TargetPlatformSupport.WiiU;
            break;
              case TargetDevice_e.TARGETDEVICE_NACL:
            info.ShapeFilter = (int)TargetPlatformSupport.NaCl;
            break;
              default:
            break;
            }

            // Trigger callbacks: ask every listener if the export actually should be performed.
            // Trigger the event, allowing plugins to cancel the export
            ExportSceneEventArgs args = new ExportSceneEventArgs(SceneEventArgs.Action.AllowExport, true, info);
            EditorManager.OnSceneEvent(args);
            if (args.CancelExport)
            {
              CurrentExportProfile.ExportPath = oldExportPath;
              return false;
            }

            // Trigger callbacks: This is only called for the vscene, not for the zones.
            // This could be changed, but listeners should handle this properly then, i.e. check the CurrentZone member
            ExportHelper.TriggerStartExportCallbacks(info);

            // Ensure that scene script file is set in script manager
            // This is e.g. required if the script was broken when the scene was loaded but it was corrected in the meantime
            // then the exporter scene will have the proper script
            // This is executed here because the callbacks also may trigger saving of scene scripts
            string sceneScriptFile = ((V3DLayer)EditorManager.Scene.MainLayer).SceneScriptFile;
            if (sceneScriptFile != null && sceneScriptFile.Length > 0)
            {
              ScriptManager.SetSceneScriptFile(sceneScriptFile);
            }

            // build plugin list (needed in StartExport)
            // We also want all plugin refs from the zones in the vscene because we cannot load engine plugins later
            IShapeVisitor collectPluginsVisitor = new SceneExportInfo.CollectPluginInfoVisitor(info);
            foreach (Layer layer in Layers)
              if (layer.ParentZone == null || info.RelevantExportZones.Contains(layer.ParentZone))
            layer.Root.RunVisitor(collectPluginsVisitor);

            EditorManager.Progress.ShowProgressDialog("Export scene");
            float fProgressStep = 100.0f / (info.RelevantExportZones.Count + 2);

            // only export layers to vscene that are not attached to a zone
            ResourceSnapshotInfo snapshot = new ResourceSnapshotInfo();

            this._bForceLocalPosition = true;

            // compute visibility in engine
            EditorManager.Progress.StatusString = "Build Visibility...";
            bool bOldUseVisibilityInEngineState = EditorManager.VisibilityBuilder.UseInEngine;
            EditorManager.Progress.SetRange(EditorManager.Progress.Percentage, EditorManager.Progress.Percentage + fProgressStep * 0.5f); // 1st half of visibility
            if (info.IncludeVisibility && EditorManager.VisibilityBuilder.Status != IVisibilityBuilder.VisibilityStatus_e.Valid)
              EditorManager.VisibilityBuilder.Build(EditorManager.Scene, EditorManager.Progress);

            EditorManager.VisibilityBuilder.UseInEngine = info.IncludeVisibility; // make sure engine instances have visibility assigned
            EditorManager.Progress.SetRange(0.0f, 100.0f);
            EditorManager.Progress.Percentage += fProgressStep * 0.5f; // 2nd half of visibilty

            // start with zone files
            if (info.RelevantExportZones.Count > 0)
            {
              SceneExportInfo zoneinfo = new SceneExportInfo();
              zoneinfo.ExportType = SceneExportInfo.ExportType_e.VZone;
              zoneinfo.ExportFlags = CurrentExportProfile.ExportFlags; // not used here though
              zoneinfo.IncludeVisibility = CurrentExportProfile.IncludeVisibilityInfo;
              zoneinfo.EmbedCustomLitFile = CurrentExportProfile.EmbedCustomLitFile;
              zoneinfo.RelevantExportZones = info.RelevantExportZones;
              zoneinfo.RelevantEmbeddedZones = info.RelevantEmbeddedZones;
              zoneinfo.ShapeFilter = info.ShapeFilter;

              foreach (Zone zone in info.RelevantExportZones)
              {
            bool bOldLoaded = zone.Loaded;
            if (!bOldLoaded)
            {
              EditorManager.Progress.StatusString = string.Format("Loading zone {0}", zone.ZoneName);
              Application.DoEvents();
              zone.ShowProgress = false;
              zone.Loaded = true;
            }
            zoneinfo.CurrentZone = zone;
            zoneinfo.AbsoluteFilename = Path.Combine(folder, zone.ExportFilename);
            snapshot.AbsoluteFilename = Path.ChangeExtension(zoneinfo.AbsoluteFilename, ".vres");
            snapshot.CurrentZone = zone;

            EditorManager.Progress.StatusString = string.Format("Export zone {0}", zone.ZoneName);
            Application.DoEvents();

            // we need the relevant shapes in this collection
            zoneinfo.RelevantShapes = new ShapeCollection();
            foreach (Layer layer in zone.Layers)
            {
              if (layer.ExportFinal)
                zoneinfo.RelevantShapes.AddRange(SceneExportInfo.GetRelevantExportShapes(layer.Root));
            }

            bOK &= ExportHelper.StartZoneExport(zoneinfo);
            bOK &= ExportHelper.StartResourceSnapshot(snapshot);

            foreach (Layer layer in zone.Layers)
            {
              if (!layer.ExportFinal)
                continue;
              if (!CurrentExportProfile.InvisibleLayersExportInvisibleObjects)
                layer.Root.SetVisible(true, true);
              if (bForceLocalPos)
                layer.Root.RunVisitor(_repositionVisitor);
              bOK &= layer.OnExport(zoneinfo);
              layer.GetDependencies(snapshot);
            }

            bOK &= ExportHelper.EndZoneExport(zoneinfo);
            bOK &= ExportHelper.EndResourceSnapshot(snapshot);

            if (!bOldLoaded)
            {
              EditorManager.Progress.StatusString = string.Format("Unloading zone {0}", zone.ZoneName);
              Application.DoEvents();
              zone.ShowProgress = false;
              zone.Loaded = false;
            }

            EditorManager.Progress.Percentage += fProgressStep;
            Application.DoEvents();
              }
            } // end of export all zones

            // vscene file
            EditorManager.Progress.StatusString = "Export layers that are not in zones to vscene";
            info.RelevantEmbeddedZones = GetRelevantEmbeddedZones(); // collection might have changed after zone export (e.g. valid bbox)
            info.RelevantShapes = new ShapeCollection();
            foreach (Layer layer in Layers)
              if (layer.ExportFinal && layer.ParentZone == null)
            info.RelevantShapes.AddRange(SceneExportInfo.GetRelevantExportShapes(layer.Root));

            // mark the plugins that should be embedded
            ExportHelper.ApplyPluginsUserSelection(CurrentExportProfile.PluginsUserSelection);

            if (!ExportHelper.StartExport(info))
            {
              if (!string.IsNullOrEmpty(info.LastErrorMessage))
            EditorManager.ShowMessageBox(info.LastErrorMessage, "Export canceled");
              else
            EditorManager.ShowMessageBox("The export was canceled for an unknown reason", "Export canceled");

              this._bForceLocalPosition = false;
              if (bForceLocalPos)
            this.OnRepositionShapes(null);
              EditorManager.VisibilityBuilder.UseInEngine = bOldUseVisibilityInEngineState; // reset the state
              EditorManager.Progress.HideProgressDialog();
              CurrentExportProfile.ExportPath = oldExportPath;
              return false;
            }

            this._bForceLocalPosition = true;

            snapshot.AbsoluteFilename = Path.Combine(folder, "resources.vres");
            snapshot.CurrentZone = null;
            bOK &= ExportHelper.StartResourceSnapshot(snapshot);
            foreach (Layer layer in Layers)
            {
              if (layer.ExportFinal && layer.ParentZone == null)
              {
            if (!CurrentExportProfile.InvisibleLayersExportInvisibleObjects)
              layer.Root.SetVisible(true, true);

            if (bForceLocalPos)
              layer.Root.RunVisitor(_repositionVisitor);

            layer.GetDependencies(snapshot);
            bOK &= layer.OnExport(info);
              }
            }
            bOK &= ExportHelper.EndResourceSnapshot(snapshot);
            EditorManager.Progress.Percentage += fProgressStep;

            // close everything, trigger callbacks
            bOK &= ExportHelper.EndExport(info);
            ExportHelper.TriggerEndExportCallbacks(info);
            EditorManager.VisibilityBuilder.UseInEngine = bOldUseVisibilityInEngineState; // reset the state

            EditorManager.Progress.StatusString = string.Format("Export finished - cleaning up...");

            // set back position
            this._bForceLocalPosition = false;
            if (bForceLocalPos)
              this.OnRepositionShapes(null);

            // set back other properties
            foreach (Layer layer in Layers)
            {
              if (!CurrentExportProfile.InvisibleLayersExportInvisibleObjects)
            layer.Root.SetVisible(layer.VisibleFinal, true);
            }
            EditorManager.Progress.HideProgressDialog();

            if (info.UnsupportedShapes.Count > 0)
            {
              ExportReportDlg report = new ExportReportDlg(info.UnsupportedShapes);
              report.Show();
            }
              }
              finally
              {
            CurrentExportProfile.ExportPath = oldExportPath;
              }

              return bOK;
        }