Ejemplo n.º 1
0
 public Scene(List <Mesh> meshList, List <Light> lights, Rasterization r, VertexProcessor v)
 {
     foreach (Mesh m in meshList)
     {
         m.MakeNormals();
         foreach (Light l in lights)
         {
             m.Light(l, v);
             m.DrawMesh(r, v, l);
         }
     }
 }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            label8.Text = "Start render...";
            this.Update();
            #region Create collections for rasterize
            Buffer          buff      = new Buffer(1500, 1500, Color.Aqua);
            List <Mesh>     meshList  = new List <Mesh>();
            List <Light>    lightList = new List <Light>();
            Rasterization   render    = new Rasterization(buff);
            VertexProcessor vertex    = new VertexProcessor(getTextBox(), getVector4());
            this.Update();
            var              objLoaderFactory = new ObjLoaderFactory();
            var              objLoader        = objLoaderFactory.Create();
            Vector3          p0    = new Vector3(2f, 5f, 5f);
            DirectionalLight light = new DirectionalLight(p0);
            #endregion


            #region Dodanie obiektów do sceny
            ObjMesh obj = new ObjMesh();

            //Console.WriteLine("OBJ File Name:");
            string nameObj    = textBox10.Text; // Console.ReadLine();
            var    fileStream = new FileStream(nameObj, FileMode.Open);
            var    result     = objLoader.Load(fileStream);
            fileStream.Close();
            //ladowanie pozycji wierzcholkow
            foreach (ObjLoader.Loader.Data.VertexData.Vertex l in result.Vertices)
            {
                Vector3 pos     = new Vector3(l.X, l.Y, l.Z);
                Vertex  newVert = new Vertex(pos);
                obj.vertexes.Add(newVert);
            }

            List <int> indexes = new List <int>();

            foreach (ObjLoader.Loader.Data.Elements.Group n in result.Groups)
            {
                foreach (ObjLoader.Loader.Data.Elements.Face f in n.Faces)
                {
                    for (int i = 0; i < f._vertices.Count; i++)
                    {
                        indexes.Add(f._vertices[i].VertexIndex - 1);
                    }
                }
            }

            lightList.Add(light);
            obj.indexes = indexes;
            meshList.Add(obj);
            Scene scene = new Scene(meshList, lightList, render, vertex);

            #endregion
            pictureBox1.Image = buff.colorBuffer;
            label8.Text       = "Render was end.";

            buff.SaveImage();

            // Console.WriteLine("Rasterization Complete.");
            // Console.ReadKey();
        }