コード例 #1
0
 private Vector2 GetTextureCoord(ObjLoader.Loader.Data.VertexData.Texture texture)
 {
     return(new Vector2(texture.X, texture.Y));
 }
コード例 #2
0
 protected Vector2 toVector(ObjLoader.Loader.Data.VertexData.Texture v)
 {
     return(new Vector2(v.X, v.Y));
 }
コード例 #3
0
 private static Vector2 ConvertTexCoord(ObjLoader.Loader.Data.VertexData.Texture tex)
 {
     return(new Vector2(tex.X, tex.Y));
 }
コード例 #4
0
        protected void TriangleMeshAdapater(LoadResult objmesh)
        {
            HashSet <string> uniqPairs = new HashSet <string> ();
            List <Face>      newFaces  = new List <Face> ();

            foreach (Face face in objmesh.Groups[0].Faces)
            {
                // Create vertex/tex pairs list
                for (int i = 0; i < face.Count; i++)
                {
                    FaceVertex fv       = face [i];
                    string     pairName = string.Format("{0}/{1}", fv.VertexIndex, fv.TextureIndex < 0 ? 0 : fv.TextureIndex);
                    uniqPairs.Add(pairName);
                }
                // Split quads into triangles
                if (face.Count == 4)                     // a quad
                //throw new NotImplementedException ("Face needs to be triangulated!");
                {
                    Face glface = new Face();
                    glface.AddVertex(new FaceVertex(face [0].VertexIndex, face [0].TextureIndex, face [0].NormalIndex));
                    glface.AddVertex(new FaceVertex(face [2].VertexIndex, face [2].TextureIndex, face [2].NormalIndex));
                    glface.AddVertex(new FaceVertex(face [3].VertexIndex, face [3].TextureIndex, face [3].NormalIndex));
                    // Added the following in Face.cs
                    //public void RemoveVertexAt (int index) { _vertices.RemoveAt (index); }
                    face.RemoveVertexAt(3);
                    newFaces.Add(glface);
                }
                else if (face.Count > 4)
                {
                    throw new NotImplementedException("Face needs to be triangulated!");
                }
            }
            ((List <Face>)(objmesh.Groups [0].Faces)).AddRange(newFaces);

            // Build OpenGL vertex / tex arrrays
            int nbPairs = uniqPairs.Count;

            string [] pairs = new string [nbPairs];
            uniqPairs.CopyTo(pairs);
            Points    = new Point3DCollection(nbPairs);
            TexCoords = new PointCollection(nbPairs);
            foreach (string pairName in pairs)
            {
                string [] def = pairName.Split('/');
                ObjLoader.Loader.Data.VertexData.Vertex vertex = objmesh.Vertices [Convert.ToInt32(def [0]) - 1];
                Points.Add(new Point3D(vertex.X, vertex.Y, vertex.Z));
                ObjLoader.Loader.Data.VertexData.Texture t = objmesh.Textures [Convert.ToInt32(def [1]) == 0 ? 0 : Convert.ToInt32(def [1]) - 1];
                TexCoords.Add(new System.Windows.Point(t.X, 1.0 - t.Y));
                //System.Diagnostics.Debug.Print ("{0}\t- {1},\t{2},\t{3}\t- {4}\t{5}", Points.Count, vertex.X, vertex.Y, vertex.Z, t.X, t.Y) ;
            }
            //System.Diagnostics.Debug.Print (" ") ;

            Normals = new Vector3DCollection();
            Indices = new Int32Collection();
            foreach (Face face in objmesh.Groups[0].Faces)
            {
                for (int i = 0; i < face.Count; i++)
                {
                    FaceVertex fv       = face [i];
                    string     pairName = string.Format("{0}/{1}", fv.VertexIndex, fv.TextureIndex < 0 ? 0 : fv.TextureIndex);
                    int        index    = Array.IndexOf(pairs, pairName);
                    Indices.Add(index);
                    //System.Diagnostics.Debug.Print ("{0}\t/{1}\t= {2}", i, pairName, index) ;
                }
            }
        }