Marching Cubes [Edited Version]

Части и запчасти к проектам, дополнительное программное обеспечение.

Marching Cubes [Edited Version]

Сообщение ZamarTerrier 14 сен 2018, 20:38

Всем Привет, Привет! ;;) Без понятия туда я пишу или нет, НО, Вкратце :
Я давненько занимаюсь алгоритмом Marching Cubes [curved_hands] . Долго втыкал что да как ~x( .

По сей день мне не понятно как смешивать не ограниченное кол-во текстур как в Террэйне. Я не терял время зря и решил переделать алгоритм. Одним словом "Тайлы". Если точнее, то теперь алгоритм создает модель не по треугольникам, а по квадратам. Раз ходячий куб теперь разбивает каждый участок модели на квадраты, то и рисовать текстуру стало легче. В данном примере я реализую текстуризацию как в Minecraft. Оххохо, сколько же можно текстур забабахать по системе Тайлов. Первоначальную идею это реализовало не полностью, но прогресс на лицо :D .

тут статейка
http://unity3d.ru/distribution/viewtopic.php?f=17&t=42671&p=267590&hilit=marching+cubes#p267590

Я на этом не останавился и решил сделать сглаживание и вот, представляю к вашему внимаю мой законченный Marching Cubes.

Таблица вершин
Синтаксис:
Используется csharp
public static int[][] m_meshTable = new int[256][]
    {
        new int[] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 12, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 13, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 1, 9, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 14, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 12, 0,  8, 3, 14, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 2, 10, 9, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 2, 10, 8, 3, 20, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 15, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 0, 8, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 13, 1, 9, 0, 15, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 1, 9, 11, 2, 20, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 3, 11, 10, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 0, 8, 10, 1, 20, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 3, 11, 9, 0, 20, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 8, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 16, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 4, 7, 3, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 13, 1, 9, 0, 16, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 4, 7, 1, 9, 21, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 14, 2, 10, 1, 16, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 3, 0, 4, 7, 14, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 2, 10, 9, 0, 16, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 2, 10, 9, 7, 15, 2, 7, 3, 16, 7, 9, 4, -1, -1, -1, -1 },
        new int[] { 16, 7, 8, 4, 15, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 11, 2, 4, 7, 21, 0, 4, 2, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 13, 1, 9, 0, 16, 7, 8, 4, 15, 3, 11, 2, -1, -1, -1, -1 },
        new int[] { 4, 7, 11, 9, 9, 11, 2, 1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 3, 11, 10, 1, 16, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 1, 4, 11, 10, 13, 0, 4, 1, 16, 7, 11, 4, -1, -1, -1, -1 },
        new int[] { 16, 7, 8, 4, 9, 0, 3, 11, 20, 11, 10, 9, -1, -1, -1, -1 },
        new int[] { 4, 7, 11, 9, 20, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 17, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 17, 4, 9, 5, 12, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 1, 5, 4, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 3, 5, 4, 8, 20, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 14, 2, 10, 1, 17, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 12, 3, 0, 8, 14, 2, 10, 1, 17, 4, 9, 5, -1, -1, -1, -1, -1 },
        new int[] { 5, 4, 2, 10, 20, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 3, 2, 10, 5, 8, 3, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 17, 4, 9, 5, 15, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 0, 8, 11, 2, 17, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 0, 1, 5, 4, 15, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 14, 1, 5, 2, 2, 5, 8, 11, 17, 4, 8, 5, -1, -1, -1, -1 },
        new int[] { 10, 1, 3, 11, 17, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 17, 4, 9, 5, 0, 8, 10, 1, 20, 8, 11, 10, -1, -1, -1, -1 },
        new int[] { 17, 4, 0, 5, 5, 0, 11, 10, 12, 3, 11, 0, -1, -1, -1, -1, -1 },
        new int[] { 5, 4, 8, 10, 20, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 5, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 9, 5, 3, 0, 20, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 0, 1, 7, 8, 20, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 1, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 9, 5, 7, 8, 14, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] {14, 2, 10, 1, 5, 3, 0, 9, 20, 5, 7, 3, -1, -1, -1, -1 },
        new int[] { 10, 5, 8, 2, 21, 2, 8, 0, 22, 7, 8, 5, -1, -1, -1, -1 },
        new int[] { 2, 10, 5, 3, 20, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 7, 8, 9, 5, 15, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 22, 7, 9, 5, 21, 0, 9, 2, 7, 11, 2, 9, -1, -1, -1},
        new int[] { 15, 3, 11, 2, 1, 7, 8, 0, 22, 7, 1, 5, -1, -1, -1, -1 },
        new int[] { 11, 2, 1, 7, 22, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 9, 5, 7, 8, 10, 1, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 5, 7, 0, 9, 0, 7, 11, 10, 13, 0, 10, 1, -1, -1 },
        new int[] { 12, 3, 11, 0, 0, 11, 10, 5, 0, 5, 7, 8, -1 },
        new int[] { 11, 10, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 18, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 12, 0, 8, 3, 18, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 13, 1, 9, 0, 18, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 1, 9, 8, 3, 18, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 2, 6, 5, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 2, 6, 5, 1, 12, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 9, 0, 6, 5, 21, 2, 6, 0, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 5, 9, 8, 2, 18, 5, 2, 6, 15, 2, 8, 3, -1, -1, -1 },
        new int[] { 15, 3, 11, 2, 18, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 0, 8, 11, 2, 18, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1 },
        new int[] {13, 1, 9, 0, 15, 3, 11, 2, 18, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1 },
        new int[] {18, 5, 10, 6, 2, 1, 9, 11, 20, 9, 8, 11, -1, -1, -1, -1 },
        new int[] { 3, 11, 6, 5, 21, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 0, 8, 11, 5, 13, 0, 5, 1, 18, 5, 11, 6, -1, -1, -1, -1 },
        new int[] { 3, 11, 6, 0, 0, 6, 5, 9, -1, -1, -1, -1 },
        new int[] { 6, 5, 9, 11, 20, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 18, 5, 10, 6, 16, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 4, 7, 3, 0, 18, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 13, 1, 9, 0, 18, 5, 10, 6, 16, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 18, 5, 10, 6, 1, 9, 4, 7, 21, 1, 7, 3, -1, -1, -1, -1 },
        new int[] { 6, 5, 1, 2, 16, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 1, 2, 6, 5, 3, 0, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 16, 7, 8, 4, 9, 0, 6, 5, 20, 0, 2, 6, -1, -1, -1, -1 },
        new int[] { 7, 3, 9, 4, 9, 3, 2, 6, 18, 5, 9, 6, -1 },
        new int[] { 15, 3, 11, 2, 16, 7, 8, 4, 18, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 18, 5, 10, 6, 7, 11, 2, 4, 20, 2, 0, 4, -1, -1, -1, -1 },
        new int[] { 13, 1, 9, 0, 16, 7, 8, 4, 15, 3, 11, 2, 18, 5, 10, 6, -1, -1, -1, -1 },
        new int[] { 9, 11, 2, 1, 9, 4, 7, 11, 18, 5, 10, 6, -1 },
        new int[] { 16, 7, 8, 4, 3, 11, 6, 5,21, 3, 5, 1, -1, -1, -1, -1 },
        new int[] { 5, 1, 11, 6, 11, 1, 0, 4, 16, 7, 11, 4, -1 },
        new int[] { 0, 6, 5, 9, 0, 3, 11, 6, 16, 7, 8, 4, -1 },
        new int[] { 6, 5, 9, 11, 4, 7, 11, 9, -1, -1, -1, -1 },
        new int[] { 6, 4, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 4, 9, 10, 6, 12, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 10, 6, 0, 1, 22, 4, 0, 6, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 8, 3, 21, 1, 8, 6, 22, 4, 8, 1, 10, 6, -1, -1, -1, -1 },
        new int[] { 1, 2, 4, 9, 20, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 12, 0, 8, 3, 1, 2, 4, 9, 20, 2, 6, 4, -1, -1, -1, -1 },
        new int[] { 0, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 8, 3, 2, 4, 20, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 10, 6, 4, 9, 15, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 0, 8, 11, 2, 4, 9, 10, 6, -1, -1, -1, -1 },
        new int[] { 15, 3, 11, 2, 20, 6, 4, 0, 1, 10, 6, 0, -1, -1, -1, -1 },
        new int[] { 6, 4, 1, 10, 14, 1, 11, 2, 8, 11, 1, 4, -1 },
        new int[] { 9, 6, 22, 4, 9, 1, 21, 3, 9, 3, 11, 6, -1, -1, -1 },
        new int[] {  8, 1, 13, 0, 11, 6, 1, 8, 1, 6, 4, 9, -1 },
        new int[] { 3, 11, 6, 0, 0, 6, 22, 4, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 6, 4, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 7, 8, 10, 6, 20, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 12, 0, 7, 3, 0, 9, 10, 7, 19, 7, 10, 6, -1, -1, -1, -1 },
        new int[] { 10, 6, 7, 1, 1, 7, 8, 0, -1, -1, -1, -1 },
        new int[] { 10, 6, 7, 1, 21, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 14, 2, 6, 1, 1, 6, 8, 9, 8, 6, 19, 7, -1, -1, -1, -1 },
        new int[] { 2, 6, 9, 1, 9, 6, 7, 3, 12, 0, 9, 3, -1 },
        new int[] { 7, 8, 0, 6, 6, 0, 21, 2, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 6, 7, 3, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 15, 3, 11, 2, 10, 6, 8, 9, 8, 6, 19, 7, -1, -1, -1, -1 },
        new int[] { 7, 11, 2, 0, 19, 7, 10, 6, 9, 10, 7, 0,- 1 },
        new int[] { 1, 7, 8, 0, 7, 1, 10, 6, 15, 3, 11, 2, -1 },
        new int[] { 11, 2, 1, 7, 10, 6, 7, 1, -1, -1, -1, -1 },
        new int[] { 8, 6, 19, 7, 9, 1, 6, 8, 6, 1, 3, 11, -1 },
        new int[] { 13, 0, 9, 1, 19, 7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 7, 8, 0, 6, 0, 3, 11, 6, -1, -1, -1, -1 },
        new int[] { 19, 7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 19, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 12, 0, 8, 3, 19, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 13, 1, 9, 0, 19, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 8, 3, 1, 9, 19, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 10, 1, 14, 2, 19, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 14, 2, 10, 1, 12, 0, 8, 3, 19, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 2, 10, 9, 0, 19, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 19, 6, 11, 7, 2, 10, 8, 3, 20, 10, 9, 8, -1, -1, -1, -1 },
        new int[] { 7, 6, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 7, 6, 0, 8, 20, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 2, 3, 7, 6, 13, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 14, 1, 6, 2, 1, 9, 8, 6, 8, 7, 19, 6, -1, -1, -1, -1 },
        new int[] { 10, 1, 7, 6, 20, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 7, 6, 10, 1, 1, 0, 8, 7, -1, -1, -1, -1 },
        new int[] { 12, 3, 7, 0, 0, 7, 10, 9, 19, 6, 10, 7, -1, -1, -1, -1 },
        new int[] { 7, 6, 10, 8, 20, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 11, 8, 4, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 3, 0, 6, 11, 20, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 8, 4, 6, 11, 9, 0, 13, 1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 9, 4, 22, 6, 9, 3, 21, 1, 3, 9, 6, 11, -1, -1, -1, -1 },
        new int[] { 8, 4, 6, 11, 14, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 14, 2, 10, 1, 3, 0, 6, 11, 20, 0, 4, 6, -1, -1, -1, -1 },
        new int[] { 4, 6, 11, 8, 0, 2, 10, 9, -1, -1, -1, -1 },
        new int[] {  10, 3, 15, 2, 9, 4, 3, 10, 3, 4, 6, 11, -1 },
        new int[] { 8, 4, 2, 3, 22, 6, 2, 4, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 0, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 13, 1, 9, 0, 3, 8, 4, 2, 2, 4, 22, 6, -1, -1, -1, -1 },
        new int[] { 1, 9, 4, 2, 2, 4, 22, 6, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 8, 1, 21, 3, 8, 4, 22, 6, 8, 6, 10, 1, -1, -1, -1, -1 },
        new int[] { 10, 1, 0, 6, 22, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 4, 6, 3, 8, 12, 3, 9, 0, 10, 9, 3, 6, -1 },
        new int[] { 10, 9, 4, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 17, 4, 9, 5, 19, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 12, 0, 8, 3, 17, 4, 9, 5, 11, 7, 19, 6, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 5, 4, 0, 1, 19, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 11, 7, 19, 6, 8, 3, 5, 4, 20, 3, 1, 5, -1, -1, -1, -1 },
        new int[] { 9, 5, 17, 4, 10, 1, 14, 2, 19, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 19, 6, 11, 7, 14, 2, 10, 1, 12, 0, 8, 3, 17, 4, 9, 5, -1, -1, -1, -1 },
        new int[] { 19, 6, 11, 7, 5, 4, 2, 10, 20, 4, 0, 2, -1, -1, -1, -1 },
        new int[] { 3, 5, 4, 8, 3, 2, 10, 5, 11, 7, 19, 6, -1 },
        new int[] { 7, 6, 2, 3, 17, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 17, 4, 9, 5, 0, 8, 6, 2, 19, 6, 8, 7, -1, -1, -1, -1 },
        new int[] { 3, 7, 6, 2, 1, 5, 4, 0, -1, -1, -1, -1 },
        new int[] { 6, 2, 8, 7, 8, 1, 5, 4, 14, 1, 8, 2, -1 },
        new int[] { 9, 5, 17, 4, 1, 7, 6, 10, 20, 1, 3, 7, -1, -1, -1, -1 },
        new int[] { 1, 7, 6, 10, 1, 0, 8, 7, 9, 5, 17, 4, -1 },
        new int[] { 4, 0, 10, 5, 6, 10, 3, 7, 12, 3, 10, 0, -1 },
        new int[] { 7, 6, 10, 8, 5, 4, 8, 10, -1, -1, -1, -1 },
        new int[] { 6, 11, 9, 5, 20, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 3, 0, 6, 11, 0, 9, 5, 6, -1, -1, -1, -1 },
        new int[] { 0, 5, 11, 8, 13, 1, 5, 0, 18, 6, 11, 5, -1, -1, -1, -1 },
        new int[] { 6, 11, 3, 5, 5, 3, 21, 1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 14, 2, 10, 1, 9, 5, 11, 8, 11, 5, 18, 6, -1, -1, -1, -1 },
        new int[] { 0, 6, 11, 3, 0, 9, 5, 6, 14, 2, 10, 1, -1 },
        new int[] { 11, 5, 18, 6, 8, 0, 5, 11, 5, 0, 2, 10, -1 },
        new int[] { 6, 11, 3, 5, 2, 10, 5, 3, -1, -1, -1, -1 },
        new int[] { 5, 2, 8, 9, 18, 6, 2, 5, 15, 3, 8, 2, -1, -1, -1, -1 },
        new int[] { 9, 5, 6, 0, 21, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 1, 5, 8, 0, 6, 2, 8, 5, 15, 3, 8, 2, -1 },
        new int[] { 1, 5, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 1, 3, 6, 10, 8, 9, 6, 3, 18, 6, 9, 5, -1 },
        new int[] { 10, 1, 0, 6, 5, 6, 0, 9, -1, -1, -1, -1 },
        new int[] { 12, 3, 8, 0, 18, 6, 10, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 10, 5, 18, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 7, 5, 10, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 11, 7, 5, 10, 8, 3, 12, 0, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 5, 10, 11, 7, 13, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 10, 11, 7, 5, 9, 8, 3, 1, -1, -1, -1, -1 },
        new int[] { 11, 7, 1, 2, 20, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 12, 0, 8, 3, 1, 2, 11, 7, 20, 7, 5, 1, -1, -1, -1, -1 },
        new int[] { 9, 7, 22, 5, 9, 0, 21, 2, 2, 11, 7, 9, -1, -1, -1, -1 },
        new int[] { 7, 5, 2, 11, 9, 8, 2, 5, 15, 2, 8, 3, -1 },
        new int[] { 2, 3, 5, 10, 20, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 8, 2, 21, 0, 8, 7, 22, 5, 10, 2, 8, 5, -1, -1, -1, -1 },
        new int[] { 9, 0, 13, 1, 20, 3, 7, 5, 3, 5, 10, 2, -1, -1, -1, -1 },
        new int[] { 8, 7, 2, 9, 9, 2, 14, 1, 5, 10, 2, 7, -1 },
        new int[] { 3, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 0, 8, 7, 1, 1, 7, 22, 5, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 9, 0, 3, 5, 20, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 9, 8, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 5, 10, 8, 4, 20, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 17, 5, 0, 4, 5, 10, 11, 0, 11, 3, 12, 0, -1, -1, -1, -1 },
        new int[] { 13, 1, 9, 0, 20, 10, 11, 8, 8, 4, 5, 10, -1, -1, -1, -1 },
        new int[] { 10, 4, 17, 5, 11, 3, 4, 10, 1, 9, 4, 3, -1 },
        new int[] { 14, 2, 5, 1, 2, 11, 8, 5, 17, 5, 8, 4, -1, -1, -1, -1 },
        new int[] { 0, 4, 11, 3, 5, 1, 11, 4, 14, 2, 11, 1, -1 },
        new int[] { 0, 2, 5, 9, 11, 8, 5, 2, 17, 5, 8, 4, -1 },
        new int[] { 9, 4, 17, 5, 15, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 2, 3, 5, 10, 3, 8, 4, 5, -1, -1, -1, -1 },
        new int[] { 5, 10, 2, 4, 20, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 2, 3, 5, 10, 5, 3, 8, 4, 13, 1, 9, 0, -1 },
        new int[] { 5, 10, 2, 4, 1, 9, 4, 2, -1, -1, -1, -1 },
        new int[] { 8, 4, 5, 3, 20, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 0, 4, 5, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 8, 4, 5, 3, 9, 0, 3, 5, -1, -1, -1, -1 },
        new int[] { 9, 4, 17, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 4, 9, 11, 7, 20, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 12, 0, 8, 3, 4, 9, 11, 7, 20, 9, 10, 11, -1, -1, -1, -1 },
        new int[] { 1, 10, 11, 4, 13, 1, 4, 0, 16, 4, 11, 7, -1, -1, -1, -1 },
        new int[] { 3, 1, 4, 8, 10, 11, 4, 1, 16, 4, 11, 7, -1 },
        new int[] { 4, 9, 11, 7, 9, 1, 2, 11, -1, -1, -1, -1 },
        new int[] { 9, 11, 7, 4, 9, 1, 2, 11, 12, 0, 8, 3, -1 },
        new int[] { 11, 7, 4, 2, 21, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 11, 7, 4, 2, 8, 3, 2, 4, -1, -1, -1, -1 },
        new int[] { 2, 7, 9, 10, 15, 3, 7, 2, 16, 4, 9, 7, -1, -1, -1, -1 },
        new int[] { 9, 7, 16, 4, 10, 2, 7, 9, 7, 2, 0, 8, -1 },
        new int[] { 3, 7, 10, 2, 4, 0, 10, 7, 13, 1, 10, 0, -1 },
        new int[] { 14, 1, 10, 2, 8, 7, 16, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 4, 9, 1, 7, 20, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 4, 9, 1, 7, 0, 8, 7, 1, -1, -1, -1, -1 },
        new int[] { 4, 0, 3, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 16, 4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 9, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 3, 0, 9, 11, 20, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 0, 1, 10, 8, 20, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 3, 1, 10, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 1, 2, 11, 9, 20, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 3, 0, 9, 11, 1, 2, 11, 9, -1, -1, -1, -1 },
        new int[] { 0, 2, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 15, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 2, 3, 8, 10, 20, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 9, 10, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 2, 3, 8, 10, 0, 1, 10, 8, -1, -1, -1, -1 },
        new int[] { 14, 1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 1, 3, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 13, 0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { 12, 3, 8, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        new int[] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }
    };


Блок для теста
Синтаксис:
Используется csharp
        float[] dencities = new float[8];

        for (int x = 1; x < Size - 1; x++)
        {
            for (int y = 1; y < Height - 1; y++)
            {
                for (int z = 1; z < Size - 1; z++)
                {
                    int cubeIndex = 0;

                    dencities[0] = Density(x, y, z + 1);
                    dencities[1] = Density(x + 1, y, z + 1);
                    dencities[2] = Density(x + 1, y, z);
                    dencities[3] = Density(x, y, z);
                    dencities[4] = Density(x, y + 1, z + 1);
                    dencities[5] = Density(x + 1, y + 1, z + 1);
                    dencities[6] = Density(x + 1, y + 1, z);
                    dencities[7] = Density(x, y + 1, z);

                    float isolevel = 1f;

                    if (dencities[0] < isolevel)
                        cubeIndex |= 1;
                    if (dencities[1] < isolevel)
                        cubeIndex |= 2;
                    if (dencities[2] < isolevel)
                        cubeIndex |= 4;
                    if (dencities[3] < isolevel)
                        cubeIndex |= 8;
                    if (dencities[4] < isolevel)
                        cubeIndex |= 16;
                    if (dencities[5] < isolevel)
                        cubeIndex |= 32;
                    if (dencities[6] < isolevel)
                        cubeIndex |= 64;
                    if (dencities[7] < isolevel)
                        cubeIndex |= 128;

                    if (cubeIndex == 0 || cubeIndex == 255)
                        continue;


                    Vector3[] pos = new Vector3[8];
                    pos[0] = new Vector3(x, y, z + 1);
                    pos[1] = new Vector3(x + 1, y, z + 1);
                    pos[2] = new Vector3(x + 1, y, z);
                    pos[3] = new Vector3(x, y, z);
                    pos[4] = new Vector3(x, y + 1, z + 1);
                    pos[5] = new Vector3(x + 1, y + 1, z + 1);
                    pos[6] = new Vector3(x + 1, y + 1, z);
                    pos[7] = new Vector3(x, y + 1, z);

                    Vector3[] positions = new Vector3[23];
                    positions[0] = VertexInterp(isolevel, pos[0], pos[1], dencities[0], dencities[1]);
                    positions[1] = VertexInterp(isolevel, pos[1], pos[2], dencities[1], dencities[2]);
                    positions[2] = VertexInterp(isolevel, pos[2], pos[3], dencities[2], dencities[3]);
                    positions[3] = VertexInterp(isolevel, pos[3], pos[0], dencities[3], dencities[0]);
                    positions[4] = VertexInterp(isolevel, pos[4], pos[5], dencities[4], dencities[5]);
                    positions[5] = VertexInterp(isolevel, pos[5], pos[6], dencities[5], dencities[6]);
                    positions[6] = VertexInterp(isolevel, pos[6], pos[7], dencities[6], dencities[7]);
                    positions[7] = VertexInterp(isolevel, pos[7], pos[4], dencities[7], dencities[4]);
                    positions[8] = VertexInterp(isolevel, pos[0], pos[4], dencities[0], dencities[4]);
                    positions[9] = VertexInterp(isolevel, pos[1], pos[5], dencities[1], dencities[5]);
                    positions[10] = VertexInterp(isolevel, pos[2], pos[6], dencities[2], dencities[6]);
                    positions[11] = VertexInterp(isolevel, pos[3], pos[7], dencities[3], dencities[7]);
                    positions[12] = (positions[0] + positions[3]) / 2;
                    positions[13] = (positions[0] + positions[1]) / 2;
                    positions[14] = (positions[1] + positions[2]) / 2;
                    positions[15] = (positions[2] + positions[3]) / 2;
                    positions[16] = (positions[4] + positions[7]) / 2;
                    positions[17] = (positions[4] + positions[5]) / 2;
                    positions[18] = (positions[5] + positions[6]) / 2;
                    positions[19] = (positions[6] + positions[7]) / 2;
                    positions[21] = (positions[0] + positions[1] + positions[2] + positions[3]) / 4;
                    positions[22] = (positions[4] + positions[5] + positions[6] + positions[7]) / 4;
                    positions[20] = (positions[8] + positions[9] + positions[10] + positions[11]) / 4;


                    for (int i = 0; m_meshTable[cubeIndex][i] != -1; i += 4)

                    {
                        int ind = vertices.Count;

                        vertices.Add(positions[m_meshTable[cubeIndex][i]]);
                        vertices.Add(positions[m_meshTable[cubeIndex][i + 1]]);
                        vertices.Add(positions[m_meshTable[cubeIndex][i + 2]]);
                        vertices.Add(positions[m_meshTable[cubeIndex][i + 3]]);

                        triangles.Add(ind + 0);
                        triangles.Add(ind + 1);
                        triangles.Add(ind + 2);
                        triangles.Add(ind + 0);
                        triangles.Add(ind + 2);
                        triangles.Add(ind + 3);

                        uv.Add(new Vector2(0, 0.9375f));
                        uv.Add(new Vector2(0, 1));
                        uv.Add(new Vector2(0.065f, 1));
                        uv.Add(new Vector2(0.065f, 0.9375f));

                    }

                }
            }
        }

        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.uv = uv.ToArray();
        mesh.RecalculateBounds();
        mesh.RecalculateNormals();

        GetComponent<MeshFilter>().mesh = mesh;
        GetComponent<MeshCollider>().sharedMesh = mesh;

float Density(int x, int y, int z)
    {
        Vector3 pos = new Vector3(x, y, z);

            if (Vector3.Distance(pos, new Vector3(0,0,0)) < 4)
                return 1;
            else
                return 0;
    }

    Vector3 VertexInterp(float isolevel, Vector3 p1, Vector3 p2, float valp1, float valp2){
        float mu;
        Vector3 p;

        if (Mathf.Abs(isolevel - valp1) < 0.00001)
            return (p1);
        if (Mathf.Abs(isolevel - valp2) < 0.00001)
            return (p2);
        if (Mathf.Abs(valp1 - valp2) < 0.00001)
            return (p1);
        mu = (isolevel - valp1) / (valp2 - valp1);
        p.x = p1.x + mu * (p2.x - p1.x);
        p.y = p1.y + mu * (p2.y - p1.y);
        p.z = p1.z + mu * (p2.z - p1.z);

        return (p);
    }


(Там картинка)
https://hkar.ru/Vt11

Почему именно он? Объясняю :
-Можно накладывать текстуру по тайловой системе.
-Обычный Marching Cubes создает где-то в 3.5 раз больше вершин, чем треугольников. Мои кубы только в 2 раза.
-Раз лишних вершин меньше + к оптимизации.
ZamarTerrier
UNец
 
Сообщения: 1
Зарегистрирован: 14 сен 2018, 20:10

Вернуться в Компоненты (Копилка)

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 5