public void UpdateCadGeometry(CadObject2D cad2D) { Mesher2D mesh = new Mesher2D(cad2D); for (int idp = 0; idp < DrawParts.Count; idp++) { CadObject2DDrawPart dp = DrawParts[idp]; dp.Clear(); uint cadId = dp.CadId; CadElementType cadType = dp.Type; if (!cad2D.IsElementId(cadType, cadId)) { continue; } uint meshId = mesh.GetIdFromCadId(cadId, cadType); if (meshId == 0) { continue; } MeshType meshType; uint elemCnt; int loc; uint cadId0; mesh.GetMeshInfo(meshId, out elemCnt, out meshType, out loc, out cadId0); System.Diagnostics.Debug.Assert(cadId0 == cadId); if (meshType == MeshType.Tri) { dp.SetTriArray(mesh.GetTriArrays()[loc]); double[] color = cad2D.GetLoopColor(cadId0); for (int iTmp = 0; iTmp < 3; iTmp++) { dp.Color[iTmp] = (float)color[iTmp]; } } else if (meshType == MeshType.Bar) { dp.SetBarArray(mesh.GetBarArrays()[loc]); System.Diagnostics.Debug.Assert(cadType == CadElementType.Edge); Edge2D edge = cad2D.GetEdge(cadId); dp.CurveType = edge.CurveType; dp.CtrlPoints.Clear(); // 2019-03-11 エッジの色 FIX double[] color = edge.Color; for (int iTmp = 0; iTmp < 3; iTmp++) { dp.Color[iTmp] = (float)color[iTmp]; } if (edge.CurveType == CurveType.CurveArc) { OpenTK.Vector2d cPt; double radius; edge.GetCenterRadius(out cPt, out radius); dp.CtrlPoints.Add(cPt); } else if (edge.CurveType == CurveType.CurveBezier) { IList <OpenTK.Vector2d> cos = edge.GetCurvePoint(); dp.CtrlPoints.Add(cos[0]); dp.CtrlPoints.Add(cos[1]); } } else if (meshType == MeshType.Vertex) { dp.SetVertex(mesh.GetVertexs()[loc]); } } { // 座標をセット IList <OpenTK.Vector2d> vec2Ds = mesh.GetVectors(); uint ptCnt = (uint)vec2Ds.Count; uint ndim = 2; VertexArray.SetSize(ptCnt, ndim); for (int iPt = 0; iPt < ptCnt; iPt++) { VertexArray.VertexCoordArray[iPt * ndim] = vec2Ds[iPt].X; VertexArray.VertexCoordArray[iPt * ndim + 1] = vec2Ds[iPt].Y; } if (VertexArray.UVCoordArray != null) { for (int iPt = 0; iPt < ptCnt; iPt++) { VertexArray.UVCoordArray[iPt * ndim] = vec2Ds[iPt].X * TexScale; VertexArray.UVCoordArray[iPt * ndim + 1] = vec2Ds[iPt].Y * TexScale; } } } }
public bool UpdateCadTopologyGeometry(CadObject2D cad2D) { SutableRotMode = RotMode.RotMode2D; IList <CadObject2DDrawPart> oldDrawParts = new List <CadObject2DDrawPart>(); for (int i = 0; i < DrawParts.Count; i++) { oldDrawParts.Add(new CadObject2DDrawPart(DrawParts[i])); } for (int idp = 0; idp < oldDrawParts.Count; idp++) { oldDrawParts[idp].MeshId = 0; oldDrawParts[idp].ShowMode = 0; } DrawParts.Clear(); int minLayer; int maxLayer; cad2D.GetLayerMinMax(out minLayer, out maxLayer); double layerHeight = 1.0 / (maxLayer - minLayer + 1); { // 面をセット IList <uint> lIds = cad2D.GetElementIds(CadElementType.Loop); for (int iLId = 0; iLId < lIds.Count; iLId++) { uint lId = lIds[iLId]; double height = 0; { int layer = cad2D.GetLayer(CadElementType.Loop, lId); height = (layer - minLayer) * layerHeight; } int idp0 = 0; for (; idp0 < oldDrawParts.Count; idp0++) { CadObject2DDrawPart olddp = oldDrawParts[idp0]; if (olddp.Type == CadElementType.Loop && olddp.CadId == lId) { olddp.MeshId = 1; olddp.Height = height; double[] color = cad2D.GetLoopColor(lId); for (int iTmp = 0; iTmp < 3; iTmp++) { olddp.Color[iTmp] = (float)color[iTmp]; } DrawParts.Add(oldDrawParts[idp0]); break; } } if (idp0 == oldDrawParts.Count) { CadObject2DDrawPart dp = new CadObject2DDrawPart(); dp.CadId = lId; dp.Type = CadElementType.Loop; dp.Height = height; double[] color = cad2D.GetLoopColor(lId); for (int iTmp = 0; iTmp < 3; iTmp++) { dp.Color[iTmp] = (float)color[iTmp]; } DrawParts.Add(dp); } } } { // set edge IList <uint> eIds = cad2D.GetElementIds(CadElementType.Edge); for (int iEId = 0; iEId < eIds.Count; iEId++) { uint eId = eIds[iEId]; double height = 0; { int layer = cad2D.GetLayer(CadElementType.Edge, eId); height += (layer - minLayer + 0.01) * layerHeight; } int idp0 = 0; for (; idp0 < oldDrawParts.Count; idp0++) { CadObject2DDrawPart olddp = oldDrawParts[idp0]; if (olddp.Type == CadElementType.Edge && olddp.CadId == eId) { olddp.MeshId = 1; olddp.Height = height; DrawParts.Add(olddp); break; } } if (idp0 == oldDrawParts.Count) { CadObject2DDrawPart dp = new CadObject2DDrawPart(); dp.CadId = eId; dp.Type = CadElementType.Edge; dp.Height = height; DrawParts.Add(dp); } { CadObject2DDrawPart dp = DrawParts[DrawParts.Count - 1]; Edge2D edge = cad2D.GetEdge(eId); dp.CtrlPoints.Clear(); dp.CurveType = edge.CurveType; if (edge.CurveType == CurveType.CurveArc) { OpenTK.Vector2d cPt; double radius; edge.GetCenterRadius(out cPt, out radius); dp.CtrlPoints.Add(cPt); } else if (edge.CurveType == CurveType.CurveBezier) { IList <OpenTK.Vector2d> cos = edge.GetCurvePoint(); dp.CtrlPoints.Add(cos[0]); dp.CtrlPoints.Add(cos[1]); } } } } { // set vertex IList <uint> vIds = cad2D.GetElementIds(CadElementType.Vertex); for (int iVId = 0; iVId < vIds.Count; iVId++) { uint vCadId = vIds[iVId]; int layer = cad2D.GetLayer(CadElementType.Vertex, vCadId); double height = (layer - minLayer + 0.1) * layerHeight; int idp0 = 0; for (; idp0 < oldDrawParts.Count; idp0++) { CadObject2DDrawPart olddp = oldDrawParts[idp0]; if (olddp.Type == CadElementType.Vertex && olddp.CadId == vCadId) { olddp.MeshId = 1; olddp.Height = height; DrawParts.Add(olddp); break; } } if (idp0 == oldDrawParts.Count) { CadObject2DDrawPart dp = new CadObject2DDrawPart(); dp.CadId = vCadId; dp.Type = CadElementType.Vertex; dp.Height = height; DrawParts.Add(dp); } } } oldDrawParts.Clear(); UpdateCadGeometry(cad2D); return(true); }
public bool MoveEdgeCtrl(uint eId, uint iCtrl, OpenTK.Vector2d deltaVec) { if (!IsElementId(CadElementType.Edge, eId)) { return(false); } IList <double> oldRelCos = null; { Edge2D e = GetEdge(eId); oldRelCos = e.GetCurveRelPoint(); } Edge2D edge = GetEdge(eId); if (iCtrl >= edge.GetCurvePoint().Count) { return(true); } { OpenTK.Vector2d sPt = edge.GetVertex(true); OpenTK.Vector2d ePt = edge.GetVertex(false); double sqLen = CadUtils.SquareLength(ePt - sPt); var eh = (ePt - sPt) * (1 / sqLen); OpenTK.Vector2d ev = new OpenTK.Vector2d(-eh.Y, eh.X); var p0 = edge.GetCurvePoint()[(int)iCtrl] + deltaVec; IList <double> aRelCo = edge.GetCurveRelPoint(); aRelCo[(int)(iCtrl * 2 + 0)] = OpenTK.Vector2d.Dot(p0 - sPt, eh); aRelCo[(int)(iCtrl * 2 + 1)] = OpenTK.Vector2d.Dot(p0 - sPt, ev); edge.SetCurveRelPoint(aRelCo); } HashSet <uint> setLId = new HashSet <uint>(); for (VertexEdgeItr vItr = this.BRep.GetVertexEdgeItr(edge.GetVertexId(true)); !vItr.IsEnd(); vItr++) { uint tmpLId = vItr.GetLoopId(); if (!setLId.Contains(tmpLId)) { setLId.Add(tmpLId); } } for (VertexEdgeItr vItr = this.BRep.GetVertexEdgeItr(edge.GetVertexId(false)); !vItr.IsEnd(); vItr++) { uint tmpLId = vItr.GetLoopId(); if (!setLId.Contains(tmpLId)) { setLId.Add(tmpLId); } } foreach (uint lId in setLId) { if (!this.BRep.IsElementId(CadElementType.Loop, lId)) { continue; } if (CheckLoop(lId) != 0) { // fail edge.SetCurveRelPoint(oldRelCos); return(true); } } return(true); }