Example #1
0
        public void Init(UStaticMesh mesh, OpenGL gl)
        {
            int i         = 0;
            var materials = mesh.GetMaterials();

            foreach (SMeshFace face in mesh.Faces)
            {
                MeshSurfice s          = new MeshSurfice();
                int         end_offset = face.index_offset + (face.triangle_count * 3);
                for (int j = face.index_offset; j < end_offset; j += 3)
                {
                    s.Vertices.Add(mesh.Verteces[mesh.vertex_indicies_1[j]].Location.ToVertex());
                    s.Vertices.Add(mesh.Verteces[mesh.vertex_indicies_1[j + 1]].Location.ToVertex());
                    s.Vertices.Add(mesh.Verteces[mesh.vertex_indicies_1[j + 2]].Location.ToVertex());
                    s.UVs.Add(mesh.texture_coords[0].elements[mesh.vertex_indicies_1[j]].UV.ToUV());
                    s.UVs.Add(mesh.texture_coords[0].elements[mesh.vertex_indicies_1[j + 1]].UV.ToUV());
                    s.UVs.Add(mesh.texture_coords[0].elements[mesh.vertex_indicies_1[j + 2]].UV.ToUV());
                    s.Normals.Add(mesh.Verteces[mesh.vertex_indicies_1[j]].Normal.ToVertex());
                    s.Normals.Add(mesh.Verteces[mesh.vertex_indicies_1[j + 1]].Normal.ToVertex());
                    s.Normals.Add(mesh.Verteces[mesh.vertex_indicies_1[j + 2]].Normal.ToVertex());
                }
                SceneGraph.Assets.Material mat = new SharpGL.SceneGraph.Assets.Material();
                Texture texture             = new Texture();
                System.Drawing.Bitmap image = LibSquish.GetImage(materials[i].Texture);
                texture.Create(gl, image);
                mat.Texture     = texture;
                s.Material      = mat;
                s.TriangleCount = face.triangle_count;
                Surfices.Add(s);
                i++;
            }
            vertices = Surfices.SelectMany(s => s.Vertices).ToList();
            Console.WriteLine();
        }
Example #2
0
        public Form1()
        {
            InitializeComponent();

            SharpGL.SceneGraph.Assets.Material SunMaterial   = new SharpGL.SceneGraph.Assets.Material();
            SharpGL.SceneGraph.Assets.Material EarthMaterial = new SharpGL.SceneGraph.Assets.Material();
            SharpGL.SceneGraph.Assets.Material MoonMaterial  = new SharpGL.SceneGraph.Assets.Material();

            SharpGL.SceneGraph.Assets.Texture SunTexture   = new SharpGL.SceneGraph.Assets.Texture();
            SharpGL.SceneGraph.Assets.Texture EarthTexture = new SharpGL.SceneGraph.Assets.Texture();
            SharpGL.SceneGraph.Assets.Texture MoonTexture  = new SharpGL.SceneGraph.Assets.Texture();

            OpenGLControl openglCtr = new SharpGL.OpenGLControl();

            SunTexture.Create(openglCtr.OpenGL, "Sun.bmp");

            OpenGLControl openglCtr1 = new SharpGL.OpenGLControl();

            MoonTexture.Create(openglCtr1.OpenGL, "Moon.jpg");

            OpenGLControl openglCtr2 = new SharpGL.OpenGLControl();

            EarthTexture.Create(openglCtr2.OpenGL, "Earth.jpg");

            //// texture1.Create(openglCtr.OpenGL, "Crate.bmp");

            //// material.Texture = texture1;
            SunMaterial.Texture = SunTexture;
            Sun.TextureCoords   = true;

            EarthMaterial.Texture = EarthTexture;
            Earth.TextureCoords   = true;

            MoonMaterial.Texture = MoonTexture;
            Moon.TextureCoords   = true;

            Light light = new Light()
            {
                On       = true,
                Position = new Vertex(0, 0, 0),
                GLCode   = OpenGL.GL_LIGHT1
            };



            sceneControl1.Scene.SceneContainer.AddChild(light);


            //SharpGL.OpenGL gl = this.sceneControl1.OpenGL;
            //texture.Create(gl, "Crate.bmp");
            //texture.Bind(gl);

            //uint[] textureID = new uint[1];
            //byte[] colors = new byte[256 * 256 * 4];
            //gl.BindTexture(OpenGL.GL_TEXTURE_2D, textureID[0]);
            //gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_TEXTURE, 256, 256, 50, OpenGL.GL_TEXTURE, OpenGL.GL_BYTE, colors);

            //// SunMaterial.Diffuse = Color.Orange;
            //EarthMaterial.Diffuse = Color.Cyan;
            //MoonMaterial.Diffuse = Color.Silver;
            ////SunMaterial.Ambient = Color.FromArgb(0, Color.Orange);
            //EarthMaterial.Ambient = Color.FromArgb(255, Color.Blue);
            //MoonMaterial.Ambient = Color.FromArgb(255, Color.Silver);

            SunMaterial.Texture = SunTexture;

            Sun.Material   = SunMaterial;
            Moon.Material  = MoonMaterial;
            Earth.Material = EarthMaterial;

            Earth.Radius = 2;
            Moon.Radius  = 0.5;
            Sun.Radius   = 4;

            sceneControl1.Scene.SceneContainer.AddChild(Earth);
            sceneControl1.Scene.SceneContainer.AddChild(Moon);
            sceneControl1.Scene.SceneContainer.AddChild(Sun);


            sceneControl1.Scene.RenderBoundingVolumes = !sceneControl1.Scene.RenderBoundingVolumes;
        }
 private void DrawCylinder(float diameter, float addendum, Material material, float centerX, float centerY)
 {
     var initVerticesCount = SpurGear.Vertices.Count;
     foreach (var pos in GetPositionsForGear(diameter / 2, 0, 0, 5))
         AddFace(pos.X + centerX, pos.Y + centerY, SpurGear.FaceWidth, SpurGear, addendum, initVerticesCount, material);
 }
