public override bool GetIntersectionWithBoundingFrustum(ref BoundingFrustum boundingFrustum) { ContainmentType con = boundingFrustum.Contains(WorldAABB); if (con == ContainmentType.Contains) { return true; } if (con == ContainmentType.Intersects) { BoundingSphere sphere = boundingFrustum.ToBoundingSphere(HelperFrustumCorners); // Get min and max cell coordinate where boundingBox can fit BoundingBox sphereBoundingBox = BoundingBoxHelper.InitialBox; BoundingBoxHelper.AddSphere(sphere, ref sphereBoundingBox); MyMwcVector3Int cellCoordMin = GetDataCellCoordinateFromMeters(ref sphereBoundingBox.Min); MyMwcVector3Int cellCoordMax = GetDataCellCoordinateFromMeters(ref sphereBoundingBox.Max); // Fix min and max cell coordinates so they don't overlap the voxelmap FixDataCellCoord(ref cellCoordMin); FixDataCellCoord(ref cellCoordMax); MyMwcVector3Int cellCoord; for (cellCoord.X = cellCoordMin.X; cellCoord.X <= cellCoordMax.X; cellCoord.X++) { for (cellCoord.Y = cellCoordMin.Y; cellCoord.Y <= cellCoordMax.Y; cellCoord.Y++) { for (cellCoord.Z = cellCoordMin.Z; cellCoord.Z <= cellCoordMax.Z; cellCoord.Z++) { // If no overlap between bounding pitch of data cell and the sphere BoundingBox dataCellBoundingBox; GetDataCellBoundingBox(ref cellCoord, out dataCellBoundingBox); if (MyUtils.IsBoxIntersectingSphere(ref dataCellBoundingBox, ref sphere) == false) continue; // Get cell from cache. If not there, precalc it and store in the cache. // If null is returned, we know that cell doesn't contain any triangleVertexes so we don't need to do intersections. MyVoxelCacheCellData cachedDataCell = null; using (MyVoxelCacheData.Locker.AcquireSharedUsing()) { cachedDataCell = MyVoxelCacheData.GetCell(this, ref cellCoord, true); if (cachedDataCell == null) continue; for (int i = 0; i < cachedDataCell.VoxelTrianglesCount; i++) { MyVoxelTriangle voxelTriangle = cachedDataCell.VoxelTriangles[i]; MyVoxelVertex voxelVertex0 = cachedDataCell.VoxelVertices[voxelTriangle.VertexIndex0]; MyVoxelVertex voxelVertex1 = cachedDataCell.VoxelVertices[voxelTriangle.VertexIndex1]; MyVoxelVertex voxelVertex2 = cachedDataCell.VoxelVertices[voxelTriangle.VertexIndex2]; if (boundingFrustum.Contains(voxelVertex0.Position + PositionLeftBottomCorner) == ContainmentType.Contains) return true; if (boundingFrustum.Contains(voxelVertex1.Position + PositionLeftBottomCorner) == ContainmentType.Contains) return true; if (boundingFrustum.Contains(voxelVertex2.Position + PositionLeftBottomCorner) == ContainmentType.Contains) return true; } } } } } } return false; }