public void OutputVoxels(Vector3 offset, OnOutputVoxel output_function)
    {
        if (ISO == null)
        {
            return;
        }
        if (output_function == null)
        {
            return;
        }
        foreach (KeyValuePair <int, VCVoxel> kvp in ISO.m_Voxels)
        {
            Vector3 lpos = new Vector3(kvp.Key & 0x3ff, kvp.Key >> 20, (kvp.Key >> 10) & 0x3ff);
            Vector3 wpos = OriginTransform.position
                           + lpos.x * OriginTransform.right
                           + lpos.y * OriginTransform.up
                           + lpos.z * OriginTransform.forward;
            wpos += offset;

            INTVECTOR3 wpos_floor = new INTVECTOR3(Mathf.FloorToInt(wpos.x), Mathf.FloorToInt(wpos.y), Mathf.FloorToInt(wpos.z));
            INTVECTOR3 wpos_ceil  = new INTVECTOR3(Mathf.CeilToInt(wpos.x), Mathf.CeilToInt(wpos.y), Mathf.CeilToInt(wpos.z));

            if (wpos_floor == wpos_ceil)
            {
                output_function(wpos_floor.x, wpos_floor.y, wpos_floor.z, kvp.Value);
            }
            else
            {
                for (int x = wpos_floor.x; x <= wpos_ceil.x; ++x)
                {
                    for (int y = wpos_floor.y; y <= wpos_ceil.y; ++y)
                    {
                        for (int z = wpos_floor.z; z <= wpos_ceil.z; ++z)
                        {
                            float deltax = 1 - Mathf.Abs(wpos.x - x);
                            float deltay = 1 - Mathf.Abs(wpos.y - y);
                            float deltaz = 1 - Mathf.Abs(wpos.z - z);
                            float u      = deltax * deltay * deltaz;
                            if (u < 0.5f)
                            {
                                u = u / (0.5f + u);
                            }
                            else
                            {
                                u = 0.5f / (1.5f - u);
                            }
                            VCVoxel voxel = kvp.Value;
                            voxel.Volume = (byte)Mathf.CeilToInt(voxel.Volume * u);
                            if (voxel.Volume > 1)
                            {
                                output_function(x, y, z, voxel);
                            }
                        }
                    }
                }
            }
        }
    }
示例#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);
    }
示例#3
0
    public void DeleteSelection()
    {
        m_Action = new VCEAction();

        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;
                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 = old_voxel;
                        new_voxel.VolumeF = new_voxel.VolumeF * (1 - strength);
                        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;
                int     voxel_pos = kvp.Key;
                VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                VCVoxel new_voxel = old_voxel;
                new_voxel.VolumeF = new_voxel.VolumeF * (1 - strength);
                if (old_voxel != new_voxel)
                {
                    VCEAlterVoxel modify = new VCEAlterVoxel(voxel_pos, old_voxel, new_voxel);
                    m_Action.Modifies.Add(modify);
                }
            }
        }
        ColorSelection(VCIsoData.BLANK_COLOR, false, true);
        if (m_Action.Modifies.Count > 0)
        {
            m_Action.DoButNotRegister();
            VCUtils.ISOCut(VCEditor.s_Scene.m_IsoData, m_Action);
            m_Action.Register();
            VCEStatusBar.ShowText("Selected voxels have been removed".ToLocalizationString(), 2);
        }
        ClearSelection();
    }
