Only assign default material if obj file doesn't call usemtl

This commit is contained in:
Sean Lilley 2018-08-30 23:04:45 -04:00
parent 574d06db2b
commit 0c897a6847

View File

@ -502,7 +502,7 @@ function loadObj(objPath, options) {
uvs = undefined;
// Load materials and textures
return finishLoading(nodes, mtlPaths, objPath, options);
return finishLoading(nodes, mtlPaths, objPath, defined(activeMaterial), options);
});
}
@ -523,7 +523,7 @@ function getMtlPaths(mtllibLine) {
return mtlPaths;
}
function finishLoading(nodes, mtlPaths, objPath, options) {
function finishLoading(nodes, mtlPaths, objPath, usesMaterials, options) {
nodes = cleanNodes(nodes);
if (nodes.length === 0) {
throw new RuntimeError(objPath + ' does not have any geometry data');
@ -531,7 +531,9 @@ function finishLoading(nodes, mtlPaths, objPath, options) {
var name = path.basename(objPath, path.extname(objPath));
return loadMtls(mtlPaths, objPath, options)
.then(function(materials) {
assignDefaultMaterial(nodes, materials);
if (materials.length > 0 && !usesMaterials) {
assignDefaultMaterial(nodes, materials, usesMaterials);
}
return {
nodes : nodes,
materials : materials,
@ -591,9 +593,6 @@ function loadMtls(mtlPaths, objPath, options) {
}
function assignDefaultMaterial(nodes, materials) {
if (materials.length === 0) {
return;
}
var defaultMaterial = materials[0].name;
var nodesLength = nodes.length;
for (var i = 0; i < nodesLength; ++i) {