Esempio n. 1
0
    protected override void Do()
    {
        m_Action = new VCEAction();

        ulong oldmat_guid = VCEditor.s_Scene.m_IsoData.MaterialGUID(VCEditor.SelectedVoxelType);
        ulong newmat_guid = VCEditor.SelectedMaterial.m_Guid;

        if (oldmat_guid != newmat_guid)
        {
            VCEAlterMaterialMap modify = new VCEAlterMaterialMap(VCEditor.SelectedVoxelType, oldmat_guid, newmat_guid);
            m_Action.Modifies.Add(modify);
        }

        IntVector3 draw = m_Target.cursor + m_Offset;

        // Mirror
        if (VCEditor.s_Mirror.Enabled_Masked)
        {
            VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
            VCEditor.s_Mirror.MirrorVoxel(draw);

            for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
            {
                if (VCEditor.s_Scene.m_IsoData.IsPointIn(VCEditor.s_Mirror.Output[i]))
                {
                    int     voxel_pos = VCIsoData.IPosToKey(VCEditor.s_Mirror.Output[i]);
                    VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                    VCVoxel new_voxel = new VCVoxel(255, (byte)VCEditor.SelectedVoxelType);
                    if (old_voxel != new_voxel)
                    {
                        VCEAlterVoxel modify = new VCEAlterVoxel(voxel_pos, old_voxel, new_voxel);
                        m_Action.Modifies.Add(modify);
                    }
                }
            }
        }
        // No mirror
        else
        {
            int     voxel_pos = VCIsoData.IPosToKey(draw);
            VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
            VCVoxel new_voxel = new VCVoxel(255, (byte)VCEditor.SelectedVoxelType);
            if (old_voxel != new_voxel)
            {
                VCEAlterVoxel modify = new VCEAlterVoxel(voxel_pos, old_voxel, new_voxel);
                m_Action.Modifies.Add(modify);
            }
        }
        if (m_Action.Modifies.Count > 0)
        {
            m_Action.Do();
        }

        VCEditor.Instance.m_MainCamera.GetComponent <VCECamera>().SetTarget(
            (draw.ToVector3() + Vector3.one * 0.5f) * VCEditor.s_Scene.m_Setting.m_VoxelSize);
    }
Esempio n. 2
0
    public void TextureSelection()
    {
        if (!VCEditor.Instance.m_UI.m_MaterialTab.isChecked)
        {
            return;
        }
        if (VCEditor.SelectedVoxelType < 0)
        {
            return;
        }

        m_Action = new VCEAction();

        ulong oldmat_guid = VCEditor.s_Scene.m_IsoData.MaterialGUID(VCEditor.SelectedVoxelType);
        ulong newmat_guid = VCEditor.SelectedMaterial.m_Guid;

        if (oldmat_guid != newmat_guid)
        {
            VCEAlterMaterialMap modify = new VCEAlterMaterialMap(VCEditor.SelectedVoxelType, oldmat_guid, newmat_guid);
            m_Action.Modifies.Add(modify);
        }

        VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
        foreach (KeyValuePair <int, byte> kvp in m_SelectionMgr.m_Selection)
        {
            // Mirror
            if (VCEditor.s_Mirror.Enabled_Masked)
            {
                IntVector3 pos = VCIsoData.KeyToIPos(kvp.Key);
                VCEditor.s_Mirror.MirrorVoxel(pos);
                float strength = (float)(kvp.Value) / 255.0f;
                if (strength < 0.5f)
                {
                    continue;
                }
                for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
                {
                    if (VCEditor.s_Scene.m_IsoData.IsPointIn(VCEditor.s_Mirror.Output[i]))
                    {
                        int     voxel_pos = VCIsoData.IPosToKey(VCEditor.s_Mirror.Output[i]);
                        VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                        VCVoxel new_voxel = new VCVoxel(old_voxel.Volume, (byte)(VCEditor.SelectedVoxelType));
                        if (old_voxel != new_voxel)
                        {
                            VCEAlterVoxel modify = new VCEAlterVoxel(voxel_pos, old_voxel, new_voxel);
                            modify.Redo();
                            m_Action.Modifies.Add(modify);
                        }
                    }
                }
            }
            // No mirror
            else
            {
                float strength = (float)(kvp.Value) / 255.0f;
                if (strength < 0.5f)
                {
                    continue;
                }
                int     voxel_pos = kvp.Key;
                VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                VCVoxel new_voxel = new VCVoxel(old_voxel.Volume, (byte)(VCEditor.SelectedVoxelType));
                if (old_voxel != new_voxel)
                {
                    VCEAlterVoxel modify = new VCEAlterVoxel(voxel_pos, old_voxel, new_voxel);
                    m_Action.Modifies.Add(modify);
                }
            }
        }
        if (m_Action.Modifies.Count > 0)
        {
            m_Action.Do();
            VCEStatusBar.ShowText("Selected voxels have been textured".ToLocalizationString(), 2);
        }
    }
