public void EnterFoldingMode(Vertex pickedVertex, Face nearestFace) { this.cloverController = CloverController.GetInstance(); // 寻找同group面中拥有pickedVertex的面中最下面的那个面作为baseFace this.group = cloverController.FaceGroupLookupTable.GetGroup(nearestFace); if (this.group == null) { System.Windows.MessageBox.Show("找不到Groups"); return; } this.pickedVertex = pickedVertex; this.baseFace = nearestFace; foreach (Face face in group.GetFaceList()) { if (CloverTreeHelper.IsVertexInFace(pickedVertex, face) && face.Layer < baseFace.Layer) baseFace = face; } // 将同Group的面分为在base面之上(含baseFace)和base面之下的两组 foreach (Face face in group.GetFaceList()) { if (face.Layer >= baseFace.Layer) this.facesAboveBase.Add(face); else this.facesBelowBase.Add(face); } // 保存pickedVertex的原始位置 originPoint = new Point3D(pickedVertex.X, pickedVertex.Y, pickedVertex.Z); }
public void Initialize(float width, float height) { // 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); // add to vertex layer foreach (Vertex v in vertices) { vertexLayer.InsertVertex(v); } // create a face Face face = new Face(); // 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]); } // use root to initialize facecell tree and lookuptable faceLayer.Initliaze(face); }
/// <summary> /// 将当前节点之后的版本删掉 /// </summary> /// <param name="vertex"></param> public void DeleteNextVersionToEnd(Vertex vertex) { int index = VertexCellTable[vertex.Index].IndexOf(vertex) + 1; if (index != -1 && index < VertexCellTable[vertex.Index].Count) { VertexCellTable[vertex.Index].RemoveRange(index, VertexCellTable[vertex.Index].Count - index); } }
public List<Face> EnterTuckingMode(Vertex pickedVertex, Face nearestFace) { this.cloverController = CloverController.GetInstance(); //cloverController.ShadowSystem.CheckUndoTree(); // 寻找同group面中拥有pickedVertex的面中最下面的那个面作为floorFace,最上面的那个面作为ceilingFace this.group = cloverController.FaceGroupLookupTable.GetGroup(nearestFace); this.pickedVertex = pickedVertex; this.floorFace = this.ceilingFace = nearestFace; // 是正向还是反向 Vector3D currNormal = group.Normal * cloverController.RenderController.Entity.Transform.Value; Double judge = Vector3D.DotProduct(currNormal, new Vector3D(0, 0, 1)); isPositive = judge < 0 ? false : true; if (isPositive) { foreach (Face face in group.GetFaceList()) { if (CloverTreeHelper.IsVertexInFace(pickedVertex, face) && face.Layer < floorFace.Layer) floorFace = face; if (CloverTreeHelper.IsVertexInFace(pickedVertex, face) && face.Layer > ceilingFace.Layer) ceilingFace = face; } // 将同Group的面分为在floor和ceiling之间和在floor和ceiling之外两组 foreach (Face face in group.GetFaceList()) { if (face.Layer >= floorFace.Layer && face.Layer <= ceilingFace.Layer) this.facesInHouse.Add(face); else this.facesNotInHouse.Add(face); } } else { foreach (Face face in group.GetFaceList()) { if (CloverTreeHelper.IsVertexInFace(pickedVertex, face) && face.Layer > floorFace.Layer) floorFace = face; if (CloverTreeHelper.IsVertexInFace(pickedVertex, face) && face.Layer < ceilingFace.Layer) ceilingFace = face; } // 将同Group的面分为在floor和ceiling之间和在floor和ceiling之外两组 foreach (Face face in group.GetFaceList()) { if (face.Layer <= floorFace.Layer && face.Layer >= ceilingFace.Layer) this.facesInHouse.Add(face); else this.facesNotInHouse.Add(face); } } // 保存pickedVertex的原始位置 originPoint = new Point3D(pickedVertex.X, pickedVertex.Y, pickedVertex.Z); return facesInHouse; }
/// <summary> /// 返回所有拥有该点的叶子面 /// </summary> /// <param name="v"></param> /// <returns></returns> public static List<Face> GetReferenceFaces(Vertex v) { List<Face> facelist = new List<Face>(); foreach (Face face in CloverController.GetInstance().FaceLeaves) { if (IsVertexInFace(v, face)) facelist.Add(face); } return facelist; }
public List<Face> EnterFoldingMode(Vertex pickedVertex, Face nearestFace) { this.cloverController = CloverController.GetInstance(); //cloverController.ShadowSystem.CheckUndoTree(); // 寻找同group面中拥有pickedVertex的面中最下面的那个面作为baseFace this.group = cloverController.FaceGroupLookupTable.GetGroup(nearestFace); this.pickedVertex = pickedVertex; this.baseFace = nearestFace; // 是正向还是反向 Vector3D currNormal = group.Normal * cloverController.RenderController.Entity.Transform.Value; Double judge = Vector3D.DotProduct(currNormal, new Vector3D(0, 0, 1)); isPositive = judge < 0 ? false : true; if (isPositive) { foreach (Face face in group.GetFaceList()) { if (CloverTreeHelper.IsVertexInFace(pickedVertex, face) && face.Layer < baseFace.Layer) baseFace = face; } // 将同Group的面分为在base面之上(含baseFace)和base面之下的两组 foreach (Face face in group.GetFaceList()) { if (face.Layer >= baseFace.Layer) this.facesAboveBase.Add(face); else this.facesBelowBase.Add(face); } } else { foreach (Face face in group.GetFaceList()) { if (CloverTreeHelper.IsVertexInFace(pickedVertex, face) && face.Layer > baseFace.Layer) baseFace = face; } // 将同Group的面分为在base面之上(含baseFace)和base面之下的两组 foreach (Face face in group.GetFaceList()) { if (face.Layer <= baseFace.Layer) this.facesAboveBase.Add(face); else this.facesBelowBase.Add(face); } } // 保存pickedVertex的原始位置 originPoint = new Point3D(pickedVertex.X, pickedVertex.Y, pickedVertex.Z); return facesAboveBase; }
/// <summary> /// 计算顶点纹理坐标 /// </summary> /// <param name="vertex"></param> /// <param name="edge"></param> /// <returns></returns> public bool CalculateTexcoord(Vertex vertex, Edge edge) { // 判断该点是否在直线上 if (!CloverMath.IsPointInTwoPoints(vertex.GetPoint3D(), edge.Vertex1.GetPoint3D(), edge.Vertex2.GetPoint3D(), 0.001)) return false; // 取中间点到其中一点的距离,以及直线长度 Vector3D v1 = vertex.GetPoint3D() - edge.Vertex1.GetPoint3D(); Vector3D v2 = edge.Vertex2.GetPoint3D() - edge.Vertex1.GetPoint3D(); double proportion = v1.Length / v2.Length; vertex.u = edge.Vertex1.u + proportion * (edge.Vertex2.u - edge.Vertex1.u); vertex.v = edge.Vertex1.v + proportion * (edge.Vertex2.v - edge.Vertex1.v); return true; }
/// <summary> /// 一条边分割成两条边 /// </summary> /// <param name="parentEdge"></param> /// <param name="cutVertex"></param> public void UpdateTree(Edge parentEdge, Vertex cutVertex) { foreach (EdgeTree tree in edgeTreeList) { if (tree.IsContain(parentEdge)) { Edge e1 = new Edge(parentEdge.Vertex1, cutVertex); Edge e2 = new Edge(cutVertex, parentEdge.Vertex2); // 设置左右孩子会自动设置父亲 //e1.Parent = e2.Parent = parentEdge; parentEdge.LeftChild = e1; parentEdge.RightChild = e2; } } }
/// <summary> /// 通过点来找面 /// </summary> /// <param name="faceList">传入一个面表</param> /// <param name="vertex"></param> /// <returns>返回找到的面</returns> public static List<Face> FindFacesFromVertex(List<Face> faceList, Vertex vertex) { List<Face> list = new List<Face>(); foreach (Face face in faceList) { foreach (Edge edge in face.Edges) { //if ( CloverMath.IsTwoPointsEqual(edge.Vertex1.GetPoint3D(), vertex.GetPoint3D(), 0.001) // || CloverMath.IsTwoPointsEqual(edge.Vertex2.GetPoint3D(), vertex.GetPoint3D(), 0.001)) if (edge.IsVerticeIn(vertex)) { list.Add(face); break; } } } return list; }
public Edge(Vertex v1, Vertex v2) { vertex1 = v1; vertex2 = v2; id = edge_count++; }
public Vertex(Vertex vertex) { point = new Point3D(vertex.X, vertex.Y, vertex.Z); renderPoint = new Point3D(vertex.renderPoint.X, vertex.renderPoint.Y, vertex.renderPoint.Z); Index = vertex.Index; _u = vertex._u; _v = vertex._v; id = vertex_count++; }
/// <summary> /// 更行面的法向量 /// </summary> /// <returns></returns> bool UpdateNormal() { if (vertices.Count < 3) return false; Vertex[] p = new Vertex[3]; p[0] = vertices[0]; p[1] = Vertices[1]; p[2] = vertices[2]; // 取任意位于面上的向量 Vector3D v1 = p[ 2 ].GetPoint3D() - p[ 0 ].GetPoint3D(); Vector3D v2 = p[ 1 ].GetPoint3D() - p[ 0 ].GetPoint3D(); normal = Vector3D.CrossProduct( v1, v2 ); normal.Normalize(); normal.Negate(); return true; }
public void AddEdge(Edge edge) { // 初始化,用第一条边 if (edges.Count == 0) { startVertex1 = edge.Vertex1; startVertex2 = edge.Vertex2; } edges.Add(edge); // UpdateVertices(); }
public Vertex GetPrevVersion(Vertex vertex) { List<Vertex> vGroup = vertexLayer.VertexCellTable[vertex.Index]; if (vGroup.Count < 2) return null; return vGroup[vGroup.Count - 2]; }
Point3D UpdateRenderPoint(Vertex v) { Point3D rp = new Point3D(); rp.X = v.X; rp.Y = v.Y; rp.Z = v.Z; v.RenderPoint = rp; return rp; }
/// <summary> /// 更新顶点 /// </summary> /// <param name="vertex">插入在下标为index的顶点</param> /// <param name="index">这个顶点的索引</param> /// <remarks>下标越界会抛出异常</remarks> public void UpdateVertex(Vertex vertex, int index) { vertex.Index = index; vertexCellTable[index].Add(vertex); }
/// <summary> /// 判断一个点是否在一个面中 /// </summary> /// <param name="vervex"></param> /// <param name="face"></param> /// <returns></returns> public static Boolean IsVertexInFace(Vertex vervex, Face face) { foreach (Vertex v in face.Vertices) { if (v == vervex) return true; } return false; }
/// <summary> /// 为一个顶点添加提示信息 /// </summary> /// <param name="v"></param> public void AddVisualInfoToVertex(Vertex v) { //VertexInfoVisual vi = new VertexInfoVisual(v); //VisualController.GetSingleton().AddVisual(vi); //v.Update += vi.UpdateInfoCallBack; ////CubeNavigator.GetInstance().Update += vi.UpdateInfoCallBack; //vi.Start(); }
/// <summary> /// 计算一个面中两点的中垂线,结果在参数从输出 /// </summary> /// <param name="f"></param> /// <param name="po"></param> /// <param name="pd"></param> /// <param name="t">直线的方向向量</param> /// <param name="p">直线上的一点</param> public static bool GetMidperpendicularInFace(Face f, Vertex po, Vertex pd, ref Vector3D t, ref Point3D p) { if (CloverMath.IsTwoPointsEqual(po.GetPoint3D(), pd.GetPoint3D(), 0.00001)) { return false; } Point3D pOriginal = po.GetPoint3D(); Point3D pDestination = pd.GetPoint3D(); t = Vector3D.CrossProduct(f.Normal, (pOriginal - pDestination)); p.X = (po.X + pd.X) / 2; p.Y = (po.Y + pd.Y) / 2; p.Z = (po.Z + pd.Z) / 2; return true; }
/// <summary> /// /// </summary> /// <returns></returns> public bool MoveToANewPosition(Vertex pickedVertex, List<Face> lastTimeMovedFaces, Edge lastFoldingLine, Edge foldingLine, Point3D projectionPoint, Point3D lastProjectionPoint) { CloverController cloverController = CloverController.GetInstance(); // 用于计算矩阵的两个关键向量 Vector3D vectorFromLastFoldingLineToOriginVertex = new Vector3D(); Vector3D vectorFromCurrentFoldingLineToProjVertex = new Vector3D(); // 更新当前选中点到最新的状态 Vertex currentVertex = cloverController.VertexLayer.GetVertex(pickedVertex.Index); // 从上次移动的面中找到带有选中点的那个面 Face pickedFaceAfterCutting = null; // 从上次移动的面中找到带有选中点的那个面 foreach (Face face in lastTimeMovedFaces) { foreach (Vertex v in face.Vertices) { if (v == currentVertex) { if (pickedFaceAfterCutting == null || pickedFaceAfterCutting.Layer > face.Layer) pickedFaceAfterCutting = face; break; } } } if (pickedFaceAfterCutting == null) return false; // 在选定的面上找到与折线边顶点位置相等的那条边 Edge foldingLineOnFace = null; foreach (Edge e in pickedFaceAfterCutting.Edges) { if (CloverMath.AreTwoEdgesEqual(e, lastFoldingLine)) foldingLineOnFace = e; } if (null == foldingLineOnFace) return false; // 在找到选顶点与折线的一条连线边,计算出计算角度所需的向量1 Edge edgeBeforeMoving = null; foreach (Edge e in pickedFaceAfterCutting.Edges) { if (e.Vertex1 == currentVertex && e.Vertex2 == foldingLineOnFace.Vertex1) { edgeBeforeMoving = e; break; } if (e.Vertex2 == currentVertex && e.Vertex1 == foldingLineOnFace.Vertex1) { edgeBeforeMoving = e; break; } if (e.Vertex1 == currentVertex && e.Vertex2 == foldingLineOnFace.Vertex2) { edgeBeforeMoving = e; break; } if (e.Vertex2 == currentVertex && e.Vertex1 == foldingLineOnFace.Vertex2) { edgeBeforeMoving = e; break; } } // 得到关键向量1 vectorFromLastFoldingLineToOriginVertex = edgeBeforeMoving.Vertex2.GetPoint3D() - edgeBeforeMoving.Vertex1.GetPoint3D(); // 在原始面中找到折线顶点所在的两条边,并用这两条边计算折线的纹理坐标 foreach (Edge e in pickedFaceAfterCutting.Parent.Edges) { // 判断折线的两个顶点,更新坐标并计算纹理 // 顶点1 if (CloverMath.IsPointInTwoPoints(foldingLineOnFace.Vertex1.GetPoint3D(), e.Vertex1.GetPoint3D(), e.Vertex2.GetPoint3D())) { cloverController.FoldingSystem.CalculateTexcoord(foldingLineOnFace.Vertex1, e); if (CloverMath.IsPointInTwoPoints(foldingLine.Vertex1.GetPoint3D(), e.Vertex1.GetPoint3D(), e.Vertex2.GetPoint3D())) { foldingLineOnFace.Vertex1.SetPoint3D(foldingLine.Vertex1.GetPoint3D()); foldingLineOnFace.Vertex1.Moved = true; } else { foldingLineOnFace.Vertex1.SetPoint3D(foldingLine.Vertex2.GetPoint3D()); foldingLineOnFace.Vertex1.Moved = true; } } // 顶点2 if (CloverMath.IsPointInTwoPoints(foldingLineOnFace.Vertex2.GetPoint3D(), e.Vertex1.GetPoint3D(), e.Vertex2.GetPoint3D())) { cloverController.FoldingSystem.CalculateTexcoord(foldingLineOnFace.Vertex2, e); if (CloverMath.IsPointInTwoPoints(foldingLine.Vertex1.GetPoint3D(), e.Vertex1.GetPoint3D(), e.Vertex2.GetPoint3D())) { foldingLineOnFace.Vertex2.SetPoint3D(foldingLine.Vertex1.GetPoint3D()); foldingLineOnFace.Vertex2.Moved = true; } else { foldingLineOnFace.Vertex2.SetPoint3D(foldingLine.Vertex2.GetPoint3D()); foldingLineOnFace.Vertex2.Moved = true; } } } // 设置选中点的新位置为projectinPoint; currentVertex.SetPoint3D(projectionPoint); currentVertex.Moved = true; // 找到选中点和折线之间的向量,得到关键向量2 vectorFromCurrentFoldingLineToProjVertex = edgeBeforeMoving.Vertex2.GetPoint3D() - edgeBeforeMoving.Vertex1.GetPoint3D(); // 计算所有上次移动面的折线,对于折线完全相等的直接更新到新的位置,对于不相等的要重新找打对应的边,然后计算折线位置,再更新折线 foreach (Face face in lastTimeMovedFaces) { if (face == pickedFaceAfterCutting) continue; Edge foldingLineForThisFace = null; foreach (Edge e in face.Edges) { // 找到与原来折线共线的那条边 Point3D crossedPoint = new Point3D(); if (2 == CloverMath.GetIntersectionOfTwoSegments(lastFoldingLine, e, ref crossedPoint)) { foldingLineForThisFace = e; break; } } // 假如木有折线,或者折线中的其中一个点和上面的折线拥有相同点返回 if (foldingLineForThisFace == null) { // 采用点更新法 foreach (Edge e in face.Edges) { // 假如其中有一条边的一个顶点等于新折线,而另一个顶点等于旧折线中的点,折更新旧点到新点 } continue; } // 计算现在的折线位置 Edge currentFoldingLineForThisFace = CloverTreeHelper.GetEdgeCrossedFace(face, foldingLine); if (currentFoldingLineForThisFace == null) continue; // 通过该面的原始面查询折线并更新折线位置和纹理坐标 foreach (Edge e in face.Parent.Edges) { // 判断折线的两个顶点,更新坐标并计算纹理 // 顶点1 if (CloverMath.IsPointInTwoPoints(foldingLineForThisFace.Vertex1.GetPoint3D(), e.Vertex1.GetPoint3D(), e.Vertex2.GetPoint3D()) && !foldingLineForThisFace.Vertex1.Moved) { cloverController.FoldingSystem.CalculateTexcoord(foldingLineForThisFace.Vertex1, e); if (CloverMath.IsPointInTwoPoints(currentFoldingLineForThisFace.Vertex1.GetPoint3D(), e.Vertex1.GetPoint3D(), e.Vertex2.GetPoint3D())) { foldingLineOnFace.Vertex1.SetPoint3D(currentFoldingLineForThisFace.Vertex1.GetPoint3D()); foldingLineOnFace.Vertex1.Moved = true; } else { foldingLineOnFace.Vertex1.SetPoint3D(currentFoldingLineForThisFace.Vertex2.GetPoint3D()); foldingLineOnFace.Vertex1.Moved = true; } } // 顶点2 if (CloverMath.IsPointInTwoPoints(foldingLineForThisFace.Vertex2.GetPoint3D(), e.Vertex1.GetPoint3D(), e.Vertex2.GetPoint3D()) && !foldingLineForThisFace.Vertex2.Moved) { cloverController.FoldingSystem.CalculateTexcoord(foldingLineForThisFace.Vertex2, e); if (CloverMath.IsPointInTwoPoints(currentFoldingLineForThisFace.Vertex1.GetPoint3D(), e.Vertex1.GetPoint3D(), e.Vertex2.GetPoint3D())) { foldingLineOnFace.Vertex2.SetPoint3D(currentFoldingLineForThisFace.Vertex1.GetPoint3D()); foldingLineOnFace.Vertex2.Moved = true; } else { foldingLineOnFace.Vertex2.SetPoint3D(currentFoldingLineForThisFace.Vertex2.GetPoint3D()); foldingLineOnFace.Vertex2.Moved = true; } } } } // 求得旋转量,并创建旋转矩阵 Vector3D axis = Vector3D.CrossProduct(vectorFromCurrentFoldingLineToProjVertex, vectorFromLastFoldingLineToOriginVertex); axis.Normalize(); axis.Negate(); double angle = Vector3D.AngleBetween(vectorFromCurrentFoldingLineToProjVertex, vectorFromLastFoldingLineToOriginVertex); AxisAngleRotation3D asixRotation = new AxisAngleRotation3D(axis, angle); RotateTransform3D rotateTransform = new RotateTransform3D(asixRotation); rotateTransform.CenterX = projectionPoint.X; rotateTransform.CenterY = projectionPoint.Y; rotateTransform.CenterZ = projectionPoint.Z; // 创建平移矩阵 Vector3D vectorFromProjToOrigin = projectionPoint - lastProjectionPoint; TranslateTransform3D translateTransform = new TranslateTransform3D(vectorFromProjToOrigin); // 移动所有没有移动过的顶点 foreach (Face face in lastTimeMovedFaces) { foreach (Vertex v in face.Vertices) { if (!v.Moved) { v.SetPoint3D(translateTransform.Transform(v.GetPoint3D())); v.SetPoint3D(rotateTransform.Transform(v.GetPoint3D())); v.Moved = true; } } } // 最终更改所有顶点移动属性复位 foreach (Face face in lastTimeMovedFaces) { foreach (Vertex v in face.Vertices) { v.Moved = false; } } // 更新渲染层 // 也许UpdateAll曾今给了你们许多欢乐的时光,但现在它应该退场了 ---kid //cloverController.RenderController.UpdateAll(); //foreach (Face face in lastTimeMovedFaces) //{ // cloverController.RenderController.Update(face); //} // 好吧。。你们还是继续使用UpdateAll好了。。 ---kid cloverController.RenderController.UpdateAll(); return true; }
/// <summary> /// 克隆和更新一个新的顶点到VertexLayer /// </summary> /// <param name="v"></param> void CloneAndUpdateVertex(Vertex v) { VertexLayer vertexLayer = CloverController.GetInstance().VertexLayer; vertexLayer.UpdateVertex(v.Clone() as Vertex, v.Index); }
public static Edge GetPerpendicularBisector3D(Face face, Point3D p1, Point3D p2) { // 定义中垂线的两个点 Point3D pbP1 = new Point3D(); Point3D pbP2 = new Point3D(); // 取线段中点 Point3D middlePoint = new Point3D(); middlePoint.X = (p1.X + p2.X) / 2; middlePoint.Y = (p1.Y + p2.Y) / 2; middlePoint.Z = (p1.Z + p2.Z) / 2; // 取中截面法向量 Vector3D normal = new Vector3D(); normal = p1 - p2; normal.Normalize(); // 求中截面平面方程 double A = normal.X; double B = normal.Y; double C = normal.Z; double D = -(A * middlePoint.X) - (B * middlePoint.Y) - (C * middlePoint.Z); double Den = Math.Sqrt((A * A + B * B + C * C)); // 求该截面与空间线段的交点 bool findFirst = false; bool finished = false; foreach (Edge e in face.Edges) { // 求空间点到该平面上的两个投影点 double d1 = A * e.Vertex1.X + B * e.Vertex1.Y + C * e.Vertex1.Z + D / Den; double d2 = A * e.Vertex2.X + B * e.Vertex2.Y + C * e.Vertex2.Z + D / Den; Point3D proP1 = e.Vertex1.GetPoint3D() - d1 * normal; Point3D proP2 = e.Vertex2.GetPoint3D() - d2 * normal; Edge proE = new Edge(new Vertex(proP1), new Vertex(proP2)); // 求空间两直线之间的交点 if (!findFirst) { if (1 == GetIntersectionOfTwoSegments(e, proE, ref pbP1)) { findFirst = true; } } else { if (1 == GetIntersectionOfTwoSegments(e, proE, ref pbP2) && pbP1 != pbP2) { finished = true; break; } } } if (finished) { Vertex vertex1 = new Vertex(pbP1); Vertex vertex2 = new Vertex(pbP2); Edge perpendicularBisector = new Edge(vertex1, vertex2); return perpendicularBisector; } return null; }
/// <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); }
/// <summary> /// 插入一个全新的顶点,会建立一个新的顶点链表 /// </summary> /// <param name="vertex"></param> /// <returns></returns> public int InsertVertex(Vertex vertex) { List<Vertex> vl = new List<Vertex>(); vl.Add(vertex); vertexCellTable.Add(vl); // 是不是返回新的顶点的索引?是的话是不是应该减一呢? —— Cedric Porter // old: return VertexCellTable.Count; // 设置顶点的index,后续插入的顶点都有同样的index,方便索引 vertex.Index = vertexCellTable.Count - 1; return vertex.Index; }
/// <summary> /// 查找顶点是否在顶点列表中,若存在返回该顶点的索引,若不存在返回-1 /// </summary> /// <param name="vertex"></param> /// <returns></returns> public int IsVertexExist(Vertex vertex) { int index = 0; foreach (List<Vertex> vl in vertexCellTable) { if (vl[vl.Count - 1].GetPoint3D() == vertex.GetPoint3D()) return index; index++; } return -1; }
public void InitializeBeforeFolding(Vertex vertex) { // 计算和创建一条新的折线 // 新增数据结构的信息 // 1.顶点 // 2.边 // 3.面 // over... // }
/// <summary> /// 更新节点 /// </summary> /// <param name="oldVertex">要被更新的节点</param> /// <param name="newVertex">新的节点</param> public void UpdateVertex(Vertex oldVertex, Vertex newVertex) { newVertex.Index = oldVertex.Index; vertexCellTable[newVertex.Index].Add(newVertex); }
public bool IsVerticeIn(Vertex v) { return IsVerticeIn(v.GetPoint3D()); }
/// <summary> /// 把当前节点和之后的节点都删除 /// </summary> /// <param name="vertex"></param> public void DeleteThisVersionToEnd(Vertex vertex) { int index = VertexCellTable[vertex.Index].IndexOf(vertex); if (index == -1) return; VertexCellTable[vertex.Index].RemoveRange(index, VertexCellTable[vertex.Index].Count - index); }
/// <summary> /// 通过点找面 /// </summary> /// <param name="vertex"></param> /// <returns></returns> public List<Face> FindFacesByVertex(Vertex vertex) { return CloverTreeHelper.FindFacesFromVertex(faceLayer.Leaves, vertex); }