Sidebar.Material.js 38 KB

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