Esempio n. 3
0
    protected override void Do()
    {
        m_Action = new VCEAction();

        VCComponentData data = VCComponentData.Create(VCEditor.SelectedPart);

        if (data != null)
        {
            data.m_ComponentId = VCEditor.SelectedPart.m_ID;
            data.m_Type        = VCEditor.SelectedPart.m_Type;
            data.m_Position    = m_PartInst.transform.localPosition;
            data.m_Rotation    = Vector3.zero;
            data.m_Scale       = Vector3.one;
            data.m_Visible     = true;
            data.m_CurrIso     = VCEditor.s_Scene.m_IsoData;
            data.Validate();

            VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
            // Mirror
            if (VCEditor.s_Mirror.Enabled_Masked)
            {
                VCEditor.s_Mirror.MirrorComponent(data);

                for (int i = VCEditor.s_Mirror.OutputCnt - 1; i >= 0; --i)
                {
                    VCComponentData image = VCEditor.s_Mirror.ComponentOutput[i];
                    if (VCEditor.s_Scene.m_IsoData.IsComponentIn(image.m_Position))
                    {
                        List <VCComponentData> conflicts = VCEditor.s_Scene.m_IsoData.FindComponentsAtPos(image.m_Position, image.m_ComponentId);
                        foreach (VCComponentData conflict in conflicts)
                        {
                            if (conflict.m_Scale != image.m_Scale)
                            {
                                continue;
                            }
                            if (conflict.m_Visible != image.m_Visible)
                            {
                                continue;
                            }

                            if (image is IVCMultiphaseComponentData && conflict is IVCMultiphaseComponentData)
                            {
                                if ((image as IVCMultiphaseComponentData).Phase != (conflict as IVCMultiphaseComponentData).Phase)
                                {
                                    continue;
                                }
                            }

                            // Delete conflict
                            int index = VCEditor.s_Scene.m_IsoData.GetComponentIndex(conflict);
                            if (index < 0)
                            {
                                continue;
                            }
                            VCEDelComponent del = new VCEDelComponent(index, conflict);
                            del.Redo();
                            m_Action.Modifies.Add(del);
                        }
                        VCEAddComponent modify = new VCEAddComponent(VCEditor.s_Scene.m_IsoData.m_Components.Count, image);
                        modify.Redo();
                        m_Action.Modifies.Add(modify);
                    }
                }
                m_Action.Register();
            }
            // No mirror
            else
            {
                VCFixedHandPartData fixdata = data as VCFixedHandPartData;
                if (fixdata != null)
                {
                    fixdata.m_LeftHand = data.m_Position.x < VCEditor.s_Scene.m_IsoData.m_HeadInfo.xSize * VCEditor.s_Scene.m_Setting.m_VoxelSize * 0.5f;
                }

                VCEAddComponent modify = new VCEAddComponent(VCEditor.s_Scene.m_IsoData.m_Components.Count, data);
                m_Action.Modifies.Add(modify);
                m_Action.Do();
            }
        }
        else
        {
            Debug.LogWarning("Forget to add this part's implementation ?");
        }
    }
Esempio n. 4
0
    //
    // Functions
    //
    public void ExtrudeSelection(int x, int y, int z)
    {
        if (x == 0 && y == 0 && z == 0)
        {
            return;
        }
        m_Action = new VCEAction();
        VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
        List <int> new_select_keys   = new List <int> ();
        List <int> new_select_values = new List <int> ();

        foreach (KeyValuePair <int, byte> kvp in m_SelectionMgr.m_Selection)
        {
            float      strength = (float)(kvp.Value) / 255.0f;
            IntVector3 ipos     = VCIsoData.KeyToIPos(kvp.Key);
            ipos.x += x;
            ipos.y += y;
            ipos.z += z;
            if (VCEditor.s_Scene.m_IsoData.IsPointIn(ipos))
            {
                int voxel_pos = VCIsoData.IPosToKey(ipos);
                new_select_keys.Add(voxel_pos);
                new_select_values.Add((int)kvp.Value);
                // Mirror
                if (VCEditor.s_Mirror.Enabled_Masked)
                {
                    //IntVector3 real = ipos;
                    VCEditor.s_Mirror.MirrorVoxel(ipos);
                    for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
                    {
                        IntVector3 image = VCEditor.s_Mirror.Output[i];
                        if (VCEditor.s_Scene.m_IsoData.IsPointIn(image))
                        {
                            voxel_pos = VCIsoData.IPosToKey(image);
                            VCVoxel src_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(kvp.Key);
                            VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                            VCVoxel new_voxel = src_voxel;
                            if (strength == 1)
                            {
                                new_voxel.VolumeF = old_voxel.VolumeF + src_voxel.VolumeF;
                            }
                            else
                            {
                                new_voxel.VolumeF = old_voxel.VolumeF + src_voxel.VolumeF * Mathf.Lerp(Mathf.Pow(strength, 0.3f), 1, 0.3f);
                            }

                            if (old_voxel != new_voxel)
                            {
                                VCEAlterVoxel modify = new VCEAlterVoxel(voxel_pos, old_voxel, new_voxel);
                                m_Action.Modifies.Add(modify);
                            }
                        }
                    }
                }
                // No mirror
                else
                {
                    VCVoxel src_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(kvp.Key);
                    VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                    VCVoxel new_voxel = src_voxel;
                    if (strength == 1)
                    {
                        new_voxel.VolumeF = old_voxel.VolumeF + src_voxel.VolumeF;
                    }
                    else
                    {
                        new_voxel.VolumeF = old_voxel.VolumeF + src_voxel.VolumeF * Mathf.Lerp(Mathf.Pow(strength, 0.3f), 1, 0.3f);
                    }

                    if (old_voxel != new_voxel)
                    {
                        VCEAlterVoxel modify = new VCEAlterVoxel(voxel_pos, old_voxel, new_voxel);
                        m_Action.Modifies.Add(modify);
                    }
                }
            }
        }

        // Clear new area's color
        ColorSelection(VCIsoData.BLANK_COLOR, false, true);

        if (m_Action.Modifies.Count > 0)
        {
            m_Action.Do();
        }

        // Select new extruded area
        m_SelectionMgr.m_Selection.Clear();
        for (int i = 0; i < new_select_keys.Count; ++i)
        {
            if (!VCEditor.s_Scene.m_IsoData.IsGarbageVoxel(new_select_keys[i]))
            {
                m_SelectionMgr.m_Selection.Add(new_select_keys[i], (byte)(new_select_values[i]));
            }
        }
        m_SelectionMgr.RebuildSelectionBoxes();
    }
