コード例 #1
0
 public Face(ObjLoader.Loader.Data.VertexData.Vertex a,
             ObjLoader.Loader.Data.VertexData.Vertex b,
             ObjLoader.Loader.Data.VertexData.Vertex c)
 {
     this.a = new Vector4(a.X, a.Y, a.Z, 0);
     this.b = new Vector4(b.X, b.Y, b.Z, 0);
     this.c = new Vector4(c.X, c.Y, c.Z, 0);
 }
コード例 #2
0
        public static void ScaleObject(
            ref LoadResult obj,
            float scale)
        {
            for (int i = 0; i < obj.Vertices.Count; i++)
            {
                var vertex = new ObjLoader.Loader.Data.VertexData.Vertex(
                    (obj.Vertices [i].X) * scale,
                    (obj.Vertices [i].Y) * scale,
                    (obj.Vertices [i].Z) * scale);

                obj.Vertices [i] = vertex;
            }
        }
コード例 #3
0
		public static float UnitizeObject(ref LoadResult obj)
		{
			float xMax, xMin, yMax, yMin, zMax, zMin;
			float cx, cy, cz, w, h, d;
			float scale;

			xMax = obj.Vertices [0].X;
			xMin = obj.Vertices [0].X;
			yMax = obj.Vertices [0].Y;
			yMin = obj.Vertices [0].Y;
			zMax = obj.Vertices [0].Z;
			zMin = obj.Vertices [0].Z;

			for (int i = 1; i < obj.Vertices.Count; i++) 
			{
				if (xMax < obj.Vertices [i].X)
					xMax = obj.Vertices [i].X;
				if (xMin > obj.Vertices [i].X)
					xMin = obj.Vertices [i].X;

				if (yMax < obj.Vertices [i].Y)
					yMax = obj.Vertices [i].Y;
				if (yMin > obj.Vertices [i].Y)
					yMin = obj.Vertices [i].Y;

				if (zMax < obj.Vertices [i].Z)
					zMax = obj.Vertices [i].Z;
				if (zMin > obj.Vertices [i].Z)
					zMin = obj.Vertices [i].Z;
			}

			/* calculate model width, height, and depth */
			w = Math.Abs (xMax) + Math.Abs (xMin);
			h = Math.Abs (yMax) + Math.Abs (yMin);
			d = Math.Abs (zMax) + Math.Abs (zMin);

			/* calculate center of the model */
			cx = (xMax + xMin) / 2.0f;
			cy = (yMax + yMin) / 2.0f;
			cz = (zMax + zMin) / 2.0f;

			scale = 2.0f / Math.Max (Math.Max (w, h), d);

			/* translate around center then scale */
			for (int i = 0; i < obj.Vertices.Count; i++) 
			{
				var vertex = new ObjLoader.Loader.Data.VertexData.Vertex (
					(obj.Vertices [i].X - cx) * scale,
					(obj.Vertices [i].Y - cy) * scale,
					(obj.Vertices [i].Z - cz) * scale);

				obj.Vertices [i] = vertex;
			}

			return scale;
		}
コード例 #4
0
		public static void ScaleObject(
			ref LoadResult obj, 
			float scale)
		{
			for (int i = 0; i < obj.Vertices.Count; i++) 
			{
				var vertex = new ObjLoader.Loader.Data.VertexData.Vertex (
					(obj.Vertices [i].X) * scale,
					(obj.Vertices [i].Y) * scale,
					(obj.Vertices [i].Z) * scale);

				obj.Vertices [i] = vertex;
			}
		}
コード例 #5
0
 private Vector4 GetPosition(ObjLoader.Loader.Data.VertexData.Vertex vertex)
 {
     return(new Vector4(vertex.X, vertex.Y, vertex.Z, 1.0f));
 }
コード例 #6
0
 private static Vector3 ConvertVert(ObjLoader.Loader.Data.VertexData.Vertex vertex)
 {
     return(new Vector3(vertex.X, vertex.Y, vertex.Z));
 }
コード例 #7
0
        public static float UnitizeObject(ref LoadResult obj)
        {
            float xMax, xMin, yMax, yMin, zMax, zMin;
            float cx, cy, cz, w, h, d;
            float scale;

            xMax = obj.Vertices [0].X;
            xMin = obj.Vertices [0].X;
            yMax = obj.Vertices [0].Y;
            yMin = obj.Vertices [0].Y;
            zMax = obj.Vertices [0].Z;
            zMin = obj.Vertices [0].Z;

            for (int i = 1; i < obj.Vertices.Count; i++)
            {
                if (xMax < obj.Vertices [i].X)
                {
                    xMax = obj.Vertices [i].X;
                }
                if (xMin > obj.Vertices [i].X)
                {
                    xMin = obj.Vertices [i].X;
                }

                if (yMax < obj.Vertices [i].Y)
                {
                    yMax = obj.Vertices [i].Y;
                }
                if (yMin > obj.Vertices [i].Y)
                {
                    yMin = obj.Vertices [i].Y;
                }

                if (zMax < obj.Vertices [i].Z)
                {
                    zMax = obj.Vertices [i].Z;
                }
                if (zMin > obj.Vertices [i].Z)
                {
                    zMin = obj.Vertices [i].Z;
                }
            }

            /* calculate model width, height, and depth */
            w = Math.Abs(xMax) + Math.Abs(xMin);
            h = Math.Abs(yMax) + Math.Abs(yMin);
            d = Math.Abs(zMax) + Math.Abs(zMin);

            /* calculate center of the model */
            cx = (xMax + xMin) / 2.0f;
            cy = (yMax + yMin) / 2.0f;
            cz = (zMax + zMin) / 2.0f;

            scale = 2.0f / Math.Max(Math.Max(w, h), d);

            /* translate around center then scale */
            for (int i = 0; i < obj.Vertices.Count; i++)
            {
                var vertex = new ObjLoader.Loader.Data.VertexData.Vertex(
                    (obj.Vertices [i].X - cx) * scale,
                    (obj.Vertices [i].Y - cy) * scale,
                    (obj.Vertices [i].Z - cz) * scale);

                obj.Vertices [i] = vertex;
            }

            return(scale);
        }
コード例 #8
0
 public V3(ObjLoader.Loader.Data.VertexData.Vertex v)
 {
     x = v.X; y = v.Y; z = v.Z;
 }
コード例 #9
0
 protected Vector3 toVector(ObjLoader.Loader.Data.VertexData.Vertex v)
 {
     return(new Vector3(v.X, v.Y, v.Z));
 }
コード例 #10
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) ;
                }
            }
        }