* Load a texture file. * * @param {String} texturePath Path to the texture file. * @param {Object} [options] An object with the following properties: * @param {Boolean} [options.checkTransparency=false] Do a more exhaustive check for texture transparency by looking at the alpha channel of each p
(texturePath, options)
| 25 | * @private |
| 26 | */ |
| 27 | function loadTexture(texturePath, options) { |
| 28 | options = defaultValue(options, {}); |
| 29 | options.checkTransparency = defaultValue(options.checkTransparency, false); |
| 30 | options.decode = defaultValue(options.decode, false); |
| 31 | options.keepSource = defaultValue(options.keepSource, false); |
| 32 | |
| 33 | return fsExtra.readFile(texturePath).then(function (source) { |
| 34 | const name = path.basename(texturePath, path.extname(texturePath)); |
| 35 | const extension = path.extname(texturePath).toLowerCase(); |
| 36 | const texture = new Texture(); |
| 37 | texture.source = source; |
| 38 | texture.name = name; |
| 39 | texture.extension = extension; |
| 40 | texture.path = texturePath; |
| 41 | |
| 42 | let decodePromise; |
| 43 | if (extension === ".png") { |
| 44 | decodePromise = decodePng(texture, options); |
| 45 | } else if (extension === ".jpg" || extension === ".jpeg") { |
| 46 | decodePromise = decodeJpeg(texture, options); |
| 47 | } |
| 48 | |
| 49 | if (defined(decodePromise)) { |
| 50 | return decodePromise.then(function () { |
| 51 | return texture; |
| 52 | }); |
| 53 | } |
| 54 | |
| 55 | return texture; |
| 56 | }); |
| 57 | } |
| 58 | |
| 59 | function hasTransparency(pixels) { |
| 60 | const pixelsLength = pixels.length / 4; |
no test coverage detected