diff --git a/src/js/main.js b/src/js/main.js index d21fd54..b9e383f 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -20,6 +20,25 @@ const PBR1_THREEJSMAPPING = { "metalness" : "metalnessMap", "opacity" : "alphaMap" }, + + // These are the "base" settings for ThreeJS if a specific map is active. + // This ensures, for example, that the metalness property is always actually active (set to 1) if a metalness map is used. + mapActiveSettings : { + "color" : ["color",new THREE.Color( 0xffffff )], + "normal": [null,null], + "roughness":["roughness",1], + "displacement":[null,null], + "metalness":["metalness",1], + "opacity":["opacity",1] + }, + mapInactiveSettings: { + "color" : ["color",new THREE.Color( 0xdddddd )], + "normal": [null,null], + "roughness":["roughness",0.5], + "displacement":[null,null], + "metalness":["metalness",0], + "opacity":["opacity",1] + }, encoding : { "sRGB": THREE.sRGBEncoding, "linear": THREE.LinearEncoding diff --git a/src/js/pbr-material.js b/src/js/pbr-material.js index 180be76..070dbfd 100644 --- a/src/js/pbr-material.js +++ b/src/js/pbr-material.js @@ -54,7 +54,23 @@ function updateScene(incomingSceneConfiguration,fallbackType){ texture.wrapT = THREE.RepeatWrapping; texture.encoding = PBR1_THREEJSMAPPING.encoding[newSceneConfiguration[`${mapName}_encoding`]]; texture.repeat.set( 1, 1 ); + + // Apply additional settings to ensure that the maps actually have an effect + + if(PBR1_THREEJSMAPPING.mapActiveSettings[mapName][0] != null){ + PBR1_ELEMENTS.mesh.material[PBR1_THREEJSMAPPING.mapActiveSettings[mapName][0]] = PBR1_THREEJSMAPPING.mapActiveSettings[mapName][1]; + console.log(PBR1_THREEJSMAPPING.mapActiveSettings[mapName][0]); + } + }else{ + + // Apply additional settings to ensure that the missing map is replaced with a sensible default + + if(PBR1_THREEJSMAPPING.mapActiveSettings[mapName][0] != null){ + PBR1_ELEMENTS.mesh.material[PBR1_THREEJSMAPPING.mapInactiveSettings[mapName][0]] = PBR1_THREEJSMAPPING.mapInactiveSettings[mapName][1]; + console.log(PBR1_THREEJSMAPPING.mapActiveSettings[mapName][0]); + } + var texture = null; }