/// <summary>
        /// Load the resources.
        /// </summary>
        /// <remarks>Remember to call the base implementation of this method.</remarks>
        protected override void LoadContent()
        {
            // Hello World
            helloWorldText = new GameObject2D();
            helloWorldText.AddComponent <HudText>();
            helloWorldText.HudText.Text.Append("Hello World");
            helloWorldText.Transform.LocalPosition = new Vector3(10, 10, 0);
            // Creating a 3D World
            camera = new GameObject3D();
            camera.AddComponent <Camera>();

            /*body = new GameObject3D();
             * body.AddComponent<ModelFilter>();
             * body.ModelFilter.Model = new FileModel("LamborghiniMurcielago\\Murcielago-Body");
             * body.AddComponent<ModelRenderer>();
             * body.ModelRenderer.Material = new Constant();*/
            body = new GameObject3D(new FileModel("LamborghiniMurcielago\\Murcielago-Body"), new Constant());
            camera.Transform.LookAt(new Vector3(5, 0, 10), Vector3.Zero, Vector3.Up);

            body.ModelRenderer.Material = new BlinnPhong();
            ((BlinnPhong)body.ModelRenderer.Material).DiffuseColor = Color.Yellow;
            directionalLight = new GameObject3D();
            directionalLight.AddComponent <DirectionalLight>();
            directionalLight.DirectionalLight.Color     = new Color(250, 250, 140);
            directionalLight.DirectionalLight.Intensity = 1f;
            directionalLight.Transform.LookAt(new Vector3(0.5f, 0.65f, 1.3f), Vector3.Zero, Vector3.Forward);

            camera.Camera.PostProcess = new PostProcess();
            camera.Camera.PostProcess.ToneMapping.ToneMappingFunction = ToneMapping.ToneMappingFunctionEnumerate.FilmicALU;

            base.LoadContent();
        } // Load
 /// <summary>
 /// If you want to work with the XNA Final Engine Editor the main scene needs to inherit from this class.
 /// </summary>
 protected EditableScene()
 {
     // The engine is not initialized yet but it works.
     editorHiddenUpdateScript = new GameObject3D {
         Layer = Layer.GetLayerByNumber(31)
     };
     editorHiddenUpdateScript.AddComponent <HiddenEditorUpdateScript>();
 } // EditableScene
        } // UpdateTasks

        #endregion

        #region Helper Methods

        /// <summary>
        /// Makes a box that is affected by physics.
        /// </summary>
        private static GameObject3D MakeBox(Vector3 position, float width, float height, float depth, float mass, Material mat)
        {
            var cubeEntity = new Box(position, width, height, depth, mass);
            var gameObject = new GameObject3D(new XNAFinalEngine.Assets.Box(width, height, depth), mat);
            var rigidBody  = (RigidBody)gameObject.AddComponent <RigidBody>();

            rigidBody.Entity = cubeEntity;

            return(gameObject);
        } // MakeBox
        /// <summary>
        /// Rotation gizmo based in Softimage XSI.
        /// </summary>
        internal RotationGizmo()
        {
            // Create the gizmo parts.
            redLine = new GameObject3D {
                Layer = Layer.GetLayerByNumber(31)
            };
            greenLine = new GameObject3D {
                Layer = Layer.GetLayerByNumber(31)
            };
            blueLine = new GameObject3D {
                Layer = Layer.GetLayerByNumber(31)
            };
            redLine.AddComponent <LineRenderer>();
            greenLine.AddComponent <LineRenderer>();
            blueLine.AddComponent <LineRenderer>();
            const int numberOfPoints = 50;
            const int radius         = 1;

            redLine.LineRenderer.Vertices      = new VertexPositionColor[numberOfPoints * 2];
            greenLine.LineRenderer.Vertices    = new VertexPositionColor[numberOfPoints * 2];
            blueLine.LineRenderer.Vertices     = new VertexPositionColor[numberOfPoints * 2];
            redLine.LineRenderer.Vertices[0]   = new VertexPositionColor(Vector3.Transform(new Vector3((float)Math.Sin(0), (float)Math.Cos(0), 0), Matrix.Identity), Color.Red);
            greenLine.LineRenderer.Vertices[0] = new VertexPositionColor(Vector3.Transform(new Vector3((float)Math.Sin(0), (float)Math.Cos(0), 0), Matrix.Identity), new Color(0, 1f, 0));
            blueLine.LineRenderer.Vertices[0]  = new VertexPositionColor(Vector3.Transform(new Vector3((float)Math.Sin(0), (float)Math.Cos(0), 0), Matrix.Identity), Color.Blue);
            for (int i = 1; i < numberOfPoints; i++)
            {
                float angle = i * (3.1416f * 2 / numberOfPoints);
                float x     = (float)Math.Sin(angle) * radius;
                float y     = (float)Math.Cos(angle) * radius;
                redLine.LineRenderer.Vertices[i * 2 - 1]   = new VertexPositionColor(Vector3.Transform(new Vector3(x, y, 0), Matrix.Identity), Color.Red);
                greenLine.LineRenderer.Vertices[i * 2 - 1] = new VertexPositionColor(Vector3.Transform(new Vector3(x, y, 0), Matrix.Identity), new Color(0, 1f, 0));
                blueLine.LineRenderer.Vertices[i * 2 - 1]  = new VertexPositionColor(Vector3.Transform(new Vector3(x, y, 0), Matrix.Identity), Color.Blue);
                redLine.LineRenderer.Vertices[i * 2]       = new VertexPositionColor(Vector3.Transform(new Vector3(x, y, 0), Matrix.Identity), Color.Red);
                greenLine.LineRenderer.Vertices[i * 2]     = new VertexPositionColor(Vector3.Transform(new Vector3(x, y, 0), Matrix.Identity), new Color(0, 1f, 0));
                blueLine.LineRenderer.Vertices[i * 2]      = new VertexPositionColor(Vector3.Transform(new Vector3(x, y, 0), Matrix.Identity), Color.Blue);
            }
            redLine.LineRenderer.Vertices[numberOfPoints * 2 - 1]   = new VertexPositionColor(Vector3.Transform(new Vector3((float)Math.Sin(0), (float)Math.Cos(0), 0), Matrix.Identity), Color.Red);
            greenLine.LineRenderer.Vertices[numberOfPoints * 2 - 1] = new VertexPositionColor(Vector3.Transform(new Vector3((float)Math.Sin(0), (float)Math.Cos(0), 0), Matrix.Identity), new Color(0, 1f, 0));
            blueLine.LineRenderer.Vertices[numberOfPoints * 2 - 1]  = new VertexPositionColor(Vector3.Transform(new Vector3((float)Math.Sin(0), (float)Math.Cos(0), 0), Matrix.Identity), Color.Blue);

            redLine.LineRenderer.Enabled   = false;
            greenLine.LineRenderer.Enabled = false;
            blueLine.LineRenderer.Enabled  = false;
        } // RotationGizmo
        } // NormalizedViewport

        #endregion

        #region Constructor

        /// <summary>
        /// Editor Viewport.
        /// </summary>
        public EditorViewport(RectangleF normalizedViewport, ViewportMode mode)
        {
            #region Controls

            viewportControl = new Container
            {
                Parent   = MainWindow.ViewportsSpace,
                Anchor   = Anchors.Left | Anchors.Top,
                CanFocus = false,
            };
            // Stores the normalized viewport to adapt to screen size changes.
            NormalizedViewport = normalizedViewport;

            ToolBarPanel topPanel = new ToolBarPanel {
                Width = viewportControl.Width
            };
            viewportControl.ToolBarPanel = topPanel;
            ToolBar toolBarTopPanel = new ToolBar
            {
                Parent  = topPanel,
                Movable = true,
                FullRow = true,
            };
            var modeComboBox = new ComboBox
            {
                Parent = topPanel,
                Width  = 200,
                Top    = 2,
            };
            modeComboBox.Items.AddRange(new [] { "Perspective", "Top", "Front", "Right", "Game" });
            modeComboBox.ItemIndex         = 0;
            modeComboBox.ItemIndexChanged += delegate
            {
                switch (modeComboBox.ItemIndex)
                {
                case 0: Mode = ViewportMode.Perspective; break;

                case 1: Mode = ViewportMode.Top; break;

                case 2: Mode = ViewportMode.Front; break;

                case 3: Mode = ViewportMode.Right; break;

                case 4: Mode = ViewportMode.Game; break;
                }
            };
            modeComboBox.Draw += delegate
            {
                if (modeComboBox.ListBoxVisible)
                {
                    return;
                }
                switch (Mode)
                {
                case ViewportMode.Perspective: modeComboBox.ItemIndex = 0; break;

                case ViewportMode.Top: modeComboBox.ItemIndex = 1; break;

                case ViewportMode.Front: modeComboBox.ItemIndex = 2; break;

                case ViewportMode.Right: modeComboBox.ItemIndex = 3; break;

                case ViewportMode.Game: modeComboBox.ItemIndex = 4; break;
                }
            };

            #endregion

            #region Cameras

            // Assets
            ambientLight = new AmbientLight {
                Name = "Editor Camara Ambient Light ", Color = Color.White, Intensity = 5f
            };
            postProcess = new PostProcess   {
                Name = "Editor Camera Post Process"
            };
            postProcess.ToneMapping.ToneMappingFunction = ToneMapping.ToneMappingFunctionEnumerate.FilmicALU;
            postProcess.Bloom.Enabled = false;

            // Editor Camera
            viewportCamera = new GameObject3D();
            viewportCamera.AddComponent <Camera>();
            viewportCamera.Camera.Enabled        = true;
            viewportCamera.Layer                 = Layer.GetLayerByNumber(31);
            viewportCamera.Camera.RenderingOrder = int.MinValue;
            editorCameraScript            = (ScriptEditorCamera)viewportCamera.AddComponent <ScriptEditorCamera>();
            editorCameraScript.Mode       = ScriptEditorCamera.ModeType.Maya;
            editorCameraScript.ClientArea = viewportControl.ClientArea;
            // Camera to render the gizmos and other editor elements.
            // This is done because the gizmos need to be in front of everything and I can't clear the ZBuffer wherever I want.
            helperCamera = new GameObject3D();
            helperCamera.AddComponent <Camera>();
            helperCamera.Camera.Enabled     = true;
            helperCamera.Camera.CullingMask = Layer.GetLayerByNumber(31).Mask; // The editor layer.
            helperCamera.Camera.ClearColor  = Color.Transparent;
            helperCamera.Layer = Layer.GetLayerByNumber(31);
            // Set the viewport camara as master of the gizmo camera.
            helperCamera.Camera.MasterCamera = viewportCamera.Camera;

            #endregion

            // Set default camera transformation in each mode.
            Mode = ViewportMode.Perspective;
            Reset();
            Mode = ViewportMode.Top;
            Reset();
            Mode = ViewportMode.Front;
            Reset();
            Mode = ViewportMode.Right;
            Reset();

            // Set current mode.
            Mode = mode;

            // Adjust viewport dimentions and render target size when the size changes.
            Screen.ScreenSizeChanged += OnScreenSizeChanged;
        } // EditorViewport
        /// <summary>
        /// Translation gizmo based in Softimage XSI.
        /// </summary>
        internal TranslationGizmo()
        {
            if (constantShader == null)
            {
                constantShader = new Shader("Materials\\PickerConstant");
            }
            // Create the gizmo parts.
            Cone cone = new Cone(0.1f, 0.2f, 10);

            redCone = new GameObject3D(cone, new Constant())
            {
                Layer = Layer.GetLayerByNumber(31)
            };
            greenCone = new GameObject3D(cone, new Constant())
            {
                Layer = Layer.GetLayerByNumber(31)
            };
            blueCone = new GameObject3D(cone, new Constant())
            {
                Layer = Layer.GetLayerByNumber(31)
            };
            lines = new GameObject3D {
                Layer = Layer.GetLayerByNumber(31),
            };
            lines.AddComponent <LineRenderer>();
            lines.LineRenderer.Vertices = new VertexPositionColor[6];
            vertices[0]   = new Vector3(0, 0, 0);
            vertices[1]   = new Vector3(1, 0, 0);
            vertices[2]   = new Vector3(0, 1, 0);
            vertices[3]   = new Vector3(0, 0, 1);
            vertices[4]   = new Vector3(1, 1, 0);
            vertices[5]   = new Vector3(0, 1, 1);
            vertices[6]   = new Vector3(1, 0, 1);
            planeRedGreen = new GameObject3D(new Plane(vertices[2], vertices[0], vertices[4], vertices[1]), new Constant {
                DiffuseColor = new Color(255, 255, 0)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeGreenBlue = new GameObject3D(new Plane(vertices[5], vertices[3], vertices[2], vertices[0]), new Constant {
                DiffuseColor = new Color(0, 255, 255)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeBlueRed = new GameObject3D(new Plane(vertices[0], vertices[3], vertices[1], vertices[6]), new Constant {
                DiffuseColor = new Color(255, 0, 255)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeRedGreenInv = new GameObject3D(new Plane(vertices[4], vertices[1], vertices[2], vertices[0]), new Constant {
                DiffuseColor = new Color(255, 255, 0)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeGreenBlueInv = new GameObject3D(new Plane(vertices[2], vertices[0], vertices[5], vertices[3]), new Constant {
                DiffuseColor = new Color(0, 255, 255)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeBlueRedInv = new GameObject3D(new Plane(vertices[1], vertices[6], vertices[0], vertices[3]), new Constant {
                DiffuseColor = new Color(255, 0, 255)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeAll = new GameObject2D {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeAll.AddComponent <LineRenderer>();
            planeAll.LineRenderer.Vertices = new VertexPositionColor[8];

            redCone.ModelRenderer.Enabled           = false;
            greenCone.ModelRenderer.Enabled         = false;
            blueCone.ModelRenderer.Enabled          = false;
            lines.LineRenderer.Enabled              = false;
            planeRedGreen.ModelRenderer.Enabled     = false;
            planeGreenBlue.ModelRenderer.Enabled    = false;
            planeBlueRed.ModelRenderer.Enabled      = false;
            planeRedGreenInv.ModelRenderer.Enabled  = false;
            planeGreenBlueInv.ModelRenderer.Enabled = false;
            planeBlueRedInv.ModelRenderer.Enabled   = false;
            planeAll.LineRenderer.Enabled           = false;
        } // TranslationGizmo
        /// <summary>
        /// Load the resources.
        /// </summary>
        /// <remarks>Remember to call the base implementation of this method.</remarks>
        protected override void LoadContent()
        {
            mainSceneExecuting = true;

            #region Setup Input Controls

            // Create the virtual buttons to control the scene selection.
            new Button
            {
                Name           = "Next Scene",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Keys.Right),
            };
            new Button
            {
                Name           = "Next Scene",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Buttons.DPadRight),
            };
            new Button
            {
                Name           = "Next Scene",
                ButtonBehavior = Button.ButtonBehaviors.AnalogInput,
                AnalogAxis     = AnalogAxes.LeftStickX,
            };
            new Button
            {
                Name           = "Previous Scene",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Keys.Left),
            };
            new Button
            {
                Name           = "Previous Scene",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Buttons.DPadLeft),
            };
            new Button
            {
                Name           = "Previous Scene",
                ButtonBehavior = Button.ButtonBehaviors.AnalogInput,
                AnalogAxis     = AnalogAxes.LeftStickX,
                Invert         = true,
            };
            new Button
            {
                Name           = "Load Scene",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Keys.Enter),
            };
            new Button
            {
                Name           = "Load Scene",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Buttons.A),
            };
            new Button
            {
                Name           = "Back To Menu",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Keys.Escape),
            };
            new Button
            {
                Name           = "Back To Menu",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Buttons.Back),
            };
            new Button
            {
                Name           = "Show Statistics",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Keys.F1),
            };
            new Button
            {
                Name           = "Show Statistics",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Buttons.Start),
            };

            #endregion

            #region Intro Video

            // Load and play the intro video...
            introVideo = new GameObject2D();
            introVideo.AddComponent <VideoRenderer>();
            introVideo.VideoRenderer.Video = new Video("LogosIntro");

            #endregion

            #region Statistics

            Layer.GetLayerByNumber(26).Name    = "Statistics Layer";
            Layer.CurrentCreationLayer         = Layer.GetLayerByNumber(26);
            Layer.GetLayerByNumber(26).Visible = false;
            statistics = new GameObject2D();
            statistics.AddComponent <ScriptStatisticsDrawer>();

            #endregion

            // This scene will be assigned to this layer.
            Layer.GetLayerByNumber(25).Name = "Examples Main Scene Layer";
            // But we hide it until the video is over.
            Layer.GetLayerByNumber(25).Visible = false;
            // Creates the scene objects in this layer;
            Layer.CurrentCreationLayer = Layer.GetLayerByNumber(25);

            #region 3D Camera

            // Camera
            examplesCamera = new GameObject3D();
            examplesCamera.AddComponent <Camera>();
            examplesCamera.AddComponent <SoundListener>();
            examplesCamera.Camera.RenderTargetSize = Size.FullScreen;
            examplesCamera.Camera.FarPlane         = 100;
            examplesCamera.Camera.NearPlane        = 1f; // Do not place a small value here, you can destroy performance, not just precision.
            examplesCamera.Transform.LookAt(new Vector3(0, 0, 25), Vector3.Zero, Vector3.Up);
            examplesCamera.Camera.ClearColor  = Color.Black;
            examplesCamera.Camera.FieldOfView = 180 / 6f;
            examplesCamera.Camera.PostProcess = new PostProcess();
            examplesCamera.Camera.PostProcess.ToneMapping.AutoExposureEnabled = false;
            examplesCamera.Camera.PostProcess.ToneMapping.LensExposure        = 0f;
            examplesCamera.Camera.PostProcess.ToneMapping.ToneMappingFunction = ToneMapping.ToneMappingFunctionEnumerate.FilmicALU;
            examplesCamera.Camera.PostProcess.MLAA.EdgeDetection = MLAA.EdgeDetectionType.Color;
            examplesCamera.Camera.PostProcess.MLAA.Enabled       = true;
            examplesCamera.Camera.AmbientLight = new AmbientLight
            {
                Color     = new Color(80, 75, 85),
                Intensity = 5f,
            };

            #endregion

            finalEngineLogo = new GameObject3D(new FileModel("XNAFinalEngine"), new BlinnPhong {
                DiffuseColor = new Color(250, 250, 250)
            });
            finalEngineLogo.Transform.Position   = new Vector3(-37, 6, 0);
            finalEngineLogo.Transform.LocalScale = new Vector3(1.3f, 1.3f, 1.3f);

            xnaLogo = new GameObject3D(new FileModel("XNA"), new BlinnPhong {
                DiffuseColor = new Color(250, 120, 0)
            });
            xnaLogo.Transform.Position   = new Vector3(-37, 6, 0);
            xnaLogo.Transform.LocalScale = new Vector3(1.3f, 1.3f, 1.3f);

            examplesLogo = new GameObject3D(new FileModel("Examples"), new BlinnPhong {
                DiffuseColor = new Color(150, 250, 0)
            });
            examplesLogo.Transform.Position   = new Vector3(40, 5.7f, 0);
            examplesLogo.Transform.LocalScale = new Vector3(1f, 1f, 1f);

            selectOneScene = new GameObject3D(new FileModel("SelectOneScene"), new BlinnPhong {
                DiffuseColor = new Color(150, 250, 0)
            });
            selectOneScene.Transform.Position = new Vector3(6, -55, 0);

            loading = new GameObject3D(new FileModel("Loading"), new BlinnPhong {
                DiffuseColor = new Color(150, 150, 150)
            });
            loading.Transform.Position    = new Vector3(-7, -5, 0);
            loading.ModelRenderer.Enabled = false;

            directionalLight = new GameObject3D();
            directionalLight.AddComponent <DirectionalLight>();
            directionalLight.DirectionalLight.Color     = new Color(190, 110, 150);
            directionalLight.DirectionalLight.Intensity = 1.2f;
            directionalLight.Transform.LookAt(new Vector3(0.6f, 0.05f, 0.6f), Vector3.Zero, Vector3.Forward);

            #region Scene Information

            exampleImage = new GameObject2D[4];
            exampleTitle = new GameObject2D[4];
            exampleText  = new GameObject2D[4];

            #region Warehouse Scene

            exampleImage[0] = new GameObject2D();
            exampleImage[0].AddComponent <HudTexture>();
            exampleImage[0].HudTexture.Texture = new Texture("ExamplesImages\\WarehouseScene");
            exampleImage[0].Transform.Position = new Vector3(75, 250, 0);
            exampleTitle[0] = new GameObject2D();
            exampleTitle[0].AddComponent <HudText>();
            exampleTitle[0].HudText.Text.Append("Warehouse");
            exampleTitle[0].HudText.Font       = new Font("BellGothicTitle");
            exampleTitle[0].Transform.Position = new Vector3(500, 200, 0);
            exampleText[0] = new GameObject2D();
            exampleText[0].AddComponent <HudText>();
            exampleText[0].HudText.Text.Append("This scene shows a Lamborghini Murcielago LP640 in a warehouse.\n\nThe car consists of 430.000 polygons. The scene includes an ambient light with spherical\nharmonic lighting and horizon based ambient occlusion (PC only), one directional light\nwith cascade shadows,two point lights and one spot light with a light mask. The post\nprocessing stage uses tone mapping, morphological antialiasing (MLAA), bloom and film\ngrain. Also a particles system that emits soft tiled particles was placed.\n\nAlmost all the car was modeled by me, with the exception of some interior elements, the\nengine and the rear lights because of my lack of texture experience and time.\n\nMehar Gill (Dog Fight Studios) provides me the warehouse model (originally created\nby igorlmax).\n\nThe reflections do not match the environment. I plan to address this soon.");
            exampleText[0].HudText.Font       = new Font("BellGothicText");
            exampleText[0].Transform.Position = new Vector3(500, 250, 0);

            #endregion

            #region Physics Scene

            exampleImage[1] = new GameObject2D();
            exampleImage[1].AddComponent <HudTexture>();
            exampleImage[1].HudTexture.Texture = new Texture("ExamplesImages\\PhysicsScene");
            exampleImage[1].Transform.Position = new Vector3(75, 250, 0);
            exampleTitle[1] = new GameObject2D();
            exampleTitle[1].AddComponent <HudText>();
            exampleTitle[1].HudText.Text.Append("Physics Demonstration");
            exampleTitle[1].HudText.Font       = new Font("BellGothicTitle");
            exampleTitle[1].Transform.Position = new Vector3(500, 200, 0);
            exampleText[1] = new GameObject2D();
            exampleText[1].AddComponent <HudText>();
            exampleText[1].HudText.Text.Append("Bepu physics library was integrated on the engine through a simple interface that hides the\ncommunication between the physic and graphic world.\n\nThis example shows the interaction between dynamic and kinematic rigid bodies and static\nmeshes. This example also loads a non-centered sphere, the interface implemented detects\nthe offset between the center of mass of the object and the model space center and match\nboth representations without user action.\n\nGarbage generation could be avoided if the initial pools are configured correctly and no other\nmemory allocation should occur. Bepu physics 1.2 has a bug in witch garbage is generated,\nto avoid this we use the developement version of Bepu that fix this bug.\n\n");
            exampleText[1].HudText.Font       = new Font("BellGothicText");
            exampleText[1].Transform.Position = new Vector3(500, 250, 0);

            #endregion

            #region Animation Scene

            exampleImage[2] = new GameObject2D();
            exampleImage[2].AddComponent <HudTexture>();
            exampleImage[2].HudTexture.Texture = new Texture("ExamplesImages\\AnimationScene");
            exampleImage[2].Transform.Position = new Vector3(75, 250, 0);
            exampleTitle[2] = new GameObject2D();
            exampleTitle[2].AddComponent <HudText>();
            exampleTitle[2].HudText.Text.Append("Animations");
            exampleTitle[2].HudText.Font       = new Font("BellGothicTitle");
            exampleTitle[2].Transform.Position = new Vector3(500, 200, 0);
            exampleText[2] = new GameObject2D();
            exampleText[2].AddComponent <HudText>();
            exampleText[2].HudText.Text.Append("This is the simple scene used to test the animation system. It includes three animations:\nwalk, run and shoot. Animation blending is performed in the transition between different\nactions.\n\nDog Fight Studios have shared with us three of their test animations resources. However\nthe animations should not be used in commercial projects.");
            exampleText[2].HudText.Font       = new Font("BellGothicText");
            exampleText[2].Transform.Position = new Vector3(500, 250, 0);

            #endregion

            #region Hellow World Scene

            exampleImage[3] = new GameObject2D();
            exampleImage[3].AddComponent <HudTexture>();
            exampleImage[3].HudTexture.Texture = new Texture("ExamplesImages\\HelloWorldScene");
            exampleImage[3].Transform.Position = new Vector3(75, 250, 0);
            exampleTitle[3] = new GameObject2D();
            exampleTitle[3].AddComponent <HudText>();
            exampleTitle[3].HudText.Text.Append("Hello World");
            exampleTitle[3].HudText.Font       = new Font("BellGothicTitle");
            exampleTitle[3].Transform.Position = new Vector3(500, 200, 0);
            exampleText[3] = new GameObject2D();
            exampleText[3].AddComponent <HudText>();
            exampleText[3].HudText.Text.Append("This is from the documentation's tutorial that shows you how to create a simple scene\nso that you can understand the basic mechanism involved in the creation of a game world.");
            exampleText[3].HudText.Font       = new Font("BellGothicText");
            exampleText[3].Transform.Position = new Vector3(500, 250, 0);

            #endregion

            #region Editor Scene

            /*#if !Xbox
             *  exampleImage[3] = new GameObject2D();
             *  exampleImage[3].AddComponent<HudTexture>();
             *  exampleImage[3].HudTexture.Texture = new Texture("ExamplesImages\\EditorScene");
             *  exampleImage[3].Transform.Position = new Vector3(75, 250, 0);
             *  exampleTitle[3] = new GameObject2D();
             *  exampleTitle[3].AddComponent<HudText>();
             *  exampleTitle[3].HudText.Text.Append("Editor");
             *  exampleTitle[3].HudText.Font = new Font("BellGothicTitle");
             *  exampleTitle[3].Transform.Position = new Vector3(500, 200, 0);
             *  exampleText[3] = new GameObject2D();
             *  exampleText[3].AddComponent<HudText>();
             *  exampleText[3].HudText.Text.Append("Unfortunately the editor is not finished, but most of the key elements are already done and it is\nvery easy to create new windows because everything is parameterized (thanks in part to .NET\nreflection) and its internal code is very clean.\n\nAt the moment it is possible to transform objects in global and local space, configure materials,\nlights, shadows, cameras and the post processing stage. You can also see the scene from\northographic views and perform undo and redo operations over almost all editor commands.\n\nIn the Editor Shortcuts section of the CodePlex documentation there is a list of all useful\nkeyboard shortcuts.");
             *  exampleText[3].HudText.Font = new Font("BellGothicText");
             *  exampleText[3].Transform.Position = new Vector3(500, 250, 0);
             #endif*/

            #endregion

            #endregion

            #region Legend

            demoLegend = new GameObject2D();
            var legend = (HudText)demoLegend.AddComponent <HudText>();
            legend.Color = new Color(0.5f, 0.5f, 0.5f, 1f);
            #if XBOX
            legend.Text.Append("Start to show the statistics\n");
            legend.Text.Append("Back to comeback to this menu");
            #else
            legend.Text.Append("Start or F1 to show the statistics\n");
            legend.Text.Append("Back or Escape to comeback to this menu");
            #endif

            #endregion

            // Set Default Layer.
            Layer.CurrentCreationLayer = Layer.GetLayerByNumber(0);

            MusicManager.LoadAllSong(true);
            MusicManager.Play(1, true);
        } // Load
Exemple #8
0
        /// <summary>
        /// Load the resources.
        /// </summary>
        protected override void LoadContent()
        {

            #region Camera
            
            camera = new GameObject3D();
            camera.AddComponent<Camera>();
            camera.AddComponent<SoundListener>();
            camera.Camera.RenderTargetSize = Size.FullScreen;
            camera.Camera.FarPlane = 300;
            camera.Camera.NearPlane = 1f; // Do not place a small value here, you can destroy performance, not just precision.
            camera.Transform.LookAt(new Vector3(0, 0, 15), Vector3.Zero, Vector3.Up);
            WarehouseCameraScript script = (WarehouseCameraScript)camera.AddComponent<WarehouseCameraScript>();
            //script.SetPosition(new Vector3(0, 3, 18), new Vector3(0, 1.5f, 2.2f));
            script.SetPosition(new Vector3(10, 3, 18), new Vector3(0, 1.5f, 3.2f));
            camera.Camera.ClearColor = Color.Black;
            camera.Camera.FieldOfView = 180 / 7f;
            camera.Camera.PostProcess = new PostProcess();
            camera.Camera.PostProcess.ToneMapping.AutoExposureEnabled = false;
            camera.Camera.PostProcess.ToneMapping.LensExposure = -0.5f;
            camera.Camera.PostProcess.ToneMapping.ToneMappingFunction = ToneMapping.ToneMappingFunctionEnumerate.FilmicALU;
            camera.Camera.PostProcess.MLAA.EdgeDetection = MLAA.EdgeDetectionType.Color;
            camera.Camera.PostProcess.MLAA.Enabled = true;
            camera.Camera.PostProcess.Bloom.Enabled = true;
            camera.Camera.PostProcess.Bloom.Threshold = 3f;
            camera.Camera.PostProcess.FilmGrain.Enabled = true;
            camera.Camera.PostProcess.FilmGrain.Strength = 0.15f;
            /*camera.Camera.PostProcess.AdjustLevels.Enabled = true;
            camera.Camera.PostProcess.AdjustLevels.InputGamma = 0.9f;
            camera.Camera.PostProcess.AdjustLevels.InputWhite = 0.95f;*/
            camera.Camera.PostProcess.AnamorphicLensFlare.Enabled = false;
            camera.Camera.PostProcess.ColorCorrection.Enabled = true;
            camera.Camera.PostProcess.ColorCorrection.FirstLookupTable = new LookupTable("LookupTableWarehouse"); // A little more red and blue.
            camera.Camera.AmbientLight = new AmbientLight
            {
                SphericalHarmonicLighting = SphericalHarmonicL2.GenerateSphericalHarmonicFromCubeTexture(new TextureCube("FactoryCatwalkRGBM") { IsRgbm = true, RgbmMaxRange = 50, }),
                Color = new Color(10, 10, 10),
                Intensity = 2f,
                AmbientOcclusionStrength = 1.5f
            };
            //camera.Camera.Sky = new Skydome { Texture = new Texture("HotPursuitSkydome") };
            //camera.Camera.Sky = new Skybox { TextureCube = new TextureCube("FactoryCatwalkRGBM") { IsRgbm = true, RgbmMaxRange = 50, } };
            #if !XBOX
                camera.Camera.AmbientLight.AmbientOcclusion = new HorizonBasedAmbientOcclusion
                {
                    NumberSteps = 12,
                    NumberDirections = 12,
                    Radius = 0.003f, // Bigger values produce more cache misses and you don’t want GPU cache misses, trust me.
                    LineAttenuation = 1.0f,
                    Contrast = 1.1f,
                    AngleBias = 0.1f,
                    Quality = HorizonBasedAmbientOcclusion.QualityType.HighQuality,
                    TextureSize = Size.TextureSize.HalfSize,
                };
            #endif

            #region Test Split Screen
            /*
            camera.Camera.NormalizedViewport = new RectangleF(0, 0, 1, 0.5f);
            camera2 = new GameObject3D();
            camera2.AddComponent<Camera>();
            camera2.Camera.MasterCamera = camera.Camera;
            camera2.Camera.ClearColor = Color.Black;
            camera2.Camera.FieldOfView = 180 / 8.0f;
            camera2.Camera.NormalizedViewport = new RectangleF(0, 0.5f, 1, 0.5f);
            camera2.Transform.LookAt(new Vector3(-5, 5, -15), new Vector3(0, 3, 0), Vector3.Up);
            camera2.Camera.AmbientLight = camera.Camera.AmbientLight;
            camera2.Camera.PostProcess = new PostProcess();
            camera2.Camera.PostProcess.ToneMapping.AutoExposureEnabled = true;
            camera2.Camera.PostProcess.ToneMapping.LensExposure = 0.5f;
            camera2.Camera.PostProcess.ToneMapping.ToneMappingFunction = ToneMapping.ToneMappingFunctionEnumerate.FilmicALU;
            camera2.Camera.PostProcess.MLAA.EdgeDetection = MLAA.EdgeDetectionType.Color;
            camera2.Camera.PostProcess.MLAA.Enabled = true;
            camera2.Camera.PostProcess.Bloom.Enabled = true;
            camera2.Camera.PostProcess.Bloom.Threshold = 3f;
            camera2.Camera.PostProcess.FilmGrain.Enabled = true;
            camera2.Camera.PostProcess.FilmGrain.Strength = 0.15f;
            */
            #endregion

            #endregion
            
            #region Models
            
            #if XBOX
                warehouseWalls = new GameObject3D(new FileModel("Warehouse\\WarehouseWallsXbox"),
                                                  new BlinnPhong
                                                      {
                                                          DiffuseTexture = new Texture("Warehouse\\Warehouse-DiffuseXbox"),
                                                          SpecularTexture = new Texture("Warehouse\\Warehouse-SpecularXbox"),
                                                          SpecularIntensity = 3,
                                                          SpecularPower = 30000,
                                                      });
                warehouseRoof  = new GameObject3D(new FileModel("Warehouse\\WarehouseRoofXbox"),  
                                                  new BlinnPhong
                                                      {
                                                          DiffuseTexture = new Texture("Warehouse\\MetalRoof-DiffuseXbox")
                                                      });
                warehouseRoof1 = new GameObject3D(new FileModel("Warehouse\\WarehouseRoof1Xbox"),
                                                  new BlinnPhong
                                                  {
                                                      DiffuseTexture = new Texture("Warehouse\\MetalRoof2-DiffuseXbox")
                                                  });

                warehouseWood = new GameObject3D(new FileModel("Warehouse\\WarehouseWoodXbox"),
                                                 new BlinnPhong
                                                 {
                                                     DiffuseTexture = new Texture("Warehouse\\Wood-DiffuseXbox")
                                                 });

                warehouseWood2 = new GameObject3D(new FileModel("Warehouse\\WarehouseWood2Xbox"),
                                                  new BlinnPhong
                                                  {
                                                      DiffuseTexture = new Texture("Warehouse\\Wood2-DiffuseXbox")
                                                  });

                warehouseBrokenWindow = new GameObject3D(new FileModel("Warehouse\\WarehouseBrokenWindowXbox"),
                                                 new BlinnPhong
                                                 {
                                                     DiffuseTexture = new Texture("Warehouse\\Window-DiffuseXbox")
                                                 });

                warehouseWindow = new GameObject3D(new FileModel("Warehouse\\WarehouseWindowXbox"),
                                                  new BlinnPhong
                                                  {
                                                      DiffuseTexture = new Texture("Warehouse\\Window-DiffuseXbox")
                                                  });
                warehouseGround = new GameObject3D(new FileModel("Warehouse\\WarehouseGroundXbox"),
                                                  new BlinnPhong
                                                  {
                                                      DiffuseTexture = new Texture("Warehouse\\Ground-DiffuseXbox"),
                                                      NormalTexture = new Texture("Warehouse\\Ground-NormalsXbox"),
                                                      SpecularIntensity = 0.7f
                                                  });
            #else
                warehouseWalls = new GameObject3D(new FileModel("Warehouse\\WarehouseWalls"),
                                                  new BlinnPhong
                                                      {
                                                          DiffuseTexture = new Texture("Warehouse\\Warehouse-Diffuse"),
                                                          SpecularTexture = new Texture("Warehouse\\Warehouse-Specular"),
                                                          SpecularIntensity = 3,
                                                          SpecularPower = 30000,
                                                      });
                warehouseRoof  = new GameObject3D(new FileModel("Warehouse\\WarehouseRoof"),  
                                                  new BlinnPhong
                                                      {
                                                          DiffuseTexture = new Texture("Warehouse\\MetalRoof-Diffuse")
                                                      });
                warehouseRoof1 = new GameObject3D(new FileModel("Warehouse\\WarehouseRoof1"),
                                                  new BlinnPhong
                                                  {
                                                      DiffuseTexture = new Texture("Warehouse\\MetalRoof2-Diffuse")
                                                  });

                warehouseWood = new GameObject3D(new FileModel("Warehouse\\WarehouseWood"),
                                                 new BlinnPhong
                                                 {
                                                     DiffuseTexture = new Texture("Warehouse\\Wood-Diffuse")
                                                 });

                warehouseWood2 = new GameObject3D(new FileModel("Warehouse\\WarehouseWood2"),
                                                  new BlinnPhong
                                                  {
                                                      DiffuseTexture = new Texture("Warehouse\\Wood2-Diffuse")
                                                  });

                warehouseBrokenWindow = new GameObject3D(new FileModel("Warehouse\\WarehouseBrokenWindow"),
                                                 new BlinnPhong
                                                 {
                                                     DiffuseTexture = new Texture("Warehouse\\Window-Diffuse")
                                                 });

                warehouseWindow = new GameObject3D(new FileModel("Warehouse\\WarehouseWindow"),
                                                  new BlinnPhong
                                                  {
                                                      DiffuseTexture = new Texture("Warehouse\\Window-Diffuse")
                                                  });
                warehouseGround = new GameObject3D(new FileModel("Warehouse\\WarehouseGround"),
                                                  new BlinnPhong
                                                  {
                                                      DiffuseTexture = new Texture("Warehouse\\Ground-Diffuse"),
                                                      NormalTexture = new Texture("Warehouse\\Ground-Normals"),
                                                      SpecularIntensity = 0.7f
                                                  });
            #endif

            #endregion
            
            #region Shadows and Lights

            Shadow.DistributeShadowCalculationsBetweenFrames = true;
            
            directionalLight = new GameObject3D();
            directionalLight.AddComponent<DirectionalLight>();
            directionalLight.DirectionalLight.Color = new Color(190, 190, 150);
            directionalLight.DirectionalLight.Intensity = 9.2f;
            directionalLight.Transform.LookAt(new Vector3(0.3f, 0.95f, -0.3f), Vector3.Zero, Vector3.Forward);
            DirectionalLight.Sun = directionalLight.DirectionalLight;
            directionalLight.DirectionalLight.Shadow = new CascadedShadow
            {
                Filter = Shadow.FilterType.PcfPosion,
                LightDepthTextureSize = Size.Square512X512,
                ShadowTextureSize = Size.TextureSize.FullSize, // Lower than this could produce artifacts if the light is too intense.
                DepthBias = 0.0025f,
                FarPlaneSplit1 = 15,
                FarPlaneSplit2 = 40,
                FarPlaneSplit3 = 100,
                //FarPlaneSplit4 = 150
            };
            /*directionalLight.DirectionalLight.Shadow = new BasicShadow
            {
                Filter = Shadow.FilterType.PcfPosion,
                LightDepthTextureSize = Size.Square512X512,
                ShadowTextureSize = Size.TextureSize.FullSize, // Lower than this could produce artifacts if the light is to intense.
                DepthBias = 0.0025f,
                Range = 100,
            };*/
            
            pointLight = new GameObject3D();
            pointLight.AddComponent<PointLight>();
            pointLight.PointLight.Color = new Color(180, 190, 230);
            pointLight.PointLight.Intensity = 0.3f;
            pointLight.PointLight.Range = 60;
            pointLight.Transform.Position = new Vector3(4.8f, 1.5f, 10);
            //pointLight.PointLight.Shadow = new CubeShadow { LightDepthTextureSize = 512, };

            pointLight = new GameObject3D();
            pointLight.AddComponent<PointLight>();
            pointLight.PointLight.Color = new Color(130, 130, 190);
            pointLight.PointLight.Intensity = 0.7f;
            pointLight.PointLight.Range = 60;
            pointLight.Transform.Position = new Vector3(-4.8f, 0, -4);

            /*pointLightClipVolumeTest = new GameObject3D();
            pointLightClipVolumeTest.AddComponent<PointLight>();
            pointLightClipVolumeTest.PointLight.Color = new Color(250, 20, 20);
            pointLightClipVolumeTest.PointLight.Intensity = 2f;
            pointLightClipVolumeTest.PointLight.Range = 60;
            pointLightClipVolumeTest.PointLight.ClipVolume = new FileModel("ClipVolume");
            pointLightClipVolumeTest.PointLight.RenderClipVolumeInLocalSpace = true;
            pointLightClipVolumeTest.Transform.Position = new Vector3(26f, 7, 35);*/

            spotLight = new GameObject3D();
            spotLight.AddComponent<SpotLight>();
            spotLight.SpotLight.Color = new Color(0, 250, 0);
            spotLight.SpotLight.Intensity = 0.5f;
            spotLight.SpotLight.Range = 40; // I always forget to set the light range lower than the camera far plane.
            spotLight.Transform.Position = new Vector3(0, 16, 15);
            spotLight.Transform.Rotate(new Vector3(-80, 0, 0));
            spotLight.SpotLight.LightMaskTexture = new Texture("LightMasks\\TestLightMask");
            /*spotLight.SpotLight.Shadow = new BasicShadow
            {
                Filter = Shadow.FilterType.PcfPosion,
                LightDepthTextureSize = Size.Square512X512,
                ShadowTextureSize = Size.TextureSize.FullSize,
                DepthBias = 0.0005f,
            };*/
            
            #endregion
            
            #region Lamborghini Murcielago LP640
           
            lamborghiniMurcielagoLoader = new LamborghiniMurcielagoLoader();
            lamborghiniMurcielagoLoader.LoadContent();
            lamborghiniMurcielagoLoader.LamborghiniMurcielago.Transform.LocalScale = new Vector3(1.2f, 1.2f, 1.2f);
            lamborghiniMurcielagoLoader.LamborghiniMurcielago.Transform.LocalPosition = new Vector3(0, 1.4f, 2.35f);
            lamborghiniMurcielagoLoader.TiresAngle = -40;
            
            #endregion

            #region Particles
            
            // Pit particles
            GameObject3D particles = new GameObject3D();
            particles.AddComponent<ParticleEmitter>();
            particles.AddComponent<ParticleRenderer>();
            particles.ParticleEmitter.MaximumNumberParticles = 75;
            particles.Transform.LocalPosition = new Vector3(-1.2f, 0, -13);
            particles.ParticleEmitter.Duration = 50f;
            particles.ParticleEmitter.EmitterVelocitySensitivity = 1;
            particles.ParticleEmitter.MinimumHorizontalVelocity = 1;
            particles.ParticleEmitter.MaximumHorizontalVelocity = 2f;
            particles.ParticleEmitter.MinimumVerticalVelocity = 1;
            particles.ParticleEmitter.MaximumVerticalVelocity = 2;
            particles.ParticleRenderer.Texture = new Texture("Particles\\Smoke");
            particles.ParticleRenderer.SoftParticles = true;
            particles.ParticleRenderer.FadeDistance = 25.0f;
            particles.ParticleRenderer.BlendState = BlendState.NonPremultiplied;
            particles.ParticleRenderer.DurationRandomness = 0.1f;
            particles.ParticleRenderer.Gravity = new Vector3(0, 1, 5);
            particles.ParticleRenderer.EndVelocity = 0.75f;
            particles.ParticleRenderer.MinimumColor = Color.Red;
            particles.ParticleRenderer.MaximumColor = Color.White;
            particles.ParticleRenderer.RotateSpeed = new Vector2(-0.3f, 0.25f);
            particles.ParticleRenderer.StartSize = new Vector2(25, 30);
            particles.ParticleRenderer.EndSize = new Vector2(75, 100);
            particles.ParticleRenderer.TilesX = 1;
            particles.ParticleRenderer.TilesY = 1;
            particles.ParticleRenderer.AnimationRepetition = 1;

            particles = new GameObject3D();
            particles.AddComponent<ParticleEmitter>();
            particles.AddComponent<ParticleRenderer>();
            particles.ParticleEmitter.MaximumNumberParticles = 75;
            particles.Transform.LocalPosition = new Vector3(-3.2f, 0, 13);
            particles.ParticleEmitter.Duration = 50f;
            particles.ParticleEmitter.EmitterVelocitySensitivity = 1;
            particles.ParticleEmitter.MinimumHorizontalVelocity = 1;
            particles.ParticleEmitter.MaximumHorizontalVelocity = 2f;
            particles.ParticleEmitter.MinimumVerticalVelocity = 1;
            particles.ParticleEmitter.MaximumVerticalVelocity = 2;
            particles.ParticleRenderer.Texture = new Texture("Particles\\Smoke");
            particles.ParticleRenderer.SoftParticles = true;
            particles.ParticleRenderer.FadeDistance = 25.0f;
            particles.ParticleRenderer.BlendState = BlendState.NonPremultiplied;
            particles.ParticleRenderer.DurationRandomness = 0.1f;
            particles.ParticleRenderer.Gravity = new Vector3(0, 1, -5);
            particles.ParticleRenderer.EndVelocity = 0.75f;
            particles.ParticleRenderer.MinimumColor = Color.Red;
            particles.ParticleRenderer.MaximumColor = Color.White;
            particles.ParticleRenderer.RotateSpeed = new Vector2(-0.2f, 0.2f);
            particles.ParticleRenderer.StartSize = new Vector2(25, 50);
            particles.ParticleRenderer.EndSize = new Vector2(75, 100);
            particles.ParticleRenderer.TilesX = 1;
            particles.ParticleRenderer.TilesY = 1;
            particles.ParticleRenderer.AnimationRepetition = 1;
            
            #endregion

            #region Statistics

            Layer.GetLayerByNumber(26).Name = "Statistics Layer";
            GameObject2D statistics = new GameObject2D();
            statistics.AddComponent<ScriptStatisticsDrawer>();

            #endregion

            #region Legend
            /*
            demoLegend = new GameObject2D();
            var legend = (HudText)demoLegend.AddComponent<HudText>();
            legend.Color = new Color(0.1f, 0.1f, 0.1f, 1f);
            #if XBOX
                legend.Text.Append("A to open the doors\n");
                legend.Text.Append("Left stick to rotate the wheels");
            #else
                legend.Text.Append("Space or A to open the doors\n");
                legend.Text.Append("Left and right cursors or left stick to rotate the wheels\n");
                legend.Text.Append("Left mouse button or right stick to move the camera");
            #endif*/
            
            #endregion
            
        } // Load
Exemple #9
0
        /// <summary>
        /// Load the resources.
        /// </summary>
        /// <remarks>Remember to call the base implementation of this method.</remarks>
        protected override void LoadContent()
        {
            #region Setup Input Controls

            buttons = new Button[4];

            // Create the virtual buttons to control the scene selection.
            buttons[0] = new Button
            {
                Name           = "Attack",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Keys.Space),
            };
            buttons[1] = new Button
            {
                Name           = "Attack",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Buttons.RightTrigger),
            };
            axis = new Axis
            {
                Name         = "Walk",
                AnalogAxis   = AnalogAxes.LeftStickY,
                AxisBehavior = Axis.AxisBehaviors.AnalogInput,
            };
            buttons[2] = new Button
            {
                Name           = "WalkPC",
                KeyButton      = new KeyButton(Keys.W),
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput
            };
            buttons[3] = new Button
            {
                Name           = "RunPC",
                KeyButton      = new KeyButton(Keys.LeftShift),
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput
            };

            #endregion

            #region Camera

            camera = new GameObject3D();
            camera.AddComponent <Camera>();
            camera.AddComponent <SoundListener>();
            camera.Camera.RenderTargetSize = Size.FullScreen;
            camera.Camera.FarPlane         = 100;
            camera.Camera.NearPlane        = 1f;
            camera.Transform.LookAt(new Vector3(-10, 10, 20), new Vector3(0, 5, 0), Vector3.Up);
            //ScriptCustomCameraScript script = (ScriptCustomCameraScript)camera.AddComponent<ScriptCustomCameraScript>();
            //script.SetPosition(new Vector3(0, 10, 20), new Vector3(0, 5, 0));
            camera.Camera.ClearColor  = Color.Black;
            camera.Camera.FieldOfView = 180 / 6f;
            camera.Camera.PostProcess = new PostProcess();
            camera.Camera.PostProcess.ToneMapping.AutoExposureEnabled = true;
            camera.Camera.PostProcess.MLAA.Enabled       = true;
            camera.Camera.PostProcess.MLAA.EdgeDetection = MLAA.EdgeDetectionType.Color;
            camera.Camera.PostProcess.Bloom.Threshold    = 3.5f;
            camera.Camera.AmbientLight = new AmbientLight
            {
                SphericalHarmonicLighting = SphericalHarmonicL2.GenerateSphericalHarmonicFromCubeTexture(new TextureCube("FactoryCatwalkRGBM")
                {
                    IsRgbm = true, RgbmMaxRange = 50,
                }),
                Color     = new Color(10, 10, 10),
                Intensity = 5f,
            };
            //camera.Camera.Sky = new Skybox { TextureCube = new TextureCube("FactoryCatwalkRGBM") { IsRgbm = true, RgbmMaxRange = 50, } };

            #endregion

            #region Models

            dude = new GameObject3D(new FileModel("DudeWalk"), new BlinnPhong());
            // One material for mesh part.
            dude.ModelRenderer.MeshMaterials    = new Material[5];
            dude.ModelRenderer.MeshMaterials[0] = new BlinnPhong {
                DiffuseTexture = new Texture("Dude\\head"), NormalTexture = new Texture("Dude\\headN"), SpecularTexture = new Texture("Dude\\headS"), SpecularPowerFromTexture = false, SpecularPower = 300
            };
            dude.ModelRenderer.MeshMaterials[2] = new BlinnPhong {
                DiffuseTexture = new Texture("Dude\\jacket"), NormalTexture = new Texture("Dude\\jacketN"), SpecularTexture = new Texture("Dude\\jacketS"), SpecularPowerFromTexture = false, SpecularPower = 300
            };
            dude.ModelRenderer.MeshMaterials[3] = new BlinnPhong {
                DiffuseTexture = new Texture("Dude\\pants"), NormalTexture = new Texture("Dude\\pantsN"), SpecularTexture = new Texture("Dude\\pantsS"), SpecularPowerFromTexture = false, SpecularPower = 300
            };
            dude.ModelRenderer.MeshMaterials[1] = new BlinnPhong {
                DiffuseTexture = new Texture("Dude\\upBodyC"), NormalTexture = new Texture("Dude\\upbodyN"), SpecularTexture = new Texture("Dude\\upbodyCS"), SpecularPowerFromTexture = false, SpecularPower = 300
            };
            dude.ModelRenderer.MeshMaterials[4] = new BlinnPhong {
                DiffuseTexture = new Texture("Dude\\upBodyC"), NormalTexture = new Texture("Dude\\upbodyN"), SpecularTexture = new Texture("Dude\\upbodyCS"), SpecularPowerFromTexture = false, SpecularPower = 300
            };
            dude.Transform.LocalScale = new Vector3(0.1f, 0.1f, 0.1f);
            // Add animations.
            dude.AddComponent <ModelAnimations>();
            ModelAnimation modelAnimation;
            // First DudeAttack.
            #if XBOX
            modelAnimation          = new ModelAnimation("DudeAttackXbox"); // Be aware to select the correct content processor when you add your fbx files on the solution.
            modelAnimation.WrapMode = WrapMode.ClampForever;
            dude.ModelAnimations.AddAnimationClip(modelAnimation);
            #else
            modelAnimation          = new ModelAnimation("DudeAttack"); // Be aware to select the correct content processor when you add your fbx files on the solution.
            modelAnimation.WrapMode = WrapMode.ClampForever;
            dude.ModelAnimations.AddAnimationClip(modelAnimation);
            #endif
            // Then DudeRun.
            #if XBOX
            modelAnimation          = new ModelAnimation("DudeRunXbox"); // Be aware to select the correct content processor when you add your fbx files on the solution.
            modelAnimation.WrapMode = WrapMode.Loop;
            dude.ModelAnimations.AddAnimationClip(modelAnimation);
            #else
            modelAnimation          = new ModelAnimation("DudeRun"); // Be aware to select the correct content processor when you add your fbx files on the solution.
            modelAnimation.WrapMode = WrapMode.Loop;
            dude.ModelAnimations.AddAnimationClip(modelAnimation);
            #endif
            // Set the parameters from the animation that it is stored in DudeWalk (this animation is added automatically by the system).
            dude.ModelAnimations["Take 001"].WrapMode = WrapMode.Loop;

            // Load the rifle model.
            rifle = new GameObject3D(new FileModel("Rifle"), new BlinnPhong {
                DiffuseColor = new Color(15, 15, 15), SpecularPower = 100, SpecularIntensity = 0.01f
            });

            // And a floor
            floor = new GameObject3D(new FileModel("Terrain/TerrainLOD0Grid"),
                                     new BlinnPhong
            {
                SpecularPower     = 300,
                DiffuseColor      = new Color(250, 250, 250),
                SpecularIntensity = 0.0f,
            })
            {
                Transform = { LocalScale = new Vector3(5, 5, 5) }
            };

            #endregion

            #region Shadows and Lights

            Shadow.DistributeShadowCalculationsBetweenFrames = true;

            directionalLight = new GameObject3D();
            directionalLight.AddComponent <DirectionalLight>();
            directionalLight.DirectionalLight.Color     = new Color(250, 250, 140);
            directionalLight.DirectionalLight.Intensity = 25f;
            directionalLight.Transform.LookAt(new Vector3(-0.75f, 0.85f, -1.3f), Vector3.Zero, Vector3.Forward);
            directionalLight.DirectionalLight.Shadow = new CascadedShadow
            {
                Filter = Shadow.FilterType.PcfPosion,
                LightDepthTextureSize = Size.Square1024X1024,
            };
            DirectionalLight.Sun = directionalLight.DirectionalLight;

            #endregion

            #region Dog Fight Studios

            // Dog Fight Studios share their animations and the scene logic.
            GameObject2D dogFightStudios = new GameObject2D();
            dogFightStudios.AddComponent <HudTexture>();
            dogFightStudios.HudTexture.Texture = new Texture("DogFightStudios");
            dogFightStudios.Transform.Position = new Vector3(-55, -80, 0);

            #endregion
        } // Load
Exemple #10
0
        /// <summary>
        /// Scale gizmo based in Softimage XSI.
        /// </summary>
        internal ScaleGizmo()
        {
            // Create the gizmo parts.
            Box box = new Box(0.15f, 0.15f, 0.15f);

            redBox = new GameObject3D(box, new Constant())
            {
                Layer = Layer.GetLayerByNumber(31)
            };
            greenBox = new GameObject3D(box, new Constant())
            {
                Layer = Layer.GetLayerByNumber(31)
            };
            blueBox = new GameObject3D(box, new Constant())
            {
                Layer = Layer.GetLayerByNumber(31)
            };
            lines = new GameObject3D {
                Layer = Layer.GetLayerByNumber(31),
            };
            lines.AddComponent <LineRenderer>();
            lines.LineRenderer.Vertices = new VertexPositionColor[6];
            vertices[0]   = new Vector3(0, 0, 0);
            vertices[1]   = new Vector3(1, 0, 0);
            vertices[2]   = new Vector3(0, 1, 0);
            vertices[3]   = new Vector3(0, 0, 1);
            vertices[4]   = new Vector3(1, 1, 0);
            vertices[5]   = new Vector3(0, 1, 1);
            vertices[6]   = new Vector3(1, 0, 1);
            planeRedGreen = new GameObject3D(new Plane(vertices[2], vertices[0], vertices[4], vertices[1]), new Constant {
                DiffuseColor = new Color(255, 255, 0)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeGreenBlue = new GameObject3D(new Plane(vertices[5], vertices[3], vertices[2], vertices[0]), new Constant {
                DiffuseColor = new Color(0, 255, 255)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeBlueRed = new GameObject3D(new Plane(vertices[0], vertices[3], vertices[1], vertices[6]), new Constant {
                DiffuseColor = new Color(255, 0, 255)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeRedGreenInv = new GameObject3D(new Plane(vertices[4], vertices[1], vertices[2], vertices[0]), new Constant {
                DiffuseColor = new Color(255, 255, 0)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeGreenBlueInv = new GameObject3D(new Plane(vertices[2], vertices[0], vertices[5], vertices[3]), new Constant {
                DiffuseColor = new Color(0, 255, 255)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeBlueRedInv = new GameObject3D(new Plane(vertices[1], vertices[6], vertices[0], vertices[3]), new Constant {
                DiffuseColor = new Color(255, 0, 255)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeAll = new GameObject2D {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeAll.AddComponent <LineRenderer>();
            planeAll.LineRenderer.Vertices = new VertexPositionColor[8];

            redBox.ModelRenderer.Enabled            = false;
            greenBox.ModelRenderer.Enabled          = false;
            blueBox.ModelRenderer.Enabled           = false;
            lines.LineRenderer.Enabled              = false;
            planeRedGreen.ModelRenderer.Enabled     = false;
            planeGreenBlue.ModelRenderer.Enabled    = false;
            planeBlueRed.ModelRenderer.Enabled      = false;
            planeRedGreenInv.ModelRenderer.Enabled  = false;
            planeGreenBlueInv.ModelRenderer.Enabled = false;
            planeBlueRedInv.ModelRenderer.Enabled   = false;
            planeAll.LineRenderer.Enabled           = false;
        } // ScaleGizmo
Exemple #11
0
        /// <summary>
        /// Load the resources.
        /// </summary>
        protected override void LoadContent()
        {

            #region Camera
            
            camera = new GameObject3D();
            camera.AddComponent<Camera>();
            camera.AddComponent<SoundListener>();
            camera.Camera.RenderTargetSize = Size.FullScreen;
            camera.Camera.FarPlane = 1000;
            camera.Camera.NearPlane = 1f; // Do not place a small value here, you can destroy performance, not just precision.
            camera.Transform.LookAt(new Vector3(0, 0, 15), Vector3.Zero, Vector3.Up);
            ScriptCustomCameraScript script = (ScriptCustomCameraScript)camera.AddComponent<ScriptCustomCameraScript>();
            script.SetPosition(new Vector3(182, -85.47f, 150), new Vector3(0, 26f, 0));
            camera.Camera.ClearColor = Color.Black;
            camera.Camera.FieldOfView = 180 / 7f;
            camera.Camera.PostProcess = new PostProcess();
            camera.Camera.PostProcess.ToneMapping.AutoExposureEnabled = true;
            camera.Camera.PostProcess.ToneMapping.LensExposure = -1.5f;
            camera.Camera.PostProcess.ToneMapping.ToneMappingFunction = ToneMapping.ToneMappingFunctionEnumerate.FilmicALU;
            camera.Camera.PostProcess.MLAA.EdgeDetection = MLAA.EdgeDetectionType.Both;
            camera.Camera.PostProcess.MLAA.ThresholdColor = 0.1f;
            camera.Camera.PostProcess.MLAA.ThresholdDepth = 0.03f;
            camera.Camera.PostProcess.MLAA.Enabled = true;
            camera.Camera.PostProcess.Bloom.Enabled = true;
            camera.Camera.PostProcess.Bloom.Threshold = 3f;
            camera.Camera.PostProcess.FilmGrain.Enabled = true;
            camera.Camera.PostProcess.FilmGrain.Strength = 0.1f;
            camera.Camera.PostProcess.AnamorphicLensFlare.Enabled = false;
            camera.Camera.PostProcess.ColorCorrection.Enabled = true;
            camera.Camera.PostProcess.ColorCorrection.FirstLookupTable = new LookupTable("LookupTableWarehouse"); // A little more red and blue.
            camera.Camera.AmbientLight = new AmbientLight
            {
                //SphericalHarmonicLighting = SphericalHarmonicL2.GenerateSphericalHarmonicFromCubeTexture(new TextureCube("FactoryCatwalkRGBM") { IsRgbm = true, RgbmMaxRange = 50, }),
                //SphericalHarmonicLighting = SphericalHarmonicL2.GenerateSphericalHarmonicFromLatLongTexture(new Texture("CubeTextures\\Arches_E_PineTree_3k")),
                SphericalHarmonicLighting = SphericalHarmonicL2.GenerateSphericalHarmonicFromLatLongTexture(new Texture("CubeTextures\\Desert-15_XXLResize")),
                //SphericalHarmonicLighting = SphericalHarmonicL2.GenerateSphericalHarmonicFromLatLongTexture(new Texture("CubeTextures\\DH102LL")),
                //SphericalHarmonicLighting = SphericalHarmonicL2.GenerateSphericalHarmonicFromLatLongTexture(new Texture("CubeTextures\\Factory_Catwalk_2k")),
                Color = new Color(0, 0, 0),
                Intensity = 5f,
                AmbientOcclusionStrength = 2.5f
            };
            camera.Camera.Sky = new Skydome { Texture = new Texture("HotPursuitSkydome") };
            //camera.Camera.Sky = new Skybox { TextureCube = new TextureCube("FactoryCatwalkRGBM") { IsRgbm = true, RgbmMaxRange = 50, }, ColorIntensity = 15 };
            #if !XBOX
                camera.Camera.AmbientLight.AmbientOcclusion = new HorizonBasedAmbientOcclusion
                {
                    NumberSteps = 12,
                    NumberDirections = 12,
                    Radius = 0.003f, // Bigger values produce more cache misses and you don’t want GPU cache misses, trust me.
                    LineAttenuation = 1.0f,
                    Contrast = 1.1f,
                    AngleBias = 0.1f,
                    Quality = HorizonBasedAmbientOcclusion.QualityType.HighQuality,
                    TextureSize = Size.TextureSize.HalfSize,
                };
            #endif
            #endregion
            
            #region Models

            warehouseGround = new GameObject3D(new FileModel("Warehouse\\WarehouseGround"),
                                      new BlinnPhong
                                      {
                                          DiffuseTexture = new Texture("Warehouse\\Ground-Diffuse"),
                                          NormalTexture = new Texture("Warehouse\\Ground-Normals"),
                                          SpecularIntensity = 0.7f
                                      });
            warehouseGround.Transform.LocalScale = new Vector3(10, 10, 10);
            warehouseGround.Transform.Translate(0, -35.5f, 0);

            float specularIntensity = 2;
            float specularPower = 500;

            townhall = new GameObject3D(new FileModel("Tech Demo\\XNA_TownHall"),
                                            new BlinnPhong
                                            {
                                                DiffuseColor = Color.White,
                                                SpecularIntensity = 3,
                                                SpecularPower = 300,
                                            });
            townhall.Transform.Rotate(new Vector3(-90, -90, 0));
            townhall.Transform.Translate(40, -26f, -260, Space.World);
            townhall.ModelRenderer.MeshMaterials = new Material[5];
            townhall.ModelRenderer.MeshMaterials[0] = new BlinnPhong
            {
                DiffuseTexture = new Texture("Tech Demo\\XNA_building02_wall04"),
                NormalTexture = new Texture("Tech Demo\\XNA_building02_wall04_N"),
                SpecularIntensity = specularIntensity,
                SpecularPower = specularPower,
            };
            townhall.ModelRenderer.MeshMaterials[1] = new BlinnPhong
            {
                DiffuseTexture = new Texture("Tech Demo\\XNA_building02_roff02"),
                NormalTexture = new Texture("Tech Demo\\XNA_building02_roff02_N"),
                SpecularIntensity = specularIntensity,
                SpecularPower = specularPower,
            };
            townhall.ModelRenderer.MeshMaterials[2] = new BlinnPhong
            {
                DiffuseTexture = new Texture("Tech Demo\\XNA_building02_wall03"),
                NormalTexture = new Texture("Tech Demo\\XNA_building02_wall03_N"),
                SpecularPowerFromTexture = false,
                SpecularIntensity = specularIntensity,
                SpecularPower = specularPower,
            };
            townhall.ModelRenderer.MeshMaterials[3] = new BlinnPhong
            {
                DiffuseTexture = new Texture("Tech Demo\\XNA_building02_wall05"),
                NormalTexture = new Texture("Tech Demo\\XNA_building02_wall05_N"),
                SpecularPowerFromTexture = false,
                SpecularIntensity = specularIntensity,
                SpecularPower = specularPower,
            };
            townhall.ModelRenderer.MeshMaterials[4] = new BlinnPhong
            {
                DiffuseTexture = new Texture("Tech Demo\\XNA_building02_window01"),
                NormalTexture = new Texture("Tech Demo\\XNA_building02_window01_N"),
                SpecularPowerFromTexture = false,
                SpecularIntensity = specularIntensity,
                SpecularPower = specularPower,
            };

            building01 = new GameObject3D(new FileModel("Tech Demo\\building01"),
                                new BlinnPhong
                                {
                                    DiffuseColor = Color.White,
                                    SpecularIntensity = 3,
                                    SpecularPower = 300,
                                });
            building01.Transform.Rotate(new Vector3(-90, 0, 0));
            building01.ModelRenderer.MeshMaterials = new Material[23];
            building01.ModelRenderer.MeshMaterials[0] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_groundfloor01_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_groundfloor01_N"),
                                                                SpecularTexture = new Texture("Tech Demo\\building01_groundfloor01_S"),
                                                                SpecularPowerFromTexture = false,
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[1] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_groundfloor02_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_groundfloor02_N"),
                                                                SpecularTexture = new Texture("Tech Demo\\building01_groundfloor02_S"),
                                                                SpecularPowerFromTexture = false,
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[2] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_wall01_D"),
                                                                SpecularPowerFromTexture = false,
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[3] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_brick02_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_brick02_N"),
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[4] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_brick03_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_brick03_N"),
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[5] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_brick01_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_brick01_N"),
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[6] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_brick04_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_brick01_N"),
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[7] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_window03_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_window03_N"),
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[8] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_window02_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_window02_N"),
                                                                SpecularTexture = new Texture("Tech Demo\\building01_window02_S"),
                                                                SpecularPowerFromTexture = false,
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[9] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_shop01_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_shop01_N"),
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[10] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_window01_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_window01_N"),
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[11] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_shop01_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_shop01_N"),
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[12] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_Shutter-doors01_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_Shutter-doors01_N"),
                                                                SpecularTexture = new Texture("Tech Demo\\building01_Shutter-doors01_S"),
                                                                SpecularPowerFromTexture = false,
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[13] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_Shutter-doors03_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_Shutter-doors03_N"),
                                                                SpecularTexture = new Texture("Tech Demo\\building01_Shutter-doors03_S"),
                                                                SpecularPowerFromTexture = false,
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[14] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_Shutter-doors02_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_Shutter-doors02_N"),
                                                                SpecularTexture = new Texture("Tech Demo\\building01_Shutter-doors02_S"),
                                                                SpecularPowerFromTexture = false,
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[15] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_bill01_D"),
                                                                SpecularTexture = new Texture("Tech Demo\\building01_bill01_S"),
                                                                SpecularPowerFromTexture = false,
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[16] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_Watertower01_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_Watertower01_N"),
                                                                SpecularTexture = new Texture("Tech Demo\\building01_Watertower01_S"),
                                                                SpecularPowerFromTexture = false,
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[17] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_Shutter-doors01_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_Shutter-doors01_N"),
                                                                SpecularTexture = new Texture("Tech Demo\\building01_Shutter-doors01_S"),
                                                                SpecularPowerFromTexture = false,
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[18] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_AirCondition01_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_AirCondition01_N"),
                                                                SpecularTexture = new Texture("Tech Demo\\building01_AirCondition01_S"),
                                                                SpecularPowerFromTexture = false,
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[19] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_flaps01_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_flaps01_N"),
                                                                SpecularTexture = new Texture("Tech Demo\\building01_flaps01_S"),
                                                                SpecularPowerFromTexture = false,
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[20] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_rainshed01_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_rainshed01_N"),
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[21] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_iron01_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_iron01_N"),
                                                                SpecularTexture = new Texture("Tech Demo\\building01_iron01_S"),
                                                                SpecularPowerFromTexture = false,
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            building01.ModelRenderer.MeshMaterials[22] = new BlinnPhong
                                                            {
                                                                DiffuseTexture = new Texture("Tech Demo\\building01_rainshed02_D"),
                                                                NormalTexture = new Texture("Tech Demo\\building01_rainshed02_N"),
                                                                SpecularIntensity = specularIntensity,
                                                                SpecularPower = specularPower,
                                                            };
            #endregion

            #region Statistics

            //GameObject2D statistics = new GameObject2D();
            //statistics.AddComponent<ScriptStatisticsDrawer>();

            #endregion
            
            #region Shadows and Lights

            Shadow.DistributeShadowCalculationsBetweenFrames = true;
            
            directionalLight = new GameObject3D();
            directionalLight.AddComponent<DirectionalLight>();
            directionalLight.DirectionalLight.Color = new Color(190, 190, 150);
            directionalLight.DirectionalLight.Intensity = 25.2f;
            directionalLight.Transform.LookAt(new Vector3(0.3f, 0.5f, -0.5f), Vector3.Zero, Vector3.Forward);
            DirectionalLight.Sun = directionalLight.DirectionalLight;
            directionalLight.DirectionalLight.Shadow = new CascadedShadow
            {
                Filter = Shadow.FilterType.Pcf7X7,
                LightDepthTextureSize = Size.Square1024X1024,
                ShadowTextureSize = Size.TextureSize.FullSize, // Lower than this could produce artifacts if the light is too intense.
                DepthBias = 0.0025f,
                FarPlaneSplit1 = 200,
                FarPlaneSplit2 = 300,
                FarPlaneSplit3 = 500,
                FarPlaneSplit4 = 800
            };
            
            #endregion

            #region Particles
            /*
            // Pit particles
            GameObject3D particles = new GameObject3D();
            particles.AddComponent<ParticleEmitter>();
            particles.AddComponent<ParticleRenderer>();
            particles.ParticleEmitter.MaximumNumberParticles = 75;
            particles.Transform.LocalPosition = new Vector3(-1.2f, 0, -13);
            particles.ParticleEmitter.Duration = 50f;
            particles.ParticleEmitter.EmitterVelocitySensitivity = 1;
            particles.ParticleEmitter.MinimumHorizontalVelocity = 1;
            particles.ParticleEmitter.MaximumHorizontalVelocity = 2f;
            particles.ParticleEmitter.MinimumVerticalVelocity = 1;
            particles.ParticleEmitter.MaximumVerticalVelocity = 2;
            particles.ParticleRenderer.Texture = new Texture("Particles\\Smoke");
            particles.ParticleRenderer.SoftParticles = true;
            particles.ParticleRenderer.FadeDistance = 25.0f;
            particles.ParticleRenderer.BlendState = BlendState.NonPremultiplied;
            particles.ParticleRenderer.DurationRandomness = 0.1f;
            particles.ParticleRenderer.Gravity = new Vector3(0, 1, 5);
            particles.ParticleRenderer.EndVelocity = 0.75f;
            particles.ParticleRenderer.MinimumColor = Color.White;
            particles.ParticleRenderer.MaximumColor = Color.White;
            particles.ParticleRenderer.RotateSpeed = new Vector2(-0.3f, 0.25f);
            particles.ParticleRenderer.StartSize = new Vector2(150, 300);
            particles.ParticleRenderer.EndSize = new Vector2(500, 750);
            particles.ParticleRenderer.TilesX = 1;
            particles.ParticleRenderer.TilesY = 1;
            particles.ParticleRenderer.AnimationRepetition = 1;

            particles = new GameObject3D();
            particles.AddComponent<ParticleEmitter>();
            particles.AddComponent<ParticleRenderer>();
            particles.ParticleEmitter.MaximumNumberParticles = 75;
            particles.Transform.LocalPosition = new Vector3(-3.2f, 0, 13);
            particles.ParticleEmitter.Duration = 50f;
            particles.ParticleEmitter.EmitterVelocitySensitivity = 1;
            particles.ParticleEmitter.MinimumHorizontalVelocity = 1;
            particles.ParticleEmitter.MaximumHorizontalVelocity = 2f;
            particles.ParticleEmitter.MinimumVerticalVelocity = 1;
            particles.ParticleEmitter.MaximumVerticalVelocity = 2;
            particles.ParticleRenderer.Texture = new Texture("Particles\\Smoke");
            particles.ParticleRenderer.SoftParticles = true;
            particles.ParticleRenderer.FadeDistance = 25.0f;
            particles.ParticleRenderer.BlendState = BlendState.NonPremultiplied;
            particles.ParticleRenderer.DurationRandomness = 0.1f;
            particles.ParticleRenderer.Gravity = new Vector3(0, 1, -25);
            particles.ParticleRenderer.EndVelocity = 0.75f;
            particles.ParticleRenderer.MinimumColor = Color.White;
            particles.ParticleRenderer.MaximumColor = Color.White;
            particles.ParticleRenderer.RotateSpeed = new Vector2(-0.2f, 0.2f);
            particles.ParticleRenderer.StartSize = new Vector2(150, 500);
            particles.ParticleRenderer.EndSize = new Vector2(500, 750);
            particles.ParticleRenderer.TilesX = 1;
            particles.ParticleRenderer.TilesY = 1;
            particles.ParticleRenderer.AnimationRepetition = 1;
            */
            #endregion
            
        } // Load
        /// <summary>
        /// Load the resources.
        /// </summary>
        protected override void LoadContent()
        {
            hitMaterial = new BlinnPhong {
                DiffuseColor = new Color(0.10f, 0.10f, 0.85f)
            };
            mat1 = new BlinnPhong {
                DiffuseColor = new Color(0.85f, 0.65f, 0f)
            };
            mat2 = new BlinnPhong {
                DiffuseColor = new Color(0.5f, 0.9f, 0.5f)
            };

            #region Physics Simulation Settings

            // Setup gravity.
            PhysicsManager.Gravity = new Vector3(0, -9.81f, 0);

            #endregion

            #region Camera

            camera = new GameObject3D();
            camera.AddComponent <Camera>();
            camera.AddComponent <SoundListener>();
            camera.Transform.LookAt(Vector3.Zero, Vector3.Forward, Vector3.Up);
            var script = (ScriptCustomCameraScript)camera.AddComponent <ScriptCustomCameraScript>();
            script.SetPosition(new Vector3(0, 15, 45), new Vector3(0, 5, 0));
            camera.Camera.RenderTargetSize = Size.FullScreen;
            camera.Camera.FarPlane         = 500;
            camera.Camera.NearPlane        = 1f;
            camera.Camera.ClearColor       = Color.Black;
            camera.Camera.FieldOfView      = 180f / 7f;
            camera.Camera.PostProcess      = new PostProcess();
            camera.Camera.PostProcess.ToneMapping.ToneMappingFunction = ToneMapping.ToneMappingFunctionEnumerate.FilmicALU;
            camera.Camera.PostProcess.ToneMapping.AutoExposureEnabled = false;
            camera.Camera.PostProcess.ToneMapping.LensExposure        = 0f;
            camera.Camera.PostProcess.MLAA.EdgeDetection          = MLAA.EdgeDetectionType.Both;
            camera.Camera.PostProcess.MLAA.Enabled                = false;
            camera.Camera.PostProcess.Bloom.Threshold             = 2;
            camera.Camera.PostProcess.FilmGrain.Enabled           = true;
            camera.Camera.PostProcess.FilmGrain.Strength          = 0.03f;
            camera.Camera.PostProcess.AnamorphicLensFlare.Enabled = false;
            camera.Camera.AmbientLight = new AmbientLight
            {
                Color     = new Color(20, 20, 25),
                Intensity = 0.5f,
                AmbientOcclusionStrength = 1f
            };

            #endregion

            #region Models and Physics

            // Make the floor (Kinematic) //
            // First, we create a bepu box entity that we will be used in our rigidbody component.
            // Notice that we don't specify the mass, so we are creating a kinematic entity.
            // Kinematic rigidbodies are moved through the transform component of the gameobject which it belongs.
            // Kinematic rigidbodies don't respond to collisions and can't collide with other kinematic rigidbodies. However, they can
            // collide with dynamic rigidbodies affecting them.
            var bepuGround = new Box(Vector3.Zero, 50, 1, 50);
            // Now, we create the game object and we add a rigidbody component to it.
            floor = new GameObject3D(new XNAFinalEngine.Assets.Box(50, 1, 50), new BlinnPhong {
                SpecularIntensity = 0.3f, SpecularPower = 200
            });
            var floorRb = (RigidBody)floor.AddComponent <RigidBody>();
            // Finally, we set the entity created previously to the rigidbody component
            floorRb.Entity = bepuGround;

            // Make a Cube (Dynamic) //
            // Now, we create a 1x1x1 bepu box entity that will appear 20 units above the floor.
            // Notice that this time we specify the entity's mass in order to create a dynamic entity.
            // Dynamic rigidbodies are affected by gravity and respond to collisions with other rigidbodies.
            // Dynamic rigidbodies are under the control of physics so they don't have to be moved or rotated through the transform component.
            var bepuCube = new Box(new Vector3(0, 20, 2), 1, 1, 1, 1);
            cube = new GameObject3D(new XNAFinalEngine.Assets.Box(1, 1, 1), new BlinnPhong {
                DiffuseColor = new Color(0.8f, 0.8f, 0.85f)
            });
            var cubeRb = (RigidBody)cube.AddComponent <RigidBody>();
            cubeRb.Entity = bepuCube;
            // Create a script for test collisions
            var          crt     = (CollisionResponseTestScript)cube.AddComponent <CollisionResponseTestScript>();
            GameObject2D debugGo = new GameObject2D();
            debugGo.Transform.Position = new Vector3(15f, Screen.Height - 90, 0f);
            crt.DebugText = (HudText)debugGo.AddComponent <HudText>();

            // Make an obstacle (Kinematic) //
            var bepuObstacle = new Box(new Vector3(0.5f, 1f, 0.5f), 4, 1, 1.5f);
            obstacle = new GameObject3D(new XNAFinalEngine.Assets.Box(4, 1, 1.5f), new BlinnPhong {
                DiffuseColor = new Color(0.9f, 0.2f, 0.15f), SpecularPower = 20
            });
            obstacle.Transform.Position = new Vector3(0.5f, 1f, 0.5f);
            var obstacleRb = (RigidBody)obstacle.AddComponent <RigidBody>();
            obstacleRb.Entity = bepuObstacle;

            // Make a wall of boxes //
            MakeWall(6, 9);

            // Make a sphere obstacle (Dynamic) //
            // The sphere model is not center in its model space, instead is displaced 10 units on Z.
            GameObject3D sphere;
            // First we creates this sphere with no physics representation.
            //sphere = new GameObject3D(new FileModel("SphereTransformed"), new BlinnPhong { DiffuseColor = new Color(1f, 0f, 0f), SpecularPower = 20 });
            // Then we creates the same sphere and asign a dynamic physic object representation.
            sphere = new GameObject3D(new FileModel("SphereTransformed"), new BlinnPhong {
                DiffuseColor = new Color(0.79f, 0.75f, 0.2f), SpecularPower = 20
            });
            // The initial motion state place the sphere just a little above.
            MotionState motionState = new MotionState {
                Position = new Vector3(0f, 10f, 0f), Orientation = Quaternion.Identity
            };
            // We create the physic object. The offset that creates Bepu is hide transparently.
            // Moreover the initial motion state takes in consideration this offset and places the sphere in the same x, z coordinates as the other sphere.
            ((RigidBody)sphere.AddComponent <RigidBody>()).CreateDynamicEntityFromModelFilter(motionState, 1);

            // Static mesh.
            var lamboBody = new GameObject3D(new FileModel("LamborghiniMurcielago\\Murcielago-Body"
#if XBOX
                                                           + "Xbox"
#endif
                                                           ), new BlinnPhong {
                DiffuseColor = Color.Gray
            });
            lamboBody.Transform.Position = new Vector3(-3, 3, 3);
            ((StaticCollider)lamboBody.AddComponent <StaticCollider>()).CreateStaticCollidableFromModelFilter();

            // Very Simple Crosshair //
            GameObject2D crosshair = new GameObject2D();
            crosshair.Transform.Position = new Vector3(Screen.Width / 2f, Screen.Height / 2f, 0f);
            var crossText = (HudText)crosshair.AddComponent <HudText>();
            crossText.Text.Append("+");

            #endregion

            #region Shadows and Lights

            Shadow.DistributeShadowCalculationsBetweenFrames = true;

            var pointLight = new GameObject3D();
            pointLight.AddComponent <PointLight>();
            pointLight.PointLight.Color     = new Color(180, 200, 250);
            pointLight.PointLight.Intensity = 4f;
            pointLight.PointLight.Range     = 60;
            pointLight.Transform.Position   = new Vector3(4.8f, 10f, 10);
            pointLight.PointLight.Shadow    = new CubeShadow {
                LightDepthTextureSize = 1024
            };

            var pointLight2 = new GameObject3D();
            pointLight2.AddComponent <PointLight>();
            pointLight2.PointLight.Color     = new Color(100, 110, 170);
            pointLight2.PointLight.Intensity = 1f;
            pointLight2.PointLight.Range     = 30;
            pointLight2.Transform.Position   = new Vector3(-12f, 10, -3);

            #endregion

            #region Demo Legend

            #region Legend Background

            Texture2D bg      = new Texture2D(EngineManager.Device, 1, 1, false, SurfaceFormat.Color);
            Color[]   bgColor = new Color[] { new Color(0f, 0f, 0f, 0.55f) };
            bg.SetData(bgColor);

            var bgTexture        = new XNAFinalEngine.Assets.Texture(bg);
            var backgroundLegend = new GameObject2D();
            backgroundLegend.Transform.Position = new Vector3(0f, 0f, 1f);
            var bgHudTex = (HudTexture)backgroundLegend.AddComponent <HudTexture>();
            bgHudTex.Texture = bgTexture;
            bgHudTex.DestinationRectangle = new Rectangle(0, Screen.Height - 115, Screen.Width, Screen.Height);

            #endregion

            var demoLegend = new GameObject2D();
            demoLegend.Transform.Position = new Vector3(Screen.Width - 380f, Screen.Height - 105f, 0f);
            var legend = (HudText)demoLegend.AddComponent <HudText>();
            legend.Color = new Color(1f, 1f, 1f, 1f);
            legend.Text.Append(" Controls\n");
            legend.Text.Append("\n");
            legend.Text.Append("- Press Left Ctrl to fire a Blue box.\n");
            legend.Text.Append("- Press Space to apply an Up impulse to the white box.\n");
            legend.Text.Append("- Press Left Shift to cast a ray that paints yellow and \n");
            legend.Text.Append("  applies an Up impulse to the GO that hits.\n");
            legend.Text.Append("- Press keys A, S, W, D, Q, E to move and rotate the red box");

            #endregion
        } // LoadContent
Exemple #13
0
        } // ViewportArea

        #endregion

        #region Add Main Window Controls

        /// <summary>
        /// Add the editor's main window controls.
        /// </summary>
        public static void AddMainControls()
        {
            #region Canvas

            // The canvas cover the whole window. I will place the static controls there.
            // I don’t place the controls directly to the manager to allow having some functionality
            // provided by the canvas like the automatic placing of menu items, status bar, etc.
            Container canvas = new Container
            {
                Top             = 0,
                Left            = 0,
                Width           = Screen.Width,
                Height          = Screen.Height,
                Anchor          = Anchors.All,
                AutoScroll      = false,
                BackgroundColor = Color.Transparent,
                StayOnBack      = true,
                Passive         = true,
                CanFocus        = false,
            };

            #endregion

            #region Main Menu

            canvas.MainMenu = new MainMenu
            {
                Width    = Screen.Width,
                Anchor   = Anchors.Left | Anchors.Top,
                CanFocus = false
            };

            #region File

            MenuItem menuItemFile = new MenuItem("File", true);
            canvas.MainMenu.Items.Add(menuItemFile);
            menuItemFile.Items.AddRange(new[]
            {
                new MenuItem("New Scene")
                {
                    RightSideText = "Ctrl+N"
                },
                new MenuItem("Open Scene")
                {
                    RightSideText = "Ctrl+O"
                },
                new MenuItem("Save Scene")
                {
                    RightSideText = "Ctrl+S", SeparationLine = true
                },
                new MenuItem("Save Scene as...")
                {
                    RightSideText = "Ctrl+Shift+S"
                },
                new MenuItem("Exit", true)
                {
                    SeparationLine = true
                },
            });
            menuItemFile.Items[0].Click += delegate { StorageManager.ClearScene(); };
            menuItemFile.Items[1].Click += delegate { StorageManager.LoadScene(); };
            menuItemFile.Items[2].Click += delegate { StorageManager.SaveScene(); };

            #endregion

            #region Edit

            MenuItem menuItemEdit = new MenuItem("Edit", true);
            canvas.MainMenu.Items.Add(menuItemEdit);
            menuItemEdit.Items.AddRange(new[]
            {
                new MenuItem("Undo")
                {
                    RightSideText = "Ctrl+Z"
                },
                new MenuItem("Redo")
                {
                    RightSideText = "Ctrl+Y"
                },
                new MenuItem("Frame Selected (All 3D Views)")
                {
                    RightSideText = "Shift+F", SeparationLine = true
                },
                new MenuItem("Frame All (All 3D Views)")
                {
                    RightSideText = "Shift+A"
                },
                new MenuItem("Reset (All 3D Views)")
                {
                    RightSideText = "Shift+R"
                },
            });
            menuItemEdit.Items[0].Click += delegate { ActionManager.Undo(); };
            menuItemEdit.Items[1].Click += delegate { ActionManager.Redo(); };
            menuItemEdit.Items[2].Click += delegate
            {
                foreach (var editorViewport in EditorManager.EditorViewports)
                {
                    editorViewport.FrameObjects(EditorManager.SelectedObjects);
                }
            };
            menuItemEdit.Items[3].Click += delegate
            {
                foreach (var editorViewport in EditorManager.EditorViewports)
                {
                    editorViewport.FrameObjects(GameObject.GameObjects);
                }
            };
            menuItemEdit.Items[4].Click += delegate
            {
                foreach (var editorViewport in EditorManager.EditorViewports)
                {
                    editorViewport.Reset();
                }
            };

            #endregion

            #region Game Object

            MenuItem menuItemGameObject = new MenuItem("Game Object", true);
            canvas.MainMenu.Items.Add(menuItemGameObject);
            menuItemGameObject.Items.AddRange(new[]
            {
                new MenuItem("Create Empty 3D Game Object")
                {
                    RightSideText = "Ctrl+Shift+N"
                },
                new MenuItem("Create Empty 2D Game Object")
                {
                    RightSideText = "Ctrl+Shift+M"
                },
                new MenuItem("Create Other"),
            });
            menuItemGameObject.Items[2].Items.AddRange(new[]
            {
                new MenuItem("Camera"),
                new MenuItem("Particle System"),
                new MenuItem("HUD Texture"),
                new MenuItem("HUD Text"),
                new MenuItem("Directional Light")
                {
                    SeparationLine = true
                },
                new MenuItem("Point Light"),
                new MenuItem("Spot Light"),
                new MenuItem("Sphere")
                {
                    SeparationLine = true
                },
                new MenuItem("Box"),
                new MenuItem("Plane"),
                new MenuItem("Cylinder"),
                new MenuItem("Cone"),
                new MenuItem("Empty Model"),
            });
            // Create Empty 3D Game Object
            menuItemGameObject.Items[0].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D();
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Camera
            menuItemGameObject.Items[2].Items[0].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D();
                gameObject3D.AddComponent <Camera>();
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Particle System
            menuItemGameObject.Items[2].Items[1].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D();
                gameObject3D.AddComponent <ParticleEmitter>();
                gameObject3D.AddComponent <ParticleRenderer>();
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // HUD Texture
            menuItemGameObject.Items[2].Items[2].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D();
                gameObject3D.AddComponent <HudTexture>();
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // HUD Text
            menuItemGameObject.Items[2].Items[3].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D();
                gameObject3D.AddComponent <HudText>();
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Directional Light
            menuItemGameObject.Items[2].Items[4].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D();
                gameObject3D.AddComponent <DirectionalLight>();
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Point Light
            menuItemGameObject.Items[2].Items[5].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D();
                gameObject3D.AddComponent <PointLight>();
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Spot Light
            menuItemGameObject.Items[2].Items[6].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D();
                gameObject3D.AddComponent <SpotLight>();
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Sphere
            menuItemGameObject.Items[2].Items[7].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D(new Sphere(), Material.DefaultMaterial);
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Box
            menuItemGameObject.Items[2].Items[8].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D(new Box(), Material.DefaultMaterial);
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Plane
            menuItemGameObject.Items[2].Items[9].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D(new Plane(), Material.DefaultMaterial);
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Cylinder
            menuItemGameObject.Items[2].Items[10].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D(new Cylinder(), Material.DefaultMaterial);
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Cone
            menuItemGameObject.Items[2].Items[11].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D(new Cone(), Material.DefaultMaterial);
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Empty Model
            menuItemGameObject.Items[2].Items[12].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D(null, Material.DefaultMaterial);
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };

            #endregion

            #region Component

            MenuItem menuItemComponent = new MenuItem("Component", true);
            canvas.MainMenu.Items.Add(menuItemComponent);
            menuItemComponent.Items.AddRange(new[]
            {
                new MenuItem("Model"),
                new MenuItem("Particles"),
                new MenuItem("Physics"),
                new MenuItem("Audio"),
                new MenuItem("Rendering"),
            });

            #endregion

            #region Window

            MenuItem menuItemWindow = new MenuItem("Window", true);
            canvas.MainMenu.Items.Add(menuItemWindow);
            menuItemWindow.Items.AddRange(new[]
            {
                new MenuItem("Layouts"),
                new MenuItem("Hierarchy")
                {
                    RightSideText = "Ctrl+6", SeparationLine = true,
                },
                new MenuItem("Heads Up Display Editor")
                {
                    RightSideText = "Ctrl+7"
                },
            });
            menuItemWindow.Items[0].Items.AddRange(new []
            {
                new MenuItem("4 Split"),
                new MenuItem("3 Split"),
                new MenuItem("Wide"),
                new MenuItem("Toggle")
                {
                    RightSideText = "F12", SeparationLine = true,
                },
            });
            menuItemWindow.Items[0].Items[0].Click += delegate { EditorManager.Layout = EditorManager.LayoutOptions.FourSplit; };
            menuItemWindow.Items[0].Items[1].Click += delegate { EditorManager.Layout = EditorManager.LayoutOptions.ThreeSplit; };
            menuItemWindow.Items[0].Items[2].Click += delegate { EditorManager.Layout = EditorManager.LayoutOptions.Wide; };
            menuItemWindow.Items[0].Items[3].Click += delegate { EditorManager.ToggleLayout(); };

            #endregion

            #region Help

            MenuItem menuItemHelp = new MenuItem("Help", true);
            canvas.MainMenu.Items.Add(menuItemHelp);
            menuItemHelp.Items.AddRange(new[]
            {
                new MenuItem("About"),
                new MenuItem("Documentation")
                {
                    RightSideText = "F1", SeparationLine = true,
                },
            });
            menuItemHelp.Items[1].Click += delegate { System.Diagnostics.Process.Start("http://xnafinalengine.codeplex.com/documentation"); };

            #endregion

            #endregion

            #region Top Panel

            ToolBarPanel topPanel = new ToolBarPanel();
            canvas.ToolBarPanel = topPanel;
            ToolBar toolBarTopPanel = new ToolBar
            {
                Parent  = topPanel,
                Movable = true,
                FullRow = true
            };

            #region Button Space

            Button buttonSpace = new Button
            {
                Text     = "Global",
                Left     = 10,
                Top      = 10,
                Height   = 15,
                Parent   = toolBarTopPanel,
                CanFocus = false,
            };
            buttonSpace.Click += delegate
            {
                if (Gizmo.Space == Gizmo.SpaceMode.Local)
                {
                    Gizmo.Space      = Gizmo.SpaceMode.Global;
                    buttonSpace.Text = "Global";
                }
                else
                {
                    Gizmo.Space      = Gizmo.SpaceMode.Local;
                    buttonSpace.Text = "Local";
                }
                buttonSpace.Focused = false;
            };

            #endregion

            #region Buttons Play, Pause and Stop

            Texture playTexture        = new Texture("Editor\\PlayIconNotPressed");
            Texture playPressedTexture = new Texture("Editor\\PlayIcon");
            Button  buttonPlay         = new Button
            {
                Left   = Screen.Width / 2 - 50,
                Top    = 2,
                Height = 32,
                Width  = 32,
                Glyph  = new Glyph(playTexture)
                {
                    SizeMode = SizeMode.Normal
                },
                Parent   = toolBarTopPanel,
                CanFocus = false,
            };
            buttonPlay.Click += delegate { buttonPlay.Glyph.Texture = buttonPlay.Glyph.Texture == playTexture ? playPressedTexture : playTexture; };
            Texture pauseTexture        = new Texture("Editor\\PauseIconNotPressed");
            Texture pausePressedTexture = new Texture("Editor\\PauseIcon");
            Button  buttonPause         = new Button
            {
                Left   = buttonPlay.Left + 34,
                Top    = 2,
                Height = 32,
                Width  = 32,
                Glyph  = new Glyph(pauseTexture)
                {
                    SizeMode = SizeMode.Normal
                },
                Parent   = toolBarTopPanel,
                CanFocus = false,
            };
            buttonPause.Click += delegate { buttonPause.Glyph.Texture = buttonPause.Glyph.Texture == pauseTexture ? pausePressedTexture : pauseTexture; };
            Texture stopTexture        = new Texture("Editor\\StopIconNotPressed");
            Texture stopPressedTexture = new Texture("Editor\\StopIcon");
            Button  buttonStop         = new Button
            {
                Left   = buttonPlay.Left + 68,
                Top    = 2,
                Height = 32,
                Width  = 32,
                Glyph  = new Glyph(stopTexture)
                {
                    SizeMode = SizeMode.Normal
                },
                Parent   = toolBarTopPanel,
                CanFocus = false,
            };
            buttonStop.Click += delegate { buttonStop.Glyph.Texture = buttonStop.Glyph.Texture == stopTexture ? stopPressedTexture : stopTexture; };

            #endregion

            // Adjust top panel height.
            topPanel.Height        = buttonStop.Top + buttonStop.Height + 2;
            toolBarTopPanel.Height = buttonStop.Top + buttonStop.Height + 2;

            #endregion

            #region Viewport Space

            // The canvas cover the whole window. I will place the static controls there.
            // I don’t place the controls directly to the manager to allow having some functionality
            // provided by the canvas like the automatic placing of menu items, status bar, etc.
            ViewportsSpace = new Container
            {
                Top             = 0,
                Left            = 0,
                Width           = canvas.ClientWidth - 420,
                Height          = canvas.ClientHeight,
                Anchor          = Anchors.All,
                AutoScroll      = false,
                BackgroundColor = Color.Transparent,
                StayOnBack      = true,
                Passive         = false,
                CanFocus        = false,
                Parent          = canvas,
            };

            #endregion

            #region Right Panel

            Panel rightPanel = new Panel
            {
                StayOnBack = true,
                Passive    = true,
                Parent     = canvas,
                Width      = 420,
                Left       = canvas.ClientWidth - 420,
                Height     = canvas.ClientHeight,
                Anchor     = Anchors.Right | Anchors.Top | Anchors.Bottom,
                Color      = new Color(64, 64, 64),
            };

            TabControl rightPanelTabControl = new TabControl
            {
                Parent = rightPanel,
                Left   = 2,
                Top    = 2,
                Width  = rightPanel.ClientWidth - 2,
                Height = rightPanel.ClientHeight - 2,
                Anchor = Anchors.All
            };
            rightPanelTabControl.AddPage();
            rightPanelTabControl.TabPages[0].Text = "Inspector";
            inspector = rightPanelTabControl.TabPages[0];
            rightPanelTabControl.AddPage();
            rightPanelTabControl.TabPages[1].Text = "Layers";
            var label = new Label
            {
                Parent = rightPanelTabControl.TabPages[1],
                Width  = 50,
                Top    = 15,
                Left   = rightPanelTabControl.TabPages[1].ClientWidth - 132,
                Text   = "Active",
                Height = 10,
            };
            label.ToolTip.Text = "Active layers are updated.";
            label = new Label
            {
                Parent = rightPanelTabControl.TabPages[1],
                Width  = 50,
                Top    = 15,
                Left   = rightPanelTabControl.TabPages[1].ClientWidth - 72,
                Text   = "Visible",
                Height = 10,
            };
            label.ToolTip.Text = "Visible layers are rendered.";
            for (int i = 0; i < 30; i++)
            {
                CommonControls.LayerBox(i, rightPanelTabControl.TabPages[1]);
            }

            #endregion
        } // AddMainControls