mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2025-01-30 19:42:59 -05:00
Fix texture options ending up in texture filename #109
This happens when in `*.mtl` a relative texture path does not have a `./` prefix. eg: map_bump -bm 0.1 foo.jpg
This commit is contained in:
parent
3cff129933
commit
3e41cdc7f6
@ -205,31 +205,40 @@ loadMtl._createMaterial = function(materialOptions, options) {
|
||||
*/
|
||||
function parseMapOptions (texturePath, textureOptions) {
|
||||
|
||||
var re = /[\\\/]-(bm|t|s|o|blendu|blendv|boost|mm|texres|clamp|imfchan|type)/;
|
||||
var re = /[\\\/]-(bm|t|s|o|blendu|blendv|boost|mm|texres|clamp|imfchan|type)/;
|
||||
|
||||
if (!re.test(texturePath)) {
|
||||
return;
|
||||
}
|
||||
if (!re.test(texturePath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var pathParts = texturePath.split(/[\\\/]/);
|
||||
if (re.test('/'+path.basename(texturePath))) {
|
||||
// options ended up in filename, eg: map_bump -bm 0.1 foo.jpg
|
||||
// assume no spaces in texture filename
|
||||
var parts = path.basename(texturePath).split(/\s+/);
|
||||
var texture = parts.pop();
|
||||
// handle options below
|
||||
texturePath = path.join(path.dirname(texturePath), parts.join(' '), texture);
|
||||
}
|
||||
|
||||
if (pathParts.length && pathParts.length > 2) {
|
||||
var mapOptions = pathParts[pathParts.length - 2].split(/\s+/);
|
||||
var currPart = null;
|
||||
var pathParts = texturePath.split(/[\\\/]/);
|
||||
|
||||
mapOptions.reduce(function (p, part) {
|
||||
if (re.test('/'+part)) {
|
||||
currPart = part;
|
||||
p[part] = [];
|
||||
} else if (currPart) {
|
||||
p[currPart].push(part);
|
||||
}
|
||||
return p;
|
||||
}, textureOptions);
|
||||
if (pathParts.length && pathParts.length > 2) {
|
||||
var mapOptions = pathParts[pathParts.length - 2].split(/\s+/);
|
||||
var currPart = null;
|
||||
|
||||
pathParts.splice(pathParts.length - 2, 1);
|
||||
return path.join.apply(null, pathParts);
|
||||
}
|
||||
mapOptions.reduce(function (p, part) {
|
||||
if (re.test('/'+part)) {
|
||||
currPart = part;
|
||||
p[part] = [];
|
||||
} else if (currPart) {
|
||||
p[currPart].push(part);
|
||||
}
|
||||
return p;
|
||||
}, textureOptions);
|
||||
|
||||
pathParts.splice(pathParts.length - 2, 1);
|
||||
return path.join.apply(null, pathParts);
|
||||
}
|
||||
}
|
||||
|
||||
function loadMaterialTexture(material, name, texturePath, textureOptions, mtlDirectory, texturePromiseMap, texturePromises, options) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user