示例#1
0
        // Update is called once per frame
        private void Update()
        {
            if (voxelObject == null) return;

            currentTime += Time.deltaTime;
            if (currentTime >= Interval)
            {
                currentTime = 0;

                for (int i = 0; i < NumVoxels; i++)
                {
                    PicaVoxelPoint p =
                        new PicaVoxelPoint(
                            ConstrainToBox
                                ? Random.Range(ConstrainBox.BottomLeftFront.X, ConstrainBox.TopRightBack.X)
                                : Random.Range(0, voxelObject.XSize),
                            ConstrainToBox
                                ? Random.Range(ConstrainBox.BottomLeftFront.Y, ConstrainBox.TopRightBack.Y)
                                : Random.Range(0, voxelObject.YSize),
                            ConstrainToBox
                                ? Random.Range(ConstrainBox.BottomLeftFront.Z, ConstrainBox.TopRightBack.Z)
                                : Random.Range(0, voxelObject.ZSize));

                    voxelObject.SetVoxelAtArrayPosition(p,
                        new Voxel()
                        {
                            State = AddVoxels?VoxelState.Active : VoxelState.Hidden,
                            Color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f))
                        });
                }
            }
        }
示例#2
0
        private void DoCursor(Event e)
        {
            //if (buttonJustClicked && e.type == EventType.MouseUp && e.button == 0)
            //    buttonJustClicked = false;

            if (GUIUtility.hotControl == 0 && EditorGUIUtility.hotControl==0 && GUI.GetNameOfFocusedControl() == "" && buttonJustClicked==false)
            {

                bool validBrushPos = false;

                if (voxelObject.Undone)
                {
                    //voxelObject.CreateChunks();
                    voxelObject.Undone = false;
                }
                foreach (var frame in voxelObject.Frames)
                {
                    if (frame.HasDeserialized) frame.CreateChunks();
                    frame.HasDeserialized = false;
                }


                Ray r =
                    Camera.current.ScreenPointToRay(new Vector3(e.mousePosition.x,
                        -e.mousePosition.y + Camera.current.pixelHeight));

                //Debug.DrawRay(r.origin, r.direction*200f, Color.red );

                for (float d = 0f; d < voxelObject.VoxelSize*200f; d += voxelObject.VoxelSize*0.1f)
                {
                    Voxel? v = voxelObject.GetVoxelAtWorldPosition(r.GetPoint(d));

                    if ((EditorPersistence.CursorMode == EditorCursorMode.Add ||
                         EditorPersistence.CursorMode == EditorCursorMode.BoxAdd ||
                         (EditorPersistence.CursorMode == EditorCursorMode.BrushAdd && !EditorPersistence.BrushReplace)) &&
                        v.HasValue)
                    {
                        if (!v.Value.Active) continue;

                        d -= voxelObject.VoxelSize*0.1f;
                        v = voxelObject.GetVoxelAtWorldPosition(r.GetPoint(d));
                        if (!v.HasValue) break;
                    }

                    if (v.HasValue &&
                        (v.Value.Active || EditorPersistence.CursorMode == EditorCursorMode.Add ||
                         EditorPersistence.CursorMode == EditorCursorMode.BoxAdd ||
                         (EditorPersistence.CursorMode == EditorCursorMode.BrushAdd && !EditorPersistence.BrushReplace)))
                    {
                        cursorPosition =
                            voxelObject.transform.TransformPoint(((voxelObject.GetVoxelPosition(r.GetPoint(d))*
                                                                   voxelObject.VoxelSize) - voxelObject.Pivot) +
                                                                 ((Vector3.one*voxelObject.VoxelSize)*0.5f));

                        if (EditorPersistence.CursorMode != EditorCursorMode.BrushAdd &&
                            EditorPersistence.CursorMode != EditorCursorMode.BrushPaint &&
                            EditorPersistence.CursorMode != EditorCursorMode.BrushSubtract)
                        {
                            Gizmos.matrix =
                                voxelObject.GetCurrentFrame().transform.FindChild("Chunks").localToWorldMatrix;
                            Handles.color = (EditorPersistence.CursorMode == EditorCursorMode.Subtract ||
                                             EditorPersistence.CursorMode == EditorCursorMode.BoxSubtract ||
                                             EditorPersistence.CursorMode == EditorCursorMode.PickColor ||
                                             EditorPersistence.CursorMode == EditorCursorMode.PickValue)
                                ? Color.red*0.5f
                                : voxelObject.PaletteColors[EditorPersistence.SelectedColor]*0.5f;
                            Handles.CubeCap(0, cursorPosition, voxelObject.transform.rotation, voxelObject.VoxelSize);
                            Repaint();
                            SceneView.RepaintAll();
                            Gizmos.matrix = Matrix4x4.identity;
                        }


                        // Mouse down (non-brush)
                        if (e.type == EventType.MouseDown && e.button == 0 &&
                            (EditorPersistence.CursorMode != EditorCursorMode.BrushAdd &&
                             EditorPersistence.CursorMode != EditorCursorMode.BrushPaint &&
                             EditorPersistence.CursorMode != EditorCursorMode.BrushSubtract))
                        {
                            //RegisterUndo();
                            if (EditorPersistence.CursorMode != EditorCursorMode.PickColor &&
                                EditorPersistence.CursorMode != EditorCursorMode.PickValue)
                            {
                                if (propogateAllFrames)
                                {


                                    foreach (Frame f in voxelObject.Frames)
                                    {
                                        f.EditingVoxels =
                                            new Voxel[voxelObject.XSize*voxelObject.YSize*voxelObject.ZSize];
                                        Helper.CopyVoxelsInBox(ref f.Voxels,
                                            ref f.EditingVoxels,
                                            new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                            new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                            false);

                                    }
                                }
                                else
                                {

                                    voxelObject.GetCurrentFrame().EditingVoxels =
                                        new Voxel[voxelObject.XSize*voxelObject.YSize*voxelObject.ZSize];
                                    Helper.CopyVoxelsInBox(ref voxelObject.GetCurrentFrame().Voxels,
                                        ref voxelObject.GetCurrentFrame().EditingVoxels,
                                        new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                        new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                        false);

                                }
                            }

                            if (EditorPersistence.CursorMode == EditorCursorMode.BoxAdd ||
                                EditorPersistence.CursorMode == EditorCursorMode.BoxSubtract ||
                                EditorPersistence.CursorMode == EditorCursorMode.BoxPaint)
                            {
                                boxStart = voxelObject.GetVoxelArrayPosition(r.GetPoint(d));
                                currentBox = new PicaVoxelBox(boxStart, boxStart);
                                changedVoxelExtents = new PicaVoxelBox(boxStart, boxStart);
                            }

                            if (EditorPersistence.CursorMode == EditorCursorMode.Add ||
                                EditorPersistence.CursorMode == EditorCursorMode.Subtract ||
                                EditorPersistence.CursorMode == EditorCursorMode.Paint)
                            {
                                changedVoxelExtents = new PicaVoxelBox(voxelObject.GetVoxelArrayPosition(r.GetPoint(d)), voxelObject.GetVoxelArrayPosition(r.GetPoint(d)));
                            }

                            if (EditorPersistence.CursorMode == EditorCursorMode.PickColor)
                            {
                                bool colorFound = false;
                                for (int c = 0; c < 25; c++)
                                    if (((Color32) voxelObject.PaletteColors[c]).r == ((Color32) v.Value.Color).r &&
                                        ((Color32) voxelObject.PaletteColors[c]).g == ((Color32) v.Value.Color).g &&
                                        ((Color32) voxelObject.PaletteColors[c]).b == ((Color32) v.Value.Color).b)
                                    {
                                        EditorPersistence.SelectedColor = c;
                                        colorFound = true;
                                    }

                                if (!colorFound)
                                    voxelObject.PaletteColors[EditorPersistence.SelectedColor] = v.Value.Color;
                            }

                            if (EditorPersistence.CursorMode == EditorCursorMode.PickValue)
                            {
                                EditorPersistence.SelectedValue = v.Value.Value;
                            }
                        }

                        // Mouse drag (non-brush)
                        if ((e.type == EventType.MouseDown || e.type == EventType.MouseDrag) && e.button == 0)
                        {
                            if (e.type == EventType.MouseDrag &&
                                (EditorPersistence.CursorMode == EditorCursorMode.BoxAdd ||
                                 EditorPersistence.CursorMode == EditorCursorMode.BoxSubtract ||
                                 EditorPersistence.CursorMode == EditorCursorMode.BoxPaint) && boxStart != null)
                            {
                                if (propogateAllFrames)
                                {
                                    foreach (Frame f in voxelObject.Frames)
                                    {
                                        Helper.CopyVoxelsInBox(ref f.Voxels,
                                            ref f.EditingVoxels, currentBox, currentBox,
                                            new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                            new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                            false);

                                    }
                                }
                                else
                                {
                                    Helper.CopyVoxelsInBox(ref voxelObject.GetCurrentFrame().Voxels,
                                        ref voxelObject.GetCurrentFrame().EditingVoxels, currentBox, currentBox,
                                        new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                        new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                        false);
                                }
                                //voxelObject.UpdateAllChunks();

                                PicaVoxelPoint boxEnd = voxelObject.GetVoxelArrayPosition(r.GetPoint(d));
                                currentBox = new PicaVoxelBox(boxStart, boxEnd);

                                if (currentBox.BottomLeftFront.X < changedVoxelExtents.BottomLeftFront.X)
                                    changedVoxelExtents.BottomLeftFront.X = currentBox.BottomLeftFront.X;
                                if (currentBox.BottomLeftFront.Y < changedVoxelExtents.BottomLeftFront.Y)
                                    changedVoxelExtents.BottomLeftFront.Y = currentBox.BottomLeftFront.Y;
                                if (currentBox.BottomLeftFront.Z < changedVoxelExtents.BottomLeftFront.Z)
                                    changedVoxelExtents.BottomLeftFront.Z = currentBox.BottomLeftFront.Z;
                                if (currentBox.TopRightBack.X > changedVoxelExtents.TopRightBack.X)
                                    changedVoxelExtents.TopRightBack.X = currentBox.TopRightBack.X;
                                if (currentBox.TopRightBack.Y > changedVoxelExtents.TopRightBack.Y)
                                    changedVoxelExtents.TopRightBack.Y = currentBox.TopRightBack.Y;
                                if (currentBox.TopRightBack.Z > changedVoxelExtents.TopRightBack.Z)
                                    changedVoxelExtents.TopRightBack.Z = currentBox.TopRightBack.Z;


                                for (int x = currentBox.BottomLeftFront.X; x <= currentBox.TopRightBack.X; x++)
                                    for (int y = currentBox.BottomLeftFront.Y; y <= currentBox.TopRightBack.Y; y++)
                                        for (int z = currentBox.BottomLeftFront.Z; z <= currentBox.TopRightBack.Z; z++)
                                        {
                                            if (propogateAllFrames)
                                            {
                                                foreach (Frame f in voxelObject.Frames)
                                                {
                                                    switch (EditorPersistence.CursorMode)
                                                    {
                                                        case EditorCursorMode.BoxAdd:
                                                            if (
                                                                !f.Voxels[
                                                                    x + voxelObject.XSize*(y + voxelObject.YSize*z)]
                                                                    .Active)
                                                            {
                                                                f.EditingVoxels[
                                                                    x + voxelObject.XSize*(y + voxelObject.YSize*z)] = new Voxel
                                                                        ()
                                                                    {
                                                                        Color =
                                                                            voxelObject.PaletteColors[
                                                                                EditorPersistence.SelectedColor],
                                                                        Value = EditorPersistence.SelectedValue,
                                                                        State =
                                                                            (EditorPersistence.CursorMode !=
                                                                             EditorCursorMode.BoxSubtract)?VoxelState.Active:VoxelState.Inactive
                                                                    };
                                                            }
                                                            break;
                                                        case EditorCursorMode.BoxSubtract:
                                                            f.EditingVoxels[
                                                                x + voxelObject.XSize*(y + voxelObject.YSize*z)] = new Voxel
                                                                    ()
                                                                {
                                                                    Color =
                                                                        voxelObject.PaletteColors[
                                                                            EditorPersistence.SelectedColor],
                                                                    Value = EditorPersistence.SelectedValue,
                                                                    State =
                                                                            (EditorPersistence.CursorMode !=
                                                                             EditorCursorMode.BoxSubtract) ? VoxelState.Active : VoxelState.Inactive
                                                                };
                                                            break;
                                                        case EditorCursorMode.BoxPaint:
                                                            if (
                                                                f.Voxels[x + voxelObject.XSize*(y + voxelObject.YSize*z)
                                                                    ].Active)
                                                            {
                                                                switch (paintMode)
                                                                {

                                                                    case EditorPaintMode.Color:
                                                                        f.EditingVoxels[
                                                                            x +
                                                                            voxelObject.XSize*(y + voxelObject.YSize*z)]
                                                                            = new Voxel()
                                                                            {
                                                                                Color =
                                                                                    voxelObject.PaletteColors[
                                                                                        EditorPersistence.SelectedColor],
                                                                                Value =
                                                                                    f.Voxels[
                                                                                        x +
                                                                                        voxelObject.XSize*
                                                                                        (y + voxelObject.YSize*z)].Value,
                                                                                State =
                                                                                    f.Voxels[
                                                                                        x +
                                                                                        voxelObject.XSize*
                                                                                        (y + voxelObject.YSize*z)]
                                                                                        .State
                                                                            };
                                                                        //GetCurrentFrame().EditingVoxels[x, y, z].Color = voxelObject.PaletteColors[selectedColor];
                                                                        break;
                                                                    case EditorPaintMode.Value:
                                                                        f.EditingVoxels[
                                                                            x +
                                                                            voxelObject.XSize*(y + voxelObject.YSize*z)]
                                                                            = new Voxel()
                                                                            {
                                                                                Color =
                                                                                    f.Voxels[
                                                                                        x +
                                                                                        voxelObject.XSize*
                                                                                        (y + voxelObject.YSize*z)].Color,
                                                                                Value = EditorPersistence.SelectedValue,
                                                                                State =
                                                                                    f.Voxels[
                                                                                        x +
                                                                                        voxelObject.XSize*
                                                                                        (y + voxelObject.YSize*z)]
                                                                                        .State
                                                                            };
                                                                        //voxelObject.GetCurrentFrame().EditingVoxels[x, y, z].Value = selectedValue;
                                                                        break;
                                                                }
                                                            }
                                                            break;
                                                    }
                                                }

                                            }
                                            else
                                            {
                                                switch (EditorPersistence.CursorMode)
                                                {
                                                    case EditorCursorMode.BoxAdd:
                                                        if (
                                                            !voxelObject.GetCurrentFrame().Voxels[
                                                                x + voxelObject.XSize*(y + voxelObject.YSize*z)].Active)
                                                        {
                                                            voxelObject.GetCurrentFrame().EditingVoxels[
                                                                x + voxelObject.XSize*(y + voxelObject.YSize*z)] = new Voxel
                                                                    ()
                                                                {
                                                                    Color =
                                                                        voxelObject.PaletteColors[
                                                                            EditorPersistence.SelectedColor],
                                                                    Value = EditorPersistence.SelectedValue,
                                                                    State =
                                                                            (EditorPersistence.CursorMode !=
                                                                             EditorCursorMode.BoxSubtract) ? VoxelState.Active : VoxelState.Inactive
                                                                };
                                                        }
                                                        break;
                                                    case EditorCursorMode.BoxSubtract:
                                                        voxelObject.GetCurrentFrame().EditingVoxels[
                                                            x + voxelObject.XSize*(y + voxelObject.YSize*z)] = new Voxel
                                                                ()
                                                            {
                                                                Color =
                                                                    voxelObject.PaletteColors[
                                                                        EditorPersistence.SelectedColor],
                                                                Value = EditorPersistence.SelectedValue,
                                                                State =
                                                                            (EditorPersistence.CursorMode !=
                                                                             EditorCursorMode.BoxSubtract) ? VoxelState.Active : VoxelState.Inactive
                                                            };
                                                        break;
                                                    case EditorCursorMode.BoxPaint:
                                                        if (
                                                            voxelObject.GetCurrentFrame().Voxels[
                                                                x + voxelObject.XSize*(y + voxelObject.YSize*z)].Active)
                                                        {
                                                            switch (paintMode)
                                                            {

                                                                case EditorPaintMode.Color:
                                                                    voxelObject.GetCurrentFrame().EditingVoxels[
                                                                        x + voxelObject.XSize*(y + voxelObject.YSize*z)]
                                                                        = new Voxel()
                                                                        {
                                                                            Color =
                                                                                voxelObject.PaletteColors[
                                                                                    EditorPersistence.SelectedColor],
                                                                            Value =
                                                                                voxelObject.GetCurrentFrame().Voxels[
                                                                                    x +
                                                                                    voxelObject.XSize*
                                                                                    (y + voxelObject.YSize*z)].Value,
                                                                            State =
                                                                                voxelObject.GetCurrentFrame().Voxels[
                                                                                    x +
                                                                                    voxelObject.XSize*
                                                                                    (y + voxelObject.YSize*z)].State
                                                                        };
                                                                    //GetCurrentFrame().EditingVoxels[x, y, z].Color = voxelObject.PaletteColors[selectedColor];
                                                                    break;
                                                                case EditorPaintMode.Value:
                                                                    voxelObject.GetCurrentFrame().EditingVoxels[
                                                                        x + voxelObject.XSize*(y + voxelObject.YSize*z)]
                                                                        = new Voxel()
                                                                        {
                                                                            Color =
                                                                                voxelObject.GetCurrentFrame().Voxels[
                                                                                    x +
                                                                                    voxelObject.XSize*
                                                                                    (y + voxelObject.YSize*z)].Color,
                                                                            Value = EditorPersistence.SelectedValue,
                                                                            State =
                                                                                voxelObject.GetCurrentFrame().Voxels[
                                                                                    x +
                                                                                    voxelObject.XSize*
                                                                                    (y + voxelObject.YSize*z)].State
                                                                        };
                                                                    //voxelObject.GetCurrentFrame().EditingVoxels[x, y, z].Value = selectedValue;
                                                                    break;
                                                            }
                                                        }
                                                        break;
                                                }
                                            }
                                        }


                                for (int x = changedVoxelExtents.BottomLeftFront.X-1;
                                    x <= changedVoxelExtents.TopRightBack.X+1;
                                    x ++)
                                    for (int y = changedVoxelExtents.BottomLeftFront.Y-1;
                                        y <= changedVoxelExtents.TopRightBack.Y+1;
                                        y ++)
                                        for (int z = changedVoxelExtents.BottomLeftFront.Z-1;
                                            z <= changedVoxelExtents.TopRightBack.Z+1;
                                            z ++)
                                            if (propogateAllFrames)
                                                foreach (Frame f in voxelObject.Frames)
                                                    f.SetChunkAtVoxelPositionDirty(x, y, z);
                                            else voxelObject.GetCurrentFrame().SetChunkAtVoxelPositionDirty(x, y, z);


                                if (propogateAllFrames)
                                    foreach (Frame f in voxelObject.Frames) f.UpdateChunks(true);
                                else voxelObject.UpdateChunks(true);

                            }

                            if (EditorPersistence.CursorMode == EditorCursorMode.Add ||
                                EditorPersistence.CursorMode == EditorCursorMode.Subtract ||
                                EditorPersistence.CursorMode == EditorCursorMode.Paint)
                            {
                                PicaVoxelPoint pv = voxelObject.GetVoxelArrayPosition(r.GetPoint(d));

                                if (pv.X < changedVoxelExtents.BottomLeftFront.X)
                                    changedVoxelExtents.BottomLeftFront.X = pv.X;
                                if (pv.Y < changedVoxelExtents.BottomLeftFront.Y)
                                    changedVoxelExtents.BottomLeftFront.Y = pv.Y;
                                if (pv.Z < changedVoxelExtents.BottomLeftFront.Z)
                                    changedVoxelExtents.BottomLeftFront.Z = pv.Z;
                                if (pv.X > changedVoxelExtents.TopRightBack.X)
                                    changedVoxelExtents.TopRightBack.X = pv.X;
                                if (pv.Y > changedVoxelExtents.TopRightBack.Y)
                                    changedVoxelExtents.TopRightBack.Y = pv.Y;
                                if (pv.Z > changedVoxelExtents.TopRightBack.Z)
                                    changedVoxelExtents.TopRightBack.Z = pv.Z;

                                if (propogateAllFrames)
                                {
                                    foreach (Frame f in voxelObject.Frames)
                                    {
                                        f.SetVoxelAtWorldPosition(r.GetPoint(d),
                                            new Voxel()
                                            {
                                                State = (EditorPersistence.CursorMode != EditorCursorMode.Subtract)?VoxelState.Active : VoxelState.Inactive,
                                                Color = voxelObject.PaletteColors[EditorPersistence.SelectedColor],
                                                Value = EditorPersistence.SelectedValue
                                            });
                                        f.UpdateChunks(true);
                                    }
                                }
                                else
                                {
                                    voxelObject.SetVoxelAtWorldPosition(r.GetPoint(d),
                                        new Voxel()
                                        {
                                            State = (EditorPersistence.CursorMode != EditorCursorMode.Subtract) ? VoxelState.Active : VoxelState.Inactive,
                                            Color = voxelObject.PaletteColors[EditorPersistence.SelectedColor],
                                            Value = EditorPersistence.SelectedValue
                                        });
                                    voxelObject.UpdateChunks(true);
                                }

                            }
                        }

                        // Mouse move (brush update)
                        if ((EditorPersistence.CursorMode == EditorCursorMode.BrushAdd ||
                             EditorPersistence.CursorMode == EditorCursorMode.BrushPaint ||
                             EditorPersistence.CursorMode == EditorCursorMode.BrushSubtract))
                        {
                            validBrushPos = true;

                            if (e.type == EventType.MouseMove)
                            {
                                if (propogateAllFrames)
                                {
                                    foreach (Frame f in voxelObject.Frames)
                                    {
                                        if (f.EditingVoxels == null)
                                        {
                                            f.EditingVoxels =
                                                new Voxel[voxelObject.XSize * voxelObject.YSize * voxelObject.ZSize];
                                            Helper.CopyVoxelsInBox(ref voxelObject.GetCurrentFrame().Voxels,
                                                ref f.EditingVoxels,
                                                new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                                new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                                false);
                                        }
                                        //f.UpdateAllChunks();
                                    }
                                }
                                else
                                {
                                    if (voxelObject.GetCurrentFrame().EditingVoxels == null)
                                    {
                                        voxelObject.GetCurrentFrame().EditingVoxels =
                                            new Voxel[voxelObject.XSize*voxelObject.YSize*voxelObject.ZSize];
                                        Helper.CopyVoxelsInBox(ref voxelObject.GetCurrentFrame().Voxels,
                                            ref voxelObject.GetCurrentFrame().EditingVoxels,
                                            new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                            new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                            false);
                                    }
                                    //voxelObject.GetCurrentFrame().EditingVoxels = null;
                                    //voxelObject.UpdateAllChunks();


                                }
                                PicaVoxelPoint brushPos = new PicaVoxelPoint(voxelObject.GetVoxelPosition(r.GetPoint(d)));

                                

                                if (propogateAllFrames)
                                {
                                    foreach (Frame f in voxelObject.Frames)
                                    {
                                        //f.EditingVoxels =
                                        //    new Voxel[voxelObject.XSize * voxelObject.YSize * voxelObject.ZSize];
                                        Helper.CopyVoxelsInBox(ref f.Voxels, ref f.EditingVoxels,
                                            new PicaVoxelBox(previousBrushPos.X - voxelObject.XChunkSize, previousBrushPos.Y - voxelObject.YChunkSize, previousBrushPos.Z - voxelObject.ZChunkSize, previousBrushPos.X + EditorPersistence.BrushSize.X + voxelObject.XChunkSize, previousBrushPos.Y + EditorPersistence.BrushSize.Y + voxelObject.YChunkSize, previousBrushPos.Z + EditorPersistence.BrushSize.Z + voxelObject.ZChunkSize),
                                            new PicaVoxelBox(previousBrushPos.X - voxelObject.XChunkSize, previousBrushPos.Y - voxelObject.YChunkSize, previousBrushPos.Z - voxelObject.ZChunkSize, previousBrushPos.X + EditorPersistence.BrushSize.X + voxelObject.XChunkSize, previousBrushPos.Y + EditorPersistence.BrushSize.Y + voxelObject.YChunkSize, previousBrushPos.Z + EditorPersistence.BrushSize.Z + voxelObject.ZChunkSize),
                                            new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                            new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                            false);

                                        
                                    }
                                }
                                else
                                {
                                    //voxelObject.GetCurrentFrame().EditingVoxels =
                                    //    new Voxel[voxelObject.XSize * voxelObject.YSize * voxelObject.ZSize];
                                    //Helper.CopyVoxelsInBox(ref voxelObject.GetCurrentFrame().Voxels,
                                    //    ref voxelObject.GetCurrentFrame().EditingVoxels,
                                    //    new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                    //    new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                    //    false);
                                    Helper.CopyVoxelsInBox(ref voxelObject.GetCurrentFrame().Voxels,
                                        ref voxelObject.GetCurrentFrame().EditingVoxels,
                                            new PicaVoxelBox(previousBrushPos.X - voxelObject.XChunkSize, previousBrushPos.Y - voxelObject.YChunkSize, previousBrushPos.Z - voxelObject.ZChunkSize, previousBrushPos.X + EditorPersistence.BrushSize.X + voxelObject.XChunkSize, previousBrushPos.Y + EditorPersistence.BrushSize.Y + voxelObject.YChunkSize, previousBrushPos.Z + EditorPersistence.BrushSize.Z + voxelObject.ZChunkSize),
                                            new PicaVoxelBox(previousBrushPos.X - voxelObject.XChunkSize, previousBrushPos.Y - voxelObject.YChunkSize, previousBrushPos.Z - voxelObject.ZChunkSize, previousBrushPos.X + EditorPersistence.BrushSize.X + voxelObject.XChunkSize, previousBrushPos.Y + EditorPersistence.BrushSize.Y + voxelObject.YChunkSize, previousBrushPos.Z + EditorPersistence.BrushSize.Z + voxelObject.ZChunkSize),
                                            new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                            new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                            false);

                                }

                                SetChunksInBoxDirty(new PicaVoxelBox(previousBrushPos.X - voxelObject.XChunkSize,
                                    previousBrushPos.Y - voxelObject.YChunkSize, previousBrushPos.Z - voxelObject.ZChunkSize,
                                    previousBrushPos.X + EditorPersistence.BrushSize.X + voxelObject.XChunkSize,
                                    previousBrushPos.Y + EditorPersistence.BrushSize.Y + voxelObject.YChunkSize,
                                    previousBrushPos.Z + EditorPersistence.BrushSize.Z + voxelObject.ZChunkSize));

                                int bx = brushPos.X -
                                         (EditorPersistence.BrushAnchorX == AnchorX.Center
                                             ? EditorPersistence.BrushSize.X/2
                                             : EditorPersistence.BrushAnchorX == AnchorX.Right
                                                 ? EditorPersistence.BrushSize.X - 1
                                                 : 0);
                                int by = brushPos.Y -
                                         (EditorPersistence.BrushAnchorY == AnchorY.Center
                                             ? EditorPersistence.BrushSize.Y/2
                                             : EditorPersistence.BrushAnchorY == AnchorY.Top
                                                 ? EditorPersistence.BrushSize.Y - 1
                                                 : 0);
                                int bz = brushPos.Z -
                                         (EditorPersistence.BrushAnchorZ == AnchorZ.Center
                                             ? EditorPersistence.BrushSize.Z/2
                                             : EditorPersistence.BrushAnchorZ == AnchorZ.Back
                                                 ? EditorPersistence.BrushSize.Z - 1
                                                 : 0);

                                previousBrushPos = new PicaVoxelPoint(bx,by,bz);

                              

                                for (int x = 0; x < EditorPersistence.BrushSize.X; x++)
                                {
                                    for (int y = 0; y < EditorPersistence.BrushSize.Y; y++)
                                    {
                                        for (int z = 0; z < EditorPersistence.BrushSize.Z; z++)
                                        {
                                            if (bx < 0 || by < 0 || bz < 0 || bx >= voxelObject.XSize ||
                                                by >= voxelObject.YSize || bz >= voxelObject.ZSize)
                                            {
                                                bz++;
                                                continue;
                                            }

                                            if (
                                                EditorPersistence.Brush[
                                                    x +
                                                    (EditorPersistence.BrushSize.X)*
                                                    (y + (EditorPersistence.BrushSize.Y)*z)].Active)
                                            {
                                                if (propogateAllFrames)
                                                {
                                                    foreach (Frame f in voxelObject.Frames)
                                                    {
                                                        if (EditorPersistence.CursorMode == EditorCursorMode.BrushPaint &&
                                                            !f.Voxels[bx + voxelObject.XSize*(by + voxelObject.YSize*bz)
                                                                ].Active) continue;
                                                        f.SetVoxelAtArrayPosition(bx, by, bz, new Voxel()
                                                        {
                                                            Color =
                                                                EditorPersistence.Brush[
                                                                    x +
                                                                    (EditorPersistence.BrushSize.X)*
                                                                    (y + (EditorPersistence.BrushSize.Y)*z)].Color,
                                                            Value =
                                                                EditorPersistence.Brush[
                                                                    x +
                                                                    (EditorPersistence.BrushSize.X)*
                                                                    (y + (EditorPersistence.BrushSize.Y)*z)].Value,
                                                            State =
                                                                (EditorPersistence.CursorMode !=
                                                                 EditorCursorMode.BrushSubtract)?VoxelState.Active : VoxelState.Inactive
                                                        });
                                                    
                                                    }
                                                    
                                                }
                                                else
                                                {
                                                    if (EditorPersistence.CursorMode == EditorCursorMode.BrushPaint &&
                                                        !voxelObject.GetCurrentFrame().Voxels[
                                                            bx + voxelObject.XSize*(by + voxelObject.YSize*bz)].Active)
                                                        continue;
                                                    voxelObject.SetVoxelAtArrayPosition(bx, by, bz, new Voxel()
                                                    {
                                                        Color =
                                                            EditorPersistence.Brush[
                                                                x +
                                                                (EditorPersistence.BrushSize.X)*
                                                                (y + (EditorPersistence.BrushSize.Y)*z)].Color,
                                                        Value =
                                                            EditorPersistence.Brush[
                                                                x +
                                                                (EditorPersistence.BrushSize.X)*
                                                                (y + (EditorPersistence.BrushSize.Y)*z)].Value,
                                                        State =
                                                                (EditorPersistence.CursorMode !=
                                                                 EditorCursorMode.BrushSubtract) ? VoxelState.Active : VoxelState.Inactive
                                                    });
                                                  
                                                }

                                            }

                                            bz++;
                                        }
                                        bz = brushPos.Z -
                                             (EditorPersistence.BrushAnchorZ == AnchorZ.Center
                                                 ? EditorPersistence.BrushSize.Z/2
                                                 : EditorPersistence.BrushAnchorZ == AnchorZ.Back
                                                     ? EditorPersistence.BrushSize.Z - 1
                                                     : 0);
                                        by++;
                                    }
                                    by = brushPos.Y -
                                         (EditorPersistence.BrushAnchorY == AnchorY.Center
                                             ? EditorPersistence.BrushSize.Y/2
                                             : EditorPersistence.BrushAnchorY == AnchorY.Top
                                                 ? EditorPersistence.BrushSize.Y - 1
                                                 : 0);
                                    bx++;
                                }

                                if (propogateAllFrames)
                                    foreach (Frame f in voxelObject.Frames) f.UpdateChunks(true);
                                else voxelObject.UpdateChunks(true);
                            }
                        }


                        // Mouse Up (Brush mode)
                        if (validBrushPos && e.type == EventType.MouseUp && e.button == 0)// &&
                           // voxelObject.GetCurrentFrame().EditingVoxels != null)
                        {
                            if ((EditorPersistence.CursorMode == EditorCursorMode.BrushAdd ||
                                 EditorPersistence.CursorMode == EditorCursorMode.BrushPaint ||
                                 EditorPersistence.CursorMode == EditorCursorMode.BrushSubtract))
                            {
                                voxelObject.GetCurrentFrame().EditingVoxels = null;

                                if (propogateAllFrames)
                                {
                                    List<Object> undoObjects = new List<Object>();

                                    foreach (Frame frame in voxelObject.Frames)
                                    {
                                        undoObjects.Add(frame);
                                    }
                                    undoObjects.Add(voxelObject);
                                    Undo.RecordObjects(undoObjects.ToArray(), "Voxel Editing");
                                    //foreach (Frame f in voxelObject.Frames)
                                    //{
                                    //    ////Helper.CopyVoxelsInBox(ref f.EditingVoxels,
                                    //    ////    ref f.Voxels,
                                    //    ////    new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                    //    ////    new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                    //    ////    false);
                                    //    //Helper.CopyVoxelsInBox(ref f.EditingVoxels,
                                    //    //    ref f.Voxels,
                                    //    //    new PicaVoxelBox(previousBrushPos.X , previousBrushPos.Y , previousBrushPos.Y , previousBrushPos.X + EditorPersistence.BrushSize.X, previousBrushPos.Y + EditorPersistence.BrushSize.Y, previousBrushPos.Z + EditorPersistence.BrushSize.Z),
                                    //    //    new PicaVoxelBox(previousBrushPos.X, previousBrushPos.Y, previousBrushPos.Y, previousBrushPos.X + EditorPersistence.BrushSize.X , previousBrushPos.Y + EditorPersistence.BrushSize.Y, previousBrushPos.Z + EditorPersistence.BrushSize.Z),
                                    //    //    new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                    //    //    new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                    //    //    false);
                                    //}
                                }
                                else
                                {
                                    Undo.RecordObjects(new UnityEngine.Object[]
                                    {
                                        voxelObject.GetCurrentFrame(),
                                        voxelObject,
                                    }, "Voxel Editing");
                                    //Helper.CopyVoxelsInBox(ref voxelObject.GetCurrentFrame().EditingVoxels,
                                    //    ref voxelObject.GetCurrentFrame().Voxels,
                                    //    new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                    //    new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                    //    false);
                                    //Helper.CopyVoxelsInBox(ref voxelObject.GetCurrentFrame().EditingVoxels,
                                    //    ref voxelObject.GetCurrentFrame().Voxels,
                                    //       new PicaVoxelBox(previousBrushPos.X, previousBrushPos.Y, previousBrushPos.Y, previousBrushPos.X + EditorPersistence.BrushSize.X, previousBrushPos.Y + EditorPersistence.BrushSize.Y, previousBrushPos.Z + EditorPersistence.BrushSize.Z),
                                    //        new PicaVoxelBox(previousBrushPos.X, previousBrushPos.Y, previousBrushPos.Y, previousBrushPos.X + EditorPersistence.BrushSize.X, previousBrushPos.Y + EditorPersistence.BrushSize.Y, previousBrushPos.Z + EditorPersistence.BrushSize.Z),
                                    //       new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                    //       new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                    //       false);
                                }

                                PicaVoxelPoint brushPos = new PicaVoxelPoint(voxelObject.GetVoxelPosition(r.GetPoint(d)));
                                int bx = brushPos.X -
                                         (EditorPersistence.BrushAnchorX == AnchorX.Center
                                             ? EditorPersistence.BrushSize.X/2
                                             : EditorPersistence.BrushAnchorX == AnchorX.Right
                                                 ? EditorPersistence.BrushSize.X - 1
                                                 : 0);
                                int by = brushPos.Y -
                                         (EditorPersistence.BrushAnchorY == AnchorY.Center
                                             ? EditorPersistence.BrushSize.Y/2
                                             : EditorPersistence.BrushAnchorY == AnchorY.Top
                                                 ? EditorPersistence.BrushSize.Y - 1
                                                 : 0);
                                int bz = brushPos.Z -
                                         (EditorPersistence.BrushAnchorZ == AnchorZ.Center
                                             ? EditorPersistence.BrushSize.Z/2
                                             : EditorPersistence.BrushAnchorZ == AnchorZ.Back
                                                 ? EditorPersistence.BrushSize.Z - 1
                                                 : 0);

                                previousBrushPos = new PicaVoxelPoint(bx,by,bz);

                              

                                for (int x = 0; x < EditorPersistence.BrushSize.X; x++)
                                {
                                    for (int y = 0; y < EditorPersistence.BrushSize.Y; y++)
                                    {
                                        for (int z = 0; z < EditorPersistence.BrushSize.Z; z++)
                                        {
                                            if (bx < 0 || by < 0 || bz < 0 || bx >= voxelObject.XSize ||
                                                by >= voxelObject.YSize || bz >= voxelObject.ZSize)
                                            {
                                                bz++;
                                                continue;
                                            }

                                            if (
                                                EditorPersistence.Brush[
                                                    x +
                                                    (EditorPersistence.BrushSize.X)*
                                                    (y + (EditorPersistence.BrushSize.Y)*z)].Active)
                                            {
                                                if (propogateAllFrames)
                                                {
                                                    foreach (Frame f in voxelObject.Frames)
                                                    {
                                                        if (EditorPersistence.CursorMode == EditorCursorMode.BrushPaint &&
                                                            !f.Voxels[bx + voxelObject.XSize*(by + voxelObject.YSize*bz)
                                                                ].Active) continue;
                                                        f.SetVoxelAtArrayPosition(bx, by, bz, new Voxel()
                                                        {
                                                            Color =
                                                                EditorPersistence.Brush[
                                                                    x +
                                                                    (EditorPersistence.BrushSize.X)*
                                                                    (y + (EditorPersistence.BrushSize.Y)*z)].Color,
                                                            Value =
                                                                EditorPersistence.Brush[
                                                                    x +
                                                                    (EditorPersistence.BrushSize.X)*
                                                                    (y + (EditorPersistence.BrushSize.Y)*z)].Value,
                                                            State =
                                                                (EditorPersistence.CursorMode !=
                                                                 EditorCursorMode.BrushSubtract) ? VoxelState.Active : VoxelState.Inactive
                                                        });
                                                    
                                                    }
                                                    
                                                }
                                                else
                                                {
                                                    if (EditorPersistence.CursorMode == EditorCursorMode.BrushPaint &&
                                                        !voxelObject.GetCurrentFrame().Voxels[
                                                            bx + voxelObject.XSize*(by + voxelObject.YSize*bz)].Active)
                                                        continue;
                                                    voxelObject.SetVoxelAtArrayPosition(bx, by, bz, new Voxel()
                                                    {
                                                        Color =
                                                            EditorPersistence.Brush[
                                                                x +
                                                                (EditorPersistence.BrushSize.X)*
                                                                (y + (EditorPersistence.BrushSize.Y)*z)].Color,
                                                        Value =
                                                            EditorPersistence.Brush[
                                                                x +
                                                                (EditorPersistence.BrushSize.X)*
                                                                (y + (EditorPersistence.BrushSize.Y)*z)].Value,
                                                        State =
                                                                (EditorPersistence.CursorMode !=
                                                                 EditorCursorMode.BrushSubtract) ? VoxelState.Active : VoxelState.Inactive
                                                    });
                                                  
                                                }

                                            }

                                            bz++;
                                        }
                                        bz = brushPos.Z -
                                             (EditorPersistence.BrushAnchorZ == AnchorZ.Center
                                                 ? EditorPersistence.BrushSize.Z/2
                                                 : EditorPersistence.BrushAnchorZ == AnchorZ.Back
                                                     ? EditorPersistence.BrushSize.Z - 1
                                                     : 0);
                                        by++;
                                    }
                                    by = brushPos.Y -
                                         (EditorPersistence.BrushAnchorY == AnchorY.Center
                                             ? EditorPersistence.BrushSize.Y/2
                                             : EditorPersistence.BrushAnchorY == AnchorY.Top
                                                 ? EditorPersistence.BrushSize.Y - 1
                                                 : 0);
                                    bx++;
                                }

                                if (propogateAllFrames)
                                    foreach (Frame f in voxelObject.Frames) f.UpdateChunks(true);
                                else voxelObject.UpdateChunks(true);
                            


                                


                                currentBox = null;
                                boxStart = null;
                                voxelObject.SaveForSerialize();
                            }
                        }


                        break;
                    }

                }

                //if (!validBrushPos && (EditorPersistence.CursorMode == EditorCursorMode.BrushAdd ||
                //                       EditorPersistence.CursorMode == EditorCursorMode.BrushPaint ||
                //                       EditorPersistence.CursorMode == EditorCursorMode.BrushSubtract))
                //{
                //    if (propogateAllFrames)
                //        foreach (Frame f in voxelObject.Frames) f.EditingVoxels = null;
                //    else voxelObject.GetCurrentFrame().EditingVoxels = null;
                //}

                // Mouse Up (non-brush)
                if (e.type == EventType.MouseUp && e.button == 0 && voxelObject.GetCurrentFrame().EditingVoxels != null)
                {
                    if ((EditorPersistence.CursorMode != EditorCursorMode.BrushAdd &&
                         EditorPersistence.CursorMode != EditorCursorMode.BrushPaint &&
                         EditorPersistence.CursorMode != EditorCursorMode.BrushSubtract))
                    {
                        if (propogateAllFrames)
                        {
                            List<Object> undoObjects = new List<Object>();

                            foreach (Frame frame in voxelObject.Frames)
                            {
                                undoObjects.Add(frame);
                            }
                            undoObjects.Add(voxelObject);
                            Undo.RecordObjects(undoObjects.ToArray(), "Voxel Editing");

                            foreach (Frame f in voxelObject.Frames)
                            {
                                //Helper.CopyVoxelsInBox(ref f.EditingVoxels,
                                //    ref f.Voxels,
                                //    new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                //    new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize), false);
                                Helper.CopyVoxelsInBox(ref f.EditingVoxels,
                                            ref f.Voxels, changedVoxelExtents, changedVoxelExtents,
                                            new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                            new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                            false);
                                f.EditingVoxels = null;
                            }
                        }
                        else
                        {
                            Undo.RecordObjects(new UnityEngine.Object[]
                            {
                                voxelObject.GetCurrentFrame(),
                                voxelObject,
                            }, "Voxel Editing");
                            //Helper.CopyVoxelsInBox(ref voxelObject.GetCurrentFrame().EditingVoxels,
                            //    ref voxelObject.GetCurrentFrame().Voxels, new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize), new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize), false);
                            Helper.CopyVoxelsInBox(ref voxelObject.GetCurrentFrame().EditingVoxels,
                                            ref voxelObject.GetCurrentFrame().Voxels, changedVoxelExtents, changedVoxelExtents,
                                            new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                            new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize),
                                            false);
                            voxelObject.GetCurrentFrame().EditingVoxels = null;
                            //voxelObject.SaveForSerialize();
                        }


                        currentBox = null;
                        boxStart = null;

                        voxelObject.SaveForSerialize();

                    }
                }
            }

            if (EditorPersistence.CursorMode == EditorCursorMode.Select)
            {
                Gizmos.matrix = voxelObject.GetCurrentFrame().transform.FindChild("Chunks").localToWorldMatrix;
                Handles.color = Color.red;

                int i = 0;
                Vector3 newPos = Vector3.zero;

                bool changedBox = false;

                for (int x = EditorPersistence.SelectBox.BottomLeftFront.X;
                    x <= EditorPersistence.SelectBox.TopRightBack.X + 1;
                    x += EditorPersistence.SelectBox.TopRightBack.X + 1 - EditorPersistence.SelectBox.BottomLeftFront.X)
                {
                    for (int y = EditorPersistence.SelectBox.BottomLeftFront.Y;
                        y <= EditorPersistence.SelectBox.TopRightBack.Y + 1;
                        y +=
                            EditorPersistence.SelectBox.TopRightBack.Y + 1 -
                            EditorPersistence.SelectBox.BottomLeftFront.Y)
                    {
                        for (int z = EditorPersistence.SelectBox.BottomLeftFront.Z;
                            z <= EditorPersistence.SelectBox.TopRightBack.Z + 1;
                            z +=
                                EditorPersistence.SelectBox.TopRightBack.Z + 1 -
                                EditorPersistence.SelectBox.BottomLeftFront.Z)
                        {
                            Vector3 handlePos =
                                voxelObject.transform.TransformPoint((new Vector3(x, y, z)*voxelObject.VoxelSize) -
                                                                     voxelObject.Pivot);

                            EditorHandles.DragHandleResult dhResult;
                            newPos = EditorHandles.DragHandle(handlePos, HandleUtility.GetHandleSize(handlePos)*0.25f,
                                Handles.SphereCap, Color.red, out dhResult);

                            if (dhResult == EditorHandles.DragHandleResult.LMBDrag)
                            {
                                Voxel? handleVox = voxelObject.GetVoxelAtWorldPosition(newPos);
                                if (handleVox.HasValue)
                                {
                                    if (i == 0)
                                    {
                                        EditorPersistence.SelectBox =
                                            new PicaVoxelBox(
                                                new PicaVoxelPoint((int) voxelObject.GetVoxelPosition(newPos).x,
                                                    (int) voxelObject.GetVoxelPosition(newPos).y,
                                                    (int) voxelObject.GetVoxelPosition(newPos).z),
                                                new PicaVoxelPoint(EditorPersistence.SelectBox.TopRightBack.X,
                                                    EditorPersistence.SelectBox.TopRightBack.Y,
                                                    EditorPersistence.SelectBox.TopRightBack.Z));
                                        changedBox = true;
                                    }
                                    if (i == 1)
                                    {
                                        EditorPersistence.SelectBox =
                                            new PicaVoxelBox(
                                                new PicaVoxelPoint((int)voxelObject.GetVoxelPosition(newPos).x,
                                                    (int)voxelObject.GetVoxelPosition(newPos).y,
                                                    EditorPersistence.SelectBox.BottomLeftFront.Z),
                                                new PicaVoxelPoint(EditorPersistence.SelectBox.TopRightBack.X,
                                                    EditorPersistence.SelectBox.TopRightBack.Y,
                                                    (int)voxelObject.GetVoxelPosition(newPos).z));

                                        changedBox = true;
                                    }
                                    if (i == 2)
                                    {
                                        EditorPersistence.SelectBox =
                                            new PicaVoxelBox(
                                                new PicaVoxelPoint((int)voxelObject.GetVoxelPosition(newPos).x,
                                                    EditorPersistence.SelectBox.BottomLeftFront.Y,
                                                    (int)voxelObject.GetVoxelPosition(newPos).z),
                                                new PicaVoxelPoint(EditorPersistence.SelectBox.TopRightBack.X,
                                                    (int)voxelObject.GetVoxelPosition(newPos).y,
                                                    EditorPersistence.SelectBox.TopRightBack.Z));

                                        changedBox = true;
                                    }
                                    if (i == 3)
                                    {
                                        EditorPersistence.SelectBox =
                                           new PicaVoxelBox(
                                               new PicaVoxelPoint((int)voxelObject.GetVoxelPosition(newPos).x,
                                                   EditorPersistence.SelectBox.BottomLeftFront.Y,
                                                   EditorPersistence.SelectBox.BottomLeftFront.Z),
                                               new PicaVoxelPoint(EditorPersistence.SelectBox.TopRightBack.X,
                                                   (int)voxelObject.GetVoxelPosition(newPos).y,
                                                   (int)voxelObject.GetVoxelPosition(newPos).z));

                                        changedBox = true;
                                    }

                                    if (i == 4)
                                    {
                                        EditorPersistence.SelectBox =
                                           new PicaVoxelBox(
                                               new PicaVoxelPoint(EditorPersistence.SelectBox.BottomLeftFront.X,
                                                    (int)voxelObject.GetVoxelPosition(newPos).y,
                                                   (int)voxelObject.GetVoxelPosition(newPos).z),
                                               new PicaVoxelPoint(
                                                   (int)voxelObject.GetVoxelPosition(newPos).x,
                                                   EditorPersistence.SelectBox.TopRightBack.Y,
                                                   EditorPersistence.SelectBox.TopRightBack.Z));

                                        changedBox = true;
                                    }
                                    if (i == 5)
                                    {
                                        EditorPersistence.SelectBox = new PicaVoxelBox(
                                               new PicaVoxelPoint(EditorPersistence.SelectBox.BottomLeftFront.X,
                                                    (int)voxelObject.GetVoxelPosition(newPos).y,
                                                   EditorPersistence.SelectBox.BottomLeftFront.Z),
                                               new PicaVoxelPoint(
                                                   (int)voxelObject.GetVoxelPosition(newPos).x,
                                                   EditorPersistence.SelectBox.TopRightBack.Y,
                                                   (int)voxelObject.GetVoxelPosition(newPos).z));

                                        changedBox = true;
                                    }
                                    if (i == 6)
                                    {
                                        EditorPersistence.SelectBox = new PicaVoxelBox(
                                              new PicaVoxelPoint(EditorPersistence.SelectBox.BottomLeftFront.X,
                                                    EditorPersistence.SelectBox.BottomLeftFront.Y,
                                                    (int)voxelObject.GetVoxelPosition(newPos).z),
                                              new PicaVoxelPoint(
                                                  (int)voxelObject.GetVoxelPosition(newPos).x,
                                                  (int)voxelObject.GetVoxelPosition(newPos).y,
                                                  EditorPersistence.SelectBox.TopRightBack.Z));

                                        changedBox = true;
                                    }
                                    if (i == 7)
                                    {
                                        EditorPersistence.SelectBox = new PicaVoxelBox(
                                              new PicaVoxelPoint(EditorPersistence.SelectBox.BottomLeftFront.X,
                                                    EditorPersistence.SelectBox.BottomLeftFront.Y,
                                                   EditorPersistence.SelectBox.BottomLeftFront.Z),
                                              new PicaVoxelPoint(
                                                  (int)voxelObject.GetVoxelPosition(newPos).x,
                                                  (int)voxelObject.GetVoxelPosition(newPos).y,
                                                   (int)voxelObject.GetVoxelPosition(newPos).z));

                                        changedBox = true;
                                    }
                                }


                            }

                            i++;
                            if (changedBox) break;
                        }
                        if (changedBox) break;
                    }
                    if (changedBox) break;
                }


                Vector3[] corners =
                {
                    voxelObject.transform.TransformPoint((EditorPersistence.SelectBox.BottomLeftFront.ToVector3()*
                                                          voxelSize) - voxelObject.Pivot),
                    voxelObject.transform.TransformPoint(
                        (new Vector3(EditorPersistence.SelectBox.BottomLeftFront.X,
                            EditorPersistence.SelectBox.BottomLeftFront.Y,
                            EditorPersistence.SelectBox.TopRightBack.Z + 1)*voxelSize) - voxelObject.Pivot),
                    voxelObject.transform.TransformPoint(
                        (new Vector3(EditorPersistence.SelectBox.TopRightBack.X + 1,
                            EditorPersistence.SelectBox.BottomLeftFront.Y,
                            EditorPersistence.SelectBox.TopRightBack.Z + 1)*voxelSize) - voxelObject.Pivot),
                    voxelObject.transform.TransformPoint(
                        (new Vector3(EditorPersistence.SelectBox.TopRightBack.X + 1,
                            EditorPersistence.SelectBox.BottomLeftFront.Y, EditorPersistence.SelectBox.BottomLeftFront.Z)*
                         voxelSize) - voxelObject.Pivot),
                    voxelObject.transform.TransformPoint(
                        (new Vector3(EditorPersistence.SelectBox.BottomLeftFront.X,
                            EditorPersistence.SelectBox.TopRightBack.Y + 1,
                            EditorPersistence.SelectBox.BottomLeftFront.Z)*voxelSize) - voxelObject.Pivot),
                    voxelObject.transform.TransformPoint(
                        (new Vector3(EditorPersistence.SelectBox.BottomLeftFront.X,
                            EditorPersistence.SelectBox.TopRightBack.Y + 1,
                            EditorPersistence.SelectBox.TopRightBack.Z + 1)*voxelSize) - voxelObject.Pivot),
                    voxelObject.transform.TransformPoint(((EditorPersistence.SelectBox.TopRightBack.ToVector3() +
                                                           Vector3.one)*voxelSize) - voxelObject.Pivot),
                    voxelObject.transform.TransformPoint(
                        (new Vector3(EditorPersistence.SelectBox.TopRightBack.X + 1,
                            EditorPersistence.SelectBox.TopRightBack.Y + 1,
                            EditorPersistence.SelectBox.BottomLeftFront.Z)*voxelSize) - voxelObject.Pivot)
                };


                Handles.DrawSolidRectangleWithOutline(new[] {corners[0], corners[1], corners[2], corners[3]},
                    Color.white*0.1f, Color.black);
                Handles.DrawSolidRectangleWithOutline(new[] {corners[0], corners[4], corners[7], corners[3]},
                    Color.white*0.1f, Color.black);
                Handles.DrawSolidRectangleWithOutline(new[] {corners[1], corners[5], corners[4], corners[0]},
                    Color.white*0.1f, Color.black);
                Handles.DrawSolidRectangleWithOutline(new[] {corners[2], corners[6], corners[5], corners[1]},
                    Color.white*0.1f, Color.black);
                Handles.DrawSolidRectangleWithOutline(new[] {corners[3], corners[7], corners[6], corners[2]},
                    Color.white*0.1f, Color.black);
                Handles.DrawSolidRectangleWithOutline(new[] {corners[4], corners[5], corners[6], corners[7]},
                    Color.white*0.1f, Color.black);



            }

            
        }
