Sidebar.Material.js 50 KB

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