public ScreenInScreenSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            // The first screen.
            _screen1 = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = RenderScreen1,
            };
            GraphicsService.Screens.Insert(0, _screen1);

            // The second screen.
            _screen2 = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = RenderScreen2,

                // A graphics screen should let the graphics service know if it renders
                // to the whole screen, thereby hiding any graphics screens in the background.
                Coverage = GraphicsScreenCoverage.Full,

                // Tell the graphics service to render the previous screens into a render
                // target with a custom format.
                RenderPreviousScreensToTexture = true,
                SourceTextureFormat            = new RenderTargetFormat(800, 600, false, SurfaceFormat.Color, DepthFormat.Depth24),
            };
            GraphicsService.Screens.Insert(1, _screen2);



            // Create a sprite batch.
            _spriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice);

            // Load a sprite font.
            _spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default");
        }
        public CustomCommandSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            // Add a DelegateGraphicsScreen as the first graphics screen to the graphics
            // service. This lets us do the rendering in the Render method of this class.
            var graphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render
            };

            GraphicsService.Screens.Insert(0, graphicsScreen);

            _spriteBatch = GraphicsService.GetSpriteBatch();

            // Load a few SpriteFonts for rendering.
            _textFont   = UIContentManager.Load <SpriteFont>("UI Themes/WindowsPhone7/Segoe15");
            _buttonFont = ContentManager.Load <SpriteFont>("ButtonImages/xboxControllerSpriteFont");

            // Add custom commands to input service.
            _buttonHoldCommand = new ButtonHoldCommand(Buttons.A, 1.0f)
            {
                Name = "Hold A"
            };
            _buttonTapCommand = new ButtonTapCommand(Buttons.A, 0.2f, 1.0f)
            {
                Name = "Tap A"
            };
            _buttonSequenceCommand = new ButtonSequenceCommand(new [] { Buttons.A, Buttons.B, Buttons.A, Buttons.B }, 2.0f)
            {
                Name = "A-B-A-B"
            };
            InputService.Commands.Add(_buttonHoldCommand);
            InputService.Commands.Add(_buttonTapCommand);
            InputService.Commands.Add(_buttonSequenceCommand);
        }
示例#3
0
        /// <summary>
        ///     Create a new <see cref="UIWindow"/>.
        /// </summary>
        /// <param name="game"></param>
        public UIWindow(Game game)
        {
            if (!UIContentManager.TryGetInstance(out _contentManager))
            {
                throw new InvalidOperationException("Window could not retrieve UI content manager.");
            }

            _game = game;
            _game.Window.ClientSizeChanged += Window_ClientSizeChanged;
            _children           = new List <IRenderableElement>();
            _updateableChildren = new List <IUpdateableElement>();
        }
示例#4
0
        /// <summary>
        ///     Initialize the UIManager.
        /// </summary>
        public override void Initialize()
        {
            // The UIContentManager needs to be created with the game as a parameter.
            UIContentManager.CreateInstance(Game);

            MenuUI    = new MenuUI(Game);
            SettingUI = new SettingsUI(Game);

            _spriteBatch = new SpriteBatch(Game.GraphicsDevice);

            base.Initialize();
        }
示例#5
0
        public DebugRendererSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;
            var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };

            GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            GameObjectService.Objects.Add(_cameraObject);

            // Load a sprite font.
            var spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default");

            // Create a new debug renderer.
            _debugRenderer = new DebugRenderer(GraphicsService, spriteFont)
            {
                DefaultColor = Color.White,
            };

            // A normal XNA model.
            _xnaModel = ContentManager.Load <Model>("Saucer3/saucer");

            // A DigitalRune model.
            _modelNode           = ContentManager.Load <ModelNode>("Dude/Dude").Clone();
            _modelNode.PoseLocal = new Pose(new Vector3F(6, 0, -7));

            // Create a geometric object with a height field shape.
            var numberOfSamplesX = 20;
            var numberOfSamplesZ = 20;
            var samples          = new float[numberOfSamplesX * numberOfSamplesZ];

            for (int z = 0; z < numberOfSamplesZ; z++)
            {
                for (int x = 0; x < numberOfSamplesX; x++)
                {
                    samples[z * numberOfSamplesX + x] = 1.0f + (float)(Math.Cos(z / 2f) * Math.Sin(x / 2f) * 1.0f);
                }
            }
            HeightField heightField = new HeightField(0, 0, 120, 120, samples, numberOfSamplesX, numberOfSamplesZ);

            _geometricObject = new GeometricObject(heightField, new Pose(new Vector3F(5, 0, -5)))
            {
                Scale = new Vector3F(0.01f, 0.05f, 0.02f),
            };
        }
        public DebugRendererSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            _delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };
            GraphicsService.Screens.Insert(0, _delegateGraphicsScreen);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            GameObjectService.Objects.Add(_cameraObject);

            // Load a sprite font.
            var spriteFont = UIContentManager.Load <SpriteFont>("Default");

            // Create a new debug renderer.
            _debugRenderer = new DebugRenderer(GraphicsService, spriteFont)
            {
                DefaultColor = Color.White,
            };

            // A normal XNA model.
            _xnaModel = ContentManager.Load <Model>("Saucer3/saucer");

            // A DigitalRune model.
            _modelNode           = ContentManager.Load <ModelNode>("Dude/Dude").Clone();
            _modelNode.PoseLocal = new Pose(new Vector3F(6, 0, -7));

            // Create a geometric object with a height field shape.
            HeightField heightField = new HeightField {
                WidthX = 120, WidthZ = 120, Array = new float[20, 20]
            };

            for (int row = 0; row < heightField.Array.GetLength(0); row++)
            {
                for (int column = 0; column < heightField.Array.GetLength(1); column++)
                {
                    heightField.Array[row, column] = 1.0f + (float)(Math.Cos(column / 2f) * Math.Sin(row / 2f) * 1.0f);
                }
            }

            _geometricObject = new GeometricObject(heightField, new Pose(new Vector3F(5, 0, -5)))
            {
                Scale = new Vector3F(0.01f, 0.05f, 0.02f),
            };
        }
