private static void DrawSparseOctrees(ref Matrix worldMatrix, Color color, MyVoxelDebugDrawMode mode, Dictionary <UInt64, IMyOctreeLeafNode> octree) { var camera = Sandbox.Game.World.MySector.MainCamera; if (camera == null) { return; } var targetPoint = camera.Position + camera.ForwardVector * 10; targetPoint = (Vector3)Vector3D.Transform(targetPoint, MatrixD.Invert(worldMatrix)); using (var batch = VRageRender.MyRenderProxy.DebugDrawBatchAABB(worldMatrix, color, true, true)) { MyCellCoord cell = new MyCellCoord(); foreach (var entry in octree) { var leaf = entry.Value as MyMicroOctreeLeaf; if (leaf != null) { cell.SetUnpack(entry.Key); Vector3D min = (cell.CoordInLod << LeafLodCount) * MyVoxelConstants.VOXEL_SIZE_IN_METRES; Vector3D max = min + LeafSizeInVoxels * MyVoxelConstants.VOXEL_SIZE_IN_METRES; if (targetPoint.IsInsideInclusive(ref min, ref max)) { leaf.DebugDraw(batch, min, mode); } } } } }
public virtual void DebugDraw(MyVoxelDebugDrawMode mode, int modeArg) { }
public virtual void DebugDraw(MyVoxelBase voxelMap, MyVoxelDebugDrawMode mode) { }
public override void DebugDraw(MyVoxelBase referenceVoxelMap, MyVoxelDebugDrawMode mode) { Matrix worldMatrix = Matrix.CreateTranslation(referenceVoxelMap.PositionLeftBottomCorner); Color color; color = Color.CornflowerBlue; color.A = 25; switch (mode) { case MyVoxelDebugDrawMode.Content_MicroNodes: case MyVoxelDebugDrawMode.Content_MicroNodesScaled: DrawSparseOctrees(ref worldMatrix, color, mode, m_contentLeaves); break; case MyVoxelDebugDrawMode.Content_MacroNodes: DrawNodes(ref worldMatrix, color, m_contentNodes); break; case MyVoxelDebugDrawMode.Content_MacroLeaves: DrawLeaves(ref worldMatrix, color, m_contentLeaves); break; case MyVoxelDebugDrawMode.Content_MacroScaled: DrawScaledNodes(ref worldMatrix, color, m_contentNodes); break; case MyVoxelDebugDrawMode.Materials_MacroNodes: DrawNodes(ref worldMatrix, color, m_materialNodes); break; case MyVoxelDebugDrawMode.Materials_MacroLeaves: DrawLeaves(ref worldMatrix, color, m_materialLeaves); break; case MyVoxelDebugDrawMode.Content_DataProvider: if (m_dataProvider != null) { var world = MatrixD.CreateTranslation(referenceVoxelMap.PositionLeftBottomCorner); m_dataProvider.DebugDraw(ref world); } break; } if (m_tmpResetLeaves.Count > 0) { Color clr = Color.GreenYellow; MySimpleObjectDraw.DrawTransparentBox(ref MatrixD.Identity, ref m_tmpResetLeavesBoundingBox, ref clr, MySimpleObjectRasterizer.Wireframe, 1, 0.04f); clr.A = 25; DrawLeaves(ref worldMatrix, clr, m_tmpResetLeaves); } if (MyFakes.ENABLE_DRAW_VOXEL_STORAGE_PLAYER_POSITION) { MyCharacter character = MySession.Static.CameraController as MyCharacter; if (character != null) { Vector3D worldPos = character.WorldMatrix.Translation; Vector3D localPos; MyVoxelCoordSystems.WorldPositionToLocalPosition(referenceVoxelMap.PositionLeftBottomCorner, ref worldPos, out localPos); localPos = Vector3I.Floor(localPos / 16) * 16; Vector3D outWorldPosMin; MyVoxelCoordSystems.LocalPositionToWorldPosition(referenceVoxelMap.PositionLeftBottomCorner, ref localPos, out outWorldPosMin); BoundingBoxD box = new BoundingBoxD(outWorldPosMin, outWorldPosMin + new Vector3D(16, 16, 16)); Color clr = Color.Orange; MySimpleObjectDraw.DrawTransparentBox(ref MatrixD.Identity, ref box, ref clr, MySimpleObjectRasterizer.Wireframe, 1, 0.04f); } } }
private static void DrawSparseOctrees(ref Matrix worldMatrix, Color color, MyVoxelDebugDrawMode mode, Dictionary<UInt64, IMyOctreeLeafNode> octree) { var camera = Sandbox.Game.World.MySector.MainCamera; if (camera == null) return; var targetPoint = camera.Position + camera.ForwardVector * 10; targetPoint = (Vector3)Vector3D.Transform(targetPoint, MatrixD.Invert(worldMatrix)); using (var batch = VRageRender.MyRenderProxy.DebugDrawBatchAABB(worldMatrix, color, true, true)) { MyCellCoord cell = new MyCellCoord(); foreach (var entry in octree) { var leaf = entry.Value as MyMicroOctreeLeaf; if (leaf != null) { cell.SetUnpack(entry.Key); Vector3D min = (cell.CoordInLod << LeafLodCount) * MyVoxelConstants.VOXEL_SIZE_IN_METRES; Vector3D max = min + LeafSizeInVoxels * MyVoxelConstants.VOXEL_SIZE_IN_METRES; if (targetPoint.IsInsideInclusive(ref min, ref max)) leaf.DebugDraw(batch, min, mode); } } } }
internal void DebugDraw(MyDebugDrawBatchAABB batch, Vector3 worldPos, MyVoxelDebugDrawMode mode) { m_octree.DebugDraw(batch, worldPos, mode); }
void IMyStorage.DebugDraw(MyVoxelDebugDrawMode mode, int modeArg) { m_trueStorage.DebugDraw(mode, modeArg); }
public override void DebugDraw(MyVoxelDebugDrawMode mode, int modeArg) { switch (mode) { case MyVoxelDebugDrawMode.EmptyCells: DebugDrawCells(MyVoxelRangeType.EMPTY); break; case MyVoxelDebugDrawMode.FullCells: DebugDrawCells(MyVoxelRangeType.FULL); break; case MyVoxelDebugDrawMode.MixedCells: DebugDrawCells(MyVoxelRangeType.MIXED); break; } }
internal unsafe void DebugDraw(VRageRender.MyDebugDrawBatchAABB batch, Vector3 worldPos, MyVoxelDebugDrawMode mode) { switch (mode) { case MyVoxelDebugDrawMode.Content_MicroNodes: foreach (var entry in m_nodes) { Vector3I childOffset; BoundingBoxD bb; MyCellCoord cell = new MyCellCoord(); cell.SetUnpack(entry.Key); var data = entry.Value; for (int i = 0; i < MyOctreeNode.CHILD_COUNT; ++i) { if (data.HasChild(i) && cell.Lod != 0) { continue; } ComputeChildCoord(i, out childOffset); var childPos = (cell.CoordInLod << (cell.Lod + 1)) + (childOffset << cell.Lod); bb.Min = worldPos + childPos * MyVoxelConstants.VOXEL_SIZE_IN_METRES; bb.Max = bb.Min + MyVoxelConstants.VOXEL_SIZE_IN_METRES * (1 << cell.Lod); batch.Add(ref bb); } } break; case MyVoxelDebugDrawMode.Content_MicroNodesScaled: foreach (var entry in m_nodes) { MyCellCoord cell = new MyCellCoord(); Vector3I childOffset; BoundingBoxD bb; cell.SetUnpack(entry.Key); var data = entry.Value; for (int i = 0; i < MyOctreeNode.CHILD_COUNT; ++i) { if (data.HasChild(i)) { continue; } ComputeChildCoord(i, out childOffset); float ratio = data.GetData(i) / MyVoxelConstants.VOXEL_CONTENT_FULL_FLOAT; if (ratio == 0f) { continue; } ratio = (float)Math.Pow((double)ratio * MyVoxelConstants.VOXEL_VOLUME_IN_METERS, 0.3333); var childPos = (cell.CoordInLod << (cell.Lod + 1)) + (childOffset << cell.Lod); var lodSize = MyVoxelConstants.VOXEL_SIZE_IN_METRES * (1 << cell.Lod); var center = worldPos + childPos * MyVoxelConstants.VOXEL_SIZE_IN_METRES + 0.5f * lodSize; bb.Min = center - 0.5f * ratio * lodSize; bb.Max = center + 0.5f * ratio * lodSize; batch.Add(ref bb); } } break; } }
internal unsafe void DebugDraw(IMyDebugDrawBatchAabb batch, Vector3 worldPos, MyVoxelDebugDrawMode mode) { Color?nullable; if (mode == MyVoxelDebugDrawMode.Content_MicroNodes) { foreach (KeyValuePair <uint, MyOctreeNode> pair in this.m_nodes) { MyCellCoord coord = new MyCellCoord(); coord.SetUnpack(pair.Key); MyOctreeNode node = pair.Value; for (int i = 0; i < 8; i++) { if (!node.HasChild(i) || (coord.Lod == 0)) { Vector3I vectori; BoundingBoxD xd; this.ComputeChildCoord(i, out vectori); Vector3I vectori2 = (Vector3I)((coord.CoordInLod << (coord.Lod + 1)) + (vectori << coord.Lod)); xd.Min = worldPos + (vectori2 * 1f); BoundingBoxD *xdPtr1 = (BoundingBoxD *)ref xd; xdPtr1->Max = xd.Min + (1f * (1 << (coord.Lod & 0x1f))); if (node.GetData(i) != 0) { nullable = null; batch.Add(ref xd, nullable); } } } } return; } else if (mode != MyVoxelDebugDrawMode.Content_MicroNodesScaled) { return; } foreach (KeyValuePair <uint, MyOctreeNode> pair2 in this.m_nodes) { MyCellCoord coord2 = new MyCellCoord(); coord2.SetUnpack(pair2.Key); MyOctreeNode node2 = pair2.Value; for (int i = 0; i < 8; i++) { if (!node2.HasChild(i)) { Vector3I vectori3; this.ComputeChildCoord(i, out vectori3); float num3 = ((float)node2.GetData(i)) / 255f; if (num3 != 0f) { BoundingBoxD xd2; num3 = (float)Math.Pow(num3 * 1.0, 0.3333); Vector3I vectori4 = (Vector3I)((coord2.CoordInLod << (coord2.Lod + 1)) + (vectori3 << coord2.Lod)); float num4 = 1f * (1 << (coord2.Lod & 0x1f)); Vector3 vector = (worldPos + (vectori4 * 1f)) + (0.5f * num4); xd2.Min = vector - ((0.5f * num3) * num4); xd2.Max = vector + ((0.5f * num3) * num4); nullable = null; batch.Add(ref xd2, nullable); } } } } }
internal void DebugDraw(IMyDebugDrawBatchAabb batch, Vector3 worldPos, MyVoxelDebugDrawMode mode) { this.m_octree.DebugDraw(batch, worldPos, mode); }
public override void DebugDraw(MyVoxelBase referenceVoxelMap, MyVoxelDebugDrawMode mode) { Matrix worldMatrix = referenceVoxelMap.WorldMatrix; //Matrix.CreateTranslation(referenceVoxelMap.PositionLeftBottomCorner); worldMatrix.Translation = referenceVoxelMap.PositionLeftBottomCorner; Color color; color = Color.CornflowerBlue; color.A = 25; switch (mode) { case MyVoxelDebugDrawMode.Content_MicroNodes: case MyVoxelDebugDrawMode.Content_MicroNodesScaled: DrawSparseOctrees(ref worldMatrix, color, mode, m_contentLeaves); break; case MyVoxelDebugDrawMode.Content_MacroNodes: DrawNodes(ref worldMatrix, color, m_contentNodes); break; case MyVoxelDebugDrawMode.Content_MacroLeaves: DrawLeaves(ref worldMatrix, color, m_contentLeaves); break; case MyVoxelDebugDrawMode.Content_MacroScaled: DrawScaledNodes(ref worldMatrix, color, m_contentNodes); break; case MyVoxelDebugDrawMode.Materials_MacroNodes: DrawNodes(ref worldMatrix, color, m_materialNodes); break; case MyVoxelDebugDrawMode.Materials_MacroLeaves: DrawLeaves(ref worldMatrix, color, m_materialLeaves); break; case MyVoxelDebugDrawMode.Content_DataProvider: if (m_dataProvider != null) { var world = MatrixD.CreateTranslation(referenceVoxelMap.PositionLeftBottomCorner); m_dataProvider.DebugDraw(ref world); } break; case MyVoxelDebugDrawMode.FullCells: { //MyStorageDataCache m_cache = new MyStorageDataCache(); var size = referenceVoxelMap.Storage.Size; //m_temporaryCache.Resize(Vector3I.Zero, size); //referenceVoxelMap.Storage.ReadRange(m_temporaryCache, MyStorageDataTypeFlags.Content, 0, ref Vector3I.Zero, ref size); var world = MatrixD.CreateTranslation(referenceVoxelMap.PositionLeftBottomCorner); for (int z = 0; z < size.Z / 2; z++) { for (int y = 0; y < size.Y; y++) { for (int x = 0; x < size.X / 2; x++) { byte content = m_temporaryCache.Get(MyStorageDataTypeEnum.Content, x, y, z); if (content != 0 && content != 255) { BoundingBoxD bb = new BoundingBoxD( referenceVoxelMap.PositionLeftBottomCorner + new Vector3D(x, y, z) * MyVoxelConstants.VOXEL_SIZE_IN_METRES + new Vector3(MyVoxelConstants.VOXEL_SIZE_IN_METRES), referenceVoxelMap.PositionLeftBottomCorner + new Vector3D(x, y, z) * MyVoxelConstants.VOXEL_SIZE_IN_METRES); MyRenderProxy.DebugDrawAABB(bb, new Color(content, content, content, content), 0.5f, 1, false); } } } } } break; } if (m_tmpResetLeaves.Count > 0) { Color clr = Color.GreenYellow; MySimpleObjectDraw.DrawTransparentBox(ref MatrixD.Identity, ref m_tmpResetLeavesBoundingBox, ref clr, MySimpleObjectRasterizer.Wireframe, 1, 0.04f); clr.A = 25; DrawLeaves(ref worldMatrix, clr, m_tmpResetLeaves); } if (MyFakes.ENABLE_DRAW_VOXEL_STORAGE_PLAYER_POSITION) { MyCharacter character = MySession.Static.CameraController as MyCharacter; if (character != null) { Vector3D worldPos = character.WorldMatrix.Translation; Vector3D localPos; MyVoxelCoordSystems.WorldPositionToLocalPosition(referenceVoxelMap.PositionLeftBottomCorner, ref worldPos, out localPos); localPos = Vector3I.Floor(localPos / 16) * 16; Vector3D outWorldPosMin; MyVoxelCoordSystems.LocalPositionToWorldPosition(referenceVoxelMap.PositionLeftBottomCorner, ref localPos, out outWorldPosMin); BoundingBoxD box = new BoundingBoxD(outWorldPosMin, outWorldPosMin + new Vector3D(16, 16, 16)); Color clr = Color.Orange; MySimpleObjectDraw.DrawTransparentBox(ref MatrixD.Identity, ref box, ref clr, MySimpleObjectRasterizer.Wireframe, 1, 0.04f); } } }
public override void DebugDraw(MyVoxelBase referenceVoxelMap, MyVoxelDebugDrawMode mode) { Matrix worldMatrix = referenceVoxelMap.WorldMatrix;//Matrix.CreateTranslation(referenceVoxelMap.PositionLeftBottomCorner); worldMatrix.Translation = referenceVoxelMap.PositionLeftBottomCorner; Color color; color = Color.CornflowerBlue; color.A = 25; switch (mode) { case MyVoxelDebugDrawMode.Content_MicroNodes: case MyVoxelDebugDrawMode.Content_MicroNodesScaled: DrawSparseOctrees(ref worldMatrix, color, mode, m_contentLeaves); break; case MyVoxelDebugDrawMode.Content_MacroNodes: DrawNodes(ref worldMatrix, color, m_contentNodes); break; case MyVoxelDebugDrawMode.Content_MacroLeaves: DrawLeaves(ref worldMatrix, color, m_contentLeaves); break; case MyVoxelDebugDrawMode.Content_MacroScaled: DrawScaledNodes(ref worldMatrix, color, m_contentNodes); break; case MyVoxelDebugDrawMode.Materials_MacroNodes: DrawNodes(ref worldMatrix, color, m_materialNodes); break; case MyVoxelDebugDrawMode.Materials_MacroLeaves: DrawLeaves(ref worldMatrix, color, m_materialLeaves); break; case MyVoxelDebugDrawMode.Content_DataProvider: if (m_dataProvider != null) { var world = MatrixD.CreateTranslation(referenceVoxelMap.PositionLeftBottomCorner); m_dataProvider.DebugDraw(ref world); } break; case MyVoxelDebugDrawMode.FullCells: { //MyStorageDataCache m_cache = new MyStorageDataCache(); var size = referenceVoxelMap.Storage.Size; //m_temporaryCache.Resize(Vector3I.Zero, size); //referenceVoxelMap.Storage.ReadRange(m_temporaryCache, MyStorageDataTypeFlags.Content, 0, ref Vector3I.Zero, ref size); var world = MatrixD.CreateTranslation(referenceVoxelMap.PositionLeftBottomCorner); for (int z = 0; z < size.Z / 2; z++) for (int y = 0; y < size.Y ; y++) for (int x = 0; x < size.X / 2; x++) { byte content = m_temporaryCache.Get(MyStorageDataTypeEnum.Content, x, y, z); if (content != 0 && content != 255) { BoundingBoxD bb = new BoundingBoxD( referenceVoxelMap.PositionLeftBottomCorner + new Vector3D(x, y, z) * MyVoxelConstants.VOXEL_SIZE_IN_METRES + new Vector3(MyVoxelConstants.VOXEL_SIZE_IN_METRES), referenceVoxelMap.PositionLeftBottomCorner + new Vector3D(x, y, z) * MyVoxelConstants.VOXEL_SIZE_IN_METRES); MyRenderProxy.DebugDrawAABB(bb, new Color(content, content, content, content), 0.5f, 1, false); } } } break; } if (m_tmpResetLeaves.Count > 0) { Color clr = Color.GreenYellow; MySimpleObjectDraw.DrawTransparentBox(ref MatrixD.Identity, ref m_tmpResetLeavesBoundingBox, ref clr, MySimpleObjectRasterizer.Wireframe, 1, 0.04f); clr.A = 25; DrawLeaves(ref worldMatrix, clr, m_tmpResetLeaves); } if (MyFakes.ENABLE_DRAW_VOXEL_STORAGE_PLAYER_POSITION) { MyCharacter character = MySession.Static.CameraController as MyCharacter; if (character != null) { Vector3D worldPos = character.WorldMatrix.Translation; Vector3D localPos; MyVoxelCoordSystems.WorldPositionToLocalPosition(referenceVoxelMap.PositionLeftBottomCorner, ref worldPos, out localPos); localPos = Vector3I.Floor(localPos / 16) * 16; Vector3D outWorldPosMin; MyVoxelCoordSystems.LocalPositionToWorldPosition(referenceVoxelMap.PositionLeftBottomCorner, ref localPos, out outWorldPosMin); BoundingBoxD box = new BoundingBoxD(outWorldPosMin, outWorldPosMin + new Vector3D(16, 16, 16)); Color clr = Color.Orange; MySimpleObjectDraw.DrawTransparentBox(ref MatrixD.Identity, ref box, ref clr, MySimpleObjectRasterizer.Wireframe, 1, 0.04f); } } }