Exemplo n.º 1
0
 // ----------- Submit ------------------------
 void Apply()
 {
     if (m_Target != null)
     {
         ulong old_guid           = 0;
         ulong new_guid           = 0;
         bool  need_update_isomat = (VCEditor.s_Scene.m_IsoData.QueryMaterial(m_Target.m_Guid) != null);
         if (VCEAssetMgr.s_Materials.ContainsKey(m_Target.m_Guid))
         {
             old_guid = m_Target.m_Guid;
             if (!VCEAssetMgr.DeleteMaterialDataFile(m_Target.m_Guid))
             {
                 VCEMsgBox.Show(VCEMsgBoxType.MATERIAL_NOT_SAVED);
             }
             VCEAssetMgr.s_Materials.Remove(m_Target.m_Guid);
             m_Target.Import(m_TempMaterial.Export());
             new_guid = m_Target.m_Guid;
             VCEAssetMgr.s_Materials.Add(m_Target.m_Guid, m_Target);
             if (!VCEAssetMgr.CreateMaterialDataFile(m_Target))
             {
                 VCEMsgBox.Show(VCEMsgBoxType.MATERIAL_NOT_SAVED);
             }
         }
         else if (VCEAssetMgr.s_TempMaterials.ContainsKey(m_Target.m_Guid))
         {
             old_guid = m_Target.m_Guid;
             VCEAssetMgr.s_TempMaterials.Remove(m_Target.m_Guid);
             m_Target.Import(m_TempMaterial.Export());
             new_guid = m_Target.m_Guid;
             VCEAssetMgr.s_TempMaterials.Add(m_Target.m_Guid, m_Target);
         }
         else
         {
             Debug.LogError("What the hell is that ?!");
             old_guid = m_Target.m_Guid;
             m_Target.Import(m_TempMaterial.Export());
             new_guid = m_Target.m_Guid;
             VCEAssetMgr.s_Materials.Add(m_Target.m_Guid, m_Target);
             if (!VCEAssetMgr.CreateMaterialDataFile(m_Target))
             {
                 VCEMsgBox.Show(VCEMsgBoxType.MATERIAL_NOT_SAVED);
             }
         }
         VCEAlterMaterialMap.MatChange(old_guid, new_guid);
         if (need_update_isomat)
         {
             VCEditor.s_Scene.GenerateIsoMat();
         }
         VCEditor.SelectedMaterial = m_Target;
         VCEditor.Instance.m_UI.m_MaterialList.RefreshMaterialListThenFocusOnSelected();
         VCEditor.SelectedMaterial = m_Target;
     }
     else
     {
         Debug.LogError("No target material, Create new material instead !");
         CreateAsNew();
     }
 }
Exemplo n.º 2
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);
    }
Exemplo n.º 3
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);
        }
    }
Exemplo n.º 4
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();
    }
Exemplo n.º 5
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();
    }
Exemplo 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);
        }

        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();
    }
Exemplo 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;
        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();
    }