Skip to content

Commit

Permalink
Make sure underlying material base values are correct
Browse files Browse the repository at this point in the history
  • Loading branch information
struffel committed Jul 12, 2022
1 parent 1f683b5 commit 83f2159
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/js/pbr-material.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 83f2159

Please sign in to comment.