Sidebar.Material.js 42 KB

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