<commit_before>texture = require './texture.coffee'

fetch_promises = {}  # {file_name: promise}
material_promises = {} # {mat_name: promise}

## Uncomment this to find out why a politician lies
# Promise._all = Promise._all or Promise.all
# Promise.all = (list) ->
#     for l in list
#         if not l
#             debugger
#     politician = Promise._all list
#     politician.list = list
#     politician

# Loads textures of material (given a name), return a promise
fetch_textures_of_material = (scene, mat, ob_name="") ->
    if mat.last_shader
        Promise.all [texture.promise for texture in mat.last_shader.textures]
    else
        # Useful when you only want to request textures to be loaded without compiling the shader
        # TODO: Do we need to draw the texture with a dummy shader
        # to force it to be actually loaded?
        Promise.all(for u in mat.data.uniforms \
            when (u.type == 13 or u.type == 262146 or u.type == 262145) and scene
                # 2D image, see constants in material.py
                tex = mat.scene.textures[u.image]
                if not tex?
                    if not u.filepath
                        throw "Texture #{u.image} not found (in material #{mat_name})."
                    tex = texture.get_texture_from_path_legacy u.image, u.filepath, u.filter, u.wrap, u.size, scene
                tex.load()
                tex.ob_user_names.push ob_name
        )

# Load a mesh of a mesh type object, return a promise
fetch_mesh = (mesh_object, options={}) ->
    {max_mesh_lod=1} = options
    promise = new Promise (resolve, reject) ->
        if mesh_object.type != 'MESH'
            reject 'object is not a mesh'
        {context} = mesh_object<commit_msg>Texture: Fix missing promise which produced race conditions.<commit_after>texture = require './texture.coffee'

fetch_promises = {}  # {file_name: promise}
material_promises = {} # {mat_name: promise}

## Uncomment this to find out why a politician lies
# Promise._all = Promise._all or Promise.all
# Promise.all = (list) ->
#     for l in list
#         if not l
#             debugger
#     politician = Promise._all list
#     politician.list = list
#     politician

# Loads textures of material (given a name), return a promise
fetch_textures_of_material = (scene, mat, ob_name="") ->
    if mat.last_shader
        Promise.all [texture.promise for texture in mat.last_shader.textures]
    else
        # Useful when you only want to request textures to be loaded without compiling the shader
        # TODO: Do we need to draw the texture with a dummy shader
        # to force it to be actually loaded?
        Promise.all(for u in mat.data.uniforms \
            when (u.type == 13 or u.type == 262146 or u.type == 262145) and scene
                # 2D image, see constants in material.py
                tex = mat.scene.textures[u.image]
                if not tex?
                    if not u.filepath
                        throw "Texture #{u.image} not found (in material #{mat_name})."
                    tex = texture.get_texture_from_path_legacy u.image, u.filepath, u.filter, u.wrap, u.size, scene
                tex.ob_user_names.push ob_name
                tex.load()
        )

# Load a mesh of a mesh type object, return a promise
fetch_mesh = (mesh_object, options={}) ->
    {max_mesh_lod=1} = options
    promise = new Promise (resolve, reject) ->
        if mesh_object.type != 'MESH'
            reject 'object is not a mesh'
        {context} = mesh_object
{'fraction_non_alphanumeric': 0.0918107112496458, 'fraction_numerical': 0.009067724567866252, 'mean_word_length': 2.1945701357466065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '4594957', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1004, 'n_words': 356}