introduction.rst 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. Introduction
  2. ============
  3. Creating a 3D game can be challenging. That extra Z coordinate makes
  4. many of the common techniques that helped to make 2D games simple no
  5. longer work. To aid in this transition, it is worth mentioning that
  6. Godot uses very similar APIs for 2D and 3D. Most nodes are the same and
  7. are present in both 2D and 3D versions. In fact, it is worth checking
  8. the 3D platformer tutorial, or the 3D kinematic character tutorials,
  9. which are almost identical to their 2D counterparts.
  10. In 3D, math is a little more complex than in 2D, so also checking the
  11. [[Vector Math]] in the wiki (which were specially created for game
  12. developers, not mathematicians or engineers) will help pave the way into
  13. efficiently developing 3D games.
  14. Spatial Node
  15. ~~~~~~~~~~~~
  16. `Node2D <https://github.com/okamstudio/godot/wiki/class_node2d>`__ is
  17. the base node for 2D.
  18. `Control <https://github.com/okamstudio/godot/wiki/class_control>`__ is
  19. the base node for everything GUI. Following this reasoning, the 3D
  20. engine uses the
  21. `Spatial <https://github.com/okamstudio/godot/wiki/class_spatial>`__
  22. node for everything 3D.
  23. .. image:: /img/tuto_3d1.png
  24. Spatial nodes have a local transform, which is relative to the parent
  25. node (as long as the parent node is also **or inherits** of type
  26. Spatial). This transform can be accessed as a 4x3
  27. `Transform <https://github.com/okamstudio/godot/wiki/class_transform>`__,
  28. or as 3
  29. `Vector3 <https://github.com/okamstudio/godot/wiki/class_vector3>`__
  30. members representing location, euler rotation (x,y and z angles) and
  31. scale.
  32. .. image:: /img/tuto_3d2.png
  33. 3D Content
  34. ~~~~~~~~~~
  35. Unlike 2D, where loading image content and drawing is straightforward,
  36. 3D is a little more difficult. The content needs to be created with
  37. special 3D tool (usually referred to as DCCs) and exported to an
  38. exchange file format in order to be imported in Godot (3D formats are
  39. not as standardized as images).
  40. DCC-Created Models
  41. ------------------
  42. There are two pipelines to import 3D models in Godot. The first and most
  43. common one is through the [[Import 3D]] importer, which allows to import
  44. entire scenes (just as they look in the DCC), including animation,
  45. skeletal rigs, blend shapes, etc.
  46. The second pipeline is through the [[Import Meshes]] importer. This
  47. second method allows importing simple .OBJ files as mesh resources,
  48. which can be then put inside a
  49. `MeshInstance <https://github.com/okamstudio/godot/wiki/class_meshinstance>`__
  50. node for display.
  51. Generated Geometry
  52. ------------------
  53. It is possible to create custom geometry by using the
  54. `Mesh <https://github.com/okamstudio/godot/wiki/class_mesh>`__ resource
  55. directly, simply create your arrays and use the
  56. `Mesh.add\_surface <https://github.com/okamstudio/godot/wiki/class_mesh#add_surface>`__
  57. function. A helper class is also available,
  58. `SurfaceTool <https://github.com/okamstudio/godot/wiki/class_surfacetool>`__,
  59. which provides a more straightforward API and helpers for indexing,
  60. generating normals, tangents, etc.
  61. In any case, this method is meant for generating static geometry (models
  62. that will not be updated often), as creating vertex arrays and
  63. submitting them to the 3D API has a significant performance cost.
  64. Immediate Geometry
  65. ------------------
  66. If, instead, there is a requirement to generate simple geometry that
  67. will be updated often, Godot provides a special node,
  68. `ImmediateGeometry <https://github.com/okamstudio/godot/wiki/class_immediategeometry>`__
  69. which provides an OpenGL 1.x style immediate-mode API to create points,
  70. lines, triangles, etc.
  71. 2D in 3D
  72. --------
  73. While Godot packs a powerful 2D engine, many types of games use 2D in a
  74. 3D environment. By using a fixed camera (either orthogonal or
  75. perspective) that does not rotate, nodes such as
  76. `Sprite3D <https://github.com/okamstudio/godot/wiki/class_sprite3d>`__
  77. and
  78. `AnimatedSprite3D <https://github.com/okamstudio/godot/wiki/class_animatedsprite3d>`__
  79. can be used to create 2D games that take advantage of mixing with 3D
  80. backgrounds, more realistic parallax, lighting/shadow effects, etc.
  81. The disadvantage is, of course, that added complexity and reduced
  82. performance in comparison to plain 2D, as well as the lack of reference
  83. of working in pixels.
  84. Environment
  85. ~~~~~~~~~~~
  86. Besides editing a scene, it is often common to edit the environment.
  87. Godot provides a
  88. `WorldEnvironment <https://github.com/okamstudio/godot/wiki/class_worldenvironment>`__
  89. node that allows changing the background color, mode (as in, put a
  90. skybox), and applying several types of built-in post-processing effects.
  91. Environments can also be overriden in the Camera.
  92. 3D Viewport
  93. ~~~~~~~~~~~
  94. Editing 3D scenes is done in the 3D tab. This tab can be selected
  95. manually, but it will be automatically enabled when a Spatial node is
  96. selected.
  97. .. image:: /img/tuto_3d3.png
  98. Default 3D scene navigation controls are similar to Blender (aiming to
  99. have some sort of consistency in the free software pipeline..), but
  100. options are included to customize mouse buttons and behavior to be
  101. similar to other tools in Editor Settings:
  102. .. image:: /img/tuto_3d4.png
  103. Coordinate System
  104. -----------------
  105. Godot uses the `metric <http://en.wikipedia.org/wiki/Metric_system>`__
  106. system for everything. 3D Physics and other areas are tuned for this, so
  107. attempting to use a different scale is usually a bad idea (unless you
  108. know what you are doing).
  109. When working with 3D assets, it's always best to work in the correct
  110. scale (set your DCC to metric). Godot allows scaling post-import and,
  111. while this works in most cases, in rare situations it may introduce
  112. floating point precision issues (and thus, glitches or artifacts) in
  113. delicate areas such as rendering or physics. So, make sure your artists
  114. always work in the right scale!
  115. The Y coordinate is used for "up", though for most objects that need
  116. alignment (like lights, cameras, capsule collider, vehicle, etc), the Z
  117. axis is used as a "pointing towards" direction. This convention roughly
  118. means that:
  119. - **X** is sides
  120. - **Y** is up/down
  121. - **Z** is front/back
  122. Space and Manipulation Gizmos
  123. -----------------------------
  124. Moving objects in the 3D view is done through the manipulator gizmos.
  125. Each axis is represented by a color: Red, Green, Blue represent X,Y,Z
  126. respectively. This convention applies to the grid and other gizmos too
  127. (and also to the shader language, ordering of components for
  128. Vector3,Color,etc).
  129. .. image:: /img/tuto_3d5.png
  130. Some useful keybindings:
  131. - To snap motion or rotation, press the "s" key while moving, scaling
  132. or rotating.
  133. - To center the view on the selected object, press the "f" key.
  134. View Menu
  135. ---------
  136. The view options are controlled by the \`[view]\` menu. Pay attention to
  137. this little menu inside the window because it is often overlooked!
  138. .. image:: /img/tuto_3d6.png
  139. Default Lighting
  140. ----------------
  141. The 3D View has by some default options on lighting:
  142. - There is a directional light that makes objects visible while editing
  143. turned on by default. It is no longer visible when running the game.
  144. - There is subtle default environment light to avoid places not reached
  145. by the light to remain visible. It is also no longer visible when
  146. running the game (and when the default light is turned off).
  147. These can be turned off by toggling the "Default Light" option:
  148. .. image:: /img/tuto_3d8.png
  149. Customizing this (and other default view options) is also possible via
  150. the settings menu:
  151. .. image:: /img/tuto_3d7.png
  152. which opens this window, allowing to customize ambient light color and
  153. default light direction:
  154. .. image:: /img/tuto_3d9.png
  155. Cameras
  156. -------
  157. No matter how many objects are placed in 3D space, nothing will be
  158. displayed unless a
  159. `Camera <https://github.com/okamstudio/godot/wiki/class_camera>`__ is
  160. also added to the scene. Cameras can either work in orthogonal or
  161. perspective projections:
  162. .. image:: /img/tuto_3d10.png
  163. Cameras are associated and only display to a parent or grand-parent
  164. viewport. Since the root of the scene tree is a viewport, cameras will
  165. display on it by default, but if sub-viewports (either as render target
  166. or picture-in-picture) are desired, they need their own children cameras
  167. to display.
  168. .. image:: /img/tuto_3d11.png
  169. When dealing with multiple cameras, the following rules are followed for
  170. each viewport:
  171. - If no cameras are present in the scene tree, the first one that
  172. enters it will become the active camera. Further cameras entering the
  173. scene will be ignored (unless they are set as *current*).
  174. - If a camera has the "*current*" property set, it will be used
  175. regardless of any other camera in the scene. If the property is set,
  176. it will become active, replacing the previous camera.
  177. - If an active camera leaves the scene tree, the first camera in
  178. tree-order will take it's place.
  179. Lights
  180. ------
  181. There is no limitation on the number of lights and types in Godot. As
  182. many as desired can be added (as long as performance allows). Shadow
  183. maps are, however, limited. The more they are used, the less the quality
  184. overall.
  185. It is possible to use [[Light Baking]], to avoid using large amount of
  186. real-time lights and improve performance.
  187. *Juan Linietsky, Ariel Manzur, Distributed under the terms of the `CC
  188. By <https://creativecommons.org/licenses/by/3.0/legalcode>`__ license.*