Example #1
0
 public void GenerateMesh(Voxel[] voxels, float voxelSize, float overlapAmount, int xOffset, int yOffset, int zOffset, int xSize,
                          int ySize, int zSize, int ub0, int ub1, int ub2, float selfShadeIntensity, MeshingMode mode, MeshingMode colliderMode, bool immediate,
                          EditorPaintMode paintMode)
Example #2
0
        private void OnEnable()
        {
     
            voxelObject = (Volume) target;
            Undo.undoRedoPerformed += () => voxelObject.OnUndoRedo();

            voxelSizeProperty = serializedObject.FindProperty("VoxelSize");
            overlapAmountProperty = serializedObject.FindProperty("OverlapAmount");
            collisionMode = serializedObject.FindProperty("CollisionMode");
            meshingMode = serializedObject.FindProperty("MeshingMode");
            meshCompression = serializedObject.FindProperty("MeshCompression");
            colliderMeshingMode = serializedObject.FindProperty("MeshColliderMeshingMode");
            separateColliderMesh = serializedObject.FindProperty("GenerateMeshColliderSeparately");
            pivotProperty = serializedObject.FindProperty("Pivot");

            voxelSize = voxelSizeProperty.floatValue;
            overlapAmount = overlapAmountProperty.floatValue;
            pivot = pivotProperty.vector3Value;

            selfShadeInt = serializedObject.FindProperty("SelfShadingIntensity");

            drawGrid = voxelObject.DrawGrid;
            drawMesh = voxelObject.DrawMesh;
            runtimeOnlyMesh = serializedObject.FindProperty("RuntimOnlyMesh");

            material = serializedObject.FindProperty("Material");
            physicMaterial = serializedObject.FindProperty("PhysicMaterial");
            castShadows = serializedObject.FindProperty("CastShadows");
            receiveShadows = serializedObject.FindProperty("ReceiveShadows");
            chunkLayer = serializedObject.FindProperty("ChunkLayer");
            collisionTrigger = serializedObject.FindProperty("CollisionTrigger");

            if (voxelObject != null && !Application.isPlaying && PrefabUtility.GetPrefabType(voxelObject) != PrefabType.Prefab && PrefabUtility.GetPrefabType(voxelObject) != PrefabType.PrefabInstance)
            {
                string path = Path.Combine(Helper.GetMeshStorePath(), voxelObject.AssetGuid);
                if (!Directory.Exists(path))
                    voxelObject.CreateChunks();
            }

            if (!Application.isPlaying && voxelObject.gameObject.activeSelf && PrefabUtility.GetPrefabType(voxelObject) != PrefabType.Prefab && !voxelObject.RuntimOnlyMesh)
                foreach (var frame in voxelObject.Frames)
                {
                    if (frame.HasDeserialized) frame.UpdateChunks(true);
                    frame.HasDeserialized = false;
                }

            paintMode = voxelObject.PaintMode;

            if (EditorPersistence.SelectBox.BottomLeftFront.X > voxelObject.XSize - 1 ||
                EditorPersistence.SelectBox.BottomLeftFront.Y > voxelObject.YSize - 1 ||
                EditorPersistence.SelectBox.BottomLeftFront.Z > voxelObject.ZSize - 1 ||
                EditorPersistence.SelectBox.TopRightBack.X > voxelObject.XSize - 1 ||
                EditorPersistence.SelectBox.TopRightBack.Y > voxelObject.YSize - 1 ||
                EditorPersistence.SelectBox.TopRightBack.Z > voxelObject.ZSize - 1)
                EditorPersistence.SelectBox = new PicaVoxelBox(0, 0, 0, voxelObject.XSize - 1, voxelObject.YSize - 1, voxelObject.ZSize - 1);
        }
Example #3
0
 private void Generate(ref Voxel[] voxels, float voxelSize, float overlapAmount, int xOffset, int yOffset, int zOffset, int xSize, int ySize, int zSize, int ub0, int ub1, int ub2, float selfShadeIntensity, MeshingMode meshMode, EditorPaintMode paintMode)
