Forum

m_rgba = require("rgba"); blend4web Module "rgba" not found

08 March 2019 01:22
As the title says I am having issues when trying to prepare m_rgba with an error of "blend4web Module "rgba" not found"

found this https://www.blend4web.com/en/forums/topic/4198/

but I don't have an index.js within the web player directory
08 March 2019 19:33
I get that error too, LOL. Looks like they never fixed it. The "temporary fix" does not work for me. It still says "module not found".

No problem though, because rgba is extremely short, only 5 functions and 40 lines of actual code. You can quickly edit it for direct use in your project's .js file. Like this:
var m_rgba = {};

var _rgb_tmp = new Float32Array(3);
var GAMMA = 2.2;

function lin_to_srgb(color, dest) {
    dest[0] = Math.pow(color[0], 1/GAMMA);
    dest[1] = Math.pow(color[1], 1/GAMMA);
    dest[2] = Math.pow(color[2], 1/GAMMA);
    return dest;
}

m_rgba.create = function() {
    var dest = new Float32Array(4);
    dest[3] = 1;
    return dest;
};

m_rgba.from_values = function (r, g, b, a) {
    var dest = new Float32Array(4);
    dest[0] = r;
    dest[1] = g;
    dest[2] = b;
    dest[3] = a;
    return dest;
};

m_rgba.set = function(r, g, b, a, dest) {
    dest[0] = r;
    dest[1] = g;
    dest[2] = b;
    dest[3] = a;
    return dest;
};

m_rgba.css_to_rgba = function(css_red, css_green, css_blue, css_alpha, dest) {

    dest = dest || new Float32Array(4);

    dest[0] = css_red / 255;
    dest[1] = css_green / 255;
    dest[2] = css_blue / 255;
    dest[3] = css_alpha;
    m_util.srgb_to_lin(dest, dest);

    return dest;
}

m_rgba.rgba_to_css = function(rgba) {

    var srgb = lin_to_srgb(rgba, _rgb_tmp);

    return [Math.round(255*srgb[0]), Math.round(255*srgb[1]), 
            Math.round(255*srgb[2]), rgba[3]];
}

Remove the m_rgba module loader line that does not work and insert the above into your .js file instead. Now you can use the RGBA functions just as if the module was loaded, with the same syntax.
09 March 2019 01:42
That's awesome, thank you so much!
 
Please register or log in to leave a reply.