Kaynağa Gözat

Merge pull request #16148 from Temdog007/editor/ColorFix

Editor: Convert textures to sRGB encoding
Mr.doob 6 yıl önce
ebeveyn
işleme
c4893ef841

+ 47 - 0
editor/js/Menubar.Edit.js

@@ -199,6 +199,53 @@ Menubar.Edit = function ( editor ) {
 	} );
 	} );
 	options.add( option );
 	options.add( option );
 
 
+	options.add( new UI.HorizontalRule() );
+
+	// Set textures to sRGB. See #15903
+
+	var option = new UI.Row();
+	option.setClass( 'option' );
+	option.setTextContent( strings.getKey( 'menubar/edit/fixcolormaps' ) );
+	option.onClick(function()
+	{
+		editor.scene.traverse(fixColorMap);
+	});
+	options.add(option);
+
+	var colorMaps = ['map', 'envMap', 'emissiveMap'];
+
+	function fixColorMap(obj)
+	{
+		var material = obj.material;
+		if(Array.isArray(material) === true)
+		{
+			for(var i = 0; i < material.length; ++i)
+			{
+				fixMaterial(material[i]);
+			}
+		}
+		else if(material !== undefined)
+		{
+			fixMaterial(material);
+		}
+
+		editor.signals.sceneGraphChanged.dispatch();
+	}
+
+	function fixMaterial(material)
+	{
+		var needsUpdate = material.needsUpdate;
+		for(var i = 0; i < colorMaps.length; ++i)
+		{
+			var map = material[colorMaps[i]];
+			if(map)
+			{
+				map.encoding = THREE.sRGBEncoding;
+				needsUpdate = true;
+			}
+		}
+		material.needsUpdate = needsUpdate;
+	}
 
 
 	return container;
 	return container;
 
 

+ 25 - 3
editor/js/Sidebar.Material.js

