Sidebar.Material.js 51 KB

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