示例#1
0
        private void OnRenderStarted()
        {
            VisualTreeviewer.GameWindow = scene.Window;
            SystemsView.GameWindow      = scene.Window;

            var manager = context.GetEntityManager();

            //
            items.Add(new LoadedItem(this, CameraGameObject.Create(context)));
            items.Add(new LoadedItem(this, LightGameObject.CreateAmbientLight(manager)));
            items.Add(new LoadedItem(this, LightGameObject.CreatePointLight(manager, Vector3.Zero + Vector3.UnitZ * 1000)));
            items.Add(new LoadedItem(this, LightGameObject.CreateDirectionLight(manager, new Vector3(1, 4, 4).Normalized())));
        }
示例#2
0
        public void LoadGameObject(IFileGeometry3D geo, FileInfo texture, string fileName)
        {
            var em = context.GetEntityManager();

            var box    = AxisAlignedBox.CreateFrom(geo.Positions);
            var center = box.Center;

            var c = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#B3B598");

            GraphicEntity en;

            if (geo.TextureCoors.Any())
            {
                en = EntityBuilders.BuildTextured(context, geo.Positions, geo.Indices,
                                                  geo.TextureCoors.ToArray(), texture,
                                                  SharpDX.Direct3D11.CullMode.None);
            }
            else
            {
                en = EntityBuilders.BuildColored(context, geo.Positions, geo.Indices, geo.Normals,
                                                 ToVector4(c), SharpDX.Direct3D11.CullMode.Front);
                en.UpdateComponent(FlatShadingGeometryComponent.Create());
            }
            en.UpdateComponent(TransformComponent.Create(Matrix4x4.CreateTranslation(Vector3.Zero - center)));
            GameObjects.Add(new SingleVisualObject(en.Tag, fileName));

            //var boxlines = PolylineGameObject.Create(
            //    Context,
            //    new ElementTag("poly"),
            //    GeometryBuilder.BuildBox(
            //        new AxisAlignedBox(box.Minimum, box.Maximum)),
            //    V4Colors.Blue
            //    );

            //Context.GetEntityManager().GetEntity(boxlines.Tag)
            //    .UpdateComponent(TransformComponent.Create(Matrix4x4.CreateTranslation(Vector3.Zero - center)));

            //GameObjects.Add(boxlines);
        }
示例#3
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo {
                X                  = 50,
                Y                  = 50,
                WindowWidth        = 960,
                WindowHeight       = 540,
                WindowInitialState = WindowState.Normal,
                WindowTitle        = "Veldrid NeoDemo"
            };

            Sdl2Window w = VeldridStartup.CreateWindow(windowCI);

            window = new Sdl2WindowWrapper(w);

            var context = new ContextStateProcessor(new EngineNotificator());

            context.AddState(0, x => new GenneralContextState(x));
            context.SwitchTo(0);

            var game = new Game(window, context);

            //====

            D3DShaderInfo[] shaders =
            {
                new D3DShaderInfo {
                    Path  = Path.Combine(AppContext.BaseDirectory, "Shaders", "Cube"),
                    Stage = ShaderStages.Vertex.ToString(), EntryPoint = "VS"
                },
                new D3DShaderInfo {
                    Path  = Path.Combine(AppContext.BaseDirectory, "Shaders", "Cube"),
                    Stage = ShaderStages.Fragment.ToString(), EntryPoint = "FS"
                }
            };

            var mb = new Helpers.MeshBulder();

            var camera = context.GetEntityManager()
                         .CreateEntity(new ElementTag(Guid.NewGuid().ToString()))
                         .AddComponent(new CameraBuilder.CameraComponent(window.Width, window.Height));
            // .AddComponent(new CameraBuilder.GraphicsComponent());

            var mage = Image.Load(Path.Combine(AppContext.BaseDirectory, "Textures", "spnza_bricks_a_diff.png"));

            var image = new TextureInfo()
            {
                Path = Path.Combine(AppContext.BaseDirectory, "Textures", "spnza_bricks_a_diff.png"),
                ///Image = Image.Load(Path.Combine(AppContext.BaseDirectory, "Textures", "spnza_bricks_a_diff.png"))
            };

            var box = GetCubeVertice();

            box = mb.BuildBox(Vector3.Zero, 1, 1, 1);

            var geo = context.GetEntityManager()
                      .CreateEntity(new ElementTag(Guid.NewGuid().ToString()))
                      .AddComponent(new TexturedGeometryGraphicsComponent(shaders, box, image)
            {
                Matrix = Matrix4x4.CreateTranslation(Vector3.UnitX * 1)
            });

            var geo1 = context.GetEntityManager()
                       .CreateEntity(new ElementTag(Guid.NewGuid().ToString()))
                       .AddComponent(new TexturedGeometryGraphicsComponent(shaders, mb.BuildSphere(Vector3.Zero, 1), image)
            {
                Matrix = Matrix4x4.CreateTranslation(Vector3.UnitY * -1)
            });

            context.GetSystemManager()
            .CreateSystem <VeldridRenderSystem>()
            .Init(game.gd, game.factory, window);

            context.EntityOrder
            .RegisterOrder <VeldridRenderSystem>(camera.Tag, 0)
            .RegisterOrder <VeldridRenderSystem>(geo.Tag, 1)
            .RegisterOrder <VeldridRenderSystem>(geo1.Tag, 2);

            //====


            game.Run(new EngineNotificator());
        }