Example #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //  HELPER FUNCTIONS
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Spawn a directional light (omni light). This light covers everything and comes from a single point from infinte distance.
        /// Good for something like a sun
        /// </summary>
        /// <param name="direction">The direction the light is facing in world space coordinates</param>
        /// <param name="intensity"></param>
        /// <param name="color"></param>
        /// <param name="position">The position is only relevant if drawing shadows</param>
        /// <param name="drawShadows"></param>
        /// <param name="shadowWorldSize">WorldSize is the width/height of the view projection for shadow mapping</param>
        /// <param name="shadowDepth">FarClip for shadow mapping</param>
        /// <param name="shadowResolution"></param>
        /// <param name="shadowFilteringFiltering"></param>
        /// <param name="screenspaceShadowBlur"></param>
        /// <param name="staticshadows">These shadows will not be updated once they are created, moving objects will be shadowed incorrectly</param>
        /// <returns></returns>
        private DirectionalLightSource AddDirectionalLight(Vector3 direction, int intensity, Color color, Vector3 position = default(Vector3), bool drawShadows = false, float shadowWorldSize = 100, float shadowDepth = 100, int shadowResolution = 512, DirectionalLightSource.ShadowFilteringTypes shadowFilteringFiltering = DirectionalLightSource.ShadowFilteringTypes.Poisson, bool screenspaceShadowBlur = false, bool staticshadows = false)
        {
            DirectionalLightSource lightSource = new DirectionalLightSource(color: color,
                                                                            intensity: intensity,
                                                                            direction: direction,
                                                                            position: position,
                                                                            drawShadows: drawShadows,
                                                                            shadowSize: shadowWorldSize,
                                                                            shadowDepth: shadowDepth,
                                                                            shadowResolution: shadowResolution,
                                                                            shadowFiltering: shadowFilteringFiltering,
                                                                            screenspaceshadowblur: screenspaceShadowBlur,
                                                                            staticshadows: staticshadows);

            DirectionalLights.Add(lightSource);
            return(lightSource);
        }
        public RasterizationTestScene(int meshcomplexity = 6)
        {
            var meshes = ThreeMFLoader.LoadFromFile(@".\data\test.3mf").ToList();
            var mesh   = meshes[0];

            Cube = new MeshObject(new Mesh(mesh.Vertices, mesh.Triangles.Select(t => new Triangle(t.Vector1, t.Vector2, t.Vector3)).ToArray(), mesh.Normals), new OpaqueMaterial(1.2f, Color.Red, .8f, .5f));
            Cube.Mesh.Normalize();
            Cube.Mesh.Rotate(MathF.PI / 4, MathF.PI / 4, 0);

            var sphereMesh = ProceduralSphere.GetSphereMesh(1f, meshcomplexity);

            SphereCenter = new Vector3(0, 0, 3.5f);
            Sphere       = new MeshObject(sphereMesh, new OpaqueMaterial(1.2f, Color.Yellow, .8f, .5f));
            Sphere.Mesh.Move(SphereCenter);
            //Sphere.Mesh.CalculateBounds(1);

            Camera      = new RectCamera(new Vector3(-16 / 4 / 2f, -9 / 4 / 2f, -6), new Vector3(16 / 4f, 0, 0), new Vector3(0, 9 / 4f, 0), -4f);
            Scene       = new RasterizationScene(Color.BlueViolet, .3f);
            LightSource = new DirectionalLightSource(new Vector3(-1, 1, 1), 1f);

            Scene.LightSources.Add(LightSource);
            Scene.Objects.Add(Cube);
            Scene.Objects.Add(Sphere);
        }
Example #3
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());
            }
        }