Example #4
0
        private void OnSceneGUI()
        {
            voxelObject.GetCurrentFrame().UpdateTransformMatrix();

            if (Selection.Contains(voxelObject.gameObject))
                UnityEditor.Tools.hidden = voxelObject.IsEnabledForEditing;
            else
                UnityEditor.Tools.hidden = false;

            buttonJustClicked = false;

            if (voxelObject.transform.localScale != Vector3.one && !Application.isPlaying)
                voxelObject.transform.localScale = Vector3.one;

            foreach (Frame frame in voxelObject.Frames)
            {
                if (frame.transform.localScale != Vector3.one && !Application.isPlaying)
                    frame.transform.localScale = Vector3.one;

                if (frame.transform.FindChild("Chunks").localScale != Vector3.one && !Application.isPlaying)
                    frame.transform.FindChild("Chunks").localScale = Vector3.one;
            }


            if (!voxelObject.IsEnabledForEditing || Selection.objects.Length > 1 || EditorUtility.Buttons.Count == 0)
                return;

            if (Event.current.type == EventType.Layout)
            {
                HandleUtility.AddDefaultControl(0);
            }


            Event e = Event.current;

            GUILayout.BeginArea(new Rect(10, 10, 120, 500));
            GUILayout.BeginVertical();

            GUISkin skin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);
            paintMode =
                (EditorPaintMode)
                    EditorGUILayout.EnumPopup(voxelObject.PaintMode,
                        new GUIStyle(skin.GetStyle("DropDown")) {margin = new RectOffset(0, 0, 0, 5)},
                        GUILayout.Width(100));
            if (paintMode != voxelObject.PaintMode)
            {
                voxelObject.PaintMode = paintMode;
                voxelObject.UpdateAllChunks();
            }

            EditorPersistence.SelectedValue =
                (byte)
                    GUILayout.HorizontalSlider(EditorPersistence.SelectedValue, 0f, 255f,
                        new GUIStyle(GUI.skin.horizontalSlider) {margin = new RectOffset(0, 0, 0, 0)},
                        new GUIStyle(GUI.skin.horizontalSliderThumb) {margin = new RectOffset(0, 0, 0, 0)},
                        GUILayout.Width(100)); //.IntSlider((int)selectedValue, 0, 255, GUILayout.Width(120));

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Value:",
                new GUIStyle(GUI.skin.label) {padding = new RectOffset(0, 0, 0, 0), margin = new RectOffset(0, 0, 0, 5)},
                GUILayout.Width(42));
            string inputSelectedValue = EditorGUILayout.TextField(EditorPersistence.SelectedValue.ToString(),
                new GUIStyle(GUI.skin.textField)
                {
                    padding = new RectOffset(2, 0, 2, 0),
                    margin = new RectOffset(0, 0, 0, 5),
                    fontStyle = FontStyle.Bold
                }, GUILayout.Width(50), GUILayout.Height(20));
            int trySelectedValue;
            int.TryParse(inputSelectedValue, out trySelectedValue);
            if (trySelectedValue >= 0 && trySelectedValue <= 255)
                EditorPersistence.SelectedValue = (byte) trySelectedValue;
            GUILayout.EndHorizontal();

            int colNum = 0;

            for (int y = 0; y < 5; y++)
            {
                GUILayout.BeginHorizontal();
                for (int x = 0; x < 5; x++)
                {
                    if (PaletteButton(voxelObject.PaletteColors[colNum], EditorPersistence.SelectedColor == colNum))
                    {

                        EditorPersistence.SelectedColor = colNum;
                        buttonJustClicked = true;
                    }
                    colNum++;
                }
                GUILayout.EndHorizontal();
            }
            newColor = EditorGUILayout.ColorField(voxelObject.PaletteColors[EditorPersistence.SelectedColor],
                GUILayout.Width(90));
            if (newColor != voxelObject.PaletteColors[EditorPersistence.SelectedColor])
                voxelObject.PaletteColors[EditorPersistence.SelectedColor] = newColor;

            GUILayout.EndVertical();

            try
            {
                EditorCursorMode oldMode = EditorPersistence.CursorMode;
                GUILayout.BeginHorizontal();
                if (HighlightButton(EditorUtility.Buttons["pvButton_Add"],
                    EditorPersistence.CursorMode == EditorCursorMode.Add,
                    "Add single voxels"))
                {
                    buttonJustClicked = true;
                    EditorPersistence.CursorMode = EditorCursorMode.Add;
                }
                if (HighlightButton(EditorUtility.Buttons["pvButton_Subtract"],
                    EditorPersistence.CursorMode == EditorCursorMode.Subtract, "Subtract single voxels"))
                {
                    buttonJustClicked = true;
                    EditorPersistence.CursorMode = EditorCursorMode.Subtract;
                }
                if (HighlightButton(EditorUtility.Buttons["pvButton_Paint"],
                    EditorPersistence.CursorMode == EditorCursorMode.Paint, "Paint single voxels"))
                {
                    buttonJustClicked = true;
                    EditorPersistence.CursorMode = EditorCursorMode.Paint;
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                if (HighlightButton(EditorUtility.Buttons["pvButton_BoxAdd"],
                    EditorPersistence.CursorMode == EditorCursorMode.BoxAdd, "Draw a box to add voxels"))
                {
                    buttonJustClicked = true;
                    EditorPersistence.CursorMode = EditorCursorMode.BoxAdd;
                }
                if (HighlightButton(EditorUtility.Buttons["pvButton_BoxSubtract"],
                    EditorPersistence.CursorMode == EditorCursorMode.BoxSubtract, "Draw a box to subtract voxels"))
                {
                    buttonJustClicked = true;
                    EditorPersistence.CursorMode = EditorCursorMode.BoxSubtract;
                }
                if (HighlightButton(EditorUtility.Buttons["pvButton_BoxPaint"],
                    EditorPersistence.CursorMode == EditorCursorMode.BoxPaint, "Draw a box to paint voxels"))
                {
                    buttonJustClicked = true;
                    EditorPersistence.CursorMode = EditorCursorMode.BoxPaint;
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                if (HighlightButton(EditorUtility.Buttons["pvButton_Select"],
                    EditorPersistence.CursorMode == EditorCursorMode.Select, "Select voxels to create a brush"))
                {
                    buttonJustClicked = true;
                    EditorPersistence.CursorMode = EditorCursorMode.Select;
                }
                if (HighlightButton(EditorUtility.Buttons["pvButton_PickColor"],
                    EditorPersistence.CursorMode == EditorCursorMode.PickColor,
                    "Change the currently selected color to the color of an existing voxel"))
                {
                    buttonJustClicked = true;
                    EditorPersistence.CursorMode = EditorCursorMode.PickColor;
                }
                if (HighlightButton(EditorUtility.Buttons["pvButton_PickValue"],
                    EditorPersistence.CursorMode == EditorCursorMode.PickValue,
                    "Change the currently selected value to the value of an existing voxel"))
                {
                    buttonJustClicked = true;
                    EditorPersistence.CursorMode = EditorCursorMode.PickValue;
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                if (HighlightButton(EditorUtility.Buttons["pvButton_BrushAdd"],
                    EditorPersistence.CursorMode == EditorCursorMode.BrushAdd,
                    "Add voxels using stored brush"))
                {
                    buttonJustClicked = true;
                    EditorPersistence.CursorMode = EditorCursorMode.BrushAdd;
                }
                if (HighlightButton(EditorUtility.Buttons["pvButton_BrushSubtract"],
                    EditorPersistence.CursorMode == EditorCursorMode.BrushSubtract, "Subtract voxels using stored brush"))
                {
                    buttonJustClicked = true;
                    EditorPersistence.CursorMode = EditorCursorMode.BrushSubtract;
                }
                if (HighlightButton(EditorUtility.Buttons["pvButton_BrushPaint"],
                    EditorPersistence.CursorMode == EditorCursorMode.BrushPaint, "Paint voxels using stored brush"))
                {
                    buttonJustClicked = true;
                    EditorPersistence.CursorMode = EditorCursorMode.BrushPaint;
                }
                GUILayout.EndHorizontal();

                if (EditorPersistence.CursorMode == EditorCursorMode.Select)
                {
                    GUILayout.Space(10);
                    EditorGUILayout.LabelField("Selection");
                    if (GUILayout.Button("Create Brush", new GUIStyle(skin.button) {margin = new RectOffset(0, 0, 0, 5)},
                        GUILayout.Width(100)))
                    {
                        buttonJustClicked = true;
                        EditorPersistence.Brush =
                            new Voxel[((EditorPersistence.SelectBox.TopRightBack.X + 1) - EditorPersistence.SelectBox.BottomLeftFront.X) *
                                      ((EditorPersistence.SelectBox.TopRightBack.Y + 1) - EditorPersistence.SelectBox.BottomLeftFront.Y) *
                                      ((EditorPersistence.SelectBox.TopRightBack.Z + 1) - EditorPersistence.SelectBox.BottomLeftFront.Z)];
                        EditorPersistence.BrushSize = new PicaVoxelPoint((EditorPersistence.SelectBox.TopRightBack.X + 1) - EditorPersistence.SelectBox.BottomLeftFront.X,
                                                                         (EditorPersistence.SelectBox.TopRightBack.Y + 1) - EditorPersistence.SelectBox.BottomLeftFront.Y,
                                                                         (EditorPersistence.SelectBox.TopRightBack.Z + 1) - EditorPersistence.SelectBox.BottomLeftFront.Z);
                        PicaVoxelBox destBox = new PicaVoxelBox(0, 0, 0, EditorPersistence.BrushSize.X-1,EditorPersistence.BrushSize.Y-1, EditorPersistence.BrushSize.Z-1);
                        Helper.CopyVoxelsInBox(ref voxelObject.GetCurrentFrame().Voxels, ref EditorPersistence.Brush,
                            EditorPersistence.SelectBox, destBox, new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize), EditorPersistence.BrushSize, false);
                        EditorPersistence.CursorMode = EditorCursorMode.BrushAdd;

                        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);
                    }
                    GUILayout.Space(10);
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("Fill", new GUIStyle(skin.button) {margin = new RectOffset(0, 0, 0, 0)},
                        GUILayout.Width(50)))
                    {
                        RegisterUndo();
                        if (propogateAllFrames)
                        {
                            foreach (Frame f in voxelObject.Frames)
                            {
                                f.EditingVoxels = null;
                                for(int x=EditorPersistence.SelectBox.BottomLeftFront.X;x<=EditorPersistence.SelectBox.TopRightBack.X;x++)
                                    for(int y=EditorPersistence.SelectBox.BottomLeftFront.Y;y<=EditorPersistence.SelectBox.TopRightBack.Y;y++)
                                        for(int z=EditorPersistence.SelectBox.BottomLeftFront.Z;z<=EditorPersistence.SelectBox.TopRightBack.Z;z++)
                                            f.Voxels[x + voxelObject.XSize*(y + voxelObject.YSize*z)] = new Voxel()
                                            {
                                                State = VoxelState.Active,
                                                Color = voxelObject.PaletteColors[EditorPersistence.SelectedColor],
                                                Value = EditorPersistence.SelectedValue
                                            };
                                f.SaveForSerialize();
                                f.UpdateAllChunks();
                            }
                        }
                        else
                        {
                            voxelObject.Frames[voxelObject.CurrentFrame].EditingVoxels = null;
                            for (int x = EditorPersistence.SelectBox.BottomLeftFront.X; x <= EditorPersistence.SelectBox.TopRightBack.X; x++)
                                for (int y = EditorPersistence.SelectBox.BottomLeftFront.Y; y <= EditorPersistence.SelectBox.TopRightBack.Y; y++)
                                    for (int z = EditorPersistence.SelectBox.BottomLeftFront.Z; z <= EditorPersistence.SelectBox.TopRightBack.Z; z++)
                                        voxelObject.Frames[voxelObject.CurrentFrame].Voxels[x + voxelObject.XSize * (y + voxelObject.YSize * z)] = new Voxel()
                                        {
                                            State = VoxelState.Active,
                                            Color = voxelObject.PaletteColors[EditorPersistence.SelectedColor],
                                            Value = EditorPersistence.SelectedValue
                                        };
                            voxelObject.Frames[voxelObject.CurrentFrame].SaveForSerialize();
                            voxelObject.Frames[voxelObject.CurrentFrame].UpdateAllChunks();
                        }
                        buttonJustClicked = true;
                    }
                    if (GUILayout.Button("Clear", new GUIStyle(skin.button) { margin = new RectOffset(0, 0, 0, 0) }, 
                        GUILayout.Width(50)))
                    {
                        RegisterUndo();
                        if (propogateAllFrames)
                        {
                            foreach (Frame f in voxelObject.Frames)
                            {
                                f.EditingVoxels = null;
                                for (int x = EditorPersistence.SelectBox.BottomLeftFront.X; x <= EditorPersistence.SelectBox.TopRightBack.X; x++)
                                    for (int y = EditorPersistence.SelectBox.BottomLeftFront.Y; y <= EditorPersistence.SelectBox.TopRightBack.Y; y++)
                                        for (int z = EditorPersistence.SelectBox.BottomLeftFront.Z; z <= EditorPersistence.SelectBox.TopRightBack.Z; z++)
                                            f.Voxels[x + voxelObject.XSize * (y + voxelObject.YSize * z)] = new Voxel()
                                            {
                                                State = VoxelState.Inactive,
                                                Color = voxelObject.PaletteColors[EditorPersistence.SelectedColor],
                                                Value = EditorPersistence.SelectedValue
                                            };
                                f.SaveForSerialize();
                                f.UpdateAllChunks();
                            }
                        }
                        else
                        {
                            voxelObject.Frames[voxelObject.CurrentFrame].EditingVoxels = null;
                            for (int x = EditorPersistence.SelectBox.BottomLeftFront.X; x <= EditorPersistence.SelectBox.TopRightBack.X; x++)
                                for (int y = EditorPersistence.SelectBox.BottomLeftFront.Y; y <= EditorPersistence.SelectBox.TopRightBack.Y; y++)
                                    for (int z = EditorPersistence.SelectBox.BottomLeftFront.Z; z <= EditorPersistence.SelectBox.TopRightBack.Z; z++)
                                        voxelObject.Frames[voxelObject.CurrentFrame].Voxels[x + voxelObject.XSize * (y + voxelObject.YSize * z)] = new Voxel()
                                        {
                                            State = VoxelState.Inactive,
                                            Color = voxelObject.PaletteColors[EditorPersistence.SelectedColor],
                                            Value = EditorPersistence.SelectedValue
                                        };
                            voxelObject.Frames[voxelObject.CurrentFrame].SaveForSerialize();
                            voxelObject.Frames[voxelObject.CurrentFrame].UpdateAllChunks();
                        }
                        buttonJustClicked = true;
                    }
                    GUILayout.EndHorizontal();

                    EditorGUILayout.LabelField("Nudge Selection");
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("X - 1", new GUIStyle(skin.button) { margin = new RectOffset(0, 0, 0, 0) },
                        GUILayout.Width(50)))
                    {
                        NudgeSelection(-1, 0, 0);
                        buttonJustClicked = true;
                    }
                    if (GUILayout.Button("X + 1", new GUIStyle(skin.button) { margin = new RectOffset(0, 0, 0, 0) },
                        GUILayout.Width(50)))
                    {
                        NudgeSelection(1, 0, 0);
                        buttonJustClicked = true;
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("Y - 1", new GUIStyle(skin.button) { margin = new RectOffset(0, 0, 0, 0) },
                        GUILayout.Width(50)))
                    {
                        NudgeSelection(0, -1, 0);
                        buttonJustClicked = true;
                    }
                    if (GUILayout.Button("Y + 1", new GUIStyle(skin.button) { margin = new RectOffset(0, 0, 0, 0) },
                        GUILayout.Width(50)))
                    {
                        NudgeSelection(0, 1, 0);
                        buttonJustClicked = true;
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("Z - 1", new GUIStyle(skin.button) { margin = new RectOffset(0, 0, 0, 0) },
                        GUILayout.Width(50)))
                    {
                        NudgeSelection(0, 0, -1);
                        buttonJustClicked = true;
                    }
                    if (GUILayout.Button("Z + 1", new GUIStyle(skin.button) { margin = new RectOffset(0, 0, 0, 0) },
                        GUILayout.Width(50)))
                    {
                        NudgeSelection(0, 0, 1);
                        buttonJustClicked = true;
                    }
                    GUILayout.EndHorizontal();
                }

                if (EditorPersistence.CursorMode == EditorCursorMode.BrushAdd ||
                    EditorPersistence.CursorMode == EditorCursorMode.BrushSubtract ||
                    EditorPersistence.CursorMode == EditorCursorMode.BrushPaint)
                {
                    if (EditorPersistence.Brush == null) EditorPersistence.CursorMode = EditorCursorMode.Select;

                    GUILayout.Space(10);
                    EditorPersistence.BrushReplace = EditorGUILayout.ToggleLeft(" Replace", EditorPersistence.BrushReplace);

                    GUILayout.Space(10);
                    EditorGUILayout.LabelField("Brush Anchor");
                    EditorPersistence.BrushAnchorX =
                        (AnchorX)
                            EditorGUILayout.EnumPopup(EditorPersistence.BrushAnchorX,
                                new GUIStyle(skin.GetStyle("DropDown")) {margin = new RectOffset(0, 0, 0, 5)},
                                GUILayout.Width(100));
                    EditorPersistence.BrushAnchorY =
                        (AnchorY)
                            EditorGUILayout.EnumPopup(EditorPersistence.BrushAnchorY,
                                new GUIStyle(skin.GetStyle("DropDown")) {margin = new RectOffset(0, 0, 0, 5)},
                                GUILayout.Width(100));
                    EditorPersistence.BrushAnchorZ =
                        (AnchorZ)
                            EditorGUILayout.EnumPopup(EditorPersistence.BrushAnchorZ,
                                new GUIStyle(skin.GetStyle("DropDown")) {margin = new RectOffset(0, 0, 0, 5)},
                                GUILayout.Width(100));

                    EditorGUILayout.LabelField("Brush Rotate");
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button(new GUIContent("X", "Rotate brush 90 degrees around X axis"),
                        new GUIStyle(GUI.skin.button)
                        {
                            padding = new RectOffset(0, 0, 0, 0),
                            margin = new RectOffset(0, 2, 2, 0)
                        }, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        buttonJustClicked = true;
                        RotateBrush(RotateAxis.X);
                        voxelObject.UpdateAllChunks();
                    }
                    if (GUILayout.Button(new GUIContent("Y", "Rotate brush 90 degrees around Y axis"),
                        new GUIStyle(GUI.skin.button)
                        {
                            padding = new RectOffset(0, 0, 0, 0),
                            margin = new RectOffset(0, 2, 2, 0)
                        }, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        buttonJustClicked = true;
                        RotateBrush(RotateAxis.Y);
                        voxelObject.UpdateAllChunks();
                    }
                    if (GUILayout.Button(new GUIContent("Z", "Rotate brush 90 degrees around Z axis"),
                        new GUIStyle(GUI.skin.button)
                        {
                            padding = new RectOffset(0, 0, 0, 0),
                            margin = new RectOffset(0, 2, 2, 0)
                        }, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        buttonJustClicked = true;
                        RotateBrush(RotateAxis.Z);
                        voxelObject.UpdateAllChunks();
                    }
                    GUILayout.EndHorizontal();

                }

                if ((oldMode == EditorCursorMode.BrushAdd || oldMode == EditorCursorMode.BrushPaint ||
                     oldMode == EditorCursorMode.BrushSubtract) && oldMode != EditorPersistence.CursorMode)
                {
                    voxelObject.GetCurrentFrame().EditingVoxels = null;
                    voxelObject.UpdateAllChunks();
                }
            }
            catch (Exception)
            {
            }

            GUILayout.EndVertical();
            GUILayout.EndArea();

            // Animation
            GUI.backgroundColor = (EditorGUIUtility.isProSkin ? Color.white : Color.grey);
            GUILayout.BeginArea(new Rect(Screen.width - 410, Screen.height - 100, 400, 50),
                EditorUtility.Buttons["pvButton_AnimBG"]);
            GUILayout.BeginHorizontal(new GUIStyle() {alignment = TextAnchor.MiddleCenter}, GUILayout.Width(260));
            if (GUILayout.Button(new GUIContent(EditorUtility.Buttons["pvButton_AddFramePrev"], "Add frame before"),
                new GUIStyle(GUI.skin.button)
                {
                    padding = new RectOffset(0, 0, 0, 0),
                    margin = new RectOffset(3, 0, 9, 0)
                }, GUILayout.Width(32), GUILayout.Height(32)))
            {
                buttonJustClicked = true;
                voxelObject.AddFrame(voxelObject.CurrentFrame);
            }
            if (GUILayout.Button(new GUIContent(EditorUtility.Buttons["pvButton_DeleteFrame"], "Delete frame"),
                new GUIStyle(GUI.skin.button)
                {
                    padding = new RectOffset(0, 0, 0, 0),
                    margin = new RectOffset(2, 0, 9, 0)
                }, GUILayout.Width(32), GUILayout.Height(32)))
            {
                buttonJustClicked = true;
                voxelObject.DeleteFrame();
            }
            if (GUILayout.Button(new GUIContent(EditorUtility.Buttons["pvButton_MoveLeft"], "Move frame left"),
                new GUIStyle(GUI.skin.button)
                {
                    padding = new RectOffset(0, 0, 0, 0),
                    margin = new RectOffset(2, 0, 9, 0)
                }, GUILayout.Width(32), GUILayout.Height(32)))
            {
                buttonJustClicked = true;
                voxelObject.MoveFrameLeft();
            }
            if (GUILayout.Button(new GUIContent(EditorUtility.Buttons["pvButton_PrevFrame"], "Previous frame"),
                new GUIStyle(GUI.skin.button)
                {
                    padding = new RectOffset(0, 0, 0, 0),
                    margin = new RectOffset(2, 0, 9, 0)
                }, GUILayout.Width(32), GUILayout.Height(32)))
            {
                buttonJustClicked = true;
                voxelObject.PrevFrame();
            }
            GUILayout.Label(voxelObject.CurrentFrame + 1 + "/" + voxelObject.NumFrames,
                new GUIStyle(GUI.skin.label)
                {
                    normal = new GUIStyleState() {textColor = Color.white},
                    fontSize = 20,
                    fontStyle = FontStyle.Bold,
                    alignment = TextAnchor.MiddleCenter,
                    padding = new RectOffset(2, 0, 0, 3)
                }, GUILayout.Width(80), GUILayout.Height(50));
            if (GUILayout.Button(new GUIContent(EditorUtility.Buttons["pvButton_NextFrame"], "Next frame"),
                new GUIStyle(GUI.skin.button)
                {
                    padding = new RectOffset(0, 0, 0, 0),
                    margin = new RectOffset(2, 0, 9, 0)
                }, GUILayout.Width(32), GUILayout.Height(32)))
            {
                buttonJustClicked = true;
                voxelObject.NextFrame();
            }
            if (GUILayout.Button(new GUIContent(EditorUtility.Buttons["pvButton_MoveRight"], "Move frame right"),
                new GUIStyle(GUI.skin.button)
                {
                    padding = new RectOffset(0, 0, 0, 0),
                    margin = new RectOffset(2, 0, 9, 0)
                }, GUILayout.Width(32), GUILayout.Height(32)))
            {
                buttonJustClicked = true;
                voxelObject.MoveFrameRight();
            }
            if (GUILayout.Button(new GUIContent(EditorUtility.Buttons["pvButton_AddFrameNext"], "Add frame after"),
                new GUIStyle(GUI.skin.button)
                {
                    padding = new RectOffset(0, 0, 0, 0),
                    margin = new RectOffset(2, 0, 9, 0)
                }, GUILayout.Width(32), GUILayout.Height(32)))
            {
                buttonJustClicked = true;
                voxelObject.AddFrame(voxelObject.CurrentFrame + 1);
            }
            if (GUILayout.Button(new GUIContent(EditorUtility.Buttons["pvButton_CopyFrame"], "Copy frame to clipboard"),
                new GUIStyle(GUI.skin.button)
                {
                    padding = new RectOffset(0, 0, 0, 0),
                    margin = new RectOffset(2, 0, 9, 0)
                }, GUILayout.Width(32), GUILayout.Height(32)))
            {
                buttonJustClicked = true;
                EditorPersistence.AnimFrameClipboard = new Voxel[voxelObject.XSize * voxelObject.YSize * voxelObject.ZSize];
                Array.Copy(voxelObject.Frames[voxelObject.CurrentFrame].Voxels, EditorPersistence.AnimFrameClipboard,
                    voxelObject.Frames[voxelObject.CurrentFrame].Voxels.Length);
                EditorPersistence.AnimFrameClipboardSize = new PicaVoxelPoint(voxelObject.XSize, voxelObject.YSize, voxelObject.ZSize);
            }

            if (
                GUILayout.Button(
                    new GUIContent(EditorUtility.Buttons["pvButton_PasteFrame"], "Paste frame from clipboard"),
                    new GUIStyle(GUI.skin.button)
                    {
                        padding = new RectOffset(0, 0, 0, 0),
                        margin = new RectOffset(2, 0, 9, 0)
                    }, GUILayout.Width(32), GUILayout.Height(32)) && EditorPersistence.AnimFrameClipboard!=null)
            {
                buttonJustClicked = true;
                voxelObject.AddFrame(voxelObject.CurrentFrame);
                voxelObject.SetFrame(voxelObject.CurrentFrame+1);
                for(int x=0;x<EditorPersistence.AnimFrameClipboardSize.X;x++)
                    for(int y=0;y<EditorPersistence.AnimFrameClipboardSize.Y;y++)
                        for (int z = 0; z < EditorPersistence.AnimFrameClipboardSize.Z; z++)
                        {
                            if (x < voxelObject.XSize && y < voxelObject.YSize && z < voxelObject.ZSize)
                            {
                                voxelObject.Frames[voxelObject.CurrentFrame].Voxels[x + voxelObject.XSize*(y + voxelObject.YSize*z)] =
                                    EditorPersistence.AnimFrameClipboard[x + EditorPersistence.AnimFrameClipboardSize.X * (y + EditorPersistence.AnimFrameClipboardSize.Y * z)];
                            }
                        }
                voxelObject.SaveForSerialize();
                voxelObject.UpdateAllChunks();
            }
            GUILayout.EndArea();
            GUI.backgroundColor = Color.white;

            Handles.SetCamera(Camera.current);
            DoCursor(e);

            //HandleUtility.Repaint();
        }
 public static void GenerateGreedy(List<Vector3> vertices, List<Vector2> uvs, List<Color32> colors, List<int> indexes, ref Vector3[] vertArray, ref Vector2[] uvArray, ref Color32[] colorArray, ref int[] indexArray, ref Voxel[] invoxels, float voxelSize, float overlapAmount, int xOffset, int yOffset, int zOffset, int xSize, int ySize, int zSize, int ub0, int ub1, int ub2, float selfShadeIntensity, EditorPaintMode paintMode)
 static void GetVoxelFace(VoxelFace voxelFace, int x, int y, int z, int side, ref Voxel[] invoxels, float voxelSize, int xOffset, int yOffset, int zOffset, int xSize, int ySize, int zSize, int ub0, int ub1, int ub2, float selfShadeIntensity, EditorPaintMode paintMode)
Example #7
0
 public void GenerateMesh(Voxel[] voxels, float voxelSize, float overlapAmount, int xOffset, int yOffset, int zOffset, int xSize,
     int ySize, int zSize, int ub0, int ub1, int ub2, float selfShadeIntensity, MeshingMode mode, MeshingMode colliderMode, bool immediate,
     EditorPaintMode paintMode)
Example #8
0
 private void Generate(ref Voxel[] voxels, float voxelSize, float overlapAmount, int xOffset, int yOffset, int zOffset, int xSize, int ySize, int zSize, int ub0, int ub1, int ub2, float selfShadeIntensity, MeshingMode meshMode, EditorPaintMode paintMode)