예제 #1
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);
            }
        }
예제 #2
0
 public SlowRender()
 {
     _vrt = new VertexObject();
     for (int i = 0; i < 4; i++)
     {
         _vrt.AppendVertex(new Vertex());
     }
     _vrt.Save();
     _norml           = new Vector3();
     _curent_material = OpenGL.Material.Defult;
 }
예제 #3
0
        public void DrawTexturedRectangle(Vector3 v, Vector2 tv, Vector3 v1, Vector2 tv1, Vector3 v2, Vector2 tv2, Vector3 v3, Vector2 tv3)
        {
            _vrt.Size = 4;
            for (int i = 0; i < _vrt.Size; i++)
            {
                _vrt.SetNormal(i, _norml);
            }
            _vrt.SetPosition(0, v);
            _vrt.SetPosition(1, v1);
            _vrt.SetPosition(2, v2);
            _vrt.SetPosition(3, v3);
            _vrt.SetTextureCoord(0, tv);
            _vrt.SetTextureCoord(1, tv1);
            _vrt.SetTextureCoord(2, tv2);
            _vrt.SetTextureCoord(3, tv3);
            _vrt.Save();
            _vrt.Material = _curent_material;

            _vrt.Draw(PrimitiveType.TriangleStrip);
        }