mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2025-01-31 03:53:13 -05:00
fix texture paths and parse texture map options
When the mtl has statements like ```map_Bump -bm 0.2 ./foo.jpg``` then the options end up in the texture path. eg: ```./-bm 0.2/foo.jpg```. This commit fixes the path and parses the options.
This commit is contained in:
parent
8f3f0d3862
commit
ac756bed05
@ -195,10 +195,52 @@ loadMtl._createMaterial = function(materialOptions, options) {
|
|||||||
return convertMaterial(combine(materialOptions, new Material()), options);
|
return convertMaterial(combine(materialOptions, new Material()), options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses texture map options like -o, -s, -bm which end up in the texturePath
|
||||||
|
*
|
||||||
|
* @param {String} texturePath The original texture path
|
||||||
|
* @param {Object} textureOptions This object will be filled with the options
|
||||||
|
*
|
||||||
|
* @return {String} The fixed texturePath or undefined when there's no texture options
|
||||||
|
*/
|
||||||
|
function parseMapOptions (texturePath, textureOptions) {
|
||||||
|
|
||||||
|
if (!/-(bm|t|s|o|blendu|blendv|boost|mm|texres|clamp|imfchan|type)\s+/.test(texturePath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pathParts = texturePath.split(/[\\\/]/);
|
||||||
|
|
||||||
|
if (pathParts.length && pathParts.length > 2) {
|
||||||
|
var mapOptions = pathParts[pathParts.length - 2].split(/\s+/);
|
||||||
|
var currPart = null;
|
||||||
|
|
||||||
|
mapOptions.reduce(function (p, part) {
|
||||||
|
if (/-/.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) {
|
function loadMaterialTexture(material, name, texturePath, textureOptions, mtlDirectory, texturePromiseMap, texturePromises, options) {
|
||||||
if (!defined(texturePath)) {
|
if (!defined(texturePath)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mapOptions = {};
|
||||||
|
var newTexturePath = parseMapOptions(texturePath, mapOptions);
|
||||||
|
// TODO: handle texture options
|
||||||
|
// NOTE: this might not be a good place to do this
|
||||||
|
texturePath = newTexturePath ? newTexturePath : texturePath;
|
||||||
|
|
||||||
var texturePromise = texturePromiseMap[texturePath];
|
var texturePromise = texturePromiseMap[texturePath];
|
||||||
if (!defined(texturePromise)) {
|
if (!defined(texturePromise)) {
|
||||||
if (options.secure && outsideDirectory(texturePath, mtlDirectory)) {
|
if (options.secure && outsideDirectory(texturePath, mtlDirectory)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user