private void DrawOctree(VoxelizingOctree o) { GL.Enable(EnableCap.DepthTest); if (showIntersectingCells) { o.Root.Draw(o.MaxLevels - 1, CellStatus.Intersecting, new Vector4(0.25f, 1.0f, 0.25f, 1.0f), 1.0f); } if (showIntersectingBoundsCells) { o.Root.Draw(o.MaxLevels - 1, CellStatus.IntersectingBounds, new Vector4(1.0f, 1.0f, 0.0f, 1.0f), 1.0f); } for (int i = 0; i < m_visualizedMaxLevel; i++) { if (showUnknownCells) { o.Root.Draw(i, CellStatus.Unknown, new Vector4(1.0f, 1.0f, 1.0f, 1.0f), 1.0f); } if (showOutsideCells) { o.Root.Draw(i, CellStatus.Outside, new Vector4(1.0f, 0.25f, 0.25f, 1.0f), 1.0f); } if (showInsideCells) { o.Root.Draw(i, CellStatus.Inside, new Vector4(0.25f, 0.25f, 1.0f, 1.0f), 1.0f); } } }
public VoxelizingOctreeCell(VoxelizingOctree tree, VoxelizingOctreeCell root, Vector3 center, float length, int level) { Tree = tree; Root = root; Center = center; Length = length; Level = level; float half_length = length / 2.0f; Bounds = new AABBf(); Bounds.MinX = center.X - half_length; Bounds.MinY = center.Y - half_length; Bounds.MinZ = center.Z - half_length; Bounds.MaxX = center.X + half_length; Bounds.MaxY = center.Y + half_length; Bounds.MaxZ = center.Z + half_length; VoxelBounds = new AABBi( (int)Math.Round((Bounds.MinX - tree.VoxelBounds.MinX) / tree.SmallestVoxelSideLength, MidpointRounding.AwayFromZero), (int)Math.Round((Bounds.MinY - tree.VoxelBounds.MinY) / tree.SmallestVoxelSideLength, MidpointRounding.AwayFromZero), (int)Math.Round((Bounds.MinZ - tree.VoxelBounds.MinZ) / tree.SmallestVoxelSideLength, MidpointRounding.AwayFromZero), (int)Math.Round((Bounds.MaxX - tree.VoxelBounds.MinX) / tree.SmallestVoxelSideLength, MidpointRounding.AwayFromZero), (int)Math.Round((Bounds.MaxY - tree.VoxelBounds.MinY) / tree.SmallestVoxelSideLength, MidpointRounding.AwayFromZero), (int)Math.Round((Bounds.MaxZ - tree.VoxelBounds.MinZ) / tree.SmallestVoxelSideLength, MidpointRounding.AwayFromZero)); }
private void CreateSolidVolume(VoxelizingOctree tree, VoxelizingOctreeCell cell, Vector3i volumeLength) { if (cell.Status == CellStatus.Inside) { int min_x = cell.VoxelBounds.MinX + tree.WorldVoxelOffset.X; int min_y = cell.VoxelBounds.MinY + tree.WorldVoxelOffset.Y; int min_z = cell.VoxelBounds.MinZ + tree.WorldVoxelOffset.Z; int max_x = cell.VoxelBounds.MaxX + tree.WorldVoxelOffset.X; int max_y = cell.VoxelBounds.MaxY + tree.WorldVoxelOffset.Y; int max_z = cell.VoxelBounds.MaxZ + tree.WorldVoxelOffset.Z; for (int x = min_x; x < max_x; x++) { for (int y = min_y; y < max_y; y++) { for (int z = min_z; z < max_z; z++) { SetVoxel(x, y, z, 1); } } } } foreach (var child in cell.Children) { CreateSolidVolume(tree, child, volumeLength); } }
public bool Intersects(ref Triangle triangle) { var boxhalfsize = new Vector3(Length / 2.0f, Length / 2.0f, Length / 2.0f); var boxcenter = new Vector3(Bounds.MinX + boxhalfsize.X, Bounds.MinY + boxhalfsize.Y, Bounds.MinZ + boxhalfsize.Z); //return VoxelizerCPU.IsTriangleCollidingWithVoxel(ref triangle, ref deltap, ref minpt); return(VoxelizingOctree.triBoxOverlap(ref boxcenter, ref boxhalfsize, ref triangle)); }
private void m_gl_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if (m_operations.Context == null) { return; } VoxelizingOctree o = m_operations.Context.Octree; switch (e.KeyChar) { case '-': case '_': m_visualizedMaxLevel = MathEx.Clamp(m_visualizedMaxLevel - 1, 0, o.MaxLevels); break; case '=': case '+': m_visualizedMaxLevel = MathEx.Clamp(m_visualizedMaxLevel + 1, 0, o.MaxLevels); break; case 'u': m_showUnknownVoxelMenu.Checked = !m_showUnknownVoxelMenu.Checked; break; case 'i': m_showInternalVoxelMenu.Checked = !m_showInternalVoxelMenu.Checked; break; case 'o': m_showExternalVoxelMenu.Checked = !m_showExternalVoxelMenu.Checked; break; case 'm': m_showOriginalMeshMenu.Checked = !m_showOriginalMeshMenu.Checked; break; } }
public VoxelField(VoxelizingOctree tree) { CellSize = new Vector3i( (int)Math.Ceiling((tree.VoxelSize.X + 1) / (double)VoxelCell.SizeX), (int)Math.Ceiling((tree.VoxelSize.Y + 1) / (double)VoxelCell.SizeY), (int)Math.Ceiling((tree.VoxelSize.Z + 1) / (double)VoxelCell.SizeZ)); VoxelSize = tree.VoxelSize; // Initialize the cell tables, but don't actually fill in the arrays with voxel cell instances // until we know those cells will be filled. Cells = new VoxelCell[CellSize.X][][]; for (int x = 0; x < Cells.Length; x++) { Cells[x] = new VoxelCell[CellSize.Y][]; for (int y = 0; y < Cells[x].Length; y++) { Cells[x][y] = new VoxelCell[CellSize.Z]; } } CreateSolidVolume(tree, tree.Root, tree.VoxelSize); }
private void DrawOctree(VoxelizingOctree o) { GL.Enable(EnableCap.DepthTest); if (showIntersectingCells) o.Root.Draw(o.MaxLevels - 1, CellStatus.Intersecting, new Vector4(0.25f, 1.0f, 0.25f, 1.0f), 1.0f); if (showIntersectingBoundsCells) o.Root.Draw(o.MaxLevels - 1, CellStatus.IntersectingBounds, new Vector4(1.0f, 1.0f, 0.0f, 1.0f), 1.0f); for (int i = 0; i < m_visualizedMaxLevel; i++) { if (showUnknownCells) o.Root.Draw(i, CellStatus.Unknown, new Vector4(1.0f, 1.0f, 1.0f, 1.0f), 1.0f); if (showOutsideCells) o.Root.Draw(i, CellStatus.Outside, new Vector4(1.0f, 0.25f, 0.25f, 1.0f), 1.0f); if (showInsideCells) o.Root.Draw(i, CellStatus.Inside, new Vector4(0.25f, 0.25f, 1.0f, 1.0f), 1.0f); } }