Esempio n. 5
0
    public void Update()
    {
        int sel_count = VCEditor.Instance.m_VoxelSelection.m_Selection.Count;

        if (sel_count == 0)
        {
            m_SelectInfo.text = "[00FFFF]0[-] " + "voxel selected".ToLocalizationString() + ".";
            m_FunctionGroup.SetActive(false);
        }
        else if (sel_count == 1)
        {
            m_SelectInfo.text = "[00FFFF]1[-] " + "voxel selected".ToLocalizationString() + ".";
            m_FunctionGroup.SetActive(true);
        }
        else if (sel_count < 10000)
        {
            m_SelectInfo.text = "[00FFFF]" + sel_count.ToString("#,###") + "[-] " + "voxels selected".ToLocalizationString() + ".";
            m_FunctionGroup.SetActive(true);
        }
        else
        {
            m_SelectInfo.text = "[00FFFF]" + sel_count.ToString("#,###") + "[-]\r\n" + "voxels selected".ToLocalizationString() + ".";
            m_FunctionGroup.SetActive(true);
        }

        if (sel_count == 1)
        {
            m_VolumeGroup.SetActive(true);
            int     key       = -1;
            VCVoxel old_voxel = new VCVoxel();
            VCVoxel new_voxel = new VCVoxel();
            foreach (KeyValuePair <int, byte> kvp in VCEditor.Instance.m_VoxelSelection.m_Selection)
            {
                key       = kvp.Key;
                old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(kvp.Key);
            }
            if (key != oldKey)
            {
                m_VolModifyAction = null;
                oldKey            = key;
            }
            if (key >= 0)
            {
                if (m_VolModifyAction == null)
                {
                    m_VolModifyAction = new VCEAction();
                    VolumeSliderValue = old_voxel.VolumeF;
                    oldVol            = VolumeSliderValue;
                }
                m_VolumeLabel.text = "Voxel volume".ToLocalizationString() + " = [FFFF00]" + (VolumeSliderValue * 200 - 100).ToString("0") + "[-]";
                new_voxel          = old_voxel;
                new_voxel.VolumeF  = VolumeSliderValue;
                if (Input.GetMouseButtonUp(0) && Mathf.Abs(oldVol - VolumeSliderValue) > 0.002f)
                {
                    oldVol = VolumeSliderValue;
                    VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
                    // Mirror
                    if (VCEditor.s_Mirror.Enabled_Masked)
                    {
                        VCEditor.s_Mirror.MirrorVoxel(VCIsoData.KeyToIPos(key));
                        for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
                        {
                            if (VCEditor.s_Scene.m_IsoData.IsPointIn(VCEditor.s_Mirror.Output[i]))
                            {
                                int     voxel_pos = VCIsoData.IPosToKey(VCEditor.s_Mirror.Output[i]);
                                VCVoxel old_v     = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                                if (old_v.Volume == 0)
                                {
                                    continue;
                                }
                                VCVoxel new_v = old_v;
                                new_v.VolumeF = VolumeSliderValue;
                                if (m_VolModifyAction.Modifies.Count == 0)
                                {
                                    VCEAlterVoxel modify = new VCEAlterVoxel(voxel_pos, old_v, new_v);
                                    m_VolModifyAction.Modifies.Add(modify);
                                    m_VolModifyAction.Do();
                                }
                                else
                                {
                                    bool changed = false;
                                    foreach (VCEModify modify in m_VolModifyAction.Modifies)
                                    {
                                        VCEAlterVoxel avmodify = modify as VCEAlterVoxel;
                                        if (avmodify != null)
                                        {
                                            if (avmodify.m_Pos == voxel_pos)
                                            {
                                                avmodify.m_New = new_v;
                                                changed        = true;
                                            }
                                        }
                                    }
                                    if (!changed)
                                    {
                                        VCEAlterVoxel modify = new VCEAlterVoxel(voxel_pos, old_v, new_v);
                                        m_VolModifyAction.Modifies.Add(modify);
                                    }
                                    m_VolModifyAction.DoButNotRegister();
                                }
                            }
                        }
                    }
                    // No mirror
                    else
                    {
                        if (m_VolModifyAction.Modifies.Count == 0)
                        {
                            VCEAlterVoxel modify = new VCEAlterVoxel(key, old_voxel, new_voxel);
                            m_VolModifyAction.Modifies.Add(modify);
                            m_VolModifyAction.Do();
                        }
                        else
                        {
                            bool changed = false;
                            foreach (VCEModify modify in m_VolModifyAction.Modifies)
                            {
                                VCEAlterVoxel avmodify = modify as VCEAlterVoxel;
                                if (avmodify != null)
                                {
                                    if (avmodify.m_Pos == key)
                                    {
                                        avmodify.m_New = new_voxel;
                                        changed        = true;
                                    }
                                }
                            }
                            if (!changed)
                            {
                                VCEAlterVoxel modify = new VCEAlterVoxel(key, old_voxel, new_voxel);
                                m_VolModifyAction.Modifies.Add(modify);
                            }
                            m_VolModifyAction.DoButNotRegister();
                        }
                    }
                }
            }
        }
        else
        {
            m_VolumeGroup.SetActive(false);
            m_VolModifyAction = null;
            oldKey            = -1;
            oldVol            = 0;
        }

        if (m_BoxMethodCheck.isChecked)
        {
            m_SelectBrush.SelectMethod = EVCESelectMethod.Box;
        }
//		else if ( m_BoxMethodCheck.isChecked )
//		{
//
//		}
        else
        {
            m_SelectBrush.SelectMethod = EVCESelectMethod.None;
        }

        if (VCEditor.Instance.m_UI.m_MaterialTab.isChecked)
        {
            if (VCEditor.SelectedVoxelType >= 0)
            {
                m_TextureBtnGO.SetActive(true);
            }
            else
            {
                m_TextureBtnGO.SetActive(false);
            }
            m_ColorBtnGO.SetActive(false);
            m_EraseBtnGO.SetActive(false);
        }
        else if (VCEditor.Instance.m_UI.m_PaintTab.isChecked)
        {
            m_TextureBtnGO.SetActive(false);
            m_ColorBtnGO.SetActive(true);
            m_EraseBtnGO.SetActive(true);
        }
        if (m_FunctionGroup.activeSelf)
        {
            m_FunctionGroup.GetComponent <UIGrid>().Reposition();
        }
    }
