import { TextureAttachment } from "./TextureAttachment.js";

const taDiffuse = new TextureAttachment({
    name: 'diffuse',
    uv_index: 0,
    read(m) {
        return m.map;
    },
    write(m, t) {
        m.map = t;
    }
});

const taAlphaMap = new TextureAttachment({
    name: "alpha",
    uv_index: 0,
    read(m) {
        return m.alphaMap;
    },
    write(m, t) {
        m.alphaMap = t;
    }
});

const taDisplacement = new TextureAttachment({
    name: "displacement",
    uv_index: 0,
    read(m) {
        return m.displacementMap;
    },
    write(m, t) {
        m.displacementMap = t;
    }
});

/**
 *
 * @type {Object<TextureAttachment[]>}
 */
export const TextureAttachmentsByMaterialType = {
    MeshDepthMaterial: [
        taDiffuse,
        taDisplacement,
        taAlphaMap
    ],
    MeshBasicMaterial: [
        taDiffuse
    ],
    MeshStandardMaterial: [
        taDiffuse,
        taAlphaMap,
        new TextureAttachment({
            name: "light",
            uv_index: 1,
            read(m) {
                return m.lightMap;
            },
            write(m, t) {
                m.lightMap = t;
            }
        }),
        new TextureAttachment({
            name: "ao",
            uv_index: 1,
            read(m) {
                return m.aoMap;
            },
            write(m, t) {
                m.aoMap = t;
            }
        }),
        new TextureAttachment({
            name: "emissive",
            uv_index: 0,
            read(m) {
                return m.emissiveMap;
            },
            write(m, t) {
                m.emissiveMap = t;
            }
        }),
        new TextureAttachment({
            name: "bump",
            uv_index: 0,
            read(m) {
                return m.bumpMap;
            },
            write(m, t) {
                m.bumpMap = t;
            }
        }),
        new TextureAttachment({
            name: "normal",
            uv_index: 0,
            read(m) {
                return m.normalMap;
            },
            write(m, t) {
                m.normalMap = t;
            }
        }),
        taDisplacement,
        new TextureAttachment({
            name: "roughness",
            uv_index: 0,
            read(m) {
                return m.roughnessMap;
            },
            write(m, t) {
                m.roughnessMap = t;
            }
        }),
        new TextureAttachment({
            name: "metalness",
            uv_index: 0,
            read(m) {
                return m.metalnessMap;
            },
            write(m, t) {
                m.metalnessMap = t;
            }
        }),
        new TextureAttachment({
            name: "environment",
            uv_index: 0,
            read(m) {
                return m.envMap;
            },
            write(m, t) {
                m.envMap = t;
            }
        })
    ]
};

TextureAttachmentsByMaterialType.MeshPhysicalMaterial = TextureAttachmentsByMaterialType.MeshStandardMaterial;
