public VoxelStruct[] doIt() { VoxelStruct[] vs = new VoxelStruct[list_.Count]; for (int i = 0; i < vs.Length; ++i) { vs [i] = new VoxelStruct(); } for (int i = 0; i < vs_.count; ++i) { var data = vs_.getData(i); for (int j = 0; j < vs.Length; ++j) { if (list_ [j].contain(data.position)) { vs [j].addData(data); } /*//vs[j]*/ } } //for (int i = 0; i < vs.Length; ++i) { // vs [i].arrange(true); // } return(vs); }
private static Point[] WritePoints(VoxelStruct vs, Vector4Int[] palette) { Point[] points = new Point[vs.count]; for (int i = 0; i < vs.count; ++i) { var data = vs.getData(i); points[i] = new Point(); points[i].x = (byte)data.position.x; points[i].y = (byte)data.position.z; points[i].z = (byte)data.position.y; Color color = data.color; if (palette == null) { ushort s = Color2Short(color); for (int x = 0; x < palette_.Length; ++x) { if (palette_ [x] == s) { points [i].i = (byte)(x + 1); break; } } } else { Vector4Int v = Color2Bytes(color); for (int x = 0; x < palette.Length; ++x) { if (palette [x] == v) { points [i].i = (byte)(x + 1); break; } } } } return(points); }
private void arrange(VoxelStruct st, bool normal = false) { structure_ = st; HashSet <Color> palette = new HashSet <Color>(); Vector3Int min = new Vector3Int(9999, 9999, 9999); Vector3Int max = new Vector3Int(-9999, -9999, -9999); for (int i = 0; i < st.count; ++i) { palette.Add(st.getData(i).color); Vector3Int pos = st.getData(i).position; min.x = Mathf.Min(pos.x, min.x); min.y = Mathf.Min(pos.y, min.y); min.z = Mathf.Min(pos.z, min.z); max.x = Mathf.Max(pos.x, max.x); max.y = Mathf.Max(pos.y, max.y); max.z = Mathf.Max(pos.z, max.z); } if (normal) { max = max - min; for (int i = 0; i < st.count; ++i) { palette.Add(st.getData(i).color); var data = st.getData(i); data.position -= min; st.setData(i, data); //.pos = pos - min; } min = new Vector3Int(0, 0, 0); } this.main = new MagicaVoxel.Main(); this.main.name = "MAIN"; this.main.size = 0; this.size = new MagicaVoxel.Size(); this.size.name = "SIZE"; this.size.size = 12; this.size.chunks = 0; this.size.box = new Vector3Int(); this.size.box.x = max.x - min.x + 1; this.size.box.y = max.y - min.y + 1; this.size.box.z = max.z - min.z + 1; this.rgba = new MagicaVoxel.Rgba(); int size = Mathf.Max(palette.Count, 256); this.rgba.palette = new Vector4Int[size]; int n = 0; foreach (Color c in palette) { this.rgba.palette [n] = MagicaVoxelFormater.Color2Bytes(c); ++n; } this.rgba.size = this.rgba.palette.Length * 4; this.rgba.name = "RGBA"; this.rgba.chunks = 0; this.version = 150; this.main.chunks = 52 + this.rgba.palette.Length * 4 + st.count * 4; }