Exemple #1
0
    private IEnumerator ShineLight()
    {
        PointLightSource pls = base.GetComponentInChildren <PointLightSource>();

        if (pls)
        {
            if (base.renderer)
            {
                base.renderer.enabled = false;
            }
            PointLightSource pointLightSource = pls;
            pointLightSource.onLightTurnOff = (Action)Delegate.Combine(pointLightSource.onLightTurnOff, new Action(delegate()
            {
                UnityEngine.Object.Destroy(base.gameObject);
            }));
            pls.isEnabled = true;
            yield return(new WaitForSeconds(pls.turnOnCurve[pls.turnOnCurve.length - 1].time));

            pls.isEnabled = false;
        }
        else
        {
            UnityEngine.Object.Destroy(base.gameObject);
        }
        yield break;
    }
Exemple #2
0
        //The function to use for new pointlights
        /// <summary>
        /// Add a point light to the list of drawn point lights
        /// </summary>
        /// <param name="position"></param>
        /// <param name="radius"></param>
        /// <param name="color"></param>
        /// <param name="intensity"></param>
        /// <param name="castShadows">will render shadow maps</param>
        /// <param name="isVolumetric">does it have a fog volume?</param>
        /// <param name="volumetricDensity">How dense is the volume?</param>
        /// <param name="shadowResolution">shadow map resolution per face. Optional</param>
        /// <param name="staticShadow">if set to true the shadows will not update at all. Dynamic shadows in contrast update only when needed.</param>
        /// <returns></returns>
        private PointLightSource AddPointLight(Vector3 position, float radius, Color color, float intensity, bool castShadows, bool isVolumetric = false, float volumetricDensity = 1, int shadowResolution = 256, bool staticShadow = false)
        {
            PointLightSource light = new PointLightSource(position, radius, color, intensity, castShadows, isVolumetric, shadowResolution, staticShadow, volumetricDensity);

            PointLights.Add(light);
            return(light);
        }
Exemple #3
0
    public override void Awake()
    {
        base.Awake();
        PointLightSource lightSource = this.lightSource;

        lightSource.onLightTurnOff = (Action)Delegate.Combine(lightSource.onLightTurnOff, new Action(this.OnLightOff));
        PointLightSource lightSource2 = this.lightSource;

        lightSource2.onLightTurnOn = (Action)Delegate.Combine(lightSource2.onLightTurnOn, new Action(this.OnLightOn));
    }
Exemple #4
0
        //private void ExportSampler()
        //{
        //    _mitsubaXml.CreateSamplerXml();
        //}

        /// <summary>
        /// This method exports the Mitsuba emitters: lights and environment.
        ///
        /// NOTE: if you try to get the environment with RhinoDoc.ActiveDoc.RenderEnvironments[0]
        /// Rhino crashes with a "pure virtual function called" error...
        /// </summary>
        private void ExportEmitters()
        {
            if (RhinoDoc.ActiveDoc.RenderEnvironments.Count > 0)
            {
                //HDR environment
                var environment = RenderEnvironment.CurrentEnvironment;
                var texture     = environment.FindChild("texture");

                if (texture != null)
                {
                    var env_file = texture.Fields.GetField("filename").ValueAsObject();
                    _mitsubaXml.CreateEnvironmentEmitterXml(env_file.ToString());
                }
            }

            //Lights
            foreach (var obj in RhinoDoc.ActiveDoc.Objects.GetObjectList(ObjectType.Light))
            {
                if (!obj.Visible)
                {
                    continue;
                }

                var objRef = new ObjRef(obj);
                var light  = objRef.Light();

                MitsubaEmitter emitter = null;

                if (light.IsPointLight)
                {
                    //var location = light.Location;
                    //var spectrum = light.Diffuse;
                    //var sampleWeight = light.Intensity;
                    emitter = new PointLightSource(light.Location, (float)light.Intensity * 100);
                }
                else if (light.IsSpotLight)
                {
                    var origin      = light.Location;
                    var target      = light.Direction;
                    var cutoffAngle = (float)RhinoMath.ToDegrees(light.SpotAngleRadians);
                    var intensity   = (float)light.Intensity * 50000;                   //TODO Multiplicador SpotLight ???
                    emitter = new SpotLightSource(origin, target, intensity, cutoffAngle);
                }
                else if (light.IsSunLight)
                {
                    //TODO SunLight
                }

                if (emitter != null)
                {
                    _mitsubaXml.CreateEmitterXml(emitter);
                }
            }
        }
