void CopySelection() { EditorSelectionBox selectionBox = TerrainEditor.SelectionBox; copy = new Block[ selectionBox.Max.Z - selectionBox.Min.Z + 1, selectionBox.Max.Y - selectionBox.Min.Y + 1, selectionBox.Max.X - selectionBox.Min.X + 1]; for (int x = selectionBox.Min.X, _x = 0; x <= selectionBox.Max.X; x++, _x++) { for (int y = selectionBox.Min.Y, _y = 0; y <= selectionBox.Max.Y; y++, _y++) { for (int z = selectionBox.Min.Z, _z = 0; z <= selectionBox.Max.Z; z++, _z++) { IndexPosition globalPos = new IndexPosition(x, y, z); IndexPosition cIndex, bIndex; GetLocalBlockCoords(globalPos, out cIndex, out bIndex); Chunk chunk; if (Terrain.Chunks.TryGetValue(cIndex, out chunk)) { copy[_z, _y, _x] = chunk.GetBlockSafe(bIndex.X, bIndex.Y, bIndex.Z); } } } } }
void PasteSelection() { EditorSelectionBox selectionBox = TerrainEditor.SelectionBox; IndexPosition origin = selectionBox.Min; IndexPosition min = origin; IndexPosition max = origin + new IndexPosition( copy.GetLength(2) - 1, copy.GetLength(1) - 1, copy.GetLength(0) - 1); if (selectionBox.Size() == IndexPosition.Zero && (max - min) != IndexPosition.Zero) { min += new IndexPosition(0, 1, 0); max += new IndexPosition(0, 1, 0); } selectionBox.SetMinMax(min, max); for (int x = selectionBox.Min.X, _x = 0; x <= selectionBox.Max.X; x++, _x++) { for (int y = selectionBox.Min.Y, _y = 0; y <= selectionBox.Max.Y; y++, _y++) { for (int z = selectionBox.Min.Z, _z = 0; z <= selectionBox.Max.Z; z++, _z++) { IndexPosition globalPos = new IndexPosition(x, y, z); IndexPosition cIndex, bIndex; GetLocalBlockCoords(globalPos, out cIndex, out bIndex); Chunk chunk; if (Terrain.Chunks.TryGetValue(cIndex, out chunk)) { TerrainEditor.SetBlock(chunk, copy[_z, _y, _x], bIndex); } } } } }
void DeleteSelection() { EditorSelectionBox selectionBox = TerrainEditor.SelectionBox; for (int x = selectionBox.Min.X, _x = 0; x <= selectionBox.Max.X; x++, _x++) { for (int y = selectionBox.Min.Y, _y = 0; y <= selectionBox.Max.Y; y++, _y++) { for (int z = selectionBox.Min.Z, _z = 0; z <= selectionBox.Max.Z; z++, _z++) { IndexPosition globalPos = new IndexPosition(x, y, z); IndexPosition cIndex, bIndex; GetLocalBlockCoords(globalPos, out cIndex, out bIndex); Chunk chunk; if (Terrain.Chunks.TryGetValue(cIndex, out chunk)) { TerrainEditor.SetBlock(chunk, Block.AIR, bIndex); } } } } }
public override void Update(EditorWorldRaycastResult intersection, float deltaTime) { // Grab first because of how many times were using it EditorSelectionBox selectionBox = TerrainEditor.SelectionBox; if (Input.GetMouseButtonUp(MouseButton.Left)) { transHandles.LetGo(); } else if (Input.GetMouseButtonDown(MouseButton.Left)) { transHandles.TryGrab(Camera.Active); } if (TerrainEditor.IsSelecting) { startSelectionBox.SetPrimary(selectionBox.Primary); startSelectionBox.SetSecondary(selectionBox.Secondary); } IndexPosition delta = transHandles.Update(Block.CUBE_SIZE, Camera.Active); if (!canMove) { delta = IndexPosition.Zero; } if (Input.IsControlHeld) { selectionBox.SetMinMax(selectionBox.Min, selectionBox.Max + delta); startSelectionBox.SetMinMax(startSelectionBox.Min, startSelectionBox.Max + delta); } else if (Input.IsAltHeld) { selectionBox.SetMinMax(selectionBox.Min + delta, selectionBox.Max); startSelectionBox.SetMinMax(startSelectionBox.Min + delta, startSelectionBox.Max); } else { selectionBox.Translate(delta); } transHandles.PositionToMinMax(selectionBox.Min, selectionBox.Max, Block.CUBE_SIZE, Block.CUBE_3D_SIZE); if (canMove) { if (transHandles.HasHold) { if (Input.WrapCursor()) { canMove = false; } } } else { Camera.Active.Update(deltaTime); transHandles.ResetStartPos(Camera.Active); canMove = true; } if (Input.GetKeyDown(Key.Enter)) { MoveSelection(); } else if (Input.GetKeyDown(Key.Delete)) { DeleteSelection(); } if (Input.IsControlHeld) { if (Input.GetKeyDown(Key.C)) { CopySelection(); } else if (Input.GetKeyDown(Key.X)) { CopySelection(); DeleteSelection(); } else if (copy != null && Input.GetKeyDown(Key.V)) { PasteSelection(); } } }
public TerrainMoveTool(EditorScreen screen, WorldEditor editor) : base(screen, editor, EditorToolType.TerrainMove, Key.Number5) { startSelectionBox = new EditorSelectionBox(); transHandles = new VoxelTranslationHandles(Renderer); }