Sidebar.Material.js 38 KB

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