public void ColorSelection(Color32 color, bool consider_strength = true, bool action_segment = false) { if (!VCEditor.Instance.m_UI.m_PaintTab.isChecked) { return; } if (!action_segment) { m_Action = new VCEAction(); } bool modified = false; VCEUpdateColorSign sign_b = new VCEUpdateColorSign(false, true); m_Action.Modifies.Add(sign_b); VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize); foreach (SelBox sb in m_SelectionMgr.m_GL.m_Boxes) { float t = (float)(sb.m_Val) / 255.0f; byte code; // This is a filter code, when color key was not on edge or vertex, their is no point to color this key. float x, y, z; for (x = sb.m_Box.xMin, code = 0; x <= sb.m_Box.xMax + 1.01f; x += 0.5f, code ^= 1) { for (y = sb.m_Box.yMin, code &= 1; y <= sb.m_Box.yMax + 1.01f; y += 0.5f, code ^= 2) { if (code == 0 || code == 4) { continue; // code 0, 4, no point to color } for (z = sb.m_Box.zMin, code &= 3; z <= sb.m_Box.zMax + 1.01f; z += 0.5f, code ^= 4) { if (code == 1 || code == 2) { continue; // code 1, 2, no point to color } // Mirror if (VCEditor.s_Mirror.Enabled_Masked) { IntVector3 color_pos = VCIsoData.IPosToColorPos(new Vector3(x, y, z)); VCEditor.s_Mirror.MirrorColor(color_pos); for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i) { if (VCEditor.s_Scene.m_IsoData.IsColorPosIn(VCEditor.s_Mirror.Output[i])) { int key = VCIsoData.ColorPosToColorKey(VCEditor.s_Mirror.Output[i]); Color32 old_color = VCEditor.s_Scene.m_IsoData.GetColor(key); Color32 new_color = consider_strength ? Color32.Lerp(old_color, color, t) : color; if (old_color.r == new_color.r && old_color.g == new_color.g && old_color.b == new_color.b && old_color.a == new_color.a) { continue; } VCEAlterColor modify = new VCEAlterColor(key, old_color, new_color); modify.Redo(); m_Action.Modifies.Add(modify); modified = true; } } } // No mirror else { int key = VCIsoData.IPosToColorKey(new Vector3(x, y, z)); Color32 old_color = VCEditor.s_Scene.m_IsoData.GetColor(key); Color32 new_color = consider_strength ? Color32.Lerp(old_color, color, t) : color; if (old_color.r == new_color.r && old_color.g == new_color.g && old_color.b == new_color.b && old_color.a == new_color.a) { continue; } VCEAlterColor modify = new VCEAlterColor(key, old_color, new_color); m_Action.Modifies.Add(modify); modified = true; } } } } } VCEUpdateColorSign sign_f = new VCEUpdateColorSign(true, false); m_Action.Modifies.Add(sign_f); if (action_segment && !modified) { m_Action.Modifies.RemoveRange(m_Action.Modifies.Count - 2, 2); } if (!action_segment && m_Action.Modifies.Count > 2) { m_Action.Do(); if (color.r == VCIsoData.BLANK_COLOR.r && color.g == VCIsoData.BLANK_COLOR.g && color.b == VCIsoData.BLANK_COLOR.b && color.a == VCIsoData.BLANK_COLOR.a) { VCEStatusBar.ShowText("Selection color have been erased".ToLocalizationString(), 2); } else { VCEStatusBar.ShowText("Selected voxels have been painted".ToLocalizationString(), 2); } } }
void ColorPosition(Vector3 iso_pos, MeshFilter mf, float strength) { if (m_Action != null && mf) { int pos = VCIsoData.IPosToColorKey(iso_pos); // Check color necessity int _x2 = pos & 0x3ff; int _y2 = (pos >> 20) & 0x3ff; int _z2 = (pos >> 10) & 0x3ff; if (_x2 % 2 == 1 && _y2 % 2 == 1) { return; } if (_y2 % 2 == 1 && _z2 % 2 == 1) { return; } if (_z2 % 2 == 1 && _x2 % 2 == 1) { return; } // Mirror if (VCEditor.s_Mirror.Enabled_Masked) { IntVector3 color_pos = VCIsoData.IPosToColorPos(iso_pos); VCEditor.s_Mirror.MirrorColor(color_pos); for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i) { if (VCEditor.s_Scene.m_IsoData.IsColorPosIn(VCEditor.s_Mirror.Output[i])) { int _pos = VCIsoData.ColorPosToColorKey(VCEditor.s_Mirror.Output[i]); Color32 old_color = VCEditor.s_Scene.m_IsoData.GetColor(_pos); Color32 new_color = Color32.Lerp(old_color, m_TargetColor, strength); if (old_color.r == new_color.r && old_color.g == new_color.g && old_color.b == new_color.b && old_color.a == new_color.a) { continue; } VCEAlterColor modify = new VCEAlterColor(_pos, old_color, new_color); m_Action.Modifies.Add(modify); modify.Redo(); if (!m_NeedUpdateMfs.Contains(mf)) { m_NeedUpdateMfs.Add(mf); } } } } // No mirror else { Color32 old_color = VCEditor.s_Scene.m_IsoData.GetColor(pos); Color32 new_color = Color32.Lerp(old_color, m_TargetColor, strength); if (old_color.r == new_color.r && old_color.g == new_color.g && old_color.b == new_color.b && old_color.a == new_color.a) { return; } VCEAlterColor modify = new VCEAlterColor(pos, old_color, new_color); m_Action.Modifies.Add(modify); modify.Redo(); if (!m_NeedUpdateMfs.Contains(mf)) { m_NeedUpdateMfs.Add(mf); } } } }