Example #1
0
    private bool DrawBoxSelection()
    {
        if (viewModel.PreviousModelFactory == null)
        {
            return(false);
        }
        NPVoxModel   previousTransformedModel = viewModel.PreviousModelFactory.GetProduct();
        NPVoxToUnity npVoxToUnity             = new NPVoxToUnity(previousTransformedModel, viewModel.Animation.MeshFactory.VoxelSize);

        List <NPVoxBox> boxes = viewModel.GetNonEditableBoxes();

        if (boxes != null)
        {
            foreach (NPVoxBox b in boxes)
            {
                NPVoxHandles.DrawBoxSelection(npVoxToUnity, b, false);
            }
        }

        if (!viewModel.IsAreaSelectionActive())
        {
            return(false);
        }


        NPVoxBox box = viewModel.GetAffectedBox();

        if (Event.current.shift)
        {
            // affected area picker
            NPVoxCoord someCoord    = box.RoundedCenter;
            NPVoxCoord someNewCoord = NPVoxHandles.VoxelPicker(new NPVoxToUnity(previousTransformedModel, viewModel.Animation.MeshFactory.VoxelSize), someCoord, 0, ((NPVoxAnimationEditorSession)target).previewFilter.transform);
            if (!someCoord.Equals(someNewCoord))
            {
                viewModel.ChangeAffectedBox(new NPVoxBox(someNewCoord, someNewCoord));
            }
        }
        else
        {
            // affected area box
            NPVoxBox newBox = NPVoxHandles.DrawBoxSelection(npVoxToUnity, box);
            if (!newBox.Equals(box))
            {
                viewModel.ChangeAffectedBox(newBox);
            }
        }

        return(true);
    }
Example #2
0
    public static Bounds DrawBoundsSelection(Bounds previous, Vector3 cellOffset, float cellSize)
    {
        NPVoxToUnity npVoxToUnity = new NPVoxToUnity(null, Vector3.one * cellSize, cellOffset - Vector3.one * 0.5f * cellSize);
        NPVoxBox     previousBox  = new NPVoxBox(
            npVoxToUnity.ToVoxCoord(previous.min + Vector3.one * cellSize / 2),
            npVoxToUnity.ToVoxCoord(previous.max - Vector3.one * cellSize / 2)
            );
        NPVoxBox newBox = NPVoxHandles.DrawBoxSelection(npVoxToUnity, previousBox, true);

        if (!previousBox.Equals(newBox))
        {
            Bounds bounds = new Bounds(Vector3.zero, Vector3.zero);
            bounds.SetMinMax(
                npVoxToUnity.ToUnityPosition(newBox.LeftDownBack) - Vector3.one * cellSize / 2,
                npVoxToUnity.ToUnityPosition(newBox.RightUpForward) + Vector3.one * cellSize / 2
                );
            return(bounds);
        }
        else
        {
            return(previous);
        }
    }