Sidebar.Material.js 41 KB

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