// 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; }
// clone a model and transform its vinfos (scraps any WIP intersection info) public CSGModel CloneModel(ModelUtil.CopyAndTransformVInfo vinfoCopier) { return CloneAndTransform(new ModelUtil.CopyAndTransformVert( (Vec3 basis, out Vec3 result) => { result = basis; }), vinfoCopier); }