MCPcopy Index your code
hub / github.com/CesiumGS/obj2gltf / loadTexture

Function loadTexture

lib/loadTexture.js:27–57  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

25 * @private
26 */
27function 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
59function hasTransparency(pixels) {
60 const pixelsLength = pixels.length / 4;

Callers 3

loadMaterialTextureFunction · 0.85
loadMtlSpec.jsFile · 0.85
loadTextureSpec.jsFile · 0.85

Calls 3

decodePngFunction · 0.85
decodeJpegFunction · 0.85
defaultValueFunction · 0.70

Tested by

no test coverage detected