diagonales en un map en mosaico

Tengo un map de fichas que se dibuja con dos triangularjs. Dibujé mi map usando un map de altura para generar vértices y hacer una celda (mosaico) de 4 vértices, así:

cells[x][z] = new Cell(corner1, corner2, corner3, corner4, colour1, colour2, colour3, colour4); 

Ahora lo quiero de modo que si 3 esquinas coinciden en color, digamos azul, y el otro 4 es verde, entonces debería tener un triángulo azul y el otro verde.

Ahora mi lógica para esto es la siguiente:

 // triangle 1 VertexInfo v1 = new VertexInfo(); VertexInfo v2 = new VertexInfo(); VertexInfo v3 = new VertexInfo(); // triangle 2 VertexInfo v4 = new VertexInfo(); VertexInfo v5 = new VertexInfo(); VertexInfo v6 = new VertexInfo(); for (Cell[] cellrow : chunks[c].cells) { for (Cell cell : cellrow) { if (cell.getColor1().equals(cell.getColor4()) && cell.getColor1().equals(cell.getColor2()) && cell.getColor2().equals(cell.getColor4()) && !cell.getColor1().equals(cell.getColor3())) { /* 4\ * | \ * 1--\2 */ v1.setPos(cell.getCorner3()).setNor(cell.getLeftNormal()).setCol(cell.getColor3()).setUV(cell.getTexturePos()); v2.setPos(cell.getCorner2()).setNor(cell.getLeftNormal()).setCol(cell.getColor3()).setUV(cell.getTexturePos()); v3.setPos(cell.getCorner4()).setNor(cell.getLeftNormal()).setCol(cell.getColor3()).setUV(cell.getTexturePos()); v4.setPos(cell.getCorner1()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos()); v5.setPos(cell.getCorner4()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos()); v6.setPos(cell.getCorner2()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos()); meshBuilder.triangle(v1, v2, v3); meshBuilder.triangle(v4, v5, v6); } else if (cell.getColor2().equals(cell.getColor1()) && cell.getColor2().equals(cell.getColor3()) && cell.getColor3().equals(cell.getColor1()) && !cell.getColor2().equals(cell.getColor4())) { /* /3 * / | * 1/--2 */ v1.setPos(cell.getCorner1()).setNor(cell.getLeftNormal()).setCol(cell.getColor2()).setUV(cell.getTexturePos()); v2.setPos(cell.getCorner3()).setNor(cell.getLeftNormal()).setCol(cell.getColor2()).setUV(cell.getTexturePos()); v3.setPos(cell.getCorner2()).setNor(cell.getLeftNormal()).setCol(cell.getColor2()).setUV(cell.getTexturePos()); v4.setPos(cell.getCorner3()).setNor(cell.getRightNormal()).setCol(cell.getColor4()).setUV(cell.getTexturePos()); v5.setPos(cell.getCorner1()).setNor(cell.getRightNormal()).setCol(cell.getColor4()).setUV(cell.getTexturePos()); v6.setPos(cell.getCorner4()).setNor(cell.getRightNormal()).setCol(cell.getColor4()).setUV(cell.getTexturePos()); meshBuilder.triangle(v1, v2, v3); meshBuilder.triangle(v4, v5, v6); } else if (cell.getColor3().equals(cell.getColor4()) && cell.getColor3().equals(cell.getColor2()) && cell.getColor2().equals(cell.getColor4()) && !cell.getColor3().equals(cell.getColor1())) { /* 4\--3 * \ | * \2 */ v1.setPos(cell.getCorner3()).setNor(cell.getLeftNormal()).setCol(cell.getColor3()).setUV(cell.getTexturePos()); v2.setPos(cell.getCorner2()).setNor(cell.getLeftNormal()).setCol(cell.getColor3()).setUV(cell.getTexturePos()); v3.setPos(cell.getCorner4()).setNor(cell.getLeftNormal()).setCol(cell.getColor3()).setUV(cell.getTexturePos()); v4.setPos(cell.getCorner1()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos()); v5.setPos(cell.getCorner4()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos()); v6.setPos(cell.getCorner2()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos()); meshBuilder.triangle(v1, v2, v3); meshBuilder.triangle(v4, v5, v6); }else if (cell.getColor4().equals(cell.getColor1()) && cell.getColor4().equals(cell.getColor3()) && cell.getColor3().equals(cell.getColor1()) && !cell.getColor4().equals(cell.getColor2())) { /* 4--/3 * | / * 1/ */ v1.setPos(cell.getCorner1()).setNor(cell.getLeftNormal()).setCol(cell.getColor2()).setUV(cell.getTexturePos()); v2.setPos(cell.getCorner3()).setNor(cell.getLeftNormal()).setCol(cell.getColor2()).setUV(cell.getTexturePos()); v3.setPos(cell.getCorner2()).setNor(cell.getLeftNormal()).setCol(cell.getColor2()).setUV(cell.getTexturePos()); v4.setPos(cell.getCorner4()).setNor(cell.getRightNormal()).setCol(cell.getColor4()).setUV(cell.getTexturePos()); v5.setPos(cell.getCorner3()).setNor(cell.getRightNormal()).setCol(cell.getColor4()).setUV(cell.getTexturePos()); v6.setPos(cell.getCorner1()).setNor(cell.getRightNormal()).setCol(cell.getColor4()).setUV(cell.getTexturePos()); meshBuilder.triangle(v1, v2, v3); meshBuilder.triangle(v4, v5, v6); } else { /* 4---3 * | | * 1---2 * (both same colour) */ v1.setPos(cell.getCorner1()).setNor(cell.getLeftNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos()); v2.setPos(cell.getCorner3()).setNor(cell.getLeftNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos()); v3.setPos(cell.getCorner2()).setNor(cell.getLeftNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos()); v4.setPos(cell.getCorner4()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos()); v5.setPos(cell.getCorner3()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos()); v6.setPos(cell.getCorner1()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos()); meshBuilder.triangle(v1, v2, v3); meshBuilder.triangle(v4, v5, v6); } } 