Esempio n. 6
0
    protected override void Do()
    {
        m_Action = new VCEAction();

        ulong oldmat_guid = VCEditor.s_Scene.m_IsoData.MaterialGUID(VCEditor.SelectedVoxelType);
        ulong newmat_guid = VCEditor.SelectedMaterial.m_Guid;

        if (oldmat_guid != newmat_guid)
        {
            VCEAlterMaterialMap modify = new VCEAlterMaterialMap(VCEditor.SelectedVoxelType, oldmat_guid, newmat_guid);
            m_Action.Modifies.Add(modify);
        }

        float maskx    = (m_Direction == ECoordAxis.X) ? 0.0f : 1.0f;
        float masky    = (m_Direction == ECoordAxis.Y) ? 0.0f : 1.0f;
        float maskz    = (m_Direction == ECoordAxis.Z) ? 0.0f : 1.0f;
        int   imaskx   = (m_Direction == ECoordAxis.X) ? 0 : 1;
        int   imasky   = (m_Direction == ECoordAxis.Y) ? 0 : 1;
        int   imaskz   = (m_Direction == ECoordAxis.Z) ? 0 : 1;
        float invmaskx = (m_Direction == ECoordAxis.X) ? 1000000.0f : 1.0f;
        float invmasky = (m_Direction == ECoordAxis.Y) ? 1000000.0f : 1.0f;
        float invmaskz = (m_Direction == ECoordAxis.Z) ? 1000000.0f : 1.0f;

        VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
        IntVector3 min           = Min;
        IntVector3 max           = Max;
        Vector3    extend        = Size.ToVector3() * 0.5f;
        Vector3    center        = min.ToVector3() + extend;
        Vector3    inv_scale     = Vector3.one;
        float      radius        = Mathf.Max(extend.x * maskx, extend.y * masky, extend.z * maskz);
        float      min_dimension = Mathf.Max(Mathf.Min(extend.x * invmaskx, extend.y * invmasky, extend.z * invmaskz) - 0.5f, 1);

        if (extend.x * maskx >= extend.y * masky && extend.x * maskx >= extend.z * maskz)
        {
            inv_scale = new Vector3(1, extend.x / extend.y, extend.x / extend.z);
        }
        else if (extend.y * masky >= extend.x * maskx && extend.y * masky >= extend.z * maskz)
        {
            inv_scale = new Vector3(extend.y / extend.x, 1, extend.y / extend.z);
        }
        else
        {
            inv_scale = new Vector3(extend.z / extend.x, extend.z / extend.y, 1);
        }

        float sizex = max.x - min.x + 0.5f;
        float sizey = max.y - min.y + 0.5f;
        float sizez = max.z - min.z + 0.5f;

        for (int x = min.x - 2 * imaskx; x <= max.x + 2 * imaskx; ++x)
        {
            for (int y = min.y - 2 * imasky; y <= max.y + 2 * imasky; ++y)
            {
                for (int z = min.z - 2 * imaskz; z <= max.z + 2 * imaskz; ++z)
                {
                    float lerpt = 1;
                    if (m_Direction == ECoordAxis.X)
                    {
                        lerpt = (float)(x - min.x) / sizex;
                    }
                    else if (m_Direction == ECoordAxis.Y)
                    {
                        lerpt = (float)(y - min.y) / sizey;
                    }
                    else if (m_Direction == ECoordAxis.Z)
                    {
                        lerpt = (float)(z - min.z) / sizez;
                    }
                    float scl = Mathf.Lerp(m_NegativeScale, m_PositiveScale, lerpt);
                    if (scl * radius < 0.01f)
                    {
                        scl = 0.01f / radius;
                    }

                    IntVector3 pos = new IntVector3(x, y, z);
                    // Mirror
                    if (VCEditor.s_Mirror.Enabled_Masked)
                    {
                        Vector3 sphere_coord = (pos.ToVector3() + Vector3.one * 0.5f) - center;
                        sphere_coord.x *= inv_scale.x;
                        sphere_coord.y *= inv_scale.y;
                        sphere_coord.z *= inv_scale.z;
                        sphere_coord.x *= maskx;
                        sphere_coord.y *= masky;
                        sphere_coord.z *= maskz;

                        float _radius = scl * radius;
                        float delta   = (_radius - sphere_coord.magnitude) / _radius;
                        float volume  = Mathf.Clamp(delta * min_dimension * scl * VCEMath.MC_ISO_VALUEF + VCEMath.MC_ISO_VALUEF, 0, 255.49f);

                        VCEditor.s_Mirror.MirrorVoxel(pos);

                        for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
                        {
                            pos = VCEditor.s_Mirror.Output[i];
                            if (VCEditor.s_Scene.m_IsoData.IsPointIn(pos))
                            {
                                int     voxel_pos = VCIsoData.IPosToKey(pos);
                                VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                                VCVoxel new_voxel = 0;
                                if (old_voxel.Volume == 0)
                                {
                                    new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                }
                                else if (old_voxel.Volume < VCEMath.MC_ISO_VALUE)
                                {
                                    if (volume < VCEMath.MC_ISO_VALUE)
                                    {
                                        new_voxel = old_voxel;
                                    }
                                    else
                                    {
                                        new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                    }
                                }
                                else
                                {
                                    if (volume < VCEMath.MC_ISO_VALUE)
                                    {
                                        new_voxel = old_voxel;
                                    }
                                    else
                                    {
                                        new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                    }
                                }
                                VCVoxel old_st_voxel = VCEditor.s_Scene.m_Stencil.GetVoxel(voxel_pos);
                                new_voxel.Volume = (new_voxel.Volume > old_st_voxel.Volume) ? (new_voxel.Volume) : (old_st_voxel.Volume);
                                VCEditor.s_Scene.m_Stencil.SetVoxel(voxel_pos, new_voxel);
                            }
                        }
                    }
                    // No mirror
                    else
                    {
                        if (VCEditor.s_Scene.m_IsoData.IsPointIn(pos))
                        {
                            Vector3 sphere_coord = (pos.ToVector3() + Vector3.one * 0.5f) - center;
                            sphere_coord.x *= inv_scale.x;
                            sphere_coord.y *= inv_scale.y;
                            sphere_coord.z *= inv_scale.z;
                            sphere_coord.x *= maskx;
                            sphere_coord.y *= masky;
                            sphere_coord.z *= maskz;

                            float _radius = scl * radius;
                            float delta   = (_radius - sphere_coord.magnitude) / _radius;
                            float volume  = Mathf.Clamp(delta * min_dimension * scl * VCEMath.MC_ISO_VALUEF + VCEMath.MC_ISO_VALUEF, 0, 255.49f);

                            int     voxel_pos = VCIsoData.IPosToKey(pos);
                            VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                            VCVoxel new_voxel = 0;
                            if (old_voxel.Volume == 0)
                            {
                                new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                            }
                            else if (old_voxel.Volume < VCEMath.MC_ISO_VALUE)
                            {
                                if (volume < VCEMath.MC_ISO_VALUE)
                                {
                                    new_voxel = old_voxel;
                                }
                                else
                                {
                                    new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                }
                            }
                            else
                            {
                                if (volume < VCEMath.MC_ISO_VALUE)
                                {
                                    new_voxel = old_voxel;
                                }
                                else
                                {
                                    new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                }
                            }
                            VCEditor.s_Scene.m_Stencil.SetVoxel(voxel_pos, new_voxel);
                        }
                    }
                }
            }
        }
        VCEditor.s_Scene.m_Stencil.NormalizeAllVoxels();
        foreach (KeyValuePair <int, VCVoxel> kvp in VCEditor.s_Scene.m_Stencil.m_Voxels)
        {
            VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(kvp.Key);
            VCVoxel new_voxel = VCEditor.s_Scene.m_Stencil.GetVoxel(kvp.Key);
            if (old_voxel != new_voxel)
            {
                VCEAlterVoxel modify = new VCEAlterVoxel(kvp.Key, old_voxel, new_voxel);
                m_Action.Modifies.Add(modify);
            }
        }
        VCEditor.s_Scene.m_Stencil.Clear();
        if (m_Action.Modifies.Count > 0)
        {
            m_Action.Do();
        }
        ResetDrawing();
    }
