| 227 | }; |
| 228 | |
| 229 | static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z, const Vector3 &voxelsize, const Face3 &p_face) { |
| 230 | AABB aabb(Vector3(x, y, z), Vector3(len_x, len_y, len_z)); |
| 231 | aabb.position = aabb.position * voxelsize; |
| 232 | aabb.size = aabb.size * voxelsize; |
| 233 | |
| 234 | if (!p_face.intersects_aabb(aabb)) { |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | if (len_x == 1 && len_y == 1 && len_z == 1) { |
| 239 | p_cell_status[x][y][z] = _CELL_SOLID; |
| 240 | return; |
| 241 | } |
| 242 | |
| 243 | int div_x = len_x > 1 ? 2 : 1; |
| 244 | int div_y = len_y > 1 ? 2 : 1; |
| 245 | int div_z = len_z > 1 ? 2 : 1; |
| 246 | |
| 247 | #define SPLIT_DIV(m_i, m_div, m_v, m_len_v, m_new_v, m_new_len_v) \ |
| 248 | if (m_div == 1) { \ |
| 249 | m_new_v = m_v; \ |
| 250 | m_new_len_v = 1; \ |
| 251 | } else if (m_i == 0) { \ |
| 252 | m_new_v = m_v; \ |
| 253 | m_new_len_v = m_len_v / 2; \ |
| 254 | } else { \ |
| 255 | m_new_v = m_v + m_len_v / 2; \ |
| 256 | m_new_len_v = m_len_v - m_len_v / 2; \ |
| 257 | } |
| 258 | |
| 259 | int new_x; |
| 260 | int new_len_x; |
| 261 | int new_y; |
| 262 | int new_len_y; |
| 263 | int new_z; |
| 264 | int new_len_z; |
| 265 | |
| 266 | for (int i = 0; i < div_x; i++) { |
| 267 | SPLIT_DIV(i, div_x, x, len_x, new_x, new_len_x); |
| 268 | |
| 269 | for (int j = 0; j < div_y; j++) { |
| 270 | SPLIT_DIV(j, div_y, y, len_y, new_y, new_len_y); |
| 271 | |
| 272 | for (int k = 0; k < div_z; k++) { |
| 273 | SPLIT_DIV(k, div_z, z, len_z, new_z, new_len_z); |
| 274 | |
| 275 | _plot_face(p_cell_status, new_x, new_y, new_z, new_len_x, new_len_y, new_len_z, voxelsize, p_face); |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | #undef SPLIT_DIV |
| 281 | } |
| 282 | |
| 283 | static inline void _mark_outside(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z) { |
| 284 | if (p_cell_status[x][y][z] & 3) { |
no test coverage detected