Exemple #5
0
    private void CheckIfSeen(Collider c)
    {
        LightTrigger component = c.GetComponent <LightTrigger>();

        if (component)
        {
            PointLightSource lightSource = component.LightSource;
            if (!lightSource.isEnabled)
            {
                return;
            }
            if (lightSource && lightSource.lightType == PointLightMask.LightType.PointLight)
            {
                this.Disappear();
            }
            else if (lightSource.lightType == PointLightMask.LightType.BeamLight)
            {
                if (Vector3.Distance(base.transform.position, lightSource.beamArcCenter) < lightSource.colliderSize)
                {
                    this.Disappear();
                }
                else
                {
                    float   beamAngle = lightSource.beamAngle;
                    Vector3 b         = Vector3.up * c.transform.position.y + Vector3.right * c.transform.position.x;
                    if (this.collisionPoints != null && this.collisionPoints.Count > 0)
                    {
                        foreach (Vector3 a in this.collisionPoints)
                        {
                            Vector3 from = a - b;
                            float   num  = Vector3.Angle(from, lightSource.transform.up);
                            float   num2 = Vector3.Distance(a, b);
                            if (num2 <= lightSource.baseLightSize + lightSource.borderWidth || num < beamAngle * 0.5f)
                            {
                                this.Disappear();
                            }
                        }
                    }
                    else
                    {
                        Vector3 a2    = Vector3.up * base.transform.position.y + Vector3.right * base.transform.position.x;
                        Vector3 from2 = a2 - b;
                        float   num   = Vector3.Angle(from2, lightSource.transform.up);
                        float   num2  = Vector3.Distance(a2, b);
                        if (num2 <= lightSource.baseLightSize + lightSource.borderWidth || num < beamAngle * 0.5f)
                        {
                            this.Disappear();
                        }
                    }
                }
            }
        }
    }
Exemple #6
0
    private void OnDestroy()
    {
        if (this.lightSource == null)
        {
            return;
        }
        PointLightSource lightSource = this.lightSource;

        lightSource.onLightTurnOff = (Action)Delegate.Remove(lightSource.onLightTurnOff, new Action(this.OnLightOff));
        PointLightSource lightSource2 = this.lightSource;

        lightSource2.onLightTurnOn = (Action)Delegate.Remove(lightSource2.onLightTurnOn, new Action(this.OnLightOn));
    }