@@ -289,7 +289,7 @@ Sidebar.Material = function ( editor ) {
 
 
 	var materialMapRow = new UI.Row();
 	var materialMapRow = new UI.Row();
 	var materialMapEnabled = new UI.Checkbox( false ).onChange( update );
 	var materialMapEnabled = new UI.Checkbox( false ).onChange( update );
-	var materialMap = new UI.Texture().onChange( update );
+	var materialMap = new UI.Texture().onChange( updateMaterial );
 
 
 	materialMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/map' ) ).setWidth( '90px' ) );
 	materialMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/map' ) ).setWidth( '90px' ) );
 	materialMapRow.add( materialMapEnabled );
 	materialMapRow.add( materialMapEnabled );
@@ -401,7 +401,7 @@ Sidebar.Material = function ( editor ) {
 
 
 	var materialEnvMapRow = new UI.Row();
 	var materialEnvMapRow = new UI.Row();
 	var materialEnvMapEnabled = new UI.Checkbox( false ).onChange( update );
 	var materialEnvMapEnabled = new UI.Checkbox( false ).onChange( update );
-	var materialEnvMap = new UI.Texture( THREE.SphericalReflectionMapping ).onChange( update );
+	var materialEnvMap = new UI.Texture( THREE.SphericalReflectionMapping ).onChange( updateMaterial );
 	var materialReflectivity = new UI.Number( 1 ).setWidth( '30px' ).onChange( update );
 	var materialReflectivity = new UI.Number( 1 ).setWidth( '30px' ).onChange( update );
 
 
 	materialEnvMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/envmap' ) ).setWidth( '90px' ) );
 	materialEnvMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/envmap' ) ).setWidth( '90px' ) );
@@ -441,7 +441,7 @@ Sidebar.Material = function ( editor ) {
 
 
 	var materialEmissiveMapRow = new UI.Row();
 	var materialEmissiveMapRow = new UI.Row();
 	var materialEmissiveMapEnabled = new UI.Checkbox( false ).onChange( update );
 	var materialEmissiveMapEnabled = new UI.Checkbox( false ).onChange( update );
-	var materialEmissiveMap = new UI.Texture().onChange( update );
+	var materialEmissiveMap = new UI.Texture().onChange( updateMaterial );
 
 
 	materialEmissiveMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/emissivemap' ) ).setWidth( '90px' ) );
 	materialEmissiveMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/emissivemap' ) ).setWidth( '90px' ) );
 	materialEmissiveMapRow.add( materialEmissiveMapEnabled );
 	materialEmissiveMapRow.add( materialEmissiveMapEnabled );
@@ -1061,6 +1061,28 @@ Sidebar.Material = function ( editor ) {
 
 
 	}
 	}
 
 
+	function updateMaterial( texture ) {
+
+		if ( texture !== null ) {
+
+			if ( texture.encoding !== THREE.sRGBEncoding ) {
+
+				texture.encoding = THREE.sRGBEncoding;
+				var object = currentObject;
+				if ( object !== null ) {
+
+					object.material.needsUpdate = true;
+
+				}
+
+			}
+
+		}
+
+		update();
+
+	}
+
 	//
 	//
 
 
 	function setRowVisibility() {
 	function setRowVisibility() {

+ 1 - 0
editor/js/Strings.js

@@ -31,6 +31,7 @@ var Strings = function ( config ) {
 			'menubar/edit/clone': 'Clone',
 			'menubar/edit/clone': 'Clone',
 			'menubar/edit/delete': 'Delete (Del)',
 			'menubar/edit/delete': 'Delete (Del)',
 			'menubar/edit/minify_shaders': 'Minify Shaders',
 			'menubar/edit/minify_shaders': 'Minify Shaders',
+			'menubar/edit/fixcolormaps': 'Fix Color Maps',
 
 
 			'menubar/add': 'Add',
 			'menubar/add': 'Add',
 			'menubar/add/group': 'Group',
 			'menubar/add/group': 'Group',

+ 20 - 3
editor/js/libs/ui.three.js

@@ -64,7 +64,7 @@ UI.Texture = function ( mapping ) {
 
 
 					scope.setValue( texture );
 					scope.setValue( texture );
 
 
-					if ( scope.onChangeCallback ) scope.onChangeCallback();
+					if ( scope.onChangeCallback ) scope.onChangeCallback( texture );
 
 
 				}, false );
 				}, false );
 
 
@@ -75,7 +75,7 @@ UI.Texture = function ( mapping ) {
 				reader.addEventListener( 'load', function ( event ) {
 				reader.addEventListener( 'load', function ( event ) {
 
 
 					var image = document.createElement( 'img' );
 					var image = document.createElement( 'img' );
-					image.addEventListener( 'load', function( event ) {
+					image.addEventListener( 'load', function ( event ) {
 
 
 						var texture = new THREE.Texture( this, mapping );
 						var texture = new THREE.Texture( this, mapping );
 						texture.sourceFile = file.name;
 						texture.sourceFile = file.name;
@@ -84,7 +84,7 @@ UI.Texture = function ( mapping ) {
 
 
 						scope.setValue( texture );
 						scope.setValue( texture );
 
 
-						if ( scope.onChangeCallback ) scope.onChangeCallback();
+						if ( scope.onChangeCallback ) scope.onChangeCallback( texture );
 
 
 					}, false );
 					}, false );
 
 
@@ -161,6 +161,19 @@ UI.Texture.prototype.setValue = function ( texture ) {
 
 
 };
 };
 
 
+UI.Texture.prototype.setEncoding = function ( encoding ) {
+
+	var texture = this.getValue();
+	if ( texture !== null ) {
+
+		texture.encoding = encoding;
+
+	}
+
+	return this;
+
+};
+
 UI.Texture.prototype.onChange = function ( callback ) {
 UI.Texture.prototype.onChange = function ( callback ) {
 
 
 	this.onChangeCallback = callback;
 	this.onChangeCallback = callback;
@@ -188,11 +201,13 @@ UI.Outliner = function ( editor ) {
 	dom.addEventListener( 'keydown', function ( event ) {
 	dom.addEventListener( 'keydown', function ( event ) {
 
 
 		switch ( event.keyCode ) {
 		switch ( event.keyCode ) {
+
 			case 38: // up
 			case 38: // up
 			case 40: // down
 			case 40: // down
 				event.preventDefault();
 				event.preventDefault();
 				event.stopPropagation();
 				event.stopPropagation();
 				break;
 				break;
+
 		}
 		}
 
 
 	}, false );
 	}, false );
@@ -201,12 +216,14 @@ UI.Outliner = function ( editor ) {
 	dom.addEventListener( 'keyup', function ( event ) {
 	dom.addEventListener( 'keyup', function ( event ) {
 
 
 		switch ( event.keyCode ) {
 		switch ( event.keyCode ) {
+
 			case 38: // up
 			case 38: // up
 				scope.selectIndex( scope.selectedIndex - 1 );
 				scope.selectIndex( scope.selectedIndex - 1 );
 				break;
 				break;
 			case 40: // down
 			case 40: // down
 				scope.selectIndex( scope.selectedIndex + 1 );
 				scope.selectIndex( scope.selectedIndex + 1 );
 				break;
 				break;
+
 		}
 		}
 
 
 	}, false );
 	}, false );