public void DeleteVoxels() { List <IntVector3> selections = GetSelectionPos(); if (selections.Count == 0) { return; } List <BSVoxel> new_voxels = new List <BSVoxel>(); List <BSVoxel> old_voxels = new List <BSVoxel>(); for (int i = 0; i < selections.Count; i++) { BSVoxel voxel = dataSource.Read(selections[i].x, selections[i].y, selections[i].z); new_voxels.Add(new BSVoxel()); old_voxels.Add(voxel); } BSAction action = new BSAction(); BSVoxelModify vm = new BSVoxelModify(selections.ToArray(), old_voxels.ToArray(), new_voxels.ToArray(), dataSource, EBSBrushMode.Subtract); action.AddModify(vm); vm.Redo(); BSHistory.AddAction(action); ResetDrawing(); }
protected void ExtrudeSelection(int x, int y, int z) { if (x == 0 && y == 0 && z == 0) { return; } if (m_PrevDS != dataSource) { return; } _extruding = true; Dictionary <IntVector3, byte> new_selection = new Dictionary <IntVector3, byte>(); //BSVoxelModify modify = new BSVoxelModify( List <IntVector3> indexes = new List <IntVector3>(); List <BSVoxel> old_voxels = new List <BSVoxel>(); List <BSVoxel> new_voxels = new List <BSVoxel>(); Dictionary <IntVector3, int> refVoxelMap = new Dictionary <IntVector3, int>(); foreach (KeyValuePair <IntVector3, byte> kvp in m_Selections) { IntVector3 ipos = new IntVector3(kvp.Key); ipos.x += x; ipos.y += y; ipos.z += z; BSVoxel new_voxel = dataSource.SafeRead(kvp.Key.x, kvp.Key.y, kvp.Key.z); BSVoxel old_voxel = dataSource.SafeRead(ipos.x, ipos.y, ipos.z); indexes.Add(ipos); old_voxels.Add(old_voxel); new_voxels.Add(new_voxel); new_selection.Add(ipos, kvp.Value); refVoxelMap.Add(ipos, 0); } // Extra Extendable FindExtraExtendableVoxels(dataSource, new_voxels, old_voxels, indexes, refVoxelMap); BSVoxelModify modify = new BSVoxelModify(indexes.ToArray(), old_voxels.ToArray(), new_voxels.ToArray(), dataSource, EBSBrushMode.Add); m_Action.AddModify(modify); modify.Redo(); Dictionary <IntVector3, byte> old_selection = new Dictionary <IntVector3, byte>(m_Selections); BSSelectedBoxModify sm = new BSSelectedBoxModify(old_selection, new_selection, this); m_Action.AddModify(sm); sm.Redo(); }
public void DeleteVoxel() { if (m_SelectionBoxes.Count == 0) { return; } List <BSVoxel> new_voxels = new List <BSVoxel>(); List <IntVector3> indexes = new List <IntVector3>(); List <BSVoxel> old_voxels = new List <BSVoxel>(); foreach (BSTools.SelBox box in m_SelectionBoxes) { for (int x = box.m_Box.xMin; x <= box.m_Box.xMax; x++) { for (int y = box.m_Box.yMin; y <= box.m_Box.yMax; y++) { for (int z = box.m_Box.zMin; z <= box.m_Box.zMax; z++) { BSVoxel voxel = dataSource.Read(x, y, z); new_voxels.Add(new BSVoxel()); indexes.Add(new IntVector3(x, y, z)); old_voxels.Add(voxel); } } } } // Select modify ClearSelection(m_Action); // Modity modify if (indexes.Count != 0) { BSVoxelModify vm = new BSVoxelModify(indexes.ToArray(), old_voxels.ToArray(), new_voxels.ToArray(), dataSource, EBSBrushMode.Subtract); m_Action.AddModify(vm); vm.Redo(); } }
protected override void Do() { Vector3 min = Min; // Vector3 max = Max; Vector3 size = Size; List <BSVoxel> new_voxels = new List <BSVoxel>(); List <IntVector3> indexes = new List <IntVector3>(); List <BSVoxel> old_voxels = new List <BSVoxel>(); Dictionary <IntVector3, int> refVoxelMap = new Dictionary <IntVector3, int>(); // x positive direction if (m_Rot == 0) { IntVector3 isize = CorrectSizeXY(size); int xMin = Mathf.FloorToInt(min.x * BSBlock45Data.s_ScaleInverted); int xMax = xMin + isize.x; int zMin = Mathf.FloorToInt(min.z * BSBlock45Data.s_ScaleInverted); int zMax = zMin + isize.z; int yMin = Mathf.FloorToInt(min.y * BSBlock45Data.s_ScaleInverted); int yMax = yMin + isize.y; if (xMax < xMin + 1 || yMax < yMin + 1 || zMax <= zMin) { return; } for (int z = zMin; z < zMax; z++) { IntVector3 up = new IntVector3(xMax, yMax, z); IntVector3 dn = new IntVector3(xMin, yMin, z); ApplyBevel2_10(up, dn, upVSeal, upBSeal, BuildingMan.Blocks, materialType, new_voxels, old_voxels, indexes, refVoxelMap); } } // z positive direction else if (m_Rot == 1) { IntVector3 isize = CorrectSizeZY(size); int xMin = Mathf.FloorToInt(min.x * BSBlock45Data.s_ScaleInverted); int xMax = xMin + isize.x; int zMin = Mathf.FloorToInt(min.z * BSBlock45Data.s_ScaleInverted); int zMax = zMin + isize.z; int yMin = Mathf.FloorToInt(min.y * BSBlock45Data.s_ScaleInverted); int yMax = yMin + isize.y; if ((xMax < xMin + 1 || yMax < yMin + 1 || zMax <= zMin)) { return; } for (int x = xMin; x < xMax; x++) { IntVector3 up = new IntVector3(x, yMax, zMax); IntVector3 dn = new IntVector3(x, yMin, zMin); ApplyBevel2_10(up, dn, upVSeal, upBSeal, BuildingMan.Blocks, materialType, new_voxels, old_voxels, indexes, refVoxelMap); } } // x negative direction else if (m_Rot == 2) { IntVector3 isize = CorrectSizeXY(size); int xMin = Mathf.FloorToInt(min.x * BSBlock45Data.s_ScaleInverted); int xMax = xMin + isize.x; int zMin = Mathf.FloorToInt(min.z * BSBlock45Data.s_ScaleInverted); int zMax = zMin + isize.z; int yMin = Mathf.FloorToInt(min.y * BSBlock45Data.s_ScaleInverted); int yMax = yMin + isize.y; if ((xMax < xMin + 1 || yMax < yMin + 1 || zMax <= zMin)) { return; } for (int z = zMin; z < zMax; z++) { IntVector3 up = new IntVector3(xMin, yMax, z); IntVector3 dn = new IntVector3(xMax, yMin, z); ApplyBevel2_10(up, dn, upVSeal, upBSeal, BuildingMan.Blocks, materialType, new_voxels, old_voxels, indexes, refVoxelMap); } } // z negative direction else if (m_Rot == 3) { IntVector3 isize = CorrectSizeZY(size); int xMin = Mathf.FloorToInt(min.x * BSBlock45Data.s_ScaleInverted); int xMax = xMin + isize.x; int zMin = Mathf.FloorToInt(min.z * BSBlock45Data.s_ScaleInverted); int zMax = zMin + isize.z; int yMin = Mathf.FloorToInt(min.y * BSBlock45Data.s_ScaleInverted); int yMax = yMin + isize.y; if ((xMax < xMin + 1 || yMax < yMin + 1 || zMax <= zMin)) { return; } for (int x = xMin; x < xMax; x++) { IntVector3 up = new IntVector3(x, yMax, zMin); IntVector3 dn = new IntVector3(x, yMin, zMax); ApplyBevel2_10(up, dn, upVSeal, upBSeal, BuildingMan.Blocks, materialType, new_voxels, old_voxels, indexes, refVoxelMap); } } // Extra Extendable FindExtraExtendableVoxels(dataSource, new_voxels, old_voxels, indexes, refVoxelMap); // Action if (indexes.Count != 0) { BSAction action = new BSAction(); BSVoxelModify modify = new BSVoxelModify(indexes.ToArray(), old_voxels.ToArray(), new_voxels.ToArray(), dataSource, EBSBrushMode.Add); action.AddModify(modify); if (action.Do()) { BSHistory.AddAction(action); } } }
protected override void Do() { if (gizmoTrigger.RayCast) { return; } Vector3 min = Min * dataSource.ScaleInverted; Vector3 max = Max * dataSource.ScaleInverted; int cnt = pattern.size; Vector3 center = new Vector3((cnt - 1) / 2.0f, 0, (cnt - 1) / 2.0f); if (mode == EBSBrushMode.Add) { List <BSVoxel> new_voxels = new List <BSVoxel>(); List <IntVector3> indexes = new List <IntVector3>(); List <BSVoxel> old_voxels = new List <BSVoxel>(); Dictionary <IntVector3, int> refVoxelMap = new Dictionary <IntVector3, int>(); for (int x = (int)min.x; x < (int)max.x; x += cnt) { for (int y = (int)min.y; y < (int)max.y; y += cnt) { for (int z = (int)min.z; z < (int)max.z; z += cnt) { for (int ix = 0; ix < cnt; ix++) { for (int iy = 0; iy < cnt; iy++) { for (int iz = 0; iz < cnt; iz++) { // rote if need Vector3 offset = Quaternion.Euler(0, 90 * m_Rot, 0) * new Vector3(ix - center.x, iy - center.y, iz - center.z) + center; IntVector3 inpos = new IntVector3(Mathf.FloorToInt(x) + offset.x, Mathf.FloorToInt(y) + offset.y, Mathf.FloorToInt(z) + offset.z); // new voxel BSVoxel voxel = pattern.voxelList[ix, iy, iz]; voxel.materialType = materialType; voxel.blockType = BSVoxel.MakeBlockType(voxel.blockType >> 2, ((voxel.blockType & 0X3) + m_Rot) % 4); //olde voxel BSVoxel old_voxel = dataSource.SafeRead(inpos.x, inpos.y, inpos.z); new_voxels.Add(voxel); old_voxels.Add(old_voxel); indexes.Add(inpos); refVoxelMap.Add(inpos, 0); } } } } } } // Extra Extendable FindExtraExtendableVoxels(dataSource, new_voxels, old_voxels, indexes, refVoxelMap); // new Modify ? if (indexes.Count != 0) { BSAction action = new BSAction(); BSVoxelModify modify = new BSVoxelModify(indexes.ToArray(), old_voxels.ToArray(), new_voxels.ToArray(), dataSource, mode); action.AddModify(modify); if (action.Do()) { BSHistory.AddAction(action); } } } else if (mode == EBSBrushMode.Subtract) { List <BSVoxel> new_voxels = new List <BSVoxel>(); List <IntVector3> indexes = new List <IntVector3>(); List <BSVoxel> old_voxels = new List <BSVoxel>(); Dictionary <IntVector3, int> refVoxelMap = new Dictionary <IntVector3, int>(); for (int x = (int)min.x; x < (int)max.x; x += cnt) { for (int y = (int)min.y; y < (int)max.y; y += cnt) { for (int z = (int)min.z; z < (int)max.z; z += cnt) { for (int ix = 0; ix < cnt; ix++) { for (int iy = 0; iy < cnt; iy++) { for (int iz = 0; iz < cnt; iz++) { IntVector3 inpos = new IntVector3(Mathf.FloorToInt(x) + ix, Mathf.FloorToInt(y) + iy, Mathf.FloorToInt(z) + iz); BSVoxel voxel = dataSource.Read(inpos.x, inpos.y, inpos.z); new_voxels.Add(new BSVoxel()); indexes.Add(inpos); old_voxels.Add(voxel); refVoxelMap[inpos] = 0; // extendtable List <IntVector4> ext_posList = null; List <BSVoxel> ext_voxels = null; if (dataSource.ReadExtendableBlock(new IntVector4(inpos, 0), out ext_posList, out ext_voxels)) { for (int i = 0; i < ext_voxels.Count; i++) { IntVector3 _ipos = new IntVector3(ext_posList[i].x, ext_posList[i].y, ext_posList[i].z); if (_ipos == inpos) { continue; } if (!refVoxelMap.ContainsKey(_ipos)) { BSVoxel v = dataSource.Read(_ipos.x, _ipos.y, _ipos.z); old_voxels.Add(v); indexes.Add(_ipos); new_voxels.Add(new BSVoxel()); refVoxelMap.Add(_ipos, 0); } } } } } } } } } // Extra Extendable FindExtraExtendableVoxels(dataSource, new_voxels, old_voxels, indexes, refVoxelMap); // Action if (indexes.Count != 0) { BSAction action = new BSAction(); BSVoxelModify modify = new BSVoxelModify(indexes.ToArray(), old_voxels.ToArray(), new_voxels.ToArray(), dataSource, mode); action.AddModify(modify); if (action.Do()) { BSHistory.AddAction(action); } } } }
void Update() { if (GameConfig.IsInVCE) { return; } if (Input.GetKeyDown(KeyCode.O)) { Gen = true; } if (Gen) { if (m_Cursor != null) { Destroy(m_Cursor.gameObject); } m_Cursor = BIsoCursor.CreateIsoCursor(GameConfig.GetUserDataPath() + BSSaveIsoBrush.s_IsoPath + File_Name + BSSaveIsoBrush.s_Ext); m_Rot = 0; Gen = false; } if (m_Cursor == null) { return; } if (BSInput.s_Cancel) { Cancel(); if (onCancelClick != null) { onCancelClick(); } return; } if (m_Cursor != null) { m_Cursor.gameObject.SetActive(true); } if (m_Cursor.ISO.m_HeadInfo.Mode == EBSVoxelType.Block) { if (BSMath.RayCastDrawTarget(BSInput.s_PickRay, BuildingMan.Blocks, out m_Target, BSMath.MC_ISO_VALUE, true, BuildingMan.Datas)) { m_Cursor.gameObject.SetActive(true); Vector3 offset = Vector3.zero; offset.x = (m_Cursor.ISO.m_HeadInfo.xSize) / 2 * BSBlock45Data.s_Scale; offset.z = (m_Cursor.ISO.m_HeadInfo.zSize) / 2 * BSBlock45Data.s_Scale; if (Input.GetKeyDown(KeyCode.T)) { m_Rot = ++m_Rot > 3 ? 0 : m_Rot; } m_Cursor.SetOriginOffset(-offset); m_Cursor.transform.rotation = Quaternion.Euler(0, 90 * m_Rot, 0); // Adjust Offset FocusAjust(); m_Cursor.transform.position = m_Target.cursor + m_FocusOffset * BSBlock45Data.s_Scale; if (Input.GetMouseButtonDown(0)) { if (BSInput.s_MouseOnUI) { return; } if (m_Cursor.gizmoTrigger.RayCast) { return; } // For History m_OldVoxel.Clear(); m_NewVoxel.Clear(); m_Indexes.Clear(); m_VoxelMap.Clear(); m_Cursor.OutputVoxels(Vector3.zero, OnOutputBlocks); // Extra Extendable FindExtraExtendableVoxels(dataSource, m_NewVoxel, m_OldVoxel, m_Indexes, m_VoxelMap); // For History BSAction action = new BSAction(); BSVoxelModify modify = new BSVoxelModify(m_Indexes.ToArray(), m_OldVoxel.ToArray(), m_NewVoxel.ToArray(), BuildingMan.Blocks, EBSBrushMode.Add); if (!modify.IsNull()) { action.AddModify(modify); } if (action.Do()) { BSHistory.AddAction(action); if (onBrushDo != null) { onBrushDo(); } } } } else { m_Cursor.gameObject.SetActive(false); } } else if (m_Cursor.ISO.m_HeadInfo.Mode == EBSVoxelType.Block) { if (BSMath.RayCastDrawTarget(BSInput.s_PickRay, BuildingMan.Voxels, out m_Target, 1, true, BuildingMan.Datas)) { m_Cursor.gameObject.SetActive(false); Debug.Log("Draw building Iso dont support the voxel"); return; } else { m_Cursor.gameObject.SetActive(false); } } }
protected override void Do() { int cnt = pattern.size; Vector3 center = new Vector3((cnt - 1) / 2.0f, 0, (cnt - 1) / 2.0f); if (mode == EBSBrushMode.Add) { List <BSVoxel> new_voxels = new List <BSVoxel>(); List <IntVector3> indexes = new List <IntVector3>(); List <BSVoxel> old_voxels = new List <BSVoxel>(); for (int x = 0; x < cnt; x++) { for (int y = 0; y < cnt; y++) { for (int z = 0; z < cnt; z++) { // rote if need Vector3 offset = Quaternion.Euler(0, 90 * m_Rot, 0) * new Vector3(x - center.x, y - center.y, z - center.z) + center; IntVector3 inpos = new IntVector3(Mathf.FloorToInt(m_Cursor.x * dataSource.ScaleInverted) + offset.x, Mathf.FloorToInt(m_Cursor.y * dataSource.ScaleInverted) + offset.y, Mathf.FloorToInt(m_Cursor.z * dataSource.ScaleInverted) + offset.z); // new voxel BSVoxel voxel = pattern.voxelList[x, y, z]; voxel.materialType = materialType; voxel.blockType = BSVoxel.MakeBlockType(voxel.blockType >> 2, ((voxel.blockType & 0X3) + m_Rot) % 4); //olde voxel BSVoxel old_voxel = dataSource.SafeRead(inpos.x, inpos.y, inpos.z); new_voxels.Add(voxel); old_voxels.Add(old_voxel); indexes.Add(inpos); } } } // Modify if (indexes.Count != 0) { BSAction action = new BSAction(); BSVoxelModify modify = new BSVoxelModify(indexes.ToArray(), old_voxels.ToArray(), new_voxels.ToArray(), dataSource, mode); action.AddModify(modify); if (action.Do()) { BSHistory.AddAction(action); } } } else if (mode == EBSBrushMode.Subtract) { List <BSVoxel> new_voxels = new List <BSVoxel>(); List <IntVector3> indexes = new List <IntVector3>(); List <BSVoxel> old_voxels = new List <BSVoxel>(); for (int x = 0; x < cnt; x++) { for (int y = 0; y < cnt; y++) { for (int z = 0; z < cnt; z++) { IntVector3 inpos = new IntVector3(Mathf.FloorToInt(m_Cursor.x * dataSource.ScaleInverted) + x, Mathf.FloorToInt(m_Cursor.y * dataSource.ScaleInverted) + y, Mathf.FloorToInt(m_Cursor.z * dataSource.ScaleInverted) + z); BSVoxel voxel = dataSource.Read(inpos.x, inpos.y, inpos.z); new_voxels.Add(new BSVoxel()); indexes.Add(inpos); old_voxels.Add(voxel); } } } // Action if (indexes.Count != 0) { BSAction action = new BSAction(); BSVoxelModify modify = new BSVoxelModify(indexes.ToArray(), old_voxels.ToArray(), new_voxels.ToArray(), dataSource, mode); action.AddModify(modify); if (action.Do()) { BSHistory.AddAction(action); } } } }