| 78 | } |
| 79 | |
| 80 | void CSG::Mesh::Add(const Mesh* other) |
| 81 | { |
| 82 | ASSERT(this != other && other); |
| 83 | |
| 84 | // Cache data |
| 85 | int32 baseIndexVertices = _vertices.Count(); |
| 86 | int32 baseIndexSurfaces = _surfaces.Count(); |
| 87 | int32 baseIndexEdges = _edges.Count(); |
| 88 | int32 baseIndexPolygons = _polygons.Count(); |
| 89 | auto oVertices = other->GetVertices(); |
| 90 | auto oSurfaces = other->GetSurfaces(); |
| 91 | auto oEdges = other->GetEdges(); |
| 92 | auto oPolygons = other->GetPolygons(); |
| 93 | auto oMeta = &other->_brushesMeta; |
| 94 | |
| 95 | // Clone vertices |
| 96 | for (int32 i = 0; i < oVertices->Count(); i++) |
| 97 | { |
| 98 | _vertices.Add(oVertices->At(i)); |
| 99 | } |
| 100 | |
| 101 | // Clone surfaces |
| 102 | for (int32 i = 0; i < oSurfaces->Count(); i++) |
| 103 | { |
| 104 | _surfaces.Add(oSurfaces->At(i)); |
| 105 | } |
| 106 | |
| 107 | // Clone edges |
| 108 | for (int32 i = 0; i < oEdges->Count(); i++) |
| 109 | { |
| 110 | HalfEdge edge = oEdges->At(i); |
| 111 | edge.PolygonIndex += baseIndexPolygons; |
| 112 | edge.TwinIndex += baseIndexEdges; |
| 113 | edge.NextIndex += baseIndexEdges; |
| 114 | edge.VertexIndex += baseIndexVertices; |
| 115 | _edges.Add(edge); |
| 116 | } |
| 117 | |
| 118 | // Clone polygons |
| 119 | for (int32 i = 0; i < oPolygons->Count(); i++) |
| 120 | { |
| 121 | Polygon polygon = oPolygons->At(i); |
| 122 | polygon.SurfaceIndex += baseIndexSurfaces; |
| 123 | polygon.FirstEdgeIndex += baseIndexEdges; |
| 124 | _polygons.Add(polygon); |
| 125 | } |
| 126 | |
| 127 | // Clone meta |
| 128 | for (int32 i = 0; i < oMeta->Count(); i++) |
| 129 | { |
| 130 | BrushMeta meta = oMeta->At(i); |
| 131 | meta.StartSurfaceIndex += baseIndexSurfaces; |
| 132 | _brushesMeta.Add(meta); |
| 133 | } |
| 134 | |
| 135 | // Increase bounds |
| 136 | _bounds.Add(other->GetBounds()); |
| 137 | } |