Exemple #7
0
        private static void Main()
        {
            var origin       = new Point3D(0, 0, -5);
            var canvasSize   = 1000;
            var canvasDepth  = 10;
            var scale        = 7.0d / (double)canvasSize;
            var ambientColor = new Color(0.1, 0.1, 0.1);

            var rays = from x in Enumerable.Range(-canvasSize / 2, canvasSize)
                       from y in Enumerable.Range(-canvasSize / 2, canvasSize)
                       select(Index: (x, y), Ray: new Ray(origin, new Vector3D(x * scale, y * scale, canvasDepth, true)));

            var sphereColor    = Color.Magenta;
            var sphereMaterial = new PhongMaterial(sphereColor, 0.1, 0.9, 0.9, 200.0);
            var sphere         = new Sphere(Matrix.Shear(Dimension.X, Dimension.Y, 0.5), sphereMaterial);

            var lightPosition = new Point3D(-10, 10, -10);
            var lightColor    = Color.White;
            var lightSource   = new PointLightSource(lightPosition, lightColor);

            var hits = rays.AsParallel()
                       .Select(r => (r.Index, r.Ray, Hit: sphere.Intersect(r.Ray).GetNearestHit()));

            var canvas = new Canvas(canvasSize, canvasSize);

            foreach (var hit in hits)
            {
                var xPixel = hit.Index.x + (canvasSize / 2);
                var yPixel = -hit.Index.y + (canvasSize / 2);

                if (!hit.Hit.HasValue)
                {
                    canvas[xPixel, yPixel] = ambientColor;
                }
                else
                {
                    var surface      = hit.Hit.Value.Surface;
                    var point        = hit.Ray.GetPosition(hit.Hit.Value.Distance);
                    var normalVector = surface.GetNormal(point);
                    var eyeVector    = -hit.Ray.Direction;

                    canvas[xPixel, yPixel] = surface.Material.Illuminate(point, eyeVector, normalVector, lightSource);
                }
            }

            var filePath = $"C:\\temp\\RayVE\\SphereDrawing\\{DateTime.Now:yyyyMMdd_HHmmss}.ppm";

            File.WriteAllText(filePath, canvas.ToPPM(255));
        }
Exemple #8
0
        public void Shade_WithInternalIntersection_ExpectCorrectColor()
        {
            //arrange
            var light        = new PointLightSource(new Point3D(0, 0.25, 0), new Color(1, 1, 1));
            var scene        = new Scene(Scene.Default.Surfaces, light);
            var ray          = new Ray(new Point3D(0, 0, 0), new Vector3D(0, 0, 1));
            var surface      = scene.Surfaces.Skip(1).First();
            var intersection = new Intersection(0.5, surface, ray);

            //act
            var color = scene.Shade(intersection);

            //assert
            Assert.AreEqual(new Color(0.9049844720832575, 0.9049844720832575, 0.9049844720832575), color);
        }
Exemple #9
0
    void OnSceneGUI()
    {
        PointLightSource source = target as PointLightSource;

        // Draw test raycasts
        Info <List <Vector3>, List <Vector3>, List <bool> > testInfo = source.GetTestRaycasts();

        if (testInfo != null)
        {
            for (int i = 0; i < testInfo.arg1.Count; i++)
            {
                Handles.color = (testInfo.arg2[i]) ? Color.green : Color.red;
                Handles.DrawLine(testInfo.arg0[i], testInfo.arg0[i] + testInfo.arg1[i]);
            }
        }
    }
Exemple #10
0
        public void Illuminate_WithLightOffsetBy45Degrees_ExpectCorrectIlluminatedColor()
        {
            //arrange
            var color            = new Color(1, 1, 1);
            var material         = new PhongMaterial(color, 0.1, 0.9, 0.9, 200.0);
            var illuminatedPoint = new Point3D(0, 0, 0);
            var eyeVector        = new Vector3D(0, 0, -1);
            var normalVector     = new Vector3D(0, 0, -1);
            var lightPosition    = new Point3D(0, 10, -10);
            var lightIntensity   = new Color(1, 1, 1);
            var lightSource      = new PointLightSource(lightPosition, lightIntensity);

            //act
            var illuminatedColor = material.Illuminate(illuminatedPoint, eyeVector, normalVector, lightSource);

            //assert
            Assert.AreEqual(new Color(0.73639610, 0.73639610, 0.73639610), illuminatedColor);
        }