Esempio n. 7
0
    protected override void Do()
    {
        m_Action = new VCEAction();

        ulong oldmat_guid = VCEditor.s_Scene.m_IsoData.MaterialGUID(VCEditor.SelectedVoxelType);
        ulong newmat_guid = VCEditor.SelectedMaterial.m_Guid;

        if (oldmat_guid != newmat_guid)
        {
            VCEAlterMaterialMap modify = new VCEAlterMaterialMap(VCEditor.SelectedVoxelType, oldmat_guid, newmat_guid);
            m_Action.Modifies.Add(modify);
        }

        VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
        IntVector3 min = Min;
        IntVector3 max = Max;

        for (int x = min.x; x <= max.x; ++x)
        {
            for (int y = min.y; y <= max.y; ++y)
            {
                for (int z = min.z; z <= max.z; ++z)
                {
                    // Mirror
                    if (VCEditor.s_Mirror.Enabled_Masked)
                    {
                        VCEditor.s_Mirror.MirrorVoxel(new IntVector3(x, y, z));
                        for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
                        {
                            if (VCEditor.s_Scene.m_IsoData.IsPointIn(VCEditor.s_Mirror.Output[i]))
                            {
                                int     voxel_pos = VCIsoData.IPosToKey(VCEditor.s_Mirror.Output[i]);
                                VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                                VCVoxel new_voxel = new VCVoxel(255, (byte)VCEditor.SelectedVoxelType);
                                if (old_voxel != new_voxel)
                                {
                                    VCEAlterVoxel modify = new VCEAlterVoxel(voxel_pos, old_voxel, new_voxel);
                                    m_Action.Modifies.Add(modify);
                                }
                            }
                        }
                    }
                    // No mirror
                    else
                    {
                        int     voxel_pos = VCIsoData.IPosToKey(new IntVector3(x, y, z));
                        VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                        VCVoxel new_voxel = new VCVoxel(255, (byte)VCEditor.SelectedVoxelType);
                        if (old_voxel != new_voxel)
                        {
                            VCEAlterVoxel modify = new VCEAlterVoxel(voxel_pos, old_voxel, new_voxel);
                            m_Action.Modifies.Add(modify);
                        }
                    }
                }
            }
        }
        if (m_Action.Modifies.Count > 0)
        {
            m_Action.Do();
        }
        ResetDrawing();
    }
    public void ApplyInspectorChange()
    {
        if (m_Selection.Count != 1)
        {
            return;
        }
        if (m_DataInspector == null)
        {
            return;
        }

        VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
        m_Action = new VCEAction();
        VCComponentData old_data = m_Selection[0].m_Component.m_Data;
        VCComponentData new_data = m_DataInspector.GetComponent <VCEUIComponentInspector>().Get();

        // Mirror
        if (VCEditor.s_Mirror.Enabled_Masked)
        {
            VCComponentData[] old_img_data = new VCComponentData [8];
            VCEditor.s_Mirror.MirrorComponent(old_data);
            for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
            {
                old_img_data[i] = VCEditor.s_Mirror.ComponentOutput[i].Copy();
            }

            VCEditor.s_Mirror.MirrorComponent(new_data);
            for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
            {
                VCComponentData        image = VCEditor.s_Mirror.ComponentOutput[i];
                List <VCComponentData> edits = VCEditor.s_Scene.m_IsoData.FindComponentsAtPos(old_img_data[i].m_Position, image.m_ComponentId);
                foreach (VCComponentData iter in edits)
                {
                    if (i > 0 && m_Selection.Find(it => it.m_Component.m_Data == iter) != null)
                    {
                        continue;
                    }
                    if (!VCEMath.IsEqualRotation(iter.m_Rotation, old_img_data[i].m_Rotation))
                    {
                        continue;
                    }
                    if (!VCEMath.IsEqualVector(iter.m_Scale, old_img_data[i].m_Scale))
                    {
                        continue;
                    }
                    if (iter.m_Visible != old_img_data[i].m_Visible)
                    {
                        continue;
                    }
                    if (old_img_data[i] is IVCMultiphaseComponentData && iter is IVCMultiphaseComponentData)
                    {
                        if ((old_img_data[i] as IVCMultiphaseComponentData).Phase != (iter as IVCMultiphaseComponentData).Phase)
                        {
                            continue;
                        }
                    }
                    int index = VCEditor.s_Scene.m_IsoData.GetComponentIndex(iter);
                    if (index < 0)
                    {
                        continue;
                    }
                    // Special process for wheels
                    if (i != 0 && image is VCQuadphaseFixedPartData)
                    {
                        (image as VCQuadphaseFixedPartData).m_Phase =
                            ((image as VCQuadphaseFixedPartData).m_Phase & 1) | ((iter as VCQuadphaseFixedPartData).m_Phase & 2);
                    }

                    VCEAlterComponent modify = new VCEAlterComponent(index, iter, image);
                    m_Action.Modifies.Add(modify);
                }
            }
        }
        // No mirror
        else
        {
            int index = VCEditor.s_Scene.m_IsoData.GetComponentIndex(old_data);
            if (index < 0)
            {
                return;
            }
            VCEAlterComponent modify = new VCEAlterComponent(index, old_data, new_data);
            m_Action.Modifies.Add(modify);
        }
        VCEStatusBar.ShowText("Changes applied".ToLocalizationString(), 2);
        m_Action.Do();
    }
    // All Gizmo End
    void OnGizmoEnd()
    {
        if (m_GizmoAction != null)
        {
            VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
            foreach (SelectInfo si in m_Selection)
            {
                bool modified = false;
                if (!VCEMath.IsEqualVector(si.m_NewPosition, si.m_OldPosition))
                {
                    modified = true;
                }
                if (!VCEMath.IsEqualRotation(si.m_NewRotation, si.m_OldRotation))
                {
                    modified = true;
                }
                if (!VCEMath.IsEqualVector(si.m_NewScale, si.m_OldScale))
                {
                    modified = true;
                }
                if (modified)
                {
                    VCEAlterComponentTransform modify = new VCEAlterComponentTransform(
                        VCEditor.s_Scene.m_IsoData.GetComponentIndex(si.m_Component.m_Data),
                        si.m_OldPosition, si.m_OldRotation, si.m_OldScale,
                        si.m_NewPosition, si.m_NewRotation, si.m_NewScale);

                    m_GizmoAction.Modifies.Add(modify);

                    // Mirror
                    if (VCEditor.s_Mirror.Enabled_Masked)
                    {
                        Vector3[] old_poses  = new Vector3[8];
                        Vector3[] old_rots   = new Vector3[8];
                        Vector3[] old_scales = new Vector3[8];
                        VCEditor.s_Mirror.MirrorComponent(si.m_Component.m_Data);
                        for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
                        {
                            old_poses[i]  = VCEditor.s_Mirror.ComponentOutput[i].m_Position;
                            old_rots[i]   = VCEditor.s_Mirror.ComponentOutput[i].m_Rotation;
                            old_scales[i] = VCEditor.s_Mirror.ComponentOutput[i].m_Scale;
                        }

                        VCComponentData tmpdata = si.m_Component.m_Data.Copy();
                        tmpdata.m_Position = si.m_NewPosition;
                        tmpdata.m_Rotation = si.m_NewRotation;
                        tmpdata.m_Scale    = si.m_NewScale;
                        VCEditor.s_Mirror.MirrorComponent(tmpdata);

                        for (int i = 1; i < VCEditor.s_Mirror.OutputCnt; ++i)
                        {
                            VCComponentData image = VCEditor.s_Mirror.ComponentOutput[i];
                            image.Validate();
                            List <VCComponentData> edits = VCEditor.s_Scene.m_IsoData.FindComponentsAtPos(old_poses[i], image.m_ComponentId);
                            foreach (VCComponentData iter in edits)
                            {
                                if (!VCEMath.IsEqualRotation(iter.m_Rotation, old_rots[i]))
                                {
                                    continue;
                                }
                                if (iter.m_Scale != old_scales[i])
                                {
                                    continue;
                                }
                                if (iter.m_Visible != image.m_Visible)
                                {
                                    continue;
                                }
                                if (image is IVCMultiphaseComponentData && iter is IVCMultiphaseComponentData)
                                {
                                    if ((image as IVCMultiphaseComponentData).Phase != (iter as IVCMultiphaseComponentData).Phase)
                                    {
                                        continue;
                                    }
                                }
                                if (m_Selection.Find(it => it.m_Component.m_Data == iter) == null)
                                {
                                    VCEAlterComponentTransform modify_mirror = new VCEAlterComponentTransform(
                                        VCEditor.s_Scene.m_IsoData.GetComponentIndex(iter),
                                        iter.m_Position, iter.m_Rotation, iter.m_Scale,
                                        image.m_Position, image.m_Rotation, image.m_Scale);

                                    m_GizmoAction.Modifies.Add(modify_mirror);
                                }
                            }
                        }
                    }
                    // End 'mirror'
                }
            }
            if (m_GizmoAction.Modifies.Count > 0)
            {
                m_GizmoAction.Do();
                m_GizmoAction = null;
            }
        }
        else
        {
            Debug.LogWarning("Must be some problem here!");
        }
    }