示例#3
0
        public void SetChunkAtVoxelPositionDirty(int x, int y, int z)
        {
            if (x < 0 || y < 0 || z < 0 || x >= ParentVolume.XSize || y >= ParentVolume.YSize || z >= ParentVolume.ZSize)
                return;

            PicaVoxelPoint chunkPos = new PicaVoxelPoint((int)(x / ParentVolume.XChunkSize), (int)(y / ParentVolume.YChunkSize),
                    (int)(z / ParentVolume.ZChunkSize));

            if (chunks[chunkPos.X, chunkPos.Y, chunkPos.Z] != null) chunks[chunkPos.X, chunkPos.Y, chunkPos.Z].IsUpdated = true;
            
        }
示例#4
0
 /// <summary>
 /// Attempts to set a voxel's state within this frame, at a specified array position
 /// </summary>
 /// <param name="pos">A PicaVoxelPoint location within the 3D array of voxels</param>
 /// <param name="state">The new state to set to</param>
 public void SetVoxelStateAtArrayPosition(PicaVoxelPoint pos, VoxelState state)
 {
     SetVoxelStateAtArrayPosition(pos.X, pos.Y, pos.Z, state);
 }
示例#5
0
 /// <summary>
 /// Attempts to set a voxel within this frame, at a specified array position
 /// </summary>
 /// <param name="pos">A PicaVoxelPoint location within the 3D array of voxels</param>
 /// <param name="vox">The new voxel to set to</param>
 public void SetVoxelAtArrayPosition(PicaVoxelPoint pos, Voxel vox)
 {
     SetVoxelAtArrayPosition(pos.X, pos.Y, pos.Z, vox);
 }
