2
0

sample_code.adoc 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. = jMonkeyEngine SDK: Sample Code
  2. :revnumber: 2.0
  3. :revdate: 2020/07/10
  4. :keywords: documentation, sdk, asset, project
  5. You can run example code by opening an included JME3Tests project and included assets. You can also search the built-in documentation or drag and drop code snippets from the Palette in the SDK to get short code sample.
  6. == Code Palette and Samples in the SDK
  7. * Type a keyword into the search box in the SDK or press kbd:[F1] to search the built-in help for sample code.
  8. * xref:code_editor.adoc[SDK code editor and palette]
  9. == The JME3Tests Project Template
  10. The jMonkeyEngine SDK contains a Test Project with lots of sample code and assets. The Test Project is all set up and ready to run, and it's easy to use for beginners (no need to mess with classpaths or libraries).
  11. . Install and Open the jMonkeyEngine xref:sdk.adoc[SDK].
  12. . Go to `menu:File[New Project]`.
  13. . In the New Project Wizard, select `JME3 Tests` from the `JME3` category. Click `btn:[Next]`.
  14. . Specify a location, e.g. create a jMonkeyProjects directory in your home directory. Click `btn:[Finish]`.
  15. This default project template creates a project called `JmeTests`. It contains all test classes and examples from the jme3 source repository. Feel free to modify the code samples and experiment! In the unlikely event that you should break the project, emoji:smiley[] you can always recreate all packaged samples by creating another project from the New Project wizard's `JME3 Tests` template.
  16. If you're using the 3.1.0-Stable+ version of the SDK, you will need to set the `Source/Binary Format` from the `Project Properties` window to Java 1.7 or later.
  17. * To change the source, `btn:[RMB]` select the jmeTestProject and then select `menu:Properties[Sources>Source/Binary Format]`, or from the File menu, with the jmeTestProject selected, `menu:File[Project Properties>Sources>Source/Binary Format]`.
  18. You will also need to remove the `jme3-jbullet` library and add `jme3-bullet` and `jme3-bullet-native` libraries.
  19. * From the `Project Properties` window select `Libraries` and then the `Compile` tab. Under `Compile-time Libraries` select `jme3-jbullet` and press `btn:[Remove]`. Press `btn:[Add Library]`, select the two libraries `jme3-bullet` and `jme3-bullet-native` while holding kbd:[Ctrl] and then press `btn:[Add Library]` and finally `btn:[OK]`.
  20. [IMPORTANT]
  21. ====
  22. Press kbd:[Shift] + kbd:[F6] to run a class that is open in the editor, or `btn:[RMB]` a class in the Project window and choose `btn:[Run File]`. You can run the `TestChooser` app by `btn:[RMB]` selecting the project and pressing `btn:[Run]`. The TestChooser app allows you to easily navigate through all the test cases.
  23. ====
  24. == JME3TestData Assets
  25. You may want access to some sample assets, such as 3D models or textures, in one of your projects. A common situation for this would be while going through the xref:tutorials:beginner/beginner.adoc[beginner tutorials].
  26. . btn:[RMB] select an existing jME3 project in the xref:sdk.adoc[SDK], and select Properties.
  27. . In the Properties window, select the `Libraries` section. Go to the `Compile` tab, it contains `Compile-time Libraries`.
  28. . Click the btn:[Add Library] button and select the pre-defined `jme3-test-data`. Click btn:[OK].
  29. . Click btn:[OK] to save and close the Properties.
  30. The project's assetManager now has access to sample files from the `jme3-test-data.jar` file. This JAR library contains
  31. * Ogre XML Models: Ninja.mesh.xml, Oto.mesh.xml, HoverTank.mesh.xml, Sinbad.mesh.xml, and many more
  32. * Blender models
  33. * Materials and Textures
  34. ** Terrain, sky, rock, brick, pond…
  35. ** Particle effect textures
  36. * Sounds
  37. * And more…
  38. == AssetPacks
  39. [.right]
  40. image::assetpackbrowser-300x166.jpg[assetpackbrowser-300x166.jpg,width="",height=""]
  41. If you need sample 3D models, don't miss the opportunity to download our community-provided xref:asset_packs.adoc[Asset Packs]!
  42. In the SDK:
  43. * Open the AssetPackBrowser from the Windows menu
  44. * In the AssetPackBrowser, click the Online AssetPacks button
  45. * Click btn:[Install] on the AssetPack of your choice. The SDK downloads it and makes the assets accessible in your AssetPack Library.
  46. * Click the btn:[View Library] button and open the Assets node.
  47. * btn:[RMB] select an asset to
  48. ** Preview it
  49. ** Add it to the SceneComposer
  50. ** Add it to a game project's assets directory