Esempio n. 10
0
    protected override void Do()
    {
        m_Action = new VCEAction();

        ulong oldmat_guid = VCEditor.s_Scene.m_IsoData.MaterialGUID(VCEditor.SelectedVoxelType);
        ulong newmat_guid = VCEditor.SelectedMaterial.m_Guid;

        if (oldmat_guid != newmat_guid)
        {
            VCEAlterMaterialMap modify = new VCEAlterMaterialMap(VCEditor.SelectedVoxelType, oldmat_guid, newmat_guid);
            m_Action.Modifies.Add(modify);
        }

        Vector3 pa = Vector3.zero;
        Vector3 pb = Vector3.zero;
        Vector3 pc = Vector3.zero;

        switch (m_Direction)
        {
        default:
        case 0: pa = new Vector3(Min.x, Min.y, Min.z - 0.5f); pb = new Vector3(Max.x + 1, Max.y + 1.5f, Max.z + 1); pc = new Vector3(Max.x + 1, Min.y, Min.z - 0.5f); break;

        case 1: pa = new Vector3(Max.x + 1, Max.y + 1, Max.z + 1.5f); pb = new Vector3(Min.x, Min.y - 0.5f, Min.z); pc = new Vector3(Max.x + 1, Min.y - 0.5f, Min.z); break;

        case 2: pa = new Vector3(Min.x, Max.y + 1.5f, Min.z); pb = new Vector3(Max.x + 1, Min.y, Max.z + 1.5f); pc = new Vector3(Max.x + 1, Max.y + 1.5f, Min.z); break;

        case 3: pa = new Vector3(Max.x + 1, Min.y - 0.5f, Max.z + 1); pb = new Vector3(Min.x, Max.y + 1, Min.z - 0.5f); pc = new Vector3(Max.x + 1, Max.y + 1, Min.z - 0.5f); break;

        case 4: pa = new Vector3(Min.x - 0.5f, Min.y, Min.z); pb = new Vector3(Max.x + 1, Max.y + 1, Max.z + 1.5f); pc = new Vector3(Min.x - 0.5f, Max.y + 1, Min.z); break;

        case 5: pa = new Vector3(Max.x + 1.5f, Max.y + 1, Max.z + 1); pb = new Vector3(Min.x, Min.y, Min.z - 0.5f); pc = new Vector3(Min.x, Max.y + 1, Min.z - 0.5f); break;

        case 6: pa = new Vector3(Max.x + 1, Min.y, Min.z - 0.5f); pb = new Vector3(Min.x - 0.5f, Max.y + 1, Max.z + 1); pc = new Vector3(Max.x + 1, Max.y + 1, Min.z - 0.5f); break;

        case 7: pa = new Vector3(Min.x, Max.y + 1, Max.z + 1.5f); pb = new Vector3(Max.x + 1.5f, Min.y, Min.z); pc = new Vector3(Max.x + 1.5f, Max.y + 1, Min.z); break;

        case 8:  pa = new Vector3(Min.x, Min.y - 0.5f, Min.z); pb = new Vector3(Max.x + 1.5f, Max.y + 1, Max.z + 1); pc = new Vector3(Min.x, Min.y - 0.5f, Max.z + 1); break;

        case 9:  pa = new Vector3(Max.x + 1, Max.y + 1.5f, Max.z + 1); pb = new Vector3(Min.x - 0.5f, Min.y, Min.z); pc = new Vector3(Min.x - 0.5f, Min.y, Max.z + 1); break;

        case 10: pa = new Vector3(Max.x + 1.5f, Min.y, Min.z); pb = new Vector3(Min.x, Max.y + 1.5f, Max.z + 1); pc = new Vector3(Max.x + 1.5f, Min.y, Max.z + 1); break;

        case 11: pa = new Vector3(Min.x - 0.5f, Max.y + 1, Max.z + 1); pb = new Vector3(Max.x + 1, Min.y - 0.5f, Min.z); pc = new Vector3(Max.x + 1, Min.y - 0.5f, Max.z + 1); break;
        }

        //Vector3 offset = m_Offset * Vector3.up;
        //Vector3 offset2 = (m_Offset-m_Thickness) * Vector3.up;
        Plane pl = new Plane(pa, pb, pc);

        //Plane pl2 = new Plane (pa+offset2, pc+offset2, pb+offset2);

        VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
        IntVector3 min = Min;
        IntVector3 max = Max;

        for (int x = min.x; x <= max.x; ++x)
        {
            for (int y = min.y; y <= max.y; ++y)
            {
                for (int z = min.z; z <= max.z; ++z)
                {
                    float volume = VCEMath.DetermineVolume(x, y, z, pl);
                    //float volume2 = VCEMath.DetermineVolume(x,y,z,pl2);
                    int vol = Mathf.RoundToInt(volume);
                    if (vol == 0)
                    {
                        continue;
                    }
                    // Mirror
                    if (VCEditor.s_Mirror.Enabled_Masked)
                    {
                        VCEditor.s_Mirror.MirrorVoxel(new IntVector3(x, y, z));
                        for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
                        {
                            if (VCEditor.s_Scene.m_IsoData.IsPointIn(VCEditor.s_Mirror.Output[i]))
                            {
                                int     voxel_pos = VCIsoData.IPosToKey(VCEditor.s_Mirror.Output[i]);
                                VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                                VCVoxel new_voxel = new VCVoxel((byte)vol, (byte)VCEditor.SelectedVoxelType);
                                if (old_voxel != new_voxel)
                                {
                                    VCEAlterVoxel modify = new VCEAlterVoxel(voxel_pos, old_voxel, new_voxel);
                                    m_Action.Modifies.Add(modify);
                                }
                            }
                        }
                    }
                    // No mirror
                    else
                    {
                        int     voxel_pos = VCIsoData.IPosToKey(new IntVector3(x, y, z));
                        VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                        VCVoxel new_voxel = new VCVoxel((byte)vol, (byte)VCEditor.SelectedVoxelType);
                        if (old_voxel != new_voxel)
                        {
                            VCEAlterVoxel modify = new VCEAlterVoxel(voxel_pos, old_voxel, new_voxel);
                            m_Action.Modifies.Add(modify);
                        }
                    }
                }
            }
        }
        if (m_Action.Modifies.Count > 0)
        {
            m_Action.Do();
        }
        ResetDrawing();
    }
