/// <summary> /// Constructor /// </summary> /// <param name="name">layer name</param> public V3DLayer(string name) : base(name) { _currentSettings = new ProfileSpecificSettings(); _currentSettings._skyConfig = new VisionSky(); }
/// <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"); }
protected override void DisposeObject() { if (ParentScene != null) { EditorManager.ProfileManager.ActiveProfileChanged -= new IProfileManager.ActiveProfileChangedEventHandler(IProfileManager_ActiveProfileChanged); EditorManager.ProfileManager.GetCurrentSettings -= new IProfileManager.GetCurrentSettingsEventHandler(IProfileManager_GetCurrentSettings); IScene.PropertyChanged -= new CSharpFramework.PropertyChangedEventHandler(IScene_PropertyChanged); } if (_currentSettings != null && _currentSettings._skyConfig != null) { _currentSettings._skyConfig.Dispose(); } _currentSettings = null; base.DisposeObject(); }