Exemple #11
0
        public void Illuminate_WithLightBehindSurface_ExpectNoIllumination()
        {
            //arrange
            var color            = new Color(1, 1, 1);
            var material         = new PhongMaterial(color, 0.1, 0.9, 0.9, 200.0);
            var illuminatedPoint = new Point3D(0, 0, 0);
            var eyeVector        = new Vector3D(0, 0, -1);
            var normalVector     = new Vector3D(0, 0, -1);
            var lightPosition    = new Point3D(0, 0, 10);
            var lightIntensity   = new Color(1, 1, 1);
            var lightSource      = new PointLightSource(lightPosition, lightIntensity);

            //act
            var illuminatedColor = material.Illuminate(illuminatedPoint, eyeVector, normalVector, lightSource);

            //assert
            Assert.AreEqual(new Color(0.1, 0.1, 0.1), illuminatedColor);
        }
Exemple #12
0
        public void Illuminate_WithLightBehindCameraAndIlluminatedPointInShadow_ExpectAmbientColor()
        {
            //arrange
            var color            = new Color(1, 1, 1);
            var material         = new PhongMaterial(color, 0.1, 0.9, 0.9, 200.0);
            var illuminatedPoint = new Point3D(0, 0, 0);
            var eyeVector        = new Vector3D(0, 0, -1);
            var normalVector     = new Vector3D(0, 0, -1);
            var lightPosition    = new Point3D(0, 0, -10);
            var lightIntensity   = new Color(1, 1, 1);
            var lightSource      = new PointLightSource(lightPosition, lightIntensity);
            var isInShadow       = true;

            //act
            var illuminatedColor = material.Illuminate(illuminatedPoint, eyeVector, normalVector, lightSource, isInShadow);

            //assert
            Assert.AreEqual(new Color(0.1, 0.1, 0.1), illuminatedColor);
        }
Exemple #13
0
 public void UpdateMeshes()
 {
     if (this.lightContainer == null)
     {
         this.lightContainer = new GameObject("LightMeshes");
         this.lightContainer.transform.parent        = this.root;
         this.lightContainer.transform.localPosition = Vector3.zero;
         this.lightContainer.transform.localScale    = Vector3.one;
         this.lightContainer.transform.localRotation = Quaternion.identity;
     }
     if (this.lightContainer.transform.childCount > 0)
     {
         for (int i = 0; i < this.lightContainer.transform.childCount; i++)
         {
             UnityEngine.Object.Destroy(this.lightContainer.transform.GetChild(i).gameObject);
         }
     }
     this.lights       = new List <PointLightMask>();
     this.lightSources = new List <PointLightSource>();
     foreach (PointLightSource item in UnityEngine.Object.FindObjectsOfType <PointLightSource>())
     {
         this.lightSources.Add(item);
     }
     for (int k = 0; k < this.lightSources.Count; k++)
     {
         PointLightSource lightSource = this.lightSources[k];
         this.CreateLight(k, lightSource);
     }
     if (this.lightSkinMesh == null)
     {
         this.lightSkinMesh = new GameObject("LightSkinnedMesh");
         this.lightSkinMesh.transform.parent        = this.root;
         this.lightSkinMesh.transform.localPosition = Vector3.zero;
         this.lightSkinMesh.transform.localRotation = Quaternion.identity;
         this.lightSmr = this.lightSkinMesh.AddComponent <SkinnedMeshRenderer>();
         this.lightSmr.updateWhenOffscreen = true;
     }
     this.CollectMeshes();
 }
Exemple #14
0
    private void CheckIfSeen(Collider c)
    {
        if (this.disabled || WPFMonoBehaviour.levelManager.gameState == LevelManager.GameState.Completed)
        {
            return;
        }
        LightTrigger component = c.GetComponent <LightTrigger>();

        if (component)
        {
            PointLightSource lightSource = component.LightSource;
            if (lightSource && lightSource.lightType == PointLightMask.LightType.PointLight)
            {
                this.Collect();
            }
            else if (lightSource.lightType == PointLightMask.LightType.BeamLight)
            {
                if (Vector3.Distance(base.transform.position, lightSource.beamArcCenter) < lightSource.colliderSize)
                {
                    this.Collect();
                }
                else
                {
                    float   beamAngle = lightSource.beamAngle;
                    Vector3 a         = Vector3.up * base.transform.position.y + Vector3.right * base.transform.position.x;
                    Vector3 b         = Vector3.up * c.transform.position.y + Vector3.right * c.transform.position.x;
                    Vector3 from      = a - b;
                    float   num       = Vector3.Angle(from, lightSource.transform.up);
                    if (num < beamAngle * 0.5f)
                    {
                        this.Collect();
                    }
                }
            }
        }
    }
