the_scene_graph.adoc 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. = The Scene Graph and Other jME3 Terminology
  2. :revnumber: 2.1
  3. :revdate: 2020/07/24
  4. :keywords: spatial, node, mesh, geometry, scenegraph, rootnode
  5. Before you start making games, make sure you understand general xref:tutorials:concepts/terminology.adoc[3D Graphics terminology].
  6. Second, if you are a beginner, we recommend our xref:tutorials:concepts/scenegraph_for_dummies.adoc[Scene Graph for Dummies] presentation for a visual introduction to the concept of a scene graph.
  7. Then continue learning about jME3 concepts here.
  8. == Coordinate System
  9. [.right]
  10. image::tutorials:concepts/coordinate-system.png[coordinate-system.png,width="235",height="210",align="right"]
  11. The jMonkeyEngine uses a right-handed coordinate system, just as OpenGL does.
  12. The coordinate system consists of:
  13. * The _origin_, a single central point in space.
  14. ** The origin point is always at coordinate zero, in Java: `new Vector3f(0,0,0)`.
  15. * Three _coordinate axes_ that are mutually perpendicular, and meet in the origin.
  16. ** The X axis starts left and goes right.
  17. ** The Y axis starts below and goes up.
  18. ** The Z axis starts away from you, and goes towards you.
  19. Every point in 3D space is uniquely defined by its X,Y,Z coordinates. The three numeric coordinates express how many "`steps`" from each of the three axes a point is. The data type for all vectors in jME3 is `com.jme3.math.Vector3f`. All vectors are relative to the described coordinate system. +
  20. Example: The point `new Vector3f(3,-5,1)` is 3 steps to the right, 5 steps down, and 1 towards you.
  21. [NOTE]
  22. ====
  23. The unit of measurement ("`one`" step) in jME3 is the *world unit*, short: wu. Typically, 1 wu is considered to be one meter. As long as you are consistent throughout your game, 1 wu can be any distance you like.
  24. ====
  25. For your orientation:
  26. * The default camera's location is `Vector3f(0.0f, 0.0f, 10.0f)`.
  27. * The default camera is looking in the direction described by the (so called) negative Z unit vector `Vector3f(0.0f, 0.0f, -1.0f)`.
  28. This means the player's point of view is on the positive side of the Z axis, looking back, towards the origin, down the Z axis.
  29. == How to move yourself through the 3D scene
  30. When you play a 3D game, you typically want to navigate the 3D scene. Note that by default, the mouse pointer is invisible, and the mouse is set up to control the camera rotation!
  31. By default, jME3 uses the following common navigation inputs
  32. [cols="3", options="header"]
  33. |===
  34. a| Game Inputs
  35. a| Camera Motion
  36. a| Player POV
  37. a|Press the W and S keys
  38. a|move the camera forward, and backward
  39. a|you walk back and forth
  40. a|Press the A and D keys
  41. a|move the camera left and right
  42. a|you step left or right
  43. a|Press the Q and Y keys
  44. a|move the camera up and down
  45. a|you fly up and down
  46. a|Move the mouse left-right
  47. a|rotate the camera left/right
  48. a|you look left or right
  49. a|Move the mouse forwards-backwards
  50. a|rotate up/down
  51. a|you look at the sky or your feet
  52. |===
  53. These default settings are called "`WASD`" keys and "`Mouse`" Look. You can customize xref:core:input/input_handling.adoc[input handling] for your game. Sorry, but these settings work best on a QWERTY/QWERTZ keyboard.
  54. == Scene Graph and RootNode
  55. The _scene graph_ represents your 3D world. Objects in the jME3 scene graph are called xref:core:scene/spatial.adoc[Spatial]s. Everything attached to the parent _rootNode_ is part of your scene. Your game inherits the `rootNode` object from the `SimpleApplication` class.
  56. image::tutorials:concepts/scene-graph.png[scene-graph.png,width="",height="",align="center"]
  57. * _Attaching_ a Spatial to the rootNode (or its child nodes) adds it to the scene;
  58. * _Detaching_ a Spatial from the rootNode (or its child nodes) removes it from the scene.
  59. All objects in the scene graph are in a parent-child relationship. When you transform (move, rotate, scale) one parent, all its children follow.
  60. [NOTE]
  61. ====
  62. The scene graph only manages the parent-child relationship of spatials. The actual location, rotation, or scale of an object is stored inside each Spatial.
  63. ====
  64. == Spatials: Node vs Geometry
  65. A Spatial can be transformed (in other words, it has a location, a rotation, and a scale). A Spatial can be loaded and saved as a .3jo file. There are two types of Spatials, _Node_ and _Geometry_:
  66. [cols="10,45,45", options="header"]
  67. |===
  68. <a|
  69. 2+a| Spatial
  70. a| Purpose:
  71. 2+a| A Spatial is an abstract data structure that stores transformations (translation, rotation, scale).
  72. <a|
  73. a| Geometry
  74. a| Node
  75. a| Visibility:
  76. a| A visible 3-D object.
  77. a| An invisible "`handle`" for a group of objects.
  78. a| Purpose:
  79. a| A Geometry represents the "`look`" of an object: Shape, color, texture, opacity/transparency.
  80. a| A Node groups Geometries and other Nodes together: You transform a Node to affect all attached Nodes (parent-child relationship).
  81. a| Content:
  82. a| Transformations, mesh, material.
  83. a| Transformations. No mesh, no material.
  84. a| Examples:
  85. a| A box, a sphere, player, a building, a piece of terrain, a vehicle, missiles, NPCs, etc…
  86. a| The rootNode, the guiNode, an audioNode, a custom grouping node for a vehicle plus its passengers, etc.
  87. |===
  88. == How to Use This Knowledge?
  89. Before you start creating your game, you should plan your scene graph: Which Nodes and Geometries will you need? Complete the xref:tutorials:beginner/beginner.adoc[Beginner tutorials] to learn how to load and create Spatials, how to lay out a scene by attaching, detaching, and transforming Spatials, and how to add interaction and effects to a game.
  90. == See also
  91. * xref:core:scene/spatial.adoc[Spatial] – More details about working with Nodes and Geometries
  92. * xref:core:scene/traverse_scenegraph.adoc[Traverse SceneGraph] – Find any Node or Geometry in the scenegraph.
  93. * xref:core:renderer/camera.adoc[Camera] – Learn more about the Camera in the scene.