Exemple #1
0
        static void Main()
        {
            var renderer = new Renderer();
            var game     = new Game(renderer);

            var vertShaderString = File.ReadAllText("Assets/Shaders/basic.vert");
            var fragShaderString = File.ReadAllText("Assets/Shaders/basic.frag");

            RawModel model;

            using (var reader = new StreamReader("Assets/Models/dragon.obj"))
            {
                model = new RawModel(ObjParser.LoadModel(reader));
            }

            var textureData = new ImageSharpTexture("Assets/Textures/white.png");
            var shaderSet   = new ShaderSet(vertShaderString, fragShaderString);

            renderer.Initialize(true);

            var mesh   = renderer.CreateMesh(model, textureData, shaderSet);
            var entity = new RenderableEntity(new Transform(new Vector3(0, -5, -10), new Vector3(), 1), mesh);

            entity.InitializeMesh(renderer);

            game.AddEntity(entity);
            game.AddEntity(new CameraController());

            game.RunMainLoop();
            renderer.DisposeGraphicsDevices();
        }
        public void Cube_NormalsInATriangleAreTheSame()
        {
            var model = ObjParser.LoadModel(new StringReader(cubeData));

            for (int i = 0; i < model.Indexes.Length; i += 3)
            {
                var normals = model.Normals;
                var indexes = model.Indexes;
                Assert.Equal(normals[indexes[i]], normals[indexes[i + 1]]); // First and second normal in a triangle should be the same.
                Assert.Equal(normals[indexes[i]], normals[indexes[i + 2]]); // First and second normal in a triangle should be the same.
            }
        }
        public void Quad_IndexesAreLoaded()
        {
            var expectedIndexes = new int[]
            {
                0, 1, 2,
                0, 3, 1
            };

            var model = ObjParser.LoadModel(new StringReader(quadData));

            Assert.Equal(expectedIndexes, model.Indexes);
        }
        public void Quad_NormalsAreLoadedAndOrdered()
        {
            var expectedNormals = new Vector3[]
            {
                new Vector3(0, 1, 0),
                new Vector3(0, 1, 0),
                new Vector3(0, 1, 0),
                new Vector3(0, 1, 0)
            };

            var model = ObjParser.LoadModel(new StringReader(quadData));

            Assert.Equal(expectedNormals, model.Normals);
        }
        public void Quad_TextureCoordsAreLoadedAndOrdered()
        {
            var expectedTextureCoords = new Vector2[]
            {
                new Vector2(1, 0),
                new Vector2(0, 1),
                new Vector2(0, 0),
                new Vector2(1, 1)
            };

            var model = ObjParser.LoadModel(new StringReader(quadData));

            Assert.Equal(expectedTextureCoords, model.TextureCoords);
        }
        public void Quad_VerticesAreLoaded()
        {
            var expectedVertices = new Vector3[]
            {
                new Vector3(1, 0, 1),
                new Vector3(-1, 0, -1),
                new Vector3(-1, 0, 1),
                new Vector3(1, 0, -1)
            };

            var model = ObjParser.LoadModel(new StringReader(quadData));

            Assert.Equal(expectedVertices, model.Vertices);
        }
        public void ModelNameIsLoaded()
        {
            var model = ObjParser.LoadModel(new StringReader(quadData));

            Assert.Equal("Quad_Plane", model.Name);
        }