示例#4
0
    public void NormalizeAllVoxels()
    {
        List <int> del_list = new List <int> ();
        List <int> max_list = new List <int> ();

        foreach (KeyValuePair <int, VCVoxel> kvp in m_Voxels)
        {
            int pos0 = kvp.Key + 1;
            int pos1 = kvp.Key - 1;
            int pos2 = kvp.Key + (1 << 10);
            int pos3 = kvp.Key - (1 << 10);
            int pos4 = kvp.Key + (1 << 20);
            int pos5 = kvp.Key - (1 << 20);
            if (kvp.Value.Volume >= VCEMath.MC_ISO_VALUE)
            {
                if (GetVoxel(pos0).Volume >= VCEMath.MC_ISO_VALUE &&
                    GetVoxel(pos1).Volume >= VCEMath.MC_ISO_VALUE &&
                    GetVoxel(pos2).Volume >= VCEMath.MC_ISO_VALUE &&
                    GetVoxel(pos3).Volume >= VCEMath.MC_ISO_VALUE &&
                    GetVoxel(pos4).Volume >= VCEMath.MC_ISO_VALUE &&
                    GetVoxel(pos5).Volume >= VCEMath.MC_ISO_VALUE)
                {
                    max_list.Add(kvp.Key);
                }
            }
            else
            {
                if (GetVoxel(pos0).Volume < VCEMath.MC_ISO_VALUE &&
                    GetVoxel(pos1).Volume < VCEMath.MC_ISO_VALUE &&
                    GetVoxel(pos2).Volume < VCEMath.MC_ISO_VALUE &&
                    GetVoxel(pos3).Volume < VCEMath.MC_ISO_VALUE &&
                    GetVoxel(pos4).Volume < VCEMath.MC_ISO_VALUE &&
                    GetVoxel(pos5).Volume < VCEMath.MC_ISO_VALUE)
                {
                    del_list.Add(kvp.Key);
                }
            }
        }
        foreach (int key in del_list)
        {
            m_Voxels.Remove(key);
        }
        foreach (int key in max_list)
        {
            VCVoxel v = m_Voxels[key];
            v.Volume      = 255;
            m_Voxels[key] = v;
        }
        del_list.Clear();
        max_list.Clear();
    }
示例#5
0
 // Set voxel
 public void SetVoxel(int pos, VCVoxel voxel)
 {
     if (voxel.Volume == 0)
     {
         if (m_Voxels.ContainsKey(pos))
         {
             m_Voxels.Remove(pos);
         }
     }
     else
     {
         m_Voxels[pos] = voxel;
     }
 }
示例#6
0
    public static void OutputTownVoxel(int x, int y, int z, VCVoxel voxel, VArtifactUnit town)
    {
        IntVector3 pos     = new IntVector3(x, y, z);
        VFVoxel    vfvoxel = new VFVoxel();

        vfvoxel.Type   = voxel.Type;
        vfvoxel.Volume = voxel.Volume;
        if (town.townVoxel.ContainsKey(pos))
        {
            VFVoxel originVoxel = town.townVoxel[pos];
            vfvoxel.Volume = (byte)Mathf.Clamp(vfvoxel.Volume + originVoxel.Volume, 0, 255);
        }
        town.townVoxel[pos] = vfvoxel;
        //Debug.LogError("addarttown:"+pos);
    }
示例#7
0
 private void GenSomeVoxelForTest()
 {
     for (int x = 0; x < 31; ++x)
     {
         for (int y = 0; y < 12; ++y)
         {
             for (int z = 0; z < 31; ++z)
             {
                 if ((x + y + z) % 3 == 0)
                 {
                     VCVoxel voxel = new VCVoxel((byte)(UnityEngine.Random.value * 128 + 128), 1);
                     m_IsoData.SetVoxel(VCIsoData.IPosToKey(new IntVector3(x, y, z)), voxel);
                     m_MeshComputer.AlterVoxel(x, y, z, voxel);
                 }
             }
         }
     }
 }
示例#8
0
 public VCEAlterVoxel(int position, VCVoxel old_voxel, VCVoxel new_voxel)
 {
     m_Pos = position;
     m_Old = old_voxel;
     m_New = new_voxel;
 }
示例#9
0
    // Input
    public void AlterVoxel(int poskey, VCVoxel voxel)
    {
        IntVector3 pos = VCIsoData.KeyToIPos(poskey);

        m_DataSource.Write(pos.x + 1, pos.y + 1, pos.z + 1, new VFVoxel(voxel.Volume, voxel.Type), 0, false);
    }
示例#10
0
 public void AlterVoxel(int x, int y, int z, VCVoxel voxel)
 {
     m_DataSource.Write(x + 1, y + 1, z + 1, new VFVoxel(voxel.Volume, voxel.Type), 0, false);
 }