示例#7
0
        public FigureSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            _delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };
            GraphicsService.Screens.Insert(0, _delegateGraphicsScreen);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            GameObjectService.Objects.Add(_cameraObject);

            var spriteFont  = UIContentManager.Load <SpriteFont>("Default");
            var spriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice);

            _figureRenderer = new FigureRenderer(GraphicsService, 2048);
            _spriteRenderer = new SpriteRenderer(GraphicsService, spriteBatch, spriteFont);
            _debugRenderer  = new DebugRenderer(GraphicsService, spriteBatch, spriteFont)
            {
                DefaultColor        = Color.Black,
                DefaultTextPosition = new Vector2F(20, 40)
            };

            _scene = new Scene();

            // To draw figures, they are flattened (= converted to line segments)
            // internally. Figure.Tolerance defines the allowed error between the
            // smooth and the flattened curve.
            Figure.Tolerance = 0.0001f;

            // Add some FigureNodes to the scene.
            CreateGrid();
            CreateGridClone();
            CreateRandomPath();
            CreateRectangles();
            CreateEllipses();
            CreateAlphaBlendedFigures();
            CreateChain();
            CreateGizmo(spriteFont);
            CreateFlower();

            // Add a game object which handles the picking:
            _figurePickerObject = new FigurePickerObject(GraphicsService, _scene, _cameraObject, _debugRenderer);
            GameObjectService.Objects.Add(_figurePickerObject);
        }
示例#8
0
        public CustomSceneNodeSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;
            var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };

            GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            GameObjectService.Objects.Add(_cameraObject);

            // Create a new empty scene.
            _scene = new Scene();

            // Add the camera node to the scene.
            _scene.Children.Add(_cameraObject.CameraNode);

            // Add a few TextNodes. Position them along a circle.
            for (int i = 0; i < 36; i++)
            {
                Vector3F position = Matrix33F.CreateRotationZ(MathHelper.ToRadians((float)i * 10)) * new Vector3F(1, 0, 0);
                var      textNode = new TextNode
                {
                    PoseLocal = new Pose(position),
                    Color     = Color.Yellow,
                    Text      = i.ToString()
                };
                _scene.Children.Add(textNode);
            }

            // Initialize the TextRenderer.
            var spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default");

            _textRenderer = new TextRenderer(GraphicsService, spriteFont);

            // For debugging:
            _debugRenderer = new DebugRenderer(GraphicsService, spriteFont);
        }
示例#9
0
        protected AnimationSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            // Add a DelegateGraphicsScreen and use the OnRender method of this class to
            // do the rendering.
            _graphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = OnRender,
            };
            // The order of the graphics screens is back-to-front. Add the screen at index 0,
            // i.e. behind all other screens. The screen should be rendered first and all other
            // screens (menu, GUI, help, ...) should be on top.
            GraphicsService.Screens.Insert(0, _graphicsScreen);

            // Provide a SpriteBatch, SpriteFont and images for rendering.
            SpriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice);
            SpriteFont  = UIContentManager.Load <SpriteFont>("Default");
            Logo        = ContentManager.Load <Texture2D>("Logo");
            Reticle     = ContentManager.Load <Texture2D>("Reticle");
        }
