public override bool OnExport(SceneExportInfo info) { EngineEntity.SetVariable("FovX", _fCustomFOV.ToString()); EngineEntity.SetVariable("NearClipDistance", NearClipDistance.ToString()); EngineEntity.SetVariable("FarClipDistance", FarClipDistance.ToString()); EngineEntity.SetVariable("m_fTimeOfDay", _bApplyTimeOfDay ? _fCustomTimeOfDay.ToString() : "-1.0"); // on the runtime side a negative value disables it bool bResult = base.OnExport(info); return(bResult); }
public override bool OnExport(SceneExportInfo info) { EngineInstanceEntity entity = _engineInstance as EngineInstanceEntity; // this shape is only exported as entity if the camera has a key SetHint(HintFlags_e.NoExport, string.IsNullOrEmpty(_objectKey)); if (entity != null) { // we dont have a specific engine instance class, so assign via standard variable reflection entity.SetVariable("NearClipDistance", NearClipDistance.ToString()); entity.SetVariable("FarClipDistance", FarClipDistance.ToString()); entity.SetVariable("FovX", FOV.ToString()); } bool bResult = base.OnExport(info); return(bResult); }
public override bool OnExport(SceneExportInfo info) { EngineInstanceEntity entity = _engineInstance as EngineInstanceEntity; if (entity != null) { // we don't have a specific engine instance class, so assign via standard variable reflection entity.SetVariable("m_fNearClipDistance", NearClipDistance.ToString()); entity.SetVariable("m_fFarClipDistance", FarClipDistance.ToString()); entity.SetVariable("m_fFovX", FOV.ToString()); } bool bResult = base.OnExport(info); return bResult; }
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; }
/// <summary> /// Recursively exports shape and its children /// </summary> /// <returns>true if export was successful</returns> public override bool OnExportRecursive(SceneExportInfo info) { if (MeshExportSettings.ExportForAssetProfile.IsActiveProfileSet && MeshExportSettings.AutomaticExport) return true; return base.OnExportRecursive(info); }
/// <summary> /// helper function to save layers as prefabs /// </summary> /// <param name="folderName">absolute path to the folder where the prefabs should be saved in. Set string to null if you want to use the default folder</param> private void ExportLayersAsPrefabs(string folderName) { if (EditorManager.Scene == null) return; int iCount = 0; bool bAsBinary = true; try { foreach (Layer layer in EditorManager.Scene.Layers) { string prefabName; if (folderName == null) //if no foldername is used { prefabName = Path.ChangeExtension(layer.AbsoluteLayerFilename, ".prefab"); } else { prefabName = Path.Combine(folderName, layer.LayerName + ".prefab"); } PrefabDesc prefab = new PrefabDesc(prefabName); prefab.AutoSaveBinary = true; //activate autosave per default [#2112] prefab.Description = layer.Description; prefab.CreateFromInstances(layer.Root.ChildCollection, Vector3F.Zero, true, true); if (prefab.SaveToFile(null)) iCount++; if (bAsBinary) { SceneExportInfo info = new SceneExportInfo(); info.ExportType = SceneExportInfo.ExportType_e.VPrefab; info.AbsoluteFilename = EditorManager.Project.MakeAbsolute(prefab.BinaryFilename); info.RelevantShapes = SceneExportInfo.GetRelevantExportShapes(layer.Root); ExportHelper.StartPrefabExport(info); layer.Root.OnExportRecursive(info); ExportHelper.EndPrefabExport(info); } } } catch (Exception ex) { EditorManager.DumpException(ex); EditorManager.ShowMessageBox(this, "Failed to export layers. Detailed message:\n\n" + ex.Message, "Export Layers as Prefabs", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (iCount == 0) EditorManager.ShowMessageBox(this, "No layer valid for export", "Export Layers as Prefabs", MessageBoxButtons.OK, MessageBoxIcon.Information); else EditorManager.ShowMessageBox(this, iCount.ToString() + " Layer(s) exported successfully", "Export Layers as Prefabs", MessageBoxButtons.OK, MessageBoxIcon.Information); }
public override bool OnExport(SceneExportInfo info) { EngineInstanceEntity entity = _engineInstance as EngineInstanceEntity; // this shape is only exported as entity if the camera has a key SetHint(HintFlags_e.NoExport, string.IsNullOrEmpty(_objectKey)); if (entity != null) { // we dont have a specific engine instance class, so assign via standard variable reflection entity.SetVariable("NearClipDistance", NearClipDistance.ToString()); entity.SetVariable("FarClipDistance", FarClipDistance.ToString()); entity.SetVariable("FovX", FOV.ToString()); } bool bResult = base.OnExport(info); return bResult; }
public override bool OnExport(SceneExportInfo info) { EngineEntity.SetVariable("FovX", _fCustomFOV.ToString()); EngineEntity.SetVariable("NearClipDistance", NearClipDistance.ToString()); EngineEntity.SetVariable("FarClipDistance", FarClipDistance.ToString()); EngineEntity.SetVariable("m_fTimeOfDay", _bApplyTimeOfDay ? _fCustomTimeOfDay.ToString() : "-1.0"); // on the runtime side a negative value disables it bool bResult = base.OnExport(info); return bResult; }