Improved Material Editor performances eliminating unnecessary GUI updates
authorMimmo Briganti
Sat Apr 30 11:21:21 2011 +0200 (12 months ago)
changeset 104bb5b3bb77c81
parent 103 c2a0f1a63cfc
child 105 932275a31231
Improved Material Editor performances eliminating unnecessary GUI updates
Cleaned up code for writing LuxRender material file
su2lux.rb
su2lux/LuxrenderExport.rb
su2lux/LuxrenderMaterialEditor.rb
     1.1 --- a/su2lux.rb	Sat Apr 30 11:19:30 2011 +0200
     1.2 +++ b/su2lux.rb	Sat Apr 30 11:21:21 2011 +0200
     1.3 @@ -627,13 +627,16 @@
     1.4  
     1.5  class SU2LUX_materials_observer < Sketchup::MaterialsObserver
     1.6  	def onMaterialSetCurrent(materials, material)
     1.7 +		SU2LUX.dbg_p "onMaterialSetCurrent: #{material.name}"
     1.8  		material_editor = SU2LUX.get_editor("material")
     1.9 -		luxmat = LuxrenderMaterial.new(material)
    1.10  		if (material_editor)
    1.11 +			luxmat = LuxrenderMaterial.new(material)
    1.12  			material_editor.set_current(luxmat.name)
    1.13  			material_editor.current = luxmat
    1.14 -			material_editor.sendDataFromSketchup
    1.15 -			material_editor.fire_event("#type", "change", "")
    1.16 +			if (material_editor.visible?)
    1.17 +				material_editor.sendDataFromSketchup
    1.18 +				material_editor.fire_event("#type", "change", "")
    1.19 +			end
    1.20  		end
    1.21  	end
    1.22  	
    1.23 @@ -641,6 +644,7 @@
    1.24  		SU2LUX.create_material_editor
    1.25  		material_editor = SU2LUX.get_editor("material")
    1.26  		material_editor.refresh() if (material_editor);
    1.27 +		SU2LUX.dbg_p "onMaterialAdd"
    1.28  		# material_editor.set_material_list() if (material_editor)
    1.29  		# luxmat = LuxrenderMaterial.new(material)
    1.30  		# material_editor.set_current(luxmat.name) if (material_editor)
    1.31 @@ -650,6 +654,7 @@
    1.32  		SU2LUX.create_material_editor
    1.33  		material_editor = SU2LUX.get_editor("material")
    1.34  		material_editor.refresh() if (material_editor);
    1.35 +		SU2LUX.dbg_p "onMaterialRemove"
    1.36  		# material_editor.set_material_list() if (material_editor)
    1.37  		# luxmat = LuxrenderMaterial.new(material)
    1.38  		# material_editor.set_current(luxmat.name) if (material_editor)
     2.1 --- a/su2lux/LuxrenderExport.rb	Sat Apr 30 11:19:30 2011 +0200
     2.2 +++ b/su2lux/LuxrenderExport.rb	Sat Apr 30 11:21:21 2011 +0200
     2.3 @@ -1054,124 +1054,66 @@
     2.4  		out.puts "# Material '" + mat.name + "'"
     2.5  		heading = "MakeNamedMaterial \"#{mat.name}\"" + "\n"
     2.6  		heading += "\"string type\" [\"#{mat.type}\"]" + "\n"
     2.7 +		pre = ""
     2.8 +		post = ""
     2.9  		case mat.type
    2.10  			when "matte"
    2.11 -				components = self.export_diffuse_component(mat)
    2.12 -				pre = components[0]
    2.13 -				post = components[1]
    2.14 +				pre, post = self.export_diffuse_component(mat, pre, post)
    2.15  				post += "\"float sigma\" [#{mat.matte_sigma}]"
    2.16  			when "glossy"
    2.17 -				components = self.export_diffuse_component(mat)
    2.18 -				pre = components[0]
    2.19 -				post = components[1]
    2.20 -				components =  self.export_specular_component(mat)
    2.21 -				pre += components[0]
    2.22 -				post += components[1]
    2.23 -				components = self.export_exponent(mat)
    2.24 -				pre += components[0]
    2.25 -				post += components[1]
    2.26 +				pre, post = self.export_diffuse_component(mat, pre, post)
    2.27 +				pre, post =  self.export_specular_component(mat, pre, post)
    2.28 +				pre, post = self.export_exponent(mat, pre, post)
    2.29  				post += "\"float index\" [0.000000]"
    2.30 -				components = self.export_absorption_component(mat)
    2.31 -				pre += components[0]
    2.32 -				post += components[1]
    2.33 +				pre, post = self.export_absorption_component(mat, pre, post)
    2.34  				multibounce = mat.multibounce ? "true": "false"
    2.35  				post += "\"bool multibounce\" [\"#{multibounce}\"]"
    2.36  			when "glass"
    2.37 -				components = self.export_reflection_component(mat)
    2.38 -				pre = components[0]
    2.39 -				post = components[1]
    2.40 -				components = self.export_transmission_component(mat)
    2.41 -				pre += components[0]
    2.42 -				post += components[1]
    2.43 -				components = export_IOR(mat)
    2.44 -				pre += components[0]
    2.45 -				post += components[1]
    2.46 +				pre, post = self.export_reflection_component(mat, pre, post)
    2.47 +				pre, post = self.export_transmission_component(mat, pre, post)
    2.48 +				pre, post = export_IOR(mat, pre, post)
    2.49  				architectural = mat.use_architectural ? "true" : "false"
    2.50  				post += "\t\"bool architectural\" [\"#{architectural}\"]"
    2.51  				if ( ! mat.use_architectural)
    2.52 -					components = export_thin_film(mat)
    2.53 -					pre += components[0]
    2.54 -					post += components[1]
    2.55 -					components = export_dispersive_refraction(mat)
    2.56 -					pre += components[0]
    2.57 -					post += components[1]
    2.58 +					pre, post = export_thin_film(mat, pre, post)
    2.59 +					pre, post = export_dispersive_refraction(mat, pre, post)
    2.60  				end
    2.61  			when "roughglass"
    2.62 -				components = self.export_reflection_component(mat)
    2.63 -				pre = components[0]
    2.64 -				post = components[1]
    2.65 -				components = self.export_transmission_component(mat)
    2.66 -				pre += components[0]
    2.67 -				post += components[1]
    2.68 -				components = export_IOR(mat)
    2.69 -				pre += components[0]
    2.70 -				post += components[1]
    2.71 -				components = export_dispersive_refraction(mat)
    2.72 -				pre += components[0]
    2.73 -				post += components[1]
    2.74 +				pre, post = self.export_reflection_component(mat, pre, post)
    2.75 +				pre, post = self.export_transmission_component(mat, pre, post)
    2.76 +				pre, post = export_IOR(mat, pre, post)
    2.77 +				pre, post = export_dispersive_refraction(mat, pre, post)
    2.78  			when "metal"
    2.79 -				components = export_nk(mat)
    2.80 -				pre = components[0]
    2.81 -				post = components[1]
    2.82 -				components = self.export_exponent(mat)
    2.83 -				pre += components[0]
    2.84 -				post += components[1]
    2.85 +				pre, post = export_nk(mat, pre, post)
    2.86 +				pre, post = self.export_exponent(mat, pre, post)
    2.87  			when "shinymetal"
    2.88 -				components = self.export_reflection_component(mat)
    2.89 -				pre = components[0]
    2.90 -				post = components[1]
    2.91 -				components = self.export_specular_component(mat)
    2.92 -				pre += components[0]
    2.93 -				post += components[1]
    2.94 -				components = self.export_exponent(mat)
    2.95 -				pre += components[0]
    2.96 -				post += components[1]
    2.97 -				components = export_thin_film(mat)
    2.98 -				pre += components[0]
    2.99 -				post += components[1]
   2.100 +				pre, post = self.export_reflection_component(mat, pre, post)
   2.101 +				pre, post = self.export_specular_component(mat, pre, post)
   2.102 +				pre, post = self.export_exponent(mat, pre, post)
   2.103 +				pre, post = export_thin_film(mat, pre, post)
   2.104  			when "mirror"
   2.105 -				components = self.export_reflection_component(mat)
   2.106 -				pre = components[0]
   2.107 -				post = components[1]
   2.108 -				components = export_thin_film(mat)
   2.109 -				pre += components[0]
   2.110 -				post += components[1]
   2.111 +				pre, post = self.export_reflection_component(mat, pre, post)
   2.112 +				pre, post = export_thin_film(mat, pre, post)
   2.113  			when "mattetranslucent"
   2.114 -				components = self.export_reflection_component(mat)
   2.115 -				pre = components[0]
   2.116 -				post = components[1]
   2.117 -				components = self.export_transmission_component(mat)
   2.118 -				pre += components[0]
   2.119 -				post += components[1]
   2.120 +				pre, post = self.export_reflection_component(mat, pre, post)
   2.121 +				pre, post = self.export_transmission_component(mat, pre, post)
   2.122  				energyconserving = mat.energyconserving ? "true": "false"
   2.123  				post += "\"bool energyconserving\" [\"#{energyconserving}\"]"
   2.124  				post += "\"float sigma\" [#{mat.matte_sigma}]"
   2.125  			when "glossytranslucent"
   2.126 -				components = self.export_diffuse_component(mat)
   2.127 -				pre = components[0]
   2.128 -				post = components[1]
   2.129 -				components = self.export_transmission_component(mat)
   2.130 -				pre += components[0]
   2.131 -				post += components[1]
   2.132 -				components = self.export_specular_component(mat)
   2.133 -				pre += components[0]
   2.134 -				post += components[1]
   2.135 -				components = self.export_exponent(mat)
   2.136 -				pre += components[0]
   2.137 -				post += components[1]
   2.138 +				pre, post = self.export_diffuse_component(mat, pre, post)
   2.139 +				pre, post = self.export_transmission_component(mat, pre, post)
   2.140 +				pre, post = self.export_specular_component(mat, pre, post)
   2.141 +				pre, post = self.export_exponent(mat, pre, post)
   2.142  				post += "\"float index\" [0.000000]"
   2.143 -				components = self.export_absorption_component(mat)
   2.144 -				pre += components[0]
   2.145 -				post += components[1]
   2.146 +				pre, post = self.export_absorption_component(mat, pre, post)
   2.147  				multibounce = mat.multibounce ? "true": "false"
   2.148  				post += "\"bool multibounce\" [\"#{multibounce}\"]"
   2.149  			when "light"
   2.150 -				post = export_mesh_light(mat)
   2.151 +				post += export_mesh_light(mat)
   2.152  		end
   2.153  		if (mat.use_bump)
   2.154 -			components = export_bump(mat)
   2.155 -			pre += components[0]
   2.156 -			post += components[1]
   2.157 +			pre, post = export_bump(mat, pre, post)
   2.158  		end
   2.159  		if (mat.type == "light")
   2.160  			out.puts post
   2.161 @@ -1186,7 +1128,7 @@
   2.162  	##
   2.163  	#
   2.164  	##
   2.165 -	def export_diffuse_component(material)
   2.166 +	def export_diffuse_component(material, before, after)
   2.167  		preceding = ""
   2.168  		following = ""
   2.169  		filled = true
   2.170 @@ -1217,27 +1159,27 @@
   2.171  			end
   2.172  			following += "\"texture Kd\" [\"#{material.name}::Kd.scale\"]" + "\n"
   2.173  		end
   2.174 -		return [preceding, following]
   2.175 +		return [before + preceding, after + following]
   2.176  		# return filled ? component : color_component
   2.177  	end
   2.178  	
   2.179  	##
   2.180  	#
   2.181  	##
   2.182 -	def export_specular_component(material)
   2.183 +	def export_specular_component(material, befor, after)
   2.184  		preceding = ""
   2.185  		following = ""
   2.186  		filled = true
   2.187  		if ( ! material.use_specular_texture)
   2.188  			following += "\"color Ks\" [#{"%.6f" %(material.specular[0])} #{"%.6f" %(material.specular[1])} #{"%.6f" %(material.specular[2])}]"
   2.189  		end
   2.190 -		return [preceding, following]
   2.191 +		return [before + preceding, after + following]
   2.192  	end
   2.193  	
   2.194  	##
   2.195  	#
   2.196  	##
   2.197 -	def export_exponent(material)
   2.198 +	def export_exponent(material, before, after)
   2.199  		preceding = ""
   2.200  		following = ""
   2.201  		filled = true
   2.202 @@ -1246,7 +1188,7 @@
   2.203  			following += "\"float uroughness\" [#{"%.6f" %(u_roughness)}]" + "\n"
   2.204  			following += "\"float vroughness\" [#{"%.6f" %(u_roughness)}]"
   2.205  		end
   2.206 -		return [preceding, following]
   2.207 +		return [before + preceding, after + following]
   2.208  	end
   2.209  	
   2.210  	##
   2.211 @@ -1260,7 +1202,7 @@
   2.212  			following += "\"float index\" [#{material.glossy_index}]"
   2.213  		else
   2.214  		end
   2.215 -		return [preceding, following]
   2.216 +		return [before + preceding, after + following]
   2.217  	end
   2.218  	
   2.219  	##
   2.220 @@ -1278,7 +1220,7 @@
   2.221  				following += "\"float d\" [#{"%.6f" %(material.ka_d)}]"
   2.222  			end
   2.223  		end
   2.224 -		return [preceding, following]
   2.225 +		return [before + preceding, after + following]
   2.226  	end
   2.227  	
   2.228  	##
   2.229 @@ -1289,7 +1231,7 @@
   2.230  		following = ""
   2.231  		filled = true
   2.232  		following += "\"string name\" [\"#{material.nk_preset}\"]"
   2.233 -		return [preceding, following]
   2.234 +		return [before + preceding, after + following]
   2.235  	end
   2.236  
   2.237  	##
   2.238 @@ -1302,7 +1244,7 @@
   2.239  		if ( ! material.use_reflection_texture)
   2.240  			following += "\"color Kr\" [#{"%.6f" %(material.kr_R)} #{"%.6f" %(material.kr_G)} #{"%.6f" %(material.kr_B)}]" + "\n"
   2.241  		end
   2.242 -		return [preceding, following]
   2.243 +		return [before + preceding, after + following]
   2.244  	end
   2.245  
   2.246  	##
   2.247 @@ -1315,7 +1257,7 @@
   2.248  		if ( ! material.use_reflection_texture)
   2.249  			following += "\"color Kt\" [#{"%.6f" %(material.kt_R)} #{"%.6f" %(material.kt_G)} #{"%.6f" %(material.kt_B)}]" + "\n"
   2.250  		end
   2.251 -		return [preceding, following]
   2.252 +		return [before + preceding, after + following]
   2.253  	end
   2.254  	
   2.255  	##
   2.256 @@ -1333,7 +1275,7 @@
   2.257  				following += "\"float filmindex\" [#{"%.6f" %(material.film_index)}]" + "\n"
   2.258  			end
   2.259  		end
   2.260 -		return [preceding, following]
   2.261 +		return [before + preceding, after + following]
   2.262  	end
   2.263  	
   2.264  	##
   2.265 @@ -1348,13 +1290,13 @@
   2.266  				following += "\"float cauchyb\" [#{"%.6f" %(material.cauchyb)}]" + "\n"
   2.267  			end
   2.268  		end
   2.269 -		return [preceding, following]
   2.270 +		return [before + preceding, after + following]
   2.271  	end
   2.272  	
   2.273  	##
   2.274  	#
   2.275  	##
   2.276 -	def export_bump(material)
   2.277 +	def export_bump(material, before, after)
   2.278  		preceding = ""
   2.279  		following = ""
   2.280  		filled = true
   2.281 @@ -1381,7 +1323,7 @@
   2.282  			preceding += "Texture \"#{material.name}::bumpmap.scale\" \"float\" \"scale\" \"texture tex1\" [\"#{material.name}::bumpmap\"] \"float tex2\" [#{material.bumpmap}]" + "\n"
   2.283  			following += "\"texture bumpmap\" [\"#{material.name}::bumpmap.scale\"]" + "\n"
   2.284  		end
   2.285 -		return [preceding, following]
   2.286 +		return [before + preceding, after + following]
   2.287  	end
   2.288  
   2.289  	##
     3.1 --- a/su2lux/LuxrenderMaterialEditor.rb	Sat Apr 30 11:19:30 2011 +0200
     3.2 +++ b/su2lux/LuxrenderMaterialEditor.rb	Sat Apr 30 11:21:21 2011 +0200
     3.3 @@ -68,7 +68,10 @@
     3.4  		@material_editor_dialog.add_action_callback('material_changed') { |dialog, material_name|
     3.5  			materials = Sketchup.active_model.materials
     3.6  			@current = self.find(material_name)
     3.7 -			materials.current = materials[material_name] if ( ! @current.nil?)
     3.8 +			SU2LUX.dbg_p "material_changed: #{materials.current.name}"
     3.9 +			if (material_name != materials.current.name)
    3.10 +				materials.current = materials[material_name] if ( ! @current.nil?)
    3.11 +			end
    3.12  			# updateSettingValue("type")
    3.13  			# self.sendDataFromSketchup()
    3.14  		}
    3.15 @@ -217,6 +220,7 @@
    3.16  	##
    3.17  	def set_current(name)
    3.18  		# cmd = "$(#material_name).attr('selected', 'selected'"
    3.19 +		SU2LUX.dbg_p "call to set_current: #{name}"
    3.20  		cmd = "$('#material_name option:contains(#{name})').attr('selected', true)"
    3.21  		@material_editor_dialog.execute_script(cmd)
    3.22  	end
    3.23 @@ -296,6 +300,7 @@
    3.24  		# setting = "type"
    3.25  		# setValue(setting, lux_material[setting])
    3.26  		# updateSettingValue(setting)
    3.27 +		SU2LUX.dbg_p "sendatafromsketchup"
    3.28  	end # END sendDataFromSketchup
    3.29  	
    3.30  	##