protected override void BeginTransitionOn() { base.BeginTransitionOn(); _scene = _kernel.Get<Scene>(); _scene.GetService<Renderer>() .StartPlan() .Then(new CreateTargetComponent(new RenderTargetInfo(1024, 768, SurfaceFormat.Color, DepthFormat.None , 0, false, RenderTargetUsage.PreserveContents), "name")) .Then<SpriteComponent>() .Show("name") .Apply(); var camera = new Camera { NearClip = 1, FarClip = 700, View = Matrix4x4.CreateLookAt(new Vector3(100, 50, 0), new Vector3(0, 50, 0), Vector3.UnitY) }; camera.Projection = Matrix4x4.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), 16f / 9f, camera.NearClip, camera.FarClip); var cameraDesc = _kernel.Get<EntityDescription>(); cameraDesc.AddProperty(new TypedName<Camera>("camera")); cameraDesc.AddProperty(new TypedName<Viewport>("viewport")); cameraDesc.AddBehaviour<View>(); var cameraEntity = cameraDesc.Create(); cameraEntity.GetProperty(new TypedName<Camera>("camera")).Value = camera; cameraEntity.GetProperty(new TypedName<Viewport>("viewport")).Value = new Viewport() {Width = _device.PresentationParameters.BackBufferWidth, Height = _device.PresentationParameters.BackBufferHeight}; _scene.Add(cameraEntity); var spriteDesc = _kernel.Get<EntityDescription>(); spriteDesc.AddBehaviour<Sprite>(); Random r = new Random(); for (int i = 0; i < 50; i++) { var e = spriteDesc.Create(); _scene.Add(e, new NamedBoxCollection { { Sprite.TextureName, _content.Load<Texture2D>("Chrysanthemum") }, { Sprite.PositionName, new Vector2(r.Next(0, 1000), r.Next(0, 1000)) }, { Sprite.ColorName, Color.White }, { Sprite.ScaleName, new Vector2(0.1f) } }); } }
protected override void BeginTransitionOn() { base.BeginTransitionOn(); _scene = _kernel.Get<Scene>(); //Start renderer var renderer = _scene.GetService<Renderer>(); renderer.StartPlan() .Then<GeometryBufferComponent>() .Then<EdgeDetectComponent>() .Then<Ssao>() .Then<LightingComponent>() .Then<RestoreDepthPhase>() .Then<ToneMapComponent>() .Then<AntiAliasComponent>() .Show("antialiased") .Apply(); _resolution = renderer.Data.Get<Vector2>("resolution"); //Create camera _camera = new Camera { NearClip = 1, FarClip = 7000, View = Matrix4x4.CreateLookAt(new Vector3(-100, 300, 10), new Vector3(300, 0, 0), -Vector3.UnitZ) }; _camera.Projection = Matrix4x4.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), 16f / 9f, _camera.NearClip, _camera.FarClip); var cameraDesc = _kernel.Get<EntityDescription>(); cameraDesc.AddProperty(new TypedName<Camera>("camera")); cameraDesc.AddProperty(new TypedName<Viewport>("viewport")); cameraDesc.AddBehaviour<View>(); var cameraEntity = cameraDesc.Create(); cameraEntity.GetProperty(new TypedName<Camera>("camera")).Value = _camera; cameraEntity.GetProperty(new TypedName<Viewport>("viewport")).Value = new Viewport() { Width = _device.PresentationParameters.BackBufferWidth, Height = _device.PresentationParameters.BackBufferHeight }; _scene.Add(cameraEntity); //create ambient light var ambientLight = _kernel.Get<EntityDescription>(); ambientLight.AddProperty(new TypedName<Vector3>("sky_colour")); ambientLight.AddProperty(new TypedName<Vector3>("ground_colour")); ambientLight.AddProperty(new TypedName<Vector3>("up")); ambientLight.AddBehaviour<AmbientLight>(); var ambientLightEntity = ambientLight.Create(); ambientLightEntity.GetProperty(new TypedName<Vector3>("sky_colour")).Value = new Vector3(0.08f); ambientLightEntity.GetProperty(new TypedName<Vector3>("ground_colour")).Value = new Vector3(0.04f, 0.05f, 0.04f); ambientLightEntity.GetProperty(new TypedName<Vector3>("up")).Value = Vector3.UnitY; _scene.Add(ambientLightEntity); //Create text var textDesc = _kernel.Get<EntityDescription>(); textDesc.AddBehaviour<ModelInstance>(); textDesc.AddProperty(ModelInstance.TransformName, Matrix4x4.Identity); textDesc.AddBehaviour<StringModelData>(); var textEnt = textDesc.Create(); var init = new NamedBoxCollection { { StringModelData.FontName, _content.Load<VertexFont>("Fonts/Cousine-Regular-Latin") }, { StringModelData.StringName, "Hello, World" }, { StringModelData.ThicknessName, 25 }, }; _scene.Add(textEnt, init); }
protected override void BeginTransitionOn() { if (_scene != null) return; _scene = _kernel.Get<Scene>(); var renderer = _scene.GetService<Renderer>(); renderer.StartPlan() .Then(new CreateTargetComponent(new RenderTargetInfo(0, 0, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 1, false, default(RenderTargetUsage)))) .Then<TranslucentComponent>() .Apply(); var cameraPosition = new Vector3(0, 25, -200); _camera = new Camera { NearClip = 1, FarClip = 3000, View = Matrix4x4.CreateLookAt(cameraPosition, new Vector3(0, 0, 0), Vector3.UnitY) }; _camera.Projection = Matrix4x4.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), 16f / 9f, _camera.NearClip, _camera.FarClip); var cameraDescription = _kernel.Get<EntityDescription>(); cameraDescription.AddProperty(new TypedName<Viewport>("viewport")); cameraDescription.AddBehaviour<View>(); var cameraEntity = cameraDescription.Create(); cameraEntity.GetProperty(new TypedName<Camera>("camera")).Value = _camera; cameraEntity.GetProperty(new TypedName<Viewport>("viewport")).Value = new Viewport() { Width = _device.PresentationParameters.BackBufferWidth, Height = _device.PresentationParameters.BackBufferHeight }; _scene.Add(cameraEntity); var particleEntityDesc = _kernel.Get<EntityDescription>(); particleEntityDesc.AddProperty(new TypedName<Vector3>("position")); particleEntityDesc.AddBehaviour<ParticleEmitter>(); var entity = particleEntityDesc.Create(); entity.GetProperty(new TypedName<Vector3>("position")).Value = Vector3.Zero; NamedBoxCollection initData = new NamedBoxCollection(); initData.Set(new TypedName<ParticleEmitterDescription>("particlesystem"), _content.Load<ParticleEmitterDescription>("Particles/TestEmitter1")); _scene.Add(entity, initData); base.OnShown(); }
public CameraScript(Camera camera) { this.camera = camera; this.positionCurve = new Curve3D(); this.lookatCurve = new Curve3D(); }
protected override void BeginTransitionOn() { _scene = _kernel.Get<Scene>(); //Camera _cameraPosition = new Vector3(5, 0, -50); _camera = new Camera { NearClip = 1, FarClip = 700, View = Matrix4x4.CreateLookAt(_cameraPosition, new Vector3(0, 0, 0), Vector3.UnitY) }; _camera.Projection = Matrix4x4.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), 16f / 9f, _camera.NearClip, _camera.FarClip); _cameraRotation = new Vector3(0, MathHelper.Pi, 0); //Camera entity var cameraDesc = _kernel.Get<EntityDescription>(); cameraDesc.AddProperty(new TypedName<Camera>("camera")); cameraDesc.AddProperty(new TypedName<Viewport>("viewport")); cameraDesc.AddBehaviour<View>(); var cameraEntity = cameraDesc.Create(); cameraEntity.GetProperty(new TypedName<Camera>("camera")).Value = _camera; cameraEntity.GetProperty(new TypedName<Viewport>("viewport")).Value = new Viewport() { Width = _device.PresentationParameters.BackBufferWidth, Height = _device.PresentationParameters.BackBufferHeight }; _scene.Add(cameraEntity); _view = cameraEntity.GetBehaviour<View>(); //Skybox var skyboxDesc = _kernel.Get<EntityDescription>(); skyboxDesc.AddBehaviour<Skybox>(); var skybox = skyboxDesc.Create(); skybox.GetProperty(new TypedName<TextureCube>("texture")).Value = _content.Load<TextureCube>("StormCubeMap"); skybox.GetProperty(new TypedName<float>("brightness")).Value = 0.5f; skybox.GetProperty(new TypedName<bool>("gamma_correct")).Value = false; _scene.Add(skybox); //Sphere for (int i = 1; i < 7; i++) { var sphereModel = _content.Load<ModelData>(@"Models\sphere"); var sphere = _kernel.Get<EntityDescription>(); sphere.AddProperty(new TypedName<ModelData>("model")); sphere.AddProperty(new TypedName<Matrix4x4>("transform")); sphere.AddProperty(new TypedName<bool>("is_static")); sphere.AddBehaviour<ModelInstance>(); var sphereEntity = sphere.Create(); sphereEntity.GetProperty(new TypedName<ModelData>("model")).Value = sphereModel; sphereEntity.GetProperty(new TypedName<Matrix4x4>("transform")).Value = Matrix4x4.CreateScale(4 / sphereModel.Meshes.First().BoundingSphere.Radius) * Matrix4x4.CreateRotationY(MathHelper.PiOver2) * Matrix4x4.CreateTranslation(0, 0, i * 20); sphereEntity.GetProperty(new TypedName<bool>("is_static")).Value = true; _scene.Add(sphereEntity); var smodel = sphereEntity.GetBehaviour<ModelInstance>(); smodel.Opacity = 0.15f; smodel.SubSurfaceScattering = 0.5f; smodel.Attenuation = 0.2f; } //Particles var particleEntityDesc = _scene.Kernel.Get<EntityDescription>(); particleEntityDesc.AddProperty(new TypedName<Vector3>("position")); particleEntityDesc.AddBehaviour<ParticleEmitter>(); var entity = particleEntityDesc.Create(); NamedBoxCollection initData = new NamedBoxCollection(); initData.Set(new TypedName<ParticleEmitterDescription>("particlesystem"), _content.Load<ParticleEmitterDescription>("Particles/TestEmitter1")); _scene.Add(entity, initData); _scene.GetService<Renderer>() .StartPlan() .Then<GeometryBufferComponent>() .Then<EdgeDetectComponent>() .Then<Ssao>() .Then<LightingComponent>() .Then<DeferredTransparency>() .Then<ToneMapComponent>() .Then<AntiAliasComponent>() .Show("antialiased") .Apply(); _game.DisplayUI = true; base.BeginTransitionOn(); }
public TestScene(IKernel kernel, Game game, ContentManager content, GraphicsDevice device, [Optional]SceneConfiguration config) { config = config ?? new SceneConfiguration(); _scene = new Scene(kernel); _game = game; _cameraPosition = new Vector3(100, 50, 0); _camera = new Camera(); _camera.NearClip = 1; _camera.FarClip = 700; _camera.View = Matrix4x4.CreateLookAt(_cameraPosition, new Vector3(0, 50, 0), Vector3.UnitY); _camera.Projection = Matrix4x4.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), 16f / 9f, _camera.NearClip, _camera.FarClip); if (config.View) { var cameraDesc = kernel.Get<EntityDescription>(); cameraDesc.AddProperty(new TypedName<Camera>("camera")); cameraDesc.AddProperty(new TypedName<Viewport>("viewport")); cameraDesc.AddBehaviour<View>(); var cameraEntity = cameraDesc.Create(); cameraEntity.GetProperty(new TypedName<Camera>("camera")).Value = _camera; cameraEntity.GetProperty(new TypedName<Viewport>("viewport")).Value = new Viewport() {Width = device.PresentationParameters.BackBufferWidth, Height = device.PresentationParameters.BackBufferHeight}; _scene.Add(cameraEntity); } if (config.Skybox) { var skyboxDesc = kernel.Get<EntityDescription>(); skyboxDesc.AddBehaviour<Skybox>(); var skybox = skyboxDesc.Create(); skybox.GetProperty(new TypedName<TextureCube>("texture")).Value = content.Load<TextureCube>("StormCubeMap"); skybox.GetProperty(new TypedName<float>("brightness")).Value = 0.5f; skybox.GetProperty(new TypedName<bool>("gamma_correct")).Value = false; _scene.Add(skybox); } var pointLight = kernel.Get<EntityDescription>(); pointLight.AddProperty(new TypedName<Vector3>("position")); pointLight.AddProperty(new TypedName<Vector3>("colour")); pointLight.AddProperty(new TypedName<float>("range")); pointLight.AddBehaviour<PointLight>(); //scene.Add(pointLight.Create()); _lights = new List<PointLight>(); var rng = new Random(); for (int i = 0; i < config.RandomPointLights; i++) { var entity = pointLight.Create(); _scene.Add(entity); entity.GetProperty(new TypedName<Vector3>("position")).Value = new Vector3(0, 10, 0); entity.GetProperty(new TypedName<Vector3>("colour")).Value = new Vector3(0, 5, 0); entity.GetProperty(new TypedName<float>("range")).Value = 200; var light = entity.GetBehaviour<PointLight>(null); light.Colour = Vector3.Normalize(new Vector3(0.1f + (float)rng.NextDouble(), 0.1f + (float)rng.NextDouble(), 0.1f + (float)rng.NextDouble())) * 10; _lights.Add(light); } if (config.Spotlight) { var spotLight = kernel.Get<EntityDescription>(); spotLight.AddProperty(new TypedName<Vector3>("position")); spotLight.AddProperty(new TypedName<Vector3>("colour")); spotLight.AddProperty(new TypedName<Vector3>("direction")); spotLight.AddProperty(new TypedName<float>("angle")); spotLight.AddProperty(new TypedName<float>("range")); spotLight.AddProperty(new TypedName<Texture2D>("mask")); spotLight.AddProperty(new TypedName<int>("shadow_resolution")); spotLight.AddBehaviour<SpotLight>(); var spotLightEntity = spotLight.Create(); spotLightEntity.GetProperty(new TypedName<Vector3>("position")).Value = new Vector3(-180, 250, 0); spotLightEntity.GetProperty(new TypedName<Vector3>("colour")).Value = new Vector3(10); spotLightEntity.GetProperty(new TypedName<Vector3>("direction")).Value = new Vector3(0, -1, 0); spotLightEntity.GetProperty(new TypedName<float>("angle")).Value = MathHelper.PiOver2; spotLightEntity.GetProperty(new TypedName<float>("range")).Value = 500; spotLightEntity.GetProperty(new TypedName<Texture2D>("mask")).Value = content.Load<Texture2D>("Chrysanthemum"); spotLightEntity.GetProperty(new TypedName<int>("shadow_resolution")).Value = 1024; _spotLight = spotLightEntity.GetBehaviour<SpotLight>(null); _scene.Add(spotLightEntity); } if (config.AmbientLight) { var ambientLight = kernel.Get<EntityDescription>(); ambientLight.AddProperty(new TypedName<Vector3>("sky_colour")); ambientLight.AddProperty(new TypedName<Vector3>("ground_colour")); ambientLight.AddProperty(new TypedName<Vector3>("up")); ambientLight.AddBehaviour<AmbientLight>(); var ambientLightEntity = ambientLight.Create(); ambientLightEntity.GetProperty(new TypedName<Vector3>("sky_colour")).Value = new Vector3(0.04f); ambientLightEntity.GetProperty(new TypedName<Vector3>("ground_colour")).Value = new Vector3(0.04f, 0.05f, 0.04f); ambientLightEntity.GetProperty(new TypedName<Vector3>("up")).Value = Vector3.UnitY; _scene.Add(ambientLightEntity); } if (config.SunLight) { var sunlight = kernel.Get<EntityDescription>(); sunlight.AddBehaviour<SunLight>(); var sunlightEntity = sunlight.Create(); sunlightEntity.GetProperty(new TypedName<Vector3>("colour")).Value = new Vector3(1, 0.75f, 0.6f); sunlightEntity.GetProperty(new TypedName<Vector3>("direction")).Value = -Vector3.UnitY; sunlightEntity.GetProperty(new TypedName<int>("shadow_resolution")).Value = 1024; _scene.Add(sunlightEntity); //var sunEntity = kernel.Get<EntityDescription>(); //sunEntity.AddProperty(SunLight.DirectionName, Vector3.Normalize(new Vector3(-.2f, -1f, .3f))); //sunEntity.AddProperty(SunLight.ColourName, new Vector3(1, 0.3f, 0.01f) * 5); //sunEntity.AddProperty(SunLight.ShadowResolutionName, 4096); //sunEntity.AddProperty(SunLight.ActiveName, true); //sunEntity.AddBehaviour<SunLight>(); //Entity sun = sunEntity.Create(); //_scene.Add(sun); //var sun2 = sunEntity.Create(); //sun2.GetProperty<Vector3>("direction").Value = Vector3.Normalize(new Vector3(1, -1, 0)); //sun2.GetProperty<Vector3>("colour").Value = new Vector3(1, 0, 0); //scene.Add(sun2); } //var floor = content.Load<ModelData>(@"Models\Ground"); //var floorEntity = kernel.Get<EntityDescription>(); //floorEntity.AddProperty<ModelData>("model", floor); //floorEntity.AddProperty<Matrix>("transform", Matrix.CreateScale(2)); //floorEntity.AddProperty<bool>("isstatic", true); //floorEntity.AddBehaviour<ModelInstance>(); //scene.Add(floorEntity.Create()); //var ship1 = content.Load<ModelData>(@"Models\Ship1"); //var ship1Entity = kernel.Get<EntityDescription>(); //ship1Entity.AddProperty<ModelData>("model", ship1); //ship1Entity.AddProperty<Matrix>("transform", Matrix.CreateTranslation(30, 0, 0)); //ship1Entity.AddProperty<bool>("is_static", true); //ship1Entity.AddBehaviour<ModelInstance>(); //scene.Add(ship1Entity.Create()); //var hebeModel = content.Load<ModelData>(@"Models\Hebe2"); //var hebe = kernel.Get<EntityDescription>(); //hebe.AddProperty(new TypedName<ModelData>("model")); //hebe.AddProperty(new TypedName<Matrix4x4>("transform")); //hebe.AddProperty(new TypedName<bool>("is_static")); //hebe.AddBehaviour<ModelInstance>(); //var hebeEntity = hebe.Create(); //hebeEntity.GetProperty(new TypedName<ModelData>("model")).Value = hebeModel; //hebeEntity.GetProperty(new TypedName<Matrix4x4>("transform")).Value = Matrix4x4.CreateScale(25 / hebeModel.Meshes.First().BoundingSphere.Radius) // * Matrix4x4.CreateRotationY(MathHelper.PiOver2) // * Matrix4x4.CreateTranslation(-150, 20, 0); //hebeEntity.GetProperty(new TypedName<bool>("is_static")).Value = true; //hebeEntity.GetProperty(ModelInstance.OpacityName).Value = 0.5f; //_scene.Add(hebeEntity); var sphereModel = content.Load<ModelData>(@"Models\sphere"); var sphere = kernel.Get<EntityDescription>(); sphere.AddProperty(new TypedName<ModelData>("model")); sphere.AddProperty(new TypedName<Matrix4x4>("transform")); sphere.AddProperty(new TypedName<bool>("is_static")); sphere.AddBehaviour<ModelInstance>(); var sphereEntity = sphere.Create(); sphereEntity.GetProperty(new TypedName<ModelData>("model")).Value = sphereModel; sphereEntity.GetProperty(new TypedName<Matrix4x4>("transform")).Value = Matrix4x4.CreateScale(5 / sphereModel.Meshes.First().BoundingSphere.Radius) * Matrix4x4.CreateRotationY(MathHelper.PiOver2) * Matrix4x4.CreateTranslation(-150, 20, 0); sphereEntity.GetProperty(new TypedName<bool>("is_static")).Value = true; _scene.Add(sphereEntity); var smodel = sphereEntity.GetBehaviour<ModelInstance>(null); smodel.Opacity = 0.5f; smodel.SubSurfaceScattering = 0.5f; smodel.Attenuation = 0.3f; //var dudeModel = content.Load<ModelData>(@"dude"); //var dude = kernel.Get<EntityDescription>(); //dude.AddProperty<ModelData>("model", dudeModel); //dude.AddProperty<Matrix>("transform", Matrix.CreateScale(0.75f) * Matrix.CreateTranslation(-50, 0, 0)); //dude.AddProperty<bool>("is_static", true); //dude.AddBehaviour<ModelInstance>(); //dude.AddBehaviour<Animated>(); //var dudeEntity = dude.Create(); //scene.Add(dudeEntity); var sponzaModel = content.Load<ModelData>(@"Sponza"); var sponza = kernel.Get<EntityDescription>(); sponza.AddProperty(new TypedName<ModelData>("model")); sponza.AddProperty(new TypedName<Matrix4x4>("transform")); sponza.AddProperty(new TypedName<bool>("is_static")); sponza.AddBehaviour<ModelInstance>(); var sponzaEntity = sponza.Create(); sponzaEntity.GetProperty(new TypedName<ModelData>("model")).Value = sponzaModel; sponzaEntity.GetProperty(new TypedName<Matrix4x4>("transform")).Value = Matrix4x4.Identity * Matrix4x4.CreateScale(1); sponzaEntity.GetProperty(new TypedName<bool>("is_static")).Value = true; _scene.Add(sponzaEntity); var renderer = _scene.GetService<Renderer>(); _resolution = renderer.Data.Get<Vector2>("resolution"); var console = kernel.Get<CommandConsole>(); renderer.Settings.BindCommandEngine(console.Engine); if (config.Fire) { //var fire1 = Fire.Create(kernel, content, new Vector3(123.5f, 30f, -55f)); //var fire2 = Fire.Create(kernel, content, new Vector3(123.5f, 30f, 35f)); //var fire3 = Fire.Create(kernel, content, new Vector3(-157f, 30f, 35f)); //var fire4 = Fire.Create(kernel, content, new Vector3(-157f, 30f, -55f)); //scene.Add(fire1); //scene.Add(fire2); //scene.Add(fire3); //scene.Add(fire4); } _cameraScript = new CameraScript(_camera); _cameraScript.AddWaypoint(0, new Vector3(218, 160, 104), new Vector3(0, 150, 0)); _cameraScript.AddWaypoint(10, new Vector3(-195, 160, 104), new Vector3(-150, 150, 0)); _cameraScript.AddWaypoint(12, new Vector3(-270, 160, 96), new Vector3(-150, 150, 0)); _cameraScript.AddWaypoint(14, new Vector3(-302, 160, 45), new Vector3(-150, 150, 0)); _cameraScript.AddWaypoint(16, new Vector3(-286, 160, 22), new Vector3(-150, 150, 0)); _cameraScript.AddWaypoint(18, new Vector3(-276, 160, 22), new Vector3(-150, 100, 0)); _cameraScript.AddWaypoint(20, new Vector3(-158, 42, 19), new Vector3(-150, 40, 0)); _cameraScript.AddWaypoint(21, new Vector3(-105, 24, -7), new Vector3(-150, 40, 0)); _cameraScript.AddWaypoint(23, new Vector3(-105, 44, -7), new Vector3(-150, 40, 0)); _cameraScript.AddWaypoint(27, new Vector3(-105, 50, -7), new Vector3(-80, 50, -100)); _cameraScript.AddWaypoint(32, new Vector3(100, 50, -7), new Vector3(150, 40, 0)); _cameraScript.AddWaypoint(34, new Vector3(100, 50, -7), new Vector3(150, 40, 100)); _cameraScript.AddWaypoint(36, new Vector3(100, 50, -7), new Vector3(0, 60, 0)); //cameraScript.AddWaypoint(1000, new Vector3(100, 50, -7), new Vector3(0, 60, 0)); _cameraScript.Initialise(); }
public DecalTest(IKernel kernel, ContentManager content, GraphicsDevice device) : base("Decal Test", kernel) { _scene = kernel.Get<Scene>(); _scene.GetService<Renderer>().StartPlan() .Then<GeometryBufferComponent>() .Then<DecalComponent>() .Then<DecalMixComponent>() .Then<Ssao>() .Then<LightingComponent>() .Then<TranslucentComponent>() .Then<ToneMapComponent>() .Then<AntiAliasComponent>() //.Show("gbuffer_normals") .Apply(); _camera = new Camera { NearClip = 1, FarClip = 7000, View = Matrix4x4.CreateLookAt(new Vector3(100, 50, -200), new Vector3(0, 0, 0), Vector3.UnitY) }; _camera.Projection = Matrix4x4.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), 16f / 9f, _camera.NearClip, _camera.FarClip); var cameraDesc = kernel.Get<EntityDescription>(); cameraDesc.AddProperty(new TypedName<Camera>("camera")); cameraDesc.AddProperty(new TypedName<Viewport>("viewport")); cameraDesc.AddBehaviour<View>(); var cameraEntity = cameraDesc.Create(); cameraEntity.GetProperty(new TypedName<Camera>("camera")).Value = _camera; cameraEntity.GetProperty(new TypedName<Viewport>("viewport")).Value = new Viewport() { Width = device.PresentationParameters.BackBufferWidth, Height = device.PresentationParameters.BackBufferHeight }; _scene.Add(cameraEntity); var ambientLight = kernel.Get<EntityDescription>(); ambientLight.AddProperty(new TypedName<Vector3>("sky_colour"), new Vector3(0.44f, 0.44f, 0.74f)); ambientLight.AddProperty(new TypedName<Vector3>("ground_colour"), new Vector3(0.24f, 0.35f, 0.24f)); ambientLight.AddProperty(new TypedName<Vector3>("up"), Vector3.UnitY); ambientLight.AddBehaviour<AmbientLight>(); _scene.Add(ambientLight.Create()); var sponza = kernel.Get<EntityDescription>(); sponza.AddProperty(new TypedName<ModelData>("model"), content.Load<ModelData>(@"Sponza")); sponza.AddProperty(new TypedName<Matrix4x4>("transform"), Matrix4x4.CreateScale(0.5f) * Matrix4x4.CreateTranslation(-350, 0, 0)); sponza.AddProperty(new TypedName<bool>("is_static"), true); sponza.AddBehaviour<ModelInstance>(); _scene.Add(sponza.Create()); var spotLight = kernel.Get<EntityDescription>(); spotLight.AddProperty(new TypedName<Vector3>("position"), new Vector3(150, 50, -50)); spotLight.AddProperty(new TypedName<Vector3>("colour"), new Vector3(1)); spotLight.AddProperty(new TypedName<Vector3>("direction"), new Vector3(-1, 0, 0.25f)); spotLight.AddProperty(new TypedName<float>("angle"), MathHelper.PiOver2); spotLight.AddProperty(new TypedName<float>("range"), 1000); spotLight.AddProperty(new TypedName<int>("shadow_resolution"), 1024); spotLight.AddBehaviour<SpotLight>(); var spotLightEntity = spotLight.Create(); _scene.Add(spotLightEntity); var decal = kernel.Get<EntityDescription>(); decal.AddBehaviour<Decal>(); //Random r = new Random(2); //for (int i = 0; i < 150; i++) //{ // _scene.Add(decal.Create(), new NamedBoxCollection { // { Decal.NormalName, content.Load<Texture2D>("randomnormals") }, // { Decal.DiffuseName, content.Load<Texture2D>("Splatter") }, // { Decal.TransformName, Matrix.CreateScale(30, 5, 30) * Matrix.CreateRotationX(MathHelper.PiOver2) * Matrix.CreateRotationY(MathHelper.PiOver2) * Matrix.CreateTranslation(-130, r.Next(-100, 100), r.Next(-100, 100)) }, // { Decal.AngleCutoffName, MathHelper.PiOver4 } // }); //} _scene.Add(decal.Create(), new NamedBoxCollection { { Decal.NormalName, content.Load<Texture2D>("randomnormals") }, { Decal.DiffuseName, content.Load<Texture2D>("Splatter") }, { Decal.TransformName, Matrix4x4.CreateScale(30, 30, 30) * Matrix4x4.CreateRotationX(MathHelper.PiOver2 + MathHelper.PiOver4) * Matrix4x4.CreateRotationY(MathHelper.PiOver2) * Matrix4x4.CreateTranslation(-135, -10, 0) }, { Decal.AngleCutoffName, MathHelper.Pi / 3.65f } }); _scene.Add(decal.Create(), new NamedBoxCollection { { Decal.NormalName, content.Load<Texture2D>("randomnormals") }, { Decal.DiffuseName, content.Load<Texture2D>("Splatter") }, { Decal.TransformName, Matrix4x4.CreateScale(30, 30, 30) * Matrix4x4.CreateRotationX(MathHelper.PiOver2 + MathHelper.PiOver4) * Matrix4x4.CreateRotationY(MathHelper.PiOver2) * Matrix4x4.CreateTranslation(-135, -10, 40) }, { Decal.AngleCutoffName, MathHelper.Pi / 3 } }); _scene.Add(decal.Create(), new NamedBoxCollection { { Decal.NormalName, content.Load<Texture2D>("randomnormals") }, { Decal.DiffuseName, content.Load<Texture2D>("Splatter") }, { Decal.TransformName, Matrix4x4.CreateScale(30, 30, 30) * Matrix4x4.CreateRotationX(MathHelper.PiOver2 + MathHelper.PiOver4) * Matrix4x4.CreateRotationY(MathHelper.PiOver2) * Matrix4x4.CreateTranslation(-135, -10, 80) }, { Decal.AngleCutoffName, MathHelper.Pi / 2 } }); _scene.Add(decal.Create(), new NamedBoxCollection { { Decal.NormalName, content.Load<Texture2D>("randomnormals") }, { Decal.DiffuseName, content.Load<Texture2D>("Splatter") }, { Decal.TransformName, Matrix4x4.CreateScale(30, 30, 30) * Matrix4x4.CreateRotationX(MathHelper.PiOver2 + MathHelper.PiOver4) * Matrix4x4.CreateRotationY(MathHelper.PiOver2) * Matrix4x4.CreateTranslation(-135, -10, 120) }, { Decal.AngleCutoffName, MathHelper.Pi } }); }
public AnimatedDude(IKernel kernel, ContentManager content, GraphicsDevice device) : base("Animated Dude", kernel) { _scene = kernel.Get<Scene>(); var model = content.Load<ModelData>(@"models/zoe"); var dude = kernel.Get<EntityDescription>(); dude.AddProperty(new TypedName<ModelData>("model"), model); dude.AddProperty(new TypedName<Matrix>("transform"), Matrix.CreateScale(50f) * Matrix.CreateTranslation(0, 0, -150)); dude.AddProperty(new TypedName<bool>("is_static"), false); dude.AddBehaviour<ModelInstance>(); dude.AddBehaviour<Animated>(); dude.AddBehaviour<AnimationQueue>(); var dudeEntity = dude.Create(); _scene.Add(dudeEntity); _animationQueue = dudeEntity.GetBehaviour<AnimationQueue>(null); _animationQueue.EnableRootBoneTranslationY = false; _animationQueue.EnableRootBoneTranslationX = false; _animationQueue.EnableRootBoneTranslationZ = false; _animationQueue.EnableRootBoneScale = false; _dude = dudeEntity.GetBehaviour<ModelInstance>(null); _animationQueue.DefaultClip = new AnimationQueue.ClipPlaybackParameters { Clip = content.Load<Clip>("Models/ZoeAnimations/t-pose"), FadeInTime = TimeSpan.FromSeconds(0.25f), FadeOutTime = TimeSpan.FromSeconds(0.25f), Loop = true, }; foreach (var name in _sequence) { _animationQueue.EnqueueClip(new AnimationQueue.ClipPlaybackParameters { Clip = content.Load<Clip>("Models/ZoeAnimations/" + name), FadeInTime = TimeSpan.FromSeconds(0.1f), FadeOutTime = TimeSpan.FromSeconds(0.0f), Loop = false, }); } var camera = new Camera { NearClip = 1, FarClip = 7000, View = Matrix.CreateLookAt(new Vector3(100, 50, -200), new Vector3(0, 20, 0), Vector3.Up) }; camera.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), 16f / 9f, camera.NearClip, camera.FarClip); var cameraDesc = kernel.Get<EntityDescription>(); cameraDesc.AddProperty(new TypedName<Camera>("camera")); cameraDesc.AddProperty(new TypedName<Viewport>("viewport")); cameraDesc.AddBehaviour<View>(); var cameraEntity = cameraDesc.Create(); cameraEntity.GetProperty(new TypedName<Camera>("camera")).Value = camera; cameraEntity.GetProperty(new TypedName<Viewport>("viewport")).Value = new Viewport() { Width = device.PresentationParameters.BackBufferWidth, Height = device.PresentationParameters.BackBufferHeight }; _scene.Add(cameraEntity); var ambientLight = kernel.Get<EntityDescription>(); ambientLight.AddProperty(new TypedName<Vector3>("sky_colour"), new Vector3(0.44f, 0.44f, 0.74f)); ambientLight.AddProperty(new TypedName<Vector3>("ground_colour"), new Vector3(0.24f, 0.35f, 0.24f)); ambientLight.AddProperty(new TypedName<Vector3>("up"), Vector3.Up); ambientLight.AddBehaviour<AmbientLight>(); _scene.Add(ambientLight.Create()); var sponza = kernel.Get<EntityDescription>(); sponza.AddProperty(new TypedName<ModelData>("model"), content.Load<ModelData>(@"Sponza")); sponza.AddProperty(new TypedName<Matrix>("transform"), Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(-350, 0, 0)); sponza.AddProperty(new TypedName<bool>("is_static"), true); sponza.AddBehaviour<ModelInstance>(); _scene.Add(sponza.Create()); var spotLight = kernel.Get<EntityDescription>(); spotLight.AddProperty(new TypedName<Vector3>("position"), new Vector3(150, 50, -50)); spotLight.AddProperty(new TypedName<Vector3>("colour"), new Vector3(1)); spotLight.AddProperty(new TypedName<Vector3>("direction"), new Vector3(-1, 0, 0.25f)); spotLight.AddProperty(new TypedName<float>("angle"), MathHelper.PiOver2); spotLight.AddProperty(new TypedName<float>("range"), 1000); spotLight.AddProperty(new TypedName<int>("shadow_resolution"), 1024); spotLight.AddBehaviour<SpotLight>(); var spotLightEntity = spotLight.Create(); _scene.Add(spotLightEntity); _scene.GetService<Renderer>().StartPlan() .Then<GeometryBufferComponent>() .Then<EdgeDetectComponent>() .Then<Ssao>() .Then<LightingComponent>() .Then<TranslucentComponent>() .Then<ToneMapComponent>() .Then<AntiAliasComponent>() .Apply(); }
public TestScene(IKernel kernel, Game game, ContentManager content, GraphicsDevice device) { scene = new Scene(kernel); this.game = game; sb = new SpriteBatch(device); basic = content.Load<Effect>("Basic"); cameraPosition = new Vector3(100, 50, 0); camera = new Camera(); camera.NearClip = 1; camera.FarClip = 700; camera.View = Matrix.CreateLookAt(cameraPosition, new Vector3(0, 50, 0), Vector3.Up); camera.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), 16f / 9f, camera.NearClip, camera.FarClip); var cameraDesc = kernel.Get<EntityDescription>(); cameraDesc.AddProperty<Camera>("camera"); cameraDesc.AddProperty<Viewport>("viewport"); cameraDesc.AddBehaviour<View>(); var cameraEntity = cameraDesc.Create(); cameraEntity.GetProperty<Camera>("camera").Value = camera; cameraEntity.GetProperty<Viewport>("viewport").Value = new Viewport() { Width = device.PresentationParameters.BackBufferWidth, Height = device.PresentationParameters.BackBufferHeight }; scene.Add(cameraEntity); var skyboxDesc = kernel.Get<EntityDescription>(); skyboxDesc.AddBehaviour<Skybox>(); var skybox = skyboxDesc.Create(); skybox.GetProperty<TextureCube>("texture").Value= content.Load<TextureCube>("StormCubeMap"); skybox.GetProperty<float>("brightness").Value = 0.5f; skybox.GetProperty<bool>("gamma_correct").Value = false; scene.Add(skybox); //var sunEntity = kernel.Get<EntityDescription>(); //sunEntity.AddProperty<Vector3>("direction", Vector3.Normalize(new Vector3(-.2f, -1f, .3f))); //sunEntity.AddProperty<Vector3>("colour", new Vector3(5f)); //sunEntity.AddProperty<int>("shadow_resolution", 4096); //sunEntity.AddBehaviour<SunLight>(); //sun = sunEntity.Create(); //scene.Add(sun); //var sun2 = sunEntity.Create(); //sun2.GetProperty<Vector3>("direction").Value = Vector3.Normalize(new Vector3(1, -1, 0)); //sun2.GetProperty<Vector3>("colour").Value = new Vector3(1, 0, 0); //scene.Add(sun2); var pointLight = kernel.Get<EntityDescription>(); pointLight.AddProperty<Vector3>("position"); pointLight.AddProperty<Vector3>("colour"); pointLight.AddProperty<float>("range"); pointLight.AddBehaviour<PointLight>(); //scene.Add(pointLight.Create()); lights = new List<PointLight>(); var rng = new Random(); for (int i = 0; i < 0; i++) { var entity = pointLight.Create(); scene.Add(entity); entity.GetProperty<Vector3>("position").Value = new Vector3(0, 10, 0); entity.GetProperty<Vector3>("colour").Value = new Vector3(0, 5, 0); entity.GetProperty<float>("range").Value = 200; var light = entity.GetBehaviour<PointLight>(); light.Colour = Vector3.Normalize(new Vector3(0.1f + (float)rng.NextDouble(), 0.1f + (float)rng.NextDouble(), 0.1f + (float)rng.NextDouble())) * 10; lights.Add(light); } var spotLight = kernel.Get<EntityDescription>(); spotLight.AddProperty<Vector3>("position"); spotLight.AddProperty<Vector3>("colour"); spotLight.AddProperty<Vector3>("direction"); spotLight.AddProperty<float>("angle"); spotLight.AddProperty<float>("range"); spotLight.AddProperty<Texture2D>("mask"); spotLight.AddProperty<int>("shadow_resolution"); spotLight.AddBehaviour<SpotLight>(); var spotLightEntity = spotLight.Create(); spotLightEntity.GetProperty<Vector3>("position").Value = new Vector3(-180, 250, 0); spotLightEntity.GetProperty<Vector3>("colour").Value = new Vector3(10); spotLightEntity.GetProperty<Vector3>("direction").Value = new Vector3(0, -1, 0); spotLightEntity.GetProperty<float>("angle").Value = MathHelper.PiOver2; spotLightEntity.GetProperty<float>("range").Value = 500; spotLightEntity.GetProperty<Texture2D>("mask").Value = null; //content.Load<Texture2D>("Chrysanthemum")); spotLightEntity.GetProperty<int>("shadow_resolution").Value = 512; //content.Load<Texture2D>("Chrysanthemum")); this.spotLight = spotLightEntity.GetBehaviour<SpotLight>(); scene.Add(spotLightEntity); var ambientLight = kernel.Get<EntityDescription>(); ambientLight.AddProperty<Vector3>("sky_colour"); ambientLight.AddProperty<Vector3>("ground_colour"); ambientLight.AddProperty<Vector3>("up"); ambientLight.AddBehaviour<AmbientLight>(); var ambientLightEntity = ambientLight.Create(); ambientLightEntity.GetProperty<Vector3>("sky_colour").Value = new Vector3(0.04f); ambientLightEntity.GetProperty<Vector3>("ground_colour").Value = new Vector3(0.04f, 0.05f, 0.04f); ambientLightEntity.GetProperty<Vector3>("up").Value = Vector3.Up; scene.Add(ambientLightEntity); //var floor = content.Load<ModelData>(@"Models\Ground"); //var floorEntity = kernel.Get<EntityDescription>(); //floorEntity.AddProperty<ModelData>("model", floor); //floorEntity.AddProperty<Matrix>("transform", Matrix.CreateScale(2)); //floorEntity.AddProperty<bool>("isstatic", true); //floorEntity.AddBehaviour<ModelInstance>(); //scene.Add(floorEntity.Create()); var lizardModel = content.Load<ModelData>(@"Models\lizard"); var lizard = kernel.Get<EntityDescription>(); lizard.AddProperty<ModelData>("model"); lizard.AddProperty<Matrix>("transform"); lizard.AddProperty<bool>("is_static"); var lizardEntity = lizard.Create(); lizardEntity.GetProperty<ModelData>("model").Value = lizardModel; lizardEntity.GetProperty<Matrix>("transform").Value = Matrix.CreateScale(50 / 700f) * Matrix.CreateTranslation(150, 0, 0); lizardEntity.GetProperty<bool>("is_static").Value = true; lizard.AddBehaviour<ModelInstance>(); scene.Add(lizardEntity); //var ship1 = content.Load<ModelData>(@"Models\Ship1"); //var ship1Entity = kernel.Get<EntityDescription>(); //ship1Entity.AddProperty<ModelData>("model", ship1); //ship1Entity.AddProperty<Matrix>("transform", Matrix.CreateTranslation(30, 0, 0)); //ship1Entity.AddProperty<bool>("is_static", true); //ship1Entity.AddBehaviour<ModelInstance>(); //scene.Add(ship1Entity.Create()); var hebeModel = content.Load<ModelData>(@"Models\Hebe2"); var hebe = kernel.Get<EntityDescription>(); hebe.AddProperty<ModelData>("model"); hebe.AddProperty<Matrix>("transform"); hebe.AddProperty<bool>("is_static"); hebe.AddBehaviour<ModelInstance>(); var hebeEntity = hebe.Create(); hebeEntity.GetProperty<ModelData>("model").Value = hebeModel; hebeEntity.GetProperty<Matrix>("transform").Value = Matrix.CreateScale(25 / hebeModel.Meshes[0].BoundingSphere.Radius) * Matrix.CreateRotationY(MathHelper.PiOver2) * Matrix.CreateTranslation(-150, 20, 0); hebeEntity.GetProperty<bool>("is_static").Value = true; scene.Add(hebeEntity); var lightBlocker = hebe.Create(); hebeTransform = lightBlocker.GetProperty<Matrix>("transform"); lightBlocker.GetProperty<ModelData>("model").Value = hebeModel; lightBlocker.GetProperty<Matrix>("transform").Value = Matrix.CreateScale(25 / hebeModel.Meshes[0].BoundingSphere.Radius) * Matrix.CreateRotationY(MathHelper.PiOver2) * Matrix.CreateTranslation(-150, 20, 0); lightBlocker.GetProperty<bool>("is_static").Value = true; scene.Add(lightBlocker); var sponzaModel = content.Load<ModelData>(@"Sponza"); var sponza = kernel.Get<EntityDescription>(); sponza.AddProperty<ModelData>("model"); sponza.AddProperty<Matrix>("transform"); sponza.AddProperty<bool>("is_static"); sponza.AddBehaviour<ModelInstance>(); var sponzaEntity = sponza.Create(); sponzaEntity.GetProperty<ModelData>("model").Value = sponzaModel; sponzaEntity.GetProperty<Matrix>("transform").Value = Matrix.Identity * Matrix.CreateScale(1); sponzaEntity.GetProperty<bool>("is_static").Value = true; scene.Add(sponzaEntity); var renderer = scene.GetService<Renderer>(); resolution = renderer.Data.Get<Vector2>("resolution"); var console = kernel.Get<CommandConsole>(); renderer.Settings.BindCommandEngine(console.Engine); //var fire1 = Fire.Create(kernel, content, new Vector3(123.5f, 30f, -55f)); //var fire2 = Fire.Create(kernel, content, new Vector3(123.5f, 30f, 35f)); //var fire3 = Fire.Create(kernel, content, new Vector3(-157f, 30f, 35f)); //var fire4 = Fire.Create(kernel, content, new Vector3(-157f, 30f, -55f)); //scene.Add(fire1); //scene.Add(fire2); //scene.Add(fire3); //scene.Add(fire4); cameraScript = new CameraScript(camera); cameraScript.AddWaypoint(0, new Vector3(218, 160, 104), new Vector3(0, 150, 0)); cameraScript.AddWaypoint(10, new Vector3(-195, 160, 104), new Vector3(-150, 150, 0)); cameraScript.AddWaypoint(12, new Vector3(-270, 160, 96), new Vector3(-150, 150, 0)); cameraScript.AddWaypoint(14, new Vector3(-302, 160, 45), new Vector3(-150, 150, 0)); cameraScript.AddWaypoint(16, new Vector3(-286, 160, 22), new Vector3(-150, 150, 0)); cameraScript.AddWaypoint(18, new Vector3(-276, 160, 22), new Vector3(-150, 100, 0)); cameraScript.AddWaypoint(20, new Vector3(-158, 42, 19), new Vector3(-150, 40, 0)); cameraScript.AddWaypoint(21, new Vector3(-105, 24, -7), new Vector3(-150, 40, 0)); cameraScript.AddWaypoint(23, new Vector3(-105, 44, -7), new Vector3(-150, 40, 0)); cameraScript.AddWaypoint(27, new Vector3(-105, 50, -7), new Vector3(-80, 50, -100)); cameraScript.AddWaypoint(32, new Vector3(100, 50, -7), new Vector3(150, 40, 0)); cameraScript.AddWaypoint(34, new Vector3(100, 50, -7), new Vector3(150, 40, 100)); cameraScript.AddWaypoint(36, new Vector3(100, 50, -7), new Vector3(0, 60, 0)); //cameraScript.AddWaypoint(1000, new Vector3(100, 50, -7), new Vector3(0, 60, 0)); cameraScript.Initialise(); }
public CameraScript(Camera camera) { _camera = camera; _positionCurve = new Curve3D(); _lookatCurve = new Curve3D(); }