Exemplo n.º 1
0
        public void RemoveVoxel(VoxelPos pos, string texture)
        {
            var offsets = new Vector3[] { Vector3.Forward, Vector3.Back, Vector3.Left, Vector3.Right, Vector3.Up, Vector3.Down }.ToList();
            var voxel = GetVoxel(pos, false);

            for (int i = 0; i < 6; i++)
            {
                var neighborPos = pos.Translate(offsets[i]);
                var neighbor    = GetVoxel(neighborPos, true);

                switch (i)
                {
                // Front Neighbor
                case 0:
                    if (!voxel.HasFront())
                    {
                        neighbor.backTexture = texture;
                    }
                    break;

                // Back Neighbord
                case 1:
                    if (!voxel.HasBack())
                    {
                        neighbor.frontTexture = texture;
                    }
                    break;

                // Left Neighbor
                case 2:
                    if (!voxel.HasLeft())
                    {
                        neighbor.rightTexture = texture;
                    }
                    break;

                // Right Neighbor
                case 3:
                    if (!voxel.HasRight())
                    {
                        neighbor.leftTexture = texture;
                    }
                    break;

                // Up Neighbor
                case 4:
                    if (!voxel.HasTop())
                    {
                        neighbor.bottomTexture = texture;
                    }
                    break;

                // Down Neighbor
                case 5:
                    if (!voxel.HasBottom())
                    {
                        neighbor.topTexture = texture;
                    }
                    break;
                }
            }

            Voxels.Remove(pos);
            updateMesh = true;
        }
Exemplo n.º 2
0
        private void Extrude(bool intrude)
        {
            if (selection.Is3D())
            {
                GD.Print("3D Selections are not implemented!");
                return;
            }

            var(start, end, normal) = selection.GetSelectionTuple();

            if (normal == Vector3.Zero)
            {
                return;
            }

            // TODO: Stuff needs to be cached here for performance and memory.
            foreach (int x in Range(start.x, end.x))
            {
                foreach (int y in Range(start.y, end.y))
                {
                    foreach (int z in Range(start.z, end.z))
                    {
                        VoxelPos pos     = new VoxelPos(x, y, z);
                        Voxel    voxel   = level.GetVoxel(pos, false);
                        string   texture = "";

                        if (voxel.IsEmpty())
                        {
                            continue;
                        }

                        if (normal == Vector3.Up)
                        {
                            texture = voxel.topTexture;
                        }
                        else if (normal == Vector3.Down)
                        {
                            texture = voxel.bottomTexture;
                        }
                        else if (normal == Vector3.Left)
                        {
                            texture = voxel.leftTexture;
                        }
                        else if (normal == Vector3.Right)
                        {
                            texture = voxel.rightTexture;
                        }
                        else if (normal == Vector3.Forward)
                        {
                            texture = voxel.frontTexture;
                        }
                        else if (normal == Vector3.Back)
                        {
                            texture = voxel.backTexture;
                        }

                        if (texture == "")
                        {
                            texture = "white";
                        }

                        if (intrude)
                        {
                            level.RemoveVoxel(pos, texture);
                        }
                        else
                        {
                            pos = pos.Translate(normal);
                            level.SetVoxel(pos, new Voxel(texture));
                        }
                    }
                }
            }

            if (intrude)
            {
                selection.Translate(-normal);
            }
            else
            {
                selection.Translate(normal);
            }

            UpdateSelectionHighlight();
        }
Exemplo n.º 3
0
 public void Translate(Vector3 normal)
 {
     start = start.Translate(normal);
     end   = end.Translate(normal);
 }