Sidebar.Material.js 48 KB

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