示例#10
0
        public ObliqueFrustumSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;
            var graphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };

            GraphicsService.Screens.Insert(0, graphicsScreen);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            GameObjectService.Objects.Add(_cameraObject);

            var spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default");

            _debugRenderer = new DebugRenderer(GraphicsService, spriteFont);

            TestClippedProjection();
        }
        public DelegateGraphicsScreenSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            // Create the DelegateGraphicsService and add it to the graphics service.
            var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                UpdateCallback = Update,
                RenderCallback = Render,
            };

            // Graphics screens are rendered in the order in which they appear in the
            // IGraphicsService.Screens collection. We insert our screen at the beginning
            // of the collection to render our screen before the other screens (e.g. menu,
            // help text, profiling).
            GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

            // Create a sprite batch.
            _spriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice);

            // Load a sprite font.
            _spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default");
        }
示例#12
0
        public ProjectedShadowSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;
            var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };

            GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

            // Create a new empty scene.
            _scene = new Scene();
            Services.Register(typeof(IScene), null, _scene);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            _cameraObject.ResetPose(new Vector3F(-8, 6, 8), -ConstantsF.PiOver4, -0.4f);
            GameObjectService.Objects.Add(_cameraObject);

            // Add a default light setup (ambient light + 3 directional lights).
            var defaultLightsObject = new DefaultLightsObject(Services);

            GameObjectService.Objects.Add(defaultLightsObject);

            // Get the main directional light.
            _mainDirectionalLightNode = ((LightNode)_scene.GetSceneNode("KeyLight"));

            // Add a ground plane model to the scene graph.
            var grid = ContentManager.Load <ModelNode>("Ground/Ground").Clone();

            grid.ScaleLocal = new Vector3F(0.3f);
            _scene.Children.Add(grid);

            // Add a tank model to the scene graph.
            var tank = ContentManager.Load <ModelNode>("Tank/tank").Clone();

            _scene.Children.Add(tank);

            // Remember the mesh nodes of tank node.
            _tankMeshNodes = tank.GetSubtree().Where(n => n is MeshNode).ToArray();

            // Create the renderers.
            _meshRenderer = new MeshRenderer();

            var spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default");

            _debugRenderer = new DebugRenderer(GraphicsService, spriteFont);

            _projectedShadowRenderer = new ProjectedShadowRenderer(GraphicsService)
            {
                // The plane onto which the shadows are projected. It is positioned a bit above the ground
                // plane to avoid z-fighting.
                ShadowedPlane = new Plane(new Vector3F(0, 1, 0), 0.01f),

                // The shadow color is a transparent black.
                ShadowColor = new Vector4F(0, 0, 0, 0.4f),

                // The light position is set in Update().
                //LightPosition = ...
            };
        }
示例#13
0
        public SceneSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            _delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };
            GraphicsService.Screens.Insert(0, _delegateGraphicsScreen);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            GameObjectService.Objects.Add(_cameraObject);

            // Create a new empty scene.
            _scene = new Scene();

            // Add the camera node to the scene.
            _scene.Children.Add(_cameraObject.CameraNode);

            // Load a model. This model uses the DigitalRune Model Processor. Several XML
            // files (*.drmdl and *.drmat) in the folder of dude.fbx define the materials and other properties.
            // The DigitalRune Model Processor also imports the animations of the dude model.
            var model = ContentManager.Load <ModelNode>("Dude/Dude");

            // Add two clones of the model to the scene.
            _model0 = model.Clone();
            _model1 = model.Clone();
            _scene.Children.Add(_model0);
            _scene.Children.Add(_model1);

            // The dude model contains a single mesh node.
            var meshNode0 = (MeshNode)_model0.Children[0];
            var meshNode1 = (MeshNode)_model1.Children[0];

            // The imported animation data (skeleton and animations) is stored with the mesh.
            var animations = meshNode0.Mesh.Animations;

            // The MeshNodes of skinned models has a SkeletonPose which can be animated.
            // Let's start the first animation.
            var timeline0 = new TimelineClip(animations.Values.First())
            {
                LoopBehavior = LoopBehavior.Cycle, // Loop animation...
                Duration     = TimeSpan.MaxValue,  // ...forever.
            };

            _animationController0 = AnimationService.StartAnimation(timeline0, (IAnimatableProperty)meshNode0.SkeletonPose);
            _animationController0.UpdateAndApply();

            var timeline1 = new TimelineClip(animations.Values.First())
            {
                LoopBehavior = LoopBehavior.Cycle,
                Duration     = TimeSpan.MaxValue,

                // Start second animation at a different animation time to add some variety.
                Delay = TimeSpan.FromSeconds(-1),
            };

            _animationController1 = AnimationService.StartAnimation(timeline1, (IAnimatableProperty)meshNode1.SkeletonPose);
            _animationController1.UpdateAndApply();

            // Add some lights to the scene which have the same properties as the lights
            // of BasicEffect.EnableDefaultLighting().
            InitializeDefaultXnaLights(_scene);

            _meshRenderer = new MeshRenderer();

            var spriteFont = UIContentManager.Load <SpriteFont>("Default");

            _debugRenderer = new DebugRenderer(GraphicsService, spriteFont);
        }
