| 20 | } |
| 21 | |
| 22 | void CSG::Mesh::PerformOperation(Mesh* other) |
| 23 | { |
| 24 | ASSERT(other->_brushesMeta.Count() > 0); |
| 25 | |
| 26 | // Check if has more than one submeshes |
| 27 | if (other->_brushesMeta.Count() > 1) |
| 28 | { |
| 29 | // Just add all subbrushes |
| 30 | Add(other); |
| 31 | } |
| 32 | else |
| 33 | { |
| 34 | auto mode = other->_brushesMeta[0].Mode; |
| 35 | |
| 36 | // Switch between mesh operation mode |
| 37 | switch (mode) |
| 38 | { |
| 39 | case Mode::Additive: |
| 40 | { |
| 41 | // Check if both meshes do not intersect |
| 42 | if (AABB::IsOutside(_bounds, other->GetBounds())) // TODO: test every sub bounds not whole _bounds |
| 43 | { |
| 44 | // Add vertices to the mesh without any additional calculations |
| 45 | Add(other); |
| 46 | } |
| 47 | else |
| 48 | { |
| 49 | // Remove common part from other mesh and then combine them |
| 50 | //intersect(other, Remove, Keep); |
| 51 | Add(other); |
| 52 | |
| 53 | // TODO: ogarnac to bo to jest zle xD |
| 54 | } |
| 55 | } |
| 56 | break; |
| 57 | |
| 58 | case Mode::Subtractive: |
| 59 | { |
| 60 | // Check if both meshes do not intersect |
| 61 | if (AABB::IsOutside(_bounds, other->GetBounds())) // TODO: test every sub bounds not whole _bounds |
| 62 | { |
| 63 | // Do nothing |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | // Perform intersection operations |
| 68 | intersect(other, Remove, Keep); |
| 69 | other->intersect(this, Flip, Remove); |
| 70 | |
| 71 | // Merge meshes |
| 72 | Add(other); |
| 73 | } |
| 74 | } |
| 75 | break; |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |