public void TestVolumeCreation()
        {
            TestManager.Helpers.OpenSceneFromFile(Path.Combine(TestManager.Helpers.TestDataDir, @"CustomVolumeShapeTests\empty.scene"));

              CustomVolumeShape volume = new CustomVolumeShape();
              Layer layer = EditorManager.Scene.ActiveLayer;
              EditorManager.Actions.Add(new AddShapeAction(volume, null, layer, false));
              volume.Preview = true;

              AddVolumeVertex(volume, new Vector3F(-200.0f, -200.0f, -136.0f));
              EditorManager.ActiveView.UpdateView(true);
              AddVolumeVertex(volume, new Vector3F( 200.0f, -200.0f, -136.0f));
              EditorManager.ActiveView.UpdateView(true);
              AddVolumeVertex(volume, new Vector3F( 200.0f,  200.0f, -136.0f));
              EditorManager.ActiveView.UpdateView(true);
              AddVolumeVertex(volume, new Vector3F(   0.0f,  250.0f, -136.0f));
              EditorManager.ActiveView.UpdateView(true);
              AddVolumeVertex(volume, new Vector3F(-200.0f,  200.0f, -136.0f));
              EditorManager.ActiveView.UpdateView(true);

              volume.Height = 100.0f;
              EditorManager.ActiveView.UpdateView(true);

              DynLightShape light = new DynLightShape("test light");
              light.LightType = LightSourceType_e.Point;
              light.Position = EditorManager.Scene.CurrentShapeSpawnPosition;
              EditorManager.Actions.Add(AddShapeAction.CreateAddShapeAction(light, null, layer, false));

              ShapeComponent component = CreateLightClippingComponent(volume);
              EditorManager.Actions.Add(new AddShapeComponentAction(light, component));

              for (int i = 0; i < 60; i++)
              {
            EditorManager.ActiveView.UpdateView(true);
              }

              bool success = EditorManager.Scene.SaveAs("volume.scene");
              Assert.IsTrue(success);
              EditorManager.Scene.Close();
              TestManager.Helpers.OpenSceneFromFile(Path.Combine(TestManager.Helpers.TestDataDir, @"CustomVolumeShapeTests\volume.scene"));

              for (int i = 0; i < 60; i++)
              {
            EditorManager.EngineManager.WriteText2D(10.0f, 10.0f, "This is the saved version", VisionColors.White);
            EditorManager.ActiveView.UpdateView(true);
              }

              EditorManager.EditorMode = EditorManager.Mode.EM_PLAYING_IN_EDITOR;
              for (int i = 0; i < 30; i++)
              {
            EditorManager.EngineManager.WriteText2D(10.0f, 10.0f, "Play in editor", VisionColors.White);
            EditorManager.ActiveView.UpdateView(true);
              }
              EditorManager.EditorMode = EditorManager.Mode.EM_NONE;

              EditorManager.Scene.ExportScene(null, null);
              EditorManager.Scene.Close();
              EditorManager.Scene = null;
              TestManager.Helpers.LoadExportedScene("volume.vscene");
              for (int i = 0; i < 60; i++)
              {
            EditorManager.EngineManager.WriteText2D(10.0f, 10.0f, "This is the exported version", VisionColors.White);
            EditorManager.ActiveView.UpdateView(true);
              }

              EditorManager.EditorMode = EditorManager.Mode.EM_NONE;
              TestManager.Helpers.CloseExportedScene();
              TestManager.Helpers.CloseActiveProject();
        }
        private void ApplySettingsOnScene()
        {
            // Set Renderer
              if (radioButton_Forward.Checked)
            _scene.V3DLayer.RendererNodeClass = IRendererNodeManager.RENDERERNODECLASS_FORWARD;
              else if (radioButton_ForwardMobile.Checked)
            _scene.V3DLayer.RendererNodeClass = IRendererNodeManager.RENDERERNODECLASS_MOBILE_FORWARD;
              else if (radioButton_Deferred.Checked)
            _scene.V3DLayer.RendererNodeClass = IRendererNodeManager.RENDERERNODECLASS_DEFERRED;
              else if (radioButton_NoRenderer.Checked)
              {
            _scene.V3DLayer.RendererNodeClass = IRendererNodeManager.RENDERERNODECLASS_SIMPLE;
            return;
              }

              // Enable Post Processors
              ShapeComponentType[] compTypes = EditorManager.RendererNodeManager.ComponentTypes;
              _scene.V3DLayer.RendererSetup._rendererComponents.Clear();
              EditorManager.RendererNodeManager.RemovePostprocessors();
              foreach (ShapeComponentType compType in compTypes)
              {
            if (compType.Hidden)
              continue;

            if (!EditorManager.RendererNodeManager.CanAttachPostprocessor(compType.ProbeComponent))
              continue;

            bool bEnable = false;
            if (compType.UniqueName.Equals("VPostProcessSSAO"))
              bEnable = checkBox_SSAO.Checked;
            else if (compType.UniqueName.Equals("VPostProcessGlow"))
              bEnable = checkBox_Glow.Checked;
            else if (compType.UniqueName.Equals("VPostProcessDepthOfField"))
              bEnable = checkBox_DOF.Checked;
            else if (compType.UniqueName.Equals("VPostProcessToneMapping"))
              bEnable = checkBox_TM.Checked;
            else if (compType.UniqueName.Equals("VPostProcessFXAA"))
              bEnable = checkBox_AA.Checked;
            else if (compType.UniqueName.Equals("VDeferredShadingLights"))
              bEnable = checkBox_Lighting.Checked && radioButton_Deferred.Checked;
            else if (compType.UniqueName.Equals("VDeferredShadingRimLight"))
              bEnable = checkBox_RimLight.Checked && radioButton_Deferred.Checked;
            else if (compType.UniqueName.Equals("VGlobalFogPostprocess"))
              bEnable = checkBox_DepthFog.Checked && radioButton_Deferred.Checked;

            ShapeComponent comp = (ShapeComponent)compType.CreateInstance(_scene.V3DLayer);
            comp.Active = bEnable;
            _scene.V3DLayer.RendererSetup._rendererComponents.Add(comp);
              }

              // Update renderer node
              EditorManager.RendererNodeManager.UpdateRendererNode(_scene.RendererProperties, _scene.Postprocessors);

              // Setup Lighting
              if (checkBox_TOD.Checked)
              {
            _scene.V3DLayer.EnableTimeOfDay = true;

            ShapeBase lightShape = null;
            DynLightShape sunlight = null;
            DynLightShape backlight = null;
            #if !HK_ANARCHY
            SunglareShape sunglare = null;
            #else
            Shape3D sunglare = null;
            #endif

            if (checkBox_Sunlight.Checked)
            {
              sunlight = new DynLightShape("Sun Light");
              lightShape = sunlight;
              sunlight.LightType = LightSourceType_e.Directional;
              sunlight.Position = EditorManager.Scene.CurrentShapeSpawnPosition;
              sunlight.ExportAsStatic = false;
              sunlight.CastModelShadows = checkBox_Shadows.Checked;
              sunlight.CastWorldShadows = checkBox_Shadows.Checked;
              sunlight.MakeTimeOfDayLight(1.0f, true, null);
            }

            // Shadows
            if (checkBox_Shadows.Checked && checkBox_Sunlight.Checked)
            {
            #if !HK_ANARCHY
              ShapeComponentType compType = (ShapeComponentType)EditorManager.EngineManager.ComponentClassManager.GetCollectionType("VShadowMapComponentSunlight");
              System.Diagnostics.Debug.Assert(compType != null, "Cannot create component of type VShadowMapComponentSunlight");
            #else
              ShapeComponentType compType = (ShapeComponentType)EditorManager.EngineManager.ComponentClassManager.GetCollectionType("VMobileShadowMapComponentSpotDirectional");
              System.Diagnostics.Debug.Assert(compType != null, "Cannot create component of type VMobileShadowMapComponentSpotDirectional");
            #endif
              if (compType != null)
              {
            ShapeComponent comp = (ShapeComponent)compType.CreateInstance(sunlight);
            sunlight.AddComponentInternal(comp);
              }
            }

            // Back light
            if (checkBox_Backlight.Checked && checkBox_Sunlight.Checked)
            {
              backlight = new DynLightShape("Back Light");
              backlight.LightType = LightSourceType_e.Directional;
              backlight.Position = EditorManager.Scene.CurrentShapeSpawnPosition;
              backlight.ExportAsStatic = false;
              backlight.CastModelShadows = false;
              backlight.CastWorldShadows = false;
              backlight.MakeTimeOfDayBackLight();
            }

            #if !HK_ANARCHY
            // Sun glare
            if (checkBox_Sunglare.Checked && checkBox_Sunlight.Checked)
            {
              sunglare = new SunglareShape("Sun Glare");
              sunglare.AttachToTimeOfDay = true;
              sunglare.Position = EditorManager.Scene.CurrentShapeSpawnPosition;
            }
            #endif

            // Group light shapes
            if (backlight != null || sunglare != null)
            {
              Group3DShape group = new Group3DShape("Sunlight Shapes");
              group.Position = EditorManager.Scene.CurrentShapeSpawnPosition;
              group.AddChild(sunlight);
              if (backlight != null)
            group.AddChild(backlight);
              if (sunglare != null)
            group.AddChild(sunglare);
              lightShape = group;
            }

            // Add to scene
            if (lightShape != null)
              _scene.V3DLayer.AddShape(lightShape, null);
              }
              else
              {
            _scene.V3DLayer.EnableTimeOfDay = false;
              }
        }
        /// <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 ShapeBase CreateShapeInstance()
        {
            if (!TestManager.IsRunning)
              {
            CreateTimeOfDayLightDlg dlg = new CreateTimeOfDayLightDlg();
            if (dlg.ShowDialog() != DialogResult.OK)
              return null;
            _bShadows = dlg.Shadows;
            _bBackLight = dlg.BackLight;
              }

              ShapeBase returnShape = null;
              DynLightShape light = new DynLightShape("Sunlight");
              returnShape = light;
              light.LightType = LightSourceType_e.Directional;
              light.Position = EditorManager.Scene.CurrentShapeSpawnPosition;
              light.ExportAsStatic = false;
              light.CastModelShadows = _bShadows;
              light.CastWorldShadows = _bShadows;
              light.MakeTimeOfDayLight(1.0f, true, null);

              if (_bShadows)
              {
            #if HK_ANARCHY
            ShapeComponentType t = (ShapeComponentType)EditorManager.EngineManager.ComponentClassManager.GetCollectionType("VMobileShadowMapComponentSpotDirectional");
            System.Diagnostics.Debug.Assert(t != null, "Cannot create component of type VMobileShadowMapComponentSpotDirectional");
            #else
            ShapeComponentType t = (ShapeComponentType)EditorManager.EngineManager.ComponentClassManager.GetCollectionType("VShadowMapComponentSpotDirectional");
            System.Diagnostics.Debug.Assert(t != null, "Cannot create component of type VShadowMapComponentSpotDirectional");
            #endif
            System.Diagnostics.Debug.Assert(t != null, "Cannot create component of type VShadowMapComponentSpotDirectional");
            if (t != null)
            {
              ShapeComponent comp = (ShapeComponent)t.CreateInstance(light);
              light.AddComponentInternal(comp);
            }
              }

              if (_bBackLight)
              {
            DynLightShape backlight = new DynLightShape("Back light");
            backlight.LightType = LightSourceType_e.Directional;
            backlight.Position = EditorManager.Scene.CurrentShapeSpawnPosition;
            backlight.ExportAsStatic = false;
            backlight.MakeTimeOfDayBackLight();

            // return a group instead
            Group3DShape group = new Group3DShape("Sunlight shapes");
            group.Position = EditorManager.Scene.CurrentShapeSpawnPosition;
            group.AddChild(light);
            group.AddChild(backlight);
            returnShape = group;
              }

              return returnShape;
        }
 public override ShapeBase CreateShapeInstance()
 {
     string name = _bStatic ? "StaticSpotlight" : "DynamicSpotlight";
       DynLightShape light = new DynLightShape(name);
       light.LightType = LightSourceType_e.Spotlight;
       light.Position = EditorManager.Scene.CurrentShapeSpawnPosition;
       if (_bStatic)
       {
     light.ExportAsStatic = true;
     light.CastStaticShadows = true;
       }
       return light;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="_owner"></param>
 public LightTypeProperties_SpotLight(DynLightShape _owner)
     : base(_owner)
 {
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="_owner"></param>
 public LightTypeProperties_Directional(DynLightShape _owner)
     : base(_owner)
 {
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="_owner"></param>
 public LightTypePropertiesBase(DynLightShape _owner)
 {
     Owner=_owner;
 }