<commit_before>import bpy

def create_mesh(importer, idx):
    mesh = importer.root['meshes'][idx]
    name = mesh.get('name', 'meshes[%d]' % idx)
    me = bpy.data.meshes.new(name)

    #TODO handle multiple primitives
    primitive = mesh['primitives'][0]
    if 'material' in primitive:
        material = importer.get_material(primitive['material'])
    else:
        material = importer.get_default_material()
    me.materials.append(material)
    #TODO handle no indices
    indices = importer.get_accessor(primitive['indices'])
    #TODO handle primitive mode != 4
    faces = [tuple(indices[i:i+3]) for i in range(0, len(indices), 3)]

    attributes = primitive['attributes']
    positions = importer.get_accessor(attributes['POSITION'])

    me.from_pydata(positions, [], faces)
    me.validate(verbose = True)

    for polygon in me.polygons:
        polygon.use_smooth = True

    if 'NORMAL' in attributes:
        normals = importer.get_accessor(attributes['NORMAL'])
        for i, vertex in enumerate(me.vertices):
            vertex.normal = normals[i]

    if 'TEXCOORD_0' in attributes:
        uvs = importer.get_accessor(attributes['TEXCOORD_0'])
        me.uv_textures.new("TEXCOORD_0")
        for i, uv_loop in enumerate(me.uv_layers[0].data):
            uv = uvs[indices[i]]
            me.uv_layers[0].data[i].uv = (uv[0], -uv[1])

    me.update()
    return me<commit_msg>Begin filling in mesh improvements<commit_after>import bmesh
import bpy

def primitive_to_mesh(importer, primitive, material_index):
    mode = primitive.get('mode', 4)
    attributes = primitive['attributes']
    if 'indices' in primitive:
        indices = importer.get_accessor(primitive['indices'])
    else:
        indices = None

    verts = importer.get_accessor(attributes['POSITION'])
    edges = []
    faces = []

    if mode == 0:
        # POINTS
        pass
    elif mode == 1:
        #LINES
        if not indices:
            indices = range(0, len(verts))
        edges = [tuple(indices[i:i+2]) for i in range(0, len(indices), 2)]
    elif mode == 4:
        #TRIANGLES
        if not indices:
            indices = range(0, len(verts))
        faces = [tuple(indices[i:i+3]) for i in range(0, len(indices), 3)]
    else:
        raise Exception("primitive mode unimplemented: %d" % mode)

    me = bpy.data.meshes.new('>>>TEMP<<<')
    me.from_pydata(verts, edges, faces)
    me.validate()

    for polygon in me.polygons:
        polygon.material_index = material_index

    if 'NORMAL' in attributes:
        normals = importer.get_accessor(attributes['NORMAL'])
        for i, vertex in enumerate(me.vertices):
            vertex.normal = normals[i]

    if 'TEXCOORD_0' in attributes:
        uvs = importer.get_accessor(attributes['TEXCOORD_0'])
        me.uv_textures.new("TEXCOORD_0")
        for i, uv_loop in enumerate(me.uv_layers[0].data):
            uv = uvs[indices[i]] #TODO what about when indices == None?
            uv_loop.uv = (uv[0], -uv[1])

    me.update()

    return me


def create_mesh(importer, idx):
    mesh = importer.root['meshes'][idx]
    name = mesh.get('name', 'meshes[%d]' % idx)
    me = bpy.data.meshes.new(name)

    bme = bmesh.new()
    for i, primitive in enumerate(mesh['primitives']):
        tmp_mesh = primitive_to_mesh(importer, primitive, i)
        bme.from_mesh(tmp_mesh)
        bpy.data.meshes.remove(tmp_mesh)
    bme.to_mesh(me)
    bme.free()

    for primitive in mesh['primitives']:
        if 'material' in primitive:
            material = importer.get_material(primitive['material'])
        else:
            material = importer.get_default_material()
        me.materials.append(material)

    for polygon in me.polygons:
        polygon.use_smooth = True

    me.update()

    return me
{'fraction_non_alphanumeric': 0.1283138918345705, 'fraction_numerical': 0.007953340402969246, 'mean_word_length': 2.7767767767767766, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '4853627', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1219, 'n_words': 272}