Pero con la lógica anterior, entiendo esto:

No veo por qué esto no está funcionando. ¿Alguien tiene una solución? o alguien ya ha hecho esto?

Decidí usar los mosaicos circundantes en lugar de las esquinas de una sola celda. No es exactamente lo que estaba buscando, pero aquí está el map resultante y el código (aún tengo que hacer algunos ajustes):

 for (int cx = 0; cx < chunks[c].cells.length; cx++) { for (int cz = 0; cz < chunks[c].cells[0].length; cz++) { colorC = chunks[c].cells[cx][cz].getColor1(); if (cx != 0 && cz != 0 && cx != chunks[c].cells.length - 1 && cz != chunks[c].cells[0].length - 1) { colorN = chunks[c].cells[cx][cz + 1].getColor1(); colorE = chunks[c].cells[cx - 1][cz].getColor1(); colorW = chunks[c].cells[cx + 1][cz].getColor1(); colorS = chunks[c].cells[cx][cz - 1].getColor1(); colorNW = chunks[c].cells[cx + 1][cz + 1].getColor1(); colorNE = chunks[c].cells[cx - 1][cz + 1].getColor1(); colorSW = chunks[c].cells[cx + 1][cz - 1].getColor1(); colorSE = chunks[c].cells[cx - 1][cz - 1].getColor1(); /* Check for South East */ if (colorC.equals(colorS) && colorC.equals(colorE) && colorC.equals(colorSE) && !colorC.equals(colorN) && !colorC.equals(colorNW) && !colorC.equals(colorW) ) { chunks[c].cells[cx][cz].setColor1(colorN); v1.setPos(chunks[c].cells[cx][cz].getCorner3()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorN).setUV(chunks[c].cells[cx][cz].getTexturePos()); v2.setPos(chunks[c].cells[cx][cz].getCorner2()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorN).setUV(chunks[c].cells[cx][cz].getTexturePos()); v3.setPos(chunks[c].cells[cx][cz].getCorner4()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorN).setUV(chunks[c].cells[cx][cz].getTexturePos()); v4.setPos(chunks[c].cells[cx][cz].getCorner1()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorS).setUV(chunks[c].cells[cx][cz].getTexturePos()); v5.setPos(chunks[c].cells[cx][cz].getCorner4()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorS).setUV(chunks[c].cells[cx][cz].getTexturePos()); v6.setPos(chunks[c].cells[cx][cz].getCorner2()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorS).setUV(chunks[c].cells[cx][cz].getTexturePos()); meshBuilder.triangle(v1, v2, v3); meshBuilder.triangle(v4, v5, v6); /* Check for South West */ } else if (colorC.equals(colorS) && colorC.equals(colorW) && colorC.equals(colorSW) && !colorC.equals(colorN) && !colorC.equals(colorNE) && !colorC.equals(colorE) ) { chunks[c].cells[cx][cz].setColor1(colorS); v1.setPos(chunks[c].cells[cx][cz].getCorner1()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorS).setUV(chunks[c].cells[cx][cz].getTexturePos()); v2.setPos(chunks[c].cells[cx][cz].getCorner3()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorS).setUV(chunks[c].cells[cx][cz].getTexturePos()); v3.setPos(chunks[c].cells[cx][cz].getCorner2()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorS).setUV(chunks[c].cells[cx][cz].getTexturePos()); v4.setPos(chunks[c].cells[cx][cz].getCorner3()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorN).setUV(chunks[c].cells[cx][cz].getTexturePos()); v5.setPos(chunks[c].cells[cx][cz].getCorner1()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorN).setUV(chunks[c].cells[cx][cz].getTexturePos()); v6.setPos(chunks[c].cells[cx][cz].getCorner4()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorN).setUV(chunks[c].cells[cx][cz].getTexturePos()); meshBuilder.triangle(v1, v2, v3); meshBuilder.triangle(v4, v5, v6); /* Check for North West */ } else if (colorC.equals(colorN) && colorC.equals(colorW) && colorC.equals(colorNW) && !colorC.equals(colorS) && !colorC.equals(colorSE) && !colorC.equals(colorE) ) { chunks[c].cells[cx][cz].setColor1(colorN); v1.setPos(chunks[c].cells[cx][cz].getCorner3()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorN).setUV(chunks[c].cells[cx][cz].getTexturePos()); v2.setPos(chunks[c].cells[cx][cz].getCorner2()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorN).setUV(chunks[c].cells[cx][cz].getTexturePos()); v3.setPos(chunks[c].cells[cx][cz].getCorner4()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorN).setUV(chunks[c].cells[cx][cz].getTexturePos()); v4.setPos(chunks[c].cells[cx][cz].getCorner1()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorS).setUV(chunks[c].cells[cx][cz].getTexturePos()); v5.setPos(chunks[c].cells[cx][cz].getCorner4()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorS).setUV(chunks[c].cells[cx][cz].getTexturePos()); v6.setPos(chunks[c].cells[cx][cz].getCorner2()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorS).setUV(chunks[c].cells[cx][cz].getTexturePos()); meshBuilder.triangle(v1, v2, v3); meshBuilder.triangle(v4, v5, v6); /* Check for North East */ } else if (colorC.equals(colorN) && colorC.equals(colorE) && colorC.equals(colorNE) && !colorC.equals(colorN) && !colorC.equals(colorSW) && !colorC.equals(colorW) ) { chunks[c].cells[cx][cz].setColor1(colorN); v1.setPos(chunks[c].cells[cx][cz].getCorner1()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorS).setUV(chunks[c].cells[cx][cz].getTexturePos()); v2.setPos(chunks[c].cells[cx][cz].getCorner3()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorS).setUV(chunks[c].cells[cx][cz].getTexturePos()); v3.setPos(chunks[c].cells[cx][cz].getCorner2()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorS).setUV(chunks[c].cells[cx][cz].getTexturePos()); v4.setPos(chunks[c].cells[cx][cz].getCorner4()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorN).setUV(chunks[c].cells[cx][cz].getTexturePos()); v5.setPos(chunks[c].cells[cx][cz].getCorner3()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorN).setUV(chunks[c].cells[cx][cz].getTexturePos()); v6.setPos(chunks[c].cells[cx][cz].getCorner1()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorN).setUV(chunks[c].cells[cx][cz].getTexturePos()); meshBuilder.triangle(v1, v2, v3); meshBuilder.triangle(v4, v5, v6); /* Full Square*/ } else { v1.setPos(chunks[c].cells[cx][cz].getCorner1()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorC).setUV(chunks[c].cells[cx][cz].getTexturePos()); v2.setPos(chunks[c].cells[cx][cz].getCorner3()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorC).setUV(chunks[c].cells[cx][cz].getTexturePos()); v3.setPos(chunks[c].cells[cx][cz].getCorner2()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorC).setUV(chunks[c].cells[cx][cz].getTexturePos()); v4.setPos(chunks[c].cells[cx][cz].getCorner4()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorC).setUV(chunks[c].cells[cx][cz].getTexturePos()); v5.setPos(chunks[c].cells[cx][cz].getCorner3()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorC).setUV(chunks[c].cells[cx][cz].getTexturePos()); v6.setPos(chunks[c].cells[cx][cz].getCorner1()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorC).setUV(chunks[c].cells[cx][cz].getTexturePos()); meshBuilder.triangle(v1, v2, v3); meshBuilder.triangle(v4, v5, v6); } /* Edge of chunk*/ } else { v1.setPos(chunks[c].cells[cx][cz].getCorner1()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorC).setUV(chunks[c].cells[cx][cz].getTexturePos()); v2.setPos(chunks[c].cells[cx][cz].getCorner3()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorC).setUV(chunks[c].cells[cx][cz].getTexturePos()); v3.setPos(chunks[c].cells[cx][cz].getCorner2()).setNor(chunks[c].cells[cx][cz].getLeftNormal()).setCol(colorC).setUV(chunks[c].cells[cx][cz].getTexturePos()); v4.setPos(chunks[c].cells[cx][cz].getCorner4()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorC).setUV(chunks[c].cells[cx][cz].getTexturePos()); v5.setPos(chunks[c].cells[cx][cz].getCorner3()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorC).setUV(chunks[c].cells[cx][cz].getTexturePos()); v6.setPos(chunks[c].cells[cx][cz].getCorner1()).setNor(chunks[c].cells[cx][cz].getRightNormal()).setCol(colorC).setUV(chunks[c].cells[cx][cz].getTexturePos()); meshBuilder.triangle(v1, v2, v3); meshBuilder.triangle(v4, v5, v6); }