Sidebar.Material.js 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. Sidebar.Material = function ( editor ) {
  5. var strings = editor.strings;
  6. var signals = editor.signals;
  7. var currentObject;
  8. var currentMaterialSlot = 0;
  9. var container = new UI.Panel();
  10. container.setBorderTop( '0' );
  11. container.setDisplay( 'none' );
  12. container.setPaddingTop( '20px' );
  13. // New / Copy / Paste
  14. var copiedMaterial;
  15. var managerRow = new UI.Row();
  16. // Current material slot
  17. var materialSlotRow = new UI.Row();
  18. materialSlotRow.add( new UI.Text( 'Slot' ).setWidth( '90px' ) );
  19. var materialSlotSelect = new UI.Select().setWidth( '170px' ).setFontSize( '12px' ).onChange( update );
  20. materialSlotSelect.setOptions( { 0: '' } ).setValue( 0 );
  21. materialSlotRow.add( materialSlotSelect );
  22. container.add( materialSlotRow );
  23. managerRow.add( new UI.Text( '' ).setWidth( '90px' ) );
  24. managerRow.add( new UI.Button( strings.getKey( 'sidebar/material/new' ) ).onClick( function () {
  25. var material = new THREE[ materialClass.getValue() ]();
  26. editor.execute( new SetMaterialCommand( currentObject, material, currentMaterialSlot ), 'New Material: ' + materialClass.getValue() );
  27. update();
  28. } ) );
  29. managerRow.add( new UI.Button( strings.getKey( 'sidebar/material/copy' ) ).setMarginLeft( '4px' ).onClick( function () {
  30. copiedMaterial = currentObject.material;
  31. if ( Array.isArray( copiedMaterial ) ) {
  32. if ( copiedMaterial.length === 0 ) return;
  33. copiedMaterial = copiedMaterial[ currentMaterialSlot ];
  34. }
  35. } ) );
  36. managerRow.add( new UI.Button( strings.getKey( 'sidebar/material/paste' ) ).setMarginLeft( '4px' ).onClick( function () {
  37. if ( copiedMaterial === undefined ) return;
  38. editor.execute( new SetMaterialCommand( currentObject, copiedMaterial, currentMaterialSlot ), 'Pasted Material: ' + materialClass.getValue() );
  39. refreshUI();
  40. update();
  41. } ) );
  42. container.add( managerRow );
  43. // type
  44. var materialClassRow = new UI.Row();
  45. var materialClass = new UI.Select().setOptions( {
  46. 'LineBasicMaterial': 'LineBasicMaterial',
  47. 'LineDashedMaterial': 'LineDashedMaterial',
  48. 'MeshBasicMaterial': 'MeshBasicMaterial',
  49. 'MeshDepthMaterial': 'MeshDepthMaterial',
  50. 'MeshNormalMaterial': 'MeshNormalMaterial',
  51. 'MeshLambertMaterial': 'MeshLambertMaterial',
  52. 'MeshPhongMaterial': 'MeshPhongMaterial',
  53. 'MeshToonMaterial': 'MeshToonMaterial',
  54. 'MeshStandardMaterial': 'MeshStandardMaterial',
  55. 'MeshPhysicalMaterial': 'MeshPhysicalMaterial',
  56. 'ShaderMaterial': 'ShaderMaterial',
  57. 'SpriteMaterial': 'SpriteMaterial'
  58. } ).setWidth( '150px' ).setFontSize( '12px' ).onChange( update );
  59. materialClassRow.add( new UI.Text( strings.getKey( 'sidebar/material/type' ) ).setWidth( '90px' ) );
  60. materialClassRow.add( materialClass );
  61. container.add( materialClassRow );
  62. // uuid
  63. var materialUUIDRow = new UI.Row();
  64. var materialUUID = new UI.Input().setWidth( '102px' ).setFontSize( '12px' ).setDisabled( true );
  65. var materialUUIDRenew = new UI.Button( strings.getKey( 'sidebar/material/new' ) ).setMarginLeft( '7px' ).onClick( function () {
  66. materialUUID.setValue( THREE.Math.generateUUID() );
  67. update();
  68. } );
  69. materialUUIDRow.add( new UI.Text( strings.getKey( 'sidebar/material/uuid' ) ).setWidth( '90px' ) );
  70. materialUUIDRow.add( materialUUID );
  71. materialUUIDRow.add( materialUUIDRenew );
  72. container.add( materialUUIDRow );
  73. // name
  74. var materialNameRow = new UI.Row();
  75. var materialName = new UI.Input().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
  76. editor.execute( new SetMaterialValueCommand( editor.selected, 'name', materialName.getValue(), currentMaterialSlot ) );
  77. } );
  78. materialNameRow.add( new UI.Text( strings.getKey( 'sidebar/material/name' ) ).setWidth( '90px' ) );
  79. materialNameRow.add( materialName );
  80. container.add( materialNameRow );
  81. // program
  82. var materialProgramRow = new UI.Row();
  83. materialProgramRow.add( new UI.Text( strings.getKey( 'sidebar/material/program' ) ).setWidth( '90px' ) );
  84. var materialProgramInfo = new UI.Button( strings.getKey( 'sidebar/material/info' ) );
  85. materialProgramInfo.setMarginLeft( '4px' );
  86. materialProgramInfo.onClick( function () {
  87. signals.editScript.dispatch( currentObject, 'programInfo' );
  88. } );
  89. materialProgramRow.add( materialProgramInfo );
  90. var materialProgramVertex = new UI.Button( strings.getKey( 'sidebar/material/vertex' ) );
  91. materialProgramVertex.setMarginLeft( '4px' );
  92. materialProgramVertex.onClick( function () {
  93. signals.editScript.dispatch( currentObject, 'vertexShader' );
  94. } );
  95. materialProgramRow.add( materialProgramVertex );
  96. var materialProgramFragment = new UI.Button( strings.getKey( 'sidebar/material/fragment' ) );
  97. materialProgramFragment.setMarginLeft( '4px' );
  98. materialProgramFragment.onClick( function () {
  99. signals.editScript.dispatch( currentObject, 'fragmentShader' );
  100. } );
  101. materialProgramRow.add( materialProgramFragment );
  102. container.add( materialProgramRow );
  103. // color
  104. var materialColorRow = new UI.Row();
  105. var materialColor = new UI.Color().onChange( update );
  106. materialColorRow.add( new UI.Text( strings.getKey( 'sidebar/material/color' ) ).setWidth( '90px' ) );
  107. materialColorRow.add( materialColor );
  108. container.add( materialColorRow );
  109. // roughness
  110. var materialRoughnessRow = new UI.Row();
  111. var materialRoughness = new UI.Number( 0.5 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
  112. materialRoughnessRow.add( new UI.Text( strings.getKey( 'sidebar/material/roughness' ) ).setWidth( '90px' ) );
  113. materialRoughnessRow.add( materialRoughness );
  114. container.add( materialRoughnessRow );
  115. // metalness
  116. var materialMetalnessRow = new UI.Row();
  117. var materialMetalness = new UI.Number( 0.5 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
  118. materialMetalnessRow.add( new UI.Text( strings.getKey( 'sidebar/material/metalness' ) ).setWidth( '90px' ) );
  119. materialMetalnessRow.add( materialMetalness );
  120. container.add( materialMetalnessRow );
  121. // emissive
  122. var materialEmissiveRow = new UI.Row();
  123. var materialEmissive = new UI.Color().setHexValue( 0x000000 ).onChange( update );
  124. materialEmissiveRow.add( new UI.Text( strings.getKey( 'sidebar/material/emissive' ) ).setWidth( '90px' ) );
  125. materialEmissiveRow.add( materialEmissive );
  126. container.add( materialEmissiveRow );
  127. // specular
  128. var materialSpecularRow = new UI.Row();
  129. var materialSpecular = new UI.Color().setHexValue( 0x111111 ).onChange( update );
  130. materialSpecularRow.add( new UI.Text( strings.getKey( 'sidebar/material/specular' ) ).setWidth( '90px' ) );
  131. materialSpecularRow.add( materialSpecular );
  132. container.add( materialSpecularRow );
  133. // shininess
  134. var materialShininessRow = new UI.Row();
  135. var materialShininess = new UI.Number( 30 ).onChange( update );
  136. materialShininessRow.add( new UI.Text( strings.getKey( 'sidebar/material/shininess' ) ).setWidth( '90px' ) );
  137. materialShininessRow.add( materialShininess );
  138. container.add( materialShininessRow );
  139. // clearCoat
  140. var materialClearCoatRow = new UI.Row();
  141. var materialClearCoat = new UI.Number( 1 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
  142. materialClearCoatRow.add( new UI.Text( strings.getKey( 'sidebar/material/clearcoat' ) ).setWidth( '90px' ) );
  143. materialClearCoatRow.add( materialClearCoat );
  144. container.add( materialClearCoatRow );
  145. // clearCoatRoughness
  146. var materialClearCoatRoughnessRow = new UI.Row();
  147. var materialClearCoatRoughness = new UI.Number( 1 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
  148. materialClearCoatRoughnessRow.add( new UI.Text( strings.getKey( 'sidebar/material/clearcoatroughness' ) ).setWidth( '90px' ) );
  149. materialClearCoatRoughnessRow.add( materialClearCoatRoughness );
  150. container.add( materialClearCoatRoughnessRow );
  151. // vertex colors
  152. var materialVertexColorsRow = new UI.Row();
  153. var materialVertexColors = new UI.Select().setOptions( {
  154. 0: strings.getKey( 'sidebar/material/vertexcolors/no' ),
  155. 1: strings.getKey( 'sidebar/material/vertexcolors/face' ),
  156. 2: strings.getKey( 'sidebar/material/vertexcolors/vertex' )
  157. } ).onChange( update );
  158. materialVertexColorsRow.add( new UI.Text( strings.getKey( 'sidebar/material/vertexcolors' ) ).setWidth( '90px' ) );
  159. materialVertexColorsRow.add( materialVertexColors );
  160. container.add( materialVertexColorsRow );
  161. // skinning
  162. var materialSkinningRow = new UI.Row();
  163. var materialSkinning = new UI.Checkbox( false ).onChange( update );
  164. materialSkinningRow.add( new UI.Text( strings.getKey( 'sidebar/material/skinning' ) ).setWidth( '90px' ) );
  165. materialSkinningRow.add( materialSkinning );
  166. container.add( materialSkinningRow );
  167. // map
  168. var materialMapRow = new UI.Row();
  169. var materialMapEnabled = new UI.Checkbox( false ).onChange( update );
  170. var materialMap = new UI.Texture().onChange( update );
  171. materialMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/map' ) ).setWidth( '90px' ) );
  172. materialMapRow.add( materialMapEnabled );
  173. materialMapRow.add( materialMap );
  174. container.add( materialMapRow );
  175. // alpha map
  176. var materialAlphaMapRow = new UI.Row();
  177. var materialAlphaMapEnabled = new UI.Checkbox( false ).onChange( update );
  178. var materialAlphaMap = new UI.Texture().onChange( update );
  179. materialAlphaMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/alphamap' ) ).setWidth( '90px' ) );
  180. materialAlphaMapRow.add( materialAlphaMapEnabled );
  181. materialAlphaMapRow.add( materialAlphaMap );
  182. container.add( materialAlphaMapRow );
  183. // bump map
  184. var materialBumpMapRow = new UI.Row();
  185. var materialBumpMapEnabled = new UI.Checkbox( false ).onChange( update );
  186. var materialBumpMap = new UI.Texture().onChange( update );
  187. var materialBumpScale = new UI.Number( 1 ).setWidth( '30px' ).onChange( update );
  188. materialBumpMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/bumpmap' ) ).setWidth( '90px' ) );
  189. materialBumpMapRow.add( materialBumpMapEnabled );
  190. materialBumpMapRow.add( materialBumpMap );
  191. materialBumpMapRow.add( materialBumpScale );
  192. container.add( materialBumpMapRow );
  193. // normal map
  194. var materialNormalMapRow = new UI.Row();
  195. var materialNormalMapEnabled = new UI.Checkbox( false ).onChange( update );
  196. var materialNormalMap = new UI.Texture().onChange( update );
  197. materialNormalMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/normalmap' ) ).setWidth( '90px' ) );
  198. materialNormalMapRow.add( materialNormalMapEnabled );
  199. materialNormalMapRow.add( materialNormalMap );
  200. container.add( materialNormalMapRow );
  201. // displacement map
  202. var materialDisplacementMapRow = new UI.Row();
  203. var materialDisplacementMapEnabled = new UI.Checkbox( false ).onChange( update );
  204. var materialDisplacementMap = new UI.Texture().onChange( update );
  205. var materialDisplacementScale = new UI.Number( 1 ).setWidth( '30px' ).onChange( update );
  206. materialDisplacementMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/displacemap' ) ).setWidth( '90px' ) );
  207. materialDisplacementMapRow.add( materialDisplacementMapEnabled );
  208. materialDisplacementMapRow.add( materialDisplacementMap );
  209. materialDisplacementMapRow.add( materialDisplacementScale );
  210. container.add( materialDisplacementMapRow );
  211. // roughness map
  212. var materialRoughnessMapRow = new UI.Row();
  213. var materialRoughnessMapEnabled = new UI.Checkbox( false ).onChange( update );
  214. var materialRoughnessMap = new UI.Texture().onChange( update );
  215. materialRoughnessMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/roughmap' ) ).setWidth( '90px' ) );
  216. materialRoughnessMapRow.add( materialRoughnessMapEnabled );
  217. materialRoughnessMapRow.add( materialRoughnessMap );
  218. container.add( materialRoughnessMapRow );
  219. // metalness map
  220. var materialMetalnessMapRow = new UI.Row();
  221. var materialMetalnessMapEnabled = new UI.Checkbox( false ).onChange( update );
  222. var materialMetalnessMap = new UI.Texture().onChange( update );
  223. materialMetalnessMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/metalmap' ) ).setWidth( '90px' ) );
  224. materialMetalnessMapRow.add( materialMetalnessMapEnabled );
  225. materialMetalnessMapRow.add( materialMetalnessMap );
  226. container.add( materialMetalnessMapRow );
  227. // specular map
  228. var materialSpecularMapRow = new UI.Row();
  229. var materialSpecularMapEnabled = new UI.Checkbox( false ).onChange( update );
  230. var materialSpecularMap = new UI.Texture().onChange( update );
  231. materialSpecularMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/specularmap' ) ).setWidth( '90px' ) );
  232. materialSpecularMapRow.add( materialSpecularMapEnabled );
  233. materialSpecularMapRow.add( materialSpecularMap );
  234. container.add( materialSpecularMapRow );
  235. // env map
  236. var materialEnvMapRow = new UI.Row();
  237. var materialEnvMapEnabled = new UI.Checkbox( false ).onChange( update );
  238. var materialEnvMap = new UI.Texture( THREE.SphericalReflectionMapping ).onChange( update );
  239. var materialReflectivity = new UI.Number( 1 ).setWidth( '30px' ).onChange( update );
  240. materialEnvMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/envmap' ) ).setWidth( '90px' ) );
  241. materialEnvMapRow.add( materialEnvMapEnabled );
  242. materialEnvMapRow.add( materialEnvMap );
  243. materialEnvMapRow.add( materialReflectivity );
  244. container.add( materialEnvMapRow );
  245. // light map
  246. var materialLightMapRow = new UI.Row();
  247. var materialLightMapEnabled = new UI.Checkbox( false ).onChange( update );
  248. var materialLightMap = new UI.Texture().onChange( update );
  249. materialLightMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/lightmap' ) ).setWidth( '90px' ) );
  250. materialLightMapRow.add( materialLightMapEnabled );
  251. materialLightMapRow.add( materialLightMap );
  252. container.add( materialLightMapRow );
  253. // ambient occlusion map
  254. var materialAOMapRow = new UI.Row();
  255. var materialAOMapEnabled = new UI.Checkbox( false ).onChange( update );
  256. var materialAOMap = new UI.Texture().onChange( update );
  257. var materialAOScale = new UI.Number( 1 ).setRange( 0, 1 ).setWidth( '30px' ).onChange( update );
  258. materialAOMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/aomap' ) ).setWidth( '90px' ) );
  259. materialAOMapRow.add( materialAOMapEnabled );
  260. materialAOMapRow.add( materialAOMap );
  261. materialAOMapRow.add( materialAOScale );
  262. container.add( materialAOMapRow );
  263. // emissive map
  264. var materialEmissiveMapRow = new UI.Row();
  265. var materialEmissiveMapEnabled = new UI.Checkbox( false ).onChange( update );
  266. var materialEmissiveMap = new UI.Texture().onChange( update );
  267. materialEmissiveMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/emissivemap' ) ).setWidth( '90px' ) );
  268. materialEmissiveMapRow.add( materialEmissiveMapEnabled );
  269. materialEmissiveMapRow.add( materialEmissiveMap );
  270. container.add( materialEmissiveMapRow );
  271. // gradient map
  272. var materialGradientMapRow = new UI.Row();
  273. var materialGradientMapEnabled = new UI.Checkbox( false ).onChange( update );
  274. var materialGradientMap = new UI.Texture().onChange( update );
  275. materialGradientMapRow.add( new UI.Text( strings.getKey( 'sidebar/material/gradientmap' ) ).setWidth( '90px' ) );
  276. materialGradientMapRow.add( materialGradientMapEnabled );
  277. materialGradientMapRow.add( materialGradientMap );
  278. container.add( materialGradientMapRow );
  279. // side
  280. var materialSideRow = new UI.Row();
  281. var materialSide = new UI.Select().setOptions( {
  282. 0: strings.getKey( 'sidebar/material/side/front' ),
  283. 1: strings.getKey( 'sidebar/material/side/back' ),
  284. 2: strings.getKey( 'sidebar/material/side/double' )
  285. } ).setWidth( '150px' ).setFontSize( '12px' ).onChange( update );
  286. materialSideRow.add( new UI.Text( strings.getKey( 'sidebar/material/side' ) ).setWidth( '90px' ) );
  287. materialSideRow.add( materialSide );
  288. container.add( materialSideRow );
  289. // shading
  290. var materialShadingRow = new UI.Row();
  291. var materialShading = new UI.Checkbox( false ).setLeft( '100px' ).onChange( update );
  292. materialShadingRow.add( new UI.Text( strings.getKey( 'sidebar/material/flatshaded' ) ).setWidth( '90px' ) );
  293. materialShadingRow.add( materialShading );
  294. container.add( materialShadingRow );
  295. // blending
  296. var materialBlendingRow = new UI.Row();
  297. var materialBlending = new UI.Select().setOptions( {
  298. 0: strings.getKey( 'sidebar/material/blending/no' ),
  299. 1: strings.getKey( 'sidebar/material/blending/normal' ),
  300. 2: strings.getKey( 'sidebar/material/blending/additive' ),
  301. 3: strings.getKey( 'sidebar/material/blending/subtractive' ),
  302. 4: strings.getKey( 'sidebar/material/blending/multiply' ),
  303. 5: strings.getKey( 'sidebar/material/blending/custom' )
  304. } ).setWidth( '150px' ).setFontSize( '12px' ).onChange( update );
  305. materialBlendingRow.add( new UI.Text( strings.getKey( 'sidebar/material/blending' ) ).setWidth( '90px' ) );
  306. materialBlendingRow.add( materialBlending );
  307. container.add( materialBlendingRow );
  308. // opacity
  309. var materialOpacityRow = new UI.Row();
  310. var materialOpacity = new UI.Number( 1 ).setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
  311. materialOpacityRow.add( new UI.Text( strings.getKey( 'sidebar/material/opacity' ) ).setWidth( '90px' ) );
  312. materialOpacityRow.add( materialOpacity );
  313. container.add( materialOpacityRow );
  314. // transparent
  315. var materialTransparentRow = new UI.Row();
  316. var materialTransparent = new UI.Checkbox().setLeft( '100px' ).onChange( update );
  317. materialTransparentRow.add( new UI.Text( strings.getKey( 'sidebar/material/transparent' ) ).setWidth( '90px' ) );
  318. materialTransparentRow.add( materialTransparent );
  319. container.add( materialTransparentRow );
  320. // alpha test
  321. var materialAlphaTestRow = new UI.Row();
  322. var materialAlphaTest = new UI.Number().setWidth( '60px' ).setRange( 0, 1 ).onChange( update );
  323. materialAlphaTestRow.add( new UI.Text( strings.getKey( 'sidebar/material/alphatest' ) ).setWidth( '90px' ) );
  324. materialAlphaTestRow.add( materialAlphaTest );
  325. container.add( materialAlphaTestRow );
  326. // wireframe
  327. var materialWireframeRow = new UI.Row();
  328. var materialWireframe = new UI.Checkbox( false ).onChange( update );
  329. var materialWireframeLinewidth = new UI.Number( 1 ).setWidth( '60px' ).setRange( 0, 100 ).onChange( update );
  330. materialWireframeRow.add( new UI.Text( strings.getKey( 'sidebar/material/wireframe' ) ).setWidth( '90px' ) );
  331. materialWireframeRow.add( materialWireframe );
  332. materialWireframeRow.add( materialWireframeLinewidth );
  333. container.add( materialWireframeRow );
  334. //
  335. function update() {
  336. var object = currentObject;
  337. var geometry = object.geometry;
  338. var previousSelectedSlot = currentMaterialSlot;
  339. currentMaterialSlot = parseInt( materialSlotSelect.getValue() );
  340. if ( currentMaterialSlot !== previousSelectedSlot ) refreshUI( true );
  341. var material = editor.getObjectMaterial( currentObject, currentMaterialSlot );
  342. var textureWarning = false;
  343. var objectHasUvs = false;
  344. if ( object.isSprite ) objectHasUvs = true;
  345. if ( geometry.isGeometry && geometry.faceVertexUvs[ 0 ].length > 0 ) objectHasUvs = true;
  346. if ( geometry.isBufferGeometry && geometry.attributes.uv !== undefined ) objectHasUvs = true;
  347. if ( material ) {
  348. if ( material.uuid !== undefined && material.uuid !== materialUUID.getValue() ) {
  349. editor.execute( new SetMaterialValueCommand( currentObject, 'uuid', materialUUID.getValue(), currentMaterialSlot ) );
  350. }
  351. if ( material instanceof THREE[ materialClass.getValue() ] === false ) {
  352. material = new THREE[ materialClass.getValue() ]();
  353. editor.execute( new SetMaterialCommand( currentObject, material, currentMaterialSlot ), 'New Material: ' + materialClass.getValue() );
  354. // TODO Copy other references in the scene graph
  355. // keeping name and UUID then.
  356. // Also there should be means to create a unique
  357. // copy for the current object explicitly and to
  358. // attach the current material to other objects.
  359. }
  360. if ( material.color !== undefined && material.color.getHex() !== materialColor.getHexValue() ) {
  361. editor.execute( new SetMaterialColorCommand( currentObject, 'color', materialColor.getHexValue(), currentMaterialSlot ) );
  362. }
  363. if ( material.roughness !== undefined && Math.abs( material.roughness - materialRoughness.getValue() ) >= 0.01 ) {
  364. editor.execute( new SetMaterialValueCommand( currentObject, 'roughness', materialRoughness.getValue(), currentMaterialSlot ) );
  365. }
  366. if ( material.metalness !== undefined && Math.abs( material.metalness - materialMetalness.getValue() ) >= 0.01 ) {
  367. editor.execute( new SetMaterialValueCommand( currentObject, 'metalness', materialMetalness.getValue(), currentMaterialSlot ) );
  368. }
  369. if ( material.emissive !== undefined && material.emissive.getHex() !== materialEmissive.getHexValue() ) {
  370. editor.execute( new SetMaterialColorCommand( currentObject, 'emissive', materialEmissive.getHexValue(), currentMaterialSlot ) );
  371. }
  372. if ( material.specular !== undefined && material.specular.getHex() !== materialSpecular.getHexValue() ) {
  373. editor.execute( new SetMaterialColorCommand( currentObject, 'specular', materialSpecular.getHexValue(), currentMaterialSlot ) );
  374. }
  375. if ( material.shininess !== undefined && Math.abs( material.shininess - materialShininess.getValue() ) >= 0.01 ) {
  376. editor.execute( new SetMaterialValueCommand( currentObject, 'shininess', materialShininess.getValue(), currentMaterialSlot ) );
  377. }
  378. if ( material.clearCoat !== undefined && Math.abs( material.clearCoat - materialClearCoat.getValue() ) >= 0.01 ) {
  379. editor.execute( new SetMaterialValueCommand( currentObject, 'clearCoat', materialClearCoat.getValue(), currentMaterialSlot ) );
  380. }
  381. if ( material.clearCoatRoughness !== undefined && Math.abs( material.clearCoatRoughness - materialClearCoatRoughness.getValue() ) >= 0.01 ) {
  382. editor.execute( new SetMaterialValueCommand( currentObject, 'clearCoatRoughness', materialClearCoatRoughness.getValue(), currentMaterialSlot ) );
  383. }
  384. if ( material.vertexColors !== undefined ) {
  385. var vertexColors = parseInt( materialVertexColors.getValue() );
  386. if ( material.vertexColors !== vertexColors ) {
  387. editor.execute( new SetMaterialValueCommand( currentObject, 'vertexColors', vertexColors, currentMaterialSlot ) );
  388. }
  389. }
  390. if ( material.skinning !== undefined && material.skinning !== materialSkinning.getValue() ) {
  391. editor.execute( new SetMaterialValueCommand( currentObject, 'skinning', materialSkinning.getValue(), currentMaterialSlot ) );
  392. }
  393. if ( material.map !== undefined ) {
  394. var mapEnabled = materialMapEnabled.getValue() === true;
  395. if ( objectHasUvs ) {
  396. var map = mapEnabled ? materialMap.getValue() : null;
  397. if ( material.map !== map ) {
  398. editor.execute( new SetMaterialMapCommand( currentObject, 'map', map, currentMaterialSlot ) );
  399. }
  400. } else {
  401. if ( mapEnabled ) textureWarning = true;
  402. }
  403. }
  404. if ( material.alphaMap !== undefined ) {
  405. var mapEnabled = materialAlphaMapEnabled.getValue() === true;
  406. if ( objectHasUvs ) {
  407. var alphaMap = mapEnabled ? materialAlphaMap.getValue() : null;
  408. if ( material.alphaMap !== alphaMap ) {
  409. editor.execute( new SetMaterialMapCommand( currentObject, 'alphaMap', alphaMap, currentMaterialSlot ) );
  410. }
  411. } else {
  412. if ( mapEnabled ) textureWarning = true;
  413. }
  414. }
  415. if ( material.bumpMap !== undefined ) {
  416. var bumpMapEnabled = materialBumpMapEnabled.getValue() === true;
  417. if ( objectHasUvs ) {
  418. var bumpMap = bumpMapEnabled ? materialBumpMap.getValue() : null;
  419. if ( material.bumpMap !== bumpMap ) {
  420. editor.execute( new SetMaterialMapCommand( currentObject, 'bumpMap', bumpMap, currentMaterialSlot ) );
  421. }
  422. if ( material.bumpScale !== materialBumpScale.getValue() ) {
  423. editor.execute( new SetMaterialValueCommand( currentObject, 'bumpScale', materialBumpScale.getValue(), currentMaterialSlot ) );
  424. }
  425. } else {
  426. if ( bumpMapEnabled ) textureWarning = true;
  427. }
  428. }
  429. if ( material.normalMap !== undefined ) {
  430. var normalMapEnabled = materialNormalMapEnabled.getValue() === true;
  431. if ( objectHasUvs ) {
  432. var normalMap = normalMapEnabled ? materialNormalMap.getValue() : null;
  433. if ( material.normalMap !== normalMap ) {
  434. editor.execute( new SetMaterialMapCommand( currentObject, 'normalMap', normalMap, currentMaterialSlot ) );
  435. }
  436. } else {
  437. if ( normalMapEnabled ) textureWarning = true;
  438. }
  439. }
  440. if ( material.displacementMap !== undefined ) {
  441. var displacementMapEnabled = materialDisplacementMapEnabled.getValue() === true;
  442. if ( objectHasUvs ) {
  443. var displacementMap = displacementMapEnabled ? materialDisplacementMap.getValue() : null;
  444. if ( material.displacementMap !== displacementMap ) {
  445. editor.execute( new SetMaterialMapCommand( currentObject, 'displacementMap', displacementMap, currentMaterialSlot ) );
  446. }
  447. if ( material.displacementScale !== materialDisplacementScale.getValue() ) {
  448. editor.execute( new SetMaterialValueCommand( currentObject, 'displacementScale', materialDisplacementScale.getValue(), currentMaterialSlot ) );
  449. }
  450. } else {
  451. if ( displacementMapEnabled ) textureWarning = true;
  452. }
  453. }
  454. if ( material.roughnessMap !== undefined ) {
  455. var roughnessMapEnabled = materialRoughnessMapEnabled.getValue() === true;
  456. if ( objectHasUvs ) {
  457. var roughnessMap = roughnessMapEnabled ? materialRoughnessMap.getValue() : null;
  458. if ( material.roughnessMap !== roughnessMap ) {
  459. editor.execute( new SetMaterialMapCommand( currentObject, 'roughnessMap', roughnessMap, currentMaterialSlot ) );
  460. }
  461. } else {
  462. if ( roughnessMapEnabled ) textureWarning = true;
  463. }
  464. }
  465. if ( material.metalnessMap !== undefined ) {
  466. var metalnessMapEnabled = materialMetalnessMapEnabled.getValue() === true;
  467. if ( objectHasUvs ) {
  468. var metalnessMap = metalnessMapEnabled ? materialMetalnessMap.getValue() : null;
  469. if ( material.metalnessMap !== metalnessMap ) {
  470. editor.execute( new SetMaterialMapCommand( currentObject, 'metalnessMap', metalnessMap, currentMaterialSlot ) );
  471. }
  472. } else {
  473. if ( metalnessMapEnabled ) textureWarning = true;
  474. }
  475. }
  476. if ( material.specularMap !== undefined ) {
  477. var specularMapEnabled = materialSpecularMapEnabled.getValue() === true;
  478. if ( objectHasUvs ) {
  479. var specularMap = specularMapEnabled ? materialSpecularMap.getValue() : null;
  480. if ( material.specularMap !== specularMap ) {
  481. editor.execute( new SetMaterialMapCommand( currentObject, 'specularMap', specularMap, currentMaterialSlot ) );
  482. }
  483. } else {
  484. if ( specularMapEnabled ) textureWarning = true;
  485. }
  486. }
  487. if ( material.envMap !== undefined ) {
  488. var envMapEnabled = materialEnvMapEnabled.getValue() === true;
  489. var envMap = envMapEnabled ? materialEnvMap.getValue() : null;
  490. if ( material.envMap !== envMap ) {
  491. editor.execute( new SetMaterialMapCommand( currentObject, 'envMap', envMap, currentMaterialSlot ) );
  492. }
  493. }
  494. if ( material.gradientMap !== undefined ) {
  495. var gradientMapEnabled = materialGradientMap.getValue() === true;
  496. var gradientMap = gradientMapEnabled ? materialGradientMap.getValue() : null;
  497. if ( material.gradientMap !== gradientMap ) {
  498. editor.execute( new SetMaterialMapCommand( currentObject, 'gradientMap', gradientMap, currentMaterialSlot ) );
  499. }
  500. }
  501. if ( material.reflectivity !== undefined ) {
  502. var reflectivity = materialReflectivity.getValue();
  503. if ( material.reflectivity !== reflectivity ) {
  504. editor.execute( new SetMaterialValueCommand( currentObject, 'reflectivity', reflectivity, currentMaterialSlot ) );
  505. }
  506. }
  507. if ( material.lightMap !== undefined ) {
  508. var lightMapEnabled = materialLightMapEnabled.getValue() === true;
  509. if ( objectHasUvs ) {
  510. var lightMap = lightMapEnabled ? materialLightMap.getValue() : null;
  511. if ( material.lightMap !== lightMap ) {
  512. editor.execute( new SetMaterialMapCommand( currentObject, 'lightMap', lightMap, currentMaterialSlot ) );
  513. }
  514. } else {
  515. if ( lightMapEnabled ) textureWarning = true;
  516. }
  517. }
  518. if ( material.aoMap !== undefined ) {
  519. var aoMapEnabled = materialAOMapEnabled.getValue() === true;
  520. if ( objectHasUvs ) {
  521. var aoMap = aoMapEnabled ? materialAOMap.getValue() : null;
  522. if ( material.aoMap !== aoMap ) {
  523. editor.execute( new SetMaterialMapCommand( currentObject, 'aoMap', aoMap, currentMaterialSlot ) );
  524. }
  525. if ( material.aoMapIntensity !== materialAOScale.getValue() ) {
  526. editor.execute( new SetMaterialValueCommand( currentObject, 'aoMapIntensity', materialAOScale.getValue(), currentMaterialSlot ) );
  527. }
  528. } else {
  529. if ( aoMapEnabled ) textureWarning = true;
  530. }
  531. }
  532. if ( material.emissiveMap !== undefined ) {
  533. var emissiveMapEnabled = materialEmissiveMapEnabled.getValue() === true;
  534. if ( objectHasUvs ) {
  535. var emissiveMap = emissiveMapEnabled ? materialEmissiveMap.getValue() : null;
  536. if ( material.emissiveMap !== emissiveMap ) {
  537. editor.execute( new SetMaterialMapCommand( currentObject, 'emissiveMap', emissiveMap, currentMaterialSlot ) );
  538. }
  539. } else {
  540. if ( emissiveMapEnabled ) textureWarning = true;
  541. }
  542. }
  543. if ( material.side !== undefined ) {
  544. var side = parseInt( materialSide.getValue() );
  545. if ( material.side !== side ) {
  546. editor.execute( new SetMaterialValueCommand( currentObject, 'side', side, currentMaterialSlot ) );
  547. }
  548. }
  549. if ( material.flatShading !== undefined ) {
  550. var flatShading = materialShading.getValue();
  551. if ( material.flatShading != flatShading ) {
  552. editor.execute( new SetMaterialValueCommand( currentObject, 'flatShading', flatShading, currentMaterialSlot ) );
  553. }
  554. }
  555. if ( material.blending !== undefined ) {
  556. var blending = parseInt( materialBlending.getValue() );
  557. if ( material.blending !== blending ) {
  558. editor.execute( new SetMaterialValueCommand( currentObject, 'blending', blending, currentMaterialSlot ) );
  559. }
  560. }
  561. if ( material.opacity !== undefined && Math.abs( material.opacity - materialOpacity.getValue() ) >= 0.01 ) {
  562. editor.execute( new SetMaterialValueCommand( currentObject, 'opacity', materialOpacity.getValue(), currentMaterialSlot ) );
  563. }
  564. if ( material.transparent !== undefined && material.transparent !== materialTransparent.getValue() ) {
  565. editor.execute( new SetMaterialValueCommand( currentObject, 'transparent', materialTransparent.getValue(), currentMaterialSlot ) );
  566. }
  567. if ( material.alphaTest !== undefined && Math.abs( material.alphaTest - materialAlphaTest.getValue() ) >= 0.01 ) {
  568. editor.execute( new SetMaterialValueCommand( currentObject, 'alphaTest', materialAlphaTest.getValue(), currentMaterialSlot ) );
  569. }
  570. if ( material.wireframe !== undefined && material.wireframe !== materialWireframe.getValue() ) {
  571. editor.execute( new SetMaterialValueCommand( currentObject, 'wireframe', materialWireframe.getValue(), currentMaterialSlot ) );
  572. }
  573. if ( material.wireframeLinewidth !== undefined && Math.abs( material.wireframeLinewidth - materialWireframeLinewidth.getValue() ) >= 0.01 ) {
  574. editor.execute( new SetMaterialValueCommand( currentObject, 'wireframeLinewidth', materialWireframeLinewidth.getValue(), currentMaterialSlot ) );
  575. }
  576. refreshUI();
  577. }
  578. if ( textureWarning ) {
  579. console.warn( "Can't set texture, model doesn't have texture coordinates" );
  580. }
  581. }
  582. //
  583. function setRowVisibility() {
  584. var properties = {
  585. 'name': materialNameRow,
  586. 'color': materialColorRow,
  587. 'roughness': materialRoughnessRow,
  588. 'metalness': materialMetalnessRow,
  589. 'emissive': materialEmissiveRow,
  590. 'specular': materialSpecularRow,
  591. 'shininess': materialShininessRow,
  592. 'clearCoat': materialClearCoatRow,
  593. 'clearCoatRoughness': materialClearCoatRoughnessRow,
  594. 'vertexShader': materialProgramRow,
  595. 'vertexColors': materialVertexColorsRow,
  596. 'skinning': materialSkinningRow,
  597. 'map': materialMapRow,
  598. 'alphaMap': materialAlphaMapRow,
  599. 'bumpMap': materialBumpMapRow,
  600. 'normalMap': materialNormalMapRow,
  601. 'displacementMap': materialDisplacementMapRow,
  602. 'roughnessMap': materialRoughnessMapRow,
  603. 'metalnessMap': materialMetalnessMapRow,
  604. 'specularMap': materialSpecularMapRow,
  605. 'envMap': materialEnvMapRow,
  606. 'lightMap': materialLightMapRow,
  607. 'aoMap': materialAOMapRow,
  608. 'emissiveMap': materialEmissiveMapRow,
  609. 'side': materialSideRow,
  610. 'flatShading': materialShadingRow,
  611. 'blending': materialBlendingRow,
  612. 'opacity': materialOpacityRow,
  613. 'transparent': materialTransparentRow,
  614. 'alphaTest': materialAlphaTestRow,
  615. 'wireframe': materialWireframeRow
  616. };
  617. var material = currentObject.material;
  618. if ( Array.isArray( material ) ) {
  619. materialSlotRow.setDisplay( '' );
  620. if ( material.length === 0 ) return;
  621. material = material[ currentMaterialSlot ];
  622. } else {
  623. materialSlotRow.setDisplay( 'none' );
  624. }
  625. for ( var property in properties ) {
  626. properties[ property ].setDisplay( material[ property ] !== undefined ? '' : 'none' );
  627. }
  628. }
  629. function refreshUI( resetTextureSelectors ) {
  630. if ( ! currentObject ) return;
  631. var material = currentObject.material;
  632. if ( Array.isArray( material ) ) {
  633. var slotOptions = {};
  634. currentMaterialSlot = Math.max( 0, Math.min( material.length, currentMaterialSlot ) );
  635. for ( var i = 0; i < material.length; i ++ ) {
  636. slotOptions[ i ] = String( i + 1 ) + ': ' + material[ i ].name;
  637. }
  638. materialSlotSelect.setOptions( slotOptions ).setValue( currentMaterialSlot );
  639. }
  640. material = editor.getObjectMaterial( currentObject, currentMaterialSlot );
  641. if ( material.uuid !== undefined ) {
  642. materialUUID.setValue( material.uuid );
  643. }
  644. if ( material.name !== undefined ) {
  645. materialName.setValue( material.name );
  646. }
  647. materialClass.setValue( material.type );
  648. if ( material.color !== undefined ) {
  649. materialColor.setHexValue( material.color.getHexString() );
  650. }
  651. if ( material.roughness !== undefined ) {
  652. materialRoughness.setValue( material.roughness );
  653. }
  654. if ( material.metalness !== undefined ) {
  655. materialMetalness.setValue( material.metalness );
  656. }
  657. if ( material.emissive !== undefined ) {
  658. materialEmissive.setHexValue( material.emissive.getHexString() );
  659. }
  660. if ( material.specular !== undefined ) {
  661. materialSpecular.setHexValue( material.specular.getHexString() );
  662. }
  663. if ( material.shininess !== undefined ) {
  664. materialShininess.setValue( material.shininess );
  665. }
  666. if ( material.clearCoat !== undefined ) {
  667. materialClearCoat.setValue( material.clearCoat );
  668. }
  669. if ( material.clearCoatRoughness !== undefined ) {
  670. materialClearCoatRoughness.setValue( material.clearCoatRoughness );
  671. }
  672. if ( material.vertexColors !== undefined ) {
  673. materialVertexColors.setValue( material.vertexColors );
  674. }
  675. if ( material.skinning !== undefined ) {
  676. materialSkinning.setValue( material.skinning );
  677. }
  678. if ( material.map !== undefined ) {
  679. materialMapEnabled.setValue( material.map !== null );
  680. if ( material.map !== null || resetTextureSelectors ) {
  681. materialMap.setValue( material.map );
  682. }
  683. }
  684. if ( material.alphaMap !== undefined ) {
  685. materialAlphaMapEnabled.setValue( material.alphaMap !== null );
  686. if ( material.alphaMap !== null || resetTextureSelectors ) {
  687. materialAlphaMap.setValue( material.alphaMap );
  688. }
  689. }
  690. if ( material.bumpMap !== undefined ) {
  691. materialBumpMapEnabled.setValue( material.bumpMap !== null );
  692. if ( material.bumpMap !== null || resetTextureSelectors ) {
  693. materialBumpMap.setValue( material.bumpMap );
  694. }
  695. materialBumpScale.setValue( material.bumpScale );
  696. }
  697. if ( material.normalMap !== undefined ) {
  698. materialNormalMapEnabled.setValue( material.normalMap !== null );
  699. if ( material.normalMap !== null || resetTextureSelectors ) {
  700. materialNormalMap.setValue( material.normalMap );
  701. }
  702. }
  703. if ( material.displacementMap !== undefined ) {
  704. materialDisplacementMapEnabled.setValue( material.displacementMap !== null );
  705. if ( material.displacementMap !== null || resetTextureSelectors ) {
  706. materialDisplacementMap.setValue( material.displacementMap );
  707. }
  708. materialDisplacementScale.setValue( material.displacementScale );
  709. }
  710. if ( material.roughnessMap !== undefined ) {
  711. materialRoughnessMapEnabled.setValue( material.roughnessMap !== null );
  712. if ( material.roughnessMap !== null || resetTextureSelectors ) {
  713. materialRoughnessMap.setValue( material.roughnessMap );
  714. }
  715. }
  716. if ( material.metalnessMap !== undefined ) {
  717. materialMetalnessMapEnabled.setValue( material.metalnessMap !== null );
  718. if ( material.metalnessMap !== null || resetTextureSelectors ) {
  719. materialMetalnessMap.setValue( material.metalnessMap );
  720. }
  721. }
  722. if ( material.specularMap !== undefined ) {
  723. materialSpecularMapEnabled.setValue( material.specularMap !== null );
  724. if ( material.specularMap !== null || resetTextureSelectors ) {
  725. materialSpecularMap.setValue( material.specularMap );
  726. }
  727. }
  728. if ( material.envMap !== undefined ) {
  729. materialEnvMapEnabled.setValue( material.envMap !== null );
  730. if ( material.envMap !== null || resetTextureSelectors ) {
  731. materialEnvMap.setValue( material.envMap );
  732. }
  733. }
  734. if ( material.reflectivity !== undefined ) {
  735. materialReflectivity.setValue( material.reflectivity );
  736. }
  737. if ( material.lightMap !== undefined ) {
  738. materialLightMapEnabled.setValue( material.lightMap !== null );
  739. if ( material.lightMap !== null || resetTextureSelectors ) {
  740. materialLightMap.setValue( material.lightMap );
  741. }
  742. }
  743. if ( material.aoMap !== undefined ) {
  744. materialAOMapEnabled.setValue( material.aoMap !== null );
  745. if ( material.aoMap !== null || resetTextureSelectors ) {
  746. materialAOMap.setValue( material.aoMap );
  747. }
  748. materialAOScale.setValue( material.aoMapIntensity );
  749. }
  750. if ( material.emissiveMap !== undefined ) {
  751. materialEmissiveMapEnabled.setValue( material.emissiveMap !== null );
  752. if ( material.emissiveMap !== null || resetTextureSelectors ) {
  753. materialEmissiveMap.setValue( material.emissiveMap );
  754. }
  755. }
  756. if ( material.side !== undefined ) {
  757. materialSide.setValue( material.side );
  758. }
  759. if ( material.flatShading !== undefined ) {
  760. materialShading.setValue( material.flatShading );
  761. }
  762. if ( material.blending !== undefined ) {
  763. materialBlending.setValue( material.blending );
  764. }
  765. if ( material.opacity !== undefined ) {
  766. materialOpacity.setValue( material.opacity );
  767. }
  768. if ( material.transparent !== undefined ) {
  769. materialTransparent.setValue( material.transparent );
  770. }
  771. if ( material.alphaTest !== undefined ) {
  772. materialAlphaTest.setValue( material.alphaTest );
  773. }
  774. if ( material.wireframe !== undefined ) {
  775. materialWireframe.setValue( material.wireframe );
  776. }
  777. if ( material.wireframeLinewidth !== undefined ) {
  778. materialWireframeLinewidth.setValue( material.wireframeLinewidth );
  779. }
  780. setRowVisibility();
  781. }
  782. // events
  783. signals.objectSelected.add( function ( object ) {
  784. var hasMaterial = false;
  785. if ( object && object.material ) {
  786. hasMaterial = true;
  787. if ( Array.isArray( object.material ) && object.material.length === 0 ) {
  788. hasMaterial = false;
  789. }
  790. }
  791. if ( hasMaterial ) {
  792. var objectChanged = object !== currentObject;
  793. currentObject = object;
  794. refreshUI( objectChanged );
  795. container.setDisplay( '' );
  796. } else {
  797. currentObject = null;
  798. container.setDisplay( 'none' );
  799. }
  800. } );
  801. signals.materialChanged.add( function () {
  802. refreshUI();
  803. } );
  804. return container;
  805. };