示例#14
0
        public LdrSkySample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;
            var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };

            GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            GameObjectService.Objects.Add(_cameraObject);


            var spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default");

            _debugRenderer = new DebugRenderer(GraphicsService, spriteFont);

            _cieSkyFilter          = new CieSkyFilter(GraphicsService);
            _cieSkyFilter.Exposure = 5;
            _cieSkyFilter.Strength = 0.9f;

            _gradientSky = new GradientSkyNode();
            //_gradientSky.GroundColor = new Vector4F(0, 0, 1, 1);
            //_gradientSky.ZenithColor = new Vector4F(0, 0, 1, 1);
            //_gradientSky.FrontColor = new Vector4F(0, 0, 1, 1);
            //_gradientSky.BackColor = new Vector4F(0, 0, 1, 1);
            //_gradientSky.FrontZenithShift = 0.3f;
            //_gradientSky.FrontGroundShift = 0.1f;
            //_gradientSky.BackGroundShift = 0.1f;
            _gradientSky.CieSkyStrength = 0;

            _gradientTextureSky                = new GradientTextureSkyNode();
            _gradientTextureSky.TimeOfDay      = _time.TimeOfDay;
            _gradientTextureSky.Color          = new Vector4F(1);
            _gradientTextureSky.FrontTexture   = ContentManager.Load <Texture2D>("Sky/GradientSkyFront");
            _gradientTextureSky.BackTexture    = ContentManager.Load <Texture2D>("Sky/GradientSkyBack");
            _gradientTextureSky.CieSkyStrength = 1;

            _scatteringSky = new ScatteringSkyNode();
            _scatteringSky.SunIntensity *= 2;
            _scatteringSky.BetaMie      *= 2;
            _scatteringSky.GMie          = 0.75f;
            _scatteringSky.ScaleHeight   = _scatteringSky.AtmosphereHeight * 0.25f;

            InitializeStarfield();

            _cloudMapRenderer = new CloudMapRenderer(GraphicsService);
            _skyRenderer      = new SkyRenderer(GraphicsService);

            _milkyWay       = ContentManager.Load <TextureCube>("Sky/MilkyWay");
            _milkyWaySkybox = new SkyboxNode(_milkyWay)
            {
                Color = new Vector3F(0.05f)
            };

            _sun = new SkyObjectNode
            {
                GlowColor0    = new Vector3F(1, 1, 1) * 5,
                GlowExponent0 = 4000,

                //GlowColor1 = new Vector3F(0.4f) * 0.1f,
                //GlowExponent1 = 100
            };

            _moon = new SkyObjectNode
            {
                Texture         = new PackedTexture(ContentManager.Load <Texture2D>("Sky/Moon")),
                SunLight        = new Vector3F(1, 1, 1) * 1,
                AmbientLight    = new Vector3F(0.001f) * 1,
                LightWrap       = 0.1f,
                LightSmoothness = 1,
                AngularDiameter = new Vector2F(MathHelper.ToRadians(5)),

                GlowColor0          = new Vector3F(0.005f * 0),
                GlowCutoffThreshold = 0.001f,
                GlowExponent0       = 100
            };

            var cloudMap = new LayeredCloudMap
            {
                Density  = 10,
                Coverage = 0.5f,
                Size     = 1024,
            };
            var scale = CreateScale(0.2f);

            cloudMap.Layers[0] = new CloudMapLayer(null, scale * CreateScale(1), -0.5f, 1, 0.011f * 0);
            cloudMap.Layers[1] = new CloudMapLayer(null, scale * CreateScale(1.7f), -0.5f, 1f / 2f, 0.017f * 0);
            cloudMap.Layers[2] = new CloudMapLayer(null, scale * CreateScale(3.97f), -0.5f, 1f / 4f, 0.033f * 0);
            cloudMap.Layers[3] = new CloudMapLayer(null, scale * CreateScale(8.1f), -0.5f, 1f / 8f, 0.043f * 0);
            cloudMap.Layers[4] = new CloudMapLayer(null, scale * CreateScale(16, 17), -0.5f, 1f / 16f, 0.051f * 0);
            cloudMap.Layers[5] = new CloudMapLayer(null, scale * CreateScale(32, 31), -0.5f, 1f / 32f, 0.059f * 0);
            cloudMap.Layers[6] = new CloudMapLayer(null, scale * CreateScale(64, 67), -0.5f, 1f / 64f, 0.067f * 0);
            cloudMap.Layers[7] = new CloudMapLayer(null, scale * CreateScale(128, 127), -0.5f, 1f / 128f, 0.081f * 0);
            _cloudLayerNode    = new CloudLayerNode(cloudMap)
            {
                ForwardScatterScale  = 2.5f,
                ForwardScatterOffset = 0.3f,
                TextureMatrix        = CreateScale(0.5f),
                SkyCurvature         = 0.9f,
                NumberOfSamples      = 16,
            };

            _ephemeris = new Ephemeris();
            // Approx. location of Ternberg: Latitude = 48, Longitude = 15, Altitude = 300
            _ephemeris.Latitude  = 0;
            _ephemeris.Longitude = 15;
            _ephemeris.Altitude  = 300;
