public BSPattern(SqliteDataReader reader) { ID = Convert.ToInt32(reader.GetString(reader.GetOrdinal("ID"))); size = Convert.ToInt32(reader.GetString(reader.GetOrdinal("Size"))); IconName = reader.GetString(reader.GetOrdinal("IconName")); MeshPath = reader.GetString(reader.GetOrdinal("MeshPath")); voxelList = new BSVoxel[size, size, size]; type = EBSVoxelType.Block; string blockString = reader.GetString(reader.GetOrdinal("Blocks")); string[] _blockList = blockString.Split(';'); int count = 0; for (int y = 0; y < size; y++) { for (int z = 0; z < size; z++) { for (int x = 0; x < size; x++) { string[] valueList = _blockList[count].Split(','); if (type == EBSVoxelType.Block) { voxelList[x, y, z] = new BSVoxel(BSVoxel.MakeBlockType(Convert.ToInt32(valueList[0]), Convert.ToInt32(valueList[1])), 0); } else if (type == EBSVoxelType.Voxel) { voxelList[x, y, z] = new BSVoxel(255, 2); } count++; } } } }
void CreatTerrian() { BSVoxel voxel = new BSVoxel(); voxel.blockType = BSVoxel.MakeBlockType(1, 0); if (BSBlockMatMap.s_ItemToMat.ContainsKey(281)) { voxel.materialType = (byte)BSBlockMatMap.s_ItemToMat[281]; } else { voxel.materialType = 0; } for (int i = 9; i <= 14; i++) { Vector3 pos1 = new Vector3(10f, 2f, i); pos1 = new Vector3(pos1.x * BuildingMan.Blocks.ScaleInverted, pos1.y * BuildingMan.Blocks.ScaleInverted, pos1.z * BuildingMan.Blocks.ScaleInverted); BuildingMan.Blocks.SafeWrite(voxel, (int)pos1.x, (int)pos1.y, (int)pos1.z); Vector3 pos2 = new Vector3(10f, 2f, i + 0.5f); pos2 = new Vector3(pos2.x * BuildingMan.Blocks.ScaleInverted, pos2.y * BuildingMan.Blocks.ScaleInverted, pos2.z * BuildingMan.Blocks.ScaleInverted); BuildingMan.Blocks.SafeWrite(voxel, (int)pos2.x, (int)pos2.y, (int)pos2.z); Vector3 pos3 = new Vector3(10f, 1.5f, i); pos3 = new Vector3(pos3.x * BuildingMan.Blocks.ScaleInverted, pos3.y * BuildingMan.Blocks.ScaleInverted, pos3.z * BuildingMan.Blocks.ScaleInverted); BuildingMan.Blocks.SafeWrite(voxel, (int)pos3.x, (int)pos3.y, (int)pos3.z); Vector3 pos4 = new Vector3(10f, 1.5f, i + 0.5f); pos4 = new Vector3(pos4.x * BuildingMan.Blocks.ScaleInverted, pos4.y * BuildingMan.Blocks.ScaleInverted, pos4.z * BuildingMan.Blocks.ScaleInverted); BuildingMan.Blocks.SafeWrite(voxel, (int)pos4.x, (int)pos4.y, (int)pos4.z); } }
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); } } } }
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); } } } }