Beispiel #1
0
        public Texture(Stream file_t, string filename)
        {
            if (file_t == null)
            {
                throw new ArgumentNullException(nameof(file_t));
            }
            if (string.IsNullOrEmpty(filename))
            {
                throw new ArgumentNullException(nameof(filename));
            }
            this.Path = filename;
            this.Data = IResourceExtentions.GetStreamData(file_t);
            using (file_t)
            {
                this.Acquire();
                if (TextureObject < 1)
                {
                    throw new GLInstanceNotCreated();
                }
                GL.BindTexture(TextureTarget.Texture2D, TextureObject);

                BaseBitmap bmp = new BaseBitmap(file_t);
                bmp.RotateY();
                Widith = bmp.Width;
                Height = bmp.Height;
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp.Width, bmp.Height, 0, OpenTK.Graphics.OpenGL4.PixelFormat.Rgba, PixelType.UnsignedByte, bmp.ColorMap);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

                GL.BindTexture(TextureTarget.Texture2D, 0);
            }
        }
Beispiel #2
0
        public void Parse(Stream fobj, Stream fmtl, Resources textures, string textures_handle = "/")
        {
            this.Data = IResourceExtentions.GetStreamData(fobj);

            WtObjectParser objparser = new WtObjectParser();

            objparser.ParseMtl(new StreamReader(fmtl));
            objparser.ParseObj(new StreamReader(fobj));
            objparser.Groups.Sort();
            foreach (WtObjectParser.WtGroup group in objparser.Groups)
            {
                VertexObject nobj = new VertexObject();

                nobj.Material.Defuse   = new Color4(group.Material.Defuse.X, group.Material.Defuse.Y, group.Material.Defuse.Z, group.Material.DefuseAlpha);
                nobj.Material.Ambient  = new Color4(group.Material.Ambient.X, group.Material.Ambient.Y, group.Material.Ambient.Z, group.Material.DefuseAlpha);
                nobj.Material.Specular = new Color4(group.Material.Specular.X, group.Material.Specular.Y, group.Material.Specular.Z, group.Material.DefuseAlpha);
                if (group.Material.MapDefuse != null)
                {
                    nobj.Material.DefuseMap = textures.GetResource <Texture>(textures_handle + group.Material.MapDefuse).TextureObject;
                }
                if (group.Material.MapSpecular != null)
                {
                    nobj.Material.SpecularMap = textures.GetResource <Texture>(textures_handle + group.Material.MapSpecular).TextureObject;
                }
                if (group.Material.MapAmbient != null)
                {
                    nobj.Material.AmbientMap = textures.GetResource <Texture>(textures_handle + group.Material.MapAmbient).TextureObject;
                }

                nobj.Capacity = (group.Faces.Count * 3);

                for (int i = 0; i < group.Faces.Count; i++)
                {
                    Vertex vt = new Vertex();
                    vt.Position      = Vector3(objparser.Vertexes[group.Faces[i].V0]);
                    vt.Normal        = Vector3(objparser.Normals[group.Faces[i].VN0]);
                    vt.TextureCoords = Vector2(objparser.TextureCoords[group.Faces[i].VT0]);
                    nobj.AppendVertex(vt);


                    vt.Position      = Vector3(objparser.Vertexes[group.Faces[i].V1]);
                    vt.Normal        = Vector3(objparser.Normals[group.Faces[i].VN1]);
                    vt.TextureCoords = Vector2(objparser.TextureCoords[group.Faces[i].VT1]);
                    nobj.AppendVertex(vt);


                    vt.Position      = Vector3(objparser.Vertexes[group.Faces[i].V2]);
                    vt.Normal        = Vector3(objparser.Normals[group.Faces[i].VN2]);
                    vt.TextureCoords = Vector2(objparser.TextureCoords[group.Faces[i].VT2]);
                    nobj.AppendVertex(vt);
                }
                nobj.Save();
                this.VertexArrays.Add(nobj);
            }
        }