public void SetAsNeighbor(CSGEdge edge) { if (!neighbors.Exists((e) => e.id == edge.id)) { neighbors.Add(edge); } }
public CSGShape(CSGModel model, CSGSourceTriangle triangleBasis) : this() { parentTriangle = triangleBasis; foreach (CSGVertex vert in triangleBasis.sourceVerts) { boundary.Add(vert); } for (int i = 0; i < 3; i++) { CSGEdge edge = model.GetEdge(boundary[i], boundary[(i + 1) % 3], true); edge.SetAsNeighbor(this); edges.Add(edge); } }
// clone a model and transform its verts and vinfos (scraps any WIP intersection info) public CSGModel CloneAndTransform(ModelUtil.CopyAndTransformVert vertCopier, ModelUtil.CopyAndTransformVInfo vinfoCopier) { CSGModel result = new CSGModel(); Dictionary<long, CSGVertex> vertexMapping = new Dictionary<long, CSGVertex>(); Dictionary<long, CSGEdge> edgeMapping = new Dictionary<long, CSGEdge>(); Dictionary<long, CSGShape> shapeMapping = new Dictionary<long, CSGShape>(); Dictionary<long, CSGSourceTriangle> triangleMapping = new Dictionary<long, CSGSourceTriangle>(); foreach (CSGVertex vert in vertices) { CSGVertex v = new CSGVertex(); vertexMapping[vert.id] = v; result.vertices.Add(v); } foreach (CSGEdge edge in edges) { CSGEdge e = new CSGEdge(); edgeMapping[edge.id] = e; result.edges.Add(e); } foreach (CSGShape shape in shapes) { CSGShape s = new CSGShape(); shapeMapping[shape.id] = s; result.shapes.Add(s); } foreach (CSGSourceTriangle triangle in sourceTriangles) { CSGSourceTriangle t = new CSGSourceTriangle(); triangleMapping[triangle.id] = t; result.sourceTriangles.Add(t); } foreach (CSGVertex iVertex in vertices) { CSGVertex rVertex = vertexMapping[iVertex.id]; if(iVertex.parentTriangle != null) rVertex.parentTriangle = triangleMapping[iVertex.parentTriangle.id]; vertCopier(iVertex.position, out rVertex.position); foreach(CSGEdge edge in iVertex.neighbors) rVertex.neighbors.Add(edgeMapping[edge.id]); } foreach (CSGEdge iEdge in edges) { CSGEdge rEdge = edgeMapping[iEdge.id]; if(iEdge.parentTriangle != null) rEdge.parentTriangle = triangleMapping[iEdge.parentTriangle.id]; for (int i = 0; i < 2; i++) { rEdge.endpoints[i] = vertexMapping[iEdge.endpoints[i].id]; if (iEdge.separatedShapes[i] != null) rEdge.separatedShapes[i] = shapeMapping[iEdge.separatedShapes[i].id]; } } foreach (CSGSourceTriangle iTriangle in sourceTriangles) { CSGSourceTriangle rTriangle = triangleMapping[iTriangle.id]; for (int i = 0; i < 3; i++) rTriangle.sourceVerts[i] = vertexMapping[iTriangle.sourceVerts[i].id]; foreach (long key in iTriangle.vertexVInfos.Keys) { VInfo vinfo; vinfoCopier(iTriangle.vertexVInfos[key], out vinfo); rTriangle.vertexVInfos[key] = vinfo; } } foreach (CSGShape iShape in shapes) { CSGShape rShape = shapeMapping[iShape.id]; rShape.parentTriangle = triangleMapping[iShape.parentTriangle.id]; foreach (CSGVertex vert in iShape.boundary) rShape.boundary.Add(vertexMapping[vert.id]); foreach (List<CSGVertex> iHole in iShape.holes) { List<CSGVertex> rHole = new List<CSGVertex>(); foreach (CSGVertex vert in iHole) rHole.Add(vertexMapping[vert.id]); rShape.holes.Add(rHole); } foreach (CSGEdge iEdge in iShape.edges) rShape.edges.Add(edgeMapping[iEdge.id]); } return result; }
public void SetAsNeighbor(CSGEdge edge) { if (!neighbors.Exists((e) => e.id == edge.id)) neighbors.Add(edge); }
// clone a model and transform its verts and vinfos (scraps any WIP intersection info) public CSGModel CloneAndTransform(ModelUtil.CopyAndTransformVert vertCopier, ModelUtil.CopyAndTransformVInfo vinfoCopier) { CSGModel result = new CSGModel(); Dictionary <long, CSGVertex> vertexMapping = new Dictionary <long, CSGVertex>(); Dictionary <long, CSGEdge> edgeMapping = new Dictionary <long, CSGEdge>(); Dictionary <long, CSGShape> shapeMapping = new Dictionary <long, CSGShape>(); Dictionary <long, CSGSourceTriangle> triangleMapping = new Dictionary <long, CSGSourceTriangle>(); foreach (CSGVertex vert in vertices) { CSGVertex v = new CSGVertex(); vertexMapping[vert.id] = v; result.vertices.Add(v); } foreach (CSGEdge edge in edges) { CSGEdge e = new CSGEdge(); edgeMapping[edge.id] = e; result.edges.Add(e); } foreach (CSGShape shape in shapes) { CSGShape s = new CSGShape(); shapeMapping[shape.id] = s; result.shapes.Add(s); } foreach (CSGSourceTriangle triangle in sourceTriangles) { CSGSourceTriangle t = new CSGSourceTriangle(); triangleMapping[triangle.id] = t; result.sourceTriangles.Add(t); } foreach (CSGVertex iVertex in vertices) { CSGVertex rVertex = vertexMapping[iVertex.id]; if (iVertex.parentTriangle != null) { rVertex.parentTriangle = triangleMapping[iVertex.parentTriangle.id]; } vertCopier(iVertex.position, out rVertex.position); foreach (CSGEdge edge in iVertex.neighbors) { rVertex.neighbors.Add(edgeMapping[edge.id]); } } foreach (CSGEdge iEdge in edges) { CSGEdge rEdge = edgeMapping[iEdge.id]; if (iEdge.parentTriangle != null) { rEdge.parentTriangle = triangleMapping[iEdge.parentTriangle.id]; } for (int i = 0; i < 2; i++) { rEdge.endpoints[i] = vertexMapping[iEdge.endpoints[i].id]; if (iEdge.separatedShapes[i] != null) { rEdge.separatedShapes[i] = shapeMapping[iEdge.separatedShapes[i].id]; } } } foreach (CSGSourceTriangle iTriangle in sourceTriangles) { CSGSourceTriangle rTriangle = triangleMapping[iTriangle.id]; for (int i = 0; i < 3; i++) { rTriangle.sourceVerts[i] = vertexMapping[iTriangle.sourceVerts[i].id]; } foreach (long key in iTriangle.vertexVInfos.Keys) { VInfo vinfo; vinfoCopier(iTriangle.vertexVInfos[key], out vinfo); rTriangle.vertexVInfos[key] = vinfo; } } foreach (CSGShape iShape in shapes) { CSGShape rShape = shapeMapping[iShape.id]; rShape.parentTriangle = triangleMapping[iShape.parentTriangle.id]; foreach (CSGVertex vert in iShape.boundary) { rShape.boundary.Add(vertexMapping[vert.id]); } foreach (List <CSGVertex> iHole in iShape.holes) { List <CSGVertex> rHole = new List <CSGVertex>(); foreach (CSGVertex vert in iHole) { rHole.Add(vertexMapping[vert.id]); } rShape.holes.Add(rHole); } foreach (CSGEdge iEdge in iShape.edges) { rShape.edges.Add(edgeMapping[iEdge.id]); } } return(result); }