diff --git a/src/cpu_voxelizer.cpp b/src/cpu_voxelizer.cpp index af695d5..277735b 100644 --- a/src/cpu_voxelizer.cpp +++ b/src/cpu_voxelizer.cpp @@ -130,9 +130,9 @@ namespace cpu_voxelizer { n_zx_e1 = -n_zx_e1; n_zx_e2 = -n_zx_e2; } - float d_xz_e0 = (-1.0f * glm::dot(n_zx_e0, glm::vec2(v0.z, v0.x))) + glm::max(0.0f, info.unit.x * n_zx_e0[0]) + glm::max(0.0f, info.unit.z * n_zx_e0[1]); - float d_xz_e1 = (-1.0f * glm::dot(n_zx_e1, glm::vec2(v1.z, v1.x))) + glm::max(0.0f, info.unit.x * n_zx_e1[0]) + glm::max(0.0f, info.unit.z * n_zx_e1[1]); - float d_xz_e2 = (-1.0f * glm::dot(n_zx_e2, glm::vec2(v2.z, v2.x))) + glm::max(0.0f, info.unit.x * n_zx_e2[0]) + glm::max(0.0f, info.unit.z * n_zx_e2[1]); + float d_xz_e0 = (-1.0f * glm::dot(n_zx_e0, glm::vec2(v0.z, v0.x))) + glm::max(0.0f, info.unit.z * n_zx_e0[0]) + glm::max(0.0f, info.unit.x * n_zx_e0[1]); + float d_xz_e1 = (-1.0f * glm::dot(n_zx_e1, glm::vec2(v1.z, v1.x))) + glm::max(0.0f, info.unit.z * n_zx_e1[0]) + glm::max(0.0f, info.unit.x * n_zx_e1[1]); + float d_xz_e2 = (-1.0f * glm::dot(n_zx_e2, glm::vec2(v2.z, v2.x))) + glm::max(0.0f, info.unit.z * n_zx_e2[0]) + glm::max(0.0f, info.unit.x * n_zx_e2[1]); // test possible grid boxes for overlap for (int z = t_bbox_grid.min.z; z <= t_bbox_grid.max.z; z++) { diff --git a/src/util.h b/src/util.h index 222a87f..6135c02 100644 --- a/src/util.h +++ b/src/util.h @@ -102,9 +102,9 @@ inline AABox createMeshBBCube(AABox box) { // Suspected cause: If a triangle is axis-aligned and lies perfectly on a voxel edge, it sometimes gets counted / not counted // Probably due to a numerical instability (division by zero?) // Ugly fix: we pad the bounding box on all sides by 1/10001th of its total length, bringing all triangles ever so slightly off-grid - glm::vec3 epsilon = (answer.max - answer.min) / 10001.0f; - answer.min -= epsilon; - answer.max += epsilon; + // glm::vec3 epsilon = (answer.max - answer.min) / 10001.0f; + // answer.min -= epsilon; + // answer.max += epsilon; return answer; } diff --git a/src/voxelize.cu b/src/voxelize.cu index aac73c9..f30fa0a 100644 --- a/src/voxelize.cu +++ b/src/voxelize.cu @@ -128,9 +128,9 @@ __global__ void voxelize_triangle(voxinfo info, float* triangle_data, unsigned i n_zx_e1 = -n_zx_e1; n_zx_e2 = -n_zx_e2; } - float d_xz_e0 = (-1.0f * glm::dot(n_zx_e0, glm::vec2(v0.z, v0.x))) + glm::max(0.0f, info.unit.x*n_zx_e0[0]) + glm::max(0.0f, info.unit.z*n_zx_e0[1]); - float d_xz_e1 = (-1.0f * glm::dot(n_zx_e1, glm::vec2(v1.z, v1.x))) + glm::max(0.0f, info.unit.x*n_zx_e1[0]) + glm::max(0.0f, info.unit.z*n_zx_e1[1]); - float d_xz_e2 = (-1.0f * glm::dot(n_zx_e2, glm::vec2(v2.z, v2.x))) + glm::max(0.0f, info.unit.x*n_zx_e2[0]) + glm::max(0.0f, info.unit.z*n_zx_e2[1]); + float d_xz_e0 = (-1.0f * glm::dot(n_zx_e0, glm::vec2(v0.z, v0.x))) + glm::max(0.0f, info.unit.z*n_zx_e0[0]) + glm::max(0.0f, info.unit.x*n_zx_e0[1]); + float d_xz_e1 = (-1.0f * glm::dot(n_zx_e1, glm::vec2(v1.z, v1.x))) + glm::max(0.0f, info.unit.z*n_zx_e1[0]) + glm::max(0.0f, info.unit.x*n_zx_e1[1]); + float d_xz_e2 = (-1.0f * glm::dot(n_zx_e2, glm::vec2(v2.z, v2.x))) + glm::max(0.0f, info.unit.z*n_zx_e2[0]) + glm::max(0.0f, info.unit.x*n_zx_e2[1]); // test possible grid boxes for overlap for (int z = t_bbox_grid.min.z; z <= t_bbox_grid.max.z; z++){ diff --git a/test_models/mechanical.STL b/test_models/mechanical.STL new file mode 100755 index 0000000..6b489e9 Binary files /dev/null and b/test_models/mechanical.STL differ