Esempio n. 1
0
        public override void Draw(EditorWorldRaycastResult intersection)
        {
            if (intersection.HitTerrain && !GUISystem.HandledMouseOver)
            {
                TerrainRaycastResult terrainIntersection = intersection.TerrainResult;

                Vector3 blockCoords = TerrainEditor.IsSelecting
                    ? TerrainEditor.SelectionBox.Center()
                    : GetGlobalBlockCoords(terrainIntersection.Chunk.IndexPosition, terrainIntersection.BlockIndex.Value)
                                      * Block.CUBE_3D_SIZE
                                      + Maths.CubeSideToSurfaceNormal(terrainIntersection.IntersectionCubeSide.Value) * Block.CUBE_3D_SIZE;

                Vector3 scale = TerrainEditor.IsSelecting
                    ? TerrainEditor.SelectionBox.Size().ToVector3() + Vector3.UnitScale
                    : Vector3.UnitScale;

                cursorCube.Position = blockCoords;
                cursorCube.VoxelObject.MeshScale = scale;
                cursorCube.RenderAsWireframe     = false;
                Color color = TerrainEditor.BlockColor;
                color.A = 128;
                cursorCube.ColorOverlay = color;

                entRenderer.Batch(cursorCube);
            }
        }
Esempio n. 2
0
        public override void Update(EditorWorldRaycastResult intersection, float deltaTime)
        {
            if (intersection.HitTerrain)
            {
                TerrainRaycastResult terrainIntersection = intersection.TerrainResult;

                if (!TerrainEditor.IsSelecting)
                {
                    lastNonSelectingNormal = terrainIntersection.IntersectionCubeSide.Value;
                }

                if (TerrainEditor.IsSelecting && Input.GetMouseButtonUp(MouseButton.Left))
                {
                    ApplyActionToSelection(TerrainEditor.SelectionBox,
                                           (chunk, blockPos) =>
                    {
                        Block block = Block.CUSTOM;
                        Color color = TerrainEditor.BlockColor;
                        block.R     = color.R;
                        block.G     = color.G;
                        block.B     = color.B;

                        TerrainEditor.SetBlock(chunk, block, blockPos);
                    });
                }
            }
        }
Esempio n. 3
0
 public override void Draw(EditorWorldRaycastResult intersection)
 {
     if (selectedObject != null)
     {
         debugRenderer.Batch(selectedObject.GetCollider());
         transHandles.Draw();
     }
 }
Esempio n. 4
0
        public override void Update(EditorWorldRaycastResult worldIntersection, float deltaTime)
        {
            if (Input.GetMouseButtonUp(MouseButton.Left))
            {
                transHandles.LetGo();
            }
            else if (Input.GetMouseButtonDown(MouseButton.Left) &&
                     !GUISystem.HandledMouseOver && selectedObject != null)
            {
                transHandles.TryGrab(Camera.Active);
            }

            if (!GUISystem.HandledMouseOver && Input.GetMouseButtonDown(MouseButton.Left) && !transHandles.HasHold)
            {
                if (worldIntersection.HitEditorObject)
                {
                    EditorObjectRaycastResult intersection = worldIntersection.EditorObjectResult;
                    selectedObject = intersection.EditorObject;
                }
                else
                {
                    selectedObject = null;
                }

                window.SetObject(selectedObject);
            }

            if (selectedObject != null)
            {
                Vector3 delta = transHandles.Update(Camera.Active, 16);
                if (!canMove)
                {
                    delta = Vector3.Zero;
                }

                AxisAlignedBoundingBox aabb = selectedObject.GetCollider();
                transHandles.PositionToMinMax(aabb.Min, aabb.Max, Vector3.Zero);

                if (canMove)
                {
                    if (transHandles.HasHold)
                    {
                        if (Input.WrapCursor())
                        {
                            canMove = false;
                        }
                    }
                }
                else
                {
                    Camera.Active.Update(deltaTime);
                    transHandles.ResetStartPos(Camera.Active);
                    canMove = true;
                }

                selectedObject.Transform.Position += delta;
            }
        }
 public override void Update(EditorWorldRaycastResult intersection, float deltaTime)
 {
     if (intersection.HitTerrain && TerrainEditor.IsSelecting && Input.GetMouseButtonUp(MouseButton.Left))
     {
         ApplyActionToSelection(TerrainEditor.SelectionBox,
                                (chunk, blockPos) =>
         {
             TerrainEditor.SetBlock(chunk, Block.AIR, blockPos);
         });
     }
 }
