Source: Thing.Extend/Resources/ImageTexture.js

const path = require('path');

/**
 * @description THING.ImageTexture ThingUE拓展版,支持设置纹理sRGB属性
 * @class ImageTexture
 */
class ImageTexture extends THING.ImageTexture {

    #sRGB;

    constructor(param = {}) {
        super(param);
        this.#sRGB = THING.Utils.parseValue(param['sRGB'], false);
    }

    _updateTextureResource() {
        super._updateTextureResource();
        let textureResource = this.context;
        textureResource && textureResource.enable('sRGB', this.#sRGB);
    }

    _loadFromURL(param) {
        let onLoad = THING.Utils.parseValue(param['onLoad'], null);

        this._url = this.parseUrl(param['url']);
        this._updateUrl();

        // Set options
        // if (param['wrapType']) {
        //     this.wrapType = param['wrapType'];
        // }

        this.wrapType = THING.Utils.parseValue(param['wrapType'], THING.ImageWrapType.ClampToEdge);
        this.mappingType = THING.Utils.parseValue(param['mappingType'], THING.ImageMappingType.UV);
        this.flipY = THING.Utils.parseValue(param['flipY'], true);
        let _sRGB = THING.Utils.parseValue(param['sRGB'], false);
        let _filterType = THING.Utils.parseValue(param['minFilterType'], THING.ImageFilterType.LinearFilter);

        THING.Utils.loadImageFile(this._url,
            // Load
            (image) => {
                this._image = image;

                this.onFixupFromImage(image);

                if (onLoad) {
                    onLoad({ image: this });
                }

                this.onNotifyComplete();
            },
            // Progress
            (ev) => {

            },
            // Error
            (ev) => {
                this.onTriggerErrorEvent(ev);
            },
            {
                flipY: this.flipY,
                premultiplyAlpha: this.premultiplyAlpha,
                generateMipmaps: this.generateMipmaps,
                wrapType: this.wrapType,
                sRGB: _sRGB,
                filter: _filterType,
                extensions: THING.Utils.getCurrentApp().view.getExtensions()
            }
        );
    }

    get sRGB() {
        return this.#sRGB;
    }

    /**
     * @param {Boolean} value - true is sRGB color space, false is Linear color space.
     */
    set sRGB(value) {
        if (this.#sRGB == value) {
            return;
        }
        this.#sRGB = value;
        this._updateTextureResource();
    }
    
    parseUrl(url) {
        if (url.startsWith("/") || url.startsWith("./") || url.startsWith("../")) {
            return path.join(`${UE.Application.getProjectDirectoryFull()}/`, url);
        }
        return url;
    }
}

module.exports = ImageTexture;