Sidebar.Material.js 48 KB

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