示例#1
0
        VertexLayer vertexLayer; /// 点层

        #endregion Fields

        #region Constructors

        public CloverController()
        {
            faceLayer = new FaceLayer(this);
            edgeLayer = new EdgeLayer(this);
            vertexLayer = new VertexLayer(this);

            //paper = new Paper("paper");
        }
示例#2
0
 /// <summary>
 /// 重新分配顶点的id号
 /// </summary>
 /// <param name="vertexLayer"></param>
 void ReAllocateVertexID(VertexLayer vertexLayer)
 {
     int vertexID = 0;
     foreach (List<Vertex> vertexList in vertexLayer.VertexCellTable)
     {
         foreach (Vertex v in vertexList)
         {
             v.ID = vertexID++;
         }
     }
     Vertex.Vertex_count = vertexID;
 }
示例#3
0
        public int SaveFile(string filename, FaceLayer faceLayer, EdgeLayer edgeLayer, VertexLayer vertexLayer, ShadowSystem shadowSystem)
        {
            FileStream fs = new FileStream(filename, FileMode.Create);
            writer = new BinaryWriter(fs);

            // 魔数,用于表示这个文件是一个Clover文件
            writer.Write(201203100);

            ReAllocateVertexID(vertexLayer);

            SaveVertexLayer(fs, vertexLayer);

            SaveEdgeLayer(fs, edgeLayer);

            SaveFaceLayer(fs, faceLayer);

            SaveShadowSystem(fs, shadowSystem);

            fs.Close();

            return 0;
        }
示例#4
0
        public void LoadFile(string filename)
        {
            fs = new FileStream(filename, FileMode.Open);

            reader = new BinaryReader(fs);

            int magicNumber = reader.ReadInt32();

            vertexIDDict = new Dictionary<int, Vertex>();
            edgeIDDict = new Dictionary<int, Edge>();
            faceIDDict = new Dictionary<int, Face>();

            vertexLayer = new VertexLayer();
            edgeLayer = new EdgeLayer();
            faceLayer = new FaceLayer();
            shadowSystem = new ShadowSystem();

            Clover();

            faceLayer.UpdateLeaves();

            fs.Close();
        }
示例#5
0
        void _VertexLayer()
        {
            if (!ReadHeader("Vertex Layer"))
                return;

            BinaryFormatter bf = new BinaryFormatter();

            vertexLayer = bf.Deserialize(fs) as VertexLayer;

            Debug.Assert(vertexLayer != null);

            int vertex_count = reader.ReadInt32();
            Vertex.Vertex_count = vertex_count;

            foreach (List<Vertex> vList in vertexLayer.VertexCellTable)
            {
                foreach (Vertex v in vList)
                {
                    vertexIDDict[v.ID] = v;
                }
            }
        }
示例#6
0
        public void LoadFile(string filename)
        {
            fileLoader.LoadFromFile(filename);

            // 重置所有的数据结构
            faceLayer = fileLoader.FaceLayer;
            edgeLayer = fileLoader.EdgeLayer;
            vertexLayer = fileLoader.VertexLayer;
            shadowSystem = fileLoader.ShadowSystem;

            renderController.DeleteAll();
            //renderController.RedrawFoldLine();
            foreach (Face face in faceLayer.Leaves)
            {
                renderController.New(face);
            }
        }
示例#7
0
        /// <summary>
        /// 根据给定的长和宽初始化纸张
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public void Initialize(float width, float height)
        {
            Vertex.Vertex_count = 0;
            Face.Face_count = 0;
            Edge.Edge_count = 0;

            faceLayer = new FaceLayer();
            edgeLayer = new EdgeLayer();
            vertexLayer = new VertexLayer();

            // Create 4 original vertices
            Vertex[] vertices = new Vertex[4];
            vertices[0] = new Vertex(-width / 2, height / 2, 0);
            vertices[1] = new Vertex(-width / 2, -height / 2, 0);
            vertices[2] = new Vertex(width / 2, -height / 2, 0);
            vertices[3] = new Vertex(width / 2, height / 2, 0);
            // 初始化纹理坐标
            vertices[0].u = 0; vertices[0].v = 0;
            vertices[1].u = 0; vertices[1].v = 1;
            vertices[2].u = 1; vertices[2].v = 1;
            vertices[3].u = 1; vertices[3].v = 0;

            // add to vertex layer
            foreach (Vertex v in vertices)
            {
                vertexLayer.InsertVertex(v);

                renderController.AddVisualInfoToVertex(v);
            }

            // create a face
            Face face = new Face(0);

            // creates 4 edges
            Edge[] edges = new Edge[4];

            // create one face and four edges
            for (int i = 0; i < 4; i++)
            {
                edges[i] = new Edge(vertices[i], vertices[i + 1 < 4 ? i + 1 : 0]);
                EdgeTree tree = new EdgeTree(edges[i]);
                edgeLayer.AddTree(tree);

                face.AddEdge(edges[i]);
                edges[i].Face1 = face;
            }

            // use root to initialize facecell tree and lookuptable
            faceLayer.Initliaze(face);

            face.UpdateVertices();
            faceLayer.UpdateLeaves();

            faceGroupLookupTable = new FaceGroupLookupTable(face);

            // 此处也应该拍一张快照
            SnapshotNode node = new SnapshotNode(faceLayer.Leaves);
            // 为了方便revert设计,详情联系 ET
            node.Type = SnapshotNodeKind.CutKind;
            node.OriginVertexListCount = vertexLayer.VertexCellTable.Count;
            node.OriginEdgeListCount = edgeLayer.Count;
            shadowSystem.Snapshot(node);

            // 调用渲染层,更新纸张
            CreatePaper(face);
        }
示例#8
0
        /// <summary>
        /// 保存顶点层
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="vertexLayer"></param>
        void SaveVertexLayer(FileStream fs, VertexLayer vertexLayer)
        {
            writer.Write("Vertex Layer");

            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(fs, vertexLayer);

            writer.Write(Vertex.Vertex_count);
        }