#if XBOX
            //_time = new DateTime(2013, 5, 1, 17, 17, 0, 0);
            _time = DateTime.Now;
#else
            _time = new DateTimeOffset(2013, 5, 1, 12, 0, 0, 0, TimeSpan.Zero);
            //_time = DateTimeOffset.UtcNow;
#endif
            UpdateEphemeris();

            _milkyWaySkybox.DrawOrder     = 0;
            _starfield.DrawOrder          = 1;
            _sun.DrawOrder                = 2;
            _moon.DrawOrder               = 3;
            _scatteringSky.DrawOrder      = 4;
            _gradientSky.DrawOrder        = 4;
            _gradientTextureSky.DrawOrder = 4;
            _cloudLayerNode.DrawOrder     = 5;

            _skyNodes = new SceneNode[]
            {
                _milkyWaySkybox,
                _starfield,
                _sun,
                _moon,
                _scatteringSky,
                //_gradientSky,
                //_gradientTextureSky,
                _cloudLayerNode,
            };

            var graphicsDevice = GraphicsService.GraphicsDevice;
            _skybox = new SkyboxNode(
                new RenderTargetCube(graphicsDevice, 512, false, SurfaceFormat.Color, DepthFormat.None))
            {
                Encoding = ColorEncoding.Rgbm,
            };

            _hdrFilter = new HdrFilter(GraphicsService)
            {
                MinExposure    = 0.5f,
                MaxExposure    = 2,
                BloomIntensity = 1,
                BloomThreshold = 0.6f,
                AdaptionSpeed  = 100,
            };

            _colorEncoder = new ColorEncoder(GraphicsService)
            {
                SourceEncoding = ColorEncoding.Rgb,
                TargetEncoding = _skybox.Encoding,
            };
        }
        public BillboardSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;
            var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };

            GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            GameObjectService.Objects.Add(_cameraObject);

            // In this example we need three renderers:
            // The MeshRenderer handles MeshNodes.
            _meshRenderer = new MeshRenderer();

            // The BillboardRenderer handles BillboardNodes and ParticleSystemNodes.
            _billboardRenderer = new BillboardRenderer(GraphicsService, 2048);

            // The DebugRenderer is used to draw text.
            var spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default");

            _debugRenderer = new DebugRenderer(GraphicsService, spriteFont);

            // Create a new empty scene.
            _scene = new Scene();

            // Add the camera node to the scene.
            _scene.Children.Add(_cameraObject.CameraNode);

            // Add a few models to the scene.
            var sandbox = ContentManager.Load <ModelNode>("Sandbox/Sandbox").Clone();

            _scene.Children.Add(sandbox);

            // Add some lights to the scene which have the same properties as the lights
            // of BasicEffect.EnableDefaultLighting().
            SceneSample.InitializeDefaultXnaLights(_scene);

            var texture = new PackedTexture(ContentManager.Load <Texture2D>("Billboard/BillboardReference"));

            // ----- View plane-aligned billboards with variations.
            // View plane-aligned billboards are rendered parallel to the screen.
            // The up-axis of the BillboardNode determines the up direction of the
            // billboard.
            var pose0         = new Pose(new Vector3(-9, 1.0f, 1.5f));
            var pose1         = pose0;
            var billboard     = new ImageBillboard(texture);
            var billboardNode = new BillboardNode(billboard);

            billboardNode.Name      = "View plane-aligned\nVarying color\nVarying alpha";
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            billboardNode.Color     = new Vector3(1, 0, 0);
            billboardNode.Alpha     = 0.9f;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            billboardNode.Color     = new Vector3(0, 1, 0);
            billboardNode.Alpha     = 0.7f;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            billboardNode.Color     = new Vector3(0, 0, 1);
            billboardNode.Alpha     = 0.3f;
            _scene.Children.Add(billboardNode);

            // ----- View plane-aligned billboards with different blend modes
            // blend mode = 0 ... additive blend
            // blend mode = 1 ... alpha blend
            pose0.Position.X       += 2;
            pose1                   = pose0;
            billboard               = new ImageBillboard(texture);
            billboard.BlendMode     = 0.0f;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.Name      = "View plane-aligned\nVarying blend mode";
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboard               = new ImageBillboard(texture);
            billboard.BlendMode     = 0.333f;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboard               = new ImageBillboard(texture);
            billboard.BlendMode     = 0.667f;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboard               = new ImageBillboard(texture);
            billboard.BlendMode     = 1.0f;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            // ----- View plane-aligned billboards with alpha test
            pose0.Position.X       += 2;
            pose1                   = pose0;
            billboard               = new ImageBillboard(texture);
            billboard.AlphaTest     = 0.9f;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.Name      = "View plane-aligned\nVarying reference alpha";
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboard               = new ImageBillboard(texture);
            billboard.AlphaTest     = 0.667f;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboard               = new ImageBillboard(texture);
            billboard.AlphaTest     = 0.333f;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboard               = new ImageBillboard(texture);
            billboard.AlphaTest     = 0.0f;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            // ----- View plane-aligned billboards with different scale and rotation
            pose0.Position.X        += 2;
            pose1                    = pose0;
            billboard                = new ImageBillboard(texture);
            billboard.Orientation    = BillboardOrientation.ViewPlaneAligned;
            billboardNode            = new BillboardNode(billboard);
            billboardNode.Name       = "View plane-aligned\nVarying scale\nVarying rotation";
            billboardNode.PoseWorld  = pose1;
            billboardNode.ScaleLocal = new Vector3(0.4f);
            _scene.Children.Add(billboardNode);

            pose1.Position.Z        -= 1;
            billboardNode            = billboardNode.Clone();
            billboardNode.Name       = null;
            billboardNode.PoseWorld  = pose1 * new Pose(Matrix.CreateRotationZ(MathHelper.ToRadians(-15)));
            billboardNode.ScaleLocal = new Vector3(0.6f);
            _scene.Children.Add(billboardNode);

            pose1.Position.Z        -= 1;
            billboardNode            = billboardNode.Clone();
            billboardNode.Name       = null;
            billboardNode.PoseWorld  = pose1 * new Pose(Matrix.CreateRotationZ(MathHelper.ToRadians(-30)));
            billboardNode.ScaleLocal = new Vector3(0.8f);
            _scene.Children.Add(billboardNode);

            pose1.Position.Z        -= 1;
            billboardNode            = billboardNode.Clone();
            billboardNode.Name       = null;
            billboardNode.PoseWorld  = pose1 * new Pose(Matrix.CreateRotationZ(MathHelper.ToRadians(-45)));
            billboardNode.ScaleLocal = new Vector3(1.0f);
            _scene.Children.Add(billboardNode);

            // ----- Viewpoint-oriented billboards
            // Viewpoint-orientated billboards always face the player. (The face normal
            // points directly to the camera.)
            pose0.Position.X       += 2;
            pose1                   = pose0;
            billboard               = new ImageBillboard(texture);
            billboard.Orientation   = BillboardOrientation.ViewpointOriented;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.Name      = "Viewpoint-oriented";
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            // ----- Screen-aligned billboards
            // View plane-aligned billboards and screen-aligned billboards are similar. The
            // billboards are rendered parallel to the screen. The orientation can be changed
            // by rotating the BillboardNode. The difference is that the orientation of view
            // plane-aligned billboards is relative to world space and the orientation of
            // screen-aligned billboards is relative to view space.
            // Screen-aligned billboards are, for example, used for text label.
            pose0.Position.X       += 2;
            pose1                   = pose0;
            billboard               = new ImageBillboard(texture);
            billboard.Orientation   = BillboardOrientation.ScreenAligned;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.Name      = "Screen-aligned";
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            // ----- Axial, view plane-aligned billboards
            pose0.Position.X       += 2;
            pose1                   = pose0;
            billboard               = new ImageBillboard(texture);
            billboard.Orientation   = BillboardOrientation.AxialViewPlaneAligned;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.Name      = "Axial, view plane-aligned";
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = billboardNode.Clone();
            billboardNode.Name      = null;
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            // ----- Axial, viewpoint-oriented billboards
            pose0.Position.X       += 2;
            pose1                   = pose0;
            billboard               = new ImageBillboard(texture);
            billboard.Orientation   = BillboardOrientation.AxialViewpointOriented;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.Name      = "Axial, viewpoint-oriented";
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            // ----- World-oriented billboards
            // World-oriented billboards have a fixed orientation in world space. The
            // orientation is determine by the BillboardNode.
            pose0.Position.X       += 2;
            pose1                   = pose0;
            pose1.Orientation      *= Matrix.CreateRotationY(0.2f);
            billboard               = new ImageBillboard(texture);
            billboard.Orientation   = BillboardOrientation.WorldOriented;
            billboardNode           = new BillboardNode(billboard);
            billboardNode.Name      = "World-oriented";
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            pose1.Orientation      *= Matrix.CreateRotationY(0.2f);
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1 * new Pose(Matrix.CreateRotationZ(MathHelper.ToRadians(15)));
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            pose1.Orientation      *= Matrix.CreateRotationY(0.2f);
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1 * new Pose(Matrix.CreateRotationZ(MathHelper.ToRadians(30)));
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            pose1.Orientation      *= Matrix.CreateRotationY(0.2f);
            billboardNode           = new BillboardNode(billboard);
            billboardNode.PoseWorld = pose1 * new Pose(Matrix.CreateRotationZ(MathHelper.ToRadians(45)));
            _scene.Children.Add(billboardNode);

            // ----- Animated billboards
            // DigitalRune Graphics supports "texture atlases". I.e. textures can be packed
            // together into a single, larger texture file. A PackedTexture can describe a
            // single texture packed into a texture atlas or a tile set packed into a
            // texture atlas. In this example the "beeWingFlap" is a set of three tiles.
            // Tile sets can be used for sprite animations. (The animation is set below in
            // Update().)
            pose0.Position.X       += 2;
            pose1                   = pose0;
            texture                 = new PackedTexture("Bee", ContentManager.Load <Texture2D>("Particles/beeWingFlap"), Vector2F.Zero, Vector2F.One, 3, 1);
            _animatedBillboard      = new ImageBillboard(texture);
            billboardNode           = new BillboardNode(_animatedBillboard);
            billboardNode.Name      = "Animated billboards";
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = new BillboardNode(_animatedBillboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            pose1.Position.Z       -= 1;
            billboardNode           = new BillboardNode(_animatedBillboard);
            billboardNode.PoseWorld = pose1;
            _scene.Children.Add(billboardNode);

            // Use DebugRenderer to draw node names above billboard nodes.
            foreach (var node in _scene.GetDescendants().OfType <BillboardNode>())
            {
                _debugRenderer.DrawText(node.Name, node.PoseWorld.Position + new Vector3(0, 1, 0), new Vector2F(0.5f), Color.Yellow, false);
            }
        }
