diff --git a/lib/VRMatToPhysical.js b/lib/VRMatToPhysical.js index bb032a7..347be90 100644 --- a/lib/VRMatToPhysical.js +++ b/lib/VRMatToPhysical.js @@ -1,290 +1,302 @@ var _ = require('underscore'); -var extractPhysical = function( varMatGraph ) { +var extractPhysical = function(varMatGraph) {}; -}; - -var getRootNodes = function( graph ) { +var getRootNodes = function(graph) { var rootNodes = []; - var collectRootNodes = function( nodeName ) { + var collectRootNodes = function(nodeName) { var node = graph.nodes[nodeName]; var connectedCount = 0; - _.forEach( Object.keys( node.outputs ), function( outputName ) { + _.forEach(Object.keys(node.outputs), function(outputName) { var output = node.outputs[outputName]; - if( output.isConnected() ) { - connectedCount ++; + if (output.isConnected()) { + connectedCount++; } //console.log( "output.isConnected()", output.isConnected(), node.path() ); - } ); + }); - if( connectedCount === 0 ) { - rootNodes.push( node ); + if (connectedCount === 0) { + rootNodes.push(node); } }; - _.forEach( Object.keys( graph.nodes ), collectRootNodes ); + _.forEach(Object.keys(graph.nodes), collectRootNodes); return rootNodes; }; -var getDiffuseColor = function( rootNode ) { - return 0; -} +var getDiffuseColor = function(rootNode) { + return 0; +}; -var nodeTreeToString = function( node, prefix ) { +var nodeTreeToString = function(node, prefix) { //console.log( node, prefix ); - console.log( prefix + node.label + " [" + node.spec.name + "]" ); + console.log(prefix + node.label + ' [' + node.spec.name + ']'); var prefix2 = prefix + ' '; - for( var inputName in node.inputs ) { + for (var inputName in node.inputs) { var input = node.inputs[inputName]; //console.log( input ); - var text = prefix2 + '.' + inputName + " <" + input.spec.type + "> = "; + var text = prefix2 + '.' + inputName + ' <' + input.spec.type + '> = '; var nodeValue = input.value; - if( nodeValue && nodeValue.node ) { - console.log( text ); - nodeTreeToString( nodeValue.node, prefix2 + ' ' ); - } - else { - console.log( text + JSON.stringify( nodeValue ) ); + if (nodeValue && nodeValue.node) { + console.log(text); + nodeTreeToString(nodeValue.node, prefix2 + ' '); + } else { + console.log(text + JSON.stringify(nodeValue)); } } -} +}; -var treeToString = function( graph ) { - var rootNodes = getRootNodes( graph ); - for( var i in rootNodes ) { - console.log( nodeTreeToString( rootNodes[i], '' ) ); +var treeToString = function(graph) { + var rootNodes = getRootNodes(graph); + for (var i in rootNodes) { + console.log(nodeTreeToString(rootNodes[i], '')); } +}; -} - -var collectNodeInputVariations = function( nodes, nodeInputVariations ) { +var collectNodeInputVariations = function(nodes, nodeInputVariations) { nodeInputVariations = nodeInputVariations || {}; - _.each( nodes, function( node ) { - var inputVariations = nodeInputVariations[ node.spec.name ] || {}; - nodeInputVariations[ node.spec.name ] = inputVariations; + _.each(nodes, function(node) { + var inputVariations = nodeInputVariations[node.spec.name] || {}; + nodeInputVariations[node.spec.name] = inputVariations; - _.each( node.inputs, function( input ) { + _.each(node.inputs, function(input) { var inputValue = input.value; - if( inputValue === undefined || inputValue === null ) { - inputValue = "" - } - var variations = inputVariations[ input.spec.name ] || {}; - inputVariations[ input.spec.name ] = variations; - if( inputValue.spec ) { - inputValue = "<" + inputValue.node.spec.name + ">"; + if (inputValue === undefined || inputValue === null) { + inputValue = ''; } - else { - inputValue = JSON.stringify( inputValue ); + var variations = inputVariations[input.spec.name] || {}; + inputVariations[input.spec.name] = variations; + if (inputValue.spec) { + inputValue = '<' + inputValue.node.spec.name + '>'; + } else { + inputValue = JSON.stringify(inputValue); } - variations[ inputValue ] = ( variations[ inputValue ] || 0 ) + 1; + variations[inputValue] = (variations[inputValue] || 0) + 1; }); }); return nodeInputVariations; -} - -var identifyVaryingNodeInputs = function( nodeInputVariations ) { - var varyingNodeInputs = {}; - _.each( nodeInputVariations, function( inputVariations, nodeSpecName ) { - _.each( inputVariations, function( variations, inputSpecName ) { - var numVariations = Object.keys( variations ).length; - if( numVariations > 1 ) { - var fullName = nodeSpecName + '.' + inputSpecName; - varyingNodeInputs[ fullName ] = variations; - } - }); +}; + +var identifyVaryingNodeInputs = function(nodeInputVariations) { + var varyingNodeInputs = {}; + _.each(nodeInputVariations, function(inputVariations, nodeSpecName) { + _.each(inputVariations, function(variations, inputSpecName) { + var numVariations = Object.keys(variations).length; + if (numVariations > 1) { + var fullName = nodeSpecName + '.' + inputSpecName; + varyingNodeInputs[fullName] = variations; + } }); + }); - return varyingNodeInputs; -} + return varyingNodeInputs; +}; -var findBaseBRDFVRayMtl = function( node, optionalNodePath ) { - if( ! node ) return null; +var findBaseBRDFVRayMtl = function(node, optionalNodePath) { + if (!node) return null; - if( optionalNodePath ) { - optionalNodePath.push( node ); + if (optionalNodePath) { + optionalNodePath.push(node); } //console.log( 'findPrimaryBRDFVRayMtl', node.label, node.spec.name ); - switch( node.spec.name ) { - - case "BRDFVRayMtl": + switch (node.spec.name) { + case 'BRDFVRayMtl': return node; - case "MtlSingleBRDF": + case 'MtlSingleBRDF': var input = node.inputs['brdf']; - if( input && input.isConnected() ) { + if (input && input.isConnected()) { //console.log( 'connected input', input ); - return findBaseBRDFVRayMtl( input.value.node, optionalNodePath ); + return findBaseBRDFVRayMtl(input.value.node, optionalNodePath); } break; - case "MtlASGVIS": + case 'MtlASGVIS': case 'BRDFLayered': - // get last brdf - for( var i = 10; i >= 0; i -- ) { + // get last brdf + for (var i = 10; i >= 0; i--) { var inputName = 'brdfs' + i; - var input = node.inputs[ inputName ]; - if( input && input.isConnected() ) { - return findBaseBRDFVRayMtl( input.value.node, optionalNodePath ) + var input = node.inputs[inputName]; + if (input && input.isConnected()) { + return findBaseBRDFVRayMtl(input.value.node, optionalNodePath); } } break; - } - console.log( "ERROR, can not traverse node in findBaseBRDFVRayMtl: " + node.label + " <" + node.spec.name + ">"); + console.log( + 'ERROR, can not traverse node in findBaseBRDFVRayMtl: ' + + node.label + + ' <' + + node.spec.name + + '>' + ); return null; -} +}; -var clampColor = function( color ) { +var clampColor = function(color) { return { - r: Math.max( Math.min( 1.0, color.r ), 0.0 ), - g: Math.max( Math.min( 1.0, color.g ), 0.0 ), - b: Math.max( Math.min( 1.0, color.b ), 0.0 ) + r: Math.max(Math.min(1.0, color.r), 0.0), + g: Math.max(Math.min(1.0, color.g), 0.0), + b: Math.max(Math.min(1.0, color.b), 0.0), }; -} +}; -var getColorFromInput = function( input, isFalloff, optionalNodePath ) { - var result = null; - if( input ) { +var getColorFromInput = function(input, isFalloff, ignoreTexture) { + if (input) { //console.log( 'getBaseColorFromInput: input', input.path() ); - if( input.isConnected() ) { - result = findColorInNode(input.value.node, isFalloff, optionalNodePath); + if (input.isConnected()) { + return findColor(input.value.node, isFalloff, null, ignoreTexture); } var colorValue = input.value; - if(( colorValue !== null )&&( colorValue !== undefined )&&( colorValue.r !== undefined )&&( colorValue.g !== undefined )&&( colorValue.b !== undefined )) { - result = colorValue; + if ( + colorValue !== null && + colorValue !== undefined && + colorValue.r !== undefined && + colorValue.g !== undefined && + colorValue.b !== undefined + ) { + return colorValue; } } - if (!result) { - result = { r: 1, g: 1, b: 1 }; - } - return result; -} -var findColorInNode = function( node, isFalloff, optionalNodePath ) { + return { r: 1, g: 1, b: 1 }; +}; + +var findColor = function(node, isFalloff, optionalNodePath, ignoreTexture) { //console.log( 'findBaseColor: node', node.path() ); var resultColor = { r: 0, g: 0, b: 0 }; - if( optionalNodePath ) { - optionalNodePath.push( node ); + if (!node) return resultColor; + + if (optionalNodePath) { + optionalNodePath.push(node); } - switch( node.spec.name ) { - - case "TexCombineColor": - var multiplier = node.inputs['texture_multiplier'].value; - if (multiplier === undefined) multiplier = 1.0; - - var color = node.inputs['color']; - var texture = node.inputs['texture']; - - if (texture && texture.isConnected()) { - // it's a valid texture, let get its color - texture = getColorFromInput(texture, isFalloff, optionalNodePath); - resultColor.r = texture.r * multiplier; - resultColor.g = texture.g * multiplier; - resultColor.b = texture.b * multiplier; - - if (color && multiplier < 1) { - // interpolate - color = color.value; - var inv = 1.0 - multiplier; - resultColor.r += color.r * inv; - resultColor.g += color.g * inv; - resultColor.b += color.b * inv; - } - } - else { + //console.log( 'findPrimaryBRDFVRayMtl', node.label, node.spec.name ); + + //console.log( 'findColor', node.spec.name ); + switch (node.spec.name) { + case 'TexCombineColor': + var gotTexture = false; + var input = node.inputs['texture']; + if (input && input.isConnected()) { + var color = findColor( + input.value.node, + isFalloff, + optionalNodePath, + ignoreTexture + ); if (color) { - color = color.value; - resultColor.r = color.r; - resultColor.g = color.g; - resultColor.b = color.b; + //console.log( "TexCombineColor texture: ", color ); + resultColor.r += color.r; + resultColor.g += color.g; + resultColor.b += color.b; + gotTexture = true; } - //else resultColor stays black } - break; + //console.log( 'texture_multiplier', node.inputs['texture_multiplier'] ? node.inputs['texture_multiplier'].value : null ); + //console.log( 'result_multiplier', node.inputs['result_multiplier'] ? node.inputs['result_multiplier'].value : null ); + + var colorInput = node.inputs['color']; + var color = colorInput.value; + if (color && (ignoreTexture || !gotTexture)) { + //console.log( "TexCombineColor color: ", color ); + resultColor.r += color.r; + resultColor.g += color.g; + resultColor.b += color.b; + } - case "TexFalloff": - var input = node.inputs[ isFalloff ? 'color2' : 'color1']; - if( input && input.isConnected() ) { - var color = getColorFromInput(input, false, optionalNodePath); - if( color ) { - //console.log( "TexFalloff color: ", color ); - resultColor.r = color.r; - resultColor.g = color.g; - resultColor.b = color.b; + //console.log( "TexCombineColor resultColor: ", resultColor ); + return clampColor(resultColor); + + case 'TexFalloff': + var input = node.inputs[isFalloff ? 'color2' : 'color1']; + if (input && input.isConnected()) { + var color = findColor( + input.value.node, + false, + optionalNodePath, + ignoreTexture + ); + if (color) { + //console.log( "TexFalloff color: ", color ); + resultColor.r += color.r; + resultColor.g += color.g; + resultColor.b += color.b; } } - break; + return clampColor(resultColor); } + //console.log( "ERROR, can not traverse node in findBaseColor: " + node.label + " <" + node.spec.name + ">"); + //nodeTreeToString( node, '' ); return resultColor; -} +}; -var findTexBitmap = function( node, isFalloff, optionalNodePath ) { +var findTexBitmap = function(node, isFalloff, optionalNodePath) { //console.log( 'findBaseTexBitmap: node', node.path() ); - if( ! node ) return null; + if (!node) return null; - if( optionalNodePath ) { - optionalNodePath.push( node ); + if (optionalNodePath) { + optionalNodePath.push(node); } //console.log( 'findPrimaryBRDFVRayMtl', node.label, node.spec.name ); - switch( node.spec.name ) { - - case "TexBitmap": + switch (node.spec.name) { + case 'TexBitmap': return node; - case "TexCombineColor": + case 'TexCombineColor': var input = node.inputs['texture']; - if( input && input.isConnected() ) { + if (input && input.isConnected()) { //console.log( 'connected input', input ); - return findTexBitmap( input.value.node, isFalloff, optionalNodePath ); + return findTexBitmap(input.value.node, isFalloff, optionalNodePath); } break; - case "TexFalloff": - var input = node.inputs[ isFalloff ? 'color2' : 'color1']; - if( input && input.isConnected() ) { + case 'TexFalloff': + var input = node.inputs[isFalloff ? 'color2' : 'color1']; + if (input && input.isConnected()) { //console.log( 'connected input', input ); - return findTexBitmap( input.value.node, false, optionalNodePath ); + return findTexBitmap(input.value.node, false, optionalNodePath); } break; } //console.log( "ERROR, can not traverse node in findBaseTexBitmap: " + node.label + " <" + node.spec.name + ">"); //nodeTreeToString( node, '' ); return null; -} +}; -var getImagePropertiesFromTexBitmap = function( node ) { - if( ! node ) return null; - if( node.spec.name !== "TexBitmap" ) throw new Error( "unknown node type: " + node.spec.name ); +var getImagePropertiesFromTexBitmap = function(node) { + if (!node) return null; + if (node.spec.name !== 'TexBitmap') + throw new Error('unknown node type: ' + node.spec.name); var properties = {}; var uvwGen = node.inputs['uvwgen'].value.node; - if( uvwGen ) { + if (uvwGen) { properties['wrap'] = { - x: ( uvwGen.inputs['wrap_u'].value === 1 ), - y: ( uvwGen.inputs['wrap_v'].value === 1 ) + x: uvwGen.inputs['wrap_u'].value === 1, + y: uvwGen.inputs['wrap_v'].value === 1, }; - var safeInverse = function( a ) { - if( a ) return 1.0 / a; + var safeInverse = function(a) { + if (a) return 1.0 / a; return 1.0; - } + }; var transformComponents = uvwGen.inputs['uvw_transform'].value; - if( transformComponents ) { + if (transformComponents) { properties['repeat'] = { - x: parseFloat( transformComponents.scale.x ), - y: parseFloat( transformComponents.scale.y ) + x: parseFloat(transformComponents.scale.x), + y: parseFloat(transformComponents.scale.y), }; properties['offset'] = { - x: parseFloat( transformComponents.translation.x ), - y: parseFloat( transformComponents.translation.y ) + x: parseFloat(transformComponents.translation.x), + y: parseFloat(transformComponents.translation.y), }; } } @@ -292,164 +304,200 @@ var getImagePropertiesFromTexBitmap = function( node ) { properties['invert'] = false; var bitmapInput = node.inputs['bitmap']; - if( bitmapInput.isConnected() ) { + if (bitmapInput.isConnected()) { var bitmapBuffer = bitmapInput.value.node; - if( bitmapBuffer ) { + if (bitmapBuffer) { var fileName = bitmapBuffer.inputs['file'].value; - if( fileName ) { + if (fileName) { properties['fileName'] = fileName; } } } return properties; -} +}; -var getImageFromInput = function( input, isFalloff ) { +var getImageFromInput = function(input, isFalloff) { //console.log( 'getImageFromInput: input', input.path() ); - if( ! input || ! input.value ) return null; - if( ! input.isConnected() ) return null; - var bitmapTex = findTexBitmap( input.value.node, isFalloff ); - if( ! bitmapTex ) return null; - return getImagePropertiesFromTexBitmap( bitmapTex ); -} - -var getBumpPropertiesFromNode = function( node ) { + if (!input || !input.value) return null; + if (!input.isConnected()) return null; + var bitmapTex = findTexBitmap(input.value.node, isFalloff); + if (!bitmapTex) return null; + return getImagePropertiesFromTexBitmap(bitmapTex); +}; - var bumpOnInput = node.inputs[ 'bump_on' ]; - if( bumpOnInput && bumpOnInput.value ) { +var getBumpPropertiesFromNode = function(node) { + var bumpOnInput = node.inputs['bump_on']; + if (bumpOnInput && bumpOnInput.value) { var properties = {}; var bumpScale = node.inputs['bump_tex_mult']; properties['bumpScale'] = bumpScale.value; - properties['bumpMap'] = getImageFromInput( node.inputs['bump_tex'] ); + properties['bumpMap'] = getImageFromInput(node.inputs['bump_tex']); return properties; } var connectedInputs = node.outputs['default'].connectedInputs; - for( var uuid in connectedInputs ) { + for (var uuid in connectedInputs) { var input = connectedInputs[uuid]; - return getBumpPropertiesFromNode( input.node ); + return getBumpPropertiesFromNode(input.node); } return null; -} - -/** - * Multiple cases for 'map' and 'color' properties that need to be matched together - */ -function mapColorProperties(properties, propMap, propColor, propSrc, node, isFalloff) { - properties[propMap] = getImageFromInput(node.inputs[propSrc], isFalloff); - if (properties[propMap]) { - properties[propColor] = { r:1, g:1, b:1 }; - } - else { - properties[propColor] = clampColor(getColorFromInput(node.inputs[propSrc], isFalloff)); - } }; -var getPhysicalPropertiesFromBRDFVRayMtl = function( node ) { - if( ! node ) return { - 'baseColor': { r:1, g:1, b:0} - } - - if( node.spec.name !== "BRDFVRayMtl" ) throw new Error( "unknown node type: " + node.spec.name ); +var gamma = 1.0 / 2.2; +var gammaCorrection = function(color) { + return { + r: Math.pow(color.r, gamma), + g: Math.pow(color.g, gamma), + b: Math.pow(color.b, gamma), + }; +}; - var properties = {}; +var getPhysicalPropertiesFromBRDFVRayMtl = function(node) { + if (!node) + return { + baseColor: { r: 1, g: 1, b: 0 }, + }; - mapColorProperties(properties, 'baseMap', 'baseColor', 'diffuse', node, false); + if (node.spec.name !== 'BRDFVRayMtl') + throw new Error('unknown node type: ' + node.spec.name); - properties['baseFalloff'] = true; - mapColorProperties(properties, 'baseFalloffMap', 'baseFalloffColor', 'diffuse', node, true); + var properties = {}; + properties['baseMap'] = getImageFromInput(node.inputs['diffuse'], false); + if (properties['baseMap']) { + properties['baseColor'] = { r: 1, g: 1, b: 1 }; + } else { + properties['baseColor'] = gammaCorrection( + getColorFromInput(node.inputs['diffuse'], false) + ); + } - if( _.isEqual( properties['baseMap'], properties['baseFalloffMap'] ) ) { - delete properties['baseFalloffMap']; - if( _.isEqual( properties['baseColor'], properties['baseFalloffColor'] ) ) { - delete properties['baseFalloffColor']; - properties['baseFalloff'] = false; - } + properties['baseFalloffMap'] = getImageFromInput( + node.inputs['diffuse'], + true + ); + if (properties['baseFalloffMap']) { + properties['baseFalloffColor'] = { r: 1, g: 1, b: 1 }; + } else { + properties['baseFalloffColor'] = gammaCorrection( + getColorFromInput(node.inputs['diffuse'], true) + ); } - var refractColor = clampColor(getColorFromInput( node.inputs['refract'], false )); - var refractMono = ( refractColor.r + refractColor.g + refractColor.b ) * 0.3333333; + var refractColor = getColorFromInput(node.inputs['refract'], false); + var refractMono = + (refractColor.r + refractColor.g + refractColor.b) * 0.3333333; var opacity = 1.0 - refractMono; properties['opacityFactor'] = opacity; - properties['opacityMap'] = getImageFromInput( node.inputs['refract'], false ); - if( properties['opacityMap'] ) { - properties['opacityMap']['invert'] = ! properties['opacityMap']['invert']; + properties['opacityMap'] = getImageFromInput(node.inputs['refract'], false); + if (properties['opacityMap']) { + properties['opacityMap']['invert'] = !properties['opacityMap']['invert']; } - if( properties['opacityFactor'] === 1 ) { - var opacityColor = clampColor(getColorFromInput( node.inputs['opacity'], false )); - var opacityMono = ( opacityColor.r + opacityColor.g + opacityColor.b ) * 0.3333333; + if (properties['opacityFactor'] === 1.0) { + var opacityColor = getColorFromInput(node.inputs['opacity'], false, true); // we want the real factor, even if there's a texture + var opacityMono = + (opacityColor.r + opacityColor.g + opacityColor.b) * 0.3333333; properties['opacityFactor'] = opacityMono; } - if( ! properties['opacityMap'] ) { - properties['opacityMap'] = getImageFromInput( node.inputs['opacity'], false ); + if (!properties['opacityMap']) { + properties['opacityMap'] = getImageFromInput(node.inputs['opacity'], false); + } + + properties['baseFalloff'] = true; + if (_.isEqual(properties['baseMap'], properties['baseFalloffMap'])) { + delete properties['baseFalloffMap']; + if (_.isEqual(properties['baseColor'], properties['baseFalloffColor'])) { + delete properties['baseFalloffColor']; + properties['baseFalloff'] = false; + } } - properties['roughness'] = clampColor(getColorFromInput( node.inputs['reflect_glossiness'], false )).r; - if( properties['roughness'] ) { - properties['roughness'] = Math.sqrt( 1 - properties['roughness'] ); + properties['roughness'] = getColorFromInput( + node.inputs['reflect_glossiness'], + false + ).r; + if (properties['roughness'] !== undefined) { + properties['roughness'] = Math.sqrt(1 - properties['roughness']); } - properties['roughnessMap'] = getImageFromInput( node.inputs['reflect_glossiness'], false ); - if( properties['roughnessMap'] ) { + properties['roughnessMap'] = getImageFromInput( + node.inputs['reflect_glossiness'], + false + ); + if (properties['roughnessMap']) { properties['roughnessMap']['invert'] = true; } - var bumpProperties = getBumpPropertiesFromNode( node ); - if( bumpProperties ) { - properties = _.extend( properties, bumpProperties ); + var reflectColor = gammaCorrection( + getColorFromInput(node.inputs['reflect'], false) + ); + var reflectMap = getImageFromInput(node.inputs['reflect'], false); + if (reflectMap) { + reflectColor.r = 1.0; + reflectColor.g = 1.0; + reflectColor.b = 1.0; } + // var reflectIntensity = 0.0; + var baseColor = properties['baseColor']; + if ( + !properties['baseMap'] && + baseColor.r === 0.0 && + baseColor.g === 0.0 && + baseColor.b === 0.0 && + (reflectMap || + reflectColor.r > 0.0 || + reflectColor.g > 0.0 || + reflectColor.b > 0.0) + ) { + properties['metallic'] = 1.0; + properties['baseColor'] = reflectColor; + properties['baseMap'] = reflectMap; + reflectMap = null; + } else { + // var reflectIntensity = Math.max(reflectColor.r, reflectColor.g, reflectColor.b) * 0.5; + // properties['specularColor'] = { r: reflectIntensity, g: reflectIntensity, b: reflectIntensity }; + // properties['specularMap' ] = reflectMap; + } + //*/ - // base color / metallic interpolation using fresnel - // map [1:12.1] --> [0:1] - var fresnel = (getColorFromInput(node.inputs['fresnel_ior'], false).r - 1.0) / 11.1; - fresnel = Math.min(1.0, Math.max(0.0, fresnel)); - - // set the metallic value - properties['metallic'] = fresnel; // because 1.0 for metallic is too much - properties['metallicMap'] = getImageFromInput( node.inputs['reflect'], false ); - - // adjust the base color (if it's set) - if (!properties['baseMap']) { - var baseColor = properties['baseColor']; - baseColor.r += (1.0 - baseColor.r)*fresnel; - baseColor.g += (1.0 - baseColor.g)*fresnel; - baseColor.b += (1.0 - baseColor.b)*fresnel; + var bumpProperties = getBumpPropertiesFromNode(node); + if (bumpProperties) { + properties = _.extend(properties, bumpProperties); } //console.log( "physicalProperties", properties ); + return properties; }; -var getPhysicalPropertiesFromVRMat = function( vrMat ) { - var rootNodes = getRootNodes( vrMat ); - if( rootNodes.length !== 1) { +var getPhysicalPropertiesFromVRMat = function(vrMat) { + var rootNodes = getRootNodes(vrMat); + if (rootNodes.length !== 1) { var bestRootNode = null; //console.log( "num of rootNodes: ", rootNodes.length, " num of total nodes:", Object.keys( vrMat.nodes ).length ); - for( var i = 0; i < rootNodes.length; i ++ ) { + for (var i = 0; i < rootNodes.length; i++) { //console.log( 'rootNode', rootNodes[i].label, rootNodes[i].spec.type, rootNodes[i].spec.name, rootNodes[i].spec.outputs.default.type ); - if( rootNodes[i].spec.outputs.default.type === "material" ) { + if (rootNodes[i].spec.outputs.default.type === 'material') { bestRootNode = rootNodes[i]; } } - if( bestRootNode ) { - rootNodes = [ bestRootNode ]; - } - else { + if (bestRootNode) { + rootNodes = [bestRootNode]; + } else { return { - 'baseColor': { r:1, g:0, b:0} + baseColor: { r: 1, g: 0, b: 0 }, }; } } - var baseBRDFVRayMtl = findBaseBRDFVRayMtl( rootNodes[0] ); + var baseBRDFVRayMtl = findBaseBRDFVRayMtl(rootNodes[0]); //nodeTreeToString( baseBRDFVRayMtl, '' ); //console.log( 'primary BRDF VRay Mtl: ' + baseBRDFVRayMtl.path() + " <" + baseBRDFVRayMtl.spec.name + ">"); - return getPhysicalPropertiesFromBRDFVRayMtl( baseBRDFVRayMtl ); -} + return getPhysicalPropertiesFromBRDFVRayMtl(baseBRDFVRayMtl); +}; module.exports = { extractPhysical: extractPhysical,