Example #4
0
        public Form1()
        {
            InitializeComponent();

            OpenGL gl = sceneControl1.OpenGL;

            SharpGL.SceneGraph.Assets.Material SunMaterial     = new SharpGL.SceneGraph.Assets.Material();
            SharpGL.SceneGraph.Assets.Material EarthMaterial   = new SharpGL.SceneGraph.Assets.Material();
            SharpGL.SceneGraph.Assets.Material MoonMaterial    = new SharpGL.SceneGraph.Assets.Material();
            SharpGL.SceneGraph.Assets.Material MercuryMaterial = new SharpGL.SceneGraph.Assets.Material();

            SharpGL.SceneGraph.Assets.Texture SunTexture     = new SharpGL.SceneGraph.Assets.Texture();
            SharpGL.SceneGraph.Assets.Texture EarthTexture   = new SharpGL.SceneGraph.Assets.Texture();
            SharpGL.SceneGraph.Assets.Texture MoonTexture    = new SharpGL.SceneGraph.Assets.Texture();
            SharpGL.SceneGraph.Assets.Texture MercuryTexture = new SharpGL.SceneGraph.Assets.Texture();

            OpenGLControl openglCtr = new SharpGL.OpenGLControl();

            SunTexture.Create(openglCtr.OpenGL, "Sun.jpg");

            OpenGLControl openglCtr1 = new SharpGL.OpenGLControl();

            MoonTexture.Create(openglCtr1.OpenGL, "Moon.jpg");

            OpenGLControl openglCtr2 = new SharpGL.OpenGLControl();

            EarthTexture.Create(openglCtr2.OpenGL, "Earth.jpg");

            OpenGLControl openglCtr3 = new SharpGL.OpenGLControl();

            MercuryTexture.Create(openglCtr2.OpenGL, "Mercury.jpg");

            SunMaterial.Texture = SunTexture;
            Sun.TextureCoords   = true;

            EarthMaterial.Texture = EarthTexture;
            Earth.TextureCoords   = true;

            MoonMaterial.Texture = MoonTexture;
            Moon.TextureCoords   = true;

            MercuryMaterial.Texture = MoonTexture;
            Mercury.TextureCoords   = true;



            SunMaterial.Texture = SunTexture;

            Sun.Material     = SunMaterial;
            Moon.Material    = MoonMaterial;
            Earth.Material   = EarthMaterial;
            Mercury.Material = MercuryMaterial;

            Earth.Radius   = 2;
            Moon.Radius    = 0.5;
            Sun.Radius     = 4;
            Mercury.Radius = 0.7;

            sceneControl1.Scene.SceneContainer.AddChild(Earth);
            sceneControl1.Scene.SceneContainer.AddChild(Moon);
            sceneControl1.Scene.SceneContainer.AddChild(Sun);
            sceneControl1.Scene.SceneContainer.AddChild(Mercury);


            sceneControl1.Scene.RenderBoundingVolumes = !sceneControl1.Scene.RenderBoundingVolumes;

            Light light = new Light()
            {
                On       = true,
                Position = new Vertex(0, 0, 0),
                GLCode   = OpenGL.GL_LIGHT0
            };

            sceneControl1.Scene.SceneContainer.AddChild(light);
        }