public override InputSimpleTiledModelData GetInputSimpleTiledData() { if (Application.isPlaying == false) { FillPrefabMap(); } var tileConfigsData = CreateTileConfigData(tilePrefab => { var symmetry = symmetrySets.GetSymmetryByTileName(tilePrefab.name); Debug.Log(tilePrefab.name + " " + symmetry); var config = new SimpleTiledModelTileConfig(tilePrefab, symmetry); return(config); }); var inputData = new InputSimpleTiledModelData(tileConfigsData); var tiles = new SimpleTiledModelTile[width, height, depth]; ExecuteForEachTile((tileGo, pos, rotation) => { tiles[(int)pos.x, (int)pos.y, (int)pos.z] = new SimpleTiledModelTile(tileConfigsData.GetConfig(tileGo.name), rotation); }); var neighbors = new Dictionary <string, NeighborData>(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { for (int z = 0; z < depth; z++) { var currentTile = tiles[x, y, z]; if (currentTile == null) { continue; } SimpleTiledModelTile nextTile; string key; for (var offset = 0; offset < 2; offset++) { var rx = x + 1 - offset; var rz = z + offset; if (rx >= width || rz >= depth) { continue; } var currentTileRotation = Card(currentTile.Rotation + offset); nextTile = tiles[rx, y, rz]; if (nextTile == null) { continue; } var nextTileRotation = Card(nextTile.Rotation + offset); key = currentTile.Config.Id + "." + currentTileRotation + " | " + nextTile.Config.Id + "." + nextTileRotation; if (neighbors.ContainsKey(key)) { continue; } Debug.Log(key); neighbors.Add(key, new NeighborData(currentTile.Config, nextTile.Config, currentTileRotation, nextTileRotation)); DrawDebugLine(new Vector3(x, y - 0.5f, z), new Vector3(rx, y - 0.5f, rz)); } if (y == 0) { continue; } nextTile = tiles[x, y - 1, z]; if (nextTile == null) { continue; } key = currentTile.Config.Id + "." + currentTile.Rotation + " | " + nextTile.Config.Id + "." + nextTile.Rotation + " |vertical"; if (neighbors.ContainsKey(key)) { continue; } Debug.Log(key); neighbors.Add(key, new NeighborData(currentTile.Config, nextTile.Config, currentTile.Rotation, nextTile.Rotation, false)); DrawDebugLine(new Vector3(x, y, z), new Vector3(x, y - 1, z)); } } } inputData.SetNeighbors(neighbors.Values.ToList()); return(inputData); }
public SimpleTiledMode3d(InputSimpleTiledModelData inputData, SimpleTiledModelParams modelParams) : base(modelParams) { this.periodic = modelParams.Periodic; this.black = modelParams.Black; tilesize = 1; List <string> subset = null; tiles = new List <SimpleTiledModelTile>(); tilenames = new List <string>(); var tempStationary = new List <double>(); List <int[]> action = new List <int[]>(); Dictionary <string, int> firstOccurrence = new Dictionary <string, int>(); foreach (var tileConfig in inputData.TileConfigData.ConfigsList) { if (subset != null && !subset.Contains(tileConfig.Id)) { continue; } Func <int, int> a, b; int cardinality; var sym = tileConfig.Symmetry; if (sym == SymmetryType.L) { cardinality = 4; a = i => (i + 1) % 4; b = i => i % 2 == 0 ? i + 1 : i - 1; } else if (sym == SymmetryType.T) { cardinality = 4; a = i => (i + 1) % 4; b = i => i % 2 == 0 ? i : 4 - i; } else if (sym == SymmetryType.I) { cardinality = 2; a = i => 1 - i; b = i => i; } else if (sym == SymmetryType.Slash) { cardinality = 2; a = i => 1 - i; b = i => 1 - i; } else { cardinality = 1; a = i => i; b = i => i; } T = action.Count; firstOccurrence.Add(tileConfig.Id, T); int[][] map = new int[cardinality][]; for (int t = 0; t < cardinality; t++) { map[t] = new int[8]; map[t][0] = t; map[t][1] = a(t); map[t][2] = a(a(t)); map[t][3] = a(a(a(t))); map[t][4] = b(t); map[t][5] = b(a(t)); map[t][6] = b(a(a(t))); map[t][7] = b(a(a(a(t)))); for (int s = 0; s < 8; s++) { map[t][s] += T; } action.Add(map[t]); } tiles.Add(new SimpleTiledModelTile(tileConfig, 0)); tilenames.Add(tileConfig.Id + " 0"); for (int t = 1; t < cardinality; t++) { //tiles.Add(rotate(tiles[T + t - 1])); //tilenames.Add($"{tilename} {t}"); tiles.Add(new SimpleTiledModelTile(tileConfig, t)); tilenames.Add(tileConfig.Id + " " + t); } for (int t = 0; t < cardinality; t++) { tempStationary.Add(tileConfig.Weight); } } T = action.Count; weights = tempStationary.ToArray(); propagator = new int[DIRECTIONS_AMOUNT][][]; var tempPropagator = new bool[DIRECTIONS_AMOUNT][][]; for (int d = 0; d < DIRECTIONS_AMOUNT; d++) { tempPropagator[d] = new bool[T][]; propagator[d] = new int[T][]; for (int t = 0; t < T; t++) { tempPropagator[d][t] = new bool[T]; } } foreach (NeighborData neighborData in inputData.NeighborDatas) { var leftNeighbor = neighborData.LeftNeighborConfig.Id; var rightNeighbor = neighborData.RightNeighborConfig.Id; if (subset != null && (!subset.Contains(leftNeighbor) || !subset.Contains(rightNeighbor))) { continue; } int L = action[firstOccurrence[leftNeighbor]][neighborData.LeftRotation], D = action[L][1]; int R = action[firstOccurrence[rightNeighbor]][neighborData.RightRotation], U = action[R][1]; if (neighborData.Horizontal) { tempPropagator[0][R][L] = true; tempPropagator[0][action[R][6]][action[L][6]] = true; tempPropagator[0][action[L][4]][action[R][4]] = true; tempPropagator[0][action[L][2]][action[R][2]] = true; tempPropagator[1][U][D] = true; tempPropagator[1][action[D][6]][action[U][6]] = true; tempPropagator[1][action[U][4]][action[D][4]] = true; tempPropagator[1][action[D][2]][action[U][2]] = true; } else { // for vertical neighbours for (int g = 0; g < 8; g++) { tempPropagator[4][action[L][g]][action[R][g]] = true; } } } for (int t2 = 0; t2 < T; t2++) { for (int t1 = 0; t1 < T; t1++) { tempPropagator[2][t2][t1] = tempPropagator[0][t1][t2]; tempPropagator[3][t2][t1] = tempPropagator[1][t1][t2]; tempPropagator[5][t2][t1] = tempPropagator[4][t1][t2]; } } List <int>[][] sparsePropagator = new List <int> [DIRECTIONS_AMOUNT][]; for (int d = 0; d < DIRECTIONS_AMOUNT; d++) { sparsePropagator[d] = new List <int> [T]; for (int t = 0; t < T; t++) { sparsePropagator[d][t] = new List <int>(); } } for (int d = 0; d < DIRECTIONS_AMOUNT; d++) { for (int t1 = 0; t1 < T; t1++) { List <int> sp = sparsePropagator[d][t1]; bool[] tp = tempPropagator[d][t1]; for (int t2 = 0; t2 < T; t2++) { if (tp[t2]) { sp.Add(t2); } } int ST = sp.Count; propagator[d][t1] = new int[ST]; for (int st = 0; st < ST; st++) { propagator[d][t1][st] = sp[st]; } } } }
public NewSimpleTiledModel(InputSimpleTiledModelData inputData, SimpleTiledModelParams modelParams) : base(modelParams) { this.periodic = modelParams.Periodic; this.black = modelParams.Black; tilesize = 1; List <string> subset = null; /* * if (subsetName != default(string)) * { * XElement xsubset = xroot.Element("subsets").Elements("subset").FirstOrDefault(x => x.Get<string>("name") == subsetName); * if (xsubset == null) Console.WriteLine($"ERROR: subset {subsetName} is not found"); * else subset = xsubset.Elements("tile").Select(x => x.Get<string>("name")).ToList(); * } * * * Color[] tile (Func<int, int, Color> f) * { * Color[] result = new Color[tilesize * tilesize]; * for (int y = 0; y < tilesize; y++) * for (int x = 0; x < tilesize; x++) result[x + y * tilesize] = f(x, y); * return result; * }; * * Color[] rotate(Color[] array) => tile((x, y) => array[tilesize - 1 - y + x * tilesize]); */ tiles = new List <SimpleTiledModelTile>(); tilenames = new List <string>(); var tempStationary = new List <double>(); List <int[]> action = new List <int[]>(); Dictionary <string, int> firstOccurrence = new Dictionary <string, int>(); foreach (var tileConfig in inputData.TileConfigData.ConfigsList) { if (subset != null && !subset.Contains(tileConfig.Id)) { continue; } Func <int, int> a, b; int cardinality; var sym = tileConfig.Symmetry; if (sym == SymmetryType.L) { cardinality = 4; a = i => (i + 1) % 4; b = i => i % 2 == 0 ? i + 1 : i - 1; } else if (sym == SymmetryType.T) { cardinality = 4; a = i => (i + 1) % 4; b = i => i % 2 == 0 ? i : 4 - i; } else if (sym == SymmetryType.I) { cardinality = 2; a = i => 1 - i; b = i => i; } else if (sym == SymmetryType.Slash) { cardinality = 2; a = i => 1 - i; b = i => 1 - i; } else { cardinality = 1; a = i => i; b = i => i; } T = action.Count; firstOccurrence.Add(tileConfig.Id, T); int[][] map = new int[cardinality][]; for (int t = 0; t < cardinality; t++) { map[t] = new int[8]; map[t][0] = t; map[t][1] = a(t); map[t][2] = a(a(t)); map[t][3] = a(a(a(t))); map[t][4] = b(t); map[t][5] = b(a(t)); map[t][6] = b(a(a(t))); map[t][7] = b(a(a(a(t)))); for (int s = 0; s < 8; s++) { map[t][s] += T; } action.Add(map[t]); } tiles.Add(new SimpleTiledModelTile(tileConfig, 0)); tilenames.Add(tileConfig.Id + " 0"); for (int t = 1; t < cardinality; t++) { //tiles.Add(rotate(tiles[T + t - 1])); //tilenames.Add($"{tilename} {t}"); tiles.Add(new SimpleTiledModelTile(tileConfig, t)); tilenames.Add(tileConfig.Id + " " + t); } for (int t = 0; t < cardinality; t++) { tempStationary.Add(tileConfig.Weight); } } T = action.Count; weights = tempStationary.ToArray(); propagator = new int[4][][]; var tempPropagator = new bool[4][][]; for (int d = 0; d < 4; d++) { tempPropagator[d] = new bool[T][]; propagator[d] = new int[T][]; for (int t = 0; t < T; t++) { tempPropagator[d][t] = new bool[T]; } } foreach (NeighborData neighborData in inputData.NeighborDatas) { var leftNeighbor = neighborData.LeftNeighborConfig.Id; var rightNeighbor = neighborData.RightNeighborConfig.Id; if (subset != null && (!subset.Contains(leftNeighbor) || !subset.Contains(rightNeighbor))) { continue; } int L = action[firstOccurrence[leftNeighbor]][neighborData.LeftRotation], D = action[L][1]; int R = action[firstOccurrence[rightNeighbor]][neighborData.RightRotation], U = action[R][1]; tempPropagator[0][R][L] = true; tempPropagator[0][action[R][6]][action[L][6]] = true; tempPropagator[0][action[L][4]][action[R][4]] = true; tempPropagator[0][action[L][2]][action[R][2]] = true; tempPropagator[1][U][D] = true; tempPropagator[1][action[D][6]][action[U][6]] = true; tempPropagator[1][action[U][4]][action[D][4]] = true; tempPropagator[1][action[D][2]][action[U][2]] = true; } for (int t2 = 0; t2 < T; t2++) { for (int t1 = 0; t1 < T; t1++) { tempPropagator[2][t2][t1] = tempPropagator[0][t1][t2]; tempPropagator[3][t2][t1] = tempPropagator[1][t1][t2]; } } List <int>[][] sparsePropagator = new List <int> [4][]; for (int d = 0; d < 4; d++) { sparsePropagator[d] = new List <int> [T]; for (int t = 0; t < T; t++) { sparsePropagator[d][t] = new List <int>(); } } for (int d = 0; d < 4; d++) { for (int t1 = 0; t1 < T; t1++) { List <int> sp = sparsePropagator[d][t1]; bool[] tp = tempPropagator[d][t1]; for (int t2 = 0; t2 < T; t2++) { if (tp[t2]) { sp.Add(t2); } } int ST = sp.Count; propagator[d][t1] = new int[ST]; for (int st = 0; st < ST; st++) { propagator[d][t1][st] = sp[st]; } } } }
public SimpleTiledModel(InputSimpleTiledModelData inputData, SimpleTiledModelParams modelParams) : base(modelParams) { periodic = modelParams.Periodic; var subset = inputData.GetSubset(modelParams.SubsetName); tiles = new List <SimpleTiledModelTile>(); tilenames = new List <string>(); var tempStationary = new List <double>(); List <int[]> action = new List <int[]>(); Dictionary <string, int> firstOccurrence = new Dictionary <string, int>(); foreach (var tileConfig in inputData.TileConfigData.ConfigsList) { if (subset != null && !subset.Contains(tileConfig.Id)) { continue; } Func <int, int> rotationTranfrom, mirrorTranform; int cardinality; var symmmetry = tileConfig.Symmetry; Debug.Log(symmmetry); switch (symmmetry) { case SymmetryType.L: cardinality = 4; rotationTranfrom = i => (i + 1) % 4; mirrorTranform = i => i % 2 == 0 ? i + 1 : i - 1; break; case SymmetryType.T: cardinality = 4; rotationTranfrom = i => (i + 1) % 4; mirrorTranform = i => i % 2 == 0 ? i : 4 - i; break; case SymmetryType.I: cardinality = 2; rotationTranfrom = i => 1 - i; mirrorTranform = i => i; break; case SymmetryType.Slash: cardinality = 2; rotationTranfrom = i => 1 - i; mirrorTranform = i => 1 - i; break; default: cardinality = 1; rotationTranfrom = i => i; mirrorTranform = i => i; break; } T = action.Count; firstOccurrence.Add(tileConfig.Id, T); int[][] map = new int[cardinality][]; for (int t = 0; t < cardinality; t++) { map[t] = new int[8]; map[t][0] = t; map[t][1] = rotationTranfrom(t); map[t][2] = rotationTranfrom(rotationTranfrom(t)); map[t][3] = rotationTranfrom(rotationTranfrom(rotationTranfrom(t))); map[t][4] = mirrorTranform(t); map[t][5] = mirrorTranform(rotationTranfrom(t)); map[t][6] = mirrorTranform(rotationTranfrom(rotationTranfrom(t))); map[t][7] = mirrorTranform(rotationTranfrom(rotationTranfrom(rotationTranfrom(t)))); for (int s = 0; s < 8; s++) { map[t][s] += T; } action.Add(map[t]); } for (int t = 0; t < cardinality; t++) { tiles.Add(new SimpleTiledModelTile(tileConfig, t)); tilenames.Add(tileConfig.Id + " " + t); Debug.Log(tilenames.Count + " >>>> " + tilenames[tilenames.Count - 1]); tempStationary.Add(tileConfig.Weight); } } T = action.Count; stationary = tempStationary.ToArray(); var tempPropagator = new bool[4][][]; propagator = new int[4][][]; for (int d = 0; d < 4; d++) { tempPropagator[d] = new bool[T][]; propagator[d] = new int[T][]; for (int t = 0; t < T; t++) { tempPropagator[d][t] = new bool[T]; } } InitWave(); foreach (NeighborData neighbor in inputData.NeighborDatas) { var leftNeighbor = neighbor.LeftNeighborConfig.Id; var rightNeighbor = neighbor.RightNeighborConfig.Id; if (subset != null && (!subset.Contains(leftNeighbor) || !subset.Contains(rightNeighbor))) { continue; } var leftRotation = neighbor.LeftRotation; var rightRotation = neighbor.RightRotation; int L = action[firstOccurrence[leftNeighbor]][leftRotation], D = action[L][1]; int R = action[firstOccurrence[rightNeighbor]][rightRotation], U = action[R][1]; tempPropagator[0][R][L] = true; tempPropagator[0][action[R][6]][action[L][6]] = true; tempPropagator[0][action[L][4]][action[R][4]] = true; tempPropagator[0][action[L][2]][action[R][2]] = true; tempPropagator[1][U][D] = true; tempPropagator[1][action[D][6]][action[U][6]] = true; tempPropagator[1][action[U][4]][action[D][4]] = true; tempPropagator[1][action[D][2]][action[U][2]] = true; } for (int t2 = 0; t2 < T; t2++) { for (int t1 = 0; t1 < T; t1++) { tempPropagator[2][t2][t1] = tempPropagator[0][t1][t2]; tempPropagator[3][t2][t1] = tempPropagator[1][t1][t2]; } } List <int>[][] sparsePropagator = new List <int> [4][]; for (int d = 0; d < 4; d++) { sparsePropagator[d] = new List <int> [T]; for (int t = 0; t < T; t++) { sparsePropagator[d][t] = new List <int>(); } } for (var d = 0; d < 4; d++) { for (var t1 = 0; t1 < T; t1++) { List <int> sp = sparsePropagator[d][t1]; bool[] tp = tempPropagator[d][t1]; for (int t2 = 0; t2 < T; t2++) { if (tp[t2]) { sp.Add(t2); } } int ST = sp.Count; propagator[d][t1] = new int[ST]; for (int st = 0; st < ST; st++) { propagator[d][t1][st] = sp[st]; } } } }