示例#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();
    }
示例#12
0
    //public static void OutputVoxels(Vector3 worldPos, ulong guid, VArtifactTown newTown)
    //{
    //    ISO = isos[guid];
    //    OutputVoxels(worldPos,newTown);
    //}

    //public static void OutputVoxels(Vector3 worldPos, int townId, VArtifactTown newTown)
    //{
    //    ulong guid = townIdIso[townId];
    //    ISO = isos[guid];
    //    OutputVoxels(worldPos,newTown);
    //}


    public static void OutputVoxels(Vector3 worldPos, VArtifactUnit newTown, float rotation = 0)
    {
        if (!isos.ContainsKey(newTown.isoGuId))
        {
            LoadIso(GetISONameFullPath(newTown.isoName));
        }
        if (!isos.ContainsKey(newTown.isoGuId))
        {
            Debug.LogError("isoGuId error: " + newTown.isoGuId + "isoName: " + newTown.isoName);
            return;
        }
        VArtifactData isoData = isos[newTown.isoGuId];
        //long tick = System.DateTime.Now.Ticks;
        Quaternion q = new Quaternion();

        q.eulerAngles = new Vector3(0, rotation, 0);
        Vector3 XDir = (q * Vector3.right).normalized;
        Vector3 YDir = (q * Vector3.up).normalized;
        Vector3 ZDir = (q * Vector3.forward).normalized;
        //Vector3 XDir = Vector3.right;
        //Vector3 YDir = Vector3.up;
        //Vector3 ZDir = Vector3.forward;
        Vector3 ofs     = new Vector3(isoData.m_HeadInfo.xSize, 0, isoData.m_HeadInfo.zSize) * (-0.5f);
        Vector3 new_pos = worldPos + q * ofs;

        foreach (KeyValuePair <int, VCVoxel> kvp in isoData.m_Voxels)
        {
            Vector3 lpos = new Vector3(kvp.Key & 0x3ff, kvp.Key >> 20, (kvp.Key >> 10) & 0x3ff);
            Vector3 wpos = new_pos
                           + lpos.x * XDir
                           + lpos.y * YDir
                           + lpos.z * ZDir;

            INTVECTOR3 wpos_floor = new INTVECTOR3(Mathf.FloorToInt(wpos.x), Mathf.FloorToInt(wpos.y), Mathf.FloorToInt(wpos.z));
            INTVECTOR3 wpos_ceil  = new INTVECTOR3(Mathf.CeilToInt(wpos.x), Mathf.CeilToInt(wpos.y), Mathf.CeilToInt(wpos.z));

            if (wpos_floor == wpos_ceil)
            {
                OutputTownVoxel(wpos_floor.x, wpos_floor.y, wpos_floor.z, kvp.Value, newTown);
            }
            else
            {
                for (int x = wpos_floor.x; x <= wpos_ceil.x; ++x)
                {
                    for (int y = wpos_floor.y; y <= wpos_ceil.y; ++y)
                    {
                        for (int z = wpos_floor.z; z <= wpos_ceil.z; ++z)
                        {
                            float deltax = 1 - Mathf.Abs(wpos.x - x);
                            float deltay = 1 - Mathf.Abs(wpos.y - y);
                            float deltaz = 1 - Mathf.Abs(wpos.z - z);
                            float u      = deltax * deltay * deltaz;
                            if (u < 0.5f)
                            {
                                u = u / (0.5f + u);
                            }
                            else
                            {
                                u = 0.5f / (1.5f - u);
                            }
                            VCVoxel voxel = kvp.Value;
                            voxel.Volume = (byte)Mathf.CeilToInt(voxel.Volume * u);
                            if (voxel.Volume > 1)
                            {
                                OutputTownVoxel(x, y, z, voxel, newTown);
                            }
                        }
                    }
                }
            }
        }
        // Debug.LogError("Output Time: " + (System.DateTime.Now.Ticks - tick) + " townCount:" + (++townCount));
    }
示例#13
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();
    }
示例#14
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);
        }
    }
