private void coverVoxelsWithTriangleEdge(float3 A, float3 B) { int3 aVoxelIndex = VoxelUtility.PosToIndex3(A); int3 bVoxelIndex = VoxelUtility.PosToIndex3(B); int aVoxelIndex1 = VoxelUtility.Index3ToIndex1(aVoxelIndex); int bVoxeklndex1 = VoxelUtility.Index3ToIndex1(bVoxelIndex); float3 aVoxelCenter = VoxelUtility.Index3ToPos(aVoxelIndex); float3 bVoxelCenter = VoxelUtility.Index3ToPos(bVoxelIndex); if (aVoxelIndex.x == bVoxelIndex.x && aVoxelIndex.y == bVoxelIndex.y || aVoxelIndex.x == bVoxelIndex.x && aVoxelIndex.z == bVoxelIndex.z || aVoxelIndex.y == bVoxelIndex.y && aVoxelIndex.z == bVoxelIndex.z) { /*Same Grid or 6-neighbor*/ voxels.TryAdd(aVoxelIndex1, true); voxels.TryAdd(bVoxeklndex1, true); return; } if (aVoxelIndex.x == bVoxelIndex.x) { /*yz plane neighbor */ float2 xy = LinePlaneIntersect(A, B, 'z', 0.5f * (aVoxelCenter.z + bVoxelCenter.z)); float x = xy.x; float y = xy.y; //if (!(A.x <= x && x <= B.x || B.x <= x && x <= A.x)){ // Debug.Log(A + "<>" + B + "<>" + aVoxelCenter + "<>" + bVoxelCenter + " -> " + x); //} //Debug.Assert(A.x <= x && x <= B.x || B.x <= x && x <= A.x); int connector; if (math.abs(y - A.y) < math.abs(y - B.y)) { connector = VoxelUtility.Index3ToIndex1(new int3(aVoxelIndex.x, aVoxelIndex.y, bVoxelIndex.z)); } else { connector = VoxelUtility.Index3ToIndex1(new int3(aVoxelIndex.x, bVoxelIndex.y, aVoxelIndex.z)); } voxels.TryAdd(connector, true); return; } if (aVoxelIndex.y == bVoxelIndex.y) { /*xz plane neighbor */ float2 yz = LinePlaneIntersect(A, B, 'x', 0.5f * (aVoxelCenter.x + bVoxelCenter.x)); float y = yz.x; float z = yz.y; //Debug.Assert(A.y <= y && y <= B.y || B.y <= y && y <= A.y); int connector; if (math.abs(z - A.z) < math.abs(z - B.z)) { connector = VoxelUtility.Index3ToIndex1(new int3(bVoxelIndex.x, aVoxelIndex.y, aVoxelIndex.z)); } else { connector = VoxelUtility.Index3ToIndex1(new int3(aVoxelIndex.x, aVoxelIndex.y, bVoxelIndex.z)); } voxels.TryAdd(connector, true); return; } if (aVoxelIndex.z == bVoxelIndex.z) { /*xy plane neighbor */ float2 xz = LinePlaneIntersect(A, B, 'y', 0.5f * (aVoxelCenter.y + bVoxelCenter.y)); float x = xz.x; float z = xz.y; //Debug.Assert(A.z <= z && z <= B.z || B.z <= z && z <= A.z); int connector; if (math.abs(x - A.x) < math.abs(x - B.x)) { connector = VoxelUtility.Index3ToIndex1(new int3(aVoxelIndex.x, bVoxelIndex.y, aVoxelIndex.z)); } else { connector = VoxelUtility.Index3ToIndex1(new int3(bVoxelIndex.x, aVoxelIndex.y, aVoxelIndex.z)); } voxels.TryAdd(connector, true); return; } /*3D diagonal */ float2 _yz = LinePlaneIntersect(A, B, 'x', 0.5f * (aVoxelCenter.x + bVoxelCenter.x)); if (RectContains(new float2(aVoxelCenter.y, aVoxelCenter.z), _yz)) { /*baa */ voxels.TryAdd(VoxelUtility.Index3ToIndex1(new int3(bVoxelIndex.x, aVoxelIndex.y, aVoxelIndex.z)), true); } else { if (RectContains(new float2(bVoxelCenter.y, bVoxelCenter.z), _yz)) { /*abb */ voxels.TryAdd(VoxelUtility.Index3ToIndex1(new int3(aVoxelIndex.x, bVoxelIndex.y, bVoxelIndex.z)), true); } } float2 _xz = LinePlaneIntersect(A, B, 'y', 0.5f * (aVoxelCenter.y + bVoxelCenter.y)); if (RectContains(new float2(aVoxelCenter.x, aVoxelCenter.z), _xz)) { /*aba */ voxels.TryAdd(VoxelUtility.Index3ToIndex1(new int3(aVoxelIndex.x, bVoxelIndex.y, aVoxelIndex.z)), true); } else { if (RectContains(new float2(bVoxelCenter.x, bVoxelCenter.z), _xz)) { /*bab */ voxels.TryAdd(VoxelUtility.Index3ToIndex1(new int3(bVoxelIndex.x, aVoxelIndex.y, bVoxelIndex.z)), true); } } float2 _xy = LinePlaneIntersect(A, B, 'z', 0.5f * (aVoxelCenter.z + bVoxelCenter.z)); if (RectContains(new float2(aVoxelCenter.x, aVoxelCenter.y), _xy)) { /*aab */ voxels.TryAdd(VoxelUtility.Index3ToIndex1(new int3(aVoxelIndex.x, aVoxelIndex.y, bVoxelIndex.z)), true); } else { if (RectContains(new float2(bVoxelCenter.x, bVoxelCenter.y), _xy)) { /*bba */ voxels.TryAdd(VoxelUtility.Index3ToIndex1(new int3(bVoxelIndex.x, bVoxelIndex.y, aVoxelIndex.z)), true); } } }