hello_asset.html 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  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 (3) - Hello Assets :: jMonkeyEngine Docs</title>
  7. <link rel="canonical" href="https://wiki.jmonkeyengine.org/docs/tutorials/beginner/hello_asset.html">
  8. <link rel="prev" href="hello_node.html">
  9. <link rel="next" href="hello_main_event_loop.html">
  10. <meta name="keywords" content="beginner, intro, documentation, lightnode, material, model, node, gui, hud, texture">
  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 (3) - Hello Assets">
  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 is-current-page" 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" 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_asset.html">Hello Asset</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_asset.adoc">Edit this Page</a></div>
  436. </div>
  437. <div class="content">
  438. <article class="doc">
  439. <h1 class="page">jMonkeyEngine 3 Tutorial (3) - Hello Assets</h1>
  440. <div id="preamble">
  441. <div class="sectionbody">
  442. <div class="paragraph">
  443. <p>In this tutorial we will learn to load 3D models and text into the scene graph, using the jME <a href="../../jme3/advanced/asset_manager.html" class="page">Asset Manager</a>. You will also learn how to determine the correct paths, and which file formats to use.</p>
  444. </div>
  445. <div class="imageblock text-center">
  446. <div class="content">
  447. <img src="../_images/beginner/beginner-assets-models.png" alt="beginner-assets-models.png" width="320" height="250">
  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="code-sample"><a class="anchor" href="#code-sample"></a>Code Sample</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.font.BitmapText;
  474. import com.jme3.light.DirectionalLight;
  475. import com.jme3.material.Material;
  476. import com.jme3.math.Vector3f;
  477. import com.jme3.scene.Geometry;
  478. import com.jme3.scene.Spatial;
  479. import com.jme3.scene.shape.Box;
  480. /** Sample 3 - how to load an OBJ model, and OgreXML model,
  481. * a material/texture, or text. */
  482. public class HelloAssets extends SimpleApplication {
  483. public static void main(String[] args) {
  484. HelloAssets app = new HelloAssets();
  485. app.start();
  486. }
  487. @Override
  488. public void simpleInitApp() {
  489. Spatial teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
  490. Material mat_default = new Material(
  491. assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
  492. teapot.setMaterial(mat_default);
  493. rootNode.attachChild(teapot);
  494. // Create a wall with a simple texture from test_data
  495. Box box = new Box(2.5f,2.5f,1.0f);
  496. Spatial wall = new Geometry("Box", box );
  497. Material mat_brick = new Material(
  498. assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  499. mat_brick.setTexture("ColorMap",
  500. assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
  501. wall.setMaterial(mat_brick);
  502. wall.setLocalTranslation(2.0f,-2.5f,0.0f);
  503. rootNode.attachChild(wall);
  504. // Display a line of text with a default font
  505. guiNode.detachAllChildren();
  506. guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
  507. BitmapText helloText = new BitmapText(guiFont, false);
  508. helloText.setSize(guiFont.getCharSet().getRenderedSize());
  509. helloText.setText("Hello World");
  510. helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
  511. guiNode.attachChild(helloText);
  512. // Load a model from test_data (OgreXML + material + texture)
  513. Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
  514. ninja.scale(0.05f, 0.05f, 0.05f);
  515. ninja.rotate(0.0f, -3.0f, 0.0f);
  516. ninja.setLocalTranslation(0.0f, -5.0f, -2.0f);
  517. rootNode.attachChild(ninja);
  518. // You must add a light to make the model visible
  519. DirectionalLight sun = new DirectionalLight();
  520. sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
  521. rootNode.addLight(sun);
  522. }
  523. }</code></pre>
  524. </div>
  525. </div>
  526. <div class="paragraph">
  527. <p>Build and run the code sample. You should see a green Ninja with a colorful teapot standing behind a wall. The text on the screen should say &#8220;Hello World&#8221;.</p>
  528. </div>
  529. </div>
  530. </div>
  531. <div class="sect1">
  532. <h2 id="the-asset-manager"><a class="anchor" href="#the-asset-manager"></a>The Asset Manager</h2>
  533. <div class="sectionbody">
  534. <div class="paragraph">
  535. <p><strong>By game assets we mean all multi-media files, such as models, materials, textures, whole scenes, custom shaders, music and sound files, and custom fonts.</strong> JME3 comes with a handy AssetManager object that helps you access your assets.
  536. The AssetManager can load files from:</p>
  537. </div>
  538. <div class="ulist">
  539. <ul>
  540. <li>
  541. <p>The current classpath (the top level of your project directory).</p>
  542. </li>
  543. <li>
  544. <p>The sub-folders of the <code>assets</code> directory of your project.</p>
  545. </li>
  546. <li>
  547. <p>Optionally, custom paths that you register.</p>
  548. </li>
  549. </ul>
  550. </div>
  551. <div class="paragraph">
  552. <p>The following is the recommended directory structure for storing assets in your project directoy:</p>
  553. </div>
  554. <div class="listingblock">
  555. <div class="content">
  556. <pre class="highlightjs highlight"><code>MyGame/assets/
  557. MyGame/assets/Interface/
  558. MyGame/assets/MatDefs/
  559. MyGame/assets/Materials/
  560. MyGame/assets/Models/ &lt;-- your .j3o models go here
  561. MyGame/assets/Scenes/
  562. MyGame/assets/Shaders/
  563. MyGame/assets/Sounds/ &lt;-- your audio files go here
  564. MyGame/assets/Textures/ &lt;-- your textures go here
  565. MyGame/build.xml &lt;-- Default Ant build script
  566. MyGame/src/... &lt;-- your Java sources go here
  567. MyGame/...</code></pre>
  568. </div>
  569. </div>
  570. <div class="paragraph">
  571. <p>This is just a suggested best practice, and it&#8217;s what you get by default when creating a new Java project in the jMokeyEngine <a href="../../sdk/sdk.html" class="page">SDK</a>. You can create an <code>assets</code> directory and technically name the subdirectories whatever you like.</p>
  572. </div>
  573. <div class="admonitionblock important">
  574. <table>
  575. <tr>
  576. <td class="icon">
  577. <i class="fa icon-important" title="Important"></i>
  578. </td>
  579. <td class="content">
  580. When you build your project for distribution, there will be no <code>assets</code> directory. Instead, you will generate an <code>assets.jar</code> file, located in the <code>dist/lib</code> folder of your project that will contain the sub-folders of the <code>assets</code> directory and all the assets in those folders.
  581. </td>
  582. </tr>
  583. </table>
  584. </div>
  585. <div class="sect2">
  586. <h3 id="loading-textures"><a class="anchor" href="#loading-textures"></a>Loading Textures</h3>
  587. <div class="paragraph">
  588. <p>Place your textures in a subdirectory of <code>assets/Textures/</code>. Load the texture into the material before you set the Material. The following code sample is from the <code>simpleInitApp()</code> method and loads a simple wall model:</p>
  589. </div>
  590. <div class="listingblock">
  591. <div class="content">
  592. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">// Create a wall with a simple texture from test_data
  593. Box box = new Box(2.5f,2.5f,1.0f);
  594. Spatial wall = new Geometry("Box", box );
  595. Material mat_brick = new Material(
  596. assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  597. mat_brick.setTexture("ColorMap",
  598. assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
  599. wall.setMaterial(mat_brick);
  600. wall.setLocalTranslation(2.0f,-2.5f,0.0f);
  601. rootNode.attachChild(wall);</code></pre>
  602. </div>
  603. </div>
  604. <div class="paragraph">
  605. <p>In this case, you <a href="hello_material.html" class="page">create your own Material</a> and apply it to a Geometry. You base Materials on default material descriptions (such as &#8220;Unshaded.j3md&#8221;), as shown in this example.</p>
  606. </div>
  607. </div>
  608. <div class="sect2">
  609. <h3 id="loading-text-and-fonts"><a class="anchor" href="#loading-text-and-fonts"></a>Loading Text and Fonts</h3>
  610. <div class="paragraph">
  611. <p>This example displays the text &#8220;Hello World&#8221; in the default font at the bottom edge of the window. You attach text to the <code>guiNode</code> – this is a special node for flat (orthogonal) display elements. You display text to show the game score, player health, etc.
  612. The following code sample goes into the <code>simpleInitApp()</code> method.</p>
  613. </div>
  614. <div class="listingblock">
  615. <div class="content">
  616. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">// Display a line of text with a default font
  617. guiNode.detachAllChildren();
  618. guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
  619. BitmapText helloText = new BitmapText(guiFont, false);
  620. helloText.setSize(guiFont.getCharSet().getRenderedSize());
  621. helloText.setText("Hello World");
  622. helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
  623. guiNode.attachChild(helloText);</code></pre>
  624. </div>
  625. </div>
  626. <div class="admonitionblock tip">
  627. <table>
  628. <tr>
  629. <td class="icon">
  630. <i class="fa icon-tip" title="Tip"></i>
  631. </td>
  632. <td class="content">
  633. <div class="paragraph">
  634. <p>Clear existing text in the guiNode by detaching all its children.</p>
  635. </div>
  636. </td>
  637. </tr>
  638. </table>
  639. </div>
  640. </div>
  641. <div class="sect2">
  642. <h3 id="loading-a-model"><a class="anchor" href="#loading-a-model"></a>Loading a Model</h3>
  643. <div class="paragraph">
  644. <p>Export your 3D model in a <a href="../../jme3/features.html#supported-external-file-types" class="page">Supported External File Type</a> (.mesh.xml, .scene, .material, .skeleton.xml, .gltf) and place it in a subdirectory of <code>assets/Models/</code>. The following code sample goes into the <code>simpleInitApp()</code> method.</p>
  645. </div>
  646. <div class="listingblock">
  647. <div class="content">
  648. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">// Load a model from test_data (OgreXML + material + texture)
  649. Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
  650. ninja.scale(0.05f, 0.05f, 0.05f);
  651. ninja.rotate(0.0f, -3.0f, 0.0f);
  652. ninja.setLocalTranslation(0.0f, -5.0f, -2.0f);
  653. rootNode.attachChild(ninja);
  654. // You must add a directional light to make the model visible!
  655. DirectionalLight sun = new DirectionalLight();
  656. sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
  657. rootNode.addLight(sun);</code></pre>
  658. </div>
  659. </div>
  660. <div class="admonitionblock note">
  661. <table>
  662. <tr>
  663. <td class="icon">
  664. <i class="fa icon-note" title="Note"></i>
  665. </td>
  666. <td class="content">
  667. You do not need to create a Material if you exported the model with a material. Remember to add a light source, as shown, otherwise the material (and the whole model) is not visible!
  668. </td>
  669. </tr>
  670. </table>
  671. </div>
  672. </div>
  673. <div class="sect2">
  674. <h3 id="loading-assets-from-custom-paths"><a class="anchor" href="#loading-assets-from-custom-paths"></a>Loading Assets From Custom Paths</h3>
  675. <div class="paragraph">
  676. <p>What if your game relies on user supplied model files, that are not included in the distribution? If a file is not located in the default location (e.g. assets directory), you can register a custom Locator and load it from any path.</p>
  677. </div>
  678. <div class="paragraph">
  679. <p>Here is a usage example of a ZipLocator that is registered to a file <code>town.zip</code> in the top level of your project directory:</p>
  680. </div>
  681. <div class="listingblock">
  682. <div class="content">
  683. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> assetManager.registerLocator("town.zip", ZipLocator.class);
  684. Spatial scene = assetManager.loadModel("main.scene");
  685. rootNode.attachChild(scene);</code></pre>
  686. </div>
  687. </div>
  688. <div class="paragraph">
  689. <p>Here is a HttpZipLocator that can download zipped models and load them:</p>
  690. </div>
  691. <div class="listingblock">
  692. <div class="content">
  693. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> assetManager.registerLocator("https://storage.googleapis.com/"
  694.          + "google-code-archive-downloads/v2/code.google.com/"
  695.         + "jmonkeyengine/wildhouse.zip", HttpZipLocator.class);
  696. Spatial scene = assetManager.loadModel("main.scene");
  697. rootNode.attachChild(scene);</code></pre>
  698. </div>
  699. </div>
  700. <div class="paragraph">
  701. <p>JME3 offers ClasspathLocator, ZipLocator, FileLocator, HttpZipLocator, and UrlLocator (see <code>com.jme3.asset.plugins</code>).</p>
  702. </div>
  703. </div>
  704. </div>
  705. </div>
  706. <div class="sect1">
  707. <h2 id="creating-models-and-scenes"><a class="anchor" href="#creating-models-and-scenes"></a>Creating Models and Scenes</h2>
  708. <div class="sectionbody">
  709. <div class="paragraph">
  710. <p>To create 3D models and scenes, you need a 3D Mesh Editor. If you don&#8217;t have any tools, install Blender.
  711. Then you <a href="http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/UV_Map_Basics">create fully textured models (e.g. with Blender)</a>, export them to your project using a <a href="../../jme3/features.html#supported-formats" class="page">Supported External File Type</a>, <a href="../../jme3/features.html#supported-external-file-types" class="page">convert models</a> to <code>.j3o</code> using the recommended method for your chosen file type, <a href="#loading-models-and-scenes">load models</a>, and create 3D scenes from them.</p>
  712. </div>
  713. <div class="sect2">
  714. <h3 id="model-file-formats"><a class="anchor" href="#model-file-formats"></a>Model File Formats</h3>
  715. <div class="paragraph">
  716. <p>JME3 can convert and load</p>
  717. </div>
  718. <div class="ulist">
  719. <ul>
  720. <li>
  721. <p>Ogre XML models + materials.</p>
  722. </li>
  723. <li>
  724. <p>Ogre DotScenes.</p>
  725. </li>
  726. <li>
  727. <p>Wavefront OBJ + MTL models.</p>
  728. </li>
  729. <li>
  730. <p>.gltf</p>
  731. </li>
  732. </ul>
  733. </div>
  734. <div class="paragraph">
  735. <p>The <code>loadModel()</code> method loads these original file formats when you run your code directly from the SDK. If you however build the executables using the default build script, then the original model files (XML, OBJ, etc) <em>are not included</em>. This means, when you run the executable outside the SDK, and load any original models directly, you get the following error message:</p>
  736. </div>
  737. <div class="listingblock">
  738. <div class="content">
  739. <pre class="highlightjs highlight"><code>com.jme3.asset.DesktopAssetManager loadAsset
  740. WARNING: Cannot locate resource: Models/Ninja/Ninja.mesh.xml
  741. com.jme3.app.Application handleError
  742. SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
  743. java.lang.NullPointerException</code></pre>
  744. </div>
  745. </div>
  746. <div class="paragraph">
  747. <p>You see that loading the <strong>XML/OBJ/GLTF</strong> directly is only acceptable during the development phase in the SDK. For example, every time your graphic designer pushes updated files to the asset directory, you can quickly review the latest version in your development environment.</p>
  748. </div>
  749. <div class="paragraph">
  750. <p>But for QA test builds and for the final release build, you use <strong>.j3o files</strong> exclusively. J3o is an optimized binary format for jME3 applications. When you do QA test builds, or are ready to release, use the <a href="../../sdk/sdk.html" class="page">SDK</a> to <a href="../../sdk/model_loader_and_viewer.html" class="page">convert</a> all .obj/.scene/.xml/.gltf files to .j3o files, and update all code to load the .j3o files. The default build script automatically packages .j3o files in the executables.</p>
  751. </div>
  752. <div class="paragraph">
  753. <p>Open your JME3 Project in the jMonkeyEngine SDK.</p>
  754. </div>
  755. <div class="olist arabic">
  756. <ol class="arabic">
  757. <li>
  758. <p>Right-click a .OBJ, GLTF, or .mesh.xml file in the Projects window, and choose &#8220;Convert to j3o Binary&#8221;.</p>
  759. </li>
  760. <li>
  761. <p>The .j3o file appears next to the .mesh.xml file and has the same name.</p>
  762. </li>
  763. <li>
  764. <p>Update all your <code>loadModel()</code> lines accordingly. For example:</p>
  765. <div class="listingblock">
  766. <div class="content">
  767. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.j3o");</code></pre>
  768. </div>
  769. </div>
  770. </li>
  771. </ol>
  772. </div>
  773. <div class="admonitionblock tip">
  774. <table>
  775. <tr>
  776. <td class="icon">
  777. <i class="fa icon-tip" title="Tip"></i>
  778. </td>
  779. <td class="content">
  780. <div class="paragraph">
  781. <p>If your executable throws a &#8220;Cannot locate resource&#8221; runtime exception, check all load paths and make sure you have converted all models to .j3o files!</p>
  782. </div>
  783. </td>
  784. </tr>
  785. </table>
  786. </div>
  787. </div>
  788. <div class="sect2">
  789. <h3 id="loading-models-and-scenes"><a class="anchor" href="#loading-models-and-scenes"></a>Loading Models and Scenes</h3>
  790. <table class="tableblock frame-all grid-all stretch">
  791. <colgroup>
  792. <col style="width: 15%;">
  793. <col style="width: 85%;">
  794. </colgroup>
  795. <thead>
  796. <tr>
  797. <th class="tableblock halign-left valign-top">Task?</th>
  798. <th class="tableblock halign-left valign-top">Solution!</th>
  799. </tr>
  800. </thead>
  801. <tbody>
  802. <tr>
  803. <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
  804. <p>Load model W/ materials.</p>
  805. </div></div></td>
  806. <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
  807. <p>Use the asset manager&#8217;s <code>loadModel()</code> method and attach the Spatial to the rootNode.</p>
  808. </div>
  809. <div class="listingblock">
  810. <div class="content">
  811. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">Spatial elephant = assetManager.loadModel("Models/Elephant/Elephant.mesh.xml");
  812. rootNode.attachChild(elephant);</code></pre>
  813. </div>
  814. </div>
  815. <div class="listingblock">
  816. <div class="content">
  817. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">Spatial elephant = assetManager.loadModel("Models/Elephant/Elephant.j3o");
  818. rootNode.attachChild(elephant);</code></pre>
  819. </div>
  820. </div></div></td>
  821. </tr>
  822. <tr>
  823. <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
  824. <p>Load model W/O materials.</p>
  825. </div></div></td>
  826. <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
  827. <p>If you have a model without materials, you have to give it a material to make it visible.</p>
  828. </div>
  829. <div class="listingblock">
  830. <div class="content">
  831. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">Spatial teapot = assetManager.loadModel("Models/Teapot/Teapot.j3o");
  832. Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md"); // default material
  833. teapot.setMaterial(mat);
  834. rootNode.attachChild(teapot);</code></pre>
  835. </div>
  836. </div></div></td>
  837. </tr>
  838. <tr>
  839. <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
  840. <p>Load a scene.</p>
  841. </div></div></td>
  842. <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
  843. <p>You load scenes just like you load models:</p>
  844. </div>
  845. <div class="listingblock">
  846. <div class="content">
  847. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">Spatial scene = assetManager.loadModel("Scenes/town/main.scene");
  848. rootNode.attachChild(scene);</code></pre>
  849. </div>
  850. </div>
  851. <div class="listingblock">
  852. <div class="content">
  853. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">Spatial scene = assetManager.loadModel("Scenes/town/main.j3o");
  854. rootNode.attachChild(scene);</code></pre>
  855. </div>
  856. </div></div></td>
  857. </tr>
  858. </tbody>
  859. </table>
  860. </div>
  861. </div>
  862. </div>
  863. <div class="sect1">
  864. <h2 id="excercise-how-to-load-assets"><a class="anchor" href="#excercise-how-to-load-assets"></a>Excercise - How to Load Assets</h2>
  865. <div class="sectionbody">
  866. <div class="paragraph">
  867. <p>As an exercise, let&#8217;s try different ways of loading a scene. You will learn how to load the scene directly, or from a zip file.</p>
  868. </div>
  869. <div class="paragraph">
  870. <p>Remember that there will be no <code>assets</code> folder in a final deployment. If you are going to use a zip, do not put it in the <code>assets</code> folder. Otherwise, you will likely get errors about a missing file. For final distribution, add it to your dist folder.</p>
  871. </div>
  872. <div class="olist arabic">
  873. <ol class="arabic">
  874. <li>
  875. <p><a href="https://wiki.jmonkeyengine.org/Scenes/Town/town.zip">Download the town.zip</a> sample scene.</p>
  876. </li>
  877. <li>
  878. <p>Place the town.zip file in the top level directory of your JME3 project, like so:</p>
  879. <div class="listingblock">
  880. <div class="content">
  881. <pre class="highlightjs highlight"><code>jMonkeyProjects/MyGameProject/assets/
  882. jMonkeyProjects/MyGameProject/build.xml
  883. jMonkeyProjects/MyGameProject/src/
  884. jMonkeyProjects/MyGameProject/town.zip
  885. ...</code></pre>
  886. </div>
  887. </div>
  888. <div class="paragraph">
  889. <p>Use the following method to load models from a zip file:</p>
  890. </div>
  891. </li>
  892. <li>
  893. <p>Verify <code>town.zip</code> is in the project directory.</p>
  894. </li>
  895. <li>
  896. <p>Register a zip file locator to the project directory: Add the following code under <code>simpleInitApp()</code>.</p>
  897. <div class="listingblock">
  898. <div class="content">
  899. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> assetManager.registerLocator("town.zip", ZipLocator.class);
  900. Spatial gameLevel = assetManager.loadModel("main.scene");
  901. gameLevel.setLocalTranslation(0, -5.2f, 0);
  902. gameLevel.setLocalScale(2);
  903. rootNode.attachChild(gameLevel);</code></pre>
  904. </div>
  905. </div>
  906. <div class="paragraph">
  907. <p>The loadModel() method now searches this zip directly for the files to load.<br>
  908. (This means, do not write <code>loadModel(town.zip/main.scene)</code> or similar!)</p>
  909. </div>
  910. </li>
  911. <li>
  912. <p>Clean, build and run the project.<br>
  913. You should now see the Ninja+wall+teapot standing in a town.</p>
  914. </li>
  915. </ol>
  916. </div>
  917. <div class="admonitionblock tip">
  918. <table>
  919. <tr>
  920. <td class="icon">
  921. <i class="fa icon-tip" title="Tip"></i>
  922. </td>
  923. <td class="content">
  924. <div class="paragraph">
  925. <p>If you register new locators, make sure you do not get any file name conflicts: Don&#8217;t name all scenes <code>main.scene</code> but give each scene a unique name.</p>
  926. </div>
  927. </td>
  928. </tr>
  929. </table>
  930. </div>
  931. <div class="paragraph">
  932. <p>Earlier in this tutorial, you loaded scenes and models from the asset directory. This is the most common way you will be loading scenes and models. Here is the typical procedure:</p>
  933. </div>
  934. <div class="olist arabic">
  935. <ol class="arabic">
  936. <li>
  937. <p>Remove the code that you added for the previous exercise.</p>
  938. </li>
  939. <li>
  940. <p>Unzip the town.zip to see the structure of the contained Ogre dotScene: You will get a directory named <code>town</code>. It contains XML, texture files, and a file called main.scene.</p>
  941. </li>
  942. <li>
  943. <p>Move the unzipped <code>town/</code> directory into the <code>assets/Scenes/</code> directory of your project.</p>
  944. </li>
  945. <li>
  946. <p>Add the following code under <code>simpleInitApp()</code>.</p>
  947. <div class="listingblock">
  948. <div class="content">
  949. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> Spatial gameLevel = assetManager.loadModel("Scenes/town/main.scene");
  950. gameLevel.setLocalTranslation(0, -5.2f, 0);
  951. gameLevel.setLocalScale(2);
  952. rootNode.attachChild(gameLevel);</code></pre>
  953. </div>
  954. </div>
  955. <div class="paragraph">
  956. <p>Note that the path is relative to the <code>assets/…</code> directory.</p>
  957. </div>
  958. </li>
  959. <li>
  960. <p>Clean, build and run the project.<br>
  961. Again, you should see the Ninja+wall+teapot standing in a town.</p>
  962. </li>
  963. </ol>
  964. </div>
  965. <div class="paragraph">
  966. <p>Here is a third method you must know, loading a scene/model from a .j3o file:</p>
  967. </div>
  968. <div class="olist arabic">
  969. <ol class="arabic">
  970. <li>
  971. <p>Remove the code from the previous exercise.</p>
  972. </li>
  973. <li>
  974. <p>If you haven&#8217;t already, open the <a href="../../sdk/sdk.html" class="page">SDK</a> and open the project that contains the HelloAsset class.</p>
  975. </li>
  976. <li>
  977. <p>In the projects window, browse to the <code>assets/Scenes/town</code> directory.</p>
  978. </li>
  979. <li>
  980. <p>Right-click the <code>main.scene</code> and convert the scene to binary: The jMonkeyPlatform generates a main.j3o file.</p>
  981. </li>
  982. <li>
  983. <p>Add the following code under <code>simpleInitApp() {</code></p>
  984. <div class="listingblock">
  985. <div class="content">
  986. <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> Spatial gameLevel = assetManager.loadModel("Scenes/town/main.j3o");
  987. gameLevel.setLocalTranslation(0, -5.2f, 0);
  988. gameLevel.setLocalScale(2);
  989. rootNode.attachChild(gameLevel);</code></pre>
  990. </div>
  991. </div>
  992. <div class="paragraph">
  993. <p>Again, note that the path is relative to the <code>assets/…</code> directory.</p>
  994. </div>
  995. </li>
  996. <li>
  997. <p>Clean, Build and run the project.<br>
  998. Again, you should see the Ninja+wall+teapot standing in a town.</p>
  999. </li>
  1000. </ol>
  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>Now you know how to populate the scenegraph with static shapes and models, and how to build scenes. You have learned how to load assets using the <code>assetManager</code> and you have seen that the paths start relative to your project directory. Another important thing you have learned is to convert models to .j3o format for the executable JARs etc.</p>
  1009. </div>
  1010. <div class="paragraph">
  1011. <p><strong>See also:</strong></p>
  1012. </div>
  1013. <div class="ulist">
  1014. <ul>
  1015. <li>
  1016. <p><a href="../../jme3/external/blender.html" class="page">The definitive Blender import tutorial</a></p>
  1017. </li>
  1018. <li>
  1019. <p><a href="../intermediate/multi-media_asset_pipeline.html" class="page">Asset pipeline introduction</a></p>
  1020. </li>
  1021. <li>
  1022. <p>If you want to learn how to load sounds, see <a href="hello_audio.html" class="page">Hello Audio</a></p>
  1023. </li>
  1024. <li>
  1025. <p>If you want to learn more about loading textures and materials, see <a href="hello_material.html" class="page">Hello Material</a></p>
  1026. </li>
  1027. </ul>
  1028. </div>
  1029. </div>
  1030. </div>
  1031. <nav class="pagination">
  1032. <span class="prev"><a href="hello_node.html">Hello Node</a></span>
  1033. <span class="next"><a href="hello_main_event_loop.html">Hello Update Loop</a></span>
  1034. </nav>
  1035. </article>
  1036. <aside class="toc sidebar" data-title="Contents" data-levels="2">
  1037. <div class="toc-menu"></div>
  1038. </aside>
  1039. </div>
  1040. </main>
  1041. </div>
  1042. <footer class="footer">
  1043. <p>Copyright 2020 jMonkeyEngine Wiki Contributors. Licensed BSD-3.</p>
  1044. </footer>
  1045. <script src="../../../_/js/vendor/docsearch.min.js"></script>
  1046. <!-- fetched from https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js -->
  1047. <script>
  1048. var search = docsearch({
  1049. apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
  1050. indexName: 'jmonkeyengine',
  1051. inputSelector: '#search-input',
  1052. autocompleteOptions: { hint: false, keyboardShortcuts: ['s'] },
  1053. algoliaOptions: { hitsPerPage: 10 }
  1054. }).autocomplete
  1055. search.on('autocomplete:closed', function () { search.autocomplete.setVal() })
  1056. function focusSearchInput () { document.querySelector('#search-input').focus() }
  1057. if (document.querySelector('.home-link.is-current')) window.addEventListener('load', focusSearchInput)
  1058. </script>
  1059. <script src="../../../_/js/site.js"></script>
  1060. <script async src="../../../_/js/vendor/highlight.js"></script>
  1061. </body>
  1062. </html>