Esempio n. 11
0
    protected override void Do()
    {
        m_Action = new VCEAction();

        ulong oldmat_guid = VCEditor.s_Scene.m_IsoData.MaterialGUID(VCEditor.SelectedVoxelType);
        ulong newmat_guid = VCEditor.SelectedMaterial.m_Guid;

        if (oldmat_guid != newmat_guid)
        {
            VCEAlterMaterialMap modify = new VCEAlterMaterialMap(VCEditor.SelectedVoxelType, oldmat_guid, newmat_guid);
            m_Action.Modifies.Add(modify);
        }

        VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
        IntVector3 min           = Min;
        IntVector3 max           = Max;
        Vector3    extend        = Size.ToVector3() * 0.5f;
        Vector3    center        = min.ToVector3() + extend;
        Vector3    inv_scale     = Vector3.one;
        float      radius        = Mathf.Max(extend.x, extend.y, extend.z);
        float      min_dimension = Mathf.Max(Mathf.Min(extend.x, extend.y, extend.z) - 0.5f, 1);

        if (extend.x >= extend.y && extend.x >= extend.z)
        {
            inv_scale = new Vector3(1, extend.x / extend.y, extend.x / extend.z);
        }
        else if (extend.y >= extend.x && extend.y >= extend.z)
        {
            inv_scale = new Vector3(extend.y / extend.x, 1, extend.y / extend.z);
        }
        else
        {
            inv_scale = new Vector3(extend.z / extend.x, extend.z / extend.y, 1);
        }

        for (int x = min.x - 2; x <= max.x + 2; ++x)
        {
            for (int y = min.y - 2; y <= max.y + 2; ++y)
            {
                for (int z = min.z - 2; z <= max.z + 2; ++z)
                {
                    IntVector3 pos = new IntVector3(x, y, z);
                    // Mirror
                    if (VCEditor.s_Mirror.Enabled_Masked)
                    {
                        Vector3 sphere_coord = (pos.ToVector3() + Vector3.one * 0.5f) - center;
                        sphere_coord.x *= inv_scale.x;
                        sphere_coord.y *= inv_scale.y;
                        sphere_coord.z *= inv_scale.z;

                        float delta  = (radius - sphere_coord.magnitude) / radius;
                        float volume = Mathf.Clamp(delta * min_dimension * VCEMath.MC_ISO_VALUEF + VCEMath.MC_ISO_VALUEF, 0, 255.49f);

                        VCEditor.s_Mirror.MirrorVoxel(pos);

                        for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
                        {
                            pos = VCEditor.s_Mirror.Output[i];
                            if (VCEditor.s_Scene.m_IsoData.IsPointIn(pos))
                            {
                                int     voxel_pos = VCIsoData.IPosToKey(pos);
                                VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                                VCVoxel new_voxel = 0;
                                if (old_voxel.Volume == 0)
                                {
                                    new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                }
                                else if (old_voxel.Volume < VCEMath.MC_ISO_VALUE)
                                {
                                    if (volume < VCEMath.MC_ISO_VALUE)
                                    {
                                        new_voxel = old_voxel;
                                    }
                                    else
                                    {
                                        new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                    }
                                }
                                else
                                {
                                    if (volume < VCEMath.MC_ISO_VALUE)
                                    {
                                        new_voxel = old_voxel;
                                    }
                                    else
                                    {
                                        new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                    }
                                }
                                VCVoxel old_st_voxel = VCEditor.s_Scene.m_Stencil.GetVoxel(voxel_pos);
                                new_voxel.Volume = (new_voxel.Volume > old_st_voxel.Volume) ? (new_voxel.Volume) : (old_st_voxel.Volume);
                                VCEditor.s_Scene.m_Stencil.SetVoxel(voxel_pos, new_voxel);
                            }
                        }
                    }
                    // No mirror
                    else
                    {
                        if (VCEditor.s_Scene.m_IsoData.IsPointIn(pos))
                        {
                            Vector3 sphere_coord = (pos.ToVector3() + Vector3.one * 0.5f) - center;
                            sphere_coord.x *= inv_scale.x;
                            sphere_coord.y *= inv_scale.y;
                            sphere_coord.z *= inv_scale.z;

                            float delta  = (radius - sphere_coord.magnitude) / radius;
                            float volume = Mathf.Clamp(delta * min_dimension * VCEMath.MC_ISO_VALUEF + VCEMath.MC_ISO_VALUEF, 0, 255.49f);

                            int     voxel_pos = VCIsoData.IPosToKey(pos);
                            VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                            VCVoxel new_voxel = 0;
                            if (old_voxel.Volume == 0)
                            {
                                new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                            }
                            else if (old_voxel.Volume < VCEMath.MC_ISO_VALUE)
                            {
                                if (volume < VCEMath.MC_ISO_VALUE)
                                {
                                    new_voxel = old_voxel;
                                }
                                else
                                {
                                    new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                }
                            }
                            else
                            {
                                if (volume < VCEMath.MC_ISO_VALUE)
                                {
                                    new_voxel = old_voxel;
                                }
                                else
                                {
                                    new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                }
                            }
                            VCEditor.s_Scene.m_Stencil.SetVoxel(voxel_pos, new_voxel);
                        }
                    }
                }
            }
        }
        VCEditor.s_Scene.m_Stencil.NormalizeAllVoxels();
        foreach (KeyValuePair <int, VCVoxel> kvp in VCEditor.s_Scene.m_Stencil.m_Voxels)
        {
            VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(kvp.Key);
            VCVoxel new_voxel = VCEditor.s_Scene.m_Stencil.GetVoxel(kvp.Key);
            if (old_voxel != new_voxel)
            {
                VCEAlterVoxel modify = new VCEAlterVoxel(kvp.Key, old_voxel, new_voxel);
                m_Action.Modifies.Add(modify);
            }
        }
        VCEditor.s_Scene.m_Stencil.Clear();
        if (m_Action.Modifies.Count > 0)
        {
            m_Action.Do();
        }
        ResetDrawing();
    }