示例#16
0
        public MeshNodeSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;
            var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };

            GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            GameObjectService.Objects.Add(_cameraObject);

            // For advanced users: Set this flag if you want to analyze the imported opaque data of
            // effect bindings.
            //EffectBinding.KeepOpaqueData = true;

            // Load a model. The model is processed using the DigitalRune Model Processor - not
            // the default XNA model processor!
            // In the folder that contains tank.fbx, there is an XML file tank.drmdl which defines
            // properties of the model. These XML files are automatically processed by the
            // DigitalRune Model Processor.
            // Each model itself is a tree of scene nodes. The grid model contains one mesh
            // node. The tank model contains several mesh nodes (turret, cannon, hatch,
            // wheels, ...).
            _model = ContentManager.Load <ModelNode>("Tank/tank");

            // The XNA ContentManager manages a single instance of each model. We clone
            // the model, to get a copy that we can modify without changing the original
            // instance. Cloning is fast because it only duplicates the scene nodes - but
            // not the mesh and material information.
            _model = _model.Clone();

            // _model is the root of a tree of scene nodes. The mesh nodes are the child
            // nodes. When we scale or move the _model, we automatically scale and move
            // all child nodes.
            _model.ScaleLocal = new Vector3F(0.8f);
            _model.PoseWorld  = new Pose(new Vector3F(0, 0, -2), Matrix33F.CreateRotationY(-0.3f));

            // Let's loop through the mesh nodes of the model:
            foreach (var meshNode in _model.GetSubtree().OfType <MeshNode>())
            {
                // Each MeshNode references a Mesh.
                Mesh mesh = meshNode.Mesh;

                // The mesh consists of several submeshes and several materials - usually
                // one material per submesh, but several submeshes could reference the same
                // materials.

                // Let's loop through the materials of this mesh.
                foreach (var material in mesh.Materials)
                {
                    // A material is a collection of EffectBindings - one EffectBinding for each
                    // render pass. For example, a complex game uses several render passes, like
                    // a pre-Z pass, a G-buffer pass, a shadow map pass, a deferred material pass,
                    // etc.In simple games there is only one pass which is called "Default".
                    var effectBinding = material["Default"];

                    // An EffectBinding references an Effect (the XNA Effect class) and it has
                    // "parameter bindings" and "technique bindings". These bindings select the
                    // values for the shader parameters when the mesh node is rendered.

                    // Let's change the binding for the DiffuseColor of the shader to give tank
                    // a red color.
                    effectBinding.Set("DiffuseColor", new Vector4(1, 0.7f, 0.7f, 1));

                    // The tank uses the default effect binding which is a BasicEffectBinding - this
                    // effect binding uses the XNA BasicEffect.
                    // In this sample we do not define any lights, therefore we disable the lighting
                    // in the shader.
                    ((BasicEffectBinding)effectBinding).LightingEnabled = false;
                }
            }

            _meshRenderer = new MeshRenderer();

            var spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default");

            _debugRenderer = new DebugRenderer(GraphicsService, spriteFont);
        }