Esempio n. 6
0
        public override void Draw(EditorWorldRaycastResult intersection)
        {
            Vector3 blockCoords = TerrainEditor.SelectionBox.Center();

            Vector3 scale = TerrainEditor.SelectionBox.Size().ToVector3() + Vector3.UnitScale;

            cursorCube.Position = blockCoords;
            cursorCube.VoxelObject.MeshScale = scale + new Vector3(0.01f, 0.01f, 0.01f);
            cursorCube.RenderAsWireframe     = true;
            cursorCube.ColorOverlay          = Color.Black;

            entRenderer.Batch(cursorCube);
            transHandles.Draw();
        }
        public override void Update(EditorWorldRaycastResult intersection, float deltaTime)
        {
            if (intersection.HitTerrain && TerrainEditor.IsSelecting && Input.GetMouseButtonUp(MouseButton.Left))
            {
                ApplyActionToSelection(TerrainEditor.SelectionBox,
                                       (chunk, blockPos) =>
                {
                    if (chunk.GetBlockSafe(blockPos.X, blockPos.Y, blockPos.Z) != Block.AIR)
                    {
                        Block block     = Block.CUSTOM;
                        Color color     = TerrainEditor.BlockColor;
                        int grainRadius = grainFactor;
                        block.R         = (byte)MathHelper.ClampToByteRange(color.R + Maths.Random.Next(-grainRadius, grainRadius));
                        block.G         = (byte)MathHelper.ClampToByteRange(color.G + Maths.Random.Next(-grainRadius, grainRadius));
                        block.B         = (byte)MathHelper.ClampToByteRange(color.B + Maths.Random.Next(-grainRadius, grainRadius));

                        TerrainEditor.SetBlock(chunk, block, blockPos);
                    }
                });
            }
        }
        public override void Draw(EditorWorldRaycastResult worldIntersection)
        {
            if (worldIntersection.HitTerrain && !GUISystem.HandledMouseOver)
            {
                TerrainRaycastResult intersection = worldIntersection.TerrainResult;

                Vector3 blockCoords = TerrainEditor.IsSelecting
                   ? TerrainEditor.SelectionBox.Center()
                   : GetGlobalBlockCoords(intersection.Chunk.IndexPosition, intersection.BlockIndex.Value) * Block.CUBE_3D_SIZE;

                Vector3 scale = TerrainEditor.IsSelecting
                    ? TerrainEditor.SelectionBox.Size().ToVector3() + Vector3.UnitScale
                    : Vector3.UnitScale;

                cursorCube.Position = blockCoords;
                cursorCube.VoxelObject.MeshScale = scale + new Vector3(0.01f, 0.01f, 0.01f);
                cursorCube.RenderAsWireframe     = true;
                cursorCube.ColorOverlay          = Color.Black;

                entRenderer.Batch(cursorCube);
            }
        }