Exemple #15
0
 private void OnGameStateChanged(GameStateChanged newState)
 {
     if (!this.isInit)
     {
         return;
     }
     if (newState.state == LevelManager.GameState.Building)
     {
         if (this.startPls)
         {
             this.startPls.isEnabled = true;
         }
         if (this.disableNv && this.nvOn)
         {
             this.ToggleNightVision();
             this.disableNv = false;
         }
     }
     else if (newState.state == LevelManager.GameState.Running)
     {
         if (this.startPls)
         {
             this.startPls.isEnabled = false;
         }
         GameObject       gameObject = UnityEngine.Object.Instantiate <GameObject>(this.pointLightPrefab);
         PointLightSource component  = gameObject.GetComponent <PointLightSource>();
         if (component != null)
         {
             component.size          = 2f;
             component.canCollide    = true;
             component.canLitObjects = true;
             component.usesCurves    = false;
         }
         if (this.nvOn)
         {
             this.disableNv = true;
         }
         if (gameObject != null)
         {
             gameObject.transform.parent        = this.levelManager.ContraptionRunning.FindPig().transform;
             gameObject.transform.localPosition = Vector3.zero;
         }
         BasePart basePart = this.levelManager.ContraptionRunning.FindPart(BasePart.PartType.GoldenPig);
         if (basePart)
         {
             Transform        transform   = basePart.transform;
             GameObject       gameObject2 = UnityEngine.Object.Instantiate <GameObject>(this.pointLightPrefab);
             PointLightSource component2  = gameObject2.GetComponent <PointLightSource>();
             if (component2 != null)
             {
                 component2.size          = 2f;
                 component2.canCollide    = true;
                 component2.canLitObjects = true;
                 component2.usesCurves    = false;
             }
             gameObject2.transform.parent        = transform.Find("Graphics");
             gameObject2.transform.localPosition = Vector3.zero;
         }
         List <WPFMonoBehaviour> list = new List <WPFMonoBehaviour>();
         foreach (TNT item in UnityEngine.Object.FindObjectsOfType <TNT>())
         {
             list.Add(item);
         }
         foreach (TNTBox item2 in UnityEngine.Object.FindObjectsOfType <TNTBox>())
         {
             list.Add(item2);
         }
         foreach (DynamicTNTBox item3 in UnityEngine.Object.FindObjectsOfType <DynamicTNTBox>())
         {
             list.Add(item3);
         }
         foreach (WPFMonoBehaviour wpfmonoBehaviour in list)
         {
             GameObject       gameObject3 = UnityEngine.Object.Instantiate <GameObject>(this.pointLightPrefab);
             PointLightSource component3  = gameObject3.GetComponent <PointLightSource>();
             component3.size                     = 4f;
             component3.canCollide               = true;
             component3.canLitObjects            = true;
             component3.isEnabled                = false;
             gameObject3.transform.parent        = wpfmonoBehaviour.transform;
             gameObject3.transform.localPosition = Vector3.zero;
         }
         Rocket[] array4 = UnityEngine.Object.FindObjectsOfType <Rocket>();
         foreach (Rocket rocket in array4)
         {
             GameObject       gameObject4 = UnityEngine.Object.Instantiate <GameObject>(this.pointLightPrefab);
             PointLightSource component4  = gameObject4.GetComponent <PointLightSource>();
             component4.size                     = 2f;
             component4.canCollide               = true;
             component4.canLitObjects            = true;
             component4.isEnabled                = false;
             gameObject4.transform.parent        = rocket.transform;
             gameObject4.transform.localPosition = Vector3.zero;
         }
         this.UpdateLights(true);
     }
     if (newState.state == LevelManager.GameState.Building && newState.prevState == LevelManager.GameState.Running)
     {
         this.UpdateLights(true);
     }
 }
