Explorar o código

Add script to fix color maps

Temdog007 %!s(int64=6) %!d(string=hai) anos
pai
achega
d55958ea47
Modificáronse 2 ficheiros con 48 adicións e 0 borrados
  1. 47 0
      editor/js/Menubar.Edit.js
  2. 1 0
      editor/js/Strings.js

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

@@ -199,6 +199,53 @@ Menubar.Edit = function ( editor ) {
 	} );
 	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;
 

+ 1 - 0
editor/js/Strings.js

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