material_editing.adoc 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. = jMonkeyEngine SDK: Material Editor
  2. :revnumber: 2.1
  3. :revdate: 2020/07/23
  4. :keywords: documentation, sdk, material, file, texture
  5. If you are looking for background information, read about xref:core:material/material_definitions.adoc[Material Definitions] and xref:core:material/j3m_material_files.adoc[j3M Material Files].
  6. You can write .j3m files in a text editor, or use the jMonkeyEngine SDK to generate them for you as described in this article.
  7. == Materials
  8. The jMonkeyEngine uses a special Material format, which comes in .j3m files. You use .j3m files to store sets of material properties that you use repeatedly. This enables you write one short line of code that simply loads the presets from a custom .j3m file. Without a .j3m file you need to write several lines of material property setters every time when you want to use a non-default material.
  9. == Creating .j3m Materials
  10. [float.right]
  11. image::material-editor.png[material-editor.png,width="275",height="245",align="right"]
  12. To create new .j3m files in the jMonkeyEngine SDK:
  13. . btn:[RMB] select the `assets/Materials` directory and choose `menu:New[Other]`.
  14. . In the New File Wizard, choose `menu:Material[Empty Material File]`, and click btn:[Next].
  15. . Give the file a name, for example `mat_wall` for a wall material.
  16. . A new file `mat_wall.j3m` is created in the Materials directory and opens in the Material Editor.
  17. You can edit the source of the material, or use the user-friendly visual editor to set the properties of the material. Set the properties to the same values as you would otherwise specify with setters on a Material object in Java code:
  18. [source,java]
  19. ----
  20. Material mat_wall = new Material(
  21. assetManager, "Common/MatDefs/Light/Lighting.j3md");
  22. mat_wall.setTexture("DiffuseMap",
  23. assetManager.loadTexture("Textures/wall_diffuse.png"));
  24. mat_wall.setTexture("NormalMap",
  25. assetManager.loadTexture("Textures/wall_normals.png"));
  26. mat_wall.setFloat("Shininess", 5f);
  27. ----
  28. This Java code corresponds to the following .j3m file:
  29. [source,xml]
  30. ----
  31. Material my brick wall : Common/MatDefs/Light/Lighting.j3md {
  32. MaterialParameters {
  33. DiffuseMap: Repeat Textures/wall_diffuse.png
  34. NormalMap: Repeat Textures/wall_normals.png
  35. Shininess: 5.0
  36. }
  37. }
  38. ----
  39. You can modify the source code of the j3m file in the "`source`" tab of the Material Editor.
  40. == Using .j3m Materials
  41. [float.right]
  42. image::applymaterial.jpg[applymaterial.jpg,width="180",height="300",align="right"]
  43. When the material is ready and saved into your projects assets directory, you can assign the .j3m to a Geometry.
  44. In the jMonkeyEngine SDK
  45. . btn:[RMB] select the j3o file and choose `Edit in SceneComposer`.
  46. . You can open the SceneExplorer window by selecting `menu:Window[SceneExplorer]` from the menu bar, if it's not already open.
  47. . In the SceneExplorer, click the geometry to which you want to assign the material.
  48. . Open the Properties window.
  49. . Assign the .j3m material to the .j3o in the `menu:Properties[Geometry>Material]` section.
  50. +
  51. TIP: If the .j3o file already has a material assigned to it from exporting/importing, you can generate the material by selecting "`create j3m file`" instead. This will place a .j3m under `assets/Materials/Generated` and assign it to your .j3o.
  52. . Save the j3o and load it into you game.
  53. Or in your Java code
  54. * Use a loader and a setter to assign the material to a Geometry.
  55. [source,java]
  56. ----
  57. mywall.setMaterial(assetManager.loadMaterial( "Materials/mat_wall.j3m"));
  58. ----
  59. '''
  60. *See also:*
  61. * xref:core:material/material_specification.adoc[Developer specification of the jME3 material system (.j3md,.j3m)]
  62. * xref:tutorials:beginner/hello_material.adoc[Hello Material]
  63. * xref:core:material/materials_overview.adoc[Materials Overview]
  64. * xref:neotexture.adoc[Neotexture] (Procedural textures)