Exemple #16
0
 public void Init(PointLightSource pls)
 {
     this.pls = pls;
 }
Exemple #17
0
    private void CreateLight(int id, PointLightSource _lightSource)
    {
        Transform  transform = this.lightContainer.transform;
        GameObject gameObject;

        if (_lightSource.lightType == PointLightMask.LightType.PointLight)
        {
            gameObject      = UnityEngine.Object.Instantiate <GameObject>(this.pointLightPrefab);
            gameObject.name = string.Format("PointLight{0:00}", id);
        }
        else
        {
            gameObject      = UnityEngine.Object.Instantiate <GameObject>(this.beamLightPrefab);
            gameObject.name = string.Format("BeamLight{0:00}", id);
        }
        gameObject.transform.parent        = transform;
        gameObject.transform.localPosition = Vector3.zero;
        gameObject.transform.localScale    = Vector3.one;
        gameObject.transform.localRotation = Quaternion.identity;
        PointLightMask component = gameObject.GetComponent <PointLightMask>();

        component.border = UnityEngine.Object.Instantiate <GameObject>(this.borderPrefab);
        component.border.transform.parent        = transform;
        component.border.transform.localPosition = new Vector3(0f, 0f, 0.1f);
        component.border.transform.localScale    = Vector3.one;
        component.border.transform.localRotation = Quaternion.identity;
        component.border.name       = string.Format("Border{0:00}", id);
        component.radius            = _lightSource.size;
        component.borderWidth       = _lightSource.borderWidth;
        component.lightSource       = _lightSource.transform;
        component.vertexCount       = _lightSource.vertexCount;
        _lightSource.lightTransform = component.transform;
        component.lightType         = _lightSource.lightType;
        if (component.lightType == PointLightMask.LightType.BeamLight)
        {
            BeamLightMask beamLightMask = component as BeamLightMask;
            beamLightMask.angle     = _lightSource.beamAngle;
            beamLightMask.cutHeight = _lightSource.beamCut;
            GameObject gameObject2 = UnityEngine.Object.Instantiate <GameObject>(this.pointLightPrefab);
            gameObject2.name                    = string.Format("BeamLightBase{0:00}", id);
            gameObject2.transform.parent        = transform;
            gameObject2.transform.localPosition = Vector3.zero;
            gameObject2.transform.localScale    = Vector3.one;
            gameObject2.transform.localRotation = Quaternion.identity;
            PointLightMask component2 = gameObject2.GetComponent <PointLightMask>();
            component2.border = UnityEngine.Object.Instantiate <GameObject>(this.borderPrefab);
            component2.border.transform.parent        = transform;
            component2.border.transform.localPosition = new Vector3(0f, 0f, 0.1f);
            component2.border.transform.localScale    = Vector3.one;
            component2.border.transform.localRotation = Quaternion.identity;
            component2.border.name          = string.Format("Border{0:00}", id);
            component2.radius               = 0.5f;
            component2.borderWidth          = 0.5f;
            component2.lightSource          = _lightSource.transform;
            component2.vertexCount          = _lightSource.vertexCount;
            _lightSource.baseLightTransform = component2.transform;
            component2.lightType            = PointLightMask.LightType.PointLight;
            component2.UpdateMesh();
            _lightSource.colliderSize = component2.radius + component2.borderWidth;
            this.lights.Add(component2);
        }
        component.UpdateMesh();
        if (component.lightType == PointLightMask.LightType.BeamLight)
        {
            BeamLightMask beamLightMask2 = (BeamLightMask)component;
            _lightSource.colliderSize  = beamLightMask2.colliderSize;
            _lightSource.beamArcCenter = beamLightMask2.arcCenter;
        }
        else
        {
            _lightSource.colliderSize = _lightSource.size + _lightSource.borderWidth;
        }
        this.lights.Add(component);
    }
