Sidebar.Material.js 48 KB

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