def setup_material(m, txt_paths, metal_prob=0.2, transm_prob=0.2, emit_prob=0):
    """Initialize material given list of paths to diff, rough, disp images."""

    # Load any images that haven't been loaded already
    img_ref = [tpath.split("/")[-1] for tpath in txt_paths]
    for img_idx, img in enumerate(img_ref):
        if img not in D.images:
            try:
                D.images.load(txt_paths[img_idx])
            except FileNotFoundError:
                pass

    # Initialize and update diff, rough, and disp shader nodes
    txt_nodes = get_tex_nodes(m)
    for n_idx, n in enumerate(txt_nodes):
        try:
            im = D.images.get(img_ref[n_idx])
            if n_idx > 0:
                im.colorspace_settings.name = "Non-Color"
            n.image = im
        except KeyError:
            pass

    nt = m.node_tree
    bsdf = nt.nodes.get("Principled BSDF")
    rough_scale = nt.nodes.get("Map Range")

    bsdf.inputs.get("Metallic").default_value = 0
    bsdf.inputs.get("Transmission Weight").default_value = 0
    bsdf.inputs.get("IOR").default_value = 1.45
    rough_scale.inputs.get("To Max").default_value = 1

    if np.random.rand() < metal_prob:
        bsdf.inputs.get("Metallic").default_value = 1
        rough_scale.inputs.get("To Max").default_value = 0.5

    elif np.random.rand() < transm_prob:
        bsdf.inputs.get("Transmission Weight").default_value = 1
        bsdf.inputs.get("IOR").default_value = 1.05 + np.random.rand() * 0.3
        rough_scale.inputs.get("To Max").default_value = 0.2

    if np.random.rand() < emit_prob:
        out_node = nt.nodes.get("Material Output")

        nt.nodes.new("ShaderNodeEmission")
        nt.nodes.new("ShaderNodeTexNoise")
        nt.nodes.new("ShaderNodeValToRGB")  # ColorRamp
        nt.nodes.new("ShaderNodeMixShader")

        em = nt.nodes.get("Emission Color")
        em.inputs.get("Strength").default_value = 5
        em.inputs.get("Color").default_value = (
            *colorsys.hsv_to_rgb(np.random.rand(), 1, 1),
            1,
        )

        noise = nt.nodes.get("Noise Texture")
        noise.inputs.get("Scale").default_value = np.random.uniform(1, 10)
        noise.inputs.get("Distortion").default_value = np.random.uniform(3, 10)

        ramp = nt.nodes.get("ColorRamp")
        ramp.color_ramp.elements[0].position = 0.4
        ramp.color_ramp.elements[1].position = 0.45
        new_link(nt, noise, "Color", ramp, "Fac")

        mix = nt.nodes.get("Mix Shader")
        new_link(nt, ramp, "Color", mix, "Fac")
        new_link(nt, bsdf, "BSDF", mix, "Shader")
        new_link(nt, em, "Emission Color", mix, "Shader")
        new_link(nt, mix, "Shader", out_node, "Surface")
Initialize material given list of paths to diff, rough, disp images.
infinigen/assets/objects/trees/utils/materials.py