Exemple #18
0
        /// <summary>
        /// Main Logic for the editor part
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="entities"></param>
        /// <param name="data"></param>
        public void Update(GameTime gameTime, List <BasicEntity> entities, List <PointLightSource> pointLights, List <DirectionalLightSource> dirLights, EditorReceivedData data, MeshMaterialLibrary meshMaterialLibrary)
        {
            if (Input.WasKeyPressed(Keys.R))
            {
                _gizmoMode = GizmoModes.Rotation;
            }
            if (Input.WasKeyPressed(Keys.T))
            {
                _gizmoMode = GizmoModes.Translation;
            }

            int hoveredId = data.HoveredId;

            if (_gizmoTransformationMode)
            {
                if (Input.mouseState.LeftButton == ButtonState.Pressed)
                {
                    GizmoControl(_gizmoId, data);
                }
                else
                {
                    _gizmoTransformationMode = false;
                }
            }
            else if (Input.WasLMBPressed())
            {
                //Gizmos
                if (hoveredId >= 1 && hoveredId <= 3)
                {
                    _gizmoId = hoveredId;
                    GizmoControl(_gizmoId, data);
                    return;
                }

                if (hoveredId <= 0)
                {
                    SelectedObject = null;
                    return;
                }

                bool foundnew = false;
                //Get the selected entity!
                for (int index = 0; index < entities.Count; index++)
                {
                    var VARIABLE = entities[index];
                    if (VARIABLE.Id == hoveredId)
                    {
                        SelectedObject = VARIABLE;
                        foundnew       = true;
                        break;
                    }
                }
                if (foundnew == false)
                {
                    for (int index = 0; index < pointLights.Count; index++)
                    {
                        PointLightSource pointLightSource = pointLights[index];
                        if (pointLightSource.Id == hoveredId)
                        {
                            SelectedObject = pointLightSource;
                            break;
                        }
                    }

                    for (int index = 0; index < dirLights.Count; index++)
                    {
                        DirectionalLightSource directionalLightSource = dirLights[index];
                        if (directionalLightSource.Id == hoveredId)
                        {
                            SelectedObject = directionalLightSource;
                            break;
                        }
                    }
                }
            }

            //Controls

            if (Input.WasKeyPressed(Keys.Delete))
            {
                //Find object
                if (SelectedObject is BasicEntity)
                {
                    entities.Remove((BasicEntity)SelectedObject);
                    meshMaterialLibrary.DeleteFromRegistry((BasicEntity)SelectedObject);

                    SelectedObject = null;
                }

                else if (SelectedObject is PointLightSource)
                {
                    pointLights.Remove((PointLightSource)SelectedObject);

                    SelectedObject = null;
                }
                else if (SelectedObject is DirectionalLightSource)
                {
                    dirLights.Remove((DirectionalLightSource)SelectedObject);

                    SelectedObject = null;
                }
            }

            if (Input.WasKeyPressed(Keys.Insert))
            {
                if (SelectedObject is BasicEntity)
                {
                    BasicEntity copy = (BasicEntity)SelectedObject.Clone;
                    copy.RegisterInLibrary(meshMaterialLibrary);

                    entities.Add(copy);
                }
                else if (SelectedObject is PointLightSource)
                {
                    PointLightSource copy = (PointLightSource)SelectedObject.Clone;
                    pointLights.Add(copy);
                }
                else if (SelectedObject is DirectionalLightSource)
                {
                    DirectionalLightSource copy = (DirectionalLightSource)SelectedObject.Clone;
                    dirLights.Add(copy);
                }
            }

            if (SelectedObject != null)
            {
                DebugScreen.AddString(SelectedObject.Position.ToString());
            }
        }