示例#15
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();
    }
示例#16
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();
    }
    // Submit this selecting action
    protected override void Submit()
    {
        m_Iso.ClampPointI(m_Begin);
        m_Iso.ClampPointI(m_End);
        IntVector3 iMin = new IntVector3(0, 0, 0);
        IntVector3 iMax = new IntVector3(0, 0, 0);

        iMin.x = Mathf.Min(m_Begin.x, m_End.x);
        iMin.y = Mathf.Min(m_Begin.y, m_End.y);
        iMin.z = Mathf.Min(m_Begin.z, m_End.z);
        iMax.x = Mathf.Max(m_Begin.x, m_End.x);
        iMax.y = Mathf.Max(m_Begin.y, m_End.y);
        iMax.z = Mathf.Max(m_Begin.z, m_End.z);

        // Calculate feather effect bound
        IntVector3 fMin = new IntVector3(0, 0, 0);
        IntVector3 fMax = new IntVector3(0, 0, 0);

        fMin.x = iMin.x - m_FeatherLength; fMin.y = iMin.y - m_FeatherLength; fMin.z = iMin.z - m_FeatherLength;
        fMax.x = iMax.x + m_FeatherLength; fMax.y = iMax.y + m_FeatherLength; fMax.z = iMax.z + m_FeatherLength;
        if (m_PlaneFeather)
        {
            switch (m_Coord)
            {
            case ECoordPlane.XY:
                fMin.z = iMin.z;
                fMax.z = iMax.z;
                break;

            case ECoordPlane.XZ:
                fMin.y = iMin.y;
                fMax.y = iMax.y;
                break;

            case ECoordPlane.ZY:
                fMin.x = iMin.x;
                fMax.x = iMax.x;
                break;
            }
        }
        m_Iso.ClampPointI(fMin);
        m_Iso.ClampPointI(fMax);

        // Select
        if (!VCEInput.s_Shift && !VCEInput.s_Alt && !VCEInput.s_Control)
        {
            m_Selection.Clear();
        }

        for (int x = fMin.x; x <= fMax.x; ++x)
        {
            for (int y = fMin.y; y <= fMax.y; ++y)
            {
                for (int z = fMin.z; z <= fMax.z; ++z)
                {
                    int poskey = VCIsoData.IPosToKey(x, y, z);
                    if (m_Iso.GetVoxel(poskey).Volume < 1)
                    {
                        continue;
                    }
                    int old_sv   = 0;
                    int alter_sv = (m_FeatherLength == 0) ? (255) : ((int)(VCEMath.BoxFeather(new IntVector3(x, y, z), iMin, iMax, m_FeatherLength) * 255.0f));
                    int new_sv   = 0;
                    if (alter_sv < 1)
                    {
                        continue;
                    }

                    if (m_Selection.ContainsKey(poskey))
                    {
                        old_sv = m_Selection[poskey];
                    }
                    if (VCEInput.s_Shift)
                    {
                        new_sv = old_sv + alter_sv;
                    }
                    else if (VCEInput.s_Alt)
                    {
                        new_sv = old_sv - alter_sv;
                    }
                    else if (VCEInput.s_Control)
                    {
                        new_sv = Mathf.Abs(old_sv - alter_sv);
                    }
                    else
                    {
                        new_sv = alter_sv;
                    }
                    new_sv = Mathf.Clamp(new_sv, 0, 255);
                    if (new_sv < 1)
                    {
                        m_Selection.Remove(poskey);
                    }
                    else if (old_sv < 1)
                    {
                        m_Selection.Add(poskey, (byte)new_sv);
                    }
                    else
                    {
                        m_Selection[poskey] = (byte)new_sv;
                    }

                    if (m_MaterialSelect)
                    {
                        VCVoxel vcv = m_Iso.GetVoxel(poskey);
                        if (m_Iso.m_Materials[vcv.Type] != VCEditor.SelectedMaterial)
                        {
                            m_Selection.Remove(poskey);
                        }
                    }
                }
            }
        }
    }
示例#18
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();
        }
    }
示例#19
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();
    }