2
0

hello_material.html 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width,initial-scale=1">
  6. <title>jMonkeyEngine 3 Tutorial (6) - Hello Materials :: jMonkeyEngine Docs</title>
  7. <link rel="canonical" href="https://wiki.jmonkeyengine.org/docs/tutorials/beginner/hello_material.html">
  8. <link rel="prev" href="hello_input_system.html">
  9. <link rel="next" href="hello_animation.html">
  10. <meta name="keywords" content="documentation, beginner, intro, model, material, color, texture, transparency">
  11. <meta name="generator" content="Antora 2.3.3">
  12. <link rel="stylesheet" href="../../../_/css/site.css">
  13. <meta property="og:image" content="https://wiki.jmonkeyengine.org/_/img/iconx128.png">
  14. <meta property="og:description" content="jMonkeyEngine 3 Tutorial (6) - Hello Materials">
  15. <meta property="og:title" content="jMonkeyEngine Docs">
  16. <link rel="stylesheet" href="../../../_/css/site-extra.css">
  17. <link rel="stylesheet" href="../../../_/css/vendor/docsearch.min.css">
  18. <!-- fetched from https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css -->
  19. <link rel="icon" href="../../../_/img/favicon.ico" type="image/x-icon">
  20. </head>
  21. <body class="article">
  22. <header class="header">
  23. <nav class="navbar">
  24. <div class="navbar-brand">
  25. <a class="navbar-item" href="https://wiki.jmonkeyengine.org">
  26. <img alt="" src="../../../_/img/jme-logo.png" height="32" type="image/x-icon">
  27. </a>
  28. <div class="navbar-item hide-for-print">
  29. <input id="search-input" type="text" placeholder="Search docs">
  30. </div>
  31. <button class="navbar-burger" data-target="topbar-nav">
  32. <span></span>
  33. <span></span>
  34. <span></span>
  35. </button>
  36. </div>
  37. <div id="topbar-nav" class="navbar-menu">
  38. <div class="navbar-end">
  39. <div class="navbar-item theme-switch-wrapper">
  40. <label class="theme-switch" for="checkbox">
  41. <input type="checkbox" id="checkbox" />
  42. <div class="slider round"></div>
  43. </label>
  44. </div>
  45. <a class="navbar-item" href="https://github.com/jmonkeyengine/wiki">Github</a>
  46. </div>
  47. </div>
  48. </nav>
  49. </header>
  50. <div class="body">
  51. <div class="nav-container" data-component="docs" data-version="master">
  52. <aside class="nav">
  53. <div class="panels">
  54. <div class="nav-panel-menu is-active" data-panel="menu">
  55. <nav class="nav-menu">
  56. <h3 class="title"><a href="../../documentation.html">Docs</a></h3>
  57. <ul class="nav-list">
  58. <li class="nav-item" data-depth="0">
  59. <ul class="nav-list">
  60. <li class="nav-item" data-depth="1">
  61. <a class="nav-link" href="../../documentation.html">Getting Started</a>
  62. </li>
  63. <li class="nav-item" data-depth="1">
  64. <a class="nav-link" href="https://javadoc.jmonkeyengine.org/v3.3.2-stable">JavaDoc</a>
  65. </li>
  66. <li class="nav-item" data-depth="1">
  67. <a class="nav-link" href="../../jme3.html">jMonkeyEngine 3</a>
  68. </li>
  69. </ul>
  70. </li>
  71. <li class="nav-item" data-depth="0">
  72. <ul class="nav-list">
  73. <li class="nav-item" data-depth="1">
  74. <button class="nav-item-toggle"></button>
  75. <span class="nav-text">Tutorials</span>
  76. <ul class="nav-list">
  77. <li class="nav-item" data-depth="2">
  78. <button class="nav-item-toggle"></button>
  79. <a class="nav-link" href="beginner.html">Beginner</a>
  80. <ul class="nav-list">
  81. <li class="nav-item" data-depth="3">
  82. <a class="nav-link" href="hello_simpleapplication.html">Hello SimpleApplication</a>
  83. </li>
  84. <li class="nav-item" data-depth="3">
  85. <a class="nav-link" href="hello_node.html">Hello Node</a>
  86. </li>
  87. <li class="nav-item" data-depth="3">
  88. <a class="nav-link" href="hello_asset.html">Hello Asset</a>
  89. </li>
  90. <li class="nav-item" data-depth="3">
  91. <a class="nav-link" href="hello_main_event_loop.html">Hello Update Loop</a>
  92. </li>
  93. <li class="nav-item" data-depth="3">
  94. <a class="nav-link" href="hello_input_system.html">Hello Input System</a>
  95. </li>
  96. <li class="nav-item is-current-page" data-depth="3">
  97. <a class="nav-link" href="hello_material.html">Hello Material</a>
  98. </li>
  99. <li class="nav-item" data-depth="3">
  100. <a class="nav-link" href="hello_animation.html">Hello Animation</a>
  101. </li>
  102. <li class="nav-item" data-depth="3">
  103. <a class="nav-link" href="hello_picking.html">Hello Picking</a>
  104. </li>
  105. <li class="nav-item" data-depth="3">
  106. <a class="nav-link" href="hello_collision.html">Hello Collision</a>
  107. </li>
  108. <li class="nav-item" data-depth="3">
  109. <a class="nav-link" href="hello_terrain.html">Hello Terrain</a>
  110. </li>
  111. <li class="nav-item" data-depth="3">
  112. <a class="nav-link" href="hello_audio.html">Hello Audio</a>
  113. </li>
  114. <li class="nav-item" data-depth="3">
  115. <a class="nav-link" href="hello_effects.html">Hello Effects</a>
  116. </li>
  117. <li class="nav-item" data-depth="3">
  118. <a class="nav-link" href="hello_physics.html">Hello Physics</a>
  119. </li>
  120. </ul>
  121. </li>
  122. <li class="nav-item" data-depth="2">
  123. <button class="nav-item-toggle"></button>
  124. <span class="nav-text">Intermediate</span>
  125. <ul class="nav-list">
  126. <li class="nav-item" data-depth="3">
  127. <a class="nav-link" href="../intermediate/best_practices.html">Best Practices</a>
  128. </li>
  129. <li class="nav-item" data-depth="3">
  130. <a class="nav-link" href="../intermediate/optimization.html">Optimization</a>
  131. </li>
  132. <li class="nav-item" data-depth="3">
  133. <a class="nav-link" href="../intermediate/faq.html">Frequently Asked Questions</a>
  134. </li>
  135. <li class="nav-item" data-depth="3">
  136. <a class="nav-link" href="../intermediate/math_for_dummies.html">Math for Dummies</a>
  137. </li>
  138. <li class="nav-item" data-depth="3">
  139. <a class="nav-link" href="../intermediate/math.html">Math overview</a>
  140. </li>
  141. <li class="nav-item" data-depth="3">
  142. <a class="nav-link" href="../intermediate/math_cheet_sheet.html">3D math "cheat sheet"</a>
  143. </li>
  144. <li class="nav-item" data-depth="3">
  145. <a class="nav-link" href="../intermediate/rotate.html">3-D Rotation</a>
  146. </li>
  147. <li class="nav-item" data-depth="3">
  148. <a class="nav-link" href="../intermediate/math_video_tutorials.html">Math video tutorial series</a>
  149. </li>
  150. <li class="nav-item" data-depth="3">
  151. <a class="nav-link" href="../intermediate/multi-media_asset_pipeline.html">Multi-Media Asset Pipeline</a>
  152. </li>
  153. <li class="nav-item" data-depth="3">
  154. <a class="nav-link" href="../intermediate/scenegraph_for_dummies.html">Scene Graph for Dummies</a>
  155. </li>
  156. <li class="nav-item" data-depth="3">
  157. <a class="nav-link" href="../intermediate/terminology.html">3D Graphics Terminology</a>
  158. </li>
  159. <li class="nav-item" data-depth="3">
  160. <a class="nav-link" href="../intermediate/how_to_use_materials.html">How to Use Materials</a>
  161. </li>
  162. <li class="nav-item" data-depth="3">
  163. <a class="nav-link" href="../intermediate/transparency_sorting.html">Transparency Sorting</a>
  164. </li>
  165. </ul>
  166. </li>
  167. </ul>
  168. </li>
  169. </ul>
  170. </li>
  171. <li class="nav-item" data-depth="0">
  172. <ul class="nav-list">
  173. <li class="nav-item" data-depth="1">
  174. <button class="nav-item-toggle"></button>
  175. <a class="nav-link" href="../../sdk/sdk.html">SDK</a>
  176. <ul class="nav-list">
  177. <li class="nav-item" data-depth="2">
  178. <button class="nav-item-toggle"></button>
  179. <span class="nav-text">Video Tutorials</span>
  180. <ul class="nav-list">
  181. <li class="nav-item" data-depth="3">
  182. <button class="nav-item-toggle"></button>
  183. <span class="nav-text">SDK Use Case Tutorials</span>
  184. <ul class="nav-list">
  185. <li class="nav-item" data-depth="4">
  186. <a class="nav-link" href="http://www.youtube.com/watch?v=-OzRZscLlHY">Demo 1 (Quixote demo)</a>
  187. </li>
  188. <li class="nav-item" data-depth="4">
  189. <a class="nav-link" href="http://www.youtube.com/watch?v=6-YWxD3JByE">Demo 2 (Models and Materials)</a>
  190. </li>
  191. </ul>
  192. </li>
  193. <li class="nav-item" data-depth="3">
  194. <button class="nav-item-toggle"></button>
  195. <span class="nav-text">SDK Tutorials</span>
  196. <ul class="nav-list">
  197. <li class="nav-item" data-depth="4">
  198. <a class="nav-link" href="http://www.youtube.com/watch?v=M1_0pbeyJzI">Basics</a>
  199. </li>
  200. <li class="nav-item" data-depth="4">
  201. <a class="nav-link" href="http://www.youtube.com/watch?v=nL7woH40i5c">Importing Models</a>
  202. </li>
  203. <li class="nav-item" data-depth="4">
  204. <a class="nav-link" href="http://www.youtube.com/watch?v=DUmgAjiNzhY">Dragging&amp;Dropping Nodes</a>
  205. </li>
  206. <li class="nav-item" data-depth="4">
  207. <a class="nav-link" href="http://www.youtube.com/watch?v=ntPAmtsQ6eM">Scene Composing</a>
  208. </li>
  209. <li class="nav-item" data-depth="4">
  210. <a class="nav-link" href="http://www.youtube.com/watch?v=zgPV3W6dD4s">Terrain with Collision Shape</a>
  211. </li>
  212. <li class="nav-item" data-depth="4">
  213. <a class="nav-link" href="http://www.youtube.com/watch?v=Feu3-mrpolc">Working with Materials</a>
  214. </li>
  215. <li class="nav-item" data-depth="4">
  216. <a class="nav-link" href="http://www.youtube.com/watch?v=MNDiZ9YHIpM">Custom Controls</a>
  217. </li>
  218. <li class="nav-item" data-depth="4">
  219. <a class="nav-link" href="http://www.youtube.com/watch?v=oZnssg8TBWQ">WebStart Deployment</a>
  220. </li>
  221. <li class="nav-item" data-depth="4">
  222. <a class="nav-link" href="http://www.youtube.com/watch?v=D7JM4VMKqPc">Animation and Effect TrackEditing</a>
  223. </li>
  224. </ul>
  225. </li>
  226. </ul>
  227. </li>
  228. <li class="nav-item" data-depth="2">
  229. <button class="nav-item-toggle"></button>
  230. <span class="nav-text">Getting Started</span>
  231. <ul class="nav-list">
  232. <li class="nav-item" data-depth="3">
  233. <a class="nav-link" href="../../sdk/update_center.html">Updating jMonkeyEngine SDK</a>
  234. </li>
  235. <li class="nav-item" data-depth="3">
  236. <a class="nav-link" href="../../sdk/troubleshooting.html">Troubleshooting</a>
  237. </li>
  238. </ul>
  239. </li>
  240. <li class="nav-item" data-depth="2">
  241. <button class="nav-item-toggle"></button>
  242. <span class="nav-text">Java Development Features</span>
  243. <ul class="nav-list">
  244. <li class="nav-item" data-depth="3">
  245. <a class="nav-link" href="../../sdk/project_creation.html">Project Creation</a>
  246. </li>
  247. <li class="nav-item" data-depth="3">
  248. <a class="nav-link" href="../../sdk/code_editor.html">Code Editor and Palette</a>
  249. </li>
  250. <li class="nav-item" data-depth="3">
  251. <a class="nav-link" href="../../sdk/version_control.html">File Version Control</a>
  252. </li>
  253. <li class="nav-item" data-depth="3">
  254. <a class="nav-link" href="../../sdk/debugging_profiling_testing.html">Debug, Profile, Test</a>
  255. </li>
  256. <li class="nav-item" data-depth="3">
  257. <button class="nav-item-toggle"></button>
  258. <a class="nav-link" href="../../sdk/application_deployment.html">Application Deployment</a>
  259. <ul class="nav-list">
  260. <li class="nav-item" data-depth="4">
  261. <a class="nav-link" href="../../sdk/default_build_script.html">Default Build Script</a>
  262. </li>
  263. <li class="nav-item" data-depth="4">
  264. <a class="nav-link" href="../../sdk/android.html">Android</a>
  265. </li>
  266. <li class="nav-item" data-depth="4">
  267. <a class="nav-link" href="../../sdk/android_cheat_sheet.html">Android Cheat Sheet</a>
  268. </li>
  269. <li class="nav-item" data-depth="4">
  270. <a class="nav-link" href="../../sdk/ios.html">iOS</a>
  271. </li>
  272. </ul>
  273. </li>
  274. </ul>
  275. </li>
  276. <li class="nav-item" data-depth="2">
  277. <button class="nav-item-toggle"></button>
  278. <span class="nav-text">Unique Features</span>
  279. <ul class="nav-list">
  280. <li class="nav-item" data-depth="3">
  281. <button class="nav-item-toggle"></button>
  282. <a class="nav-link" href="../../sdk/model_loader_and_viewer.html">Import, View, Convert Models</a>
  283. <ul class="nav-list">
  284. <li class="nav-item" data-depth="4">
  285. <a class="nav-link" href="../../sdk/asset_packs.html">Asset Packs</a>
  286. </li>
  287. </ul>
  288. </li>
  289. <li class="nav-item" data-depth="3">
  290. <a class="nav-link" href="../../sdk/scene_explorer.html">The SceneExplorer</a>
  291. </li>
  292. <li class="nav-item" data-depth="3">
  293. <a class="nav-link" href="../../sdk/scene_composer.html">Composing a Scene</a>
  294. </li>
  295. <li class="nav-item" data-depth="3">
  296. <a class="nav-link" href="../../sdk/terrain_editor.html">Terrain Editor</a>
  297. </li>
  298. <li class="nav-item" data-depth="3">
  299. <a class="nav-link" href="../../sdk/sample_code.html">Sample Code</a>
  300. </li>
  301. <li class="nav-item" data-depth="3">
  302. <a class="nav-link" href="../../sdk/material_editing.html">Material Editing</a>
  303. </li>
  304. <li class="nav-item" data-depth="3">
  305. <a class="nav-link" href="../../sdk/font_creation.html">Creating Bitmap Fonts</a>
  306. </li>
  307. <li class="nav-item" data-depth="3">
  308. <button class="nav-item-toggle"></button>
  309. <a class="nav-link" href="https://hub.jmonkeyengine.org/t/effecttrack-and-audiotrack-editing-in-the-sdk/23378">Audio and Effect Track Editing</a>
  310. <ul class="nav-list">
  311. <li class="nav-item" data-depth="4">
  312. <a class="nav-link" href="https://www.youtube.com/watch?v=D7JM4VMKqPc">Video: Effect and AudioTrack editing in jMonkeyEngine 3 sdk</a>
  313. </li>
  314. </ul>
  315. </li>
  316. <li class="nav-item" data-depth="3">
  317. <a class="nav-link" href="../../sdk/filters.html">Post-Processor Filter Editor and Viewer</a>
  318. </li>
  319. <li class="nav-item" data-depth="3">
  320. <a class="nav-link" href="../../jme3/advanced/application_states.html">Application States</a>
  321. </li>
  322. <li class="nav-item" data-depth="3">
  323. <a class="nav-link" href="../../jme3/advanced/custom_controls.html">Custom Controls</a>
  324. </li>
  325. <li class="nav-item" data-depth="3">
  326. <a class="nav-link" href="../../sdk/vehicle_creator.html">Vehicle Creator</a>
  327. </li>
  328. </ul>
  329. </li>
  330. <li class="nav-item" data-depth="2">
  331. <button class="nav-item-toggle"></button>
  332. <span class="nav-text">Advanced Usage</span>
  333. <ul class="nav-list">
  334. <li class="nav-item" data-depth="3">
  335. <a class="nav-link" href="../../sdk/build_platform.html">Building jMonkeyEngine SDK</a>
  336. </li>
  337. <li class="nav-item" data-depth="3">
  338. <a class="nav-link" href="../../sdk/use_own_jme.html#.adoc">Using your own (modified) version of jME3 in jMonkeyEngine SDK</a>
  339. </li>
  340. <li class="nav-item" data-depth="3">
  341. <a class="nav-link" href="../../sdk/increasing_heap_memory.html">Increasing Heap Memory</a>
  342. </li>
  343. <li class="nav-item" data-depth="3">
  344. <a class="nav-link" href="../../sdk/log_files.html">Log Files</a>
  345. </li>
  346. </ul>
  347. </li>
  348. <li class="nav-item" data-depth="2">
  349. <button class="nav-item-toggle"></button>
  350. <span class="nav-text">Available external plugins</span>
  351. <ul class="nav-list">
  352. <li class="nav-item" data-depth="3">
  353. <a class="nav-link" href="../../jme3/contributions.html">Contributions</a>
  354. </li>
  355. <li class="nav-item" data-depth="3">
  356. <a class="nav-link" href="../../sdk/neotexture.html">Neo Texture Editor for procedural textures</a>
  357. </li>
  358. <li class="nav-item" data-depth="3">
  359. <a class="nav-link" href="http://www.youtube.com/watch?v=yS9a9o4WzL8">Video: Mesh Tool &amp; Physics Editor</a>
  360. </li>
  361. </ul>
  362. </li>
  363. <li class="nav-item" data-depth="2">
  364. <button class="nav-item-toggle"></button>
  365. <a class="nav-link" href="../../sdk/development.html">Developing plugins for jMonkeyEngine SDK</a>
  366. <ul class="nav-list">
  367. <li class="nav-item" data-depth="3">
  368. <a class="nav-link" href="../../sdk/development/setup.html">Creating a plugin</a>
  369. </li>
  370. <li class="nav-item" data-depth="3">
  371. <a class="nav-link" href="../../sdk/development/general.html">Creating components</a>
  372. </li>
  373. <li class="nav-item" data-depth="3">
  374. <a class="nav-link" href="../../sdk/development/scene.html">The Main Scene</a>
  375. </li>
  376. <li class="nav-item" data-depth="3">
  377. <a class="nav-link" href="../../sdk/development/sceneexplorer.html">The Scene Explorer</a>
  378. </li>
  379. <li class="nav-item" data-depth="3">
  380. <a class="nav-link" href="../../sdk/development/projects_assets.html">Projects and Assets</a>
  381. </li>
  382. <li class="nav-item" data-depth="3">
  383. <a class="nav-link" href="../../sdk/development/extension_library.html">Create a library plugin from a jar file</a>
  384. </li>
  385. <li class="nav-item" data-depth="3">
  386. <a class="nav-link" href="../../sdk/development/model_loader.html">Create a new or custom model filetype and loader</a>
  387. </li>
  388. </ul>
  389. </li>
  390. </ul>
  391. </li>
  392. </ul>
  393. </li>
  394. </ul>
  395. </nav>
  396. </div>
  397. <div class="nav-panel-explore" data-panel="explore">
  398. <div class="context">
  399. <span class="title">Docs</span>
  400. <span class="version">master</span>
  401. </div>
  402. <ul class="components">
  403. <li class="component is-current">
  404. <span class="title">Docs</span>
  405. <ul class="versions">
  406. <li class="version is-current is-latest">
  407. <a href="../../documentation.html">master</a>
  408. </li>
  409. </ul>
  410. </li>
  411. <li class="component">
  412. <span class="title">Wiki UI</span>
  413. <ul class="versions">
  414. <li class="version is-latest">
  415. <a href="../../../wiki-ui/index.html">master</a>
  416. </li>
  417. </ul>
  418. </li>
  419. </ul>
  420. </div>
  421. </div>
  422. </aside>
  423. </div>
  424. <main class="article">
  425. <div class="toolbar" role="navigation">
  426. <button class="nav-toggle"></button>
  427. <nav class="breadcrumbs" aria-label="breadcrumbs">
  428. <ul>
  429. <li><a href="../../documentation.html">Docs</a></li>
  430. <li>Tutorials</li>
  431. <li><a href="beginner.html">Beginner</a></li>
  432. <li><a href="hello_material.html">Hello Material</a></li>
  433. </ul>
  434. </nav>
  435. <div class="edit-this-page"><a href="https://github.com/jMonkeyEngine/wiki/edit/master/docs/modules/tutorials/pages/beginner/hello_material.adoc">Edit this Page</a></div>
  436. </div>
  437. <div class="content">
  438. <article class="doc">
  439. <h1 class="page">jMonkeyEngine 3 Tutorial (6) - Hello Materials</h1>
  440. <div id="preamble">
  441. <div class="sectionbody">
  442. <div class="paragraph">
  443. <p>The term Material includes everything that influences what the surface of a 3D model looks like: The color, texture, shininess, and opacity/transparency. Plain coloring is covered in <a href="hello_node.html" class="page">Hello Node</a>. Loading models that come with materials is covered in <a href="hello_asset.html" class="page">Hello Asset</a>. In this tutorial you learn to create and use custom JME3 Material Definitions.</p>
  444. </div>
  445. <div class="imageblock text-center">
  446. <div class="content">
  447. <img src="../_images/beginner/beginner-materials.png" alt="beginner-materials.png" width="320" height="240">
  448. </div>
  449. </div>
  450. <div class="admonitionblock tip">
  451. <table>
  452. <tr>
  453. <td class="icon">
  454. <i class="fa icon-tip" title="Tip"></i>
  455. </td>
  456. <td class="content">
  457. <div class="paragraph">
  458. <p>To use the example assets in a new jMonkeyEngine SDK project, right-click your project, select <span class="menuseq"><b class="menu">Properties</b>&#160;<i class="fa fa-angle-right caret"></i> <b class="submenu">Libraries</b>&#160;<i class="fa fa-angle-right caret"></i> <b class="menuitem">Add Library</b></span>, and add the &#8220;jme3-test-data&#8221; library.</p>
  459. </div>
  460. </td>
  461. </tr>
  462. </table>
  463. </div>
  464. </div>
  465. </div>
  466. <div class="sect1">
  467. <h2 id="sample-code"><a class="anchor" href="#sample-code"></a>Sample Code</h2>
  468. <div class="sectionbody">
  469. <div class="listingblock">
  470. <div class="content">
  471. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">package jme3test.helloworld;
  472. import com.jme3.app.SimpleApplication;
  473. import com.jme3.light.DirectionalLight;
  474. import com.jme3.material.Material;
  475. import com.jme3.material.RenderState.BlendMode;
  476. import com.jme3.math.ColorRGBA;
  477. import com.jme3.math.Vector3f;
  478. import com.jme3.renderer.queue.RenderQueue.Bucket;
  479. import com.jme3.scene.Geometry;
  480. import com.jme3.scene.shape.Box;
  481. import com.jme3.scene.shape.Sphere;
  482. import com.jme3.texture.Texture;
  483. import com.jme3.util.TangentBinormalGenerator;
  484. /** Sample 6 - how to give an object's surface a material and texture.
  485. * How to make objects transparent. How to make bumpy and shiny surfaces. */
  486. public class HelloMaterial extends SimpleApplication {
  487. public static void main(String[] args) {
  488. HelloMaterial app = new HelloMaterial();
  489. app.start();
  490. }
  491. @Override
  492. public void simpleInitApp() {
  493. /** A simple textured cube -- in good MIP map quality. */
  494. Box cube1Mesh = new Box( 1f,1f,1f);
  495. Geometry cube1Geo = new Geometry("My Textured Box", cube1Mesh);
  496. cube1Geo.setLocalTranslation(new Vector3f(-3f,1.1f,0f));
  497. Material cube1Mat = new Material(assetManager,
  498. "Common/MatDefs/Misc/Unshaded.j3md");
  499. Texture cube1Tex = assetManager.loadTexture(
  500. "Interface/Logo/Monkey.jpg");
  501. cube1Mat.setTexture("ColorMap", cube1Tex);
  502. cube1Geo.setMaterial(cube1Mat);
  503. rootNode.attachChild(cube1Geo);
  504. /** A translucent/transparent texture, similar to a window frame. */
  505. Box cube2Mesh = new Box( 1f,1f,0.01f);
  506. Geometry cube2Geo = new Geometry("window frame", cube2Mesh);
  507. Material cube2Mat = new Material(assetManager,
  508. "Common/MatDefs/Misc/Unshaded.j3md");
  509. cube2Mat.setTexture("ColorMap",
  510. assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
  511. cube2Mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
  512. cube2Geo.setQueueBucket(Bucket.Transparent);
  513. cube2Geo.setMaterial(cube2Mat);
  514. rootNode.attachChild(cube2Geo);
  515. /** A bumpy rock with a shiny light effect.*/
  516. Sphere sphereMesh = new Sphere(32,32, 2f);
  517. Geometry sphereGeo = new Geometry("Shiny rock", sphereMesh);
  518. sphereMesh.setTextureMode(Sphere.TextureMode.Projected); // better quality on spheres
  519. TangentBinormalGenerator.generate(sphereMesh); // for lighting effect
  520. Material sphereMat = new Material(assetManager,
  521. "Common/MatDefs/Light/Lighting.j3md");
  522. sphereMat.setTexture("DiffuseMap",
  523. assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
  524. sphereMat.setTexture("NormalMap",
  525. assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));
  526. sphereMat.setBoolean("UseMaterialColors",true);
  527. sphereMat.setColor("Diffuse",ColorRGBA.White);
  528. sphereMat.setColor("Specular",ColorRGBA.White);
  529. sphereMat.setFloat("Shininess", 64f); // [0,128]
  530. sphereGeo.setMaterial(sphereMat);
  531. sphereGeo.setLocalTranslation(0,2,-2); // Move it a bit
  532. sphereGeo.rotate(1.6f, 0, 0); // Rotate it a bit
  533. rootNode.attachChild(sphereGeo);
  534. /** Must add a light to make the lit object visible! */
  535. DirectionalLight sun = new DirectionalLight();
  536. sun.setDirection(new Vector3f(1,0,-2).normalizeLocal());
  537. sun.setColor(ColorRGBA.White);
  538. rootNode.addLight(sun);
  539. }
  540. }</code></pre>
  541. </div>
  542. </div>
  543. <div class="paragraph">
  544. <p>You should see</p>
  545. </div>
  546. <div class="ulist">
  547. <ul>
  548. <li>
  549. <p>Left – A cube with a brown monkey texture.</p>
  550. </li>
  551. <li>
  552. <p>Right – A translucent monkey picture in front of a shiny bumpy rock.</p>
  553. </li>
  554. </ul>
  555. </div>
  556. <div class="paragraph">
  557. <p>Move around with the WASD keys to have a closer look at the translucency, and the rock&#8217;s bumpiness.</p>
  558. </div>
  559. </div>
  560. </div>
  561. <div class="sect1">
  562. <h2 id="simple-unshaded-texture"><a class="anchor" href="#simple-unshaded-texture"></a>Simple Unshaded Texture</h2>
  563. <div class="sectionbody">
  564. <div class="paragraph">
  565. <p>Typically you want to give objects in your scene textures: It can be rock, grass, brick, wood, water, metal, paper… A texture is a normal image file in JPG or PNG format. In this example, you create a box with a simple unshaded Monkey texture as material.</p>
  566. </div>
  567. <div class="listingblock">
  568. <div class="content">
  569. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> /** A simple textured cube -- in good MIP map quality. */
  570. Box cube1Mesh = new Box( 1f,1f,1f);
  571. Geometry cube1Geo = new Geometry("My Textured Box", cube1Mesh);
  572. cube1Geo.setLocalTranslation(new Vector3f(-3f,1.1f,0f));
  573. Material cube1Mat = new Material(assetManager,
  574. "Common/MatDefs/Misc/Unshaded.j3md");
  575. Texture cube1Tex = assetManager.loadTexture(
  576. "Interface/Logo/Monkey.jpg");
  577. cube1Mat.setTexture("ColorMap", cube1Tex);
  578. cube1Geo.setMaterial(cube1Mat);
  579. rootNode.attachChild(cube1Geo);</code></pre>
  580. </div>
  581. </div>
  582. <div class="paragraph">
  583. <p>Here is what we did: to create a textured box:</p>
  584. </div>
  585. <div class="olist arabic">
  586. <ol class="arabic">
  587. <li>
  588. <p>Create a Geometry <code>cube1Geo</code> from a Box mesh <code>cube1Mesh</code>.</p>
  589. </li>
  590. <li>
  591. <p>Create a Material <code>cube1Mat</code> based on jME3&#8217;s default <code>Unshaded.j3md</code> material definition.</p>
  592. </li>
  593. <li>
  594. <p>Create a texture <code>cube1Tex</code> from the <code>Monkey.jpg</code> file in the <code>assets/Interface/Logo/</code> directory of the project.</p>
  595. </li>
  596. <li>
  597. <p>Load the texture <code>cube1Tex</code> into the <code>ColorMap</code> layer of the material <code>cube1Mat</code>.</p>
  598. </li>
  599. <li>
  600. <p>Apply the material to the cube, and attach the cube to the rootnode.</p>
  601. </li>
  602. </ol>
  603. </div>
  604. </div>
  605. </div>
  606. <div class="sect1">
  607. <h2 id="transparent-unshaded-texture"><a class="anchor" href="#transparent-unshaded-texture"></a>Transparent Unshaded Texture</h2>
  608. <div class="sectionbody">
  609. <div class="paragraph">
  610. <p><code>Monkey.png</code> is the same texture as <code>Monkey.jpg</code>, but with an added alpha channel. The alpha channel allows you to specify which areas of the texture you want to be opaque or transparent: Black areas of the alpha channel remain opaque, gray areas become translucent, and white areas become transparent.</p>
  611. </div>
  612. <div class="paragraph">
  613. <p>For a partially translucent/transparent texture, you need:</p>
  614. </div>
  615. <div class="ulist">
  616. <ul>
  617. <li>
  618. <p>A Texture with alpha channel</p>
  619. </li>
  620. <li>
  621. <p>A Texture with blend mode of <code>BlendMode.Alpha</code></p>
  622. </li>
  623. <li>
  624. <p>A Geometry in the <code>Bucket.Transparent</code> render bucket.<br>
  625. This bucket ensures that the transparent object is drawn on top of objects behind it, and they show up correctly under the transparent parts.</p>
  626. </li>
  627. </ul>
  628. </div>
  629. <div class="listingblock">
  630. <div class="content">
  631. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> /** A translucent/transparent texture, similar to a window frame. */
  632. Box cube2Mesh = new Box( 1f,1f,0.01f);
  633. Geometry cube2Geo = new Geometry("window frame", cube2Mesh);
  634. Material cube2Mat = new Material(assetManager,
  635. "Common/MatDefs/Misc/Unshaded.j3md");
  636. cube2Mat.setTexture("ColorMap",
  637. assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
  638. cube2Mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); // !
  639. cube2Geo.setQueueBucket(Bucket.Transparent); // !
  640. cube2Geo.setMaterial(cube2Mat);
  641. rootNode.attachChild(cube2Geo);</code></pre>
  642. </div>
  643. </div>
  644. <div class="paragraph">
  645. <p>For non-transparent objects, the drawing order is not so important, because the z-buffer already keeps track of whether a pixel is behind something else or not, and the color of an opaque pixel doesn&#8217;t depend on the pixels under it, this is why opaque Geometries can be drawn in any order.</p>
  646. </div>
  647. <div class="paragraph">
  648. <p>What you did for the transparent texture is the same as before, with only one added step for the transparency.</p>
  649. </div>
  650. <div class="olist arabic">
  651. <ol class="arabic">
  652. <li>
  653. <p>Create a Geometry <code>cube2Geo</code> from a Box mesh <code>cube2Mesh</code>. This Box Geometry is flat upright box (because z=0.01f).</p>
  654. </li>
  655. <li>
  656. <p>Create a Material <code>cube2Mat</code> based on jME3&#8217;s default <code>Unshaded.j3md</code> material definition.</p>
  657. </li>
  658. <li>
  659. <p>Create a texture <code>cube2Tex</code> from the <code>Monkey.png</code> file in the <code>assets/Textures/ColoredTex/</code> directory of the project. This PNG file must have an alpha layer.</p>
  660. </li>
  661. <li>
  662. <p><strong>Activate transparency in the material by setting the blend mode to Alpha.</strong></p>
  663. </li>
  664. <li>
  665. <p><strong>Set the QueueBucket of the Geometry to <code>Bucket.Transparent</code>.</strong></p>
  666. </li>
  667. <li>
  668. <p>Load the texture <code>cube2Tex</code> into the <code>ColorMap</code> layer of the material <code>cube2Mat</code>.</p>
  669. </li>
  670. <li>
  671. <p>Apply the material to the cube, and attach the cube to the rootnode.</p>
  672. </li>
  673. </ol>
  674. </div>
  675. <div class="admonitionblock tip">
  676. <table>
  677. <tr>
  678. <td class="icon">
  679. <i class="fa icon-tip" title="Tip"></i>
  680. </td>
  681. <td class="content">
  682. <div class="paragraph">
  683. <p>Learn more about creating PNG images with an alpha layer in the help system of your graphic editor.</p>
  684. </div>
  685. </td>
  686. </tr>
  687. </table>
  688. </div>
  689. </div>
  690. </div>
  691. <div class="sect1">
  692. <h2 id="shininess-and-bumpiness"><a class="anchor" href="#shininess-and-bumpiness"></a>Shininess and Bumpiness</h2>
  693. <div class="sectionbody">
  694. <div class="paragraph">
  695. <p>But textures are not all. Have a close look at the shiny sphere – you cannot get such a nice bumpy material with just a plain texture. You see that JME3 also supports so-called Phong-illuminated materials:</p>
  696. </div>
  697. <div class="paragraph">
  698. <p>In a lit material, the standard texture layer is refered to as <em>DiffuseMap</em>, any material can use this layer. A lit material can additionally have lighting effects such as <em>Shininess</em> used together with the <em>SpecularMap</em> layer and <em>Specular</em> color. And you can even get a realistically bumpy or cracked surface with help of the <em>NormalMap</em> layer.</p>
  699. </div>
  700. <div class="paragraph">
  701. <p>Let&#8217;s have a look at the part of the code example where you create the shiny bumpy rock.</p>
  702. </div>
  703. <div class="olist arabic">
  704. <ol class="arabic">
  705. <li>
  706. <p>Create a Geometry from a Sphere shape. Note that this shape is a normal smooth sphere mesh.</p>
  707. <div class="listingblock">
  708. <div class="content">
  709. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> Sphere sphereMesh = new Sphere(32,32, 2f);
  710. Geometry sphereGeo = new Geometry("Shiny rock", sphereMesh);</code></pre>
  711. </div>
  712. </div>
  713. <div class="olist loweralpha">
  714. <ol class="loweralpha" type="a">
  715. <li>
  716. <p>(Only for Spheres) Change the sphere&#8217;s TextureMode to make the square texture project better onto the sphere.</p>
  717. <div class="listingblock">
  718. <div class="content">
  719. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> sphereMesh.setTextureMode(Sphere.TextureMode.Projected);</code></pre>
  720. </div>
  721. </div>
  722. </li>
  723. <li>
  724. <p>You must generate TangentBinormals for the mesh so you can use the NormalMap layer of the texture.</p>
  725. <div class="listingblock">
  726. <div class="content">
  727. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> TangentBinormalGenerator.generate(sphereMesh);</code></pre>
  728. </div>
  729. </div>
  730. </li>
  731. </ol>
  732. </div>
  733. </li>
  734. <li>
  735. <p>Create a material based on the <code>Lighting.j3md</code> default material.</p>
  736. <div class="listingblock">
  737. <div class="content">
  738. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> Material sphereMat = new Material(assetManager,
  739. "Common/MatDefs/Light/Lighting.j3md");</code></pre>
  740. </div>
  741. </div>
  742. <div class="olist loweralpha">
  743. <ol class="loweralpha" type="a">
  744. <li>
  745. <p>Set a standard rocky texture in the <code>DiffuseMap</code> layer.</p>
  746. <div class="imageblock text-right">
  747. <div class="content">
  748. <img src="https://github.com/jMonkeyEngine/jmonkeyengine/raw/445f7ed010199d30c484fe75bacef4b87f2eb38e/jme3-testdata/src/main/resources/Textures/Terrain/Pond/Pond.jpg" alt="Pond.jpg" width="64" height="64">
  749. </div>
  750. </div>
  751. <div class="listingblock">
  752. <div class="content">
  753. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> sphereMat.setTexture("DiffuseMap",
  754. assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));</code></pre>
  755. </div>
  756. </div>
  757. </li>
  758. <li>
  759. <p>Set the <code>NormalMap</code> layer that contains the bumpiness. The NormalMap was generated for this particular DiffuseMap with a special tool (e.g. Blender).</p>
  760. <div class="imageblock text-right">
  761. <div class="content">
  762. <img src="https://github.com/jMonkeyEngine/jmonkeyengine/raw/445f7ed010199d30c484fe75bacef4b87f2eb38e/jme3-testdata/src/main/resources/Textures/Terrain/Pond/Pond_normal.png" alt="Pond_normal.png" width="64" height="64">
  763. </div>
  764. </div>
  765. <div class="listingblock">
  766. <div class="content">
  767. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> sphereMat.setTexture("NormalMap",
  768. assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));</code></pre>
  769. </div>
  770. </div>
  771. </li>
  772. <li>
  773. <p>Set the Material&#8217;s Shininess to a value between 1 and 128. For a rock, a low fuzzy shininess is appropriate. Use material colors to define the shiny Specular color.</p>
  774. <div class="listingblock">
  775. <div class="content">
  776. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> sphereMat.setBoolean("UseMaterialColors",true);
  777. sphereMat.setColor("Diffuse",ColorRGBA.White); // minimum material color
  778. sphereMat.setColor("Specular",ColorRGBA.White); // for shininess
  779. sphereMat.setFloat("Shininess", 64f); // [1,128] for shininess</code></pre>
  780. </div>
  781. </div>
  782. </li>
  783. </ol>
  784. </div>
  785. </li>
  786. <li>
  787. <p>Assign your newly created material to the Geometry.</p>
  788. <div class="listingblock">
  789. <div class="content">
  790. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> sphereGeo.setMaterial(sphereMat);</code></pre>
  791. </div>
  792. </div>
  793. </li>
  794. <li>
  795. <p>Let&#8217;s move and rotate the geometry a bit to position it better.</p>
  796. <div class="listingblock">
  797. <div class="content">
  798. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> sphereGeo.setLocalTranslation(0,2,-2); // Move it a bit
  799. sphereGeo.rotate(1.6f, 0, 0); // Rotate it a bit
  800. rootNode.attachChild(sphereGeo);</code></pre>
  801. </div>
  802. </div>
  803. </li>
  804. </ol>
  805. </div>
  806. <div class="paragraph">
  807. <p>Remember that any Lighting.j3md-based material requires a light source, as shown in the full code sample above.</p>
  808. </div>
  809. <div class="admonitionblock tip">
  810. <table>
  811. <tr>
  812. <td class="icon">
  813. <i class="fa icon-tip" title="Tip"></i>
  814. </td>
  815. <td class="content">
  816. <div class="paragraph">
  817. <p>To deactivate Shininess, do not set <code>Shininess</code> to 0, but instead set the <code>Specular</code> color to <code>ColorRGBA.Black</code>.</p>
  818. </div>
  819. </td>
  820. </tr>
  821. </table>
  822. </div>
  823. </div>
  824. </div>
  825. <div class="sect1">
  826. <h2 id="default-material-definitions"><a class="anchor" href="#default-material-definitions"></a>Default Material Definitions</h2>
  827. <div class="sectionbody">
  828. <div class="paragraph">
  829. <p>As you have seen, you can find the following default materials in <code>jme/core-data/Common/MatDefs/…</code>.</p>
  830. </div>
  831. <table class="tableblock frame-all grid-all stretch">
  832. <colgroup>
  833. <col style="width: 20%;">
  834. <col style="width: 40%;">
  835. <col style="width: 40%;">
  836. </colgroup>
  837. <thead>
  838. <tr>
  839. <th class="tableblock halign-left valign-top">Default Definition</th>
  840. <th class="tableblock halign-left valign-top">Usage</th>
  841. <th class="tableblock halign-left valign-top">Parameters</th>
  842. </tr>
  843. </thead>
  844. <tbody>
  845. <tr>
  846. <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
  847. <p><code>Misc/Unshaded.j3md</code></p>
  848. </div></div></td>
  849. <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
  850. <p>Colored: Use with mat.setColor() and ColorRGBA.<br>
  851. Textured: Use with mat.setTexture() and Texture.</p>
  852. </div></div></td>
  853. <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
  854. <p>Color : Color<br>
  855. ColorMap : Texture2D</p>
  856. </div></div></td>
  857. </tr>
  858. <tr>
  859. <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
  860. <p><code>Light/Lighting.j3md</code></p>
  861. </div></div></td>
  862. <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
  863. <p>Use with shiny Textures, Bump- and NormalMaps textures.<br>
  864. Requires a light source.</p>
  865. </div></div></td>
  866. <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
  867. <p>Ambient, Diffuse, Specular : Color<br>
  868. DiffuseMap, NormalMap, SpecularMap : Texture2D<br>
  869. Shininess : Float</p>
  870. </div></div></td>
  871. </tr>
  872. </tbody>
  873. </table>
  874. <div class="paragraph">
  875. <p>For a game, you create custom Materials based on these existing MaterialDefintions – as you have just seen in the example with the shiny rock&#8217;s material.</p>
  876. </div>
  877. </div>
  878. </div>
  879. <div class="sect1">
  880. <h2 id="exercises"><a class="anchor" href="#exercises"></a>Exercises</h2>
  881. <div class="sectionbody">
  882. <div class="sect2">
  883. <h3 id="exercise-1-custom-j3m-material"><a class="anchor" href="#exercise-1-custom-j3m-material"></a>Exercise 1: Custom .j3m Material</h3>
  884. <div class="paragraph">
  885. <p>Look at the shiny rocky sphere above again. It takes several lines to create and set the Material.</p>
  886. </div>
  887. <div class="ulist">
  888. <ul>
  889. <li>
  890. <p>Note how it loads the <code>Lighting.j3md</code> Material definition.</p>
  891. </li>
  892. <li>
  893. <p>Note how it sets the <code>DiffuseMap</code> and <code>NormalMap</code> to a texture path.</p>
  894. </li>
  895. <li>
  896. <p>Note how it activates <code>UseMaterialColors</code> and sets <code>Specular</code> and <code>Diffuse</code> to 4 float values (RGBA color).</p>
  897. </li>
  898. <li>
  899. <p>Note how it sets <code>Shininess</code> to 64.</p>
  900. </li>
  901. </ul>
  902. </div>
  903. <div class="paragraph">
  904. <p>If you want to use one custom material for several models, you can store it in a .j3m file, and save a few lines of code every time.</p>
  905. </div>
  906. <div class="paragraph">
  907. <p>You create a j3m file as follows:</p>
  908. </div>
  909. <div class="olist arabic">
  910. <ol class="arabic">
  911. <li>
  912. <p>Create a plain text file <code>assets/Materials/MyCustomMaterial.j3m</code> in your project directory, with the following content:</p>
  913. <div class="listingblock">
  914. <div class="content">
  915. <pre class="highlightjs highlight"><code>Material My shiny custom material : Common/MatDefs/Light/Lighting.j3md {
  916. MaterialParameters {
  917. DiffuseMap : Textures/Terrain/Pond/Pond.jpg
  918. NormalMap : Textures/Terrain/Pond/Pond_normal.png
  919. UseMaterialColors : true
  920. Specular : 1.0 1.0 1.0 1.0
  921. Diffuse : 1.0 1.0 1.0 1.0
  922. Shininess : 64.0
  923. }
  924. }</code></pre>
  925. </div>
  926. </div>
  927. <div class="ulist">
  928. <ul>
  929. <li>
  930. <p>Note that <code>Material</code> is a fixed keyword.</p>
  931. </li>
  932. <li>
  933. <p>Note that <code>My shiny custom material</code> is a String that you can choose to describe the material.</p>
  934. </li>
  935. <li>
  936. <p>Note how the code sets all the same properties as before!</p>
  937. </li>
  938. </ul>
  939. </div>
  940. </li>
  941. <li>
  942. <p>In the code sample, comment out the eight lines that have <code>sphereMat</code> in them.</p>
  943. </li>
  944. <li>
  945. <p>Below this line, add the following line:</p>
  946. <div class="listingblock">
  947. <div class="content">
  948. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">sphereGeo.setMaterial((Material) assetManager.loadMaterial(
  949. "Materials/MyCustomMaterial.j3m"));</code></pre>
  950. </div>
  951. </div>
  952. </li>
  953. <li>
  954. <p>Run the app. The result is the same.</p>
  955. </li>
  956. </ol>
  957. </div>
  958. <div class="paragraph">
  959. <p>Using this new custom material <code>MyCustomMaterial.j3m</code> only takes one line. You have replaced the eight lines of an on-the-fly material definition with one line that loads a custom material from a file. Using .j3m files is very handy if you use the same material often.</p>
  960. </div>
  961. </div>
  962. <div class="sect2">
  963. <h3 id="exercise-2-bumpiness-and-shininess"><a class="anchor" href="#exercise-2-bumpiness-and-shininess"></a>Exercise 2: Bumpiness and Shininess</h3>
  964. <div class="paragraph">
  965. <p>Go back to the bumpy rock sample above:</p>
  966. </div>
  967. <div class="olist arabic">
  968. <ol class="arabic">
  969. <li>
  970. <p>Comment out the DiffuseMap line, and run the app. (Uncomment it again.)</p>
  971. <div class="ulist">
  972. <ul>
  973. <li>
  974. <p>Which property of the rock is lost?</p>
  975. </li>
  976. </ul>
  977. </div>
  978. </li>
  979. <li>
  980. <p>Comment out the NormalMap line, and run the app. (Uncomment it again.)</p>
  981. <div class="ulist">
  982. <ul>
  983. <li>
  984. <p>Which property of the rock is lost?</p>
  985. </li>
  986. </ul>
  987. </div>
  988. </li>
  989. <li>
  990. <p>Change the value of Shininess to values like 0, 63, 127.</p>
  991. <div class="ulist">
  992. <ul>
  993. <li>
  994. <p>What aspect of the Shininess changes?</p>
  995. </li>
  996. </ul>
  997. </div>
  998. </li>
  999. </ol>
  1000. </div>
  1001. </div>
  1002. </div>
  1003. </div>
  1004. <div class="sect1">
  1005. <h2 id="conclusion"><a class="anchor" href="#conclusion"></a>Conclusion</h2>
  1006. <div class="sectionbody">
  1007. <div class="paragraph">
  1008. <p>You have learned how to create a Material, specify its properties, and use it on a Geometry. You know how to load an image file (.png, .jpg) as texture into a material. You know to save texture files in a subfolder of your project&#8217;s <code>assets/Textures/</code> directory.</p>
  1009. </div>
  1010. <div class="paragraph">
  1011. <p>You have also learned that a material can be stored in a .j3m file. The file references a built-in MaterialDefinition and specifies values for properties of that MaterialDefinition. You know to save your custom .j3m files in your project&#8217;s <code>assets/Materials/</code> directory.</p>
  1012. </div>
  1013. <div class="paragraph">
  1014. <p><strong>See also:</strong></p>
  1015. </div>
  1016. <div class="ulist">
  1017. <ul>
  1018. <li>
  1019. <p><a href="../intermediate/how_to_use_materials.html" class="page">How to Use Materials</a></p>
  1020. </li>
  1021. <li>
  1022. <p><a href="../../sdk/material_editing.html" class="page">Material Editing</a></p>
  1023. </li>
  1024. <li>
  1025. <p><a href="https://hub.jmonkeyengine.org/t/jmonkeyengine3-material-system-full-explanation/12947">Materials</a> forum thread</p>
  1026. </li>
  1027. <li>
  1028. <p><a href="http://www.youtube.com/watch?v=Feu3-mrpolc">Video Tutorial: Editing and Assigning Materials to Models in jMonkeyEngine SDK (from 2010, is there a newer one?</a></p>
  1029. </li>
  1030. <li>
  1031. <p><a href="https://www.blender.org/support/tutorials/">Blender tutorials</a></p>
  1032. </li>
  1033. </ul>
  1034. </div>
  1035. </div>
  1036. </div>
  1037. <nav class="pagination">
  1038. <span class="prev"><a href="hello_input_system.html">Hello Input System</a></span>
  1039. <span class="next"><a href="hello_animation.html">Hello Animation</a></span>
  1040. </nav>
  1041. </article>
  1042. <aside class="toc sidebar" data-title="Contents" data-levels="2">
  1043. <div class="toc-menu"></div>
  1044. </aside>
  1045. </div>
  1046. </main>
  1047. </div>
  1048. <footer class="footer">
  1049. <p>Copyright 2020 jMonkeyEngine Wiki Contributors. Licensed BSD-3.</p>
  1050. </footer>
  1051. <script src="../../../_/js/vendor/docsearch.min.js"></script>
  1052. <!-- fetched from https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js -->
  1053. <script>
  1054. var search = docsearch({
  1055. apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
  1056. indexName: 'jmonkeyengine',
  1057. inputSelector: '#search-input',
  1058. autocompleteOptions: { hint: false, keyboardShortcuts: ['s'] },
  1059. algoliaOptions: { hitsPerPage: 10 }
  1060. }).autocomplete
  1061. search.on('autocomplete:closed', function () { search.autocomplete.setVal() })
  1062. function focusSearchInput () { document.querySelector('#search-input').focus() }
  1063. if (document.querySelector('.home-link.is-current')) window.addEventListener('load', focusSearchInput)
  1064. </script>
  1065. <script src="../../../_/js/site.js"></script>
  1066. <script async src="../../../_/js/vendor/highlight.js"></script>
  1067. </body>
  1068. </html>