Beispiel #1
0
 /// <summary>
 /// 重新将组设置到过去
 /// </summary>
 private void UndoGroup(SnapshotNode node)
 {
     CloverController.GetInstance().FaceGroupLookupTable = node.FaceGroupLookupTable;
 }
Beispiel #2
0
        SnapshotNode SnapshotNode()
        {
            SnapshotNode node = new SnapshotNode();
            node.Type = (SnapshotNodeKind)reader.ReadInt32();

            List<Face> leaves = new List<Face>();
            int faceCount = reader.ReadInt32();
            for (int i = 0; i < faceCount; i++)
            {
                int faceID = reader.ReadInt32();
                leaves.Add(faceIDDict[faceID]);
            }
            node.FaceLeaves = leaves;

            List<Edge> newEdgeList = new List<Edge>();
            int newEdgeCount = reader.ReadInt32();
            for (int i = 0; i < newEdgeCount; i++)
            {
                int edgeID = reader.ReadInt32();
                newEdgeList.Add(edgeIDDict[edgeID]);
            }
            node.NewEdges = newEdgeList;

            List<Vertex> vertexList = new List<Vertex>();
            int vertexCount = reader.ReadInt32();
            for (int i = 0; i < vertexCount; i++)
            {
                int vertexID = reader.ReadInt32();
                vertexList.Add(vertexIDDict[vertexID]);
            }
            node.MovedVertexList = vertexList;

            int originVertexListCount = reader.ReadInt32();
            node.OriginVertexListCount = originVertexListCount;
            int originEdgeListCount = reader.ReadInt32();
            node.OriginEdgeListCount = originEdgeListCount;

            return node;
        }
 public SnapshotNode SnapshotBeforeCut()
 {
     // 拍快照
     shadowSystem.CheckUndoTree();
     SnapshotNode node = new SnapshotNode(faceLayer.Leaves);
     node.Type = SnapshotNodeKind.CutKind;
     node.OriginVertexListCount = vertexLayer.VertexCellTable.Count;
     node.OriginEdgeListCount = edgeLayer.Count;
     node.FaceGroupLookupTable = CloverController.GetInstance().FaceGroupLookupTable.Clone() as FaceGroupLookupTable;
     return node;
 }
Beispiel #4
0
        /// <summary>
        /// 拍快照
        /// </summary>
        public void Snapshot(SnapshotNode node)
        {
            //CheckUndoTree();

            snapshotList.Add(node);
            operationLevel++;
        }
 public void SnapshotAfterCut(SnapshotNode node, List<Edge> newEdges)
 {
     node.NewEdges = newEdges;
     shadowSystem.Snapshot(node);
 }
        public void RotateFaces(List<Face> beRotatedFaceList, Edge foldingLine, double angle)
        {
            SnapshotNode node = new SnapshotNode(CloverController.GetInstance().FaceLayer.Leaves);

            List<Vertex> movedVertexList = foldingSystem.RotateFaces(beRotatedFaceList, foldingLine, angle);

            // 记录本次移动了的顶点
            node.MovedVertexList = movedVertexList;
            node.OriginEdgeListCount = CloverController.GetInstance().EdgeLayer.Count;
            node.OriginVertexListCount = CloverController.GetInstance().VertexLayer.VertexCellTable.Count;
            node.Type = SnapshotNodeKind.RotateKind;
            shadowSystem.Snapshot(node);
        }
        /// <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);
        }
        public void AnimatedRotateFaces(List<Face> beRotatedFaceList, Edge foldingLine, double angle)
        {
            try
            {
                List<Face> faceList = new List<Face>();
                faceList.AddRange(beRotatedFaceList);
                List<Vertex> movedVertexList = null;

                AutoCamera(beRotatedFaceList[0]);

                // 控制时间
                animaWatch.Restart();
                long lastTime = 0;
                long thisTime = 0;
                double interval = angle / animationDuration; //0.5秒
                while (thisTime <= animationDuration)
                {
                    thisTime = animaWatch.ElapsedMilliseconds;
                    double step;
                    if (thisTime <= animationDuration)
                        step = interval * (thisTime - lastTime);
                    else
                        step = interval * (animationDuration - lastTime);
                    List<Vertex> list = mainWindow.Dispatcher.Invoke(
                        new RotateFacesHandle(foldingSystem.RotateFaces),
                         faceList, foldingLine, step) as List<Vertex>;

                    // 取第一次的移动的顶点列表
                    if (movedVertexList == null)
                    {
                        movedVertexList = list;
                    }

                    lastTime = thisTime;
                }
                animaWatch.Stop();

                // 快照
                SnapshotNode node = new SnapshotNode(CloverController.GetInstance().FaceLayer.Leaves);
                node.MovedVertexList = movedVertexList;
                node.OriginEdgeListCount = CloverController.GetInstance().EdgeLayer.Count;
                node.OriginVertexListCount = CloverController.GetInstance().VertexLayer.VertexCellTable.Count;
                node.Type = SnapshotNodeKind.RotateKind;
                shadowSystem.Snapshot(node);
            }
            catch (System.Exception ex)
            {
                System.Windows.MessageBox.Show(ex.ToString());
            }
        }
        /// <summary>
        /// 保存SnapshotNode节点到文件中
        /// </summary>
        /// <param name="node"></param>
        void SaveSnapshotNode(SnapshotNode node)
        {
            writer.Write((int)node.Type);

            writer.Write(node.FaceLeaves.Count);
            foreach (Face face in node.FaceLeaves)
            {
                writer.Write(face.ID);
            }

            writer.Write(node.NewEdges.Count);
            foreach (Edge edge in node.NewEdges)
            {
                writer.Write(edge.ID);
            }

            writer.Write(node.MovedVertexList.Count);
            foreach (Vertex v in node.MovedVertexList)
            {
                writer.Write(v.ID);
            }

            writer.Write(node.OriginVertexListCount);

            writer.Write(node.OriginEdgeListCount);
        }