Esempio n. 9
0
        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 override void Update(EditorWorldRaycastResult worldIntersection, float deltaTime)
        {
            halfBrush = (int)Math.Ceiling(brushSize / 2f);

            if (worldIntersection.HitTerrain && !GUISystem.HandledMouseInput)
            {
                TerrainRaycastResult intersection = worldIntersection.TerrainResult;

                if (Input.GetMouseButtonDown(MouseButton.Left))
                {
                    if (Input.IsControlHeld)
                    {
                        dragging        = true;
                        dragHeight      = intersection.BlockIndex.Value.Y;
                        chunkDragHeight = intersection.Chunk.IndexPosition.Y;
                    }
                }

                if (Input.GetMouseButtonUp(MouseButton.Left) && dragging)
                {
                    dragging = false;
                }
                else if (Input.GetMouseButtonUp(MouseButton.Left) || dragging)
                {
                    IndexPosition cIndex, bIndex;
                    if (dragging)
                    {
                        cIndex = new IndexPosition(intersection.Chunk.IndexPosition.X,
                                                   chunkDragHeight, intersection.Chunk.IndexPosition.Z);
                        bIndex = new IndexPosition(intersection.BlockIndex.Value.X, dragHeight,
                                                   intersection.BlockIndex.Value.Z);
                    }
                    else
                    {
                        cIndex = intersection.Chunk.IndexPosition;
                        bIndex = intersection.BlockIndex.Value;
                    }

                    IndexPosition globalBlock = GetGlobalBlockCoords(cIndex, bIndex);

                    for (int x = -halfBrush; x <= halfBrush; x++)
                    {
                        for (int y = -halfBrush; y <= halfBrush; y++)
                        {
                            for (int z = -halfBrush; z <= halfBrush; z++)
                            {
                                float dist = (new Vector3(x, y, z)).Length;
                                if (dist > halfBrush)
                                {
                                    continue;
                                }

                                float distPercent = (float)Math.Cos((dist / halfBrush) * MathHelper.PiOver2);
                                int   offset      = (int)Math.Round(distPercent * riseHeight);

                                IndexPosition globalPos = globalBlock + new IndexPosition(x, y - offset, z);
                                GetLocalBlockCoords(globalPos, out cIndex, out bIndex);

                                Chunk chunk;
                                if (Terrain.Chunks.TryGetValue(cIndex, out chunk) && chunk.IsBlockCoordInRange(bIndex))
                                {
                                    IndexPosition cIndex2, bIndex2;
                                    IndexPosition globalPos2 = globalBlock + new IndexPosition(x, y, z);
                                    GetLocalBlockCoords(globalPos2, out cIndex2, out bIndex2);

                                    Chunk chunk2;
                                    if (Terrain.Chunks.TryGetValue(cIndex2, out chunk2) && chunk2.IsBlockCoordInRange(bIndex2))
                                    {
                                        TerrainEditor.SetBlock(chunk2, chunk[bIndex], bIndex2);
                                    }
                                }
                            }
                        }
                    }

                    //ApplyActionToBrush(cIndex, bIndex,
                    //    (chunk, blockIndex, x, y, z, _) =>
                    //    {
                    //    //    int ay = 0;// Math.Abs(y);
                    //    //    float dist = (new Vector3(x + ay, ay, z + ay)).Length;
                    //    //    int offset = (int)Math.Round(((brushSize - dist) / brushSize) * riseHeight);

                    //    ////if (x == 0 && z == 0)
                    //    ////    y++;

                    //    //if (y > riseHeight)
                    //    //        return;

                    //    //    IndexPosition newBlockPos;
                    //    //    IndexPosition newChunkIndex;
                    //    //    Chunk.WrapBlockCoords(blockIndex.X, blockIndex.Y + offset, blockIndex.Z, chunk.IndexPosition,
                    //    //        out newBlockPos, out newChunkIndex);

                    //    //    if (Terrain.Chunks.TryGetValue(newChunkIndex, out chunk))
                    //    //    {
                    //    //        IndexPosition blockPos = new IndexPosition(x, y, z);
                    //    //        Vector3 coloroff = (blockPos + (newChunkIndex * Chunk.SIZE)) * Block.CUBE_SIZE;
                    //    //        Nybble2 data;
                    //    //        Color voxelColor;
                    //    //        if (y == riseHeight)
                    //    //        {
                    //    //            data = Block.GRASS.Data;
                    //    //            voxelColor = grassGradient.GetColor(coloroff);
                    //    //        }
                    //    //        else
                    //    //        {
                    //    //            data = Block.STONE.Data;
                    //    //            voxelColor = stoneGradient.GetColor(coloroff);
                    //    //        }

                    //    //        voxelColor = new Color(
                    //    //            (byte)MathHelper.Clamp(voxelColor.R + Maths.Random.Next(-3, 3), 0, 255),
                    //    //            (byte)MathHelper.Clamp(voxelColor.G + Maths.Random.Next(-3, 3), 0, 255),
                    //    //            (byte)MathHelper.Clamp(voxelColor.B + Maths.Random.Next(-3, 3), 0, 255));

                    //    //        if (chunk.GetBlockSafe(newBlockPos.X, newBlockPos.Y, newBlockPos.Z).Data.Value != data.Value)
                    //    //            Editor.SetBlock(chunk, new Block(data, voxelColor.R, voxelColor.G, voxelColor.B), newBlockPos);
                    //    //    }
                    //    });
                }
            }
        }