示例#6
0
 /// <summary>
 /// Attempts to set a voxel's state within this volume's current frame, at a specified array position
 /// </summary>
 /// <param name="pos">A PicaVoxelPoint location within the 3D array of voxels</param>
 /// <param name="state">The new state to set to</param>
 public void SetVoxelStateAtArrayPosition(PicaVoxelPoint pos, VoxelState state)
 {
     Frames[CurrentFrame].SetVoxelStateAtArrayPosition(pos, state);
 }
示例#7
0
 /// <summary>
 /// Attempts to set a voxel within this volume's current frame, at a specified array position
 /// </summary>
 /// <param name="pos">A PicaVoxelPoint location within the 3D array of voxels</param>
 /// <param name="vox">The new voxel to set to</param>
 public void SetVoxelAtArrayPosition(PicaVoxelPoint pos, Voxel vox)
 {
     Frames[CurrentFrame].SetVoxelAtArrayPosition(pos, vox);
 }
示例#8
0
        private void AddChunkToUpdateList(int x, int y, int z)
        {
            var pvp = new PicaVoxelPoint(x, y, z);
            if (chunksToUpdate.Contains(pvp)) return;

            chunks[x, y, z].IsUpdated = true;
            chunksToUpdate.Add(pvp);
        }
示例#9
0
 public void Add(Voxel voxel, PicaVoxelPoint arrayPoint, Vector3 worldPos)
 {
     Voxels.Add(new BatchVoxel(voxel, arrayPoint, worldPos));
 }
示例#10
0
 public BatchVoxel(Voxel voxel, PicaVoxelPoint arrayPoint, Vector3 worldPos)
 {
     Voxel = voxel;
     ArrayPosition = arrayPoint;
     WorldPosition = worldPos;
 }