示例#17
0
        public ProxyNodeSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;
            var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };

            GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

            _renderer = new MeshRenderer();

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            GameObjectService.Objects.Add(_cameraObject);

            _scene = new Scene();
            SceneSample.InitializeDefaultXnaLights(_scene);

            // For advanced users: Set this flag if you want to analyze the imported opaque data of
            // effect bindings.
            EffectBinding.KeepOpaqueData = true;

            // Original model in scene graph.
            var modelNode = ContentManager.Load <ModelNode>("Dude/Dude").Clone();

            modelNode.PoseLocal = new Pose(new Vector3(-2, 0, 0));
            var meshNode = modelNode.GetSubtree().OfType <MeshNode>().First();

            _scene.Children.Add(modelNode);

            // Clone referenced by proxy node.
            var modelNode2 = modelNode.Clone();
            var meshNode2  = modelNode2.GetSubtree().OfType <MeshNode>().First();

            meshNode2.SkeletonPose = meshNode.SkeletonPose;
            _proxyNode             = new ProxyNode(null)
            {
                Name       = "Proxy",
                PoseLocal  = new Pose(new Vector3(2, 0, 0), Matrix.CreateRotationY(ConstantsF.Pi)),
                ScaleLocal = new Vector3(0.5f),
            };
            _scene.Children.Add(_proxyNode);
            _proxyNode.Node = modelNode2;

            var spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default");

            _debugRenderer = new DebugRenderer(GraphicsService, spriteFont);

            var mesh = meshNode.Mesh;

            foreach (var m in mesh.Materials)
            {
                //((ConstParameterBinding<Vector3>)m["Default"].ParameterBindings["SpecularColor"]).Value = new Vector3();
                ((SkinnedEffectBinding)m["Default"]).PreferPerPixelLighting = true;
            }

            var timeline = new TimelineClip(mesh.Animations.Values.First())
            {
                Duration     = TimeSpan.MaxValue,
                LoopBehavior = LoopBehavior.Cycle,
            };

            AnimationService.StartAnimation(timeline, (IAnimatableProperty)meshNode.SkeletonPose);
        }
        public MaterialCaptureSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            _delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };
            GraphicsService.Screens.Insert(0, _delegateGraphicsScreen);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            GameObjectService.Objects.Add(_cameraObject);

            // Create a new empty scene.
            _scene = new Scene();

            // Add the camera node to the scene.
            _scene.Children.Add(_cameraObject.CameraNode);

            // Load the model using a new content manager.
            // We will change the material of the loaded mesh. These changes should not
            // affect the other samples in this project. Therefore, we use a new
            // content manager instance to load a unique instance of the model.
            _contentManager = new ContentManager(Services, game.Content.RootDirectory);
            _model          = _contentManager.Load <ModelNode>("Dude/Dude").Clone();

            // Add the model to the scene.
            _scene.Children.Add(_model);

            // The dude model does not use a matcap shader. Following code replaces the
            // dude model's materials with a matcap shader.
            var matcapMaterial = _contentManager.Load <Material>("Matcaps/MatcapNormalSkinned");
            var meshNode       = (MeshNode)_model.Children[0];

            for (int i = 0; i < meshNode.Mesh.Materials.Count; i++)
            {
                // Replace original material with the matcap material.
                var oldMaterial = meshNode.Mesh.Materials[i];
                var newMaterial = matcapMaterial.Clone();
                newMaterial.Name           = oldMaterial.Name;
                meshNode.Mesh.Materials[i] = newMaterial;

                // The original material uses a normal map in the "GBuffer" pass.
                // The matcap shader should use the same normal map.
                var oldNormalTextureBinding = oldMaterial["GBuffer"].ParameterBindings["NormalTexture"];
#if MONOGAME
                // In MonoGame the effect parameter is of type Texture2D, but in XNA it is Texture.
                var normalTexture = ((EffectParameterBinding <Texture2D>)oldNormalTextureBinding).Value;
#else
                var normalTexture = ((EffectParameterBinding <Texture>)oldNormalTextureBinding).Value;
#endif
                newMaterial["Default"].Set("NormalTexture", normalTexture);
            }

            // We have replaced the material of the mesh. The MeshNode caches several material
            // parameters. We must force the MeshNode to load the new material info.
            meshNode.Mesh = meshNode.Mesh;

            _meshRenderer = new MeshRenderer();

            var spriteFont = UIContentManager.Load <SpriteFont>("Default");
            _debugRenderer = new DebugRenderer(GraphicsService, spriteFont);

            UpdateMatcapTexture();
        }