Beispiel #1
0
        public override void ReadData(Scene scene, BinaryReader stream)
        {
            //	Note: A max face is three indices and
            //	a flag short.

            //	Read number of faces.
            short faceCount = 0;

            faceCount = stream.ReadInt16();

            //	Read each face and add it.
            for (short i = 0; i < faceCount; i++)
            {
                Face  f     = new Face();
                Index index = new Index(stream.ReadInt16());
                f.Indices.Add(index);
                index = new Index(stream.ReadInt16());
                f.Indices.Add(index);
                index = new Index(stream.ReadInt16());
                f.Indices.Add(index);
                stream.ReadInt16();
                faces.Add(f);
            }
        }
Beispiel #2
0
        public override void ReadData(Scene scene, BinaryReader stream)
        {
            //	Note: A max face is three indices and
            //	a flag short.

            //	Read number of faces.
            short faceCount = 0;
            faceCount = stream.ReadInt16();

            //	Read each face and add it.
            for(short i = 0; i < faceCount; i++)
            {
                Face f = new Face();
                Index index = new Index(stream.ReadInt16());
                f.Indices.Add(index);
                index = new Index(stream.ReadInt16());
                f.Indices.Add(index);
                index = new Index(stream.ReadInt16());
                f.Indices.Add(index);
                stream.ReadInt16();
                faces.Add(f);
            }
        }
Beispiel #3
0
 //	Constructors.
 public Index(Index index) { vertex = index.vertex; uv = index.uv; }
Beispiel #4
0
        /// <summary>
        /// This function subdivides the faces of this polygon.
        /// </summary>
        /// <param name="smooth">If set to true the faces will be smoothed.</param>
        /// <returns>The number of faces in the new subdivided polygon.</returns>
        public int Subdivide()
        {
            FaceCollection newFaces = new FaceCollection();

            foreach(Face face in Faces)
            {
                //	Make sure the face is a triangle.
                if(face.Count != 3)
                    continue;

                //	Now get the vertices of the face.
                Vertex v1 = Vertices[face.Indices[0].Vertex];
                Vertex v2 = Vertices[face.Indices[1].Vertex];
                Vertex v3 = Vertices[face.Indices[2].Vertex];

                //	Add the vertices to get a the midpoint of the edge formed by those
                //	vectors.
                Vertex vMidpoint = (v1 + v2 + v3) / 3;
                Index iMidpoint = new Index(Vertices.Add(vMidpoint));

                //	Now make three new faces from the old vertices and the midpoint.
                Face newFace = new Face();
                newFace.Indices.Add(new Index(face.Indices[0]));
                newFace.Indices.Add(new Index(face.Indices[1]));
                newFace.Indices.Add(iMidpoint);
                newFaces.Add(newFace);

                newFace = new Face();
                newFace.Indices.Add(new Index(face.Indices[1]));
                newFace.Indices.Add(new Index(face.Indices[2]));
                newFace.Indices.Add(iMidpoint);
                newFaces.Add(newFace);

                newFace = new Face();
                newFace.Indices.Add(new Index(face.Indices[2]));
                newFace.Indices.Add(new Index(face.Indices[0]));
                newFace.Indices.Add(iMidpoint);
                newFaces.Add(newFace);
            }

            faces = newFaces;

            return faces.Count;
        }