/// <summary> /// Called when deserializing /// </summary> /// <param name="info"></param> /// <param name="context"></param> protected V3DLayer(SerializationInfo info, StreamingContext context) : base(info, context) { _v3dFilename = info.GetString("_v3dFilename"); // deprecated _currentSettings = new ProfileSpecificSettings(); // Determine the scene to use as reference for loading. If the layer is loaded during project load, // it is the scene saved temporarily as currently loading scene. Otherwise (e.g., when a layer is // reloaded after a change), this will likely be the scene active in the editor. Note that we have // no guarantee that currentScene will never be null - so always check before using it. IScene currentScene = EditorManager.Project.CurrentlyLoadingScene; if (currentScene == null) { currentScene = EditorManager.Project.Scene; } // We use _skyConfig to determine whether we have an old file that stores // the profile specific data in the main layer or a new one that stores it externally. if (SerializationHelper.HasElement(info, "_skyConfig")) { _currentSettings._skyConfig = (SkyConfig)info.GetValue("_skyConfig", typeof(SkyConfig)); if (SerializationHelper.HasElement(info, "_defaultLightColor")) _currentSettings._defaultLightColor = (Color)info.GetValue("_defaultLightColor", typeof(Color)); if (SerializationHelper.HasElement(info, "_fNearClip")) _currentSettings._fNearClip = info.GetSingle("_fNearClip"); if (SerializationHelper.HasElement(info, "_fFarClip")) _currentSettings._fFarClip = info.GetSingle("_fFarClip"); // view settings: if (SerializationHelper.HasElement(info, "_fovX")) _currentSettings._fFovX = info.GetSingle("_fovX"); // old version if (SerializationHelper.HasElement(info, "_renderer")) _renderer = (Renderer)info.GetValue("_renderer", typeof(Renderer)); // new version: if (SerializationHelper.HasElement(info, "_rendererNodeClass")) { _currentSettings._rendererSetup._rendererNodeClass = info.GetString("_rendererNodeClass"); _currentSettings._rendererSetup._rendererProperties = (DynamicPropertyCollection)info.GetValue("_rendererProperties", typeof(DynamicPropertyCollection)); _currentSettings._rendererSetup._rendererComponents = (ShapeComponentCollection)info.GetValue("_rendererComponents", typeof(ShapeComponentCollection)); } if (SerializationHelper.HasElement(info, "_fogSetup")) { FogSetup = (FogSetup)info.GetValue("_fogSetup", typeof(FogSetup)); } else if (SerializationHelper.HasElement(info, "_fogConfig")) { DepthFogConfig fogConfig = (DepthFogConfig)info.GetValue("_fogConfig", typeof(DepthFogConfig)); SetupFogData(fogConfig); } if (SerializationHelper.HasElement(info, "_timeOfDay")) { _currentSettings._timeOfDay = (TimeOfDay)info.GetValue("_timeOfDay", typeof(TimeOfDay)); if (_currentSettings._timeOfDay != null) { _currentSettings._timeOfDay.Owner = this; _currentSettings._timeOfDay.SceneSky = _currentSettings._skyConfig; } } if (SerializationHelper.HasElement(info, "_currentTime")) { _currentSettings._currentTime = info.GetSingle("_currentTime"); } if (SerializationHelper.HasElement(info, "_bWantsTimeOfDay")) { _currentSettings._bWantsTimeOfDay = info.GetBoolean("_bWantsTimeOfDay"); } if (SerializationHelper.HasElement(info, "_bAssumeSRGB")) { _currentSettings._eSRGBMode = info.GetBoolean("_bAssumeSRGB") ? SRGBMode_e.AssumeForDiffuse : SRGBMode_e.Disable; EditorManager.EngineManager.SetSRGBMode(_currentSettings._eSRGBMode); } // The settings from the main layer are migrated to the profiles in OnActivateScene } else //New version that stores profile settings externally { if (currentScene != null) { _currentSettings._skyConfig = new VisionSky(); EditorManager.ProfileManager.LoadProfileSpecificSettings(currentScene, _currentSettings, false); _currentSettings._skyConfig.Dispose(); } _currentSettings = EditorManager.ProfileManager.GetActiveProfileSettings(); } // not profile specific: if (SerializationHelper.HasElement(info, "_sceneScriptFile")) _sceneScriptFile = info.GetString("_sceneScriptFile"); if (SerializationHelper.HasElement(info, "_scriptThinkInterval")) _scriptThinkInterval = info.GetSingle("_scriptThinkInterval"); if (SerializationHelper.HasElement(info, "_orthographicViewBox")) _orthographicViewBox = (OrthographicViewBoxShape)info.GetValue("_orthographicViewBox", typeof(OrthographicViewBoxShape)); if (SerializationHelper.HasElement(info, "_customSceneObjects")) { try { ArrayList objList = (ArrayList)info.GetValue("_customSceneObjects", typeof(ArrayList)); _customSceneObjects = new CustomSceneObjectCollection(objList, this); } catch (Exception e) { _customSceneObjects = null; EditorManager.DumpException(e); string msg = "Failed to load custom plugin objects in the scene file.\nPossible cause might be that a plugin is missing or is not compatible.\nThe scene has been loaded, but some information might be missing.\n\nDetailed information:\n" + e.ToString(); EditorManager.ShowMessageBox(msg, "Serialization exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { _customSceneObjects = new CustomSceneObjectCollection(false, this); if (currentScene != null) { LoadCustomObjectsFromFiles(currentScene.AbsoluteFileName + ".Layers"); } } if (SerializationHelper.HasElement(info, "_mapProjection")) MapProjection = (CoordinateSystem)info.GetValue("_mapProjection", typeof(CoordinateSystem)); else MapProjection = new CoordinateSystem(); if (SerializationHelper.HasElement(info, "SceneReferenceLocation")) SceneReferenceLocation = (Vector3D)info.GetValue("SceneReferenceLocation", typeof(Vector3D)); else SceneReferenceLocation = Vector3D.Zero; if (SerializationHelper.HasElement(info, "_fWorldGeometryThreshold")) _fWorldGeometryThreshold = info.GetSingle("_fWorldGeometryThreshold"); if (SerializationHelper.HasElement(info, "_fEntityThreshold")) _fEntityThreshold = info.GetSingle("_fEntityThreshold"); }
/// <summary> /// Overridden version /// </summary> public override void OnDeserialization() { base.OnDeserialization(); if (_renderer != null) _renderer.Owner = this; if (_customSceneObjects != null) { CustomSceneSerializationArgs customObjArg = new CustomSceneSerializationArgs(_customSceneObjects); EditorManager.OnCustomSceneSerialization(customObjArg); // notify the tools _customSceneObjects = null; } try { MigrateRendererProperties(_renderer); // this can be removed later // new renderer type properties if (RendererNodeClass == IRendererNodeManager.RENDERERNODECLASS_NONE) { RendererNodeClass = IRendererNodeManager.RENDERERNODECLASS_SIMPLE; } { DynamicPropertyCollection oldProperties = _currentSettings._rendererSetup._rendererProperties; DynamicPropertyCollectionType propertiesType = EditorManager.RendererNodeManager.NodeClassTypeManager.GetCollectionType(RendererNodeClass); bool bAddSun = false; if (propertiesType != null) { if (_currentSettings._rendererSetup._rendererProperties == null) _currentSettings._rendererSetup._rendererProperties = propertiesType.CreateInstance(this); else _currentSettings._rendererSetup._rendererProperties = propertiesType.CreateMigratedCollection(oldProperties); } else _currentSettings._rendererSetup._rendererProperties = EditorManager.RendererNodeManager.NodeClassTypeManager.CreateMigratedCollection(oldProperties); if (_currentSettings._rendererSetup._rendererProperties != null) _currentSettings._rendererSetup._rendererProperties.Owner = this; // Vision 8.1: Migrate old time of day properties to a light source that is added to the scene if (RendererNodeClass == IRendererNodeManager.RENDERERNODECLASS_DEFERRED && oldProperties != null) { // migrate old depth fog MigrateFogProperties(); object sun = oldProperties.GetPropertyValue("SunLight", false); if (sun is bool) // seems an 8.0 scene { bAddSun = (bool)sun; if (bAddSun) { // assume that the other properties are there as well: DynLightShape lightShape = new DynLightShape("Sun Light"); lightShape.MakeTimeOfDayLight( (float)oldProperties.GetPropertyValue("SunIntensity", false), (bool)oldProperties.GetPropertyValue("Corona", false), (string)oldProperties.GetPropertyValue("CoronaFilename", false) ); // add shadowmaps? object sunShadow = oldProperties.GetPropertyValue("SunShadowsEnabled", false); if ((sunShadow is bool) && ((bool)sunShadow) == true) { ShapeComponentType t = (ShapeComponentType)EditorManager.EngineManager.ComponentClassManager.GetCollectionType("VShadowMapComponentSpotDirectional"); System.Diagnostics.Debug.Assert(t != null, "Cannot create component of type VShadowMapComponentSpotDirectional"); if (t != null) { ShapeComponent comp = (ShapeComponent)t.CreateInstance(this); float fRange = (float)oldProperties.GetPropertyValue("ShadowRange", false); object oldCascades = oldProperties.GetPropertyValue("ShadowCascades", false); // there might be old maps without this property int iCascades = (oldCascades == null) ? 1 : (int)oldCascades; float fOffset = (float)oldProperties.GetPropertyValue("ShadowOffset", false); comp.SetPropertyValue("CascadeCount", iCascades); if (iCascades == 1) fRange *= 2.0f; comp.SetPropertyValue("CascadeRange[0]", fRange * 0.5f); comp.SetPropertyValue("CascadeRange[1]", fRange); object oldInterval = oldProperties.GetPropertyValue("ShadowCenterUpdateDistance", false); if (oldInterval is float) comp.SetPropertyValue("CameraUpdateInterval", (float)oldInterval, false); comp.SetPropertyValue("ShadowMapSize", (int)oldProperties.GetPropertyValue("ShadowTextureSize", false), false); comp.SetPropertyValue("Bias[0]", fOffset, false); comp.SetPropertyValue("Bias[1]", fOffset, false); object oldMask = oldProperties.GetPropertyValue("ShadowContextFilterBitmask", false); if (oldMask is int) comp.SetPropertyValue("FilterBitmask", (int)oldMask, false); // more properties from lighting pp component? lightShape.AddComponentInternal(comp); } } AddPendingAction(AddShapeAction.CreateAddShapeAction(lightShape, this.Root, this, true)); } } object backLight = oldProperties.GetPropertyValue("BackLight", false); if ((backLight is bool) && ((bool)backLight) == true) { DynLightShape backLightShape = new DynLightShape("Back Light"); AddPendingAction(AddShapeAction.CreateAddShapeAction(backLightShape, this.Root, this, true)); } } } } catch (Exception ex) { EditorManager.DumpException(ex, true); } if (_currentSettings._rendererSetup._rendererComponents != null) _currentSettings._rendererSetup._rendererComponents.MigrateProperties(this, EditorManager.EngineManager.ComponentClassManager); }
public override bool SaveToFile() { if (!base.SaveToFile()) { return false; } // No need to continue if no scene (but, can this ever happen?) if (EditorManager.Scene == null) { return true; } if (_currentSettings._skyConfig != null && EditorManager.Scene != null) { _currentSettings._skyConfig.SaveSky(EditorManager.Scene.AbsoluteFileName + ".Layers\\"); } // Collect any custom scene objects from plug-ins... _customSceneObjects = new CustomSceneObjectCollection(true, this); CustomSceneSerializationArgs customObjArg = new CustomSceneSerializationArgs(_customSceneObjects); EditorManager.OnCustomSceneSerialization(customObjArg); // collect the objects // ...and save them to separate files (one for each plug-in) bool bResult = true; foreach (KeyValuePair<string, ArrayList> pair in _customSceneObjects) { if (String.IsNullOrEmpty(pair.Key) || pair.Value == null || pair.Value.Count < 1) { continue; } string customObjectFileName = EditorManager.Scene.AbsoluteFileName + ".Layers\\" + pair.Key + ".PluginData"; if (!SaveCustomObjectsToFile(customObjectFileName, pair.Value)) { bResult = false; break; } } _customSceneObjects = null; return bResult; }
public override bool SaveToFile() { if (!base.SaveToFile()) { return false; } // No need to continue if no scene (but, can this ever happen?) if (EditorManager.Scene == null) { return true; } if (_currentSettings._skyConfig != null && EditorManager.Scene != null) { _currentSettings._skyConfig.SaveSky(EditorManager.Scene.AbsoluteFileName + ".Layers\\"); } var oldCustomObjects = _customSceneObjects; // Collect any custom scene objects from plug-ins... _customSceneObjects = new CustomSceneObjectCollection(true, this); if (oldCustomObjects != null && !oldCustomObjects.IsLegacyMode) { // Reuse the empty array lists from loading in order to keep serialization stable foreach (var pair in oldCustomObjects) { _customSceneObjects.SetObjects(pair.Key, pair.Value); } } CustomSceneSerializationArgs customObjArg = new CustomSceneSerializationArgs(_customSceneObjects); EditorManager.OnCustomSceneSerialization(customObjArg); // collect the objects // ...and save them to separate files (one for each plug-in) bool bResult = true; foreach (KeyValuePair<string, ArrayList> pair in _customSceneObjects) { if (String.IsNullOrEmpty(pair.Key) || pair.Value == null || pair.Value.Count < 1) { continue; } string customObjectFileName = EditorManager.Scene.AbsoluteFileName + ".Layers\\" + pair.Key + ".PluginData"; if (!SaveCustomObjectsToFile(customObjectFileName, pair.Value)) { bResult = false; break; } } // Clear lists to prevent memory leaks, but keep the ArrayLists around to preserve object identity across serialization foreach (var pair in _customSceneObjects) { pair.Value.Clear(); } return bResult; }