<commit_before>﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(MeshFilter))]
public class ChunkMeshGenerator : MonoBehaviour {

    private MeshFilter filter;

    void BlockUpdate(Chunk updatedChunk)
    {
        var generatedMesh = GenerateMesh(updatedChunk);
        if (filter == null)
        {
            filter = GetComponent<MeshFilter>();
        }
        filter.mesh = generatedMesh;
    }

    private Mesh GenerateMesh(Chunk updatedChunk)
    {
        Mesh mesh = new Mesh();
        var generatedColors = new List<Color>();
        var generatedVertices = new List<Vector3>();
        var generatedTriangles = new List<int>();

        for (var x = 0; x < updatedChunk.width; ++x)
        {
            for (var y = 0; y < updatedChunk.width; ++y)
            {
                for (var z = 0; z < updatedChunk.width; ++z)
                {
                    var block = CheckBlock(updatedChunk, x, y, z);
                    if (block.color != default(Color))
                    {
                        // current Block is valid
                        var adjacentBlocks = new Block[] {
                            CheckBlock(updatedChunk, x-1, y, z),
                            CheckBlock(updatedChunk, x+1, y, z),
                            CheckBlock(updatedChunk, x, y-1, z),
                            CheckBlock(updatedChunk, x, y+1, z),
                            CheckBlock(updatedChunk, x, y, z-1),
                            CheckBlock(updatedChunk, x, y, z+1)
                        };

                        GenerateMeshForAdjacentBlocks(block, adjacentBlocks, generatedColors, generatedTriangles, generatedVertices);
                    }
                }
            }
        }

        mesh.SetVertices(generatedVertices);
        mesh.SetColors(generatedColors);
        mesh.SetTriangles(generatedTriangles);

        return mesh;
    }

    private void GenerateMeshForAdjacentBlocks(Block block, Block[] adjacentBlocks, List<Color> generatedColors, List<int> generatedTriangles, List<Vector3> generatedVertices)
    {
        foreach (var adj in adjacentBlocks)<commit_msg>Add submesh ID to `SetTriangles` call.<commit_after>﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(MeshFilter))]
public class ChunkMeshGenerator : MonoBehaviour {

    private MeshFilter filter;

    void BlockUpdate(Chunk updatedChunk)
    {
        var generatedMesh = GenerateMesh(updatedChunk);
        if (filter == null)
        {
            filter = GetComponent<MeshFilter>();
        }
        filter.mesh = generatedMesh;
    }

    private Mesh GenerateMesh(Chunk updatedChunk)
    {
        Mesh mesh = new Mesh();
        var generatedColors = new List<Color>();
        var generatedVertices = new List<Vector3>();
        var generatedTriangles = new List<int>();

        for (var x = 0; x < updatedChunk.width; ++x)
        {
            for (var y = 0; y < updatedChunk.width; ++y)
            {
                for (var z = 0; z < updatedChunk.width; ++z)
                {
                    var block = CheckBlock(updatedChunk, x, y, z);
                    if (block.color != default(Color))
                    {
                        // current Block is valid
                        var adjacentBlocks = new Block[] {
                            CheckBlock(updatedChunk, x-1, y, z),
                            CheckBlock(updatedChunk, x+1, y, z),
                            CheckBlock(updatedChunk, x, y-1, z),
                            CheckBlock(updatedChunk, x, y+1, z),
                            CheckBlock(updatedChunk, x, y, z-1),
                            CheckBlock(updatedChunk, x, y, z+1)
                        };

                        GenerateMeshForAdjacentBlocks(block, adjacentBlocks, generatedColors, generatedTriangles, generatedVertices);
                    }
                }
            }
        }

        mesh.SetVertices(generatedVertices);
        mesh.SetColors(generatedColors);
        mesh.SetTriangles(generatedTriangles, 0);

        return mesh;
    }

    private void GenerateMeshForAdjacentBlocks(Block block, Block[] adjacentBlocks, List<Color> generatedColors, List<int> generatedTriangles, List<Vector3> generatedVertices)
    {
        foreach (var adj in adjacentBlocks)
{'fraction_non_alphanumeric': 0.09312839059674503, 'fraction_numerical': 0.005198915009041591, 'mean_word_length': 1.7147239263803682, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1666667', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1103, 'n_words': 281}